From: "flichtenheld (Code Review)" In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, antonio@...2726..., gert@...1296... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Ec64+lHvvb8="; charset=UTF-8 Subject: [Openvpn-devel] [XL] Change in openvpn[master]: Reformat the whole project with clang-format List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Wed, 16 Jul 2025 15:34:55 -0000 To: plaisthos Cc: openvpn-devel --Ec64+lHvvb8= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, ordex, plaisthos. Hello plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/791?usp=3Demail to look at the new patch set (#22). Change subject: Reformat the whole project with clang-format ...................................................................... Reformat the whole project with clang-format Done with pre-commit run -a, so the version defined in pre-commit config is used. Change-Id: I2566ad493629e1f5fdfa6f6483b8973463404e3e Signed-off-by: Frank Lichtenheld --- M include/openvpn-msg.h M sample/sample-plugins/client-connect/sample-client-connect.c M sample/sample-plugins/defer/multi-auth.c M sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporte= r.c M sample/sample-plugins/log/log.c M sample/sample-plugins/log/log_v3.c M sample/sample-plugins/simple/base64.c M sample/sample-plugins/simple/simple.c M src/compat/compat-basename.c M src/compat/compat-dirname.c M src/compat/compat-gettimeofday.c M src/openvpn/argv.c M src/openvpn/argv.h M src/openvpn/auth_token.c M src/openvpn/auth_token.h M src/openvpn/base64.c M src/openvpn/base64.h M src/openvpn/basic.h M src/openvpn/buffer.c M src/openvpn/buffer.h M src/openvpn/circ_list.h M src/openvpn/clinat.c M src/openvpn/clinat.h M src/openvpn/common.h M src/openvpn/comp-lz4.c M src/openvpn/comp.c M src/openvpn/comp.h M src/openvpn/compstub.c M src/openvpn/console.c M src/openvpn/console.h M src/openvpn/console_builtin.c M src/openvpn/console_systemd.c M src/openvpn/crypto.c M src/openvpn/crypto.h M src/openvpn/crypto_backend.h M src/openvpn/crypto_epoch.c M src/openvpn/crypto_epoch.h M src/openvpn/crypto_mbedtls.c M src/openvpn/crypto_mbedtls.h M src/openvpn/crypto_openssl.c M src/openvpn/crypto_openssl.h M src/openvpn/cryptoapi.c M src/openvpn/dco.c M src/openvpn/dco.h M src/openvpn/dco_freebsd.c M src/openvpn/dco_freebsd.h M src/openvpn/dco_internal.h M src/openvpn/dco_linux.c M src/openvpn/dco_linux.h M src/openvpn/dco_win.c M src/openvpn/dco_win.h M src/openvpn/dhcp.c M src/openvpn/dhcp.h M src/openvpn/dns.c M src/openvpn/dns.h M src/openvpn/env_set.c M src/openvpn/env_set.h M src/openvpn/errlevel.h M src/openvpn/error.c M src/openvpn/error.h M src/openvpn/event.c M src/openvpn/event.h M src/openvpn/fdmisc.c M src/openvpn/fdmisc.h M src/openvpn/forward.c M src/openvpn/forward.h M src/openvpn/fragment.c M src/openvpn/fragment.h M src/openvpn/gremlin.c M src/openvpn/gremlin.h M src/openvpn/helper.c M src/openvpn/httpdigest.c M src/openvpn/httpdigest.h M src/openvpn/init.c M src/openvpn/init.h M src/openvpn/integer.h M src/openvpn/interval.c M src/openvpn/interval.h M src/openvpn/list.c M src/openvpn/list.h M src/openvpn/lladdr.c M src/openvpn/lzo.c M src/openvpn/lzo.h M src/openvpn/manage.c M src/openvpn/manage.h M src/openvpn/mbedtls_compat.h M src/openvpn/mbuf.c M src/openvpn/mbuf.h M src/openvpn/memdbg.h M src/openvpn/misc.c M src/openvpn/misc.h M src/openvpn/mroute.c M src/openvpn/mroute.h M src/openvpn/mss.c M src/openvpn/mss.h M src/openvpn/mstats.c M src/openvpn/mstats.h M src/openvpn/mtcp.c M src/openvpn/mtcp.h M src/openvpn/mtu.c M src/openvpn/mtu.h M src/openvpn/mudp.c M src/openvpn/multi.c M src/openvpn/multi.h M src/openvpn/multi_io.c M src/openvpn/networking.h M src/openvpn/networking_freebsd.c M src/openvpn/networking_iproute2.c M src/openvpn/networking_sitnl.c M src/openvpn/ntlm.c M src/openvpn/occ.c M src/openvpn/occ.h M src/openvpn/openssl_compat.h M src/openvpn/openvpn.c M src/openvpn/openvpn.h M src/openvpn/options.c M src/openvpn/options.h M src/openvpn/options_util.c M src/openvpn/options_util.h M src/openvpn/otime.c M src/openvpn/otime.h M src/openvpn/ovpn_dco_freebsd.h M src/openvpn/packet_id.c M src/openvpn/packet_id.h M src/openvpn/perf.c M src/openvpn/perf.h M src/openvpn/ping.c M src/openvpn/ping.h M src/openvpn/pkcs11.c M src/openvpn/pkcs11.h M src/openvpn/pkcs11_backend.h M src/openvpn/pkcs11_mbedtls.c M src/openvpn/pkcs11_openssl.c M src/openvpn/platform.c M src/openvpn/platform.h M src/openvpn/plugin.c M src/openvpn/plugin.h M src/openvpn/pool.c M src/openvpn/pool.h M src/openvpn/proto.c M src/openvpn/proto.h M src/openvpn/proxy.c M src/openvpn/proxy.h M src/openvpn/ps.c M src/openvpn/ps.h M src/openvpn/push.c M src/openvpn/push.h M src/openvpn/pushlist.h M src/openvpn/reflect_filter.c M src/openvpn/reflect_filter.h M src/openvpn/reliable.c M src/openvpn/reliable.h A src/openvpn/ring_buffer.h M src/openvpn/route.c M src/openvpn/route.h M src/openvpn/run_command.c M src/openvpn/run_command.h M src/openvpn/schedule.c M src/openvpn/schedule.h M src/openvpn/session_id.h M src/openvpn/shaper.c M src/openvpn/shaper.h M src/openvpn/sig.c M src/openvpn/sig.h M src/openvpn/socket.c M src/openvpn/socket.h M src/openvpn/socks.c M src/openvpn/socks.h M src/openvpn/ssl.c M src/openvpn/ssl.h M src/openvpn/ssl_backend.h M src/openvpn/ssl_common.h M src/openvpn/ssl_mbedtls.c M src/openvpn/ssl_mbedtls.h M src/openvpn/ssl_ncp.c M src/openvpn/ssl_ncp.h M src/openvpn/ssl_openssl.c M src/openvpn/ssl_openssl.h M src/openvpn/ssl_pkt.c M src/openvpn/ssl_pkt.h M src/openvpn/ssl_util.c M src/openvpn/ssl_util.h M src/openvpn/ssl_verify.c M src/openvpn/ssl_verify.h M src/openvpn/ssl_verify_backend.h M src/openvpn/ssl_verify_mbedtls.c M src/openvpn/ssl_verify_mbedtls.h M src/openvpn/ssl_verify_openssl.c M src/openvpn/status.c M src/openvpn/status.h M src/openvpn/syshead.h M src/openvpn/tls_crypt.c M src/openvpn/tls_crypt.h M src/openvpn/tun.c M src/openvpn/tun.h M src/openvpn/tun_afunix.c M src/openvpn/tun_afunix.h M src/openvpn/vlan.c M src/openvpn/vlan.h M src/openvpn/wfp_block.c M src/openvpn/wfp_block.h M src/openvpn/win32-util.c M src/openvpn/win32.c M src/openvpn/win32.h M src/openvpn/xkey_common.h M src/openvpn/xkey_helper.c M src/openvpn/xkey_provider.c M src/openvpnmsica/dllmain.c M src/openvpnmsica/msica_arg.c M src/openvpnmsica/msica_arg.h M src/openvpnmsica/msiex.c M src/openvpnmsica/msiex.h M src/openvpnmsica/openvpnmsica.c M src/openvpnmsica/openvpnmsica.h M src/openvpnserv/common.c M src/openvpnserv/interactive.c M src/openvpnserv/service.c M src/openvpnserv/service.h M src/openvpnserv/validate.c M src/openvpnserv/validate.h M src/plugins/auth-pam/auth-pam.c M src/plugins/auth-pam/pamdl.c M src/plugins/auth-pam/utils.c M src/plugins/auth-pam/utils.h M src/plugins/down-root/down-root.c M src/tapctl/basic.h M src/tapctl/error.h M src/tapctl/main.c M src/tapctl/tap.c M src/tapctl/tap.h M tests/ntlm_support.c M tests/unit_tests/example_test/test.c M tests/unit_tests/example_test/test2.c M tests/unit_tests/openvpn/cert_data.h M tests/unit_tests/openvpn/mock_management.c M tests/unit_tests/openvpn/mock_msg.c M tests/unit_tests/openvpn/mock_msg.h M tests/unit_tests/openvpn/mock_ssl_dependencies.c M tests/unit_tests/openvpn/pkey_test_utils.c M tests/unit_tests/openvpn/test_argv.c M tests/unit_tests/openvpn/test_auth_token.c M tests/unit_tests/openvpn/test_buffer.c M tests/unit_tests/openvpn/test_crypto.c M tests/unit_tests/openvpn/test_cryptoapi.c M tests/unit_tests/openvpn/test_misc.c M tests/unit_tests/openvpn/test_ncp.c M tests/unit_tests/openvpn/test_networking.c M tests/unit_tests/openvpn/test_packet_id.c M tests/unit_tests/openvpn/test_pkcs11.c M tests/unit_tests/openvpn/test_pkt.c M tests/unit_tests/openvpn/test_provider.c M tests/unit_tests/openvpn/test_ssl.c M tests/unit_tests/openvpn/test_tls_crypt.c M tests/unit_tests/openvpn/test_user_pass.c M tests/unit_tests/plugins/auth-pam/test_search_and_replace.c 255 files changed, 11,864 insertions(+), 15,015 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/91/791/22 diff --git a/include/openvpn-msg.h b/include/openvpn-msg.h index e0d0bb0..6e43588 100644 --- a/include/openvpn-msg.h +++ b/include/openvpn-msg.h @@ -27,7 +27,8 @@ #include #include -typedef enum { +typedef enum +{ msg_acknowledgement, msg_add_address, msg_del_address, @@ -51,28 +52,33 @@ msg_create_adapter } message_type_t; -typedef struct { +typedef struct +{ message_type_t type; size_t size; int message_id; } message_header_t; -typedef union { +typedef union +{ struct in_addr ipv4; struct in6_addr ipv6; } inet_address_t; -typedef struct { +typedef struct +{ int index; char name[256]; } interface_t; -typedef enum { - wfp_block_local =3D 1<<0, - wfp_block_dns =3D 1<<1 +typedef enum +{ + wfp_block_local =3D 1 << 0, + wfp_block_dns =3D 1 << 1 } wfp_block_flags_t; -typedef struct { +typedef struct +{ message_header_t header; short family; inet_address_t address; @@ -80,7 +86,8 @@ interface_t iface; } address_message_t; -typedef struct { +typedef struct +{ message_header_t header; short family; inet_address_t prefix; @@ -90,7 +97,8 @@ int metric; } route_message_t; -typedef struct { +typedef struct +{ message_header_t header; interface_t iface; char domains[512]; @@ -100,14 +108,16 @@ } dns_cfg_message_t; -typedef enum { +typedef enum +{ nrpt_dnssec } nrpt_flags_t; -#define NRPT_ADDR_NUM 8 /* Max. number of addresses */ +#define NRPT_ADDR_NUM 8 /* Max. number of addresses */ #define NRPT_ADDR_SIZE 48 /* Max. address strlen + some */ typedef char nrpt_address_t[NRPT_ADDR_SIZE]; -typedef struct { +typedef struct +{ message_header_t header; interface_t iface; nrpt_address_t addresses[NRPT_ADDR_NUM]; @@ -116,14 +126,16 @@ nrpt_flags_t flags; } nrpt_dns_cfg_message_t; -typedef struct { +typedef struct +{ message_header_t header; interface_t iface; int addr_len; inet_address_t addr[4]; /* support up to 4 dns addresses */ } wins_cfg_message_t; -typedef struct { +typedef struct +{ message_header_t header; interface_t iface; int disable_nbt; @@ -135,41 +147,48 @@ /* TODO: NTP */ -typedef struct { +typedef struct +{ message_header_t header; short family; interface_t iface; } flush_neighbors_message_t; =20 -typedef struct { +typedef struct +{ message_header_t header; int error_number; } ack_message_t; -typedef struct { +typedef struct +{ message_header_t header; wfp_block_flags_t flags; interface_t iface; } wfp_block_message_t; -typedef struct { +typedef struct +{ message_header_t header; interface_t iface; } enable_dhcp_message_t; -typedef struct { +typedef struct +{ message_header_t header; interface_t iface; short family; int mtu; } set_mtu_message_t; -typedef enum { +typedef enum +{ ADAPTER_TYPE_DCO, ADAPTER_TYPE_TAP, } adapter_type_t; -typedef struct { +typedef struct +{ message_header_t header; adapter_type_t adapter_type; } create_adapter_message_t; diff --git a/sample/sample-plugins/client-connect/sample-client-connect.c b= /sample/sample-plugins/client-connect/sample-client-connect.c index 18c2c6f..b180002 100644 --- a/sample/sample-plugins/client-connect/sample-client-connect.c +++ b/sample/sample-plugins/client-connect/sample-client-connect.c @@ -59,8 +59,9 @@ * Our context, where we keep our state. */ -struct plugin_context { - int verb; /* logging verbosity */ +struct plugin_context +{ + int verb; /* logging verbosity */ }; /* this is used for the CLIENT_CONNECT_V2 async/deferred handler @@ -69,8 +70,9 @@ * this, and the "CLIENT_CONNECT_DEFER_V2" handler looks at it to see * if it's time yet to succeed/fail */ -struct plugin_per_client_context { - time_t sleep_until; /* wakeup time (time() + sleep) */ +struct plugin_per_client_context +{ + time_t sleep_until; /* wakeup time (time() + sleep) */ bool want_fail; bool want_disable; const char *client_config; @@ -119,8 +121,7 @@ /* use v3 functions so we can use openvpn's logging and base64 etc. */ OPENVPN_EXPORT int -openvpn_plugin_open_v3(const int v3structver, - struct openvpn_plugin_args_open_in const *args, +openvpn_plugin_open_v3(const int v3structver, struct openvpn_plugin_args_o= pen_in const *args, struct openvpn_plugin_args_open_return *ret) { /* const char **argv =3D args->argv; */ /* command line arguments (unu= sed) */ @@ -129,7 +130,9 @@ /* Check API compatibility -- struct version 5 or higher needed */ if (v3structver < 5) { - fprintf(stderr, "sample-client-connect: this plugin is incompatibl= e with the running version of OpenVPN\n"); + fprintf( + stderr, + "sample-client-connect: this plugin is incompatible with the r= unning version of OpenVPN\n"); return OPENVPN_PLUGIN_FUNC_ERROR; } @@ -145,18 +148,17 @@ /* * Intercept just about everything... */ - ret->type_mask =3D - OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_UP) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_ROUTE_UP) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_IPCHANGE) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL); + ret->type_mask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_UP) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_ROUTE_UP) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_IPCHANGE) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V= 2) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_D= EFER_V2) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNEC= T) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL); /* Save global pointers to functions exported from openvpn */ plugin_log =3D args->callbacks->plugin_log; @@ -168,7 +170,7 @@ */ context->verb =3D atoi_null0(get_env("verb", envp)); - ret->handle =3D (openvpn_plugin_handle_t *) context; + ret->handle =3D (openvpn_plugin_handle_t *)context; plugin_log(PLOG_NOTE, MODULE, "initialization succeeded"); return OPENVPN_PLUGIN_FUNC_SUCCESS; @@ -244,8 +246,10 @@ const char *ccd_file =3D get_env("client_connect_deferred_file", envp); if (!ccd_file) { - plugin_log(PLOG_NOTE, MODULE, "env has UV_WANT_CC_ASYNC=3D%d, but " - "'client_connect_deferred_file' not set -> fail", secon= ds); + plugin_log(PLOG_NOTE, MODULE, + "env has UV_WANT_CC_ASYNC=3D%d, but " + "'client_connect_deferred_file' not set -> fail", + seconds); return OPENVPN_PLUGIN_FUNC_ERROR; } @@ -259,13 +263,13 @@ int fd =3D open(ccd_file, O_WRONLY); if (fd < 0) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "open('%s') failed", ccd_f= ile); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "open('%s') failed", ccd= _file); return OPENVPN_PLUGIN_FUNC_ERROR; } if (write(fd, "2", 1) !=3D 1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "write to '%s' failed", cc= d_file ); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "write to '%s' failed", = ccd_file); close(fd); return OPENVPN_PLUGIN_FUNC_ERROR; } @@ -279,11 +283,11 @@ /* fork, sleep, succeed/fail according to env vars */ pid_t p1 =3D fork(); - if (p1 < 0) /* Fork failed */ + if (p1 < 0) /* Fork failed */ { return OPENVPN_PLUGIN_FUNC_ERROR; } - if (p1 > 0) /* parent process */ + if (p1 > 0) /* parent process */ { waitpid(p1, NULL, 0); return OPENVPN_PLUGIN_FUNC_DEFERRED; @@ -293,10 +297,10 @@ pid_t p2 =3D fork(); if (p2 < 0) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: fork(2) faile= d"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "BACKGROUND: fork(2) fai= led"); exit(1); } - if (p2 > 0) /* new parent: exit right away */ + if (p2 > 0) /* new parent: exit right away */ { exit(0); } @@ -326,16 +330,16 @@ fd =3D open(ccd_file, O_WRONLY); if (fd < 0) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "open('%s') failed", ccd_f= ile); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "open('%s') failed", ccd= _file); exit(1); } plugin_log(PLOG_NOTE, MODULE, "cc_handle_deferred_v1: done, signalling= %s", - (ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) ? "success" : "fai= l" ); + (ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) ? "success" : "fai= l"); if (write(fd, (ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) ? "1" : "0", 1)= !=3D 1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "write to '%s' failed", cc= d_file ); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "write to '%s' failed", = ccd_file); } close(fd); @@ -343,14 +347,12 @@ } int -openvpn_plugin_client_connect(struct plugin_context *context, - const char **argv, - const char **envp) +openvpn_plugin_client_connect(struct plugin_context *context, const char *= *argv, const char **envp) { /* log environment variables handed to us by OpenVPN, but * only if "setenv verb" is 3 or higher (arbitrary number) */ - if (context->verb>=3D3) + if (context->verb >=3D 3) { for (int i =3D 0; argv[i]; i++) { @@ -391,8 +393,7 @@ int openvpn_plugin_client_connect_v2(struct plugin_context *context, - struct plugin_per_client_context *pcc, - const char **envp, + struct plugin_per_client_context *pcc, co= nst char **envp, struct openvpn_plugin_string_list **retur= n_list) { /* by setting "UV_WANT_CC2_ASYNC" we go to async/deferred mode */ @@ -422,7 +423,8 @@ pcc->want_fail =3D (want_fail !=3D NULL); pcc->want_disable =3D (want_disable !=3D NULL); pcc->client_config =3D client_config; - plugin_log(PLOG_NOTE, MODULE, "env has UV_WANT_CC2_ASYNC=3D%s -> s= et up deferred handler", want_async); + plugin_log(PLOG_NOTE, MODULE, "env has UV_WANT_CC2_ASYNC=3D%s -> s= et up deferred handler", + want_async); return OPENVPN_PLUGIN_FUNC_DEFERRED; } @@ -433,8 +435,7 @@ return OPENVPN_PLUGIN_FUNC_ERROR; } - struct openvpn_plugin_string_list *rl =3D - calloc(1, sizeof(struct openvpn_plugin_string_list)); + struct openvpn_plugin_string_list *rl =3D calloc(1, sizeof(struct open= vpn_plugin_string_list)); if (!rl) { plugin_log(PLOG_ERR, MODULE, "malloc(return_list) failed"); @@ -468,12 +469,10 @@ int openvpn_plugin_client_connect_defer_v2(struct plugin_context *context, struct plugin_per_client_context *p= cc, - struct openvpn_plugin_string_list - **return_list) + struct openvpn_plugin_string_list *= *return_list) { time_t time_left =3D pcc->sleep_until - time(NULL); - plugin_log(PLOG_NOTE, MODULE, "defer_v2: seconds left=3D%d", - (int) time_left); + plugin_log(PLOG_NOTE, MODULE, "defer_v2: seconds left=3D%d", (int)time= _left); /* not yet due? */ if (time_left > 0) @@ -484,15 +483,14 @@ /* client wants fail? */ if (pcc->want_fail) { - plugin_log(PLOG_NOTE, MODULE, "env has UV_WANT_CC2_FAIL -> fail" ); + plugin_log(PLOG_NOTE, MODULE, "env has UV_WANT_CC2_FAIL -> fail"); return OPENVPN_PLUGIN_FUNC_ERROR; } /* fill in RL according to with-disable / without-disable */ /* TODO: unify this with non-deferred case */ - struct openvpn_plugin_string_list *rl =3D - calloc(1, sizeof(struct openvpn_plugin_string_list)); + struct openvpn_plugin_string_list *rl =3D calloc(1, sizeof(struct open= vpn_plugin_string_list)); if (!rl) { plugin_log(PLOG_ERR, MODULE, "malloc(return_list) failed"); @@ -524,15 +522,12 @@ } OPENVPN_EXPORT int -openvpn_plugin_func_v2(openvpn_plugin_handle_t handle, - const int type, - const char *argv[], - const char *envp[], - void *per_client_context, +openvpn_plugin_func_v2(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], + const char *envp[], void *per_client_context, struct openvpn_plugin_string_list **return_list) { - struct plugin_context *context =3D (struct plugin_context *) handle; - struct plugin_per_client_context *pcc =3D (struct plugin_per_client_co= ntext *) per_client_context; + struct plugin_context *context =3D (struct plugin_context *)handle; + struct plugin_per_client_context *pcc =3D (struct plugin_per_client_co= ntext *)per_client_context; /* for most functions, we just "don't do anything" but log the * event received (so one can follow it in the log and understand @@ -566,13 +561,11 @@ case OPENVPN_PLUGIN_CLIENT_CONNECT_V2: plugin_log(PLOG_NOTE, MODULE, "OPENVPN_PLUGIN_CLIENT_CONNECT_V= 2"); - return openvpn_plugin_client_connect_v2(context, pcc, envp, - return_list); + return openvpn_plugin_client_connect_v2(context, pcc, envp, re= turn_list); case OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2: plugin_log(PLOG_NOTE, MODULE, "OPENVPN_PLUGIN_CLIENT_CONNECT_D= EFER_V2"); - return openvpn_plugin_client_connect_defer_v2(context, pcc, - return_list); + return openvpn_plugin_client_connect_defer_v2(context, pcc, re= turn_list); case OPENVPN_PLUGIN_CLIENT_DISCONNECT: plugin_log(PLOG_NOTE, MODULE, "OPENVPN_PLUGIN_CLIENT_DISCONNEC= T"); @@ -609,7 +602,7 @@ OPENVPN_EXPORT void openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; printf("FUNC: openvpn_plugin_close_v1\n"); free(context); } diff --git a/sample/sample-plugins/defer/multi-auth.c b/sample/sample-plugi= ns/defer/multi-auth.c index 38db07f..9f98391 100644 --- a/sample/sample-plugins/defer/multi-auth.c +++ b/sample/sample-plugins/defer/multi-auth.c @@ -63,7 +63,8 @@ * Our context, where we keep our state. */ -struct plugin_context { +struct plugin_context +{ int test_deferred_auth; char *authid; char *test_valid_user; @@ -104,11 +105,12 @@ * structver '5' here to indicate a desire for modern openvpn, rather * than a need for any particular feature found in structver beyond '1'. */ -#define OPENVPN_PLUGIN_VERSION_MIN 3 +#define OPENVPN_PLUGIN_VERSION_MIN 3 #define OPENVPN_PLUGIN_STRUCTVER_MIN 5 -struct plugin_per_client_context { +struct plugin_per_client_context +{ int n_calls; bool generated_pf_file; }; @@ -177,13 +179,13 @@ /* use v3 functions so we can use openvpn's logging and base64 etc. */ OPENVPN_EXPORT int -openvpn_plugin_open_v3(const int v3structver, - struct openvpn_plugin_args_open_in const *args, +openvpn_plugin_open_v3(const int v3structver, struct openvpn_plugin_args_o= pen_in const *args, struct openvpn_plugin_args_open_return *ret) { if (v3structver < OPENVPN_PLUGIN_STRUCTVER_MIN) { - fprintf(stderr, "%s: this plugin is incompatible with the running = version of OpenVPN\n", MODULE); + fprintf(stderr, "%s: this plugin is incompatible with the running = version of OpenVPN\n", + MODULE); return OPENVPN_PLUGIN_FUNC_ERROR; } @@ -196,7 +198,7 @@ * Allocate our context */ struct plugin_context *context =3D NULL; - context =3D (struct plugin_context *) calloc(1, sizeof(struct plugin_c= ontext)); + context =3D (struct plugin_context *)calloc(1, sizeof(struct plugin_co= ntext)); if (!context) { goto error; @@ -240,7 +242,7 @@ * Which callbacks to intercept. */ ret->type_mask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_V= ERIFY); - ret->handle =3D (openvpn_plugin_handle_t *) context; + ret->handle =3D (openvpn_plugin_handle_t *)context; plog(context, PLOG_NOTE, "initialization succeeded"); return OPENVPN_PLUGIN_FUNC_SUCCESS; @@ -255,29 +257,22 @@ } static bool -do_auth_user_pass(struct plugin_context *context, - const char *username, const char *password) +do_auth_user_pass(struct plugin_context *context, const char *username, co= nst char *password) { - plog(context, PLOG_NOTE, - "expect_user=3D%s, received_user=3D%s, expect_passw=3D%s, receive= d_passw=3D%s", - np(context->test_valid_user), - np(username), - np(context->test_valid_pass), - np(password)); + plog(context, PLOG_NOTE, "expect_user=3D%s, received_user=3D%s, expect= _passw=3D%s, received_passw=3D%s", + np(context->test_valid_user), np(username), np(context->test_vali= d_pass), np(password)); if (context->test_valid_user && context->test_valid_pass) { if ((strcmp(context->test_valid_user, username) !=3D 0) || (strcmp(context->test_valid_pass, password) !=3D 0)) { - plog(context, PLOG_ERR, - "User/Password auth result: FAIL"); + plog(context, PLOG_ERR, "User/Password auth result: FAIL"); return false; } else { - plog(context, PLOG_NOTE, - "User/Password auth result: PASS"); + plog(context, PLOG_NOTE, "User/Password auth result: PASS"); return true; } } @@ -286,8 +281,7 @@ static int -auth_user_pass_verify(struct plugin_context *context, - struct plugin_per_client_context *pcc, +auth_user_pass_verify(struct plugin_context *context, struct plugin_per_cl= ient_context *pcc, const char *argv[], const char *envp[]) { /* get username/password from envp string array */ @@ -297,8 +291,8 @@ if (!context->test_deferred_auth) { plog(context, PLOG_NOTE, "Direct authentication"); - return do_auth_user_pass(context, username, password) ? - OPENVPN_PLUGIN_FUNC_SUCCESS : OPENVPN_PLUGIN_FUNC_ERROR; + return do_auth_user_pass(context, username, password) ? OPENVPN_PL= UGIN_FUNC_SUCCESS + : OPENVPN_PL= UGIN_FUNC_ERROR; } /* get auth_control_file filename from envp string array*/ @@ -319,11 +313,11 @@ /* fork, sleep, succeed (no "real" auth done =3D always succeed) */ pid_t p1 =3D fork(); - if (p1 < 0) /* Fork failed */ + if (p1 < 0) /* Fork failed */ { return OPENVPN_PLUGIN_FUNC_ERROR; } - if (p1 > 0) /* parent process */ + if (p1 > 0) /* parent process */ { waitpid(p1, NULL, 0); return OPENVPN_PLUGIN_FUNC_DEFERRED; @@ -333,11 +327,11 @@ pid_t p2 =3D fork(); if (p2 < 0) { - plog(context, PLOG_ERR|PLOG_ERRNO, "BACKGROUND: fork(2) failed"); + plog(context, PLOG_ERR | PLOG_ERRNO, "BACKGROUND: fork(2) failed"); exit(1); } - if (p2 !=3D 0) /* new parent: exit right aw= ay */ + if (p2 !=3D 0) /* new parent: exit right away */ { exit(0); } @@ -350,15 +344,14 @@ /* do mighty complicated work that will really take time here... */ plog(context, PLOG_NOTE, "in async/deferred handler, usleep(%d)", - context->test_deferred_auth*1000); - usleep(context->test_deferred_auth*1000); + context->test_deferred_auth * 1000); + usleep(context->test_deferred_auth * 1000); /* now signal success state to openvpn */ int fd =3D open(auth_control_file, O_WRONLY); if (fd < 0) { - plog(context, PLOG_ERR|PLOG_ERRNO, - "open('%s') failed", auth_control_file); + plog(context, PLOG_ERR | PLOG_ERRNO, "open('%s') failed", auth_con= trol_file); exit(1); } @@ -370,7 +363,7 @@ if (write(fd, result, 1) !=3D 1) { - plog(context, PLOG_ERR|PLOG_ERRNO, "write to '%s' failed", auth_co= ntrol_file ); + plog(context, PLOG_ERR | PLOG_ERRNO, "write to '%s' failed", auth_= control_file); } close(fd); @@ -379,19 +372,20 @@ OPENVPN_EXPORT int -openvpn_plugin_func_v3(const int v3structver, - struct openvpn_plugin_args_func_in const *args, +openvpn_plugin_func_v3(const int v3structver, struct openvpn_plugin_args_f= unc_in const *args, struct openvpn_plugin_args_func_return *ret) { if (v3structver < OPENVPN_PLUGIN_STRUCTVER_MIN) { - fprintf(stderr, "%s: this plugin is incompatible with the running = version of OpenVPN\n", MODULE); + fprintf(stderr, "%s: this plugin is incompatible with the running = version of OpenVPN\n", + MODULE); return OPENVPN_PLUGIN_FUNC_ERROR; } const char **argv =3D args->argv; const char **envp =3D args->envp; - struct plugin_context *context =3D (struct plugin_context *) args->han= dle; - struct plugin_per_client_context *pcc =3D (struct plugin_per_client_co= ntext *) args->per_client_context; + struct plugin_context *context =3D (struct plugin_context *)args->hand= le; + struct plugin_per_client_context *pcc =3D + (struct plugin_per_client_context *)args->per_client_context; switch (args->type) { case OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY: @@ -407,7 +401,7 @@ OPENVPN_EXPORT void * openvpn_plugin_client_constructor_v1(openvpn_plugin_handle_t handle) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; plog(context, PLOG_NOTE, "FUNC: openvpn_plugin_client_constructor_v1"); return calloc(1, sizeof(struct plugin_per_client_context)); } @@ -415,7 +409,7 @@ OPENVPN_EXPORT void openvpn_plugin_client_destructor_v1(openvpn_plugin_handle_t handle, void *= per_client_context) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; plog(context, PLOG_NOTE, "FUNC: openvpn_plugin_client_destructor_v1"); free(per_client_context); } @@ -423,7 +417,7 @@ OPENVPN_EXPORT void openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; plog(context, PLOG_NOTE, "FUNC: openvpn_plugin_close_v1"); free(context); } diff --git a/sample/sample-plugins/keying-material-exporter-demo/keyingmate= rialexporter.c b/sample/sample-plugins/keying-material-exporter-demo/keying= materialexporter.c index cc256dd..137cf20 100644 --- a/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexp= orter.c +++ b/sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexp= orter.c @@ -38,22 +38,25 @@ #define MAXPATH 1024 #endif -#define ovpn_err(fmt, ...) \ - plugin->log(PLOG_ERR, "SSO", fmt, ## __VA_ARGS__) -#define ovpn_dbg(fmt, ...) \ - plugin->log(PLOG_DEBUG, "SSO", fmt, ## __VA_ARGS__) -#define ovpn_note(fmt, ...) \ - plugin->log(PLOG_NOTE, "SSO", fmt, ## __VA_ARGS__) +#define ovpn_err(fmt, ...) plugin->log(PLOG_ERR, "SSO", fmt, ##__VA_ARGS_= _) +#define ovpn_dbg(fmt, ...) plugin->log(PLOG_DEBUG, "SSO", fmt, ##__VA_ARG= S__) +#define ovpn_note(fmt, ...) plugin->log(PLOG_NOTE, "SSO", fmt, ##__VA_ARGS= __) -enum endpoint { CLIENT =3D 1, SERVER =3D 2 }; +enum endpoint +{ + CLIENT =3D 1, + SERVER =3D 2 +}; -struct plugin { +struct plugin +{ plugin_log_t log; enum endpoint type; int mask; }; -struct session { +struct session +{ char user[48]; char key[48]; }; @@ -87,8 +90,7 @@ } OPENVPN_EXPORT int -openvpn_plugin_open_v3(const int version, - struct openvpn_plugin_args_open_in const *args, +openvpn_plugin_open_v3(const int version, struct openvpn_plugin_args_open_= in const *args, struct openvpn_plugin_args_open_return *rv) { struct plugin *plugin =3D calloc(1, sizeof(*plugin)); @@ -100,9 +102,9 @@ } plugin->type =3D get_env("remote_1", args->envp) ? CLIENT : SERVER; - plugin->log =3D args->callbacks->plugin_log; + plugin->log =3D args->callbacks->plugin_log; - plugin->mask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL); + plugin->mask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL); plugin->mask |=3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY); ovpn_note("vpn endpoint type=3D%s", plugin->type =3D=3D CLIENT ? "clie= nt" : "server"); @@ -165,8 +167,8 @@ static int tls_verify(struct openvpn_plugin_args_func_in const *args) { - struct plugin *plugin =3D (struct plugin *)args->handle; - struct session *sess =3D (struct session *)args->per_client_context; + struct plugin *plugin =3D (struct plugin *)args->handle; + struct session *sess =3D (struct session *)args->per_client_context; /* we store cert subject for the server end point only */ if (plugin->type !=3D SERVER) @@ -201,8 +203,8 @@ static void server_store(struct openvpn_plugin_args_func_in const *args) { - struct plugin *plugin =3D (struct plugin *)args->handle; - struct session *sess =3D (struct session *)args->per_client_context; + struct plugin *plugin =3D (struct plugin *)args->handle; + struct session *sess =3D (struct session *)args->per_client_context; char file[MAXPATH]; snprintf(file, sizeof(file) - 1, "/tmp/openvpn_sso_%s", sess->key); @@ -213,8 +215,8 @@ static void client_store(struct openvpn_plugin_args_func_in const *args) { - struct plugin *plugin =3D (struct plugin *)args->handle; - struct session *sess =3D (struct session *)args->per_client_context; + struct plugin *plugin =3D (struct plugin *)args->handle; + struct session *sess =3D (struct session *)args->per_client_context; char *file =3D "/tmp/openvpn_sso_user"; ovpn_note("app session file: %s", file); @@ -225,8 +227,8 @@ tls_final(struct openvpn_plugin_args_func_in const *args, struct openvpn_plugin_args_func_return *rv) { - struct plugin *plugin =3D (struct plugin *)args->handle; - struct session *sess =3D (struct session *)args->per_client_context; + struct plugin *plugin =3D (struct plugin *)args->handle; + struct session *sess =3D (struct session *)args->per_client_context; const char *key; if (!(key =3D get_env("exported_keying_material", args->envp))) @@ -253,8 +255,7 @@ } OPENVPN_EXPORT int -openvpn_plugin_func_v3(const int version, - struct openvpn_plugin_args_func_in const *args, +openvpn_plugin_func_v3(const int version, struct openvpn_plugin_args_func_= in const *args, struct openvpn_plugin_args_func_return *rv) { switch (args->type) @@ -272,7 +273,7 @@ openvpn_plugin_client_constructor_v1(openvpn_plugin_handle_t handle) { struct plugin *plugin =3D (struct plugin *)handle; - struct session *sess =3D calloc(1, sizeof(*sess)); + struct session *sess =3D calloc(1, sizeof(*sess)); ovpn_note("app session created"); @@ -283,7 +284,7 @@ openvpn_plugin_client_destructor_v1(openvpn_plugin_handle_t handle, void *= ctx) { struct plugin *plugin =3D (struct plugin *)handle; - struct session *sess =3D (struct session *)ctx; + struct session *sess =3D (struct session *)ctx; ovpn_note("app session key: %s", sess->key); ovpn_note("app session destroyed"); diff --git a/sample/sample-plugins/log/log.c b/sample/sample-plugins/log/lo= g.c index 82595cf..0a96c63 100644 --- a/sample/sample-plugins/log/log.c +++ b/sample/sample-plugins/log/log.c @@ -37,7 +37,8 @@ /* * Our context, where we keep our state. */ -struct plugin_context { +struct plugin_context +{ const char *username; const char *password; }; @@ -77,7 +78,7 @@ /* * Allocate our context */ - context =3D (struct plugin_context *) calloc(1, sizeof(struct plugin_c= ontext)); + context =3D (struct plugin_context *)calloc(1, sizeof(struct plugin_co= ntext)); if (context =3D=3D NULL) { printf("PLUGIN: allocating memory for context failed\n"); @@ -93,19 +94,17 @@ /* * Which callbacks to intercept. */ - *type_mask =3D - OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_UP) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_ROUTE_UP) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_IPCHANGE) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL); + *type_mask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_UP) | OPENVPN_PLUGIN= _MASK(OPENVPN_PLUGIN_DOWN) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_ROUTE_UP) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_IPCHANGE) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_VERIF= Y) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL); - return (openvpn_plugin_handle_t) context; + return (openvpn_plugin_handle_t)context; } void @@ -173,9 +172,10 @@ } OPENVPN_EXPORT int -openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], const char *envp[]) +openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], + const char *envp[]) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; show(type, argv, envp); @@ -186,8 +186,8 @@ const char *username =3D get_env("username", envp); const char *password =3D get_env("password", envp); - if (username && !strcmp(username, context->username) - && password && !strcmp(password, context->password)) + if (username && !strcmp(username, context->username) && password + && !strcmp(password, context->password)) { return OPENVPN_PLUGIN_FUNC_SUCCESS; } @@ -205,6 +205,6 @@ OPENVPN_EXPORT void openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; free(context); } diff --git a/sample/sample-plugins/log/log_v3.c b/sample/sample-plugins/log= /log_v3.c index c90cc3d..7da49c7 100644 --- a/sample/sample-plugins/log/log_v3.c +++ b/sample/sample-plugins/log/log_v3.c @@ -40,7 +40,8 @@ /* * Our context, where we keep our state. */ -struct plugin_context { +struct plugin_context +{ const char *username; const char *password; }; @@ -73,8 +74,7 @@ } OPENVPN_EXPORT int -openvpn_plugin_open_v3(const int v3structver, - struct openvpn_plugin_args_open_in const *args, +openvpn_plugin_open_v3(const int v3structver, struct openvpn_plugin_args_o= pen_in const *args, struct openvpn_plugin_args_open_return *ret) { struct plugin_context *context =3D NULL; @@ -82,7 +82,8 @@ /* Check that we are API compatible */ if (v3structver !=3D OPENVPN_PLUGINv3_STRUCTVER) { - printf("log_v3: ** ERROR ** Incompatible plug-in interface between= this plug-in and OpenVPN\n"); + printf( + "log_v3: ** ERROR ** Incompatible plug-in interface between th= is plug-in and OpenVPN\n"); return OPENVPN_PLUGIN_FUNC_ERROR; } @@ -93,26 +94,24 @@ } /* Print some version information about the OpenVPN process using this= plug-in */ - printf("log_v3: OpenVPN %s (Major: %i, Minor: %i, Patch: %s)\n", - args->ovpn_version, args->ovpn_version_major, - args->ovpn_version_minor, args->ovpn_version_patch); + printf("log_v3: OpenVPN %s (Major: %i, Minor: %i, Patch: %s)\n", args= ->ovpn_version, + args->ovpn_version_major, args->ovpn_version_minor, args->ovpn_= version_patch); /* Which callbacks to intercept. */ - ret->type_mask =3D - OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_UP) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_ROUTE_UP) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_IPCHANGE) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL); + ret->type_mask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_UP) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_ROUTE_UP) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_IPCHANGE) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_V= ERIFY) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V= 2) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNEC= T) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL); =20 /* Allocate our context */ - context =3D (struct plugin_context *) calloc(1, sizeof(struct plugin_c= ontext)); + context =3D (struct plugin_context *)calloc(1, sizeof(struct plugin_co= ntext)); if (context =3D=3D NULL) { printf("PLUGIN: allocating memory for context failed\n"); @@ -124,7 +123,7 @@ context->password =3D "bar"; /* Point the global context handle to our newly created context */ - ret->handle =3D (void *) context; + ret->handle =3D (void *)context; return OPENVPN_PLUGIN_FUNC_SUCCESS; } @@ -245,13 +244,11 @@ } - OPENVPN_EXPORT int -openvpn_plugin_func_v3(const int version, - struct openvpn_plugin_args_func_in const *args, +openvpn_plugin_func_v3(const int version, struct openvpn_plugin_args_func_= in const *args, struct openvpn_plugin_args_func_return *retptr) { - struct plugin_context *context =3D (struct plugin_context *) args->han= dle; + struct plugin_context *context =3D (struct plugin_context *)args->hand= le; printf("\nopenvpn_plugin_func_v3() :::::>> "); show(args->type, args->argv, args->envp); @@ -272,8 +269,8 @@ const char *username =3D get_env("username", args->envp); const char *password =3D get_env("password", args->envp); - if (username && !strcmp(username, context->username) - && password && !strcmp(password, context->password)) + if (username && !strcmp(username, context->username) && password + && !strcmp(password, context->password)) { return OPENVPN_PLUGIN_FUNC_SUCCESS; } @@ -291,6 +288,6 @@ OPENVPN_EXPORT void openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; free(context); } diff --git a/sample/sample-plugins/simple/base64.c b/sample/sample-plugins/= simple/base64.c index 6855966..5b2cff5 100644 --- a/sample/sample-plugins/simple/base64.c +++ b/sample/sample-plugins/simple/base64.c @@ -100,21 +100,20 @@ * */ OPENVPN_EXPORT int -openvpn_plugin_open_v3(const int v3structver, - struct openvpn_plugin_args_open_in const *args, +openvpn_plugin_open_v3(const int v3structver, struct openvpn_plugin_args_o= pen_in const *args, struct openvpn_plugin_args_open_return *ret) { /* Check that we are API compatible */ if (v3structver !=3D OPENVPN_PLUGINv3_STRUCTVER) { - printf("base64.c: ** ERROR ** Incompatible plug-in interface betwe= en this plug-in and OpenVPN\n"); + printf( + "base64.c: ** ERROR ** Incompatible plug-in interface between = this plug-in and OpenVPN\n"); return OPENVPN_PLUGIN_FUNC_ERROR; } /* Which callbacks to intercept. */ - ret->type_mask =3D - OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY) - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2); + ret->type_mask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY) + | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V= 2); /* we don't need a plug-in context in this example, but OpenVPN expect= s "something" */ ret->handle =3D calloc(1, 1); @@ -127,8 +126,8 @@ /* Print some version information about the OpenVPN process using this= plug-in */ ovpn_log(PLOG_NOTE, PLUGIN_NAME, "OpenVPN %s (Major: %i, Minor: %i, P= atch: %s)\n", - args->ovpn_version, args->ovpn_version_major, - args->ovpn_version_minor, args->ovpn_version_patch); + args->ovpn_version, args->ovpn_version_major, args->ovpn_vers= ion_minor, + args->ovpn_version_patch); return OPENVPN_PLUGIN_FUNC_SUCCESS; } @@ -156,10 +155,10 @@ */ OPENVPN_EXPORT int -openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], const char *envp[]) +openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], + const char *envp[]) { - if (type !=3D OPENVPN_PLUGIN_TLS_VERIFY - && type !=3D OPENVPN_PLUGIN_CLIENT_CONNECT_V2) + if (type !=3D OPENVPN_PLUGIN_TLS_VERIFY && type !=3D OPENVPN_PLUGIN_CL= IENT_CONNECT_V2) { ovpn_log(PLOG_ERR, PLUGIN_NAME, "Unsupported plug-in hook call att= empted"); return OPENVPN_PLUGIN_FUNC_ERROR; @@ -176,14 +175,13 @@ /* test the BASE64 encode function */ char *buf =3D NULL; int r =3D ovpn_base64_encode(clcert_cn, strlen(clcert_cn), &buf); - ovpn_log(PLOG_NOTE, PLUGIN_NAME, "BASE64 encoded '%s' (return value %i= ): '%s'", - clcert_cn, r, buf); + ovpn_log(PLOG_NOTE, PLUGIN_NAME, "BASE64 encoded '%s' (return value %i= ): '%s'", clcert_cn, r, + buf); /* test the BASE64 decode function */ - char buf2[256] =3D {0}; + char buf2[256] =3D { 0 }; r =3D ovpn_base64_decode(buf, &buf2, 255); - ovpn_log(PLOG_NOTE, PLUGIN_NAME, "BASE64 decoded '%s' (return value %i= ): '%s'", - buf, r, buf2); + ovpn_log(PLOG_NOTE, PLUGIN_NAME, "BASE64 decoded '%s' (return value %i= ): '%s'", buf, r, buf2); /* Verify the result, and free the buffer allocated by ovpn_base64_enc= ode() */ r =3D strcmp(clcert_cn, buf2); @@ -203,6 +201,6 @@ OPENVPN_EXPORT void openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; free(context); } diff --git a/sample/sample-plugins/simple/simple.c b/sample/sample-plugins/= simple/simple.c index e17f3fa..2666e2f 100644 --- a/sample/sample-plugins/simple/simple.c +++ b/sample/sample-plugins/simple/simple.c @@ -39,7 +39,8 @@ /* * Our context, where we keep our state. */ -struct plugin_context { +struct plugin_context +{ const char *username; const char *password; }; @@ -79,7 +80,7 @@ /* * Allocate our context */ - context =3D (struct plugin_context *) calloc(1, sizeof(struct plugin_c= ontext)); + context =3D (struct plugin_context *)calloc(1, sizeof(struct plugin_co= ntext)); if (context =3D=3D NULL) { printf("PLUGIN: allocating memory for context failed\n"); @@ -98,21 +99,22 @@ */ *type_mask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_VERIF= Y); - return (openvpn_plugin_handle_t) context; + return (openvpn_plugin_handle_t)context; } OPENVPN_EXPORT int -openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], const char *envp[]) +openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], + const char *envp[]) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; /* get username/password from envp string array */ const char *username =3D get_env("username", envp); const char *password =3D get_env("password", envp); /* check entered username/password against what we require */ - if (username && !strcmp(username, context->username) - && password && !strcmp(password, context->password)) + if (username && !strcmp(username, context->username) && password + && !strcmp(password, context->password)) { return OPENVPN_PLUGIN_FUNC_SUCCESS; } @@ -125,6 +127,6 @@ OPENVPN_EXPORT void openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) { - struct plugin_context *context =3D (struct plugin_context *) handle; + struct plugin_context *context =3D (struct plugin_context *)handle; free(context); } diff --git a/src/compat/compat-basename.c b/src/compat/compat-basename.c index abb4f49..ea8bfbb 100644 --- a/src/compat/compat-basename.c +++ b/src/compat/compat-basename.c @@ -42,7 +42,7 @@ /* If NULL, check for \ instead ... might be Windows a path */ p =3D strrchr(filename, '\\'); } - return p ? p + 1 : (char *) filename; + return p ? p + 1 : (char *)filename; } #endif /* HAVE_BASENAME */ diff --git a/src/compat/compat-dirname.c b/src/compat/compat-dirname.c index c131dee..527f252 100644 --- a/src/compat/compat-dirname.c +++ b/src/compat/compat-dirname.c @@ -90,7 +90,7 @@ /* The '/' is the last character, we have to look further. */ if (runp !=3D path) { - last_slash =3D (char *) __memrchr(path, separator, runp - path= ); + last_slash =3D (char *)__memrchr(path, separator, runp - path); } } @@ -135,7 +135,7 @@ /* This assignment is ill-designed but the XPG specs require to * return a string containing "." in any case no directory part is * found and so a static and constant string is required. */ - path =3D (char *) dot; + path =3D (char *)dot; } return path; diff --git a/src/compat/compat-gettimeofday.c b/src/compat/compat-gettimeof= day.c index 997f360..23b5734 100644 --- a/src/compat/compat-gettimeofday.c +++ b/src/compat/compat-gettimeofday.c @@ -49,7 +49,7 @@ { const time_t t =3D time(NULL); const DWORD gtc =3D GetTickCount(); - gtc_base =3D t - gtc/1000; + gtc_base =3D t - gtc / 1000; gtc_last =3D gtc; } =20 @@ -113,7 +113,7 @@ return 0; } -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ #include diff --git a/src/openvpn/argv.c b/src/openvpn/argv.c index 95215c0..78d37c7 100644 --- a/src/openvpn/argv.c +++ b/src/openvpn/argv.c @@ -285,8 +285,7 @@ * free()d to avoid memory leaks. */ static char * -argv_prep_format(const char *format, const char delim, size_t *count, - struct gc_arena *gc) +argv_prep_format(const char *format, const char delim, size_t *count, stru= ct gc_arena *gc) { if (format =3D=3D NULL) { @@ -312,7 +311,7 @@ * the string is empty; the resulting format string * will never start with a delimiter. */ - if (j > 0) /* Has anything been written to the output string?= */ + if (j > 0) /* Has anything been written to the output string? = */ { f[j++] =3D delim; } @@ -348,7 +347,7 @@ static bool argv_printf_arglist(struct argv *argres, const char *format, va_list argli= st) { - const char delim =3D 0x1D; /* ASCII Group Separator (GS) */ + const char delim =3D 0x1D; /* ASCII Group Separator (GS) */ bool res =3D false; /* @@ -485,8 +484,8 @@ argv_reset(argres); char *parms[MAX_PARMS + 1] =3D { 0 }; - int nparms =3D parse_line(cmdstr, parms, MAX_PARMS, "SCRIPT-ARGV", 0, - D_ARGV_PARSE_CMD, &argres->gc); + int nparms =3D + parse_line(cmdstr, parms, MAX_PARMS, "SCRIPT-ARGV", 0, D_ARGV_PARS= E_CMD, &argres->gc); if (nparms) { int i; diff --git a/src/openvpn/argv.h b/src/openvpn/argv.h index 098a1cb..9aaa55b 100644 --- a/src/openvpn/argv.h +++ b/src/openvpn/argv.h @@ -32,7 +32,8 @@ #include "buffer.h" -struct argv { +struct argv +{ struct gc_arena gc; size_t capacity; size_t argc; @@ -56,21 +57,21 @@ bool argv_printf(struct argv *a, const char *format, ...) #ifdef __GNUC__ #if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 2, 3))) + __attribute__((format(gnu_printf, 2, 3))) #else -__attribute__ ((format(__printf__, 2, 3))) + __attribute__((format(__printf__, 2, 3))) #endif #endif -; + ; bool argv_printf_cat(struct argv *a, const char *format, ...) #ifdef __GNUC__ #if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 2, 3))) + __attribute__((format(gnu_printf, 2, 3))) #else -__attribute__ ((format(__printf__, 2, 3))) + __attribute__((format(__printf__, 2, 3))) #endif #endif -; + ; #endif /* ifndef ARGV_H */ diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c index 3cf55e8..a694e81 100644 --- a/src/openvpn/auth_token.c +++ b/src/openvpn/auth_token.c @@ -18,7 +18,7 @@ const char *auth_token_pem_name =3D "OpenVPN auth-token server key"; -#define AUTH_TOKEN_SESSION_ID_LEN 12 +#define AUTH_TOKEN_SESSION_ID_LEN 12 #define AUTH_TOKEN_SESSION_ID_BASE64_LEN (AUTH_TOKEN_SESSION_ID_LEN * 8 / = 6) #if AUTH_TOKEN_SESSION_ID_LEN % 3 @@ -53,7 +53,7 @@ } else if (auth_token_state_flags & AUTH_TOKEN_HMAC_OK) { - switch (auth_token_state_flags & (AUTH_TOKEN_VALID_EMPTYUSER|AUTH_= TOKEN_EXPIRED)) + switch (auth_token_state_flags & (AUTH_TOKEN_VALID_EMPTYUSER | AUT= H_TOKEN_EXPIRED)) { case 0: state =3D "Authenticated"; @@ -107,9 +107,9 @@ * in the encoding */ - char session_id[AUTH_TOKEN_SESSION_ID_LEN*2] =3D {0}; + char session_id[AUTH_TOKEN_SESSION_ID_LEN * 2] =3D { 0 }; memcpy(session_id, session_id_source + strlen(SESSION_ID_PREFIX), - AUTH_TOKEN_SESSION_ID_LEN*8/6); + AUTH_TOKEN_SESSION_ID_LEN * 8 / 6); setenv_str(session->opt->es, "session_id", session_id); } @@ -121,8 +121,7 @@ } void -auth_token_init_secret(struct key_ctx *key_ctx, const char *key_file, - bool key_inline) +auth_token_init_secret(struct key_ctx *key_ctx, const char *key_file, bool= key_inline) { struct key_type kt =3D auth_token_kt(); @@ -131,14 +130,12 @@ bool key_loaded =3D false; if (key_file) { - key_loaded =3D read_pem_key_file(&server_secret_key, - auth_token_pem_name, - key_file, key_inline); + key_loaded =3D + read_pem_key_file(&server_secret_key, auth_token_pem_name, key= _file, key_inline); } else { - key_loaded =3D generate_ephemeral_key(&server_secret_key, - auth_token_pem_name); + key_loaded =3D generate_ephemeral_key(&server_secret_key, auth_tok= en_pem_name); } if (!key_loaded) @@ -169,7 +166,7 @@ int64_t initial_timestamp =3D timestamp; hmac_ctx_t *ctx =3D multi->opt.auth_token_key.hmac; - ASSERT(hmac_ctx_size(ctx) =3D=3D 256/8); + ASSERT(hmac_ctx_size(ctx) =3D=3D 256 / 8); uint8_t sessid[AUTH_TOKEN_SESSION_ID_LEN]; @@ -185,7 +182,7 @@ char *initial_token_copy =3D string_alloc(multi->auth_token_initia= l, &gc); char *old_sessid =3D initial_token_copy + strlen(SESSION_ID_PREFIX= ); - char *old_tstamp_initial =3D old_sessid + AUTH_TOKEN_SESSION_ID_LE= N*8/6; + char *old_tstamp_initial =3D old_sessid + AUTH_TOKEN_SESSION_ID_LE= N * 8 / 6; /* * We null terminate the old token just after the session ID to let @@ -197,12 +194,13 @@ memcpy(&initial_timestamp, &old_tstamp_decode, sizeof(initial_time= stamp)); old_tstamp_initial[0] =3D '\0'; - ASSERT(openvpn_base64_decode(old_sessid, sessid, AUTH_TOKEN_SESSIO= N_ID_LEN) =3D=3D AUTH_TOKEN_SESSION_ID_LEN); + ASSERT(openvpn_base64_decode(old_sessid, sessid, AUTH_TOKEN_SESSIO= N_ID_LEN) + =3D=3D AUTH_TOKEN_SESSION_ID_LEN); } else if (!rand_bytes(sessid, AUTH_TOKEN_SESSION_ID_LEN)) { - msg( M_FATAL, "Failed to get enough randomness for " - "authentication token"); + msg(M_FATAL, "Failed to get enough randomness for " + "authentication token"); } /* Calculate the HMAC */ @@ -210,7 +208,7 @@ * with \0 in them is asking for troubles in so many ways anyway that = we * ignore that corner case here */ - uint8_t hmac_output[256/8]; + uint8_t hmac_output[256 / 8]; =20 hmac_ctx_reset(ctx); @@ -222,20 +220,20 @@ struct key_state *ks =3D &multi->session[TM_ACTIVE].key[KS_PRIMARY]; if (ks->auth_token_state_flags & AUTH_TOKEN_VALID_EMPTYUSER) { - hmac_ctx_update(ctx, (const uint8_t *) "", 0); + hmac_ctx_update(ctx, (const uint8_t *)"", 0); } else { - hmac_ctx_update(ctx, (uint8_t *) up->username, (int) strlen(up->us= ername)); + hmac_ctx_update(ctx, (uint8_t *)up->username, (int)strlen(up->user= name)); } hmac_ctx_update(ctx, sessid, AUTH_TOKEN_SESSION_ID_LEN); - hmac_ctx_update(ctx, (uint8_t *) &initial_timestamp, sizeof(initial_ti= mestamp)); - hmac_ctx_update(ctx, (uint8_t *) ×tamp, sizeof(timestamp)); + hmac_ctx_update(ctx, (uint8_t *)&initial_timestamp, sizeof(initial_tim= estamp)); + hmac_ctx_update(ctx, (uint8_t *)×tamp, sizeof(timestamp)); hmac_ctx_final(ctx, hmac_output); /* Construct the unencoded session token */ - struct buffer token =3D alloc_buf_gc( - 2*sizeof(uint64_t) + AUTH_TOKEN_SESSION_ID_LEN + 256/8, &gc); + struct buffer token =3D + alloc_buf_gc(2 * sizeof(uint64_t) + AUTH_TOKEN_SESSION_ID_LEN + 25= 6 / 8, &gc); ASSERT(buf_write(&token, sessid, sizeof(sessid))); ASSERT(buf_write(&token, &initial_timestamp, sizeof(initial_timestamp)= )); @@ -245,8 +243,8 @@ char *b64output =3D NULL; openvpn_base64_encode(BPTR(&token), BLEN(&token), &b64output); - struct buffer session_token =3D alloc_buf_gc( - strlen(SESSION_ID_PREFIX) + strlen(b64output) + 1, &gc); + struct buffer session_token =3D + alloc_buf_gc(strlen(SESSION_ID_PREFIX) + strlen(b64output) + 1, &g= c); ASSERT(buf_write(&session_token, SESSION_ID_PREFIX, strlen(SESSION_ID_= PREFIX))); ASSERT(buf_write(&session_token, b64output, (int)strlen(b64output))); @@ -258,8 +256,7 @@ free(multi->auth_token); multi->auth_token =3D strdup((char *)BPTR(&session_token)); - dmsg(D_SHOW_KEYS, "Generated token for client: %s (%s)", - multi->auth_token, up->username); + dmsg(D_SHOW_KEYS, "Generated token for client: %s (%s)", multi->auth_t= oken, up->username); if (!multi->auth_token_initial) { @@ -277,22 +274,21 @@ static bool check_hmac_token(hmac_ctx_t *ctx, const uint8_t *b64decoded, const char *u= sername) { - ASSERT(hmac_ctx_size(ctx) =3D=3D 256/8); + ASSERT(hmac_ctx_size(ctx) =3D=3D 256 / 8); - uint8_t hmac_output[256/8]; + uint8_t hmac_output[256 / 8]; hmac_ctx_reset(ctx); - hmac_ctx_update(ctx, (uint8_t *) username, (int)strlen(username)); - hmac_ctx_update(ctx, b64decoded, TOKEN_DATA_LEN - 256/8); + hmac_ctx_update(ctx, (uint8_t *)username, (int)strlen(username)); + hmac_ctx_update(ctx, b64decoded, TOKEN_DATA_LEN - 256 / 8); hmac_ctx_final(ctx, hmac_output); - const uint8_t *hmac =3D b64decoded + TOKEN_DATA_LEN - 256/8; + const uint8_t *hmac =3D b64decoded + TOKEN_DATA_LEN - 256 / 8; return memcmp_constant_time(&hmac_output, hmac, 32) =3D=3D 0; } unsigned int -verify_auth_token(struct user_pass *up, struct tls_multi *multi, - struct tls_session *session) +verify_auth_token(struct user_pass *up, struct tls_multi *multi, struct tl= s_session *session) { /* * Base64 is <=3D input and input is < USER_PASS_LEN, so using USER_PA= SS_LEN @@ -300,8 +296,8 @@ */ ASSERT(up && !up->protected); uint8_t b64decoded[USER_PASS_LEN]; - int decoded_len =3D openvpn_base64_decode(up->password + strlen(SESSIO= N_ID_PREFIX), - b64decoded, USER_PASS_LEN); + int decoded_len =3D + openvpn_base64_decode(up->password + strlen(SESSION_ID_PREFIX), b6= 4decoded, USER_PASS_LEN); /* * Ensure that the decoded data is the size of the @@ -309,8 +305,7 @@ */ if (decoded_len !=3D TOKEN_DATA_LEN) { - msg(M_WARN, "ERROR: --auth-token wrong size (%d!=3D%d)", - decoded_len, (int) TOKEN_DATA_LEN); + msg(M_WARN, "ERROR: --auth-token wrong size (%d!=3D%d)", decoded_l= en, (int)TOKEN_DATA_LEN); return 0; } @@ -343,15 +338,14 @@ } else { - msg(M_WARN, "--auth-gen-token: HMAC on token from client failed (%= s)", - up->username); + msg(M_WARN, "--auth-gen-token: HMAC on token from client failed (%= s)", up->username); return 0; } /* Accept session tokens only if their timestamp is in the acceptable = range * for renegotiations */ - bool in_renegotiation_time =3D now >=3D timestamp - && now < timestamp + 2 * session->opt->au= th_token_renewal; + bool in_renegotiation_time =3D + now >=3D timestamp && now < timestamp + 2 * session->opt->auth_tok= en_renewal; if (!in_renegotiation_time) { @@ -363,14 +357,14 @@ /* Sanity check the initial timestamp */ if (timestamp < timestamp_initial) { - msg(M_WARN, "Initial timestamp (%" PRIu64 ") in token from client = earlier than " + msg(M_WARN, + "Initial timestamp (%" PRIu64 ") in token from client earlier = than " "current timestamp %" PRIu64 ". Broken/unsynchronised clock?", timestamp_initial, timestamp); ret |=3D AUTH_TOKEN_EXPIRED; } - if (multi->opt.auth_token_lifetime - && now > timestamp_initial + multi->opt.auth_token_lifetime) + if (multi->opt.auth_token_lifetime && now > timestamp_initial + multi-= >opt.auth_token_lifetime) { ret |=3D AUTH_TOKEN_EXPIRED; } @@ -391,7 +385,7 @@ strlen(SESSION_ID_PREFIX) + AUTH_TOKEN_SES= SION_ID_BASE64_LEN)) { msg(M_WARN, "--auth-gen-token: session id in token changed (Reject= ing " - "token."); + "token."); ret =3D 0; } return ret; @@ -409,8 +403,7 @@ } if (multi->auth_token_initial) { - secure_memzero(multi->auth_token_initial, - strlen(multi->auth_token_initial)); + secure_memzero(multi->auth_token_initial, strlen(multi->auth_t= oken_initial)); free(multi->auth_token_initial); } multi->auth_token =3D NULL; @@ -438,7 +431,7 @@ if (!multi->auth_token_initial) { msg(D_SHOW_KEYS, "initial auth-token not generated yet, skipping " - "auth-token renewal."); + "auth-token renewal."); return; } diff --git a/src/openvpn/auth_token.h b/src/openvpn/auth_token.h index 5859905..f127127 100644 --- a/src/openvpn/auth_token.h +++ b/src/openvpn/auth_token.h @@ -59,27 +59,22 @@ * This function will free() an existing multi->auth_token and keep the * existing initial timestamp and session id contained in that token. */ -void -generate_auth_token(const struct user_pass *up, struct tls_multi *multi); +void generate_auth_token(const struct user_pass *up, struct tls_multi *mul= ti); /** * Verifies the auth token to be in the format that generate_auth_token * create and checks if the token is valid. * */ -unsigned -verify_auth_token(struct user_pass *up, struct tls_multi *multi, - struct tls_session *session); - +unsigned verify_auth_token(struct user_pass *up, struct tls_multi *multi, + struct tls_session *session); /** * Loads an HMAC secret from a file or if no file is present generates a * epheremal secret for the run time of the server and stores it into ctx */ -void -auth_token_init_secret(struct key_ctx *key_ctx, const char *key_file, - bool key_inline); +void auth_token_init_secret(struct key_ctx *key_ctx, const char *key_file,= bool key_inline); /** @@ -126,8 +121,7 @@ static inline bool is_auth_token(const char *password) { - return (memcmp_constant_time(SESSION_ID_PREFIX, password, - strlen(SESSION_ID_PREFIX)) =3D=3D 0); + return (memcmp_constant_time(SESSION_ID_PREFIX, password, strlen(SESSI= ON_ID_PREFIX)) =3D=3D 0); } /** * Checks if a client should be sent a new auth token to update its @@ -135,15 +129,13 @@ * @param multi Pointer the multi object of the TLS session * @param session Pointer to the TLS session itself */ -void -resend_auth_token_renegotiation(struct tls_multi *multi, struct tls_sessio= n *session); +void resend_auth_token_renegotiation(struct tls_multi *multi, struct tls_s= ession *session); /** * Checks if the timer to resend the auth-token has expired and if a new * auth-token should be send to the client and triggers the resending */ -void -check_send_auth_token(struct context *c); +void check_send_auth_token(struct context *c); #endif /* AUTH_TOKEN_H */ diff --git a/src/openvpn/base64.c b/src/openvpn/base64.c index a9c2f4c..54d5b79 100644 --- a/src/openvpn/base64.c +++ b/src/openvpn/base64.c @@ -41,8 +41,7 @@ #include "memdbg.h" -static char base64_chars[] =3D - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static char base64_chars[] =3D "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop= qrstuvwxyz0123456789+/"; /* * base64 encode input data of length size to malloced * buffer which is returned as *str. Returns string @@ -60,14 +59,14 @@ { return -1; } - p =3D s =3D (char *) malloc(size * 4 / 3 + 4); + p =3D s =3D (char *)malloc(size * 4 / 3 + 4); if (p =3D=3D NULL) { return -1; } - q =3D (const unsigned char *) data; + q =3D (const unsigned char *)data; i =3D 0; - for (i =3D 0; i < size; ) + for (i =3D 0; i < size;) { c =3D q[i++]; c *=3D 256; @@ -196,5 +195,5 @@ *q++ =3D val & 0xff; } } - return q - (unsigned char *) data; + return q - (unsigned char *)data; } diff --git a/src/openvpn/base64.h b/src/openvpn/base64.h index 7b4224a..be7aa64 100644 --- a/src/openvpn/base64.h +++ b/src/openvpn/base64.h @@ -35,12 +35,10 @@ #define _BASE64_H_ /** Compute resulting base64 length. 6 bits per byte, padded to 4 bytes. = */ -#define OPENVPN_BASE64_LENGTH(binary_length) \ - ((((8 * binary_length) / 6) + 3) & ~3) +#define OPENVPN_BASE64_LENGTH(binary_length) ((((8 * binary_length) / 6) += 3) & ~3) /** Compute the maximal number of bytes encoded in a base64 string. */ -#define OPENVPN_BASE64_DECODED_LENGTH(base64_length) \ - ((base64_length / 4) * 3) +#define OPENVPN_BASE64_DECODED_LENGTH(base64_length) ((base64_length / 4) = * 3) int openvpn_base64_encode(const void *data, int size, char **str); diff --git a/src/openvpn/basic.h b/src/openvpn/basic.h index f603ecc..0360803 100644 --- a/src/openvpn/basic.h +++ b/src/openvpn/basic.h @@ -27,7 +27,7 @@ #define BOOL_CAST(x) ((x) ? (true) : (false)) /* size of an array */ -#define SIZE(x) (sizeof(x)/sizeof(x[0])) +#define SIZE(x) (sizeof(x) / sizeof(x[0])) /* clear an object (may be optimized away, use secure_memzero() to erase s= ecrets) */ #define CLEAR(x) memset(&(x), 0, sizeof(x)) diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index dd6044b..1a7e305 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -41,12 +41,14 @@ array_mult_safe(const size_t m1, const size_t m2, const size_t extra) { const size_t limit =3D 0xFFFFFFFF; - unsigned long long res =3D (unsigned long long)m1 * (unsigned long lon= g)m2 + (unsigned long long)extra; - if (unlikely(m1 > limit) || unlikely(m2 > limit) || unlikely(extra > l= imit) || unlikely(res > (unsigned long long)limit)) + unsigned long long res =3D + (unsigned long long)m1 * (unsigned long long)m2 + (unsigned long l= ong)extra; + if (unlikely(m1 > limit) || unlikely(m2 > limit) || unlikely(extra > l= imit) + || unlikely(res > (unsigned long long)limit)) { msg(M_FATAL, "attempted allocation of excessively large array"); } - return (size_t) res; + return (size_t)res; } void @@ -97,9 +99,9 @@ buf.offset =3D 0; buf.len =3D 0; #ifdef DMALLOC - buf.data =3D (uint8_t *) gc_malloc_debug(size, false, gc, file, line); + buf.data =3D (uint8_t *)gc_malloc_debug(size, false, gc, file, line); #else - buf.data =3D (uint8_t *) gc_malloc(size, false, gc); + buf.data =3D (uint8_t *)gc_malloc(size, false, gc); #endif if (size) { @@ -120,9 +122,9 @@ ret.offset =3D buf->offset; ret.len =3D buf->len; #ifdef DMALLOC - ret.data =3D (uint8_t *) openvpn_dmalloc(file, line, buf->capacity); + ret.data =3D (uint8_t *)openvpn_dmalloc(file, line, buf->capacity); #else - ret.data =3D (uint8_t *) malloc(buf->capacity); + ret.data =3D (uint8_t *)malloc(buf->capacity); #endif check_malloc_return(ret.data); memcpy(BPTR(&ret), BPTR(buf), BLEN(buf)); @@ -151,7 +153,7 @@ return buf->debug_file; } -#else /* ifdef BUF_INIT_TRACKING */ +#else /* ifdef BUF_INIT_TRACKING */ #define buf_debug_line(buf) 0 #define buf_debug_file(buf) "[UNDEF]" @@ -253,7 +255,7 @@ stat =3D vsnprintf((char *)ptr, cap, format, arglist); va_end(arglist); *(buf->data + buf->capacity - 1) =3D 0; /* windows vsnprintf n= eeds this */ - buf->len +=3D (int) strlen((char *)ptr); + buf->len +=3D (int)strlen((char *)ptr); if (stat >=3D 0 && stat < cap) { ret =3D true; @@ -273,7 +275,7 @@ { strncpynt((char *)ptr, str, cap); *(buf->data + buf->capacity - 1) =3D 0; /* windows vsnprintf needs= this */ - buf->len +=3D (int) strlen((char *)ptr); + buf->len +=3D (int)strlen((char *)ptr); ret =3D true; } return ret; @@ -300,8 +302,7 @@ buffer_write_file(const char *filename, const struct buffer *buf) { bool ret =3D false; - int fd =3D platform_open(filename, O_CREAT | O_TRUNC | O_WRONLY, - S_IRUSR | S_IWUSR); + int fd =3D platform_open(filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRU= SR | S_IWUSR); if (fd =3D=3D -1) { msg(M_ERRNO, "Cannot open file '%s' for write", filename); @@ -341,12 +342,12 @@ { struct gc_entry *e; #ifdef DMALLOC - e =3D (struct gc_entry *) openvpn_dmalloc(file, line, size + sizeo= f(struct gc_entry)); + e =3D (struct gc_entry *)openvpn_dmalloc(file, line, size + sizeof= (struct gc_entry)); #else - e =3D (struct gc_entry *) malloc(size + sizeof(struct gc_entry)); + e =3D (struct gc_entry *)malloc(size + sizeof(struct gc_entry)); #endif check_malloc_return(e); - ret =3D (char *) e + sizeof(struct gc_entry); + ret =3D (char *)e + sizeof(struct gc_entry); e->next =3D a->list; a->list =3D e; } @@ -362,7 +363,7 @@ #ifndef ZERO_BUFFER_ON_ALLOC if (clear) #endif - memset(ret, 0, size); + memset(ret, 0, size); return ret; } @@ -440,9 +441,9 @@ ASSERT(a); struct gc_entry_special *e; #ifdef DMALLOC - e =3D (struct gc_entry_special *) openvpn_dmalloc(file, line, sizeof(s= truct gc_entry_special)); + e =3D (struct gc_entry_special *)openvpn_dmalloc(file, line, sizeof(st= ruct gc_entry_special)); #else - e =3D (struct gc_entry_special *) malloc(sizeof(struct gc_entry_specia= l)); + e =3D (struct gc_entry_special *)malloc(sizeof(struct gc_entry_special= )); #endif check_malloc_return(e); e->free_fnc =3D free_function; @@ -480,15 +481,15 @@ */ char * -format_hex_ex(const uint8_t *data, int size, int maxoutput, - unsigned int space_break_flags, const char *separator, - struct gc_arena *gc) +format_hex_ex(const uint8_t *data, int size, int maxoutput, unsigned int s= pace_break_flags, + const char *separator, struct gc_arena *gc) { const size_t bytes_per_hexblock =3D space_break_flags & FHE_SPACE_BREA= K_MASK; const size_t separator_len =3D separator ? strlen(separator) : 0; static_assert(INT_MAX <=3D SIZE_MAX, "Code assumes INT_MAX <=3D SIZE_M= AX"); - const size_t out_len =3D maxoutput > 0 ? maxoutput : - ((size * 2) + ((size / bytes_per_hexblock) * se= parator_len) + 2); + const size_t out_len =3D maxoutput > 0 + ? maxoutput + : ((size * 2) + ((size / bytes_per_hexblock= ) * separator_len) + 2); struct buffer out =3D alloc_buf_gc(out_len, gc); for (int i =3D 0; i < size; ++i) @@ -532,13 +533,13 @@ void buf_null_terminate(struct buffer *buf) { - char *last =3D (char *) BLAST(buf); + char *last =3D (char *)BLAST(buf); if (last && *last =3D=3D '\0') /* already terminated? */ { return; } - if (!buf_safe(buf, 1)) /* make space for trailing null */ + if (!buf_safe(buf, 1)) /* make space for trailing null */ { buf_inc_len(buf, -1); } @@ -555,12 +556,12 @@ { while (true) { - char *last =3D (char *) BLAST(buf); + char *last =3D (char *)BLAST(buf); if (!last) { break; } - if (char_class(*last, CC_CRLF|CC_NULL)) + if (char_class(*last, CC_CRLF | CC_NULL)) { if (!buf_inc_len(buf, -1)) { @@ -657,9 +658,9 @@ if (gc) { #ifdef DMALLOC - ret =3D (char *) gc_malloc_debug(n, false, gc, file, line); + ret =3D (char *)gc_malloc_debug(n, false, gc, file, line); #else - ret =3D (char *) gc_malloc(n, false, gc); + ret =3D (char *)gc_malloc(n, false, gc); #endif } else @@ -718,7 +719,7 @@ { struct buffer out =3D alloc_buf_gc(256, gc); int i =3D 0; - for (;; ) + for (;;) { const char *cp =3D *p++; if (!cp) @@ -757,9 +758,9 @@ ASSERT(str); #ifdef DMALLOC - buf_set_read(&buf, (uint8_t *) string_alloc_debug(str, gc, file, line)= , strlen(str) + 1); + buf_set_read(&buf, (uint8_t *)string_alloc_debug(str, gc, file, line),= strlen(str) + 1); #else - buf_set_read(&buf, (uint8_t *) string_alloc(str, gc), strlen(str) + 1); + buf_set_read(&buf, (uint8_t *)string_alloc(str, gc), strlen(str) + 1); #endif if (buf.len > 0) /* Don't count trailing '\0' as part of length */ @@ -846,10 +847,9 @@ break; } line[n++] =3D (char)c; - } - while (c); + } while (c); - line[size-1] =3D '\0'; + line[size - 1] =3D '\0'; return !(eol && !strlen(line)); } @@ -1039,7 +1039,8 @@ * Guaranteed to not increase string length. */ bool -string_mod(char *str, const unsigned int inclusive, const unsigned int exc= lusive, const char replace) +string_mod(char *str, const unsigned int inclusive, const unsigned int exc= lusive, + const char replace) { const char *in =3D str; bool ret =3D true; @@ -1088,11 +1089,8 @@ } const char * -string_mod_const(const char *str, - const unsigned int inclusive, - const unsigned int exclusive, - const char replace, - struct gc_arena *gc) +string_mod_const(const char *str, const unsigned int inclusive, const unsi= gned int exclusive, + const char replace, struct gc_arena *gc) { if (str) { @@ -1131,23 +1129,16 @@ if (buf && buf->len) { int msglevel =3D D_ALIGN_DEBUG; - const unsigned int u =3D (unsigned int) BPTR(buf); + const unsigned int u =3D (unsigned int)BPTR(buf); - if (u & (PAYLOAD_ALIGN-1)) + if (u & (PAYLOAD_ALIGN - 1)) { msglevel =3D D_ALIGN_ERRORS; } msg(msglevel, "%sAlignment at %s/%d ptr=3D" ptr_format " OLC=3D%d/= %d/%d I=3D%s/%d", - (msglevel =3D=3D D_ALIGN_ERRORS) ? "ERROR: " : "", - file, - line, - (ptr_type)buf->data, - buf->offset, - buf->len, - buf->capacity, - buf_debug_file(buf), - buf_debug_line(buf)); + (msglevel =3D=3D D_ALIGN_ERRORS) ? "ERROR: " : "", file, line,= (ptr_type)buf->data, + buf->offset, buf->len, buf->capacity, buf_debug_file(buf), buf= _debug_line(buf)); } } #endif /* ifdef VERIFY_ALIGNMENT */ @@ -1201,7 +1192,7 @@ if (str) { const size_t len =3D strlen((const char *)str); - struct buffer_entry *e =3D buffer_list_push_data(ol, str, len+1); + struct buffer_entry *e =3D buffer_list_push_data(ol, str, len + 1); if (e) { e->buf.len =3D (int)len; /* Don't count trailing '\0' as part = of length */ @@ -1250,8 +1241,7 @@ } void -buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max_l= en, - const char *sep) +buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max_l= en, const char *sep) { const size_t sep_len =3D strlen(sep); struct buffer_entry *more =3D bl->head; @@ -1340,7 +1330,7 @@ if (fp) { - char *line =3D (char *) malloc(max_line_len); + char *line =3D (char *)malloc(max_line_len); if (line) { bl =3D buffer_list_new(); diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index 5f2ad5d..e512992 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -59,13 +59,13 @@ */ struct buffer { - int capacity; /**< Size in bytes of memory allocated by - * \c malloc(). */ - int offset; /**< Offset in bytes of the actual content - * within the allocated memory. */ - int len; /**< Length in bytes of the actual content - * within the allocated memory. */ - uint8_t *data; /**< Pointer to the allocated memory. */ + int capacity; /**< Size in bytes of memory allocated by + * \c malloc(). */ + int offset; /**< Offset in bytes of the actual content + * within the allocated memory. */ + int len; /**< Length in bytes of the actual content + * within the allocated memory. */ + uint8_t *data; /**< Pointer to the allocated memory. */ #ifdef BUF_INIT_TRACKING const char *debug_file; @@ -86,8 +86,8 @@ */ struct gc_entry { - struct gc_entry *next; /**< Pointer to the next item in the - * linked list. */ + struct gc_entry *next; /**< Pointer to the next item in the + * linked list. */ }; /** @@ -115,8 +115,8 @@ */ struct gc_arena { - struct gc_entry *list; /**< First element of the linked list of - * \c gc_entry structures. */ + struct gc_entry *list; /**< First element of the linked list of + * \c gc_entry structures. */ struct gc_entry_special *list_special; }; @@ -141,7 +141,7 @@ size_t array_mult_safe(const size_t m1, const size_t m2, const size_t extr= a); -#define PA_BRACKET (1<<0) +#define PA_BRACKET (1 << 0) char *print_argv(const char **p, struct gc_arena *gc, const unsigned int f= lags); void buf_size_error(const size_t size); @@ -167,13 +167,15 @@ char *string_alloc_debug(const char *str, struct gc_arena *gc, const char = *file, int line); -struct buffer string_alloc_buf_debug(const char *str, struct gc_arena *gc,= const char *file, int line); +struct buffer string_alloc_buf_debug(const char *str, struct gc_arena *gc,= const char *file, + int line); #else /* ifdef DMALLOC */ struct buffer alloc_buf(size_t size); -struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc); /* allocate= buffer with garbage collection */ +struct buffer alloc_buf_gc(size_t size, + struct gc_arena *gc); /* allocate buffer with g= arbage collection */ struct buffer clone_buf(const struct buffer *buf); @@ -198,8 +200,7 @@ * @param a gc_arena to use * @return new pointer */ -void * -gc_realloc(void *ptr, size_t size, struct gc_arena *a); +void *gc_realloc(void *ptr, size_t size, struct gc_arena *a); #ifdef BUF_INIT_TRACKING #define buf_init(buf, offset) buf_init_debug(buf, offset, __FILE__, __LINE= __) @@ -214,14 +215,14 @@ static inline void gc_freeaddrinfo_callback(void *addr) { - freeaddrinfo((struct addrinfo *) addr); + freeaddrinfo((struct addrinfo *)addr); } /** Return an empty struct buffer */ static inline struct buffer clear_buf(void) { - return (struct buffer) { 0 }; + return (struct buffer){ 0 }; } static inline bool @@ -362,7 +363,7 @@ { if (maxlen > 0) { - strncpy(dest, src, maxlen-1); + strncpy(dest, src, maxlen - 1); dest[maxlen - 1] =3D 0; } } @@ -417,9 +418,9 @@ SecureZeroMemory(data, len); #elif defined(__GNUC__) || defined(__clang__) memset(data, 0, len); - __asm__ __volatile__ ("" : : "r" (data) : "memory"); + __asm__ __volatile__("" : : "r"(data) : "memory"); #else - volatile char *p =3D (volatile char *) data; + volatile char *p =3D (volatile char *)data; while (len--) { *p++ =3D 0; @@ -436,12 +437,12 @@ bool buf_printf(struct buffer *buf, const char *format, ...) #ifdef __GNUC__ #if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 2, 3))) + __attribute__((format(gnu_printf, 2, 3))) #else -__attribute__ ((format(__printf__, 2, 3))) + __attribute__((format(__printf__, 2, 3))) #endif #endif -; + ; /* * puts append to a buffer with overflow check @@ -494,12 +495,10 @@ /* * Hex dump -- Output a binary buffer to a hex string and return it. */ -#define FHE_SPACE_BREAK_MASK 0xFF /* space_break parameter in lower 8 bits= */ -#define FHE_CAPS 0x100 /* output hex in caps */ -char * -format_hex_ex(const uint8_t *data, int size, int maxoutput, - unsigned int space_break_flags, const char *separator, - struct gc_arena *gc); +#define FHE_SPACE_BREAK_MASK 0xFF /* space_break parameter in lower 8 bit= s */ +#define FHE_CAPS 0x100 /* output hex in caps */ +char *format_hex_ex(const uint8_t *data, int size, int maxoutput, unsigned= int space_break_flags, + const char *separator, struct gc_arena *gc); static inline char * format_hex(const uint8_t *data, int size, int maxoutput, struct gc_arena *= gc) @@ -726,16 +725,10 @@ } static inline bool -buf_copy_range(struct buffer *dest, - int dest_index, - const struct buffer *src, - int src_index, +buf_copy_range(struct buffer *dest, int dest_index, const struct buffer *s= rc, int src_index, int src_len) { - if (src_index < 0 - || src_len < 0 - || src_index + src_len > src->len - || dest_index < 0 + if (src_index < 0 || src_len < 0 || src_index + src_len > src->len || = dest_index < 0 || dest->offset + dest_index + src_len > dest->capacity) { return false; @@ -750,9 +743,7 @@ /* truncate src to len, copy excess data beyond len to dest */ static inline bool -buf_copy_excess(struct buffer *dest, - struct buffer *src, - int len) +buf_copy_excess(struct buffer *dest, struct buffer *src, int len) { if (len < 0) { @@ -880,44 +871,44 @@ /* character classes */ -#define CC_ANY (1<<0) /**< any character */ -#define CC_NULL (1<<1) /**< null character \0 */ +#define CC_ANY (1 << 0) /**< any character */ +#define CC_NULL (1 << 1) /**< null character \0 */ -#define CC_ALNUM (1<<2) /**< alphanumeric isalnum() */ -#define CC_ALPHA (1<<3) /**< alphabetic isalpha() */ -#define CC_ASCII (1<<4) /**< ASCII character */ -#define CC_CNTRL (1<<5) /**< control character iscntrl() */ -#define CC_DIGIT (1<<6) /**< digit isdigit() */ -#define CC_PRINT (1<<7) /**< printable (>=3D 32, !=3D 127) */ -#define CC_PUNCT (1<<8) /**< punctuation ispunct() */ -#define CC_SPACE (1<<9) /**< whitespace isspace() */ -#define CC_XDIGIT (1<<10) /**< hex digit isxdigit() */ +#define CC_ALNUM (1 << 2) /**< alphanumeric isalnum() */ +#define CC_ALPHA (1 << 3) /**< alphabetic isalpha() */ +#define CC_ASCII (1 << 4) /**< ASCII character */ +#define CC_CNTRL (1 << 5) /**< control character iscntrl() */ +#define CC_DIGIT (1 << 6) /**< digit isdigit() */ +#define CC_PRINT (1 << 7) /**< printable (>=3D 32, !=3D 127) */ +#define CC_PUNCT (1 << 8) /**< punctuation ispunct() */ +#define CC_SPACE (1 << 9) /**< whitespace isspace() */ +#define CC_XDIGIT (1 << 10) /**< hex digit isxdigit() */ -#define CC_BLANK (1<<11) /**< space or tab */ -#define CC_NEWLINE (1<<12) /**< newline */ -#define CC_CR (1<<13) /**< carriage return */ +#define CC_BLANK (1 << 11) /**< space or tab */ +#define CC_NEWLINE (1 << 12) /**< newline */ +#define CC_CR (1 << 13) /**< carriage return */ -#define CC_BACKSLASH (1<<14) /**< backslash */ -#define CC_UNDERBAR (1<<15) /**< underscore */ -#define CC_DASH (1<<16) /**< dash */ -#define CC_DOT (1<<17) /**< dot */ -#define CC_COMMA (1<<18) /**< comma */ -#define CC_COLON (1<<19) /**< colon */ -#define CC_SLASH (1<<20) /**< slash */ -#define CC_SINGLE_QUOTE (1<<21) /**< single quote */ -#define CC_DOUBLE_QUOTE (1<<22) /**< double quote */ -#define CC_REVERSE_QUOTE (1<<23) /**< reverse quote */ -#define CC_AT (1<<24) /**< at sign */ -#define CC_EQUAL (1<<25) /**< equal sign */ -#define CC_LESS_THAN (1<<26) /**< less than sign */ -#define CC_GREATER_THAN (1<<27) /**< greater than sign */ -#define CC_PIPE (1<<28) /**< pipe */ -#define CC_QUESTION_MARK (1<<29) /**< question mark */ -#define CC_ASTERISK (1<<30) /**< asterisk */ +#define CC_BACKSLASH (1 << 14) /**< backslash */ +#define CC_UNDERBAR (1 << 15) /**< underscore */ +#define CC_DASH (1 << 16) /**< dash */ +#define CC_DOT (1 << 17) /**< dot */ +#define CC_COMMA (1 << 18) /**< comma */ +#define CC_COLON (1 << 19) /**< colon */ +#define CC_SLASH (1 << 20) /**< slash */ +#define CC_SINGLE_QUOTE (1 << 21) /**< single quote */ +#define CC_DOUBLE_QUOTE (1 << 22) /**< double quote */ +#define CC_REVERSE_QUOTE (1 << 23) /**< reverse quote */ +#define CC_AT (1 << 24) /**< at sign */ +#define CC_EQUAL (1 << 25) /**< equal sign */ +#define CC_LESS_THAN (1 << 26) /**< less than sign */ +#define CC_GREATER_THAN (1 << 27) /**< greater than sign */ +#define CC_PIPE (1 << 28) /**< pipe */ +#define CC_QUESTION_MARK (1 << 29) /**< question mark */ +#define CC_ASTERISK (1 << 30) /**< asterisk */ /* macro classes */ -#define CC_NAME (CC_ALNUM|CC_UNDERBAR) /**< alphanumeric plu= s underscore */ -#define CC_CRLF (CC_CR|CC_NEWLINE) /**< carriage return or n= ewline */ +#define CC_NAME (CC_ALNUM | CC_UNDERBAR) /**< alphanumeric plus underscore= */ +#define CC_CRLF (CC_CR | CC_NEWLINE) /**< carriage return or newline */ bool char_class(const unsigned char c, const unsigned int flags); @@ -936,7 +927,8 @@ * @param replace The character to replace the specified character classes= with. * @return True if the string was not modified, false otherwise. */ -bool string_mod(char *str, const unsigned int inclusive, const unsigned in= t exclusive, const char replace); +bool string_mod(char *str, const unsigned int inclusive, const unsigned in= t exclusive, + const char replace); /** @@ -947,8 +939,8 @@ * @param exclusive Character classes that are not allowed even if they ar= e also in inclusive. * @return True if the string consists only of allowed characters, false o= therwise. */ -bool -string_check_buf(struct buffer *buf, const unsigned int inclusive, const u= nsigned int exclusive); +bool string_check_buf(struct buffer *buf, const unsigned int inclusive, + const unsigned int exclusive); /** * Returns a copy of a string with certain classes of characters of it rep= laced with a specified @@ -964,11 +956,8 @@ * * @return The modified string with characters replaced within the specifi= ed range. */ -const char *string_mod_const(const char *str, - const unsigned int inclusive, - const unsigned int exclusive, - const char replace, - struct gc_arena *gc); +const char *string_mod_const(const char *str, const unsigned int inclusive, + const unsigned int exclusive, const char repl= ace, struct gc_arena *gc); void string_replace_leading(char *str, const char match, const char replac= e); @@ -1052,51 +1041,51 @@ * Allocate memory to hold a structure */ -#define ALLOC_OBJ(dptr, type) \ - { \ - check_malloc_return((dptr) =3D (type *) malloc(sizeof(type))); \ +#define ALLOC_OBJ(dptr, type) \ + { \ + check_malloc_return((dptr) =3D (type *)malloc(sizeof(type))); \ } -#define ALLOC_OBJ_CLEAR(dptr, type) \ - { \ - ALLOC_OBJ(dptr, type); \ +#define ALLOC_OBJ_CLEAR(dptr, type) \ + { \ + ALLOC_OBJ(dptr, type); \ memset((dptr), 0, sizeof(type)); \ } -#define ALLOC_ARRAY(dptr, type, n) \ - { \ - check_malloc_return((dptr) =3D (type *) malloc(array_mult_safe(siz= eof(type), (n), 0))); \ +#define ALLOC_ARRAY(dptr, type, n) = \ + { = \ + check_malloc_return((dptr) =3D (type *)malloc(array_mult_safe(size= of(type), (n), 0))); \ } -#define ALLOC_ARRAY_GC(dptr, type, n, gc) \ - { \ - (dptr) =3D (type *) gc_malloc(array_mult_safe(sizeof(type), (n), 0= ), false, (gc)); \ +#define ALLOC_ARRAY_GC(dptr, type, n, gc) = \ + { = \ + (dptr) =3D (type *)gc_malloc(array_mult_safe(sizeof(type), (n), 0)= , false, (gc)); \ } -#define ALLOC_ARRAY_CLEAR(dptr, type, n) \ - { \ - ALLOC_ARRAY(dptr, type, n); \ +#define ALLOC_ARRAY_CLEAR(dptr, type, n) \ + { \ + ALLOC_ARRAY(dptr, type, n); \ memset((dptr), 0, (array_mult_safe(sizeof(type), (n), 0))); \ } =20 -#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc) \ - { \ - (dptr) =3D (type *) gc_malloc(array_mult_safe(sizeof(type), (n), 0= ), true, (gc)); \ +#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc) = \ + { = \ + (dptr) =3D (type *)gc_malloc(array_mult_safe(sizeof(type), (n), 0)= , true, (gc)); \ } -#define ALLOC_VAR_ARRAY_CLEAR_GC(dptr, type, atype, n, gc) \ - { \ - (dptr) =3D (type *) gc_malloc(array_mult_safe(sizeof(atype), (n), = sizeof(type)), true, (gc)); \ +#define ALLOC_VAR_ARRAY_CLEAR_GC(dptr, type, atype, n, gc) = \ + { = \ + (dptr) =3D (type *)gc_malloc(array_mult_safe(sizeof(atype), (n), s= izeof(type)), true, (gc)); \ } -#define ALLOC_OBJ_GC(dptr, type, gc) \ - { \ - (dptr) =3D (type *) gc_malloc(sizeof(type), false, (gc)); \ +#define ALLOC_OBJ_GC(dptr, type, gc) \ + { \ + (dptr) =3D (type *)gc_malloc(sizeof(type), false, (gc)); \ } -#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc) \ - { \ - (dptr) =3D (type *) gc_malloc(sizeof(type), true, (gc)); \ +#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc) \ + { \ + (dptr) =3D (type *)gc_malloc(sizeof(type), true, (gc)); \ } static inline void @@ -1121,8 +1110,8 @@ { struct buffer_entry *head; /* next item to pop/peek */ struct buffer_entry *tail; /* last item pushed */ - int size; /* current number of entries */ - int max_size; /* maximum size list should grow to */ + int size; /* current number of entries */ + int max_size; /* maximum size list should grow to */ }; /** @@ -1210,8 +1199,7 @@ * @param max_len the maximum length of the aggregated buffer * @param sep the separator to put between buffers during aggregation */ -void buffer_list_aggregate_separator(struct buffer_list *bl, - const size_t max_len, const char *sep= ); +void buffer_list_aggregate_separator(struct buffer_list *bl, const size_t = max_len, const char *sep); struct buffer_list *buffer_list_file(const char *fn, int max_line_len); diff --git a/src/openvpn/circ_list.h b/src/openvpn/circ_list.h index 0189c8b..9b9a478 100644 --- a/src/openvpn/circ_list.h +++ b/src/openvpn/circ_list.h @@ -29,49 +29,46 @@ #include "error.h" #define CIRC_LIST(name, type) \ - struct name { \ - int x_head; \ - int x_size; \ - int x_cap; \ - int x_sizeof; \ - type x_list[]; \ + struct name \ + { \ + int x_head; \ + int x_size; \ + int x_cap; \ + int x_sizeof; \ + type x_list[]; \ } -#define CIRC_LIST_PUSH(obj, item) \ - { \ +#define CIRC_LIST_PUSH(obj, item) \ + { \ (obj)->x_head =3D modulo_add((obj)->x_head, -1, (obj)->x_cap); \ - (obj)->x_list[(obj)->x_head] =3D (item); \ - (obj)->x_size =3D min_int((obj)->x_size + 1, (obj)->x_cap); \ + (obj)->x_list[(obj)->x_head] =3D (item); \ + (obj)->x_size =3D min_int((obj)->x_size + 1, (obj)->x_cap); \ } -#define CIRC_LIST_SIZE(obj) \ - ((obj)->x_size) +#define CIRC_LIST_SIZE(obj) ((obj)->x_size) -#define CIRC_LIST_INDEX(obj, index) \ - modulo_add((obj)->x_head, \ - index_verify((index), (obj)->x_size, __FILE__, __LINE__), \ +#define CIRC_LIST_INDEX(obj, index) = \ + modulo_add((obj)->x_head, index_verify((index), (obj)->x_size, __FILE_= _, __LINE__), \ (obj)->x_cap) -#define CIRC_LIST_ITEM(obj, index) \ - ((obj)->x_list[CIRC_LIST_INDEX((obj), (index))]) +#define CIRC_LIST_ITEM(obj, index) ((obj)->x_list[CIRC_LIST_INDEX((obj), (= index))]) #define CIRC_LIST_RESET(obj) \ - { \ - (obj)->x_head =3D 0; \ - (obj)->x_size =3D 0; \ + { \ + (obj)->x_head =3D 0; \ + (obj)->x_size =3D 0; \ } -#define CIRC_LIST_ALLOC(dest, list_type, size) \ - { \ +#define CIRC_LIST_ALLOC(dest, list_type, size) = \ + { = \ const int so =3D sizeof(list_type) + sizeof((dest)->x_list[0]) * (= size); \ - (dest) =3D (list_type *) malloc(so); \ - check_malloc_return(dest); \ - memset((dest), 0, so); \ - (dest)->x_cap =3D size; \ - (dest)->x_sizeof =3D so; \ + (dest) =3D (list_type *)malloc(so); = \ + check_malloc_return(dest); = \ + memset((dest), 0, so); = \ + (dest)->x_cap =3D size; = \ + (dest)->x_sizeof =3D so; = \ } -#define CIRC_LIST_FREE(dest) \ - free(dest) +#define CIRC_LIST_FREE(dest) free(dest) =20 #endif /* ifndef CIRC_LIST_H */ diff --git a/src/openvpn/clinat.c b/src/openvpn/clinat.c index f040724..7bf4d82 100644 --- a/src/openvpn/clinat.c +++ b/src/openvpn/clinat.c @@ -33,8 +33,7 @@ #include "memdbg.h" static bool -add_entry(struct client_nat_option_list *dest, - const struct client_nat_entry *e) +add_entry(struct client_nat_option_list *dest, const struct client_nat_ent= ry *e) { if (dest->n >=3D MAX_CLIENT_NAT) { @@ -60,9 +59,7 @@ for (i =3D 0; i < list->n; ++i) { const struct client_nat_entry *e =3D &list->entries[i]; - msg(msglevel, " CNAT[%d] t=3D%d %s/%s/%s", - i, - e->type, + msg(msglevel, " CNAT[%d] t=3D%d %s/%s/%s", i, e->type, print_in_addr_t(e->network, IA_NET_ORDER, &gc), print_in_addr_t(e->netmask, IA_NET_ORDER, &gc), print_in_addr_t(e->foreign_network, IA_NET_ORDER, &gc)); @@ -103,11 +100,8 @@ } 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, +add_client_nat_to_option_list(struct client_nat_option_list *dest, const c= har *type, + const char *network, const char *netmask, co= nst char *foreign_network, int msglevel) { struct client_nat_entry e; @@ -180,9 +174,7 @@ dirstr =3D "IN"; } - msg(msglevel, "** CNAT %s %s %s -> %s", - dirstr, - prefix, + msg(msglevel, "** CNAT %s %s %s -> %s", dirstr, prefix, print_in_addr_t(iph->saddr, IA_NET_ORDER, &gc), print_in_addr_t(iph->daddr, IA_NET_ORDER, &gc)); =20 @@ -190,11 +182,10 @@ } void -client_nat_transform(const struct client_nat_option_list *list, - struct buffer *ipbuf, +client_nat_transform(const struct client_nat_option_list *list, struct buf= fer *ipbuf, const int direction) { - struct ip_tcp_udp_hdr *h =3D (struct ip_tcp_udp_hdr *) BPTR(ipbuf); + struct ip_tcp_udp_hdr *h =3D (struct ip_tcp_udp_hdr *)BPTR(ipbuf); int i; uint32_t addr, *addr_ptr; const uint32_t *from, *to; diff --git a/src/openvpn/clinat.h b/src/openvpn/clinat.h index 334b3f2..a9b42dd 100644 --- a/src/openvpn/clinat.h +++ b/src/openvpn/clinat.h @@ -31,7 +31,8 @@ #define CN_OUTGOING 0 #define CN_INCOMING 1 -struct client_nat_entry { +struct client_nat_entry +{ #define CN_SNAT 0 #define CN_DNAT 1 int type; @@ -40,28 +41,27 @@ in_addr_t foreign_network; }; -struct client_nat_option_list { +struct client_nat_option_list +{ int n; struct client_nat_entry entries[MAX_CLIENT_NAT]; }; struct client_nat_option_list *new_client_nat_list(struct gc_arena *gc); -struct client_nat_option_list *clone_client_nat_option_list(const struct c= lient_nat_option_list *src, struct gc_arena *gc); +struct client_nat_option_list *clone_client_nat_option_list( + const struct client_nat_option_list *src, struct gc_arena *gc); -void copy_client_nat_option_list(struct client_nat_option_list *dest, cons= t struct client_nat_option_list *src); +void copy_client_nat_option_list(struct client_nat_option_list *dest, + const struct client_nat_option_list *src); void print_client_nat_list(const struct client_nat_option_list *list, int = msglevel); -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, - int msglevel); +void add_client_nat_to_option_list(struct client_nat_option_list *dest, co= nst char *type, + const char *network, const char *netmas= k, + const char *foreign_network, int msglev= el); -void client_nat_transform(const struct client_nat_option_list *list, - struct buffer *ipbuf, +void client_nat_transform(const struct client_nat_option_list *list, struc= t buffer *ipbuf, const int direction); #endif /* if !defined(CLINAT_H) */ diff --git a/src/openvpn/common.h b/src/openvpn/common.h index 5d4cf2e..645ebb9 100644 --- a/src/openvpn/common.h +++ b/src/openvpn/common.h @@ -28,7 +28,7 @@ * Statistics counters and associated printf format. */ typedef uint64_t counter_type; -#define counter_format "%" PRIu64 +#define counter_format "%" PRIu64 /* * Time intervals @@ -38,17 +38,17 @@ /* * Used as an upper bound for timeouts. */ -#define BIG_TIMEOUT (60*60*24*7) /* one week (in seconds) */ +#define BIG_TIMEOUT (60 * 60 * 24 * 7) /* one week (in seconds) */ /* * Printf formats for special types */ #ifdef _WIN64 -#define ptr_format "0x%016" PRIx64 +#define ptr_format "0x%016" PRIx64 #else -#define ptr_format "0x%08lx" +#define ptr_format "0x%08lx" #endif -#define fragment_header_format "0x%08x" +#define fragment_header_format "0x%08x" /* these are used to cast the arguments * and MUST match the formats above */ @@ -95,6 +95,7 @@ /* * Script security warning */ -#define SCRIPT_SECURITY_WARNING "WARNING: External program may not be call= ed unless '--script-security 2' or higher is enabled. See --help text or ma= n page for detailed info." +#define SCRIPT_SECURITY_WARNING \ + "WARNING: External program may not be called unless '--script-security= 2' or higher is enabled. See --help text or man page for detailed info." #endif /* ifndef COMMON_H */ diff --git a/src/openvpn/comp-lz4.c b/src/openvpn/comp-lz4.c index ab37164..57eb85a 100644 --- a/src/openvpn/comp-lz4.c +++ b/src/openvpn/comp-lz4.c @@ -57,8 +57,7 @@ /* Doesn't do any actual compression anymore */ static void -lz4_compress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +lz4_compress(struct buffer *buf, struct buffer work, struct compress_conte= xt *compctx, const struct frame *frame) { if (buf->len <=3D 0) @@ -79,8 +78,7 @@ /* Doesn't do any actual compression anymore */ static void -lz4v2_compress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +lz4v2_compress(struct buffer *buf, struct buffer work, struct compress_con= text *compctx, const struct frame *frame) { if (buf->len <=3D 0) @@ -92,14 +90,13 @@ } static void -do_lz4_decompress(size_t zlen_max, - struct buffer *work, - struct buffer *buf, +do_lz4_decompress(size_t zlen_max, struct buffer *work, struct buffer *buf, struct compress_context *compctx) { int uncomp_len; ASSERT(buf_safe(work, zlen_max)); - uncomp_len =3D LZ4_decompress_safe((const char *)BPTR(buf), (char *)BP= TR(work), (size_t)BLEN(buf), zlen_max); + uncomp_len =3D LZ4_decompress_safe((const char *)BPTR(buf), (char *)BP= TR(work), (size_t)BLEN(buf), + zlen_max); if (uncomp_len <=3D 0) { dmsg(D_COMP_ERRORS, "LZ4 decompression error: %d", uncomp_len); @@ -118,12 +115,11 @@ } static void -lz4_decompress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +lz4_decompress(struct buffer *buf, struct buffer work, struct compress_con= text *compctx, const struct frame *frame) { size_t zlen_max =3D frame->buf.payload_size; - uint8_t c; /* flag indicating whether or not our peer compres= sed */ + uint8_t c; /* flag indicating whether or not our peer compressed */ if (buf->len <=3D 0) { @@ -156,12 +152,11 @@ } static void -lz4v2_decompress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +lz4v2_decompress(struct buffer *buf, struct buffer work, struct compress_c= ontext *compctx, const struct frame *frame) { size_t zlen_max =3D frame->buf.payload_size; - uint8_t c; /* flag indicating whether or not our peer compres= sed */ + uint8_t c; /* flag indicating whether or not our peer compressed */ if (buf->len <=3D 0) { @@ -204,19 +199,9 @@ } } -const struct compress_alg lz4_alg =3D { - "lz4", - lz4_compress_init, - lz4_compress_uninit, - lz4_compress, - lz4_decompress -}; +const struct compress_alg lz4_alg =3D { "lz4", lz4_compress_init, lz4_comp= ress_uninit, lz4_compress, + lz4_decompress }; -const struct compress_alg lz4v2_alg =3D { - "lz4v2", - lz4v2_compress_init, - lz4_compress_uninit, - lz4v2_compress, - lz4v2_decompress -}; +const struct compress_alg lz4v2_alg =3D { "lz4v2", lz4v2_compress_init, lz= 4_compress_uninit, + lz4v2_compress, lz4v2_decompress }; #endif /* ENABLE_LZ4 */ diff --git a/src/openvpn/comp.c b/src/openvpn/comp.c index b2aa07e..82979a8 100644 --- a/src/openvpn/comp.c +++ b/src/openvpn/comp.c @@ -172,10 +172,10 @@ { #ifdef USE_COMP msg(msglevel, "Compression or compression stub framing is not allo= wed " - "since data-channel offloading is enabled."); + "since data-channel offloading is enabled."); #else msg(msglevel, "Compression or compression stub framing is not allo= wed " - "since OpenVPN was built without compression support."); + "since OpenVPN was built without compression support= ."); #endif return false; } @@ -183,14 +183,14 @@ if ((info->flags & COMP_F_ALLOW_STUB_ONLY) && comp_non_stub_enabled(in= fo)) { msg(msglevel, "Compression is not allowed since allow-compression = is " - "set to 'stub-only'"); + "set to 'stub-only'"); return false; } #ifndef ENABLE_LZ4 if (info->alg =3D=3D COMP_ALGV2_LZ4 || info->alg =3D=3D COMP_ALG_LZ4) { msg(msglevel, "OpenVPN is compiled without LZ4 support. Requested " - "compression cannot be enabled."); + "compression cannot be enabled."); return false; } #endif @@ -198,7 +198,7 @@ if (info->alg =3D=3D COMP_ALG_LZO) { msg(msglevel, "OpenVPN is compiled without LZO support. Requested " - "compression cannot be enabled."); + "compression cannot be enabled."); return false; } #endif diff --git a/src/openvpn/comp.h b/src/openvpn/comp.h index 0bb0d32..3ac2a3d 100644 --- a/src/openvpn/comp.h +++ b/src/openvpn/comp.h @@ -34,21 +34,22 @@ /* Compression flags */ /* Removed #define COMP_F_ADAPTIVE (1<<0) / * COMP_ALG_LZO only * / - #define COMP_F_ALLOW_COMPRESS (1<<1) / * not only incoming is compr= essed but also outgoing * / + #define COMP_F_ALLOW_COMPRESS (1<<1) / * not only incoming is compr= essed but also outgoing * + / */ /** initial command byte is swapped with last byte in buffer to preserve p= ayload alignment */ -#define COMP_F_SWAP (1<<2) +#define COMP_F_SWAP (1 << 2) /** tell server that we only support compression stubs */ -#define COMP_F_ADVERTISE_STUBS_ONLY (1<<3) +#define COMP_F_ADVERTISE_STUBS_ONLY (1 << 3) /** Only accept stub compression, even with COMP_F_ADVERTISE_STUBS_ONLY * we still accept other compressions to be pushed */ -#define COMP_F_ALLOW_STUB_ONLY (1<<4) +#define COMP_F_ALLOW_STUB_ONLY (1 << 4) /** push stub-v2 or comp-lzo no when we see a client with comp-lzo in occ = */ -#define COMP_F_MIGRATE (1<<5) +#define COMP_F_MIGRATE (1 << 5) /** Compression was explicitly set to allow asymetric compression */ -#define COMP_F_ALLOW_ASYM (1<<6) +#define COMP_F_ALLOW_ASYM (1 << 6) /** Do not allow compression framing (breaks DCO) */ -#define COMP_F_ALLOW_NOCOMP_ONLY (1<<7) +#define COMP_F_ALLOW_NOCOMP_ONLY (1 << 7) /* algorithms */ #define COMP_ALG_UNDEF 0 @@ -61,7 +62,7 @@ /* algorithm v2 */ #define COMP_ALGV2_UNCOMPRESSED 10 -#define COMP_ALGV2_LZ4 11 +#define COMP_ALGV2_LZ4 11 /* #define COMP_ALGV2_LZO 12 #define COMP_ALGV2_SNAPPY 13 @@ -80,8 +81,7 @@ static inline bool comp_non_stub_enabled(const struct compress_options *info) { - return info->alg !=3D COMP_ALGV2_UNCOMPRESSED - && info->alg !=3D COMP_ALG_STUB + return info->alg !=3D COMP_ALGV2_UNCOMPRESSED && info->alg !=3D COMP_A= LG_STUB && info->alg !=3D COMP_ALG_UNDEF; } @@ -90,8 +90,7 @@ * flags of allow-compression and also the whether algorithms are compiled * in */ -bool -check_compression_settings_valid(struct compress_options *info, int msglev= el); +bool check_compression_settings_valid(struct compress_options *info, int m= sglevel); #ifdef USE_COMP #include "buffer.h" @@ -110,18 +109,18 @@ /* V1 on wire codes */ /* Initial command byte to tell our peer if we compressed */ -#define LZO_COMPRESS_BYTE 0x66 -#define LZ4_COMPRESS_BYTE 0x69 +#define LZO_COMPRESS_BYTE 0x66 +#define LZ4_COMPRESS_BYTE 0x69 #define NO_COMPRESS_BYTE 0xFA /** to maintain payload alignment, replace this byte with last byte of pac= ket */ #define NO_COMPRESS_BYTE_SWAP 0xFB /* V2 on wire code */ -#define COMP_ALGV2_INDICATOR_BYTE 0x50 -#define COMP_ALGV2_UNCOMPRESSED_BYTE 0 -#define COMP_ALGV2_LZ4_BYTE 1 -#define COMP_ALGV2_LZO_BYTE 2 -#define COMP_ALGV2_SNAPPY_BYTE 3 +#define COMP_ALGV2_INDICATOR_BYTE 0x50 +#define COMP_ALGV2_UNCOMPRESSED_BYTE 0 +#define COMP_ALGV2_LZ4_BYTE 1 +#define COMP_ALGV2_LZO_BYTE 2 +#define COMP_ALGV2_SNAPPY_BYTE 3 /* * Compress worst case size expansion (for any algorithm) @@ -130,7 +129,7 @@ * Snappy: len + len/6 + 32 * LZ4: len + len/255 + 16 (LZ4_COMPRESSBOUND(len)) */ -#define COMP_EXTRA_BUFFER(len) ((len)/6 + 128 + 3 + COMP_PREFIX_LEN) +#define COMP_EXTRA_BUFFER(len) ((len) / 6 + 128 + 3 + COMP_PREFIX_LEN) /* * Don't try to compress any packet smaller than this. @@ -148,12 +147,10 @@ const char *name; void (*compress_init)(struct compress_context *compctx); void (*compress_uninit)(struct compress_context *compctx); - void (*compress)(struct buffer *buf, struct buffer work, - struct compress_context *compctx, + void (*compress)(struct buffer *buf, struct buffer work, struct compre= ss_context *compctx, const struct frame *frame); - void (*decompress)(struct buffer *buf, struct buffer work, - struct compress_context *compctx, + void (*decompress)(struct buffer *buf, struct buffer work, struct comp= ress_context *compctx, const struct frame *frame); }; diff --git a/src/openvpn/compstub.c b/src/openvpn/compstub.c index 109d691..0d6e0e0 100644 --- a/src/openvpn/compstub.c +++ b/src/openvpn/compstub.c @@ -46,8 +46,7 @@ } static void -stub_compress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +stub_compress(struct buffer *buf, struct buffer work, struct compress_cont= ext *compctx, const struct frame *frame) { if (buf->len <=3D 0) @@ -57,7 +56,7 @@ if (compctx->flags & COMP_F_SWAP) { uint8_t *head =3D BPTR(buf); - uint8_t *tail =3D BEND(buf); + uint8_t *tail =3D BEND(buf); ASSERT(buf_safe(buf, 1)); ++buf->len; @@ -73,8 +72,7 @@ } static void -stub_decompress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +stub_decompress(struct buffer *buf, struct buffer work, struct compress_co= ntext *compctx, const struct frame *frame) { uint8_t c; @@ -108,8 +106,7 @@ static void -stubv2_compress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +stubv2_compress(struct buffer *buf, struct buffer work, struct compress_co= ntext *compctx, const struct frame *frame) { if (buf->len <=3D 0) @@ -121,8 +118,7 @@ } static void -stubv2_decompress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +stubv2_decompress(struct buffer *buf, struct buffer work, struct compress_= context *compctx, const struct frame *frame) { if (buf->len <=3D 0) @@ -158,19 +154,9 @@ } } -const struct compress_alg compv2_stub_alg =3D { - "stubv2", - stub_compress_init, - stub_compress_uninit, - stubv2_compress, - stubv2_decompress -}; +const struct compress_alg compv2_stub_alg =3D { "stubv2", stub_compress_in= it, stub_compress_uninit, + stubv2_compress, stubv2_deco= mpress }; -const struct compress_alg comp_stub_alg =3D { - "stub", - stub_compress_init, - stub_compress_uninit, - stub_compress, - stub_decompress -}; +const struct compress_alg comp_stub_alg =3D { "stub", stub_compress_init, = stub_compress_uninit, + stub_compress, stub_decompress= }; #endif /* USE_STUB */ diff --git a/src/openvpn/console.c b/src/openvpn/console.c index 617e146..deb280e 100644 --- a/src/openvpn/console.c +++ b/src/openvpn/console.c @@ -38,7 +38,7 @@ #endif -struct _query_user query_user[QUERY_USER_NUMSLOTS]; /* GLOBAL */ +struct _query_user query_user[QUERY_USER_NUMSLOTS]; /* GLOBAL */ void @@ -54,16 +54,14 @@ void -query_user_add(char *prompt, size_t prompt_len, - char *resp, size_t resp_len, - bool echo) +query_user_add(char *prompt, size_t prompt_len, char *resp, size_t resp_le= n, bool echo) { int i; /* Ensure input is sane. All these must be present otherwise it is * a programming error. */ - ASSERT( prompt_len > 0 && prompt !=3D NULL && resp_len > 0 && resp != =3D NULL ); + ASSERT(prompt_len > 0 && prompt !=3D NULL && resp_len > 0 && resp !=3D= NULL); /* Seek to the last unused slot */ for (i =3D 0; i < QUERY_USER_NUMSLOTS; i++) @@ -73,7 +71,7 @@ break; } } - ASSERT( i < QUERY_USER_NUMSLOTS ); /* Unlikely, but we want to panic = if it happens */ + ASSERT(i < QUERY_USER_NUMSLOTS); /* Unlikely, but we want to panic if = it happens */ /* Save the information needed for the user interaction */ query_user[i].prompt =3D prompt; diff --git a/src/openvpn/console.h b/src/openvpn/console.h index 589f778..e2dddec 100644 --- a/src/openvpn/console.h +++ b/src/openvpn/console.h @@ -31,16 +31,17 @@ /** * Configuration setup for declaring what kind of information to ask a us= er for */ -struct _query_user { - char *prompt; /**< Prompt to present to the user */ - size_t prompt_len; /**< Length of the prompt string */ - char *response; /**< The user's response */ - size_t response_len; /**< Length the of the user response */ - bool echo; /**< True: The user should see what is being= typed, otherwise mask it */ +struct _query_user +{ + char *prompt; /**< Prompt to present to the user */ + size_t prompt_len; /**< Length of the prompt string */ + char *response; /**< The user's response */ + size_t response_len; /**< Length the of the user response */ + bool echo; /**< True: The user should see what is being type= d, otherwise mask it */ }; #define QUERY_USER_NUMSLOTS 10 -extern struct _query_user query_user[]; /**< Global variable, declared in= console.c */ +extern struct _query_user query_user[]; /**< Global variable, declared in = console.c */ /** * Wipes all data put into all of the query_user structs @@ -59,9 +60,7 @@ * @param echo Should the user input be echoed to the user? If Fals= e, input will be masked * */ -void query_user_add(char *prompt, size_t prompt_len, - char *resp, size_t resp_len, - bool echo); +void query_user_add(char *prompt, size_t prompt_len, char *resp, size_t re= sp_len, bool echo); /** @@ -108,7 +107,7 @@ { return query_user_exec_builtin(); } -#endif /* defined(ENABLE_SYSTEMD) */ +#endif /* defined(ENABLE_SYSTEMD) */ =20 /** @@ -119,9 +118,7 @@ * */ static inline bool -query_user_SINGLE(char *prompt, size_t prompt_len, - char *resp, size_t resp_len, - bool echo) +query_user_SINGLE(char *prompt, size_t prompt_len, char *resp, size_t resp= _len, bool echo) { query_user_clear(); query_user_add(prompt, prompt_len, resp, resp_len, echo); diff --git a/src/openvpn/console_builtin.c b/src/openvpn/console_builtin.c index ba61d3f..a0984bf 100644 --- a/src/openvpn/console_builtin.c +++ b/src/openvpn/console_builtin.c @@ -68,11 +68,10 @@ HANDLE in =3D GetStdHandle(STD_INPUT_HANDLE); int orig_stderr =3D get_orig_stderr(); /* guaranteed to be always vali= d */ - if ((in =3D=3D INVALID_HANDLE_VALUE) - || win32_service_interrupt(&win32_signal) + if ((in =3D=3D INVALID_HANDLE_VALUE) || win32_service_interrupt(&win32= _signal) || (_write(orig_stderr, prompt, strlen(prompt)) =3D=3D -1)) { - msg(M_WARN|M_ERRNO, "get_console_input_win32(): unexpected error"); + msg(M_WARN | M_ERRNO, "get_console_input_win32(): unexpected error= "); return false; } @@ -136,7 +135,7 @@ return false; } -#endif /* _WIN32 */ +#endif /* _WIN32 */ #ifdef HAVE_TERMIOS_H @@ -178,7 +177,7 @@ } } -#endif /* HAVE_TERMIOS_H */ +#endif /* HAVE_TERMIOS_H */ /** @@ -210,15 +209,17 @@ * (in which case neither stdin or stderr are connected to a tty and * /dev/tty can not be open()ed anymore) */ - if (!isatty(0) && !isatty(2) ) + if (!isatty(0) && !isatty(2)) { - int fd =3D open( "/dev/tty", O_RDWR ); + int fd =3D open("/dev/tty", O_RDWR); if (fd < 0) { - msg(M_FATAL, "neither stdin nor stderr are a tty device and yo= u have neither a " + msg(M_FATAL, + "neither stdin nor stderr are a tty device and you have ne= ither a " "controlling tty nor systemd - can't ask for '%s'. If you= used --daemon, " "you need to use --askpass to make passphrase-protected ke= ys work, and you " - "can not use --auth-nocache.", prompt ); + "can not use --auth-nocache.", + prompt); } close(fd); } @@ -286,8 +287,8 @@ /* Loop through configured query_user slots */ for (i =3D 0; i < QUERY_USER_NUMSLOTS && query_user[i].response !=3D N= ULL; i++) { - if (!get_console_input(query_user[i].prompt, query_user[i].echo, - query_user[i].response, query_user[i].respo= nse_len) ) + if (!get_console_input(query_user[i].prompt, query_user[i].echo, q= uery_user[i].response, + query_user[i].response_len)) { /* Force the final result state to failed on failure */ ret =3D false; diff --git a/src/openvpn/console_systemd.c b/src/openvpn/console_systemd.c index 91ebb35..af67b15 100644 --- a/src/openvpn/console_systemd.c +++ b/src/openvpn/console_systemd.c @@ -51,9 +51,7 @@ * mounted, as well as the systemd-ask-password executable * being available */ - return (sd_booted() > 0) - && (stat(SYSTEMD_ASK_PASSWORD_PATH, &c) =3D=3D 0); - + return (sd_booted() > 0) && (stat(SYSTEMD_ASK_PASSWORD_PATH, &c) =3D= =3D 0); } static bool @@ -80,7 +78,7 @@ return false; } memset(input, 0, capacity); - if (read(std_out, input, capacity-1) !=3D 0) + if (read(std_out, input, capacity - 1) !=3D 0) { chomp(input); ret =3D true; @@ -100,7 +98,7 @@ bool query_user_exec_systemd(void) { - bool ret =3D true; /* Presume everything goes okay */ + bool ret =3D true; /* Presume everything goes okay */ int i; /* If systemd is not available, use the default built-in mechanism */ @@ -113,7 +111,7 @@ for (i =3D 0; i < QUERY_USER_NUMSLOTS && query_user[i].response !=3D N= ULL; i++) { if (!get_console_input_systemd(query_user[i].prompt, query_user[i]= .echo, - query_user[i].response, query_user[= i].response_len) ) + query_user[i].response, query_user[= i].response_len)) { /* Force the final result state to failed on failure */ ret =3D false; diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 7564f82..3bac0d1 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -64,8 +64,7 @@ */ static void -openvpn_encrypt_aead(struct buffer *buf, struct buffer work, - struct crypto_options *opt) +openvpn_encrypt_aead(struct buffer *buf, struct buffer work, struct crypto= _options *opt) { struct gc_arena gc; int outlen =3D 0; @@ -89,7 +88,7 @@ /* Prepare IV */ { struct buffer iv_buffer; - uint8_t iv[OPENVPN_MAX_IV_LENGTH] =3D {0}; + uint8_t iv[OPENVPN_MAX_IV_LENGTH] =3D { 0 }; const int iv_len =3D cipher_ctx_iv_length(ctx->cipher); ASSERT(iv_len >=3D OPENVPN_AEAD_MIN_IV_LEN && iv_len <=3D OPENVPN_= MAX_IV_LENGTH); @@ -134,17 +133,14 @@ /* Buffer overflow check */ if (!buf_safe(&work, buf->len + mac_len + cipher_ctx_block_size(ctx->c= ipher))) { - msg(D_CRYPT_ERRORS, - "ENCRYPT: buffer size error, bc=3D%d bo=3D%d bl=3D%d wc=3D%d w= o=3D%d wl=3D%d", - buf->capacity, buf->offset, buf->len, work.capacity, work.offs= et, - work.len); + msg(D_CRYPT_ERRORS, "ENCRYPT: buffer size error, bc=3D%d bo=3D%d b= l=3D%d wc=3D%d wo=3D%d wl=3D%d", + buf->capacity, buf->offset, buf->len, work.capacity, work.offs= et, work.len); goto err; } /* For AEAD ciphers, authenticate Additional Data, including opcode */ ASSERT(cipher_ctx_update_ad(ctx->cipher, BPTR(&work), BLEN(&work))); - dmsg(D_PACKET_CONTENT, "ENCRYPT AD: %s", - format_hex(BPTR(&work), BLEN(&work), 0, &gc)); + dmsg(D_PACKET_CONTENT, "ENCRYPT AD: %s", format_hex(BPTR(&work), BLEN(= &work), 0, &gc)); if (!use_epoch_data_format) { @@ -160,7 +156,7 @@ /* update number of plaintext blocks encrypted. Use the (x + (n-1))/n = trick * to round up the result to the number of blocks used */ const int blocksize =3D AEAD_LIMIT_BLOCKSIZE; - opt->key_ctx_bi.encrypt.plaintext_blocks +=3D (outlen + (blocksize - 1= ))/blocksize; + opt->key_ctx_bi.encrypt.plaintext_blocks +=3D (outlen + (blocksize - 1= )) / blocksize; /* Flush the encryption buffer */ ASSERT(cipher_ctx_final(ctx->cipher, BEND(&work), &outlen)); @@ -192,8 +188,7 @@ } static void -openvpn_encrypt_v1(struct buffer *buf, struct buffer work, - struct crypto_options *opt) +openvpn_encrypt_v1(struct buffer *buf, struct buffer work, struct crypto_o= ptions *opt) { struct gc_arena gc; gc_init(&gc); @@ -207,7 +202,7 @@ /* Do Encrypt from buf -> work */ if (ctx->cipher) { - uint8_t iv_buf[OPENVPN_MAX_IV_LENGTH] =3D {0}; + uint8_t iv_buf[OPENVPN_MAX_IV_LENGTH] =3D { 0 }; const int iv_size =3D cipher_ctx_iv_length(ctx->cipher); int outlen; @@ -227,8 +222,7 @@ /* Put packet ID in plaintext buffer */ if (packet_id_initialized(&opt->packet_id) && !packet_id_write(&opt->packet_id.send, buf, - opt->flags & CO_PACKET_ID_LONG_FOR= M, - true)) + opt->flags & CO_PACKET_ID_LONG_FOR= M, true)) { msg(D_CRYPT_ERRORS, "ENCRYPT ERROR: packet ID roll ove= r"); goto err; @@ -253,8 +247,7 @@ ASSERT(buf_write(&work, iv_buf, iv_size)); dmsg(D_PACKET_CONTENT, "ENCRYPT IV: %s", format_hex(iv_buf, iv= _size, 0, &gc)); - dmsg(D_PACKET_CONTENT, "ENCRYPT FROM: %s", - format_hex(BPTR(buf), BLEN(buf), 80, &gc)); + dmsg(D_PACKET_CONTENT, "ENCRYPT FROM: %s", format_hex(BPTR(buf= ), BLEN(buf), 80, &gc)); /* cipher_ctx was already initialized with key & keylen */ ASSERT(cipher_ctx_reset(ctx->cipher, iv_buf)); @@ -262,13 +255,9 @@ /* Buffer overflow check */ if (!buf_safe(&work, buf->len + cipher_ctx_block_size(ctx->cip= her))) { - msg(D_CRYPT_ERRORS, "ENCRYPT: buffer size error, bc=3D%d b= o=3D%d bl=3D%d wc=3D%d wo=3D%d wl=3D%d cbs=3D%d", - buf->capacity, - buf->offset, - buf->len, - work.capacity, - work.offset, - work.len, + msg(D_CRYPT_ERRORS, + "ENCRYPT: buffer size error, bc=3D%d bo=3D%d bl=3D%d w= c=3D%d wo=3D%d wl=3D%d cbs=3D%d", + buf->capacity, buf->offset, buf->len, work.capacity, w= ork.offset, work.len, cipher_ctx_block_size(ctx->cipher)); goto err; } @@ -282,14 +271,13 @@ ASSERT(buf_inc_len(&work, outlen)); /* For all CBC mode ciphers, check the last block is complete = */ - ASSERT(cipher_ctx_mode(ctx->cipher) !=3D OPENVPN_MODE_CBC - || outlen =3D=3D iv_size); + ASSERT(cipher_ctx_mode(ctx->cipher) !=3D OPENVPN_MODE_CBC || o= utlen =3D=3D iv_size); } - else /* No Encryption */ + else /* No Encryption */ { if (packet_id_initialized(&opt->packet_id) - && !packet_id_write(&opt->packet_id.send, buf, - opt->flags & CO_PACKET_ID_LONG_FORM, t= rue)) + && !packet_id_write(&opt->packet_id.send, buf, opt->flags = & CO_PACKET_ID_LONG_FORM, + true)) { msg(D_CRYPT_ERRORS, "ENCRYPT ERROR: packet ID roll over"); goto err; @@ -318,8 +306,7 @@ *buf =3D work; - dmsg(D_PACKET_CONTENT, "ENCRYPT TO: %s", - format_hex(BPTR(&work), BLEN(&work), 80, &gc)); + dmsg(D_PACKET_CONTENT, "ENCRYPT TO: %s", format_hex(BPTR(&work), B= LEN(&work), 80, &gc)); } gc_free(&gc); @@ -333,8 +320,7 @@ } void -openvpn_encrypt(struct buffer *buf, struct buffer work, - struct crypto_options *opt) +openvpn_encrypt(struct buffer *buf, struct buffer work, struct crypto_opti= ons *opt) { if (buf->len > 0 && opt) { @@ -381,10 +367,8 @@ } bool -crypto_check_replay(struct crypto_options *opt, - const struct packet_id_net *pin, uint16_t epoch, - const char *error_prefix, - struct gc_arena *gc) +crypto_check_replay(struct crypto_options *opt, const struct packet_id_net= *pin, uint16_t epoch, + const char *error_prefix, struct gc_arena *gc) { bool ret =3D false; struct packet_id_rec *recv; @@ -401,8 +385,10 @@ { /* We have an epoch that is neither current or old recv key but * is authenticated, ie we need to move to a new current recv key = */ - msg(D_GENKEY, "Received data packet with new epoch %d. Updating " - "receive key", epoch); + msg(D_GENKEY, + "Received data packet with new epoch %d. Updating " + "receive key", + epoch); epoch_replace_update_recv_key(opt, epoch); recv =3D &opt->packet_id.rec; } @@ -421,7 +407,8 @@ { if (!(opt->flags & CO_MUTE_REPLAY_WARNINGS)) { - msg(D_REPLAY_ERRORS, "%s: bad packet ID (may be a replay): %s = -- " + msg(D_REPLAY_ERRORS, + "%s: bad packet ID (may be a replay): %s -- " "see the man page entry for --replay-window for " "more info or silence this warning with --mute-replay-warn= ings", error_prefix, packet_id_net_print(pin, true, gc)); @@ -439,9 +426,8 @@ * On success, buf is set to point to plaintext, true is returned. */ static bool -openvpn_decrypt_aead(struct buffer *buf, struct buffer work, - struct crypto_options *opt, const struct frame *frame, - const uint8_t *ad_start) +openvpn_decrypt_aead(struct buffer *buf, struct buffer work, struct crypto= _options *opt, + const struct frame *frame, const uint8_t *ad_start) { static const char error_prefix[] =3D "AEAD Decrypt error"; struct packet_id_net pin =3D { 0 }; @@ -463,8 +449,7 @@ ASSERT(buf->len > 0); ASSERT(ctx->cipher); - dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", - format_hex(BPTR(buf), BLEN(buf), 80, &gc)); + dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", format_hex(BPTR(buf), BLEN(= buf), 80, &gc)); ASSERT(ad_start >=3D buf->data && ad_start <=3D BPTR(buf)); @@ -572,28 +557,24 @@ /* feed in tag and the authenticated data */ ASSERT(cipher_ctx_update_ad(ctx->cipher, ad_start, ad_size)); - dmsg(D_PACKET_CONTENT, "DECRYPT AD: %s", - format_hex(ad_start, ad_size, 0, &gc)); + dmsg(D_PACKET_CONTENT, "DECRYPT AD: %s", format_hex(ad_start, ad_size,= 0, &gc)); /* Decrypt and authenticate packet */ int outlen; - if (!cipher_ctx_update(ctx->cipher, BPTR(&work), &outlen, BPTR(buf), - data_len)) + if (!cipher_ctx_update(ctx->cipher, BPTR(&work), &outlen, BPTR(buf), d= ata_len)) { CRYPT_ERROR("packet decryption failed"); } ASSERT(buf_inc_len(&work, outlen)); - if (!cipher_ctx_final_check_tag(ctx->cipher, BPTR(&work) + outlen, - &outlen, tag_ptr, tag_size)) + if (!cipher_ctx_final_check_tag(ctx->cipher, BPTR(&work) + outlen, &ou= tlen, tag_ptr, tag_size)) { ctx->failed_verifications++; CRYPT_DROP("packet tag authentication failed"); } ASSERT(buf_inc_len(&work, outlen)); - dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s", - format_hex(BPTR(&work), BLEN(&work), 80, &gc)); + dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s", format_hex(BPTR(&work), BLEN(= &work), 80, &gc)); if (!crypto_check_replay(opt, &pin, epoch, error_prefix, &gc)) { @@ -604,7 +585,7 @@ /* update number of plaintext blocks decrypted. Use the (x + (n-1))/n = trick * to round up the result to the number of blocks used. */ const int blocksize =3D AEAD_LIMIT_BLOCKSIZE; - opt->key_ctx_bi.decrypt.plaintext_blocks +=3D (outlen + (blocksize - 1= ))/blocksize; + opt->key_ctx_bi.decrypt.plaintext_blocks +=3D (outlen + (blocksize - 1= )) / blocksize; *buf =3D work; @@ -627,8 +608,8 @@ * On success, buf is set to point to plaintext, true is returned. */ static bool -openvpn_decrypt_v1(struct buffer *buf, struct buffer work, - struct crypto_options *opt, const struct frame *frame) +openvpn_decrypt_v1(struct buffer *buf, struct buffer work, struct crypto_o= ptions *opt, + const struct frame *frame) { static const char error_prefix[] =3D "Authenticate/Decrypt packet erro= r"; struct gc_arena gc; @@ -640,8 +621,7 @@ struct packet_id_net pin; bool have_pin =3D false; - dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", - format_hex(BPTR(buf), BLEN(buf), 80, &gc)); + dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", format_hex(BPTR(buf), B= LEN(buf), 80, &gc)); /* Verify the HMAC */ if (ctx->hmac) @@ -723,8 +703,7 @@ } ASSERT(buf_inc_len(&work, outlen)); - dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s", - format_hex(BPTR(&work), BLEN(&work), 80, &gc)); + dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s", format_hex(BPTR(&work= ), BLEN(&work), 80, &gc)); /* Get packet ID from plaintext buffer or IV, depending on cip= her mode */ { @@ -732,7 +711,8 @@ { if (packet_id_initialized(&opt->packet_id)) { - if (!packet_id_read(&pin, &work, BOOL_CAST(opt->fl= ags & CO_PACKET_ID_LONG_FORM))) + if (!packet_id_read(&pin, &work, + BOOL_CAST(opt->flags & CO_PACK= ET_ID_LONG_FORM))) { CRYPT_ERROR("error reading CBC packet-id"); } @@ -791,9 +771,8 @@ bool -openvpn_decrypt(struct buffer *buf, struct buffer work, - struct crypto_options *opt, const struct frame *frame, - const uint8_t *ad_start) +openvpn_decrypt(struct buffer *buf, struct buffer work, struct crypto_opti= ons *opt, + const struct frame *frame, const uint8_t *ad_start) { bool ret =3D false; @@ -816,9 +795,7 @@ } unsigned int -calculate_crypto_overhead(const struct key_type *kt, - unsigned int pkt_id_size, - bool occ) +calculate_crypto_overhead(const struct key_type *kt, unsigned int pkt_id_s= ize, bool occ) { unsigned int crypto_overhead =3D 0; @@ -867,9 +844,8 @@ unsigned int crypto_max_overhead(void) { - return packet_id_size(true) + OPENVPN_MAX_IV_LENGTH - +OPENVPN_MAX_CIPHER_BLOCK_SIZE - +max_int(OPENVPN_MAX_HMAC_SIZE, OPENVPN_AEAD_TAG_LENGTH); + return packet_id_size(true) + OPENVPN_MAX_IV_LENGTH + OPENVPN_MAX_CIPH= ER_BLOCK_SIZE + + max_int(OPENVPN_MAX_HMAC_SIZE, OPENVPN_AEAD_TAG_LENGTH); } static void @@ -877,12 +853,13 @@ { if (cipher_kt_insecure(ciphername)) { - msg(M_WARN, "WARNING: INSECURE cipher (%s) with block size less th= an 128" + msg(M_WARN, + "WARNING: INSECURE cipher (%s) with block size less than 128" " bit (%d bit). This allows attacks like SWEET32. Mitigate b= y " "using a --cipher with a larger block size (e.g. AES-256-CBC).= " "Support for these insecure ciphers will be removed in " "OpenVPN 2.7.", - ciphername, cipher_kt_block_size(ciphername)*8); + ciphername, cipher_kt_block_size(ciphername) * 8); } } @@ -890,8 +867,8 @@ * Build a struct key_type. */ void -init_key_type(struct key_type *kt, const char *ciphername, - const char *authname, bool tls_mode, bool warn) +init_key_type(struct key_type *kt, const char *ciphername, const char *aut= hname, bool tls_mode, + bool warn) { bool aead_cipher =3D false; @@ -909,12 +886,11 @@ /* check legal cipher mode */ aead_cipher =3D cipher_kt_mode_aead(kt->cipher); - if (!(cipher_kt_mode_cbc(kt->cipher) - || (tls_mode && aead_cipher) + if (!(cipher_kt_mode_cbc(kt->cipher) || (tls_mode && aead_cipher) #ifdef ENABLE_OFB_CFB_MODE || (tls_mode && cipher_kt_mode_ofb_cfb(kt->cipher)) #endif - )) + )) { msg(M_FATAL, "Cipher '%s' mode not supported", ciphername); } @@ -933,9 +909,9 @@ if (warn) { msg(M_WARN, "******* WARNING *******: '--cipher none' was spec= ified. " - "This means NO encryption will be performed and tunnelled " - "data WILL be transmitted in clear text over the network! " - "PLEASE DO RECONSIDER THIS SETTING!"); + "This means NO encryption will be performed and tu= nnelled " + "data WILL be transmitted in clear text over the n= etwork! " + "PLEASE DO RECONSIDER THIS SETTING!"); } } kt->digest =3D authname; @@ -960,10 +936,10 @@ if (warn) { msg(M_WARN, "******* WARNING *******: '--auth none' was specif= ied. " - "This means no authentication will be performed on receive= d " - "packets, meaning you CANNOT trust that the data received = by " - "the remote side have NOT been manipulated. " - "PLEASE DO RECONSIDER THIS SETTING!"); + "This means no authentication will be performed on= received " + "packets, meaning you CANNOT trust that the data r= eceived by " + "the remote side have NOT been manipulated. " + "PLEASE DO RECONSIDER THIS SETTING!"); } } } @@ -1012,9 +988,8 @@ /* given a key and key_type, build a key_ctx */ void -init_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, - const struct key_type *kt, int enc, - const char *prefix) +init_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, const = struct key_type *kt, + int enc, const char *prefix) { struct gc_arena gc =3D gc_new(); CLEAR(*ctx); @@ -1025,14 +1000,13 @@ cipher_ctx_init(ctx->cipher, key->cipher, kt->cipher, enc); const char *ciphername =3D cipher_kt_name(kt->cipher); - msg(D_CIPHER_INIT, "%s: Cipher '%s' initialized with %d bit key", - prefix, ciphername, cipher_kt_key_size(kt->cipher) * 8); + msg(D_CIPHER_INIT, "%s: Cipher '%s' initialized with %d bit key", = prefix, ciphername, + cipher_kt_key_size(kt->cipher) * 8); dmsg(D_SHOW_KEYS, "%s: CIPHER KEY: %s", prefix, format_hex(key->cipher, cipher_kt_key_size(kt->cipher), 0, &g= c)); - dmsg(D_CRYPTO_DEBUG, "%s: CIPHER block_size=3D%d iv_size=3D%d", - prefix, cipher_kt_block_size(kt->cipher), - cipher_kt_iv_size(kt->cipher)); + dmsg(D_CRYPTO_DEBUG, "%s: CIPHER block_size=3D%d iv_size=3D%d", pr= efix, + cipher_kt_block_size(kt->cipher), cipher_kt_iv_size(kt->ciphe= r)); warn_insecure_key_type(ciphername); } @@ -1042,18 +1016,14 @@ ctx->hmac =3D hmac_ctx_new(); hmac_ctx_init(ctx->hmac, key->hmac, kt->digest); - msg(D_CIPHER_INIT, - "%s: Using %d bit message hash '%s' for HMAC authentication", - prefix, md_kt_size(kt->digest) * 8, md_kt_name(kt->digest)); + msg(D_CIPHER_INIT, "%s: Using %d bit message hash '%s' for HMAC au= thentication", prefix, + md_kt_size(kt->digest) * 8, md_kt_name(kt->digest)); dmsg(D_SHOW_KEYS, "%s: HMAC KEY: %s", prefix, format_hex(key->hmac, md_kt_size(kt->digest), 0, &gc)); - dmsg(D_CRYPTO_DEBUG, "%s: HMAC size=3D%d block_size=3D%d", - prefix, - md_kt_size(kt->digest), + dmsg(D_CRYPTO_DEBUG, "%s: HMAC size=3D%d block_size=3D%d", prefix,= md_kt_size(kt->digest), hmac_ctx_size(ctx->hmac)); - } ctx->epoch =3D key->epoch; gc_free(&gc); @@ -1084,8 +1054,8 @@ } void -init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, - int key_direction, const struct key_type *kt, const char *= name) +init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, int key_d= irection, + const struct key_type *kt, const char *name) { struct key_direction_state kds; @@ -1175,39 +1145,34 @@ struct gc_arena gc =3D gc_new(); CLEAR(*key); - if (!rand_bytes(key->cipher, cipher_len) - || !rand_bytes(key->hmac, hmac_len)) + if (!rand_bytes(key->cipher, cipher_len) || !rand_bytes(key->hmac, hma= c_len)) { msg(M_FATAL, "ERROR: Random number generator cannot obtain entropy= for key generation"); } - dmsg(D_SHOW_KEY_SOURCE, "Cipher source entropy: %s", format_hex(key->c= ipher, cipher_len, 0, &gc)); + dmsg(D_SHOW_KEY_SOURCE, "Cipher source entropy: %s", + format_hex(key->cipher, cipher_len, 0, &gc)); dmsg(D_SHOW_KEY_SOURCE, "HMAC source entropy: %s", format_hex(key->hma= c, hmac_len, 0, &gc)); gc_free(&gc); } static void -key_print(const struct key *key, - const struct key_type *kt, - const char *prefix) +key_print(const struct key *key, const struct key_type *kt, const char *pr= efix) { struct gc_arena gc =3D gc_new(); - dmsg(D_SHOW_KEY_SOURCE, "%s (cipher, %s, %d bits): %s", - prefix, cipher_kt_name(kt->cipher), cipher_kt_key_size(kt->cipher= ) * 8, + dmsg(D_SHOW_KEY_SOURCE, "%s (cipher, %s, %d bits): %s", prefix, cipher= _kt_name(kt->cipher), + cipher_kt_key_size(kt->cipher) * 8, format_hex(key->cipher, cipher_kt_key_size(kt->cipher), 0, &gc)); - dmsg(D_SHOW_KEY_SOURCE, "%s (hmac, %s, %d bits): %s", - prefix, md_kt_name(kt->digest), md_kt_size(kt->digest) * 8, - format_hex(key->hmac, md_kt_size(kt->digest), 0, &gc)); + dmsg(D_SHOW_KEY_SOURCE, "%s (hmac, %s, %d bits): %s", prefix, md_kt_na= me(kt->digest), + md_kt_size(kt->digest) * 8, format_hex(key->hmac, md_kt_size(kt->= digest), 0, &gc)); gc_free(&gc); } /** * Prints the keys in a key2 structure. */ void -key2_print(const struct key2 *k, - const struct key_type *kt, - const char *prefix0, +key2_print(const struct key2 *k, const struct key_type *kt, const char *pr= efix0, const char *prefix1) { ASSERT(k->n =3D=3D 2); @@ -1249,11 +1214,10 @@ ASSERT(cipher_ctx_iv_length(cipher) >=3D OPENVPN_AEAD_MIN_IV_L= EN); /* Generate dummy implicit IV */ - ASSERT(rand_bytes(co->key_ctx_bi.encrypt.implicit_iv, - OPENVPN_MAX_IV_LENGTH)); + ASSERT(rand_bytes(co->key_ctx_bi.encrypt.implicit_iv, OPENVPN_= MAX_IV_LENGTH)); - memcpy(co->key_ctx_bi.decrypt.implicit_iv, - co->key_ctx_bi.encrypt.implicit_iv, OPENVPN_MAX_IV_LENG= TH); + memcpy(co->key_ctx_bi.decrypt.implicit_iv, co->key_ctx_bi.encr= ypt.implicit_iv, + OPENVPN_MAX_IV_LENGTH); } } @@ -1318,11 +1282,9 @@ } void -crypto_read_openvpn_key(const struct key_type *key_type, - struct key_ctx_bi *ctx, const char *key_file, - bool key_inline, const int key_direction, - const char *key_name, const char *opt_name, - struct key2 *keydata) +crypto_read_openvpn_key(const struct key_type *key_type, struct key_ctx_bi= *ctx, + const char *key_file, bool key_inline, const int k= ey_direction, + const char *key_name, const char *opt_name, struct= key2 *keydata) { struct key2 key2; struct key_direction_state kds; @@ -1336,7 +1298,8 @@ =20 if (key2.n !=3D 2) { - msg(M_ERR, "File '%s' does not have OpenVPN Static Key format. Us= ing " + msg(M_ERR, + "File '%s' does not have OpenVPN Static Key format. Using " "free-form passphrase file is not supported anymore.", print_key_filename(key_file, key_inline)); } @@ -1375,7 +1338,7 @@ struct gc_arena gc =3D gc_new(); struct buffer in; int size; - uint8_t hex_byte[3] =3D {0, 0, 0}; + uint8_t hex_byte[3] =3D { 0, 0, 0 }; /* parse info */ const unsigned char *cp; @@ -1385,17 +1348,17 @@ int match =3D 0; /* output */ - uint8_t *out =3D (uint8_t *) &key2->keys; + uint8_t *out =3D (uint8_t *)&key2->keys; const int keylen =3D sizeof(key2->keys); int count =3D 0; /* parse states */ -#define PARSE_INITIAL 0 -#define PARSE_HEAD 1 -#define PARSE_DATA 2 -#define PARSE_DATA_COMPLETE 3 -#define PARSE_FOOT 4 -#define PARSE_FINISHED 5 +#define PARSE_INITIAL 0 +#define PARSE_HEAD 1 +#define PARSE_DATA 2 +#define PARSE_DATA_COMPLETE 3 +#define PARSE_FOOT 4 +#define PARSE_FINISHED 5 int state =3D PARSE_INITIAL; /* constants */ @@ -1507,11 +1470,9 @@ } else { - msg(M_FATAL, - (isprint(c) ? printable_char_fmt : unprintable_cha= r_fmt), - c, line_num, - print_key_filename(file, flags & RKF_INLINE), coun= t, - onekeylen, keylen); + msg(M_FATAL, (isprint(c) ? printable_char_fmt : unprin= table_char_fmt), c, + line_num, print_key_filename(file, flags & RKF_INL= INE), count, onekeylen, + keylen); } } ++line_index; @@ -1525,22 +1486,21 @@ */ key2->n =3D count / onekeylen; - ASSERT(key2->n >=3D 0 && key2->n <=3D (int) SIZE(key2->keys)); + ASSERT(key2->n >=3D 0 && key2->n <=3D (int)SIZE(key2->keys)); if (flags & RKF_MUST_SUCCEED) { if (!key2->n) { - msg(M_FATAL, "Insufficient key material or header text not fou= nd in file '%s' (%d/%d/%d bytes found/min/max)", - print_key_filename(file, flags & RKF_INLINE), count, oneke= ylen, - keylen); + msg(M_FATAL, + "Insufficient key material or header text not found in fil= e '%s' (%d/%d/%d bytes found/min/max)", + print_key_filename(file, flags & RKF_INLINE), count, oneke= ylen, keylen); } if (state !=3D PARSE_FINISHED) { msg(M_FATAL, "Footer text not found in file '%s' (%d/%d/%d byt= es found/min/max)", - print_key_filename(file, flags & RKF_INLINE), count, oneke= ylen, - keylen); + print_key_filename(file, flags & RKF_INLINE), count, oneke= ylen, keylen); } } @@ -1599,12 +1559,7 @@ generate_key_random(&key); /* format key as ascii */ - fmt =3D format_hex_ex((const uint8_t *)&key, - sizeof(key), - 0, - bytes_per_line, - "\n", - &gc); + fmt =3D format_hex_ex((const uint8_t *)&key, sizeof(key), 0, bytes= _per_line, "\n", &gc); /* write to holding buffer */ buf_printf(&out, "%s\n", fmt); @@ -1617,7 +1572,7 @@ buf_printf(&out, "%s\n", static_key_foot); /* write key file to stdout if no filename given */ - if (!filename || strcmp(filename, "")=3D=3D0) + if (!filename || strcmp(filename, "") =3D=3D 0) { printf("%.*s\n", BLEN(&out), BPTR(&out)); } @@ -1642,9 +1597,14 @@ if (key2->n < n) { #ifdef ENABLE_SMALL - msg(M_FATAL, "Key file '%s' used in --%s contains insufficient key= material [keys found=3D%d required=3D%d]", filename, option, key2->n, n); + msg(M_FATAL, + "Key file '%s' used in --%s contains insufficient key material= [keys found=3D%d required=3D%d]", + filename, option, key2->n, n); #else - msg(M_FATAL, "Key file '%s' used in --%s contains insufficient key= material [keys found=3D%d required=3D%d] -- try generating a new key file = with '" PACKAGE " --genkey secret [file]', or use the existing key file in = bidirectional mode by specifying --%s without a key direction parameter", f= ilename, option, key2->n, n, option); + msg(M_FATAL, + "Key file '%s' used in --%s contains insufficient key material= [keys found=3D%d required=3D%d] -- try generating a new key file with '" P= ACKAGE + " --genkey secret [file]', or use the existing key file in bid= irectional mode by specifying --%s without a key direction parameter", + filename, option, key2->n, n, option); #endif } } @@ -1740,8 +1700,8 @@ /* This should be a very improbable failure */ if (!check_key(&key2->keys[i], kt)) { - msg(M_FATAL, "Key #%d in '%s' is bad. Try making a new key wi= th --genkey.", - i+1, shared_secret_file); + msg(M_FATAL, "Key #%d in '%s' is bad. Try making a new key wi= th --genkey.", i + 1, + shared_secret_file); } } } @@ -1768,9 +1728,7 @@ void print_cipher(const char *ciphername) { - printf("%s (%d bit key, ", - cipher_kt_name(ciphername), - cipher_kt_key_size(ciphername) * 8); + printf("%s (%d bit key, ", cipher_kt_name(ciphername), cipher_kt_key_= size(ciphername) * 8); if (cipher_kt_block_size(ciphername) =3D=3D 1) { @@ -1856,14 +1814,13 @@ goto cleanup; } buf_set_read(&server_key_buf, (void *)&server_key, sizeof(server_key)); - if (!crypto_pem_encode(pem_name, &server_key_pem, - &server_key_buf, &gc)) + if (!crypto_pem_encode(pem_name, &server_key_pem, &server_key_buf, &gc= )) { msg(M_WARN, "ERROR: could not PEM-encode key"); goto cleanup; } - if (!filename || strcmp(filename, "")=3D=3D0) + if (!filename || strcmp(filename, "") =3D=3D 0) { printf("%.*s", BLEN(&server_key_pem), BPTR(&server_key_pem)); } @@ -1899,8 +1856,7 @@ } bool -read_pem_key_file(struct buffer *key, const char *pem_name, - const char *key_file, bool key_inline) +read_pem_key_file(struct buffer *key, const char *pem_name, const char *ke= y_file, bool key_inline) { bool ret =3D false; struct buffer key_pem =3D { 0 }; @@ -1911,8 +1867,7 @@ key_pem =3D buffer_read_from_file(key_file, &gc); if (!buf_valid(&key_pem)) { - msg(M_WARN, "ERROR: failed to read %s file (%s)", - pem_name, key_file); + msg(M_WARN, "ERROR: failed to read %s file (%s)", pem_name, ke= y_file); goto cleanup; } } @@ -1949,9 +1904,8 @@ uint8_t out[8]; uint8_t expected_out[] =3D { 'q', 'D', '\xfe', '%', '@', 's', 'u', '\x= 95' }; - int ret =3D ssl_tls1_PRF((uint8_t *)seed, (int) strlen(seed), - (uint8_t *)secret, (int) strlen(secret), - out, sizeof(out)); + int ret =3D ssl_tls1_PRF((uint8_t *)seed, (int)strlen(seed), (uint8_t = *)secret, + (int)strlen(secret), out, sizeof(out)); return (ret && memcmp(out, expected_out, sizeof(out)) =3D=3D 0); } diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index 68ad901..216d798 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -130,7 +130,8 @@ #include "mtu.h" /** Wrapper struct to pass around SHA256 digests */ -struct sha256_digest { +struct sha256_digest +{ uint8_t digest[SHA256_DIGEST_LENGTH]; }; @@ -139,8 +140,8 @@ */ struct key_type { - const char *cipher; /**< const name of the cipher */ - const char *digest; /**< Message digest static parameters */ + const char *cipher; /**< const name of the cipher */ + const char *digest; /**< Message digest static parameters */ }; /** @@ -159,7 +160,8 @@ /** internal structure similar to struct key that holds key information * but is not represented on wire and can be changed/extended */ -struct key_parameters { +struct key_parameters +{ /** %Key material for cipher operations. */ uint8_t cipher[MAX_CIPHER_KEY_LENGTH]; @@ -185,10 +187,10 @@ * @param key_params destination for the converted struct * @param key source of the conversion */ -void -key_parameters_from_key(struct key_parameters *key_params, const struct ke= y *key); +void key_parameters_from_key(struct key_parameters *key_params, const stru= ct key *key); -struct epoch_key { +struct epoch_key +{ uint8_t epoch_key[SHA256_DIGEST_LENGTH]; uint16_t epoch; }; @@ -199,8 +201,8 @@ */ struct key_ctx { - cipher_ctx_t *cipher; /**< Generic cipher %context. */ - hmac_ctx_t *hmac; /**< Generic HMAC %context. */ + cipher_ctx_t *cipher; /**< Generic cipher %context. */ + hmac_ctx_t *hmac; /**< Generic HMAC %context. */ /** * This implicit IV will be always XORed with the packet id that is se= nt on * the wire to get the IV. For the common AEAD ciphers of AES-GCM and @@ -214,7 +216,7 @@ */ uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH]; /**< The implicit part of the IV */ - size_t implicit_iv_len; /**< The length of implicit_iv */ + size_t implicit_iv_len; /**< The length of implicit_iv */ /** Counter for the number of plaintext block encrypted using this cip= her * with the current key in number of 128 bit blocks (only used for * AEAD ciphers) */ @@ -237,12 +239,12 @@ */ struct key2 { - int n; /**< The number of \c key objects stored - * in the \c key2.keys array. */ - struct key keys[2]; /**< Two unidirectional sets of %key - * material. The first key is the client - * (encrypts) to server (decrypts), the - * second the server to client key. */ + int n; /**< The number of \c key objects stored + * in the \c key2.keys array. */ + struct key keys[2]; /**< Two unidirectional sets of %key + * material. The first key is the client + * (encrypts) to server (decrypts), the + * second the server to client key. */ }; /** @@ -256,18 +258,18 @@ */ struct key_direction_state { - int out_key; /**< Index into the \c key2.keys array for - * the sending direction. */ - int in_key; /**< Index into the \c key2.keys array for - * the receiving direction. */ - int need_keys; /**< The number of key objects necessary - * to support both sending and - * receiving. - * - * This will be 1 if the same keys are - * used in both directions, or 2 if - * there are two sets of unidirectional - * keys. */ + int out_key; /**< Index into the \c key2.keys array for + * the sending direction. */ + int in_key; /**< Index into the \c key2.keys array for + * the receiving direction. */ + int need_keys; /**< The number of key objects necessary + * to support both sending and + * receiving. + * + * This will be 1 if the same keys are + * used in both directions, or 2 if + * there are two sets of unidirectional + * keys. */ }; /** @@ -277,10 +279,10 @@ */ struct key_ctx_bi { - struct key_ctx encrypt; /**< Cipher and/or HMAC contexts for sendi= ng - * direction. */ - struct key_ctx decrypt; /**< cipher and/or HMAC contexts for - * receiving direction. */ + struct key_ctx encrypt; /**< Cipher and/or HMAC contexts for sending + * direction. */ + struct key_ctx decrypt; /**< cipher and/or HMAC contexts for + * receiving direction. */ bool initialized; }; @@ -341,54 +343,58 @@ * keeping state between successive * OpenVPN process startups. */ -#define CO_PACKET_ID_LONG_FORM (1<<0) +#define CO_PACKET_ID_LONG_FORM (1 << 0) /**< Bit-flag indicating whether to use - * OpenVPN's long packet ID format. */ -#define CO_IGNORE_PACKET_ID (1<<1) + * OpenVPN's long packet ID format. */ +#define CO_IGNORE_PACKET_ID (1 << 1) /**< Bit-flag indicating whether to ignore * the packet ID of a received packet. * This flag is used during processing * of the first packet received from a * client. */ -#define CO_MUTE_REPLAY_WARNINGS (1<<2) +#define CO_MUTE_REPLAY_WARNINGS (1 << 2) /**< Bit-flag indicating not to display * replay warnings. */ -#define CO_USE_TLS_KEY_MATERIAL_EXPORT (1<<3) +#define CO_USE_TLS_KEY_MATERIAL_EXPORT (1 << 3) /**< Bit-flag indicating that data channel key derivation * is done using TLS keying material export [RFC5705] */ -#define CO_RESEND_WKC (1<<4) +#define CO_RESEND_WKC (1 << 4) /**< Bit-flag indicating that the client is expected to * resend the wrapped client key with the 2nd packet (packet-id 1) * like with the HARD_RESET_CLIENT_V3 packet */ -#define CO_FORCE_TLSCRYPTV2_COOKIE (1<<5) +#define CO_FORCE_TLSCRYPTV2_COOKIE (1 << 5) /**< Bit-flag indicating that we do not allow clients that do * not support resending the wrapped client key (WKc) with the * third packet of the three-way handshake */ -#define CO_USE_CC_EXIT_NOTIFY (1<<6) +#define CO_USE_CC_EXIT_NOTIFY (1 << 6) /**< Bit-flag indicating that explicit exit notifies should be * sent via the control channel instead of using an OCC message */ -#define CO_USE_DYNAMIC_TLS_CRYPT (1<<7) +#define CO_USE_DYNAMIC_TLS_CRYPT (1 << 7) /**< Bit-flag indicating that renegotiations are using tls-crypt * with a TLS-EKM derived key. */ -#define CO_EPOCH_DATA_KEY_FORMAT (1<<8) +#define CO_EPOCH_DATA_KEY_FORMAT (1 << 8) /**< Bit-flag indicating the epoch the data format. This format * has the AEAD tag at the end of the packet and is using a longer * 64-bit packet id that is split into a 16 bit epoch and 48 bit * epoch counter */ - unsigned int flags; /**< Bit-flags determining behavior of - * security operation functions. */ + unsigned int flags; /**< Bit-flags determining behavior of + * security operation functions. */ }; -#define CRYPT_ERROR_EXIT(flags, format) \ - do { msg(flags, "%s: " format, error_prefix); goto error_exit; } while= (false) +#define CRYPT_ERROR_EXIT(flags, format) \ + do \ + { \ + msg(flags, "%s: " format, error_prefix); \ + goto error_exit; \ + } while (false) #define CRYPT_ERROR(format) CRYPT_ERROR_EXIT(D_CRYPT_ERRORS, format) -#define CRYPT_DROP(format) CRYPT_ERROR_EXIT(D_MULTI_DROPPED, format) +#define CRYPT_DROP(format) CRYPT_ERROR_EXIT(D_MULTI_DROPPED, format) /** * Minimal IV length for AEAD mode ciphers (in bytes): @@ -396,8 +402,8 @@ */ #define OPENVPN_AEAD_MIN_IV_LEN (sizeof(packet_id_type) + 8) -#define RKF_MUST_SUCCEED (1<<0) -#define RKF_INLINE (1<<1) +#define RKF_MUST_SUCCEED (1 << 0) +#define RKF_INLINE (1 << 1) void read_key_file(struct key2 *key2, const char *file, const unsigned int= flags); /** @@ -419,30 +425,26 @@ * more ciphers than static key mode. * @param warn Print warnings when null cipher / auth is used. */ -void init_key_type(struct key_type *kt, const char *ciphername, - const char *authname, bool tls_mode, bool warn); +void init_key_type(struct key_type *kt, const char *ciphername, const char= *authname, bool tls_mode, + bool warn); /* * Key context functions */ -void init_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, - const struct key_type *kt, int enc, - const char *prefix); +void init_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, c= onst struct key_type *kt, + int enc, const char *prefix); -void -init_key_bi_ctx_send(struct key_ctx *ctx, const struct key_parameters *key, - const struct key_type *kt, const char *name); +void init_key_bi_ctx_send(struct key_ctx *ctx, const struct key_parameters= *key, + const struct key_type *kt, const char *name); -void -init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key_parameters *key, - const struct key_type *kt, const char *name); +void init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key_parameters= *key, + const struct key_type *kt, const char *name); void free_key_ctx(struct key_ctx *ctx); -void init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, - int key_direction, const struct key_type *kt, - const char *name); +void init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, int = key_direction, + const struct key_type *kt, const char *name); void free_key_ctx_bi(struct key_ctx_bi *ctx); @@ -477,8 +479,7 @@ * contain the processed packet ready for sending, or be empty if an * error occurred. */ -void openvpn_encrypt(struct buffer *buf, struct buffer work, - struct crypto_options *opt); +void openvpn_encrypt(struct buffer *buf, struct buffer work, struct crypto= _options *opt); /** @@ -514,9 +515,8 @@ * the plaintext packet ready for further processing, or be empty if * an error occurred. */ -bool openvpn_decrypt(struct buffer *buf, struct buffer work, - struct crypto_options *opt, const struct frame *frame, - const uint8_t *ad_start); +bool openvpn_decrypt(struct buffer *buf, struct buffer work, struct crypto= _options *opt, + const struct frame *frame, const uint8_t *ad_start); /** @} name Functions for performing security operations on data channel p= ackets */ @@ -531,11 +531,8 @@ * * @return true if packet ID is validated to be not a replay, false otherw= ise. */ -bool crypto_check_replay(struct crypto_options *opt, - const struct packet_id_net *pin, - uint16_t epoch, - const char *error_prefix, - struct gc_arena *gc); +bool crypto_check_replay(struct crypto_options *opt, const struct packet_i= d_net *pin, + uint16_t epoch, const char *error_prefix, struct = gc_arena *gc); =20 /** Calculate the maximum overhead that our encryption has @@ -551,10 +548,8 @@ * incorrect way as all previous OpenVPN versions did= , to * end up with identical numbers for OCC compatibility */ -unsigned int -calculate_crypto_overhead(const struct key_type *kt, - unsigned int pkt_id_size, - bool occ); +unsigned int calculate_crypto_overhead(const struct key_type *kt, unsigned= int pkt_id_size, + bool occ); /** Return the worst-case OpenVPN crypto overhead (in bytes) */ unsigned int crypto_max_overhead(void); @@ -566,8 +561,7 @@ * @param filename Filename of the server key file to create. * @param key_name The name to use in the PEM header/footer. */ -void -write_pem_key_file(const char *filename, const char *key_name); +void write_pem_key_file(const char *filename, const char *key_name); /** * Generate ephermal key material into the key structure @@ -576,8 +570,7 @@ * @param pem_name the name used for logging * @return true if key generation was successful */ -bool -generate_ephemeral_key(struct buffer *key, const char *pem_name); +bool generate_ephemeral_key(struct buffer *key, const char *pem_name); /** * Read key material from a PEM encoded files into the key structure @@ -589,9 +582,8 @@ * otherwise. * @return true if reading into key was successful */ -bool -read_pem_key_file(struct buffer *key, const char *pem_name, - const char *key_file, bool key_inline); +bool read_pem_key_file(struct buffer *key, const char *pem_name, const cha= r *key_file, + bool key_inline); /* * Message digest-based pseudo random number generator. @@ -632,16 +624,12 @@ const char *keydirection2ascii(int kd, bool remote, bool humanreadable); /* print keys */ -void key2_print(const struct key2 *k, - const struct key_type *kt, - const char *prefix0, +void key2_print(const struct key2 *k, const struct key_type *kt, const cha= r *prefix0, const char *prefix1); -void crypto_read_openvpn_key(const struct key_type *key_type, - struct key_ctx_bi *ctx, const char *key_file, - bool key_inline, const int key_direction, - const char *key_name, const char *opt_name, - struct key2 *keydata); +void crypto_read_openvpn_key(const struct key_type *key_type, struct key_c= tx_bi *ctx, + const char *key_file, bool key_inline, const = int key_direction, + const char *key_name, const char *opt_name, s= truct key2 *keydata); /* * Inline functions @@ -691,12 +679,12 @@ if (cipher_defined(kt.cipher) && !cipher_valid(kt.cipher)) { msg(M_WARN, "ERROR: --%s requires %s support.", optname, kt.cipher= ); - return (struct key_type) { 0 }; + return (struct key_type){ 0 }; } if (md_defined(kt.digest) && !md_valid(kt.digest)) { msg(M_WARN, "ERROR: --%s requires %s support.", optname, kt.digest= ); - return (struct key_type) { 0 }; + return (struct key_type){ 0 }; } return kt; @@ -711,8 +699,7 @@ * For reference see the OpenVPN RFC draft and * https://www.ietf.org/archive/id/draft-irtf-cfrg-aead-limits-08.html */ -uint64_t -cipher_get_aead_limits(const char *ciphername); +uint64_t cipher_get_aead_limits(const char *ciphername); /** * Check if the number of failed decryption is over the acceptable limit. @@ -725,7 +712,7 @@ * but we accept slightly lower security bound for the edge * of Chacha20-Poly1305 and packets over 16k as MTUs over 16k are * extremely rarely used */ - return ctx->failed_verifications > (1ull << 36); + return ctx->failed_verifications > (1ull << 36); } /** @@ -736,7 +723,7 @@ cipher_decrypt_verify_fail_warn(const struct key_ctx *ctx) { /* Use 2**35, half the amount after which we refuse to decrypt */ - return ctx->failed_verifications > (1ull << 35); + return ctx->failed_verifications > (1ull << 35); } @@ -745,7 +732,7 @@ * * Since cipher_ctx_block_size() is not reliable and will return 1 in many * cases use a hardcoded blocksize instead */ -#define AEAD_LIMIT_BLOCKSIZE 16 +#define AEAD_LIMIT_BLOCKSIZE 16 /** * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 @@ -762,13 +749,12 @@ * to read. */ static inline bool -aead_usage_limit_reached(const uint64_t limit, const struct key_ctx *key_c= tx, - int64_t higest_pid) +aead_usage_limit_reached(const uint64_t limit, const struct key_ctx *key_c= tx, int64_t higest_pid) { /* This is the q + s <=3D p^(1/2) * 2^(129/2) - 1 calculation where * q is the number of protected messages (highest_pid) * s Total plaintext length in all messages (in blocks) */ - return (limit > 0 && key_ctx->plaintext_blocks + (uint64_t) higest_pid= > limit); + return (limit > 0 && key_ctx->plaintext_blocks + (uint64_t)higest_pid = > limit); } #endif /* CRYPTO_H */ diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h index 8bb7f47..239724c 100644 --- a/src/openvpn/crypto_backend.h +++ b/src/openvpn/crypto_backend.h @@ -46,18 +46,20 @@ #define OPENVPN_MAX_CIPHER_BLOCK_SIZE 32 /* Maximum HMAC digest size (bytes) */ -#define OPENVPN_MAX_HMAC_SIZE 64 +#define OPENVPN_MAX_HMAC_SIZE 64 /** Types referencing specific message digest hashing algorithms */ -typedef enum { +typedef enum +{ MD_SHA1, MD_SHA256 } hash_algo_type; /** Struct used in cipher name translation table */ -typedef struct { - const char *openvpn_name; /**< Cipher name used by OpenVPN */ - const char *lib_name; /**< Cipher name used by crypto library */ +typedef struct +{ + const char *openvpn_name; /**< Cipher name used by OpenVPN */ + const char *lib_name; /**< Cipher name used by crypto library */ } cipher_name_pair; /** Cipher name translation table */ @@ -123,8 +125,8 @@ * * @return true iff PEM encode succeeded. */ -bool crypto_pem_encode(const char *name, struct buffer *dst, - const struct buffer *src, struct gc_arena *gc); +bool crypto_pem_encode(const char *name, struct buffer *dst, const struct = buffer *src, + struct gc_arena *gc); /** * Decode a PEM buffer to binary data. @@ -135,8 +137,7 @@ * * @return true iff PEM decode succeeded. */ -bool crypto_pem_decode(const char *name, struct buffer *dst, - const struct buffer *src); +bool crypto_pem_decode(const char *name, struct buffer *dst, const struct = buffer *src); /* * @@ -339,8 +340,8 @@ * @param enc Whether to encrypt or decrypt (either * \c OPENVPN_OP_ENCRYPT or \c OPENVPN_OP_DECRYPT). */ -void cipher_ctx_init(cipher_ctx_t *ctx, const uint8_t *key, - const char *ciphername, crypto_operation_t enc); +void cipher_ctx_init(cipher_ctx_t *ctx, const uint8_t *key, const char *ci= phername, + crypto_operation_t enc); /** * Returns the size of the IV used by the cipher, in bytes, or 0 if no IV = is @@ -448,8 +449,7 @@ * * @return \c 0 on failure, \c 1 on success. */ -int cipher_ctx_update(cipher_ctx_t *ctx, uint8_t *dst, int *dst_len, - uint8_t *src, int src_len); +int cipher_ctx_update(cipher_ctx_t *ctx, uint8_t *dst, int *dst_len, uint8= _t *src, int src_len); /** * Pads the final cipher block using PKCS padding, and output to the desti= nation @@ -476,8 +476,8 @@ * * @return \c 0 on failure, \c 1 on success. */ -int cipher_ctx_final_check_tag(cipher_ctx_t *ctx, uint8_t *dst, int *dst_l= en, - uint8_t *tag, size_t tag_len); +int cipher_ctx_final_check_tag(cipher_ctx_t *ctx, uint8_t *dst, int *dst_l= en, uint8_t *tag, + size_t tag_len); /* @@ -717,7 +717,7 @@ * * @return true if successful, false on any error */ -bool ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, - int secret_len, uint8_t *output, int output_len); +bool ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret= , int secret_len, + uint8_t *output, int output_len); #endif /* CRYPTO_BACKEND_H_ */ diff --git a/src/openvpn/crypto_epoch.c b/src/openvpn/crypto_epoch.c index 14727c7..9c00c50 100644 --- a/src/openvpn/crypto_epoch.c +++ b/src/openvpn/crypto_epoch.c @@ -40,9 +40,8 @@ #include "integer.h" void -ovpn_hkdf_expand(const uint8_t *secret, - const uint8_t *info, int info_len, - uint8_t *out, int out_len) +ovpn_hkdf_expand(const uint8_t *secret, const uint8_t *info, int info_len,= uint8_t *out, + int out_len) { hmac_ctx_t *hmac_ctx =3D hmac_ctx_new(); hmac_ctx_init(hmac_ctx, secret, "SHA256"); @@ -75,13 +74,10 @@ } bool -ovpn_expand_label(const uint8_t *secret, size_t secret_len, - const uint8_t *label, size_t label_len, - const uint8_t *context, size_t context_len, - uint8_t *out, uint16_t out_len) +ovpn_expand_label(const uint8_t *secret, size_t secret_len, const uint8_t = *label, size_t label_len, + const uint8_t *context, size_t context_len, uint8_t *out= , uint16_t out_len) { - if (secret_len !=3D 32 || label_len > 250 || context_len > 255 - || label_len < 1) + if (secret_len !=3D 32 || label_len > 250 || context_len > 255 || labe= l_len < 1) { /* Our current implementation is not a general purpose one * and assumes that the secret size matches the size of the @@ -93,7 +89,7 @@ struct gc_arena gc =3D gc_new(); /* 2 byte for the outlen encoded as uint16, 5 bytes for "ovpn ", * 1 byte for context len byte and 1 byte for label len byte */ - const uint8_t *label_prefix =3D (const uint8_t *) ("ovpn "); + const uint8_t *label_prefix =3D (const uint8_t *)("ovpn "); int prefix_len =3D 5; int hkdf_label_len =3D 2 + prefix_len + 1 + label_len + 1 + context_le= n; @@ -112,8 +108,7 @@ ASSERT(buf_len(&hkdf_label) =3D=3D hkdf_label_len); - ovpn_hkdf_expand(secret, buf_bptr(&hkdf_label), - buf_len(&hkdf_label), out, out_len); + ovpn_hkdf_expand(secret, buf_bptr(&hkdf_label), buf_len(&hkdf_label), = out, out_len); gc_free(&gc); return true; @@ -134,16 +129,14 @@ const size_t epoch_update_label_len =3D sizeof(epoch_update_label) - 1; /* E_N+1 =3D OVPN-Expand-Label(E_N, "datakey upd", "", 32) */ - ovpn_expand_label(epoch_key->epoch_key, sizeof(epoch_key->epoch_key), - epoch_update_label, epoch_update_label_len, - NULL, 0, - new_epoch_key.epoch_key, sizeof(new_epoch_key.epoch_= key)); + ovpn_expand_label(epoch_key->epoch_key, sizeof(epoch_key->epoch_key), = epoch_update_label, + epoch_update_label_len, NULL, 0, new_epoch_key.epoch= _key, + sizeof(new_epoch_key.epoch_key)); *epoch_key =3D new_epoch_key; } void -epoch_data_key_derive(struct key_parameters *key, - const struct epoch_key *epoch_key, +epoch_data_key_derive(struct key_parameters *key, const struct epoch_key *= epoch_key, const struct key_type *kt) { key->hmac_size =3D cipher_kt_iv_size(kt->cipher); @@ -158,19 +151,16 @@ /* length of the array without extra \0 byte from the string */ const size_t epoch_data_key_label_len =3D sizeof(epoch_data_key_label)= - 1; - ovpn_expand_label(epoch_key->epoch_key, sizeof(epoch_key->epoch_key), - epoch_data_key_label, epoch_data_key_label_len, - NULL, 0, - (uint8_t *)(&key->cipher), key->cipher_size); + ovpn_expand_label(epoch_key->epoch_key, sizeof(epoch_key->epoch_key), = epoch_data_key_label, + epoch_data_key_label_len, NULL, 0, (uint8_t *)(&key-= >cipher), + key->cipher_size); const uint8_t epoch_data_iv_label[] =3D "data_iv"; /* length of the array without extra \0 byte from the string */ const size_t epoch_data_iv_label_len =3D sizeof(epoch_data_iv_label) -= 1; - ovpn_expand_label(epoch_key->epoch_key, sizeof(epoch_key->epoch_key), - epoch_data_iv_label, epoch_data_iv_label_len, - NULL, 0, - (uint8_t *)(&key->hmac), key->hmac_size); + ovpn_expand_label(epoch_key->epoch_key, sizeof(epoch_key->epoch_key), = epoch_data_iv_label, + epoch_data_iv_label_len, NULL, 0, (uint8_t *)(&key->= hmac), key->hmac_size); key->epoch =3D epoch_key->epoch; } @@ -188,8 +178,7 @@ epoch_data_key_derive(&send_key, &co->epoch_key_send, &co->epoch_key_t= ype); - init_key_bi_ctx_send(&co->key_ctx_bi.encrypt, &send_key, - &co->epoch_key_type, name); + init_key_bi_ctx_send(&co->key_ctx_bi.encrypt, &send_key, &co->epoch_ke= y_type, name); reset_packet_id_send(&co->packet_id.send); CLEAR(send_key); } @@ -220,10 +209,10 @@ /* Either we have not generated any future keys yet (first initialisat= ion) * or the last index is the same as our current epoch key * (last generated receive epoch key should match the epoch key) */ - struct key_ctx *highest_future_key =3D &co->epoch_data_keys_future[co-= >epoch_data_keys_future_count - 1]; + struct key_ctx *highest_future_key =3D + &co->epoch_data_keys_future[co->epoch_data_keys_future_count - 1]; - ASSERT(co->epoch_key_recv.epoch =3D=3D 1 - || highest_future_key->epoch =3D=3D co->epoch_key_recv.epoch); + ASSERT(co->epoch_key_recv.epoch =3D=3D 1 || highest_future_key->epoch = =3D=3D co->epoch_key_recv.epoch); /* free the keys that are not used anymore */ for (uint16_t i =3D 0; i < co->epoch_data_keys_future_count; i++) @@ -251,12 +240,12 @@ { ASSERT(co->epoch_data_keys_future[i].epoch =3D=3D 0); } - memmove(co->epoch_data_keys_future, - co->epoch_data_keys_future + num_keys_generate, + memmove(co->epoch_data_keys_future, co->epoch_data_keys_future + num_k= eys_generate, (co->epoch_data_keys_future_count - num_keys_generate) * sizeo= f(struct key_ctx)); /* Clear and regenerate the array elements at the end */ - for (uint16_t i =3D co->epoch_data_keys_future_count - num_keys_genera= te; i < co->epoch_data_keys_future_count; i++) + for (uint16_t i =3D co->epoch_data_keys_future_count - num_keys_genera= te; + i < co->epoch_data_keys_future_count; i++) { CLEAR(co->epoch_data_keys_future[i]); epoch_key_iterate(&co->epoch_key_recv); @@ -281,8 +270,7 @@ } void -epoch_replace_update_recv_key(struct crypto_options *co, - uint16_t new_epoch) +epoch_replace_update_recv_key(struct crypto_options *co, uint16_t new_epoc= h) { /* Find the key of the new epoch in future keys */ uint16_t fki; @@ -351,8 +339,7 @@ void epoch_init_key_ctx(struct crypto_options *co, const struct key_type *key_t= ype, - const struct epoch_key *e1_send, - const struct epoch_key *e1_recv, + const struct epoch_key *e1_send, const struct epoch_key= *e1_recv, uint16_t future_key_count) { ASSERT(e1_send->epoch =3D=3D 1 && e1_recv->epoch =3D=3D 1); @@ -442,11 +429,9 @@ * decryption fail warn limit. * */ else if (opt->key_ctx_bi.encrypt.epoch =3D=3D opt->key_ctx_bi.decr= ypt.epoch - && (aead_usage_limit_reached(opt->aead_usage_limit, - &opt->key_ctx_bi.decrypt, + && (aead_usage_limit_reached(opt->aead_usage_limit, &opt-= >key_ctx_bi.decrypt, opt->packet_id.rec.id) - || cipher_decrypt_verify_fail_warn(&opt->key_ctx_bi.d= ecrypt) - )) + || cipher_decrypt_verify_fail_warn(&opt->key_ctx_bi.d= ecrypt))) { /* Receive key limit reached. Increase our own send key to sig= nal * that we want to use a new epoch. Peer should then also move= its @@ -459,5 +444,4 @@ { epoch_iterate_send_key(opt); } - } diff --git a/src/openvpn/crypto_epoch.h b/src/openvpn/crypto_epoch.h index c16f966..67a2240 100644 --- a/src/openvpn/crypto_epoch.h +++ b/src/openvpn/crypto_epoch.h @@ -39,10 +39,8 @@ * @param out output keying material * @param out_len length of output keying material */ -void -ovpn_hkdf_expand(const uint8_t *secret, - const uint8_t *info, int info_len, - uint8_t *out, int out_len); +void ovpn_hkdf_expand(const uint8_t *secret, const uint8_t *info, int info= _len, uint8_t *out, + int out_len); /** * Variant of the RFC 8446 TLS 1.3 HKDF-Expand-Label function with the @@ -61,11 +59,9 @@ * @param out_len length of output keying material * @return */ -bool -ovpn_expand_label(const uint8_t *secret, size_t secret_len, - const uint8_t *label, size_t label_len, - const uint8_t *context, size_t context_len, - uint8_t *out, uint16_t out_len); +bool ovpn_expand_label(const uint8_t *secret, size_t secret_len, const uin= t8_t *label, + size_t label_len, const uint8_t *context, size_t co= ntext_len, uint8_t *out, + uint16_t out_len); /** * Generate a data channel key pair from the epoch key @@ -73,10 +69,8 @@ * @param epoch_key Epoch key to be used * @param kt Cipher information to generate the data channel ke= y for */ -void -epoch_data_key_derive(struct key_parameters *key, - const struct epoch_key *epoch_key, - const struct key_type *kt); +void epoch_data_key_derive(struct key_parameters *key, const struct epoch_= key *epoch_key, + const struct key_type *kt); /** * Generates and fills the epoch_data_keys_future with next valid @@ -91,8 +85,7 @@ * free the ones that are older than the crypto_options.key_ctx_bi.decrypt= and * generate the keys from the newer epoch. */ -void -epoch_generate_future_receive_keys(struct crypto_options *co); +void epoch_generate_future_receive_keys(struct crypto_options *co); /** This is called when the peer uses a new send key that is not the defau= lt @@ -103,21 +96,17 @@ * @param co crypto_options to update * @param new_epoch the new epoch to use for the receive key */ -void -epoch_replace_update_recv_key(struct crypto_options *co, - uint16_t new_epoch); +void epoch_replace_update_recv_key(struct crypto_options *co, uint16_t new= _epoch); /** * Updates the send key and send_epoch_key in cryptio_options->key_ctx_bi = to * use the next epoch */ -void -epoch_iterate_send_key(struct crypto_options *co); +void epoch_iterate_send_key(struct crypto_options *co); /** * Frees the extra data structures used by epoch keys in \c crypto_options */ -void -free_epoch_key_ctx(struct crypto_options *co); +void free_epoch_key_ctx(struct crypto_options *co); /** * Initialises data channel keys and internal structures for epoch data ke= ys @@ -132,10 +121,9 @@ * @param future_key_count the number of future epoch keys that should be * considered valid when receiving data from the = peer */ -void -epoch_init_key_ctx(struct crypto_options *co, const struct key_type *key_t= ype, - const struct epoch_key *e1_send, const struct epoch_key= *e1_recv, - uint16_t future_key_count); +void epoch_init_key_ctx(struct crypto_options *co, const struct key_type *= key_type, + const struct epoch_key *e1_send, const struct epoc= h_key *e1_recv, + uint16_t future_key_count); /** * Using an epoch, this function will try to retrieve a decryption @@ -144,8 +132,7 @@ * @param epoch epoch of the key to lookup * @return the key context with */ -struct key_ctx * -epoch_lookup_decrypt_key(struct crypto_options *opt, uint16_t epoch); +struct key_ctx *epoch_lookup_decrypt_key(struct crypto_options *opt, uint1= 6_t epoch); /** * Checks if we need to iterate the send epoch key. This needs to be in one @@ -154,8 +141,7 @@ * - send key aead usage limit reached (for AES-GCM and similar ciphers) * - recv key usage limit reached */ -void -epoch_check_send_iterate(struct crypto_options *opt); +void epoch_check_send_iterate(struct crypto_options *opt); #endif /* ifndef CRYPTO_EPOCH_H */ diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c index 1f3dcba..b13b662 100644 --- a/src/openvpn/crypto_mbedtls.c +++ b/src/openvpn/crypto_mbedtls.c @@ -66,7 +66,7 @@ crypto_init_lib_engine(const char *engine_name) { msg(M_WARN, "Note: mbed TLS hardware crypto engine functionality is no= t " - "available"); + "available"); } provider_t * @@ -124,8 +124,7 @@ } bool -mbed_log_func_line(unsigned int flags, int errval, const char *func, - int line) +mbed_log_func_line(unsigned int flags, int errval, const char *func, int l= ine) { char prefix[256]; @@ -204,8 +203,8 @@ const int *digests =3D mbedtls_md_list(); #ifndef ENABLE_SMALL - printf("The following message digests are available for use with\n" - PACKAGE_NAME ". A message digest is used in conjunction with\n" + printf("The following message digests are available for use with\n" PA= CKAGE_NAME + ". A message digest is used in conjunction with\n" "the HMAC function, to authenticate received packets.\n" "You can specify a message digest as parameter to\n" "the --auth option.\n\n"); @@ -233,12 +232,12 @@ } bool -crypto_pem_encode(const char *name, struct buffer *dst, - const struct buffer *src, struct gc_arena *gc) +crypto_pem_encode(const char *name, struct buffer *dst, const struct buffe= r *src, + struct gc_arena *gc) { /* 1000 chars is the PEM line length limit (+1 for tailing NUL) */ - char header[1000+1] =3D { 0 }; - char footer[1000+1] =3D { 0 }; + char header[1000 + 1] =3D { 0 }; + char footer[1000 + 1] =3D { 0 }; if (!snprintf(header, sizeof(header), "-----BEGIN %s-----\n", name)) { @@ -250,9 +249,8 @@ } size_t out_len =3D 0; - if (MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL !=3D - mbedtls_pem_write_buffer(header, footer, BPTR(src), BLEN(src), - NULL, 0, &out_len)) + if (MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL + !=3D mbedtls_pem_write_buffer(header, footer, BPTR(src), BLEN(src)= , NULL, 0, &out_len)) { return false; } @@ -260,9 +258,9 @@ /* We set the size buf to out_len-1 to NOT include the 0 byte that * mbedtls_pem_write_buffer in its length calculation */ *dst =3D alloc_buf_gc(out_len, gc); - if (!mbed_ok(mbedtls_pem_write_buffer(header, footer, BPTR(src), BLEN(= src), - BPTR(dst), BCAP(dst), &out_len)) - || !buf_inc_len(dst, out_len-1)) + if (!mbed_ok(mbedtls_pem_write_buffer(header, footer, BPTR(src), BLEN(= src), BPTR(dst), + BCAP(dst), &out_len)) + || !buf_inc_len(dst, out_len - 1)) { CLEAR(*dst); return false; @@ -272,12 +270,11 @@ } bool -crypto_pem_decode(const char *name, struct buffer *dst, - const struct buffer *src) +crypto_pem_decode(const char *name, struct buffer *dst, const struct buffe= r *src) { /* 1000 chars is the PEM line length limit (+1 for tailing NUL) */ - char header[1000+1] =3D { 0 }; - char footer[1000+1] =3D { 0 }; + char header[1000 + 1] =3D { 0 }; + char footer[1000 + 1] =3D { 0 }; if (!snprintf(header, sizeof(header), "-----BEGIN %s-----", name)) { @@ -297,8 +294,8 @@ size_t use_len =3D 0; mbedtls_pem_context ctx =3D { 0 }; - bool ret =3D mbed_ok(mbedtls_pem_read_buffer(&ctx, header, footer, BPT= R(&input), - NULL, 0, &use_len)); + bool ret =3D + mbed_ok(mbedtls_pem_read_buffer(&ctx, header, footer, BPTR(&input)= , NULL, 0, &use_len)); size_t buf_size =3D 0; const unsigned char *buf =3D mbedtls_pem_get_buffer(&ctx, &buf_size); if (ret && !buf_write(dst, buf, buf_size)) @@ -328,8 +325,8 @@ mbedtls_ctr_drbg_context * rand_ctx_get(void) { - static mbedtls_entropy_context ec =3D {0}; - static mbedtls_ctr_drbg_context cd_ctx =3D {0}; + static mbedtls_entropy_context ec =3D { 0 }; + static mbedtls_ctr_drbg_context cd_ctx =3D { 0 }; static bool rand_initialised =3D false; if (!rand_initialised) @@ -342,14 +339,15 @@ * 800-90 section 8.7.1). We have very little information at this = stage. * Include Program Name, memory address of the context and PID. */ - buf_printf(&pers_string, "OpenVPN %0u %p %s", platform_getpid(), &= cd_ctx, time_string(0, 0, 0, &gc)); + buf_printf(&pers_string, "OpenVPN %0u %p %s", platform_getpid(), &= cd_ctx, + time_string(0, 0, 0, &gc)); /* Initialise mbed TLS RNG, and built-in entropy sources */ mbedtls_entropy_init(&ec); mbedtls_ctr_drbg_init(&cd_ctx); - if (!mbed_ok(mbedtls_ctr_drbg_seed(&cd_ctx, mbedtls_entropy_func, = &ec, - BPTR(&pers_string), BLEN(&pers_= string)))) + if (!mbed_ok(mbedtls_ctr_drbg_seed(&cd_ctx, mbedtls_entropy_func, = &ec, BPTR(&pers_string), + BLEN(&pers_string)))) { msg(M_FATAL, "Failed to initialize random generator"); } @@ -422,12 +420,14 @@ return false; } - const size_t key_bytelen =3D mbedtls_cipher_info_get_key_bitlen(cipher= )/8; + const size_t key_bytelen =3D mbedtls_cipher_info_get_key_bitlen(cipher= ) / 8; if (key_bytelen > MAX_CIPHER_KEY_LENGTH) { - msg(D_LOW, "Cipher algorithm '%s' uses a default key size (%zu byt= es) " + msg(D_LOW, + "Cipher algorithm '%s' uses a default key size (%zu bytes) " "which is larger than " PACKAGE_NAME "'s current maximum key s= ize " - "(%d bytes)", ciphername, key_bytelen, MAX_CIPHER_KEY_LENGTH); + "(%d bytes)", + ciphername, key_bytelen, MAX_CIPHER_KEY_LENGTH); *reason =3D "disabled due to key size too large"; return false; } @@ -458,7 +458,7 @@ return 0; } - return (int)mbedtls_cipher_info_get_key_bitlen(cipher_kt)/8; + return (int)mbedtls_cipher_info_get_key_bitlen(cipher_kt) / 8; } int @@ -507,7 +507,7 @@ #ifdef MBEDTLS_CHACHAPOLY_C || mbedtls_cipher_info_get_type(cipher_kt) =3D=3D MBEDTLS_CIP= HER_CHACHA20_POLY1305 #endif - ); + ); } static mbedtls_cipher_mode_t @@ -528,19 +528,21 @@ cipher_kt_mode_ofb_cfb(const char *ciphername) { const mbedtls_cipher_info_t *cipher =3D cipher_get(ciphername); - return cipher && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_OFB - || cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_CFB); + return cipher + && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_OFB + || cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_CFB); } bool cipher_kt_mode_aead(const char *ciphername) { const mbedtls_cipher_info_t *cipher =3D cipher_get(ciphername); - return cipher && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_GCM + return cipher + && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_GCM #ifdef MBEDTLS_CHACHAPOLY_C - || cipher_kt_mode(cipher) =3D=3D MBEDTLS_MODE_CHACHA= POLY + || cipher_kt_mode(cipher) =3D=3D MBEDTLS_MODE_CHACHAPOLY #endif - ); + ); } @@ -566,8 +568,8 @@ } void -cipher_ctx_init(mbedtls_cipher_context_t *ctx, const uint8_t *key, - const char *ciphername, crypto_operation_t enc) +cipher_ctx_init(mbedtls_cipher_context_t *ctx, const uint8_t *key, const c= har *ciphername, + crypto_operation_t enc) { ASSERT(NULL !=3D ciphername && NULL !=3D ctx); CLEAR(*ctx); @@ -612,7 +614,7 @@ return 0; } - if (!mbed_ok(mbedtls_cipher_write_tag(ctx, (unsigned char *) tag, tag_= len))) + if (!mbed_ok(mbedtls_cipher_write_tag(ctx, (unsigned char *)tag, tag_l= en))) { return 0; } @@ -644,18 +646,20 @@ bool cipher_ctx_mode_ofb_cfb(const cipher_ctx_t *ctx) { - return ctx && (cipher_ctx_mode(ctx) =3D=3D OPENVPN_MODE_OFB - || cipher_ctx_mode(ctx) =3D=3D OPENVPN_MODE_CFB); + return ctx + && (cipher_ctx_mode(ctx) =3D=3D OPENVPN_MODE_OFB + || cipher_ctx_mode(ctx) =3D=3D OPENVPN_MODE_CFB); } bool cipher_ctx_mode_aead(const cipher_ctx_t *ctx) { - return ctx && (cipher_ctx_mode(ctx) =3D=3D OPENVPN_MODE_GCM + return ctx + && (cipher_ctx_mode(ctx) =3D=3D OPENVPN_MODE_GCM #ifdef MBEDTLS_CHACHAPOLY_C - || cipher_ctx_mode(ctx) =3D=3D MBEDTLS_MODE_CHACHAPOLY + || cipher_ctx_mode(ctx) =3D=3D MBEDTLS_MODE_CHACHAPOLY #endif - ); + ); } int @@ -691,13 +695,12 @@ } int -cipher_ctx_update(mbedtls_cipher_context_t *ctx, uint8_t *dst, - int *dst_len, uint8_t *src, int src_len) +cipher_ctx_update(mbedtls_cipher_context_t *ctx, uint8_t *dst, int *dst_le= n, uint8_t *src, + int src_len) { size_t s_dst_len =3D *dst_len; - if (!mbed_ok(mbedtls_cipher_update(ctx, src, (size_t) src_len, dst, - &s_dst_len))) + if (!mbed_ok(mbedtls_cipher_update(ctx, src, (size_t)src_len, dst, &s_= dst_len))) { return 0; } @@ -723,8 +726,8 @@ } int -cipher_ctx_final_check_tag(mbedtls_cipher_context_t *ctx, uint8_t *dst, - int *dst_len, uint8_t *tag, size_t tag_len) +cipher_ctx_final_check_tag(mbedtls_cipher_context_t *ctx, uint8_t *dst, in= t *dst_len, uint8_t *tag, + size_t tag_len) { size_t olen =3D 0; @@ -750,8 +753,7 @@ } *dst_len =3D olen; - if (!mbed_ok(mbedtls_cipher_check_tag(ctx, (const unsigned char *) tag, - tag_len))) + if (!mbed_ok(mbedtls_cipher_check_tag(ctx, (const unsigned char *)tag,= tag_len))) { return 0; } @@ -760,7 +762,6 @@ } - /* * * Generic message digest information functions @@ -781,10 +782,10 @@ } if (mbedtls_md_get_size(md) > MAX_HMAC_KEY_LENGTH) { - msg(M_FATAL, "Message hash algorithm '%s' uses a default hash size= (%d bytes) which is larger than " PACKAGE_NAME "'s current maximum hash si= ze (%d bytes)", - digest, - mbedtls_md_get_size(md), - MAX_HMAC_KEY_LENGTH); + msg(M_FATAL, + "Message hash algorithm '%s' uses a default hash size (%d byte= s) which is larger than " PACKAGE_NAME + "'s current maximum hash size (%d bytes)", + digest, mbedtls_md_get_size(md), MAX_HMAC_KEY_LENGTH); } return md; } @@ -792,7 +793,7 @@ bool md_valid(const char *digest) { - const mbedtls_md_info_t *md =3D mbedtls_md_info_from_string(digest); + const mbedtls_md_info_t *md =3D mbedtls_md_info_from_string(digest); return md !=3D NULL; } @@ -967,8 +968,8 @@ * via its APIs like OpenSSL does with CRYPTO_memcmp * Adapt the function that mbedtls itself uses in * mbedtls_safer_memcmp as it considers that to be safe */ - volatile const unsigned char *A =3D (volatile const unsigned char *) a; - volatile const unsigned char *B =3D (volatile const unsigned char *) b; + volatile const unsigned char *A =3D (volatile const unsigned char *)a; + volatile const unsigned char *B =3D (volatile const unsigned char *)b; volatile unsigned char diff =3D 0; for (size_t i =3D 0; i < size; i++) @@ -983,12 +984,11 @@ * from recent versions, so we use our own implementation if necessary. */ #if defined(HAVE_MBEDTLS_SSL_TLS_PRF) && defined(MBEDTLS_SSL_TLS_PRF_TLS1) bool -ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, - int secret_len, uint8_t *output, int output_len) +ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int= secret_len, + uint8_t *output, int output_len) { - return mbed_ok(mbedtls_ssl_tls_prf(MBEDTLS_SSL_TLS_PRF_TLS1, secret, - secret_len, "", seed, seed_len, out= put, - output_len)); + return mbed_ok(mbedtls_ssl_tls_prf(MBEDTLS_SSL_TLS_PRF_TLS1, secret, s= ecret_len, "", seed, + seed_len, output, output_len)); } #else /* defined(HAVE_MBEDTLS_SSL_TLS_PRF) && defined(MBEDTLS_SSL_TLS_PRF_= TLS1) */ /* @@ -1003,8 +1003,8 @@ * @param olen Length of the output buffer */ static void -tls1_P_hash(const mbedtls_md_info_t *md_kt, const uint8_t *sec, int sec_le= n, - const uint8_t *seed, int seed_len, uint8_t *out, int olen) +tls1_P_hash(const mbedtls_md_info_t *md_kt, const uint8_t *sec, int sec_le= n, const uint8_t *seed, + int seed_len, uint8_t *out, int olen) { struct gc_arena gc =3D gc_new(); uint8_t A1[MAX_HMAC_KEY_LENGTH]; @@ -1038,7 +1038,7 @@ hmac_ctx_update(ctx, seed, seed_len); hmac_ctx_final(ctx, A1); - for (;; ) + for (;;) { hmac_ctx_reset(ctx); hmac_ctx_reset(ctx_tmp); @@ -1053,7 +1053,7 @@ olen -=3D chunk; hmac_ctx_final(ctx_tmp, A1); /* calc the next A1 value */ } - else /* last one */ + else /* last one */ { hmac_ctx_final(ctx, A1); memcpy(out, A1, olen); @@ -1090,8 +1090,8 @@ * (2) The pre-master secret is generated by the client. */ bool -ssl_tls1_PRF(const uint8_t *label, int label_len, const uint8_t *sec, - int slen, uint8_t *out1, int olen) +ssl_tls1_PRF(const uint8_t *label, int label_len, const uint8_t *sec, int = slen, uint8_t *out1, + int olen) { struct gc_arena gc =3D gc_new(); const md_kt_t *md5 =3D md_get("MD5"); @@ -1099,15 +1099,15 @@ uint8_t *out2 =3D (uint8_t *)gc_malloc(olen, false, &gc); - int len =3D slen/2; + int len =3D slen / 2; const uint8_t *S1 =3D sec; const uint8_t *S2 =3D &(sec[len]); - len +=3D (slen&1); /* add for odd, make longer */ + len +=3D (slen & 1); /* add for odd, make longer */ tls1_P_hash(md5, S1, len, label, label_len, out1, olen); tls1_P_hash(sha1, S2, len, label, label_len, out2, olen); - for (int i =3D 0; i=3D 0x30000000L */ +#else /* OPENSSL_VERSION_NUMBER >=3D 0x30000000L */ msg(M_WARN, "Note: OpenSSL provider functionality is not available"); return NULL; #endif @@ -250,12 +245,13 @@ if (ERR_GET_REASON(err) =3D=3D SSL_R_NO_SHARED_CIPHER) { msg(D_CRYPT_ERRORS, "TLS error: The server has no TLS ciphersu= ites " - "in common with the client. Your --tls-cipher setting migh= t be " - "too restrictive."); + "in common with the client. Your --tls-cip= her setting might be " + "too restrictive."); } else if (ERR_GET_REASON(err) =3D=3D SSL_R_UNSUPPORTED_PROTOCOL) { - msg(D_CRYPT_ERRORS, "TLS error: Unsupported protocol. This typ= ically " + msg(D_CRYPT_ERRORS, + "TLS error: Unsupported protocol. This typically " "indicates that client and server have no common TLS versi= on enabled. " "This can be caused by mismatched tls-version-min and tls-= version-max " "options on client and server. " @@ -271,8 +267,8 @@ } else { - msg(flags, "OpenSSL: %s:%s:%s:%d:%s", ERR_error_string(err, NU= LL), - data, file, line, func); + msg(flags, "OpenSSL: %s:%s:%s:%d:%s", ERR_error_string(err, NU= LL), data, file, line, + func); } } } @@ -308,9 +304,7 @@ void crypto_init_dmalloc(void) { - CRYPTO_set_mem_ex_functions(crypto_malloc, - crypto_realloc, - crypto_free); + CRYPTO_set_mem_ex_functions(crypto_malloc, crypto_realloc, crypto_free= ); } #endif /* DMALLOC */ @@ -333,7 +327,8 @@ return strcmp(EVP_CIPHER_get0_name(*cipher_a), EVP_CIPHER_get0_name(*c= ipher_b)); } -struct collect_ciphers { +struct collect_ciphers +{ /* If we ever exceed this, we must be more selective */ const EVP_CIPHER *list[1000]; size_t num; @@ -355,12 +350,12 @@ const char *ciphername =3D EVP_CIPHER_get0_name(cipher); - if (ciphername && (cipher_kt_mode_cbc(ciphername) + if (ciphername + && (cipher_kt_mode_cbc(ciphername) #ifdef ENABLE_OFB_CFB_MODE - || cipher_kt_mode_ofb_cfb(ciphername) + || cipher_kt_mode_ofb_cfb(ciphername) #endif - || cipher_kt_mode_aead(ciphername) - )) + || cipher_kt_mode_aead(ciphername))) { cipher_list->list[cipher_list->num++] =3D cipher; } @@ -394,17 +389,18 @@ { cipher =3D EVP_get_cipherbyname(name); } -#else /* if defined(LIBRESSL_VERSION_NUMBER) */ +#else /* if defined(LIBRESSL_VERSION_NUMBER) */ const EVP_CIPHER *cipher =3D EVP_get_cipherbynid(nid); #endif /* We cast the const away so we can keep the function prototype * compatible with EVP_CIPHER_do_all_provided */ - collect_ciphers((EVP_CIPHER *) cipher, &cipher_list); + collect_ciphers((EVP_CIPHER *)cipher, &cipher_list); } #endif /* cast to non-const to prevent warning */ - qsort((EVP_CIPHER *)cipher_list.list, cipher_list.num, sizeof(*cipher_= list.list), cipher_name_cmp); + qsort((EVP_CIPHER *)cipher_list.list, cipher_list.num, sizeof(*cipher_= list.list), + cipher_name_cmp); for (size_t i =3D 0; i < cipher_list.num; i++) { @@ -437,8 +433,8 @@ show_available_digests(void) { #ifndef ENABLE_SMALL - printf("The following message digests are available for use with\n" - PACKAGE_NAME ". A message digest is used in conjunction with\n" + printf("The following message digests are available for use with\n" PA= CKAGE_NAME + ". A message digest is used in conjunction with\n" "the HMAC function, to authenticate received packets.\n" "You can specify a message digest as parameter to\n" "the --auth option.\n"); @@ -487,21 +483,19 @@ e =3D ENGINE_get_first(); while (e) { - printf("%s [%s]\n", - ENGINE_get_name(e), - ENGINE_get_id(e)); + printf("%s [%s]\n", ENGINE_get_name(e), ENGINE_get_id(e)); e =3D ENGINE_get_next(e); } ENGINE_cleanup(); -#else /* if HAVE_OPENSSL_ENGINE */ +#else /* if HAVE_OPENSSL_ENGINE */ printf("Sorry, OpenSSL hardware crypto engine functionality is not ava= ilable.\n"); #endif } bool -crypto_pem_encode(const char *name, struct buffer *dst, - const struct buffer *src, struct gc_arena *gc) +crypto_pem_encode(const char *name, struct buffer *dst, const struct buffe= r *src, + struct gc_arena *gc) { bool ret =3D false; BIO *bio =3D BIO_new(BIO_s_mem()); @@ -528,8 +522,7 @@ } bool -crypto_pem_decode(const char *name, struct buffer *dst, - const struct buffer *src) +crypto_pem_decode(const char *name, struct buffer *dst, const struct buffe= r *src) { bool ret =3D false; @@ -543,8 +536,7 @@ char *header_read =3D NULL; uint8_t *data_read =3D NULL; long data_read_len =3D 0; - if (!PEM_read_bio(bio, &name_read, &header_read, &data_read, - &data_read_len)) + if (!PEM_read_bio(bio, &name_read, &header_read, &data_read, &data_rea= d_len)) { dmsg(D_CRYPT_ERRORS, "%s: PEM decode failed", __func__); goto cleanup; @@ -552,17 +544,16 @@ if (strcmp(name, name_read)) { - dmsg(D_CRYPT_ERRORS, - "%s: unexpected PEM name (got '%s', expected '%s')", - __func__, name_read, name); + dmsg(D_CRYPT_ERRORS, "%s: unexpected PEM name (got '%s', expected = '%s')", __func__, + name_read, name); goto cleanup; } uint8_t *dst_data =3D buf_write_alloc(dst, data_read_len); if (!dst_data) { - dmsg(D_CRYPT_ERRORS, "%s: dst too small (%i, needs %li)", __func__, - BCAP(dst), data_read_len); + dmsg(D_CRYPT_ERRORS, "%s: dst too small (%i, needs %li)", __func__= , BCAP(dst), + data_read_len); goto cleanup; } memcpy(dst_data, data_read, data_read_len); @@ -633,18 +624,21 @@ if (FIPS_mode() && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_FIPS)) { - msg(D_LOW, "Cipher algorithm '%s' is known by OpenSSL library but " - "currently disabled by running in FIPS mode.", ciphername); + msg(D_LOW, + "Cipher algorithm '%s' is known by OpenSSL library but " + "currently disabled by running in FIPS mode.", + ciphername); *reason =3D "disabled by FIPS mode"; goto out; } #endif if (EVP_CIPHER_key_length(cipher) > MAX_CIPHER_KEY_LENGTH) { - msg(D_LOW, "Cipher algorithm '%s' uses a default key size (%d byte= s) " + msg(D_LOW, + "Cipher algorithm '%s' uses a default key size (%d bytes) " "which is larger than " PACKAGE_NAME "'s current maximum key s= ize " - "(%d bytes)", ciphername, EVP_CIPHER_key_length(cipher), - MAX_CIPHER_KEY_LENGTH); + "(%d bytes)", + ciphername, EVP_CIPHER_key_length(cipher), MAX_CIPHER_KEY_LENG= TH); *reason =3D "disabled due to key size too large"; goto out; } @@ -759,7 +753,6 @@ bool cipher_kt_insecure(const char *ciphername) { - if (cipher_kt_block_size(ciphername) >=3D 128 / 8) { return false; @@ -791,12 +784,13 @@ { evp_cipher_type *cipher =3D cipher_get(ciphername); - bool ret =3D cipher && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_CBC - /* Exclude AEAD cipher modes, they require a dif= ferent API */ + bool ret =3D cipher + && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_CBC + /* Exclude AEAD cipher modes, they require a different API */ #ifdef EVP_CIPH_FLAG_CTS - && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CT= S) + && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CTS) #endif - && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AE= AD_CIPHER)); + && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPH= ER)); EVP_CIPHER_free(cipher); return ret; } @@ -805,8 +799,9 @@ cipher_kt_mode_ofb_cfb(const char *ciphername) { evp_cipher_type *cipher =3D cipher_get(ciphername); - bool ofb_cfb =3D cipher && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE= _OFB - || cipher_kt_mode(cipher) =3D=3D OPENVPN_MOD= E_CFB) + bool ofb_cfb =3D cipher + && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_OFB + || cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_CFB) /* Exclude AEAD cipher modes, they require a different = API */ && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPH= ER); EVP_CIPHER_free(cipher); @@ -829,7 +824,7 @@ #ifdef NID_chacha20_poly1305 if (EVP_CIPHER_nid(cipher) =3D=3D NID_chacha20_poly1305) { - isaead =3D true; + isaead =3D true; } #endif } @@ -860,8 +855,8 @@ } void -cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *key, - const char *ciphername, crypto_operation_t enc) +cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *key, const char *ciphe= rname, + crypto_operation_t enc) { ASSERT(NULL !=3D ciphername && NULL !=3D ctx); evp_cipher_type *kt =3D cipher_get(ciphername); @@ -914,7 +909,7 @@ int mode =3D EVP_CIPHER_CTX_mode(ctx); return mode =3D=3D EVP_CIPH_CBC_MODE - /* Exclude AEAD cipher modes, they require a different API */ + /* Exclude AEAD cipher modes, they require a different API */ #ifdef EVP_CIPH_FLAG_CTS && !(flags & EVP_CIPH_FLAG_CTS) #endif @@ -977,8 +972,7 @@ } int -cipher_ctx_update(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len, - uint8_t *src, int src_len) +cipher_ctx_update(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len, uint8_t= *src, int src_len) { if (!EVP_CipherUpdate(ctx, dst, dst_len, src, src_len)) { @@ -994,8 +988,8 @@ } int -cipher_ctx_final_check_tag(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len, - uint8_t *tag, size_t tag_len) +cipher_ctx_final_check_tag(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len= , uint8_t *tag, + size_t tag_len) { ASSERT(tag_len < SIZE_MAX); if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, tag_len, tag)) @@ -1026,7 +1020,8 @@ } if (EVP_MD_size(md) > MAX_HMAC_KEY_LENGTH) { - crypto_msg(M_FATAL, "Message hash algorithm '%s' uses a default ha= sh " + crypto_msg(M_FATAL, + "Message hash algorithm '%s' uses a default hash " "size (%d bytes) which is larger than " PACKAGE_NAME "'= s current " "maximum hash size (%d bytes)", digest, EVP_MD_size(md), MAX_HMAC_KEY_LENGTH); @@ -1052,17 +1047,12 @@ * this translation table for forward lookup, only for returning the name * with md_kt_name() */ const cipher_name_pair digest_name_translation_table[] =3D { - { "BLAKE2s256", "BLAKE2S-256"}, - { "BLAKE2b512", "BLAKE2B-512"}, - { "RIPEMD160", "RIPEMD-160" }, - { "SHA224", "SHA2-224"}, - { "SHA256", "SHA2-256"}, - { "SHA384", "SHA2-384"}, - { "SHA512", "SHA2-512"}, - { "SHA512-224", "SHA2-512/224"}, - { "SHA512-256", "SHA2-512/256"}, - { "SHAKE128", "SHAKE-128"}, - { "SHAKE256", "SHAKE-256"}, + { "BLAKE2s256", "BLAKE2S-256" }, { "BLAKE2b512", "BLAKE2B-512" }, + { "RIPEMD160", "RIPEMD-160" }, { "SHA224", "SHA2-224" }, + { "SHA256", "SHA2-256" }, { "SHA384", "SHA2-384" }, + { "SHA512", "SHA2-512" }, { "SHA512-224", "SHA2-512/224" }, + { "SHA512-256", "SHA2-512/256" }, { "SHAKE128", "SHAKE-128" }, + { "SHAKE256", "SHAKE-256" }, }; const size_t digest_name_translation_table_count =3D sizeof(digest_name_translation_table) / sizeof(*digest_name_translatio= n_table); @@ -1099,7 +1089,7 @@ return 0; } evp_md_type *kt =3D md_get(mdname); - unsigned char size =3D (unsigned char)EVP_MD_size(kt); + unsigned char size =3D (unsigned char)EVP_MD_size(kt); EVP_MD_free(kt); return size; } @@ -1287,10 +1277,8 @@ * only used for lookup so we cast (as OpenSSL also does internally) * the constness away here. */ - ctx->params[0] =3D OSSL_PARAM_construct_utf8_string("digest", - (char *) EVP_MD_get0= _name(kt), 0); - ctx->params[1] =3D OSSL_PARAM_construct_octet_string("key", - ctx->key, EVP_MD_si= ze(kt)); + ctx->params[0] =3D OSSL_PARAM_construct_utf8_string("digest", (char *)= EVP_MD_get0_name(kt), 0); + ctx->params[1] =3D OSSL_PARAM_construct_octet_string("key", ctx->key, = EVP_MD_size(kt)); ctx->params[2] =3D OSSL_PARAM_construct_end(); if (!EVP_MAC_init(ctx->ctx, NULL, 0, ctx->params)) @@ -1349,8 +1337,8 @@ } #if (OPENSSL_VERSION_NUMBER >=3D 0x30000000L) && !defined(LIBRESSL_VERSION= _NUMBER) bool -ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, - int secret_len, uint8_t *output, int output_len) +ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int= secret_len, + uint8_t *output, int output_len) { bool ret =3D true; EVP_KDF_CTX *kctx =3D NULL; @@ -1373,18 +1361,18 @@ /* The OpenSSL APIs require us to cast the const aways even though the * strings are never changed and only read */ - params[0] =3D OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, - SN_md5_sha1, strlen(SN_md= 5_sha1)); - params[1] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET, - (uint8_t *) secret, (siz= e_t) secret_len); - params[2] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED, - (uint8_t *) seed, (size_= t) seed_len); + params[0] =3D + OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, SN_md5_sha= 1, strlen(SN_md5_sha1)); + params[1] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,= (uint8_t *)secret, + (size_t)secret_len); + params[2] =3D + OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED, (uint8_t *)= seed, (size_t)seed_len); params[3] =3D OSSL_PARAM_construct_end(); if (EVP_KDF_derive(kctx, output, output_len, params) <=3D 0) { crypto_msg(D_TLS_DEBUG_LOW, "Generating TLS 1.0 PRF using " - "EVP_KDF_derive failed"); + "EVP_KDF_derive failed"); goto err; } @@ -1400,15 +1388,15 @@ } #elif defined(OPENSSL_IS_AWSLC) bool -ssl_tls1_PRF(const uint8_t *label, int label_len, const uint8_t *sec, - int slen, uint8_t *out1, int olen) +ssl_tls1_PRF(const uint8_t *label, int label_len, const uint8_t *sec, int = slen, uint8_t *out1, + int olen) { CRYPTO_tls1_prf(EVP_md5_sha1(), out1, olen, sec, slen, label, label_le= n, NULL, 0, NULL, 0); } #elif !defined(LIBRESSL_VERSION_NUMBER) && !defined(ENABLE_CRYPTO_WOLFSSL) bool -ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, - int secret_len, uint8_t *output, int output_len) +ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int= secret_len, + uint8_t *output, int output_len) { EVP_PKEY_CTX *pctx =3D EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL); if (!pctx) @@ -1456,8 +1444,8 @@ * OpenSSL does. As result they will only be able to support * peers that support TLS EKM like when running with OpenSSL 3.x FIPS */ bool -ssl_tls1_PRF(const uint8_t *label, int label_len, const uint8_t *sec, - int slen, uint8_t *out1, int olen) +ssl_tls1_PRF(const uint8_t *label, int label_len, const uint8_t *sec, int = slen, uint8_t *out1, + int olen) { return false; } diff --git a/src/openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h index 85f53f6..3e0067c 100644 --- a/src/openvpn/crypto_openssl.h +++ b/src/openvpn/crypto_openssl.h @@ -51,7 +51,8 @@ /* Use a dummy type for the provider */ typedef void provider_t; #else -typedef struct { +typedef struct +{ OSSL_PARAM params[3]; uint8_t key[EVP_MAX_KEY_LENGTH]; EVP_MAC_CTX *ctx; @@ -72,29 +73,29 @@ #endif /** Maximum length of an IV */ -#define OPENVPN_MAX_IV_LENGTH EVP_MAX_IV_LENGTH +#define OPENVPN_MAX_IV_LENGTH EVP_MAX_IV_LENGTH /** Cipher is in CBC mode */ -#define OPENVPN_MODE_CBC EVP_CIPH_CBC_MODE +#define OPENVPN_MODE_CBC EVP_CIPH_CBC_MODE /** Cipher is in OFB mode */ -#define OPENVPN_MODE_OFB EVP_CIPH_OFB_MODE +#define OPENVPN_MODE_OFB EVP_CIPH_OFB_MODE /** Cipher is in CFB mode */ -#define OPENVPN_MODE_CFB EVP_CIPH_CFB_MODE +#define OPENVPN_MODE_CFB EVP_CIPH_CFB_MODE /** Cipher is in GCM mode */ -#define OPENVPN_MODE_GCM EVP_CIPH_GCM_MODE +#define OPENVPN_MODE_GCM EVP_CIPH_GCM_MODE typedef int crypto_operation_t; /** Cipher should encrypt */ -#define OPENVPN_OP_ENCRYPT 1 +#define OPENVPN_OP_ENCRYPT 1 /** Cipher should decrypt */ -#define OPENVPN_OP_DECRYPT 0 +#define OPENVPN_OP_DECRYPT 0 -#define MD4_DIGEST_LENGTH 16 +#define MD4_DIGEST_LENGTH 16 /** * Retrieve any occurred OpenSSL errors and print those errors. @@ -113,10 +114,11 @@ * @param flags Flags to indicate error type and priority. * @param ... Format string and optional format arguments */ -#define crypto_msg(flags, ...) \ - do { \ +#define crypto_msg(flags, ...) \ + do \ + { \ crypto_print_openssl_errors(nonfatal(flags)); \ - msg((flags), __VA_ARGS__); \ + msg((flags), __VA_ARGS__); \ } while (false) #endif /* CRYPTO_OPENSSL_H_ */ diff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c index 67dc382..d91d9a1 100644 --- a/src/openvpn/cryptoapi.c +++ b/src/openvpn/cryptoapi.c @@ -62,11 +62,12 @@ return 0; } -#else /* HAVE_XKEY_PROVIDER */ +#else /* HAVE_XKEY_PROVIDER */ static XKEY_EXTERNAL_SIGN_fn xkey_cng_sign; -typedef struct _CAPI_DATA { +typedef struct _CAPI_DATA +{ const CERT_CONTEXT *cert_context; HCRYPTPROV_OR_NCRYPT_KEY_HANDLE crypt_prov; EVP_PKEY *pubkey; @@ -112,7 +113,7 @@ break; default: - msg(M_WARN|M_INFO, "cryptoapicert: Unknown hash type NID=3D0x%= x", md_type); + msg(M_WARN | M_INFO, "cryptoapicert: Unknown hash type NID=3D0= x%x", md_type); break; } return alg; @@ -157,7 +158,7 @@ parse_hexstring(const char *p, unsigned char *arr, size_t capacity) { int i =3D 0; - for ( ; *p && i < capacity; p +=3D 2) + for (; *p && i < capacity; p +=3D 2) { /* skip spaces */ while (*p =3D=3D ' ') @@ -169,8 +170,7 @@ break; } - if (!isxdigit(p[0]) || !isxdigit(p[1]) - || sscanf(p, "%2hhx", &arr[i++]) !=3D 1) + if (!isxdigit(p[0]) || !isxdigit(p[1]) || sscanf(p, "%2hhx", &arr[= i++]) !=3D 1) { return 0; } @@ -179,21 +179,21 @@ } static void * -decode_object(struct gc_arena *gc, LPCSTR struct_type, - const CRYPT_OBJID_BLOB *val, DWORD flags, DWORD *cb) +decode_object(struct gc_arena *gc, LPCSTR struct_type, const CRYPT_OBJID_B= LOB *val, DWORD flags, + DWORD *cb) { /* get byte count for decoding */ BYTE *buf; - if (!CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, struct= _type, - val->pbData, val->cbData, flags, NULL, cb)) + if (!CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, struct= _type, val->pbData, + val->cbData, flags, NULL, cb)) { return NULL; } /* do the actual decode */ buf =3D gc_malloc(*cb, false, gc); - if (!CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, struct= _type, - val->pbData, val->cbData, flags, buf, cb)) + if (!CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, struct= _type, val->pbData, + val->cbData, flags, buf, cb)) { return NULL; } @@ -243,8 +243,8 @@ return true; } - const CRYPT_OID_INFO *tmpl_oid =3D find_oid(CRYPT_OID_INFO_NAM= E_KEY, tmpl_name, - CRYPT_TEMPLATE_OID_G= ROUP_ID); + const CRYPT_OID_INFO *tmpl_oid =3D + find_oid(CRYPT_OID_INFO_NAME_KEY, tmpl_name, CRYPT_TEMPLAT= E_OID_GROUP_ID); if (tmpl_oid && !stricmp(tmpl_oid->pszOID, cte->pszObjId)) { /* found OID match in extension against resolved key */ @@ -274,7 +274,7 @@ DWORD find_type; const void *find_param; unsigned char hash[255]; - CRYPT_HASH_BLOB blob =3D {.cbData =3D 0, .pbData =3D hash}; + CRYPT_HASH_BLOB blob =3D { .cbData =3D 0, .pbData =3D hash }; struct gc_arena gc =3D gc_new(); if (!strncmp(cert_prop, "SUBJ:", 5)) @@ -296,7 +296,7 @@ blob.cbData =3D parse_hexstring(cert_prop + 6, hash, sizeof(hash)); if (blob.cbData =3D=3D 0) { - msg(M_WARN|M_INFO, "WARNING: cryptoapicert: error parsing <%s>= .", cert_prop); + msg(M_WARN | M_INFO, "WARNING: cryptoapicert: error parsing <%= s>.", cert_prop); goto out; } } @@ -308,7 +308,8 @@ } else { - msg(M_NONFATAL, "Error in cryptoapicert: unsupported certificate s= pecification <%s>", cert_prop); + msg(M_NONFATAL, "Error in cryptoapicert: unsupported certificate s= pecification <%s>", + cert_prop); goto out; } @@ -316,15 +317,14 @@ { int validity =3D 1; /* this frees previous rv, if not NULL */ - rv =3D CertFindCertificateInStore(cert_store, X509_ASN_ENCODING | = PKCS_7_ASN_ENCODING, - 0, find_type, find_param, rv); + rv =3D CertFindCertificateInStore(cert_store, X509_ASN_ENCODING | = PKCS_7_ASN_ENCODING, 0, + find_type, find_param, rv); if (!rv) { break; } /* if searching by template name, check now if it matches */ - if (find_type =3D=3D CERT_FIND_HAS_PRIVATE_KEY - && !test_certificate_template(cert_prop, rv)) + if (find_type =3D=3D CERT_FIND_HAS_PRIVATE_KEY && !test_certificat= e_template(cert_prop, rv)) { continue; } @@ -333,7 +333,7 @@ { break; } - msg(M_WARN|M_INFO, "WARNING: cryptoapicert: ignoring certificate i= n store %s.", + msg(M_WARN | M_INFO, "WARNING: cryptoapicert: ignoring certificate= in store %s.", validity < 0 ? "not yet valid" : "that has expired"); } @@ -356,12 +356,12 @@ if (status !=3D ERROR_SUCCESS) { SetLastError(status); - msg(M_NONFATAL|M_ERRNO, "Error in cryptoapicert: ECDSA signature u= sing CNG failed."); + msg(M_NONFATAL | M_ERRNO, "Error in cryptoapicert: ECDSA signature= using CNG failed."); return 0; } /* NCryptSignHash returns r|s -- convert to DER encoded buffer expecte= d by OpenSSL */ - int derlen =3D ecdsa_bin2der(sig, (int) len, *siglen); + int derlen =3D ecdsa_bin2der(sig, (int)len, *siglen); if (derlen <=3D 0) { return 0; @@ -396,9 +396,9 @@ { msg(D_LOW, "Signing using NCryptSignHash with PKCS1 padding: hasha= lg <%s>", sigalg.mdname); - BCRYPT_PKCS1_PADDING_INFO padinfo =3D {hashalg}; - status =3D NCryptSignHash(cd->crypt_prov, &padinfo, (BYTE *)tbs, (= DWORD)tbslen, - sig, (DWORD)*siglen, &len, BCRYPT_PAD_PKCS= 1); + BCRYPT_PKCS1_PADDING_INFO padinfo =3D { hashalg }; + status =3D NCryptSignHash(cd->crypt_prov, &padinfo, (BYTE *)tbs, (= DWORD)tbslen, sig, + (DWORD)*siglen, &len, BCRYPT_PAD_PKCS1); } else if (!strcmp(sigalg.padmode, "pss")) { @@ -416,9 +416,10 @@ msg(D_LOW, "Signing using NCryptSignHash with PSS padding: hashalg= <%s>, saltlen <%d>", sigalg.mdname, saltlen); - BCRYPT_PSS_PADDING_INFO padinfo =3D {hashalg, (DWORD) saltlen}; /*= cast is safe as saltlen >=3D 0 */ - status =3D NCryptSignHash(cd->crypt_prov, &padinfo, (BYTE *)tbs, (= DWORD) tbslen, - sig, (DWORD)*siglen, &len, BCRYPT_PAD_PSS); + BCRYPT_PSS_PADDING_INFO padinfo =3D { hashalg, + (DWORD)saltlen }; /* cast is s= afe as saltlen >=3D 0 */ + status =3D NCryptSignHash(cd->crypt_prov, &padinfo, (BYTE *)tbs, (= DWORD)tbslen, sig, + (DWORD)*siglen, &len, BCRYPT_PAD_PSS); } else { @@ -429,7 +430,7 @@ if (status !=3D ERROR_SUCCESS) { SetLastError(status); - msg(M_NONFATAL|M_ERRNO, "Error in cryptoapicert: RSA signature usi= ng CNG failed."); + msg(M_NONFATAL | M_ERRNO, "Error in cryptoapicert: RSA signature u= sing CNG failed."); return 0; } @@ -484,7 +485,7 @@ char *name =3D NULL; if (len) { - wchar_t *wname =3D gc_malloc(len*sizeof(wchar_t), false, gc); + wchar_t *wname =3D gc_malloc(len * sizeof(wchar_t), false, gc); if (!wname || CertGetNameStringW(cc, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, = NULL, wname, len) =3D=3D 0) { @@ -504,7 +505,6 @@ static int Load_CryptoAPI_certificate(const char *cert_prop, X509 **cert, EVP_PKEY **= privkey) { - HCERTSTORE cs; CAPI_DATA *cd =3D calloc(1, sizeof(*cd)); struct gc_arena gc =3D gc_new(); @@ -515,29 +515,35 @@ goto err; } /* search CURRENT_USER first, then LOCAL_MACHINE */ - cs =3D CertOpenStore((LPCSTR) CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTE= M_STORE_CURRENT_USER - |CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONL= Y_FLAG, L"MY"); + cs =3D CertOpenStore((LPCSTR)CERT_STORE_PROV_SYSTEM, 0, 0, + CERT_SYSTEM_STORE_CURRENT_USER | CERT_STORE_OPEN_EX= ISTING_FLAG + | CERT_STORE_READONLY_FLAG, + L"MY"); if (cs =3D=3D NULL) { - msg(M_NONFATAL|M_ERRNO, "Error in cryptoapicert: failed to open us= er certficate store"); + msg(M_NONFATAL | M_ERRNO, "Error in cryptoapicert: failed to open = user certficate store"); goto err; } cd->cert_context =3D find_certificate_in_store(cert_prop, cs); CertCloseStore(cs, 0); if (!cd->cert_context) { - cs =3D CertOpenStore((LPCSTR) CERT_STORE_PROV_SYSTEM, 0, 0, CERT_S= YSTEM_STORE_LOCAL_MACHINE - |CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_REA= DONLY_FLAG, L"MY"); + cs =3D CertOpenStore((LPCSTR)CERT_STORE_PROV_SYSTEM, 0, 0, + CERT_SYSTEM_STORE_LOCAL_MACHINE | CERT_STORE_OP= EN_EXISTING_FLAG + | CERT_STORE_READONLY_FLAG, + L"MY"); if (cs =3D=3D NULL) { - msg(M_NONFATAL|M_ERRNO, "Error in cryptoapicert: failed to ope= n machine certficate store"); + msg(M_NONFATAL | M_ERRNO, + "Error in cryptoapicert: failed to open machine certficate= store"); goto err; } cd->cert_context =3D find_certificate_in_store(cert_prop, cs); CertCloseStore(cs, 0); if (cd->cert_context =3D=3D NULL) { - msg(M_NONFATAL, "Error in cryptoapicert: certificate matching = <%s> not found", cert_prop); + msg(M_NONFATAL, "Error in cryptoapicert: certificate matching = <%s> not found", + cert_prop); goto err; } } @@ -550,7 +556,7 @@ } /* cert_context->pbCertEncoded is the cert X509 DER encoded. */ - *cert =3D d2i_X509(NULL, (const unsigned char **) &cd->cert_context->p= bCertEncoded, + *cert =3D d2i_X509(NULL, (const unsigned char **)&cd->cert_context->pb= CertEncoded, cd->cert_context->cbCertEncoded); if (*cert =3D=3D NULL) { @@ -560,13 +566,13 @@ /* set up stuff to use the private key */ /* We support NCRYPT key handles only */ - DWORD flags =3D CRYPT_ACQUIRE_COMPARE_KEY_FLAG - | CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG; - if (!CryptAcquireCertificatePrivateKey(cd->cert_context, flags, NULL, - &cd->crypt_prov, &cd->key_spec,= &cd->free_crypt_prov)) + DWORD flags =3D CRYPT_ACQUIRE_COMPARE_KEY_FLAG | CRYPT_ACQUIRE_ONLY_NC= RYPT_KEY_FLAG; + if (!CryptAcquireCertificatePrivateKey(cd->cert_context, flags, NULL, = &cd->crypt_prov, + &cd->key_spec, &cd->free_crypt_= prov)) { /* private key may be in a token not available, or incompatible wi= th CNG */ - msg(M_NONFATAL|M_ERRNO, "Error in cryptoapicert: failed to acquire= key. Key not present or " + msg(M_NONFATAL | M_ERRNO, + "Error in cryptoapicert: failed to acquire key. Key not presen= t or " "is in a legacy token not supported by Windows CNG API"); X509_free(*cert); goto err; @@ -576,8 +582,8 @@ EVP_PKEY *pkey =3D X509_get_pubkey(*cert); cd->pubkey =3D pkey; /* will be freed with cd */ - *privkey =3D xkey_load_generic_key(tls_libctx, cd, pkey, - xkey_cng_sign, (XKEY_PRIVKEY_FREE_fn = *) CAPI_DATA_free); + *privkey =3D xkey_load_generic_key(tls_libctx, cd, pkey, xkey_cng_sign, + (XKEY_PRIVKEY_FREE_fn *)CAPI_DATA_fre= e); gc_free(&gc); return 1; /* do not free cd -- its kept by xkey provider */ @@ -598,8 +604,7 @@ { return ret; } - if (SSL_CTX_use_certificate(ssl_ctx, cert) - && SSL_CTX_use_PrivateKey(ssl_ctx, privkey)) + if (SSL_CTX_use_certificate(ssl_ctx, cert) && SSL_CTX_use_PrivateKey(s= sl_ctx, privkey)) { crypto_print_openssl_errors(M_WARN); ret =3D 1; @@ -612,5 +617,5 @@ return ret; } -#endif /* HAVE_XKEY_PROVIDER */ -#endif /* _WIN32 */ +#endif /* HAVE_XKEY_PROVIDER */ +#endif /* _WIN32 */ diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c index 98cbb72..daa5553 100644 --- a/src/openvpn/dco.c +++ b/src/openvpn/dco.c @@ -52,14 +52,13 @@ #endif static int -dco_install_key(struct tls_multi *multi, struct key_state *ks, - const uint8_t *encrypt_key, const uint8_t *encrypt_iv, - const uint8_t *decrypt_key, const uint8_t *decrypt_iv, +dco_install_key(struct tls_multi *multi, struct key_state *ks, const uint8= _t *encrypt_key, + const uint8_t *encrypt_iv, const uint8_t *decrypt_key, con= st uint8_t *decrypt_iv, const char *ciphername) { - msg(D_DCO_DEBUG, "%s: peer_id=3D%d keyid=3D%d, currently %d keys insta= lled", - __func__, multi->dco_peer_id, ks->key_id, multi->dco_keys_installe= d); + msg(D_DCO_DEBUG, "%s: peer_id=3D%d keyid=3D%d, currently %d keys insta= lled", __func__, + multi->dco_peer_id, ks->key_id, multi->dco_keys_installed); /* Install a key in the PRIMARY slot only when no other key exist. * From that moment on, any new key will be installed in the SECONDARY @@ -72,33 +71,27 @@ slot =3D OVPN_KEY_SLOT_SECONDARY; } - int ret =3D dco_new_key(multi->dco, multi->dco_peer_id, ks->key_id, sl= ot, - encrypt_key, encrypt_iv, - decrypt_key, decrypt_iv, - ciphername); + int ret =3D dco_new_key(multi->dco, multi->dco_peer_id, ks->key_id, sl= ot, encrypt_key, encrypt_iv, + decrypt_key, decrypt_iv, ciphername); if ((ret =3D=3D 0) && (multi->dco_keys_installed < 2)) { multi->dco_keys_installed++; - ks->dco_status =3D (slot =3D=3D OVPN_KEY_SLOT_PRIMARY) ? DCO_INSTA= LLED_PRIMARY : - DCO_INSTALLED_SECONDARY; + ks->dco_status =3D + (slot =3D=3D OVPN_KEY_SLOT_PRIMARY) ? DCO_INSTALLED_PRIMARY : = DCO_INSTALLED_SECONDARY; } return ret; } int -init_key_dco_bi(struct tls_multi *multi, struct key_state *ks, - const struct key2 *key2, int key_direction, - const char *ciphername, bool server) +init_key_dco_bi(struct tls_multi *multi, struct key_state *ks, const struc= t key2 *key2, + int key_direction, const char *ciphername, bool server) { struct key_direction_state kds; key_direction_state_init(&kds, key_direction); - return dco_install_key(multi, ks, - key2->keys[kds.out_key].cipher, - key2->keys[(int)server].hmac, - key2->keys[kds.in_key].cipher, - key2->keys[1 - (int)server].hmac, + return dco_install_key(multi, ks, key2->keys[kds.out_key].cipher, key2= ->keys[(int)server].hmac, + key2->keys[kds.in_key].cipher, key2->keys[1 - (= int)server].hmac, ciphername); } @@ -184,13 +177,15 @@ { if (secondary) { - msg(D_DCO_DEBUG, "Swapping primary and secondary keys to " + msg(D_DCO_DEBUG, + "Swapping primary and secondary keys to " "primary-id=3D%d secondary-id=3D%d", primary->key_id, secondary->key_id); } else { - msg(D_DCO_DEBUG, "Swapping primary and secondary keys to " + msg(D_DCO_DEBUG, + "Swapping primary and secondary keys to " "primary-id=3D%d secondary-id=3D(to be deleted)", primary->key_id); } @@ -276,13 +271,15 @@ #if defined(_WIN32) if (!proto_is_udp(ce->proto) && mode =3D=3D MODE_SERVER) { - msg(msglevel, "NOTE: TCP transport disables data channel offload o= n Windows in server mode."); + msg(msglevel, + "NOTE: TCP transport disables data channel offload on Windows = in server mode."); return false; } if (!ce->remote && !dco_win_supports_multipeer()) { - msg(msglevel, "NOTE: --remote is not defined. This DCO version doe= sn't support multipeer. Disabling Data Channel Offload"); + msg(msglevel, + "NOTE: --remote is not defined. This DCO version doesn't suppo= rt multipeer. Disabling Data Channel Offload"); return false; } @@ -311,7 +308,7 @@ if (!o->tls_client && !o->tls_server) { msg(msglevel, "No tls-client or tls-server option in configuration= " - "detected. Disabling data channel offload."); + "detected. Disabling data channel offload."); return false; } @@ -355,7 +352,8 @@ #if defined(_WIN32) if ((o->mode =3D=3D MODE_SERVER) && !dco_win_supports_multipeer()) { - msg(msglevel, "--mode server is set. This DCO version doesn't supp= ort multipeer. Disabling Data Channel Offload"); + msg(msglevel, + "--mode server is set. This DCO version doesn't support multip= eer. Disabling Data Channel Offload"); return false; } @@ -386,8 +384,8 @@ } else if ((ret < 0) && (ret !=3D -ENODEV)) { - msg(msglevel, "Cannot retrieve type of device %s: %s (%d)", o-= >dev, - strerror(-ret), ret); + msg(msglevel, "Cannot retrieve type of device %s: %s (%d)", o-= >dev, strerror(-ret), + ret); } } #endif /* if defined(_WIN32) */ @@ -402,13 +400,13 @@ if (!capng_have_capability(CAPNG_EFFECTIVE, CAP_SETPCAP)) { msg(msglevel, "--user specified but lacking CAP_SETPCAP. " - "Cannot retain CAP_NET_ADMIN. Disabling data channel offlo= ad"); + "Cannot retain CAP_NET_ADMIN. Disabling data cha= nnel offload"); return false; } if (!capng_have_capability(CAPNG_PERMITTED, CAP_NET_ADMIN)) { msg(msglevel, "--user specified but not permitted to retain CA= P_NET_ADMIN. " - "Disabling data channel offload"); + "Disabling data channel offload"); return false; } } @@ -439,16 +437,18 @@ if (o->enable_ncp_fallback && !tls_item_in_cipher_list(o->ciphername, dco_get_supported_ciphe= rs())) { - msg(msglevel, "Note: --data-ciphers-fallback with cipher '%s' " - "disables data channel offload.", o->ciphername); + msg(msglevel, + "Note: --data-ciphers-fallback with cipher '%s' " + "disables data channel offload.", + o->ciphername); return false; } #if defined(USE_COMP) - if (o->comp.alg !=3D COMP_ALG_UNDEF - || o->comp.flags & COMP_F_ALLOW_ASYM) + if (o->comp.alg !=3D COMP_ALG_UNDEF || o->comp.flags & COMP_F_ALLOW_AS= YM) { - msg(msglevel, "Note: '--allow-compression' is not set to 'no', dis= abling data channel offload."); + msg(msglevel, + "Note: '--allow-compression' is not set to 'no', disabling dat= a channel offload."); if (o->mode =3D=3D MODE_SERVER && !(o->comp.flags & COMP_F_MIGRATE= )) { @@ -467,8 +467,10 @@ { if (!tls_item_in_cipher_list(token, dco_get_supported_ciphers())) { - msg(msglevel, "Note: cipher '%s' in --data-ciphers is not supp= orted " - "by ovpn-dco, disabling data channel offload.", token); + msg(msglevel, + "Note: cipher '%s' in --data-ciphers is not supported " + "by ovpn-dco, disabling data channel offload.", + token); gc_free(&gc); return false; } @@ -484,7 +486,7 @@ if (!o->use_peer_id) { msg(msglevel, "OPTIONS IMPORT: Server did not request DATA_V2 pack= et " - "format required for data channel offload"); + "format required for data channel offload"); return false; } return true; @@ -514,8 +516,7 @@ } #endif int ret =3D dco_new_peer(&c->c1.tuntap->dco, multi->peer_id, sock->sd,= NULL, - proto_is_dgram(sock->info.proto) ? remoteaddr := NULL, - NULL, NULL); + proto_is_dgram(sock->info.proto) ? remoteaddr := NULL, NULL, NULL); if (ret < 0) { return ret; @@ -548,7 +549,8 @@ #if ENABLE_IP_PKTINFO struct context *c =3D &mi->context; - if (!proto_is_udp(c->c2.link_sockets[0]->info.proto) || !(c->options.s= ockflags & SF_USE_IP_PKTINFO)) + if (!proto_is_udp(c->c2.link_sockets[0]->info.proto) + || !(c->options.sockflags & SF_USE_IP_PKTINFO)) { return false; } @@ -632,8 +634,8 @@ localaddr =3D (struct sockaddr *)&local; } - int ret =3D dco_new_peer(&c->c1.tuntap->dco, peer_id, sd, localaddr, - remoteaddr, vpn_addr4, vpn_addr6); + int ret =3D + dco_new_peer(&c->c1.tuntap->dco, peer_id, sd, localaddr, remoteadd= r, vpn_addr4, vpn_addr6); if (ret < 0) { return ret; @@ -645,8 +647,7 @@ } void -dco_install_iroute(struct multi_context *m, struct multi_instance *mi, - struct mroute_addr *addr) +dco_install_iroute(struct multi_context *m, struct multi_instance *mi, str= uct mroute_addr *addr) { #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_WIN32) if (!dco_enabled(&m->top.options)) @@ -667,7 +668,8 @@ if (addrtype =3D=3D MR_ADDR_IPV6) { #if defined(_WIN32) - dco_win_add_iroute_ipv6(&c->c1.tuntap->dco, addr->v6.addr, addr->n= etbits, c->c2.tls_multi->peer_id); + dco_win_add_iroute_ipv6(&c->c1.tuntap->dco, addr->v6.addr, addr->n= etbits, + c->c2.tls_multi->peer_id); #else net_route_v6_add(&m->top.net_ctx, &addr->v6.addr, addr->netbits, &mi->context.c2.push_ifconfig_ipv6_local, c->c1.t= untap->actual_name, 0, @@ -677,12 +679,12 @@ else if (addrtype =3D=3D MR_ADDR_IPV4) { #if defined(_WIN32) - dco_win_add_iroute_ipv4(&c->c1.tuntap->dco, addr->v4.addr, addr->n= etbits, c->c2.tls_multi->peer_id); + dco_win_add_iroute_ipv4(&c->c1.tuntap->dco, addr->v4.addr, addr->n= etbits, + c->c2.tls_multi->peer_id); #else in_addr_t dest =3D htonl(addr->v4.addr); - net_route_v4_add(&m->top.net_ctx, &dest, addr->netbits, - &mi->context.c2.push_ifconfig_local, c->c1.tuntap= ->actual_name, 0, - DCO_IROUTE_METRIC); + net_route_v4_add(&m->top.net_ctx, &dest, addr->netbits, &mi->conte= xt.c2.push_ifconfig_local, + c->c1.tuntap->actual_name, 0, DCO_IROUTE_METRIC); #endif } #endif /* if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_= WIN32) */ @@ -702,32 +704,28 @@ if (mi->context.c2.push_ifconfig_defined) { - for (const struct iroute *ir =3D c->options.iroutes; - ir; - ir =3D ir->next) + for (const struct iroute *ir =3D c->options.iroutes; ir; ir =3D ir= ->next) { #if defined(_WIN32) dco_win_del_iroute_ipv4(&c->c1.tuntap->dco, htonl(ir->network)= , ir->netbits); #else net_route_v4_del(&m->top.net_ctx, &ir->network, ir->netbits, - &mi->context.c2.push_ifconfig_local, c->c1.tu= ntap->actual_name, - 0, DCO_IROUTE_METRIC); + &mi->context.c2.push_ifconfig_local, c->c1.tu= ntap->actual_name, 0, + DCO_IROUTE_METRIC); #endif } } if (mi->context.c2.push_ifconfig_ipv6_defined) { - for (const struct iroute_ipv6 *ir6 =3D c->options.iroutes_ipv6; - ir6; - ir6 =3D ir6->next) + for (const struct iroute_ipv6 *ir6 =3D c->options.iroutes_ipv6; ir= 6; ir6 =3D ir6->next) { #if defined(_WIN32) dco_win_del_iroute_ipv6(&c->c1.tuntap->dco, ir6->network, ir6-= >netbits); #else net_route_v6_del(&m->top.net_ctx, &ir6->network, ir6->netbits, - &mi->context.c2.push_ifconfig_ipv6_local, c->= c1.tuntap->actual_name, - 0, DCO_IROUTE_METRIC); + &mi->context.c2.push_ifconfig_ipv6_local, c->= c1.tuntap->actual_name, 0, + DCO_IROUTE_METRIC); #endif } } diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h index f38316d..b1bd210 100644 --- a/src/openvpn/dco.h +++ b/src/openvpn/dco.h @@ -44,8 +44,8 @@ struct tls_multi; struct tuntap; -#define DCO_IROUTE_METRIC 100 -#define DCO_DEFAULT_METRIC 200 +#define DCO_IROUTE_METRIC 100 +#define DCO_DEFAULT_METRIC 200 #if defined(ENABLE_DCO) @@ -156,9 +156,8 @@ * * @return 0 on success or a negative error code otherwise */ -int init_key_dco_bi(struct tls_multi *multi, struct key_state *ks, - const struct key2 *key2, int key_direction, - const char *ciphername, bool server); +int init_key_dco_bi(struct tls_multi *multi, struct key_state *ks, const s= truct key2 *key2, + int key_direction, const char *ciphername, bool server= ); /** * Possibly swap or wipe keys from DCO @@ -190,8 +189,8 @@ * * @return 0 on success or a negative error code otherwi= se */ -int dco_set_peer(dco_context_t *dco, unsigned int peerid, - int keepalive_interval, int keepalive_timeout, int mss); +int dco_set_peer(dco_context_t *dco, unsigned int peerid, int keepalive_in= terval, + int keepalive_timeout, int mss); /** * Remove a peer from DCO @@ -262,7 +261,7 @@ { return false; } -#else /* if defined(ENABLE_DCO) */ +#else /* if defined(ENABLE_DCO) */ typedef void *dco_context_t; @@ -326,9 +325,8 @@ } static inline int -init_key_dco_bi(struct tls_multi *multi, struct key_state *ks, - const struct key2 *key2, int key_direction, - const char *ciphername, bool server) +init_key_dco_bi(struct tls_multi *multi, struct key_state *ks, const struc= t key2 *key2, + int key_direction, const char *ciphername, bool server) { return 0; } @@ -347,8 +345,8 @@ } static inline int -dco_set_peer(dco_context_t *dco, unsigned int peerid, - int keepalive_interval, int keepalive_timeout, int mss) +dco_set_peer(dco_context_t *dco, unsigned int peerid, int keepalive_interv= al, int keepalive_timeout, + int mss) { return 0; } @@ -365,8 +363,7 @@ } static inline void -dco_install_iroute(struct multi_context *m, struct multi_instance *mi, - struct mroute_addr *addr) +dco_install_iroute(struct multi_context *m, struct multi_instance *mi, str= uct mroute_addr *addr) { } diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index b8816c6..7175d37 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -73,9 +73,8 @@ } int -dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, - struct sockaddr *localaddr, struct sockaddr *remoteaddr, - struct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6) +dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, struct socka= ddr *localaddr, + struct sockaddr *remoteaddr, struct in_addr *vpn_ipv4, struct= in6_addr *vpn_ipv6) { struct ifdrv drv; nvlist_t *nvl, *local_nvl, *remote_nvl; @@ -99,8 +98,7 @@ if (vpn_ipv4) { - nvlist_add_binary(nvl, "vpn_ipv4", &vpn_ipv4->s_addr, - sizeof(vpn_ipv4->s_addr)); + nvlist_add_binary(nvl, "vpn_ipv4", &vpn_ipv4->s_addr, sizeof(vpn_i= pv4->s_addr)); } if (vpn_ipv6) @@ -216,7 +214,7 @@ if (ret) { ret =3D -errno; - msg(M_WARN|M_ERRNO, "Failed to create interface %s (SIOCIFCREATE2)= ", ifr.ifr_name); + msg(M_WARN | M_ERRNO, "Failed to create interface %s (SIOCIFCREATE= 2)", ifr.ifr_name); return ret; } @@ -238,7 +236,7 @@ ret =3D -errno; /* Delete the created interface again. */ (void)ioctl(tt->dco.fd, SIOCIFDESTROY, &ifr); - msg(M_WARN|M_ERRNO, "Failed to create interface %s (SIOCSIFNAME)",= ifr.ifr_data); + msg(M_WARN | M_ERRNO, "Failed to create interface %s (SIOCSIFNAME)= ", ifr.ifr_data); return ret; } @@ -350,8 +348,7 @@ } int -dco_del_key(dco_context_t *dco, unsigned int peerid, - dco_key_slot_t slot) +dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { struct ifdrv drv; nvlist_t *nvl; @@ -421,18 +418,16 @@ } int -dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, - dco_key_slot_t slot, - const uint8_t *encrypt_key, const uint8_t *encrypt_iv, - const uint8_t *decrypt_key, const uint8_t *decrypt_iv, - const char *ciphername) +dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_key_sl= ot_t slot, + const uint8_t *encrypt_key, const uint8_t *encrypt_iv, const u= int8_t *decrypt_key, + const uint8_t *decrypt_iv, const char *ciphername) { struct ifdrv drv; nvlist_t *nvl, *encrypt_nvl, *decrypt_nvl; int ret; - msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", - __func__, slot, keyid, peerid, ciphername); + msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", __fu= nc__, slot, keyid, peerid, + ciphername); nvl =3D nvlist_create(0); @@ -470,16 +465,15 @@ } int -dco_set_peer(dco_context_t *dco, unsigned int peerid, - int keepalive_interval, int keepalive_timeout, +dco_set_peer(dco_context_t *dco, unsigned int peerid, int keepalive_interv= al, int keepalive_timeout, int mss) { struct ifdrv drv; nvlist_t *nvl; int ret; - msg(D_DCO_DEBUG, "%s: peer-id %d, ping interval %d, ping timeout %d", - __func__, peerid, keepalive_interval, keepalive_timeout); + msg(D_DCO_DEBUG, "%s: peer-id %d, ping interval %d, ping timeout %d", = __func__, peerid, + keepalive_interval, keepalive_timeout); nvl =3D nvlist_create(0); nvlist_add_number(nvl, "peerid", peerid); @@ -699,7 +693,6 @@ static void dco_update_peer_stat(struct multi_context *m, uint32_t peerid, const nvlis= t_t *nvl) { - if (peerid >=3D m->max_clients || !m->instances[peerid]) { msg(M_WARN, "dco_update_peer_stat: invalid peer ID %d returned by = kernel", peerid); @@ -716,7 +709,6 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m, const bool raise_sigusr1_on_err) { - struct ifdrv drv; uint8_t *buf =3D NULL; size_t buf_size =3D 4096; diff --git a/src/openvpn/dco_freebsd.h b/src/openvpn/dco_freebsd.h index e1a054e..28d97bb 100644 --- a/src/openvpn/dco_freebsd.h +++ b/src/openvpn/dco_freebsd.h @@ -27,25 +27,28 @@ #include "ovpn_dco_freebsd.h" -#define DCO_IROUTE_METRIC 100 +#define DCO_IROUTE_METRIC 100 typedef enum ovpn_key_slot dco_key_slot_t; typedef enum ovpn_key_cipher dco_cipher_t; -enum ovpn_message_type_t { +enum ovpn_message_type_t +{ OVPN_CMD_DEL_PEER, OVPN_CMD_PACKET, OVPN_CMD_SWAP_KEYS, }; -enum ovpn_del_reason_t { +enum ovpn_del_reason_t +{ OVPN_DEL_PEER_REASON_EXPIRED, OVPN_DEL_PEER_REASON_TRANSPORT_ERROR, OVPN_DEL_PEER_REASON_USERSPACE, OVPN_DEL_PEER_REASON_TRANSPORT_DISCONNECT, }; -typedef struct dco_context { +typedef struct dco_context +{ bool open; int fd; int pipefd[2]; diff --git a/src/openvpn/dco_internal.h b/src/openvpn/dco_internal.h index 27d03ef..866b364 100644 --- a/src/openvpn/dco_internal.h +++ b/src/openvpn/dco_internal.h @@ -60,17 +60,14 @@ * They are implemented by dco_linux.c */ =20 -int dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, - struct sockaddr *localaddr, struct sockaddr *remoteaddr, - struct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6); +int dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, struct s= ockaddr *localaddr, + struct sockaddr *remoteaddr, struct in_addr *vpn_ipv4, st= ruct in6_addr *vpn_ipv6); int dco_del_peer(dco_context_t *dco, unsigned int peerid); -int dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, - dco_key_slot_t slot, - const uint8_t *encrypt_key, const uint8_t *encrypt_iv, - const uint8_t *decrypt_key, const uint8_t *decrypt_iv, - const char *ciphername); +int dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_ke= y_slot_t slot, + const uint8_t *encrypt_key, const uint8_t *encrypt_iv, con= st uint8_t *decrypt_key, + const uint8_t *decrypt_iv, const char *ciphername); int dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t sl= ot); diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index 22a445a..075efe8 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -55,8 +55,7 @@ * have to explicitly do it to prevent the kernel from failing upon * parsing of the message */ -#define nla_nest_start(_msg, _type) \ - nla_nest_start(_msg, (_type) | NLA_F_NESTED) +#define nla_nest_start(_msg, _type) nla_nest_start(_msg, (_type) | NLA_F_N= ESTED) static int ovpn_get_mcast_id(dco_context_t *dco); @@ -90,8 +89,7 @@ ret =3D genl_connect(nl_sock); if (ret) { - msg(msglevel, "Cannot connect to generic netlink: %s", - nl_geterror(ret)); + msg(msglevel, "Cannot connect to generic netlink: %s", nl_geterror= (ret)); goto err_sock; } set_cloexec(nl_socket_get_fd(nl_sock)); @@ -99,8 +97,7 @@ ret =3D genl_ctrl_resolve(nl_sock, OVPN_FAMILY_NAME); if (ret < 0) { - msg(msglevel, "Cannot find ovpn_dco netlink component: %s", - nl_geterror(ret)); + msg(msglevel, "Cannot find ovpn_dco netlink component: %s", nl_get= error(ret)); } err_sock: @@ -158,7 +155,8 @@ default: if (ret) { - msg(M_NONFATAL, "%s: netlink reports error (%d): %s", pref= ix, ret, nl_geterror(-ret)); + msg(M_NONFATAL, "%s: netlink reports error (%d): %s", pref= ix, ret, + nl_geterror(-ret)); } break; } @@ -178,8 +176,8 @@ * @return status of sending the message */ static int -ovpn_nl_msg_send(dco_context_t *dco, struct nl_msg *nl_msg, ovpn_nl_cb cb, - void *cb_arg, const char *prefix) +ovpn_nl_msg_send(dco_context_t *dco, struct nl_msg *nl_msg, ovpn_nl_cb cb,= void *cb_arg, + const char *prefix) { dco->status =3D 1; @@ -193,8 +191,8 @@ if (dco->status < 0) { - msg(M_INFO, "%s: failed to send netlink message: %s (%d)", - prefix, strerror(-dco->status), dco->status); + msg(M_INFO, "%s: failed to send netlink message: %s (%d)", prefix,= strerror(-dco->status), + dco->status); } =20 return dco->status; @@ -206,7 +204,6 @@ struct sockaddr_in6 *sock6 =3D (struct sockaddr_in6 *)sock; if (sock->sa_family =3D=3D AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sock6->si= n6_addr)) { - struct sockaddr_in *sock4; ALLOC_OBJ_CLEAR_GC(sock4, struct sockaddr_in, gc); memcpy(&sock4->sin_addr, sock6->sin6_addr.s6_addr + 12, 4); @@ -218,9 +215,8 @@ } int -dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, - struct sockaddr *localaddr, struct sockaddr *remoteaddr, - struct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6) +dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, struct socka= ddr *localaddr, + struct sockaddr *remoteaddr, struct in_addr *vpn_ipv4, struct= in6_addr *vpn_ipv6) { struct gc_arena gc =3D gc_new(); const char *remotestr =3D "[undefined]"; @@ -228,8 +224,7 @@ { remotestr =3D print_sockaddr(remoteaddr, &gc); } - msg(D_DCO_DEBUG, "%s: peer-id %d, fd %d, remote addr: %s", __func__, - peerid, sd, remotestr); + msg(D_DCO_DEBUG, "%s: peer-id %d, fd %d, remote addr: %s", __func__, p= eerid, sd, remotestr); struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_PEER_NEW= ); struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_A_PEER); @@ -247,14 +242,17 @@ { NLA_PUT(nl_msg, OVPN_A_PEER_REMOTE_IPV4, sizeof(struct in_addr= ), &((struct sockaddr_in *)remoteaddr)->sin_addr); - NLA_PUT_U16(nl_msg, OVPN_A_PEER_REMOTE_PORT, ((struct sockaddr= _in *)remoteaddr)->sin_port); + NLA_PUT_U16(nl_msg, OVPN_A_PEER_REMOTE_PORT, + ((struct sockaddr_in *)remoteaddr)->sin_port); } else if (remoteaddr->sa_family =3D=3D AF_INET6) { NLA_PUT(nl_msg, OVPN_A_PEER_REMOTE_IPV6, sizeof(struct in6_add= r), &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); - NLA_PUT_U16(nl_msg, OVPN_A_PEER_REMOTE_PORT, ((struct sockaddr= _in6 *)remoteaddr)->sin6_port); - NLA_PUT_U32(nl_msg, OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID, ((struct= sockaddr_in6 *)remoteaddr)->sin6_scope_id); + NLA_PUT_U16(nl_msg, OVPN_A_PEER_REMOTE_PORT, + ((struct sockaddr_in6 *)remoteaddr)->sin6_port); + NLA_PUT_U32(nl_msg, OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID, + ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id= ); } } @@ -280,8 +278,7 @@ } if (vpn_ipv6) { - NLA_PUT(nl_msg, OVPN_A_PEER_VPN_IPV6, sizeof(struct in6_addr), - vpn_ipv6); + NLA_PUT(nl_msg, OVPN_A_PEER_VPN_IPV6, sizeof(struct in6_addr), vpn= _ipv6); } nla_nest_end(nl_msg, attr); @@ -294,7 +291,7 @@ } static int -ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void *arg) +ovpn_nl_cb_finish(struct nl_msg(*msg) __attribute__((unused)), void *arg) { int *status =3D arg; @@ -315,7 +312,8 @@ * missing at the message level * @NLMSGERR_ATTR_MISS_NEST: offset of the nest where attribute was missing */ -enum ovpn_nlmsgerr_attrs { +enum ovpn_nlmsgerr_attrs +{ OVPN_NLMSGERR_ATTR_MISS_TYPE =3D 5, OVPN_NLMSGERR_ATTR_MISS_NEST =3D 6, OVPN_NLMSGERR_ATTR_MAX =3D 6, @@ -330,8 +328,7 @@ * reply to see if it contains a human-readable error. If found, it is pri= nted. */ static int -ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)), - struct nlmsgerr *err, void *arg) +ovpn_nl_cb_error(struct sockaddr_nl(*nla) __attribute__((unused)), struct = nlmsgerr *err, void *arg) { struct nlmsghdr *nlh =3D (struct nlmsghdr *)err - 1; struct nlattr *tb_msg[OVPN_NLMSGERR_ATTR_MAX + 1]; @@ -365,8 +362,7 @@ { len =3D strnlen((char *)nla_data(tb_msg[NLMSGERR_ATTR_MSG]), nla_len(tb_msg[NLMSGERR_ATTR_MSG])); - msg(M_WARN, "kernel error: %*s", len, - (char *)nla_data(tb_msg[NLMSGERR_ATTR_MSG])); + msg(M_WARN, "kernel error: %*s", len, (char *)nla_data(tb_msg[NLMS= GERR_ATTR_MSG])); } if (tb_msg[OVPN_NLMSGERR_ATTR_MISS_NEST]) @@ -399,14 +395,12 @@ int ret =3D genl_connect(dco->nl_sock); if (ret) { - msg(M_ERR, "Cannot connect to generic netlink: %s", - nl_geterror(ret)); + msg(M_ERR, "Cannot connect to generic netlink: %s", nl_geterror(re= t)); } /* enable Extended ACK for detailed error reporting */ ret =3D 1; - setsockopt(nl_socket_get_fd(dco->nl_sock), SOL_NETLINK, NETLINK_EXT_AC= K, - &ret, sizeof(ret)); + setsockopt(nl_socket_get_fd(dco->nl_sock), SOL_NETLINK, NETLINK_EXT_AC= K, &ret, sizeof(ret)); /* set close on exec and non-block on the netlink socket */ set_cloexec(nl_socket_get_fd(dco->nl_sock)); @@ -421,10 +415,8 @@ nl_socket_set_cb(dco->nl_sock, dco->nl_cb); nl_cb_err(dco->nl_cb, NL_CB_CUSTOM, ovpn_nl_cb_error, &dco->status); - nl_cb_set(dco->nl_cb, NL_CB_FINISH, NL_CB_CUSTOM, ovpn_nl_cb_finish, - &dco->status); - nl_cb_set(dco->nl_cb, NL_CB_ACK, NL_CB_CUSTOM, ovpn_nl_cb_finish, - &dco->status); + nl_cb_set(dco->nl_cb, NL_CB_FINISH, NL_CB_CUSTOM, ovpn_nl_cb_finish, &= dco->status); + nl_cb_set(dco->nl_cb, NL_CB_ACK, NL_CB_CUSTOM, ovpn_nl_cb_finish, &dco= ->status); /* The async PACKET messages confuse libnl and it will drop them with * wrong sequence numbers (NLE_SEQ_MISMATCH), so disable libnl's seque= nce @@ -434,7 +426,7 @@ /* nl library sets the buffer size to 32k/32k by default which is some= times * overrun with very fast connecting/disconnecting clients. * TODO: fix this in a better and more reliable way */ - ASSERT(!nl_socket_set_buffer_size(dco->nl_sock, 1024*1024, 1024*1024)); + ASSERT(!nl_socket_set_buffer_size(dco->nl_sock, 1024 * 1024, 1024 * 10= 24)); } bool @@ -478,7 +470,7 @@ if (dco->ovpn_dco_mcast_id < 0) { - msg(M_ERR, "cannot get mcast group: %s", nl_geterror(dco->ovpn_dc= o_mcast_id)); + msg(M_ERR, "cannot get mcast group: %s", nl_geterror(dco->ovpn_dco= _mcast_id)); } /* Register for ovpn-dco specific multicast messages that the kernel m= ay @@ -575,8 +567,7 @@ int -dco_del_key(dco_context_t *dco, unsigned int peerid, - dco_key_slot_t slot) +dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { int ret =3D -EMSGSIZE; msg(D_DCO_DEBUG, "%s: peer-id %d, slot %d", __func__, peerid, slot); @@ -600,14 +591,12 @@ } int -dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, - dco_key_slot_t slot, - const uint8_t *encrypt_key, const uint8_t *encrypt_iv, - const uint8_t *decrypt_key, const uint8_t *decrypt_iv, - const char *ciphername) +dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_key_sl= ot_t slot, + const uint8_t *encrypt_key, const uint8_t *encrypt_iv, const u= int8_t *decrypt_key, + const uint8_t *decrypt_iv, const char *ciphername) { - msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", - __func__, slot, keyid, peerid, ciphername); + msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", __fu= nc__, slot, keyid, peerid, + ciphername); =20 const size_t key_len =3D cipher_kt_key_size(ciphername); const int nonce_tail_len =3D 8; @@ -628,23 +617,19 @@ NLA_PUT_U32(nl_msg, OVPN_A_KEYCONF_KEY_ID, keyid); NLA_PUT_U32(nl_msg, OVPN_A_KEYCONF_CIPHER_ALG, dco_cipher); - struct nlattr *key_enc =3D nla_nest_start(nl_msg, - OVPN_A_KEYCONF_ENCRYPT_DIR); + struct nlattr *key_enc =3D nla_nest_start(nl_msg, OVPN_A_KEYCONF_ENCRY= PT_DIR); if (dco_cipher !=3D OVPN_CIPHER_ALG_NONE) { NLA_PUT(nl_msg, OVPN_A_KEYDIR_CIPHER_KEY, key_len, encrypt_key); - NLA_PUT(nl_msg, OVPN_A_KEYDIR_NONCE_TAIL, nonce_tail_len, - encrypt_iv); + NLA_PUT(nl_msg, OVPN_A_KEYDIR_NONCE_TAIL, nonce_tail_len, encrypt_= iv); } nla_nest_end(nl_msg, key_enc); - struct nlattr *key_dec =3D nla_nest_start(nl_msg, - OVPN_A_KEYCONF_DECRYPT_DIR); + struct nlattr *key_dec =3D nla_nest_start(nl_msg, OVPN_A_KEYCONF_DECRY= PT_DIR); if (dco_cipher !=3D OVPN_CIPHER_ALG_NONE) { NLA_PUT(nl_msg, OVPN_A_KEYDIR_CIPHER_KEY, key_len, decrypt_key); - NLA_PUT(nl_msg, OVPN_A_KEYDIR_NONCE_TAIL, nonce_tail_len, - decrypt_iv); + NLA_PUT(nl_msg, OVPN_A_KEYDIR_NONCE_TAIL, nonce_tail_len, decrypt_= iv); } nla_nest_end(nl_msg, key_dec); @@ -659,11 +644,11 @@ } int -dco_set_peer(dco_context_t *dco, unsigned int peerid, - int keepalive_interval, int keepalive_timeout, int mss) +dco_set_peer(dco_context_t *dco, unsigned int peerid, int keepalive_interv= al, int keepalive_timeout, + int mss) { - msg(D_DCO_DEBUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __func__, - peerid, keepalive_interval, keepalive_timeout, mss); + msg(D_DCO_DEBUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __func__, = peerid, + keepalive_interval, keepalive_timeout, mss); struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_PEER_SET= ); if (!nl_msg) @@ -674,10 +659,8 @@ struct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_A_PEER); int ret =3D -EMSGSIZE; NLA_PUT_U32(nl_msg, OVPN_A_PEER_ID, peerid); - NLA_PUT_U32(nl_msg, OVPN_A_PEER_KEEPALIVE_INTERVAL, - keepalive_interval); - NLA_PUT_U32(nl_msg, OVPN_A_PEER_KEEPALIVE_TIMEOUT, - keepalive_timeout); + NLA_PUT_U32(nl_msg, OVPN_A_PEER_KEEPALIVE_INTERVAL, keepalive_interval= ); + NLA_PUT_U32(nl_msg, OVPN_A_PEER_KEEPALIVE_TIMEOUT, keepalive_timeout); nla_nest_end(nl_msg, attr); ret =3D ovpn_nl_msg_send(dco, nl_msg, NULL, NULL, __func__); @@ -701,8 +684,7 @@ struct nlattr *tb[CTRL_ATTR_MAX + 1]; struct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg)); - nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), - genlmsg_attrlen(gnlh, 0), NULL); + nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrle= n(gnlh, 0), NULL); if (!tb[CTRL_ATTR_MCAST_GROUPS]) { @@ -715,18 +697,16 @@ { struct nlattr *tb_mcgrp[CTRL_ATTR_MCAST_GRP_MAX + 1]; - nla_parse(tb_mcgrp, CTRL_ATTR_MCAST_GRP_MAX, - nla_data(mcgrp), nla_len(mcgrp), NULL); + nla_parse(tb_mcgrp, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), nla_= len(mcgrp), NULL); - if (!tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME] - || !tb_mcgrp[CTRL_ATTR_MCAST_GRP_ID]) + if (!tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME] || !tb_mcgrp[CTRL_ATTR_MCA= ST_GRP_ID]) { continue; } - if (strncmp(nla_data(tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME]), - OVPN_MCGRP_PEERS, - nla_len(tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME])) !=3D 0) + if (strncmp(nla_data(tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME]), OVPN_MCG= RP_PEERS, + nla_len(tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME])) + !=3D 0) { continue; } @@ -784,8 +764,7 @@ return NL_STOP; } - if (nla_parse(attrs, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0), - genlmsg_attrlen(gnlh, 0), NULL)) + if (nla_parse(attrs, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_at= trlen(gnlh, 0), NULL)) { msg(D_DCO, "received bogus data from ovpn-dco"); return NL_STOP; @@ -803,9 +782,8 @@ uint32_t ifindex =3D nla_get_u32(attrs[OVPN_A_IFINDEX]); if (ifindex !=3D dco->ifindex) { - msg(D_DCO_DEBUG, - "ovpn-dco: ignoring message (type=3D%d) for foreign ifindex %d= ", - gnlh->cmd, ifindex); + msg(D_DCO_DEBUG, "ovpn-dco: ignoring message (type=3D%d) for forei= gn ifindex %d", gnlh->cmd, + ifindex); return NL_STOP; } @@ -827,8 +805,7 @@ } struct nlattr *dp_attrs[OVPN_A_PEER_MAX + 1]; - if (nla_parse_nested(dp_attrs, OVPN_A_PEER_MAX, attrs[OVPN_A_P= EER], - NULL)) + if (nla_parse_nested(dp_attrs, OVPN_A_PEER_MAX, attrs[OVPN_A_P= EER], NULL)) { msg(D_DCO, "ovpn-dco: can't parse peer in PEER_DEL_NTF mes= ssage"); return NL_STOP; @@ -848,8 +825,9 @@ int reason =3D nla_get_u32(dp_attrs[OVPN_A_PEER_DEL_REASON]); unsigned int peerid =3D nla_get_u32(dp_attrs[OVPN_A_PEER_ID]); - msg(D_DCO_DEBUG, "ovpn-dco: received CMD_PEER_DEL_NTF, ifindex= : %d, peer-id %u, reason: %d", - ifindex, peerid, reason); + msg(D_DCO_DEBUG, + "ovpn-dco: received CMD_PEER_DEL_NTF, ifindex: %d, peer-id= %u, reason: %d", ifindex, + peerid, reason); dco->dco_message_peer_id =3D peerid; dco->dco_del_peer_reason =3D reason; dco->dco_message_type =3D OVPN_CMD_PEER_DEL_NTF; @@ -865,8 +843,7 @@ } struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX + 1]; - if (nla_parse_nested(dp_attrs, OVPN_A_KEYCONF_MAX, - attrs[OVPN_A_KEYCONF], NULL)) + if (nla_parse_nested(dp_attrs, OVPN_A_KEYCONF_MAX, attrs[OVPN_= A_KEYCONF], NULL)) { msg(D_DCO, "ovpn-dco: can't parse keyconf in KEY_SWAP_NTF = message"); return NL_STOP; @@ -885,8 +862,9 @@ int key_id =3D nla_get_u16(dp_attrs[OVPN_A_KEYCONF_KEY_ID]); unsigned int peer_id =3D nla_get_u32(dp_attrs[OVPN_A_KEYCONF_P= EER_ID]); =20 - msg(D_DCO_DEBUG, "ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex= : %d, peer-id %u, key-id: %d", - ifindex, peer_id, key_id); + msg(D_DCO_DEBUG, + "ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex: %d, peer-id= %u, key-id: %d", ifindex, + peer_id, key_id); dco->dco_message_peer_id =3D peer_id; dco->dco_message_key_id =3D key_id; dco->dco_message_type =3D OVPN_CMD_KEY_SWAP_NTF; @@ -931,49 +909,41 @@ if (tb[OVPN_A_PEER_LINK_RX_BYTES]) { c2->dco_read_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_LINK_RX_BY= TES]); - msg(D_DCO_DEBUG, "%s / dco_read_bytes: " counter_format, __func__, - c2->dco_read_bytes); + msg(D_DCO_DEBUG, "%s / dco_read_bytes: " counter_format, __func__,= c2->dco_read_bytes); } else { - msg(M_WARN, "%s: no link RX bytes provided in reply for peer %u", - __func__, id); + msg(M_WARN, "%s: no link RX bytes provided in reply for peer %u", = __func__, id); } if (tb[OVPN_A_PEER_LINK_TX_BYTES]) { c2->dco_write_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_LINK_TX_B= YTES]); - msg(D_DCO_DEBUG, "%s / dco_write_bytes: " counter_format, __func__, - c2->dco_write_bytes); + msg(D_DCO_DEBUG, "%s / dco_write_bytes: " counter_format, __func__= , c2->dco_write_bytes); } else { - msg(M_WARN, "%s: no link TX bytes provided in reply for peer %u", - __func__, id); + msg(M_WARN, "%s: no link TX bytes provided in reply for peer %u", = __func__, id); } if (tb[OVPN_A_PEER_VPN_RX_BYTES]) { c2->tun_read_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_VPN_RX_BYT= ES]); - msg(D_DCO_DEBUG, "%s / tun_read_bytes: " counter_format, __func__, - c2->tun_read_bytes); + msg(D_DCO_DEBUG, "%s / tun_read_bytes: " counter_format, __func__,= c2->tun_read_bytes); } else { - msg(M_WARN, "%s: no VPN RX bytes provided in reply for peer %u", - __func__, id); + msg(M_WARN, "%s: no VPN RX bytes provided in reply for peer %u", _= _func__, id); } if (tb[OVPN_A_PEER_VPN_TX_BYTES]) { c2->tun_write_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_VPN_TX_BY= TES]); - msg(D_DCO_DEBUG, "%s / tun_write_bytes: " counter_format, __func__, - c2->tun_write_bytes); + msg(D_DCO_DEBUG, "%s / tun_write_bytes: " counter_format, __func__= , c2->tun_write_bytes); } else { - msg(M_WARN, "%s: no VPN TX bytes provided in reply for peer %u", - __func__, id); + msg(M_WARN, "%s: no VPN TX bytes provided in reply for peer %u", _= _func__, id); } } @@ -985,8 +955,7 @@ msg(D_DCO_DEBUG, "%s: parsing message...", __func__); - nla_parse(tb, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0), - genlmsg_attrlen(gnlh, 0), NULL); + nla_parse(tb, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(g= nlh, 0), NULL); if (!tb[OVPN_A_PEER]) { @@ -1007,8 +976,7 @@ if (peer_id >=3D m->max_clients || !m->instances[peer_id]) { - msg(M_WARN, "%s: cannot store DCO stats for peer %u", __func__, - peer_id); + msg(M_WARN, "%s: cannot store DCO stats for peer %u", __func__, pe= er_id); return NL_SKIP; } @@ -1034,8 +1002,8 @@ if (raise_sigusr1_on_err && ret < 0) { msg(M_WARN, "Error retrieving DCO peer stats: the underlying DCO p= eer" - "may have been deleted from the kernel without notifying " - "userspace. Restarting the session"); + "may have been deleted from the kernel without notifyi= ng " + "userspace. Restarting the session"); register_signal(m->top.sig, SIGUSR1, "dco peer stats error"); } return ret; @@ -1050,8 +1018,7 @@ msg(D_DCO_DEBUG, "%s: parsing message...", __func__); - nla_parse(tb, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0), - genlmsg_attrlen(gnlh, 0), NULL); + nla_parse(tb, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(g= nlh, 0), NULL); if (!tb[OVPN_A_PEER]) { @@ -1111,8 +1078,8 @@ if (raise_sigusr1_on_err && ret < 0) { msg(M_WARN, "Error retrieving DCO peer stats: the underlying DCO p= eer" - "may have been deleted from the kernel without notifying " - "userspace. Restarting the session"); + "may have been deleted from the kernel without notifyi= ng " + "userspace. Restarting the session"); register_signal(c->sig, SIGUSR1, "dco peer stats error"); } return ret; @@ -1123,8 +1090,7 @@ { if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0) { - msg(msglevel, - "Note: Kernel support for ovpn-dco missing, disabling data cha= nnel offload."); + msg(msglevel, "Note: Kernel support for ovpn-dco missing, disablin= g data channel offload."); return false; } diff --git a/src/openvpn/dco_linux.h b/src/openvpn/dco_linux.h index 4e441ec..1800752 100644 --- a/src/openvpn/dco_linux.h +++ b/src/openvpn/dco_linux.h @@ -32,7 +32,7 @@ #include /* Defines to avoid mismatching with other platforms */ -#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF #define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF typedef enum ovpn_key_slot dco_key_slot_t; @@ -42,12 +42,14 @@ #ifndef IFLA_OVPN_MAX -enum ovpn_mode { +enum ovpn_mode +{ OVPN_MODE_P2P, OVPN_MODE_MP, }; -enum ovpn_ifla_attrs { +enum ovpn_ifla_attrs +{ IFLA_OVPN_UNSPEC =3D 0, IFLA_OVPN_MODE, diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 2a13658..ff8205b 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -76,14 +76,12 @@ bool res =3D false; - HANDLE h =3D CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ, - 0, NULL, OPEN_EXISTING, 0, NULL); + HANDLE h =3D CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ, 0, NULL, = OPEN_EXISTING, 0, NULL); if (h =3D=3D INVALID_HANDLE_VALUE) { /* fallback to a "normal" device, this will fail if device is alre= ady in use */ - h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ, - 0, NULL, OPEN_EXISTING, 0, NULL); + h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ, 0, NULL, OPEN_EX= ISTING, 0, NULL); } if (h =3D=3D INVALID_HANDLE_VALUE) @@ -92,8 +90,8 @@ } DWORD bytes_returned =3D 0; - if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0, - version, sizeof(*version), &bytes_returned, NULL)) + if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0, version, size= of(*version), + &bytes_returned, NULL)) { goto done; } @@ -146,7 +144,8 @@ /* set mp mode */ OVPN_MODE m =3D OVPN_MODE_MP; DWORD bytes_returned =3D 0; - if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_SET_MODE, &m, sizeof(m)= , NULL, 0, &bytes_returned, NULL)) + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_SET_MODE, &m, sizeof(m)= , NULL, 0, + &bytes_returned, NULL)) { msg(M_ERR, "DeviceIoControl(OVPN_IOCTL_SET_MODE) failed"); } @@ -220,7 +219,7 @@ { volatile int *signal_received =3D &sig_info->signal_received; /* GetOverlappedResultEx is available starting from Windows 8 */ - typedef BOOL (WINAPI *get_overlapped_result_ex_t)(HANDLE, LPOVERLAPPED= , LPDWORD, DWORD, BOOL); + typedef BOOL(WINAPI * get_overlapped_result_ex_t)(HANDLE, LPOVERLAPPED= , LPDWORD, DWORD, BOOL); get_overlapped_result_ex_t get_overlapped_result_ex =3D (get_overlapped_result_ex_t)GetProcAddress(GetModuleHandle("Kernel= 32.dll"), "GetOverlappedResultEx"= ); @@ -294,8 +293,8 @@ } if (!cur) { - msg(M_FATAL, "%s: Socket bind failed: Addr to bind has no %s recor= d", - __func__, addr_family_name(ai_family)); + msg(M_FATAL, "%s: Socket bind failed: Addr to bind has no %s recor= d", __func__, + addr_family_name(ai_family)); } OVPN_MP_START_VPN in, out; @@ -321,7 +320,8 @@ } void -dco_p2p_new_peer(HANDLE handle, OVERLAPPED *ov, struct link_socket *sock, = struct signal_info *sig_info) +dco_p2p_new_peer(HANDLE handle, OVERLAPPED *ov, struct link_socket *sock, + struct signal_info *sig_info) { msg(D_DCO_DEBUG, "%s", __func__); @@ -332,8 +332,7 @@ struct sockaddr *local =3D NULL; struct sockaddr *remote =3D remoteaddr->ai_addr; - if (remoteaddr->ai_protocol =3D=3D IPPROTO_TCP - || remoteaddr->ai_socktype =3D=3D SOCK_STREAM) + if (remoteaddr->ai_protocol =3D=3D IPPROTO_TCP || remoteaddr->ai_sockt= ype =3D=3D SOCK_STREAM) { peer.Proto =3D OVPN_PROTO_TCP; } @@ -405,15 +404,15 @@ } else { - dco_connect_wait(handle, ov, get_server_poll_remaining_time(so= ck->server_poll_timeout), sig_info); + dco_connect_wait(handle, ov, get_server_poll_remaining_time(so= ck->server_poll_timeout), + sig_info); } } } int -dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, - struct sockaddr *localaddr, struct sockaddr *remoteaddr, - struct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6) +dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, struct socka= ddr *localaddr, + struct sockaddr *remoteaddr, struct in_addr *vpn_ipv4, struct= in6_addr *vpn_ipv6) { msg(D_DCO_DEBUG, "%s: peer-id %d, fd %d", __func__, peerid, sd); @@ -423,7 +422,7 @@ return 0; } - OVPN_MP_NEW_PEER newPeer =3D {0}; + OVPN_MP_NEW_PEER newPeer =3D { 0 }; if (remoteaddr) { @@ -453,7 +452,8 @@ newPeer.PeerId =3D peerid; DWORD bytesReturned; - if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_NEW_PEER, &newPeer, = sizeof(newPeer), NULL, 0, &bytesReturned, NULL)) + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_NEW_PEER, &newPeer, = sizeof(newPeer), NULL, 0, + &bytesReturned, NULL)) { msg(M_ERR, "DeviceIoControl(OVPN_IOCTL_MP_NEW_PEER) failed"); } @@ -488,11 +488,11 @@ } int -dco_set_peer(dco_context_t *dco, unsigned int peerid, - int keepalive_interval, int keepalive_timeout, int mss) +dco_set_peer(dco_context_t *dco, unsigned int peerid, int keepalive_interv= al, int keepalive_timeout, + int mss) { - msg(D_DCO_DEBUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __func__, - peerid, keepalive_interval, keepalive_timeout, mss); + msg(D_DCO_DEBUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __func__, = peerid, + keepalive_interval, keepalive_timeout, mss); OVPN_MP_SET_PEER mp_peer =3D { peerid, keepalive_interval, keepalive_t= imeout, mss }; OVPN_SET_PEER peer =3D { keepalive_interval, keepalive_timeout, mss }; @@ -522,14 +522,12 @@ } int -dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, - dco_key_slot_t slot, - const uint8_t *encrypt_key, const uint8_t *encrypt_iv, - const uint8_t *decrypt_key, const uint8_t *decrypt_iv, - const char *ciphername) +dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_key_sl= ot_t slot, + const uint8_t *encrypt_key, const uint8_t *encrypt_iv, const u= int8_t *decrypt_key, + const uint8_t *decrypt_iv, const char *ciphername) { - msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", - __func__, slot, keyid, peerid, ciphername); + msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", __fu= nc__, slot, keyid, peerid, + ciphername); const int nonce_len =3D 8; size_t key_len =3D cipher_kt_key_size(ciphername); @@ -554,8 +552,8 @@ DWORD bytes_returned =3D 0; - if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_NEW_KEY, &crypto_data, - sizeof(crypto_data), NULL, 0, &bytes_returned, NU= LL)) + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_NEW_KEY, &crypto_data, = sizeof(crypto_data), NULL, + 0, &bytes_returned, NULL)) { msg(M_ERR, "DeviceIoControl(OVPN_IOCTL_NEW_KEY) failed"); return -1; @@ -565,8 +563,7 @@ int dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { - msg(D_DCO, "%s: peer-id %d, slot %d called but ignored", __func__, pee= rid, - slot); + msg(D_DCO, "%s: peer-id %d, slot %d called but ignored", __func__, pee= rid, slot); /* FIXME: Implement in driver first */ return 0; } @@ -576,7 +573,7 @@ { msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peer_id); - OVPN_MP_SWAP_KEYS swap =3D {peer_id}; + OVPN_MP_SWAP_KEYS swap =3D { peer_id }; DWORD ioctl =3D OVPN_IOCTL_SWAP_KEYS; VOID *buf =3D NULL; DWORD len =3D 0; @@ -601,8 +598,8 @@ dco_available(int msglevel) { /* try to open device by symbolic name */ - HANDLE h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRIT= E, - 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | = FILE_FLAG_OVERLAPPED, NULL); + HANDLE h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRIT= E, 0, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NU= LL); if (h !=3D INVALID_HANDLE_VALUE) { @@ -627,7 +624,7 @@ const char * dco_version_string(struct gc_arena *gc) { - OVPN_VERSION version =3D {0}; + OVPN_VERSION version =3D { 0 }; if (dco_get_version(&version)) { struct buffer out =3D alloc_buf_gc(256, gc); @@ -658,7 +655,8 @@ BOOL res =3D GetOverlappedResult(dco->tt->hand, &dco->ov, &bytes_read,= FALSE); if (res) { - msg(D_DCO_DEBUG, "%s: completion%s success [%ld]", __func__, queue= d ? "" : " non-queued", bytes_read); + msg(D_DCO_DEBUG, "%s: completion%s success [%ld]", __func__, queue= d ? "" : " non-queued", + bytes_read); dco->dco_message_peer_id =3D dco->notif_buf.PeerId; dco->dco_message_type =3D dco->notif_buf.Cmd; @@ -733,8 +731,8 @@ ZeroMemory(&stats, sizeof(OVPN_STATS)); DWORD bytes_returned =3D 0; - if (!DeviceIoControl(tt->hand, OVPN_IOCTL_GET_STATS, NULL, 0, - &stats, sizeof(stats), &bytes_returned, NULL)) + if (!DeviceIoControl(tt->hand, OVPN_IOCTL_GET_STATS, NULL, 0, &stats, = sizeof(stats), + &bytes_returned, NULL)) { msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_GET_STATS) faile= d"); return -1; @@ -764,7 +762,8 @@ /* the overlapped IOCTL will signal this event on I/O completion */ ASSERT(ResetEvent(dco->ov.hEvent)); - if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_NOTIFY_EVENT, NULL,= 0, &dco->notif_buf, sizeof(dco->notif_buf), NULL, &dco->ov)) + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_NOTIFY_EVENT, NULL,= 0, &dco->notif_buf, + sizeof(dco->notif_buf), NULL, &dco->ov)) { DWORD err =3D GetLastError(); if (err =3D=3D ERROR_IO_PENDING) /* operation queued? */ @@ -825,17 +824,21 @@ } void -dco_win_add_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned int ne= tbits, unsigned int peer_id) +dco_win_add_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned int ne= tbits, + unsigned int peer_id) { struct gc_arena gc =3D gc_new(); - OVPN_MP_IROUTE route =3D {.Addr.Addr4.S_un.S_addr =3D dst, .Netbits = =3D netbits, .PeerId =3D peer_id, .IPv6 =3D 0}; + OVPN_MP_IROUTE route =3D { + .Addr.Addr4.S_un.S_addr =3D dst, .Netbits =3D netbits, .PeerId =3D= peer_id, .IPv6 =3D 0 + }; - msg(D_DCO_DEBUG, "%s: %s/%d -> peer %d", __func__, print_in_addr_t(dst= , IA_NET_ORDER, &gc), netbits, peer_id); + msg(D_DCO_DEBUG, "%s: %s/%d -> peer %d", __func__, print_in_addr_t(dst= , IA_NET_ORDER, &gc), + netbits, peer_id); DWORD bytes_returned =3D 0; - if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_ADD_IROUTE, &route, - sizeof(route), NULL, 0, &bytes_returned, NULL)) + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_ADD_IROUTE, &route, = sizeof(route), NULL, 0, + &bytes_returned, NULL)) { msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_MP_ADD_IROUTE) f= ailed"); } @@ -844,17 +847,19 @@ } void -dco_win_add_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsigned = int netbits, unsigned int peer_id) +dco_win_add_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsigned = int netbits, + unsigned int peer_id) { struct gc_arena gc =3D gc_new(); OVPN_MP_IROUTE route =3D { .Addr.Addr6 =3D dst, .Netbits =3D netbits, = .PeerId =3D peer_id, .IPv6 =3D 1 }; - msg(D_DCO_DEBUG, "%s: %s/%d -> peer %d", __func__, print_in6_addr(dst,= IA_NET_ORDER, &gc), netbits, peer_id); + msg(D_DCO_DEBUG, "%s: %s/%d -> peer %d", __func__, print_in6_addr(dst,= IA_NET_ORDER, &gc), + netbits, peer_id); DWORD bytes_returned =3D 0; - if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_ADD_IROUTE, &route, - sizeof(route), NULL, 0, &bytes_returned, NULL)) + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_ADD_IROUTE, &route, = sizeof(route), NULL, 0, + &bytes_returned, NULL)) { msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_MP_ADD_IROUTE) f= ailed"); } @@ -867,13 +872,15 @@ { struct gc_arena gc =3D gc_new(); - OVPN_MP_IROUTE route =3D { .Addr.Addr4.S_un.S_addr =3D dst, .Netbits = =3D netbits, .PeerId =3D -1, .IPv6 =3D 0 }; + OVPN_MP_IROUTE route =3D { + .Addr.Addr4.S_un.S_addr =3D dst, .Netbits =3D netbits, .PeerId =3D= -1, .IPv6 =3D 0 + }; msg(D_DCO_DEBUG, "%s: %s/%d", __func__, print_in_addr_t(dst, IA_NET_OR= DER, &gc), netbits); DWORD bytes_returned =3D 0; - if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_DEL_IROUTE, &route, - sizeof(route), NULL, 0, &bytes_returned, NULL)) + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_DEL_IROUTE, &route, = sizeof(route), NULL, 0, + &bytes_returned, NULL)) { msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_MP_DEL_IROUTE) f= ailed"); } @@ -891,8 +898,8 @@ msg(D_DCO_DEBUG, "%s: %s/%d", __func__, print_in6_addr(dst, IA_NET_ORD= ER, &gc), netbits); DWORD bytes_returned =3D 0; - if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_DEL_IROUTE, &route, - sizeof(route), NULL, 0, &bytes_returned, NULL)) + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_DEL_IROUTE, &route, = sizeof(route), NULL, 0, + &bytes_returned, NULL)) { msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_MP_DEL_IROUTE) f= ailed"); } diff --git a/src/openvpn/dco_win.h b/src/openvpn/dco_win.h index 4513f3f..5e489da 100644 --- a/src/openvpn/dco_win.h +++ b/src/openvpn/dco_win.h @@ -33,21 +33,23 @@ typedef OVPN_KEY_SLOT dco_key_slot_t; typedef OVPN_CIPHER_ALG dco_cipher_t; -typedef enum { +typedef enum +{ DCO_MODE_UNINIT, DCO_MODE_P2P, DCO_MODE_MP } dco_mode_type; -struct dco_context { +struct dco_context +{ struct tuntap *tt; dco_mode_type ifmode; OVPN_NOTIFY_EVENT notif_buf; /**< Buffer for incoming notifications. */ - OVERLAPPED ov; /**< Used by overlapped I/O for async IOCTL. */ - int iostate; /**< State of overlapped I/O; see definitions in win32.h.= */ - struct rw_handle rwhandle; /**< Used to hook async I/O to the OpenVPN = event loop. */ - int ov_ret; /**< Win32 error code for overlapped operation, 0 for succ= ess */ + OVERLAPPED ov; /**< Used by overlapped I/O for async IOC= TL. */ + int iostate; /**< State of overlapped I/O; see definit= ions in win32.h. */ + struct rw_handle rwhandle; /**< Used to hook async I/O to the OpenVP= N event loop. */ + int ov_ret; /**< Win32 error code for overlapped oper= ation, 0 for success */ int dco_message_peer_id; int dco_message_type; @@ -59,31 +61,26 @@ typedef struct dco_context dco_context_t; -void -dco_mp_start_vpn(HANDLE handle, struct link_socket *sock); +void dco_mp_start_vpn(HANDLE handle, struct link_socket *sock); -void -dco_p2p_new_peer(HANDLE handle, OVERLAPPED *ov, struct link_socket *sock, = struct signal_info *sig_info); +void dco_p2p_new_peer(HANDLE handle, OVERLAPPED *ov, struct link_socket *s= ock, + struct signal_info *sig_info); -void -dco_start_tun(struct tuntap *tt); +void dco_start_tun(struct tuntap *tt); -bool -dco_win_supports_multipeer(void); +bool dco_win_supports_multipeer(void); -void -dco_win_add_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned int ne= tbits, unsigned int peer_id); +void dco_win_add_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned i= nt netbits, + unsigned int peer_id); -void -dco_win_add_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsigned = int netbits, unsigned int peer_id); +void dco_win_add_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsi= gned int netbits, + unsigned int peer_id); -void -dco_win_del_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned int ne= tbits); +void dco_win_del_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned i= nt netbits); -void -dco_win_del_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsigned = int netbits); +void dco_win_del_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsi= gned int netbits); -#else /* if defined(ENABLE_DCO) && defined(_WIN32) */ +#else /* if defined(ENABLE_DCO) && defined(_WIN32) */ static inline void dco_start_tun(struct tuntap *tt) diff --git a/src/openvpn/dhcp.c b/src/openvpn/dhcp.c index da7a932..1d0b143 100644 --- a/src/openvpn/dhcp.c +++ b/src/openvpn/dhcp.c @@ -36,37 +36,37 @@ static int get_dhcp_message_type(const struct dhcp *dhcp, const int optlen) { - const uint8_t *p =3D (uint8_t *) (dhcp + 1); + const uint8_t *p =3D (uint8_t *)(dhcp + 1); int i; for (i =3D 0; i < optlen; ++i) { const uint8_t type =3D p[i]; const int room =3D optlen - i; - if (type =3D=3D DHCP_END) /* didn't find what we were look= ing for */ + if (type =3D=3D DHCP_END) /* didn't find what we were looking for = */ { return -1; } - else if (type =3D=3D DHCP_PAD) /* no-operation */ + else if (type =3D=3D DHCP_PAD) /* no-operation */ { } else if (type =3D=3D DHCP_MSG_TYPE) /* what we are looking for */ { if (room >=3D 3) { - if (p[i+1] =3D=3D 1) /* option length should be 1 */ + if (p[i + 1] =3D=3D 1) /* option length should be 1 */ { - return p[i+2]; /* return message type */ + return p[i + 2]; /* return message type */ } } return -1; } - else /* some other option */ + else /* some other option */ { if (room >=3D 2) { - const int len =3D p[i+1]; /* get option length */ - i +=3D (len + 1); /* advance to next option */ + const int len =3D p[i + 1]; /* get option length */ + i +=3D (len + 1); /* advance to next option */ } } } @@ -76,11 +76,11 @@ static in_addr_t do_extract(struct dhcp *dhcp, int optlen) { - uint8_t *p =3D (uint8_t *) (dhcp + 1); + uint8_t *p =3D (uint8_t *)(dhcp + 1); int i; in_addr_t ret =3D 0; - for (i =3D 0; i < optlen; ) + for (i =3D 0; i < optlen;) { const uint8_t type =3D p[i]; const int room =3D optlen - i; @@ -96,25 +96,25 @@ { if (room >=3D 2) { - const int len =3D p[i+1]; /* get option length */ - if (len <=3D (room-2)) + const int len =3D p[i + 1]; /* get option length */ + if (len <=3D (room - 2)) { /* get router IP address */ if (!ret && len >=3D 4 && (len & 3) =3D=3D 0) { - memcpy(&ret, p+i+2, 4); + memcpy(&ret, p + i + 2, 4); ret =3D ntohl(ret); } { /* delete the router option */ uint8_t *dest =3D p + i; - const int owlen =3D len + 2; /* len of data= to overwrite */ + const int owlen =3D len + 2; /* len of data to ove= rwrite */ uint8_t *src =3D dest + owlen; uint8_t *end =3D p + optlen; const int movlen =3D end - src; if (movlen > 0) { - memmove(dest, src, movlen); /* overwrite rou= ter option */ + memmove(dest, src, movlen); /* overwrite= router option */ } memset(end - owlen, DHCP_PAD, owlen); /* pad tail = */ } @@ -129,12 +129,12 @@ break; } } - else /* some other option */ + else /* some other option */ { if (room >=3D 2) { - const int len =3D p[i+1]; /* get option length */ - i +=3D (len + 2); /* advance to next option */ + const int len =3D p[i + 1]; /* get option length */ + i +=3D (len + 2); /* advance to next option */ } else { @@ -148,13 +148,13 @@ in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf) { - struct dhcp_full *df =3D (struct dhcp_full *) BPTR(ipbuf); - const int optlen =3D BLEN(ipbuf) - (sizeof(struct openvpn_iphdr) + siz= eof(struct openvpn_udphdr) + sizeof(struct dhcp)); + struct dhcp_full *df =3D (struct dhcp_full *)BPTR(ipbuf); + const int optlen =3D + BLEN(ipbuf) + - (sizeof(struct openvpn_iphdr) + sizeof(struct openvpn_udphdr) + = sizeof(struct dhcp)); - if (optlen >=3D 0 - && df->ip.protocol =3D=3D OPENVPN_IPPROTO_UDP - && df->udp.source =3D=3D htons(BOOTPS_PORT) - && df->udp.dest =3D=3D htons(BOOTPC_PORT) + if (optlen >=3D 0 && df->ip.protocol =3D=3D OPENVPN_IPPROTO_UDP + && df->udp.source =3D=3D htons(BOOTPS_PORT) && df->udp.dest =3D=3D= htons(BOOTPC_PORT) && df->dhcp.op =3D=3D BOOTREPLY) { const int message_type =3D get_dhcp_message_type(&df->dhcp, optlen= ); @@ -165,10 +165,10 @@ /* recompute the UDP checksum */ df->udp.check =3D 0; - df->udp.check =3D htons(ip_checksum(AF_INET, (uint8_t *)&df->u= dp, - sizeof(struct openvpn_udphdr= ) + sizeof(struct dhcp) + optlen, - (uint8_t *)&df->ip.saddr, (u= int8_t *)&df->ip.daddr, - OPENVPN_IPPROTO_UDP)); + df->udp.check =3D htons(ip_checksum( + AF_INET, (uint8_t *)&df->udp, + sizeof(struct openvpn_udphdr) + sizeof(struct dhcp) + optl= en, + (uint8_t *)&df->ip.saddr, (uint8_t *)&df->ip.daddr, OPENVP= N_IPPROTO_UDP)); /* only return the extracted Router address if DHCPACK */ if (message_type =3D=3D DHCPACK) diff --git a/src/openvpn/dhcp.h b/src/openvpn/dhcp.h index c578c6a..109d97c 100644 --- a/src/openvpn/dhcp.h +++ b/src/openvpn/dhcp.h @@ -31,10 +31,10 @@ #pragma pack(1) =20 /* DHCP Option types */ -#define DHCP_PAD 0 -#define DHCP_ROUTER 3 -#define DHCP_MSG_TYPE 53 /* message type (u8) */ -#define DHCP_END 255 +#define DHCP_PAD 0 +#define DHCP_ROUTER 3 +#define DHCP_MSG_TYPE 53 /* message type (u8) */ +#define DHCP_END 255 /* DHCP Messages types */ #define DHCPDISCOVER 1 @@ -50,28 +50,30 @@ #define BOOTPS_PORT 67 #define BOOTPC_PORT 68 -struct dhcp { +struct dhcp +{ #define BOOTREQUEST 1 #define BOOTREPLY 2 - uint8_t op; /* message op */ + uint8_t op; /* message op */ - uint8_t htype; /* hardware address type (e.g. '1' =3D 10Mb Etherne= t) */ - uint8_t hlen; /* hardware address length (e.g. '6' for 10Mb Ether= net) */ - uint8_t hops; /* client sets to 0, may be used by relay agents */ - uint32_t xid; /* transaction ID, chosen by client */ - uint16_t secs; /* seconds since request process began, set by clie= nt */ + uint8_t htype; /* hardware address type (e.g. '1' =3D 10Mb Ethern= et) */ + uint8_t hlen; /* hardware address length (e.g. '6' for 10Mb Ethe= rnet) */ + uint8_t hops; /* client sets to 0, may be used by relay agents */ + uint32_t xid; /* transaction ID, chosen by client */ + uint16_t secs; /* seconds since request process began, set by cli= ent */ uint16_t flags; - uint32_t ciaddr; /* client IP address, client sets if known */ - uint32_t yiaddr; /* 'your' IP address -- server's response to client= */ - uint32_t siaddr; /* server IP address */ - uint32_t giaddr; /* relay agent IP address */ + uint32_t ciaddr; /* client IP address, client sets if known */ + uint32_t yiaddr; /* 'your' IP address -- server's response to clien= t */ + uint32_t siaddr; /* server IP address */ + uint32_t giaddr; /* relay agent IP address */ uint8_t chaddr[16]; /* client hardware address */ - uint8_t sname[64]; /* optional server host name */ - uint8_t file[128]; /* boot file name */ - uint32_t magic; /* must be 0x63825363 (network order) */ + uint8_t sname[64]; /* optional server host name */ + uint8_t file[128]; /* boot file name */ + uint32_t magic; /* must be 0x63825363 (network order) */ }; -struct dhcp_full { +struct dhcp_full +{ struct openvpn_iphdr ip; struct openvpn_udphdr udp; struct dhcp dhcp; diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c index ea3d91b..00d6ecb 100644 --- a/src/openvpn/dns.c +++ b/src/openvpn/dns.c @@ -66,7 +66,7 @@ return false; } - char addrcopy[INET6_ADDRSTRLEN] =3D {0}; + char addrcopy[INET6_ADDRSTRLEN] =3D { 0 }; size_t copylen =3D 0; in_port_t port =3D 0; sa_family_t af; @@ -203,13 +203,13 @@ bool dns_options_verify(int msglevel, const struct dns_options *o) { - const struct dns_server *server =3D - o->servers ? o->servers : o->servers_prepull; + const struct dns_server *server =3D o->servers ? o->servers : o->serve= rs_prepull; while (server) { if (server->addr_count =3D=3D 0) { - msg(msglevel, "ERROR: dns server %ld does not have an address = assigned", server->priority); + msg(msglevel, "ERROR: dns server %ld does not have an address = assigned", + server->priority); return false; } server =3D server->next; @@ -353,8 +353,8 @@ #ifdef _WIN32 static void -make_domain_list(const char *what, const struct dns_domain *src, - bool nrpt_domains, char *dst, size_t dst_size) +make_domain_list(const char *what, const struct dns_domain *src, bool nrpt= _domains, char *dst, + size_t dst_size) { /* NRPT domains need two \0 at the end for REG_MULTI_SZ * and a leading '.' added in front of the domain name */ @@ -430,11 +430,8 @@ ack_message_t ack; nrpt_dns_cfg_message_t nrpt =3D { - .header =3D { - (add ? msg_add_nrpt_cfg : msg_del_nrpt_cfg), - sizeof(nrpt_dns_cfg_message_t), - 0 - }, + .header =3D { (add ? msg_add_nrpt_cfg : msg_del_nrpt_cfg), sizeof(= nrpt_dns_cfg_message_t), + 0 }, .iface =3D { .index =3D tt->adapter_index, .name =3D "" }, .flags =3D server->dnssec =3D=3D DNS_SECURITY_NO ? 0 : nrpt_dnssec, }; @@ -448,28 +445,27 @@ break; } - if (inet_ntop(server->addr[i].family, &server->addr[i].in, - nrpt.addresses[i], NRPT_ADDR_SIZE) =3D=3D NULL) + if (inet_ntop(server->addr[i].family, &server->addr[i].in, nrpt.ad= dresses[i], + NRPT_ADDR_SIZE) + =3D=3D NULL) { msg(M_WARN, "WARNING: could not convert dns server address"); } } - make_domain_list("dns server resolve domains", server->domains, true, - nrpt.resolve_domains, sizeof(nrpt.resolve_domains)); + make_domain_list("dns server resolve domains", server->domains, true, = nrpt.resolve_domains, + sizeof(nrpt.resolve_domains)); - make_domain_list("dns search domains", search_domains, false, - nrpt.search_domains, sizeof(nrpt.search_domains)); + make_domain_list("dns search domains", search_domains, false, nrpt.sea= rch_domains, + sizeof(nrpt.search_domains)); send_msg_iservice(o->msg_channel, &nrpt, sizeof(nrpt), &ack, "DNS"); } -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ static void -setenv_dns_option(struct env_set *es, - const char *format, int i, int j, - const char *value) +setenv_dns_option(struct env_set *es, const char *format, int i, int j, co= nst char *value) { char name[64]; bool name_ok =3D false; @@ -535,14 +531,12 @@ if (s->dnssec) { - setenv_dns_option(es, "dns_server_%d_dnssec", i, -1, - dnssec_value(s->dnssec)); + setenv_dns_option(es, "dns_server_%d_dnssec", i, -1, dnssec_va= lue(s->dnssec)); } if (s->transport) { - setenv_dns_option(es, "dns_server_%d_transport", i, -1, - transport_value(s->transport)); + setenv_dns_option(es, "dns_server_%d_transport", i, -1, transp= ort_value(s->transport)); } if (s->sni) { @@ -562,7 +556,8 @@ } static int -do_run_up_down_command(bool up, const char *vars_file, const struct dns_op= tions *o, const struct tuntap *tt) +do_run_up_down_command(bool up, const char *vars_file, const struct dns_op= tions *o, + const struct tuntap *tt) { struct gc_arena gc =3D gc_new(); struct argv argv =3D argv_new(); @@ -594,12 +589,12 @@ } static bool -run_updown_runner(bool up, struct options *o, const struct tuntap *tt, str= uct dns_updown_runner_info *updown_runner) +run_updown_runner(bool up, struct options *o, const struct tuntap *tt, + struct dns_updown_runner_info *updown_runner) { int dns_pipe_fd[2]; int ack_pipe_fd[2]; - if (pipe(dns_pipe_fd) !=3D 0 - || pipe(ack_pipe_fd) !=3D 0) + if (pipe(dns_pipe_fd) !=3D 0 || pipe(ack_pipe_fd) !=3D 0) { msg(M_ERR | M_ERRNO, "run_dns_up_down: unable to create pipes"); return false; @@ -627,8 +622,7 @@ /* Script runner process, close unused FDs */ for (int fd =3D 3; fd < 100; ++fd) { - if (fd !=3D dns_pipe_fd[0] - && fd !=3D ack_pipe_fd[1]) + if (fd !=3D dns_pipe_fd[0] && fd !=3D ack_pipe_fd[1]) { close(fd); } @@ -689,7 +683,8 @@ } static void -run_up_down_command(bool up, struct options *o, const struct tuntap *tt, s= truct dns_updown_runner_info *updown_runner) +run_up_down_command(bool up, struct options *o, const struct tuntap *tt, + struct dns_updown_runner_info *updown_runner) { struct dns_options *dns =3D &o->dns_options; if (!dns->updown || (o->up_script && !dns_updown_user_set(dns) && !dns= _updown_forced(dns))) @@ -847,7 +842,8 @@ } void -run_dns_up_down(bool up, struct options *o, const struct tuntap *tt, struc= t dns_updown_runner_info *duri) +run_dns_up_down(bool up, struct options *o, const struct tuntap *tt, + struct dns_updown_runner_info *duri) { if (!o->dns_options.servers) { @@ -877,14 +873,17 @@ } if (bad_count =3D=3D s->addr_count) { - msg(M_WARN, "DNS server %ld only has address(es) from a family= " + msg(M_WARN, + "DNS server %ld only has address(es) from a family " "the tunnel is not configured for - it will not be reachab= le", s->priority); } else if (bad_count) { - msg(M_WARN, "DNS server %ld has address(es) from a family " - "the tunnel is not configured for", s->priority); + msg(M_WARN, + "DNS server %ld has address(es) from a family " + "the tunnel is not configured for", + s->priority); } s =3D s->next; } diff --git a/src/openvpn/dns.h b/src/openvpn/dns.h index d33f64e..9610358 100644 --- a/src/openvpn/dns.h +++ b/src/openvpn/dns.h @@ -28,33 +28,39 @@ #include "env_set.h" #include "tun.h" -enum dns_security { +enum dns_security +{ DNS_SECURITY_UNSET, DNS_SECURITY_NO, DNS_SECURITY_YES, DNS_SECURITY_OPTIONAL }; -enum dns_server_transport { +enum dns_server_transport +{ DNS_TRANSPORT_UNSET, DNS_TRANSPORT_PLAIN, DNS_TRANSPORT_HTTPS, DNS_TRANSPORT_TLS }; -enum dns_updown_flags { +enum dns_updown_flags +{ DNS_UPDOWN_NO_FLAGS, DNS_UPDOWN_USER_SET, DNS_UPDOWN_FORCED }; -struct dns_domain { +struct dns_domain +{ struct dns_domain *next; const char *name; }; -struct dns_server_addr { - union { +struct dns_server_addr +{ + union + { struct in_addr a4; struct in6_addr a6; } in; @@ -62,7 +68,8 @@ in_port_t port; }; -struct dns_server { +struct dns_server +{ struct dns_server *next; long priority; size_t addr_count; @@ -73,7 +80,8 @@ const char *sni; }; -struct dns_updown_runner_info { +struct dns_updown_runner_info +{ bool required; int fds[2]; #if !defined(_WIN32) @@ -89,7 +97,8 @@ #define N_SEARCH_LIST_LEN 10 #endif -struct dhcp_options { +struct dhcp_options +{ in_addr_t dns[N_DHCP_ADDR]; int dns_len; @@ -101,7 +110,8 @@ int domain_search_list_len; }; -struct dns_options { +struct dns_options +{ struct dhcp_options from_dhcp; struct dns_domain *search_domains; struct dns_server *servers_prepull; @@ -166,8 +176,7 @@ * @param gc Pointer to the gc_arena to use for the clone * @return The dns_options clone */ -struct dns_options clone_dns_options(const struct dns_options *o, - struct gc_arena *gc); +struct dns_options clone_dns_options(const struct dns_options *o, struct g= c_arena *gc); /** * Saves and resets the server options, so that pulled ones don't mix in. diff --git a/src/openvpn/env_set.c b/src/openvpn/env_set.c index f20ee8a..9a5681d 100644 --- a/src/openvpn/env_set.c +++ b/src/openvpn/env_set.c @@ -247,7 +247,7 @@ if (es) { - const struct env_item *item =3D es->list; + const struct env_item *item =3D es->list; while (item) { fputs(item->string, fp); @@ -357,15 +357,10 @@ } void -setenv_str_ex(struct env_set *es, - const char *name, - const char *value, - const unsigned int name_include, - const unsigned int name_exclude, - const char name_replace, - const unsigned int value_include, - const unsigned int value_exclude, - const char value_replace) +setenv_str_ex(struct env_set *es, const char *name, const char *value, + const unsigned int name_include, const unsigned int name_exc= lude, + const char name_replace, const unsigned int value_include, + const unsigned int value_exclude, const char value_replace) { struct gc_arena gc =3D gc_new(); const char *name_tmp; @@ -443,9 +438,7 @@ /* Make arrays of strings */ const char ** -make_env_array(const struct env_set *es, - const bool check_allowed, - struct gc_arena *gc) +make_env_array(const struct env_set *es, const bool check_allowed, struct = gc_arena *gc) { char **ret =3D NULL; struct env_item *e =3D NULL; @@ -461,7 +454,7 @@ } /* alloc return array */ - ALLOC_ARRAY_CLEAR_GC(ret, char *, n+1, gc); + ALLOC_ARRAY_CLEAR_GC(ret, char *, n + 1, gc); /* fill return array */ if (es) diff --git a/src/openvpn/env_set.h b/src/openvpn/env_set.h index 52c5312..5bbccbd 100644 --- a/src/openvpn/env_set.h +++ b/src/openvpn/env_set.h @@ -34,26 +34,23 @@ * Handle environmental variable lists */ -struct env_item { +struct env_item +{ char *string; struct env_item *next; }; -struct env_set { +struct env_set +{ struct gc_arena *gc; struct env_item *list; }; /* set/delete environmental variable */ -void setenv_str_ex(struct env_set *es, - const char *name, - const char *value, - const unsigned int name_include, - const unsigned int name_exclude, - const char name_replace, - const unsigned int value_include, - const unsigned int value_exclude, - const char value_replace); +void setenv_str_ex(struct env_set *es, const char *name, const char *value, + const unsigned int name_include, const unsigned int nam= e_exclude, + const char name_replace, const unsigned int value_inclu= de, + const unsigned int value_exclude, const char value_repl= ace); void setenv_counter(struct env_set *es, const char *name, counter_type val= ue); @@ -124,8 +121,7 @@ /* returns true if environmental variable may be passed to an external pro= gram */ bool env_allowed(const char *str); -const char **make_env_array(const struct env_set *es, - const bool check_allowed, +const char **make_env_array(const struct env_set *es, const bool check_all= owed, struct gc_arena *gc); #endif /* ifndef ENV_SET_H */ diff --git a/src/openvpn/errlevel.h b/src/openvpn/errlevel.h index fc3e64a..dce09c2 100644 --- a/src/openvpn/errlevel.h +++ b/src/openvpn/errlevel.h @@ -50,134 +50,134 @@ * of output. */ -#define M_VERB0 LOGLEV(0, 0, 0) /* Messages displayed= even at --verb 0 (fatal errors only) */ +#define M_VERB0 LOGLEV(0, 0, 0) /* Messages displayed even at --verb 0 (fa= tal errors only) */ -#define M_INFO LOGLEV(1, 0, 0) /* default informatio= nal messages */ +#define M_INFO LOGLEV(1, 0, 0) /* default informational messages */ -#define D_LINK_ERRORS LOGLEV(1, 1, M_NONFATAL) /* show link error= s from main event loop */ -#define D_CRYPT_ERRORS LOGLEV(1, 2, M_NONFATAL) /* show errors fro= m encrypt/decrypt */ -#define D_TLS_ERRORS LOGLEV(1, 3, M_NONFATAL) /* show TLS contro= l channel errors */ -#define D_RESOLVE_ERRORS LOGLEV(1, 4, M_NONFATAL) /* show hostname r= esolve errors */ -#define D_COMP_ERRORS LOGLEV(1, 5, M_NONFATAL) /* show compressio= n errors */ -#define D_REPLAY_ERRORS LOGLEV(1, 6, M_NONFATAL) /* show packet rep= lay errors */ -#define D_STREAM_ERRORS LOGLEV(1, 7, M_NONFATAL) /* TCP stream err= or requiring restart */ -#define D_IMPORT_ERRORS LOGLEV(1, 8, M_NONFATAL) /* show server im= port option errors */ -#define D_MULTI_ERRORS LOGLEV(1, 9, M_NONFATAL) /* show multi-cli= ent server errors */ -#define D_EVENT_ERRORS LOGLEV(1, 10, M_NONFATAL) /* show event.[ch= ] errors */ -#define D_PUSH_ERRORS LOGLEV(1, 11, M_NONFATAL) /* show push/pull= errors */ -#define D_PID_PERSIST LOGLEV(1, 12, M_NONFATAL) /* show packet_id= persist errors */ -#define D_FRAG_ERRORS LOGLEV(1, 13, M_NONFATAL) /* show fragmenta= tion errors */ -#define D_ALIGN_ERRORS LOGLEV(1, 14, M_NONFATAL) /* show bad struc= t alignments */ +#define D_LINK_ERRORS LOGLEV(1, 1, M_NONFATAL) /* show link errors fro= m main event loop */ +#define D_CRYPT_ERRORS LOGLEV(1, 2, M_NONFATAL) /* show errors from enc= rypt/decrypt */ +#define D_TLS_ERRORS LOGLEV(1, 3, M_NONFATAL) /* show TLS control cha= nnel errors */ +#define D_RESOLVE_ERRORS LOGLEV(1, 4, M_NONFATAL) /* show hostname resolv= e errors */ +#define D_COMP_ERRORS LOGLEV(1, 5, M_NONFATAL) /* show compression err= ors */ +#define D_REPLAY_ERRORS LOGLEV(1, 6, M_NONFATAL) /* show packet replay e= rrors */ +#define D_STREAM_ERRORS LOGLEV(1, 7, M_NONFATAL) /* TCP stream error req= uiring restart */ +#define D_IMPORT_ERRORS LOGLEV(1, 8, M_NONFATAL) /* show server import o= ption errors */ +#define D_MULTI_ERRORS LOGLEV(1, 9, M_NONFATAL) /* show multi-client se= rver errors */ +#define D_EVENT_ERRORS LOGLEV(1, 10, M_NONFATAL) /* show event.[ch] erro= rs */ +#define D_PUSH_ERRORS LOGLEV(1, 11, M_NONFATAL) /* show push/pull error= s */ +#define D_PID_PERSIST LOGLEV(1, 12, M_NONFATAL) /* show packet_id persi= st errors */ +#define D_FRAG_ERRORS LOGLEV(1, 13, M_NONFATAL) /* show fragmentation e= rrors */ +#define D_ALIGN_ERRORS LOGLEV(1, 14, M_NONFATAL) /* show bad struct alig= nments */ -#define D_HANDSHAKE LOGLEV(2, 20, 0) /* show data & contro= l channel handshakes */ -#define D_CLOSE LOGLEV(2, 22, 0) /* show socket and TU= N/TAP close */ -#define D_PROXY LOGLEV(2, 24, 0) /* show http proxy co= ntrol packets */ -#define D_ARGV LOGLEV(2, 25, 0) /* show struct argv e= rrors */ +#define D_HANDSHAKE LOGLEV(2, 20, 0) /* show data & control = channel handshakes */ +#define D_CLOSE LOGLEV(2, 22, 0) /* show socket and TUN/= TAP close */ +#define D_PROXY LOGLEV(2, 24, 0) /* show http proxy cont= rol packets */ +#define D_ARGV LOGLEV(2, 25, 0) /* show struct argv err= ors */ -#define D_TLS_DEBUG_LOW LOGLEV(3, 20, 0) /* low frequency info= from tls_session routines */ -#define D_GREMLIN LOGLEV(3, 30, 0) /* show simulated out= age info from gremlin module */ -#define D_GENKEY LOGLEV(3, 31, 0) /* print message afte= r key generation */ -#define D_ROUTE LOGLEV(3, 0, 0) /* show routes added = and deleted (don't mute) */ -#define D_TUNTAP_INFO LOGLEV(3, 32, 0) /* show debugging inf= o from TUN/TAP driver */ -#define D_RESTART LOGLEV(3, 33, 0) /* show certain resta= rt messages */ -#define D_PUSH LOGLEV(3, 34, 0) /* show push/pull inf= o */ -#define D_IFCONFIG_POOL LOGLEV(3, 35, 0) /* show ifconfig pool= info */ -#define D_AUTH LOGLEV(3, 37, 0) /* show user/pass aut= h info */ -#define D_MULTI_LOW LOGLEV(3, 38, 0) /* show point-to-mult= ipoint low-freq debug info */ -#define D_PLUGIN LOGLEV(3, 39, 0) /* show plugin calls = */ -#define D_MANAGEMENT LOGLEV(3, 40, 0) /* show --management = info */ -#define D_SCHED_EXIT LOGLEV(3, 41, 0) /* show arming of sch= eduled exit */ -#define D_ROUTE_QUOTA LOGLEV(3, 42, 0) /* show route quota e= xceeded messages */ -#define D_OSBUF LOGLEV(3, 43, 0) /* show socket/tun/ta= p buffer sizes */ -#define D_PS_PROXY LOGLEV(3, 44, 0) /* messages related t= o --port-share option */ -#define D_IFCONFIG LOGLEV(3, 0, 0) /* show ifconfig info= (don't mute) */ -#define D_DCO LOGLEV(3, 0, 0) /* show DCO related m= essages */ +#define D_TLS_DEBUG_LOW LOGLEV(3, 20, 0) /* low frequency info from = tls_session routines */ +#define D_GREMLIN LOGLEV(3, 30, 0) /* show simulated outage in= fo from gremlin module */ +#define D_GENKEY LOGLEV(3, 31, 0) /* print message after key = generation */ +#define D_ROUTE LOGLEV(3, 0, 0) /* show routes added and de= leted (don't mute) */ +#define D_TUNTAP_INFO LOGLEV(3, 32, 0) /* show debugging info from= TUN/TAP driver */ +#define D_RESTART LOGLEV(3, 33, 0) /* show certain restart mes= sages */ +#define D_PUSH LOGLEV(3, 34, 0) /* show push/pull info */ +#define D_IFCONFIG_POOL LOGLEV(3, 35, 0) /* show ifconfig pool info = */ +#define D_AUTH LOGLEV(3, 37, 0) /* show user/pass auth info= */ +#define D_MULTI_LOW LOGLEV(3, 38, 0) /* show point-to-multipoint= low-freq debug info */ +#define D_PLUGIN LOGLEV(3, 39, 0) /* show plugin calls */ +#define D_MANAGEMENT LOGLEV(3, 40, 0) /* show --management info */ +#define D_SCHED_EXIT LOGLEV(3, 41, 0) /* show arming of scheduled= exit */ +#define D_ROUTE_QUOTA LOGLEV(3, 42, 0) /* show route quota exceede= d messages */ +#define D_OSBUF LOGLEV(3, 43, 0) /* show socket/tun/tap buff= er sizes */ +#define D_PS_PROXY LOGLEV(3, 44, 0) /* messages related to --po= rt-share option */ +#define D_IFCONFIG LOGLEV(3, 0, 0) /* show ifconfig info (don'= t mute) */ +#define D_DCO LOGLEV(3, 0, 0) /* show DCO related message= s */ -#define D_SHOW_PARMS LOGLEV(4, 50, 0) /* show all parameter= s on program initiation */ -#define D_LOW LOGLEV(4, 52, 0) /* miscellaneous low-= frequency debug info */ -#define D_DHCP_OPT LOGLEV(4, 53, 0) /* show DHCP options = binary string */ -#define D_MBUF LOGLEV(4, 54, 0) /* mbuf.[ch] routines= */ -#define D_PACKET_TRUNC_ERR LOGLEV(4, 55, 0) /* PACKET_TRUNCATION_= CHECK */ -#define D_MULTI_DROPPED LOGLEV(4, 57, 0) /* show point-to-mult= ipoint packet drops */ -#define D_MULTI_MEDIUM LOGLEV(4, 58, 0) /* show medium freque= ncy multi messages */ -#define D_X509_ATTR LOGLEV(4, 59, 0) /* show x509-track at= tributes on connection */ -#define D_INIT_MEDIUM LOGLEV(4, 60, 0) /* show medium freque= ncy init messages */ -#define D_MTU_INFO LOGLEV(4, 61, 0) /* show terse MTU inf= o */ -#define D_PID_DEBUG_LOW LOGLEV(4, 63, 0) /* show low-freq pack= et-id debugging info */ -#define D_PID_DEBUG_MEDIUM LOGLEV(4, 64, 0) /* show medium-freq p= acket-id debugging info */ -#define D_CIPHER_INIT LOGLEV(4, 65, 0) /* show messages abou= t cipher init */ +#define D_SHOW_PARMS LOGLEV(4, 50, 0) /* show all parameters on p= rogram initiation */ +#define D_LOW LOGLEV(4, 52, 0) /* miscellaneous low-freque= ncy debug info */ +#define D_DHCP_OPT LOGLEV(4, 53, 0) /* show DHCP options binary= string */ +#define D_MBUF LOGLEV(4, 54, 0) /* mbuf.[ch] routines */ +#define D_PACKET_TRUNC_ERR LOGLEV(4, 55, 0) /* PACKET_TRUNCATION_CHECK = */ +#define D_MULTI_DROPPED LOGLEV(4, 57, 0) /* show point-to-multipoint= packet drops */ +#define D_MULTI_MEDIUM LOGLEV(4, 58, 0) /* show medium frequency mu= lti messages */ +#define D_X509_ATTR LOGLEV(4, 59, 0) /* show x509-track attribut= es on connection */ +#define D_INIT_MEDIUM LOGLEV(4, 60, 0) /* show medium frequency in= it messages */ +#define D_MTU_INFO LOGLEV(4, 61, 0) /* show terse MTU info */ +#define D_PID_DEBUG_LOW LOGLEV(4, 63, 0) /* show low-freq packet-id = debugging info */ +#define D_PID_DEBUG_MEDIUM LOGLEV(4, 64, 0) /* show medium-freq packet-= id debugging info */ +#define D_CIPHER_INIT LOGLEV(4, 65, 0) /* show messages about ciph= er init */ -#define D_LOG_RW LOGLEV(5, 0, 0) /* Print 'R' or 'W' t= o stdout for read/write */ +#define D_LOG_RW LOGLEV(5, 0, 0) /* Print 'R' or 'W' to stdo= ut for read/write */ -#define D_RTNL LOGLEV(6, 68, M_DEBUG) /* show RTNL low leve= l operations */ -#define D_LINK_RW LOGLEV(6, 69, M_DEBUG) /* show TCP/UDP reads= /writes (terse) */ -#define D_TUN_RW LOGLEV(6, 69, M_DEBUG) /* show TUN/TAP reads= /writes */ -#define D_TAP_WIN_DEBUG LOGLEV(6, 69, M_DEBUG) /* show TAP-Windows d= river debug info */ -#define D_CLIENT_NAT LOGLEV(6, 69, M_DEBUG) /* show client NAT de= bug info */ -#define D_XKEY LOGLEV(6, 69, M_DEBUG) /* show xkey-provider= debug info */ -#define D_DCO_DEBUG LOGLEV(6, 69, M_DEBUG) /* show DCO related l= owlevel debug messages */ -#define D_SIGNAL_DEBUG LOGLEV(6, 69, M_DEBUG) /* show signal relate= d debug messages */ +#define D_RTNL LOGLEV(6, 68, M_DEBUG) /* show RTNL low level oper= ations */ +#define D_LINK_RW LOGLEV(6, 69, M_DEBUG) /* show TCP/UDP reads/write= s (terse) */ +#define D_TUN_RW LOGLEV(6, 69, M_DEBUG) /* show TUN/TAP reads/write= s */ +#define D_TAP_WIN_DEBUG LOGLEV(6, 69, M_DEBUG) /* show TAP-Windows driver = debug info */ +#define D_CLIENT_NAT LOGLEV(6, 69, M_DEBUG) /* show client NAT debug in= fo */ +#define D_XKEY LOGLEV(6, 69, M_DEBUG) /* show xkey-provider debug= info */ +#define D_DCO_DEBUG LOGLEV(6, 69, M_DEBUG) /* show DCO related lowleve= l debug messages */ +#define D_SIGNAL_DEBUG LOGLEV(6, 69, M_DEBUG) /* show signal related debu= g messages */ -#define D_SHOW_KEYS LOGLEV(7, 70, M_DEBUG) /* show data channel = encryption keys */ -#define D_SHOW_KEY_SOURCE LOGLEV(7, 70, M_DEBUG) /* show data channel = key source entropy */ -#define D_REL_LOW LOGLEV(7, 70, M_DEBUG) /* show low frequency= info from reliable layer */ -#define D_FRAG_DEBUG LOGLEV(7, 70, M_DEBUG) /* show fragment debu= gging info */ -#define D_WIN32_IO_LOW LOGLEV(7, 70, M_DEBUG) /* low freq win32 I/O= debugging info */ -#define D_MTU_DEBUG LOGLEV(7, 70, M_DEBUG) /* show MTU debugging= info */ -#define D_MULTI_DEBUG LOGLEV(7, 70, M_DEBUG) /* show medium-freq m= ulti debugging info */ -#define D_MSS LOGLEV(7, 70, M_DEBUG) /* show MSS adjustmen= ts */ -#define D_COMP_LOW LOGLEV(7, 70, M_DEBUG) /* show adaptive comp= ression state changes */ -#define D_CONNECTION_LIST LOGLEV(7, 70, M_DEBUG) /* show = list info */ -#define D_SCRIPT LOGLEV(7, 70, M_DEBUG) /* show parms & env v= ars passed to scripts */ -#define D_SHOW_NET LOGLEV(7, 70, M_DEBUG) /* show routing table= and adapter list */ -#define D_ROUTE_DEBUG LOGLEV(7, 70, M_DEBUG) /* show verbose route= .[ch] output */ -#define D_TLS_STATE_ERRORS LOGLEV(7, 70, M_DEBUG) /* no TLS state for c= lient */ -#define D_SEMAPHORE_LOW LOGLEV(7, 70, M_DEBUG) /* show Win32 semapho= re waits (low freq) */ -#define D_SEMAPHORE LOGLEV(7, 70, M_DEBUG) /* show Win32 semapho= re waits */ -#define D_TEST_FILE LOGLEV(7, 70, M_DEBUG) /* show test_file() c= alls */ -#define D_MANAGEMENT_DEBUG LOGLEV(3, 70, M_DEBUG) /* show --management = debug info */ -#define D_PLUGIN_DEBUG LOGLEV(7, 70, M_DEBUG) /* show verbose plugi= n calls */ -#define D_SOCKET_DEBUG LOGLEV(7, 70, M_DEBUG) /* show socket.[ch] d= ebugging info */ -#define D_SHOW_PKCS11 LOGLEV(7, 70, M_DEBUG) /* show PKCS#11 actio= ns */ -#define D_ALIGN_DEBUG LOGLEV(7, 70, M_DEBUG) /* show verbose struc= t alignment info */ -#define D_PACKET_TRUNC_DEBUG LOGLEV(7, 70, M_DEBUG) /* PACKET_TRUNCATION_= CHECK verbose */ -#define D_PING LOGLEV(7, 70, M_DEBUG) /* PING send/receive = messages */ -#define D_PS_PROXY_DEBUG LOGLEV(7, 70, M_DEBUG) /* port share proxy d= ebug */ -#define D_TLS_KEYSELECT LOGLEV(7, 70, M_DEBUG) /* show key selection= for data channel */ -#define D_ARGV_PARSE_CMD LOGLEV(7, 70, M_DEBUG) /* show parse_line() = errors in argv_parse_cmd */ -#define D_CRYPTO_DEBUG LOGLEV(7, 70, M_DEBUG) /* show detailed info= from crypto.c routines */ -#define D_PID_DEBUG LOGLEV(7, 70, M_DEBUG) /* show packet-id deb= ugging info */ -#define D_PUSH_DEBUG LOGLEV(7, 73, M_DEBUG) /* show push/pull deb= ugging info */ -#define D_SHOW_OCC LOGLEV(7, 74, M_DEBUG) /* show options compa= tibility string */ +#define D_SHOW_KEYS LOGLEV(7, 70, M_DEBUG) /* show data channel e= ncryption keys */ +#define D_SHOW_KEY_SOURCE LOGLEV(7, 70, M_DEBUG) /* show data channel k= ey source entropy */ +#define D_REL_LOW LOGLEV(7, 70, M_DEBUG) /* show low frequency = info from reliable layer */ +#define D_FRAG_DEBUG LOGLEV(7, 70, M_DEBUG) /* show fragment debug= ging info */ +#define D_WIN32_IO_LOW LOGLEV(7, 70, M_DEBUG) /* low freq win32 I/O = debugging info */ +#define D_MTU_DEBUG LOGLEV(7, 70, M_DEBUG) /* show MTU debugging = info */ +#define D_MULTI_DEBUG LOGLEV(7, 70, M_DEBUG) /* show medium-freq mu= lti debugging info */ +#define D_MSS LOGLEV(7, 70, M_DEBUG) /* show MSS adjustment= s */ +#define D_COMP_LOW LOGLEV(7, 70, M_DEBUG) /* show adaptive compr= ession state changes */ +#define D_CONNECTION_LIST LOGLEV(7, 70, M_DEBUG) /* show l= ist info */ +#define D_SCRIPT LOGLEV(7, 70, M_DEBUG) /* show parms & env va= rs passed to scripts */ +#define D_SHOW_NET LOGLEV(7, 70, M_DEBUG) /* show routing table = and adapter list */ +#define D_ROUTE_DEBUG LOGLEV(7, 70, M_DEBUG) /* show verbose route.= [ch] output */ +#define D_TLS_STATE_ERRORS LOGLEV(7, 70, M_DEBUG) /* no TLS state for cl= ient */ +#define D_SEMAPHORE_LOW LOGLEV(7, 70, M_DEBUG) /* show Win32 semaphor= e waits (low freq) */ +#define D_SEMAPHORE LOGLEV(7, 70, M_DEBUG) /* show Win32 semaphor= e waits */ +#define D_TEST_FILE LOGLEV(7, 70, M_DEBUG) /* show test_file() ca= lls */ +#define D_MANAGEMENT_DEBUG LOGLEV(3, 70, M_DEBUG) /* show --management d= ebug info */ +#define D_PLUGIN_DEBUG LOGLEV(7, 70, M_DEBUG) /* show verbose plugin= calls */ +#define D_SOCKET_DEBUG LOGLEV(7, 70, M_DEBUG) /* show socket.[ch] de= bugging info */ +#define D_SHOW_PKCS11 LOGLEV(7, 70, M_DEBUG) /* show PKCS#11 action= s */ +#define D_ALIGN_DEBUG LOGLEV(7, 70, M_DEBUG) /* show verbose struct= alignment info */ +#define D_PACKET_TRUNC_DEBUG LOGLEV(7, 70, M_DEBUG) /* PACKET_TRUNCATION_C= HECK verbose */ +#define D_PING LOGLEV(7, 70, M_DEBUG) /* PING send/receive m= essages */ +#define D_PS_PROXY_DEBUG LOGLEV(7, 70, M_DEBUG) /* port share proxy de= bug */ +#define D_TLS_KEYSELECT LOGLEV(7, 70, M_DEBUG) /* show key selection = for data channel */ +#define D_ARGV_PARSE_CMD LOGLEV(7, 70, M_DEBUG) /* show parse_line() e= rrors in argv_parse_cmd */ +#define D_CRYPTO_DEBUG LOGLEV(7, 70, M_DEBUG) /* show detailed info = from crypto.c routines */ +#define D_PID_DEBUG LOGLEV(7, 70, M_DEBUG) /* show packet-id debu= gging info */ +#define D_PUSH_DEBUG LOGLEV(7, 73, M_DEBUG) /* show push/pull debu= gging info */ +#define D_SHOW_OCC LOGLEV(7, 74, M_DEBUG) /* show options compat= ibility string */ -#define D_VLAN_DEBUG LOGLEV(7, 74, M_DEBUG) /* show VLAN tagging/= untagging debug info */ +#define D_VLAN_DEBUG LOGLEV(7, 74, M_DEBUG) /* show VLAN tagging/un= tagging debug info */ -#define D_HANDSHAKE_VERBOSE LOGLEV(8, 70, M_DEBUG) /* show detailed desc= ription of handshake */ -#define D_TLS_DEBUG_MED LOGLEV(8, 70, M_DEBUG) /* limited info from = tls_session routines */ -#define D_INTERVAL LOGLEV(8, 70, M_DEBUG) /* show interval.h de= bugging info */ -#define D_SCHEDULER LOGLEV(8, 70, M_DEBUG) /* show scheduler deb= ugging info */ -#define D_GREMLIN_VERBOSE LOGLEV(8, 70, M_DEBUG) /* show verbose info = from gremlin module */ -#define D_REL_DEBUG LOGLEV(8, 70, M_DEBUG) /* show detailed info= from reliable routines */ -#define D_EVENT_WAIT LOGLEV(8, 70, M_DEBUG) /* show detailed info= from event waits */ -#define D_MULTI_TCP LOGLEV(8, 70, M_DEBUG) /* show debug info fr= om mtcp.c */ +#define D_HANDSHAKE_VERBOSE LOGLEV(8, 70, M_DEBUG) /* show detailed descri= ption of handshake */ +#define D_TLS_DEBUG_MED LOGLEV(8, 70, M_DEBUG) /* limited info from tl= s_session routines */ +#define D_INTERVAL LOGLEV(8, 70, M_DEBUG) /* show interval.h debu= gging info */ +#define D_SCHEDULER LOGLEV(8, 70, M_DEBUG) /* show scheduler debug= ging info */ +#define D_GREMLIN_VERBOSE LOGLEV(8, 70, M_DEBUG) /* show verbose info fr= om gremlin module */ +#define D_REL_DEBUG LOGLEV(8, 70, M_DEBUG) /* show detailed info f= rom reliable routines */ +#define D_EVENT_WAIT LOGLEV(8, 70, M_DEBUG) /* show detailed info f= rom event waits */ +#define D_MULTI_TCP LOGLEV(8, 70, M_DEBUG) /* show debug info from= mtcp.c */ -#define D_TLS_DEBUG LOGLEV(9, 70, M_DEBUG) /* show detailed info= from TLS routines */ -#define D_COMP LOGLEV(9, 70, M_DEBUG) /* show compression i= nfo */ -#define D_READ_WRITE LOGLEV(9, 70, M_DEBUG) /* show all tun/tcp/u= dp reads/writes/opens */ -#define D_PACKET_CONTENT LOGLEV(9, 70, M_DEBUG) /* show before/after = encryption packet content */ -#define D_TLS_NO_SEND_KEY LOGLEV(9, 70, M_DEBUG) /* show when no data = channel send-key exists */ -#define D_PID_PERSIST_DEBUG LOGLEV(9, 70, M_DEBUG) /* show packet-id per= sist debugging info */ -#define D_LINK_RW_VERBOSE LOGLEV(9, 70, M_DEBUG) /* increase link read= s/writes verbosity */ -#define D_STREAM_DEBUG LOGLEV(9, 70, M_DEBUG) /* show TCP stream de= bug info */ -#define D_WIN32_IO LOGLEV(9, 70, M_DEBUG) /* win32 I/O debuggin= g info */ -#define D_PKCS11_DEBUG LOGLEV(9, 70, M_DEBUG) /* show PKCS#11 debug= ging */ +#define D_TLS_DEBUG LOGLEV(9, 70, M_DEBUG) /* show detailed info f= rom TLS routines */ +#define D_COMP LOGLEV(9, 70, M_DEBUG) /* show compression inf= o */ +#define D_READ_WRITE LOGLEV(9, 70, M_DEBUG) /* show all tun/tcp/udp= reads/writes/opens */ +#define D_PACKET_CONTENT LOGLEV(9, 70, M_DEBUG) /* show before/after en= cryption packet content */ +#define D_TLS_NO_SEND_KEY LOGLEV(9, 70, M_DEBUG) /* show when no data ch= annel send-key exists */ +#define D_PID_PERSIST_DEBUG LOGLEV(9, 70, M_DEBUG) /* show packet-id persi= st debugging info */ +#define D_LINK_RW_VERBOSE LOGLEV(9, 70, M_DEBUG) /* increase link reads/= writes verbosity */ +#define D_STREAM_DEBUG LOGLEV(9, 70, M_DEBUG) /* show TCP stream debu= g info */ +#define D_WIN32_IO LOGLEV(9, 70, M_DEBUG) /* win32 I/O debugging = info */ +#define D_PKCS11_DEBUG LOGLEV(9, 70, M_DEBUG) /* show PKCS#11 debuggi= ng */ -#define D_SHAPER_DEBUG LOGLEV(10, 70, M_DEBUG) /* show traffic shape= r info */ +#define D_SHAPER_DEBUG LOGLEV(10, 70, M_DEBUG) /* show traffic shaper = info */ -#define D_REGISTRY LOGLEV(11, 70, M_DEBUG) /* win32 registry deb= ugging info */ -#define D_OPENSSL_LOCK LOGLEV(11, 70, M_DEBUG) /* show OpenSSL locks= */ +#define D_REGISTRY LOGLEV(11, 70, M_DEBUG) /* win32 registry debug= ging info */ +#define D_OPENSSL_LOCK LOGLEV(11, 70, M_DEBUG) /* show OpenSSL locks */ -/*#define D_THREAD_DEBUG LOGLEV(4, 70, M_DEBUG)*/ /* show pthread d= ebug information */ +/*#define D_THREAD_DEBUG LOGLEV(4, 70, M_DEBUG)*/ /* show pthread de= bug information */ -#endif /* ifndef ERRLEVEL_H */ +#endif /* ifndef ERRLEVEL= _H */ diff --git a/src/openvpn/error.c b/src/openvpn/error.c index 049cd92..d79d76a 100644 --- a/src/openvpn/error.c +++ b/src/openvpn/error.c @@ -52,9 +52,9 @@ unsigned int x_debug_level; /* GLOBAL */ /* Mute state */ -static int mute_cutoff; /* GLOBAL */ -static int mute_count; /* GLOBAL */ -static int mute_category; /* GLOBAL */ +static int mute_cutoff; /* GLOBAL */ +static int mute_count; /* GLOBAL */ +static int mute_category; /* GLOBAL */ /* * Output mode priorities are as follows: @@ -68,28 +68,28 @@ /* If true, indicates that stdin/stdout/stderr * have been redirected due to --log */ -static bool std_redir; /* GLOBAL */ +static bool std_redir; /* GLOBAL */ /* Should messages be written to the syslog? */ -static bool use_syslog; /* GLOBAL */ +static bool use_syslog; /* GLOBAL */ /* Should stdout/stderr be be parsable and always be prefixed with time * and message flags */ -static bool machine_readable_output; /* GLOBAL */ +static bool machine_readable_output; /* GLOBAL */ /* Should timestamps be included on messages to stdout/stderr? */ static bool suppress_timestamps; /* GLOBAL */ /* The program name passed to syslog */ #if SYSLOG_CAPABILITY -static char *pgmname_syslog; /* GLOBAL */ +static char *pgmname_syslog; /* GLOBAL */ #endif /* If non-null, messages should be written here (used for debugging only) = */ -static FILE *msgfp; /* GLOBAL */ +static FILE *msgfp; /* GLOBAL */ /* If true, we forked from main OpenVPN process */ -static bool forked; /* GLOBAL */ +static bool forked; /* GLOBAL */ /* our default output targets */ static FILE *default_out; /* GLOBAL */ @@ -176,7 +176,7 @@ { openvpn_exit(OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE); /* exit = point */ } -#else /* ifdef OPENVPN_DEBUG_COMMAND_LINE */ +#else /* ifdef OPENVPN_DEBUG_COMMAND_LINE */ msgfp =3D NULL; #endif } @@ -196,7 +196,7 @@ FILE *fp =3D msgfp; if (!fp) { - fp =3D (flags & (M_FATAL|M_USAGE_SMALL)) ? default_err : default_o= ut; + fp =3D (flags & (M_FATAL | M_USAGE_SMALL)) ? default_err : default= _out; } if (!fp) { @@ -205,7 +205,12 @@ return fp; } -#define SWAP { tmp =3D m1; m1 =3D m2; m2 =3D tmp; } +#define SWAP \ + { \ + tmp =3D m1; \ + m1 =3D m2; \ + m2 =3D tmp; \ + } int x_msg_line_num; /* GLOBAL */ @@ -266,16 +271,15 @@ gc_init(&gc); - m1 =3D (char *) gc_malloc(ERR_BUF_SIZE, false, &gc); - m2 =3D (char *) gc_malloc(ERR_BUF_SIZE, false, &gc); + m1 =3D (char *)gc_malloc(ERR_BUF_SIZE, false, &gc); + m2 =3D (char *)gc_malloc(ERR_BUF_SIZE, false, &gc); vsnprintf(m1, ERR_BUF_SIZE, format, arglist); m1[ERR_BUF_SIZE - 1] =3D 0; /* windows vsnprintf needs this */ if ((flags & M_ERRNO) && e) { - snprintf(m2, ERR_BUF_SIZE, "%s: %s (errno=3D%d)", - m1, openvpn_strerror(e, crt_error, &gc), e); + snprintf(m2, ERR_BUF_SIZE, "%s: %s (errno=3D%d)", m1, openvpn_stre= rror(e, crt_error, &gc), e); SWAP; } @@ -286,7 +290,7 @@ } #if SYSLOG_CAPABILITY - if (flags & (M_FATAL|M_NONFATAL|M_USAGE_SMALL)) + if (flags & (M_FATAL | M_NONFATAL | M_USAGE_SMALL)) { level =3D LOG_ERR; } @@ -321,10 +325,7 @@ const struct virtual_output *vo =3D msg_get_virtual_output(); if (vo) { - snprintf(m2, ERR_BUF_SIZE, "%s%s%s", - prefix, - prefix_sep, - m1); + snprintf(m2, ERR_BUF_SIZE, "%s%s%s", prefix, prefix_sep, m1); virtual_output_print(vo, flags, m2); } } @@ -334,10 +335,7 @@ if (use_syslog && !std_redir && !forked) { #if SYSLOG_CAPABILITY - syslog(level, "%s%s%s", - prefix, - prefix_sep, - m1); + syslog(level, "%s%s%s", prefix, prefix_sep, m1); #endif } else @@ -350,32 +348,17 @@ struct timeval tv; gettimeofday(&tv, NULL); - fprintf(fp, "%" PRIi64 ".%06ld %x %s%s%s%s", - (int64_t)tv.tv_sec, - (long)tv.tv_usec, - flags, - prefix, - prefix_sep, - m1, - "\n"); - + fprintf(fp, "%" PRIi64 ".%06ld %x %s%s%s%s", (int64_t)tv.t= v_sec, (long)tv.tv_usec, + flags, prefix, prefix_sep, m1, "\n"); } else if ((flags & M_NOPREFIX) || suppress_timestamps) { - fprintf(fp, "%s%s%s%s", - prefix, - prefix_sep, - m1, - (flags&M_NOLF) ? "" : "\n"); + fprintf(fp, "%s%s%s%s", prefix, prefix_sep, m1, (flags & M= _NOLF) ? "" : "\n"); } else { - fprintf(fp, "%s %s%s%s%s", - time_string(0, 0, show_usec, &gc), - prefix, - prefix_sep, - m1, - (flags&M_NOLF) ? "" : "\n"); + fprintf(fp, "%s %s%s%s%s", time_string(0, 0, show_usec, &g= c), prefix, prefix_sep, + m1, (flags & M_NOLF) ? "" : "\n"); } fflush(fp); ++x_msg_line_num; @@ -390,7 +373,6 @@ if (flags & M_FATAL) { openvpn_exit(OPENVPN_EXIT_STATUS_ERROR); /* exit point */ - } if (flags & M_USAGE_SMALL) { @@ -427,8 +409,7 @@ if (suppressed > 0) { msg(M_INFO | M_NOMUTE, - "%d variation(s) on previous %d message(s) suppressed = by --mute", - suppressed, + "%d variation(s) on previous %d message(s) suppressed = by --mute", suppressed, mute_cutoff); } mute_count =3D 1; @@ -482,8 +463,9 @@ } } } -#else /* if SYSLOG_CAPABILITY */ - msg(M_WARN, "Warning on use of --daemon: this operating system lacks d= aemon logging features, therefore when I become a daemon, I won't be able t= o log status or error messages"); +#else /* if SYSLOG_CAPABILITY */ + msg(M_WARN, + "Warning on use of --daemon: this operating system lacks daemon lo= gging features, therefore when I become a daemon, I won't be able to log st= atus or error messages"); #endif } @@ -526,19 +508,14 @@ saAttr.bInheritHandle =3D TRUE; saAttr.lpSecurityDescriptor =3D NULL; - log_handle =3D CreateFileW(wide_string(file, &gc), - GENERIC_WRITE, - FILE_SHARE_READ, - &saAttr, - append ? OPEN_ALWAYS : CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - NULL); + log_handle =3D CreateFileW(wide_string(file, &gc), GENERIC_WRITE, = FILE_SHARE_READ, &saAttr, + append ? OPEN_ALWAYS : CREATE_ALWAYS, FIL= E_ATTRIBUTE_NORMAL, NULL); gc_free(&gc); if (log_handle =3D=3D INVALID_HANDLE_VALUE) { - msg(M_WARN|M_ERRNO, "Warning: cannot open --log file: %s", fil= e); + msg(M_WARN | M_ERRNO, "Warning: cannot open --log file: %s", f= ile); return; } @@ -555,7 +532,8 @@ orig_stderr =3D _dup(_fileno(stderr)); if (orig_stderr =3D=3D -1) { - msg(M_WARN | M_ERRNO, "Warning: cannot duplicate stderr, passw= ord prompts will appear in log file instead of console."); + msg(M_WARN | M_ERRNO, + "Warning: cannot duplicate stderr, password prompts will a= ppear in log file instead of console."); orig_stderr =3D _fileno(stderr); } @@ -585,13 +563,12 @@ #elif defined(HAVE_DUP2) if (!std_redir) { - int out =3D open(file, - O_CREAT | O_WRONLY | (append ? O_APPEND : O_TRUNC), - S_IRUSR | S_IWUSR); + int out =3D open(file, O_CREAT | O_WRONLY | (append ? O_APPEND : O= _TRUNC), S_IRUSR | S_IWUSR); if (out < 0) { - msg(M_WARN|M_ERRNO, "Warning: Error redirecting stdout/stderr = to --log file: %s", file); + msg(M_WARN | M_ERRNO, "Warning: Error redirecting stdout/stder= r to --log file: %s", + file); return; } @@ -613,7 +590,8 @@ } #else /* if defined(_WIN32) */ - msg(M_WARN, "WARNING: The --log option is not supported on this OS bec= ause it lacks the dup2 function"); + msg(M_WARN, + "WARNING: The --log option is not supported on this OS because it = lacks the dup2 function"); #endif /* if defined(_WIN32) */ } @@ -649,10 +627,7 @@ * from the OS. */ void -x_check_status(int status, - const char *description, - struct link_socket *sock, - struct tuntap *tt) +x_check_status(int status, const char *description, struct link_socket *so= ck, struct tuntap *tt) { const char *extended_msg =3D NULL; @@ -660,9 +635,7 @@ int my_errno =3D openvpn_errno_maybe_crt(&crt_error); msg(x_cs_verbose_level, "%s %s returned %d", - sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "", - description, - status); + sock ? proto2ascii(sock->info.proto, sock->info.af, true) : "", de= scription, status); if (status < 0) { @@ -694,16 +667,14 @@ if (extended_msg) { msg(x_cs_info_level, "%s %s [%s]: %s (fd=3D" SOCKET_PRINTF= ",code=3D%d)", description, - sock ? proto2ascii(sock->info.proto, sock->info.af, tr= ue) : "", - extended_msg, openvpn_strerror(my_errno, crt_error, &g= c), - sock ? sock->sd : -1, my_errno); + sock ? proto2ascii(sock->info.proto, sock->info.af, tr= ue) : "", extended_msg, + openvpn_strerror(my_errno, crt_error, &gc), sock ? soc= k->sd : -1, my_errno); } else { msg(x_cs_info_level, "%s %s: %s (fd=3D" SOCKET_PRINTF ",co= de=3D%d)", description, sock ? proto2ascii(sock->info.proto, sock->info.af, tr= ue) : "", - openvpn_strerror(my_errno, crt_error, &gc), - sock ? sock->sd : -1, my_errno); + openvpn_strerror(my_errno, crt_error, &gc), sock ? soc= k->sd : -1, my_errno); } if (x_cs_err_delay_ms) @@ -971,16 +942,10 @@ wchar_t wmessage[256]; char *message =3D NULL; struct buffer out =3D alloc_buf_gc(256, gc); - const DWORD status =3D FormatMessageW( - FORMAT_MESSAGE_IGNORE_INSERTS - | FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_ARGUMENT_ARRAY, - NULL, - errnum, - 0, - wmessage, - SIZE(wmessage), - NULL); + const DWORD status =3D + FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_= FROM_SYSTEM + | FORMAT_MESSAGE_ARGUMENT_ARRAY, + NULL, errnum, 0, wmessage, SIZE(wmessage), NULL= ); if (status) { message =3D utf16to8(wmessage, gc); diff --git a/src/openvpn/error.h b/src/openvpn/error.h index e0a2730..1625df1 100644 --- a/src/openvpn/error.h +++ b/src/openvpn/error.h @@ -50,10 +50,10 @@ * Exit status codes */ -#define OPENVPN_EXIT_STATUS_GOOD 0 -#define OPENVPN_EXIT_STATUS_ERROR 1 -#define OPENVPN_EXIT_STATUS_USAGE 1 -#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE 1 +#define OPENVPN_EXIT_STATUS_GOOD 0 +#define OPENVPN_EXIT_STATUS_ERROR 1 +#define OPENVPN_EXIT_STATUS_USAGE 1 +#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE 1 /* * Special command line debugging mode. @@ -84,27 +84,27 @@ /* msg() flags */ -#define M_DEBUG_LEVEL (0x0F) /* debug level mask */ +#define M_DEBUG_LEVEL (0x0F) /* debug level mask */ -#define M_FATAL (1<<4) /* exit program */ -#define M_NONFATAL (1<<5) /* non-fatal error */ -#define M_WARN (1<<6) /* call syslog with LOG_WARNING */ -#define M_DEBUG (1<<7) +#define M_FATAL (1 << 4) /* exit program */ +#define M_NONFATAL (1 << 5) /* non-fatal error */ +#define M_WARN (1 << 6) /* call syslog with LOG_WARNING */ +#define M_DEBUG (1 << 7) -#define M_ERRNO (1<<8) /* show errno description */ +#define M_ERRNO (1 << 8) /* show errno description */ -#define M_NOMUTE (1<<11) /* don't do mute processing */ -#define M_NOPREFIX (1<<12) /* don't show date/time prefix */ -#define M_USAGE_SMALL (1<<13) /* fatal options error, call usag= e_small */ -#define M_MSG_VIRT_OUT (1<<14) /* output message through msg_sta= tus_output callback */ -#define M_OPTERR (1<<15) /* print "Options error:" prefix = */ -#define M_NOLF (1<<16) /* don't print new line */ -#define M_NOIPREFIX (1<<17) /* don't print instance prefix */ +#define M_NOMUTE (1 << 11) /* don't do mute processing */ +#define M_NOPREFIX (1 << 12) /* don't show date/time prefix */ +#define M_USAGE_SMALL (1 << 13) /* fatal options error, call usage_small = */ +#define M_MSG_VIRT_OUT (1 << 14) /* output message through msg_status_outp= ut callback */ +#define M_OPTERR (1 << 15) /* print "Options error:" prefix */ +#define M_NOLF (1 << 16) /* don't print new line */ +#define M_NOIPREFIX (1 << 17) /* don't print instance prefix */ /* flag combinations which are frequently used */ -#define M_ERR (M_FATAL | M_ERRNO) -#define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR) -#define M_CLIENT (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX) +#define M_ERR (M_FATAL | M_ERRNO) +#define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR) +#define M_CLIENT (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX) /* * Mute levels are designed to avoid large numbers of @@ -113,10 +113,10 @@ * A mute level of 0 is always printed. */ #define MUTE_LEVEL_SHIFT 24 -#define MUTE_LEVEL_MASK 0xFF +#define MUTE_LEVEL_MASK 0xFF #define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEVEL_MASK) <<= MUTE_LEVEL_SHIFT) -#define DECODE_MUTE_LEVEL(flags) (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEV= EL_MASK) +#define DECODE_MUTE_LEVEL(flags) (((flags) >> MUTE_LEVEL_SHIFT) & MUT= E_LEVEL_MASK) /* * log_level: verbosity level n (--verb n) must be >=3D log_level to prin= t. @@ -139,11 +139,34 @@ bool dont_mute(unsigned int flags); /* Macro to ensure (and teach static analysis tools) we exit on fatal erro= rs */ -#define EXIT_FATAL(flags) do { if ((flags) & M_FATAL) {_exit(1);}} while (= false) +#define EXIT_FATAL(flags) \ + do \ + { \ + if ((flags) & M_FATAL) \ + { \ + _exit(1); \ + } \ + } while (false) -#define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARG= S__);} EXIT_FATAL(flags); } while (false) +#define msg(flags, ...) \ + do \ + { \ + if (msg_test(flags)) \ + { \ + x_msg((flags), __VA_ARGS__); \ + } \ + EXIT_FATAL(flags); \ + } while (false) #ifdef ENABLE_DEBUG -#define dmsg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_AR= GS__);} EXIT_FATAL(flags); } while (false) +#define dmsg(flags, ...) \ + do \ + { \ + if (msg_test(flags)) \ + { \ + x_msg((flags), __VA_ARGS__); \ + } \ + EXIT_FATAL(flags); \ + } while (false) #else #define dmsg(flags, ...) #endif @@ -151,12 +174,12 @@ void x_msg(const unsigned int flags, const char *format, ...) #ifdef __GNUC__ #if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 2, 3))) + __attribute__((format(gnu_printf, 2, 3))) #else -__attribute__ ((format(__printf__, 2, 3))) + __attribute__((format(__printf__, 2, 3))) #endif #endif -; /* should be called via msg above */ + ; /* should be called via msg above */ void x_msg_va(const unsigned int flags, const char *format, va_list arglis= t); @@ -174,7 +197,7 @@ void set_machine_readable_output(bool parsable); -#define SDL_CONSTRAIN (1<<0) +#define SDL_CONSTRAIN (1 << 0) bool set_debug_level(const int level, const unsigned int flags); bool set_mute_cutoff(const int cutoff); @@ -192,26 +215,41 @@ /* Fatal logic errors */ #ifndef ENABLE_SMALL -#define ASSERT(x) do { if (!(x)) {assert_failed(__FILE__, __LINE__, #x);}}= while (false) +#define ASSERT(x) \ + do \ + { \ + if (!(x)) \ + { \ + assert_failed(__FILE__, __LINE__, #x); \ + } \ + } while (false) #else -#define ASSERT(x) do { if (!(x)) {assert_failed(__FILE__, __LINE__, NULL);= }} while (false) +#define ASSERT(x) \ + do \ + { \ + if (!(x)) \ + { \ + assert_failed(__FILE__, __LINE__, NULL); \ + } \ + } while (false) #endif #ifdef _MSC_VER __declspec(noreturn) #endif -void assert_failed(const char *filename, int line, const char *condition) +void +assert_failed(const char *filename, int line, const char *condition) #ifndef _MSC_VER -__attribute__((__noreturn__)) + __attribute__((__noreturn__)) #endif -; + ; /* Poor-man's static_assert() for when not supplied by assert.h, taken from * Linux's sys/cdefs.h under GPLv2 */ #ifndef static_assert -#define static_assert(expr, diagnostic) \ - extern int (*__OpenVPN_static_assert_function(void)) \ - [!!sizeof(struct { int __error_if_negative : (expr) ? 2 : -1; })] +#define static_assert(expr, diagnostic) \ + extern int (*__OpenVPN_static_assert_function( \ + void))[!!sizeof(struct { int __error_if_negative : (expr) ? 2 : -1= ; })] #endif /* Inline functions */ @@ -268,9 +306,7 @@ void set_check_status(unsigned int info_level, unsigned int verbose_level); -void x_check_status(int status, - const char *description, - struct link_socket *sock, +void x_check_status(int status, const char *description, struct link_socke= t *sock, struct tuntap *tt); static inline void @@ -384,7 +420,7 @@ *crt_error =3D true; err =3D errno; } -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ *crt_error =3D true; err =3D errno; #endif diff --git a/src/openvpn/event.c b/src/openvpn/event.c index c3907b9..f3f992e 100644 --- a/src/openvpn/event.c +++ b/src/openvpn/event.c @@ -177,8 +177,8 @@ ASSERT(index >=3D 0 && index < wes->n_events); for (i =3D index; i < wes->n_events - 1; ++i) { - wes->events[i] =3D wes->events[i+1]; - wes->esr[i] =3D wes->esr[i+1]; + wes->events[i] =3D wes->events[i + 1]; + wes->esr[i] =3D wes->esr[i + 1]; } --wes->n_events; } @@ -207,7 +207,7 @@ static void we_free(struct event_set *es) { - struct we_set *wes =3D (struct we_set *) es; + struct we_set *wes =3D (struct we_set *)es; free(wes->events); free(wes->esr); free(wes); @@ -216,7 +216,7 @@ static void we_reset(struct event_set *es) { - struct we_set *wes =3D (struct we_set *) es; + struct we_set *wes =3D (struct we_set *)es; ASSERT(wes->fast); wes->n_events =3D 0; } @@ -224,7 +224,7 @@ static void we_del(struct event_set *es, event_t event) { - struct we_set *wes =3D (struct we_set *) es; + struct we_set *wes =3D (struct we_set *)es; ASSERT(!wes->fast); we_del_event(wes, event); } @@ -232,13 +232,10 @@ static void we_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *ar= g) { - struct we_set *wes =3D (struct we_set *) es; + struct we_set *wes =3D (struct we_set *)es; - dmsg(D_EVENT_WAIT, "WE_CTL n=3D%d ev=3D%p rwflags=3D0x%04x arg=3D" ptr= _format, - wes->n_events, - event, - rwflags, - (ptr_type)arg); + dmsg(D_EVENT_WAIT, "WE_CTL n=3D%d ev=3D%p rwflags=3D0x%04x arg=3D" ptr= _format, wes->n_events, event, + rwflags, (ptr_type)arg); if (wes->fast) { @@ -331,11 +328,11 @@ } break; - case EVENT_READ|EVENT_WRITE: + case EVENT_READ | EVENT_WRITE: switch (n) { case 0: - if (!we_append_event(wes, event, EVENT_READ|EVENT_= WRITE, arg)) + if (!we_append_event(wes, event, EVENT_READ | EVEN= T_WRITE, arg)) { goto err; } @@ -378,13 +375,15 @@ return; err: - msg(D_EVENT_ERRORS, "Error: Windows resource limit WSA_MAXIMUM_WAIT_EV= ENTS (%d) has been exceeded", WSA_MAXIMUM_WAIT_EVENTS); + msg(D_EVENT_ERRORS, + "Error: Windows resource limit WSA_MAXIMUM_WAIT_EVENTS (%d) has be= en exceeded", + WSA_MAXIMUM_WAIT_EVENTS); } static int we_wait(struct event_set *es, const struct timeval *tv, struct event_set_r= eturn *out, int outlen) { - struct we_set *wes =3D (struct we_set *) es; + struct we_set *wes =3D (struct we_set *)es; const int timeout =3D tv_to_ms_timeout(tv); DWORD status; @@ -396,11 +395,8 @@ int i; for (i =3D 0; i < wes->n_events; ++i) { - dmsg(D_EVENT_WAIT, "[%d] ev=3D%p rwflags=3D0x%04x arg=3D" ptr_= format, - i, - wes->events[i], - wes->esr[i].rwflags, - (ptr_type)wes->esr[i].arg); + dmsg(D_EVENT_WAIT, "[%d] ev=3D%p rwflags=3D0x%04x arg=3D" ptr_= format, i, wes->events[i], + wes->esr[i].rwflags, (ptr_type)wes->esr[i].arg); } } #endif @@ -408,18 +404,13 @@ /* * First poll our event list with 0 timeout */ - status =3D WSAWaitForMultipleEvents( - (DWORD) wes->n_events, - wes->events, - FALSE, - (DWORD) 0, - FALSE); + status =3D WSAWaitForMultipleEvents((DWORD)wes->n_events, wes->events,= FALSE, (DWORD)0, FALSE); /* * If at least one event is already set, we must * individually poll the whole list. */ - if (status >=3D WSA_WAIT_EVENT_0 && status < WSA_WAIT_EVENT_0 + (DWORD= ) wes->n_events) + if (status >=3D WSA_WAIT_EVENT_0 && status < WSA_WAIT_EVENT_0 + (DWORD= )wes->n_events) { int i; int j =3D 0; @@ -432,8 +423,8 @@ if (WaitForSingleObject(wes->events[i], 0) =3D=3D WAIT_OBJECT_= 0) { *out =3D wes->esr[i]; - dmsg(D_EVENT_WAIT, "WE_WAIT leave [%d,%d] rwflags=3D0x%04x= arg=3D" ptr_format, - i, j, out->rwflags, (ptr_type)out->arg); + dmsg(D_EVENT_WAIT, "WE_WAIT leave [%d,%d] rwflags=3D0x%04x= arg=3D" ptr_format, i, j, + out->rwflags, (ptr_type)out->arg); ++j; ++out; } @@ -453,19 +444,16 @@ */ if (timeout > 0) { - status =3D WSAWaitForMultipleEvents( - (DWORD) wes->n_events, - wes->events, - FALSE, - (DWORD) timeout, - FALSE); + status =3D WSAWaitForMultipleEvents((DWORD)wes->n_events, wes-= >events, FALSE, + (DWORD)timeout, FALSE); } - if (outlen >=3D 1 && status >=3D WSA_WAIT_EVENT_0 && status < WSA_= WAIT_EVENT_0 + (DWORD) wes->n_events) + if (outlen >=3D 1 && status >=3D WSA_WAIT_EVENT_0 + && status < WSA_WAIT_EVENT_0 + (DWORD)wes->n_events) { *out =3D wes->esr[status - WSA_WAIT_EVENT_0]; - dmsg(D_EVENT_WAIT, "WE_WAIT leave rwflags=3D0x%04x arg=3D" ptr= _format, - out->rwflags, (ptr_type)out->arg); + dmsg(D_EVENT_WAIT, "WE_WAIT leave rwflags=3D0x%04x arg=3D" ptr= _format, out->rwflags, + (ptr_type)out->arg); return 1; } else if (status =3D=3D WSA_WAIT_TIMEOUT) @@ -512,10 +500,9 @@ /* Allocate space for event_set_return objects */ ALLOC_ARRAY_CLEAR(wes->esr, struct event_set_return, wes->capacity); - dmsg(D_EVENT_WAIT, "WE_INIT maxevents=3D%d capacity=3D%d", - *maxevents, wes->capacity); + dmsg(D_EVENT_WAIT, "WE_INIT maxevents=3D%d capacity=3D%d", *maxevents,= wes->capacity); - return (struct event_set *) wes; + return (struct event_set *)wes; } #endif /* _WIN32 */ @@ -534,7 +521,7 @@ static void ep_free(struct event_set *es) { - struct ep_set *eps =3D (struct ep_set *) es; + struct ep_set *eps =3D (struct ep_set *)es; close(eps->epfd); free(eps->events); free(eps); @@ -543,7 +530,7 @@ static void ep_reset(struct event_set *es) { - const struct ep_set *eps =3D (struct ep_set *) es; + const struct ep_set *eps =3D (struct ep_set *)es; ASSERT(eps->fast); } @@ -551,7 +538,7 @@ ep_del(struct event_set *es, event_t event) { struct epoll_event ev; - struct ep_set *eps =3D (struct ep_set *) es; + struct ep_set *eps =3D (struct ep_set *)es; dmsg(D_EVENT_WAIT, "EP_DEL ev=3D%d", (int)event); @@ -559,14 +546,14 @@ CLEAR(ev); if (epoll_ctl(eps->epfd, EPOLL_CTL_DEL, event, &ev) < 0) { - msg(M_WARN|M_ERRNO, "EVENT: epoll_ctl EPOLL_CTL_DEL failed, sd=3D%= d", (int)event); + msg(M_WARN | M_ERRNO, "EVENT: epoll_ctl EPOLL_CTL_DEL failed, sd= =3D%d", (int)event); } } static void ep_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *ar= g) { - struct ep_set *eps =3D (struct ep_set *) es; + struct ep_set *eps =3D (struct ep_set *)es; struct epoll_event ev; CLEAR(ev); @@ -581,11 +568,8 @@ ev.events |=3D EPOLLOUT; } - dmsg(D_EVENT_WAIT, "EP_CTL fd=3D%d rwflags=3D0x%04x ev=3D0x%08x arg=3D= " ptr_format, - (int)event, - rwflags, - (unsigned int)ev.events, - (ptr_type)ev.data.ptr); + dmsg(D_EVENT_WAIT, "EP_CTL fd=3D%d rwflags=3D0x%04x ev=3D0x%08x arg=3D= " ptr_format, (int)event, rwflags, + (unsigned int)ev.events, (ptr_type)ev.data.ptr); if (epoll_ctl(eps->epfd, EPOLL_CTL_MOD, event, &ev) < 0) { @@ -606,7 +590,7 @@ static int ep_wait(struct event_set *es, const struct timeval *tv, struct event_set_r= eturn *out, int outlen) { - struct ep_set *eps =3D (struct ep_set *) es; + struct ep_set *eps =3D (struct ep_set *)es; int stat; if (outlen > eps->maxevents) @@ -625,7 +609,7 @@ for (i =3D 0; i < stat; ++i) { esr->rwflags =3D 0; - if (ev->events & (EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP)) + if (ev->events & (EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP)) { esr->rwflags |=3D EVENT_READ; } @@ -634,8 +618,8 @@ esr->rwflags |=3D EVENT_WRITE; } esr->arg =3D ev->data.ptr; - dmsg(D_EVENT_WAIT, "EP_WAIT[%d] rwflags=3D0x%04x ev=3D0x%08x a= rg=3D" ptr_format, - i, esr->rwflags, ev->events, (ptr_type)ev->data.ptr); + dmsg(D_EVENT_WAIT, "EP_WAIT[%d] rwflags=3D0x%04x ev=3D0x%08x a= rg=3D" ptr_format, i, + esr->rwflags, ev->events, (ptr_type)ev->data.ptr); ++ev; ++esr; } @@ -683,7 +667,7 @@ /* set epoll control fd */ eps->epfd =3D fd; - return (struct event_set *) eps; + return (struct event_set *)eps; } #endif /* EPOLL */ @@ -702,7 +686,7 @@ static void po_free(struct event_set *es) { - struct po_set *pos =3D (struct po_set *) es; + struct po_set *pos =3D (struct po_set *)es; free(pos->events); free(pos->args); free(pos); @@ -711,7 +695,7 @@ static void po_reset(struct event_set *es) { - struct po_set *pos =3D (struct po_set *) es; + struct po_set *pos =3D (struct po_set *)es; ASSERT(pos->fast); pos->n_events =3D 0; } @@ -719,7 +703,7 @@ static void po_del(struct event_set *es, event_t event) { - struct po_set *pos =3D (struct po_set *) es; + struct po_set *pos =3D (struct po_set *)es; int i; dmsg(D_EVENT_WAIT, "PO_DEL ev=3D%d", (int)event); @@ -732,8 +716,8 @@ int j; for (j =3D i; j < pos->n_events - 1; ++j) { - pos->events[j] =3D pos->events[j+1]; - pos->args[j] =3D pos->args[j+1]; + pos->events[j] =3D pos->events[j + 1]; + pos->args[j] =3D pos->args[j + 1]; } --pos->n_events; break; @@ -751,7 +735,7 @@ } if (rwflags & EVENT_READ) { - pfdp->events |=3D (POLLIN|POLLPRI); + pfdp->events |=3D (POLLIN | POLLPRI); } } @@ -776,10 +760,10 @@ static void po_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *ar= g) { - struct po_set *pos =3D (struct po_set *) es; + struct po_set *pos =3D (struct po_set *)es; - dmsg(D_EVENT_WAIT, "PO_CTL rwflags=3D0x%04x ev=3D%d arg=3D" ptr_format, - rwflags, (int)event, (ptr_type)arg); + dmsg(D_EVENT_WAIT, "PO_CTL rwflags=3D0x%04x ev=3D%d arg=3D" ptr_format= , rwflags, (int)event, + (ptr_type)arg); if (pos->fast) { @@ -817,7 +801,7 @@ static int po_wait(struct event_set *es, const struct timeval *tv, struct event_set_r= eturn *out, int outlen) { - struct po_set *pos =3D (struct po_set *) es; + struct po_set *pos =3D (struct po_set *)es; int stat; stat =3D poll(pos->events, pos->n_events, tv_to_ms_timeout(tv)); @@ -830,10 +814,10 @@ const struct pollfd *pfdp =3D pos->events; for (i =3D 0; i < pos->n_events && j < outlen; ++i) { - if (pfdp->revents & (POLLIN|POLLPRI|POLLERR|POLLHUP|POLLOUT)) + if (pfdp->revents & (POLLIN | POLLPRI | POLLERR | POLLHUP | PO= LLOUT)) { out->rwflags =3D 0; - if (pfdp->revents & (POLLIN|POLLPRI|POLLERR|POLLHUP)) + if (pfdp->revents & (POLLIN | POLLPRI | POLLERR | POLLHUP)) { out->rwflags |=3D EVENT_READ; } @@ -842,8 +826,10 @@ out->rwflags |=3D EVENT_WRITE; } out->arg =3D pos->args[i]; - dmsg(D_EVENT_WAIT, "PO_WAIT[%d,%d] fd=3D%d rev=3D0x%08x rw= flags=3D0x%04x arg=3D" ptr_format " %s", - i, j, pfdp->fd, pfdp->revents, out->rwflags, (ptr_typ= e)out->arg, pos->fast ? "" : "[scalable]"); + dmsg(D_EVENT_WAIT, + "PO_WAIT[%d,%d] fd=3D%d rev=3D0x%08x rwflags=3D0x%04x= arg=3D" ptr_format " %s", i, j, + pfdp->fd, pfdp->revents, out->rwflags, (ptr_type)out-= >arg, + pos->fast ? "" : "[scalable]"); ++out; ++j; } @@ -892,7 +878,7 @@ /* Allocate space for event_set_return objects */ ALLOC_ARRAY_CLEAR(pos->args, void *, pos->capacity); - return (struct event_set *) pos; + return (struct event_set *)pos; } #endif /* POLL */ @@ -904,15 +890,15 @@ bool fast; fd_set readfds; fd_set writefds; - void **args; /* allocated to capacity size */ - int maxfd; /* largest fd seen so far, always < capacity */ + void **args; /* allocated to capacity size */ + int maxfd; /* largest fd seen so far, always < capacity */ int capacity; /* fixed largest fd + 1 */ }; static void se_free(struct event_set *es) { - struct se_set *ses =3D (struct se_set *) es; + struct se_set *ses =3D (struct se_set *)es; free(ses->args); free(ses); } @@ -920,7 +906,7 @@ static void se_reset(struct event_set *es) { - struct se_set *ses =3D (struct se_set *) es; + struct se_set *ses =3D (struct se_set *)es; int i; ASSERT(ses->fast); @@ -938,7 +924,7 @@ static void se_del(struct event_set *es, event_t event) { - struct se_set *ses =3D (struct se_set *) es; + struct se_set *ses =3D (struct se_set *)es; ASSERT(!ses->fast); dmsg(D_EVENT_WAIT, "SE_DEL ev=3D%d", (int)event); @@ -959,7 +945,7 @@ static void se_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *ar= g) { - struct se_set *ses =3D (struct se_set *) es; + struct se_set *ses =3D (struct se_set *)es; dmsg(D_EVENT_WAIT, "SE_CTL rwflags=3D0x%04x ev=3D%d fast=3D%d cap=3D%d= maxfd=3D%d arg=3D" ptr_format, rwflags, (int)event, (int)ses->fast, ses->capacity, ses->maxfd, (= ptr_type)arg); @@ -1001,17 +987,13 @@ } else { - msg(D_EVENT_ERRORS, "Error: select: too many I/O wait events, fd= =3D%d cap=3D%d", - (int) event, + msg(D_EVENT_ERRORS, "Error: select: too many I/O wait events, fd= =3D%d cap=3D%d", (int)event, ses->capacity); } } static int -se_wait_return(struct se_set *ses, - fd_set *read, - fd_set *write, - struct event_set_return *out, +se_wait_return(struct se_set *ses, fd_set *read, fd_set *write, struct eve= nt_set_return *out, int outlen) { int i, j =3D 0; @@ -1031,8 +1013,8 @@ out->rwflags |=3D EVENT_WRITE; } out->arg =3D ses->args[i]; - dmsg(D_EVENT_WAIT, "SE_WAIT[%d,%d] rwflags=3D0x%04x arg=3D" pt= r_format, - i, j, out->rwflags, (ptr_type)out->arg); + dmsg(D_EVENT_WAIT, "SE_WAIT[%d,%d] rwflags=3D0x%04x arg=3D" pt= r_format, i, j, out->rwflags, + (ptr_type)out->arg); ++out; ++j; } @@ -1041,16 +1023,15 @@ } static int -se_wait_fast(struct event_set *es, const struct timeval *tv, struct event_= set_return *out, int outlen) +se_wait_fast(struct event_set *es, const struct timeval *tv, struct event_= set_return *out, + int outlen) { - struct se_set *ses =3D (struct se_set *) es; + struct se_set *ses =3D (struct se_set *)es; struct timeval tv_tmp =3D *tv; int stat; - dmsg(D_EVENT_WAIT, "SE_WAIT_FAST maxfd=3D%d tv=3D%" PRIi64 "/%ld", - ses->maxfd, - (int64_t)tv_tmp.tv_sec, - (long)tv_tmp.tv_usec); + dmsg(D_EVENT_WAIT, "SE_WAIT_FAST maxfd=3D%d tv=3D%" PRIi64 "/%ld", ses= ->maxfd, + (int64_t)tv_tmp.tv_sec, (long)tv_tmp.tv_usec); stat =3D select(ses->maxfd + 1, &ses->readfds, &ses->writefds, NULL, &= tv_tmp); @@ -1063,16 +1044,17 @@ } static int -se_wait_scalable(struct event_set *es, const struct timeval *tv, struct ev= ent_set_return *out, int outlen) +se_wait_scalable(struct event_set *es, const struct timeval *tv, struct ev= ent_set_return *out, + int outlen) { - struct se_set *ses =3D (struct se_set *) es; + struct se_set *ses =3D (struct se_set *)es; struct timeval tv_tmp =3D *tv; fd_set read =3D ses->readfds; fd_set write =3D ses->writefds; int stat; - dmsg(D_EVENT_WAIT, "SE_WAIT_SCALEABLE maxfd=3D%d tv=3D%" PRIi64 "/%ld", - ses->maxfd, (int64_t)tv_tmp.tv_sec, (long)tv_tmp.tv_usec); + dmsg(D_EVENT_WAIT, "SE_WAIT_SCALEABLE maxfd=3D%d tv=3D%" PRIi64 "/%ld"= , ses->maxfd, + (int64_t)tv_tmp.tv_sec, (long)tv_tmp.tv_usec); stat =3D select(ses->maxfd + 1, &read, &write, NULL, &tv_tmp); @@ -1117,7 +1099,7 @@ /* Allocate space for event_set_return void * args */ ALLOC_ARRAY_CLEAR(ses->args, void *, ses->capacity); - return (struct event_set *) ses; + return (struct event_set *)ses; } #endif /* SELECT */ @@ -1143,7 +1125,7 @@ { ret =3D po_init(maxevents, flags); } -#else /* ifdef SELECT_PREFERRED_OVER_POLL */ +#else /* ifdef SELECT_PREFERRED_OVER_POLL */ if (!ret) { ret =3D po_init(maxevents, flags); @@ -1175,7 +1157,7 @@ msg(M_WARN, "Note: sys_epoll API is unavailable, falling back to p= oll/select API"); ret =3D event_set_init_simple(maxevents, flags); } -#else /* if EPOLL */ +#else /* if EPOLL */ ret =3D event_set_init_simple(maxevents, flags); #endif ASSERT(ret); diff --git a/src/openvpn/event.h b/src/openvpn/event.h index 389f80d..a5329e4 100644 --- a/src/openvpn/event.h +++ b/src/openvpn/event.h @@ -32,12 +32,12 @@ * rwflags passed to event_ctl and returned by * struct event_set_return. */ -#define READ_SHIFT 0 -#define WRITE_SHIFT 1 +#define READ_SHIFT 0 +#define WRITE_SHIFT 1 -#define EVENT_UNDEF 4 -#define EVENT_READ (1 << READ_SHIFT) -#define EVENT_WRITE (1 << WRITE_SHIFT) +#define EVENT_UNDEF 4 +#define EVENT_READ (1 << READ_SHIFT) +#define EVENT_WRITE (1 << WRITE_SHIFT) /* event flags returned by io_wait. * @@ -58,35 +58,35 @@ * signals. */ -#define SOCKET_SHIFT 0 -#define SOCKET_READ (1 << (SOCKET_SHIFT + READ_SHIFT)) -#define SOCKET_WRITE (1 << (SOCKET_SHIFT + WRITE_SHIFT)) -#define TUN_SHIFT 2 -#define TUN_READ (1 << (TUN_SHIFT + READ_SHIFT)) -#define TUN_WRITE (1 << (TUN_SHIFT + WRITE_SHIFT)) -#define ERR_SHIFT 4 -#define ES_ERROR (1 << (ERR_SHIFT + READ_SHIFT)) -#define ES_TIMEOUT (1 << (ERR_SHIFT + WRITE_SHIFT)) -#define MANAGEMENT_SHIFT 6 -#define MANAGEMENT_READ (1 << (MANAGEMENT_SHIFT + READ_SHIFT)) -#define MANAGEMENT_WRITE (1 << (MANAGEMENT_SHIFT + WRITE_SHIFT)) -#define FILE_SHIFT 8 -#define FILE_CLOSED (1 << (FILE_SHIFT + READ_SHIFT)) -#define DCO_SHIFT 10 -#define DCO_READ (1 << (DCO_SHIFT + READ_SHIFT)) -#define DCO_WRITE (1 << (DCO_SHIFT + WRITE_SHIFT)) +#define SOCKET_SHIFT 0 +#define SOCKET_READ (1 << (SOCKET_SHIFT + READ_SHIFT)) +#define SOCKET_WRITE (1 << (SOCKET_SHIFT + WRITE_SHIFT)) +#define TUN_SHIFT 2 +#define TUN_READ (1 << (TUN_SHIFT + READ_SHIFT)) +#define TUN_WRITE (1 << (TUN_SHIFT + WRITE_SHIFT)) +#define ERR_SHIFT 4 +#define ES_ERROR (1 << (ERR_SHIFT + READ_SHIFT)) +#define ES_TIMEOUT (1 << (ERR_SHIFT + WRITE_SHIFT)) +#define MANAGEMENT_SHIFT 6 +#define MANAGEMENT_READ (1 << (MANAGEMENT_SHIFT + READ_SHIFT)) +#define MANAGEMENT_WRITE (1 << (MANAGEMENT_SHIFT + WRITE_SHIFT)) +#define FILE_SHIFT 8 +#define FILE_CLOSED (1 << (FILE_SHIFT + READ_SHIFT)) +#define DCO_SHIFT 10 +#define DCO_READ (1 << (DCO_SHIFT + READ_SHIFT)) +#define DCO_WRITE (1 << (DCO_SHIFT + WRITE_SHIFT)) /* * Initialization flags passed to event_set_init */ -#define EVENT_METHOD_US_TIMEOUT (1<<0) -#define EVENT_METHOD_FAST (1<<1) +#define EVENT_METHOD_US_TIMEOUT (1 << 0) +#define EVENT_METHOD_FAST (1 << 1) /* * The following constant is used as boundary between integer value * and real addresses when passing arguments to event handlers as (void *) */ -#define MULTI_N ((void *)16) /* upper bound on MTCP_x */ +#define MULTI_N ((void *)16) /* upper bound on MTCP_x */ #ifdef _WIN32 @@ -94,7 +94,7 @@ #define UNDEFINED_EVENT (NULL) -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ typedef int event_t; @@ -118,7 +118,8 @@ * 0 on timeout * length of event_set_return if at least 1 event is returned */ - int (*wait)(struct event_set *es, const struct timeval *tv, struct eve= nt_set_return *out, int outlen); + int (*wait)(struct event_set *es, const struct timeval *tv, struct eve= nt_set_return *out, + int outlen); }; struct event_set_return @@ -132,7 +133,8 @@ struct event_set_functions func; }; -typedef enum { +typedef enum +{ EVENT_ARG_MULTI_INSTANCE =3D 0, EVENT_ARG_LINK_SOCKET, } event_arg_t; @@ -141,9 +143,10 @@ struct event_arg { event_arg_t type; - union { + union + { struct multi_instance *mi; /* if type =3D EVENT_ARG_MULTI_INSTANCE= */ - struct link_socket *sock; /* if type =3D EVENT_ARG_LINK_SOCKET */ + struct link_socket *sock; /* if type =3D EVENT_ARG_LINK_SOCKET */ } u; }; @@ -211,7 +214,7 @@ } } -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ static inline void wait_signal(struct event_set *es, void *arg) diff --git a/src/openvpn/fdmisc.c b/src/openvpn/fdmisc.c index 3d8654c..f6be9fd 100644 --- a/src/openvpn/fdmisc.c +++ b/src/openvpn/fdmisc.c @@ -42,7 +42,7 @@ { return false; } -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { return false; diff --git a/src/openvpn/fdmisc.h b/src/openvpn/fdmisc.h index 17b6994..1ff66aa 100644 --- a/src/openvpn/fdmisc.h +++ b/src/openvpn/fdmisc.h @@ -46,4 +46,4 @@ } #undef FD_SET /* prevent direct use of FD_SET() */ -#endif /* FD_MISC_H */ +#endif /* FD_MISC_H */ diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index a4f260a..f798c6e 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -59,14 +59,11 @@ { struct buffer out =3D alloc_buf_gc(64, gc); - buf_printf(&out, "I/O WAIT %s|%s| %s", - tun_stat(c->c1.tuntap, EVENT_READ, gc), - tun_stat(c->c1.tuntap, EVENT_WRITE, gc), - tv_string(&c->c2.timeval, gc)); + buf_printf(&out, "I/O WAIT %s|%s| %s", tun_stat(c->c1.tuntap, EVENT_RE= AD, gc), + tun_stat(c->c1.tuntap, EVENT_WRITE, gc), tv_string(&c->c2.t= imeval, gc)); for (int i =3D 0; i < c->c1.link_sockets_num; i++) { - buf_printf(&out, "\n %s|%s", - socket_stat(c->c2.link_sockets[i], EVENT_READ, gc), + buf_printf(&out, "\n %s|%s", socket_stat(c->c2.link_sockets[i], EV= ENT_READ, gc), socket_stat(c->c2.link_sockets[i], EVENT_WRITE, gc)); } return BSTR(&out); @@ -128,7 +125,7 @@ static inline void context_immediate_reschedule(struct context *c) { - c->c2.timeval.tv_sec =3D 0; /* ZERO-TIMEOUT */ + c->c2.timeval.tv_sec =3D 0; /* ZERO-TIMEOUT */ c->c2.timeval.tv_usec =3D 0; } @@ -186,9 +183,8 @@ if (interval_test(&c->c2.tmp_int)) { - const int tmp_status =3D tls_multi_process - (c->c2.tls_multi, &c->c2.to_link, &c->c= 2.to_link_addr, - get_link_socket_info(c), &wakeup); + const int tmp_status =3D tls_multi_process( + c->c2.tls_multi, &c->c2.to_link, &c->c2.to_link_addr, get_link= _socket_info(c), &wakeup); if (tmp_status =3D=3D TLSMP_RECONNECT) { @@ -346,12 +342,7 @@ #ifdef ENABLE_MANAGEMENT if (management) { - management_set_state(management, - OPENVPN_STATE_GET_CONFIG, - NULL, - NULL, - NULL, - NULL, + management_set_state(management, OPENVPN_STATE_GET_CONFIG,= NULL, NULL, NULL, NULL, NULL); } #endif @@ -378,8 +369,7 @@ } bool -send_control_channel_string_dowork(struct tls_session *session, - const char *str, int msglevel) +send_control_channel_string_dowork(struct tls_session *session, const char= *str, int msglevel) { struct gc_arena gc =3D gc_new(); bool stat; @@ -388,12 +378,11 @@ struct key_state *ks =3D &session->key[KS_PRIMARY]; /* buffered cleartext write onto TLS control channel */ - stat =3D tls_send_payload(ks, (uint8_t *) str, strlen(str) + 1); + stat =3D tls_send_payload(ks, (uint8_t *)str, strlen(str) + 1); msg(msglevel, "SENT CONTROL [%s]: '%s' (status=3D%d)", - session->common_name ? session->common_name : "UNDEF", - sanitize_control_message(str, &gc), - (int) stat); + session->common_name ? session->common_name : "UNDEF", sanitize_co= ntrol_message(str, &gc), + (int)stat); gc_free(&gc); return stat; @@ -426,8 +415,8 @@ static void check_add_routes_action(struct context *c, const bool errors) { - bool route_status =3D do_route(&c->options, c->c1.route_list, c->c1.ro= ute_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->n= et_ctx); + bool route_status =3D do_route(&c->options, c->c1.route_list, c->c1.ro= ute_ipv6_list, c->c1.tuntap, + c->plugins, c->c2.es, &c->net_ctx); int flags =3D (errors ? ISC_ERRORS : 0); flags |=3D (!route_status ? ISC_ROUTE_ERRORS : 0); @@ -459,8 +448,8 @@ register_signal(c->sig, SIGHUP, "ip-fail"); c->persist.restart_sleep_seconds =3D 10; #ifdef _WIN32 - show_routes(M_INFO|M_NOPREFIX); - show_adapters(M_INFO|M_NOPREFIX); + show_routes(M_INFO | M_NOPREFIX); + show_adapters(M_INFO | M_NOPREFIX); #endif } } @@ -603,7 +592,8 @@ * Buffer reallocation, for use with null encryption. */ static inline void -buffer_turnover(const uint8_t *orig_buf, struct buffer *dest_stub, struct = buffer *src_stub, struct buffer *storage) +buffer_turnover(const uint8_t *orig_buf, struct buffer *dest_stub, struct = buffer *src_stub, + struct buffer *storage) { if (orig_buf =3D=3D src_stub->data && src_stub->data !=3D storage->dat= a) { @@ -631,7 +621,7 @@ if (dco_enabled(&c->options)) { msg(M_WARN, "Attempting to send data packet while data channel off= load is in use. " - "Dropping packet"); + "Dropping packet"); c->c2.buf.len =3D 0; } @@ -651,7 +641,8 @@ /* Compress the packet. */ if (c->c2.comp_context) { - (*c->c2.comp_context->alg.compress)(&c->c2.buf, b->compress_bu= f, c->c2.comp_context, &c->c2.frame); + (*c->c2.comp_context->alg.compress)(&c->c2.buf, b->compress_bu= f, c->c2.comp_context, + &c->c2.frame); } #endif #ifdef ENABLE_FRAGMENT @@ -698,8 +689,7 @@ /* * Get the address we will be sending the packet to. */ - link_socket_get_outgoing_addr(&c->c2.buf, get_link_socket_info(c), - &c->c2.to_link_addr); + link_socket_get_outgoing_addr(&c->c2.buf, get_link_socket_info(c), &c-= >c2.to_link_addr); /* if null encryption, copy result to read_tun_buf */ buffer_turnover(orig_buf, &c->c2.to_link, &c->c2.buf, &b->read_tun_buf= ); @@ -712,8 +702,7 @@ check_session_timeout(struct context *c) { if (c->options.session_timeout - && event_timeout_trigger(&c->c2.session_interval, &c->c2.timeval, - ETT_DEFAULT)) + && event_timeout_trigger(&c->c2.session_interval, &c->c2.timeval, = ETT_DEFAULT)) { msg(M_INFO, "Session timeout, exiting"); register_signal(c->sig, SIGTERM, "session-timeout"); @@ -727,7 +716,7 @@ process_coarse_timers(struct context *c) { /* flush current packet-id to file once per 60 - * seconds if --replay-persist was specified */ + * seconds if --replay-persist was specified */ if (packet_id_persist_enabled(&c->c1.pid_persist) && event_timeout_trigger(&c->c2.packet_id_persist_interval, &c->c2= .timeval, ETT_DEFAULT)) { @@ -850,7 +839,8 @@ process_coarse_timers(c); c->c2.coarse_timer_wakeup =3D now + c->c2.timeval.tv_sec; - dmsg(D_INTERVAL, "TIMER: coarse timer wakeup %" PRIi64 " seconds", (in= t64_t)c->c2.timeval.tv_sec); + dmsg(D_INTERVAL, "TIMER: coarse timer wakeup %" PRIi64 " seconds", + (int64_t)c->c2.timeval.tv_sec); /* Is the coarse timeout NOT the earliest one? */ if (c->c2.timeval.tv_sec > save.tv_sec) @@ -864,10 +854,10 @@ { const int update_interval =3D 10; /* seconds */ c->c2.update_timeout_random_component =3D now + update_interval; - c->c2.timeout_random_component.tv_usec =3D (time_t) get_random() & 0x0= 003FFFF; + c->c2.timeout_random_component.tv_usec =3D (time_t)get_random() & 0x00= 03FFFF; c->c2.timeout_random_component.tv_sec =3D 0; - dmsg(D_INTERVAL, "RANDOM USEC=3D%ld", (long) c->c2.timeout_random_comp= onent.tv_usec); + dmsg(D_INTERVAL, "RANDOM USEC=3D%ld", (long)c->c2.timeout_random_compo= nent.tv_usec); } static inline void @@ -898,10 +888,8 @@ } static inline void -socks_preprocess_outgoing_link(struct context *c, - struct link_socket *sock, - struct link_socket_actual **to_addr, - int *size_delta) +socks_preprocess_outgoing_link(struct context *c, struct link_socket *sock, + struct link_socket_actual **to_addr, int *s= ize_delta) { if (sock->socks_proxy && sock->info.proto =3D=3D PROTO_UDP) { @@ -912,9 +900,7 @@ /* undo effect of socks_preprocess_outgoing_link */ static inline void -link_socket_write_post_size_adjust(int *size, - int size_delta, - struct buffer *buf) +link_socket_write_post_size_adjust(int *size, int size_delta, struct buffe= r *buf) { if (size_delta > 0 && *size > size_delta) { @@ -946,9 +932,7 @@ c->c2.buf =3D c->c2.buffers->read_link_buf; ASSERT(buf_init(&c->c2.buf, c->c2.frame.buf.headroom)); - status =3D link_socket_read(sock, - &c->c2.buf, - &c->c2.from); + status =3D link_socket_read(sock, &c->c2.buf, &c->c2.from); if (socket_connection_reset(sock, status)) { @@ -966,12 +950,14 @@ /* received a disconnect from a connection-oriented protocol */ if (event_timeout_defined(&c->c2.explicit_exit_notification_in= terval)) { - msg(D_STREAM_ERRORS, "Connection reset during exit notific= ation period, ignoring [%d]", status); + msg(D_STREAM_ERRORS, + "Connection reset during exit notification period, ign= oring [%d]", status); management_sleep(1); } else { - register_signal(c->sig, SIGUSR1, "connection-reset"); /* S= OFT-SIGUSR1 -- TCP connection reset */ + register_signal(c->sig, SIGUSR1, + "connection-reset"); /* SOFT-SIGUSR1 -- TC= P connection reset */ msg(D_STREAM_ERRORS, "Connection reset, restarting [%d]", = status); } } @@ -1017,7 +1003,8 @@ if (management) { management_bytes_client(management, c->c2.buf.len, 0); - management_bytes_server(management, &c->c2.link_read_bytes, &c= ->c2.link_write_bytes, &c->c2.mda_context); + management_bytes_server(management, &c->c2.link_read_bytes, &c= ->c2.link_write_bytes, + &c->c2.mda_context); } #endif } @@ -1045,11 +1032,8 @@ fprintf(stderr, "R"); } #endif - msg(D_LINK_RW, "%s READ [%d] from %s: %s", - proto2ascii(lsi->proto, lsi->af, true), - BLEN(&c->c2.buf), - print_link_socket_actual(&c->c2.from, &gc), - PROTO_DUMP(&c->c2.buf, &gc)); + msg(D_LINK_RW, "%s READ [%d] from %s: %s", proto2ascii(lsi->proto, lsi= ->af, true), + BLEN(&c->c2.buf), print_link_socket_actual(&c->c2.from, &gc), PROT= O_DUMP(&c->c2.buf, &gc)); /* * Good, non-zero length packet received. @@ -1081,9 +1065,8 @@ */ if ((opcode =3D=3D P_DATA_V1) && dco_enabled(&c->options)) { - msg(D_LINK_ERRORS, - "Data Channel Offload doesn't support DATA_V1 packets.= " - "Upgrade your server to 2.4.5 or newer."); + msg(D_LINK_ERRORS, "Data Channel Offload doesn't support D= ATA_V1 packets. " + "Upgrade your server to 2.4.5 or newer.= "); c->c2.buf.len =3D 0; } @@ -1097,8 +1080,7 @@ * will load crypto_options with the correct encryption key * and return false. */ - if (tls_pre_decrypt(c->c2.tls_multi, &c->c2.from, &c->c2.buf, = &co, - floated, &ad_start)) + if (tls_pre_decrypt(c->c2.tls_multi, &c->c2.from, &c->c2.buf, = &co, floated, &ad_start)) { interval_action(&c->c2.tmp_int); @@ -1125,15 +1107,16 @@ } /* authenticate and decrypt the incoming packet */ - decrypt_status =3D openvpn_decrypt(&c->c2.buf, c->c2.buffers->decr= ypt_buf, - co, &c->c2.frame, ad_start); + decrypt_status =3D + openvpn_decrypt(&c->c2.buf, c->c2.buffers->decrypt_buf, co, &c= ->c2.frame, ad_start); if (!decrypt_status /* on the instance context we have only one socket, so just ch= eck the first one */ && link_socket_connection_oriented(c->c2.link_sockets[0])) { /* decryption errors are fatal in TCP mode */ - register_signal(c->sig, SIGUSR1, "decryption-error"); /* SOFT-= SIGUSR1 -- decryption error in TCP mode */ + register_signal(c->sig, SIGUSR1, + "decryption-error"); /* SOFT-SIGUSR1 -- decryp= tion error in TCP mode */ msg(D_STREAM_ERRORS, "Fatal decryption error (process_incoming= _link), restarting"); } } @@ -1147,7 +1130,8 @@ } void -process_incoming_link_part2(struct context *c, struct link_socket_info *ls= i, const uint8_t *orig_buf) +process_incoming_link_part2(struct context *c, struct link_socket_info *ls= i, + const uint8_t *orig_buf) { if (c->c2.buf.len > 0) { @@ -1162,17 +1146,15 @@ /* decompress the incoming packet */ if (c->c2.comp_context) { - (*c->c2.comp_context->alg.decompress)(&c->c2.buf, c->c2.buffer= s->decompress_buf, c->c2.comp_context, &c->c2.frame); + (*c->c2.comp_context->alg.decompress)(&c->c2.buf, c->c2.buffer= s->decompress_buf, + c->c2.comp_context, &c->= c2.frame); } #endif #ifdef PACKET_TRUNCATION_CHECK /* if (c->c2.buf.len > 1) --c->c2.buf.len; */ - ipv4_packet_size_verify(BPTR(&c->c2.buf), - BLEN(&c->c2.buf), - TUNNEL_TYPE(c->c1.tuntap), - "POST_DECRYPT", - &c->c2.n_trunc_post_decrypt); + ipv4_packet_size_verify(BPTR(&c->c2.buf), BLEN(&c->c2.buf), TUNNEL= _TYPE(c->c1.tuntap), + "POST_DECRYPT", &c->c2.n_trunc_post_decryp= t); #endif /* @@ -1199,7 +1181,8 @@ if (c->c2.buf.len > 0) { c->c2.link_read_bytes_auth +=3D c->c2.buf.len; - c->c2.max_recv_size_local =3D max_int(c->c2.original_recv_size= , c->c2.max_recv_size_local); + c->c2.max_recv_size_local =3D + max_int(c->c2.original_recv_size, c->c2.max_recv_size_loca= l); } /* Did we just receive an openvpn ping packet? */ @@ -1262,9 +1245,10 @@ * ourselves in the foot and removing the just established session */ if (dco->dco_message_peer_id !=3D c->c2.tls_multi->dco_peer_id) { - msg(D_DCO_DEBUG, "%s: received message for mismatching peer-id %d,= " - "expected %d", __func__, dco->dco_message_peer_id, - c->c2.tls_multi->dco_peer_id); + msg(D_DCO_DEBUG, + "%s: received message for mismatching peer-id %d, " + "expected %d", + __func__, dco->dco_message_peer_id, c->c2.tls_multi->dco_peer_= id); return; } @@ -1275,16 +1259,18 @@ c->c2.tls_multi->dco_peer_id =3D -1; if (dco->dco_del_peer_reason =3D=3D OVPN_DEL_PEER_REASON_EXPIR= ED) { - msg(D_DCO_DEBUG, "%s: received peer expired notification o= f for peer-id " - "%d", __func__, dco->dco_message_peer_id); + msg(D_DCO_DEBUG, + "%s: received peer expired notification of for peer-id= " + "%d", + __func__, dco->dco_message_peer_id); trigger_ping_timeout_signal(c); return; } break; case OVPN_CMD_SWAP_KEYS: - msg(D_DCO_DEBUG, "%s: received key rotation notification for p= eer-id %d", - __func__, dco->dco_message_peer_id); + msg(D_DCO_DEBUG, "%s: received key rotation notification for p= eer-id %d", __func__, + dco->dco_message_peer_id); tls_session_soft_reset(c->c2.tls_multi); break; @@ -1324,7 +1310,8 @@ ASSERT(buf_safe(&c->c2.buf, c->c2.frame.buf.payload_size)); if (c->c1.tuntap->backend_driver =3D=3D DRIVER_AFUNIX) { - c->c2.buf.len =3D read_tun_afunix(c->c1.tuntap, BPTR(&c->c2.buf), = c->c2.frame.buf.payload_size); + c->c2.buf.len =3D + read_tun_afunix(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.bu= f.payload_size); } else { @@ -1333,11 +1320,8 @@ #endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK - ipv4_packet_size_verify(BPTR(&c->c2.buf), - BLEN(&c->c2.buf), - TUNNEL_TYPE(c->c1.tuntap), - "READ_TUN", - &c->c2.n_trunc_tun_read); + ipv4_packet_size_verify(BPTR(&c->c2.buf), BLEN(&c->c2.buf), TUNNEL_TYP= E(c->c1.tuntap), + "READ_TUN", &c->c2.n_trunc_tun_read); #endif /* Was TUN/TAP interface stopped? */ @@ -1392,7 +1376,7 @@ if (proto_ver =3D=3D 4) { /* make sure we got whole IP header */ - if (BLEN(buf) < ((int) sizeof(struct openvpn_iphdr) + ip_hdr_offse= t)) + if (BLEN(buf) < ((int)sizeof(struct openvpn_iphdr) + ip_hdr_offset= )) { return; } @@ -1403,7 +1387,7 @@ return; } - struct openvpn_iphdr *pip =3D (struct openvpn_iphdr *) (BPTR(buf) = + ip_hdr_offset); + struct openvpn_iphdr *pip =3D (struct openvpn_iphdr *)(BPTR(buf) += ip_hdr_offset); /* drop packets with same dest addr as gateway */ if (memcmp(&tun_sa.addr.in4.sin_addr.s_addr, &pip->daddr, sizeof(p= ip->daddr)) =3D=3D 0) @@ -1414,7 +1398,7 @@ else if (proto_ver =3D=3D 6) { /* make sure we got whole IPv6 header */ - if (BLEN(buf) < ((int) sizeof(struct openvpn_ipv6hdr) + ip_hdr_off= set)) + if (BLEN(buf) < ((int)sizeof(struct openvpn_ipv6hdr) + ip_hdr_offs= et)) { return; } @@ -1425,7 +1409,7 @@ return; } - struct openvpn_ipv6hdr *pip6 =3D (struct openvpn_ipv6hdr *) (BPTR(= buf) + ip_hdr_offset); + struct openvpn_ipv6hdr *pip6 =3D (struct openvpn_ipv6hdr *)(BPTR(b= uf) + ip_hdr_offset); /* drop packets with same dest addr as gateway */ if (OPENVPN_IN6_ARE_ADDR_EQUAL(&tun_sa.addr.in6.sin6_addr, &pip6->= daddr)) @@ -1483,19 +1467,15 @@ * The --passtos and --mssfix options require * us to examine the IP header (IPv4 or IPv6). */ - unsigned int flags =3D PIPV4_PASSTOS | PIP_MSSFIX | PIPV4_CLIENT_N= AT - | PIPV6_ICMP_NOHOST_CLIENT; + unsigned int flags =3D + PIPV4_PASSTOS | PIP_MSSFIX | PIPV4_CLIENT_NAT | PIPV6_ICMP_NOH= OST_CLIENT; process_ip_header(c, flags, &c->c2.buf, out_sock); #ifdef PACKET_TRUNCATION_CHECK /* if (c->c2.buf.len > 1) --c->c2.buf.len; */ - ipv4_packet_size_verify(BPTR(&c->c2.buf), - BLEN(&c->c2.buf), - TUNNEL_TYPE(c->c1.tuntap), - "PRE_ENCRYPT", - &c->c2.n_trunc_pre_encrypt); + ipv4_packet_size_verify(BPTR(&c->c2.buf), BLEN(&c->c2.buf), TUNNEL= _TYPE(c->c1.tuntap), + "PRE_ENCRYPT", &c->c2.n_trunc_pre_encrypt); #endif - } if (c->c2.buf.len > 0) { @@ -1571,8 +1551,7 @@ icmp6out.icmp6_type =3D OPENVPN_ICMP6_DESTINATION_UNREACHABLE; icmp6out.icmp6_code =3D OPENVPN_ICMP6_DU_NOROUTE; - int icmpheader_len =3D sizeof(struct openvpn_ipv6hdr) - + sizeof(struct openvpn_icmp6hdr); + int icmpheader_len =3D sizeof(struct openvpn_ipv6hdr) + sizeof(struct = openvpn_icmp6hdr); int totalheader_len =3D icmpheader_len; if (TUNNEL_TYPE(c->c1.tuntap) =3D=3D DEV_TYPE_TAP) @@ -1585,8 +1564,7 @@ * frame should be <=3D 1280 and have as much as possible of the origi= nal * packet */ - int max_payload_size =3D min_int(MAX_ICMPV6LEN, - c->c2.frame.tun_mtu - icmpheader_len); + int max_payload_size =3D min_int(MAX_ICMPV6LEN, c->c2.frame.tun_mtu - = icmpheader_len); int payload_len =3D min_int(max_payload_size, BLEN(&inputipbuf)); pip6out.payload_len =3D htons(sizeof(struct openvpn_icmp6hdr) + payloa= d_len); @@ -1614,10 +1592,10 @@ /* Calculate checksum over the packet and write to header */ - uint16_t new_csum =3D ip_checksum(AF_INET6, BPTR(outbuf), BLEN(outbuf), - (const uint8_t *)&pip6out.saddr, - (uint8_t *)&pip6out.daddr, OPENVPN_IPP= ROTO_ICMPV6); - ((struct openvpn_icmp6hdr *) BPTR(outbuf))->icmp6_cksum =3D htons(new_= csum); + uint16_t new_csum =3D + ip_checksum(AF_INET6, BPTR(outbuf), BLEN(outbuf), (const uint8_t *= )&pip6out.saddr, + (uint8_t *)&pip6out.daddr, OPENVPN_IPPROTO_ICMPV6); + ((struct openvpn_icmp6hdr *)BPTR(outbuf))->icmp6_cksum =3D htons(new_c= sum); /* IPv6 Header */ @@ -1633,7 +1611,7 @@ return; } - const struct openvpn_ethhdr *orig_ethhdr =3D (struct openvpn_ethhd= r *) BPTR(buf); + const struct openvpn_ethhdr *orig_ethhdr =3D (struct openvpn_ethhd= r *)BPTR(buf); /* Copy frametype and reverse source/destination for the response = */ struct openvpn_ethhdr ethhdr; @@ -1714,15 +1692,13 @@ { mss_fixup_ipv6(&ipbuf, c->c2.frame.mss_fix); } - if (!(flags & PIP_OUTGOING) && (flags - &(PIPV6_ICMP_NOHOST_CLIENT | P= IPV6_ICMP_NOHOST_SERVER))) + if (!(flags & PIP_OUTGOING) + && (flags & (PIPV6_ICMP_NOHOST_CLIENT | PIPV6_ICMP_NOHOST_= SERVER))) { - ipv6_send_icmp_unreachable(c, buf, - (bool)(flags & PIPV6_ICMP_NOHOS= T_CLIENT)); + ipv6_send_icmp_unreachable(c, buf, (bool)(flags & PIPV6_IC= MP_NOHOST_CLIENT)); /* Drop the IPv6 packet */ buf->len =3D 0; } - } } } @@ -1759,10 +1735,9 @@ */ if (c->options.shaper) { - int overhead =3D datagram_overhead(c->c2.to_link_addr->des= t.addr.sa.sa_family, - sock->info.proto); - shaper_wrote_bytes(&c->c2.shaper, - BLEN(&c->c2.to_link) + overhead); + int overhead =3D + datagram_overhead(c->c2.to_link_addr->dest.addr.sa.sa_= family, sock->info.proto); + shaper_wrote_bytes(&c->c2.shaper, BLEN(&c->c2.to_link) + o= verhead); } /* @@ -1786,10 +1761,8 @@ } #endif msg(D_LINK_RW, "%s WRITE [%d] to %s: %s", - proto2ascii(sock->info.proto, sock->info.af, true), - BLEN(&c->c2.to_link), - print_link_socket_actual(c->c2.to_link_addr, &gc), - PROTO_DUMP(&c->c2.to_link, &gc)); + proto2ascii(sock->info.proto, sock->info.af, true), BLEN(&= c->c2.to_link), + print_link_socket_actual(c->c2.to_link_addr, &gc), PROTO_D= UMP(&c->c2.to_link, &gc)); /* Packet send complexified by possible Socks5 usage */ { @@ -1800,9 +1773,7 @@ socks_preprocess_outgoing_link(c, sock, &to_addr, &size_de= lta); /* Send packet */ - size =3D (int)link_socket_write(sock, - &c->c2.to_link, - to_addr); + size =3D (int)link_socket_write(sock, &c->c2.to_link, to_a= ddr); /* Undo effect of prepend */ link_socket_write_post_size_adjust(&size, size_delta, &c->= c2.to_link); @@ -1823,7 +1794,8 @@ if (management) { management_bytes_client(management, 0, size); - management_bytes_server(management, &c->c2.link_read_b= ytes, &c->c2.link_write_bytes, &c->c2.mda_context); + management_bytes_server(management, &c->c2.link_read_b= ytes, + &c->c2.link_write_bytes, &c->c= 2.mda_context); } #endif } @@ -1840,9 +1812,7 @@ { msg(D_LINK_ERRORS, "TCP/UDP packet was truncated/expanded on write to %s = (tried=3D%d,actual=3D%d)", - print_link_socket_actual(c->c2.to_link_addr, &gc), - BLEN(&c->c2.to_link), - size); + print_link_socket_actual(c->c2.to_link_addr, &gc), BLE= N(&c->c2.to_link), size); } } @@ -1861,7 +1831,8 @@ ENETUNREACH; #endif if (size < 0 && unreachable && c->c2.tls_multi - && !tls_initial_packet_received(c->c2.tls_multi) && c->options= .mode =3D=3D MODE_POINT_TO_POINT) + && !tls_initial_packet_received(c->c2.tls_multi) + && c->options.mode =3D=3D MODE_POINT_TO_POINT) { msg(M_INFO, "Network unreachable, restarting"); register_signal(c->sig, SIGUSR1, "network-unreachable"); @@ -1872,8 +1843,7 @@ if (c->c2.to_link.len > 0) { msg(D_LINK_ERRORS, "TCP/UDP packet too large on write to %s (t= ried=3D%d,max=3D%d)", - print_link_socket_actual(c->c2.to_link_addr, &gc), - c->c2.to_link.len, + print_link_socket_actual(c->c2.to_link_addr, &gc), c->c2.t= o_link.len, c->c2.frame.buf.payload_size); } } @@ -1906,8 +1876,8 @@ * The --mssfix option requires * us to examine the IP header (IPv4 or IPv6). */ - process_ip_header(c, PIP_MSSFIX|PIPV4_EXTRACT_DHCP_ROUTER|PIPV4_CLIENT= _NAT|PIP_OUTGOING, &c->c2.to_tun, - in_sock); + process_ip_header(c, PIP_MSSFIX | PIPV4_EXTRACT_DHCP_ROUTER | PIPV4_CL= IENT_NAT | PIP_OUTGOING, + &c->c2.to_tun, in_sock); if (c->c2.to_tun.len <=3D c->c2.frame.buf.payload_size) { @@ -1925,11 +1895,8 @@ dmsg(D_TUN_RW, "TUN WRITE [%d]", BLEN(&c->c2.to_tun)); #ifdef PACKET_TRUNCATION_CHECK - ipv4_packet_size_verify(BPTR(&c->c2.to_tun), - BLEN(&c->c2.to_tun), - TUNNEL_TYPE(c->c1.tuntap), - "WRITE_TUN", - &c->c2.n_trunc_tun_write); + ipv4_packet_size_verify(BPTR(&c->c2.to_tun), BLEN(&c->c2.to_tun), = TUNNEL_TYPE(c->c1.tuntap), + "WRITE_TUN", &c->c2.n_trunc_tun_write); #endif #ifdef _WIN32 @@ -1959,9 +1926,7 @@ { msg(D_LINK_ERRORS, "TUN/TAP packet was destructively fragmented on write = to %s (tried=3D%d,actual=3D%d)", - c->c1.tuntap->actual_name, - BLEN(&c->c2.to_tun), - size); + c->c1.tuntap->actual_name, BLEN(&c->c2.to_tun), size); } /* indicate activity regarding --inactive parameter */ @@ -1974,8 +1939,7 @@ * This should never happen, probably indicates some kind * of MTU mismatch. */ - msg(D_LINK_ERRORS, "tun packet too large on write (tried=3D%d,max= =3D%d)", - c->c2.to_tun.len, + msg(D_LINK_ERRORS, "tun packet too large on write (tried=3D%d,max= =3D%d)", c->c2.to_tun.len, c->c2.frame.buf.payload_size); } @@ -2051,9 +2015,8 @@ } static void -multi_io_process_flags(struct context *c, struct event_set *es, - const unsigned int flags, unsigned int *out_socket, - unsigned int *out_tuntap) +multi_io_process_flags(struct context *c, struct event_set *es, const unsi= gned int flags, + unsigned int *out_socket, unsigned int *out_tuntap) { unsigned int socket =3D 0; unsigned int tuntap =3D 0; @@ -2144,8 +2107,7 @@ */ for (int i =3D 0; i < c->c1.link_sockets_num; i++) { - socket_set(c->c2.link_sockets[i], es, socket, - &c->c2.link_sockets[i]->ev_arg, NULL); + socket_set(c->c2.link_sockets[i], es, socket, &c->c2.link_sockets[= i]->ev_arg, NULL); } tun_set(c->c1.tuntap, es, tuntap, (void *)tun_shift, NULL); @@ -2159,7 +2121,6 @@ { *out_tuntap =3D tuntap; } - } /* @@ -2210,15 +2171,16 @@ struct event_set_return esr[4]; /* These shifts all depend on EVENT_READ and EVENT_WRITE */ - static uintptr_t socket_shift =3D SOCKET_SHIFT; /* depends on SOCKET= _READ and SOCKET_WRITE */ + static uintptr_t socket_shift =3D SOCKET_SHIFT; /* depends on SOCKET_R= EAD and SOCKET_WRITE */ #ifdef ENABLE_MANAGEMENT - static uintptr_t management_shift =3D MANAGEMENT_SHIFT; /* depends on = MANAGEMENT_READ and MANAGEMENT_WRITE */ + static uintptr_t management_shift =3D + MANAGEMENT_SHIFT; /* depends on MANAGEMENT_READ and MANAGEMENT_WRI= TE */ #endif #ifdef ENABLE_ASYNC_PUSH static uintptr_t file_shift =3D FILE_SHIFT; #endif #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) - static uintptr_t dco_shift =3D DCO_SHIFT; /* Event from DCO linux k= ernel module */ + static uintptr_t dco_shift =3D DCO_SHIFT; /* Event from DCO linux kern= el module */ #endif /* @@ -2297,8 +2259,7 @@ if (ev_arg->type !=3D EVENT_ARG_LINK_SOCKET) { c->c2.event_set_status =3D ES_ERROR; - msg(D_LINK_ERRORS, - "io_work: non socket event delivered"); + msg(D_LINK_ERRORS, "io_work: non socket event = delivered"); return; } @@ -2341,7 +2302,7 @@ const unsigned int status =3D c->c2.event_set_status; #ifdef ENABLE_MANAGEMENT - if (status & (MANAGEMENT_READ|MANAGEMENT_WRITE)) + if (status & (MANAGEMENT_READ | MANAGEMENT_WRITE)) { ASSERT(management); management_io(management); diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h index 318691f..e527d67 100644 --- a/src/openvpn/forward.h +++ b/src/openvpn/forward.h @@ -35,9 +35,9 @@ * file */ -#define TUN_OUT(c) (BLEN(&(c)->c2.to_tun) > 0) -#define LINK_OUT(c) (BLEN(&(c)->c2.to_link) > 0) -#define ANY_OUT(c) (TUN_OUT(c) || LINK_OUT(c)) +#define TUN_OUT(c) (BLEN(&(c)->c2.to_tun) > 0) +#define LINK_OUT(c) (BLEN(&(c)->c2.to_link) > 0) +#define ANY_OUT(c) (TUN_OUT(c) || LINK_OUT(c)) #ifdef ENABLE_FRAGMENT #define TO_LINK_FRAG(c) ((c)->c2.fragment && fragment_outgoing_defined((c)= ->c2.fragment)) @@ -45,31 +45,32 @@ #define TO_LINK_FRAG(c) (false) #endif -#define TO_LINK_DEF(c) (LINK_OUT(c) || TO_LINK_FRAG(c)) +#define TO_LINK_DEF(c) (LINK_OUT(c) || TO_LINK_FRAG(c)) #include "openvpn.h" #include "occ.h" #include "ping.h" #include "multi_io.h" -#define IOW_TO_TUN (1<<0) -#define IOW_TO_LINK (1<<1) -#define IOW_READ_TUN (1<<2) -#define IOW_READ_LINK (1<<3) -#define IOW_SHAPER (1<<4) -#define IOW_CHECK_RESIDUAL (1<<5) -#define IOW_FRAG (1<<6) -#define IOW_MBUF (1<<7) -#define IOW_READ_TUN_FORCE (1<<8) -#define IOW_WAIT_SIGNAL (1<<9) +#define IOW_TO_TUN (1 << 0) +#define IOW_TO_LINK (1 << 1) +#define IOW_READ_TUN (1 << 2) +#define IOW_READ_LINK (1 << 3) +#define IOW_SHAPER (1 << 4) +#define IOW_CHECK_RESIDUAL (1 << 5) +#define IOW_FRAG (1 << 6) +#define IOW_MBUF (1 << 7) +#define IOW_READ_TUN_FORCE (1 << 8) +#define IOW_WAIT_SIGNAL (1 << 9) -#define IOW_READ (IOW_READ_TUN|IOW_READ_LINK) +#define IOW_READ (IOW_READ_TUN | IOW_READ_LINK) extern counter_type link_read_bytes_global; extern counter_type link_write_bytes_global; -void get_io_flags_dowork_udp(struct context *c, struct multi_io *multi_io,= const unsigned int flags); +void get_io_flags_dowork_udp(struct context *c, struct multi_io *multi_io, + const unsigned int flags); void get_io_flags_udp(struct context *c, struct multi_io *multi_io, const = unsigned int flags); @@ -193,7 +194,8 @@ * @param orig_buf - Pointer to a buffer data. * */ -void process_incoming_link_part2(struct context *c, struct link_socket_inf= o *lsi, const uint8_t *orig_buf); +void process_incoming_link_part2(struct context *c, struct link_socket_inf= o *lsi, + const uint8_t *orig_buf); /** * Write a packet to the external network interface. @@ -271,8 +273,7 @@ * @param str - The message to be sent * @param msglevel - Message level to use for logging */ -bool -send_control_channel_string(struct context *c, const char *str, int msglev= el); +bool send_control_channel_string(struct context *c, const char *str, int m= sglevel); /* * Send a string to remote over the TLS control channel. @@ -290,9 +291,7 @@ * @param msglevel - Message level to use for logging */ -bool -send_control_channel_string_dowork(struct tls_session *session, - const char *str, int msglevel); +bool send_control_channel_string_dowork(struct tls_session *session, const= char *str, int msglevel); /** @@ -303,13 +302,13 @@ */ void reschedule_multi_process(struct context *c); -#define PIPV4_PASSTOS (1<<0) -#define PIP_MSSFIX (1<<1) /* v4 and v6 */ -#define PIP_OUTGOING (1<<2) -#define PIPV4_EXTRACT_DHCP_ROUTER (1<<3) -#define PIPV4_CLIENT_NAT (1<<4) -#define PIPV6_ICMP_NOHOST_CLIENT (1<<5) -#define PIPV6_ICMP_NOHOST_SERVER (1<<6) +#define PIPV4_PASSTOS (1 << 0) +#define PIP_MSSFIX (1 << 1) /* v4 and v6 */ +#define PIP_OUTGOING (1 << 2) +#define PIPV4_EXTRACT_DHCP_ROUTER (1 << 3) +#define PIPV4_CLIENT_NAT (1 << 4) +#define PIPV6_ICMP_NOHOST_CLIENT (1 << 5) +#define PIPV6_ICMP_NOHOST_SERVER (1 << 6) void process_ip_header(struct context *c, unsigned int flags, struct buffe= r *buf, @@ -351,7 +350,7 @@ static inline unsigned int p2p_iow_flags(const struct context *c) { - unsigned int flags =3D (IOW_SHAPER|IOW_CHECK_RESIDUAL|IOW_FRAG|IOW_REA= D|IOW_WAIT_SIGNAL); + unsigned int flags =3D (IOW_SHAPER | IOW_CHECK_RESIDUAL | IOW_FRAG | I= OW_READ | IOW_WAIT_SIGNAL); if (c->c2.to_link.len > 0) { flags |=3D IOW_TO_LINK; @@ -370,8 +369,8 @@ static inline void io_wait(struct context *c, const unsigned int flags) { - if (proto_is_dgram(c->c2.link_sockets[0]->info.proto) - && c->c2.fast_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF))) + if (proto_is_dgram(c->c2.link_sockets[0]->info.proto) && c->c2.fast_io + && (flags & (IOW_TO_TUN | IOW_TO_LINK | IOW_MBUF))) { /* fast path -- only for TUN/TAP/UDP writes */ unsigned int ret =3D 0; @@ -379,7 +378,7 @@ { ret |=3D TUN_WRITE; } - if (flags & (IOW_TO_LINK|IOW_MBUF)) + if (flags & (IOW_TO_LINK | IOW_MBUF)) { ret |=3D SOCKET_WRITE; } diff --git a/src/openvpn/fragment.c b/src/openvpn/fragment.c index 287eb9b..c121aae 100644 --- a/src/openvpn/fragment.c +++ b/src/openvpn/fragment.c @@ -35,7 +35,11 @@ #include "integer.h" #include "memdbg.h" -#define FRAG_ERR(s) { errmsg =3D s; goto error; } +#define FRAG_ERR(s) \ + { \ + errmsg =3D s; \ + goto error; \ + } static void fragment_list_buf_init(struct fragment_list *list, const struct frame *fra= me) @@ -133,8 +137,7 @@ * If a fragment fully completes the datagram, return the datagram. */ void -fragment_incoming(struct fragment_master *f, struct buffer *buf, - const struct frame *frame) +fragment_incoming(struct fragment_master *f, struct buffer *buf, const str= uct frame *frame) { const char *errmsg =3D NULL; fragment_header_type flags =3D 0; @@ -165,11 +168,8 @@ /* handle the fragment type */ if (frag_type =3D=3D FRAG_WHOLE) { - dmsg(D_FRAG_DEBUG, - "FRAG_IN buf->len=3D%d type=3DFRAG_WHOLE flags=3D" - fragment_header_format, - buf->len, - flags); + dmsg(D_FRAG_DEBUG, "FRAG_IN buf->len=3D%d type=3DFRAG_WHOLE fl= ags=3D" fragment_header_format, + buf->len, flags); if (flags & (FRAG_SEQ_ID_MASK | FRAG_ID_MASK)) { @@ -180,22 +180,18 @@ { const int seq_id =3D ((flags >> FRAG_SEQ_ID_SHIFT) & FRAG_SEQ_= ID_MASK); const int n =3D ((flags >> FRAG_ID_SHIFT) & FRAG_ID_MASK); - const int size =3D ((frag_type =3D=3D FRAG_YES_LAST) - ? (int)(((flags >> FRAG_SIZE_SHIFT) & FRAG_S= IZE_MASK) << FRAG_SIZE_ROUND_SHIFT) - : buf->len); + const int size =3D + ((frag_type =3D=3D FRAG_YES_LAST) + ? (int)(((flags >> FRAG_SIZE_SHIFT) & FRAG_SIZE_MASK)= << FRAG_SIZE_ROUND_SHIFT) + : buf->len); /* get the appropriate fragment buffer based on received seq_i= d */ struct fragment *frag =3D fragment_list_get_buf(&f->incoming, = seq_id); - dmsg(D_FRAG_DEBUG, - "FRAG_IN len=3D%d type=3D%d seq_id=3D%d frag_id=3D%d size= =3D%d flags=3D" - fragment_header_format, - buf->len, - frag_type, - seq_id, - n, - size, - flags); + dmsg( + D_FRAG_DEBUG, + "FRAG_IN len=3D%d type=3D%d seq_id=3D%d frag_id=3D%d size= =3D%d flags=3D" fragment_header_format, + buf->len, frag_type, seq_id, n, size, flags); /* make sure that size is an even multiple of 1<len, type, seq_id, frag_id, frag_size, flags); + dmsg( + D_FRAG_DEBUG, + "FRAG_OUT len=3D%d type=3D%d seq_id=3D%d frag_id=3D%d frag_siz= e=3D%d flags=3D" fragment_header_format, + buf->len, type, seq_id, frag_id, frag_size, flags); } else { flags |=3D (((frag_size >> FRAG_SIZE_ROUND_SHIFT) & FRAG_SIZE_MASK= ) << FRAG_SIZE_SHIFT); - dmsg(D_FRAG_DEBUG, - "FRAG_OUT len=3D%d type=3D%d seq_id=3D%d frag_id=3D%d frag_si= ze=3D%d flags=3D" - fragment_header_format, - buf->len, type, seq_id, frag_id, frag_size, flags); + dmsg( + D_FRAG_DEBUG, + "FRAG_OUT len=3D%d type=3D%d seq_id=3D%d frag_id=3D%d frag_siz= e=3D%d flags=3D" fragment_header_format, + buf->len, type, seq_id, frag_id, frag_size, flags); } flags =3D hton_fragment_header_type(flags); @@ -307,8 +299,9 @@ if (div > 0 && mod > 0 && mod < mfs_aligned * 3 / 4) { - return min_int(mfs_aligned, (max_frag_size - ((max_frag_size - mod= ) / (div + 1)) - + FRAG_SIZE_ROUND_MASK) & ~FRAG_SIZE_= ROUND_MASK); + return min_int(mfs_aligned, + (max_frag_size - ((max_frag_size - mod) / (div + 1)= ) + FRAG_SIZE_ROUND_MASK) + & ~FRAG_SIZE_ROUND_MASK); } else { @@ -318,8 +311,7 @@ /* process an outgoing datagram, possibly breaking it up into fragments */ void -fragment_outgoing(struct fragment_master *f, struct buffer *buf, - const struct frame *frame) +fragment_outgoing(struct fragment_master *f, struct buffer *buf, const str= uct frame *frame) { const char *errmsg =3D NULL; if (buf->len > 0) @@ -327,8 +319,8 @@ /* The outgoing buffer should be empty so we can put new data in i= t */ if (f->outgoing.len) { - msg(D_FRAG_ERRORS, "FRAG: outgoing buffer is not empty, len=3D= [%d,%d]", - buf->len, f->outgoing.len); + msg(D_FRAG_ERRORS, "FRAG: outgoing buffer is not empty, len=3D= [%d,%d]", buf->len, + f->outgoing.len); } if (buf->len > frame->max_fragment_size) /* should we fragment? */ { @@ -352,11 +344,7 @@ /* * Send the datagram whole. */ - fragment_prepend_flags(buf, - FRAG_WHOLE, - 0, - 0, - 0); + fragment_prepend_flags(buf, FRAG_WHOLE, 0, 0, 0); } } return; @@ -364,8 +352,8 @@ error: if (errmsg) { - msg(D_FRAG_ERRORS, "FRAG_OUT error, len=3D%d frag_size=3D%d MAX_FR= AGS=3D%d: %s", - buf->len, f->outgoing_frag_size, MAX_FRAGS, errmsg); + msg(D_FRAG_ERRORS, "FRAG_OUT error, len=3D%d frag_size=3D%d MAX_FR= AGS=3D%d: %s", buf->len, + f->outgoing_frag_size, MAX_FRAGS, errmsg); } buf->len =3D 0; return; @@ -373,8 +361,7 @@ /* return true (and set buf) if we have an outgoing fragment which is read= y to send */ bool -fragment_ready_to_send(struct fragment_master *f, struct buffer *buf, - const struct frame *frame) +fragment_ready_to_send(struct fragment_master *f, struct buffer *buf, cons= t struct frame *frame) { if (fragment_outgoing_defined(f)) { @@ -393,13 +380,12 @@ ASSERT(buf_copy_n(buf, &f->outgoing, size)); /* fragment flags differ based on whether or not we are sending th= e last fragment */ - fragment_prepend_flags(buf, - last ? FRAG_YES_LAST : FRAG_YES_NOTLAST, - f->outgoing_seq_id, - f->outgoing_frag_id++, - f->outgoing_frag_size); + fragment_prepend_flags(buf, last ? FRAG_YES_LAST : FRAG_YES_NOTLAS= T, f->outgoing_seq_id, + f->outgoing_frag_id++, f->outgoing_frag_siz= e); - ASSERT(!last || !f->outgoing.len); /* outgoing buffer length shoul= d be zero after last fragment sent */ + ASSERT(!last + || !f->outgoing + .len); /* outgoing buffer length should be zero aft= er last fragment sent */ return true; } diff --git a/src/openvpn/fragment.h b/src/openvpn/fragment.h index cc96057..c5c8108 100644 --- a/src/openvpn/fragment.h +++ b/src/openvpn/fragment.h @@ -46,15 +46,15 @@ #include "error.h" -#define N_FRAG_BUF 25 +#define N_FRAG_BUF 25 /**< Number of packet buffers for * reassembling incoming fragmented * packets. */ -#define FRAG_TTL_SEC 10 +#define FRAG_TTL_SEC 10 /**< Time-to-live in seconds for a %fragment. */ -#define FRAG_WAKEUP_INTERVAL 5 +#define FRAG_WAKEUP_INTERVAL 5 /**< Interval in seconds between calls to * wakeup code. */ @@ -62,15 +62,16 @@ /** * Structure for reassembling one incoming fragmented packet. */ -struct fragment { - bool defined; /**< Whether reassembly is currently - * taking place in this structure. */ +struct fragment +{ + bool defined; /**< Whether reassembly is currently + * taking place in this structure. */ - int max_frag_size; /**< Maximum size of each %fragment. */ + int max_frag_size; /**< Maximum size of each %fragment. */ #define FRAG_MAP_MASK 0xFFFFFFFF /**< Mask for reassembly map. */ -#define MAX_FRAGS 32 /**< Maximum number of fragments per packe= t. */ +#define MAX_FRAGS 32 /**< Maximum number of fragments per packet. */ unsigned int map; /**< Reassembly map for recording which * fragments have been received. @@ -81,10 +82,10 @@ * n has been received. Needs to have * at least \c MAX_FRAGS bits. */ - time_t timestamp; /**< Timestamp for time-to-live purposes. = */ + time_t timestamp; /**< Timestamp for time-to-live purposes. */ - struct buffer buf; /**< Buffer in which received datagrams - * are reassembled. */ + struct buffer buf; /**< Buffer in which received datagrams + * are reassembled. */ }; @@ -136,11 +137,12 @@ * fragment_incoming() function adds newly received parts into this array * and returns the whole packets once reassembly is complete. */ -struct fragment_master { +struct fragment_master +{ struct event_timeout wakeup; /**< Timeout structure used by the main * event loop to know when to do * fragmentation housekeeping. */ -#define N_SEQ_ID 256 +#define N_SEQ_ID 256 /**< One more than the maximum fragment * sequence ID, above which the IDs wrap * to zero. Should be a power of 2. */ @@ -196,24 +198,24 @@ #define ntoh_fragment_header_type(x) ntohl(x) /**< Convert a \c fragment_header_type from network to host order. */ -#define FRAG_TYPE_MASK 0x00000003 /**< Bit mask for %fragmen= t type info. */ -#define FRAG_TYPE_SHIFT 0 /**< Bit shift for %fragme= nt type info. */ +#define FRAG_TYPE_MASK 0x00000003 /**< Bit mask for %fragment type info. = */ +#define FRAG_TYPE_SHIFT 0 /**< Bit shift for %fragment type info.= */ -#define FRAG_WHOLE 0 /**< Fragment type indicat= ing packet is whole. */ -#define FRAG_YES_NOTLAST 1 +#define FRAG_WHOLE 0 /**< Fragment type indicating packet is= whole. */ +#define FRAG_YES_NOTLAST 1 /**< Fragment type indicating packet is part of a fragmented packet, but n= ot * the last part in the sequence. */ -#define FRAG_YES_LAST 2 +#define FRAG_YES_LAST 2 /**< Fragment type indicating packet is the last part in the sequence of p= arts. */ -#define FRAG_TEST 3 +#define FRAG_TEST 3 /**< Fragment type not implemented yet. * In the future might be used as a control packet for establishing MTU si= ze. */ -#define FRAG_SEQ_ID_MASK 0x000000ff /**< Bit mask for %fragmen= t sequence ID. */ -#define FRAG_SEQ_ID_SHIFT 2 /**< Bit shift for %fragme= nt sequence ID. */ +#define FRAG_SEQ_ID_MASK 0x000000ff /**< Bit mask for %fragment sequence = ID. */ +#define FRAG_SEQ_ID_SHIFT 2 /**< Bit shift for %fragment sequence= ID. */ -#define FRAG_ID_MASK 0x0000001f /**< Bit mask for %fragmen= t ID. */ -#define FRAG_ID_SHIFT 10 /**< Bit shift for %fragme= nt ID. */ +#define FRAG_ID_MASK 0x0000001f /**< Bit mask for %fragment ID. */ +#define FRAG_ID_SHIFT 10 /**< Bit shift for %fragment ID. */ /* @@ -225,10 +227,10 @@ * max_frag_size is only sent over the wire if FRAG_LAST is set. Otherw= ise it is assumed * to be the actual %fragment size received. */ -#define FRAG_SIZE_MASK 0x00003fff /**< Bit mask for %fragmen= t size. */ -#define FRAG_SIZE_SHIFT 15 /**< Bit shift for %fragme= nt size. */ -#define FRAG_SIZE_ROUND_SHIFT 2 /**< Bit shift for %fragme= nt size rounding. */ -#define FRAG_SIZE_ROUND_MASK ((1 << FRAG_SIZE_ROUND_SHIFT) - 1) +#define FRAG_SIZE_MASK 0x00003fff /**< Bit mask for %fragment size.= */ +#define FRAG_SIZE_SHIFT 15 /**< Bit shift for %fragment size= . */ +#define FRAG_SIZE_ROUND_SHIFT 2 /**< Bit shift for %fragment size= rounding. */ +#define FRAG_SIZE_ROUND_MASK ((1 << FRAG_SIZE_ROUND_SHIFT) - 1) /**< Bit mask for %fragment size rounding. */ /* @@ -236,14 +238,14 @@ * * IF FRAG_WHOLE or FRAG_YES_NOTLAST, these 16 bits are available (not cur= rently used) */ -#define FRAG_EXTRA_MASK 0x0000ffff /**< Bit mask for extra bi= ts. */ -#define FRAG_EXTRA_SHIFT 15 /**< Bit shift for extra b= its. */ +#define FRAG_EXTRA_MASK 0x0000ffff /**< Bit mask for extra bits. */ +#define FRAG_EXTRA_SHIFT 15 /**< Bit shift for extra bits. */ -/** @} name Fragment header *//*******************************************= */ +/** @} name Fragment header */ /*************************************= *******/ /*************************************************************************= */ -/** @name Functions for initialization and cleanup *//** @{ *//***********= */ +/** @name Functions for initialization and cleanup */ /** @{ */ /*********= ***/ =20 /** * Allocate and initialize a \c fragment_master structure. @@ -279,7 +281,7 @@ */ void fragment_free(struct fragment_master *f); -/** @} name Functions for initialization and cleanup *//******************= */ +/** @} name Functions for initialization and cleanup */ /*****************= **/ /*************************************************************************= */ @@ -327,8 +329,7 @@ * complete. If an error occurs during processing, the buffer length * is also set to zero. */ -void fragment_incoming(struct fragment_master *f, struct buffer *buf, - const struct frame *frame); +void fragment_incoming(struct fragment_master *f, struct buffer *buf, cons= t struct frame *frame); /** @} name Functions for processing packets received from a VPN tunnel */ @@ -379,8 +380,7 @@ * cases a fragmentation header will have been prepended to inform the * remote peer how to handle the packet. */ -void fragment_outgoing(struct fragment_master *f, struct buffer *buf, - const struct frame *frame); +void fragment_outgoing(struct fragment_master *f, struct buffer *buf, cons= t struct frame *frame); /** * Check whether outgoing fragments are ready to be send, and if so make @@ -436,7 +436,7 @@ /*************************************************************************= */ -/** @name Functions for regular housekeeping *//** @{ *//*****************= */ +/** @name Functions for regular housekeeping */ /** @{ */ /***************= ***/ /** * Perform housekeeping of a \c fragment_master structure. @@ -460,10 +460,10 @@ } } -/** @} name Functions for regular housekeeping *//************************= */ +/** @} name Functions for regular housekeeping */ /***********************= **/ -/** @} addtogroup fragmentation *//***************************************= */ +/** @} addtogroup fragmentation */ /**************************************= **/ #endif /* ifdef ENABLE_FRAGMENT */ diff --git a/src/openvpn/gremlin.c b/src/openvpn/gremlin.c index b58defe..8bd68e5 100644 --- a/src/openvpn/gremlin.c +++ b/src/openvpn/gremlin.c @@ -65,28 +65,29 @@ * When network goes up, it will be up for between * UP_LOW and UP_HIGH seconds. */ -static const int up_low[] =3D { 60, 10, 5 }; +static const int up_low[] =3D { 60, 10, 5 }; static const int up_high[] =3D { 600, 60, 10 }; /* * When network goes down, it will be down for between * DOWN_LOW and DOWN_HIGH seconds. */ -static const int down_low[] =3D { 5, 10, 10 }; +static const int down_low[] =3D { 5, 10, 10 }; static const int down_high[] =3D { 10, 60, 120 }; /* * Packet flood levels: * { number of packets, packet size } */ -static const struct packet_flood_parms packet_flood_data[] =3D -{{10, 100}, {10, 1500}, {100, 1500}}; +static const struct packet_flood_parms packet_flood_data[] =3D { { 10, 100= }, + { 10, 1500 = }, + { 100, 1500= } }; struct packet_flood_parms get_packet_flood_parms(int level) { ASSERT(level > 0 && level < 4); - return packet_flood_data [level - 1]; + return packet_flood_data[level - 1]; } /* @@ -148,18 +149,16 @@ int delta; if (up) { - delta =3D roll(down_low[up_down_level-1], down_high[up_dow= n_level-1]); + delta =3D roll(down_low[up_down_level - 1], down_high[up_d= own_level - 1]); up =3D false; } else { - delta =3D roll(up_low[up_down_level-1], up_high[up_down_le= vel-1]); + delta =3D roll(up_low[up_down_level - 1], up_high[up_down_= level - 1]); up =3D true; } - msg(D_GREMLIN, - "GREMLIN: CONNECTION GOING %s FOR %d SECONDS", - (up ? "UP" : "DOWN"), + msg(D_GREMLIN, "GREMLIN: CONNECTION GOING %s FOR %d SECONDS", = (up ? "UP" : "DOWN"), delta); next =3D now + delta; } @@ -167,7 +166,7 @@ if (drop_level) { - if (up && flip(drop_freq[drop_level-1])) + if (up && flip(drop_freq[drop_level - 1])) { dmsg(D_GREMLIN_VERBOSE, "GREMLIN: Random packet drop"); return false; @@ -186,7 +185,7 @@ const int corrupt_level =3D GREMLIN_CORRUPT_LEVEL(flags); if (corrupt_level) { - if (flip(corrupt_freq[corrupt_level-1])) + if (flip(corrupt_freq[corrupt_level - 1])) { do { @@ -227,7 +226,7 @@ { break; } - } while (flip(2)); /* a 50% chance we will corrupt again */ + } while (flip(2)); /* a 50% chance we will corrupt again */ } } } diff --git a/src/openvpn/gremlin.h b/src/openvpn/gremlin.h index bf1cfea..a0491b4 100644 --- a/src/openvpn/gremlin.h +++ b/src/openvpn/gremlin.h @@ -30,30 +30,32 @@ * Gremlin options, presented as bitmask argument to --gremlin directive */ -#define GREMLIN_CONNECTION_FLOOD_SHIFT (0) -#define GREMLIN_CONNECTION_FLOOD_MASK (0x07) +#define GREMLIN_CONNECTION_FLOOD_SHIFT (0) +#define GREMLIN_CONNECTION_FLOOD_MASK (0x07) -#define GREMLIN_PACKET_FLOOD_SHIFT (3) -#define GREMLIN_PACKET_FLOOD_MASK (0x03) +#define GREMLIN_PACKET_FLOOD_SHIFT (3) +#define GREMLIN_PACKET_FLOOD_MASK (0x03) -#define GREMLIN_CORRUPT_SHIFT (5) -#define GREMLIN_CORRUPT_MASK (0x03) +#define GREMLIN_CORRUPT_SHIFT (5) +#define GREMLIN_CORRUPT_MASK (0x03) -#define GREMLIN_UP_DOWN_SHIFT (7) -#define GREMLIN_UP_DOWN_MASK (0x03) +#define GREMLIN_UP_DOWN_SHIFT (7) +#define GREMLIN_UP_DOWN_MASK (0x03) /* 512:1/500 1024:1/100 1536:1/50 */ -#define GREMLIN_DROP_SHIFT (9) -#define GREMLIN_DROP_MASK (0x03) +#define GREMLIN_DROP_SHIFT (9) +#define GREMLIN_DROP_MASK (0x03) /* extract gremlin parms */ -#define GREMLIN_CONNECTION_FLOOD_LEVEL(x) (((x)>>GREMLIN_CONNECTION_FLOOD_= SHIFT) & GREMLIN_CONNECTION_FLOOD_MASK) -#define GREMLIN_PACKET_FLOOD_LEVEL(x) (((x)>>GREMLIN_PACKET_FLOOD_SHIF= T) & GREMLIN_PACKET_FLOOD_MASK) -#define GREMLIN_CORRUPT_LEVEL(x) (((x)>>GREMLIN_CORRUPT_SHIFT) = & GREMLIN_CORRUPT_MASK) -#define GREMLIN_UP_DOWN_LEVEL(x) (((x)>>GREMLIN_UP_DOWN_SHIFT) = & GREMLIN_UP_DOWN_MASK) -#define GREMLIN_DROP_LEVEL(x) (((x)>>GREMLIN_DROP_SHIFT) = & GREMLIN_DROP_MASK) +#define GREMLIN_CONNECTION_FLOOD_LEVEL(x) \ + (((x) >> GREMLIN_CONNECTION_FLOOD_SHIFT) & GREMLIN_CONNECTION_FLOOD_MA= SK) +#define GREMLIN_PACKET_FLOOD_LEVEL(x) \ + (((x) >> GREMLIN_PACKET_FLOOD_SHIFT) & GREMLIN_PACKET_FLOOD_MASK) +#define GREMLIN_CORRUPT_LEVEL(x) (((x) >> GREMLIN_CORRUPT_SHIFT) & GREMLIN= _CORRUPT_MASK) +#define GREMLIN_UP_DOWN_LEVEL(x) (((x) >> GREMLIN_UP_DOWN_SHIFT) & GREMLIN= _UP_DOWN_MASK) +#define GREMLIN_DROP_LEVEL(x) (((x) >> GREMLIN_DROP_SHIFT) & GREMLIN_DR= OP_MASK) #include "buffer.h" diff --git a/src/openvpn/helper.c b/src/openvpn/helper.c index 7cef9db..6ddffbe 100644 --- a/src/openvpn/helper.c +++ b/src/openvpn/helper.c @@ -71,14 +71,12 @@ if (netmask) { - buf_printf(&out, "route %s %s", - print_in_addr_t(network, 0, gc), + buf_printf(&out, "route %s %s", print_in_addr_t(network, 0, gc), print_in_addr_t(netmask, 0, gc)); } else { - buf_printf(&out, "route %s", - print_in_addr_t(network, 0, gc)); + buf_printf(&out, "route %s", print_in_addr_t(network, 0, gc)); } return BSTR(&out); @@ -114,11 +112,8 @@ helper_add_route(const in_addr_t network, const in_addr_t netmask, struct = options *o) { rol_check_alloc(o); - add_route_to_option_list(o->routes, - print_in_addr_t(network, 0, &o->gc), - print_in_addr_t(netmask, 0, &o->gc), - NULL, - NULL, + add_route_to_option_list(o->routes, print_in_addr_t(network, 0, &o->gc= ), + print_in_addr_t(netmask, 0, &o->gc), NULL, NU= LL, o->route_default_table_id); } @@ -128,10 +123,8 @@ struct gc_arena gc =3D gc_new(); if ((a & subnet) !=3D (b & subnet)) { - msg(M_USAGE, "%s IP addresses %s and %s are not in the same %s sub= net", - opt, - print_in_addr_t(a, 0, &gc), - print_in_addr_t(b, 0, &gc), + msg(M_USAGE, "%s IP addresses %s and %s are not in the same %s sub= net", opt, + print_in_addr_t(a, 0, &gc), print_in_addr_t(b, 0, &gc), print_in_addr_t(subnet, 0, &gc)); } gc_free(&gc); @@ -207,17 +200,17 @@ } if (o->ifconfig_ipv6_pool_defined) { - msg(M_USAGE, "--server-ipv6 already defines an ifconfig-ipv6-p= ool, so you can't also specify --ifconfig-pool explicitly"); + msg(M_USAGE, + "--server-ipv6 already defines an ifconfig-ipv6-pool, so y= ou can't also specify --ifconfig-pool explicitly"); } o->mode =3D MODE_SERVER; o->tls_server =3D true; /* local ifconfig is "base address + 1" and "+2" */ - o->ifconfig_ipv6_local =3D - print_in6_addr( add_in6_addr( o->server_network_ipv6, 1), 0, &= o->gc ); + o->ifconfig_ipv6_local =3D print_in6_addr(add_in6_addr(o->server_n= etwork_ipv6, 1), 0, &o->gc); o->ifconfig_ipv6_remote =3D - print_in6_addr( add_in6_addr( o->server_network_ipv6, 2), 0, &= o->gc ); + print_in6_addr(add_in6_addr(o->server_network_ipv6, 2), 0, &o-= >gc); o->ifconfig_ipv6_netbits =3D o->server_netbits_ipv6; /* basic sanity check */ @@ -229,8 +222,8 @@ * * Smaller pools can't get that far, therefore we just increase by= 2 */ - o->ifconfig_ipv6_pool_base =3D add_in6_addr(o->server_network_ipv6, - o->server_netbits_ipv6 <= 112 ? 0x1000 : 2); + o->ifconfig_ipv6_pool_base =3D + add_in6_addr(o->server_network_ipv6, o->server_netbits_ipv6 < = 112 ? 0x1000 : 2); o->ifconfig_ipv6_pool_netbits =3D o->server_netbits_ipv6; push_option(o, "tun-ipv6", M_USAGE); @@ -284,12 +277,14 @@ if (o->shared_secret_file) { - msg(M_USAGE, "--server and --secret cannot be used together (y= ou must use SSL/TLS keys)"); + msg(M_USAGE, + "--server and --secret cannot be used together (you must u= se SSL/TLS keys)"); } if (!(o->server_flags & SF_NOPOOL) && o->ifconfig_pool_defined) { - msg(M_USAGE, "--server already defines an ifconfig-pool, so yo= u can't also specify --ifconfig-pool explicitly"); + msg(M_USAGE, + "--server already defines an ifconfig-pool, so you can't a= lso specify --ifconfig-pool explicitly"); } if (!(dev =3D=3D DEV_TYPE_TAP || dev =3D=3D DEV_TYPE_TUN)) @@ -310,7 +305,8 @@ if (netbits < IFCONFIG_POOL_MIN_NETBITS) { - msg(M_USAGE, "--server directive netmask allows for too many h= ost addresses (subnet must be %s or higher)", + msg(M_USAGE, + "--server directive netmask allows for too many host addre= sses (subnet must be %s or higher)", print_netmask(IFCONFIG_POOL_MIN_NETBITS, &gc)); } @@ -320,7 +316,8 @@ if (netbits > 29) { - msg(M_USAGE, "--server directive when used with --dev tun = must define a subnet of %s or lower", + msg(M_USAGE, + "--server directive when used with --dev tun must defi= ne a subnet of %s or lower", print_netmask(29, &gc)); } @@ -343,14 +340,17 @@ { o->ifconfig_pool_defined =3D true; o->ifconfig_pool_start =3D o->server_network + 4; - o->ifconfig_pool_end =3D (o->server_network | ~o->serv= er_netmask) - pool_end_reserve; - ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_s= tart, o->ifconfig_pool_end); + o->ifconfig_pool_end =3D + (o->server_network | ~o->server_netmask) - pool_en= d_reserve; + ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_s= tart, + o->ifconfig_pool_end); } helper_add_route(o->server_network, o->server_netmask, o); if (o->enable_c2c) { - push_option(o, print_opt_route(o->server_network, o->s= erver_netmask, &o->gc), M_USAGE); + push_option(o, print_opt_route(o->server_network, o->s= erver_netmask, &o->gc), + M_USAGE); } else if (o->topology =3D=3D TOP_NET30) { @@ -367,7 +367,8 @@ o->ifconfig_pool_defined =3D true; o->ifconfig_pool_start =3D o->server_network + 2; o->ifconfig_pool_end =3D (o->server_network | ~o->serv= er_netmask) - 1; - ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_s= tart, o->ifconfig_pool_end); + ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_s= tart, + o->ifconfig_pool_end); } o->ifconfig_pool_netmask =3D o->server_netmask; @@ -387,16 +388,17 @@ if (o->topology =3D=3D TOP_NET30 && !(o->server_flags & SF_NOP= OOL)) { msg(M_WARN, "WARNING: --topology net30 support for server " - "configs with IPv4 pools will be removed in a future " - "release. Please migrate to --topology subnet as soon " - "as possible."); + "configs with IPv4 pools will be removed in a = future " + "release. Please migrate to --topology subnet = as soon " + "as possible."); } } else if (dev =3D=3D DEV_TYPE_TAP) { if (netbits > 30) { - msg(M_USAGE, "--server directive when used with --dev tap = must define a subnet of %s or lower", + msg(M_USAGE, + "--server directive when used with --dev tap must defi= ne a subnet of %s or lower", print_netmask(30, &gc)); } @@ -464,12 +466,14 @@ if (!(o->server_flags & SF_NOPOOL) && o->ifconfig_pool_defined) { - msg(M_USAGE, "--server-bridge already defines an ifconfig-pool= , so you can't also specify --ifconfig-pool explicitly"); + msg(M_USAGE, + "--server-bridge already defines an ifconfig-pool, so you = can't also specify --ifconfig-pool explicitly"); } if (o->shared_secret_file) { - msg(M_USAGE, "--server-bridge and --secret cannot be used toge= ther (you must use SSL/TLS keys)"); + msg(M_USAGE, + "--server-bridge and --secret cannot be used together (you= must use SSL/TLS keys)"); } if (dev !=3D DEV_TYPE_TAP) @@ -479,9 +483,12 @@ if (o->server_bridge_defined) { - verify_common_subnet("--server-bridge", o->server_bridge_ip, o= ->server_bridge_pool_start, o->server_bridge_netmask); - verify_common_subnet("--server-bridge", o->server_bridge_pool_= start, o->server_bridge_pool_end, o->server_bridge_netmask); - verify_common_subnet("--server-bridge", o->server_bridge_ip, o= ->server_bridge_pool_end, o->server_bridge_netmask); + verify_common_subnet("--server-bridge", o->server_bridge_ip, + o->server_bridge_pool_start, o->server_br= idge_netmask); + verify_common_subnet("--server-bridge", o->server_bridge_pool_= start, + o->server_bridge_pool_end, o->server_brid= ge_netmask); + verify_common_subnet("--server-bridge", o->server_bridge_ip, o= ->server_bridge_pool_end, + o->server_bridge_netmask); } o->mode =3D MODE_SERVER; @@ -552,13 +559,14 @@ } if (o->keepalive_ping * 2 > o->keepalive_timeout) { - msg(M_USAGE, "the second parameter to --keepalive (restart tim= eout=3D%d) must be at least twice the value of the first parameter (ping in= terval=3D%d). A ratio of 1:5 or 1:6 would be even better. Recommended set= ting is --keepalive 10 60.", - o->keepalive_timeout, - o->keepalive_ping); + msg(M_USAGE, + "the second parameter to --keepalive (restart timeout=3D%d= ) must be at least twice the value of the first parameter (ping interval=3D= %d). A ratio of 1:5 or 1:6 would be even better. Recommended setting is -= -keepalive 10 60.", + o->keepalive_timeout, o->keepalive_ping); } if (o->ping_send_timeout || o->ping_rec_timeout) { - msg(M_USAGE, "--keepalive conflicts with --ping, --ping-exit, = or --ping-restart. If you use --keepalive, you don't need any of the other= --ping directives."); + msg(M_USAGE, + "--keepalive conflicts with --ping, --ping-exit, or --ping= -restart. If you use --keepalive, you don't need any of the other --ping d= irectives."); } /* diff --git a/src/openvpn/httpdigest.c b/src/openvpn/httpdigest.c index 8665402..a907d32 100644 --- a/src/openvpn/httpdigest.c +++ b/src/openvpn/httpdigest.c @@ -33,10 +33,7 @@ #include "httpdigest.h" static void -CvtHex( - IN HASH Bin, - OUT HASHHEX Hex - ) +CvtHex(IN HASH Bin, OUT HASHHEX Hex) { unsigned short i; unsigned char j; @@ -46,20 +43,20 @@ j =3D (Bin[i] >> 4) & 0xf; if (j <=3D 9) { - Hex[i*2] =3D (j + '0'); + Hex[i * 2] =3D (j + '0'); } else { - Hex[i*2] =3D (j + 'a' - 10); + Hex[i * 2] =3D (j + 'a' - 10); } j =3D Bin[i] & 0xf; if (j <=3D 9) { - Hex[i*2+1] =3D (j + '0'); + Hex[i * 2 + 1] =3D (j + '0'); } else { - Hex[i*2+1] =3D (j + 'a' - 10); + Hex[i * 2 + 1] =3D (j + 'a' - 10); } } Hex[HASHHEXLEN] =3D '\0'; @@ -67,34 +64,27 @@ /* calculate H(A1) as per spec */ void -DigestCalcHA1( - IN char *pszAlg, - IN char *pszUserName, - IN char *pszRealm, - IN char *pszPassword, - IN char *pszNonce, - IN char *pszCNonce, - OUT HASHHEX SessionKey - ) +DigestCalcHA1(IN char *pszAlg, IN char *pszUserName, IN char *pszRealm, IN= char *pszPassword, + IN char *pszNonce, IN char *pszCNonce, OUT HASHHEX SessionKe= y) { HASH HA1; md_ctx_t *md5_ctx =3D md_ctx_new(); md_ctx_init(md5_ctx, "MD5"); - md_ctx_update(md5_ctx, (const uint8_t *) pszUserName, strlen(pszUserNa= me)); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); - md_ctx_update(md5_ctx, (const uint8_t *) pszRealm, strlen(pszRealm)); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); - md_ctx_update(md5_ctx, (const uint8_t *) pszPassword, strlen(pszPasswo= rd)); + md_ctx_update(md5_ctx, (const uint8_t *)pszUserName, strlen(pszUserNam= e)); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)pszRealm, strlen(pszRealm)); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)pszPassword, strlen(pszPasswor= d)); md_ctx_final(md5_ctx, HA1); if (pszAlg && strcasecmp(pszAlg, "md5-sess") =3D=3D 0) { md_ctx_init(md5_ctx, "MD5"); md_ctx_update(md5_ctx, HA1, HASHLEN); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); - md_ctx_update(md5_ctx, (const uint8_t *) pszNonce, strlen(pszNonce= )); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); - md_ctx_update(md5_ctx, (const uint8_t *) pszCNonce, strlen(pszCNon= ce)); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)pszNonce, strlen(pszNonce)= ); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)pszCNonce, strlen(pszCNonc= e)); md_ctx_final(md5_ctx, HA1); } md_ctx_cleanup(md5_ctx); @@ -104,17 +94,16 @@ /* calculate request-digest/response-digest as per HTTP Digest spec */ void -DigestCalcResponse( - IN HASHHEX HA1, /* H(A1) */ - IN char *pszNonce, /* nonce from server */ - IN char *pszNonceCount, /* 8 hex digits */ - IN char *pszCNonce, /* client nonce */ - IN char *pszQop, /* qop-value: "", "auth", "au= th-int" */ - IN char *pszMethod, /* method from the request */ - IN char *pszDigestUri, /* requested URL */ - IN HASHHEX HEntity, /* H(entity body) if qop=3D"a= uth-int" */ - OUT HASHHEX Response /* request-digest or response= -digest */ - ) +DigestCalcResponse(IN HASHHEX HA1, /* H(A1) */ + IN char *pszNonce, /* nonce from server */ + IN char *pszNonceCount, /* 8 hex digits */ + IN char *pszCNonce, /* client nonce */ + IN char *pszQop, /* qop-value: "", "auth", "auth= -int" */ + IN char *pszMethod, /* method from the request */ + IN char *pszDigestUri, /* requested URL */ + IN HASHHEX HEntity, /* H(entity body) if qop=3D"aut= h-int" */ + OUT HASHHEX Response /* request-digest or response-d= igest */ +) { HASH HA2; HASH RespHash; @@ -124,12 +113,12 @@ /* calculate H(A2) */ md_ctx_init(md5_ctx, "MD5"); - md_ctx_update(md5_ctx, (const uint8_t *) pszMethod, strlen(pszMethod)); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); - md_ctx_update(md5_ctx, (const uint8_t *) pszDigestUri, strlen(pszDiges= tUri)); + md_ctx_update(md5_ctx, (const uint8_t *)pszMethod, strlen(pszMethod)); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)pszDigestUri, strlen(pszDigest= Uri)); if (strcasecmp(pszQop, "auth-int") =3D=3D 0) { - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); md_ctx_update(md5_ctx, HEntity, HASHHEXLEN); } md_ctx_final(md5_ctx, HA2); @@ -138,17 +127,17 @@ /* calculate response */ md_ctx_init(md5_ctx, "MD5"); md_ctx_update(md5_ctx, HA1, HASHHEXLEN); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); - md_ctx_update(md5_ctx, (const uint8_t *) pszNonce, strlen(pszNonce)); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)pszNonce, strlen(pszNonce)); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); if (*pszQop) { - md_ctx_update(md5_ctx, (const uint8_t *) pszNonceCount, strlen(psz= NonceCount)); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); - md_ctx_update(md5_ctx, (const uint8_t *) pszCNonce, strlen(pszCNon= ce)); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); - md_ctx_update(md5_ctx, (const uint8_t *) pszQop, strlen(pszQop)); - md_ctx_update(md5_ctx, (const uint8_t *) ":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)pszNonceCount, strlen(pszN= onceCount)); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)pszCNonce, strlen(pszCNonc= e)); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); + md_ctx_update(md5_ctx, (const uint8_t *)pszQop, strlen(pszQop)); + md_ctx_update(md5_ctx, (const uint8_t *)":", 1); } md_ctx_update(md5_ctx, HA2Hex, HASHHEXLEN); md_ctx_final(md5_ctx, RespHash); diff --git a/src/openvpn/httpdigest.h b/src/openvpn/httpdigest.h index 50cf451..1d1bc49 100644 --- a/src/openvpn/httpdigest.h +++ b/src/openvpn/httpdigest.h @@ -26,34 +26,26 @@ #define HASHLEN 16 typedef unsigned char HASH[HASHLEN]; #define HASHHEXLEN 32 -typedef unsigned char HASHHEX[HASHHEXLEN+1]; +typedef unsigned char HASHHEX[HASHHEXLEN + 1]; #undef IN #undef OUT #define IN const #define OUT /* calculate H(A1) as per HTTP Digest spec */ -void DigestCalcHA1( - IN char *pszAlg, - IN char *pszUserName, - IN char *pszRealm, - IN char *pszPassword, - IN char *pszNonce, - IN char *pszCNonce, - OUT HASHHEX SessionKey - ); +void DigestCalcHA1(IN char *pszAlg, IN char *pszUserName, IN char *pszReal= m, IN char *pszPassword, + IN char *pszNonce, IN char *pszCNonce, OUT HASHHEX Sess= ionKey); /* calculate request-digest/response-digest as per HTTP Digest spec */ -void DigestCalcResponse( - IN HASHHEX HA1, /* H(A1) */ - IN char *pszNonce, /* nonce from server */ - IN char *pszNonceCount, /* 8 hex digits */ - IN char *pszCNonce, /* client nonce */ - IN char *pszQop, /* qop-value: "", "auth", "auth-int" */ - IN char *pszMethod, /* method from the request */ - IN char *pszDigestUri, /* requested URL */ - IN HASHHEX HEntity, /* H(entity body) if qop=3D"auth-int" */ - OUT HASHHEX Response /* request-digest or response-digest */ - ); +void DigestCalcResponse(IN HASHHEX HA1, /* H(A1) */ + IN char *pszNonce, /* nonce from server */ + IN char *pszNonceCount, /* 8 hex digits */ + IN char *pszCNonce, /* client nonce */ + IN char *pszQop, /* qop-value: "", "auth", = "auth-int" */ + IN char *pszMethod, /* method from the request= */ + IN char *pszDigestUri, /* requested URL */ + IN HASHHEX HEntity, /* H(entity body) if qop= =3D"auth-int" */ + OUT HASHHEX Response /* request-digest or respo= nse-digest */ +); #endif /* if PROXY_DIGEST_AUTH */ diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 77747a2..1085bce 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -59,15 +59,15 @@ #include "memdbg.h" -static struct context *static_context; /* GLOBAL */ +static struct context *static_context; /* GLOBAL */ static const char *saved_pid_file_name; /* GLOBAL */ /* * Crypto initialization flags */ -#define CF_LOAD_PERSISTED_PACKET_ID (1<<0) -#define CF_INIT_TLS_MULTI (1<<1) -#define CF_INIT_TLS_AUTH_STANDALONE (1<<2) +#define CF_LOAD_PERSISTED_PACKET_ID (1 << 0) +#define CF_INIT_TLS_MULTI (1 << 1) +#define CF_INIT_TLS_AUTH_STANDALONE (1 << 2) static void do_init_first_time(struct context *c); @@ -106,21 +106,14 @@ * Used to execute the up/down script/plugins. */ static void -run_up_down(const char *command, - const struct plugin_list *plugins, - int plugin_type, +run_up_down(const char *command, const struct plugin_list *plugins, int pl= ugin_type, const char *arg, #ifdef _WIN32 DWORD adapter_index, #endif - const char *dev_type, - int tun_mtu, - const char *ifconfig_local, - const char *ifconfig_remote, - const char *context, - const char *signal_text, - const char *script_type, - struct env_set *es) + const char *dev_type, int tun_mtu, const char *ifconfig_local, + const char *ifconfig_remote, const char *context, const char *= signal_text, + const char *script_type, struct env_set *es) { struct gc_arena gc =3D gc_new(); @@ -156,9 +149,8 @@ { struct argv argv =3D argv_new(); ASSERT(arg); - argv_printf(&argv, - "%s %d 0 %s %s %s", - arg, tun_mtu, ifconfig_local, ifconfig_remote, context= ); + argv_printf(&argv, "%s %d 0 %s %s %s", arg, tun_mtu, ifconfig_loca= l, ifconfig_remote, + context); if (plugin_call(plugins, plugin_type, &argv, NULL, es) !=3D OPENVP= N_PLUGIN_FUNC_SUCCESS) { @@ -174,8 +166,8 @@ ASSERT(arg); setenv_str(es, "script_type", script_type); argv_parse_cmd(&argv, command); - argv_printf_cat(&argv, "%s %d 0 %s %s %s", arg, tun_mtu, - ifconfig_local, ifconfig_remote, context); + argv_printf_cat(&argv, "%s %d 0 %s %s %s", arg, tun_mtu, ifconfig_= local, ifconfig_remote, + context); argv_msg(M_INFO, &argv); openvpn_run_script(&argv, es, S_FATAL, "--up/--down"); argv_free(&argv); @@ -197,8 +189,7 @@ * for the period of time before we pull the --ping-restart parameter * from the server. */ - if (options->pull - && options->ping_rec_timeout_action =3D=3D PING_UNDEF + if (options->pull && options->ping_rec_timeout_action =3D=3D PING_UNDEF && proto_is_dgram(options->ce.proto)) { options->ping_rec_timeout =3D PRE_PULL_INITIAL_PING_RESTART; @@ -304,11 +295,9 @@ * @return if sending was successful */ static bool -management_callback_send_cc_message(void *arg, - const char *command, - const char *parameters) +management_callback_send_cc_message(void *arg, const char *command, const = char *parameters) { - struct context *c =3D (struct context *) arg; + struct context *c =3D (struct context *)arg; size_t len =3D strlen(command) + 1 + strlen(parameters) + 1; if (len > PUSH_BUNDLE_SIZE) { @@ -332,7 +321,7 @@ management_callback_remote_entry_count(void *arg) { assert(arg); - struct context *c =3D (struct context *) arg; + struct context *c =3D (struct context *)arg; struct connection_list *l =3D c->options.connection_list; return l->len; @@ -344,7 +333,7 @@ assert(arg); assert(remote); - struct context *c =3D (struct context *) arg; + struct context *c =3D (struct context *)arg; struct connection_list *l =3D c->options.connection_list; bool ret =3D true; @@ -355,8 +344,8 @@ const char *status =3D (ce->flags & CE_DISABLED) ? "disabled" : "e= nabled"; /* space for output including 3 commas and a nul */ - int len =3D strlen(ce->remote) + strlen(ce->remote_port) + strlen(= proto) - + strlen(status) + 3 + 1; + int len =3D + strlen(ce->remote) + strlen(ce->remote_port) + strlen(proto) += strlen(status) + 3 + 1; char *out =3D malloc(len); check_malloc_return(out); @@ -375,10 +364,12 @@ static bool management_callback_remote_cmd(void *arg, const char **p) { - struct context *c =3D (struct context *) arg; + struct context *c =3D (struct context *)arg; struct connection_entry *ce =3D &c->options.ce; int ret =3D false; - if (p[1] && ((ce->flags>>CE_MAN_QUERY_REMOTE_SHIFT)&CE_MAN_QUERY_REMOT= E_MASK) =3D=3D CE_MAN_QUERY_REMOTE_QUERY) + if (p[1] + && ((ce->flags >> CE_MAN_QUERY_REMOTE_SHIFT) & CE_MAN_QUERY_REMOTE= _MASK) + =3D=3D CE_MAN_QUERY_REMOTE_QUERY) { int flags =3D 0; if (!strcmp(p[1], "ACCEPT")) @@ -413,8 +404,8 @@ } if (ret) { - ce->flags &=3D ~(CE_MAN_QUERY_REMOTE_MASK<flags |=3D ((flags&CE_MAN_QUERY_REMOTE_MASK)<flags &=3D ~(CE_MAN_QUERY_REMOTE_MASK << CE_MAN_QUERY_REMO= TE_SHIFT); + ce->flags |=3D ((flags & CE_MAN_QUERY_REMOTE_MASK) << CE_MAN_Q= UERY_REMOTE_SHIFT); } } return ret; @@ -439,8 +430,8 @@ ce->flags &=3D ~(CE_MAN_QUERY_REMOTE_MASK << CE_MAN_QUERY_REMOTE_S= HIFT); ce->flags |=3D (CE_MAN_QUERY_REMOTE_QUERY << CE_MAN_QUERY_REMOTE_S= HIFT); - while (((ce->flags >> CE_MAN_QUERY_REMOTE_SHIFT) - & CE_MAN_QUERY_REMOTE_MASK) =3D=3D CE_MAN_QUERY_REMOTE_QUE= RY) + while (((ce->flags >> CE_MAN_QUERY_REMOTE_SHIFT) & CE_MAN_QUERY_RE= MOTE_MASK) + =3D=3D CE_MAN_QUERY_REMOTE_QUERY) { management_event_loop_n_seconds(management, 1); if (IS_SIG(c)) @@ -458,8 +449,7 @@ /* If it is likely a connection entry was modified, * check what changed in the flags and that it was not skipped */ - const int flags =3D ((ce->flags >> CE_MAN_QUERY_REMOTE_SHIFT) - & CE_MAN_QUERY_REMOTE_MASK); + const int flags =3D ((ce->flags >> CE_MAN_QUERY_REMOTE_SHIFT) & CE= _MAN_QUERY_REMOTE_MASK); ce_changed =3D (flags !=3D CE_MAN_QUERY_REMOTE_SKIP); } return ce_changed; @@ -636,7 +626,7 @@ /* Check if this connection attempt would bring us over the limit */ if (c->options.connect_retry_max > 0 - && c->options.unsuccessful_attempts > (l->len * c->options.connec= t_retry_max)) + && c->options.unsuccessful_attempts > (l->len * c->options.connect= _retry_max)) { msg(M_FATAL, "All connections have been connect-retry-max (%d) tim= es unsuccessful, exiting", c->options.connect_retry_max); @@ -661,12 +651,11 @@ { enable_auth_user_pass(); #ifdef ENABLE_MANAGEMENT - auth_user_pass_setup(c->options.auth_user_pass_file, - c->options.auth_user_pass_file_inline, + auth_user_pass_setup(c->options.auth_user_pass_file, c->options.au= th_user_pass_file_inline, &c->options.sc_info); #else - auth_user_pass_setup(c->options.auth_user_pass_file, - c->options.auth_user_pass_file_inline, NULL); + auth_user_pass_setup(c->options.auth_user_pass_file, c->options.au= th_user_pass_file_inline, + NULL); #endif } } @@ -714,9 +703,9 @@ if (!did_http && c->options.ce.socks_proxy_server) { - c->c1.socks_proxy =3D socks_proxy_new(c->options.ce.socks_proxy_se= rver, - c->options.ce.socks_proxy_port, - c->options.ce.socks_proxy_auth= file); + c->c1.socks_proxy =3D + socks_proxy_new(c->options.ce.socks_proxy_server, c->options.c= e.socks_proxy_port, + c->options.ce.socks_proxy_authfile); if (c->c1.socks_proxy) { c->c1.socks_proxy_owned =3D true; @@ -739,8 +728,8 @@ static void do_link_socket_addr_new(struct context *c) { - ALLOC_ARRAY_CLEAR_GC(c->c1.link_socket_addrs, struct link_socket_addr, - c->c1.link_sockets_num, &c->gc); + ALLOC_ARRAY_CLEAR_GC(c->c1.link_socket_addrs, struct link_socket_addr,= c->c1.link_sockets_num, + &c->gc); } void @@ -761,10 +750,11 @@ { int i; pkcs11_initialize(true, c->options.pkcs11_pin_cache_period); - for (i =3D 0; ioptions.pkcs11_providers[i] !=3D N= ULL; i++) + for (i =3D 0; i < MAX_PARMS && c->options.pkcs11_providers[i] !=3D= NULL; i++) { - pkcs11_addProvider(c->options.pkcs11_providers[i], c->options.= pkcs11_protected_authentication[i], - c->options.pkcs11_private_mode[i], c->optio= ns.pkcs11_cert_private[i]); + pkcs11_addProvider( + c->options.pkcs11_providers[i], c->options.pkcs11_protecte= d_authentication[i], + c->options.pkcs11_private_mode[i], c->options.pkcs11_cert_= private[i]); } } #endif @@ -789,9 +779,8 @@ * See possibly_become_daemon() [init.c] for more details. */ sd_notifyf(0, "READY=3D1\nSTATUS=3DPre-connection initialization succe= ssful\nMAINPID=3D%lu", - (unsigned long) getpid()); + (unsigned long)getpid()); #endif - } void @@ -819,10 +808,9 @@ { if (!port_share && (c->options.port_share_host && c->options.port_shar= e_port)) { - port_share =3D port_share_open(c->options.port_share_host, - c->options.port_share_port, - c->c2.frame.buf.payload_size, - c->options.port_share_journal_dir); + port_share =3D + port_share_open(c->options.port_share_host, c->options.port_sh= are_port, + c->c2.frame.buf.payload_size, c->options.port_= share_journal_dir); if (port_share =3D=3D NULL) { msg(M_FATAL, "Fatal error: Port sharing failed"); @@ -850,12 +838,12 @@ struct timeval tv; if (!gettimeofday(&tv, NULL)) { - const unsigned int seed =3D (unsigned int) tv.tv_sec ^ tv.tv_usec; + const unsigned int seed =3D (unsigned int)tv.tv_sec ^ tv.tv_usec; srandom(seed); } - error_reset(); /* initialize error.c */ - reset_check_status(); /* initialize status check code in socket.= c */ + error_reset(); /* initialize error.c */ + reset_check_status(); /* initialize status check code in socket.c */ #ifdef _WIN32 init_win32(); @@ -893,9 +881,7 @@ #ifdef GEN_PATH_TEST { struct gc_arena gc =3D gc_new(); - const char *fn =3D gen_path("foo", - "bar", - &gc); + const char *fn =3D gen_path("foo", "bar", &gc); printf("%s\n", fn); gc_free(&gc); } @@ -1012,8 +998,7 @@ } if (options->show_tls_ciphers) { - show_available_tls_ciphers(options->cipher_list, - options->cipher_list_tls13, + show_available_tls_ciphers(options->cipher_list, options->ciph= er_list_tls13, options->tls_cert_profile); } if (options->show_curves) @@ -1041,11 +1026,10 @@ * We do not want user to use --genkey with --secret. In the transisti= on * phase we for secret. */ - if (options->genkey && options->genkey_type !=3D GENKEY_SECRET - && options->shared_secret_file) + if (options->genkey && options->genkey_type !=3D GENKEY_SECRET && opti= ons->shared_secret_file) { msg(M_USAGE, "Using --genkey type with --secret filename is " - "not supported. Use --genkey type filename instead."); + "not supported. Use --genkey type filename instead."= ); } if (options->genkey && options->genkey_type =3D=3D GENKEY_SECRET) { @@ -1054,7 +1038,7 @@ if (options->shared_secret_file && options->genkey_filename) { msg(M_USAGE, "You must provide a filename to either --genkey " - "or --secret, not both"); + "or --secret, not both"); } /* @@ -1064,7 +1048,7 @@ if (options->shared_secret_file) { msg(M_WARN, "WARNING: Using --genkey --secret filename is " - "DEPRECATED. Use --genkey secret filename instead."); + "DEPRECATED. Use --genkey secret filename instead= ."); genkey_filename =3D options->shared_secret_file; } @@ -1074,8 +1058,7 @@ msg(M_FATAL, "Failed to write key file"); } - msg(D_GENKEY | M_NOPREFIX, - "Randomly generated %d bit key written to %s", nbits_written, + msg(D_GENKEY | M_NOPREFIX, "Randomly generated %d bit key written = to %s", nbits_written, options->shared_secret_file); return true; } @@ -1092,8 +1075,8 @@ "--genkey tls-crypt-v2-client requires a server key to be = set via --tls-crypt-v2 to create a client key"); } - tls_crypt_v2_write_client_key_file(options->genkey_filename, - options->genkey_extra_data, opt= ions->tls_crypt_v2_file, + tls_crypt_v2_write_client_key_file(options->genkey_filename, optio= ns->genkey_extra_data, + options->tls_crypt_v2_file, options->tls_crypt_v2_file_inli= ne); return true; } @@ -1121,13 +1104,10 @@ /* sanity check on options for --mktun or --rmtun */ notnull(options->dev, "TUN/TAP device (--dev)"); - if (options->ce.remote || options->ifconfig_local - || options->ifconfig_remote_netmask - || options->shared_secret_file - || options->tls_server || options->tls_client - ) + if (options->ce.remote || options->ifconfig_local || options->ifconfig= _remote_netmask + || options->shared_secret_file || options->tls_server || options->= tls_client) { - msg(M_FATAL|M_OPTERR, + msg(M_FATAL | M_OPTERR, "options --mktun or --rmtun should only be used together with = --dev"); } @@ -1151,21 +1131,20 @@ #endif #ifdef ENABLE_FEATURE_TUN_PERSIST - tuncfg(options->dev, options->dev_type, options->dev_node, - options->persist_mode, - options->username, options->groupname, &options->tuntap_options, - ctx); + tuncfg(options->dev, options->dev_type, options->dev_node, options->pe= rsist_mode, + options->username, options->groupname, &options->tuntap_options= , ctx); if (options->persist_mode && options->lladdr) { set_lladdr(ctx, options->dev, options->lladdr, NULL); } return true; -#else /* ifdef ENABLE_FEATURE_TUN_PERSIST */ - msg(M_FATAL|M_OPTERR, +#else /* ifdef ENABLE_FEATURE_TUN_PERSIST */ + msg(M_FATAL | M_OPTERR, "options --mktun and --rmtun are not available on your operating " "system. Please check 'man tun' (or 'tap'), whether your system " "supports using 'ifconfig %s create' / 'destroy' to create/remove " - "persistent tunnel interfaces.", options->dev ); + "persistent tunnel interfaces.", + options->dev); #endif return false; } @@ -1242,9 +1221,7 @@ { if (no_delay) { - platform_user_group_set(&c0->platform_state_user, - &c0->platform_state_group, - c); + platform_user_group_set(&c0->platform_state_user, &c0->pla= tform_state_group, c); } else if (c->first_time) { @@ -1272,7 +1249,8 @@ { if (-1 =3D=3D setcon(c->options.selinux_context)) { - msg(M_ERR, "setcon to '%s' failed; is /proc accessible= ?", c->options.selinux_context); + msg(M_ERR, "setcon to '%s' failed; is /proc accessible= ?", + c->options.selinux_context); } else { @@ -1317,17 +1295,12 @@ #ifdef _WIN32 if (options->exit_event_name) { - win32_signal_open(&win32_signal, - WSO_FORCE_SERVICE, - options->exit_event_name, + win32_signal_open(&win32_signal, WSO_FORCE_SERVICE, options->exit_= event_name, options->exit_event_initial_state); } else { - win32_signal_open(&win32_signal, - WSO_FORCE_CONSOLE, - NULL, - false); + win32_signal_open(&win32_signal, WSO_FORCE_CONSOLE, NULL, false); /* put a title on the top window bar */ if (win32_signal.mode =3D=3D WSO_MODE_CONSOLE) @@ -1378,8 +1351,7 @@ /* initialize inactivity timeout */ if (c->options.session_timeout) { - event_timeout_init(&c->c2.session_interval, c->options.session_tim= eout, - now); + event_timeout_init(&c->c2.session_interval, c->options.session_tim= eout, now); } /* initialize pings */ @@ -1410,8 +1382,7 @@ if (c->options.auth_token_generate && c->options.auth_token_renewal < c->options.renegotiate_seconds) { - event_timeout_init(&c->c2.auth_token_renewal_interval, - c->options.auth_token_renewal, now); + event_timeout_init(&c->c2.auth_token_renewal_interval, c->options.= auth_token_renewal, now); } if (!deferred) @@ -1421,16 +1392,16 @@ /* initialize occ timers */ - if (c->options.occ - && !TLS_MODE(c) - && c->c2.options_string_local && c->c2.options_string_remote) + if (c->options.occ && !TLS_MODE(c) && c->c2.options_string_local + && c->c2.options_string_remote) { event_timeout_init(&c->c2.occ_interval, OCC_INTERVAL_SECONDS, = now); } if (c->options.mtu_test) { - event_timeout_init(&c->c2.occ_mtu_load_test_interval, OCC_MTU_= LOAD_INTERVAL_SECONDS, now); + event_timeout_init(&c->c2.occ_mtu_load_test_interval, OCC_MTU_= LOAD_INTERVAL_SECONDS, + now); } /* initialize packet_id persistence timer */ @@ -1483,10 +1454,8 @@ * options and saving routes in the environment. */ static void -do_init_route_list(const struct options *options, - struct route_list *route_list, - const struct link_socket_info *link_socket_info, - struct env_set *es, +do_init_route_list(const struct options *options, struct route_list *route= _list, + const struct link_socket_info *link_socket_info, struct= env_set *es, openvpn_net_ctx_t *ctx) { const char *gw =3D NULL; @@ -1515,13 +1484,8 @@ metric =3D options->route_default_metric; } - if (init_route_list(route_list, - options->routes, - gw, - metric, - link_socket_current_remote(link_socket_info), - es, - ctx)) + if (init_route_list(route_list, options->routes, gw, metric, + link_socket_current_remote(link_socket_info), es, = ctx)) { /* copy routes to environment */ setenv_routes(es, route_list); @@ -1529,14 +1493,12 @@ } static void -do_init_route_ipv6_list(const struct options *options, - struct route_ipv6_list *route_ipv6_list, - const struct link_socket_info *link_socket_info, - struct env_set *es, +do_init_route_ipv6_list(const struct options *options, struct route_ipv6_l= ist *route_ipv6_list, + const struct link_socket_info *link_socket_info, s= truct env_set *es, openvpn_net_ctx_t *ctx) { const char *gw =3D NULL; - int metric =3D -1; /* no metric set */ + int metric =3D -1; /* no metric set */ /* see explanation in do_init_route_list() */ if (dco_enabled(options)) @@ -1544,7 +1506,7 @@ metric =3D DCO_DEFAULT_METRIC; } - gw =3D options->ifconfig_ipv6_remote; /* default GW =3D remote= end */ + gw =3D options->ifconfig_ipv6_remote; /* default GW =3D remote end */ if (options->route_ipv6_default_gateway) { gw =3D options->route_ipv6_default_gateway; @@ -1564,19 +1526,14 @@ for (i =3D 0; opt_list[i]; i++) { - add_route_ipv6_to_option_list( options->routes_ipv6, - string_alloc(opt_list[i], optio= ns->routes_ipv6->gc), - NULL, NULL, options->route_defa= ult_table_id); + add_route_ipv6_to_option_list(options->routes_ipv6, + string_alloc(opt_list[i], option= s->routes_ipv6->gc), NULL, + NULL, options->route_default_tab= le_id); } } - if (init_route_ipv6_list(route_ipv6_list, - options->routes_ipv6, - gw, - metric, - link_socket_current_remote_ipv6(link_socket_i= nfo), - es, - ctx)) + if (init_route_ipv6_list(route_ipv6_list, options->routes_ipv6, gw, me= tric, + link_socket_current_remote_ipv6(link_socket_i= nfo), es, ctx)) { /* copy routes to environment */ setenv_routes_ipv6(es, route_ipv6_list); @@ -1602,8 +1559,8 @@ if (flags & ISC_ERRORS) { #ifdef _WIN32 - show_routes(M_INFO|M_NOPREFIX); - show_adapters(M_INFO|M_NOPREFIX); + show_routes(M_INFO | M_NOPREFIX); + show_adapters(M_INFO | M_NOPREFIX); msg(M_INFO, "%s With Errors ( see http://openvpn.net/faq.html#dhcp= clientserv )", message); #else #ifdef ENABLE_SYSTEMD @@ -1621,7 +1578,7 @@ } /* Flag that we initialized */ - if ((flags & (ISC_ERRORS|ISC_SERVER)) =3D=3D 0) + if ((flags & (ISC_ERRORS | ISC_SERVER)) =3D=3D 0) { c->options.no_advance =3D true; } @@ -1683,13 +1640,8 @@ tun_local =3D &c->c1.tuntap->local; tun_local6 =3D &c->c1.tuntap->local_ipv6; } - management_set_state(management, - OPENVPN_STATE_CONNECTED, - detail, - tun_local, - tun_local6, - &local, - &remote); + management_set_state(management, OPENVPN_STATE_CONNECTED, detail, = tun_local, tun_local6, + &local, &remote); if (tun_local) { management_post_tunnel_open(management, *tun_local); @@ -1705,8 +1657,7 @@ static bool route_noexec_enabled(const struct options *o, const struct tuntap *tt) { - return o->route_noexec - || (tt && tt->backend_driver =3D=3D DRIVER_AFUNIX) + return o->route_noexec || (tt && tt->backend_driver =3D=3D DRIVER_AFUN= IX) || (tt && tt->backend_driver =3D=3D DRIVER_NULL); } @@ -1715,19 +1666,14 @@ * based on options. */ bool -do_route(const struct options *options, - struct route_list *route_list, - struct route_ipv6_list *route_ipv6_list, - const struct tuntap *tt, - const struct plugin_list *plugins, - struct env_set *es, - openvpn_net_ctx_t *ctx) +do_route(const struct options *options, struct route_list *route_list, + struct route_ipv6_list *route_ipv6_list, const struct tuntap *tt, + const struct plugin_list *plugins, struct env_set *es, openvpn_ne= t_ctx_t *ctx) { bool ret =3D true; - if (!route_noexec_enabled(options, tt) && ( route_list || route_ipv6_l= ist ) ) + if (!route_noexec_enabled(options, tt) && (route_list || route_ipv6_li= st)) { - ret =3D add_routes(route_list, route_ipv6_list, tt, ROUTE_OPTION_F= LAGS(options), - es, ctx); + ret =3D add_routes(route_list, route_ipv6_list, tt, ROUTE_OPTION_F= LAGS(options), es, ctx); setenv_int(es, "redirect_gateway", route_did_redirect_default_gate= way(route_list)); } #ifdef ENABLE_MANAGEMENT @@ -1739,7 +1685,8 @@ if (plugin_defined(plugins, OPENVPN_PLUGIN_ROUTE_UP)) { - if (plugin_call(plugins, OPENVPN_PLUGIN_ROUTE_UP, NULL, NULL, es) = !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) + if (plugin_call(plugins, OPENVPN_PLUGIN_ROUTE_UP, NULL, NULL, es) + !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) { msg(M_WARN, "WARNING: route-up plugin call failed"); } @@ -1757,13 +1704,13 @@ #ifdef _WIN32 if (options->show_net_up) { - show_routes(M_INFO|M_NOPREFIX); - show_adapters(M_INFO|M_NOPREFIX); + show_routes(M_INFO | M_NOPREFIX); + show_adapters(M_INFO | M_NOPREFIX); } else if (check_debug_level(D_SHOW_NET)) { - show_routes(D_SHOW_NET|M_NOPREFIX); - show_adapters(D_SHOW_NET|M_NOPREFIX); + show_routes(D_SHOW_NET | M_NOPREFIX); + show_adapters(D_SHOW_NET | M_NOPREFIX); } #endif return ret; @@ -1775,27 +1722,19 @@ static void do_init_tun(struct context *c) { - c->c1.tuntap =3D init_tun(c->options.dev, - c->options.dev_type, - c->options.topology, - c->options.ifconfig_local, - c->options.ifconfig_remote_netmask, - c->options.ifconfig_ipv6_local, - c->options.ifconfig_ipv6_netbits, - c->options.ifconfig_ipv6_remote, - c->c1.link_socket_addrs[0].bind_local, - c->c1.link_socket_addrs[0].remote_list, - !c->options.ifconfig_nowarn, - c->c2.es, - &c->net_ctx, - c->c1.tuntap); + c->c1.tuntap =3D init_tun(c->options.dev, c->options.dev_type, c->opti= ons.topology, + c->options.ifconfig_local, c->options.ifconfig= _remote_netmask, + c->options.ifconfig_ipv6_local, c->options.ifc= onfig_ipv6_netbits, + c->options.ifconfig_ipv6_remote, c->c1.link_so= cket_addrs[0].bind_local, + c->c1.link_socket_addrs[0].remote_list, !c->op= tions.ifconfig_nowarn, + c->c2.es, &c->net_ctx, c->c1.tuntap); if (is_tun_afunix(c->options.dev_node)) { /* Using AF_UNIX trumps using DCO */ c->c1.tuntap->backend_driver =3D DRIVER_AFUNIX; } - else if (is_dev_type(c->options.dev, c->options.dev_type, "null")) + else if (is_dev_type(c->options.dev, c->options.dev_type, "null")) { c->c1.tuntap->backend_driver =3D DRIVER_NULL; } @@ -1815,9 +1754,7 @@ } #endif - init_tun_post(c->c1.tuntap, - &c->c2.frame, - &c->options.tuntap_options); + init_tun_post(c->c1.tuntap, &c->c2.frame, &c->options.tuntap_options); c->c1.tuntap_owned =3D true; } @@ -1917,10 +1854,10 @@ } else { - open_tun(c->options.dev, c->options.dev_type, c->options.dev_node, - tt, &c->net_ctx); + open_tun(c->options.dev, c->options.dev_type, c->options.dev_node,= tt, &c->net_ctx); } - msg(M_INFO, "%s device [%s] opened", print_tun_backend_driver(tt->back= end_driver), tt->actual_name); + msg(M_INFO, "%s device [%s] opened", print_tun_backend_driver(tt->back= end_driver), + tt->actual_name); } @@ -1959,8 +1896,7 @@ #ifdef _WIN32 /* store (hide) interactive service handle in tuntap_options */ c->c1.tuntap->options.msg_channel =3D c->options.msg_channel; - msg(D_ROUTE, "interactive service msg_channel=3D%" PRIuPTR, - (intptr_t) c->options.msg_channel); + msg(D_ROUTE, "interactive service msg_channel=3D%" PRIuPTR, (intpt= r_t)c->options.msg_channel); #endif /* allocate route list structure */ @@ -1970,8 +1906,8 @@ ASSERT(c->c2.link_sockets[0]); if (c->options.routes && c->c1.route_list) { - do_init_route_list(&c->options, c->c1.route_list, - &c->c2.link_sockets[0]->info, c->c2.es, &c-= >net_ctx); + do_init_route_list(&c->options, c->c1.route_list, &c->c2.link_= sockets[0]->info, + c->c2.es, &c->net_ctx); } if (c->options.routes_ipv6 && c->c1.route_ipv6_list) { @@ -1980,15 +1916,12 @@ } /* do ifconfig */ - if (!ifconfig_noexec_enabled(c) - && ifconfig_order(c->c1.tuntap) =3D=3D IFCONFIG_BEFORE_TUN_OPE= N) + if (!ifconfig_noexec_enabled(c) && ifconfig_order(c->c1.tuntap) = =3D=3D IFCONFIG_BEFORE_TUN_OPEN) { /* guess actual tun/tap unit number that will be returned * by open_tun */ - const char *guess =3D guess_tuntap_dev(c->options.dev, - c->options.dev_type, - c->options.dev_node, - &gc); + const char *guess =3D + guess_tuntap_dev(c->options.dev, c->options.dev_type, c->o= ptions.dev_node, &gc); do_ifconfig(c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es= , &c->net_ctx); } @@ -2020,31 +1953,23 @@ } /* do ifconfig */ - if (!ifconfig_noexec_enabled(c) - && ifconfig_order(c->c1.tuntap) =3D=3D IFCONFIG_AFTER_TUN_OPEN) + if (!ifconfig_noexec_enabled(c) && ifconfig_order(c->c1.tuntap) = =3D=3D IFCONFIG_AFTER_TUN_OPEN) { - do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name, - c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); + do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name, c->c2.fra= me.tun_mtu, c->c2.es, + &c->net_ctx); } run_dns_up_down(true, &c->options, c->c1.tuntap, &c->persist.duri); /* run the up script */ - run_up_down(c->options.up_script, - c->plugins, - OPENVPN_PLUGIN_UP, - c->c1.tuntap->actual_name, + run_up_down(c->options.up_script, c->plugins, OPENVPN_PLUGIN_UP, c= ->c1.tuntap->actual_name, #ifdef _WIN32 c->c1.tuntap->adapter_index, #endif - dev_type_string(c->options.dev, c->options.dev_type), - c->c2.frame.tun_mtu, + dev_type_string(c->options.dev, c->options.dev_type), = c->c2.frame.tun_mtu, print_in_addr_t(c->c1.tuntap->local, IA_EMPTY_IF_UNDEF= , &gc), - print_in_addr_t(c->c1.tuntap->remote_netmask, IA_EMPTY= _IF_UNDEF, &gc), - "init", - NULL, - "up", - c->c2.es); + print_in_addr_t(c->c1.tuntap->remote_netmask, IA_EMPTY= _IF_UNDEF, &gc), "init", + NULL, "up", c->c2.es); add_wfp_block(c); @@ -2061,8 +1986,7 @@ } else { - msg(M_INFO, "Preserving previous TUN/TAP instance: %s", - c->c1.tuntap->actual_name); + msg(M_INFO, "Preserving previous TUN/TAP instance: %s", c->c1.tunt= ap->actual_name); /* explicitly set the ifconfig_* env vars */ do_ifconfig_setenv(c->c1.tuntap, c->c2.es); @@ -2072,21 +1996,15 @@ /* run the up script if user specified --up-restart */ if (c->options.up_restart) { - run_up_down(c->options.up_script, - c->plugins, - OPENVPN_PLUGIN_UP, + run_up_down(c->options.up_script, c->plugins, OPENVPN_PLUGIN_U= P, c->c1.tuntap->actual_name, #ifdef _WIN32 c->c1.tuntap->adapter_index, #endif - dev_type_string(c->options.dev, c->options.dev_typ= e), - c->c2.frame.tun_mtu, + dev_type_string(c->options.dev, c->options.dev_typ= e), c->c2.frame.tun_mtu, print_in_addr_t(c->c1.tuntap->local, IA_EMPTY_IF_U= NDEF, &gc), print_in_addr_t(c->c1.tuntap->remote_netmask, IA_E= MPTY_IF_UNDEF, &gc), - "restart", - NULL, - "up", - c->c2.es); + "restart", NULL, "up", c->c2.es); } add_wfp_block(c); @@ -2102,8 +2020,7 @@ static void do_close_tun_simple(struct context *c) { - msg(D_CLOSE, "Closing %s interface", - print_tun_backend_driver(c->c1.tuntap->backend_driver)); + msg(D_CLOSE, "Closing %s interface", print_tun_backend_driver(c->c1.tu= ntap->backend_driver)); if (c->c1.tuntap) { @@ -2175,26 +2092,18 @@ /* delete any routes we added */ if (c->c1.route_list || c->c1.route_ipv6_list) { - run_up_down(c->options.route_predown_script, - c->plugins, - OPENVPN_PLUGIN_ROUTE_PREDOWN, + run_up_down(c->options.route_predown_script, c->plugins, OPENV= PN_PLUGIN_ROUTE_PREDOWN, tuntap_actual, #ifdef _WIN32 adapter_index, #endif - NULL, - c->c2.frame.tun_mtu, - print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc), - print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF,= &gc), - "init", - signal_description(c->sig->signal_received, - c->sig->signal_text), - "route-pre-down", - c->c2.es); + NULL, c->c2.frame.tun_mtu, print_in_addr_t(local, = IA_EMPTY_IF_UNDEF, &gc), + print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF,= &gc), "init", + signal_description(c->sig->signal_received, c->sig= ->signal_text), + "route-pre-down", c->c2.es); - delete_routes(c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, ROUTE_OPTION_FLAGS(&c->options), - c->c2.es, &c->net_ctx); + delete_routes(c->c1.route_list, c->c1.route_ipv6_list, c->c1.t= untap, + ROUTE_OPTION_FLAGS(&c->options), c->c2.es, &c->n= et_ctx); } /* actually close tun/tap device based on --down-pre flag */ @@ -2205,21 +2114,13 @@ /* Run the down script -- note that it will run at reduced * privilege if, for example, "--user" was used. */ - run_up_down(c->options.down_script, - c->plugins, - OPENVPN_PLUGIN_DOWN, - tuntap_actual, + run_up_down(c->options.down_script, c->plugins, OPENVPN_PLUGIN_DOW= N, tuntap_actual, #ifdef _WIN32 adapter_index, #endif - NULL, - c->c2.frame.tun_mtu, - print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc), - print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc= ), - "init", - signal_description(c->sig->signal_received, - c->sig->signal_text), - "down", + NULL, c->c2.frame.tun_mtu, print_in_addr_t(local, IA_E= MPTY_IF_UNDEF, &gc), + print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc= ), "init", + signal_description(c->sig->signal_received, c->sig->si= gnal_text), "down", c->c2.es); del_wfp_block(c, adapter_index); @@ -2235,21 +2136,13 @@ /* run the down script on this restart if --up-restart was specifi= ed */ if (c->options.up_restart) { - run_up_down(c->options.down_script, - c->plugins, - OPENVPN_PLUGIN_DOWN, - tuntap_actual, + run_up_down(c->options.down_script, c->plugins, OPENVPN_PLUGIN= _DOWN, tuntap_actual, #ifdef _WIN32 adapter_index, #endif - NULL, - c->c2.frame.tun_mtu, - print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc), - print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF,= &gc), - "restart", - signal_description(c->sig->signal_received, - c->sig->signal_text), - "down", + NULL, c->c2.frame.tun_mtu, print_in_addr_t(local, = IA_EMPTY_IF_UNDEF, &gc), + print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF,= &gc), "restart", + signal_description(c->sig->signal_received, c->sig= ->signal_text), "down", c->c2.es); } @@ -2278,10 +2171,9 @@ * equal, or either one is all-zeroes. */ static bool -options_hash_changed_or_zero(const struct sha256_digest *a, - const struct sha256_digest *b) +options_hash_changed_or_zero(const struct sha256_digest *a, const struct s= ha256_digest *b) { - const struct sha256_digest zero =3D {{0}}; + const struct sha256_digest zero =3D { { 0 } }; return memcmp(a, b, sizeof(struct sha256_digest)) || !memcmp(a, &zero, sizeof(struct sha256_digest)); } @@ -2317,13 +2209,12 @@ if (cipher_kt_mode_aead(o->ciphername)) { - buf_printf(&out, "Data Channel: cipher '%s'", - cipher_kt_name(o->ciphername)); + buf_printf(&out, "Data Channel: cipher '%s'", cipher_kt_name(o->ci= phername)); } else { - buf_printf(&out, "Data Channel: cipher '%s', auth '%s'", - cipher_kt_name(o->ciphername), md_kt_name(o->authname)); + buf_printf(&out, "Data Channel: cipher '%s', auth '%s'", cipher_kt= _name(o->ciphername), + md_kt_name(o->authname)); } if (o->use_peer_id) @@ -2394,8 +2285,7 @@ if (c->options.ce.explicit_exit_notification) { - buf_printf(&out, "explicit-exit-notify %d", - c->options.ce.explicit_exit_notification); + buf_printf(&out, "explicit-exit-notify %d", c->options.ce.explicit= _exit_notification); } if (c->options.imported_protocol_flags) { @@ -2447,10 +2337,8 @@ #endif struct tls_session *session =3D &c->c2.tls_multi->session[TM_ACTIVE]; - if (!tls_session_update_crypto_params(c->c2.tls_multi, session, - &c->options, &c->c2.frame, - frame_fragment, - get_link_socket_info(c), + if (!tls_session_update_crypto_params(c->c2.tls_multi, session, &c->op= tions, &c->c2.frame, + frame_fragment, get_link_socket_= info(c), &c->c1.tuntap->dco)) { msg(D_TLS_ERRORS, "OPTIONS ERROR: failed to import crypto options"= ); @@ -2487,14 +2375,13 @@ * Was tun interface object persisted from previous restart it= eration, * and if so did pulled options string change from previous it= eration? */ - if (!c->c2.did_open_tun - && PULL_DEFINED(&c->options) - && c->c1.tuntap + if (!c->c2.did_open_tun && PULL_DEFINED(&c->options) && c->c1.= tuntap && options_hash_changed_or_zero(&c->c1.pulled_options_dige= st_save, &c->c2.pulled_options_dige= st)) { /* if so, close tun, delete routes, then reinitialize tun = and add routes */ - msg(M_INFO, "NOTE: Pulled options changed on restart, will= need to close and reopen TUN/TAP device."); + msg(M_INFO, + "NOTE: Pulled options changed on restart, will need to= close and reopen TUN/TAP device."); bool tt_dco_win =3D tuntap_is_dco_win(c->c1.tuntap); do_close_tun(c, true); @@ -2520,7 +2407,8 @@ * reconnects to setup various things (like DCO and NCP cipher) that * might have changed from the previous connection. */ - if (!c->c2.do_up_ran || (c->c2.tls_multi && c->c2.tls_multi->multi_sta= te =3D=3D CAS_RECONNECT_PENDING)) + if (!c->c2.do_up_ran + || (c->c2.tls_multi && c->c2.tls_multi->multi_state =3D=3D CAS_REC= ONNECT_PENDING)) { if (c->mode =3D=3D MODE_POINT_TO_POINT) { @@ -2568,7 +2456,8 @@ if ((route_order(c->c1.tuntap) =3D=3D ROUTE_AFTER_TUN) && c->o= ptions.route_delay_defined) { event_timeout_init(&c->c2.route_wakeup, c->options.route_d= elay, now); - event_timeout_init(&c->c2.route_wakeup_expire, c->options.= route_delay + c->options.route_delay_window, now); + event_timeout_init(&c->c2.route_wakeup_expire, + c->options.route_delay + c->options.rou= te_delay_window, now); tun_standby_init(c->c1.tuntap); } else @@ -2600,23 +2489,10 @@ unsigned int pull_permission_mask(const struct context *c) { - unsigned int flags =3D - OPT_P_UP - | OPT_P_ROUTE_EXTRAS - | OPT_P_SOCKBUF - | OPT_P_SOCKFLAGS - | OPT_P_SETENV - | OPT_P_SHAPER - | OPT_P_TIMER - | OPT_P_COMP - | OPT_P_PERSIST - | OPT_P_MESSAGES - | OPT_P_EXPLICIT_NOTIFY - | OPT_P_ECHO - | OPT_P_PULL_MODE - | OPT_P_PEER_ID - | OPT_P_NCP - | OPT_P_PUSH_MTU; + unsigned int flags =3D OPT_P_UP | OPT_P_ROUTE_EXTRAS | OPT_P_SOCKBUF |= OPT_P_SOCKFLAGS + | OPT_P_SETENV | OPT_P_SHAPER | OPT_P_TIMER | OPT= _P_COMP | OPT_P_PERSIST + | OPT_P_MESSAGES | OPT_P_EXPLICIT_NOTIFY | OPT_P_= ECHO | OPT_P_PULL_MODE + | OPT_P_PEER_ID | OPT_P_NCP | OPT_P_PUSH_MTU; if (!c->options.route_nopull) { @@ -2638,8 +2514,8 @@ struct tls_session *session =3D &c->c2.tls_multi->session[TM_ACTIVE]; - const char *ncp_cipher =3D get_p2p_ncp_cipher(session, c->c2.tls_multi= ->peer_info, - &c->options.gc); + const char *ncp_cipher =3D + get_p2p_ncp_cipher(session, c->c2.tls_multi->peer_info, &c->option= s.gc); if (ncp_cipher) { @@ -2648,8 +2524,8 @@ else if (!c->options.enable_ncp_fallback) { msg(D_TLS_ERRORS, "ERROR: failed to negotiate cipher with peer and= " - "--data-ciphers-fallback not enabled. No usable " - "data channel cipher"); + "--data-ciphers-fallback not enabled. No usable " + "data channel cipher"); return false; } @@ -2661,9 +2537,8 @@ } #endif - if (!tls_session_update_crypto_params(c->c2.tls_multi, session, &c->op= tions, - &c->c2.frame, frame_fragment, - get_link_socket_info(c), + if (!tls_session_update_crypto_params(c->c2.tls_multi, session, &c->op= tions, &c->c2.frame, + frame_fragment, get_link_socket_= info(c), &c->c1.tuntap->dco)) { msg(D_TLS_ERRORS, "ERROR: failed to set crypto cipher"); @@ -2680,7 +2555,7 @@ { if (found & OPT_P_MESSAGES) { - init_verb_mute(c, IVM_LEVEL_1|IVM_LEVEL_2); + init_verb_mute(c, IVM_LEVEL_1 | IVM_LEVEL_2); msg(D_PUSH, "OPTIONS IMPORT: --verb and/or --mute level changed"); } if (found & OPT_P_TIMER) @@ -2709,9 +2584,9 @@ if (!check_compression_settings_valid(&c->options.comp, D_PUSH_ERR= ORS)) { msg(D_PUSH_ERRORS, "OPTIONS ERROR: server pushed compression " - "settings that are not allowed and will result " - "in a non-working connection. " - "See also allow-compression in the manual."); + "settings that are not allowed and will res= ult " + "in a non-working connection. " + "See also allow-compression in the manual."= ); return false; } #ifdef USE_COMP @@ -2733,8 +2608,7 @@ for (int i =3D 0; i < c->c1.link_sockets_num; i++) { - link_socket_update_buffer_sizes(c->c2.link_sockets[i], - c->options.rcvbuf, + link_socket_update_buffer_sizes(c->c2.link_sockets[i], c->opti= ons.rcvbuf, c->options.sndbuf); } } @@ -2744,8 +2618,7 @@ msg(D_PUSH, "OPTIONS IMPORT: --socket-flags option modified"); for (int i =3D 0; i < c->c1.link_sockets_num; i++) { - link_socket_update_flags(c->c2.link_sockets[i], - c->options.sockflags); + link_socket_update_flags(c->c2.link_sockets[i], c->options.soc= kflags); } } @@ -2790,12 +2663,11 @@ } /* Check if pushed options are compatible with DCO, if enabled */ - if (dco_enabled(&c->options) - && !dco_check_pull_options(D_PUSH_ERRORS, &c->options)) + if (dco_enabled(&c->options) && !dco_check_pull_options(D_PUSH_ERR= ORS, &c->options)) { msg(D_PUSH_ERRORS, "OPTIONS ERROR: pushed options are incompat= ible " - "with data channel offload. Use --disable-dco to connect t= o " - "this server"); + "with data channel offload. Use --disable-d= co to connect to " + "this server"); return false; } } @@ -2808,7 +2680,7 @@ if (epoch_data && !datav2_enabled) { msg(D_PUSH_ERRORS, "OPTIONS ERROR: Epoch key data format tag requi= res " - "data v2 (peer-id) to be enabled."); + "data v2 (peer-id) to be enabled."); return false; } @@ -2823,7 +2695,8 @@ if (c->options.ce.tun_mtu > frame->tun_max_mtu) { - msg(D_PUSH_ERRORS, "Server-pushed tun-mtu is too large, please= add " + msg(D_PUSH_ERRORS, + "Server-pushed tun-mtu is too large, please add " "tun-mtu-max %d in the client configuration", c->options.ce.tun_mtu); } @@ -2887,8 +2760,7 @@ } /* Slow down reconnection after 5 retries per remote -- for TCP client= or UDP tls-client only */ - if (c->mode =3D=3D CM_CHILD_TCP - || (c->options.ce.proto =3D=3D PROTO_UDP && c->options.tls_client)) + if (c->mode =3D=3D CM_CHILD_TCP || (c->options.ce.proto =3D=3D PROTO_U= DP && c->options.tls_client)) { backoff =3D (c->options.unsuccessful_attempts / c->options.connect= ion_list->len) - 4; if (backoff > 0) @@ -2957,10 +2829,8 @@ ASSERT(o->ce.link_mtu_defined); /* if we have a link mtu defined we calculate what the old code * would have come up with as tun-mtu */ - size_t overhead =3D frame_calculate_protocol_header_size(&c->c1.ks= .key_type, - o, true); + size_t overhead =3D frame_calculate_protocol_header_size(&c->c1.ks= .key_type, o, true); mtu =3D o->ce.link_mtu - overhead; - } else { @@ -3045,7 +2915,8 @@ size_t tailroom =3D headroom; #ifdef USE_COMP - msg(D_MTU_DEBUG, "MTU: adding %zu buffer tailroom for compression for = %zu " + msg(D_MTU_DEBUG, + "MTU: adding %zu buffer tailroom for compression for %zu " "bytes of payload", COMP_EXTRA_BUFFER(payload_size), payload_size); tailroom +=3D COMP_EXTRA_BUFFER(payload_size); @@ -3114,14 +2985,11 @@ } /* Initialize packet ID tracking */ - packet_id_init(&c->c2.crypto_options.packet_id, - options->replay_window, - options->replay_time, + packet_id_init(&c->c2.crypto_options.packet_id, options->replay_window= , options->replay_time, "STATIC", 0); c->c2.crypto_options.pid_persist =3D &c->c1.pid_persist; c->c2.crypto_options.flags |=3D CO_PACKET_ID_LONG_FORM; - packet_id_persist_load_obj(&c->c1.pid_persist, - &c->c2.crypto_options.packet_id); + packet_id_persist_load_obj(&c->c1.pid_persist, &c->c2.crypto_options.p= acket_id); if (!key_ctx_bi_defined(&c->c1.ks.static_key)) { @@ -3131,10 +2999,8 @@ /* Read cipher and hmac keys from shared secret file */ crypto_read_openvpn_key(&c->c1.ks.key_type, &c->c1.ks.static_key, - options->shared_secret_file, - options->shared_secret_file_inline, - options->key_direction, "Static Key Encryp= tion", - "secret", NULL); + options->shared_secret_file, options->shar= ed_secret_file_inline, + options->key_direction, "Static Key Encryp= tion", "secret", NULL); } else { @@ -3162,26 +3028,23 @@ c->c1.ks.tls_auth_key_type.digest =3D options->authname; if (!md_valid(options->authname)) { - msg(M_FATAL, "ERROR: tls-auth enabled, but no valid --auth " - "algorithm specified ('%s')", options->authname); + msg(M_FATAL, + "ERROR: tls-auth enabled, but no valid --auth " + "algorithm specified ('%s')", + options->authname); } - crypto_read_openvpn_key(&c->c1.ks.tls_auth_key_type, - &c->c1.ks.tls_wrap_key, - options->ce.tls_auth_file, - options->ce.tls_auth_file_inline, - options->ce.key_direction, - "Control Channel Authentication", "tls-aut= h", - &c->c1.ks.original_wrap_keydata); + crypto_read_openvpn_key(&c->c1.ks.tls_auth_key_type, &c->c1.ks.tls= _wrap_key, + options->ce.tls_auth_file, options->ce.tls= _auth_file_inline, + options->ce.key_direction, "Control Channe= l Authentication", + "tls-auth", &c->c1.ks.original_wrap_keydat= a); } /* TLS handshake encryption+authentication (--tls-crypt) */ if (options->ce.tls_crypt_file) { - tls_crypt_init_key(&c->c1.ks.tls_wrap_key, - &c->c1.ks.original_wrap_keydata, - options->ce.tls_crypt_file, - options->ce.tls_crypt_file_inline, + tls_crypt_init_key(&c->c1.ks.tls_wrap_key, &c->c1.ks.original_wrap= _keydata, + options->ce.tls_crypt_file, options->ce.tls_cry= pt_file_inline, options->tls_server); } @@ -3190,16 +3053,14 @@ { if (options->tls_server) { - tls_crypt_v2_init_server_key(&c->c1.ks.tls_crypt_v2_server_key, - true, options->ce.tls_crypt_v2_fi= le, + tls_crypt_v2_init_server_key(&c->c1.ks.tls_crypt_v2_server_key= , true, + options->ce.tls_crypt_v2_file, options->ce.tls_crypt_v2_file_inl= ine); } else { - tls_crypt_v2_init_client_key(&c->c1.ks.tls_wrap_key, - &c->c1.ks.original_wrap_keydata, - &c->c1.ks.tls_crypt_v2_wkc, - options->ce.tls_crypt_v2_file, + tls_crypt_v2_init_client_key(&c->c1.ks.tls_wrap_key, &c->c1.ks= .original_wrap_keydata, + &c->c1.ks.tls_crypt_v2_wkc, optio= ns->ce.tls_crypt_v2_file, options->ce.tls_crypt_v2_file_inl= ine); } /* We have to ensure that the loaded tls-crypt key is small enough @@ -3211,15 +3072,14 @@ if (required_size > c->options.ce.tls_mtu) { - msg(M_WARN, "ERROR: tls-crypt-v2 client key too large to work = with " + msg(M_WARN, + "ERROR: tls-crypt-v2 client key too large to work with " "requested --max-packet-size %d, requires at least " "--max-packet-size %d. Packets will ignore requested " - "maximum packet size", c->options.ce.tls_mtu, - required_size); + "maximum packet size", + c->options.ce.tls_mtu, required_size); } } - - } =20 /* @@ -3248,7 +3108,7 @@ case AR_INTERACT: ssl_purge_auth(false); - /* Intentional [[fallthrough]]; */ + /* Intentional [[fallthrough]]; */ case AR_NOINTERACT: /* SOFT-SIGUSR1 -- Password failure error */ @@ -3289,8 +3149,7 @@ /* Do not warn if the cipher is used only in OCC */ bool warn =3D options->enable_ncp_fallback; - init_key_type(&c->c1.ks.key_type, ciphername, options->authname, - true, warn); + init_key_type(&c->c1.ks.key_type, ciphername, options->authname, t= rue, warn); /* initialize tls-auth/crypt/crypt-v2 key */ do_init_tls_wrap_key(c); @@ -3298,8 +3157,7 @@ /* initialise auth-token crypto support */ if (c->options.auth_token_generate) { - auth_token_init_secret(&c->c1.ks.auth_token_key, - c->options.auth_token_secret_file, + auth_token_init_secret(&c->c1.ks.auth_token_key, c->options.au= th_token_secret_file, c->options.auth_token_secret_file_inlin= e); } @@ -3377,25 +3235,27 @@ if (options->renegotiate_seconds_min < 0) { /* Add 10% jitter to reneg-sec by default (server side only) */ - int auto_jitter =3D options->mode !=3D MODE_SERVER ? 0 : - get_random() % max_int(options->renegotiate_seco= nds / 10, 1); + int auto_jitter =3D options->mode !=3D MODE_SERVER + ? 0 + : get_random() % max_int(options->renegotiat= e_seconds / 10, 1); to.renegotiate_seconds =3D options->renegotiate_seconds - auto_jit= ter; } else { /* Add user-specified jitter to reneg-sec */ - to.renegotiate_seconds =3D options->renegotiate_seconds - -(get_random() % max_int(options->renegot= iate_seconds - - options->reneg= otiate_seconds_min, 1)); + to.renegotiate_seconds =3D + options->renegotiate_seconds + - (get_random() + % max_int(options->renegotiate_seconds - options->renegotia= te_seconds_min, 1)); } to.single_session =3D options->single_session; to.mode =3D options->mode; to.pull =3D options->pull; - if (options->push_peer_info) /* all there is */ + if (options->push_peer_info) /* all there is */ { to.push_peer_info_detail =3D 3; } - else if (options->pull) /* pull clients send some details = */ + else if (options->pull) /* pull clients send some details */ { to.push_peer_info_detail =3D 2; } @@ -3403,7 +3263,7 @@ { to.push_peer_info_detail =3D 0; } - else /* default: minimal info to allow NCP in P2P mod= e */ + else /* default: minimal info to allow NCP in P2P mode */ { to.push_peer_info_detail =3D 1; } @@ -3506,8 +3366,7 @@ } /* TLS handshake encryption (--tls-crypt) */ - if (options->ce.tls_crypt_file - || (options->ce.tls_crypt_v2_file && options->tls_client)) + if (options->ce.tls_crypt_file || (options->ce.tls_crypt_v2_file && op= tions->tls_client)) { to.tls_wrap.mode =3D TLS_WRAP_CRYPT; } @@ -3565,10 +3424,8 @@ if (c->c2.tls_multi) { tls_multi_init_finalize(c->c2.tls_multi, c->options.ce.tls_mtu); - ASSERT(c->c2.tls_multi->opt.frame.buf.payload_size <=3D - c->c2.frame.buf.payload_size); - frame_print(&c->c2.tls_multi->opt.frame, D_MTU_INFO, - "Control Channel MTU parms"); + ASSERT(c->c2.tls_multi->opt.frame.buf.payload_size <=3D c->c2.fram= e.buf.payload_size); + frame_print(&c->c2.tls_multi->opt.frame, D_MTU_INFO, "Control Chan= nel MTU parms"); /* Keep the max mtu also in the frame of tls multi so it can access * it in push_peer_info */ @@ -3576,9 +3433,9 @@ } if (c->c2.tls_auth_standalone) { - tls_init_control_channel_frame_parameters(&c->c2.tls_auth_standalo= ne->frame, c->options.ce.tls_mtu); - frame_print(&c->c2.tls_auth_standalone->frame, D_MTU_INFO, - "TLS-Auth MTU parms"); + tls_init_control_channel_frame_parameters(&c->c2.tls_auth_standalo= ne->frame, + c->options.ce.tls_mtu); + frame_print(&c->c2.tls_auth_standalone->frame, D_MTU_INFO, "TLS-Au= th MTU parms"); c->c2.tls_auth_standalone->tls_wrap.work =3D alloc_buf_gc(BUF_SIZE= (&c->c2.frame), &c->c2.gc); c->c2.tls_auth_standalone->workbuf =3D alloc_buf_gc(BUF_SIZE(&c->c= 2.frame), &c->c2.gc); } @@ -3594,14 +3451,12 @@ /* Initialise key_type with auth/cipher "none", so the key_type struct= is * valid */ - init_key_type(&c->c1.ks.key_type, "none", "none", - c->options.test_crypto, true); + init_key_type(&c->c1.ks.key_type, "none", "none", c->options.test_cryp= to, true); - msg(M_WARN, - "******* WARNING *******: All encryption and authentication featur= es " - "disabled -- All data will be tunnelled as clear text and will not= be " - "protected against man-in-the-middle changes. " - "PLEASE DO RECONSIDER THIS CONFIGURATION!"); + msg(M_WARN, "******* WARNING *******: All encryption and authenticatio= n features " + "disabled -- All data will be tunnelled as clear text and = will not be " + "protected against man-in-the-middle changes. " + "PLEASE DO RECONSIDER THIS CONFIGURATION!"); } static void @@ -3615,7 +3470,7 @@ { do_init_crypto_tls(c, flags); } - else /* no encryption or authentication. */ + else /* no encryption or authentication. */ { do_init_crypto_none(c); } @@ -3653,7 +3508,8 @@ #ifdef ENABLE_FRAGMENT if (c->options.ce.fragment > 0 && c->options.ce.mssfix > c->options.ce= .fragment) { - msg(M_WARN, "WARNING: if you use --mssfix and --fragment, you shou= ld " + msg(M_WARN, + "WARNING: if you use --mssfix and --fragment, you should " "set --fragment (%d) larger or equal than --mssfix (%d)", c->options.ce.fragment, c->options.ce.mssfix); } @@ -3661,7 +3517,7 @@ && c->options.ce.fragment_encap !=3D c->options.ce.mssfix_encap) { msg(M_WARN, "WARNING: if you use --mssfix and --fragment, you shou= ld " - "use the \"mtu\" flag for both or none of of them."); + "use the \"mtu\" flag for both or none of of them."); } #endif } @@ -3680,34 +3536,39 @@ #ifdef ENABLE_SELINUX || o->selinux_context #endif - ) + ) { if (!o->persist_tun) { - msg(M_WARN, "WARNING: you are using user/group/chroot/setcon w= ithout persist-tun -- this may cause restarts to fail"); + msg(M_WARN, + "WARNING: you are using user/group/chroot/setcon without p= ersist-tun -- this may cause restarts to fail"); } } if (o->chroot_dir && !(o->username && o->groupname)) { - msg(M_WARN, "WARNING: you are using chroot without specifying user= and group -- this may cause the chroot jail to be insecure"); + msg(M_WARN, + "WARNING: you are using chroot without specifying user and gro= up -- this may cause the chroot jail to be insecure"); } if (o->pull && o->ifconfig_local && c->first_time) { - msg(M_WARN, "WARNING: using --pull/--client and --ifconfig togethe= r is probably not what you want"); + msg(M_WARN, + "WARNING: using --pull/--client and --ifconfig together is pro= bably not what you want"); } if (o->server_bridge_defined || o->server_bridge_proxy_dhcp) { - msg(M_WARN, "NOTE: when bridging your LAN adapter with the TAP ada= pter, note that the new bridge adapter will often take on its own IP addres= s that is different from what the LAN adapter was previously set to"); + msg(M_WARN, + "NOTE: when bridging your LAN adapter with the TAP adapter, no= te that the new bridge adapter will often take on its own IP address that i= s different from what the LAN adapter was previously set to"); } if (o->mode =3D=3D MODE_SERVER) { if (o->duplicate_cn && o->client_config_dir) { - msg(M_WARN, "WARNING: using --duplicate-cn and --client-config= -dir together is probably not what you want"); + msg(M_WARN, + "WARNING: using --duplicate-cn and --client-config-dir tog= ether is probably not what you want"); } if (o->duplicate_cn && o->ifconfig_pool_persist_filename) { @@ -3723,14 +3584,12 @@ { warn_on_use_of_common_subnets(&c->net_ctx); } - if (o->tls_client - && !o->tls_verify - && o->verify_x509_type =3D=3D VERIFY_X509_NONE - && !(o->ns_cert_type & NS_CERT_CHECK_SERVER) - && !o->remote_cert_eku + if (o->tls_client && !o->tls_verify && o->verify_x509_type =3D=3D VERI= FY_X509_NONE + && !(o->ns_cert_type & NS_CERT_CHECK_SERVER) && !o->remote_cert_eku && !(o->verify_hash_depth =3D=3D 0 && o->verify_hash)) { - msg(M_WARN, "WARNING: No server certificate verification method ha= s been enabled. See http://openvpn.net/howto.html#mitm for more info."); + msg(M_WARN, + "WARNING: No server certificate verification method has been e= nabled. See http://openvpn.net/howto.html#mitm for more info."); } if (o->ns_cert_type) { @@ -3742,15 +3601,19 @@ { if (script_security() >=3D SSEC_SCRIPTS) { - msg(M_WARN, "NOTE: the current --script-security setting may a= llow this configuration to call user-defined scripts"); + msg(M_WARN, + "NOTE: the current --script-security setting may allow thi= s configuration to call user-defined scripts"); } else if (script_security() >=3D SSEC_PW_ENV) { - msg(M_WARN, "WARNING: the current --script-security setting ma= y allow passwords to be passed to scripts via environmental variables"); + msg(M_WARN, + "WARNING: the current --script-security setting may allow = passwords to be passed to scripts via environmental variables"); } else { - msg(M_WARN, "NOTE: starting with " PACKAGE_NAME " 2.1, '--scri= pt-security 2' or higher is required to call user-defined scripts or execut= ables"); + msg(M_WARN, + "NOTE: starting with " PACKAGE_NAME + " 2.1, '--script-security 2' or higher is required to call= user-defined scripts or executables"); } } } @@ -3829,8 +3692,8 @@ */ c->c2.frame_fragment =3D c->c2.frame; - frame_calculate_dynamic(&c->c2.frame_fragment, &c->c1.ks.key_type, - &c->options, get_link_socket_info(c)); + frame_calculate_dynamic(&c->c2.frame_fragment, &c->c1.ks.key_type, &c-= >options, + get_link_socket_info(c)); fragment_frame_init(c->c2.fragment, &c->c2.frame_fragment); } #endif @@ -3843,8 +3706,7 @@ { ASSERT(!c->c2.link_sockets); - ALLOC_ARRAY_GC(c->c2.link_sockets, struct link_socket *, - c->c1.link_sockets_num, &c->c2.gc); + ALLOC_ARRAY_GC(c->c2.link_sockets, struct link_socket *, c->c1.link_so= ckets_num, &c->c2.gc); for (int i =3D 0; i < c->c1.link_sockets_num; i++) { @@ -3907,8 +3769,7 @@ #ifdef ENABLE_FRAGMENT if (c->c2.fragment) { - frame_print(&c->c2.frame_fragment, D_MTU_INFO, - "Fragmentation MTU parms"); + frame_print(&c->c2.frame_fragment, D_MTU_INFO, "Fragmentation MTU = parms"); } #endif } @@ -3922,23 +3783,18 @@ struct gc_arena gc =3D gc_new(); c->c2.options_string_local =3D - options_string(&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ct= x, - false, &gc); + options_string(&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ct= x, false, &gc); c->c2.options_string_remote =3D - options_string(&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ct= x, - true, &gc); + options_string(&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ct= x, true, &gc); msg(D_SHOW_OCC, "Local Options String (VER=3D%s): '%s'", - options_string_version(c->c2.options_string_local, &gc), - c->c2.options_string_local); + options_string_version(c->c2.options_string_local, &gc), c->c2.opt= ions_string_local); msg(D_SHOW_OCC, "Expected Remote Options String (VER=3D%s): '%s'", - options_string_version(c->c2.options_string_remote, &gc), - c->c2.options_string_remote); + options_string_version(c->c2.options_string_remote, &gc), c->c2.op= tions_string_remote); if (c->c2.tls_multi) { - tls_multi_init_set_options(c->c2.tls_multi, - c->c2.options_string_local, + tls_multi_init_set_options(c->c2.tls_multi, c->c2.options_string_l= ocal, c->c2.options_string_remote); } @@ -3962,10 +3818,8 @@ /* get user and/or group that we want to setuid/setgid to, * sets also platform_x_state */ - bool group_defined =3D platform_group_get(c->options.groupname, - &c0->platform_state_group= ); - bool user_defined =3D platform_user_get(c->options.username, - &c0->platform_state_user); + bool group_defined =3D platform_group_get(c->options.groupname, &c= 0->platform_state_group); + bool user_defined =3D platform_user_get(c->options.username, &c0->= platform_state_user); c0->uid_gid_specified =3D user_defined || group_defined; @@ -4074,16 +3928,13 @@ * reconnect to the same host again or there are still addresses that = need * to be tried */ if (!(c->sig->signal_received =3D=3D SIGUSR1 - && ( (c->options.persist_remote_ip) - || - ( c->sig->source !=3D SIG_SOURCE_HARD - && ((c->c1.link_socket_addrs[0].current_remote - && c->c1.link_socket_addrs[0].current_remote->ai_nex= t) - || c->options.no_advance)) - ))) + && ((c->options.persist_remote_ip) + || (c->sig->source !=3D SIG_SOURCE_HARD + && ((c->c1.link_socket_addrs[0].current_remote + && c->c1.link_socket_addrs[0].current_remote->ai_ne= xt) + || c->options.no_advance))))) { - clear_remote_addrlist(&c->c1.link_socket_addrs[0], - !c->options.resolve_in_advance); + clear_remote_addrlist(&c->c1.link_socket_addrs[0], !c->options.res= olve_in_advance); } /* Clear the remote actual address when persist_remote_ip is not in us= e */ @@ -4099,8 +3950,7 @@ { for (int i =3D 0; i < c->c1.link_sockets_num; i++) { - if (c->c1.link_socket_addrs[i].bind_local - && !c->options.resolve_in_advance) + if (c->c1.link_socket_addrs[i].bind_local && !c->options.resol= ve_in_advance) { freeaddrinfo(c->c1.link_socket_addrs[i].bind_local); } @@ -4144,8 +3994,7 @@ */ static void -do_event_set_init(struct context *c, - bool need_us_timeout) +do_event_set_init(struct context *c, bool need_us_timeout) { unsigned int flags =3D 0; @@ -4182,11 +4031,9 @@ { if (!c->c1.status_output) { - c->c1.status_output =3D status_open(c->options.status_file, - c->options.status_file_update_fr= eq, - -1, - NULL, - STATUS_OUTPUT_WRITE); + c->c1.status_output =3D + status_open(c->options.status_file, c->options.status_file_upd= ate_freq, -1, NULL, + STATUS_OUTPUT_WRITE); c->c1.status_output_owned =3D true; } } @@ -4213,8 +4060,9 @@ { if (!c->c1.ifconfig_pool_persist && c->options.ifconfig_pool_persist_f= ilename) { - c->c1.ifconfig_pool_persist =3D ifconfig_pool_persist_init(c->opti= ons.ifconfig_pool_persist_filename, - c->option= s.ifconfig_pool_persist_refresh_freq); + c->c1.ifconfig_pool_persist =3D + ifconfig_pool_persist_init(c->options.ifconfig_pool_persist_fi= lename, + c->options.ifconfig_pool_persist_re= fresh_freq); c->c1.ifconfig_pool_persist_owned =3D true; } } @@ -4328,12 +4176,9 @@ unsigned int option_types_found =3D 0; if (config.list[i] && config.list[i]->value) { - options_string_import(&c->options, - config.list[i]->value, - D_IMPORT_ERRORS|M_OPTERR, - OPT_P_DEFAULT & ~OPT_P_PLUGI= N, - &option_types_found, - c->es); + options_string_import( + &c->options, config.list[i]->value, D_IMPORT_E= RRORS | M_OPTERR, + OPT_P_DEFAULT & ~OPT_P_PLUGIN, &option_types_f= ound, c->es); } } } @@ -4374,7 +4219,7 @@ static void management_callback_status_p2p(void *arg, const int version, struct status= _output *so) { - struct context *c =3D (struct context *) arg; + struct context *c =3D (struct context *)arg; print_status(c, so); } @@ -4407,7 +4252,7 @@ */ int socketfd =3D -1; - struct context *c =3D (struct context *) arg; + struct context *c =3D (struct context *)arg; if (!c->c2.link_sockets || !c->c2.link_sockets[0]) { return -1; @@ -4488,24 +4333,14 @@ { flags |=3D MF_SERVER; } - if (management_open(management, - c->options.management_addr, - c->options.management_port, - c->options.management_user_pass, - c->options.management_client_user, - c->options.management_client_group, - c->options.management_log_history_cache, - c->options.management_echo_buffer_size, - c->options.management_state_buffer_size, - c->options.remap_sigusr1, - flags)) + if (management_open( + management, c->options.management_addr, c->options.man= agement_port, + c->options.management_user_pass, c->options.management= _client_user, + c->options.management_client_group, c->options.managem= ent_log_history_cache, + c->options.management_echo_buffer_size, c->options.man= agement_state_buffer_size, + c->options.remap_sigusr1, flags)) { - management_set_state(management, - OPENVPN_STATE_CONNECTING, - NULL, - NULL, - NULL, - NULL, + management_set_state(management, OPENVPN_STATE_CONNECTING,= NULL, NULL, NULL, NULL, NULL); } @@ -4884,9 +4719,7 @@ /* close event objects */ do_close_event_set(c); - if (c->mode =3D=3D CM_P2P - || c->mode =3D=3D CM_CHILD_TCP - || c->mode =3D=3D CM_CHILD_UDP + if (c->mode =3D=3D CM_P2P || c->mode =3D=3D CM_CHILD_TCP || c->mode = =3D=3D CM_CHILD_UDP || c->mode =3D=3D CM_TOP) { #ifdef USE_COMP @@ -4954,9 +4787,7 @@ } void -inherit_context_child(struct context *dest, - const struct context *src, - struct link_socket *sock) +inherit_context_child(struct context *dest, const struct context *src, str= uct link_socket *sock) { CLEAR(*dest); @@ -5044,8 +4875,7 @@ } void -inherit_context_top(struct context *dest, - const struct context *src) +inherit_context_top(struct context *dest, const struct context *src) { /* copy parent */ *dest =3D *src; @@ -5173,7 +5003,7 @@ static void * test_crypto_thread(void *arg) { - struct context *c =3D (struct context *) arg; + struct context *c =3D (struct context *)arg; const struct options *options =3D &c->options; ASSERT(options->test_crypto); @@ -5207,7 +5037,7 @@ c.options =3D *o; options_detach(&c.options); c.first_time =3D true; - test_crypto_thread((void *) &c); + test_crypto_thread((void *)&c); return true; } return false; diff --git a/src/openvpn/init.h b/src/openvpn/init.h index 5c6b9c1..a650de6 100644 --- a/src/openvpn/init.h +++ b/src/openvpn/init.h @@ -46,8 +46,8 @@ void uninit_static(void); -#define IVM_LEVEL_1 (1<<0) -#define IVM_LEVEL_2 (1<<1) +#define IVM_LEVEL_1 (1 << 0) +#define IVM_LEVEL_2 (1 << 1) void init_verb_mute(struct context *c, unsigned int flags); void init_options_dev(struct options *options); @@ -62,7 +62,8 @@ void pre_setup(const struct options *options); -void init_instance_handle_signals(struct context *c, const struct env_set = *env, const unsigned int flags); +void init_instance_handle_signals(struct context *c, const struct env_set = *env, + const unsigned int flags); void init_instance(struct context *c, const struct env_set *env, const uns= igned int flags); @@ -73,8 +74,7 @@ bool do_route(const struct options *options, struct route_list *route_list, struct route_ipv6_list *route_ipv6_list, const struct tuntap= *tt, - const struct plugin_list *plugins, struct env_set *es, - openvpn_net_ctx_t *ctx); + const struct plugin_list *plugins, struct env_set *es, openv= pn_net_ctx_t *ctx); void close_instance(struct context *c); @@ -82,9 +82,7 @@ void context_gc_free(struct context *c); -bool do_up(struct context *c, - bool pulled_options, - unsigned int option_types_found); +bool do_up(struct context *c, bool pulled_options, unsigned int option_typ= es_found); unsigned int pull_permission_mask(const struct context *c); @@ -94,17 +92,15 @@ bool do_deferred_options(struct context *c, const unsigned int found); -void inherit_context_child(struct context *dest, - const struct context *src, +void inherit_context_child(struct context *dest, const struct context *src, struct link_socket *sock); -void inherit_context_top(struct context *dest, - const struct context *src); +void inherit_context_top(struct context *dest, const struct context *src); -#define CC_GC_FREE (1<<0) -#define CC_USR1_TO_HUP (1<<1) -#define CC_HARD_USR1_TO_HUP (1<<2) -#define CC_NO_CLOSE (1<<3) +#define CC_GC_FREE (1 << 0) +#define CC_USR1_TO_HUP (1 << 1) +#define CC_HARD_USR1_TO_HUP (1 << 2) +#define CC_NO_CLOSE (1 << 3) void close_context(struct context *c, int sig, unsigned int flags); @@ -112,9 +108,9 @@ void free_context_buffers(struct context_buffers *b); -#define ISC_ERRORS (1<<0) -#define ISC_SERVER (1<<1) -#define ISC_ROUTE_ERRORS (1<<2) +#define ISC_ERRORS (1 << 0) +#define ISC_SERVER (1 << 1) +#define ISC_ROUTE_ERRORS (1 << 2) void initialization_sequence_completed(struct context *c, const unsigned i= nt flags); #ifdef ENABLE_MANAGEMENT diff --git a/src/openvpn/integer.h b/src/openvpn/integer.h index c568036..e1f7950 100644 --- a/src/openvpn/integer.h +++ b/src/openvpn/integer.h @@ -27,13 +27,17 @@ #include "error.h" #ifndef htonll -#define htonll(x) ((1=3D=3Dhtonl(1)) ? (x) : \ - ((uint64_t)htonl((uint32_t)((x) & 0xFFFFFFFF)) << 32) |= htonl((uint32_t)((x) >> 32))) +#define htonll(x) \ + ((1 =3D=3D htonl(1)) \ + ? (x) \ + : ((uint64_t)htonl((uint32_t)((x) & 0xFFFFFFFF)) << 32) | htonl((= uint32_t)((x) >> 32))) #endif #ifndef ntohll -#define ntohll(x) ((1=3D=3Dntohl(1)) ? (x) : \ - ((uint64_t)ntohl((uint32_t)((x) & 0xFFFFFFFF)) << 32) |= ntohl((uint32_t)((x) >> 32))) +#define ntohll(x) \ + ((1 =3D=3D ntohl(1)) \ + ? (x) \ + : ((uint64_t)ntohl((uint32_t)((x) & 0xFFFFFFFF)) << 32) | ntohl((= uint32_t)((x) >> 32))) #endif static inline int @@ -197,10 +201,7 @@ if (index < 0 || index >=3D size) { msg(M_FATAL, "Assertion Failed: Array index=3D%d out of bounds for= array size=3D%d in %s:%d", - index, - size, - file, - line); + index, size, file, line); } return index; } diff --git a/src/openvpn/interval.c b/src/openvpn/interval.c index f1abeee..35c1382 100644 --- a/src/openvpn/interval.c +++ b/src/openvpn/interval.c @@ -40,9 +40,7 @@ } bool -event_timeout_trigger(struct event_timeout *et, - struct timeval *tv, - const int et_const_retry) +event_timeout_trigger(struct event_timeout *et, struct timeval *tv, const = int et_const_retry) { if (!et->defined) { @@ -55,8 +53,7 @@ if (wakeup <=3D 0) { #if INTERVAL_DEBUG - dmsg(D_INTERVAL, "EVENT event_timeout_trigger (%d) etcr=3D%d", et-= >n, - et_const_retry); + dmsg(D_INTERVAL, "EVENT event_timeout_trigger (%d) etcr=3D%d", et-= >n, et_const_retry); #endif if (et_const_retry < 0) { @@ -73,8 +70,8 @@ if (tv && wakeup < tv->tv_sec) { #if INTERVAL_DEBUG - dmsg(D_INTERVAL, "EVENT event_timeout_wakeup (%d/%d) etcr=3D%d", - (int) wakeup, et->n, et_const_retry); + dmsg(D_INTERVAL, "EVENT event_timeout_wakeup (%d/%d) etcr=3D%d", (= int)wakeup, et->n, + et_const_retry); #endif tv->tv_sec =3D wakeup; tv->tv_usec =3D 0; diff --git a/src/openvpn/interval.h b/src/openvpn/interval.h index 60030fd..d2473e4 100644 --- a/src/openvpn/interval.h +++ b/src/openvpn/interval.h @@ -75,8 +75,7 @@ } if (top->last_action + top->horizon > local_now - || top->last_test_true + top->refresh <=3D local_now - || trigger) + || top->last_test_true + top->refresh <=3D local_now || trigger) { top->last_test_true =3D local_now; #if INTERVAL_DEBUG @@ -135,9 +134,9 @@ struct event_timeout { - bool defined; /**< This timeout is active */ - interval_t n; /**< periodic interval for periodic timeouts */ - time_t last; /**< time of last event */ + bool defined; /**< This timeout is active */ + interval_t n; /**< periodic interval for periodic timeouts */ + time_t last; /**< time of last event */ }; static inline bool @@ -218,7 +217,7 @@ static inline interval_t event_timeout_remaining(struct event_timeout *et) { - return (interval_t) ((et->last + et->n) - now); + return (interval_t)((et->last + et->n) - now); } #define ETT_DEFAULT (-1) @@ -255,19 +254,18 @@ * @param et_const_retry see above * @return if the timeout has triggered and event has bee= n reset */ -bool event_timeout_trigger(struct event_timeout *et, - struct timeval *tv, - int et_const_retry); +bool event_timeout_trigger(struct event_timeout *et, struct timeval *tv, i= nt et_const_retry); /* * Measure time intervals in microseconds */ -#define USEC_TIMER_MAX 60 /* maximum interval size in seconds */ +#define USEC_TIMER_MAX 60 /* maximum interval size in seconds */ #define USEC_TIMER_MAX_USEC (USEC_TIMER_MAX * 1000000) -struct usec_timer { +struct usec_timer +{ struct timeval start; struct timeval end; }; diff --git a/src/openvpn/list.c b/src/openvpn/list.c index 1f33b5f..3baaafd 100644 --- a/src/openvpn/list.c +++ b/src/openvpn/list.c @@ -35,8 +35,7 @@ #include "memdbg.h" struct hash * -hash_init(const int n_buckets, - const uint32_t iv, +hash_init(const int n_buckets, const uint32_t iv, uint32_t (*hash_function)(const void *key, uint32_t iv), bool (*compare_function)(const void *key1, const void *key2)) { @@ -45,7 +44,7 @@ ASSERT(n_buckets > 0); ALLOC_OBJ_CLEAR(h, struct hash); - h->n_buckets =3D (int) adjust_power_of_2(n_buckets); + h->n_buckets =3D (int)adjust_power_of_2(n_buckets); h->mask =3D h->n_buckets - 1; h->hash_function =3D hash_function; h->compare_function =3D compare_function; @@ -80,10 +79,7 @@ } struct hash_element * -hash_lookup_fast(struct hash *hash, - struct hash_bucket *bucket, - const void *key, - uint32_t hv) +hash_lookup_fast(struct hash *hash, struct hash_bucket *bucket, const void= *key, uint32_t hv) { struct hash_element *he; struct hash_element *prev =3D NULL; @@ -111,10 +107,7 @@ } bool -hash_remove_fast(struct hash *hash, - struct hash_bucket *bucket, - const void *key, - uint32_t hv) +hash_remove_fast(struct hash *hash, struct hash_bucket *bucket, const void= *key, uint32_t hv) { struct hash_element *he; struct hash_element *prev =3D NULL; @@ -220,9 +213,7 @@ } void -hash_iterator_init_range(struct hash *hash, - struct hash_iterator *hi, - int start_bucket, +hash_iterator_init_range(struct hash *hash, struct hash_iterator *hi, int = start_bucket, int end_bucket) { if (end_bucket > hash->n_buckets) @@ -243,8 +234,7 @@ } void -hash_iterator_init(struct hash *hash, - struct hash_iterator *hi) +hash_iterator_init(struct hash *hash, struct hash_iterator *hi) { hash_iterator_init_range(hash, hi, 0, hash->n_buckets); } @@ -391,17 +381,35 @@ * -------------------------------------------------------------------- */ -#define mix(a, b, c) \ - { \ - a -=3D b; a -=3D c; a ^=3D (c>>13); \ - b -=3D c; b -=3D a; b ^=3D (a<<8); \ - c -=3D a; c -=3D b; c ^=3D (b>>13); \ - a -=3D b; a -=3D c; a ^=3D (c>>12); \ - b -=3D c; b -=3D a; b ^=3D (a<<16); \ - c -=3D a; c -=3D b; c ^=3D (b>>5); \ - a -=3D b; a -=3D c; a ^=3D (c>>3); \ - b -=3D c; b -=3D a; b ^=3D (a<<10); \ - c -=3D a; c -=3D b; c ^=3D (b>>15); \ +#define mix(a, b, c) \ + { \ + a -=3D b; \ + a -=3D c; \ + a ^=3D (c >> 13); \ + b -=3D c; \ + b -=3D a; \ + b ^=3D (a << 8); \ + c -=3D a; \ + c -=3D b; \ + c ^=3D (b >> 13); \ + a -=3D b; \ + a -=3D c; \ + a ^=3D (c >> 12); \ + b -=3D c; \ + b -=3D a; \ + b ^=3D (a << 16); \ + c -=3D a; \ + c -=3D b; \ + c ^=3D (b >> 5); \ + a -=3D b; \ + a -=3D c; \ + a ^=3D (c >> 3); \ + b -=3D c; \ + b -=3D a; \ + b ^=3D (a << 10); \ + c -=3D a; \ + c -=3D b; \ + c ^=3D (b >> 15); \ } uint32_t @@ -411,21 +419,15 @@ /* Set up the internal state */ len =3D length; - a =3D b =3D 0x9e3779b9; /* the golden ratio; an arbitrary value */ - c =3D initval; /* the previous hash value */ + a =3D b =3D 0x9e3779b9; /* the golden ratio; an arbitrary value */ + c =3D initval; /* the previous hash value */ /*---------------------------------------- handle most of the key */ while (len >=3D 12) { - a +=3D (k[0] + ((uint32_t) k[1] << 8) - + ((uint32_t) k[2] << 16) - + ((uint32_t) k[3] << 24)); - b +=3D (k[4] + ((uint32_t) k[5] << 8) - + ((uint32_t) k[6] << 16) - + ((uint32_t) k[7] << 24)); - c +=3D (k[8] + ((uint32_t) k[9] << 8) - + ((uint32_t) k[10] << 16) - + ((uint32_t) k[11] << 24)); + a +=3D (k[0] + ((uint32_t)k[1] << 8) + ((uint32_t)k[2] << 16) + ((= uint32_t)k[3] << 24)); + b +=3D (k[4] + ((uint32_t)k[5] << 8) + ((uint32_t)k[6] << 16) + ((= uint32_t)k[7] << 24)); + c +=3D (k[8] + ((uint32_t)k[9] << 8) + ((uint32_t)k[10] << 16) + (= (uint32_t)k[11] << 24)); mix(a, b, c); k +=3D 12; len -=3D 12; @@ -433,48 +435,48 @@ /*------------------------------------- handle the last 11 bytes */ c +=3D length; - switch (len) /* all the case statements fall through */ + switch (len) /* all the case statements fall through */ { case 11: - c +=3D ((uint32_t) k[10] << 24); - /* Intentional [[fallthrough]]; */ + c +=3D ((uint32_t)k[10] << 24); + /* Intentional [[fallthrough]]; */ case 10: - c +=3D ((uint32_t) k[9] << 16); - /* Intentional [[fallthrough]]; */ + c +=3D ((uint32_t)k[9] << 16); + /* Intentional [[fallthrough]]; */ case 9: - c +=3D ((uint32_t) k[8] << 8); + c +=3D ((uint32_t)k[8] << 8); /* Intentional [[fallthrough]]; */ /* the first byte of c is reserved for the length */ case 8: - b +=3D ((uint32_t) k[7] << 24); - /* Intentional [[fallthrough]]; */ + b +=3D ((uint32_t)k[7] << 24); + /* Intentional [[fallthrough]]; */ case 7: - b +=3D ((uint32_t) k[6] << 16); - /* Intentional [[fallthrough]]; */ + b +=3D ((uint32_t)k[6] << 16); + /* Intentional [[fallthrough]]; */ case 6: - b +=3D ((uint32_t) k[5] << 8); - /* Intentional [[fallthrough]]; */ + b +=3D ((uint32_t)k[5] << 8); + /* Intentional [[fallthrough]]; */ case 5: b +=3D k[4]; - /* Intentional [[fallthrough]]; */ + /* Intentional [[fallthrough]]; */ case 4: - a +=3D ((uint32_t) k[3] << 24); - /* Intentional [[fallthrough]]; */ + a +=3D ((uint32_t)k[3] << 24); + /* Intentional [[fallthrough]]; */ case 3: - a +=3D ((uint32_t) k[2] << 16); - /* Intentional [[fallthrough]]; */ + a +=3D ((uint32_t)k[2] << 16); + /* Intentional [[fallthrough]]; */ case 2: - a +=3D ((uint32_t) k[1] << 8); - /* Intentional [[fallthrough]]; */ + a +=3D ((uint32_t)k[1] << 8); + /* Intentional [[fallthrough]]; */ case 1: a +=3D k[0]; diff --git a/src/openvpn/list.h b/src/openvpn/list.h index 783570f..678e817 100644 --- a/src/openvpn/list.h +++ b/src/openvpn/list.h @@ -37,8 +37,8 @@ #include "basic.h" #include "buffer.h" -#define hashsize(n) ((uint32_t)1<<(n)) -#define hashmask(n) (hashsize(n)-1) +#define hashsize(n) ((uint32_t)1 << (n)) +#define hashmask(n) (hashsize(n) - 1) struct hash_element { @@ -64,8 +64,7 @@ struct hash_bucket *buckets; }; -struct hash *hash_init(const int n_buckets, - const uint32_t iv, +struct hash *hash_init(const int n_buckets, const uint32_t iv, uint32_t (*hash_function)(const void *key, uint32_t= iv), bool (*compare_function)(const void *key1, const vo= id *key2)); @@ -73,15 +72,10 @@ bool hash_add(struct hash *hash, const void *key, void *value, bool replac= e); -struct hash_element *hash_lookup_fast(struct hash *hash, - struct hash_bucket *bucket, - const void *key, - uint32_t hv); +struct hash_element *hash_lookup_fast(struct hash *hash, struct hash_bucke= t *bucket, + const void *key, uint32_t hv); -bool hash_remove_fast(struct hash *hash, - struct hash_bucket *bucket, - const void *key, - uint32_t hv); +bool hash_remove_fast(struct hash *hash, struct hash_bucket *bucket, const= void *key, uint32_t hv); void hash_remove_by_value(struct hash *hash, void *value); @@ -97,9 +91,7 @@ int bucket_index_end; }; -void hash_iterator_init_range(struct hash *hash, - struct hash_iterator *hi, - int start_bucket, +void hash_iterator_init_range(struct hash *hash, struct hash_iterator *hi,= int start_bucket, int end_bucket); void hash_iterator_init(struct hash *hash, struct hash_iterator *iter); @@ -155,10 +147,7 @@ /* NOTE: assumes that key is not a duplicate */ static inline void -hash_add_fast(struct hash *hash, - struct hash_bucket *bucket, - const void *key, - uint32_t hv, +hash_add_fast(struct hash *hash, struct hash_bucket *bucket, const void *k= ey, uint32_t hv, void *value) { struct hash_element *he; diff --git a/src/openvpn/lladdr.c b/src/openvpn/lladdr.c index cc677b4..d8bcad9 100644 --- a/src/openvpn/lladdr.c +++ b/src/openvpn/lladdr.c @@ -14,8 +14,7 @@ #include "proto.h" =20 int -set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr, - const struct env_set *es) +set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr,= const struct env_set *es) { int r; @@ -32,27 +31,16 @@ #else /* if defined(TARGET_LINUX) */ struct argv argv =3D argv_new(); #if defined(TARGET_SOLARIS) - argv_printf(&argv, - "%s %s ether %s", - IFCONFIG_PATH, - ifname, lladdr); + argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifname, lladdr); #elif defined(TARGET_OPENBSD) - argv_printf(&argv, - "%s %s lladdr %s", - IFCONFIG_PATH, - ifname, lladdr); + argv_printf(&argv, "%s %s lladdr %s", IFCONFIG_PATH, ifname, lladdr); #elif defined(TARGET_DARWIN) - argv_printf(&argv, - "%s %s lladdr %s", - IFCONFIG_PATH, - ifname, lladdr); + argv_printf(&argv, "%s %s lladdr %s", IFCONFIG_PATH, ifname, lladdr); #elif defined(TARGET_FREEBSD) - argv_printf(&argv, - "%s %s ether %s", - IFCONFIG_PATH, - ifname, lladdr); + argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH, ifname, lladdr); #else /* if defined(TARGET_SOLARIS) */ - msg(M_WARN, "Sorry, but I don't know how to configure link layer addre= sses on this operating system."); + msg(M_WARN, + "Sorry, but I don't know how to configure link layer addresses on = this operating system."); return -1; #endif /* if defined(TARGET_SOLARIS) */ argv_msg(M_INFO, &argv); diff --git a/src/openvpn/lzo.c b/src/openvpn/lzo.c index 01db221..a8649f8 100644 --- a/src/openvpn/lzo.c +++ b/src/openvpn/lzo.c @@ -51,9 +51,10 @@ int lzo_status =3D lzo_init(); if (lzo_status !=3D LZO_E_OK) { - msg(M_FATAL, "Cannot initialize LZO compression library (lzo_init(= ) returns %d)", lzo_status); + msg(M_FATAL, "Cannot initialize LZO compression library (lzo_init(= ) returns %d)", + lzo_status); } - compctx->wu.lzo.wmem =3D (lzo_voidp) malloc(compctx->wu.lzo.wmem_size); + compctx->wu.lzo.wmem =3D (lzo_voidp)malloc(compctx->wu.lzo.wmem_size); check_malloc_return(compctx->wu.lzo.wmem); } @@ -65,8 +66,7 @@ } static void -lzo_compress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +lzo_compress(struct buffer *buf, struct buffer work, struct compress_conte= xt *compctx, const struct frame *frame) { uint8_t *header =3D buf_prepend(buf, 1); @@ -74,13 +74,12 @@ } static void -lzo_decompress(struct buffer *buf, struct buffer work, - struct compress_context *compctx, +lzo_decompress(struct buffer *buf, struct buffer work, struct compress_con= text *compctx, const struct frame *frame) { lzo_uint zlen =3D frame->buf.payload_size; int err; - uint8_t c; /* flag indicating whether or not our peer compres= sed */ + uint8_t c; /* flag indicating whether or not our peer compressed */ if (buf->len <=3D 0) { @@ -95,8 +94,7 @@ if (c =3D=3D LZO_COMPRESS_BYTE) /* packet was compressed */ { ASSERT(buf_safe(&work, zlen)); - err =3D LZO_DECOMPRESS(BPTR(buf), BLEN(buf), BPTR(&work), &zlen, - compctx->wu.lzo.wmem); + err =3D LZO_DECOMPRESS(BPTR(buf), BLEN(buf), BPTR(&work), &zlen, c= ompctx->wu.lzo.wmem); if (err !=3D LZO_E_OK) { dmsg(D_COMP_ERRORS, "LZO decompression error: %d", err); @@ -113,7 +111,7 @@ *buf =3D work; } - else if (c =3D=3D NO_COMPRESS_BYTE) /* packet was not compressed */ + else if (c =3D=3D NO_COMPRESS_BYTE) /* packet was not compressed */ { /* nothing to do */ } @@ -124,11 +122,6 @@ } } -const struct compress_alg lzo_alg =3D { - "lzo", - lzo_compress_init, - lzo_compress_uninit, - lzo_compress, - lzo_decompress -}; +const struct compress_alg lzo_alg =3D { "lzo", lzo_compress_init, lzo_comp= ress_uninit, lzo_compress, + lzo_decompress }; #endif /* ENABLE_LZO */ diff --git a/src/openvpn/lzo.h b/src/openvpn/lzo.h index 03da2af..d5bab54 100644 --- a/src/openvpn/lzo.h +++ b/src/openvpn/lzo.h @@ -57,19 +57,19 @@ extern const struct compress_alg lzo_alg; /*************************************************************************= */ -/** @name LZO library interface defines *//** @{ *//**********************= */ -#define LZO_COMPRESS lzo1x_1_15_compress +/** @name LZO library interface defines */ /** @{ */ /********************= ***/ +#define LZO_COMPRESS lzo1x_1_15_compress /**< LZO library compression function. * * Use \c lzo1x_1_15_compress because it * is described as faster than the * standard routine, although it does * need a bit more memory. */ -#define LZO_WORKSPACE LZO1X_1_15_MEM_COMPRESS +#define LZO_WORKSPACE LZO1X_1_15_MEM_COMPRESS /**< The size in bytes of the memory * %buffer required by the LZO library * compression algorithm. */ -#define LZO_DECOMPRESS lzo1x_decompress_safe +#define LZO_DECOMPRESS lzo1x_decompress_safe /**< LZO library decompression function. * * Use safe decompress because it @@ -79,26 +79,30 @@ * verify the integrity of incoming * packets, you might want to consider * using the non-safe version. */ -/** @} name LZO library interface *//*************************************= */ +/** @} name LZO library interface */ /************************************= **/ /*************************************************************************= */ -/** @name Adaptive compression defines *//** @{ *//***********************= */ -#define AC_SAMP_SEC 2 /**< Number of seconds in a sample period.= */ -#define AC_MIN_BYTES 1000 /**< Minimum number of bytes a sample - * period must contain for it to be - * evaluated. */ -#define AC_SAVE_PCT 5 /**< Minimum size reduction percentage - * below which compression will be - * turned off. */ -#define AC_OFF_SEC 60 /**< Seconds to wait after compression has - * been turned off before retesting. */ -/** @} name Adaptive compression defines *//******************************= */ +/** @name Adaptive compression defines */ /** @{ */ /*********************= ***/ +#define AC_SAMP_SEC 2 /**< Number of seconds= in a sample period. */ +#define AC_MIN_BYTES = \ + 1000 /**< Minimum number of= bytes a sample \ + * period must conta= in for it to be \ + * evaluated. */ +#define AC_SAVE_PCT = \ + 5 /**< Minimum size redu= ction percentage \ + * below which compr= ession will be \ + * turned off. */ +#define AC_OFF_SEC = \ + 60 /**< Seconds to wait a= fter compression has \ + * been turned off b= efore retesting. */ +/** @} name Adaptive compression defines */ /*********************= **********/ /** * Adaptive compression state. */ -struct lzo_adaptive_compress { +struct lzo_adaptive_compress +{ bool compress_state; time_t next; int n_total; diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 8836e79..40dcd62 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -75,7 +75,8 @@ msg(M_CLIENT, "auth-retry t : Auth failure retry mode (none,= interact,nointeract)."); msg(M_CLIENT, "bytecount n : Show bytes in/out, update ever= y n secs (0=3Doff)."); msg(M_CLIENT, "echo [on|off] [N|all] : Like log, but only show messag= es in echo buffer."); - msg(M_CLIENT, "cr-response response : Send a challenge response answ= er via CR_RESPONSE to server"); + msg(M_CLIENT, + "cr-response response : Send a challenge response answer via CR_= RESPONSE to server"); msg(M_CLIENT, "exit|quit : Close management session."); msg(M_CLIENT, "forget-passwords : Forget passwords entered so fa= r."); msg(M_CLIENT, "help : Print this message."); @@ -86,7 +87,8 @@ msg(M_CLIENT, "load-stats : Show global server load stats.= "); msg(M_CLIENT, "log [on|off] [N|all] : Turn on/off realtime log displ= ay"); msg(M_CLIENT, " + show last N lines or 'all' f= or entire history."); - msg(M_CLIENT, "mute [n] : Set log mute level to n, or sh= ow level if n is absent."); + msg(M_CLIENT, + "mute [n] : Set log mute level to n, or show level i= f n is absent."); msg(M_CLIENT, "needok type action : Enter confirmation for NEED-OK= request of 'type',"); msg(M_CLIENT, " where action =3D 'ok' or 'canc= el'."); msg(M_CLIENT, "needstr type action : Enter confirmation for NEED-ST= R request of 'type',"); @@ -104,18 +106,25 @@ #endif msg(M_CLIENT, "client-auth CID KID : Authenticate client-id/key-id = CID/KID (MULTILINE)"); msg(M_CLIENT, "client-auth-nt CID KID : Authenticate client-id/key-id = CID/KID"); - msg(M_CLIENT, "client-deny CID KID R [CR] : Deny auth client-id/key-id= CID/KID with log reason"); + msg(M_CLIENT, + "client-deny CID KID R [CR] : Deny auth client-id/key-id CID/KID w= ith log reason"); msg(M_CLIENT, " text R and optional client= reason text CR"); - msg(M_CLIENT, "client-pending-auth CID KID MSG timeout : Instruct Open= VPN to send AUTH_PENDING and INFO_PRE msg"); - msg(M_CLIENT, " to the client and= wait for a final client-auth/client-deny"); + msg(M_CLIENT, + "client-pending-auth CID KID MSG timeout : Instruct OpenVPN to sen= d AUTH_PENDING and INFO_PRE msg"); + msg(M_CLIENT, + " to the client and wait for = a final client-auth/client-deny"); msg(M_CLIENT, "client-kill CID [M] : Kill client instance CID with = message M (def=3DRESTART)"); msg(M_CLIENT, "env-filter [level] : Set env-var filter level"); msg(M_CLIENT, "rsa-sig : Enter a signature in response = to >RSA_SIGN challenge"); - msg(M_CLIENT, " Enter signature base64 on subs= equent lines followed by END"); + msg(M_CLIENT, + " Enter signature base64 on subsequent lin= es followed by END"); msg(M_CLIENT, "pk-sig : Enter a signature in response = to >PK_SIGN challenge"); - msg(M_CLIENT, " Enter signature base64 on subs= equent lines followed by END"); - msg(M_CLIENT, "certificate : Enter a client certificate in = response to >NEED-CERT challenge"); - msg(M_CLIENT, " Enter certificate base64 on su= bsequent lines followed by END"); + msg(M_CLIENT, + " Enter signature base64 on subsequent lin= es followed by END"); + msg(M_CLIENT, + "certificate : Enter a client certificate in response t= o >NEED-CERT challenge"); + msg(M_CLIENT, + " Enter certificate base64 on subsequent l= ines followed by END"); msg(M_CLIENT, "signal s : Send signal s to daemon,"); msg(M_CLIENT, " s =3D SIGHUP|SIGTERM|SIGUSR1|S= IGUSR2."); msg(M_CLIENT, "state [on|off] [N|all] : Like log, but show state histo= ry."); @@ -123,7 +132,8 @@ msg(M_CLIENT, "test n : Produce n lines of output for = testing/debugging."); msg(M_CLIENT, "username type u : Enter username u for a queried= OpenVPN username."); msg(M_CLIENT, "verb [n] : Set log verbosity level to n, = or show if n is absent."); - msg(M_CLIENT, "version [n] : Set client's version to n or s= how current version of daemon."); + msg(M_CLIENT, + "version [n] : Set client's version to n or show curren= t version of daemon."); msg(M_CLIENT, "END"); } @@ -306,7 +316,7 @@ man_delete_unix_socket(struct management *man) { #if UNIX_SOCK_SUPPORT - if ((man->settings.flags & (MF_UNIX_SOCK|MF_CONNECT_AS_CLIENT)) =3D=3D= MF_UNIX_SOCK) + if ((man->settings.flags & (MF_UNIX_SOCK | MF_CONNECT_AS_CLIENT)) =3D= =3D MF_UNIX_SOCK) { socket_delete_unix(&man->settings.local_unix); } @@ -332,11 +342,11 @@ static void virtual_output_callback_func(void *arg, const unsigned int flags, const ch= ar *str) { - struct management *man =3D (struct management *) arg; + struct management *man =3D (struct management *)arg; static int recursive_level =3D 0; /* GLOBAL */ -#define AF_DID_PUSH (1<<0) -#define AF_DID_RESET (1<<1) +#define AF_DID_PUSH (1 << 0) +#define AF_DID_RESET (1 << 1) if (recursive_level < 5) /* limit recursion */ { struct gc_arena gc =3D gc_new(); @@ -370,10 +380,10 @@ } else if (man->connection.log_realtime) { - out =3D log_entry_print(&e, LOG_PRINT_INT_DATE - | LOG_PRINT_MSG_FLAGS - | LOG_PRINT_LOG_PREFIX - | LOG_PRINT_CRLF, &gc); + out =3D log_entry_print(&e, + LOG_PRINT_INT_DATE | LOG_PRINT_MSG_F= LAGS + | LOG_PRINT_LOG_PREFIX | LOG_PRI= NT_CRLF, + &gc); } if (out) { @@ -382,11 +392,11 @@ } if (flags & M_FATAL) { - out =3D log_entry_print(&e, LOG_FATAL_NOTIFY|LOG_PRINT_CRL= F, &gc); + out =3D log_entry_print(&e, LOG_FATAL_NOTIFY | LOG_PRINT_C= RLF, &gc); if (out) { man_output_list_push_str(man, out); - action_flags |=3D (AF_DID_PUSH|AF_DID_RESET); + action_flags |=3D (AF_DID_PUSH | AF_DID_RESET); } } } @@ -408,7 +418,8 @@ { /* cannot use msg here */ printf("virtual_output: message to management interface " - "dropped due to recursion: <%s>\n", str); + "dropped due to recursion: <%s>\n", + str); } } @@ -472,7 +483,8 @@ static void man_command_unsupported(const char *command_name) { - msg(M_CLIENT, "ERROR: The '%s' command is not supported by the current= daemon mode", command_name); + msg(M_CLIENT, "ERROR: The '%s' command is not supported by the current= daemon mode", + command_name); } static void @@ -495,8 +507,7 @@ { man->connection.bytecount_update_seconds =3D update_seconds; event_timeout_init(&man->connection.bytecount_update_interval, - man->connection.bytecount_update_seconds, - now); + man->connection.bytecount_update_seconds, now); } else { @@ -507,8 +518,7 @@ } static void -man_bytecount_output_client(struct management *man, - counter_type dco_read_bytes, +man_bytecount_output_client(struct management *man, counter_type dco_read_= bytes, counter_type dco_write_bytes) { char in[32]; @@ -521,8 +531,7 @@ } void -man_bytecount_output_server(const counter_type *bytes_in_total, - const counter_type *bytes_out_total, +man_bytecount_output_server(const counter_type *bytes_in_total, const coun= ter_type *bytes_out_total, struct man_def_auth_context *mdac) { char in[32]; @@ -547,7 +556,7 @@ char p3[128]; int n_killed; - buf_set_read(&buf, (uint8_t *) victim, strlen(victim) + 1); + buf_set_read(&buf, (uint8_t *)victim, strlen(victim) + 1); buf_parse(&buf, ':', p1, sizeof(p1)); buf_parse(&buf, ':', p2, sizeof(p2)); buf_parse(&buf, ':', p3, sizeof(p3)); @@ -556,29 +565,29 @@ { /* IP:port specified */ bool status; - const in_addr_t addr =3D getaddr(GETADDR_HOST_ORDER|GETADDR_MS= G_VIRT_OUT, p2, 0, &status, NULL); + const in_addr_t addr =3D + getaddr(GETADDR_HOST_ORDER | GETADDR_MSG_VIRT_OUT, p2, 0, = &status, NULL); if (status) { const int port =3D atoi(p3); - const int proto =3D (streq(p1, "tcp")) ? PROTO_TCP_SERVER : - (streq(p1, "udp")) ? PROTO_UDP : PROTO_N= ONE; + const int proto =3D (streq(p1, "tcp")) ? PROTO_TCP_SERVER + : (streq(p1, "udp")) ? PROTO_UDP + : PROTO_NONE; if ((port > 0 && port < 65536) && (proto !=3D PROTO_NONE)) { - n_killed =3D (*man->persist.callback.kill_by_addr)(man= ->persist.callback.arg, addr, port, proto); + n_killed =3D (*man->persist.callback.kill_by_addr)(man= ->persist.callback.arg, + addr,= port, proto); if (n_killed > 0) { - msg(M_CLIENT, "SUCCESS: %d client(s) at address %s= :%s:%d killed", - n_killed, - proto2ascii(proto, AF_UNSPEC, false), - print_in_addr_t(addr, 0, &gc), + msg(M_CLIENT, "SUCCESS: %d client(s) at address %s= :%s:%d killed", n_killed, + proto2ascii(proto, AF_UNSPEC, false), print_in= _addr_t(addr, 0, &gc), port); } else { msg(M_CLIENT, "ERROR: client at address %s:%s:%d n= ot found", - proto2ascii(proto, AF_UNSPEC, false), - print_in_addr_t(addr, 0, &gc), + proto2ascii(proto, AF_UNSPEC, false), print_in= _addr_t(addr, 0, &gc), port); } } @@ -623,12 +632,8 @@ * for the log and echo commands. */ static void -man_history(struct management *man, - const char *parm, - const char *type, - struct log_history *log, - bool *realtime, - const unsigned int lep_flags) +man_history(struct management *man, const char *parm, const char *type, st= ruct log_history *log, + bool *realtime, const unsigned int lep_flags) { struct gc_arena gc =3D gc_new(); int n =3D 0; @@ -671,35 +676,22 @@ static void man_log(struct management *man, const char *parm) { - man_history(man, - parm, - "log", - man->persist.log, - &man->connection.log_realtime, - LOG_PRINT_INT_DATE|LOG_PRINT_MSG_FLAGS); + man_history(man, parm, "log", man->persist.log, &man->connection.log_r= ealtime, + LOG_PRINT_INT_DATE | LOG_PRINT_MSG_FLAGS); } static void man_echo(struct management *man, const char *parm) { - man_history(man, - parm, - "echo", - man->persist.echo, - &man->connection.echo_realtime, - LOG_PRINT_INT_DATE|MANAGEMENT_ECHO_FLAGS); + man_history(man, parm, "echo", man->persist.echo, &man->connection.ech= o_realtime, + LOG_PRINT_INT_DATE | MANAGEMENT_ECHO_FLAGS); } static void man_state(struct management *man, const char *parm) { - man_history(man, - parm, - "state", - man->persist.state, - &man->connection.state_realtime, - LOG_PRINT_INT_DATE|LOG_PRINT_STATE - |LOG_PRINT_LOCAL_IP|LOG_PRINT_REMOTE_IP); + man_history(man, parm, "state", man->persist.state, &man->connection.s= tate_realtime, + LOG_PRINT_INT_DATE | LOG_PRINT_STATE | LOG_PRINT_LOCAL_IP = | LOG_PRINT_REMOTE_IP); } static void @@ -733,13 +725,8 @@ } static void -man_query_user_pass(struct management *man, - const char *type, - const char *string, - const bool needed, - const char *prompt, - char *dest, - int len) +man_query_user_pass(struct management *man, const char *type, const char *= string, const bool needed, + const char *prompt, char *dest, int len) { if (needed) { @@ -748,16 +735,12 @@ { strncpynt(dest, string, len); man_up_finalize(man); - msg(M_CLIENT, "SUCCESS: '%s' %s entered, but not yet verified", - type, - prompt); + msg(M_CLIENT, "SUCCESS: '%s' %s entered, but not yet verified"= , type, prompt); } else { - msg(M_CLIENT, "ERROR: %s of type '%s' entered, but we need one= of type '%s'", - prompt, - type, - man->connection.up_query_type); + msg(M_CLIENT, "ERROR: %s of type '%s' entered, but we need one= of type '%s'", prompt, + type, man->connection.up_query_type); } } else @@ -769,36 +752,42 @@ static void man_query_username(struct management *man, const char *type, const char *s= tring) { - const bool needed =3D ((man->connection.up_query_mode =3D=3D UP_QUERY_= USER_PASS - ) && man->connection.up_query_type); - man_query_user_pass(man, type, string, needed, "username", man->connec= tion.up_query.username, USER_PASS_LEN); + const bool needed =3D + ((man->connection.up_query_mode =3D=3D UP_QUERY_USER_PASS) && man-= >connection.up_query_type); + man_query_user_pass(man, type, string, needed, "username", man->connec= tion.up_query.username, + USER_PASS_LEN); } static void man_query_password(struct management *man, const char *type, const char *s= tring) { const bool needed =3D ((man->connection.up_query_mode =3D=3D UP_QUERY_= PASS - || man->connection.up_query_mode =3D=3D UP_QUERY= _USER_PASS - ) && man->connection.up_query_type); + || man->connection.up_query_mode =3D=3D UP_QUERY= _USER_PASS) + && man->connection.up_query_type); if (!string[0]) /* allow blank passwords to be passed through using th= e blank_up tag */ { string =3D blank_up; } - man_query_user_pass(man, type, string, needed, "password", man->connec= tion.up_query.password, USER_PASS_LEN); + man_query_user_pass(man, type, string, needed, "password", man->connec= tion.up_query.password, + USER_PASS_LEN); } static void man_query_need_ok(struct management *man, const char *type, const char *ac= tion) { - const bool needed =3D ((man->connection.up_query_mode =3D=3D UP_QUERY_= NEED_OK) && man->connection.up_query_type); - man_query_user_pass(man, type, action, needed, "needok-confirmation", = man->connection.up_query.password, USER_PASS_LEN); + const bool needed =3D + ((man->connection.up_query_mode =3D=3D UP_QUERY_NEED_OK) && man->c= onnection.up_query_type); + man_query_user_pass(man, type, action, needed, "needok-confirmation", + man->connection.up_query.password, USER_PASS_LEN); } static void man_query_need_str(struct management *man, const char *type, const char *a= ction) { - const bool needed =3D ((man->connection.up_query_mode =3D=3D UP_QUERY_= NEED_STR) && man->connection.up_query_type); - man_query_user_pass(man, type, action, needed, "needstr-string", man->= connection.up_query.password, USER_PASS_LEN); + const bool needed =3D + ((man->connection.up_query_mode =3D=3D UP_QUERY_NEED_STR) && man->= connection.up_query_type); + man_query_user_pass(man, type, action, needed, "needstr-string", + man->connection.up_query.password, USER_PASS_LEN); } static void @@ -827,8 +816,8 @@ { if (man->persist.callback.send_cc_message) { - const bool status =3D (*man->persist.callback.send_cc_message) - (man->persist.callback.arg, message, param= eters); + const bool status =3D (*man->persist.callback.send_cc_message)(man= ->persist.callback.arg, + messa= ge, parameters); if (status) { msg(M_CLIENT, "SUCCESS: command succeeded"); @@ -893,13 +882,12 @@ { ASSERT(p1); - if (man->persist.callback.remote_entry_get - && man->persist.callback.remote_entry_count) + if (man->persist.callback.remote_entry_get && man->persist.callback.re= mote_entry_count) { unsigned int count =3D (*man->persist.callback.remote_entry_count)= (man->persist.callback.arg); - unsigned int from =3D (unsigned int) atoi(p1); - unsigned int to =3D p2 ? (unsigned int) atoi(p2) : from + 1; + unsigned int from =3D (unsigned int)atoi(p1); + unsigned int to =3D p2 ? (unsigned int)atoi(p2) : from + 1; if (!strcmp(p1, "all")) { @@ -910,7 +898,8 @@ for (unsigned int i =3D from; i < min_uint(to, count); i++) { char *remote =3D NULL; - bool res =3D (*man->persist.callback.remote_entry_get)(man->pe= rsist.callback.arg, i, &remote); + bool res =3D + (*man->persist.callback.remote_entry_get)(man->persist.cal= lback.arg, i, &remote); if (res && remote) { msg(M_CLIENT, "%u,%s", i, remote); @@ -956,8 +945,8 @@ } } -#define IER_RESET 0 -#define IER_NEW 1 +#define IER_RESET 0 +#define IER_NEW 1 static void in_extra_reset(struct man_connection *mc, const int mode) @@ -990,14 +979,9 @@ case IEC_CLIENT_AUTH: if (man->persist.callback.client_auth) { - const bool status =3D (*man->persist.callback.client_auth) - (man->persist.callback.arg, - man->connection.in_extra_cid, - man->connection.in_extra_kid, - true, - NULL, - NULL, - man->connection.in_extra); + const bool status =3D (*man->persist.callback.client_auth)( + man->persist.callback.arg, man->connection.in_extra_ci= d, + man->connection.in_extra_kid, true, NULL, NULL, man->c= onnection.in_extra); man->connection.in_extra =3D NULL; report_command_status(status, "client-auth"); } @@ -1064,9 +1048,8 @@ * @param timeout_str The timeout value in string form */ static void -man_client_pending_auth(struct management *man, const char *cid_str, - const char *kid_str, const char *extra, - const char *timeout_str) +man_client_pending_auth(struct management *man, const char *cid_str, const= char *kid_str, + const char *extra, const char *timeout_str) { unsigned long cid =3D 0; unsigned int kid =3D 0; @@ -1076,8 +1059,8 @@ { if (man->persist.callback.client_pending_auth) { - bool ret =3D (*man->persist.callback.client_pending_auth) - (man->persist.callback.arg, cid, kid, extra, ti= meout); + bool ret =3D (*man->persist.callback.client_pending_auth)(man-= >persist.callback.arg, cid, + kid, e= xtra, timeout); if (ret) { @@ -1086,7 +1069,7 @@ else { msg(M_CLIENT, "ERROR: client-pending-auth command failed." - " Extra parameter might be too long"); + " Extra parameter might be too long"); } } else @@ -1102,8 +1085,7 @@ struct man_connection *mc =3D &man->connection; mc->in_extra_cid =3D 0; mc->in_extra_kid =3D 0; - if (parse_cid(cid_str, &mc->in_extra_cid) - && parse_uint(kid_str, "KID", &mc->in_extra_kid)) + if (parse_cid(cid_str, &mc->in_extra_cid) && parse_uint(kid_str, "KID"= , &mc->in_extra_kid)) { mc->in_extra_cmd =3D IEC_CLIENT_AUTH; in_extra_reset(mc, IER_NEW); @@ -1115,7 +1097,8 @@ } static void -man_client_deny(struct management *man, const char *cid_str, const char *k= id_str, const char *reason, const char *client_reason) +man_client_deny(struct management *man, const char *cid_str, const char *k= id_str, + const char *reason, const char *client_reason) { unsigned long cid =3D 0; unsigned int kid =3D 0; @@ -1123,14 +1106,8 @@ { if (man->persist.callback.client_auth) { - const bool status =3D (*man->persist.callback.client_auth) - (man->persist.callback.arg, - cid, - kid, - false, - reason, - client_reason, - NULL); + const bool status =3D (*man->persist.callback.client_auth)( + man->persist.callback.arg, cid, kid, false, reason, client= _reason, NULL); if (status) { msg(M_CLIENT, "SUCCESS: client-deny command succeeded"); @@ -1155,7 +1132,8 @@ { if (man->persist.callback.kill_by_cid) { - const bool status =3D (*man->persist.callback.kill_by_cid)(man= ->persist.callback.arg, cid, kill_msg); + const bool status =3D + (*man->persist.callback.kill_by_cid)(man->persist.callback= .arg, cid, kill_msg); if (status) { msg(M_CLIENT, "SUCCESS: client-kill command succeeded"); @@ -1238,12 +1216,10 @@ nclients =3D (*man->persist.callback.n_clients)(man->persist.callb= ack.arg); } msg(M_CLIENT, "SUCCESS: nclients=3D%d,bytesin=3D" counter_format ",byt= esout=3D" counter_format, - nclients, - link_read_bytes_global, - link_write_bytes_global); + nclients, link_read_bytes_global, link_write_bytes_global); } -#define MN_AT_LEAST (1<<0) +#define MN_AT_LEAST (1 << 0) /** * Checks if the correct number of arguments to a management command are p= resent * and otherwise prints an error and returns false. @@ -1263,11 +1239,8 @@ { if (!p[i]) { - msg(M_CLIENT, "ERROR: the '%s' command requires %s%d parameter= %s", - p[0], - (flags & MN_AT_LEAST) ? "at least " : "", - n, - n > 1 ? "s" : ""); + msg(M_CLIENT, "ERROR: the '%s' command requires %s%d parameter= %s", p[0], + (flags & MN_AT_LEAST) ? "at least " : "", n, n > 1 ? "s" := ""); return false; } } @@ -1313,8 +1286,7 @@ */ if (man->persist.callback.network_change) { - int fd =3D (*man->persist.callback.network_change) - (man->persist.callback.arg, samenetwork); + int fd =3D (*man->persist.callback.network_change)(man->persist.ca= llback.arg, samenetwork); man->connection.fdtosend =3D fd; msg(M_CLIENT, "PROTECTFD: fd '%d' sent to be protected", fd); if (fd =3D=3D -2) @@ -1335,7 +1307,8 @@ } static void -man_dispatch_command(struct management *man, struct status_output *so, con= st char **p, const int nparms) +man_dispatch_command(struct management *man, struct status_output *so, con= st char **p, + const int nparms) { struct gc_arena gc =3D gc_new(); @@ -1665,7 +1638,8 @@ const int n =3D atoi(p[1]); for (i =3D 0; i < n; ++i) { - msg(M_CLIENT, "[%d] The purpose of this command is to gene= rate large amounts of output.", i); + msg(M_CLIENT, + "[%d] The purpose of this command is to generate large= amounts of output.", i); } } } @@ -1692,7 +1666,8 @@ case MS_CC_WAIT_READ: case MS_CC_WAIT_WRITE: - net_event_win32_start(&man->connection.ne32, FD_READ|FD_WRITE|= FD_CLOSE, man->connection.sd_cli); + net_event_win32_start(&man->connection.ne32, FD_READ | FD_WRIT= E | FD_CLOSE, + man->connection.sd_cli); break; default: @@ -1737,27 +1712,24 @@ #if UNIX_SOCK_SUPPORT if (man->settings.flags & MF_UNIX_SOCK) { - msg(D_MANAGEMENT, "MANAGEMENT: %s %s", - description, + msg(D_MANAGEMENT, "MANAGEMENT: %s %s", description, sockaddr_unix_name(&man->settings.local_unix, "NULL")); } else #endif - if (man->settings.flags & MF_CONNECT_AS_CLIENT) + if (man->settings.flags & MF_CONNECT_AS_CLIENT) { - msg(D_MANAGEMENT, "MANAGEMENT: %s %s", - description, + msg(D_MANAGEMENT, "MANAGEMENT: %s %s", description, print_sockaddr(man->settings.local->ai_addr, &gc)); } else { struct sockaddr_storage addr; socklen_t addrlen =3D sizeof(addr); - if (!getpeername(man->connection.sd_cli, (struct sockaddr *) &addr, - &addrlen)) + if (!getpeername(man->connection.sd_cli, (struct sockaddr *)&addr,= &addrlen)) { msg(D_MANAGEMENT, "MANAGEMENT: %s %s", description, - print_sockaddr((struct sockaddr *) &addr, &gc)); + print_sockaddr((struct sockaddr *)&addr, &gc)); } else { @@ -1783,19 +1755,22 @@ { if (socket_defined(sd) && (man->settings.client_uid !=3D -1 || man->se= ttings.client_gid !=3D -1)) { - static const char err_prefix[] =3D "MANAGEMENT: unix domain socket= client connection rejected --"; + static const char err_prefix[] =3D + "MANAGEMENT: unix domain socket client connection rejected --"; int uid, gid; if (unix_socket_get_peer_uid_gid(man->connection.sd_cli, &uid, &gi= d)) { if (man->settings.client_uid !=3D -1 && man->settings.client_u= id !=3D uid) { - msg(D_MANAGEMENT, "%s UID of socket peer (%d) doesn't matc= h required value (%d) as given by --management-client-user", + msg(D_MANAGEMENT, + "%s UID of socket peer (%d) doesn't match required val= ue (%d) as given by --management-client-user", err_prefix, uid, man->settings.client_uid); return false; } if (man->settings.client_gid !=3D -1 && man->settings.client_g= id !=3D gid) { - msg(D_MANAGEMENT, "%s GID of socket peer (%d) doesn't matc= h required value (%d) as given by --management-client-group", + msg(D_MANAGEMENT, + "%s GID of socket peer (%d) doesn't match required val= ue (%d) as given by --management-client-group", err_prefix, gid, man->settings.client_gid); return false; } @@ -1877,8 +1852,8 @@ #endif { man->connection.sd_top =3D create_socket_tcp(man->settings.loc= al); - socket_bind(man->connection.sd_top, man->settings.local, - man->settings.local->ai_family, "MANAGEMENT", fals= e); + socket_bind(man->connection.sd_top, man->settings.local, man->= settings.local->ai_family, + "MANAGEMENT", false); } /* @@ -1906,14 +1881,13 @@ const struct sockaddr *man_addr =3D man->settings.local->ai_ad= dr; struct sockaddr_storage addr; socklen_t addrlen =3D sizeof(addr); - if (!getsockname(man->connection.sd_top, (struct sockaddr *) &= addr, &addrlen)) + if (!getsockname(man->connection.sd_top, (struct sockaddr *)&a= ddr, &addrlen)) { - man_addr =3D (struct sockaddr *) &addr; + man_addr =3D (struct sockaddr *)&addr; } else { - msg(M_WARN|M_ERRNO, - "Failed to get the management socket address"); + msg(M_WARN | M_ERRNO, "Failed to get the management socket= address"); } msg(D_MANAGEMENT, "MANAGEMENT: TCP Socket listening on %s", print_sockaddr(man_addr, &gc)); @@ -1959,9 +1933,7 @@ #endif { man->connection.sd_cli =3D create_socket_tcp(man->settings.local); - status =3D openvpn_connect(man->connection.sd_cli, - man->settings.local->ai_addr, - 5, + status =3D openvpn_connect(man->connection.sd_cli, man->settings.l= ocal->ai_addr, 5, &signal_received); } @@ -1976,15 +1948,13 @@ #if UNIX_SOCK_SUPPORT if (man->settings.flags & MF_UNIX_SOCK) { - msg(D_LINK_ERRORS | M_ERRNO, - "MANAGEMENT: connect to unix socket %s failed", + msg(D_LINK_ERRORS | M_ERRNO, "MANAGEMENT: connect to unix sock= et %s failed", sockaddr_unix_name(&man->settings.local_unix, "NULL")); } else #endif { - msg(D_LINK_ERRORS | M_ERRNO, - "MANAGEMENT: connect to %s failed", + msg(D_LINK_ERRORS | M_ERRNO, "MANAGEMENT: connect to %s failed= ", print_sockaddr(man->settings.local->ai_addr, &gc)); } throw_signal_soft(SIGTERM, "management-connect-failed"); @@ -2049,7 +2019,7 @@ struct gc_arena gc =3D gc_new(); struct status_output *so; int nparms; - char *parms[MAX_PARMS+1]; + char *parms[MAX_PARMS + 1]; CLEAR(parms); so =3D status_open(NULL, 0, -1, &man->persist.vout, 0); @@ -2102,8 +2072,7 @@ if (!ignore_sys_error(err, crt_error)) { struct gc_arena gc =3D gc_new(); - msg(D_MANAGEMENT, "MANAGEMENT: TCP %s error: %s", prefix, - strerror(err)); + msg(D_MANAGEMENT, "MANAGEMENT: TCP %s error: %s", prefix, strerror= (err)); gc_free(&gc); return true; } @@ -2120,7 +2089,8 @@ struct msghdr msg =3D { 0 }; struct iovec iov[1]; - union { + union + { struct cmsghdr cm; char control[CMSG_SPACE(sizeof(int))]; } control_un; @@ -2133,7 +2103,7 @@ cmptr->cmsg_len =3D CMSG_LEN(sizeof(int)); cmptr->cmsg_level =3D SOL_SOCKET; cmptr->cmsg_type =3D SCM_RIGHTS; - *((int *) CMSG_DATA(cmptr)) =3D sendfd; + *((int *)CMSG_DATA(cmptr)) =3D sendfd; msg.msg_name =3D NULL; msg.msg_namelen =3D 0; @@ -2153,13 +2123,14 @@ struct iovec iov[1]; ssize_t n; - union { + union + { struct cmsghdr cm; char control[CMSG_SPACE(sizeof(int))]; } control_un; - struct cmsghdr *cmptr; + struct cmsghdr *cmptr; - msghdr.msg_control =3D control_un.control; + msghdr.msg_control =3D control_un.control; msghdr.msg_controllen =3D sizeof(control_un.control); msghdr.msg_name =3D NULL; @@ -2170,13 +2141,12 @@ msghdr.msg_iov =3D iov; msghdr.msg_iovlen =3D 1; - if ( (n =3D recvmsg(fd, &msghdr, flags)) <=3D 0) + if ((n =3D recvmsg(fd, &msghdr, flags)) <=3D 0) { return (n); } - if ( (cmptr =3D CMSG_FIRSTHDR(&msghdr)) !=3D NULL - && cmptr->cmsg_len =3D=3D CMSG_LEN(sizeof(int))) + if ((cmptr =3D CMSG_FIRSTHDR(&msghdr)) !=3D NULL && cmptr->cmsg_len = =3D=3D CMSG_LEN(sizeof(int))) { if (cmptr->cmsg_level !=3D SOL_SOCKET) { @@ -2186,12 +2156,11 @@ { msg(M_ERR, "control type !=3D SCM_RIGHTS"); } - *recvfd =3D *((int *) CMSG_DATA(cmptr)); + *recvfd =3D *((int *)CMSG_DATA(cmptr)); } else { - *recvfd =3D -1; /* descriptor was not passed */ - + *recvfd =3D -1; /* descriptor was not passed */ } return (n); } @@ -2209,10 +2178,10 @@ } struct user_pass up; CLEAR(up); - strncpy(up.username, msg, sizeof(up.username)-1); + strncpy(up.username, msg, sizeof(up.username) - 1); - management_query_user_pass(management, &up, command, GET_USER_PASS_NEE= D_OK, (void *) 0); - return strcmp("ok", up.password)=3D=3D0; + management_query_user_pass(management, &up, command, GET_USER_PASS_NEE= D_OK, (void *)0); + return strcmp("ok", up.password) =3D=3D 0; } /* @@ -2227,8 +2196,8 @@ struct user_pass up; CLEAR(up); strcpy(up.username, "tunmethod"); - management_query_user_pass(management, &up, "PERSIST_TUN_ACTION", - GET_USER_PASS_NEED_OK, (void *) 0); + management_query_user_pass(management, &up, "PERSIST_TUN_ACTION", GET_= USER_PASS_NEED_OK, + (void *)0); if (!strcmp("NOACTION", up.password)) { return ANDROID_KEEP_OLD_TUN; @@ -2239,7 +2208,8 @@ } else { - msg(M_ERR, "Got unrecognised '%s' from management for PERSIST_TUN_= ACTION query", up.password); + msg(M_ERR, "Got unrecognised '%s' from management for PERSIST_TUN_= ACTION query", + up.password); } ASSERT(0); @@ -2265,7 +2235,7 @@ { man->connection.lastfdreceived =3D fd; } -#else /* ifdef TARGET_ANDROID */ +#else /* ifdef TARGET_ANDROID */ len =3D recv(man->connection.sd_cli, (void *)buf, sizeof(buf), MSG_NOS= IGNAL); #endif @@ -2277,7 +2247,7 @@ { bool processed_command =3D false; - ASSERT(len <=3D (int) sizeof(buf)); + ASSERT(len <=3D (int)sizeof(buf)); command_line_add(man->connection.in, buf, len); /* @@ -2305,7 +2275,7 @@ } else { - man_process_command(man, (char *) line); + man_process_command(man, (char *)line); } if (man->connection.halt) { @@ -2358,12 +2328,13 @@ #ifdef TARGET_ANDROID if (man->connection.fdtosend > 0) { - sent =3D man_send_with_fd(man->connection.sd_cli, BPTR(buf), l= en, MSG_NOSIGNAL, man->connection.fdtosend); + sent =3D man_send_with_fd(man->connection.sd_cli, BPTR(buf), l= en, MSG_NOSIGNAL, + man->connection.fdtosend); man->connection.fdtosend =3D -1; } else #endif - sent =3D send(man->connection.sd_cli, (const void *)BPTR(buf), len= , MSG_NOSIGNAL); + sent =3D send(man->connection.sd_cli, (const void *)BPTR(buf),= len, MSG_NOSIGNAL); if (sent >=3D 0) { buffer_list_advance(man->connection.out, sent); @@ -2399,9 +2370,7 @@ } static void -man_persist_init(struct management *man, - const int log_history_cache, - const int echo_buffer_size, +man_persist_init(struct management *man, const int log_history_cache, cons= t int echo_buffer_size, const int state_buffer_size) { struct man_persist *mp =3D &man->persist; @@ -2459,17 +2428,10 @@ } static void -man_settings_init(struct man_settings *ms, - const char *addr, - const char *port, - const char *pass_file, - const char *client_user, - const char *client_group, - const int log_history_cache, - const int echo_buffer_size, - const int state_buffer_size, - const int remap_sigusr1, - const unsigned int flags) +man_settings_init(struct man_settings *ms, const char *addr, const char *p= ort, + const char *pass_file, const char *client_user, const ch= ar *client_group, + const int log_history_cache, const int echo_buffer_size, + const int state_buffer_size, const int remap_sigusr1, co= nst unsigned int flags) { if (!ms->defined) { @@ -2515,7 +2477,6 @@ else #endif { - /* * Run management over tunnel, or * separate channel? @@ -2527,16 +2488,16 @@ else { int status; - int resolve_flags =3D GETADDR_RESOLVE|GETADDR_WARN_ON_SIGN= AL|GETADDR_FATAL; + int resolve_flags =3D GETADDR_RESOLVE | GETADDR_WARN_ON_SI= GNAL | GETADDR_FATAL; if (!(flags & MF_CONNECT_AS_CLIENT)) { resolve_flags |=3D GETADDR_PASSIVE; } - status =3D openvpn_getaddrinfo(resolve_flags, addr, port, = 0, - NULL, AF_UNSPEC, &ms->local); - ASSERT(status=3D=3D0); + status =3D + openvpn_getaddrinfo(resolve_flags, addr, port, 0, NULL= , AF_UNSPEC, &ms->local); + ASSERT(status =3D=3D 0); } } @@ -2654,9 +2615,7 @@ struct management *man; ALLOC_OBJ_CLEAR(man, struct management); - man_persist_init(man, - MANAGEMENT_LOG_HISTORY_INITIAL_SIZE, - MANAGEMENT_ECHO_BUFFER_SIZE, + man_persist_init(man, MANAGEMENT_LOG_HISTORY_INITIAL_SIZE, MANAGEMENT_= ECHO_BUFFER_SIZE, MANAGEMENT_STATE_BUFFER_SIZE); man_connection_clear(&man->connection); @@ -2665,16 +2624,9 @@ } bool -management_open(struct management *man, - const char *addr, - const char *port, - const char *pass_file, - const char *client_user, - const char *client_group, - const int log_history_cache, - const int echo_buffer_size, - const int state_buffer_size, - const int remap_sigusr1, +management_open(struct management *man, const char *addr, const char *port= , const char *pass_file, + const char *client_user, const char *client_group, const i= nt log_history_cache, + const int echo_buffer_size, const int state_buffer_size, c= onst int remap_sigusr1, const unsigned int flags) { bool ret =3D false; @@ -2683,17 +2635,8 @@ * Save the settings only if they have not * been saved before. */ - man_settings_init(&man->settings, - addr, - port, - pass_file, - client_user, - client_group, - log_history_cache, - echo_buffer_size, - state_buffer_size, - remap_sigusr1, - flags); + man_settings_init(&man->settings, addr, port, pass_file, client_user, = client_group, + log_history_cache, echo_buffer_size, state_buffer_si= ze, remap_sigusr1, flags); /* * The log is initially sized to MANAGEMENT_LOG_HISTORY_INITIAL_SIZE, @@ -2730,8 +2673,7 @@ } void -management_set_callback(struct management *man, - const struct management_callback *cb) +management_set_callback(struct management *man, const struct management_ca= llback *cb) { man->persist.standalone_disabled =3D true; man->persist.callback =3D *cb; @@ -2747,15 +2689,12 @@ } 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) +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 op= envpn_sockaddr *remote) { - if (man->persist.state && (!(man->settings.flags & MF_SERVER) || state= < OPENVPN_STATE_CLIENT_BASE)) + if (man->persist.state + && (!(man->settings.flags & MF_SERVER) || state < OPENVPN_STATE_CL= IENT_BASE)) { struct gc_arena gc =3D gc_new(); struct log_entry e; @@ -2787,13 +2726,11 @@ if (man->connection.state_realtime) { - out =3D log_entry_print(&e, LOG_PRINT_STATE_PREFIX - | LOG_PRINT_INT_DATE - | LOG_PRINT_STATE - | LOG_PRINT_LOCAL_IP - | LOG_PRINT_REMOTE_IP - | LOG_PRINT_CRLF - | LOG_ECHO_TO_LOG, &gc); + out =3D log_entry_print(&e, + LOG_PRINT_STATE_PREFIX | LOG_PRINT_INT_D= ATE | LOG_PRINT_STATE + | LOG_PRINT_LOCAL_IP | LOG_PRINT_REM= OTE_IP | LOG_PRINT_CRLF + | LOG_ECHO_TO_LOG, + &gc); } if (out) @@ -2808,25 +2745,23 @@ static bool env_filter_match(const char *env_str, const int env_filter_level) { - static const char *env_names[] =3D { - "username=3D", - "password=3D", - "X509_0_CN=3D", - "tls_serial_", - "untrusted_ip=3D", - "ifconfig_local=3D", - "ifconfig_netmask=3D", - "daemon_start_time=3D", - "daemon_pid=3D", - "dev=3D", - "ifconfig_pool_remote_ip=3D", - "ifconfig_pool_netmask=3D", - "time_duration=3D", - "bytes_sent=3D", - "bytes_received=3D", - "session_id=3D", - "session_state=3D" - }; + static const char *env_names[] =3D { "username=3D", + "password=3D", + "X509_0_CN=3D", + "tls_serial_", + "untrusted_ip=3D", + "ifconfig_local=3D", + "ifconfig_netmask=3D", + "daemon_start_time=3D", + "daemon_pid=3D", + "dev=3D", + "ifconfig_pool_remote_ip=3D", + "ifconfig_pool_netmask=3D", + "time_duration=3D", + "bytes_sent=3D", + "bytes_received=3D", + "session_id=3D", + "session_state=3D" }; if (env_filter_level =3D=3D 0) { @@ -2854,7 +2789,8 @@ } static void -man_output_env(const struct env_set *es, const bool tail, const int env_fi= lter_level, const char *prefix) +man_output_env(const struct env_set *es, const bool tail, const int env_fi= lter_level, + const char *prefix) { if (es) { @@ -2915,11 +2851,12 @@ char line[256]; if (man->persist.callback.get_peer_info) { - const char *peer_info =3D (*man->persist.callback.get_peer_info)(m= an->persist.callback.arg, mdac->cid); + const char *peer_info =3D + (*man->persist.callback.get_peer_info)(man->persist.callback.a= rg, mdac->cid); if (peer_info) { struct buffer buf; - buf_set_read(&buf, (const uint8_t *) peer_info, strlen(peer_in= fo)); + buf_set_read(&buf, (const uint8_t *)peer_info, strlen(peer_inf= o)); while (buf_parse(&buf, '\n', line, sizeof(line))) { chomp(line); @@ -2937,10 +2874,8 @@ } void -management_notify_client_needing_auth(struct management *management, - const unsigned int mda_key_id, - struct man_def_auth_context *mdac, - const struct env_set *es) +management_notify_client_needing_auth(struct management *management, const= unsigned int mda_key_id, + struct man_def_auth_context *mdac, c= onst struct env_set *es) { if (!(mdac->flags & DAF_CONNECTION_CLOSED)) { @@ -2951,7 +2886,7 @@ } msg(M_CLIENT, ">CLIENT:%s,%lu,%u", mode, mdac->cid, mda_key_id); man_output_extra_env(management, "CLIENT"); - if (management->connection.env_filter_level>0) + if (management->connection.env_filter_level > 0) { man_output_peer_info_env(management, mdac); } @@ -2961,18 +2896,15 @@ } void -management_notify_client_cr_response(unsigned mda_key_id, - const struct man_def_auth_context *md= ac, - const struct env_set *es, - const char *response) +management_notify_client_cr_response(unsigned mda_key_id, const struct man= _def_auth_context *mdac, + const struct env_set *es, const char = *response) { struct gc_arena gc; if (management) { gc =3D gc_new(); - msg(M_CLIENT, ">CLIENT:CR_RESPONSE,%lu,%u,%s", - mdac->cid, mda_key_id, response); + msg(M_CLIENT, ">CLIENT:CR_RESPONSE,%lu,%u,%s", mdac->cid, mda_key_= id, response); man_output_extra_env(management, "CLIENT"); if (management->connection.env_filter_level > 0) { @@ -2984,8 +2916,7 @@ } void -management_connection_established(struct management *management, - struct man_def_auth_context *mdac, +management_connection_established(struct management *management, struct ma= n_def_auth_context *mdac, const struct env_set *es) { mdac->flags |=3D DAF_CONNECTION_ESTABLISHED; @@ -2995,8 +2926,7 @@ } void -management_notify_client_close(struct management *management, - struct man_def_auth_context *mdac, +management_notify_client_close(struct management *management, struct man_d= ef_auth_context *mdac, const struct env_set *es) { if ((mdac->flags & DAF_INITIAL_AUTH) && !(mdac->flags & DAF_CONNECTION= _CLOSED)) @@ -3008,18 +2938,14 @@ } void -management_learn_addr(struct management *management, - struct man_def_auth_context *mdac, - const struct mroute_addr *addr, - const bool primary) +management_learn_addr(struct management *management, struct man_def_auth_c= ontext *mdac, + const struct mroute_addr *addr, const bool primary) { struct gc_arena gc =3D gc_new(); if ((mdac->flags & DAF_INITIAL_AUTH) && !(mdac->flags & DAF_CONNECTION= _CLOSED)) { - msg(M_CLIENT, ">CLIENT:ADDRESS,%lu,%s,%d", - mdac->cid, - mroute_addr_print_ex(addr, MAPF_SUBNET, &gc), - BOOL_CAST(primary)); + msg(M_CLIENT, ">CLIENT:ADDRESS,%lu,%s,%d", mdac->cid, + mroute_addr_print_ex(addr, MAPF_SUBNET, &gc), BOOL_CAST(primar= y)); } gc_free(&gc); } @@ -3043,7 +2969,10 @@ if (man->connection.echo_realtime) { - out =3D log_entry_print(&e, LOG_PRINT_INT_DATE|LOG_PRINT_ECHO_= PREFIX|LOG_PRINT_CRLF|MANAGEMENT_ECHO_FLAGS, &gc); + out =3D log_entry_print(&e, + LOG_PRINT_INT_DATE | LOG_PRINT_ECHO_PREF= IX | LOG_PRINT_CRLF + | MANAGEMENT_ECHO_FLAGS, + &gc); } if (out) @@ -3062,8 +2991,7 @@ * If we are running management over the tunnel, * this is the place to initialize the connection. */ - if (man->settings.management_over_tunnel - && man->connection.state =3D=3D MS_INITIAL) + if (man->settings.management_over_tunnel && man->connection.state =3D= =3D MS_INITIAL) { /* listen on our local TUN/TAP IP address */ struct in_addr ia; @@ -3072,12 +3000,11 @@ ia.s_addr =3D htonl(tun_local_ip); inet_ntop(AF_INET, &ia, buf, sizeof(buf)); - ret =3D openvpn_getaddrinfo(GETADDR_PASSIVE, buf, NULL, 0, NULL, - AF_INET, &man->settings.local); - ASSERT(ret=3D=3D0); + ret =3D + openvpn_getaddrinfo(GETADDR_PASSIVE, buf, NULL, 0, NULL, AF_IN= ET, &man->settings.local); + ASSERT(ret =3D=3D 0); man_connection_init(man); } - } void @@ -3125,9 +3052,7 @@ #ifdef _WIN32 void -management_socket_set(struct management *man, - struct event_set *es, - void *arg, +management_socket_set(struct management *man, struct event_set *es, void *= arg, unsigned int *persistent) { if (man->connection.state !=3D MS_INITIAL) @@ -3154,7 +3079,7 @@ case MS_CC_WAIT_WRITE: if (man_persist_state(persistent, 3)) { - event_ctl(es, ev, EVENT_READ|EVENT_WRITE, arg); + event_ctl(es, ev, EVENT_READ | EVENT_WRITE, arg); } break; @@ -3187,7 +3112,8 @@ net_event_win32_clear_selected_events(&man->connection= .ne32, FD_ACCEPT); } } - else if (man->connection.state =3D=3D MS_CC_WAIT_READ || man->= connection.state =3D=3D MS_CC_WAIT_WRITE) + else if (man->connection.state =3D=3D MS_CC_WAIT_READ + || man->connection.state =3D=3D MS_CC_WAIT_WRITE) { if (net_events & FD_READ) { @@ -3214,9 +3140,7 @@ #else /* ifdef _WIN32 */ void -management_socket_set(struct management *man, - struct event_set *es, - void *arg, +management_socket_set(struct management *man, struct event_set *es, void *= arg, unsigned int *persistent) { switch (man->connection.state) @@ -3383,7 +3307,8 @@ * Process management event loop outside primary event loop */ static int -man_standalone_event_loop(struct management *man, volatile int *signal_rec= eived, const time_t expire) +man_standalone_event_loop(struct management *man, volatile int *signal_rec= eived, + const time_t expire) { int status =3D -1; if (man_standalone_ok(man)) @@ -3397,18 +3322,16 @@ return status; } -#define MWCC_PASSWORD_WAIT (1<<0) -#define MWCC_HOLD_WAIT (1<<1) -#define MWCC_OTHER_WAIT (1<<2) +#define MWCC_PASSWORD_WAIT (1 << 0) +#define MWCC_HOLD_WAIT (1 << 1) +#define MWCC_OTHER_WAIT (1 << 2) /* * Block until client connects */ static void -man_wait_for_client_connection(struct management *man, - volatile int *signal_received, - const time_t expire, - unsigned int flags) +man_wait_for_client_connection(struct management *man, volatile int *signa= l_received, + const time_t expire, unsigned int flags) { ASSERT(man_standalone_ok(man)); if (man->connection.state =3D=3D MS_LISTEN) @@ -3493,11 +3416,8 @@ * Get a username/password from management channel in standalone mode. */ bool -management_query_user_pass(struct management *man, - struct user_pass *up, - const char *type, - const unsigned int flags, - const char *static_challenge) +management_query_user_pass(struct management *man, struct user_pass *up, c= onst char *type, + const unsigned int flags, const char *static_ch= allenge) { struct gc_arena gc =3D gc_new(); bool ret =3D false; @@ -3546,10 +3466,7 @@ sc =3D static_challenge; } } - buf_printf(&alert_msg, ">%s:Need '%s' %s", - prefix, - type, - alert_type); + buf_printf(&alert_msg, ">%s:Need '%s' %s", prefix, type, alert_typ= e); if (flags & (GET_USER_PASS_NEED_OK | GET_USER_PASS_NEED_STR)) { @@ -3560,7 +3477,7 @@ { buf_printf(&alert_msg, " SC:%d,%s", BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_EC= HO) - |(BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_= CONCAT) << 1), + | (BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALL= ENGE_CONCAT) << 1), sc); } @@ -3625,8 +3542,8 @@ } static int -management_query_multiline(struct management *man, - const char *b64_data, const char *prompt, const= char *cmd, int *state, struct buffer_list **input) +management_query_multiline(struct management *man, const char *b64_data, c= onst char *prompt, + const char *cmd, int *state, struct buffer_list= **input) { struct gc_arena gc =3D gc_new(); int ret =3D 0; @@ -3645,12 +3562,12 @@ =20 if (b64_data) { - alert_msg =3D alloc_buf_gc(strlen(b64_data)+strlen(prompt)+3, = &gc); + alert_msg =3D alloc_buf_gc(strlen(b64_data) + strlen(prompt) += 3, &gc); buf_printf(&alert_msg, ">%s:%s", prompt, b64_data); } else { - alert_msg =3D alloc_buf_gc(strlen(prompt)+3, &gc); + alert_msg =3D alloc_buf_gc(strlen(prompt) + 3, &gc); buf_printf(&alert_msg, ">%s", prompt); } @@ -3703,8 +3620,9 @@ static char * /* returns allocated base64 signature */ -management_query_multiline_flatten_newline(struct management *man, - const char *b64_data, const cha= r *prompt, const char *cmd, int *state, struct buffer_list **input) +management_query_multiline_flatten_newline(struct management *man, const c= har *b64_data, + const char *prompt, const char = *cmd, int *state, + struct buffer_list **input) { int ok; char *result =3D NULL; @@ -3717,7 +3635,7 @@ buf =3D buffer_list_peek(*input); if (buf && BLEN(buf) > 0) { - result =3D (char *) malloc(BLEN(buf)+1); + result =3D (char *)malloc(BLEN(buf) + 1); check_malloc_return(result); memcpy(result, buf->data, BLEN(buf)); result[BLEN(buf)] =3D '\0'; @@ -3732,8 +3650,8 @@ static char * /* returns allocated base64 signature */ -management_query_multiline_flatten(struct management *man, - const char *b64_data, const char *promp= t, const char *cmd, int *state, struct buffer_list **input) +management_query_multiline_flatten(struct management *man, const char *b64= _data, const char *prompt, + const char *cmd, int *state, struct buf= fer_list **input) { int ok; char *result =3D NULL; @@ -3746,7 +3664,7 @@ buf =3D buffer_list_peek(*input); if (buf && BLEN(buf) > 0) { - result =3D (char *) malloc(BLEN(buf)+1); + result =3D (char *)malloc(BLEN(buf) + 1); check_malloc_return(result); memcpy(result, buf->data, BLEN(buf)); result[BLEN(buf)] =3D '\0'; @@ -3761,8 +3679,7 @@ char * /* returns allocated base64 signature */ -management_query_pk_sig(struct management *man, const char *b64_data, - const char *algorithm) +management_query_pk_sig(struct management *man, const char *b64_data, cons= t char *algorithm) { const char *prompt =3D "PK_SIGN"; const char *desc =3D "pk-sign"; @@ -3774,15 +3691,15 @@ desc =3D "rsa-sign"; } - buf_write(&buf_data, b64_data, (int) strlen(b64_data)); + buf_write(&buf_data, b64_data, (int)strlen(b64_data)); if (man->connection.client_version > 2) { - buf_write(&buf_data, ",", (int) strlen(",")); - buf_write(&buf_data, algorithm, (int) strlen(algorithm)); + buf_write(&buf_data, ",", (int)strlen(",")); + buf_write(&buf_data, algorithm, (int)strlen(algorithm)); } - char *ret =3D management_query_multiline_flatten(man, - (char *)buf_bptr(&buf_d= ata), prompt, desc, - &man->connection.ext_ke= y_state, &man->connection.ext_key_input); + char *ret =3D management_query_multiline_flatten(man, (char *)buf_bptr= (&buf_data), prompt, desc, + &man->connection.ext_ke= y_state, + &man->connection.ext_ke= y_input); free_buf(&buf_data); return ret; } @@ -3793,12 +3710,12 @@ const char prompt_1[] =3D "NEED-CERTIFICATE:"; struct buffer buf_prompt =3D alloc_buf(strlen(cert_name) + 20); buf_write(&buf_prompt, prompt_1, strlen(prompt_1)); - buf_write(&buf_prompt, cert_name, strlen(cert_name)+1); /* +1 for \0 */ + buf_write(&buf_prompt, cert_name, strlen(cert_name) + 1); /* +1 for \0= */ char *result; - result =3D management_query_multiline_flatten_newline(management, - NULL, (char *)buf_= bptr(&buf_prompt), "certificate", - &man->connection.e= xt_cert_state, &man->connection.ext_cert_input); + result =3D management_query_multiline_flatten_newline( + management, NULL, (char *)buf_bptr(&buf_prompt), "certificate", + &man->connection.ext_cert_state, &man->connection.ext_cert_input); free_buf(&buf_prompt); return result; } @@ -3825,7 +3742,8 @@ const bool standalone_disabled_save =3D man->persist.standalone_di= sabled; struct gc_arena gc =3D gc_new(); - man->persist.standalone_disabled =3D false; /* This is so M_CLIENT= messages will be correctly passed through msg() */ + man->persist.standalone_disabled =3D + false; /* This is so M_CLIENT messages will be correctly passe= d through msg() */ man->persist.special_state_msg =3D NULL; man->settings.mansig |=3D MANSIG_IGNORE_USR1_HUP; =20 @@ -3904,7 +3822,7 @@ int i; for (i =3D 0; i < len; ++i) { - if (buf[i] && char_class(buf[i], (CC_PRINT|CC_NEWLINE))) + if (buf[i] && char_class(buf[i], (CC_PRINT | CC_NEWLINE))) { if (!buf_write_u8(&cl->buf, buf[i])) { @@ -3988,10 +3906,16 @@ } if (flags & LOG_PRINT_REMOTE_IP) { - buf_printf(&out, ",%s", (!addr_defined(&e->remote_sock) ? "," : - print_sockaddr_ex(&e->remote_sock.addr.sa= , ",", PS_DONT_SHOW_FAMILY|PS_SHOW_PORT, gc))); - buf_printf(&out, ",%s", (!addr_defined(&e->local_sock) ? "," : - print_sockaddr_ex(&e->local_sock.addr.sa,= ",", PS_DONT_SHOW_FAMILY|PS_SHOW_PORT, gc))); + buf_printf(&out, ",%s", + (!addr_defined(&e->remote_sock) + ? "," + : print_sockaddr_ex(&e->remote_sock.addr.sa, ",", + PS_DONT_SHOW_FAMILY | PS_SHOW_= PORT, gc))); + buf_printf(&out, ",%s", + (!addr_defined(&e->local_sock) + ? "," + : print_sockaddr_ex(&e->local_sock.addr.sa, ",", + PS_DONT_SHOW_FAMILY | PS_SHOW_= PORT, gc))); } if (flags & LOG_PRINT_LOCAL_IP && !IN6_IS_ADDR_UNSPECIFIED(&e->local_i= p6)) { @@ -4144,8 +4068,7 @@ void management_check_bytecount(struct context *c, struct management *man, stru= ct timeval *timeval) { - if (event_timeout_trigger(&man->connection.bytecount_update_interval, - timeval, ETT_DEFAULT)) + if (event_timeout_trigger(&man->connection.bytecount_update_interval, = timeval, ETT_DEFAULT)) { counter_type dco_read_bytes =3D 0; counter_type dco_write_bytes =3D 0; @@ -4182,7 +4105,7 @@ } } -#else /* ifdef ENABLE_MANAGEMENT */ +#else /* ifdef ENABLE_MANAGEMENT */ #include "win32.h" void diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index eb19a4e..b541434 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -25,24 +25,24 @@ #define MANAGE_H /* management_open flags */ -#define MF_SERVER (1<<0) -#define MF_QUERY_PASSWORDS (1<<1) -#define MF_HOLD (1<<2) -#define MF_SIGNAL (1<<3) -#define MF_FORGET_DISCONNECT (1<<4) -#define MF_CONNECT_AS_CLIENT (1<<5) -#define MF_CLIENT_AUTH (1<<6) +#define MF_SERVER (1 << 0) +#define MF_QUERY_PASSWORDS (1 << 1) +#define MF_HOLD (1 << 2) +#define MF_SIGNAL (1 << 3) +#define MF_FORGET_DISCONNECT (1 << 4) +#define MF_CONNECT_AS_CLIENT (1 << 5) +#define MF_CLIENT_AUTH (1 << 6) /* #define MF_CLIENT_PF (1<<7) *REMOVED FEATURE* */ -#define MF_UNIX_SOCK (1<<8) -#define MF_EXTERNAL_KEY (1<<9) -#define MF_EXTERNAL_KEY_NOPADDING (1<<10) -#define MF_EXTERNAL_KEY_PKCS1PAD (1<<11) -#define MF_UP_DOWN (1<<12) -#define MF_QUERY_REMOTE (1<<13) -#define MF_QUERY_PROXY (1<<14) -#define MF_EXTERNAL_CERT (1<<15) -#define MF_EXTERNAL_KEY_PSSPAD (1<<16) -#define MF_EXTERNAL_KEY_DIGEST (1<<17) +#define MF_UNIX_SOCK (1 << 8) +#define MF_EXTERNAL_KEY (1 << 9) +#define MF_EXTERNAL_KEY_NOPADDING (1 << 10) +#define MF_EXTERNAL_KEY_PKCS1PAD (1 << 11) +#define MF_UP_DOWN (1 << 12) +#define MF_QUERY_REMOTE (1 << 13) +#define MF_QUERY_PROXY (1 << 14) +#define MF_EXTERNAL_CERT (1 << 15) +#define MF_EXTERNAL_KEY_PSSPAD (1 << 16) +#define MF_EXTERNAL_KEY_DIGEST (1 << 17) #ifdef ENABLE_MANAGEMENT @@ -52,21 +52,22 @@ #include "socket.h" #include "mroute.h" -#define MANAGEMENT_VERSION 5 -#define MANAGEMENT_N_PASSWORD_RETRIES 3 -#define MANAGEMENT_LOG_HISTORY_INITIAL_SIZE 100 -#define MANAGEMENT_ECHO_BUFFER_SIZE 100 -#define MANAGEMENT_STATE_BUFFER_SIZE 100 +#define MANAGEMENT_VERSION 5 +#define MANAGEMENT_N_PASSWORD_RETRIES 3 +#define MANAGEMENT_LOG_HISTORY_INITIAL_SIZE 100 +#define MANAGEMENT_ECHO_BUFFER_SIZE 100 +#define MANAGEMENT_STATE_BUFFER_SIZE 100 /* * Management-interface-based deferred authentication */ -struct man_def_auth_context { +struct man_def_auth_context +{ unsigned long cid; -#define DAF_CONNECTION_ESTABLISHED (1<<0) -#define DAF_CONNECTION_CLOSED (1<<1) -#define DAF_INITIAL_AUTH (1<<2) +#define DAF_CONNECTION_ESTABLISHED (1 << 0) +#define DAF_CONNECTION_CLOSED (1 << 1) +#define DAF_INITIAL_AUTH (1 << 2) unsigned int flags; unsigned int mda_key_id_counter; @@ -99,7 +100,8 @@ * Manage log file history */ -union log_entry_union { +union log_entry_union +{ unsigned int msg_flags; int state; int intval; @@ -116,23 +118,23 @@ union log_entry_union u; }; -#define LOG_PRINT_LOG_PREFIX (1<<0) -#define LOG_PRINT_ECHO_PREFIX (1<<1) -#define LOG_PRINT_STATE_PREFIX (1<<2) +#define LOG_PRINT_LOG_PREFIX (1 << 0) +#define LOG_PRINT_ECHO_PREFIX (1 << 1) +#define LOG_PRINT_STATE_PREFIX (1 << 2) -#define LOG_PRINT_INT_DATE (1<<3) -#define LOG_PRINT_MSG_FLAGS (1<<4) -#define LOG_PRINT_STATE (1<<5) -#define LOG_PRINT_LOCAL_IP (1<<6) +#define LOG_PRINT_INT_DATE (1 << 3) +#define LOG_PRINT_MSG_FLAGS (1 << 4) +#define LOG_PRINT_STATE (1 << 5) +#define LOG_PRINT_LOCAL_IP (1 << 6) -#define LOG_PRINT_CRLF (1<<7) -#define LOG_FATAL_NOTIFY (1<<8) +#define LOG_PRINT_CRLF (1 << 7) +#define LOG_FATAL_NOTIFY (1 << 8) -#define LOG_PRINT_INTVAL (1<<9) +#define LOG_PRINT_INTVAL (1 << 9) -#define LOG_PRINT_REMOTE_IP (1<<10) +#define LOG_PRINT_REMOTE_IP (1 << 10) -#define LOG_ECHO_TO_LOG (1<<11) +#define LOG_ECHO_TO_LOG (1 << 11) const char *log_entry_print(const struct log_entry *e, unsigned int flags,= struct gc_arena *gc); @@ -174,32 +176,25 @@ { void *arg; -#define MCF_SERVER (1<<0) /* is OpenVPN being run as a server? */ +#define MCF_SERVER (1 << 0) /* is OpenVPN being run as a server? */ unsigned int flags; - void (*status) (void *arg, const int version, struct status_output *so= ); - void (*show_net) (void *arg, const int msglevel); - int (*kill_by_cn) (void *arg, const char *common_name); - int (*kill_by_addr) (void *arg, const in_addr_t addr, const int port, = const int proto); - void (*delete_event) (void *arg, event_t event); - int (*n_clients) (void *arg); - bool (*send_cc_message) (void *arg, const char *message, const char *p= arameter); + void (*status)(void *arg, const int version, struct status_output *so); + void (*show_net)(void *arg, const int msglevel); + int (*kill_by_cn)(void *arg, const char *common_name); + int (*kill_by_addr)(void *arg, const in_addr_t addr, const int port, c= onst int proto); + void (*delete_event)(void *arg, event_t event); + int (*n_clients)(void *arg); + bool (*send_cc_message)(void *arg, const char *message, const char *pa= rameter); bool (*kill_by_cid)(void *arg, const unsigned long cid, const char *ki= ll_msg); - bool (*client_auth) (void *arg, - const unsigned long cid, - const unsigned int mda_key_id, - const bool auth, - const char *reason, - const char *client_reason, - struct buffer_list *cc_config); /* ownership tran= sferred */ - bool (*client_pending_auth) (void *arg, - const unsigned long cid, - const unsigned int kid, - const char *extra, - unsigned int timeout); - char *(*get_peer_info) (void *arg, const unsigned long cid); + bool (*client_auth)(void *arg, const unsigned long cid, const unsigned= int mda_key_id, + const bool auth, const char *reason, const char *c= lient_reason, + struct buffer_list *cc_config); /* ownership trans= ferred */ + bool (*client_pending_auth)(void *arg, const unsigned long cid, const = unsigned int kid, + const char *extra, unsigned int timeout); + char *(*get_peer_info)(void *arg, const unsigned long cid); bool (*proxy_cmd)(void *arg, const char **p); - bool (*remote_cmd) (void *arg, const char **p); + bool (*remote_cmd)(void *arg, const char **p); #ifdef TARGET_ANDROID int (*network_change)(void *arg, bool samenetwork); #endif @@ -221,7 +216,8 @@ * connections. */ -struct man_persist { +struct man_persist +{ bool defined; struct log_history *log; @@ -241,7 +237,8 @@ counter_type bytes_out; }; -struct man_settings { +struct man_settings +{ bool defined; unsigned int flags; /* MF_x flags */ struct addrinfo *local; @@ -257,9 +254,9 @@ int client_gid; /* flags for handling the management interface "signal" command */ -#define MANSIG_IGNORE_USR1_HUP (1<<0) -#define MANSIG_MAP_USR1_TO_HUP (1<<1) -#define MANSIG_MAP_USR1_TO_TERM (1<<2) +#define MANSIG_IGNORE_USR1_HUP (1 << 0) +#define MANSIG_MAP_USR1_TO_HUP (1 << 1) +#define MANSIG_MAP_USR1_TO_TERM (1 << 2) unsigned int mansig; }; @@ -271,12 +268,13 @@ #define UP_QUERY_NEED_STR 4 /* states */ -#define MS_INITIAL 0 /* all sockets are closed */ -#define MS_LISTEN 1 /* no client is connected */ -#define MS_CC_WAIT_READ 2 /* client is connected, waiting for read on= socket */ -#define MS_CC_WAIT_WRITE 3 /* client is connected, waiting for ability= to write to socket */ +#define MS_INITIAL 0 /* all sockets are closed */ +#define MS_LISTEN 1 /* no client is connected */ +#define MS_CC_WAIT_READ 2 /* client is connected, waiting for read on soc= ket */ +#define MS_CC_WAIT_WRITE 3 /* client is connected, waiting for ability to = write to socket */ -struct man_connection { +struct man_connection +{ int state; socket_descriptor_t sd_top; @@ -345,16 +343,10 @@ struct management *management_init(void); -bool management_open(struct management *man, - const char *addr, - const char *port, - const char *pass_file, - const char *client_user, - const char *client_group, - const int log_history_cache, - const int echo_buffer_size, - const int state_buffer_size, - const int remap_sigusr1, +bool management_open(struct management *man, const char *addr, const char = *port, + const char *pass_file, const char *client_user, const= char *client_group, + const int log_history_cache, const int echo_buffer_si= ze, + const int state_buffer_size, const int remap_sigusr1, const unsigned int flags); void management_close(struct management *man); @@ -363,28 +355,22 @@ void management_pre_tunnel_close(struct management *man); -void management_socket_set(struct management *man, - struct event_set *es, - void *arg, +void management_socket_set(struct management *man, struct event_set *es, v= oid *arg, unsigned int *persistent); void management_io(struct management *man); -void management_set_callback(struct management *man, - const struct management_callback *cb); +void management_set_callback(struct management *man, const struct manageme= nt_callback *cb); void management_clear_callback(struct management *man); -bool management_query_user_pass(struct management *man, - struct user_pass *up, - const char *type, - const unsigned int flags, - const char *static_challenge); +bool management_query_user_pass(struct management *man, struct user_pass *= up, const char *type, + const unsigned int flags, const char *stat= ic_challenge); #ifdef TARGET_ANDROID bool management_android_control(struct management *man, const char *comman= d, const char *msg); -#define ANDROID_KEEP_OLD_TUN 1 +#define ANDROID_KEEP_OLD_TUN 1 #define ANDROID_OPEN_BEFORE_CLOSE 2 int managment_android_persisttun_action(struct management *man); @@ -398,7 +384,8 @@ void management_up_down(struct management *man, const char *updown, const = struct env_set *es); -void management_notify(struct management *man, const char *severity, const= char *type, const char *text); +void management_notify(struct management *man, const char *severity, const= char *type, + const char *text); void management_notify_generic(struct management *man, const char *str); @@ -408,25 +395,19 @@ const struct env_set *es); void management_connection_established(struct management *management, - struct man_def_auth_context *mdac, - const struct env_set *es); + struct man_def_auth_context *mdac, = const struct env_set *es); void management_notify_client_close(struct management *management, - struct man_def_auth_context *mdac, - const struct env_set *es); + struct man_def_auth_context *mdac, con= st struct env_set *es); -void management_learn_addr(struct management *management, - struct man_def_auth_context *mdac, - const struct mroute_addr *addr, - const bool primary); +void management_learn_addr(struct management *management, struct man_def_a= uth_context *mdac, + const struct mroute_addr *addr, const bool prim= ary); void management_notify_client_cr_response(unsigned mda_key_id, const struct man_def_auth_contex= t *mdac, - const struct env_set *es, - const char *response); + const struct env_set *es, const = char *response); -char *management_query_pk_sig(struct management *man, const char *b64_data, - const char *algorithm); +char *management_query_pk_sig(struct management *man, const char *b64_data= , const char *algorithm); char *management_query_cert(struct management *man, const char *cert_name); @@ -466,30 +447,28 @@ */ /* client/server states */ -#define OPENVPN_STATE_INITIAL 0 /* Initial, undefined state */ -#define OPENVPN_STATE_CONNECTING 1 /* Management interface has been in= itialized */ -#define OPENVPN_STATE_ASSIGN_IP 2 /* Assigning IP address to virtual = network interface */ -#define OPENVPN_STATE_ADD_ROUTES 3 /* Adding routes to system */ -#define OPENVPN_STATE_CONNECTED 4 /* Initialization sequence complete= d */ -#define OPENVPN_STATE_RECONNECTING 5 /* Restart */ -#define OPENVPN_STATE_EXITING 6 /* Exit */ +#define OPENVPN_STATE_INITIAL 0 /* Initial, undefined state */ +#define OPENVPN_STATE_CONNECTING 1 /* Management interface has been init= ialized */ +#define OPENVPN_STATE_ASSIGN_IP 2 /* Assigning IP address to virtual ne= twork interface */ +#define OPENVPN_STATE_ADD_ROUTES 3 /* Adding routes to system */ +#define OPENVPN_STATE_CONNECTED 4 /* Initialization sequence completed = */ +#define OPENVPN_STATE_RECONNECTING 5 /* Restart */ +#define OPENVPN_STATE_EXITING 6 /* Exit */ /* client-only states */ -#define OPENVPN_STATE_WAIT 7 /* Waiting for initial response fro= m server */ -#define OPENVPN_STATE_AUTH 8 /* Authenticating with server */ -#define OPENVPN_STATE_GET_CONFIG 9 /* Downloading configuration from s= erver */ -#define OPENVPN_STATE_RESOLVE 10 /* DNS lookup */ -#define OPENVPN_STATE_TCP_CONNECT 11 /* Connecting to TCP server */ -#define OPENVPN_STATE_AUTH_PENDING 12 /* Waiting in auth-pending mode - * technically variant of GET_CONFI= G */ +#define OPENVPN_STATE_WAIT 7 /* Waiting for initial response from = server */ +#define OPENVPN_STATE_AUTH 8 /* Authenticating with server */ +#define OPENVPN_STATE_GET_CONFIG 9 /* Downloading configuration from ser= ver */ +#define OPENVPN_STATE_RESOLVE 10 /* DNS lookup */ +#define OPENVPN_STATE_TCP_CONNECT 11 /* Connecting to TCP server */ +#define OPENVPN_STATE_AUTH_PENDING \ + 12 /* Waiting in auth-pending mode \ + * technically variant of GET_CONFIG = */ -#define OPENVPN_STATE_CLIENT_BASE 7 /* Base index of client-only states= */ +#define OPENVPN_STATE_CLIENT_BASE 7 /* Base index of client-only states */ -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, +void management_set_state(struct management *man, const int state, const c= har *detail, + const in_addr_t *tun_local_ip, const struct in6_= addr *tun_local_ip6, const struct openvpn_sockaddr *local_addr, const struct openvpn_sockaddr *remote_addr); @@ -514,15 +493,10 @@ * These functions drive the bytecount in/out counters. */ -void -management_check_bytecount(struct context *c, - struct management *man, - struct timeval *timeval); +void management_check_bytecount(struct context *c, struct management *man,= struct timeval *timeval); static inline void -management_bytes_client(struct management *man, - const int size_in, - const int size_out) +management_bytes_client(struct management *man, const int size_in, const i= nt size_out) { if (!(man->persist.callback.flags & MCF_SERVER)) { @@ -531,27 +505,24 @@ } } -void -man_bytecount_output_server(const counter_type *bytes_in_total, - const counter_type *bytes_out_total, - struct man_def_auth_context *mdac); +void man_bytecount_output_server(const counter_type *bytes_in_total, + const counter_type *bytes_out_total, + struct man_def_auth_context *mdac); static inline void -management_bytes_server(struct management *man, - const counter_type *bytes_in_total, - const counter_type *bytes_out_total, - struct man_def_auth_context *mdac) +management_bytes_server(struct management *man, const counter_type *bytes_= in_total, + const counter_type *bytes_out_total, struct man_de= f_auth_context *mdac) { if (man->connection.bytecount_update_seconds > 0 && now >=3D mdac->bytecount_last_update + man->connection.bytecoun= t_update_seconds - && (mdac->flags & (DAF_CONNECTION_ESTABLISHED | DAF_CONNECTION_CLO= SED)) =3D=3D DAF_CONNECTION_ESTABLISHED) + && (mdac->flags & (DAF_CONNECTION_ESTABLISHED | DAF_CONNECTION_CLO= SED)) + =3D=3D DAF_CONNECTION_ESTABLISHED) { man_bytecount_output_server(bytes_in_total, bytes_out_total, mdac); } } =20 -void -man_persist_client_stats(struct management *man, struct context *c); +void man_persist_client_stats(struct management *man, struct context *c); #endif /* ifdef ENABLE_MANAGEMENT */ diff --git a/src/openvpn/mbedtls_compat.h b/src/openvpn/mbedtls_compat.h index aeb0c5f..94d56f9 100644 --- a/src/openvpn/mbedtls_compat.h +++ b/src/openvpn/mbedtls_compat.h @@ -49,7 +49,7 @@ #include #ifdef HAVE_PSA_CRYPTO_H - #include +#include #endif #if MBEDTLS_VERSION_NUMBER >=3D 0x03000000 @@ -90,8 +90,7 @@ * an error code. */ static inline int -mbedtls_compat_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx, - const unsigned char *additional, +mbedtls_compat_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx, const unsign= ed char *additional, size_t add_len) { #if MBEDTLS_VERSION_NUMBER > 0x03000000 @@ -116,8 +115,7 @@ } static inline int -mbedtls_compat_pk_parse_key(mbedtls_pk_context *ctx, - const unsigned char *key, size_t keylen, +mbedtls_compat_pk_parse_key(mbedtls_pk_context *ctx, const unsigned char *= key, size_t keylen, const unsigned char *pwd, size_t pwdlen, int (*f_rng)(void *, unsigned char *, size_t),= void *p_rng) { @@ -129,8 +127,7 @@ } static inline int -mbedtls_compat_pk_parse_keyfile(mbedtls_pk_context *ctx, - const char *path, const char *password, +mbedtls_compat_pk_parse_keyfile(mbedtls_pk_context *ctx, const char *path,= const char *password, int (*f_rng)(void *, unsigned char *, size= _t), void *p_rng) { #if MBEDTLS_VERSION_NUMBER < 0x03020100 @@ -141,8 +138,9 @@ } #if MBEDTLS_VERSION_NUMBER < 0x03020100 -typedef enum { - MBEDTLS_SSL_VERSION_UNKNOWN, /*!< Context not in use or version not ye= t negotiated. */ +typedef enum +{ + MBEDTLS_SSL_VERSION_UNKNOWN, /*!< Context not in use or versio= n not yet negotiated. */ MBEDTLS_SSL_VERSION_TLS1_2 =3D 0x0303, /*!< (D)TLS 1.2 */ MBEDTLS_SSL_VERSION_TLS1_3 =3D 0x0304, /*!< (D)TLS 1.3 */ } mbedtls_ssl_protocol_version; diff --git a/src/openvpn/mbuf.c b/src/openvpn/mbuf.c index 3346a11..0585395 100644 --- a/src/openvpn/mbuf.c +++ b/src/openvpn/mbuf.c @@ -51,7 +51,7 @@ if (ms) { int i; - for (i =3D 0; i < (int) ms->len; ++i) + for (i =3D 0; i < (int)ms->len; ++i) { struct mbuf_item *item =3D &ms->array[MBUF_INDEX(ms->head, i, = ms->capacity)]; mbuf_free_buf(item->buffer); @@ -135,7 +135,7 @@ if (ms) { int i; - for (i =3D 0; i < (int) ms->len; ++i) + for (i =3D 0; i < (int)ms->len; ++i) { struct mbuf_item *item =3D &ms->array[MBUF_INDEX(ms->head, i, = ms->capacity)]; if (item->instance) @@ -154,7 +154,7 @@ if (ms) { int i; - for (i =3D 0; i < (int) ms->len; ++i) + for (i =3D 0; i < (int)ms->len; ++i) { struct mbuf_item *item =3D &ms->array[MBUF_INDEX(ms->head, i, = ms->capacity)]; if (item->instance =3D=3D mi) diff --git a/src/openvpn/mbuf.h b/src/openvpn/mbuf.h index b9c1645..9c41a58 100644 --- a/src/openvpn/mbuf.h +++ b/src/openvpn/mbuf.h @@ -36,14 +36,14 @@ struct multi_instance; -#define MBUF_INDEX(head, offset, size) (((head) + (offset)) & ((size)-1)) +#define MBUF_INDEX(head, offset, size) (((head) + (offset)) & ((size) - 1)) struct mbuf_buffer { struct buffer buf; int refcount; -#define MF_UNICAST (1<<0) +#define MF_UNICAST (1 << 0) unsigned int flags; }; @@ -91,7 +91,7 @@ static inline int mbuf_maximum_queued(const struct mbuf_set *ms) { - return (int) ms->max_queued; + return (int)ms->max_queued; } struct multi_instance *mbuf_peek_dowork(struct mbuf_set *ms); diff --git a/src/openvpn/memdbg.h b/src/openvpn/memdbg.h index 6947275..743a853 100644 --- a/src/openvpn/memdbg.h +++ b/src/openvpn/memdbg.h @@ -39,7 +39,8 @@ * from uninitialized data, we need to untaint it before use -- * otherwise we will get a lot of useless warnings. * - * valgrind --tool=3Dmemcheck --error-limit=3Dno --suppressions=3Ddebug/= valgrind-suppress --gen-suppressions=3Dyes ./openvpn ... + * valgrind --tool=3Dmemcheck --error-limit=3Dno --suppressions=3Ddebug/= valgrind-suppress + * --gen-suppressions=3Dyes ./openvpn ... */ #ifdef USE_VALGRIND @@ -48,7 +49,7 @@ #define VALGRIND_MAKE_READABLE(addr, len) -#else /* ifdef USE_VALGRIND */ +#else /* ifdef USE_VALGRIND */ #define VALGRIND_MAKE_READABLE(addr, len) @@ -86,7 +87,8 @@ #include -#define openvpn_dmalloc(file, line, size) dmalloc_malloc((file), (line), (= size), DMALLOC_FUNC_MALLOC, 0, 0) +#define openvpn_dmalloc(file, line, size) \ + dmalloc_malloc((file), (line), (size), DMALLOC_FUNC_MALLOC, 0, 0) /* * This #define will put the line number of the log diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index 4695700..6cb0e96 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -85,7 +85,7 @@ uint8_t rnd_bytes[n_rnd_bytes]; const char *rnd_str; - struct buffer hname =3D alloc_buf_gc(strlen(hostname)+sizeof(rnd_bytes= )*2+4, gc); + struct buffer hname =3D alloc_buf_gc(strlen(hostname) + sizeof(rnd_byt= es) * 2 + 4, gc); prng_bytes(rnd_bytes, sizeof(rnd_bytes)); rnd_str =3D format_hex_ex(rnd_bytes, sizeof(rnd_bytes), 40, 0, NULL, g= c); @@ -119,7 +119,9 @@ } else { - msg(M_FATAL, "ERROR: could not read %s username/password/ok/st= ring from management interface", prefix); + msg(M_FATAL, + "ERROR: could not read %s username/password/ok/string from= management interface", + prefix); } } return true; @@ -135,7 +137,8 @@ * @param auth_challenge The authentication challenge string to parse. Can= 't be NULL. * @param gc The gc_arena structure for memory allocation. * - * @return A pointer to the parsed auth_challenge_info struc= ture, or NULL if parsing fails. + * @return A pointer to the parsed auth_challenge_info struc= ture, or NULL if parsing + * fails. */ static struct auth_challenge_info * parse_auth_challenge(const char *auth_challenge, struct gc_arena *gc) @@ -144,7 +147,7 @@ struct auth_challenge_info *ac; const int len =3D strlen(auth_challenge); - char *work =3D (char *) gc_malloc(len+1, false, gc); + char *work =3D (char *)gc_malloc(len + 1, false, gc); char *cp; struct buffer b; @@ -192,7 +195,7 @@ { return NULL; } - ac->user =3D (char *) gc_malloc(strlen(work)+1, true, gc); + ac->user =3D (char *)gc_malloc(strlen(work) + 1, true, gc); openvpn_base64_decode(work, (void *)ac->user, -1); /* parse challenge text */ @@ -208,11 +211,8 @@ */ bool -get_user_pass_cr(struct user_pass *up, - const char *auth_file, - const char *prefix, - const unsigned int flags, - const char *auth_challenge) +get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *= prefix, + const unsigned int flags, const char *auth_challenge) { struct gc_arena gc =3D gc_new(); @@ -233,8 +233,7 @@ /* * Get username/password from management interface? */ - if (management - && (!from_authfile && (flags & GET_USER_PASS_MANAGEMENT)) + if (management && (!from_authfile && (flags & GET_USER_PASS_MANAGE= MENT)) && management_query_user_pass_enabled(management)) { response_from_stdin =3D false; @@ -245,118 +244,119 @@ } else #endif /* ifdef ENABLE_MANAGEMENT */ - /* - * Get NEED_OK confirmation from the console - */ - if (flags & GET_USER_PASS_NEED_OK) - { - struct buffer user_prompt =3D alloc_buf_gc(128, &gc); - - buf_printf(&user_prompt, "NEED-OK|%s|%s:", prefix, up->usernam= e); - if (!query_user_SINGLE(BSTR(&user_prompt), BLEN(&user_prompt), - up->password, USER_PASS_LEN, false)) - { - msg(M_FATAL, "ERROR: could not read %s ok-confirmation fro= m stdin", prefix); - } - - if (!strlen(up->password)) - { - strcpy(up->password, "ok"); - } - } - else if (flags & GET_USER_PASS_INLINE_CREDS) - { - struct buffer buf; - buf_set_read(&buf, (uint8_t *) auth_file, strlen(auth_file) + = 1); - if (!(flags & GET_USER_PASS_PASSWORD_ONLY)) - { - buf_parse(&buf, '\n', up->username, USER_PASS_LEN); - } - buf_parse(&buf, '\n', up->password, USER_PASS_LEN); - - if (strlen(up->password) =3D=3D 0) - { - password_from_stdin =3D 1; - } - } - /* - * Read from auth file unless this is a dynamic challenge request. - */ - else if (from_authfile && !(flags & GET_USER_PASS_DYNAMIC_CHALLENG= E)) - { /* - * Try to get username/password from a file. + * Get NEED_OK confirmation from the console */ - FILE *fp; - char password_buf[USER_PASS_LEN] =3D { '\0' }; - - fp =3D platform_fopen(auth_file, "r"); - if (!fp) + if (flags & GET_USER_PASS_NEED_OK) { - msg(M_ERR, "Error opening '%s' auth file: %s", prefix, aut= h_file); - } + struct buffer user_prompt =3D alloc_buf_gc(128, &gc); - if ((flags & GET_USER_PASS_PASSWORD_ONLY) =3D=3D 0) - { - /* Read username first */ - if (fgets(up->username, USER_PASS_LEN, fp) =3D=3D NULL) + buf_printf(&user_prompt, "NEED-OK|%s|%s:", prefix, up->use= rname); + if (!query_user_SINGLE(BSTR(&user_prompt), BLEN(&user_prom= pt), up->password, + USER_PASS_LEN, false)) { - msg(M_FATAL, "Error reading username from %s authfile:= %s", - prefix, + msg(M_FATAL, "ERROR: could not read %s ok-confirmation= from stdin", prefix); + } + + if (!strlen(up->password)) + { + strcpy(up->password, "ok"); + } + } + else if (flags & GET_USER_PASS_INLINE_CREDS) + { + struct buffer buf; + buf_set_read(&buf, (uint8_t *)auth_file, strlen(auth_file)= + 1); + if (!(flags & GET_USER_PASS_PASSWORD_ONLY)) + { + buf_parse(&buf, '\n', up->username, USER_PASS_LEN); + } + buf_parse(&buf, '\n', up->password, USER_PASS_LEN); + + if (strlen(up->password) =3D=3D 0) + { + password_from_stdin =3D 1; + } + } + /* + * Read from auth file unless this is a dynamic challenge requ= est. + */ + else if (from_authfile && !(flags & GET_USER_PASS_DYNAMIC_CHAL= LENGE)) + { + /* + * Try to get username/password from a file. + */ + FILE *fp; + char password_buf[USER_PASS_LEN] =3D { '\0' }; + + fp =3D platform_fopen(auth_file, "r"); + if (!fp) + { + msg(M_ERR, "Error opening '%s' auth file: %s", prefix,= auth_file); + } + + if ((flags & GET_USER_PASS_PASSWORD_ONLY) =3D=3D 0) + { + /* Read username first */ + if (fgets(up->username, USER_PASS_LEN, fp) =3D=3D NULL) + { + msg(M_FATAL, "Error reading username from %s authf= ile: %s", prefix, + auth_file); + } + } + chomp(up->username); + + if (fgets(password_buf, USER_PASS_LEN, fp) !=3D NULL) + { + chomp(password_buf); + } + + if (flags & GET_USER_PASS_PASSWORD_ONLY && !password_buf[0= ]) + { + msg(M_FATAL, "Error reading password from %s authfile:= %s", prefix, auth_file); + } + + if (password_buf[0]) + { + strncpy(up->password, password_buf, USER_PASS_LEN); + } + /* The auth-file does not have the password: get both user= name + * and password from the management interface if possible. + * Otherwise set to read password from console. + */ +#if defined(ENABLE_MANAGEMENT) + else if (management && (flags & GET_USER_PASS_MANAGEMENT) + && management_query_user_pass_enabled(management)) + { + msg(D_LOW, + "No password found in %s authfile '%s'. Querying t= he management interface", + prefix, auth_file); + if (!auth_user_pass_mgmt(up, prefix, flags, auth_chall= enge)) + { + fclose(fp); + return false; + } + } +#endif + else + { + password_from_stdin =3D 1; + } + + fclose(fp); + + if (!(flags & GET_USER_PASS_PASSWORD_ONLY) && strlen(up->u= sername) =3D=3D 0) + { + msg(M_FATAL, "ERROR: username from %s authfile '%s' is= empty", prefix, auth_file); } } - chomp(up->username); - - if (fgets(password_buf, USER_PASS_LEN, fp) !=3D NULL) - { - chomp(password_buf); - } - - if (flags & GET_USER_PASS_PASSWORD_ONLY && !password_buf[0]) - { - msg(M_FATAL, "Error reading password from %s authfile: %s"= , prefix, auth_file); - } - - if (password_buf[0]) - { - strncpy(up->password, password_buf, USER_PASS_LEN); - } - /* The auth-file does not have the password: get both username - * and password from the management interface if possible. - * Otherwise set to read password from console. - */ -#if defined(ENABLE_MANAGEMENT) - else if (management - && (flags & GET_USER_PASS_MANAGEMENT) - && management_query_user_pass_enabled(management)) - { - msg(D_LOW, "No password found in %s authfile '%s'. Queryin= g the management interface", prefix, auth_file); - if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge= )) - { - fclose(fp); - return false; - } - } -#endif else { - password_from_stdin =3D 1; + username_from_stdin =3D true; + password_from_stdin =3D true; } - fclose(fp); - - if (!(flags & GET_USER_PASS_PASSWORD_ONLY) && strlen(up->usern= ame) =3D=3D 0) - { - msg(M_FATAL, "ERROR: username from %s authfile '%s' is emp= ty", prefix, auth_file); - } - } - else - { - username_from_stdin =3D true; - password_from_stdin =3D true; - } - /* * Get username/password from standard input? */ @@ -368,15 +368,15 @@ struct auth_challenge_info *ac =3D parse_auth_challenge(au= th_challenge, &gc); if (ac) { - char *response =3D (char *) gc_malloc(USER_PASS_LEN, f= alse, &gc); + char *response =3D (char *)gc_malloc(USER_PASS_LEN, fa= lse, &gc); struct buffer packed_resp, challenge; - challenge =3D alloc_buf_gc(14+strlen(ac->challenge_tex= t), &gc); + challenge =3D alloc_buf_gc(14 + strlen(ac->challenge_t= ext), &gc); buf_printf(&challenge, "CHALLENGE: %s", ac->challenge_= text); buf_set_write(&packed_resp, (uint8_t *)up->password, U= SER_PASS_LEN); - if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challen= ge), - response, USER_PASS_LEN, BOOL_C= AST(ac->flags&CR_ECHO))) + if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challen= ge), response, + USER_PASS_LEN, BOOL_CAST(ac->fl= ags & CR_ECHO))) { msg(M_FATAL, "ERROR: could not read challenge resp= onse from stdin"); } @@ -400,17 +400,17 @@ if (username_from_stdin && !(flags & GET_USER_PASS_PASSWOR= D_ONLY)) { - query_user_add(BSTR(&user_prompt), BLEN(&user_prompt), - up->username, USER_PASS_LEN, true); + query_user_add(BSTR(&user_prompt), BLEN(&user_prompt),= up->username, + USER_PASS_LEN, true); } =20 if (password_from_stdin) { - query_user_add(BSTR(&pass_prompt), BLEN(&pass_prompt), - up->password, USER_PASS_LEN, false); + query_user_add(BSTR(&pass_prompt), BLEN(&pass_prompt),= up->password, + USER_PASS_LEN, false); } - if (!query_user_exec() ) + if (!query_user_exec()) { msg(M_FATAL, "ERROR: Failed retrieving username or pas= sword"); } @@ -424,17 +424,18 @@ } #ifdef ENABLE_MANAGEMENT - if (auth_challenge && (flags & GET_USER_PASS_STATIC_CHALLE= NGE) && response_from_stdin) + if (auth_challenge && (flags & GET_USER_PASS_STATIC_CHALLE= NGE) + && response_from_stdin) { - char *response =3D (char *) gc_malloc(USER_PASS_LEN, f= alse, &gc); + char *response =3D (char *)gc_malloc(USER_PASS_LEN, fa= lse, &gc); struct buffer packed_resp, challenge; char *pw64 =3D NULL, *resp64 =3D NULL; - challenge =3D alloc_buf_gc(14+strlen(auth_challenge), = &gc); + challenge =3D alloc_buf_gc(14 + strlen(auth_challenge)= , &gc); buf_printf(&challenge, "CHALLENGE: %s", auth_challenge= ); - if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challen= ge), - response, USER_PASS_LEN, + if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challen= ge), response, + USER_PASS_LEN, BOOL_CAST(flags & GET_USER_PASS= _STATIC_CHALLENGE_ECHO))) { msg(M_FATAL, "ERROR: could not retrieve static cha= llenge response"); @@ -457,7 +458,8 @@ { if (strlen(up->password) + strlen(response) >=3D U= SER_PASS_LEN) { - msg(M_FATAL, "ERROR: could not concatenate pas= sword/static_response: string too long"); + msg(M_FATAL, + "ERROR: could not concatenate password/sta= tic_response: string too long"); } strncat(up->password, response, USER_PASS_LEN - st= rlen(up->password) - 1); } @@ -500,7 +502,8 @@ */ if (!warn_shown) { - msg(M_WARN, "WARNING: this configuration may cache passwords i= n memory -- use the auth-nocache option to prevent this"); + msg(M_WARN, + "WARNING: this configuration may cache passwords in memory= -- use the auth-nocache option to prevent this"); warn_shown =3D true; } } @@ -595,7 +598,7 @@ char **ret =3D NULL; int i =3D 0; - buf_set_read(&buf, (const uint8_t *) str, strlen(str)); + buf_set_read(&buf, (const uint8_t *)str, strlen(str)); while (buf_parse(&buf, '\n', line, sizeof(line))) { ++len; @@ -604,7 +607,7 @@ /* alloc return array */ ALLOC_ARRAY_CLEAR_GC(ret, char *, len + 1, gc); - buf_set_read(&buf, (const uint8_t *) str, strlen(str)); + buf_set_read(&buf, (const uint8_t *)str, strlen(str)); while (buf_parse(&buf, '\n', line, sizeof(line))) { chomp(line); @@ -669,12 +672,12 @@ const char * sanitize_control_message(const char *src, struct gc_arena *gc) { - char *ret =3D gc_malloc(strlen(src)+1, false, gc); + char *ret =3D gc_malloc(strlen(src) + 1, false, gc); char *dest =3D ret; bool redact =3D false; int skip =3D 0; - for (;; ) + for (;;) { const char c =3D *src; if (c =3D=3D '\0') @@ -691,8 +694,7 @@ skip =3D 4; redact =3D true; } - else if (!check_debug_level(D_SHOW_KEYS) - && (c =3D=3D 'a' && !strncmp(src, "auth-token ", 11))) + else if (!check_debug_level(D_SHOW_KEYS) && (c =3D=3D 'a' && !strn= cmp(src, "auth-token ", 11))) { /* Unless --verb is 7 or higher (D_SHOW_KEYS), hide * the auth-token value coming in the src string @@ -756,8 +758,7 @@ case 2: /* after the '=3D', replace non-printable or shell meta wi= th '_' */ - if (!isprint(c) || isspace(c) - || c =3D=3D '$' || c =3D=3D '(' || c =3D=3D '`') + if (!isprint(c) || isspace(c) || c =3D=3D '$' || c =3D=3D = '(' || c =3D=3D '`') { *line =3D '_'; } @@ -772,12 +773,12 @@ { char line[256]; struct buffer buf; - buf_set_read(&buf, (const uint8_t *) peer_info, strlen(peer_info)); + buf_set_read(&buf, (const uint8_t *)peer_info, strlen(peer_info)); while (buf_parse(&buf, '\n', line, sizeof(line))) { chomp(line); if (validate_peer_info_line(line) - && (strncmp(line, "IV_", 3) =3D=3D 0 || strncmp(line, "UV_", 3= ) =3D=3D 0) ) + && (strncmp(line, "IV_", 3) =3D=3D 0 || strncmp(line, "UV_", 3= ) =3D=3D 0)) { msg(M_INFO, "peer info: %s", line); env_set_add(es, line); diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h index c6e2fa51..07ac92d 100644 --- a/src/openvpn/misc.h +++ b/src/openvpn/misc.h @@ -43,8 +43,7 @@ const char **make_arg_array(const char *first, const char *parms, struct g= c_arena *gc); -const char **make_extended_arg_array(char **p, bool is_inline, - struct gc_arena *gc); +const char **make_extended_arg_array(char **p, bool is_inline, struct gc_a= rena *gc); /* prepend a random prefix to hostname */ const char *hostname_randomize(const char *hostname, struct gc_arena *gc); @@ -77,9 +76,10 @@ /* * Challenge response info on client as pushed by server. */ -struct auth_challenge_info { -#define CR_ECHO (1<<0) /* echo response when typed by user */ -#define CR_RESPONSE (1<<1) /* response needed */ +struct auth_challenge_info +{ +#define CR_ECHO (1 << 0) /* echo response when typed by user */ +#define CR_RESPONSE (1 << 1) /* response needed */ unsigned int flags; const char *user; @@ -90,38 +90,43 @@ /* * Challenge response info on client as pushed by server. */ -struct static_challenge_info { -#define SC_ECHO (1<<0) /* echo response when typed by user */ -#define SC_CONCAT (1<<1) /* concatenate password and response and do no= t base64 encode */ +struct static_challenge_info +{ +#define SC_ECHO (1 << 0) /* echo response when typed by user */ +#define SC_CONCAT (1 << 1) /* concatenate password and response and do not= base64 encode */ unsigned int flags; const char *challenge_text; }; #else /* ifdef ENABLE_MANAGEMENT */ -struct auth_challenge_info {}; -struct static_challenge_info {}; +struct auth_challenge_info +{ +}; +struct static_challenge_info +{ +}; #endif /* ifdef ENABLE_MANAGEMENT */ /* * Flags for get_user_pass and management_query_user_pass */ -#define GET_USER_PASS_MANAGEMENT (1<<0) +#define GET_USER_PASS_MANAGEMENT (1 << 0) /* GET_USER_PASS_SENSITIVE (1<<1) not used anymore */ -#define GET_USER_PASS_PASSWORD_ONLY (1<<2) -#define GET_USER_PASS_NEED_OK (1<<3) -#define GET_USER_PASS_NOFATAL (1<<4) -#define GET_USER_PASS_NEED_STR (1<<5) -#define GET_USER_PASS_PREVIOUS_CREDS_FAILED (1<<6) +#define GET_USER_PASS_PASSWORD_ONLY (1 << 2) +#define GET_USER_PASS_NEED_OK (1 << 3) +#define GET_USER_PASS_NOFATAL (1 << 4) +#define GET_USER_PASS_NEED_STR (1 << 5) +#define GET_USER_PASS_PREVIOUS_CREDS_FAILED (1 << 6) -#define GET_USER_PASS_DYNAMIC_CHALLENGE (1<<7) /**< CRV1 protocol --= dynamic challenge */ -#define GET_USER_PASS_STATIC_CHALLENGE (1<<8) /**< SCRV1 protocol --= static challenge */ -#define GET_USER_PASS_STATIC_CHALLENGE_ECHO (1<<9) /**< SCRV1 protocol --= echo response */ +#define GET_USER_PASS_DYNAMIC_CHALLENGE (1 << 7) /**< CRV1 protocol -= - dynamic challenge */ +#define GET_USER_PASS_STATIC_CHALLENGE (1 << 8) /**< SCRV1 protocol -= - static challenge */ +#define GET_USER_PASS_STATIC_CHALLENGE_ECHO (1 << 9) /**< SCRV1 protocol -= - echo response */ /** indicates that auth_file is actually inline creds */ -#define GET_USER_PASS_INLINE_CREDS (1<<10) +#define GET_USER_PASS_INLINE_CREDS (1 << 10) /** indicates password and response should be concatenated */ -#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT (1<<11) +#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT (1 << 11) /** * Retrieves the user credentials from various sources depending on the fl= ags. @@ -133,11 +138,8 @@ * @param auth_challenge The authentication challenge string. * @return true if the user credentials were successfully retrieved, false= otherwise. */ -bool get_user_pass_cr(struct user_pass *up, - const char *auth_file, - const char *prefix, - const unsigned int flags, - const char *auth_challenge); +bool get_user_pass_cr(struct user_pass *up, const char *auth_file, const c= har *prefix, + const unsigned int flags, const char *auth_challenge= ); /** * Retrieves the user credentials from various sources depending on the fl= ags. @@ -149,9 +151,7 @@ * @return true if the user credentials were successfully retrieved, false= otherwise. */ static inline bool -get_user_pass(struct user_pass *up, - const char *auth_file, - const char *prefix, +get_user_pass(struct user_pass *up, const char *auth_file, const char *pre= fix, const unsigned int flags) { return get_user_pass_cr(up, auth_file, prefix, flags, NULL); @@ -206,29 +206,24 @@ /** * Prepend a directory to a path. */ -struct buffer -prepend_dir(const char *dir, const char *path, struct gc_arena *gc); +struct buffer prepend_dir(const char *dir, const char *path, struct gc_are= na *gc); /** * Encrypt username and password buffers in user_pass */ -void -protect_user_pass(struct user_pass *up); +void protect_user_pass(struct user_pass *up); /** * Decrypt username and password buffers in user_pass */ -void -unprotect_user_pass(struct user_pass *up); +void unprotect_user_pass(struct user_pass *up); =20 -#define _STRINGIFY(S) #S +#define _STRINGIFY(S) #S /* *INDENT-OFF* - uncrustify need to ignore this macro */ -#define MAC_FMT _STRINGIFY(%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx) +#define MAC_FMT _STRINGIFY(%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:= %02hhx) /* *INDENT-ON* */ -#define MAC_PRINT_ARG(_mac) _mac[0], _mac[1], _mac[2], \ - _mac[3], _mac[4], _mac[5] -#define MAC_SCAN_ARG(_mac) &_mac[0], &_mac[1], &_mac[2], \ - &_mac[3], &_mac[4], &_mac[5] +#define MAC_PRINT_ARG(_mac) _mac[0], _mac[1], _mac[2], _mac[3], _mac[4], _= mac[5] +#define MAC_SCAN_ARG(_mac) &_mac[0], &_mac[1], &_mac[2], &_mac[3], &_mac[= 4], &_mac[5] #endif /* ifndef MISC_H */ diff --git a/src/openvpn/mroute.c b/src/openvpn/mroute.c index a617b33..4692cbf 100644 --- a/src/openvpn/mroute.c +++ b/src/openvpn/mroute.c @@ -48,14 +48,13 @@ static inline bool is_mac_mcast_addr(const uint8_t *mac) { - return (bool) (mac[0] & 1); + return (bool)(mac[0] & 1); } static inline bool is_mac_mcast_maddr(const struct mroute_addr *addr) { - return (addr->type & MR_ADDR_MASK) =3D=3D MR_ADDR_ETHER - && is_mac_mcast_addr(addr->ether.addr); + return (addr->type & MR_ADDR_MASK) =3D=3D MR_ADDR_ETHER && is_mac_mcas= t_addr(addr->ether.addr); } /* @@ -82,8 +81,7 @@ } /* only networkss shorter than 8 bits are allowed to be all 0s. */ - if (all_zeros - && !((addr->type & MR_WITH_NETBITS) && (addr->netbits < 8))) + if (all_zeros && !((addr->type & MR_WITH_NETBITS) && (addr->netbits < = 8))) { msg(D_MULTI_LOW, "Can't learn %s: network is all 0s, but netbits >= =3D 8", mroute_addr_print(addr, gc)); @@ -92,8 +90,7 @@ if (all_ones) { - msg(D_MULTI_LOW, "Can't learn %s: network is all 1s", - mroute_addr_print(addr, gc)); + msg(D_MULTI_LOW, "Can't learn %s: network is all 1s", mroute_addr_= print(addr, gc)); return false; } @@ -148,8 +145,7 @@ unsigned int -mroute_extract_addr_ip(struct mroute_addr *src, struct mroute_addr *dest, - const struct buffer *buf) +mroute_extract_addr_ip(struct mroute_addr *src, struct mroute_addr *dest, = const struct buffer *buf) { unsigned int ret =3D 0; if (BLEN(buf) >=3D 1) @@ -157,9 +153,9 @@ switch (OPENVPN_IPH_GET_VER(*BPTR(buf))) { case 4: - if (BLEN(buf) >=3D (int) sizeof(struct openvpn_iphdr)) + if (BLEN(buf) >=3D (int)sizeof(struct openvpn_iphdr)) { - const struct openvpn_iphdr *ip =3D (const struct openv= pn_iphdr *) BPTR(buf); + const struct openvpn_iphdr *ip =3D (const struct openv= pn_iphdr *)BPTR(buf); mroute_get_in_addr_t(src, ip->saddr, 0); mroute_get_in_addr_t(dest, ip->daddr, 0); @@ -181,10 +177,10 @@ break; case 6: - if (BLEN(buf) >=3D (int) sizeof(struct openvpn_ipv6hdr)) + if (BLEN(buf) >=3D (int)sizeof(struct openvpn_ipv6hdr)) { - const struct openvpn_ipv6hdr *ipv6 =3D (const struct o= penvpn_ipv6hdr *) BPTR(buf); -#if 0 /* very basic debug */ + const struct openvpn_ipv6hdr *ipv6 =3D (const struct o= penvpn_ipv6hdr *)BPTR(buf); +#if 0 /* very basic debug */ struct gc_arena gc =3D gc_new(); msg( M_INFO, "IPv6 packet! src=3D%s, dst=3D%s", print_in6_addr( ipv6->saddr, 0, &gc ), @@ -213,9 +209,7 @@ } static void -mroute_copy_ether_to_addr(struct mroute_addr *maddr, - const uint8_t *ether_addr, - uint16_t vid) +mroute_copy_ether_to_addr(struct mroute_addr *maddr, const uint8_t *ether_= addr, uint16_t vid) { maddr->type =3D MR_ADDR_ETHER; maddr->netbits =3D 0; @@ -226,15 +220,13 @@ } unsigned int -mroute_extract_addr_ether(struct mroute_addr *src, - struct mroute_addr *dest, - uint16_t vid, +mroute_extract_addr_ether(struct mroute_addr *src, struct mroute_addr *des= t, uint16_t vid, const struct buffer *buf) { unsigned int ret =3D 0; - if (BLEN(buf) >=3D (int) sizeof(struct openvpn_ethhdr)) + if (BLEN(buf) >=3D (int)sizeof(struct openvpn_ethhdr)) { - const struct openvpn_ethhdr *eth =3D (const struct openvpn_ethhdr = *) BPTR(buf); + const struct openvpn_ethhdr *eth =3D (const struct openvpn_ethhdr = *)BPTR(buf); if (src) { mroute_copy_ether_to_addr(src, eth->source, vid); @@ -251,7 +243,6 @@ } ret |=3D MROUTE_EXTRACT_SUCCEEDED; - } return ret; } @@ -261,8 +252,7 @@ * to a struct mroute_addr (addr). */ bool -mroute_extract_openvpn_sockaddr(struct mroute_addr *addr, - const struct openvpn_sockaddr *osaddr, +mroute_extract_openvpn_sockaddr(struct mroute_addr *addr, const struct ope= nvpn_sockaddr *osaddr, bool use_port) { switch (osaddr->addr.sa.sa_family) @@ -336,7 +326,7 @@ } else if ((ma->type & MR_ADDR_MASK) =3D=3D MR_ADDR_IPV6) { - int byte =3D sizeof(ma->v6.addr) - 1; /* rightmost byte in add= ress */ + int byte =3D sizeof(ma->v6.addr) - 1; /* rightmost byte in address= */ int bits_to_clear =3D 128 - ma->netbits; while (byte >=3D 0 && bits_to_clear > 0) @@ -352,7 +342,7 @@ bits_to_clear =3D 0; } } - ASSERT( bits_to_clear =3D=3D 0 ); + ASSERT(bits_to_clear =3D=3D 0); } else { @@ -368,29 +358,24 @@ uint32_t mroute_addr_hash_function(const void *key, uint32_t iv) { - return hash_func(mroute_addr_hash_ptr((const struct mroute_addr *) key= ), - mroute_addr_hash_len((const struct mroute_addr *) key= ), - iv); + return hash_func(mroute_addr_hash_ptr((const struct mroute_addr *)key), + mroute_addr_hash_len((const struct mroute_addr *)key)= , iv); } bool mroute_addr_compare_function(const void *key1, const void *key2) { - return mroute_addr_equal((const struct mroute_addr *) key1, - (const struct mroute_addr *) key2); + return mroute_addr_equal((const struct mroute_addr *)key1, (const stru= ct mroute_addr *)key2); } const char * -mroute_addr_print(const struct mroute_addr *ma, - struct gc_arena *gc) +mroute_addr_print(const struct mroute_addr *ma, struct gc_arena *gc) { return mroute_addr_print_ex(ma, MAPF_IA_EMPTY_IF_UNDEF, gc); } const char * -mroute_addr_print_ex(const struct mroute_addr *ma, - const unsigned int flags, - struct gc_arena *gc) +mroute_addr_print_ex(const struct mroute_addr *ma, const unsigned int flag= s, struct gc_arena *gc) { struct buffer out =3D alloc_buf_gc(64, gc); if (ma) @@ -400,8 +385,8 @@ switch (maddr.type & MR_ADDR_MASK) { case MR_ADDR_ETHER: - buf_printf(&out, "%s", format_hex_ex(ma->ether.addr, - sizeof(ma->ether.addr= ), 0, 1, ":", gc)); + buf_printf(&out, "%s", + format_hex_ex(ma->ether.addr, sizeof(ma->ether.= addr), 0, 1, ":", gc)); buf_printf(&out, "@%hu", ma->ether.vid); break; @@ -415,8 +400,10 @@ { buf_printf(&out, "%s:", proto2ascii(maddr.proto, AF_IN= ET, false)); } - buf_printf(&out, "%s", print_in_addr_t(ntohl(maddr.v4.addr= ), - (flags & MAPF_IA_EM= PTY_IF_UNDEF) ? IA_EMPTY_IF_UNDEF : 0, gc)); + buf_printf(&out, "%s", + print_in_addr_t(ntohl(maddr.v4.addr), + (flags & MAPF_IA_EMPTY_IF_UNDEF= ) ? IA_EMPTY_IF_UNDEF : 0, + gc)); if (maddr.type & MR_WITH_NETBITS) { if (flags & MAPF_SUBNET) @@ -442,10 +429,10 @@ { buf_printf(&out, "%s:", proto2ascii(maddr.proto, AF_IN= ET6, false)); } - if (IN6_IS_ADDR_V4MAPPED( &maddr.v6.addr ) ) + if (IN6_IS_ADDR_V4MAPPED(&maddr.v6.addr)) { - buf_printf(&out, "%s", print_in_addr_t(maddr.v4mappedv= 6.addr, - IA_NET_ORDER, g= c)); + buf_printf(&out, "%s", + print_in_addr_t(maddr.v4mappedv6.addr, IA_N= ET_ORDER, gc)); } else if (maddr.type & MR_WITH_PORT) { @@ -501,7 +488,7 @@ { if (mh->net_len_refcount[i] > 0) { - mh->net_len[j++] =3D (uint8_t) i; + mh->net_len[j++] =3D (uint8_t)i; } } mh->n_net_len =3D j; diff --git a/src/openvpn/mroute.h b/src/openvpn/mroute.h index c359fd2..08e8f6e 100644 --- a/src/openvpn/mroute.h +++ b/src/openvpn/mroute.h @@ -30,22 +30,22 @@ #include -#define IP_MCAST_SUBNET_MASK ((in_addr_t)240<<24) -#define IP_MCAST_NETWORK ((in_addr_t)224<<24) +#define IP_MCAST_SUBNET_MASK ((in_addr_t)240 << 24) +#define IP_MCAST_NETWORK ((in_addr_t)224 << 24) /* Return status values for mroute_extract_addr_from_packet */ -#define MROUTE_EXTRACT_SUCCEEDED (1<<0) -#define MROUTE_EXTRACT_BCAST (1<<1) -#define MROUTE_EXTRACT_MCAST (1<<2) -#define MROUTE_EXTRACT_IGMP (1<<3) +#define MROUTE_EXTRACT_SUCCEEDED (1 << 0) +#define MROUTE_EXTRACT_BCAST (1 << 1) +#define MROUTE_EXTRACT_MCAST (1 << 2) +#define MROUTE_EXTRACT_IGMP (1 << 3) -#define MROUTE_SEC_EXTRACT_SUCCEEDED (1<<(0+MROUTE_SEC_SHIFT)) -#define MROUTE_SEC_EXTRACT_BCAST (1<<(1+MROUTE_SEC_SHIFT)) -#define MROUTE_SEC_EXTRACT_MCAST (1<<(2+MROUTE_SEC_SHIFT)) -#define MROUTE_SEC_EXTRACT_IGMP (1<<(3+MROUTE_SEC_SHIFT)) +#define MROUTE_SEC_EXTRACT_SUCCEEDED (1 << (0 + MROUTE_SEC_SHIFT)) +#define MROUTE_SEC_EXTRACT_BCAST (1 << (1 + MROUTE_SEC_SHIFT)) +#define MROUTE_SEC_EXTRACT_MCAST (1 << (2 + MROUTE_SEC_SHIFT)) +#define MROUTE_SEC_EXTRACT_IGMP (1 << (3 + MROUTE_SEC_SHIFT)) -#define MROUTE_SEC_SHIFT 4 +#define MROUTE_SEC_SHIFT 4 /* * Choose the largest address possible with @@ -57,60 +57,64 @@ /* * Address Types */ -#define MR_ADDR_NONE 0 -#define MR_ADDR_ETHER 1 -#define MR_ADDR_IPV4 2 -#define MR_ADDR_IPV6 3 -#define MR_ADDR_MASK 3 +#define MR_ADDR_NONE 0 +#define MR_ADDR_ETHER 1 +#define MR_ADDR_IPV4 2 +#define MR_ADDR_IPV6 3 +#define MR_ADDR_MASK 3 /* Address type mask indicating that port # is part of address */ -#define MR_WITH_PORT 4 +#define MR_WITH_PORT 4 /* Address type mask indicating that netbits is part of address */ -#define MR_WITH_NETBITS 8 +#define MR_WITH_NETBITS 8 /* Indicates than IPv4 addr was extracted from ARP packet */ -#define MR_ARP 16 +#define MR_ARP 16 /* Address type mask indicating that proto # is part of address */ -#define MR_WITH_PROTO 32 +#define MR_WITH_PROTO 32 -struct mroute_addr { - uint8_t len; /* length of address */ +struct mroute_addr +{ + uint8_t len; /* length of address */ uint8_t proto; - uint8_t type; /* MR_ADDR/MR_WITH flags */ + uint8_t type; /* MR_ADDR/MR_WITH flags */ uint8_t netbits; /* number of bits in network part of address, * valid if MR_WITH_NETBITS is set */ - union { + union + { uint8_t raw_addr[MR_MAX_ADDR_LEN]; /* actual address */ - struct { + struct + { uint8_t addr[OPENVPN_ETH_ALEN]; uint16_t vid; } ether; - struct { - in_addr_t addr; /* _network order_ IPv4 address */ - in_port_t port; /* _network order_ TCP/UDP port */ + struct + { + in_addr_t addr; /* _network order_ IPv4 address */ + in_port_t port; /* _network order_ TCP/UDP port */ } v4; - struct { + struct + { struct in6_addr addr; - in_port_t port; /* _network order_ TCP/UDP port */ + in_port_t port; /* _network order_ TCP/UDP port */ } v6; - struct { + struct + { uint8_t prefix[12]; - in_addr_t addr; /* _network order_ IPv4 address */ + in_addr_t addr; /* _network order_ IPv4 address */ } v4mappedv6; }; }; /* Double-check that struct packing works as expected */ -static_assert(offsetof(struct mroute_addr, v4.port) =3D=3D - offsetof(struct mroute_addr, v4) + 4, +static_assert(offsetof(struct mroute_addr, v4.port) =3D=3D offsetof(struct= mroute_addr, v4) + 4, "Unexpected struct packing of v4"); -static_assert(offsetof(struct mroute_addr, v6.port) =3D=3D - offsetof(struct mroute_addr, v6) + 16, +static_assert(offsetof(struct mroute_addr, v6.port) =3D=3D offsetof(struct= mroute_addr, v6) + 16, "Unexpected struct packing of v6"); -static_assert(offsetof(struct mroute_addr, v4mappedv6.addr) =3D=3D - offsetof(struct mroute_addr, v4mappedv6) + 12, +static_assert(offsetof(struct mroute_addr, v4mappedv6.addr) + =3D=3D offsetof(struct mroute_addr, v4mappedv6) + 12, "Unexpected struct packing of v4mappedv6"); /* @@ -121,22 +125,21 @@ /* * Used to help maintain CIDR routing table. */ -struct mroute_helper { - unsigned int cache_generation; /* incremented when route added */ - int ageable_ttl_secs; /* host route cache entry time-to-live*/ - int n_net_len; /* length of net_len array */ - uint8_t net_len[MR_HELPER_NET_LEN]; /* CIDR netlengths in descendin= g order */ +struct mroute_helper +{ + unsigned int cache_generation; /* incremented when route add= ed */ + int ageable_ttl_secs; /* host route cache entry tim= e-to-live*/ + int n_net_len; /* length of net_len array */ + uint8_t net_len[MR_HELPER_NET_LEN]; /* CIDR netlengths in descend= ing order */ int net_len_refcount[MR_HELPER_NET_LEN]; /* refcount of each netlength= */ }; struct openvpn_sockaddr; bool mroute_extract_openvpn_sockaddr(struct mroute_addr *addr, - const struct openvpn_sockaddr *osaddr, - bool use_port); + const struct openvpn_sockaddr *osaddr= , bool use_port); -bool mroute_learnable_address(const struct mroute_addr *addr, - struct gc_arena *gc); +bool mroute_learnable_address(const struct mroute_addr *addr, struct gc_ar= ena *gc); uint32_t mroute_addr_hash_function(const void *key, uint32_t iv); @@ -144,14 +147,12 @@ void mroute_addr_init(struct mroute_addr *addr); -const char *mroute_addr_print(const struct mroute_addr *ma, - struct gc_arena *gc); +const char *mroute_addr_print(const struct mroute_addr *ma, struct gc_aren= a *gc); -#define MAPF_SUBNET (1<<0) -#define MAPF_IA_EMPTY_IF_UNDEF (1<<1) -#define MAPF_SHOW_ARP (1<<2) -const char *mroute_addr_print_ex(const struct mroute_addr *ma, - const unsigned int flags, +#define MAPF_SUBNET (1 << 0) +#define MAPF_IA_EMPTY_IF_UNDEF (1 << 1) +#define MAPF_SHOW_ARP (1 << 2) +const char *mroute_addr_print_ex(const struct mroute_addr *ma, const unsig= ned int flags, struct gc_arena *gc); void mroute_addr_mask_host_bits(struct mroute_addr *ma); @@ -164,25 +165,19 @@ void mroute_helper_del_iroute46(struct mroute_helper *mh, int netbits); -unsigned int mroute_extract_addr_ip(struct mroute_addr *src, - struct mroute_addr *dest, +unsigned int mroute_extract_addr_ip(struct mroute_addr *src, struct mroute= _addr *dest, const struct buffer *buf); -unsigned int mroute_extract_addr_ether(struct mroute_addr *src, - struct mroute_addr *dest, - uint16_t vid, - const struct buffer *buf); +unsigned int mroute_extract_addr_ether(struct mroute_addr *src, struct mro= ute_addr *dest, + uint16_t vid, const struct buffer *= buf); /* * Given a raw packet in buf, return the src and dest * addresses of the packet. */ static inline unsigned int -mroute_extract_addr_from_packet(struct mroute_addr *src, - struct mroute_addr *dest, - uint16_t vid, - const struct buffer *buf, - int tunnel_type) +mroute_extract_addr_from_packet(struct mroute_addr *src, struct mroute_add= r *dest, uint16_t vid, + const struct buffer *buf, int tunnel_type) { unsigned int ret =3D 0; verify_align_4(buf); @@ -232,13 +227,13 @@ mroute_addr_hash_ptr(const struct mroute_addr *a) { /* NOTE: depends on ordering of struct mroute_addr */ - return (uint8_t *) &a->proto; + return (uint8_t *)&a->proto; } static inline uint32_t mroute_addr_hash_len(const struct mroute_addr *a) { - return (uint32_t) a->len + 3; + return (uint32_t)a->len + 3; } static inline void diff --git a/src/openvpn/mss.c b/src/openvpn/mss.c index 01ccdeb..2ab839c 100644 --- a/src/openvpn/mss.c +++ b/src/openvpn/mss.c @@ -49,27 +49,24 @@ const struct openvpn_iphdr *pip; int hlen; - if (BLEN(buf) < (int) sizeof(struct openvpn_iphdr)) + if (BLEN(buf) < (int)sizeof(struct openvpn_iphdr)) { return; } verify_align_4(buf); - pip =3D (struct openvpn_iphdr *) BPTR(buf); + pip =3D (struct openvpn_iphdr *)BPTR(buf); hlen =3D OPENVPN_IPH_GET_LEN(pip->version_len); - if (pip->protocol =3D=3D OPENVPN_IPPROTO_TCP - && ntohs(pip->tot_len) =3D=3D BLEN(buf) - && (ntohs(pip->frag_off) & OPENVPN_IP_OFFMASK) =3D=3D 0 - && hlen <=3D BLEN(buf) - && BLEN(buf) - hlen - >=3D (int) sizeof(struct openvpn_tcphdr)) + if (pip->protocol =3D=3D OPENVPN_IPPROTO_TCP && ntohs(pip->tot_len) = =3D=3D BLEN(buf) + && (ntohs(pip->frag_off) & OPENVPN_IP_OFFMASK) =3D=3D 0 && hlen <= =3D BLEN(buf) + && BLEN(buf) - hlen >=3D (int)sizeof(struct openvpn_tcphdr)) { struct buffer newbuf =3D *buf; if (buf_advance(&newbuf, hlen)) { - struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *) BPTR(&= newbuf); + struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *)BPTR(&n= ewbuf); if (tc->flags & OPENVPN_TCPH_SYN_MASK) { mss_fixup_dowork(&newbuf, maxmss); @@ -89,18 +86,18 @@ const struct openvpn_ipv6hdr *pip6; struct buffer newbuf; - if (BLEN(buf) < (int) sizeof(struct openvpn_ipv6hdr)) + if (BLEN(buf) < (int)sizeof(struct openvpn_ipv6hdr)) { return; } verify_align_4(buf); - pip6 =3D (struct openvpn_ipv6hdr *) BPTR(buf); + pip6 =3D (struct openvpn_ipv6hdr *)BPTR(buf); /* do we have the full IPv6 packet? * "payload_len" does not include IPv6 header (+40 bytes) */ - if (BLEN(buf) !=3D (int) ntohs(pip6->payload_len)+40) + if (BLEN(buf) !=3D (int)ntohs(pip6->payload_len) + 40) { return; } @@ -124,13 +121,12 @@ * verify remainder is large enough to contain a full TCP header */ newbuf =3D *buf; - if (buf_advance( &newbuf, 40 ) - && BLEN(&newbuf) >=3D (int) sizeof(struct openvpn_tcphdr)) + if (buf_advance(&newbuf, 40) && BLEN(&newbuf) >=3D (int)sizeof(struct = openvpn_tcphdr)) { - struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *) BPTR(&newb= uf); + struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *)BPTR(&newbu= f); if (tc->flags & OPENVPN_TCPH_SYN_MASK) { - mss_fixup_dowork(&newbuf, maxmss-20); + mss_fixup_dowork(&newbuf, maxmss - 20); } } } @@ -149,25 +145,22 @@ int accumulate; struct openvpn_tcphdr *tc; - if (BLEN(buf) < (int) sizeof(struct openvpn_tcphdr)) + if (BLEN(buf) < (int)sizeof(struct openvpn_tcphdr)) { return; } verify_align_4(buf); - tc =3D (struct openvpn_tcphdr *) BPTR(buf); + tc =3D (struct openvpn_tcphdr *)BPTR(buf); hlen =3D OPENVPN_TCPH_GET_DOFF(tc->doff_res); /* Invalid header length or header without options. */ - if (hlen <=3D (int) sizeof(struct openvpn_tcphdr) - || hlen > BLEN(buf)) + if (hlen <=3D (int)sizeof(struct openvpn_tcphdr) || hlen > BLEN(buf)) { return; } - for (olen =3D hlen - (int) sizeof(struct openvpn_tcphdr), - opt =3D (uint8_t *)(tc + 1); - olen > 1; + for (olen =3D hlen - (int)sizeof(struct openvpn_tcphdr), opt =3D (uint= 8_t *)(tc + 1); olen > 1; olen -=3D optlen, opt +=3D optlen) { if (*opt =3D=3D OPENVPN_TCPOPT_EOL) @@ -197,8 +190,8 @@ { dmsg(D_MSS, "MSS: %" PRIu16 " -> %" PRIu16, mssval, ma= xmss); accumulate =3D htons(mssval); - opt[2] =3D (uint8_t)((maxmss>>8)&0xff); - opt[3] =3D (uint8_t)(maxmss&0xff); + opt[2] =3D (uint8_t)((maxmss >> 8) & 0xff); + opt[3] =3D (uint8_t)(maxmss & 0xff); accumulate -=3D htons(maxmss); ADJUST_CHECKSUM(accumulate, tc->check); } @@ -228,8 +221,7 @@ } static size_t -get_ip_encap_overhead(const struct options *options, - const struct link_socket_info *lsi) +get_ip_encap_overhead(const struct options *options, const struct link_soc= ket_info *lsi) { /* Add the overhead of the encapsulating IP packets */ sa_family_t af; @@ -253,8 +245,7 @@ } static void -frame_calculate_fragment(struct frame *frame, struct key_type *kt, - const struct options *options, +frame_calculate_fragment(struct frame *frame, struct key_type *kt, const s= truct options *options, struct link_socket_info *lsi) { #if defined(ENABLE_FRAGMENT) @@ -284,8 +275,7 @@ } static void -frame_calculate_mssfix(struct frame *frame, struct key_type *kt, - const struct options *options, +frame_calculate_mssfix(struct frame *frame, struct key_type *kt, const str= uct options *options, struct link_socket_info *lsi) { if (options->ce.mssfix_fixed) @@ -327,13 +317,10 @@ /* This is the target value our payload needs to be smaller */ size_t target =3D options->ce.mssfix - overhead; frame->mss_fix =3D (uint16_t)(adjust_payload_max_cbc(kt, target) - pay= load_overhead); - - } void -frame_calculate_dynamic(struct frame *frame, struct key_type *kt, - const struct options *options, +frame_calculate_dynamic(struct frame *frame, struct key_type *kt, const st= ruct options *options, struct link_socket_info *lsi) { if (options->ce.fragment > 0) @@ -364,30 +351,29 @@ int encap_overhead =3D datagram_overhead(af, proto); /* check if mssfix and fragment need to be adjusted */ - if (pmtu < o->ce.mssfix - || (o->ce.mssfix_encap && pmtu < o->ce.mssfix + encap_overhead)) + if (pmtu < o->ce.mssfix || (o->ce.mssfix_encap && pmtu < o->ce.mssfix = + encap_overhead)) { const char *mtustr =3D o->ce.mssfix_encap ? " mtu" : ""; - msg(D_MTU_INFO, "Note adjusting 'mssfix %d%s' to 'mssfix %d mtu' " - "according to path MTU discovery", o->ce.mssfix, - mtustr, pmtu); + msg(D_MTU_INFO, + "Note adjusting 'mssfix %d%s' to 'mssfix %d mtu' " + "according to path MTU discovery", + o->ce.mssfix, mtustr, pmtu); o->ce.mssfix =3D pmtu; o->ce.mssfix_encap =3D true; frame_calculate_dynamic(&c->c2.frame, &c->c1.ks.key_type, o, lsi); } #if defined(ENABLE_FRAGMENT) - if (pmtu < o->ce.fragment - || (o->ce.fragment_encap && pmtu < o->ce.fragment + encap_overhead= )) + if (pmtu < o->ce.fragment || (o->ce.fragment_encap && pmtu < o->ce.fra= gment + encap_overhead)) { const char *mtustr =3D o->ce.fragment_encap ? " mtu" : ""; - msg(D_MTU_INFO, "Note adjusting 'fragment %d%s' to 'fragment %d mt= u' " - "according to path MTU discovery", o->ce.fragment, - mtustr, pmtu); + msg(D_MTU_INFO, + "Note adjusting 'fragment %d%s' to 'fragment %d mtu' " + "according to path MTU discovery", + o->ce.fragment, mtustr, pmtu); o->ce.fragment =3D pmtu; o->ce.fragment_encap =3D true; - frame_calculate_dynamic(&c->c2.frame_fragment, &c->c1.ks.key_type, - o, lsi); + frame_calculate_dynamic(&c->c2.frame_fragment, &c->c1.ks.key_type,= o, lsi); } #endif } diff --git a/src/openvpn/mss.h b/src/openvpn/mss.h index 426af5e..46a956e 100644 --- a/src/openvpn/mss.h +++ b/src/openvpn/mss.h @@ -37,8 +37,7 @@ /** Set the --mssfix option. */ void frame_calculate_dynamic(struct frame *frame, struct key_type *kt, - const struct options *options, - struct link_socket_info *lsi); + const struct options *options, struct link_so= cket_info *lsi); /** * Checks and adjusts the fragment and mssfix value according to the diff --git a/src/openvpn/mstats.c b/src/openvpn/mstats.c index cbef26a..b9c6741 100644 --- a/src/openvpn/mstats.c +++ b/src/openvpn/mstats.c @@ -84,7 +84,7 @@ } /* mmap the file */ - data =3D mmap(NULL, sizeof(struct mmap_stats), PROT_READ|PROT_WRITE, M= AP_SHARED, fd, 0); + data =3D mmap(NULL, sizeof(struct mmap_stats), PROT_READ | PROT_WRITE,= MAP_SHARED, fd, 0); if (data =3D=3D MAP_FAILED) { msg(M_ERR, "mstats_open: write error: %s", fn); diff --git a/src/openvpn/mstats.h b/src/openvpn/mstats.h index ea0237f..8d63457 100644 --- a/src/openvpn/mstats.h +++ b/src/openvpn/mstats.h @@ -31,7 +31,8 @@ #include "basic.h" /* this struct is mapped to the file */ -struct mmap_stats { +struct mmap_stats +{ counter_type link_read_bytes; /* counter_type can be assumed to be a u= int64_t */ counter_type link_write_bytes; int n_clients; diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c index 71991dd..5bc2578 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -67,8 +67,9 @@ if (he) { - struct multi_instance *oldmi =3D (struct multi_instance *) he-= >value; - msg(D_MULTI_LOW, "MULTI TCP: new incoming client address match= es existing client address -- new client takes precedence"); + struct multi_instance *oldmi =3D (struct multi_instance *)he->= value; + msg(D_MULTI_LOW, + "MULTI TCP: new incoming client address matches existing c= lient address -- new client takes precedence"); oldmi->did_real_hash =3D false; multi_close_instance(m, oldmi, false); he->key =3D &mi->real; @@ -109,12 +110,10 @@ ASSERT(mi->context.c2.link_sockets[0]->info.lsa); ASSERT(mi->context.c2.link_sockets[0]->mode =3D=3D LS_MODE_TCP_ACCEPT_= FROM); ASSERT(mi->context.c2.link_sockets[0]->info.lsa->actual.dest.addr.sa.s= a_family =3D=3D AF_INET - || mi->context.c2.link_sockets[0]->info.lsa->actual.dest.addr.s= a.sa_family =3D=3D AF_INET6 - ); + || mi->context.c2.link_sockets[0]->info.lsa->actual.dest.addr.s= a.sa_family =3D=3D AF_INET6); mi->real.proto =3D mi->context.c2.link_sockets[0]->info.proto; - if (!mroute_extract_openvpn_sockaddr(&mi->real, - &mi->context.c2.link_sockets[0]->= info.lsa->actual.dest, - true)) + if (!mroute_extract_openvpn_sockaddr( + &mi->real, &mi->context.c2.link_sockets[0]->info.lsa->actual.d= est, true)) { msg(D_MULTI_ERRORS, "MULTI TCP: TCP client address is undefined"); return false; @@ -150,7 +149,8 @@ } bool -multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct mult= i_instance *mi, const unsigned int mpp_flags) +multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct mult= i_instance *mi, + const unsigned int mpp_flags) { struct mbuf_item item; bool ret =3D true; diff --git a/src/openvpn/mtcp.h b/src/openvpn/mtcp.h index 334d6eb..500aec2 100644 --- a/src/openvpn/mtcp.h +++ b/src/openvpn/mtcp.h @@ -40,9 +40,11 @@ void multi_tcp_instance_specific_free(struct multi_instance *mi); -bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, = const unsigned int mpp_flags); +bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, + const unsigned int mpp_flags); -bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct= multi_instance *mi, const unsigned int mpp_flags); +bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct= multi_instance *mi, + const unsigned int mpp_flags); struct multi_instance *multi_create_instance_tcp(struct multi_context *m, = struct link_socket *sock); =20 diff --git a/src/openvpn/mtu.c b/src/openvpn/mtu.c index 78f1309..2b76387 100644 --- a/src/openvpn/mtu.c +++ b/src/openvpn/mtu.c @@ -39,8 +39,7 @@ /* allocate a buffer for socket or tun layer */ void -alloc_buf_sock_tun(struct buffer *buf, - const struct frame *frame) +alloc_buf_sock_tun(struct buffer *buf, const struct frame *frame) { /* allocate buffer for overlapped I/O */ *buf =3D alloc_buf(BUF_SIZE(frame)); @@ -60,8 +59,7 @@ } size_t -frame_calculate_protocol_header_size(const struct key_type *kt, - const struct options *options, +frame_calculate_protocol_header_size(const struct key_type *kt, const stru= ct options *options, bool occ) { /* Sum of all the overhead that reduces the usable packet size */ @@ -98,8 +96,7 @@ size_t -frame_calculate_payload_overhead(size_t extra_tun, - const struct options *options, +frame_calculate_payload_overhead(size_t extra_tun, const struct options *o= ptions, const struct key_type *kt) { size_t overhead =3D 0; @@ -139,8 +136,7 @@ } size_t -frame_calculate_payload_size(const struct frame *frame, - const struct options *options, +frame_calculate_payload_size(const struct frame *frame, const struct optio= ns *options, const struct key_type *kt) { size_t payload_size =3D options->ce.tun_mtu; @@ -175,7 +171,7 @@ * overhead */ /* overhead of BF-CBC: 64 bit block size, 64 bit IV size */ - overhead +=3D 64/8 + 64/8; + overhead +=3D 64 / 8 + 64 / 8; /* set ciphername to none, so its size does get added in the * fake_kt and the cipher is not tried to be resolved */ ciphername =3D "none"; @@ -192,9 +188,7 @@ } void -frame_print(const struct frame *frame, - int level, - const char *prefix) +frame_print(const struct frame *frame, int level, const char *prefix) { struct gc_arena gc =3D gc_new(); struct buffer out =3D alloc_buf_gc(256, &gc); @@ -230,19 +224,18 @@ { #if defined(IP_MTU_DISCOVER) case AF_INET: - if (setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER, - (void *) &mtu_type, sizeof(mtu_type))) + if (setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER, (void *)&m= tu_type, + sizeof(mtu_type))) { - msg(M_ERR, "Error setting IP_MTU_DISCOVER type=3D%d on= TCP/UDP socket", - mtu_type); + msg(M_ERR, "Error setting IP_MTU_DISCOVER type=3D%d on= TCP/UDP socket", mtu_type); } break; #endif #if defined(IPV6_MTU_DISCOVER) case AF_INET6: - if (setsockopt(sd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, - (void *) &mtu_type, sizeof(mtu_type))) + if (setsockopt(sd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, (void = *)&mtu_type, + sizeof(mtu_type))) { msg(M_ERR, "Error setting IPV6_MTU_DISCOVER type=3D%d = on TCP6/UDP6 socket", mtu_type); @@ -273,13 +266,11 @@ { return IP_PMTUDISC_DONT; } - msg(M_FATAL, - "invalid --mtu-disc type: '%s' -- valid types are 'yes', 'maybe', = or 'no'", - name); -#else /* if defined(IP_PMTUDISC_DONT) && defined(IP_PMTUDISC_WANT) && def= ined(IP_PMTUDISC_DO) */ + msg(M_FATAL, "invalid --mtu-disc type: '%s' -- valid types are 'yes', = 'maybe', or 'no'", name); +#else /* if defined(IP_PMTUDISC_DONT) && defined(IP_PMTUDISC_WANT) && defi= ned(IP_PMTUDISC_DO) */ msg(M_FATAL, MTUDISC_NOT_SUPPORTED_MSG); #endif - return -1; /* NOTREACHED */ + return -1; /* NOTREACHED */ } #if EXTENDED_SOCKET_ERROR_CAPABILITY @@ -301,7 +292,7 @@ struct sock_extended_err *e; struct sockaddr_storage addr; struct buffer out =3D alloc_buf_gc(256, gc); - char *cbuf =3D (char *) gc_malloc(256, false, gc); + char *cbuf =3D (char *)gc_malloc(256, false, gc); *mtu =3D 0; @@ -310,7 +301,7 @@ memset(&rcvbuf, -1, sizeof(rcvbuf)); iov.iov_base =3D &rcvbuf; iov.iov_len =3D sizeof(rcvbuf); - msg.msg_name =3D (uint8_t *) &addr; + msg.msg_name =3D (uint8_t *)&addr; msg.msg_namelen =3D sizeof(addr); msg.msg_iov =3D &iov; msg.msg_iovlen =3D 1; @@ -332,7 +323,7 @@ { if (cmsg->cmsg_type =3D=3D IP_RECVERR) { - e =3D (struct sock_extended_err *) CMSG_DATA(cmsg); + e =3D (struct sock_extended_err *)CMSG_DATA(cmsg); } else { @@ -343,7 +334,7 @@ { if (cmsg->cmsg_type =3D=3D IPV6_RECVERR) { - e =3D (struct sock_extended_err *) CMSG_DATA(cmsg); + e =3D (struct sock_extended_err *)CMSG_DATA(cmsg); } else { @@ -406,7 +397,7 @@ /* see "man 7 ip" (on Linux) * this works on IPv4 and IPv6(-dual-stack) sockets (v4-mapped) */ - if (setsockopt(sd, SOL_IP, IP_RECVERR, (void *) &on, sizeof(on)) !=3D = 0) + if (setsockopt(sd, SOL_IP, IP_RECVERR, (void *)&on, sizeof(on)) !=3D 0) { msg(M_WARN | M_ERRNO, "Note: enable extended error passing on TCP/UDP socket failed = (IP_RECVERR)"); @@ -415,7 +406,7 @@ * this only works on IPv6 sockets */ if (proto_af =3D=3D AF_INET6 - && setsockopt(sd, IPPROTO_IPV6, IPV6_RECVERR, (void *) &on, sizeof= (on)) !=3D 0) + && setsockopt(sd, IPPROTO_IPV6, IPV6_RECVERR, (void *)&on, sizeof(= on)) !=3D 0) { msg(M_WARN | M_ERRNO, "Note: enable extended error passing on TCP/UDP socket failed = (IPV6_RECVERR)"); diff --git a/src/openvpn/mtu.h b/src/openvpn/mtu.h index dca402a..b4ec11b 100644 --- a/src/openvpn/mtu.h +++ b/src/openvpn/mtu.h @@ -51,38 +51,38 @@ /* * Standard ethernet MTU */ -#define ETHERNET_MTU 1500 +#define ETHERNET_MTU 1500 /* * It is a fatal error if mtu is less than * this value for tun device. */ -#define TUN_MTU_MIN 100 +#define TUN_MTU_MIN 100 /* * Default MTU of network over which tunnel data will pass by TCP/UDP. */ -#define LINK_MTU_DEFAULT 1500 +#define LINK_MTU_DEFAULT 1500 /* * Default MTU of tunnel device. */ -#define TUN_MTU_DEFAULT 1500 +#define TUN_MTU_DEFAULT 1500 /* * MTU Defaults for TAP devices */ -#define TAP_MTU_EXTRA_DEFAULT 32 +#define TAP_MTU_EXTRA_DEFAULT 32 /* * Default MSSFIX value, used for reducing TCP MTU size */ -#define MSSFIX_DEFAULT 1492 +#define MSSFIX_DEFAULT 1492 /* * Default maximum size of control channel packets */ -#define TLS_MTU_DEFAULT 1250 +#define TLS_MTU_DEFAULT 1250 /* * Alignment of payload data such as IP packet or @@ -95,62 +95,64 @@ /** * Packet geometry parameters. */ -struct frame { - struct { +struct frame +{ + struct + { /* This struct holds all the information about the buffers that are * allocated to match this frame */ - int payload_size; /**< the maximum size that a payload that = our - * buffers can hold from either tun devi= ce - * or network link. - */ + int payload_size; /**< the maximum size that a payload that our + * buffers can hold from either tun device + * or network link. + */ - int headroom; /**< the headroom in the buffer, this is c= hoosen - * to allow all potential header to be a= dded - * before the packet */ + int headroom; /**< the headroom in the buffer, this is choosen + * to allow all potential header to be added + * before the packet */ - int tailroom; /**< the tailroom in the buffer. Chosen l= arge - * enough to also accompany any extrea h= eader - * or work space required by - * decryption/encryption or compression.= */ + int tailroom; /**< the tailroom in the buffer. Chosen large + * enough to also accompany any extrea header + * or work space required by + * decryption/encryption or compression. */ } buf; - uint16_t mss_fix; /**< The actual MSS value that should be - * written to the payload packets. This - * is the value for IPv4 TCP packets. For - * IPv6 packets another 20 bytes must - * be subtracted */ + uint16_t mss_fix; /**< The actual MSS value that should be + * written to the payload packets. This + * is the value for IPv4 TCP packets. For + * IPv6 packets another 20 bytes must + * be subtracted */ - int max_fragment_size; /**< The maximum size of a fragment. - * Fragmentation is done on the unencrypted - * payload after (potential) compression. = So - * this value specifies the maximum payload - * size that can be send in a single fragm= ent - */ + int max_fragment_size; /**< The maximum size of a fragment. + * Fragmentation is done on the unencrypted + * payload after (potential) compression. So + * this value specifies the maximum payload + * size that can be send in a single fragment + */ - int tun_mtu; /**< the (user) configured tun-mtu. This i= s used - * in configuring the tun interface or - * in calculations that use the desired = size - * of the payload in the buffer. - * - * This variable is also used in control - * frame context to set the desired maxi= mum - * control frame payload (although most = of - * code ignores it) - */ - int tun_max_mtu; /**< the maximum tun-mtu size the buffers = are - * are sized for. This is the upper boun= d that - * a server can push as MTU */ + int tun_mtu; /**< the (user) configured tun-mtu. This is used + * in configuring the tun interface or + * in calculations that use the desired size + * of the payload in the buffer. + * + * This variable is also used in control + * frame context to set the desired maximum + * control frame payload (although most of + * code ignores it) + */ + int tun_max_mtu; /**< the maximum tun-mtu size the buffers are + * are sized for. This is the upper bound that + * a server can push as MTU */ - int extra_tun; /**< Maximum number of bytes in excess of - * the tun/tap MTU that might be read - * from or written to the virtual - * tun/tap network interface. - * - * Only set with the option --tun-mtu-ex= tra - * which defaults to 0 for tun and 32 - * (\c TAP_MTU_EXTRA_DEFAULT) for tap. - * */ + int extra_tun; /**< Maximum number of bytes in excess of + * the tun/tap MTU that might be read + * from or written to the virtual + * tun/tap network interface. + * + * Only set with the option --tun-mtu-extra + * which defaults to 0 for tun and 32 + * (\c TAP_MTU_EXTRA_DEFAULT) for tap. + * */ }; /* Forward declarations, to prevent includes */ @@ -175,9 +177,7 @@ * Function prototypes. */ -void frame_print(const struct frame *frame, - int level, - const char *prefix); +void frame_print(const struct frame *frame, int level, const char *prefix); void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family= _t proto_af); @@ -195,10 +195,8 @@ * * * [IP][UDP][OPENVPN PROTOCOL HEADER][ **PAYLOAD incl compression heade= r** ] */ -size_t -frame_calculate_payload_size(const struct frame *frame, - const struct options *options, - const struct key_type *kt); +size_t frame_calculate_payload_size(const struct frame *frame, const struc= t options *options, + const struct key_type *kt); /** * Calculates the size of the payload overhead according to tun-mtu and @@ -216,10 +214,8 @@ * * * [IP][UDP][OPENVPN PROTOCOL HEADER][ **PAYLOAD incl compression heade= r** ] */ -size_t -frame_calculate_payload_overhead(size_t extra_tun, - const struct options *options, - const struct key_type *kt); +size_t frame_calculate_payload_overhead(size_t extra_tun, const struct opt= ions *options, + const struct key_type *kt); /** @@ -237,10 +233,8 @@ * @param occ Use the calculation for the OCC link-mtu * @return size of the overhead in bytes */ -size_t -frame_calculate_protocol_header_size(const struct key_type *kt, - const struct options *options, - bool occ); +size_t frame_calculate_protocol_header_size(const struct key_type *kt, + const struct options *options,= bool occ); /** * Calculate the link-mtu to advertise to our peer. The actual value is n= ot @@ -249,23 +243,18 @@ * value they expect. This assumes that the traditional cipher/auth direc= tives * in the config match the config of the peer. */ -size_t -calc_options_string_link_mtu(const struct options *options, - const struct frame *frame); +size_t calc_options_string_link_mtu(const struct options *options, const s= truct frame *frame); /** * Return the size of the packet ID size that is currently in use by ciphe= r and * options for the data channel. */ -unsigned int -calc_packet_id_size_dc(const struct options *options, - const struct key_type *kt); +unsigned int calc_packet_id_size_dc(const struct options *options, const s= truct key_type *kt); /* * allocate a buffer for socket or tun layer */ -void alloc_buf_sock_tun(struct buffer *buf, - const struct frame *frame); +void alloc_buf_sock_tun(struct buffer *buf, const struct frame *frame); /* * EXTENDED_SOCKET_ERROR_CAPABILITY functions -- print extra error info diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index 93e65e0..3fb015d 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -39,18 +39,15 @@ #endif static void -send_hmac_reset_packet(struct multi_context *m, - struct tls_pre_decrypt_state *state, - struct tls_auth_standalone *tas, - struct session_id *sid, +send_hmac_reset_packet(struct multi_context *m, struct tls_pre_decrypt_sta= te *state, + struct tls_auth_standalone *tas, struct session_id = *sid, bool request_resend_wkc) { reset_packet_id_send(&state->tls_wrap_tmp.opt.packet_id.send); state->tls_wrap_tmp.opt.packet_id.rec.initialized =3D true; uint8_t header =3D 0 | (P_CONTROL_HARD_RESET_SERVER_V2 << P_OPCODE_SHI= FT); struct buffer buf =3D tls_reset_standalone(&state->tls_wrap_tmp, tas, = sid, - &state->peer_session_id, head= er, - request_resend_wkc); + &state->peer_session_id, head= er, request_resend_wkc); struct context *c =3D &m->top; @@ -66,8 +63,7 @@ /* Returns true if this packet should create a new session */ static bool -do_pre_decrypt_check(struct multi_context *m, - struct tls_pre_decrypt_state *state, +do_pre_decrypt_check(struct multi_context *m, struct tls_pre_decrypt_state= *state, struct mroute_addr addr) { ASSERT(m->top.c2.tls_auth_standalone); @@ -109,8 +105,8 @@ if (early_neg_support) { /* Calculate the session ID HMAC for our reply and create rese= t packet */ - struct session_id sid =3D calculate_session_id_hmac(state->pee= r_session_id, - from, hmac, = handwindow, 0); + struct session_id sid =3D + calculate_session_id_hmac(state->peer_session_id, from, hm= ac, handwindow, 0); send_hmac_reset_packet(m, state, tas, &sid, true); return false; @@ -125,8 +121,10 @@ { struct gc_arena gc =3D gc_new(); const char *peer =3D print_link_socket_actual(&m->top.c2.f= rom, &gc); - msg(D_MULTI_DEBUG, "tls-crypt-v2 force-cookie is enabled, " - "ignoring connection attempt from old client (%s)", pe= er); + msg(D_MULTI_DEBUG, + "tls-crypt-v2 force-cookie is enabled, " + "ignoring connection attempt from old client (%s)", + peer); gc_free(&gc); return false; } @@ -139,14 +137,13 @@ else if (verdict =3D=3D VERDICT_VALID_RESET_V2) { /* Calculate the session ID HMAC for our reply and create reset pa= cket */ - struct session_id sid =3D calculate_session_id_hmac(state->peer_se= ssion_id, - from, hmac, hand= window, 0); + struct session_id sid =3D + calculate_session_id_hmac(state->peer_session_id, from, hmac, = handwindow, 0); send_hmac_reset_packet(m, state, tas, &sid, false); =20 /* We have a reply do not create a new session */ return false; - } else if (verdict =3D=3D VERDICT_VALID_CONTROL_V1 || verdict =3D=3D VER= DICT_VALID_ACK_V1 || verdict =3D=3D VERDICT_VALID_WKC_V1) @@ -158,7 +155,7 @@ bool ret =3D check_session_id_hmac(state, from, hmac, handwindow); const char *peer =3D print_link_socket_actual(&m->top.c2.from, &gc= ); - uint8_t pkt_firstbyte =3D *BPTR( &m->top.c2.buf); + uint8_t pkt_firstbyte =3D *BPTR(&m->top.c2.buf); int op =3D pkt_firstbyte >> P_OPCODE_SHIFT; if (!ret) @@ -168,8 +165,10 @@ } else { - msg(D_MULTI_DEBUG, "Valid packet (%s) with HMAC challenge from= peer (%s), " - "accepting new connection.", packet_opcode_name(op), peer); + msg(D_MULTI_DEBUG, + "Valid packet (%s) with HMAC challenge from peer (%s), " + "accepting new connection.", + packet_opcode_name(op), peer); } gc_free(&gc); @@ -187,18 +186,16 @@ */ struct multi_instance * -multi_get_create_instance_udp(struct multi_context *m, bool *floated, - struct link_socket *sock) +multi_get_create_instance_udp(struct multi_context *m, bool *floated, stru= ct link_socket *sock) { struct gc_arena gc =3D gc_new(); - struct mroute_addr real =3D {0}; + struct mroute_addr real =3D { 0 }; struct multi_instance *mi =3D NULL; struct hash *hash =3D m->hash; real.proto =3D sock->info.proto; m->hmac_reply_ls =3D sock; - if (mroute_extract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true) - && m->top.c2.buf.len > 0) + if (mroute_extract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true)= && m->top.c2.buf.len > 0) { struct hash_element *he; const uint32_t hv =3D hash_value(hash, &real); @@ -234,19 +231,20 @@ he =3D hash_lookup_fast(hash, bucket, &real, hv); if (he) { - mi =3D (struct multi_instance *) he->value; + mi =3D (struct multi_instance *)he->value; } } /* we have no existing multi instance for this connection */ if (!mi) { - struct tls_pre_decrypt_state state =3D {0}; + struct tls_pre_decrypt_state state =3D { 0 }; if (m->deferred_shutdown_signal.signal_received) { msg(D_MULTI_ERRORS, "MULTI: Connection attempt from %s ignored while serve= r is " - "shutting down", mroute_addr_print(&real, &gc)); + "shutting down", + mroute_addr_print(&real, &gc)); } else if (do_pre_decrypt_check(m, &state, real)) { @@ -274,7 +272,8 @@ && session_id_defined((&state.peer_session_id)= )) { mi->context.c2.tls_multi->n_sessions++; - struct tls_session *session =3D &mi->context.c= 2.tls_multi->session[TM_INITIAL]; + struct tls_session *session =3D + &mi->context.c2.tls_multi->session[TM_INIT= IAL]; session_skip_to_pre_start(session, &state, &m-= >top.c2.from); } } @@ -294,9 +293,7 @@ { const char *status =3D mi ? "[ok]" : "[failed]"; =20 - dmsg(D_MULTI_DEBUG, "GET INST BY REAL: %s %s", - mroute_addr_print(&real, &gc), - status); + dmsg(D_MULTI_DEBUG, "GET INST BY REAL: %s %s", mroute_addr_pri= nt(&real, &gc), status); } #endif } @@ -336,8 +333,8 @@ { const unsigned int status =3D m->multi_io->udp_flags; const unsigned int mpp_flags =3D m->top.c2.fast_io - ? (MPP_CONDITIONAL_PRE_SELECT | MPP_CLO= SE_ON_SIGNAL) - : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL= ); + ? (MPP_CONDITIONAL_PRE_SELECT | MPP= _CLOSE_ON_SIGNAL) + : (MPP_PRE_SELECT | MPP_CLOSE_ON_SI= GNAL); #ifdef MULTI_DEBUG_EVENT_LOOP char buf[16]; @@ -366,7 +363,7 @@ #endif /* ifdef MULTI_DEBUG_EVENT_LOOP */ #ifdef ENABLE_MANAGEMENT - if (status & (MANAGEMENT_READ|MANAGEMENT_WRITE)) + if (status & (MANAGEMENT_READ | MANAGEMENT_WRITE)) { ASSERT(management); management_io(management); diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index a760e07..a65f8c2 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -92,9 +92,7 @@ } static bool -learn_address_script(const struct multi_context *m, - const struct multi_instance *mi, - const char *op, +learn_address_script(const struct multi_context *m, const struct multi_ins= tance *mi, const char *op, const struct mroute_addr *addr) { struct gc_arena gc =3D gc_new(); @@ -125,14 +123,13 @@ if (plugin_defined(plugins, OPENVPN_PLUGIN_LEARN_ADDRESS)) { struct argv argv =3D argv_new(); - argv_printf(&argv, "%s %s", - op, - mroute_addr_print(addr, &gc)); + argv_printf(&argv, "%s %s", op, mroute_addr_print(addr, &gc)); if (mi) { argv_printf_cat(&argv, "%s", tls_common_name(mi->context.c2.tl= s_multi, false)); } - if (plugin_call(plugins, OPENVPN_PLUGIN_LEARN_ADDRESS, &argv, NULL= , es) !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) + if (plugin_call(plugins, OPENVPN_PLUGIN_LEARN_ADDRESS, &argv, NULL= , es) + !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) { msg(M_WARN, "WARNING: learn-address plugin call failed"); ret =3D false; @@ -165,8 +162,7 @@ multi_ifconfig_pool_persist(struct multi_context *m, bool force) { /* write pool data to file */ - if (m->ifconfig_pool - && m->top.c1.ifconfig_pool_persist + if (m->ifconfig_pool && m->top.c1.ifconfig_pool_persist && (force || ifconfig_pool_write_trigger(m->top.c1.ifconfig_pool_p= ersist))) { ifconfig_pool_write(m->top.c1.ifconfig_pool_persist, m->ifconfig_p= ool); @@ -174,9 +170,7 @@ } static void -multi_reap_range(const struct multi_context *m, - int start_bucket, - int end_bucket) +multi_reap_range(const struct multi_context *m, int start_bucket, int end_= bucket) { struct gc_arena gc =3D gc_new(); struct hash_iterator hi; @@ -192,11 +186,10 @@ hash_iterator_init_range(m->vhash, &hi, start_bucket, end_bucket); while ((he =3D hash_iterator_next(&hi)) !=3D NULL) { - struct multi_route *r =3D (struct multi_route *) he->value; + struct multi_route *r =3D (struct multi_route *)he->value; if (!multi_route_defined(m, r)) { - dmsg(D_MULTI_DEBUG, "MULTI: REAP DEL %s", - mroute_addr_print(&r->addr, &gc)); + dmsg(D_MULTI_DEBUG, "MULTI: REAP DEL %s", mroute_addr_print(&r= ->addr, &gc)); learn_address_script(m, NULL, "delete", &r->addr); multi_route_del(r); hash_iterator_delete_element(&hi); @@ -257,7 +250,7 @@ cid_hash_function(const void *key, uint32_t iv) { const unsigned long *k =3D (const unsigned long *)key; - return (uint32_t) *k; + return (uint32_t)*k; } static bool @@ -295,8 +288,7 @@ { int dev =3D DEV_TYPE_UNDEF; - msg(D_MULTI_LOW, "MULTI: multi_init called, r=3D%d v=3D%d", - t->options.real_hash_size, + msg(D_MULTI_LOW, "MULTI: multi_init called, r=3D%d v=3D%d", t->options= .real_hash_size, t->options.virtual_hash_size); /* @@ -315,18 +307,14 @@ * to determine which client sent an incoming packet * which is seen on the TCP/UDP socket. */ - m->hash =3D hash_init(t->options.real_hash_size, - get_random(), - mroute_addr_hash_function, + m->hash =3D hash_init(t->options.real_hash_size, get_random(), mroute_= addr_hash_function, mroute_addr_compare_function); /* * Virtual address hash table. Used to determine * which client to route a packet to. */ - m->vhash =3D hash_init(t->options.virtual_hash_size, - get_random(), - mroute_addr_hash_function, + m->vhash =3D hash_init(t->options.virtual_hash_size, get_random(), mro= ute_addr_hash_function, mroute_addr_compare_function); /* @@ -334,16 +322,10 @@ * bucket size of one so that it can be used * for fast iteration through the list. */ - m->iter =3D hash_init(1, - get_random(), - mroute_addr_hash_function, - mroute_addr_compare_function); + m->iter =3D hash_init(1, get_random(), mroute_addr_hash_function, mrou= te_addr_compare_function); #ifdef ENABLE_MANAGEMENT - m->cid_hash =3D hash_init(t->options.real_hash_size, - 0, - cid_hash_function, - cid_compare_function); + m->cid_hash =3D hash_init(t->options.real_hash_size, 0, cid_hash_funct= ion, cid_compare_function); #endif #ifdef ENABLE_ASYNC_PUSH @@ -351,10 +333,8 @@ * Mapping between inotify watch descriptors and * multi_instances. */ - m->inotify_watchers =3D hash_init(t->options.real_hash_size, - get_random(), - int_hash_function, - int_compare_function); + m->inotify_watchers =3D + hash_init(t->options.real_hash_size, get_random(), int_hash_functi= on, int_compare_function); #endif /* @@ -367,10 +347,9 @@ * Limit frequency of incoming connections to control * DoS. */ - m->new_connection_limiter =3D frequency_limit_init(t->options.cf_max, - t->options.cf_per); - m->initial_rate_limiter =3D initial_rate_limit_init(t->options.cf_init= ial_max, - t->options.cf_initia= l_per); + m->new_connection_limiter =3D frequency_limit_init(t->options.cf_max, = t->options.cf_per); + m->initial_rate_limiter =3D + initial_rate_limit_init(t->options.cf_initial_max, t->options.cf_i= nitial_per); /* * Allocate broadcast/multicast buffer list @@ -387,8 +366,7 @@ * differently based on whether a tun or tap style * tunnel. */ - if (t->options.ifconfig_pool_defined - || t->options.ifconfig_ipv6_pool_defined) + if (t->options.ifconfig_pool_defined || t->options.ifconfig_ipv6_pool_= defined) { int pool_type =3D IFCONFIG_POOL_INDIV; @@ -397,14 +375,11 @@ pool_type =3D IFCONFIG_POOL_30NET; } - m->ifconfig_pool =3D ifconfig_pool_init(t->options.ifconfig_pool_d= efined, - pool_type, - t->options.ifconfig_pool_sta= rt, - t->options.ifconfig_pool_end, - t->options.duplicate_cn, - t->options.ifconfig_ipv6_poo= l_defined, - t->options.ifconfig_ipv6_poo= l_base, - t->options.ifconfig_ipv6_poo= l_netbits ); + m->ifconfig_pool =3D ifconfig_pool_init( + t->options.ifconfig_pool_defined, pool_type, t->options.ifconf= ig_pool_start, + t->options.ifconfig_pool_end, t->options.duplicate_cn, + t->options.ifconfig_ipv6_pool_defined, t->options.ifconfig_ipv= 6_pool_base, + t->options.ifconfig_ipv6_pool_netbits); /* reload pool data from file */ if (t->c1.ifconfig_pool_persist) @@ -454,7 +429,8 @@ /* initialize stale routes check timer */ if (t->options.stale_routes_check_interval > 0) { - msg(M_INFO, "Initializing stale route check timer to run every %i = seconds and to removing routes with activity timeout older than %i seconds", + msg(M_INFO, + "Initializing stale route check timer to run every %i seconds = and to removing routes with activity timeout older than %i seconds", t->options.stale_routes_check_interval, t->options.stale_route= s_ageing_time); event_timeout_init(&m->stale_routes_check_et, t->options.stale_rou= tes_check_interval, 0); } @@ -475,8 +451,7 @@ buf_printf(&out, "%s/", cn); } buf_printf(&out, "%s", mroute_addr_print(&mi->real, gc)); - if (mi->context.c2.tls_multi - && check_debug_level(D_DCO_DEBUG) + if (mi->context.c2.tls_multi && check_debug_level(D_DCO_DEBUG) && dco_enabled(&mi->context.options)) { buf_printf(&out, " peer-id=3D%d", mi->context.c2.tls_multi->pe= er_id); @@ -523,8 +498,7 @@ * CIDR netlengths. */ static void -multi_del_iroutes(struct multi_context *m, - struct multi_instance *mi) +multi_del_iroutes(struct multi_context *m, struct multi_instance *mi) { const struct iroute *ir; const struct iroute_ipv6 *ir6; @@ -580,7 +554,9 @@ if (plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_DISCONNE= CT)) { - if (plugin_call(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_DISCONN= ECT, NULL, NULL, mi->context.c2.es) !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) + if (plugin_call(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_DISCONN= ECT, NULL, NULL, + mi->context.c2.es) + !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) { msg(M_WARN, "WARNING: client-disconnect plugin call failed"); } @@ -603,9 +579,7 @@ } void -multi_close_instance(struct multi_context *m, - struct multi_instance *mi, - bool shutdown) +multi_close_instance(struct multi_context *m, struct multi_instance *mi, b= ool shutdown) { perf_push(PERF_MULTI_CLOSE_INSTANCE); @@ -650,7 +624,7 @@ #ifdef ENABLE_ASYNC_PUSH if (mi->inotify_watch !=3D -1) { - hash_remove(m->inotify_watchers, (void *) (unsigned long)mi->i= notify_watch); + hash_remove(m->inotify_watchers, (void *)(unsigned long)mi->in= otify_watch); mi->inotify_watch =3D -1; } #endif @@ -660,7 +634,7 @@ m->instances[mi->context.c2.tls_multi->peer_id] =3D NULL; } - schedule_remove_entry(m->schedule, (struct schedule_entry *) mi); + schedule_remove_entry(m->schedule, (struct schedule_entry *)mi); ifconfig_pool_release(m->ifconfig_pool, mi->vaddr_handle, false); @@ -717,7 +691,7 @@ hash_iterator_init(m->iter, &hi); while ((he =3D hash_iterator_next(&hi))) { - struct multi_instance *mi =3D (struct multi_instance *) he->va= lue; + struct multi_instance *mi =3D (struct multi_instance *)he->val= ue; mi->did_iter =3D false; multi_close_instance(m, mi, true); } @@ -789,7 +763,9 @@ if (hash_n_elements(m->hash) >=3D m->max_clients) { - msg(D_MULTI_ERRORS, "MULTI: new incoming connection would exceed m= aximum number of clients (%d)", m->max_clients); + msg(D_MULTI_ERRORS, + "MULTI: new incoming connection would exceed maximum number of= clients (%d)", + m->max_clients); goto err; } @@ -879,7 +855,7 @@ while ((he =3D hash_iterator_next(&hi))) { struct gc_arena gc =3D gc_new(); - const struct multi_instance *mi =3D (struct multi_instance= *) he->value; + const struct multi_instance *mi =3D (struct multi_instance= *)he->value; if (!mi->halt) { @@ -900,21 +876,19 @@ while ((he =3D hash_iterator_next(&hi))) { struct gc_arena gc =3D gc_new(); - const struct multi_route *route =3D (struct multi_route *)= he->value; + const struct multi_route *route =3D (struct multi_route *)= he->value; if (multi_route_defined(m, route)) { const struct multi_instance *mi =3D route->instance; const struct mroute_addr *ma =3D &route->addr; - char flags[2] =3D {0, 0}; + char flags[2] =3D { 0, 0 }; if (route->flags & MULTI_ROUTE_CACHE) { flags[0] =3D 'C'; } - status_printf(so, "%s%s,%s,%s,%s", - mroute_addr_print(ma, &gc), - flags, + status_printf(so, "%s%s,%s,%s,%s", mroute_addr_print(m= a, &gc), flags, tls_common_name(mi->context.c2.tls_multi= , false), mroute_addr_print(&mi->real, &gc), time_string(route->last_reference, 0, fa= lse, &gc)); @@ -926,8 +900,7 @@ status_printf(so, "GLOBAL STATS"); if (m->mbuf) { - status_printf(so, "Max bcast/mcast queue length,%d", - mbuf_maximum_queued(m->mbuf)); + status_printf(so, "Max bcast/mcast queue length,%d", mbuf_= maximum_queued(m->mbuf)); } status_printf(so, "END"); @@ -940,69 +913,77 @@ * Status file version 2 and 3 */ status_printf(so, "TITLE%c%s", sep, title_string); - status_printf(so, "TIME%c%s%c%u", sep, time_string(now, 0, fal= se, &gc_top), sep, (unsigned int)now); - status_printf(so, "HEADER%cCLIENT_LIST%cCommon Name%cReal Addr= ess%cVirtual Address%cVirtual IPv6 Address%cBytes Received%cBytes Sent%cCon= nected Since%cConnected Since (time_t)%cUsername%cClient ID%cPeer ID%cData = Channel Cipher", - sep, sep, sep, sep, sep, sep, sep, sep, sep, sep= , sep, sep, sep); + status_printf(so, "TIME%c%s%c%u", sep, time_string(now, 0, fal= se, &gc_top), sep, + (unsigned int)now); + status_printf( + so, + "HEADER%cCLIENT_LIST%cCommon Name%cReal Address%cVirtual A= ddress%cVirtual IPv6 Address%cBytes Received%cBytes Sent%cConnected Since%c= Connected Since (time_t)%cUsername%cClient ID%cPeer ID%cData Channel Cipher= ", + sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep= , sep); hash_iterator_init(m->hash, &hi); while ((he =3D hash_iterator_next(&hi))) { struct gc_arena gc =3D gc_new(); - const struct multi_instance *mi =3D (struct multi_instance= *) he->value; + const struct multi_instance *mi =3D (struct multi_instance= *)he->value; if (!mi->halt) { - status_printf(so, "CLIENT_LIST%c%s%c%s%c%s%c%s%c" coun= ter_format "%c" counter_format "%c%s%c%u%c%s%c" + status_printf( + so, + "CLIENT_LIST%c%s%c%s%c%s%c%s%c" counter_format "%c= " counter_format + "%c%s%c%u%c%s%c" #ifdef ENABLE_MANAGEMENT - "%lu" + "%lu" #else - "" + "" #endif - "%c%" PRIu32 "%c%s", - sep, tls_common_name(mi->context.c2.tls_= multi, false), - sep, mroute_addr_print(&mi->real, &gc), - sep, print_in_addr_t(mi->reporting_addr,= IA_EMPTY_IF_UNDEF, &gc), - sep, print_in6_addr(mi->reporting_addr_i= pv6, IA_EMPTY_IF_UNDEF, &gc), - sep, mi->context.c2.link_read_bytes + mi= ->context.c2.dco_read_bytes, - sep, mi->context.c2.link_write_bytes + m= i->context.c2.dco_write_bytes, - sep, time_string(mi->created, 0, false, = &gc), - sep, (unsigned int)mi->created, - sep, tls_username(mi->context.c2.tls_mul= ti, false), + "%c%" PRIu32 "%c%s", + sep, tls_common_name(mi->context.c2.tls_multi, fal= se), sep, + mroute_addr_print(&mi->real, &gc), sep, + print_in_addr_t(mi->reporting_addr, IA_EMPTY_IF_UN= DEF, &gc), sep, + print_in6_addr(mi->reporting_addr_ipv6, IA_EMPTY_I= F_UNDEF, &gc), sep, + mi->context.c2.link_read_bytes + mi->context.c2.dc= o_read_bytes, sep, + mi->context.c2.link_write_bytes + mi->context.c2.d= co_write_bytes, sep, + time_string(mi->created, 0, false, &gc), sep, (uns= igned int)mi->created, + sep, tls_username(mi->context.c2.tls_multi, false), #ifdef ENABLE_MANAGEMENT - sep, mi->context.c2.mda_context.cid, + sep, mi->context.c2.mda_context.cid, #else - sep, + sep, #endif - sep, mi->context.c2.tls_multi ? mi->cont= ext.c2.tls_multi->peer_id : UINT32_MAX, - sep, translate_cipher_name_to_openvpn(mi= ->context.options.ciphername)); + sep, + mi->context.c2.tls_multi ? mi->context.c2.tls_mult= i->peer_id : UINT32_MAX, + sep, translate_cipher_name_to_openvpn(mi->context.= options.ciphername)); } gc_free(&gc); } hash_iterator_free(&hi); - status_printf(so, "HEADER%cROUTING_TABLE%cVirtual Address%cCom= mon Name%cReal Address%cLast Ref%cLast Ref (time_t)", - sep, sep, sep, sep, sep, sep); + status_printf( + so, + "HEADER%cROUTING_TABLE%cVirtual Address%cCommon Name%cReal= Address%cLast Ref%cLast Ref (time_t)", + sep, sep, sep, sep, sep, sep); hash_iterator_init(m->vhash, &hi); while ((he =3D hash_iterator_next(&hi))) { struct gc_arena gc =3D gc_new(); - const struct multi_route *route =3D (struct multi_route *)= he->value; + const struct multi_route *route =3D (struct multi_route *)= he->value; if (multi_route_defined(m, route)) { const struct multi_instance *mi =3D route->instance; const struct mroute_addr *ma =3D &route->addr; - char flags[2] =3D {0, 0}; + char flags[2] =3D { 0, 0 }; if (route->flags & MULTI_ROUTE_CACHE) { flags[0] =3D 'C'; } - status_printf(so, "ROUTING_TABLE%c%s%s%c%s%c%s%c%s%c%u= ", - sep, mroute_addr_print(ma, &gc), flags, - sep, tls_common_name(mi->context.c2.tls_= multi, false), - sep, mroute_addr_print(&mi->real, &gc), - sep, time_string(route->last_reference, = 0, false, &gc), - sep, (unsigned int)route->last_reference= ); + status_printf(so, "ROUTING_TABLE%c%s%s%c%s%c%s%c%s%c%u= ", sep, + mroute_addr_print(ma, &gc), flags, sep, + tls_common_name(mi->context.c2.tls_multi= , false), sep, + mroute_addr_print(&mi->real, &gc), sep, + time_string(route->last_reference, 0, fa= lse, &gc), sep, + (unsigned int)route->last_reference); } gc_free(&gc); } @@ -1010,11 +991,12 @@ if (m->mbuf) { - status_printf(so, "GLOBAL_STATS%cMax bcast/mcast queue len= gth%c%d", - sep, sep, mbuf_maximum_queued(m->mbuf)); + status_printf(so, "GLOBAL_STATS%cMax bcast/mcast queue len= gth%c%d", sep, sep, + mbuf_maximum_queued(m->mbuf)); } - status_printf(so, "GLOBAL_STATS%cdco_enabled%c%d", sep, sep, d= co_enabled(&m->top.options)); + status_printf(so, "GLOBAL_STATS%cdco_enabled%c%d", sep, sep, + dco_enabled(&m->top.options)); status_printf(so, "END"); } else @@ -1024,19 +1006,22 @@ #ifdef PACKET_TRUNCATION_CHECK { - status_printf(so, "HEADER,ERRORS,Common Name,TUN Read Trunc,TU= N Write Trunc,Pre-encrypt Trunc,Post-decrypt Trunc"); + status_printf( + so, + "HEADER,ERRORS,Common Name,TUN Read Trunc,TUN Write Trunc,= Pre-encrypt Trunc,Post-decrypt Trunc"); hash_iterator_init(m->hash, &hi); while ((he =3D hash_iterator_next(&hi))) { struct gc_arena gc =3D gc_new(); - const struct multi_instance *mi =3D (struct multi_instance= *) he->value; + const struct multi_instance *mi =3D (struct multi_instance= *)he->value; if (!mi->halt) { - status_printf(so, "ERRORS,%s," counter_format "," coun= ter_format "," counter_format "," counter_format, + status_printf(so, + "ERRORS,%s," counter_format "," counter_= format "," counter_format + "," counter_format, tls_common_name(mi->context.c2.tls_multi= , false), - m->top.c2.n_trunc_tun_read, - mi->context.c2.n_trunc_tun_write, + m->top.c2.n_trunc_tun_read, mi->context.= c2.n_trunc_tun_write, mi->context.c2.n_trunc_pre_encrypt, mi->context.c2.n_trunc_post_decrypt); } @@ -1067,9 +1052,7 @@ * or NULL if none. */ static struct multi_instance * -multi_learn_addr(struct multi_context *m, - struct multi_instance *mi, - const struct mroute_addr *addr, +multi_learn_addr(struct multi_context *m, struct multi_instance *mi, const= struct mroute_addr *addr, const unsigned int flags) { struct hash_element *he; @@ -1083,7 +1066,7 @@ he =3D hash_lookup_fast(m->vhash, bucket, addr, hv); if (he) { - oldroute =3D (struct multi_route *) he->value; + oldroute =3D (struct multi_route *)he->value; } if (oldroute && multi_route_defined(m, oldroute)) { @@ -1141,10 +1124,8 @@ } } =20 - msg(D_MULTI_LOW, "MULTI: Learn%s: %s -> %s", - learn_succeeded ? "" : " FAILED", - mroute_addr_print(&newroute->addr, &gc), - multi_instance_string(mi, false, &gc)); + msg(D_MULTI_LOW, "MULTI: Learn%s: %s -> %s", learn_succeeded ? "" = : " FAILED", + mroute_addr_print(&newroute->addr, &gc), multi_instance_string= (mi, false, &gc)); if (!learn_succeeded) { @@ -1160,8 +1141,7 @@ * Get client instance based on virtual address. */ static struct multi_instance * -multi_get_instance_by_virtual_addr(struct multi_context *m, - const struct mroute_addr *addr, +multi_get_instance_by_virtual_addr(struct multi_context *m, const struct m= route_addr *addr, bool cidr_routing) { struct multi_route *route; @@ -1173,7 +1153,7 @@ return NULL; } - route =3D (struct multi_route *) hash_lookup(m->vhash, addr); + route =3D (struct multi_route *)hash_lookup(m->vhash, addr); /* does host route (possible cached) exist? */ if (route && multi_route_defined(m, route)) @@ -1197,13 +1177,13 @@ mroute_addr_mask_host_bits(&tryaddr); /* look up a possible route with netbits netmask */ - route =3D (struct multi_route *) hash_lookup(m->vhash, &tryadd= r); + route =3D (struct multi_route *)hash_lookup(m->vhash, &tryaddr= ); if (route && multi_route_defined(m, route)) { /* found an applicable route, cache host route */ struct multi_instance *mi =3D route->instance; - multi_learn_addr(m, mi, addr, MULTI_ROUTE_CACHE|MULTI_ROUT= E_AGEABLE); + multi_learn_addr(m, mi, addr, MULTI_ROUTE_CACHE | MULTI_RO= UTE_AGEABLE); ret =3D mi; break; } @@ -1217,15 +1197,12 @@ const char *addr_text =3D mroute_addr_print(addr, &gc); if (ret) { - dmsg(D_MULTI_DEBUG, "GET INST BY VIRT: %s -> %s via %s", - addr_text, - multi_instance_string(ret, false, &gc), - mroute_addr_print(&route->addr, &gc)); + dmsg(D_MULTI_DEBUG, "GET INST BY VIRT: %s -> %s via %s", addr_= text, + multi_instance_string(ret, false, &gc), mroute_addr_print= (&route->addr, &gc)); } else { - dmsg(D_MULTI_DEBUG, "GET INST BY VIRT: %s [failed]", - addr_text); + dmsg(D_MULTI_DEBUG, "GET INST BY VIRT: %s [failed]", addr_text= ); } gc_free(&gc); } @@ -1239,14 +1216,12 @@ * Helper function to multi_learn_addr(). */ static struct multi_instance * -multi_learn_in_addr_t(struct multi_context *m, - struct multi_instance *mi, - in_addr_t a, - int netbits, /* -1 if host route, otherwise # of ne= twork bits in address */ +multi_learn_in_addr_t(struct multi_context *m, struct multi_instance *mi, = in_addr_t a, + int netbits, /* -1 if host route, otherwise # of net= work bits in address */ bool primary) { struct openvpn_sockaddr remote_si; - struct mroute_addr addr =3D {0}; + struct mroute_addr addr =3D { 0 }; CLEAR(remote_si); remote_si.addr.in4.sin_family =3D AF_INET; @@ -1257,7 +1232,7 @@ if (netbits >=3D 0) { addr.type |=3D MR_WITH_NETBITS; - addr.netbits =3D (uint8_t) netbits; + addr.netbits =3D (uint8_t)netbits; } struct multi_instance *owner =3D multi_learn_addr(m, mi, &addr, 0); @@ -1272,7 +1247,7 @@ /* "primary" is the VPN ifconfig address of the peer and already * known to DCO, so only install "extra" iroutes (primary =3D fals= e) */ - ASSERT(netbits >=3D 0); /* DCO requires populated netbit= s */ + ASSERT(netbits >=3D 0); /* DCO requires populated netbits */ dco_install_iroute(m, mi, &addr); } @@ -1280,13 +1255,11 @@ } static struct multi_instance * -multi_learn_in6_addr(struct multi_context *m, - struct multi_instance *mi, - struct in6_addr a6, - int netbits, /* -1 if host route, otherwise # of ne= twork bits in address */ +multi_learn_in6_addr(struct multi_context *m, struct multi_instance *mi, s= truct in6_addr a6, + int netbits, /* -1 if host route, otherwise # of netw= ork bits in address */ bool primary) { - struct mroute_addr addr =3D {0}; + struct mroute_addr addr =3D { 0 }; addr.len =3D 16; addr.type =3D MR_ADDR_IPV6; @@ -1296,8 +1269,8 @@ if (netbits >=3D 0) { addr.type |=3D MR_WITH_NETBITS; - addr.netbits =3D (uint8_t) netbits; - mroute_addr_mask_host_bits( &addr ); + addr.netbits =3D (uint8_t)netbits; + mroute_addr_mask_host_bits(&addr); } struct multi_instance *owner =3D multi_learn_addr(m, mi, &addr, 0); @@ -1312,7 +1285,7 @@ /* "primary" is the VPN ifconfig address of the peer and already * known to DCO, so only install "extra" iroutes (primary =3D fals= e) */ - ASSERT(netbits >=3D 0); /* DCO requires populated netbit= s */ + ASSERT(netbits >=3D 0); /* DCO requires populated netbits */ dco_install_iroute(m, mi, &addr); } @@ -1324,8 +1297,7 @@ * to internal routing table. */ static void -multi_add_iroutes(struct multi_context *m, - struct multi_instance *mi) +multi_add_iroutes(struct multi_context *m, struct multi_instance *mi) { struct gc_arena gc =3D gc_new(); const struct iroute *ir; @@ -1338,15 +1310,13 @@ if (ir->netbits >=3D 0) { msg(D_MULTI_LOW, "MULTI: internal route %s/%d -> %s", - print_in_addr_t(ir->network, 0, &gc), - ir->netbits, + print_in_addr_t(ir->network, 0, &gc), ir->netbits, multi_instance_string(mi, false, &gc)); } else { msg(D_MULTI_LOW, "MULTI: internal route %s -> %s", - print_in_addr_t(ir->network, 0, &gc), - multi_instance_string(mi, false, &gc)); + print_in_addr_t(ir->network, 0, &gc), multi_instance_s= tring(mi, false, &gc)); } mroute_helper_add_iroute46(m->route_helper, ir->netbits); @@ -1356,8 +1326,7 @@ for (ir6 =3D mi->context.options.iroutes_ipv6; ir6 !=3D NULL; ir6 = =3D ir6->next) { msg(D_MULTI_LOW, "MULTI: internal route %s/%d -> %s", - print_in6_addr(ir6->network, 0, &gc), - ir6->netbits, + print_in6_addr(ir6->network, 0, &gc), ir6->netbits, multi_instance_string(mi, false, &gc)); mroute_helper_add_iroute46(m->route_helper, ir6->netbits); @@ -1387,7 +1356,7 @@ hash_iterator_init(m->iter, &hi); while ((he =3D hash_iterator_next(&hi))) { - struct multi_instance *mi =3D (struct multi_instance *) he= ->value; + struct multi_instance *mi =3D (struct multi_instance *)he-= >value; if (mi !=3D new_mi && !mi->halt) { const char *cn =3D tls_common_name(mi->context.c2.tls_= multi, true); @@ -1404,7 +1373,9 @@ =20 if (count) { - msg(D_MULTI_LOW, "MULTI: new connection by client '%s' wil= l cause previous active sessions by this client to be dropped. Remember to= use the --duplicate-cn option if you want multiple clients using the same = certificate or username to concurrently connect.", new_cn); + msg(D_MULTI_LOW, + "MULTI: new connection by client '%s' will cause previ= ous active sessions by this client to be dropped. Remember to use the --du= plicate-cn option if you want multiple clients using the same certificate o= r username to concurrently connect.", + new_cn); } } } @@ -1413,7 +1384,6 @@ static void check_stale_routes(struct multi_context *m) { - struct gc_arena gc =3D gc_new(); struct hash_iterator hi; struct hash_element *he; @@ -1422,8 +1392,9 @@ hash_iterator_init_range(m->vhash, &hi, 0, hash_n_buckets(m->vhash)); while ((he =3D hash_iterator_next(&hi)) !=3D NULL) { - struct multi_route *r =3D (struct multi_route *) he->value; - if (multi_route_defined(m, r) && difftime(now, r->last_reference) = >=3D m->top.options.stale_routes_ageing_time) + struct multi_route *r =3D (struct multi_route *)he->value; + if (multi_route_defined(m, r) + && difftime(now, r->last_reference) >=3D m->top.options.stale_= routes_ageing_time) { dmsg(D_MULTI_DEBUG, "MULTI: Deleting stale route for address '= %s'", mroute_addr_print(&r->addr, &gc)); @@ -1446,7 +1417,8 @@ const struct options *o =3D &c->options; if (o->push_ifconfig_constraint_defined && c->c2.push_ifconfig_defined) { - return (o->push_ifconfig_constraint_netmask & c->c2.push_ifconfig_= local) =3D=3D o->push_ifconfig_constraint_network; + return (o->push_ifconfig_constraint_netmask & c->c2.push_ifconfig_= local) + =3D=3D o->push_ifconfig_constraint_network; } else { @@ -1480,7 +1452,8 @@ mi->context.c2.push_ifconfig_defined =3D true; mi->context.c2.push_ifconfig_local =3D mi->context.options.push_if= config_local; - mi->context.c2.push_ifconfig_remote_netmask =3D mi->context.option= s.push_ifconfig_remote_netmask; + mi->context.c2.push_ifconfig_remote_netmask =3D + mi->context.options.push_ifconfig_remote_netmask; mi->context.c2.push_ifconfig_local_alias =3D mi->context.options.p= ush_ifconfig_local_alias; /* the current implementation does not allow "static IPv4, pool IP= v6", @@ -1490,7 +1463,8 @@ if (mi->context.options.ifconfig_ipv6_pool_defined && !mi->context.options.push_ifconfig_ipv6_defined) { - msg( M_INFO, "MULTI_sva: WARNING: if --ifconfig-push is used f= or IPv4, automatic IPv6 assignment from --ifconfig-ipv6-pool does not work.= Use --ifconfig-ipv6-push for IPv6 then." ); + msg(M_INFO, + "MULTI_sva: WARNING: if --ifconfig-push is used for IPv4, = automatic IPv6 assignment from --ifconfig-ipv6-pool does not work. Use --i= fconfig-ipv6-push for IPv6 then."); } } else if (m->ifconfig_pool && mi->vaddr_handle < 0) /* otherwise, choos= e a pool address */ @@ -1505,30 +1479,33 @@ } CLEAR(remote_ipv6); - mi->vaddr_handle =3D ifconfig_pool_acquire(m->ifconfig_pool, &loca= l, &remote, &remote_ipv6, cn); + mi->vaddr_handle =3D + ifconfig_pool_acquire(m->ifconfig_pool, &local, &remote, &remo= te_ipv6, cn); if (mi->vaddr_handle >=3D 0) { const int tunnel_type =3D TUNNEL_TYPE(mi->context.c1.tuntap); const int tunnel_topology =3D TUNNEL_TOPOLOGY(mi->context.c1.t= untap); - msg( M_INFO, "MULTI_sva: pool returned IPv4=3D%s, IPv6=3D%s", - (mi->context.options.ifconfig_pool_defined - ? print_in_addr_t(remote, 0, &gc) - : "(Not enabled)"), - (mi->context.options.ifconfig_ipv6_pool_defined - ? print_in6_addr( remote_ipv6, 0, &gc ) - : "(Not enabled)") ); + msg(M_INFO, "MULTI_sva: pool returned IPv4=3D%s, IPv6=3D%s", + (mi->context.options.ifconfig_pool_defined ? print_in_addr= _t(remote, 0, &gc) + : "(Not enabled= )"), + (mi->context.options.ifconfig_ipv6_pool_defined + ? print_in6_addr(remote_ipv6, 0, &gc) + : "(Not enabled)")); if (mi->context.options.ifconfig_pool_defined) { /* set push_ifconfig_remote_netmask from pool ifconfig add= ress(es) */ mi->context.c2.push_ifconfig_local =3D remote; - if (tunnel_type =3D=3D DEV_TYPE_TAP || (tunnel_type =3D=3D= DEV_TYPE_TUN && tunnel_topology =3D=3D TOP_SUBNET)) + if (tunnel_type =3D=3D DEV_TYPE_TAP + || (tunnel_type =3D=3D DEV_TYPE_TUN && tunnel_topology= =3D=3D TOP_SUBNET)) { - mi->context.c2.push_ifconfig_remote_netmask =3D mi->co= ntext.options.ifconfig_pool_netmask; + mi->context.c2.push_ifconfig_remote_netmask =3D + mi->context.options.ifconfig_pool_netmask; if (!mi->context.c2.push_ifconfig_remote_netmask) { - mi->context.c2.push_ifconfig_remote_netmask =3D mi= ->context.c1.tuntap->remote_netmask; + mi->context.c2.push_ifconfig_remote_netmask =3D + mi->context.c1.tuntap->remote_netmask; } } else if (tunnel_type =3D=3D DEV_TYPE_TUN) @@ -1558,8 +1535,7 @@ if (mi->context.options.ifconfig_ipv6_pool_defined) { mi->context.c2.push_ifconfig_ipv6_local =3D remote_ipv6; - mi->context.c2.push_ifconfig_ipv6_remote =3D - mi->context.c1.tuntap->local_ipv6; + mi->context.c2.push_ifconfig_ipv6_remote =3D mi->context.c= 1.tuntap->local_ipv6; mi->context.c2.push_ifconfig_ipv6_netbits =3D mi->context.options.ifconfig_ipv6_netbits; mi->context.c2.push_ifconfig_ipv6_defined =3D true; @@ -1580,17 +1556,14 @@ */ if (mi->context.options.push_ifconfig_ipv6_defined) { - mi->context.c2.push_ifconfig_ipv6_local =3D - mi->context.options.push_ifconfig_ipv6_local; - mi->context.c2.push_ifconfig_ipv6_remote =3D - mi->context.options.push_ifconfig_ipv6_remote; - mi->context.c2.push_ifconfig_ipv6_netbits =3D - mi->context.options.push_ifconfig_ipv6_netbits; + mi->context.c2.push_ifconfig_ipv6_local =3D mi->context.options.pu= sh_ifconfig_ipv6_local; + mi->context.c2.push_ifconfig_ipv6_remote =3D mi->context.options.p= ush_ifconfig_ipv6_remote; + mi->context.c2.push_ifconfig_ipv6_netbits =3D mi->context.options.= push_ifconfig_ipv6_netbits; mi->context.c2.push_ifconfig_ipv6_defined =3D true; - msg( M_INFO, "MULTI_sva: push_ifconfig_ipv6 %s/%d", - print_in6_addr( mi->context.c2.push_ifconfig_ipv6_local, 0, &= gc ), - mi->context.c2.push_ifconfig_ipv6_netbits ); + msg(M_INFO, "MULTI_sva: push_ifconfig_ipv6 %s/%d", + print_in6_addr(mi->context.c2.push_ifconfig_ipv6_local, 0, &gc= ), + mi->context.c2.push_ifconfig_ipv6_netbits); } gc_free(&gc); @@ -1611,24 +1584,19 @@ const int tunnel_type =3D TUNNEL_TYPE(mi->context.c1.tuntap); const int tunnel_topology =3D TUNNEL_TOPOLOGY(mi->context.c1.tunta= p); - setenv_in_addr_t(mi->context.c2.es, - "ifconfig_pool_remote_ip", - mi->context.c2.push_ifconfig_local, - SA_SET_IF_NONZERO); + setenv_in_addr_t(mi->context.c2.es, "ifconfig_pool_remote_ip", + mi->context.c2.push_ifconfig_local, SA_SET_IF_NON= ZERO); - if (tunnel_type =3D=3D DEV_TYPE_TAP || (tunnel_type =3D=3D DEV_TYP= E_TUN && tunnel_topology =3D=3D TOP_SUBNET)) + if (tunnel_type =3D=3D DEV_TYPE_TAP + || (tunnel_type =3D=3D DEV_TYPE_TUN && tunnel_topology =3D=3D = TOP_SUBNET)) { - setenv_in_addr_t(mi->context.c2.es, - "ifconfig_pool_netmask", - mi->context.c2.push_ifconfig_remote_netmask, - SA_SET_IF_NONZERO); + setenv_in_addr_t(mi->context.c2.es, "ifconfig_pool_netmask", + mi->context.c2.push_ifconfig_remote_netmask, = SA_SET_IF_NONZERO); } else if (tunnel_type =3D=3D DEV_TYPE_TUN) { - setenv_in_addr_t(mi->context.c2.es, - "ifconfig_pool_local_ip", - mi->context.c2.push_ifconfig_remote_netmask, - SA_SET_IF_NONZERO); + setenv_in_addr_t(mi->context.c2.es, "ifconfig_pool_local_ip", + mi->context.c2.push_ifconfig_remote_netmask, = SA_SET_IF_NONZERO); } } @@ -1638,16 +1606,11 @@ if (mi->context.c2.push_ifconfig_ipv6_defined) { - setenv_in6_addr(mi->context.c2.es, - "ifconfig_pool_remote", - &mi->context.c2.push_ifconfig_ipv6_local, - SA_SET_IF_NONZERO); - setenv_in6_addr(mi->context.c2.es, - "ifconfig_pool_local", - &mi->context.c2.push_ifconfig_ipv6_remote, - SA_SET_IF_NONZERO); - setenv_int(mi->context.c2.es, - "ifconfig_pool_ip6_netbits", + setenv_in6_addr(mi->context.c2.es, "ifconfig_pool_remote", + &mi->context.c2.push_ifconfig_ipv6_local, SA_SET_I= F_NONZERO); + setenv_in6_addr(mi->context.c2.es, "ifconfig_pool_local", + &mi->context.c2.push_ifconfig_ipv6_remote, SA_SET_= IF_NONZERO); + setenv_int(mi->context.c2.es, "ifconfig_pool_ip6_netbits", mi->context.c2.push_ifconfig_ipv6_netbits); } } @@ -1656,20 +1619,14 @@ * Called after client-connect script is called */ static void -multi_client_connect_post(struct multi_context *m, - struct multi_instance *mi, - const char *dc_file, +multi_client_connect_post(struct multi_context *m, struct multi_instance *= mi, const char *dc_file, unsigned int *option_types_found) { /* Did script generate a dynamic config file? */ if (platform_test_file(dc_file)) { - options_server_import(&mi->context.options, - dc_file, - D_IMPORT_ERRORS|M_OPTERR, - CLIENT_CONNECT_OPT_MASK, - option_types_found, - mi->context.c2.es); + options_server_import(&mi->context.options, dc_file, D_IMPORT_ERRO= RS | M_OPTERR, + CLIENT_CONNECT_OPT_MASK, option_types_found,= mi->context.c2.es); /* * If the --client-connect script generates a config file @@ -1688,10 +1645,8 @@ * Called after client-connect plug-in is called */ static void -multi_client_connect_post_plugin(struct multi_context *m, - struct multi_instance *mi, - const struct plugin_return *pr, - unsigned int *option_types_found) +multi_client_connect_post_plugin(struct multi_context *m, struct multi_ins= tance *mi, + const struct plugin_return *pr, unsigned = int *option_types_found) { struct plugin_return config; @@ -1705,12 +1660,9 @@ { if (config.list[i] && config.list[i]->value) { - options_string_import(&mi->context.options, - config.list[i]->value, - D_IMPORT_ERRORS|M_OPTERR, - CLIENT_CONNECT_OPT_MASK, - option_types_found, - mi->context.c2.es); + options_string_import(&mi->context.options, config.list[i]= ->value, + D_IMPORT_ERRORS | M_OPTERR, CLIENT_C= ONNECT_OPT_MASK, + option_types_found, mi->context.c2.e= s); } } @@ -1732,9 +1684,7 @@ * Called to load management-derived client-connect config */ enum client_connect_return -multi_client_connect_mda(struct multi_context *m, - struct multi_instance *mi, - bool deferred, +multi_client_connect_mda(struct multi_context *m, struct multi_instance *m= i, bool deferred, unsigned int *option_types_found) { /* We never return CC_RET_DEFERRED */ @@ -1747,12 +1697,8 @@ for (be =3D mi->cc_config->head; be !=3D NULL; be =3D be->next) { const char *opt =3D BSTR(&be->buf); - options_string_import(&mi->context.options, - opt, - D_IMPORT_ERRORS|M_OPTERR, - CLIENT_CONNECT_OPT_MASK, - option_types_found, - mi->context.c2.es); + options_string_import(&mi->context.options, opt, D_IMPORT_ERRO= RS | M_OPTERR, + CLIENT_CONNECT_OPT_MASK, option_types_fo= und, mi->context.c2.es); } /* @@ -1817,9 +1763,9 @@ else if (dco_enabled(o)) { msg(M_INFO, "Client does not support DATA_V2. Data channel offload= ing " - "requires DATA_V2. Dropping client."); + "requires DATA_V2. Dropping client."); auth_set_client_reason(tls_multi, "Data channel negotiation " - "failed (missing DATA_V2)"); + "failed (missing DATA_V2)"); return false; } @@ -1828,8 +1774,8 @@ if (proto & IV_PROTO_NCP_P2P) { msg(M_WARN, "Note: peer reports running in P2P mode (no --pull/--c= lient " - "option). It will not negotiate ciphers with this server. " - "Expect this connection to fail."); + "option). It will not negotiate ciphers with this serv= er. " + "Expect this connection to fail."); } if (proto & IV_PROTO_REQUEST_PUSH) @@ -1844,11 +1790,11 @@ else if (o->force_key_material_export) { msg(M_INFO, "PUSH: client does not support TLS Keying Material " - "Exporters but --force-tls-key-material-export is enabled."); + "Exporters but --force-tls-key-material-export is enab= led."); auth_set_client_reason(tls_multi, "Client incompatible with this " - "server. Keying Material Exporters (RFC 570= 5) " - "support missing. Upgrade to a client that " - "supports this feature (OpenVPN 2.6.0+)."); + "server. Keying Material Exporte= rs (RFC 5705) " + "support missing. Upgrade to a c= lient that " + "supports this feature (OpenVPN = 2.6.0+)."); return false; } if (proto & IV_PROTO_DYN_TLS_CRYPT) @@ -1869,10 +1815,11 @@ */ if (get_primary_key(tls_multi)->crypto_options.key_ctx_bi.initialized) { - msg(M_INFO, "PUSH: client wants to negotiate cipher (NCP), but " + msg(M_INFO, + "PUSH: client wants to negotiate cipher (NCP), but " "server has already generated data channel keys, " "re-sending previously negotiated cipher '%s'", - o->ciphername ); + o->ciphername); return true; } @@ -1880,14 +1827,13 @@ * Push the first cipher from --data-ciphers to the client that * the client announces to be supporting. */ - char *push_cipher =3D ncp_get_best_cipher(o->ncp_ciphers, peer_info, - tls_multi->remote_ciphername, - &o->gc); + char *push_cipher =3D + ncp_get_best_cipher(o->ncp_ciphers, peer_info, tls_multi->remote_c= iphername, &o->gc); if (push_cipher) { /* Enable epoch data key format if supported and AEAD cipher in us= e */ - if (tls_multi->session[TM_ACTIVE].opt->data_epoch_supported - && (proto & IV_PROTO_DATA_EPOCH) && cipher_kt_mode_aead(push_c= ipher)) + if (tls_multi->session[TM_ACTIVE].opt->data_epoch_supported && (pr= oto & IV_PROTO_DATA_EPOCH) + && cipher_kt_mode_aead(push_cipher)) { o->imported_protocol_flags |=3D CO_EPOCH_DATA_KEY_FORMAT; } @@ -1908,16 +1854,17 @@ * side, in this situation we fail the auth*/ if (strlen(peer_ciphers) > 0) { - msg(M_INFO, "PUSH: No common cipher between server and client. " + msg(M_INFO, + "PUSH: No common cipher between server and client. " "Server data-ciphers: '%s'%s, client supported ciphers '%s'", o->ncp_ciphers_conf, ncp_expanded_ciphers(o, &gc), peer_cipher= s); } else if (tls_multi->remote_ciphername) { - msg(M_INFO, "PUSH: No common cipher between server and client. " + msg(M_INFO, + "PUSH: No common cipher between server and client. " "Server data-ciphers: '%s'%s, client supports cipher '%s'", - o->ncp_ciphers_conf, ncp_expanded_ciphers(o, &gc), - tls_multi->remote_ciphername); + o->ncp_ciphers_conf, ncp_expanded_ciphers(o, &gc), tls_multi->= remote_ciphername); } else { @@ -1925,20 +1872,22 @@ if (o->enable_ncp_fallback && !tls_multi->remote_ciphername) { - msg(M_INFO, "Using data channel cipher '%s' since " - "--data-ciphers-fallback is set.", o->ciphername); + msg(M_INFO, + "Using data channel cipher '%s' since " + "--data-ciphers-fallback is set.", + o->ciphername); ret =3D true; } else { msg(M_INFO, "Use --data-ciphers-fallback with the cipher the " - "client is using if you want to allow the client to connec= t"); + "client is using if you want to allow the client t= o connect"); } } if (!ret) { auth_set_client_reason(tls_multi, "Data channel cipher negotiation= " - "failed (no shared cipher)"); + "failed (no shared cipher)"); } gc_free(&gc); @@ -1961,8 +1910,7 @@ setenv_del(mi->context.c2.es, "client_connect_deferred_file"); if (!platform_unlink(ccs->deferred_ret_file)) { - msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %s", - ccs->deferred_ret_file); + msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %s", = ccs->deferred_ret_file); } free(ccs->deferred_ret_file); ccs->deferred_ret_file =3D NULL; @@ -1993,8 +1941,7 @@ } ccs->deferred_ret_file =3D string_alloc(fn, NULL); - setenv_str(mi->context.c2.es, "client_connect_deferred_file", - ccs->deferred_ret_file); + setenv_str(mi->context.c2.es, "client_connect_deferred_file", ccs->def= erred_ret_file); gc_free(&gc); return true; @@ -2045,7 +1992,7 @@ default: /* We received an unknown/unexpected value. Assume failure. */ msg(M_WARN, "WARNING: Unknown/unexpected value in deferred " - "client-connect resultfile"); + "client-connect resultfile"); ret =3D CC_RET_FAILED; } fclose(fp); @@ -2067,8 +2014,7 @@ setenv_del(mi->context.c2.es, "client_connect_config_file"); if (!platform_unlink(ccs->config_file)) { - msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %= s", - ccs->config_file); + msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %= s", ccs->config_file); } free(ccs->config_file); ccs->config_file =3D NULL; @@ -2102,18 +2048,15 @@ } ccs->config_file =3D string_alloc(fn, NULL); - setenv_str(mi->context.c2.es, "client_connect_config_file", - ccs->config_file); + setenv_str(mi->context.c2.es, "client_connect_config_file", ccs->confi= g_file); gc_free(&gc); return true; } static enum client_connect_return -multi_client_connect_call_plugin_v1(struct multi_context *m, - struct multi_instance *mi, - bool deferred, - unsigned int *option_types_found) +multi_client_connect_call_plugin_v1(struct multi_context *m, struct multi_= instance *mi, + bool deferred, unsigned int *option_ty= pes_found) { enum client_connect_return ret =3D CC_RET_SKIPPED; #ifdef ENABLE_PLUGIN @@ -2131,8 +2074,7 @@ if (!deferred) { call =3D OPENVPN_PLUGIN_CLIENT_CONNECT; - if (!ccs_gen_config_file(mi) - || !ccs_gen_deferred_ret_file(mi)) + if (!ccs_gen_config_file(mi) || !ccs_gen_deferred_ret_file(mi)) { ret =3D CC_RET_FAILED; goto cleanup; @@ -2147,8 +2089,7 @@ } argv_printf(&argv, "%s", ccs->config_file); - int plug_ret =3D plugin_call(mi->context.plugins, call, - &argv, NULL, mi->context.c2.es); + int plug_ret =3D plugin_call(mi->context.plugins, call, &argv, NUL= L, mi->context.c2.es); if (plug_ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) { ret =3D CC_RET_SUCCEEDED; @@ -2188,8 +2129,7 @@ /* if we still think we have succeeded, do postprocessing */ if (ret =3D=3D CC_RET_SUCCEEDED) { - multi_client_connect_post(m, mi, ccs->config_file, - option_types_found); + multi_client_connect_post(m, mi, ccs->config_file, option_type= s_found); } cleanup: argv_free(&argv); @@ -2205,10 +2145,8 @@ } static enum client_connect_return -multi_client_connect_call_plugin_v2(struct multi_context *m, - struct multi_instance *mi, - bool deferred, - unsigned int *option_types_found) +multi_client_connect_call_plugin_v2(struct multi_context *m, struct multi_= instance *mi, + bool deferred, unsigned int *option_ty= pes_found) { enum client_connect_return ret =3D CC_RET_SKIPPED; #ifdef ENABLE_PLUGIN @@ -2216,8 +2154,7 @@ ASSERT(mi); ASSERT(option_types_found); - int call =3D deferred ? OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 : - OPENVPN_PLUGIN_CLIENT_CONNECT_V2; + int call =3D deferred ? OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 : OPENV= PN_PLUGIN_CLIENT_CONNECT_V2; /* V2 callback, use a plugin_return struct for passing back return inf= o */ if (plugin_defined(mi->context.plugins, call)) { @@ -2225,8 +2162,7 @@ plugin_return_init(&pr); - int plug_ret =3D plugin_call(mi->context.plugins, call, - NULL, &pr, mi->context.c2.es); + int plug_ret =3D plugin_call(mi->context.plugins, call, NULL, &pr,= mi->context.c2.es); if (plug_ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) { multi_client_connect_post_plugin(m, mi, &pr, option_types_foun= d); @@ -2235,13 +2171,12 @@ else if (plug_ret =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED) { ret =3D CC_RET_DEFERRED; - if (!(plugin_defined(mi->context.plugins, - OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2))) + if (!(plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIEN= T_CONNECT_DEFER_V2))) { msg(M_WARN, "A plugin that defers from the " - "OPENVPN_PLUGIN_CLIENT_CONNECT_V2 call must also " - "declare support for " - "OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2"); + "OPENVPN_PLUGIN_CLIENT_CONNECT_V2 call must al= so " + "declare support for " + "OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2"); ret =3D CC_RET_FAILED; } } @@ -2259,8 +2194,7 @@ } static enum client_connect_return -multi_client_connect_script_deferred(struct multi_context *m, - struct multi_instance *mi, +multi_client_connect_script_deferred(struct multi_context *m, struct multi= _instance *mi, unsigned int *option_types_found) { ASSERT(mi); @@ -2285,8 +2219,7 @@ if (ret =3D=3D CC_RET_SUCCEEDED) { ccs_delete_deferred_ret_file(mi); - multi_client_connect_post(m, mi, ccs->config_file, - option_types_found); + multi_client_connect_post(m, mi, ccs->config_file, option_types_fo= und); ccs_delete_config_file(mi); } if (ret =3D=3D CC_RET_FAILED) @@ -2302,9 +2235,7 @@ * Runs the --client-connect script if one is defined. */ static enum client_connect_return -multi_client_connect_call_script(struct multi_context *m, - struct multi_instance *mi, - bool deferred, +multi_client_connect_call_script(struct multi_context *m, struct multi_ins= tance *mi, bool deferred, unsigned int *option_types_found) { if (deferred) @@ -2324,8 +2255,7 @@ setenv_str(mi->context.c2.es, "script_type", "client-connect"); - if (!ccs_gen_config_file(mi) - || !ccs_gen_deferred_ret_file(mi)) + if (!ccs_gen_config_file(mi) || !ccs_gen_deferred_ret_file(mi)) { ret =3D CC_RET_FAILED; goto cleanup; @@ -2342,8 +2272,7 @@ } else { - multi_client_connect_post(m, mi, ccs->config_file, - option_types_found); + multi_client_connect_post(m, mi, ccs->config_file, option_= types_found); ret =3D CC_RET_SUCCEEDED; } } @@ -2364,8 +2293,7 @@ } static bool -multi_client_setup_dco_initial(struct multi_context *m, - struct multi_instance *mi, +multi_client_setup_dco_initial(struct multi_context *m, struct multi_insta= nce *mi, struct gc_arena *gc) { if (!dco_enabled(&mi->context.options)) @@ -2376,8 +2304,8 @@ int ret =3D dco_multi_add_new_peer(m, mi); if (ret < 0) { - msg(D_DCO, "Cannot add peer to DCO for %s: %s (%d)", - multi_instance_string(mi, false, gc), strerror(-ret), ret); + msg(D_DCO, "Cannot add peer to DCO for %s: %s (%d)", multi_instanc= e_string(mi, false, gc), + strerror(-ret), ret); return false; } @@ -2398,9 +2326,8 @@ } #endif struct tls_session *session =3D &c->c2.tls_multi->session[TM_ACTIVE]; - if (!tls_session_update_crypto_params(c->c2.tls_multi, session, &c->op= tions, - &c->c2.frame, frame_fragment, - get_link_socket_info(c), + if (!tls_session_update_crypto_params(c->c2.tls_multi, session, &c->op= tions, &c->c2.frame, + frame_fragment, get_link_socket_= info(c), &c->c1.tuntap->dco)) { msg(D_TLS_ERRORS, "TLS Error: initializing data channel failed"); @@ -2412,8 +2339,7 @@ } static void -multi_client_connect_late_setup(struct multi_context *m, - struct multi_instance *mi, +multi_client_connect_late_setup(struct multi_context *m, struct multi_inst= ance *mi, const unsigned int option_types_found) { ASSERT(m); @@ -2430,7 +2356,8 @@ */ if (!mi->context.c2.push_ifconfig_defined) { - msg(D_MULTI_ERRORS, "MULTI: no dynamic or static remote " + msg(D_MULTI_ERRORS, + "MULTI: no dynamic or static remote " "--ifconfig address is available for %s", multi_instance_string(mi, false, &gc)); } @@ -2446,7 +2373,8 @@ print_in_addr_t(mi->context.options.push_ifconfig_constraint_n= etmask, 0, &gc); /* JYFIXME -- this should cause the connection to fail */ - msg(D_MULTI_ERRORS, "MULTI ERROR: primary virtual IP for %s (%s) " + msg(D_MULTI_ERRORS, + "MULTI ERROR: primary virtual IP for %s (%s) " "violates tunnel network/netmask constraint (%s/%s)", multi_instance_string(mi, false, &gc), print_in_addr_t(mi->context.c2.push_ifconfig_local, 0, &gc), @@ -2490,9 +2418,7 @@ { if (mi->context.c2.push_ifconfig_defined) { - multi_learn_in_addr_t(m, mi, - mi->context.c2.push_ifconfig_local, - -1, true); + multi_learn_in_addr_t(m, mi, mi->context.c2.push_ifconfig_loca= l, -1, true); msg(D_MULTI_LOW, "MULTI: primary virtual IP for %s: %s", multi_instance_string(mi, false, &gc), print_in_addr_t(mi->context.c2.push_ifconfig_local, 0, &gc= )); @@ -2500,15 +2426,12 @@ if (mi->context.c2.push_ifconfig_ipv6_defined) { - multi_learn_in6_addr(m, mi, - mi->context.c2.push_ifconfig_ipv6_local, - -1, true); + multi_learn_in6_addr(m, mi, mi->context.c2.push_ifconfig_ipv6_= local, -1, true); /* TODO: find out where addresses are "unlearned"!! */ const char *ifconfig_local_ipv6 =3D print_in6_addr(mi->context.c2.push_ifconfig_ipv6_local, 0,= &gc); msg(D_MULTI_LOW, "MULTI: primary virtual IPv6 for %s: %s", - multi_instance_string(mi, false, &gc), - ifconfig_local_ipv6); + multi_instance_string(mi, false, &gc), ifconfig_local_ipv6= ); } /* add routes locally, pointing to new client, if @@ -2524,7 +2447,8 @@ } else if (mi->context.options.iroutes) { - msg(D_MULTI_ERRORS, "MULTI: --iroute options rejected for %s -- ir= oute " + msg(D_MULTI_ERRORS, + "MULTI: --iroute options rejected for %s -- iroute " "only works with tun-style tunnels", multi_instance_string(mi, false, &gc)); } @@ -2538,8 +2462,7 @@ } static void -multi_client_connect_early_setup(struct multi_context *m, - struct multi_instance *mi) +multi_client_connect_early_setup(struct multi_context *m, struct multi_ins= tance *mi) { ASSERT(mi->context.c1.tuntap); /* @@ -2574,10 +2497,8 @@ * ccd/script to do compression on a special client. */ static enum client_connect_return -multi_client_connect_compress_migrate(struct multi_context *m, - struct multi_instance *mi, - bool deferred, - unsigned int *option_types_found) +multi_client_connect_compress_migrate(struct multi_context *m, struct mult= i_instance *mi, + bool deferred, unsigned int *option_= types_found) { #ifdef USE_COMP struct options *o =3D &mi->context.options; @@ -2608,9 +2529,7 @@ * --client-config-dir directory. */ static enum client_connect_return -multi_client_connect_source_ccd(struct multi_context *m, - struct multi_instance *mi, - bool deferred, +multi_client_connect_source_ccd(struct multi_context *m, struct multi_inst= ance *mi, bool deferred, unsigned int *option_types_found) { /* Since we never return a CC_RET_DEFERRED, this indicates a serious @@ -2624,12 +2543,10 @@ const char *ccd_client =3D platform_gen_path(mi->context.options.client_config_dir, - tls_common_name(mi->context.c2.tls_multi, fa= lse), - &gc); + tls_common_name(mi->context.c2.tls_multi, fa= lse), &gc); const char *ccd_default =3D - platform_gen_path(mi->context.options.client_config_dir, - CCD_DEFAULT, &gc); + platform_gen_path(mi->context.options.client_config_dir, CCD_D= EFAULT, &gc); /* try common-name file */ @@ -2645,12 +2562,8 @@ if (ccd_file) { - options_server_import(&mi->context.options, - ccd_file, - D_IMPORT_ERRORS|M_OPTERR, - CLIENT_CONNECT_OPT_MASK, - option_types_found, - mi->context.c2.es); + options_server_import(&mi->context.options, ccd_file, D_IMPORT= _ERRORS | M_OPTERR, + CLIENT_CONNECT_OPT_MASK, option_types_fo= und, mi->context.c2.es); /* * Select a virtual address from either --ifconfig-push in * --client-config-dir file or --ifconfig-pool. @@ -2666,9 +2579,9 @@ return ret; } -typedef enum client_connect_return (*multi_client_connect_handler) - (struct multi_context *m, struct multi_instance *mi, - bool from_deferred, unsigned int *option_types_found); +typedef enum client_connect_return (*multi_client_connect_handler)( + struct multi_context *m, struct multi_instance *mi, bool from_deferred, + unsigned int *option_types_found); static const multi_client_connect_handler client_connect_handlers[] =3D { multi_client_connect_compress_migrate, @@ -2694,9 +2607,9 @@ if (!multi->locked_username) { msg(D_MULTI_ERRORS, "MULTI: Ignoring override-username as no " - "user/password method is enabled. Enable " - "--management-client-auth, --auth-user-pass-verify, or a " - "plugin with user/password verify capability."); + "user/password method is enabled. Enable " + "--management-client-auth, --auth-user-pass-ve= rify, or a " + "plugin with user/password verify capability."= ); return false; } @@ -2727,16 +2640,15 @@ { struct user_pass up; CLEAR(up); - strncpynt(up.username, multi->locked_username, - sizeof(up.username)); + strncpynt(up.username, multi->locked_username, sizeof(up.usern= ame)); generate_auth_token(&up, multi); } - msg(D_MULTI_LOW, "MULTI: Note, override-username changes username " + msg(D_MULTI_LOW, + "MULTI: Note, override-username changes username " "from '%s' to '%s'", - multi->locked_original_username, - multi->locked_username); + multi->locked_original_username, multi->locked_username); } return true; } @@ -2767,8 +2679,7 @@ bool from_deferred =3D (mi->context.c2.tls_multi->multi_state !=3D CAS= _PENDING); int *cur_handler_index =3D &mi->client_connect_defer_state.cur_handler= _index; - unsigned int *option_types_found =3D - &mi->client_connect_defer_state.option_types_found; + unsigned int *option_types_found =3D &mi->client_connect_defer_state.o= ption_types_found; /* We are called for the first time */ if (!from_deferred) @@ -2783,12 +2694,10 @@ bool cc_succeeded =3D true; - while (cc_succeeded - && client_connect_handlers[*cur_handler_index] !=3D NULL) + while (cc_succeeded && client_connect_handlers[*cur_handler_index] != =3D NULL) { enum client_connect_return ret; - ret =3D client_connect_handlers[*cur_handler_index](m, mi, from_de= ferred, - option_types_fou= nd); + ret =3D client_connect_handlers[*cur_handler_index](m, mi, from_de= ferred, option_types_found); from_deferred =3D false; @@ -2836,7 +2745,7 @@ if (mi->context.options.disable) { msg(D_MULTI_ERRORS, "MULTI: client has been rejected due to " - "'disable' directive"); + "'disable' directive"); cc_succeeded =3D false; } @@ -2889,8 +2798,8 @@ #ifdef ENABLE_MANAGEMENT if (management) { - management_connection_established(management, - &mi->context.c2.mda_context, mi-= >context.c2.es); + management_connection_established(management, &mi->context.c2.mda_= context, + mi->context.c2.es); } #endif } @@ -2912,13 +2821,14 @@ while (buffer_i < r) { /* parse inotify events */ - struct inotify_event *pevent =3D (struct inotify_event *) &buffer[= buffer_i]; + struct inotify_event *pevent =3D (struct inotify_event *)&buffer[b= uffer_i]; size_t event_size =3D sizeof(struct inotify_event) + pevent->len; buffer_i +=3D event_size; msg(D_MULTI_DEBUG, "MULTI: modified fd %d, mask %d", pevent->wd, p= event->mask); - struct multi_instance *mi =3D hash_lookup(m->inotify_watchers, (vo= id *) (unsigned long) pevent->wd); + struct multi_instance *mi =3D + hash_lookup(m->inotify_watchers, (void *)(unsigned long)pevent= ->wd); if (pevent->mask & IN_CLOSE_WRITE) { @@ -2937,7 +2847,7 @@ /* this event is _always_ fired when watch is removed or file = is deleted */ if (mi) { - hash_remove(m->inotify_watchers, (void *) (unsigned long) = pevent->wd); + hash_remove(m->inotify_watchers, (void *)(unsigned long)pe= vent->wd); mi->inotify_watch =3D -1; } } @@ -2954,9 +2864,7 @@ * instance. */ void -multi_add_mbuf(struct multi_context *m, - struct multi_instance *mi, - struct mbuf_buffer *mb) +multi_add_mbuf(struct multi_context *m, struct multi_instance *mi, struct = mbuf_buffer *mb) { if (multi_output_queue_ready(m, mi)) { @@ -2975,9 +2883,7 @@ * Add a packet to a client instance output queue. */ static inline void -multi_unicast(struct multi_context *m, - const struct buffer *buf, - struct multi_instance *mi) +multi_unicast(struct multi_context *m, const struct buffer *buf, struct mu= lti_instance *mi) { struct mbuf_buffer *mb; @@ -2994,10 +2900,8 @@ * Broadcast a packet to all clients. */ static void -multi_bcast(struct multi_context *m, - const struct buffer *buf, - const struct multi_instance *sender_instance, - uint16_t vid) +multi_bcast(struct multi_context *m, const struct buffer *buf, + const struct multi_instance *sender_instance, uint16_t vid) { struct hash_iterator hi; struct hash_element *he; @@ -3015,7 +2919,7 @@ while ((he =3D hash_iterator_next(&hi))) { - mi =3D (struct multi_instance *) he->value; + mi =3D (struct multi_instance *)he->value; if (mi !=3D sender_instance && !mi->halt) { if (vid !=3D 0 && vid !=3D mi->context.options.vlan_pvid) @@ -3073,29 +2977,24 @@ tv_add(&mi->wakeup, &mi->context.c2.timeval); /* tell scheduler to wake us up at some point in the future */ - schedule_add_entry(m->schedule, - (struct schedule_entry *) mi, - &mi->wakeup, + schedule_add_entry(m->schedule, (struct schedule_entry *)mi, &mi->wake= up, compute_wakeup_sigma(&mi->context.c2.timeval)); } #if defined(ENABLE_ASYNC_PUSH) static void -add_inotify_file_watch(struct multi_context *m, struct multi_instance *mi, - int inotify_fd, const char *file) +add_inotify_file_watch(struct multi_context *m, struct multi_instance *mi,= int inotify_fd, + const char *file) { /* watch acf file */ - long watch_descriptor =3D inotify_add_watch(inotify_fd, file, - IN_CLOSE_WRITE | IN_ONESHOT); + long watch_descriptor =3D inotify_add_watch(inotify_fd, file, IN_CLOSE= _WRITE | IN_ONESHOT); if (watch_descriptor >=3D 0) { if (mi->inotify_watch !=3D -1) { - hash_remove(m->inotify_watchers, - (void *) (unsigned long)mi->inotify_watch); + hash_remove(m->inotify_watchers, (void *)(unsigned long)mi->in= otify_watch); } - hash_add(m->inotify_watchers, (const uintptr_t *)watch_descriptor, - mi, true); + hash_add(m->inotify_watchers, (const uintptr_t *)watch_descriptor,= mi, true); mi->inotify_watch =3D watch_descriptor; } else @@ -3117,7 +3016,9 @@ { bool ret =3D true; - if (!IS_SIG(&mi->context) && ((flags & MPP_PRE_SELECT) || ((flags & MP= P_CONDITIONAL_PRE_SELECT) && !ANY_OUT(&mi->context)))) + if (!IS_SIG(&mi->context) + && ((flags & MPP_PRE_SELECT) + || ((flags & MPP_CONDITIONAL_PRE_SELECT) && !ANY_OUT(&mi->cont= ext)))) { #if defined(ENABLE_ASYNC_PUSH) bool was_unauthenticated =3D true; @@ -3142,14 +3043,12 @@ if (ks && ks->plugin_auth.auth_control_file && was_unauthenticated && (ks->authenticated =3D=3D KS_AUTH_DEFERRED)) { - add_inotify_file_watch(m, mi, m->top.c2.inotify_fd, - ks->plugin_auth.auth_control_file); + add_inotify_file_watch(m, mi, m->top.c2.inotify_fd, ks->plugin= _auth.auth_control_file); } if (ks && ks->script_auth.auth_control_file && was_unauthenticated && (ks->authenticated =3D=3D KS_AUTH_DEFERRED)) { - add_inotify_file_watch(m, mi, m->top.c2.inotify_fd, - ks->script_auth.auth_control_file); + add_inotify_file_watch(m, mi, m->top.c2.inotify_fd, ks->script= _auth.auth_control_file); } #endif @@ -3167,8 +3066,7 @@ && mi->client_connect_defer_state.deferred_ret_file) { add_inotify_file_watch(m, mi, m->top.c2.inotify_fd, - mi->client_connect_defer_state. - deferred_ret_file); + mi->client_connect_defer_state.defe= rred_ret_file); } #endif /* tell scheduler to wake us up at some point in the future */ @@ -3190,14 +3088,10 @@ multi_set_pending(m, ANY_OUT(&mi->context) ? mi : NULL); #ifdef MULTI_DEBUG_EVENT_LOOP - printf("POST %s[%d] to=3D%d lo=3D%d/%d w=3D%" PRIi64 "/%ld\n", - id(mi), - (int) (mi =3D=3D m->pending), - mi ? mi->context.c2.to_tun.len : -1, - mi ? mi->context.c2.to_link.len : -1, + printf("POST %s[%d] to=3D%d lo=3D%d/%d w=3D%" PRIi64 "/%ld\n", id(= mi), (int)(mi =3D=3D m->pending), + mi ? mi->context.c2.to_tun.len : -1, mi ? mi->context.c2.to= _link.len : -1, (mi && mi->context.c2.fragment) ? mi->context.c2.fragment->= outgoing.len : -1, - (int64_t)mi->context.c2.timeval.tv_sec, - (long)mi->context.c2.timeval.tv_usec); + (int64_t)mi->context.c2.timeval.tv_sec, (long)mi->context.c= 2.timeval.tv_usec); #endif } @@ -3210,10 +3104,9 @@ } void -multi_process_float(struct multi_context *m, struct multi_instance *mi, - struct link_socket *sock) +multi_process_float(struct multi_context *m, struct multi_instance *mi, st= ruct link_socket *sock) { - struct mroute_addr real =3D {0}; + struct mroute_addr real =3D { 0 }; struct hash *hash =3D m->hash; struct gc_arena gc =3D gc_new(); @@ -3235,7 +3128,7 @@ struct hash_element *he =3D hash_lookup_fast(hash, bucket, &real, hv); if (he) { - struct multi_instance *ex_mi =3D (struct multi_instance *) he->val= ue; + struct multi_instance *ex_mi =3D (struct multi_instance *)he->valu= e; struct tls_multi *m1 =3D mi->context.c2.tls_multi; struct tls_multi *m2 =3D ex_mi->context.c2.tls_multi; @@ -3256,10 +3149,8 @@ } msg(D_MULTI_MEDIUM, "peer %" PRIu32 " (%s) floated from %s to %s", - mi->context.c2.tls_multi->peer_id, - tls_common_name(mi->context.c2.tls_multi, false), - mroute_addr_print(&mi->real, &gc), - print_link_socket_actual(&m->top.c2.from, &gc)); + mi->context.c2.tls_multi->peer_id, tls_common_name(mi->context.c2.= tls_multi, false), + mroute_addr_print(&mi->real, &gc), print_link_socket_actual(&m->to= p.c2.from, &gc)); /* remove old address from hash table before changing address */ ASSERT(hash_remove(m->hash, &mi->real)); @@ -3303,7 +3194,8 @@ multi_close_instance(m, mi, false); } -#if (defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEB= SD))) || defined(ENABLE_MANAGEMENT) +#if (defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEB= SD))) \ + || defined(ENABLE_MANAGEMENT) static void multi_signal_instance(struct multi_context *m, struct multi_instance *mi, = const int sig) { @@ -3315,8 +3207,7 @@ #if defined(ENABLE_DCO) \ && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(TARGET= _WIN32)) static void -process_incoming_del_peer(struct multi_context *m, struct multi_instance *= mi, - dco_context_t *dco) +process_incoming_del_peer(struct multi_context *m, struct multi_instance *= mi, dco_context_t *dco) { const char *reason =3D "ovpn-dco: unknown reason"; switch (dco->dco_del_peer_reason) @@ -3404,9 +3295,10 @@ */ msglevel =3D D_DCO_DEBUG; } - msg(msglevel, "Received DCO message for unknown peer-id: %d, " - "type %d, del_peer_reason %d", peer_id, dco->dco_message_type, - dco->dco_del_peer_reason); + msg(msglevel, + "Received DCO message for unknown peer-id: %d, " + "type %d, del_peer_reason %d", + peer_id, dco->dco_message_type, dco->dco_del_peer_reason); } dco->dco_message_type =3D 0; @@ -3496,11 +3388,8 @@ if (TUNNEL_TYPE(m->top.c1.tuntap) =3D=3D DEV_TYPE_TUN) { /* extract packet source and dest addresses */ - mroute_flags =3D mroute_extract_addr_from_packet(&src, - &dest, - 0, - &c->c2.to_t= un, - DEV_TYPE_TU= N); + mroute_flags =3D + mroute_extract_addr_from_packet(&src, &dest, 0, &c->c2= .to_tun, DEV_TYPE_TUN); /* drop packet if extract failed */ if (!(mroute_flags & MROUTE_EXTRACT_SUCCEEDED)) @@ -3511,14 +3400,15 @@ else if (multi_get_instance_by_virtual_addr(m, &src, true)= !=3D m->pending) { /* IPv6 link-local address (fe80::xxx)? */ - if ( (src.type & MR_ADDR_MASK) =3D=3D MR_ADDR_IPV6 - && IN6_IS_ADDR_LINKLOCAL(&src.v6.addr) ) + if ((src.type & MR_ADDR_MASK) =3D=3D MR_ADDR_IPV6 + && IN6_IS_ADDR_LINKLOCAL(&src.v6.addr)) { /* do nothing, for now. TODO: add address learnin= g */ } else { - msg(D_MULTI_DROPPED, "MULTI: bad source address fr= om client [%s], packet dropped", + msg(D_MULTI_DROPPED, + "MULTI: bad source address from client [%s], p= acket dropped", mroute_addr_print(&src, &gc)); } c->c2.to_tun.len =3D 0; @@ -3567,11 +3457,8 @@ } } /* extract packet source and dest addresses */ - mroute_flags =3D mroute_extract_addr_from_packet(&src, - &dest, - vid, - &c->c2.to_t= un, - DEV_TYPE_TA= P); + mroute_flags =3D + mroute_extract_addr_from_packet(&src, &dest, vid, &c->= c2.to_tun, DEV_TYPE_TAP); if (mroute_flags & MROUTE_EXTRACT_SUCCEEDED) { @@ -3580,7 +3467,7 @@ /* check for broadcast */ if (m->enable_c2c) { - if (mroute_flags & (MROUTE_EXTRACT_BCAST|MROUT= E_EXTRACT_MCAST)) + if (mroute_flags & (MROUTE_EXTRACT_BCAST | MRO= UTE_EXTRACT_MCAST)) { multi_bcast(m, &c->c2.to_tun, m->pending, = vid); } @@ -3600,7 +3487,8 @@ } else { - msg(D_MULTI_DROPPED, "MULTI: bad source address fr= om client [%s], packet dropped", + msg(D_MULTI_DROPPED, + "MULTI: bad source address from client [%s], p= acket dropped", mroute_addr_print(&src, &gc)); c->c2.to_tun.len =3D 0; } @@ -3634,7 +3522,7 @@ if (BLEN(&m->top.c2.buf) > 0) { unsigned int mroute_flags; - struct mroute_addr src =3D {0}, dest =3D {0}; + struct mroute_addr src =3D { 0 }, dest =3D { 0 }; const int dev_type =3D TUNNEL_TYPE(m->top.c1.tuntap); int16_t vid =3D 0; @@ -3661,25 +3549,22 @@ * the appropriate multi_instance object. */ - mroute_flags =3D mroute_extract_addr_from_packet(&src, - &dest, - vid, - &m->top.c2.buf, - dev_type); + mroute_flags =3D mroute_extract_addr_from_packet(&src, &dest, vid,= &m->top.c2.buf, dev_type); if (mroute_flags & MROUTE_EXTRACT_SUCCEEDED) { struct context *c; /* broadcast or multicast dest addr? */ - if (mroute_flags & (MROUTE_EXTRACT_BCAST|MROUTE_EXTRACT_MCAST)) + if (mroute_flags & (MROUTE_EXTRACT_BCAST | MROUTE_EXTRACT_MCAS= T)) { /* for now, treat multicast as broadcast */ multi_bcast(m, &m->top.c2.buf, NULL, vid); } else { - multi_set_pending(m, multi_get_instance_by_virtual_addr(m,= &dest, dev_type =3D=3D DEV_TYPE_TUN)); + multi_set_pending( + m, multi_get_instance_by_virtual_addr(m, &dest, dev_ty= pe =3D=3D DEV_TYPE_TUN)); if (m->pending) { @@ -3697,7 +3582,8 @@ else { /* drop packet */ - msg(D_MULTI_DROPPED, "MULTI: packet dropped du= e to output saturation (multi_process_incoming_tun)"); + msg(D_MULTI_DROPPED, + "MULTI: packet dropped due to output satur= ation (multi_process_incoming_tun)"); buf_reset_len(&c->c2.buf); } } @@ -3731,7 +3617,8 @@ set_prefix(item.instance); item.instance->context.c2.buf =3D item.buffer->buf; - if (item.buffer->flags & MF_UNICAST) /* --mssfix doesn't make sens= e for broadcast or multicast */ + if (item.buffer->flags + & MF_UNICAST) /* --mssfix doesn't make sense for broadcast or = multicast */ { pip_flags |=3D PIP_MSSFIX; } @@ -3769,7 +3656,8 @@ { if (m->earliest_wakeup =3D=3D (struct multi_instance *)&m->deferre= d_shutdown_signal) { - schedule_remove_entry(m->schedule, (struct schedule_entry *) &= m->deferred_shutdown_signal); + schedule_remove_entry(m->schedule, + (struct schedule_entry *)&m->deferred_sh= utdown_signal); throw_signal(m->deferred_shutdown_signal.signal_received); } else @@ -3812,9 +3700,9 @@ route_quota_exceeded(const struct multi_instance *mi) { struct gc_arena gc =3D gc_new(); - msg(D_ROUTE_QUOTA, "MULTI ROUTE: route quota (%d) exceeded for %s (see= --max-routes-per-client option)", - mi->context.options.max_routes_per_client, - multi_instance_string(mi, false, &gc)); + msg(D_ROUTE_QUOTA, + "MULTI ROUTE: route quota (%d) exceeded for %s (see --max-routes-p= er-client option)", + mi->context.options.max_routes_per_client, multi_instance_string(m= i, false, &gc)); gc_free(&gc); } @@ -3837,8 +3725,7 @@ parm.packet_size =3D min_int(parm.packet_size, m->top.c2.frame.buf= .payload_size); msg(D_GREMLIN, "GREMLIN_FLOOD_CLIENTS: flooding clients with %d pa= ckets of size %d", - parm.n_packets, - parm.packet_size); + parm.n_packets, parm.packet_size); for (i =3D 0; i < parm.packet_size; ++i) { @@ -3926,10 +3813,11 @@ hash_iterator_init(m->iter, &hi); while ((he =3D hash_iterator_next(&hi))) { - struct multi_instance *mi =3D (struct multi_instance *) he->value; + struct multi_instance *mi =3D (struct multi_instance *)he->value; if (!mi->halt && proto_is_dgram(mi->context.c2.link_sockets[0]->in= fo.proto)) { - send_control_channel_string(&mi->context, next_server ? "RESTA= RT,[N]" : "RESTART", D_PUSH); + send_control_channel_string(&mi->context, next_server ? "RESTA= RT,[N]" : "RESTART", + D_PUSH); multi_schedule_context_wakeup(m, mi); } } @@ -3943,8 +3831,7 @@ m->deferred_shutdown_signal.signal_received =3D m->top.sig->signal_rec= eived; - schedule_add_entry(m->schedule, - (struct schedule_entry *) &m->deferred_shutdown_sig= nal, + schedule_add_entry(m->schedule, (struct schedule_entry *)&m->deferred_= shutdown_signal, &m->deferred_shutdown_signal.wakeup, compute_wakeup_sigma(&m->deferred_shutdown_signal.w= akeup)); @@ -3965,8 +3852,7 @@ status_close(so); return false; } - else if (has_udp_in_local_list(&m->top.options) - && is_exit_restart(m->top.sig->signal_received) + else if (has_udp_in_local_list(&m->top.options) && is_exit_restart(m->= top.sig->signal_received) && (m->deferred_shutdown_signal.signal_received =3D=3D 0) && m->top.options.ce.explicit_exit_notification !=3D 0) { @@ -3984,7 +3870,7 @@ static void management_callback_status(void *arg, const int version, struct status_out= put *so) { - struct multi_context *m =3D (struct multi_context *) arg; + struct multi_context *m =3D (struct multi_context *)arg; if (!version) { @@ -3999,14 +3885,14 @@ static int management_callback_n_clients(void *arg) { - struct multi_context *m =3D (struct multi_context *) arg; + struct multi_context *m =3D (struct multi_context *)arg; return m->n_clients; } static int management_callback_kill_by_cn(void *arg, const char *del_cn) { - struct multi_context *m =3D (struct multi_context *) arg; + struct multi_context *m =3D (struct multi_context *)arg; struct hash_iterator hi; struct hash_element *he; int count =3D 0; @@ -4014,7 +3900,7 @@ hash_iterator_init(m->iter, &hi); while ((he =3D hash_iterator_next(&hi))) { - struct multi_instance *mi =3D (struct multi_instance *) he->value; + struct multi_instance *mi =3D (struct multi_instance *)he->value; if (!mi->halt) { const char *cn =3D tls_common_name(mi->context.c2.tls_multi, f= alse); @@ -4030,10 +3916,9 @@ } static int -management_callback_kill_by_addr(void *arg, const in_addr_t addr, - const int port, const int proto) +management_callback_kill_by_addr(void *arg, const in_addr_t addr, const in= t port, const int proto) { - struct multi_context *m =3D (struct multi_context *) arg; + struct multi_context *m =3D (struct multi_context *)arg; struct hash_iterator hi; struct hash_element *he; struct openvpn_sockaddr saddr; @@ -4050,7 +3935,7 @@ hash_iterator_init(m->iter, &hi); while ((he =3D hash_iterator_next(&hi))) { - struct multi_instance *mi =3D (struct multi_instance *) he->va= lue; + struct multi_instance *mi =3D (struct multi_instance *)he->val= ue; if (!mi->halt && mroute_addr_equal(&maddr, &mi->real)) { multi_signal_instance(m, mi, SIGTERM); @@ -4065,7 +3950,7 @@ static void management_delete_event(void *arg, event_t event) { - struct multi_context *m =3D (struct multi_context *) arg; + struct multi_context *m =3D (struct multi_context *)arg; if (m->multi_io) { multi_tcp_delete_event(m->multi_io, event); @@ -4077,7 +3962,7 @@ { if (m) { - struct multi_instance *mi =3D (struct multi_instance *) hash_looku= p(m->cid_hash, &cid); + struct multi_instance *mi =3D (struct multi_instance *)hash_lookup= (m->cid_hash, &cid); if (mi && !mi->halt) { return mi; @@ -4089,7 +3974,7 @@ static bool management_kill_by_cid(void *arg, const unsigned long cid, const char *kil= l_msg) { - struct multi_context *m =3D (struct multi_context *) arg; + struct multi_context *m =3D (struct multi_context *)arg; struct multi_instance *mi =3D lookup_by_cid(m, cid); if (mi) { @@ -4104,13 +3989,10 @@ } static bool -management_client_pending_auth(void *arg, - const unsigned long cid, - const unsigned int mda_key_id, - const char *extra, - unsigned int timeout) +management_client_pending_auth(void *arg, const unsigned long cid, const u= nsigned int mda_key_id, + const char *extra, unsigned int timeout) { - struct multi_context *m =3D (struct multi_context *) arg; + struct multi_context *m =3D (struct multi_context *)arg; struct multi_instance *mi =3D lookup_by_cid(m, cid); if (mi) @@ -4132,8 +4014,7 @@ } /* sends INFO_PRE and AUTH_PENDING messages to client */ - bool ret =3D send_auth_pending_messages(multi, session, extra, - timeout); + bool ret =3D send_auth_pending_messages(multi, session, extra, tim= eout); reschedule_multi_process(&mi->context); multi_schedule_context_wakeup(m, mi); return ret; @@ -4143,15 +4024,11 @@ static bool -management_client_auth(void *arg, - const unsigned long cid, - const unsigned int mda_key_id, - const bool auth, - const char *reason, - const char *client_reason, - struct buffer_list *cc_config) /* ownership transf= erred */ +management_client_auth(void *arg, const unsigned long cid, const unsigned = int mda_key_id, + const bool auth, const char *reason, const char *cl= ient_reason, + struct buffer_list *cc_config) /* ownership transfe= rred */ { - struct multi_context *m =3D (struct multi_context *) arg; + struct multi_context *m =3D (struct multi_context *)arg; struct multi_instance *mi =3D lookup_by_cid(m, cid); bool cc_config_owned =3D true; bool ret =3D false; @@ -4171,7 +4048,8 @@ } else if (reason) { - msg(D_MULTI_LOW, "MULTI: connection rejected: %s, CLI:%s",= reason, np(client_reason)); + msg(D_MULTI_LOW, "MULTI: connection rejected: %s, CLI:%s",= reason, + np(client_reason)); } } } @@ -4185,7 +4063,7 @@ static char * management_get_peer_info(void *arg, const unsigned long cid) { - struct multi_context *m =3D (struct multi_context *) arg; + struct multi_context *m =3D (struct multi_context *)arg; struct multi_instance *mi =3D lookup_by_cid(m, cid); char *ret =3D NULL; @@ -4328,7 +4206,7 @@ tunnel_server_loop(&multi); - #ifdef ENABLE_ASYNC_PUSH +#ifdef ENABLE_ASYNC_PUSH close(top->c2.inotify_fd); #endif @@ -4342,5 +4220,4 @@ multi_uninit(&multi); multi_top_free(&multi); close_instance(top); - } diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 40f7519..184432e 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -100,27 +100,28 @@ * page describes the role the structure plays when OpenVPN is running in * server-mode. */ -struct multi_instance { - struct schedule_entry se; /* this must be the first element of the st= ructure, - * We cast between this and schedule_entry = so the - * beginning of the struct must be identica= l */ +struct multi_instance +{ + struct schedule_entry se; /* this must be the first element of the str= ucture, + * We cast between this and schedule_entry s= o the + * beginning of the struct must be identical= */ - struct event_arg ev_arg; /**< this struct will store a pointer to ei= ther mi or - * link_socket, depending on the event type= , to keep - * it accessible it's placed within the sam= e struct - * it points to. */ + struct event_arg ev_arg; /**< this struct will store a pointer to eit= her mi or + * link_socket, depending on the event type,= to keep + * it accessible it's placed within the same= struct + * it points to. */ struct gc_arena gc; bool halt; int refcount; - int route_count; /* number of routes (including cached route= s) owned by this instance */ - time_t created; /**< Time at which a VPN tunnel instance - * was created. This parameter is set - * by the \c multi_create_instance() - * function. */ - struct timeval wakeup; /* absolute time */ - struct mroute_addr real; /**< External network address of the - * remote peer. */ + int route_count; /* number of routes (including cached routes)= owned by this instance */ + time_t created; /**< Time at which a VPN tunnel instance + * was created. This parameter is set + * by the \c multi_create_instance() + * function. */ + struct timeval wakeup; /* absolute time */ + struct mroute_addr real; /**< External network address of the + * remote peer. */ ifconfig_pool_handle vaddr_handle; char msg_prefix[MULTI_PREFIX_MAX_LENGTH]; @@ -129,7 +130,7 @@ struct mbuf_set *tcp_link_out_deferred; bool socket_set_called; - in_addr_t reporting_addr; /* IP address shown in status listing */ + in_addr_t reporting_addr; /* IP address shown in status lis= ting */ struct in6_addr reporting_addr_ipv6; /* IPv6 address in status listing= */ bool did_real_hash; @@ -139,10 +140,10 @@ struct buffer_list *cc_config; #endif bool did_iroutes; - int n_clients_delta; /* added to multi_context.n_clients when instance= is closed */ + int n_clients_delta; /* added to multi_context.n_clients when insta= nce is closed */ - struct context context; /**< The context structure storing state - * for this VPN tunnel. */ + struct context context; /**< The context structure storing state + * for this VPN tunnel. */ struct client_connect_defer_state client_connect_defer_state; #ifdef ENABLE_ASYNC_PUSH int inotify_watch; /* watch descriptor for acf */ @@ -160,22 +161,23 @@ * page describes the role the structure plays when OpenVPN is running in * server-mode. */ -struct multi_context { - struct multi_instance **instances; /**< Array of multi_instances. An = instance can be - * accessed using peer-id as an in= dex. */ +struct multi_context +{ + struct multi_instance **instances; /**< Array of multi_instances. An i= nstance can be + * accessed using peer-id as an ind= ex. */ - struct hash *hash; /**< VPN tunnel instances indexed by real - * address of the remote peer. */ - struct hash *vhash; /**< VPN tunnel instances indexed by - * virtual address of remote hosts. */ - struct hash *iter; /**< VPN tunnel instances indexed by real - * address of the remote peer, optimized - * for iteration. */ + struct hash *hash; /**< VPN tunnel instances indexed b= y real + * address of the remote peer. */ + struct hash *vhash; /**< VPN tunnel instances indexed by + * virtual address of remote host= s. */ + struct hash *iter; /**< VPN tunnel instances indexed b= y real + * address of the remote peer, op= timized + * for iteration. */ struct schedule *schedule; - struct mbuf_set *mbuf; /**< Set of buffers for passing data - * channel packets between VPN tunnel - * instances. */ - struct multi_io *multi_io; /**< I/O state and events tracker */ + struct mbuf_set *mbuf; /**< Set of buffers for passing data + * channel packets between VPN tu= nnel + * instances. */ + struct multi_io *multi_io; /**< I/O state and events tracker */ struct ifconfig_pool *ifconfig_pool; struct frequency_limit *new_connection_limiter; struct initial_packet_rate_limit *initial_rate_limiter; @@ -199,8 +201,8 @@ struct context_buffers *context_buffers; time_t per_second_trigger; - struct context top; /**< Storage structure for process-wide - * configuration. */ + struct context top; /**< Storage structure for process-wide + * configuration. */ struct buffer hmac_reply; struct link_socket_actual *hmac_reply_dest; @@ -238,8 +240,8 @@ struct mroute_addr addr; struct multi_instance *instance; -#define MULTI_ROUTE_CACHE (1<<0) -#define MULTI_ROUTE_AGEABLE (1<<1) +#define MULTI_ROUTE_CACHE (1 << 0) +#define MULTI_ROUTE_AGEABLE (1 << 1) unsigned int flags; unsigned int cache_generation; @@ -271,7 +273,8 @@ void multi_top_free(struct multi_context *m); -struct multi_instance *multi_create_instance(struct multi_context *m, cons= t struct mroute_addr *real, +struct multi_instance *multi_create_instance(struct multi_context *m, + const struct mroute_addr *rea= l, struct link_socket *sock); void multi_close_instance(struct multi_context *m, struct multi_instance *= mi, bool shutdown); @@ -289,10 +292,10 @@ void multi_process_float(struct multi_context *m, struct multi_instance *m= i, struct link_socket *sock); -#define MPP_PRE_SELECT (1<<0) -#define MPP_CONDITIONAL_PRE_SELECT (1<<1) -#define MPP_CLOSE_ON_SIGNAL (1<<2) -#define MPP_RECORD_TOUCH (1<<3) +#define MPP_PRE_SELECT (1 << 0) +#define MPP_CONDITIONAL_PRE_SELECT (1 << 1) +#define MPP_CLOSE_ON_SIGNAL (1 << 2) +#define MPP_RECORD_TOUCH (1 << 3) /*************************************************************************= */ @@ -317,7 +320,8 @@ * signal during processing. * - False, if the VPN tunnel instance \a mi was closed. */ -bool multi_process_post(struct multi_context *m, struct multi_instance *mi= , const unsigned int flags); +bool multi_process_post(struct multi_context *m, struct multi_instance *mi, + const unsigned int flags); /** * Process an incoming DCO message (from kernel space). @@ -354,8 +358,8 @@ * @param mpp_flags - Fast I/O optimization flags. * @param sock - Socket where the packet was received. */ -bool multi_process_incoming_link(struct multi_context *m, struct multi_ins= tance *instance, const unsigned int mpp_flags, - struct link_socket *sock); +bool multi_process_incoming_link(struct multi_context *m, struct multi_ins= tance *instance, + const unsigned int mpp_flags, struct link= _socket *sock); /** @@ -382,9 +386,7 @@ struct multi_instance *multi_get_queue(struct mbuf_set *ms); -void multi_add_mbuf(struct multi_context *m, - struct multi_instance *mi, - struct mbuf_buffer *mb); +void multi_add_mbuf(struct multi_context *m, struct multi_instance *mi, st= ruct mbuf_buffer *mb); void multi_ifconfig_pool_persist(struct multi_context *m, bool force); @@ -410,8 +412,7 @@ * Return true if our output queue is not full */ static inline bool -multi_output_queue_ready(const struct multi_context *m, - const struct multi_instance *mi) +multi_output_queue_ready(const struct multi_context *m, const struct multi= _instance *mi) { if (mi->tcp_link_out_deferred) { @@ -507,8 +508,7 @@ } static inline bool -multi_route_defined(const struct multi_context *m, - const struct multi_route *r) +multi_route_defined(const struct multi_context *m, const struct multi_rout= e *r) { if (r->instance->halt) { @@ -533,8 +533,7 @@ /* * Takes prefix away from multi_instance. */ -void -ungenerate_prefix(struct multi_instance *mi); +void ungenerate_prefix(struct multi_instance *mi); /* * Set a msg() function prefix with our current client instance ID. @@ -570,10 +569,10 @@ * don't want to reap in a single pass. */ -#define REAP_MAX_WAKEUP 10 /* Do reap pass at least once per n seconds = */ -#define REAP_DIVISOR 256 /* How many passes to cover whole hash table= */ -#define REAP_MIN 16 /* Minimum number of buckets per pass */ -#define REAP_MAX 1024 /* Maximum number of buckets per pass */ +#define REAP_MAX_WAKEUP 10 /* Do reap pass at least once per n seconds */ +#define REAP_DIVISOR 256 /* How many passes to cover whole hash table = */ +#define REAP_MIN 16 /* Minimum number of buckets per pass */ +#define REAP_MAX 1024 /* Maximum number of buckets per pass */ /* * Mark a cached host route for deletion after this @@ -618,7 +617,7 @@ struct timeval tv, current; CLEAR(tv); - m->earliest_wakeup =3D (struct multi_instance *) schedule_get_earliest= _wakeup(m->schedule, &tv); + m->earliest_wakeup =3D (struct multi_instance *)schedule_get_earliest_= wakeup(m->schedule, &tv); if (m->earliest_wakeup) { ASSERT(!openvpn_gettimeofday(¤t, NULL)); @@ -663,9 +662,7 @@ ASSERT(mi); #ifdef MULTI_DEBUG_EVENT_LOOP - printf("%s -> TUN len=3D%d\n", - id(mi), - mi->context.c2.to_tun.len); + printf("%s -> TUN len=3D%d\n", id(mi), mi->context.c2.to_tun.len); #endif set_prefix(mi); vlan_process_outgoing_tun(m, mi); @@ -675,12 +672,13 @@ return ret; } -#define CLIENT_CONNECT_OPT_MASK (OPT_P_INSTANCE | OPT_P_INHERIT \ - |OPT_P_PUSH | OPT_P_TIMER | OPT_P_CONFIG = \ - |OPT_P_ECHO | OPT_P_COMP | OPT_P_SOCKFLAG= S) +#define CLIENT_CONNECT_OPT_MASK = \ + (OPT_P_INSTANCE | OPT_P_INHERIT | OPT_P_PUSH | OPT_P_TIMER | OPT_P_CON= FIG | OPT_P_ECHO \ + | OPT_P_COMP | OPT_P_SOCKFLAGS) static inline bool -multi_process_outgoing_link_dowork(struct multi_context *m, struct multi_i= nstance *mi, const unsigned int mpp_flags) +multi_process_outgoing_link_dowork(struct multi_context *m, struct multi_i= nstance *mi, + const unsigned int mpp_flags) { bool ret =3D true; set_prefix(mi); diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c index 4854f4b..8cd7bba 100644 --- a/src/openvpn/multi_io.c +++ b/src/openvpn/multi_io.c @@ -40,12 +40,12 @@ /* * Special tags passed to event.[ch] functions */ -#define MULTI_IO_SOCKET ((void *)1) -#define MULTI_IO_TUN ((void *)2) -#define MULTI_IO_SIG ((void *)3) /* Only on Windows */ -#define MULTI_IO_MANAGEMENT ((void *)4) +#define MULTI_IO_SOCKET ((void *)1) +#define MULTI_IO_TUN ((void *)2) +#define MULTI_IO_SIG ((void *)3) /* Only on Windows */ +#define MULTI_IO_MANAGEMENT ((void *)4) #define MULTI_IO_FILE_CLOSE_WRITE ((void *)5) -#define MULTI_IO_DCO ((void *)6) +#define MULTI_IO_DCO ((void *)6) struct ta_iow_flags { @@ -128,7 +128,8 @@ wait_signal(multi_io->es, MULTI_IO_SIG); ALLOC_ARRAY(multi_io->esr, struct event_set_return, multi_io->maxevent= s); *maxclients =3D max_int(min_int(multi_io->maxevents - extra_events, *m= axclients), 1); - msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=3D%d maxevents=3D= %d", *maxclients, multi_io->maxevents); + msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=3D%d maxevents=3D= %d", *maxclients, + multi_io->maxevents); return multi_io; } @@ -143,18 +144,13 @@ mi->socket_set_called =3D true; if (proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto)) { - socket_set(mi->context.c2.link_sockets[0], - m->multi_io->es, - EVENT_READ, - &mi->context.c2.link_sockets[0]->ev_arg, - NULL); + socket_set(mi->context.c2.link_sockets[0], m->multi_io->es, EVENT_= READ, + &mi->context.c2.link_sockets[0]->ev_arg, NULL); } else { - socket_set(mi->context.c2.link_sockets[0], - m->multi_io->es, - mbuf_defined(mi->tcp_link_out_deferred) ? EVENT_WRITE := EVENT_READ, - &mi->ev_arg, + socket_set(mi->context.c2.link_sockets[0], m->multi_io->es, + mbuf_defined(mi->tcp_link_out_deferred) ? EVENT_WRITE := EVENT_READ, &mi->ev_arg, &mi->tcp_rwflags); } } @@ -199,7 +195,8 @@ #ifdef ENABLE_MANAGEMENT if (management) { - management_socket_set(management, m->multi_io->es, MULTI_IO_MANAGE= MENT, &m->multi_io->management_persist_flags); + management_socket_set(management, m->multi_io->es, MULTI_IO_MANAGE= MENT, + &m->multi_io->management_persist_flags); } #endif @@ -208,7 +205,8 @@ event_ctl(m->multi_io->es, m->top.c2.inotify_fd, EVENT_READ, MULTI_IO_= FILE_CLOSE_WRITE); #endif - status =3D event_wait(m->multi_io->es, &m->top.c2.timeval, m->multi_io= ->esr, m->multi_io->maxevents); + status =3D + event_wait(m->multi_io->es, &m->top.c2.timeval, m->multi_io->esr, = m->multi_io->maxevents); update_time(); m->multi_io->n_esr =3D 0; if (status > 0) @@ -219,13 +217,13 @@ } static int -multi_io_wait_lite(struct multi_context *m, struct multi_instance *mi, con= st int action, bool *tun_input_pending) +multi_io_wait_lite(struct multi_context *m, struct multi_instance *mi, con= st int action, + bool *tun_input_pending) { struct context *c =3D multi_get_context(m, mi); unsigned int looking_for =3D 0; - dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_wait_lite a=3D%s mi=3D" ptr_fo= rmat, - pract(action), + dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_wait_lite a=3D%s mi=3D" ptr_fo= rmat, pract(action), (ptr_type)mi); tv_clear(&c->c2.timeval); /* ZERO-TIMEOUT */ @@ -256,7 +254,7 @@ case TA_SOCKET_WRITE: looking_for =3D SOCKET_WRITE; - io_wait(c, IOW_TO_LINK|IOW_READ_TUN_FORCE); + io_wait(c, IOW_TO_LINK | IOW_READ_TUN_FORCE); break; default: @@ -292,12 +290,11 @@ static struct multi_instance * multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, cons= t int action) { - const unsigned int mpp_flags =3D MPP_PRE_SELECT|MPP_RECORD_TOUCH; + const unsigned int mpp_flags =3D MPP_PRE_SELECT | MPP_RECORD_TOUCH; struct multi_instance *touched =3D mi; m->mpp_touched =3D &touched; - dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_dispatch a=3D%s mi=3D" ptr_for= mat, - pract(action), + dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_dispatch a=3D%s mi=3D" ptr_for= mat, pract(action), (ptr_type)mi); switch (action) @@ -320,8 +317,7 @@ clear_prefix(); if (!IS_SIG(&mi->context)) { - multi_process_incoming_link(m, mi, mpp_flags, - mi->context.c2.link_sockets[0]= ); + multi_process_incoming_link(m, mi, mpp_flags, mi->context.= c2.link_sockets[0]); if (!IS_SIG(&mi->context)) { stream_buf_read_setup(mi->context.c2.link_sockets[0]); @@ -374,9 +370,9 @@ struct context *c =3D multi_get_context(m, mi); int newaction =3D TA_UNDEF; -#define MTP_NONE 0 -#define MTP_TUN_OUT (1<<0) -#define MTP_LINK_OUT (1<<1) +#define MTP_NONE 0 +#define MTP_TUN_OUT (1 << 0) +#define MTP_LINK_OUT (1 << 1) unsigned int flags =3D MTP_NONE; if (TUN_OUT(c)) @@ -390,7 +386,7 @@ switch (flags) { - case MTP_TUN_OUT|MTP_LINK_OUT: + case MTP_TUN_OUT | MTP_LINK_OUT: case MTP_TUN_OUT: newaction =3D TA_TUN_WRITE; break; @@ -414,16 +410,13 @@ { struct gc_arena gc =3D gc_new(); msg(M_FATAL, "MULTI IO: multi_io_post bad state, mi=3D%s flags= =3D%d", - multi_instance_string(mi, false, &gc), - flags); + multi_instance_string(mi, false, &gc), flags); gc_free(&gc); break; } } - dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_post %s -> %s", - pract(action), - pract(newaction)); + dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_post %s -> %s", pract(action),= pract(newaction)); return newaction; } @@ -502,48 +495,48 @@ } else #endif - /* incoming data on TUN? */ - if (e->arg =3D=3D MULTI_IO_TUN) - { - if (e->rwflags & EVENT_WRITE) + /* incoming data on TUN? */ + if (e->arg =3D=3D MULTI_IO_TUN) { - multi_io_action(m, NULL, TA_TUN_WRITE, false); + if (e->rwflags & EVENT_WRITE) + { + multi_io_action(m, NULL, TA_TUN_WRITE, false); + } + else if (e->rwflags & EVENT_READ) + { + multi_io_action(m, NULL, TA_TUN_READ, false); + } } - else if (e->rwflags & EVENT_READ) + /* new incoming TCP client attempting to connect? */ + else if (e->arg =3D=3D MULTI_IO_SOCKET) { - multi_io_action(m, NULL, TA_TUN_READ, false); + struct multi_instance *mi; + ASSERT(m->top.c2.link_sockets[0]); + socket_reset_listen_persistent(m->top.c2.link_sockets[= 0]); + mi =3D multi_create_instance_tcp(m, m->top.c2.link_soc= kets[0]); + if (mi) + { + multi_io_action(m, mi, TA_INITIAL, false); + } } - } - /* new incoming TCP client attempting to connect? */ - else if (e->arg =3D=3D MULTI_IO_SOCKET) - { - struct multi_instance *mi; - ASSERT(m->top.c2.link_sockets[0]); - socket_reset_listen_persistent(m->top.c2.link_sockets[0]); - mi =3D multi_create_instance_tcp(m, m->top.c2.link_sockets= [0]); - if (mi) - { - multi_io_action(m, mi, TA_INITIAL, false); - } - } #if defined(ENABLE_DCO) \ - && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || define= d(TARGET_WIN32)) - /* incoming data on DCO? */ - else if (e->arg =3D=3D MULTI_IO_DCO) - { - multi_process_incoming_dco(m); - } + && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(TARGET= _WIN32)) + /* incoming data on DCO? */ + else if (e->arg =3D=3D MULTI_IO_DCO) + { + multi_process_incoming_dco(m); + } #endif - /* signal received? */ - else if (e->arg =3D=3D MULTI_IO_SIG) - { - get_signal(&m->top.sig->signal_received); - } + /* signal received? */ + else if (e->arg =3D=3D MULTI_IO_SIG) + { + get_signal(&m->top.sig->signal_received); + } #ifdef ENABLE_ASYNC_PUSH - else if (e->arg =3D=3D MULTI_IO_FILE_CLOSE_WRITE) - { - multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECORD_T= OUCH); - } + else if (e->arg =3D=3D MULTI_IO_FILE_CLOSE_WRITE) + { + multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECO= RD_TOUCH); + } #endif } if (IS_SIG(&m->top)) @@ -572,9 +565,7 @@ do { - dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_action a=3D%s p=3D%d", - pract(action), - poll); + dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_action a=3D%s p=3D%d", pra= ct(action), poll); /* * If TA_SOCKET_READ_RESIDUAL, it means we still have pending @@ -593,7 +584,8 @@ action =3D multi_io_wait_lite(m, mi, action, &tun_input_pendin= g); if (action =3D=3D TA_UNDEF) { - msg(M_FATAL, "MULTI IO: I/O wait required blocking in mult= i_io_action, action=3D%d", orig_action); + msg(M_FATAL, "MULTI IO: I/O wait required blocking in mult= i_io_action, action=3D%d", + orig_action); } } diff --git a/src/openvpn/networking.h b/src/openvpn/networking.h index 0ba4963..93fa765 100644 --- a/src/openvpn/networking.h +++ b/src/openvpn/networking.h @@ -102,8 +102,8 @@ * * @return 0 on success, negative error code on error */ -int net_iface_new(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, - const char *type, void *arg); +int net_iface_new(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface= , const char *type, + void *arg); /** * Retrieve the interface type @@ -114,8 +114,7 @@ * * @return 0 on success, a negative error code otherwise */ -int net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, - char type[IFACE_TYPE_LEN_MAX]); +int net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, char type[IF= ACE_TYPE_LEN_MAX]); /** * Remove an interface @@ -135,8 +134,7 @@ * * @return 0 on success, a negative error code otherwise */ -int net_iface_up(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, - bool up); +int net_iface_up(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,= bool up); /** * Set the MTU for an interface @@ -147,8 +145,7 @@ * * @return 0 on success, a negative error code otherwise */ -int net_iface_mtu_set(openvpn_net_ctx_t *ctx, - const openvpn_net_iface_t *iface, uint32_t mtu); +int net_iface_mtu_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *i= face, uint32_t mtu); /** * Set the Link Layer (Ethernet) address of the TAP interface @@ -159,8 +156,7 @@ * * @return 0 on success, a negative error code otherwise */ -int net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *ifa= ce, - uint8_t *addr); +int net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *ifa= ce, uint8_t *addr); /** * Add an IPv4 address to an interface @@ -172,8 +168,8 @@ * * @return 0 on success, a negative error code otherwise */ -int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *ifa= ce, - const in_addr_t *addr, int prefixlen); +int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *ifa= ce, const in_addr_t *addr, + int prefixlen); /** * Add an IPv6 address to an interface @@ -198,8 +194,8 @@ * * @return 0 on success, a negative error code otherwise */ -int net_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *ifa= ce, - const in_addr_t *addr, int prefixlen); +int net_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *ifa= ce, const in_addr_t *addr, + int prefixlen); /** * Remove an IPv6 from an interface @@ -223,8 +219,7 @@ * * @return 0 on success, a negative error code otherwise */ -int net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, - const openvpn_net_iface_t *iface, +int net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t = *iface, const in_addr_t *local, const in_addr_t *remote); /** @@ -237,8 +232,7 @@ * * @return 0 on success, a negative error code otherwise */ -int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, - const openvpn_net_iface_t *iface, +int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t = *iface, const in_addr_t *local, const in_addr_t *remote); #endif /* ENABLE_SITNL || ENABLE_IPROUTE */ @@ -258,9 +252,8 @@ * * @return 0 on success, a negative error code otherwise */ -int net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, - int prefixlen, const in_addr_t *gw, - const openvpn_net_iface_t *iface, uint32_t table, +int net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int pre= fixlen, + const in_addr_t *gw, const openvpn_net_iface_t *iface= , uint32_t table, int metric); /** @@ -277,10 +270,9 @@ * * @return 0 on success, a negative error code otherwise */ -int net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, const struct in6_addr *gw, - const openvpn_net_iface_t *iface, - uint32_t table, int metric); +int net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, i= nt prefixlen, + const struct in6_addr *gw, const openvpn_net_iface_t = *iface, uint32_t table, + int metric); /** * Delete a route for an IPv4 address/network @@ -296,9 +288,8 @@ * * @return 0 on success, a negative error code otherwise */ -int net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, - int prefixlen, const in_addr_t *gw, - const openvpn_net_iface_t *iface, uint32_t table, +int net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int pre= fixlen, + const in_addr_t *gw, const openvpn_net_iface_t *iface= , uint32_t table, int metric); /** @@ -315,10 +306,9 @@ * * @return 0 on success, a negative error code otherwise */ -int net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, const struct in6_addr *gw, - const openvpn_net_iface_t *iface, - uint32_t table, int metric); +int net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, i= nt prefixlen, + const struct in6_addr *gw, const openvpn_net_iface_t = *iface, uint32_t table, + int metric); #endif /* ENABLE_SITNL || ENABLE_IPROUTE || TARGET_FREEBSD */ @@ -335,8 +325,8 @@ * * @return 0 on success, a negative error code otherwise */ -int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, - in_addr_t *best_gw, openvpn_net_iface_t *best_ifa= ce); +int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, in_= addr_t *best_gw, + openvpn_net_iface_t *best_iface); /** * Retrieve the gateway and outgoing interface for the specified IPv6 @@ -350,8 +340,7 @@ * @return 0 on success, a negative error code otherwise */ int net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *ds= t, - struct in6_addr *best_gw, - openvpn_net_iface_t *best_iface); + struct in6_addr *best_gw, openvpn_net_iface_t *be= st_iface); #endif /* ENABLE_SITNL || ENABLE_IPROUTE */ diff --git a/src/openvpn/networking_freebsd.c b/src/openvpn/networking_free= bsd.c index 1c94756..b47444c 100644 --- a/src/openvpn/networking_freebsd.c +++ b/src/openvpn/networking_freebsd.c @@ -9,9 +9,8 @@ #if defined(TARGET_FREEBSD) static int -net_route_v4(const char *op, const in_addr_t *dst, int prefixlen, - const in_addr_t *gw, const char *iface, uint32_t table, - int metric) +net_route_v4(const char *op, const in_addr_t *dst, int prefixlen, const in= _addr_t *gw, + const char *iface, uint32_t table, int metric) { char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN]; in_addr_t _dst, _gw; @@ -21,16 +20,12 @@ _dst =3D ntohl(*dst); _gw =3D ntohl(*gw); - argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", - ROUTE_PATH, op, - inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), - prefixlen, - inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), - table); + argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op, + inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen, + inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table); argv_msg(M_INFO, &argv); - status =3D openvpn_execve_check(&argv, NULL, 0, - "ERROR: FreeBSD route command failed"); + status =3D openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route = command failed"); argv_free(&argv); @@ -38,24 +33,19 @@ } static int -net_route_v6(const char *op, const struct in6_addr *dst, - int prefixlen, const struct in6_addr *gw, const char *iface, - uint32_t table, int metric) +net_route_v6(const char *op, const struct in6_addr *dst, int prefixlen, co= nst struct in6_addr *gw, + const char *iface, uint32_t table, int metric) { char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN]; struct argv argv =3D argv_new(); bool status; - argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", - ROUTE_PATH, op, - inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), - prefixlen, - inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), - table); + argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op, + inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen, + inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table); argv_msg(M_INFO, &argv); - status =3D openvpn_execve_check(&argv, NULL, 0, - "ERROR: FreeBSD route command failed"); + status =3D openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route = command failed"); argv_free(&argv); @@ -63,33 +53,29 @@ } int -net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, - const in_addr_t *gw, const char *iface, uint32_t table, - int metric) +net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, const in_addr_t *gw, + const char *iface, uint32_t table, int metric) { return net_route_v4("add", dst, prefixlen, gw, iface, table, metric); } int -net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, const struct in6_addr *gw, const char *ifa= ce, - uint32_t table, int metric) +net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int p= refixlen, + const struct in6_addr *gw, const char *iface, uint32_t ta= ble, int metric) { return net_route_v6("add", dst, prefixlen, gw, iface, table, metric); } int -net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, - const in_addr_t *gw, const char *iface, uint32_t table, - int metric) +net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, const in_addr_t *gw, + const char *iface, uint32_t table, int metric) { return net_route_v4("del", dst, prefixlen, gw, iface, table, metric); } int -net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, const struct in6_addr *gw, const char *ifa= ce, - uint32_t table, int metric) +net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int p= refixlen, + const struct in6_addr *gw, const char *iface, uint32_t ta= ble, int metric) { return net_route_v6("del", dst, prefixlen, gw, iface, table, metric); } diff --git a/src/openvpn/networking_iproute2.c b/src/openvpn/networking_ipr= oute2.c index 28b5bfc..aac245a 100644 --- a/src/openvpn/networking_iproute2.c +++ b/src/openvpn/networking_iproute2.c @@ -62,8 +62,7 @@ } int -net_iface_new(openvpn_net_ctx_t *ctx, const char *iface, const char *type, - void *arg) +net_iface_new(openvpn_net_ctx_t *ctx, const char *iface, const char *type,= void *arg) { struct argv argv =3D argv_new(); @@ -77,8 +76,7 @@ } int -net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, - char type[IFACE_TYPE_LEN_MAX]) +net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, char type[IFACE_= TYPE_LEN_MAX]) { /* not supported by iproute2 */ msg(M_WARN, "%s: operation not supported by iproute2 backend", __func_= _); @@ -103,8 +101,7 @@ { struct argv argv =3D argv_new(); - argv_printf(&argv, "%s link set dev %s %s", iproute_path, iface, - up ? "up" : "down"); + argv_printf(&argv, "%s link set dev %s %s", iproute_path, iface, up ? = "up" : "down"); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip link set faile= d"); @@ -118,8 +115,7 @@ { struct argv argv =3D argv_new(); - argv_printf(&argv, "%s link set dev %s up mtu %d", iproute_path, iface, - mtu); + argv_printf(&argv, "%s link set dev %s up mtu %d", iproute_path, iface= , mtu); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip link set faile= d"); @@ -129,19 +125,16 @@ } int -net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, - uint8_t *addr) +net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, = uint8_t *addr) { struct argv argv =3D argv_new(); int ret =3D 0; - argv_printf(&argv, - "%s link set addr " MAC_FMT " dev %s", - iproute_path, MAC_PRINT_ARG(addr), iface); + argv_printf(&argv, "%s link set addr " MAC_FMT " dev %s", iproute_path= , MAC_PRINT_ARG(addr), + iface); argv_msg(M_INFO, &argv); - if (!openvpn_execve_check(&argv, ctx->es, 0, - "Linux ip link set addr failed")) + if (!openvpn_execve_check(&argv, ctx->es, 0, "Linux ip link set addr f= ailed")) { ret =3D -1; } @@ -152,15 +145,13 @@ } int -net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface, - const in_addr_t *addr, int prefixlen) +net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t= *addr, int prefixlen) { struct argv argv =3D argv_new(); const char *addr_str =3D print_in_addr_t(*addr, 0, &ctx->gc); - argv_printf(&argv, "%s addr add dev %s %s/%d", iproute_path, iface, - addr_str, prefixlen); + argv_printf(&argv, "%s addr add dev %s %s/%d", iproute_path, iface, ad= dr_str, prefixlen); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip addr add faile= d"); @@ -170,17 +161,15 @@ } int -net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface, - const struct in6_addr *addr, int prefixlen) +net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface, const struct in= 6_addr *addr, + int prefixlen) { struct argv argv =3D argv_new(); char *addr_str =3D (char *)print_in6_addr(*addr, 0, &ctx->gc); - argv_printf(&argv, "%s -6 addr add %s/%d dev %s", iproute_path, addr_s= tr, - prefixlen, iface); + argv_printf(&argv, "%s -6 addr add %s/%d dev %s", iproute_path, addr_s= tr, prefixlen, iface); argv_msg(M_INFO, &argv); - openvpn_execve_check(&argv, ctx->es, S_FATAL, - "Linux ip -6 addr add failed"); + openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip -6 addr add fa= iled"); argv_free(&argv); @@ -188,14 +177,12 @@ } int -net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *iface, - const in_addr_t *addr, int prefixlen) +net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t= *addr, int prefixlen) { struct argv argv =3D argv_new(); const char *addr_str =3D print_in_addr_t(*addr, 0, &ctx->gc); - argv_printf(&argv, "%s addr del dev %s %s/%d", iproute_path, iface, - addr_str, prefixlen); + argv_printf(&argv, "%s addr del dev %s %s/%d", iproute_path, iface, ad= dr_str, prefixlen); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, 0, "Linux ip addr del failed"); @@ -206,14 +193,13 @@ } int -net_addr_v6_del(openvpn_net_ctx_t *ctx, const char *iface, - const struct in6_addr *addr, int prefixlen) +net_addr_v6_del(openvpn_net_ctx_t *ctx, const char *iface, const struct in= 6_addr *addr, + int prefixlen) { struct argv argv =3D argv_new(); char *addr_str =3D (char *)print_in6_addr(*addr, 0, &ctx->gc); - argv_printf(&argv, "%s -6 addr del %s/%d dev %s", iproute_path, - addr_str, prefixlen, iface); + argv_printf(&argv, "%s -6 addr del %s/%d dev %s", iproute_path, addr_s= tr, prefixlen, iface); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, 0, "Linux ip -6 addr del failed"); @@ -223,15 +209,15 @@ } int -net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char *iface, - const in_addr_t *local, const in_addr_t *remote) +net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_ad= dr_t *local, + const in_addr_t *remote) { struct argv argv =3D argv_new(); const char *local_str =3D print_in_addr_t(*local, 0, &ctx->gc); const char *remote_str =3D print_in_addr_t(*remote, 0, &ctx->gc); - argv_printf(&argv, "%s addr add dev %s local %s peer %s", iproute_path, - iface, local_str, remote_str); + argv_printf(&argv, "%s addr add dev %s local %s peer %s", iproute_path= , iface, local_str, + remote_str); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip addr add faile= d"); @@ -241,15 +227,15 @@ } int -net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const char *iface, - const in_addr_t *local, const in_addr_t *remote) +net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_ad= dr_t *local, + const in_addr_t *remote) { struct argv argv =3D argv_new(); const char *local_str =3D print_in_addr_t(*local, 0, &ctx->gc); const char *remote_str =3D print_in_addr_t(*remote, 0, &ctx->gc); - argv_printf(&argv, "%s addr del dev %s local %s peer %s", iproute_path, - iface, local_str, remote_str); + argv_printf(&argv, "%s addr del dev %s local %s peer %s", iproute_path= , iface, local_str, + remote_str); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, 0, "Linux ip addr del failed"); @@ -259,9 +245,8 @@ } int -net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, - const in_addr_t *gw, const char *iface, uint32_t table, - int metric) +net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, const in_addr_t *gw, + const char *iface, uint32_t table, int metric) { struct argv argv =3D argv_new(); const char *dst_str =3D print_in_addr_t(*dst, 0, &ctx->gc); @@ -298,16 +283,14 @@ } int -net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, const struct in6_addr *gw, const char *ifa= ce, - uint32_t table, int metric) +net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int p= refixlen, + const struct in6_addr *gw, const char *iface, uint32_t ta= ble, int metric) { struct argv argv =3D argv_new(); char *dst_str =3D (char *)print_in6_addr(*dst, 0, &ctx->gc); int ret =3D 0; - argv_printf(&argv, "%s -6 route add %s/%d dev %s", iproute_path, dst_s= tr, - prefixlen, iface); + argv_printf(&argv, "%s -6 route add %s/%d dev %s", iproute_path, dst_s= tr, prefixlen, iface); if (gw) { @@ -333,9 +316,8 @@ } int -net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, - const in_addr_t *gw, const char *iface, uint32_t table, - int metric) +net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, const in_addr_t *gw, + const char *iface, uint32_t table, int metric) { struct argv argv =3D argv_new(); const char *dst_str =3D print_in_addr_t(*dst, 0, &ctx->gc); @@ -360,16 +342,14 @@ } int -net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, const struct in6_addr *gw, const char *ifa= ce, - uint32_t table, int metric) +net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int p= refixlen, + const struct in6_addr *gw, const char *iface, uint32_t ta= ble, int metric) { struct argv argv =3D argv_new(); char *dst_str =3D (char *)print_in6_addr(*dst, 0, &ctx->gc); int ret =3D 0; - argv_printf(&argv, "%s -6 route del %s/%d dev %s", iproute_path, dst_s= tr, - prefixlen, iface); + argv_printf(&argv, "%s -6 route del %s/%d dev %s", iproute_path, dst_s= tr, prefixlen, iface); if (gw) { diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index 79aba8d..5b78971 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -44,12 +44,12 @@ #define SNDBUF_SIZE (1024 * 2) #define RCVBUF_SIZE (1024 * 4) -#define SITNL_ADDATTR(_msg, _max_size, _attr, _data, _size) \ - { \ +#define SITNL_ADDATTR(_msg, _max_size, _attr, _data, _size) \ + { \ if (sitnl_addattr(_msg, _max_size, _attr, _data, _size) < 0) \ - { \ - goto err; \ - } \ + { \ + goto err; \ + } \ } #define SITNL_NEST(_msg, _max_size, _attr) \ @@ -59,8 +59,8 @@ _nest; \ }) -#define SITNL_NEST_END(_msg, _nest) \ - { \ +#define SITNL_NEST_END(_msg, _nest) \ + { \ _nest->rta_len =3D (void *)sitnl_nlmsg_tail(_msg) - (void *)_nest;= \ } @@ -74,7 +74,7 @@ * The only way out to avoid any warning/error is to force the function to * not be inline'd. */ -static __attribute__ ((noinline)) void * +static __attribute__((noinline)) void * sitnl_nlmsg_tail(const struct nlmsghdr *nlh) { return (unsigned char *)nlh + NLMSG_ALIGN(nlh->nlmsg_len); @@ -84,7 +84,8 @@ * Generic address data structure used to pass addresses and prefixes as * argument to AF family agnostic functions */ -typedef union { +typedef union +{ in_addr_t ipv4; struct in6_addr ipv6; } inet_address_t; @@ -92,7 +93,8 @@ /** * Link state request message */ -struct sitnl_link_req { +struct sitnl_link_req +{ struct nlmsghdr n; struct ifinfomsg i; char buf[256]; @@ -101,7 +103,8 @@ /** * Address request message */ -struct sitnl_addr_req { +struct sitnl_addr_req +{ struct nlmsghdr n; struct ifaddrmsg i; char buf[256]; @@ -110,7 +113,8 @@ /** * Route request message */ -struct sitnl_route_req { +struct sitnl_route_req +{ struct nlmsghdr n; struct rtmsg r; char buf[256]; @@ -121,7 +125,8 @@ /** * Object returned by route request operation */ -struct sitnl_route_data_cb { +struct sitnl_route_data_cb +{ unsigned int iface; inet_address_t gw; }; @@ -130,16 +135,14 @@ * Helper function used to easily add attributes to a rtnl message */ static int -sitnl_addattr(struct nlmsghdr *n, int maxlen, int type, const void *data, - int alen) +sitnl_addattr(struct nlmsghdr *n, int maxlen, int type, const void *data, = int alen) { int len =3D RTA_LENGTH(alen); struct rtattr *rta; if ((int)(NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len)) > maxlen) { - msg(M_WARN, "%s: rtnl: message exceeded bound of %d", __func__, - maxlen); + msg(M_WARN, "%s: rtnl: message exceeded bound of %d", __func__, ma= xlen); return -EMSGSIZE; } @@ -241,8 +244,8 @@ * Send Netlink message and run callback on reply (if specified) */ static int -sitnl_send(struct nlmsghdr *payload, pid_t peer, unsigned int groups, - sitnl_parse_reply_cb cb, void *arg_cb) +sitnl_send(struct nlmsghdr *payload, pid_t peer, unsigned int groups, sitn= l_parse_reply_cb cb, + void *arg_cb) { int len, rem_len, fd, ret, rcv_len; struct sockaddr_nl nladdr; @@ -250,13 +253,11 @@ struct nlmsghdr *h; unsigned int seq; char buf[1024 * 16]; - struct iovec iov =3D - { + struct iovec iov =3D { .iov_base =3D payload, .iov_len =3D payload->nlmsg_len, }; - struct msghdr nlmsg =3D - { + struct msghdr nlmsg =3D { .msg_name =3D &nladdr, .msg_namelen =3D sizeof(nladdr), .msg_iov =3D &iov, @@ -335,8 +336,8 @@ if (nlmsg.msg_namelen !=3D sizeof(nladdr)) { - msg(M_WARN, "%s: sender address length: %u (expected %zu)", - __func__, nlmsg.msg_namelen, sizeof(nladdr)); + msg(M_WARN, "%s: sender address length: %u (expected %zu)", __= func__, nlmsg.msg_namelen, + sizeof(nladdr)); ret =3D -EIO; goto out; } @@ -360,17 +361,18 @@ goto out; } -/* if (((int)nladdr.nl_pid !=3D peer) || (h->nlmsg_pid !=3D nla= ddr.nl_pid) - * || (h->nlmsg_seq !=3D seq)) - * { - * rcv_len -=3D NLMSG_ALIGN(len); - * h =3D (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); - * msg(M_DEBUG, "%s: skipping unrelated message. nl_pid:%d (= peer:%d) nl_msg_pid:%d nl_seq:%d seq:%d", - * __func__, (int)nladdr.nl_pid, peer, h->nlmsg_pid, - * h->nlmsg_seq, seq); - * continue; - * } - */ + /* if (((int)nladdr.nl_pid !=3D peer) || (h->nlmsg_= pid !=3D nladdr.nl_pid) + * || (h->nlmsg_seq !=3D seq)) + * { + * rcv_len -=3D NLMSG_ALIGN(len); + * h =3D (struct nlmsghdr *)((char *)h + NLMSG_A= LIGN(len)); + * msg(M_DEBUG, "%s: skipping unrelated message.= nl_pid:%d (peer:%d) + * nl_msg_pid:%d nl_seq:%d seq:%d", + * __func__, (int)nladdr.nl_pid, peer, h->nl= msg_pid, + * h->nlmsg_seq, seq); + * continue; + * } + */ if (h->nlmsg_type =3D=3D NLMSG_DONE) { @@ -402,8 +404,8 @@ } else { - msg(M_WARN, "%s: rtnl: generic error (%d): %s", - __func__, err->error, strerror(-err->error)); + msg(M_WARN, "%s: rtnl: generic error (%d): %s", __= func__, err->error, + strerror(-err->error)); ret =3D err->error; } } @@ -447,7 +449,8 @@ return ret; } -typedef struct { +typedef struct +{ int addr_size; inet_address_t gw; char iface[IFNAMSIZ]; @@ -509,8 +512,7 @@ if (!if_indextoname(ifindex, res->iface)) { - msg(M_WARN | M_ERRNO, "%s: rtnl: can't get ifname for index %d", - __func__, ifindex); + msg(M_WARN | M_ERRNO, "%s: rtnl: can't get ifname for index %d", _= _func__, ifindex); return -1; } @@ -523,8 +525,8 @@ } static int -sitnl_route_best_gw(sa_family_t af_family, const inet_address_t *dst, - void *best_gw, char *best_iface) +sitnl_route_best_gw(sa_family_t af_family, const inet_address_t *dst, void= *best_gw, + char *best_iface) { struct sitnl_route_req req; route_res_t res; @@ -586,15 +588,14 @@ strncpy(best_iface, res.iface, IFNAMSIZ); err: return ret; - } /* used by iproute2 implementation too */ int -net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - struct in6_addr *best_gw, char *best_iface) +net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, s= truct in6_addr *best_gw, + char *best_iface) { - inet_address_t dst_v6 =3D {0}; + inet_address_t dst_v6 =3D { 0 }; char buf[INET6_ADDRSTRLEN]; int ret; @@ -603,8 +604,7 @@ dst_v6.ipv6 =3D *dst; } - msg(D_ROUTE, "%s query: dst %s", __func__, - inet_ntop(AF_INET6, &dst_v6.ipv6, buf, sizeof(buf))); + msg(D_ROUTE, "%s query: dst %s", __func__, inet_ntop(AF_INET6, &dst_v6= .ipv6, buf, sizeof(buf))); ret =3D sitnl_route_best_gw(AF_INET6, &dst_v6, best_gw, best_iface); if (ret < 0) @@ -616,15 +616,14 @@ inet_ntop(AF_INET6, best_gw, buf, sizeof(buf)), best_iface); return ret; - } /* used by iproute2 implementation too */ int -net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, - in_addr_t *best_gw, char *best_iface) +net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, in_addr= _t *best_gw, + char *best_iface) { - inet_address_t dst_v4 =3D {0}; + inet_address_t dst_v4 =3D { 0 }; char buf[INET_ADDRSTRLEN]; int ret; @@ -633,8 +632,7 @@ dst_v4.ipv4 =3D htonl(*dst); } - msg(D_ROUTE, "%s query: dst %s", __func__, - inet_ntop(AF_INET, &dst_v4.ipv4, buf, sizeof(buf))); + msg(D_ROUTE, "%s query: dst %s", __func__, inet_ntop(AF_INET, &dst_v4.= ipv4, buf, sizeof(buf))); ret =3D sitnl_route_best_gw(AF_INET, &dst_v4, best_gw, best_iface); if (ret < 0) @@ -670,8 +668,7 @@ ifindex =3D if_nametoindex(iface); if (ifindex =3D=3D 0) { - msg(M_WARN, "%s: rtnl: cannot get ifindex for %s: %s", __func__, i= face, - strerror(errno)); + msg(M_WARN, "%s: rtnl: cannot get ifindex for %s: %s", __func__, i= face, strerror(errno)); return -ENOENT; } @@ -697,8 +694,7 @@ } int -net_iface_mtu_set(openvpn_net_ctx_t *ctx, const char *iface, - uint32_t mtu) +net_iface_mtu_set(openvpn_net_ctx_t *ctx, const char *iface, uint32_t mtu) { struct sitnl_link_req req; int ifindex, ret =3D -1; @@ -708,8 +704,7 @@ ifindex =3D if_nametoindex(iface); if (ifindex =3D=3D 0) { - msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __fun= c__, - iface); + msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __fun= c__, iface); return -1; } @@ -730,8 +725,7 @@ } int -net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, - uint8_t *addr) +net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, = uint8_t *addr) { struct sitnl_link_req req; int ifindex, ret =3D -1; @@ -741,8 +735,7 @@ ifindex =3D if_nametoindex(iface); if (ifindex =3D=3D 0) { - msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __fun= c__, - iface); + msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __fun= c__, iface); return -1; } @@ -755,8 +748,7 @@ SITNL_ADDATTR(&req.n, sizeof(req), IFLA_ADDRESS, addr, OPENVPN_ETH_ALE= N); - msg(M_INFO, "%s: lladdr " MAC_FMT " for %s", __func__, MAC_PRINT_ARG(a= ddr), - iface); + msg(M_INFO, "%s: lladdr " MAC_FMT " for %s", __func__, MAC_PRINT_ARG(a= ddr), iface); ret =3D sitnl_send(&req.n, 0, 0, NULL, NULL); err: @@ -765,8 +757,7 @@ static int sitnl_addr_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family, - const inet_address_t *local, const inet_address_t *remote, - int prefixlen) + const inet_address_t *local, const inet_address_t *remote, = int prefixlen) { struct sitnl_addr_req req; uint32_t size; @@ -792,8 +783,7 @@ break; default: - msg(M_WARN, "%s: rtnl: unknown address family %d", __func__, - af_family); + msg(M_WARN, "%s: rtnl: unknown address family %d", __func__, a= f_family); return -EINVAL; } @@ -824,8 +814,7 @@ } static int -sitnl_addr_ptp_add(sa_family_t af_family, const char *iface, - const inet_address_t *local, +sitnl_addr_ptp_add(sa_family_t af_family, const char *iface, const inet_ad= dress_t *local, const inet_address_t *remote) { int ifindex; @@ -849,18 +838,16 @@ ifindex =3D if_nametoindex(iface); if (ifindex =3D=3D 0) { - msg(M_WARN, "%s: cannot get ifindex for %s: %s", __func__, np(ifac= e), - strerror(errno)); + msg(M_WARN, "%s: cannot get ifindex for %s: %s", __func__, np(ifac= e), strerror(errno)); return -ENOENT; } - return sitnl_addr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifind= ex, - af_family, local, remote, 0); + return sitnl_addr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifind= ex, af_family, local, + remote, 0); } static int -sitnl_addr_ptp_del(sa_family_t af_family, const char *iface, - const inet_address_t *local) +sitnl_addr_ptp_del(sa_family_t af_family, const char *iface, const inet_ad= dress_t *local) { int ifindex; @@ -891,9 +878,8 @@ } static int -sitnl_route_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_famil= y, - const void *dst, int prefixlen, - const void *gw, enum rt_class_t table, int metric, +sitnl_route_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_famil= y, const void *dst, + int prefixlen, const void *gw, enum rt_class_t table, int = metric, enum rt_scope_t scope, int protocol, int type) { struct sitnl_route_req req; @@ -961,8 +947,7 @@ } static int -sitnl_addr_add(sa_family_t af_family, const char *iface, - const inet_address_t *addr, int prefixlen) +sitnl_addr_add(sa_family_t af_family, const char *iface, const inet_addres= s_t *addr, int prefixlen) { int ifindex; @@ -985,52 +970,47 @@ ifindex =3D if_nametoindex(iface); if (ifindex =3D=3D 0) { - msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __fun= c__, - iface); + msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __fun= c__, iface); return -ENOENT; } - return sitnl_addr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifind= ex, - af_family, addr, NULL, prefixlen); -} - -static int -sitnl_addr_del(sa_family_t af_family, const char *iface, inet_address_t *a= ddr, - int prefixlen) -{ - int ifindex; - - switch (af_family) - { - case AF_INET: - case AF_INET6: - break; - - default: - return -EINVAL; - } - - if (!iface) - { - msg(M_WARN, "%s: passed NULL interface", __func__); - return -EINVAL; - } - - ifindex =3D if_nametoindex(iface); - if (ifindex =3D=3D 0) - { - msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __fun= c__, - iface); - return -ENOENT; - } - - return sitnl_addr_set(RTM_DELADDR, 0, ifindex, af_family, addr, NULL, + return sitnl_addr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifind= ex, af_family, addr, NULL, prefixlen); } +static int +sitnl_addr_del(sa_family_t af_family, const char *iface, inet_address_t *a= ddr, int prefixlen) +{ + int ifindex; + + switch (af_family) + { + case AF_INET: + case AF_INET6: + break; + + default: + return -EINVAL; + } + + if (!iface) + { + msg(M_WARN, "%s: passed NULL interface", __func__); + return -EINVAL; + } + + ifindex =3D if_nametoindex(iface); + if (ifindex =3D=3D 0) + { + msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __fun= c__, iface); + return -ENOENT; + } + + return sitnl_addr_set(RTM_DELADDR, 0, ifindex, af_family, addr, NULL, = prefixlen); +} + int -net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface, - const in_addr_t *addr, int prefixlen) +net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t= *addr, int prefixlen) { inet_address_t addr_v4 =3D { 0 }; char buf[INET_ADDRSTRLEN]; @@ -1042,15 +1022,15 @@ addr_v4.ipv4 =3D htonl(*addr); - msg(M_INFO, "%s: %s/%d dev %s", __func__, - inet_ntop(AF_INET, &addr_v4.ipv4, buf, sizeof(buf)), prefixlen, if= ace); + msg(M_INFO, "%s: %s/%d dev %s", __func__, inet_ntop(AF_INET, &addr_v4.= ipv4, buf, sizeof(buf)), + prefixlen, iface); return sitnl_addr_add(AF_INET, iface, &addr_v4, prefixlen); } int -net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface, - const struct in6_addr *addr, int prefixlen) +net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface, const struct in= 6_addr *addr, + int prefixlen) { inet_address_t addr_v6 =3D { 0 }; char buf[INET6_ADDRSTRLEN]; @@ -1062,15 +1042,14 @@ addr_v6.ipv6 =3D *addr; - msg(M_INFO, "%s: %s/%d dev %s", __func__, - inet_ntop(AF_INET6, &addr_v6.ipv6, buf, sizeof(buf)), prefixlen, i= face); + msg(M_INFO, "%s: %s/%d dev %s", __func__, inet_ntop(AF_INET6, &addr_v6= .ipv6, buf, sizeof(buf)), + prefixlen, iface); return sitnl_addr_add(AF_INET6, iface, &addr_v6, prefixlen); } int -net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *iface, - const in_addr_t *addr, int prefixlen) +net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t= *addr, int prefixlen) { inet_address_t addr_v4 =3D { 0 }; char buf[INET_ADDRSTRLEN]; @@ -1082,15 +1061,15 @@ addr_v4.ipv4 =3D htonl(*addr); - msg(M_INFO, "%s: %s dev %s", __func__, - inet_ntop(AF_INET, &addr_v4.ipv4, buf, sizeof(buf)), iface); + msg(M_INFO, "%s: %s dev %s", __func__, inet_ntop(AF_INET, &addr_v4.ipv= 4, buf, sizeof(buf)), + iface); return sitnl_addr_del(AF_INET, iface, &addr_v4, prefixlen); } int -net_addr_v6_del(openvpn_net_ctx_t *ctx, const char *iface, - const struct in6_addr *addr, int prefixlen) +net_addr_v6_del(openvpn_net_ctx_t *ctx, const char *iface, const struct in= 6_addr *addr, + int prefixlen) { inet_address_t addr_v6 =3D { 0 }; char buf[INET6_ADDRSTRLEN]; @@ -1102,15 +1081,15 @@ addr_v6.ipv6 =3D *addr; - msg(M_INFO, "%s: %s/%d dev %s", __func__, - inet_ntop(AF_INET6, &addr_v6.ipv6, buf, sizeof(buf)), prefixlen, i= face); + msg(M_INFO, "%s: %s/%d dev %s", __func__, inet_ntop(AF_INET6, &addr_v6= .ipv6, buf, sizeof(buf)), + prefixlen, iface); return sitnl_addr_del(AF_INET6, iface, &addr_v6, prefixlen); } int -net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char *iface, - const in_addr_t *local, const in_addr_t *remote) +net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_ad= dr_t *local, + const in_addr_t *remote) { inet_address_t local_v4 =3D { 0 }; inet_address_t remote_v4 =3D { 0 }; @@ -1137,8 +1116,8 @@ } int -net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const char *iface, - const in_addr_t *local, const in_addr_t *remote) +net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_ad= dr_t *local, + const in_addr_t *remote) { inet_address_t local_v4 =3D { 0 }; char buf[INET6_ADDRSTRLEN]; @@ -1151,15 +1130,15 @@ local_v4.ipv4 =3D htonl(*local); - msg(M_INFO, "%s: %s dev %s", __func__, - inet_ntop(AF_INET, &local_v4.ipv4, buf, sizeof(buf)), iface); + msg(M_INFO, "%s: %s dev %s", __func__, inet_ntop(AF_INET, &local_v4.ip= v4, buf, sizeof(buf)), + iface); return sitnl_addr_ptp_del(AF_INET, iface, &local_v4); } static int -sitnl_route_add(const char *iface, sa_family_t af_family, const void *dst, - int prefixlen, const void *gw, uint32_t table, int metric) +sitnl_route_add(const char *iface, sa_family_t af_family, const void *dst,= int prefixlen, + const void *gw, uint32_t table, int metric) { enum rt_scope_t scope =3D RT_SCOPE_UNIVERSE; int ifindex =3D 0; @@ -1169,8 +1148,7 @@ ifindex =3D if_nametoindex(iface); if (ifindex =3D=3D 0) { - msg(M_WARN | M_ERRNO, "%s: rtnl: can't get ifindex for %s", - __func__, iface); + msg(M_WARN | M_ERRNO, "%s: rtnl: can't get ifindex for %s", __= func__, iface); return -ENOENT; } } @@ -1185,15 +1163,13 @@ scope =3D RT_SCOPE_LINK; } - return sitnl_route_set(RTM_NEWROUTE, NLM_F_CREATE, ifindex, - af_family, dst, prefixlen, gw, table, metric, s= cope, - RTPROT_BOOT, RTN_UNICAST); + return sitnl_route_set(RTM_NEWROUTE, NLM_F_CREATE, ifindex, af_family,= dst, prefixlen, gw, + table, metric, scope, RTPROT_BOOT, RTN_UNICAST); } int -net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, - const in_addr_t *gw, const char *iface, - uint32_t table, int metric) +net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, const in_addr_t *gw, + const char *iface, uint32_t table, int metric) { in_addr_t *dst_ptr =3D NULL, *gw_ptr =3D NULL; in_addr_t dst_be =3D 0, gw_be =3D 0; @@ -1213,18 +1189,15 @@ } msg(D_ROUTE, "%s: %s/%d via %s dev %s table %d metric %d", __func__, - inet_ntop(AF_INET, &dst_be, dst_str, sizeof(dst_str)), - prefixlen, inet_ntop(AF_INET, &gw_be, gw_str, sizeof(gw_str)), - np(iface), table, metric); + inet_ntop(AF_INET, &dst_be, dst_str, sizeof(dst_str)), prefixlen, + inet_ntop(AF_INET, &gw_be, gw_str, sizeof(gw_str)), np(iface), tab= le, metric); - return sitnl_route_add(iface, AF_INET, dst_ptr, prefixlen, gw_ptr, tab= le, - metric); + return sitnl_route_add(iface, AF_INET, dst_ptr, prefixlen, gw_ptr, tab= le, metric); } int -net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, const struct in6_addr *gw, - const char *iface, uint32_t table, int metric) +net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int p= refixlen, + const struct in6_addr *gw, const char *iface, uint32_t ta= ble, int metric) { inet_address_t dst_v6 =3D { 0 }; inet_address_t gw_v6 =3D { 0 }; @@ -1242,18 +1215,15 @@ } msg(D_ROUTE, "%s: %s/%d via %s dev %s table %d metric %d", __func__, - inet_ntop(AF_INET6, &dst_v6.ipv6, dst_str, sizeof(dst_str)), - prefixlen, inet_ntop(AF_INET6, &gw_v6.ipv6, gw_str, sizeof(gw_str)= ), - np(iface), table, metric); + inet_ntop(AF_INET6, &dst_v6.ipv6, dst_str, sizeof(dst_str)), prefi= xlen, + inet_ntop(AF_INET6, &gw_v6.ipv6, gw_str, sizeof(gw_str)), np(iface= ), table, metric); - return sitnl_route_add(iface, AF_INET6, dst, prefixlen, gw, table, - metric); + return sitnl_route_add(iface, AF_INET6, dst, prefixlen, gw, table, met= ric); } static int -sitnl_route_del(const char *iface, sa_family_t af_family, inet_address_t *= dst, - int prefixlen, inet_address_t *gw, uint32_t table, - int metric) +sitnl_route_del(const char *iface, sa_family_t af_family, inet_address_t *= dst, int prefixlen, + inet_address_t *gw, uint32_t table, int metric) { int ifindex =3D 0; @@ -1262,8 +1232,7 @@ ifindex =3D if_nametoindex(iface); if (ifindex =3D=3D 0) { - msg(M_WARN | M_ERRNO, "%s: rtnl: can't get ifindex for %s", - __func__, iface); + msg(M_WARN | M_ERRNO, "%s: rtnl: can't get ifindex for %s", __= func__, iface); return -ENOENT; } } @@ -1273,14 +1242,13 @@ table =3D RT_TABLE_MAIN; } - return sitnl_route_set(RTM_DELROUTE, 0, ifindex, af_family, dst, prefi= xlen, - gw, table, metric, RT_SCOPE_NOWHERE, 0, 0); + return sitnl_route_set(RTM_DELROUTE, 0, ifindex, af_family, dst, prefi= xlen, gw, table, metric, + RT_SCOPE_NOWHERE, 0, 0); } int -net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, - const in_addr_t *gw, const char *iface, uint32_t table, - int metric) +net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en, const in_addr_t *gw, + const char *iface, uint32_t table, int metric) { inet_address_t dst_v4 =3D { 0 }; inet_address_t gw_v4 =3D { 0 }; @@ -1298,18 +1266,15 @@ } msg(D_ROUTE, "%s: %s/%d via %s dev %s table %d metric %d", __func__, - inet_ntop(AF_INET, &dst_v4.ipv4, dst_str, sizeof(dst_str)), - prefixlen, inet_ntop(AF_INET, &gw_v4.ipv4, gw_str, sizeof(gw_str)), - np(iface), table, metric); + inet_ntop(AF_INET, &dst_v4.ipv4, dst_str, sizeof(dst_str)), prefix= len, + inet_ntop(AF_INET, &gw_v4.ipv4, gw_str, sizeof(gw_str)), np(iface)= , table, metric); - return sitnl_route_del(iface, AF_INET, &dst_v4, prefixlen, &gw_v4, tab= le, - metric); + return sitnl_route_del(iface, AF_INET, &dst_v4, prefixlen, &gw_v4, tab= le, metric); } int -net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, const struct in6_addr *gw, - const char *iface, uint32_t table, int metric) +net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int p= refixlen, + const struct in6_addr *gw, const char *iface, uint32_t ta= ble, int metric) { inet_address_t dst_v6 =3D { 0 }; inet_address_t gw_v6 =3D { 0 }; @@ -1327,20 +1292,17 @@ } msg(D_ROUTE, "%s: %s/%d via %s dev %s table %d metric %d", __func__, - inet_ntop(AF_INET6, &dst_v6.ipv6, dst_str, sizeof(dst_str)), - prefixlen, inet_ntop(AF_INET6, &gw_v6.ipv6, gw_str, sizeof(gw_str)= ), - np(iface), table, metric); + inet_ntop(AF_INET6, &dst_v6.ipv6, dst_str, sizeof(dst_str)), prefi= xlen, + inet_ntop(AF_INET6, &gw_v6.ipv6, gw_str, sizeof(gw_str)), np(iface= ), table, metric); - return sitnl_route_del(iface, AF_INET6, &dst_v6, prefixlen, &gw_v6, - table, metric); + return sitnl_route_del(iface, AF_INET6, &dst_v6, prefixlen, &gw_v6, ta= ble, metric); } int -net_iface_new(openvpn_net_ctx_t *ctx, const char *iface, const char *type, - void *arg) +net_iface_new(openvpn_net_ctx_t *ctx, const char *iface, const char *type,= void *arg) { - struct sitnl_link_req req =3D { }; + struct sitnl_link_req req =3D {}; int ret =3D -1; ASSERT(iface); @@ -1358,8 +1320,7 @@ { dco_context_t *dco =3D arg; struct rtattr *data =3D SITNL_NEST(&req.n, sizeof(req), IFLA_INFO_= DATA); - SITNL_ADDATTR(&req.n, sizeof(req), IFLA_OVPN_MODE, &dco->ifmode, - sizeof(uint8_t)); + SITNL_ADDATTR(&req.n, sizeof(req), IFLA_OVPN_MODE, &dco->ifmode, s= izeof(uint8_t)); SITNL_NEST_END(&req.n, data); } #endif @@ -1367,7 +1328,7 @@ req.i.ifi_family =3D AF_PACKET; - msg(D_ROUTE, "%s: add %s type %s", __func__, iface, type); + msg(D_ROUTE, "%s: add %s type %s", __func__, iface, type); ret =3D sitnl_send(&req.n, 0, 0, NULL, NULL); err: @@ -1375,8 +1336,8 @@ } static int -sitnl_parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta, - int len, unsigned short flags) +sitnl_parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta,= int len, + unsigned short flags) { unsigned short type; @@ -1396,8 +1357,7 @@ if (len) { - msg(D_ROUTE, "%s: %d bytes not parsed! (rta_len=3D%d)", __func__, = len, - rta->rta_len); + msg(D_ROUTE, "%s: %d bytes not parsed! (rta_len=3D%d)", __func__, = len, rta->rta_len); } return 0; @@ -1410,8 +1370,7 @@ } #define sitnl_parse_rtattr_nested(tb, max, rta) \ - (sitnl_parse_rtattr_flags(tb, max, RTA_DATA(rta), RTA_PAYLOAD(rta), \ - NLA_F_NESTED)) + (sitnl_parse_rtattr_flags(tb, max, RTA_DATA(rta), RTA_PAYLOAD(rta), NL= A_F_NESTED)) static int sitnl_type_save(struct nlmsghdr *n, void *arg) @@ -1431,8 +1390,7 @@ { struct rtattr *tb_link[IFLA_INFO_MAX + 1]; - ret =3D sitnl_parse_rtattr_nested(tb_link, IFLA_INFO_MAX, - tb[IFLA_LINKINFO]); + ret =3D sitnl_parse_rtattr_nested(tb_link, IFLA_INFO_MAX, tb[IFLA_= LINKINFO]); if (ret < 0) { return ret; @@ -1450,10 +1408,9 @@ } int -net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, - char type[IFACE_TYPE_LEN_MAX]) +net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, char type[IFACE_= TYPE_LEN_MAX]) { - struct sitnl_link_req req =3D { }; + struct sitnl_link_req req =3D {}; int ifindex =3D if_nametoindex(iface); if (!ifindex) @@ -1473,8 +1430,7 @@ int ret =3D sitnl_send(&req.n, 0, 0, sitnl_type_save, type); if (ret < 0) { - msg(D_ROUTE, "%s: cannot retrieve iface %s: %s (%d)", __func__, if= ace, - strerror(-ret), ret); + msg(D_ROUTE, "%s: cannot retrieve iface %s: %s (%d)", __func__, if= ace, strerror(-ret), ret); return ret; } @@ -1486,7 +1442,7 @@ int net_iface_del(openvpn_net_ctx_t *ctx, const char *iface) { - struct sitnl_link_req req =3D { }; + struct sitnl_link_req req =3D {}; int ifindex =3D if_nametoindex(iface); if (!ifindex) diff --git a/src/openvpn/ntlm.c b/src/openvpn/ntlm.c index 2c6a69d..52afdb7 100644 --- a/src/openvpn/ntlm.c +++ b/src/openvpn/ntlm.c @@ -45,15 +45,14 @@ #ifdef _MSC_VER /* MS compilers */ #define UINTEGER64 __int64 -#define UINT64(c) c ## Ui64 +#define UINT64(c) c##Ui64 #else /* Non MS compilers */ #define UINTEGER64 unsigned long long -#define UINT64(c) c ## LL +#define UINT64(c) c##LL #endif - static void gen_md4_hash(const uint8_t *data, int data_len, uint8_t *result) { @@ -65,8 +64,7 @@ } static void -gen_hmac_md5(const uint8_t *data, int data_len, const uint8_t *key, - uint8_t *result) +gen_hmac_md5(const uint8_t *data, int data_len, const uint8_t *key, uint8_= t *result) { hmac_ctx_t *hmac_ctx =3D hmac_ctx_new(); @@ -92,13 +90,13 @@ /* store little endian value */ timestamp[0] =3D timestamp_ull & UINT64(0xFF); - timestamp[1] =3D (timestamp_ull >> 8) & UINT64(0xFF); - timestamp[2] =3D (timestamp_ull >> 16) & UINT64(0xFF); - timestamp[3] =3D (timestamp_ull >> 24) & UINT64(0xFF); - timestamp[4] =3D (timestamp_ull >> 32) & UINT64(0xFF); - timestamp[5] =3D (timestamp_ull >> 40) & UINT64(0xFF); - timestamp[6] =3D (timestamp_ull >> 48) & UINT64(0xFF); - timestamp[7] =3D (timestamp_ull >> 56) & UINT64(0xFF); + timestamp[1] =3D (timestamp_ull >> 8) & UINT64(0xFF); + timestamp[2] =3D (timestamp_ull >> 16) & UINT64(0xFF); + timestamp[3] =3D (timestamp_ull >> 24) & UINT64(0xFF); + timestamp[4] =3D (timestamp_ull >> 32) & UINT64(0xFF); + timestamp[5] =3D (timestamp_ull >> 40) & UINT64(0xFF); + timestamp[6] =3D (timestamp_ull >> 48) & UINT64(0xFF); + timestamp[7] =3D (timestamp_ull >> 56) & UINT64(0xFF); } static void @@ -107,7 +105,7 @@ /* Generates 8 random bytes to be used as client nonce */ int i; - for (i =3D 0; i<8; i++) + for (i =3D 0; i < 8; i++) { nonce[i] =3D (unsigned char)get_random(); } @@ -153,8 +151,8 @@ } static void -add_security_buffer(int sb_offset, void *data, int length, - unsigned char *msg_buf, int *msg_bufpos, size_t msg_bu= fsize) +add_security_buffer(int sb_offset, void *data, int length, unsigned char *= msg_buf, int *msg_bufpos, + size_t msg_bufsize) { if (*msg_bufpos + length > msg_bufsize) { @@ -189,8 +187,7 @@ } const char * -ntlm_phase_3(const struct http_proxy_info *p, const char *phase_2, - struct gc_arena *gc) +ntlm_phase_3(const struct http_proxy_info *p, const char *phase_2, struct = gc_arena *gc) { /* NTLM handshake * @@ -206,13 +203,13 @@ int i, ret_val; uint8_t ntlmv2_response[256]; - char userdomain_u[256]; /* for uppercase unicode username and doma= in */ - char userdomain[128]; /* the same as previous but ascii */ + char userdomain_u[256]; /* for uppercase unicode username and domain */ + char userdomain[128]; /* the same as previous but ascii */ uint8_t ntlmv2_hash[MD5_DIGEST_LENGTH]; uint8_t ntlmv2_hmacmd5[16]; - uint8_t *ntlmv2_blob =3D ntlmv2_response + 16; /* inside ntlmv2_re= sponse, length: 128 */ + uint8_t *ntlmv2_blob =3D ntlmv2_response + 16; /* inside ntlmv2_respon= se, length: 128 */ int ntlmv2_blob_size =3D 0; - int phase3_bufpos =3D 0x40; /* offset to next security buffer data= to be added */ + int phase3_bufpos =3D 0x40; /* offset to next security buffer data to = be added */ size_t len; =20 char domain[128]; @@ -226,20 +223,20 @@ separator =3D strchr(p->up.username, '\\'); if (separator =3D=3D NULL) { - strncpy(username, p->up.username, sizeof(username)-1); - username[sizeof(username)-1] =3D 0; + strncpy(username, p->up.username, sizeof(username) - 1); + username[sizeof(username) - 1] =3D 0; domain[0] =3D 0; } else { - strncpy(username, separator+1, sizeof(username)-1); - username[sizeof(username)-1] =3D 0; + strncpy(username, separator + 1, sizeof(username) - 1); + username[sizeof(username) - 1] =3D 0; len =3D separator - p->up.username; if (len > sizeof(domain) - 1) { len =3D sizeof(domain) - 1; } - strncpy(domain, p->up.username, len); + strncpy(domain, p->up.username, len); domain[len] =3D 0; } @@ -265,9 +262,9 @@ } /* extract the challenge from bytes 24-31 */ - for (i =3D 0; i<8; i++) + for (i =3D 0; i < 8; i++) { - challenge[i] =3D buf2[i+24]; + challenge[i] =3D buf2[i + 24]; } /* Generate NTLMv2 response */ @@ -285,17 +282,16 @@ msg(M_INFO, "NTLM: Username or domain too long"); } unicodize(userdomain_u, userdomain); - gen_hmac_md5((uint8_t *)userdomain_u, 2 * strlen(userdomain), md4_hash, - ntlmv2_hash); + gen_hmac_md5((uint8_t *)userdomain_u, 2 * strlen(userdomain), md4_hash= , ntlmv2_hash); /* NTLMv2 Blob */ - memset(ntlmv2_blob, 0, 128); /* Clear blob buff= er */ - ntlmv2_blob[0x00] =3D 1; /* Signature */ - ntlmv2_blob[0x01] =3D 1; /* Signature */ - ntlmv2_blob[0x04] =3D 0; /* Reserved */ - gen_timestamp(&ntlmv2_blob[0x08]); /* 64-bit Timestam= p */ - gen_nonce(&ntlmv2_blob[0x10]); /* 64-bit Client N= once */ - ntlmv2_blob[0x18] =3D 0; /* Unknown, zero= should work */ + memset(ntlmv2_blob, 0, 128); /* Clear blob buffer */ + ntlmv2_blob[0x00] =3D 1; /* Signature */ + ntlmv2_blob[0x01] =3D 1; /* Signature */ + ntlmv2_blob[0x04] =3D 0; /* Reserved */ + gen_timestamp(&ntlmv2_blob[0x08]); /* 64-bit Timestamp */ + gen_nonce(&ntlmv2_blob[0x10]); /* 64-bit Client Nonce */ + ntlmv2_blob[0x18] =3D 0; /* Unknown, zero should work */ /* Add target information block to the blob */ @@ -312,11 +308,11 @@ * byte order on the wire for the NTLM header is LE. */ const size_t hoff =3D 0x14; - unsigned long flags =3D buf2[hoff] | (buf2[hoff + 1] << 8) - |(buf2[hoff + 2] << 16) | (buf2[hoff + 3] << 24); + unsigned long flags =3D + buf2[hoff] | (buf2[hoff + 1] << 8) | (buf2[hoff + 2] << 16) | (buf= 2[hoff + 3] << 24); if ((flags & 0x00800000) =3D=3D 0x00800000) { - tib_len =3D buf2[0x28]; /* Get Target Information block= size */ + tib_len =3D buf2[0x28]; /* Get Target Information block size */ if (tib_len + 0x1c + 16 > sizeof(ntlmv2_response)) { msg(M_WARN, "NTLM: target information buffer too long for resp= onse (len=3D%d)", tib_len); @@ -328,7 +324,9 @@ uint8_t tib_pos =3D buf2[0x2c]; if (tib_pos + tib_len > sizeof(buf2)) { - msg(M_ERR, "NTLM: phase 2 response from server too long (n= eed %d bytes at offset %u)", tib_len, tib_pos); + msg(M_ERR, + "NTLM: phase 2 response from server too long (need %d = bytes at offset %u)", + tib_len, tib_pos); return NULL; } /* Get Target Information block pointer */ @@ -352,41 +350,38 @@ memcpy(&ntlmv2_response[8], challenge, 8); /* hmac-md5 */ - gen_hmac_md5(&ntlmv2_response[8], ntlmv2_blob_size + 8, ntlmv2_hash, - ntlmv2_hmacmd5); + gen_hmac_md5(&ntlmv2_response[8], ntlmv2_blob_size + 8, ntlmv2_hash, n= tlmv2_hmacmd5); /* Add hmac-md5 result to the blob. * Note: This overwrites challenge previously written at * ntlmv2_response[8..15] */ memcpy(ntlmv2_response, ntlmv2_hmacmd5, MD5_DIGEST_LENGTH); - memset(phase3, 0, sizeof(phase3)); /* clear reply */ + memset(phase3, 0, sizeof(phase3)); /* clear reply */ - strcpy((char *)phase3, "NTLMSSP\0"); /* signature */ - phase3[8] =3D 3; /* type 3 */ + strcpy((char *)phase3, "NTLMSSP\0"); /* signature */ + phase3[8] =3D 3; /* type 3 */ /* NTLMv2 response */ - add_security_buffer(0x14, ntlmv2_response, ntlmv2_blob_size + 16, - phase3, &phase3_bufpos, sizeof(phase3)); + add_security_buffer(0x14, ntlmv2_response, ntlmv2_blob_size + 16, phas= e3, &phase3_bufpos, + sizeof(phase3)); /* username in ascii */ - add_security_buffer(0x24, username, strlen(username), phase3, - &phase3_bufpos, sizeof(phase3)); + add_security_buffer(0x24, username, strlen(username), phase3, &phase3_= bufpos, sizeof(phase3)); /* Set domain. If is empty, default domain will be used * (i.e. proxy's domain) */ add_security_buffer(0x1c, domain, strlen(domain), phase3, &phase3_bufp= os, sizeof(phase3)); /* other security buffers will be empty */ - phase3[0x10] =3D phase3_bufpos; /* lm not used */ - phase3[0x30] =3D phase3_bufpos; /* no workstation name supplied */ - phase3[0x38] =3D phase3_bufpos; /* no session key */ + phase3[0x10] =3D phase3_bufpos; /* lm not used */ + phase3[0x30] =3D phase3_bufpos; /* no workstation name supplied */ + phase3[0x38] =3D phase3_bufpos; /* no session key */ /* flags */ phase3[0x3c] =3D 0x02; /* negotiate oem */ phase3[0x3d] =3D 0x02; /* negotiate ntlm */ - return ((const char *)make_base64_string2((unsigned char *)phase3, - phase3_bufpos, gc)); + return ((const char *)make_base64_string2((unsigned char *)phase3, pha= se3_bufpos, gc)); } #endif /* if NTLM */ diff --git a/src/openvpn/occ.c b/src/openvpn/occ.c index 773fcfd..5f5bc9e 100644 --- a/src/openvpn/occ.c +++ b/src/openvpn/occ.c @@ -52,95 +52,93 @@ * OCC_STRING_SIZE must be set to sizeof (occ_magic) */ -const uint8_t occ_magic[] =3D { - 0x28, 0x7f, 0x34, 0x6b, 0xd4, 0xef, 0x7a, 0x81, - 0x2d, 0x56, 0xb8, 0xd3, 0xaf, 0xc5, 0x45, 0x9c -}; +const uint8_t occ_magic[] =3D { 0x28, 0x7f, 0x34, 0x6b, 0xd4, 0xef, 0x7a, = 0x81, + 0x2d, 0x56, 0xb8, 0xd3, 0xaf, 0xc5, 0x45, 0x= 9c }; static const struct mtu_load_test mtu_load_test_sequence[] =3D { - {OCC_MTU_LOAD_REQUEST, -1000}, - {OCC_MTU_LOAD, -1000}, - {OCC_MTU_LOAD_REQUEST, -1000}, - {OCC_MTU_LOAD, -1000}, - {OCC_MTU_LOAD_REQUEST, -1000}, - {OCC_MTU_LOAD, -1000}, + { OCC_MTU_LOAD_REQUEST, -1000 }, + { OCC_MTU_LOAD, -1000 }, + { OCC_MTU_LOAD_REQUEST, -1000 }, + { OCC_MTU_LOAD, -1000 }, + { OCC_MTU_LOAD_REQUEST, -1000 }, + { OCC_MTU_LOAD, -1000 }, - {OCC_MTU_LOAD_REQUEST, -750}, - {OCC_MTU_LOAD, -750}, - {OCC_MTU_LOAD_REQUEST, -750}, - {OCC_MTU_LOAD, -750}, - {OCC_MTU_LOAD_REQUEST, -750}, - {OCC_MTU_LOAD, -750}, + { OCC_MTU_LOAD_REQUEST, -750 }, + { OCC_MTU_LOAD, -750 }, + { OCC_MTU_LOAD_REQUEST, -750 }, + { OCC_MTU_LOAD, -750 }, + { OCC_MTU_LOAD_REQUEST, -750 }, + { OCC_MTU_LOAD, -750 }, - {OCC_MTU_LOAD_REQUEST, -500}, - {OCC_MTU_LOAD, -500}, - {OCC_MTU_LOAD_REQUEST, -500}, - {OCC_MTU_LOAD, -500}, - {OCC_MTU_LOAD_REQUEST, -500}, - {OCC_MTU_LOAD, -500}, + { OCC_MTU_LOAD_REQUEST, -500 }, + { OCC_MTU_LOAD, -500 }, + { OCC_MTU_LOAD_REQUEST, -500 }, + { OCC_MTU_LOAD, -500 }, + { OCC_MTU_LOAD_REQUEST, -500 }, + { OCC_MTU_LOAD, -500 }, - {OCC_MTU_LOAD_REQUEST, -400}, - {OCC_MTU_LOAD, -400}, - {OCC_MTU_LOAD_REQUEST, -400}, - {OCC_MTU_LOAD, -400}, - {OCC_MTU_LOAD_REQUEST, -400}, - {OCC_MTU_LOAD, -400}, + { OCC_MTU_LOAD_REQUEST, -400 }, + { OCC_MTU_LOAD, -400 }, + { OCC_MTU_LOAD_REQUEST, -400 }, + { OCC_MTU_LOAD, -400 }, + { OCC_MTU_LOAD_REQUEST, -400 }, + { OCC_MTU_LOAD, -400 }, - {OCC_MTU_LOAD_REQUEST, -300}, - {OCC_MTU_LOAD, -300}, - {OCC_MTU_LOAD_REQUEST, -300}, - {OCC_MTU_LOAD, -300}, - {OCC_MTU_LOAD_REQUEST, -300}, - {OCC_MTU_LOAD, -300}, + { OCC_MTU_LOAD_REQUEST, -300 }, + { OCC_MTU_LOAD, -300 }, + { OCC_MTU_LOAD_REQUEST, -300 }, + { OCC_MTU_LOAD, -300 }, + { OCC_MTU_LOAD_REQUEST, -300 }, + { OCC_MTU_LOAD, -300 }, - {OCC_MTU_LOAD_REQUEST, -200}, - {OCC_MTU_LOAD, -200}, - {OCC_MTU_LOAD_REQUEST, -200}, - {OCC_MTU_LOAD, -200}, - {OCC_MTU_LOAD_REQUEST, -200}, - {OCC_MTU_LOAD, -200}, + { OCC_MTU_LOAD_REQUEST, -200 }, + { OCC_MTU_LOAD, -200 }, + { OCC_MTU_LOAD_REQUEST, -200 }, + { OCC_MTU_LOAD, -200 }, + { OCC_MTU_LOAD_REQUEST, -200 }, + { OCC_MTU_LOAD, -200 }, - {OCC_MTU_LOAD_REQUEST, -150}, - {OCC_MTU_LOAD, -150}, - {OCC_MTU_LOAD_REQUEST, -150}, - {OCC_MTU_LOAD, -150}, - {OCC_MTU_LOAD_REQUEST, -150}, - {OCC_MTU_LOAD, -150}, + { OCC_MTU_LOAD_REQUEST, -150 }, + { OCC_MTU_LOAD, -150 }, + { OCC_MTU_LOAD_REQUEST, -150 }, + { OCC_MTU_LOAD, -150 }, + { OCC_MTU_LOAD_REQUEST, -150 }, + { OCC_MTU_LOAD, -150 }, - {OCC_MTU_LOAD_REQUEST, -100}, - {OCC_MTU_LOAD, -100}, - {OCC_MTU_LOAD_REQUEST, -100}, - {OCC_MTU_LOAD, -100}, - {OCC_MTU_LOAD_REQUEST, -100}, - {OCC_MTU_LOAD, -100}, + { OCC_MTU_LOAD_REQUEST, -100 }, + { OCC_MTU_LOAD, -100 }, + { OCC_MTU_LOAD_REQUEST, -100 }, + { OCC_MTU_LOAD, -100 }, + { OCC_MTU_LOAD_REQUEST, -100 }, + { OCC_MTU_LOAD, -100 }, - {OCC_MTU_LOAD_REQUEST, -50}, - {OCC_MTU_LOAD, -50}, - {OCC_MTU_LOAD_REQUEST, -50}, - {OCC_MTU_LOAD, -50}, - {OCC_MTU_LOAD_REQUEST, -50}, - {OCC_MTU_LOAD, -50}, + { OCC_MTU_LOAD_REQUEST, -50 }, + { OCC_MTU_LOAD, -50 }, + { OCC_MTU_LOAD_REQUEST, -50 }, + { OCC_MTU_LOAD, -50 }, + { OCC_MTU_LOAD_REQUEST, -50 }, + { OCC_MTU_LOAD, -50 }, - {OCC_MTU_LOAD_REQUEST, 0}, - {OCC_MTU_LOAD, 0}, - {OCC_MTU_LOAD_REQUEST, 0}, - {OCC_MTU_LOAD, 0}, - {OCC_MTU_LOAD_REQUEST, 0}, - {OCC_MTU_LOAD, 0}, + { OCC_MTU_LOAD_REQUEST, 0 }, + { OCC_MTU_LOAD, 0 }, + { OCC_MTU_LOAD_REQUEST, 0 }, + { OCC_MTU_LOAD, 0 }, + { OCC_MTU_LOAD_REQUEST, 0 }, + { OCC_MTU_LOAD, 0 }, - {OCC_MTU_REQUEST, 0}, - {OCC_MTU_REQUEST, 0}, - {OCC_MTU_REQUEST, 0}, - {OCC_MTU_REQUEST, 0}, - {OCC_MTU_REQUEST, 0}, - {OCC_MTU_REQUEST, 0}, - {OCC_MTU_REQUEST, 0}, - {OCC_MTU_REQUEST, 0}, - {OCC_MTU_REQUEST, 0}, - {OCC_MTU_REQUEST, 0}, + { OCC_MTU_REQUEST, 0 }, + { OCC_MTU_REQUEST, 0 }, + { OCC_MTU_REQUEST, 0 }, + { OCC_MTU_REQUEST, 0 }, + { OCC_MTU_REQUEST, 0 }, + { OCC_MTU_REQUEST, 0 }, + { OCC_MTU_REQUEST, 0 }, + { OCC_MTU_REQUEST, 0 }, + { OCC_MTU_REQUEST, 0 }, + { OCC_MTU_REQUEST, 0 }, - {-1, 0} + { -1, 0 } }; void @@ -156,15 +154,12 @@ */ msg(D_SHOW_OCC, "NOTE: failed to obtain options consistency info from peer= -- " - "this could occur if the remote peer is running a version = of " - PACKAGE_NAME - " before 1.5-beta8 or if there is a network connectivity p= roblem, and will not necessarily prevent " - PACKAGE_NAME + "this could occur if the remote peer is running a version = of " PACKAGE_NAME + " before 1.5-beta8 or if there is a network connectivity p= roblem, and will not necessarily prevent " PACKAGE_NAME " from running (" counter_format " bytes received from pee= r, " counter_format " bytes authenticated data channel traffic) -- you can dis= able the options consistency " "check with --disable-occ.", - c->c2.link_read_bytes, - c->c2.link_read_bytes_auth); + c->c2.link_read_bytes, c->c2.link_read_bytes_auth); } event_timeout_clear(&c->c2.occ_interval); } @@ -197,16 +192,17 @@ if (entry->op >=3D 0) { c->c2.occ_op =3D entry->op; - size_t payload_size =3D frame_calculate_payload_size(&c->c2.fr= ame, - &c->options= , &c->c1.ks.key_type); - size_t header_size =3D frame_calculate_protocol_header_size(&c= ->c1.ks.key_type, &c->options, false); + size_t payload_size =3D + frame_calculate_payload_size(&c->c2.frame, &c->options, &c= ->c1.ks.key_type); + size_t header_size =3D + frame_calculate_protocol_header_size(&c->c1.ks.key_type, &= c->options, false); c->c2.occ_mtu_load_size =3D payload_size + header_size; } else { - msg(M_INFO, - "NOTE: failed to empirically measure MTU (requires " PACKA= GE_NAME " 1.5 or higher at other end of connection)."); + msg(M_INFO, "NOTE: failed to empirically measure MTU (requires= " PACKAGE_NAME + " 1.5 or higher at other end of connection)."); event_timeout_clear(&c->c2.occ_mtu_load_test_interval); c->c2.occ_mtu_load_n_tries =3D 0; } @@ -309,10 +305,8 @@ proto_hdr =3D frame_calculate_protocol_header_size(kt, &c->opt= ions, false); need_to_add =3D min_int(c->c2.occ_mtu_load_size, c->c2.frame.b= uf.payload_size) - - OCC_STRING_SIZE - - sizeof(uint8_t) /* occ opcode */ - - payload_hdr - - proto_hdr; + - OCC_STRING_SIZE - sizeof(uint8_t) /* occ opcod= e */ + - payload_hdr - proto_hdr; while (need_to_add > 0) { @@ -326,13 +320,8 @@ --need_to_add; } dmsg(D_PACKET_CONTENT, "SENT OCC_MTU_LOAD min_int(%d,%d)-%d-%d= -%d-%d) size=3D%d", - c->c2.occ_mtu_load_size, - c->c2.frame.buf.payload_size, - OCC_STRING_SIZE, - (int) sizeof(uint8_t), - (int) payload_hdr, - (int) proto_hdr, - BLEN(&c->c2.buf)); + c->c2.occ_mtu_load_size, c->c2.frame.buf.payload_size, OC= C_STRING_SIZE, + (int)sizeof(uint8_t), (int)payload_hdr, (int)proto_hdr, B= LEN(&c->c2.buf)); doit =3D true; } break; @@ -388,12 +377,10 @@ dmsg(D_PACKET_CONTENT, "RECEIVED OCC_REPLY"); if (c->options.occ && !TLS_MODE(c) && c->c2.options_string_rem= ote) { - if (!options_cmp_equal_safe((char *) BPTR(&c->c2.buf), - c->c2.options_string_remote, + if (!options_cmp_equal_safe((char *)BPTR(&c->c2.buf), c->c= 2.options_string_remote, c->c2.buf.len)) { - options_warning_safe((char *) BPTR(&c->c2.buf), - c->c2.options_string_remote, + options_warning_safe((char *)BPTR(&c->c2.buf), c->c2.o= ptions_string_remote, c->c2.buf.len); } } @@ -404,22 +391,20 @@ dmsg(D_PACKET_CONTENT, "RECEIVED OCC_MTU_REPLY"); c->c2.max_recv_size_remote =3D buf_read_u16(&c->c2.buf); c->c2.max_send_size_remote =3D buf_read_u16(&c->c2.buf); - if (c->options.mtu_test - && c->c2.max_recv_size_remote > 0 + if (c->options.mtu_test && c->c2.max_recv_size_remote > 0 && c->c2.max_send_size_remote > 0) { - msg(M_INFO, "NOTE: Empirical MTU test completed [Tried,Act= ual] local->remote=3D[%d,%d] remote->local=3D[%d,%d]", - c->c2.max_send_size_local, - c->c2.max_recv_size_remote, - c->c2.max_send_size_remote, - c->c2.max_recv_size_local); - if (!c->options.ce.fragment - && (proto_is_dgram(c->options.ce.proto)) + msg(M_INFO, + "NOTE: Empirical MTU test completed [Tried,Actual] loc= al->remote=3D[%d,%d] remote->local=3D[%d,%d]", + c->c2.max_send_size_local, c->c2.max_recv_size_remote, + c->c2.max_send_size_remote, c->c2.max_recv_size_local); + if (!c->options.ce.fragment && (proto_is_dgram(c->options.= ce.proto)) && c->c2.max_send_size_local > TUN_MTU_MIN && (c->c2.max_recv_size_remote < c->c2.max_send_size_l= ocal || c->c2.max_recv_size_local < c->c2.max_send_size= _remote)) { - msg(M_INFO, "NOTE: This connection is unable to accomm= odate a UDP packet size of %d. Consider using --fragment or --mssfix option= s as a workaround.", + msg(M_INFO, + "NOTE: This connection is unable to accommodate a = UDP packet size of %d. Consider using --fragment or --mssfix options as a w= orkaround.", c->c2.max_send_size_local); } } diff --git a/src/openvpn/occ.h b/src/openvpn/occ.h index 8631bce..1ac93b2 100644 --- a/src/openvpn/occ.h +++ b/src/openvpn/occ.h @@ -33,8 +33,8 @@ * OCC (OpenVPN Configuration Control) protocol opcodes. */ -#define OCC_REQUEST 0 /* request options string from peer */ -#define OCC_REPLY 1 /* deliver options string to peer */ +#define OCC_REQUEST 0 /* request options string from peer */ +#define OCC_REPLY 1 /* deliver options string to peer */ /* * Send an OCC_REQUEST once every OCC_INTERVAL @@ -49,11 +49,12 @@ /* * Other OCC protocol opcodes used to estimate the MTU empirically. */ -#define OCC_MTU_LOAD_REQUEST 2 /* Ask peer to send a big packet t= o us */ -#define OCC_MTU_LOAD 3 /* Send a big packet to peer */ -#define OCC_MTU_REQUEST 4 /* Ask peer to tell us the largest - * packet it has received from us = so far */ -#define OCC_MTU_REPLY 5 /* Send largest packet size to pee= r */ +#define OCC_MTU_LOAD_REQUEST 2 /* Ask peer to send a big packet to us */ +#define OCC_MTU_LOAD 3 /* Send a big packet to peer */ +#define OCC_MTU_REQUEST \ + 4 /* Ask peer to tell us the largest \ + * packet it has received from us so far */ +#define OCC_MTU_REPLY 5 /* Send largest packet size to peer */ /* * Process one command from mtu_load_test_sequence @@ -64,7 +65,7 @@ /* * Send an exit message to remote. */ -#define OCC_EXIT 6 +#define OCC_EXIT 6 /* * Used to conduct a load test command sequence @@ -72,10 +73,10 @@ */ struct mtu_load_test { - int op; /* OCC opcode to send to peer */ - int delta; /* determine packet size to send by using - * this delta against currently - * configured MTU */ + int op; /* OCC opcode to send to peer */ + int delta; /* determine packet size to send by using + * this delta against currently + * configured MTU */ }; =20 extern const uint8_t occ_magic[]; @@ -111,8 +112,7 @@ check_send_occ_req(struct context *c) { if (event_timeout_defined(&c->c2.occ_interval) - && event_timeout_trigger(&c->c2.occ_interval, - &c->c2.timeval, + && event_timeout_trigger(&c->c2.occ_interval, &c->c2.timeval, (!TO_LINK_DEF(c) && c->c2.occ_op < 0) ? E= TT_DEFAULT : 0)) { check_send_occ_req_dowork(c); @@ -126,8 +126,7 @@ check_send_occ_load_test(struct context *c) { if (event_timeout_defined(&c->c2.occ_mtu_load_test_interval) - && event_timeout_trigger(&c->c2.occ_mtu_load_test_interval, - &c->c2.timeval, + && event_timeout_trigger(&c->c2.occ_mtu_load_test_interval, &c->c2= .timeval, (!TO_LINK_DEF(c) && c->c2.occ_op < 0) ? E= TT_DEFAULT : 0)) { check_send_occ_load_test_dowork(c); diff --git a/src/openvpn/openssl_compat.h b/src/openvpn/openssl_compat.h index 6baaaea..f9e1460 100644 --- a/src/openvpn/openssl_compat.h +++ b/src/openvpn/openssl_compat.h @@ -68,15 +68,16 @@ } } -#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG -#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG +#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG +#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG #endif #if defined(LIBRESSL_VERSION_NUMBER) -#define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT RSA_F_RSA_EAY_PRIVATE_ENCRYPT +#define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT RSA_F_RSA_EAY_PRIVATE_ENCRYPT #endif -#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x305040= 0fL || defined(OPENSSL_IS_AWSLC) +#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x305040= 0fL \ + || defined(OPENSSL_IS_AWSLC) #define SSL_get_peer_tmp_key SSL_get_server_tmp_key #endif @@ -86,10 +87,8 @@ /* Note that this is not a perfect emulation of the new function but * is good enough for our case of printing certificate details during * handshake */ -static inline -int -EVP_PKEY_get_group_name(EVP_PKEY *pkey, char *gname, size_t gname_sz, - size_t *gname_len) +static inline int +EVP_PKEY_get_group_name(EVP_PKEY *pkey, char *gname, size_t gname_sz, size= _t *gname_len) { const EC_KEY *ec =3D EVP_PKEY_get0_EC_KEY(pkey); if (ec =3D=3D NULL) @@ -118,13 +117,12 @@ #endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L && !defined(OPENSSL_NO_E= C) */ #if OPENSSL_VERSION_NUMBER < 0x30000000L -#define EVP_MD_get0_name EVP_MD_name -#define EVP_CIPHER_get0_name EVP_CIPHER_name +#define EVP_MD_get0_name EVP_MD_name +#define EVP_CIPHER_get0_name EVP_CIPHER_name #define EVP_CIPHER_CTX_get_mode EVP_CIPHER_CTX_mode /** Reduce SSL_CTX_new_ex() to SSL_CTX_new() for OpenSSL < 3 */ -#define SSL_CTX_new_ex(libctx, propq, method) \ - SSL_CTX_new((method)) +#define SSL_CTX_new_ex(libctx, propq, method) SSL_CTX_new((method)) /* Some safe typedefs to avoid too many ifdefs */ typedef void OSSL_LIB_CTX; @@ -161,9 +159,7 @@ } static inline unsigned long -ERR_get_error_all(const char **file, int *line, - const char **func, - const char **data, int *flags) +ERR_get_error_all(const char **file, int *line, const char **func, const c= har **data, int *flags) { static const char *empty =3D ""; *func =3D empty; @@ -173,13 +169,13 @@ #endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ -#if OPENSSL_VERSION_NUMBER < 0x30500000 && (!defined(LIBRESSL_VERSION_NUMB= ER) || LIBRESSL_VERSION_NUMBER > 0x3050400fL) +#if OPENSSL_VERSION_NUMBER < 0x30500000 \ + && (!defined(LIBRESSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3= 050400fL) static inline int SSL_get0_peer_signature_name(SSL *ssl, const char **sigalg) { int peer_sig_nid; - if (SSL_get_peer_signature_nid(ssl, &peer_sig_nid) - && peer_sig_nid !=3D NID_undef) + if (SSL_get_peer_signature_nid(ssl, &peer_sig_nid) && peer_sig_nid != =3D NID_undef) { *sigalg =3D OBJ_nid2sn(peer_sig_nid); return 1; @@ -195,7 +191,8 @@ *sigalg =3D NULL; return 0; } -#endif /* if OPENSSL_VERSION_NUMBER < 0x30500000 && (!defined(LIBRESSL_VER= SION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3050400fL) */ +#endif /* if OPENSSL_VERSION_NUMBER < 0x30500000 && (!defined(LIBRESSL_VER= SION_NUMBER) || \ + LIBRESSL_VERSION_NUMBER > 0x3050400fL) */ #if OPENSSL_VERSION_NUMBER < 0x30200000L && OPENSSL_VERSION_NUMBER >=3D 0x= 30000000L static inline const char * diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c index 54d5a06..51dcd92 100644 --- a/src/openvpn/openvpn.c +++ b/src/openvpn/openvpn.c @@ -120,8 +120,7 @@ * printing depends on it */ for (int j =3D 1; j < MAX_PARMS && c->options.providers.names[j]; j++) { - c->options.providers.providers[j] =3D - crypto_load_provider(c->options.providers.names[j]); + c->options.providers.providers[j] =3D crypto_load_provider(c->opti= ons.providers.names[j]); } } @@ -130,8 +129,7 @@ { for (int j =3D 1; j < MAX_PARMS && c->options.providers.providers[j]; = j++) { - crypto_unload_provider(c->options.providers.names[j], - c->options.providers.providers[j]); + crypto_unload_provider(c->options.providers.names[j], c->options.p= roviders.providers[j]); } net_ctx_free(&c->net_ctx); } @@ -157,14 +155,15 @@ * @param argc - Commandline argument count. * @param argv - Commandline argument values. */ -static -int +static int openvpn_main(int argc, char *argv[]) { struct context c; #if PEDANTIC - fprintf(stderr, "Sorry, I was built with --enable-pedantic and I am in= capable of doing any real work!\n"); + fprintf( + stderr, + "Sorry, I was built with --enable-pedantic and I am incapable of d= oing any real work!\n"); return 1; #endif @@ -333,15 +332,13 @@ /* pass restart status to management subsystem */ signal_restart_status(c.sig); - } - while (signal_reset(c.sig, SIGUSR1) =3D=3D SIGUSR1); + } while (signal_reset(c.sig, SIGUSR1) =3D=3D SIGUSR1); env_set_destroy(c.es); uninit_options(&c.options); gc_reset(&c.gc); uninit_early(&c); - } - while (signal_reset(c.sig, SIGHUP) =3D=3D SIGHUP); + } while (signal_reset(c.sig, SIGHUP) =3D=3D SIGHUP); } context_gc_free(&c); @@ -366,7 +363,7 @@ int ret; int i; - if ((argv =3D calloc(argc+1, sizeof(char *))) =3D=3D NULL) + if ((argv =3D calloc(argc + 1, sizeof(char *))) =3D=3D NULL) { return 1; } diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h index 3c8ce39..c5f88c8 100644 --- a/src/openvpn/openvpn.h +++ b/src/openvpn/openvpn.h @@ -70,7 +70,7 @@ * renegotiation key */ struct key2 original_wrap_keydata; struct key_ctx tls_crypt_v2_server_key; - struct buffer tls_crypt_v2_wkc; /**< Wrapped client key */ + struct buffer tls_crypt_v2_wkc; /**< Wrapped client key */ struct key_ctx auth_token_key; }; @@ -170,10 +170,10 @@ /* persist crypto sequence number to/from file */ struct packet_id_persist pid_persist; - struct tuntap *tuntap; /**< Tun/tap virtual network interface. */ - bool tuntap_owned; /**< Whether the tun/tap interface should - * be cleaned up when this %context is - * cleaned up. */ + struct tuntap *tuntap; /**< Tun/tap virtual network interface. */ + bool tuntap_owned; /**< Whether the tun/tap interface should + * be cleaned up when this %context is + * cleaned up. */ struct route_list *route_list; /**< List of routing information. See the @@ -209,8 +209,7 @@ static inline bool is_cas_pending(enum multi_status cas) { - return cas =3D=3D CAS_PENDING || cas =3D=3D CAS_PENDING_DEFERRED - || cas =3D=3D CAS_PENDING_DEFERRED_PARTIAL; + return cas =3D=3D CAS_PENDING || cas =3D=3D CAS_PENDING_DEFERRED || ca= s =3D=3D CAS_PENDING_DEFERRED_PARTIAL; } /** @@ -224,9 +223,9 @@ */ struct context_2 { - struct gc_arena gc; /**< Garbage collection arena for - * allocations done in the level 2 scope - * of this context_2 structure. */ + struct gc_arena gc; /**< Garbage collection arena for + * allocations done in the level 2 scope + * of this context_2 structure. */ /* our global wait events */ struct event_set *event_set; @@ -241,13 +240,13 @@ bool link_socket_owned; =20 - const struct link_socket *accept_from; /* possibly do accept() on a pa= rent link_socket */ + const struct link_socket *accept_from; /* possibly do accept() on a = parent link_socket */ - struct link_socket_actual *to_link_addr; /* IP address of remote */ - struct link_socket_actual from; /* address of incoming dat= agram */ + struct link_socket_actual *to_link_addr; /* IP address of remote */ + struct link_socket_actual from; /* address of incoming datagr= am */ /* MTU frame parameters */ - struct frame frame; /* Active frame parameters= */ + struct frame frame; /* Active frame parameters */ #ifdef ENABLE_FRAGMENT /* Object to handle advanced MTU negotiation and datagram fragmentatio= n */ @@ -298,7 +297,7 @@ char *options_string_local; char *options_string_remote; - int occ_op; /* INIT to -1 */ + int occ_op; /* INIT to -1 */ int occ_n_tries; struct event_timeout occ_interval; @@ -306,11 +305,11 @@ * Keep track of maximum packet size received so far * (of authenticated packets). */ - int original_recv_size; /* temporary */ - int max_recv_size_local; /* max packet size received */ - int max_recv_size_remote; /* max packet size received by remote */ - int max_send_size_local; /* max packet size sent */ - int max_send_size_remote; /* max packet size sent by remote */ + int original_recv_size; /* temporary */ + int max_recv_size_local; /* max packet size received */ + int max_recv_size_remote; /* max packet size received by remote */ + int max_send_size_local; /* max packet size sent */ + int max_send_size_remote; /* max packet size sent by remote */ /* remote wants us to send back a load test packet of this size */ @@ -474,60 +473,64 @@ */ struct context { - struct options options; /**< Options loaded from command line or - * configuration file. */ + struct options options; /**< Options loaded from command line or + * configuration file. */ - bool first_time; /**< True on the first iteration of - * OpenVPN's main loop. */ + bool first_time; /**< True on the first iteration of + * OpenVPN's main loop. */ /* context modes */ -#define CM_P2P 0 /* standalone point-to-point session or clien= t */ -#define CM_TOP 1 /* top level of a multi-client or point-to-mu= ltipoint server */ -#define CM_TOP_CLONE 2 /* clone of a CM_TOP context for one thread */ -#define CM_CHILD_UDP 3 /* child context of a CM_TOP or CM_THREAD */ -#define CM_CHILD_TCP 4 /* child context of a CM_TOP or CM_THREAD */ - int mode; /**< Role of this context within the - * OpenVPN process. Valid values are \c - * CM_P2P, \c CM_TOP, \c CM_TOP_CLONE, - * \c CM_CHILD_UDP, and \c CM_CHILD_TCP.= */ +#define CM_P2P 0 /* standalone point-to-point session or c= lient */ +#define CM_TOP 1 /* top level of a multi-client or point-t= o-multipoint server */ +#define CM_TOP_CLONE 2 /* clone of a CM_TOP context for one thre= ad */ +#define CM_CHILD_UDP 3 /* child context of a CM_TOP or CM_THREAD= */ +#define CM_CHILD_TCP 4 /* child context of a CM_TOP or CM_THREAD= */ + int mode; /**< Role of this context within the + * OpenVPN process. Valid values are \c + * CM_P2P, \c CM_TOP, \c CM_TOP_CLONE, + * \c CM_CHILD_UDP, and \c CM_CHILD_TCP= . */ - struct gc_arena gc; /**< Garbage collection arena for - * allocations done in the scope of this - * context structure. */ + struct gc_arena gc; /**< Garbage collection arena for + * allocations done in the scope of this + * context structure. */ - struct env_set *es; /**< Set of environment variables. */ + struct env_set *es; /**< Set of environment variables. */ - openvpn_net_ctx_t net_ctx; /**< Networking API opaque context */ + openvpn_net_ctx_t net_ctx; /**< Networking API opaque context */ - struct signal_info *sig; /**< Internal error signaling object. */ + struct signal_info *sig; /**< Internal error signaling object. */ struct plugin_list *plugins; /**< List of plug-ins. */ - bool plugins_owned; /**< Whether the plug-ins should be - * cleaned up when this %context is - * cleaned up. */ + bool plugins_owned; /**< Whether the plug-ins should be + * cleaned up when this %context is + * cleaned up. */ - bool did_we_daemonize; /**< Whether demonization has already - * taken place. */ + bool did_we_daemonize; /**< Whether demonization has already + * taken place. */ struct context_persist persist; /**< Persistent %context. */ - struct context_0 *c0; /**< Level 0 %context. */ - struct context_1 c1; /**< Level 1 %context. */ - struct context_2 c2; /**< Level 2 %context. */ + struct context_0 *c0; /**< Level 0 %context. */ + struct context_1 c1; /**< Level 1 %context. */ + struct context_2 c2; /**< Level 2 %context. */ }; /* * Check for a signal when inside an event loop */ -#define EVENT_LOOP_CHECK_SIGNAL(c, func, arg) \ - if (IS_SIG(c)) \ - { \ - const int brk =3D func(arg); \ - perf_pop(); \ - if (brk) { \ - break;} \ - else { \ - continue;} \ +#define EVENT_LOOP_CHECK_SIGNAL(c, func, arg) \ + if (IS_SIG(c)) \ + { \ + const int brk =3D func(arg); \ + perf_pop(); \ + if (brk) \ + { \ + break; \ + } \ + else \ + { \ + continue; \ + } \ } /* @@ -535,14 +538,15 @@ * have been compiled in. */ -#define TLS_MODE(c) ((c)->c2.tls_multi !=3D NULL) -#define PROTO_DUMP_FLAGS (check_debug_level(D_LINK_RW_VERBOSE) ? (PD_SHOW_= DATA|PD_VERBOSE) : 0) -#define PROTO_DUMP(buf, gc) protocol_dump((buf), \ - PROTO_DUMP_FLAGS \ - |(c->c2.tls_multi ? PD_TLS : 0) = \ - |(c->options.tls_auth_file ? md_= kt_size(c->c1.ks.key_type.digest) : 0) \ - |(c->options.tls_crypt_file || c= ->options.tls_crypt_v2_file ? PD_TLS_CRYPT : 0), \ - gc) +#define TLS_MODE(c) ((c)->c2.tls_multi !=3D NULL) +#define PROTO_DUMP_FLAGS (check_debug_level(D_LINK_RW_VERBOSE) ? (PD_SHOW_= DATA | PD_VERBOSE) : 0) +#define PROTO_DUMP(buf, gc) = \ + protocol_dump( = \ + (buf), = \ + PROTO_DUMP_FLAGS | (c->c2.tls_multi ? PD_TLS : 0) = \ + | (c->options.tls_auth_file ? md_kt_size(c->c1.ks.key_type.dig= est) : 0) \ + | (c->options.tls_crypt_file || c->options.tls_crypt_v2_file ?= PD_TLS_CRYPT : 0), \ + gc) /* this represents "disabled peer-id" */ #define MAX_PEER_ID 0xFFFFFF diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 0662b49..742ff58 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -67,8 +67,7 @@ #include "memdbg.h" -const char title_string[] =3D - PACKAGE_STRING +const char title_string[] =3D PACKAGE_STRING #ifdef CONFIGURE_GIT_REVISION " [git:" CONFIGURE_GIT_REVISION CONFIGURE_GIT_FLAGS "]" #endif @@ -114,7 +113,7 @@ #ifdef CONFIGURE_GIT_REVISION " built on " __DATE__ #endif -; + ; #ifndef ENABLE_SMALL @@ -698,7 +697,7 @@ " cache until token is removed.\n" "--pkcs11-id-management : Acquire identity from management in= terface.\n" "--pkcs11-id serialized-id 'id' : Identity to use, get using standalo= ne --show-pkcs11-ids\n" -#endif /* ENABLE_PKCS11 */ +#endif /* ENABLE_PKCS11 */ "\n" "SSL Library information:\n" "--show-ciphers : Show cipher algorithms to use with --cipher option.= \n" @@ -787,13 +786,13 @@ "--show-pkcs11-ids provider [cert_private] : Show PKCS#11 available id= s.\n" #endif " --verb option can be adde= d *BEFORE* this.\n" -#endif /* ENABLE_PKCS11 */ +#endif /* ENABLE_PKCS11 */ "\n" "General Standalone Options:\n" #ifdef ENABLE_DEBUG "--show-gateway [address]: Show info about gateway [to v4/v6 address].= \n" #endif -; + ; #endif /* !ENABLE_SMALL */ @@ -894,7 +893,7 @@ #endif #ifdef ENABLE_PKCS11 o->pkcs11_pin_cache_period =3D -1; -#endif /* ENABLE_PKCS11 */ +#endif /* ENABLE_PKCS11 */ /* P2MP server context features */ o->auth_token_generate =3D false; @@ -909,7 +908,7 @@ /* Error out if we can't find a valid temporary directory, which s= hould * be very unlikely. */ msg(M_USAGE, "Could not find a suitable temporary directory." - " (GetTempPath() failed). Consider using --tmp-dir"); + " (GetTempPath() failed). Consider using --tmp-dir"); } #else /* ifdef _WIN32 */ /* Non-windows platforms use $TMPDIR, and if not set, default to '/tmp= ' */ @@ -950,10 +949,10 @@ struct pull_filter { -#define PUF_TYPE_UNDEF 0 /**< undefined filter type */ -#define PUF_TYPE_ACCEPT 1 /**< filter type to accept a matching option = */ -#define PUF_TYPE_IGNORE 2 /**< filter type to ignore a matching option = */ -#define PUF_TYPE_REJECT 3 /**< filter type to reject and trigger SIGUSR= 1 */ +#define PUF_TYPE_UNDEF 0 /**< undefined filter type */ +#define PUF_TYPE_ACCEPT 1 /**< filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2 /**< filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3 /**< filter type to reject and trigger SIGUSR1 */ int type; int size; char *pattern; @@ -990,23 +989,19 @@ } #define SHOW_PARM(name, value, format) msg(D_SHOW_PARMS, " " #name " =3D = " format, (value)) -#define SHOW_STR(var) SHOW_PARM(var, (o->var ? o->var : "[UNDEF]"), = "'%s'") -#define SHOW_STR_INLINE(var) SHOW_PARM(var, \ - o->var ## _inline ? "[INLINE]" := \ - (o->var ? o->var : "[UNDEF]"), \ - "'%s'") -#define SHOW_INT(var) SHOW_PARM(var, o->var, "%d") -#define SHOW_UINT(var) SHOW_PARM(var, o->var, "%u") -#define SHOW_INT64(var) SHOW_PARM(var, o->var, "%" PRIi64) -#define SHOW_UNSIGNED(var) SHOW_PARM(var, o->var, "0x%08x") -#define SHOW_BOOL(var) SHOW_PARM(var, (o->var ? "ENABLED" : "DISABLED= "), "%s"); +#define SHOW_STR(var) SHOW_PARM(var, (o->var ? o->var : "= [UNDEF]"), "'%s'") +#define SHOW_STR_INLINE(var) \ + SHOW_PARM(var, o->var##_inline ? "[INLINE]" : (o->var ? o->var : "[UND= EF]"), "'%s'") +#define SHOW_INT(var) SHOW_PARM(var, o->var, "%d") +#define SHOW_UINT(var) SHOW_PARM(var, o->var, "%u") +#define SHOW_INT64(var) SHOW_PARM(var, o->var, "%" PRIi64) +#define SHOW_UNSIGNED(var) SHOW_PARM(var, o->var, "0x%08x") +#define SHOW_BOOL(var) SHOW_PARM(var, (o->var ? "ENABLED" : "DISABLED"= ), "%s"); #endif /* ifndef ENABLE_SMALL */ static void -setenv_connection_entry(struct env_set *es, - const struct connection_entry *e, - const int i) +setenv_connection_entry(struct env_set *es, const struct connection_entry = *e, const int i) { setenv_str_i(es, "remote", e->remote, i); setenv_str_i(es, "remote_port", e->remote_port, i); @@ -1024,9 +1019,7 @@ } static void -setenv_local_entry(struct env_set *es, - const struct local_entry *e, - const int i) +setenv_local_entry(struct env_set *es, const struct local_entry *e, const = int i) { setenv_str_i(es, "proto", proto2ascii(e->proto, AF_UNSPEC, false), i); setenv_str_i(es, "local", e->local, i); @@ -1048,7 +1041,7 @@ int i; for (i =3D 0; i < o->connection_list->len; ++i) { - setenv_connection_entry(es, o->connection_list->array[i], i+1); + setenv_connection_entry(es, o->connection_list->array[i], i + = 1); } } else @@ -1060,7 +1053,7 @@ { for (int i =3D 0; i < o->ce.local_list->len; i++) { - setenv_local_entry(es, o->ce.local_list->array[i], i+1); + setenv_local_entry(es, o->ce.local_list->array[i], i + 1); } } } @@ -1149,18 +1142,18 @@ } static bool -ipv6_addr_safe_hexplusbits( const char *ipv6_prefix_spec ) +ipv6_addr_safe_hexplusbits(const char *ipv6_prefix_spec) { struct in6_addr t_addr; unsigned int t_bits; - return get_ipv6_addr( ipv6_prefix_spec, &t_addr, &t_bits, M_WARN ); + return get_ipv6_addr(ipv6_prefix_spec, &t_addr, &t_bits, M_WARN); } static char * string_substitute(const char *src, int from, int to, struct gc_arena *gc) { - char *ret =3D (char *) gc_malloc(strlen(src) + 1, true, gc); + char *ret =3D (char *)gc_malloc(strlen(src) + 1, true, gc); char *dest =3D ret; char c; @@ -1172,8 +1165,7 @@ c =3D to; } *dest++ =3D c; - } - while (c); + } while (c); return ret; } @@ -1201,9 +1193,7 @@ while (*cp && i < nbytes) { /* valid segments consist of exactly two hex digits, then ':' or E= OS */ - if (!isxdigit(cp[0]) - || !isxdigit(cp[1]) - || (cp[2] !=3D ':' && cp[2] !=3D '\0') + if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || (cp[2] !=3D ':' && cp[= 2] !=3D '\0') || sscanf(cp, "%x", &byte) !=3D 1) { msg(msglevel, "format error in hash fingerprint: %s", str); @@ -1221,7 +1211,8 @@ } if (i < nbytes) { - msg(msglevel, "hash fingerprint is wrong length - expected %d byte= s, got %d: %s", nbytes, i, str); + msg(msglevel, "hash fingerprint is wrong length - expected %d byte= s, got %d: %s", nbytes, i, + str); } else if (term !=3D '\0') { @@ -1241,8 +1232,7 @@ * @param gc The returned list items will be allocated in this = gc */ static struct verify_hash_list * -parse_hash_fingerprint_multiline(const char *str, int nbytes, int msglevel, - struct gc_arena *gc) +parse_hash_fingerprint_multiline(const char *str, int nbytes, int msglevel= , struct gc_arena *gc) { struct gc_arena gc_temp =3D gc_new(); char *lines =3D string_alloc(str, &gc_temp); @@ -1263,8 +1253,7 @@ continue; } - struct verify_hash_list *hash =3D parse_hash_fingerprint(line, nby= tes, - msglevel, g= c); + struct verify_hash_list *hash =3D parse_hash_fingerprint(line, nby= tes, msglevel, gc); if (!hash) { @@ -1289,7 +1278,7 @@ int i; for (i =3D 0; i < len; ++i) { - msg(D_SHOW_PARMS, " %s[%d] =3D %s", name, i, array[i] ); + msg(D_SHOW_PARMS, " %s[%d] =3D %s", name, i, array[i]); } } @@ -1300,10 +1289,7 @@ int i; for (i =3D 0; i < len; ++i) { - msg(D_SHOW_PARMS, " %s[%d] =3D %s", - name, - i, - print_in_addr_t(array[i], 0, &gc)); + msg(D_SHOW_PARMS, " %s[%d] =3D %s", name, i, print_in_addr_t(arra= y[i], 0, &gc)); } gc_free(&gc); } @@ -1349,14 +1335,13 @@ } } static void -dhcp_option_address_parse(const char *name, const char *parm, in_addr_t *a= rray, int *len, int msglevel) +dhcp_option_address_parse(const char *name, const char *parm, in_addr_t *a= rray, int *len, + int msglevel) { if (*len >=3D N_DHCP_ADDR) { - msg(msglevel, "--dhcp-option %s: maximum of %d %s servers can be s= pecified", - name, - N_DHCP_ADDR, - name); + msg(msglevel, "--dhcp-option %s: maximum of %d %s servers can be s= pecified", name, + N_DHCP_ADDR, name); } else { @@ -1401,12 +1386,15 @@ msg(D_SHOW_PARMS, " server_network =3D %s", print_in_addr_t(o->server= _network, 0, &gc)); msg(D_SHOW_PARMS, " server_netmask =3D %s", print_in_addr_t(o->server= _netmask, 0, &gc)); - msg(D_SHOW_PARMS, " server_network_ipv6 =3D %s", print_in6_addr(o->se= rver_network_ipv6, 0, &gc) ); + msg(D_SHOW_PARMS, " server_network_ipv6 =3D %s", print_in6_addr(o->se= rver_network_ipv6, 0, &gc)); SHOW_INT(server_netbits_ipv6); msg(D_SHOW_PARMS, " server_bridge_ip =3D %s", print_in_addr_t(o->serv= er_bridge_ip, 0, &gc)); - msg(D_SHOW_PARMS, " server_bridge_netmask =3D %s", print_in_addr_t(o-= >server_bridge_netmask, 0, &gc)); - msg(D_SHOW_PARMS, " server_bridge_pool_start =3D %s", print_in_addr_t= (o->server_bridge_pool_start, 0, &gc)); - msg(D_SHOW_PARMS, " server_bridge_pool_end =3D %s", print_in_addr_t(o= ->server_bridge_pool_end, 0, &gc)); + msg(D_SHOW_PARMS, " server_bridge_netmask =3D %s", + print_in_addr_t(o->server_bridge_netmask, 0, &gc)); + msg(D_SHOW_PARMS, " server_bridge_pool_start =3D %s", + print_in_addr_t(o->server_bridge_pool_start, 0, &gc)); + msg(D_SHOW_PARMS, " server_bridge_pool_end =3D %s", + print_in_addr_t(o->server_bridge_pool_end, 0, &gc)); if (o->push_list.head) { const struct push_entry *e =3D o->push_list.head; @@ -1420,13 +1408,16 @@ } } SHOW_BOOL(ifconfig_pool_defined); - msg(D_SHOW_PARMS, " ifconfig_pool_start =3D %s", print_in_addr_t(o->i= fconfig_pool_start, 0, &gc)); + msg(D_SHOW_PARMS, " ifconfig_pool_start =3D %s", + print_in_addr_t(o->ifconfig_pool_start, 0, &gc)); msg(D_SHOW_PARMS, " ifconfig_pool_end =3D %s", print_in_addr_t(o->ifc= onfig_pool_end, 0, &gc)); - msg(D_SHOW_PARMS, " ifconfig_pool_netmask =3D %s", print_in_addr_t(o-= >ifconfig_pool_netmask, 0, &gc)); + msg(D_SHOW_PARMS, " ifconfig_pool_netmask =3D %s", + print_in_addr_t(o->ifconfig_pool_netmask, 0, &gc)); SHOW_STR(ifconfig_pool_persist_filename); SHOW_INT(ifconfig_pool_persist_refresh_freq); SHOW_BOOL(ifconfig_ipv6_pool_defined); - msg(D_SHOW_PARMS, " ifconfig_ipv6_pool_base =3D %s", print_in6_addr(o= ->ifconfig_ipv6_pool_base, 0, &gc)); + msg(D_SHOW_PARMS, " ifconfig_ipv6_pool_base =3D %s", + print_in6_addr(o->ifconfig_ipv6_pool_base, 0, &gc)); SHOW_INT(ifconfig_ipv6_pool_netbits); SHOW_INT(n_bcast_buf); SHOW_INT(tcp_queue_limit); @@ -1440,11 +1431,15 @@ SHOW_BOOL(ccd_exclusive); SHOW_STR(tmp_dir); SHOW_BOOL(push_ifconfig_defined); - msg(D_SHOW_PARMS, " push_ifconfig_local =3D %s", print_in_addr_t(o->p= ush_ifconfig_local, 0, &gc)); - msg(D_SHOW_PARMS, " push_ifconfig_remote_netmask =3D %s", print_in_ad= dr_t(o->push_ifconfig_remote_netmask, 0, &gc)); + msg(D_SHOW_PARMS, " push_ifconfig_local =3D %s", + print_in_addr_t(o->push_ifconfig_local, 0, &gc)); + msg(D_SHOW_PARMS, " push_ifconfig_remote_netmask =3D %s", + print_in_addr_t(o->push_ifconfig_remote_netmask, 0, &gc)); SHOW_BOOL(push_ifconfig_ipv6_defined); - msg(D_SHOW_PARMS, " push_ifconfig_ipv6_local =3D %s/%d", print_in6_ad= dr(o->push_ifconfig_ipv6_local, 0, &gc), o->push_ifconfig_ipv6_netbits ); - msg(D_SHOW_PARMS, " push_ifconfig_ipv6_remote =3D %s", print_in6_addr= (o->push_ifconfig_ipv6_remote, 0, &gc)); + msg(D_SHOW_PARMS, " push_ifconfig_ipv6_local =3D %s/%d", + print_in6_addr(o->push_ifconfig_ipv6_local, 0, &gc), o->push_ifcon= fig_ipv6_netbits); + msg(D_SHOW_PARMS, " push_ifconfig_ipv6_remote =3D %s", + print_in6_addr(o->push_ifconfig_ipv6_remote, 0, &gc)); SHOW_BOOL(enable_c2c); SHOW_BOOL(duplicate_cn); SHOW_INT(cf_max); @@ -1477,16 +1472,13 @@ #endif /* ! ENABLE_SMALL */ static void -option_iroute(struct options *o, - const char *network_str, - const char *netmask_str, - int msglevel) +option_iroute(struct options *o, const char *network_str, const char *netm= ask_str, int msglevel) { struct iroute *ir; ALLOC_OBJ_GC(ir, struct iroute, &o->gc); ir->network =3D getaddr(GETADDR_HOST_ORDER, network_str, 0, NULL, NULL= ); - ir->netbits =3D 32; /* host route if no netmask given */ + ir->netbits =3D 32; /* host route if no netmask given */ if (netmask_str) { @@ -1495,8 +1487,7 @@ if (ir->netbits < 0) { - msg(msglevel, "in --iroute %s %s : Bad network/subnet specific= ation", - network_str, + msg(msglevel, "in --iroute %s %s : Bad network/subnet specific= ation", network_str, netmask_str); return; } @@ -1507,18 +1498,15 @@ } static void -option_iroute_ipv6(struct options *o, - const char *prefix_str, - int msglevel) +option_iroute_ipv6(struct options *o, const char *prefix_str, int msglevel) { struct iroute_ipv6 *ir; ALLOC_OBJ_GC(ir, struct iroute_ipv6, &o->gc); - if (!get_ipv6_addr(prefix_str, &ir->network, &ir->netbits, msglevel )) + if (!get_ipv6_addr(prefix_str, &ir->network, &ir->netbits, msglevel)) { - msg(msglevel, "in --iroute-ipv6 %s: Bad IPv6 prefix specification", - prefix_str); + msg(msglevel, "in --iroute-ipv6 %s: Bad IPv6 prefix specification"= , prefix_str); return; } @@ -1541,17 +1529,16 @@ SHOW_BOOL(nocache); SHOW_STR(http_version); SHOW_STR(user_agent); - for (i =3D 0; i < MAX_CUSTOM_HTTP_HEADER && o->custom_headers[i].name= ; i++) + for (i =3D 0; i < MAX_CUSTOM_HTTP_HEADER && o->custom_headers[i].name;= i++) { if (o->custom_headers[i].content) { - msg(D_SHOW_PARMS, " custom_header[%d] =3D %s: %s", i, - o->custom_headers[i].name, o->custom_headers[i].content); + msg(D_SHOW_PARMS, " custom_header[%d] =3D %s: %s", i, o->cust= om_headers[i].name, + o->custom_headers[i].content); } else { - msg(D_SHOW_PARMS, " custom_header[%d] =3D %s", i, - o->custom_headers[i].name); + msg(D_SHOW_PARMS, " custom_header[%d] =3D %s", i, o->custom_h= eaders[i].name); } } msg(D_SHOW_PARMS, "END http_proxy"); @@ -1608,7 +1595,8 @@ for (int i =3D 0; i < o->local_list->len; i++) { msg(D_SHOW_PARMS, " [%s]:%s-%s", o->local_list->array[i]->local, - o->local_list->array[i]->port, proto2ascii(o->local_list->arra= y[i]->proto, o->af, false)); + o->local_list->array[i]->port, + proto2ascii(o->local_list->array[i]->proto, o->af, false)); } SHOW_STR(remote); SHOW_STR(remote_port); @@ -1645,8 +1633,7 @@ SHOW_INT(explicit_exit_notification); SHOW_STR_INLINE(tls_auth_file); - SHOW_PARM(key_direction, keydirection2ascii(o->key_direction, false, t= rue), - "%s"); + SHOW_PARM(key_direction, keydirection2ascii(o->key_direction, false, t= rue), "%s"); SHOW_STR_INLINE(tls_crypt_file); SHOW_STR_INLINE(tls_crypt_v2_file); } @@ -1901,7 +1888,7 @@ SHOW_INT(ns_cert_type); { int i; - for (i =3D 0; iverify_hash; - int digest_len =3D (o->verify_hash_algo =3D=3D MD_SHA1) ? SHA_DIGE= ST_LENGTH : - SHA256_DIGEST_LENGTH; + int digest_len =3D + (o->verify_hash_algo =3D=3D MD_SHA1) ? SHA_DIGEST_LENGTH : SHA= 256_DIGEST_LENGTH; while (hl) { - char *s =3D format_hex_ex(hl->hash, digest_len, 0, - 1, ":", &gc); + char *s =3D format_hex_ex(hl->hash, digest_len, 0, 1, ":", &gc= ); SHOW_PARM(verify_hash, s, "%s"); hl =3D hl->next; } @@ -1944,36 +1930,38 @@ #ifdef ENABLE_PKCS11 { int i; - for (i =3D 0; ipkcs11_providers[i] !=3D NULL; i++) + for (i =3D 0; i < MAX_PARMS && o->pkcs11_providers[i] !=3D NULL; i= ++) { SHOW_PARM(pkcs11_providers, o->pkcs11_providers[i], "%s"); } } { int i; - for (i =3D 0; ipkcs11_protected= _authentication[i] ? "ENABLED" : "DISABLED", "%s"); + SHOW_PARM(pkcs11_protected_authentication, + o->pkcs11_protected_authentication[i] ? "ENABLED" : = "DISABLED", "%s"); } } { int i; - for (i =3D 0; ipkcs11_private_mode[i], "%08= x"); } } { int i; - for (i =3D 0; ipkcs11_cert_private[i] ? "EN= ABLED" : "DISABLED", "%s"); + SHOW_PARM(pkcs11_cert_private, o->pkcs11_cert_private[i] ? "EN= ABLED" : "DISABLED", + "%s"); } } SHOW_INT(pkcs11_pin_cache_period); SHOW_STR(pkcs11_id); SHOW_BOOL(pkcs11_id_management); -#endif /* ENABLE_PKCS11 */ +#endif /* ENABLE_PKCS11 */ show_p2mp_parms(o); @@ -1994,9 +1982,7 @@ #ifdef ENABLE_MANAGEMENT static struct http_proxy_options * -parse_http_proxy_override(const char *server, - const char *port, - const char *flags, +parse_http_proxy_override(const char *server, const char *port, const char= *flags, struct gc_arena *gc) { if (server && port) @@ -2051,7 +2037,8 @@ } else { - msg(M_WARN, "Note: option http-proxy-override ignored because no T= CP-based connection profiles are defined"); + msg(M_WARN, + "Note: option http-proxy-override ignored because no TCP-based= connection profiles are defined"); } } @@ -2068,8 +2055,7 @@ } static struct local_entry * -alloc_local_entry(struct connection_entry *ce, const int msglevel, - struct gc_arena *gc) +alloc_local_entry(struct connection_entry *ce, const int msglevel, struct = gc_arena *gc) { struct local_list *l =3D alloc_local_list_if_undef(ce, gc); struct local_entry *e; @@ -2082,7 +2068,9 @@ struct local_entry **new_array =3D gc_realloc(l->array, new_cap * = elem_size, gc); if (!new_array) { - msg(msglevel, "Unable to process more local options: out of me= mory. Number of entries =3D %d", l->len); + msg(msglevel, + "Unable to process more local options: out of memory. Numb= er of entries =3D %d", + l->len); return NULL; } @@ -2116,10 +2104,13 @@ if (l->len =3D=3D l->capacity) { int capacity =3D l->capacity + CONNECTION_LIST_SIZE; - struct connection_entry **ce =3D gc_realloc(l->array, capacity*siz= eof(struct connection_entry *), &options->gc); + struct connection_entry **ce =3D + gc_realloc(l->array, capacity * sizeof(struct connection_entry= *), &options->gc); if (ce =3D=3D NULL) { - msg(msglevel, "Unable to process more connection options: out = of memory. Number of entries =3D %d", l->len); + msg(msglevel, + "Unable to process more connection options: out of memory.= Number of entries =3D %d", + l->len); return NULL; } l->array =3D ce; @@ -2149,10 +2140,13 @@ if (l->len =3D=3D l->capacity) { int capacity =3D l->capacity + CONNECTION_LIST_SIZE; - struct remote_entry **re =3D gc_realloc(l->array, capacity*sizeof(= struct remote_entry *), &options->gc); + struct remote_entry **re =3D + gc_realloc(l->array, capacity * sizeof(struct remote_entry *),= &options->gc); if (re =3D=3D NULL) { - msg(msglevel, "Unable to process more remote options: out of m= emory. Number of entries =3D %d", l->len); + msg(msglevel, + "Unable to process more remote options: out of memory. Num= ber of entries =3D %d", + l->len); return NULL; } l->array =3D re; @@ -2216,8 +2210,7 @@ } static void -connection_entry_preload_key(const char **key_file, bool *key_inline, - struct gc_arena *gc) +connection_entry_preload_key(const char **key_file, bool *key_inline, stru= ct gc_arena *gc) { if (key_file && *key_file && !(*key_inline)) { @@ -2227,7 +2220,7 @@ msg(M_FATAL, "Cannot pre-load keyfile (%s)", *key_file); } - *key_file =3D (const char *) in.data; + *key_file =3D (const char *)in.data; *key_inline =3D true; } } @@ -2242,13 +2235,11 @@ } #endif - if (options->verify_hash_no_ca - || options->pkcs12_file - || options->ca_file + if (options->verify_hash_no_ca || options->pkcs12_file || options->ca_= file #ifndef ENABLE_CRYPTO_MBEDTLS || options->ca_path #endif - ) + ) { return; } @@ -2261,14 +2252,19 @@ msg(M_USAGE, "%s", str); } -#define MUST_BE_UNDEF(parm, parm_name) \ - if (options->parm !=3D defaults.parm) { msg(M_USAGE, use_err, parm_nam= e); } +#define MUST_BE_UNDEF(parm, parm_name) \ + if (options->parm !=3D defaults.parm) \ + { \ + msg(M_USAGE, use_err, parm_name); \ + } #define MUST_BE_FALSE(condition, parm_name) \ - if (condition) { msg(M_USAGE, use_err, parm_name); } + if (condition) \ + { \ + msg(M_USAGE, use_err, parm_name); \ + } static void -options_postprocess_verify_ce(const struct options *options, - const struct connection_entry *ce) +options_postprocess_verify_ce(const struct options *options, const struct = connection_entry *ce) { struct options defaults; int dev =3D DEV_TYPE_UNDEF; @@ -2296,9 +2292,8 @@ */ if (ce->proto =3D=3D PROTO_TCP) { - msg(M_USAGE, - "--proto tcp is ambiguous in this context. Please specify " - "--proto tcp-server or --proto tcp-client"); + msg(M_USAGE, "--proto tcp is ambiguous in this context. Please spe= cify " + "--proto tcp-server or --proto tcp-client"); } /* @@ -2338,16 +2333,13 @@ if (string_defined_equal(ce->remote, options->ifconfig_local) || string_defined_equal(ce->remote, options->ifconfig_remote_netma= sk)) { - msg(M_USAGE, - "--local and --remote addresses must be distinct from --ifconf= ig " - "addresses"); + msg(M_USAGE, "--local and --remote addresses must be distinct from= --ifconfig " + "addresses"); } =20 - if (string_defined_equal(options->ifconfig_local, - options->ifconfig_remote_netmask)) + if (string_defined_equal(options->ifconfig_local, options->ifconfig_re= mote_netmask)) { - msg(M_USAGE, - "local and remote/netmask --ifconfig addresses must be differe= nt"); + msg(M_USAGE, "local and remote/netmask --ifconfig addresses must b= e different"); } if (ce->bind_defined && !ce->bind_local) @@ -2357,8 +2349,7 @@ if (ce->local_port_defined && !ce->bind_local) { - msg(M_USAGE, - "--lport and --nobind don't make sense when used together"); + msg(M_USAGE, "--lport and --nobind don't make sense when used toge= ther"); } if (!ce->remote && !ce->bind_local) @@ -2370,8 +2361,7 @@ { struct local_entry *le =3D ce->local_list->array[i]; - if (proto_is_net(le->proto) - && string_defined_equal(le->local, ce->remote) + if (proto_is_net(le->proto) && string_defined_equal(le->local, ce-= >remote) && string_defined_equal(le->port, ce->remote_port)) { msg(M_USAGE, "--remote and one of the --local addresses are th= e same"); @@ -2397,7 +2387,8 @@ && (options->management_flags || options->management_log_history_cache !=3D defaults.managem= ent_log_history_cache)) { - msg(M_USAGE, "--management is not specified, however one or more o= ptions which modify the behavior of --management were specified"); + msg(M_USAGE, + "--management is not specified, however one or more options wh= ich modify the behavior of --management were specified"); } if ((options->management_client_user || options->management_client_gro= up) @@ -2406,24 +2397,21 @@ msg(M_USAGE, "--management-client-(user|group) can only be used on= unix domain sockets"); } - if (options->management_addr - && !(options->management_flags & MF_UNIX_SOCK) + if (options->management_addr && !(options->management_flags & MF_UNIX_= SOCK) && (!options->management_user_pass)) { msg(M_WARN, "WARNING: Using --management on a TCP port WITHOUT " - "passwords is STRONGLY discouraged and considered insecure"); + "passwords is STRONGLY discouraged and considered inse= cure"); } #endif /* ifdef ENABLE_MANAGEMENT */ #if !defined(HAVE_XKEY_PROVIDER) - if ((tls_version_max() >=3D TLS_VER_1_3) - && (options->management_flags & MF_EXTERNAL_KEY) - && !(options->management_flags & (MF_EXTERNAL_KEY_NOPADDING)) - ) + if ((tls_version_max() >=3D TLS_VER_1_3) && (options->management_flags= & MF_EXTERNAL_KEY) + && !(options->management_flags & (MF_EXTERNAL_KEY_NOPADDING))) { msg(M_FATAL, "management-external-key with TLS 1.3 or later requir= es " - "nopadding argument/support"); + "nopadding argument/support"); } #endif /* @@ -2431,7 +2419,8 @@ */ #ifdef _WIN32 - if (dev =3D=3D DEV_TYPE_TUN && !(pull || (options->ifconfig_local && o= ptions->ifconfig_remote_netmask))) + if (dev =3D=3D DEV_TYPE_TUN + && !(pull || (options->ifconfig_local && options->ifconfig_remote_= netmask))) { msg(M_USAGE, "On Windows, --ifconfig is required when --dev tun is= used"); } @@ -2447,14 +2436,13 @@ const char *prefix =3D "Some --dhcp-option or --dns options requir= e DHCP server"; if (options->windows_driver !=3D WINDOWS_DRIVER_TAP_WINDOWS6) { - msg(M_USAGE, "%s, which is not supported by the selected %s dr= iver", - prefix, print_tun_backend_driver(options->windows_driver)); + msg(M_USAGE, "%s, which is not supported by the selected %s dr= iver", prefix, + print_tun_backend_driver(options->windows_driver)); } else if (options->tuntap_options.ip_win32_type !=3D IPW32_SET_DHCP= _MASQ && options->tuntap_options.ip_win32_type !=3D IPW32_SET_A= DAPTIVE) { - msg(M_USAGE, "%s, which requires --ip-win32 dynamic or adaptiv= e", - prefix); + msg(M_USAGE, "%s, which requires --ip-win32 dynamic or adaptiv= e", prefix); } } #endif /* ifdef _WIN32 */ @@ -2477,21 +2465,18 @@ if ((ce->http_proxy_options) && ce->proto !=3D PROTO_TCP_CLIENT) { - msg(M_USAGE, - "--http-proxy MUST be used in TCP Client mode (i.e. --proto " - "tcp-client)"); + msg(M_USAGE, "--http-proxy MUST be used in TCP Client mode (i.e. -= -proto " + "tcp-client)"); } if ((ce->http_proxy_options) && !ce->http_proxy_options->server) { - msg(M_USAGE, - "--http-proxy not specified but other http proxy options prese= nt"); + msg(M_USAGE, "--http-proxy not specified but other http proxy opti= ons present"); } if (ce->http_proxy_options && ce->socks_proxy_server) { - msg(M_USAGE, - "--http-proxy can not be used together with --socks-proxy"); + msg(M_USAGE, "--http-proxy can not be used together with --socks-p= roxy"); } if (ce->socks_proxy_server && ce->proto =3D=3D PROTO_TCP_SERVER) @@ -2511,7 +2496,8 @@ { const char use_err[] =3D "--%s cannot be used with --mode server."; -#define USAGE_VALID_SERVER_PROTOS "--mode server currently only supports "= \ +#define USAGE_VALID_SERVER_PROTOS \ + "--mode server currently only supports " \ "--proto values of udp, tcp-server, tcp4-server, or tcp6-server" #ifdef TARGET_ANDROID msg(M_FATAL, "--mode server not supported on Android"); @@ -2534,7 +2520,7 @@ && (ce->proto !=3D PROTO_TCP_SERVER)) { msg(M_USAGE, "--port-share only works in TCP server mode " - "(--proto values of tcp-server, tcp4-server, or tcp6-serve= r)"); + "(--proto values of tcp-server, tcp4-server, or t= cp6-server)"); } #endif if (!options->tls_server) @@ -2548,8 +2534,7 @@ /* blocks force to have a remote embedded, so we check * for the --remote and bail out if it is present */ - if (options->connection_list->len >1 - || options->connection_list->array[0]->remote) + if (options->connection_list->len > 1 || options->connection_list-= >array[0]->remote) { msg(M_USAGE, " cannot be used with --mode server"); } @@ -2557,9 +2542,8 @@ MUST_BE_UNDEF(shaper, "shaper"); if (options->ipchange) { - msg(M_USAGE, - "--ipchange cannot be used with --mode server (use " - "--client-connect instead)"); + msg(M_USAGE, "--ipchange cannot be used with --mode server (us= e " + "--client-connect instead)"); } if (!(proto_is_dgram(ce->proto) || ce->proto =3D=3D PROTO_TCP_SERV= ER)) { @@ -2567,20 +2551,23 @@ } if (!proto_is_udp(ce->proto) && (options->cf_max || options->cf_pe= r)) { - msg(M_USAGE, "--connect-freq only works with --mode server --p= roto udp. Try --max-clients instead."); + msg(M_USAGE, + "--connect-freq only works with --mode server --proto udp.= Try --max-clients instead."); } - if (!(dev =3D=3D DEV_TYPE_TAP || (dev =3D=3D DEV_TYPE_TUN && optio= ns->topology =3D=3D TOP_SUBNET)) && options->ifconfig_pool_netmask) + if (!(dev =3D=3D DEV_TYPE_TAP || (dev =3D=3D DEV_TYPE_TUN && optio= ns->topology =3D=3D TOP_SUBNET)) + && options->ifconfig_pool_netmask) { - msg(M_USAGE, "The third parameter to --ifconfig-pool (netmask)= is only valid in --dev tap mode"); + msg(M_USAGE, + "The third parameter to --ifconfig-pool (netmask) is only = valid in --dev tap mode"); } if (options->routes && (options->routes->flags & RG_ENABLE)) { - msg(M_USAGE, "--redirect-gateway cannot be used with --mode se= rver (however --push \"redirect-gateway\" is fine)"); + msg(M_USAGE, + "--redirect-gateway cannot be used with --mode server (how= ever --push \"redirect-gateway\" is fine)"); } MUST_BE_UNDEF(route_delay_defined, "route-delay"); MUST_BE_UNDEF(up_delay, "up-delay"); - if (!options->ifconfig_pool_defined - && !options->ifconfig_ipv6_pool_defined + if (!options->ifconfig_pool_defined && !options->ifconfig_ipv6_poo= l_defined && options->ifconfig_pool_persist_filename) { msg(M_USAGE, @@ -2593,7 +2580,8 @@ MUST_BE_UNDEF(allow_recursive_routing, "allow-recursive-routing"); if (options->auth_user_pass_file) { - msg(M_USAGE, "--auth-user-pass cannot be used with --mode serv= er (it should be used on the client side only)"); + msg(M_USAGE, + "--auth-user-pass cannot be used with --mode server (it sh= ould be used on the client side only)"); } if (options->ccd_exclusive && !options->client_config_dir) { @@ -2602,24 +2590,24 @@ if (options->auth_token_generate && !options->renegotiate_seconds) { msg(M_USAGE, "--auth-gen-token needs a non-infinite " - "--renegotiate_seconds setting"); + "--renegotiate_seconds setting"); } if (options->auth_token_generate && options->auth_token_renewal && options->auth_token_renewal < 2 * options->handshake_window) { - msg(M_USAGE, "--auth-gen-token renewal time needs to be at lea= st " + msg(M_USAGE, + "--auth-gen-token renewal time needs to be at least " " two times --hand-window (%d).", options->handshake_window); - } - if (!options->auth_user_pass_verify_script - && !PLUGIN_OPTION_LIST(options) + if (!options->auth_user_pass_verify_script && !PLUGIN_OPTION_LIST(= options) && !MAN_CLIENT_AUTH_ENABLED(options)) { - const char *use_err =3D "--%s must be used with --management-c= lient-auth, an --auth-user-pass-verify script, or plugin"; + const char *use_err =3D + "--%s must be used with --management-client-auth, an --aut= h-user-pass-verify script, or plugin"; MUST_BE_FALSE(options->ssl_flags - & (SSLF_CLIENT_CERT_NOT_REQUIRED|SSLF_CLIENT_CER= T_OPTIONAL), + & (SSLF_CLIENT_CERT_NOT_REQUIRED | SSLF_CLIE= NT_CERT_OPTIONAL), "verify-client-cert none|optional"); MUST_BE_FALSE(options->ssl_flags & SSLF_USERNAME_AS_COMMON_NAM= E, "username-as-common-name"); @@ -2661,7 +2649,7 @@ MUST_BE_UNDEF(cf_max, "connect-freq"); MUST_BE_UNDEF(cf_per, "connect-freq"); MUST_BE_FALSE(options->ssl_flags - & (SSLF_CLIENT_CERT_NOT_REQUIRED|SSLF_CLIENT_CERT_OP= TIONAL), + & (SSLF_CLIENT_CERT_NOT_REQUIRED | SSLF_CLIENT_C= ERT_OPTIONAL), "verify-client-cert"); MUST_BE_FALSE(options->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME, "= username-as-common-name"); MUST_BE_FALSE(options->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL, "= auth-user-pass-optional"); @@ -2669,15 +2657,16 @@ if (options->server_flags & SF_TCP_NODELAY_HELPER) { msg(M_WARN, "WARNING: setting tcp-nodelay on the client side w= ill not " - "affect the server. To have TCP_NODELAY in both direction = use " - "tcp-nodelay in the server configuration instead."); + "affect the server. To have TCP_NODELAY in both di= rection use " + "tcp-nodelay in the server configuration instead."= ); } MUST_BE_UNDEF(auth_user_pass_verify_script, "auth-user-pass-verify= "); MUST_BE_UNDEF(auth_token_generate, "auth-gen-token"); #if PORT_SHARE if (options->port_share_host || options->port_share_port) { - msg(M_USAGE, "--port-share requires TCP server mode (--mode se= rver --proto tcp-server)"); + msg(M_USAGE, + "--port-share requires TCP server mode (--mode server --pr= oto tcp-server)"); } #endif MUST_BE_UNDEF(stale_routes_check_interval, "stale-routes-check"); @@ -2690,8 +2679,7 @@ /* * SSL/TLS mode sanity checks. */ - if (options->tls_server + options->tls_client - + (options->shared_secret_file !=3D NULL) > 1) + if (options->tls_server + options->tls_client + (options->shared_secre= t_file !=3D NULL) > 1) { msg(M_USAGE, "specify only one of --tls-server, --tls-client, or -= -secret"); } @@ -2705,29 +2693,26 @@ } msg(msglevel, "DEPRECATION: No tls-client or tls-server option in " - "configuration detected. OpenVPN 2.8 will remove the " - "functionality to run a VPN without TLS. " - "See the examples section in the manual page for " - "examples of a similar quick setup with peer-fingerprint. " - "OpenVPN 2.7 allows using this configuration when using " - "--allow-deprecated-insecure-static-crypto but you should move= " - "to a proper configuration using TLS as soon as possible." - ); + "configuration detected. OpenVPN 2.8 will remove the= " + "functionality to run a VPN without TLS. " + "See the examples section in the manual page for " + "examples of a similar quick setup with peer-fingerp= rint. " + "OpenVPN 2.7 allows using this configuration when us= ing " + "--allow-deprecated-insecure-static-crypto but you s= hould move " + "to a proper configuration using TLS as soon as poss= ible."); } - if (options->ssl_flags & (SSLF_CLIENT_CERT_NOT_REQUIRED|SSLF_CLIENT_CE= RT_OPTIONAL)) + if (options->ssl_flags & (SSLF_CLIENT_CERT_NOT_REQUIRED | SSLF_CLIENT_= CERT_OPTIONAL)) { msg(M_WARN, "WARNING: POTENTIALLY DANGEROUS OPTION " - "--verify-client-cert none|optional " - "may accept clients which do not present a certificate"); + "--verify-client-cert none|optional " + "may accept clients which do not present a certificate= "); } const int tls_version_max =3D - (options->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) - & SSLF_TLS_VERSION_MAX_MASK; + (options->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERS= ION_MAX_MASK; const int tls_version_min =3D - (options->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) - & SSLF_TLS_VERSION_MIN_MASK; + (options->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERS= ION_MIN_MASK; if (tls_version_max > 0 && tls_version_max < tls_version_min) { @@ -2744,20 +2729,24 @@ } else if (!options->pkcs11_providers[0] && options->pkcs11_id_manag= ement) { - msg(M_WARN, "Option pkcs11-id-management is ignored as no pkcs= 11-providers are specified"); + msg(M_WARN, + "Option pkcs11-id-management is ignored as no pkcs11-provi= ders are specified"); } if (options->pkcs11_providers[0]) { if (options->pkcs11_id_management && options->pkcs11_id !=3D N= ULL) { - msg(M_USAGE, "Parameter --pkcs11-id cannot be used when --= pkcs11-id-management is also specified."); + msg(M_USAGE, + "Parameter --pkcs11-id cannot be used when --pkcs11-id= -management is also specified."); } if (!options->pkcs11_id_management && options->pkcs11_id =3D= =3D NULL) { - msg(M_USAGE, "Parameter --pkcs11-id or --pkcs11-id-managem= ent should be specified."); + msg(M_USAGE, + "Parameter --pkcs11-id or --pkcs11-id-management shoul= d be specified."); } - const char use_err[] =3D "Parameter --%s cannot be used when -= -pkcs11-provider is also specified."; + const char use_err[] =3D + "Parameter --%s cannot be used when --pkcs11-provider is a= lso specified."; MUST_BE_UNDEF(cert_file, "cert"); MUST_BE_UNDEF(priv_key_file, "key"); MUST_BE_UNDEF(pkcs12_file, "pkcs12"); @@ -2770,9 +2759,10 @@ else #endif /* ifdef ENABLE_PKCS11 */ #ifdef ENABLE_CRYPTOAPI - if (options->cryptoapi_cert) + if (options->cryptoapi_cert) { - const char use_err[] =3D "Parameter --%s cannot be used when -= -cryptoapicert is also specified."; + const char use_err[] =3D + "Parameter --%s cannot be used when --cryptoapicert is als= o specified."; MUST_BE_UNDEF(cert_file, "cert"); MUST_BE_UNDEF(priv_key_file, "key"); MUST_BE_UNDEF(pkcs12_file, "pkcs12"); @@ -2781,7 +2771,7 @@ } else #endif - if (options->pkcs12_file) + if (options->pkcs12_file) { #ifdef ENABLE_CRYPTO_MBEDTLS msg(M_USAGE, "Parameter --pkcs12 cannot be used with the mbed = TLS version of OpenVPN."); @@ -2792,7 +2782,7 @@ MUST_BE_UNDEF(priv_key_file, "key"); MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "ma= nagement-external-key"); MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "m= anagement-external-cert"); -#endif /* ifdef ENABLE_CRYPTO_MBEDTLS */ +#endif /* ifdef ENABLE_CRYPTO_MBEDTLS */ } else /* cert/key from none of pkcs11, pkcs12, cryptoapi */ { @@ -2808,24 +2798,25 @@ } else if (!(options->management_flags & MF_EXTERNAL_KEY)) { - msg(M_USAGE, "--management-external-cert must be used = with --management-external-key"); + msg(M_USAGE, + "--management-external-cert must be used with --ma= nagement-external-key"); } } if (pull) { - const int sum =3D ((options->cert_file !=3D NULL) || (options->managemen= t_flags & MF_EXTERNAL_CERT)) - + ((options->priv_key_file !=3D NULL) || (options->man= agement_flags & MF_EXTERNAL_KEY)); + + ((options->priv_key_file !=3D NULL) + || (options->management_flags & MF_EXTERNAL_KEY)); if (sum =3D=3D 0) { if (!options->auth_user_pass_file) { msg(M_USAGE, "No client-side authentication method= is " - "specified. You must use either " - "--cert/--key, --pkcs12, or " - "--auth-user-pass"); + "specified. You must use either " + "--cert/--key, --pkcs12, or " + "--auth-user-pass"); } } else if (sum !=3D 2) @@ -2837,11 +2828,13 @@ { if (!(options->management_flags & MF_EXTERNAL_CERT)) { - notnull(options->cert_file, "certificate file (--cert)= or PKCS#12 file (--pkcs12)"); + notnull(options->cert_file, + "certificate file (--cert) or PKCS#12 file (--= pkcs12)"); } if (!(options->management_flags & MF_EXTERNAL_KEY)) { - notnull(options->priv_key_file, "private key file (--k= ey) or PKCS#12 file (--pkcs12)"); + notnull(options->priv_key_file, + "private key file (--key) or PKCS#12 file (--p= kcs12)"); } } } @@ -2852,7 +2845,8 @@ if (options->tls_client && ce->tls_crypt_v2_file && (ce->tls_auth_file || ce->tls_crypt_file)) { - msg(M_USAGE, "--tls-crypt-v2, --tls-auth and --tls-crypt are m= utually exclusive in client mode"); + msg(M_USAGE, + "--tls-crypt-v2, --tls-auth and --tls-crypt are mutually e= xclusive in client mode"); } } else @@ -2981,12 +2975,12 @@ if (ce->af =3D=3D AF_INET6) { msg(M_INFO, "WARNING: '--proto udp6' is not compatible with " - "'--socks-proxy' today. Forcing IPv4 mode." ); + "'--socks-proxy' today. Forcing IPv4 mode."); } else { msg(M_INFO, "NOTICE: dual-stack mode for '--proto udp' does no= t " - "work correctly with '--socks-proxy' today. Forcing IPv4.= " ); + "work correctly with '--socks-proxy' today. Forci= ng IPv4."); } ce->af =3D AF_INET; } @@ -3020,7 +3014,7 @@ } else #endif - if (ce->tun_mtu_defined) + if (ce->tun_mtu_defined) { if (o->ce.tun_mtu =3D=3D TUN_MTU_DEFAULT) { @@ -3063,12 +3057,9 @@ /* Pre-cache tls-auth/crypt(-v2) key file if * keys were not already embedded in the config file. */ - connection_entry_preload_key(&ce->tls_auth_file, - &ce->tls_auth_file_inline, &o->gc); - connection_entry_preload_key(&ce->tls_crypt_file, - &ce->tls_crypt_file_inline, &o->gc); - connection_entry_preload_key(&ce->tls_crypt_v2_file, - &ce->tls_crypt_v2_file_inline, &o->gc); + connection_entry_preload_key(&ce->tls_auth_file, &ce->tls_auth_file_in= line, &o->gc); + connection_entry_preload_key(&ce->tls_crypt_file, &ce->tls_crypt_file_= inline, &o->gc); + connection_entry_preload_key(&ce->tls_crypt_v2_file, &ce->tls_crypt_v2= _file_inline, &o->gc); if (!proto_is_udp(ce->proto) && ce->explicit_exit_notification) @@ -3099,10 +3090,8 @@ static void remap_redirect_gateway_flags(struct options *opt) { - if (opt->routes - && opt->route_method =3D=3D ROUTE_METHOD_SERVICE - && opt->routes->flags & RG_REROUTE_GW - && !(opt->routes->flags & RG_DEF1)) + if (opt->routes && opt->route_method =3D=3D ROUTE_METHOD_SERVICE + && opt->routes->flags & RG_REROUTE_GW && !(opt->routes->flags & RG= _DEF1)) { msg(M_INFO, "Flag 'def1' added to --redirect-gateway (iservice is = in use)"); opt->routes->flags |=3D RG_DEF1; @@ -3281,8 +3270,7 @@ /* If p11-kit is present on the system then load its p11-kit-proxy.so * by default if the user asks for PKCS#11 without otherwise specifying * the module to use. */ - if (!options->pkcs11_providers[0] - && (options->pkcs11_id || options->pkcs11_id_management)) + if (!options->pkcs11_providers[0] && (options->pkcs11_id || options->p= kcs11_id_management)) { options->pkcs11_providers[0] =3D DEFAULT_PKCS11_MODULE; } @@ -3310,8 +3298,8 @@ if (dco_enabled(o) && o->enable_c2c) { msg(M_WARN, "Note: --client-to-client has no effect when using dat= a " - "channel offload: packets are always sent to the VPN " - "interface and then routed based on the system routing table"); + "channel offload: packets are always sent to the VPN " + "interface and then routed based on the system routing= table"); } } @@ -3341,17 +3329,19 @@ * parts of OpenVPN assert that the ciphername is set */ o->ciphername =3D "BF-CBC"; - msg(M_INFO, "Note: --cipher is not set. OpenVPN versions before 2.= 5 " + msg(M_INFO, + "Note: --cipher is not set. OpenVPN versions before 2.5 " "defaulted to BF-CBC as fallback when cipher negotiation " "failed in this case. If you need this fallback please add " "'--data-ciphers-fallback BF-CBC' to your configuration " "and/or add BF-CBC to --data-ciphers. E.g. " - "--data-ciphers %s:BF-CBC", o->ncp_ciphers_conf); + "--data-ciphers %s:BF-CBC", + o->ncp_ciphers_conf); } - else if (!o->enable_ncp_fallback - && !tls_item_in_cipher_list(o->ciphername, o->ncp_ciphers)) + else if (!o->enable_ncp_fallback && !tls_item_in_cipher_list(o->cipher= name, o->ncp_ciphers)) { - msg(M_WARN, "DEPRECATED OPTION: --cipher set to '%s' but missing i= n " + msg(M_WARN, + "DEPRECATED OPTION: --cipher set to '%s' but missing in " "--data-ciphers (%s). OpenVPN ignores --cipher for cipher " "negotiations. ", o->ciphername, o->ncp_ciphers_conf); @@ -3387,12 +3377,10 @@ options_set_backwards_compatible_options(struct options *o) { /* TLS min version is not set */ - int tls_ver_min =3D (o->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) - & SSLF_TLS_VERSION_MIN_MASK; + int tls_ver_min =3D (o->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSL= F_TLS_VERSION_MIN_MASK; if (tls_ver_min =3D=3D 0) { - int tls_ver_max =3D (o->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) - & SSLF_TLS_VERSION_MAX_MASK; + int tls_ver_max =3D (o->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) &= SSLF_TLS_VERSION_MAX_MASK; if (need_compatibility_before(o, 20307)) { /* 2.3.6 and earlier have TLS 1.0 only, set minimum to TLS 1.0= */ @@ -3448,7 +3436,7 @@ o->comp.flags =3D COMP_F_ALLOW_STUB_ONLY | COMP_F_ADVERTISE_ST= UBS_ONLY; } } -#else /* ifdef USE_COMP */ +#else /* ifdef USE_COMP */ o->comp.flags =3D COMP_F_ALLOW_NOCOMP_ONLY; #endif } @@ -3459,17 +3447,16 @@ if (!check_tls_prf_working()) { msg(D_TLS_ERRORS, "Warning: TLS 1.0 PRF with MD5+SHA1 PRF is not " - "supported by the TLS library. Your system does not support th= is " - "calculation anymore or your security policy (e.g. FIPS 140-2)= " - "forbids it. Connections will only work with peers running " - "OpenVPN 2.6.0 or higher)"); + "supported by the TLS library. Your system does = not support this " + "calculation anymore or your security policy (e.= g. FIPS 140-2) " + "forbids it. Connections will only work with pee= rs running " + "OpenVPN 2.6.0 or higher)"); if (o->mode =3D=3D MODE_SERVER) { msg(M_WARN, "Automatically enabling option " - "--force-tls-key-material-export"); + "--force-tls-key-material-export"); o->force_key_material_export =3D true; } - } } @@ -3514,9 +3501,9 @@ #if defined(_WIN32) if (tt->ip_win32_type !=3D IPW32_SET_DHCP_MASQ && tt->ip_win32_type != =3D IPW32_SET_ADAPTIVE) { - return; /* Not in DHCP mode */ + return; /* Not in DHCP mode */ } -#endif /* if defined(_WIN32) */ +#endif /* if defined(_WIN32) */ /* Copy --dns options to tuntap_options */ const struct dns_domain *d =3D dns->search_domains; @@ -3543,8 +3530,7 @@ } } if ((s->transport && s->transport !=3D DNS_TRANSPORT_PLAIN) - || (s->dnssec && s->dnssec !=3D DNS_SECURITY_NO) - || non_standard_server_port) + || (s->dnssec && s->dnssec !=3D DNS_SECURITY_NO) || non_standa= rd_server_port) { /* Skip servers requiring unsupported config to be set */ s =3D s->next; @@ -3576,7 +3562,7 @@ } } -#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */ +#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */ /** * @brief Postprocess DNS related settings @@ -3703,8 +3689,7 @@ } } if ((s->transport && s->transport !=3D DNS_TRANSPORT_PLAIN) - || (s->dnssec && s->dnssec !=3D DNS_SECURITY_NO) - || non_standard_server_port) + || (s->dnssec && s->dnssec !=3D DNS_SECURITY_NO) || non_st= andard_server_port) { /* Skip servers requiring unsupported config to be set */ s =3D s->next; @@ -3838,7 +3823,7 @@ { /* DH file is only meaningful in a tls-server context. */ msg(M_WARN, "WARNING: Ignoring option 'dh' in tls-client mode, ple= ase only " - "include this in your server configuration"); + "include this in your server configuration"); o->dh_file =3D NULL; } #if ENABLE_MANAGEMENT @@ -3847,25 +3832,23 @@ options_postprocess_http_proxy_override(o); } #endif - if (!o->ca_file && !o->ca_path && o->verify_hash - && o->verify_hash_depth =3D=3D 0) + if (!o->ca_file && !o->ca_path && o->verify_hash && o->verify_hash_dep= th =3D=3D 0) { msg(M_INFO, "Using certificate fingerprint to verify peer (no CA " - "option set). "); + "option set). "); o->verify_hash_no_ca =3D true; } if (o->config && streq(o->config, "stdin") && o->remap_sigusr1 =3D=3D = SIGHUP) { msg(M_USAGE, "Options 'config stdin' and 'remap-usr1 SIGHUP' are " - "incompatible with each other."); + "incompatible with each other."); } if (dco_enabled(o)) { /* check if any option should force disabling DCO */ - o->disable_dco =3D !dco_check_option(D_DCO, o) - || !dco_check_startup_option(D_DCO, o); + o->disable_dco =3D !dco_check_option(D_DCO, o) || !dco_check_start= up_option(D_DCO, o); } #ifdef USE_COMP if (dco_enabled(o)) @@ -3883,7 +3866,8 @@ { if (o->windows_driver =3D=3D DRIVER_DCO) { - msg(M_WARN, "Option --windows-driver ovpn-dco is ignored becau= se Data Channel Offload is disabled"); + msg(M_WARN, + "Option --windows-driver ovpn-dco is ignored because Data = Channel Offload is disabled"); o->windows_driver =3D WINDOWS_DRIVER_TAP_WINDOWS6; } else if (o->windows_driver =3D=3D WINDOWS_DRIVER_UNSPECIFIED) @@ -3895,7 +3879,7 @@ if (dco_enabled(o) && o->dev_node) { msg(M_WARN, "Note: ignoring --dev-node as it has no effect when us= ing " - "data channel offload"); + "data channel offload"); o->dev_node =3D NULL; } #endif /* _WIN32 */ @@ -3933,14 +3917,14 @@ * Check file/directory sanity * */ -#ifndef ENABLE_SMALL /* Expect people using the stripped down version to = know what they do */ +#ifndef ENABLE_SMALL /* Expect people using the stripped down version to k= now what they do */ -#define CHKACC_FILE (1<<0) /**< Check for a file/directory presence = */ -#define CHKACC_DIRPATH (1<<1) /**< Check for directory presence where a= file should reside */ -#define CHKACC_FILEXSTWR (1<<2) /**< If file exists, is it writable? */ -#define CHKACC_ACPTSTDIN (1<<3) /**< If filename is stdin, it's allowed a= nd "exists" */ -#define CHKACC_PRIVATE (1<<4) /**< Warn if this (private) file is group= /others accessible */ -#define CHKACC_ACCEPT_URI (1<<5) /**< Do not check URIs, unless they start= with file: */ +#define CHKACC_FILE (1 << 0) /**< Check for a file/directory presenc= e */ +#define CHKACC_DIRPATH (1 << 1) /**< Check for directory presence where= a file should reside */ +#define CHKACC_FILEXSTWR (1 << 2) /**< If file exists, is it writable? */ +#define CHKACC_ACPTSTDIN (1 << 3) /**< If filename is stdin, it's allowed= and "exists" */ +#define CHKACC_PRIVATE (1 << 4) /**< Warn if this (private) file is gro= up/others accessible */ +#define CHKACC_ACCEPT_URI (1 << 5) /**< Do not check URIs, unless they sta= rt with file: */ static bool check_file_access(const int type, const char *file, const int mode, const = char *opt) @@ -3956,7 +3940,7 @@ /* If stdin is allowed and the file name is 'stdin', then do no * further checks as stdin is always available */ - if ( (type & CHKACC_ACPTSTDIN) && streq(file, "stdin") ) + if ((type & CHKACC_ACPTSTDIN) && streq(file, "stdin")) { return false; } @@ -3979,10 +3963,11 @@ /* Is the directory path leading to the given file accessible? */ if (type & CHKACC_DIRPATH) { - char *fullpath =3D string_alloc(file, NULL); /* POSIX dirname() im= plementation may modify its arguments */ + char *fullpath =3D + string_alloc(file, NULL); /* POSIX dirname() implementation ma= y modify its arguments */ char *dirpath =3D dirname(fullpath); - if (platform_access(dirpath, mode|X_OK) !=3D 0) + if (platform_access(dirpath, mode | X_OK) !=3D 0) { errcode =3D errno; } @@ -3990,13 +3975,13 @@ } /* Is the file itself accessible? */ - if (!errcode && (type & CHKACC_FILE) && (platform_access(file, mode) != =3D 0) ) + if (!errcode && (type & CHKACC_FILE) && (platform_access(file, mode) != =3D 0)) { errcode =3D errno; } /* If the file exists and is accessible, is it writable? */ - if (!errcode && (type & CHKACC_FILEXSTWR) && (platform_access(file, F_= OK) =3D=3D 0) ) + if (!errcode && (type & CHKACC_FILEXSTWR) && (platform_access(file, F_= OK) =3D=3D 0)) { if (platform_access(file, W_OK) !=3D 0) { @@ -4015,7 +4000,7 @@ #ifndef _WIN32 else { - if (st.st_mode & (S_IRWXG|S_IRWXO)) + if (st.st_mode & (S_IRWXG | S_IRWXO)) { msg(M_WARN, "WARNING: file '%s' is group or others accessi= ble", file); } @@ -4038,7 +4023,8 @@ * otherwise it will look for the file inside the given chroot directory i= nstead. */ static bool -check_file_access_chroot(const char *chroot, const int type, const char *f= ile, const int mode, const char *opt) +check_file_access_chroot(const char *chroot, const int type, const char *f= ile, const int mode, + const char *opt) { bool ret =3D false; @@ -4071,9 +4057,8 @@ * the file is inline (and therefore there is no access to check) */ static bool -check_file_access_chroot_inline(bool is_inline, const char *chroot, - const int type, const char *file, - const int mode, const char *opt) +check_file_access_chroot_inline(bool is_inline, const char *chroot, const = int type, + const char *file, const int mode, const ch= ar *opt) { if (is_inline) { @@ -4088,8 +4073,8 @@ * is inline (and therefore there is no access to check) */ static bool -check_file_access_inline(bool is_inline, const int type, const char *file, - const int mode, const char *opt) +check_file_access_inline(bool is_inline, const int type, const char *file,= const int mode, + const char *opt) { if (is_inline) { @@ -4142,8 +4127,7 @@ } else { - msg(M_NOPREFIX|M_OPTERR, "%s fails with '%s': No path to executabl= e.", - opt, command); + msg(M_NOPREFIX | M_OPTERR, "%s fails with '%s': No path to executa= ble.", opt, command); return_code =3D true; } @@ -4162,55 +4146,51 @@ bool errs =3D false; /* ** SSL/TLS/crypto related files ** */ - errs |=3D check_file_access_inline(options->dh_file_inline, CHKACC_FIL= E, - options->dh_file, R_OK, "--dh"); + errs |=3D check_file_access_inline(options->dh_file_inline, CHKACC_FIL= E, options->dh_file, R_OK, + "--dh"); if (!options->verify_hash_no_ca) { - errs |=3D check_file_access_inline(options->ca_file_inline, CHKACC= _FILE, - options->ca_file, R_OK, "--ca"); + errs |=3D check_file_access_inline(options->ca_file_inline, CHKACC= _FILE, options->ca_file, + R_OK, "--ca"); } - errs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FILE, - options->ca_path, R_OK, "--capath"); + errs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FILE, o= ptions->ca_path, R_OK, + "--capath"); - errs |=3D check_file_access_inline(options->cert_file_inline, CHKACC_F= ILE|CHKACC_ACCEPT_URI, + errs |=3D check_file_access_inline(options->cert_file_inline, CHKACC_F= ILE | CHKACC_ACCEPT_URI, options->cert_file, R_OK, "--cert"); errs |=3D check_file_access_inline(options->extra_certs_file, CHKACC_F= ILE, - options->extra_certs_file, R_OK, - "--extra-certs"); + options->extra_certs_file, R_OK, "--e= xtra-certs"); if (!(options->management_flags & MF_EXTERNAL_KEY)) { errs |=3D check_file_access_inline(options->priv_key_file_inline, - CHKACC_FILE|CHKACC_PRIVATE|CHKACC= _ACCEPT_URI, + CHKACC_FILE | CHKACC_PRIVATE | CH= KACC_ACCEPT_URI, options->priv_key_file, R_OK, "--= key"); } - errs |=3D check_file_access_inline(options->pkcs12_file_inline, - CHKACC_FILE|CHKACC_PRIVATE, + errs |=3D check_file_access_inline(options->pkcs12_file_inline, CHKACC= _FILE | CHKACC_PRIVATE, options->pkcs12_file, R_OK, "--pkcs12= "); if (options->ssl_flags & SSLF_CRL_VERIFY_DIR) { - errs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FIL= E, - options->crl_file, R_OK|X_OK, - "--crl-verify directory"); + errs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FIL= E, options->crl_file, + R_OK | X_OK, "--crl-verify direct= ory"); } else { - errs |=3D check_file_access_chroot_inline(options->crl_file_inline, - options->chroot_dir, - CHKACC_FILE, options->crl_= file, - R_OK, "--crl-verify"); + errs |=3D + check_file_access_chroot_inline(options->crl_file_inline, opti= ons->chroot_dir, + CHKACC_FILE, options->crl_file= , R_OK, "--crl-verify"); } if (options->tls_export_peer_cert_dir) { - errs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FIL= E, - options->tls_export_peer_cert_dir, - W_OK, "--tls-export-cert"); + errs |=3D + check_file_access_chroot(options->chroot_dir, CHKACC_FILE, + options->tls_export_peer_cert_dir, W_= OK, "--tls-export-cert"); } ASSERT(options->connection_list); @@ -4218,55 +4198,46 @@ { struct connection_entry *ce =3D options->connection_list->array[i]; - errs |=3D check_file_access_inline(ce->tls_auth_file_inline, - CHKACC_FILE|CHKACC_PRIVATE, - ce->tls_auth_file, R_OK, - "--tls-auth"); - errs |=3D check_file_access_inline(ce->tls_crypt_file_inline, - CHKACC_FILE|CHKACC_PRIVATE, - ce->tls_crypt_file, R_OK, - "--tls-crypt"); - errs |=3D check_file_access_inline(ce->tls_crypt_v2_file_inline, - CHKACC_FILE|CHKACC_PRIVATE, - ce->tls_crypt_v2_file, R_OK, - "--tls-crypt-v2"); + errs |=3D check_file_access_inline(ce->tls_auth_file_inline, CHKAC= C_FILE | CHKACC_PRIVATE, + ce->tls_auth_file, R_OK, "--tls-a= uth"); + errs |=3D check_file_access_inline(ce->tls_crypt_file_inline, CHKA= CC_FILE | CHKACC_PRIVATE, + ce->tls_crypt_file, R_OK, "--tls-= crypt"); + errs |=3D check_file_access_inline(ce->tls_crypt_v2_file_inline, C= HKACC_FILE | CHKACC_PRIVATE, + ce->tls_crypt_v2_file, R_OK, "--t= ls-crypt-v2"); } - errs |=3D check_file_access_inline(options->shared_secret_file_inline, - CHKACC_FILE|CHKACC_PRIVATE, - options->shared_secret_file, R_OK, - "--secret"); + errs |=3D + check_file_access_inline(options->shared_secret_file_inline, CHKAC= C_FILE | CHKACC_PRIVATE, + options->shared_secret_file, R_OK, "--sec= ret"); - errs |=3D check_file_access(CHKACC_DIRPATH|CHKACC_FILEXSTWR, - options->packet_id_file, R_OK|W_OK, "--repla= y-persist"); + errs |=3D check_file_access(CHKACC_DIRPATH | CHKACC_FILEXSTWR, options= ->packet_id_file, + R_OK | W_OK, "--replay-persist"); /* ** Password files ** */ - errs |=3D check_file_access(CHKACC_FILE|CHKACC_ACPTSTDIN|CHKACC_PRIVAT= E, + errs |=3D check_file_access(CHKACC_FILE | CHKACC_ACPTSTDIN | CHKACC_PR= IVATE, options->key_pass_file, R_OK, "--askpass"); #ifdef ENABLE_MANAGEMENT - errs |=3D check_file_access(CHKACC_FILE|CHKACC_ACPTSTDIN|CHKACC_PRIVAT= E, - options->management_user_pass, R_OK, - "--management user/password file"); + errs |=3D + check_file_access(CHKACC_FILE | CHKACC_ACPTSTDIN | CHKACC_PRIVATE, + options->management_user_pass, R_OK, "--manageme= nt user/password file"); #endif /* ENABLE_MANAGEMENT */ errs |=3D check_file_access_inline(options->auth_user_pass_file_inline, - CHKACC_FILE|CHKACC_ACPTSTDIN|CHKACC_P= RIVATE, - options->auth_user_pass_file, R_OK, - "--auth-user-pass"); + CHKACC_FILE | CHKACC_ACPTSTDIN | CHKA= CC_PRIVATE, + options->auth_user_pass_file, R_OK, "= --auth-user-pass"); /* ** System related ** */ - errs |=3D check_file_access(CHKACC_FILE, options->chroot_dir, - R_OK|X_OK, "--chroot directory"); - errs |=3D check_file_access(CHKACC_DIRPATH|CHKACC_FILEXSTWR, options->= writepid, - R_OK|W_OK, "--writepid"); + errs |=3D check_file_access(CHKACC_FILE, options->chroot_dir, R_OK | X= _OK, "--chroot directory"); + errs |=3D check_file_access(CHKACC_DIRPATH | CHKACC_FILEXSTWR, options= ->writepid, R_OK | W_OK, + "--writepid"); /* ** Log related ** */ - errs |=3D check_file_access(CHKACC_DIRPATH|CHKACC_FILEXSTWR, options->= status_file, - R_OK|W_OK, "--status"); + errs |=3D check_file_access(CHKACC_DIRPATH | CHKACC_FILEXSTWR, options= ->status_file, R_OK | W_OK, + "--status"); /* ** Config related ** */ errs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FILE, o= ptions->client_config_dir, - R_OK|X_OK, "--client-config-dir"); + R_OK | X_OK, "--client-config-dir"); errs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FILE, o= ptions->tmp_dir, - R_OK|W_OK|X_OK, "Temporary directory = (--tmp-dir)"); + R_OK | W_OK | X_OK, "Temporary direct= ory (--tmp-dir)"); if (errs) { @@ -4352,12 +4323,8 @@ * the other end of the connection] */ 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) +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 buffer out =3D alloc_buf(OPTION_LINE_SIZE); bool tt_local =3D false; @@ -4373,8 +4340,7 @@ * cipher (p2p) or have a fallback cipher configured for older non * ncp clients. But not sending it will make even 2.4 complain * about it being missing. So still send it. */ - buf_printf(&out, ",link-mtu %u", - (unsigned int) calc_options_string_link_mtu(o, frame)); + buf_printf(&out, ",link-mtu %u", (unsigned int)calc_options_string_lin= k_mtu(o, frame)); if (o->ce.occ_mtu !=3D 0) { @@ -4385,7 +4351,7 @@ buf_printf(&out, ",tun-mtu %d", frame->tun_mtu); } - buf_printf(&out, ",proto %s", proto_remote(o->ce.proto, remote)); + buf_printf(&out, ",proto %s", proto_remote(o->ce.proto, remote)); bool p2p_nopull =3D o->mode =3D=3D MODE_POINT_TO_POINT && !PULL_DEFINE= D(o); /* send tun_ipv6 only in peer2peer mode - in client/server mode, it @@ -4402,20 +4368,9 @@ */ if (!tt) { - tt =3D init_tun(o->dev, - o->dev_type, - o->topology, - o->ifconfig_local, - o->ifconfig_remote_netmask, - o->ifconfig_ipv6_local, - o->ifconfig_ipv6_netbits, - o->ifconfig_ipv6_remote, - NULL, - NULL, - false, - NULL, - ctx, - NULL); + tt =3D init_tun(o->dev, o->dev_type, o->topology, o->ifconfig_loca= l, + o->ifconfig_remote_netmask, o->ifconfig_ipv6_local, = o->ifconfig_ipv6_netbits, + o->ifconfig_ipv6_remote, NULL, NULL, false, NULL, ct= x, NULL); if (tt) { tt_local =3D true; @@ -4439,7 +4394,8 @@ #ifdef USE_COMP if (o->comp.alg !=3D COMP_ALG_UNDEF) { - buf_printf(&out, ",comp-lzo"); /* for compatibility, this simply i= ndicates that compression context is active, not necessarily LZO per-se */ + buf_printf(&out, ",comp-lzo"); /* for compatibility, this simply i= ndicates that compression + context is active, not necessari= ly LZO per-se */ } #endif @@ -4471,10 +4427,7 @@ { struct key_type kt; - ASSERT((o->shared_secret_file !=3D NULL) - + (TLS_CLIENT =3D=3D true) - + (TLS_SERVER =3D=3D true) - <=3D 1); + ASSERT((o->shared_secret_file !=3D NULL) + (TLS_CLIENT =3D=3D true= ) + (TLS_SERVER =3D=3D true) <=3D 1); /* Skip resolving BF-CBC to allow SSL libraries without BF-CBC * to work here in the default configuration */ @@ -4583,8 +4536,7 @@ } static const char * -options_warning_extract_parm1(const char *option_string, - struct gc_arena *gc_ret) +options_warning_extract_parm1(const char *option_string, struct gc_arena *= gc_ret) { struct gc_arena gc =3D gc_new(); struct buffer b =3D string_alloc_buf(option_string, &gc); @@ -4598,24 +4550,16 @@ } static void -options_warning_safe_scan2(const int msglevel, - const int delim, - const bool report_inconsistent, - const char *p1, - const struct buffer *b2_src, - const char *b1_name, +options_warning_safe_scan2(const int msglevel, const int delim, const bool= report_inconsistent, + const char *p1, const struct buffer *b2_src, co= nst char *b1_name, const char *b2_name) { /* We will stop sending 'key-method', 'keydir', 'proto' and 'tls-auth'= in * OCC in a future version (because it's not useful). To reduce questi= ons * when interoperating, we no longer printing a warning about it. */ - if (strprefix(p1, "key-method ") - || strprefix(p1, "keydir ") - || strprefix(p1, "proto ") - || streq(p1, "tls-auth") - || strprefix(p1, "tun-ipv6") - || strprefix(p1, "cipher ")) + if (strprefix(p1, "key-method ") || strprefix(p1, "keydir ") || strpre= fix(p1, "proto ") + || streq(p1, "tls-auth") || strprefix(p1, "tun-ipv6") || strprefix= (p1, "cipher ")) { return; } @@ -4642,10 +4586,7 @@ if (report_inconsistent) { msg(msglevel, "WARNING: '%s' is used inconsistentl= y, %s=3D'%s', %s=3D'%s'", - safe_print(p1_prefix, &gc), - b1_name, - safe_print(p1, &gc), - b2_name, + safe_print(p1_prefix, &gc), b1_name, safe_prin= t(p1, &gc), b2_name, safe_print(p2, &gc)); } goto done; @@ -4654,11 +4595,7 @@ } msg(msglevel, "WARNING: '%s' is present in %s config but missing i= n %s config, %s=3D'%s'", - safe_print(p1_prefix, &gc), - b1_name, - b2_name, - b1_name, - safe_print(p1, &gc)); + safe_print(p1_prefix, &gc), b1_name, b2_name, b1_name, safe_pr= int(p1, &gc)); done: gc_free(&gc); @@ -4666,13 +4603,9 @@ } static void -options_warning_safe_scan1(const int msglevel, - const int delim, - const bool report_inconsistent, - const struct buffer *b1_src, - const struct buffer *b2_src, - const char *b1_name, - const char *b2_name) +options_warning_safe_scan1(const int msglevel, const int delim, const bool= report_inconsistent, + const struct buffer *b1_src, const struct buffe= r *b2_src, + const char *b1_name, const char *b2_name) { struct gc_arena gc =3D gc_new(); struct buffer b =3D *b1_src; @@ -4680,7 +4613,8 @@ while (buf_parse(&b, delim, p, OPTION_PARM_SIZE)) { - options_warning_safe_scan2(msglevel, delim, report_inconsistent, p= , b2_src, b1_name, b2_name); + options_warning_safe_scan2(msglevel, delim, report_inconsistent, p= , b2_src, b1_name, + b2_name); } gc_free(&gc); @@ -4700,13 +4634,9 @@ buf_printf(&local, "version %s", expected); buf_printf(&remote, "version %s", actual); - options_warning_safe_scan1(msglevel, ',', true, - &local, &remote, - "local", "remote"); + options_warning_safe_scan1(msglevel, ',', true, &local, &remote, "= local", "remote"); - options_warning_safe_scan1(msglevel, ',', false, - &remote, &local, - "remote", "local"); + options_warning_safe_scan1(msglevel, ',', false, &remote, &local, = "remote", "local"); } gc_free(&gc); @@ -4745,13 +4675,12 @@ options_string_version(const char *s, struct gc_arena *gc) { struct buffer out =3D alloc_buf_gc(4, gc); - strncpynt((char *) BPTR(&out), s, 3); + strncpynt((char *)BPTR(&out), s, 3); return BSTR(&out); } char * -options_string_extract_option(const char *options_string, const char *opt_= name, - struct gc_arena *gc) +options_string_extract_option(const char *options_string, const char *opt_= name, struct gc_arena *gc) { char *ret =3D NULL; const size_t opt_name_len =3D strlen(opt_name); @@ -4759,14 +4688,14 @@ const char *p =3D options_string; while (p) { - if (0 =3D=3D strncmp(p, opt_name, opt_name_len) - && strlen(p) > (opt_name_len+1) && p[opt_name_len] =3D=3D ' ') + if (0 =3D=3D strncmp(p, opt_name, opt_name_len) && strlen(p) > (op= t_name_len + 1) + && p[opt_name_len] =3D=3D ' ') { /* option found, extract value */ - const char *start =3D &p[opt_name_len+1]; + const char *start =3D &p[opt_name_len + 1]; const char *end =3D strchr(p, ','); size_t val_len =3D end ? end - start : strlen(start); - ret =3D gc_malloc(val_len+1, true, gc); + ret =3D gc_malloc(val_len + 1, true, gc); memcpy(ret, start, val_len); break; } @@ -4898,20 +4827,13 @@ struct options o; init_options(&o, true); - fprintf(fp, usage_message, - title_string, - o.ce.connect_retry_seconds, - o.ce.connect_retry_seconds_max, - o.ce.local_port, o.ce.remote_port, - TUN_MTU_DEFAULT, TAP_MTU_EXTRA_DEFAULT, - o.verbosity, - o.authname, - o.replay_window, o.replay_time, - o.tls_timeout, o.renegotiate_seconds, - o.handshake_window, o.transition_window); + fprintf(fp, usage_message, title_string, o.ce.connect_retry_seconds, + o.ce.connect_retry_seconds_max, o.ce.local_port, o.ce.remote_p= ort, TUN_MTU_DEFAULT, + TAP_MTU_EXTRA_DEFAULT, o.verbosity, o.authname, o.replay_windo= w, o.replay_time, + o.tls_timeout, o.renegotiate_seconds, o.handshake_window, o.tr= ansition_window); fflush(fp); -#endif /* ENABLE_SMALL */ +#endif /* ENABLE_SMALL */ openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */ } @@ -4919,7 +4841,7 @@ void usage_small(void) { - msg(M_WARN|M_NOPREFIX, "Use --help for more information."); + msg(M_WARN | M_NOPREFIX, "Use --help for more information."); openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */ } @@ -4952,8 +4874,7 @@ #define LZO_LIB_VER_STR "", "" #endif - msg(flags, "library versions: %s%s%s", get_ssl_library_version(), - LZO_LIB_VER_STR); + msg(flags, "library versions: %s%s%s", get_ssl_library_version(), LZO_= LIB_VER_STR); #undef LZO_LIB_VER_STR } @@ -4961,20 +4882,20 @@ static void usage_version(void) { - msg(M_INFO|M_NOPREFIX, "%s", title_string); - show_library_versions( M_INFO|M_NOPREFIX ); + msg(M_INFO | M_NOPREFIX, "%s", title_string); + show_library_versions(M_INFO | M_NOPREFIX); #ifdef _WIN32 - show_windows_version( M_INFO|M_NOPREFIX ); + show_windows_version(M_INFO | M_NOPREFIX); #endif show_dco_version(M_INFO | M_NOPREFIX); - msg(M_INFO|M_NOPREFIX, "Originally developed by James Yonan"); - msg(M_INFO|M_NOPREFIX, "Copyright (C) 2002-2025 OpenVPN Inc "); + msg(M_INFO | M_NOPREFIX, "Originally developed by James Yonan"); + msg(M_INFO | M_NOPREFIX, "Copyright (C) 2002-2025 OpenVPN Inc "); #ifndef ENABLE_SMALL #ifdef CONFIGURE_DEFINES - msg(M_INFO|M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES); + msg(M_INFO | M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES= ); #endif #ifdef CONFIGURE_SPECIAL_BUILD - msg(M_INFO|M_NOPREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD); + msg(M_INFO | M_NOPREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD); #endif #endif openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); @@ -5010,7 +4931,7 @@ } #endif -#ifdef _WIN32 /* This function is only used when compiling on Windows */ +#ifdef _WIN32 /* This function is only used when compiling on Windows */ static unsigned int atou(const char *str) { @@ -5027,13 +4948,8 @@ } int -parse_line(const char *line, - char *p[], - const int n, - const char *file, - const int line_num, - int msglevel, - struct gc_arena *gc) +parse_line(const char *line, char *p[], const int n, const char *file, con= st int line_num, + int msglevel, struct gc_arena *gc) { const int STATE_INITIAL =3D 0; const int STATE_READING_QUOTED_PARM =3D 1; @@ -5142,9 +5058,13 @@ if (!(out =3D=3D '\\' || out =3D=3D '\"' || space(out))) { #ifdef ENABLE_SMALL - msg(msglevel, "%sOptions warning: Bad backslash ('\\')= usage in %s:%d", error_prefix, file, line_num); + msg(msglevel, "%sOptions warning: Bad backslash ('\\')= usage in %s:%d", + error_prefix, file, line_num); #else - msg(msglevel, "%sOptions warning: Bad backslash ('\\')= usage in %s:%d: remember that backslashes are treated as shell-escapes and= if you need to pass backslash characters as part of a Windows filename, yo= u should use double backslashes such as \"c:\\\\" PACKAGE "\\\\static.key\"= ", error_prefix, file, line_num); + msg(msglevel, + "%sOptions warning: Bad backslash ('\\') usage in = %s:%d: remember that backslashes are treated as shell-escapes and if you ne= ed to pass backslash characters as part of a Windows filename, you should u= se double backslashes such as \"c:\\\\" PACKAGE + "\\\\static.key\"", + error_prefix, file, line_num); #endif return 0; } @@ -5159,7 +5079,7 @@ { parm[SIZE(parm) - 1] =3D 0; msg(msglevel, "%sOptions error: Parameter at %s:%d is too = long (%d chars max): %s", - error_prefix, file, line_num, (int) SIZE(parm), parm); + error_prefix, file, line_num, (int)SIZE(parm), parm); return 0; } parm[parm_len++] =3D out; @@ -5175,17 +5095,20 @@ if (state =3D=3D STATE_READING_QUOTED_PARM) { - msg(msglevel, "%sOptions error: No closing quotation (\") in %s:%d= ", error_prefix, file, line_num); + msg(msglevel, "%sOptions error: No closing quotation (\") in %s:%d= ", error_prefix, file, + line_num); return 0; } if (state =3D=3D STATE_READING_SQUOTED_PARM) { - msg(msglevel, "%sOptions error: No closing single quotation (\') i= n %s:%d", error_prefix, file, line_num); + msg(msglevel, "%sOptions error: No closing single quotation (\') i= n %s:%d", error_prefix, + file, line_num); return 0; } if (state !=3D STATE_INITIAL) { - msg(msglevel, "%sOptions error: Residual parse state (%d) in %s:%d= ", error_prefix, state, file, line_num); + msg(msglevel, "%sOptions error: Residual parse state (%d) in %s:%d= ", error_prefix, state, + file, line_num); return 0; } #if 0 @@ -5209,11 +5132,13 @@ } } -struct in_src { -#define IS_TYPE_FP 1 +struct in_src +{ +#define IS_TYPE_FP 1 #define IS_TYPE_BUF 2 int type; - union { + union + { FILE *fp; struct buffer *multiline; } u; @@ -5229,7 +5154,7 @@ else if (is->type =3D=3D IS_TYPE_BUF) { bool status =3D buf_parse(is->u.multiline, '\n', line, size); - if ((int) strlen(line) + 1 < size) + if ((int)strlen(line) + 1 < size) { strcat(line, "\n"); } @@ -5243,11 +5168,10 @@ } static char * -read_inline_file(struct in_src *is, const char *close_tag, - int *num_lines, struct gc_arena *gc) +read_inline_file(struct in_src *is, const char *close_tag, int *num_lines,= struct gc_arena *gc) { char line[OPTION_LINE_SIZE]; - struct buffer buf =3D alloc_buf(8*OPTION_LINE_SIZE); + struct buffer buf =3D alloc_buf(8 * OPTION_LINE_SIZE); char *ret; bool endtagfound =3D false; @@ -5265,7 +5189,7 @@ endtagfound =3D true; break; } - if (!buf_safe(&buf, strlen(line)+1)) + if (!buf_safe(&buf, strlen(line) + 1)) { /* Increase buffer size */ struct buffer buf2 =3D alloc_buf(buf.capacity * 2); @@ -5295,7 +5219,7 @@ if (p[0] && !p[1]) { char *arg =3D p[0]; - if (arg[0] =3D=3D '<' && arg[strlen(arg)-1] =3D=3D '>') + if (arg[0] =3D=3D '<' && arg[strlen(arg) - 1] =3D=3D '>') { struct buffer close_tag; @@ -5321,8 +5245,7 @@ } static int -check_inline_file_via_buf(struct buffer *multiline, char *p[], - struct gc_arena *gc) +check_inline_file_via_buf(struct buffer *multiline, char *p[], struct gc_a= rena *gc) { struct in_src is; is.type =3D IS_TYPE_BUF; @@ -5330,34 +5253,21 @@ return check_inline_file(&is, p, gc); } -static void -add_option(struct options *options, - char *p[], - bool is_inline, - const char *file, - int line, - const int level, - const int msglevel, - const unsigned int permission_mask, - unsigned int *option_types_found, - struct env_set *es); +static void add_option(struct options *options, char *p[], bool is_inline,= const char *file, + int line, const int level, const int msglevel, + const unsigned int permission_mask, unsigned int *o= ption_types_found, + struct env_set *es); static void -read_config_file(struct options *options, - const char *file, - int level, - const char *top_file, - const int top_line, - const int msglevel, - const unsigned int permission_mask, - unsigned int *option_types_found, - struct env_set *es) +read_config_file(struct options *options, const char *file, int level, con= st char *top_file, + const int top_line, const int msglevel, const unsigned in= t permission_mask, + unsigned int *option_types_found, struct env_set *es) { const int max_recursive_levels =3D 10; FILE *fp; int line_num; - char line[OPTION_LINE_SIZE+1]; - char *p[MAX_PARMS+1]; + char line[OPTION_LINE_SIZE + 1]; + char *p[MAX_PARMS + 1]; ++level; if (level <=3D max_recursive_levels) @@ -5380,7 +5290,8 @@ ++line_num; if (strlen(line) =3D=3D OPTION_LINE_SIZE) { - msg(msglevel, "In %s:%d: Maximum option line length (%= d) exceeded, line starts with %s", + msg(msglevel, + "In %s:%d: Maximum option line length (%d) exceede= d, line starts with %s", file, line_num, OPTION_LINE_SIZE, line); } @@ -5389,13 +5300,13 @@ { offset =3D 3; } - if (parse_line(line + offset, p, SIZE(p)-1, file, line_num= , msglevel, &options->gc)) + if (parse_line(line + offset, p, SIZE(p) - 1, file, line_n= um, msglevel, + &options->gc)) { bypass_doubledash(&p[0]); int lines_inline =3D check_inline_file_via_fp(fp, p, &= options->gc); - add_option(options, p, lines_inline, file, line_num, l= evel, - msglevel, permission_mask, option_types_fou= nd, - es); + add_option(options, p, lines_inline, file, line_num, l= evel, msglevel, + permission_mask, option_types_found, es); line_num +=3D lines_inline; } } @@ -5406,25 +5317,24 @@ } else { - msg(msglevel, "In %s:%d: Error opening configuration file: %s"= , top_file, top_line, file); + msg(msglevel, "In %s:%d: Error opening configuration file: %s"= , top_file, top_line, + file); } } else { - msg(msglevel, "In %s:%d: Maximum recursive include levels exceeded= in include attempt of file %s -- probably you have a configuration file th= at tries to include itself.", top_file, top_line, file); + msg(msglevel, + "In %s:%d: Maximum recursive include levels exceeded in includ= e attempt of file %s -- probably you have a configuration file that tries t= o include itself.", + top_file, top_line, file); } secure_memzero(line, sizeof(line)); CLEAR(p); } static void -read_config_string(const char *prefix, - struct options *options, - const char *config, - const int msglevel, - const unsigned int permission_mask, - unsigned int *option_types_found, - struct env_set *es) +read_config_string(const char *prefix, struct options *options, const char= *config, + const int msglevel, const unsigned int permission_mask, + unsigned int *option_types_found, struct env_set *es) { char line[OPTION_LINE_SIZE]; struct buffer multiline; @@ -5434,15 +5344,15 @@ while (buf_parse(&multiline, '\n', line, sizeof(line))) { - char *p[MAX_PARMS+1]; + char *p[MAX_PARMS + 1]; CLEAR(p); ++line_num; - if (parse_line(line, p, SIZE(p)-1, prefix, line_num, msglevel, &op= tions->gc)) + if (parse_line(line, p, SIZE(p) - 1, prefix, line_num, msglevel, &= options->gc)) { bypass_doubledash(&p[0]); int lines_inline =3D check_inline_file_via_buf(&multiline, p, = &options->gc); - add_option(options, p, lines_inline, prefix, line_num, 0, msgl= evel, - permission_mask, option_types_found, es); + add_option(options, p, lines_inline, prefix, line_num, 0, msgl= evel, permission_mask, + option_types_found, es); line_num +=3D lines_inline; } CLEAR(p); @@ -5451,13 +5361,8 @@ } void -parse_argv(struct options *options, - const int argc, - char *argv[], - const int msglevel, - const unsigned int permission_mask, - unsigned int *option_types_found, - struct env_set *es) +parse_argv(struct options *options, const int argc, char *argv[], const in= t msglevel, + const unsigned int permission_mask, unsigned int *option_types_= found, struct env_set *es) { /* usage message */ if (argc <=3D 1) @@ -5468,24 +5373,26 @@ /* config filename specified only? */ if (argc =3D=3D 2 && strncmp(argv[1], "--", 2)) { - char *p[MAX_PARMS+1]; + char *p[MAX_PARMS + 1]; CLEAR(p); p[0] =3D "config"; p[1] =3D argv[1]; - add_option(options, p, false, NULL, 0, 0, msglevel, permission_mas= k, - option_types_found, es); + add_option(options, p, false, NULL, 0, 0, msglevel, permission_mas= k, option_types_found, + es); } else { /* parse command line */ for (int i =3D 1; i < argc; ++i) { - char *p[MAX_PARMS+1]; + char *p[MAX_PARMS + 1]; CLEAR(p); p[0] =3D argv[i]; if (strncmp(p[0], "--", 2)) { - msg(msglevel, "I'm trying to parse \"%s\" as an --option p= arameter but I don't see a leading '--'", p[0]); + msg(msglevel, + "I'm trying to parse \"%s\" as an --option parameter b= ut I don't see a leading '--'", + p[0]); } else { @@ -5508,8 +5415,8 @@ } } } - add_option(options, p, false, NULL, 0, 0, msglevel, permission= _mask, - option_types_found, es); + add_option(options, p, false, NULL, 0, 0, msglevel, permission= _mask, option_types_found, + es); i +=3D j - 1; } } @@ -5564,84 +5471,64 @@ } bool -apply_push_options(struct options *options, - struct buffer *buf, - unsigned int permission_mask, - unsigned int *option_types_found, - struct env_set *es) +apply_push_options(struct options *options, struct buffer *buf, unsigned i= nt permission_mask, + unsigned int *option_types_found, struct env_set *es) { char line[OPTION_PARM_SIZE]; int line_num =3D 0; const char *file =3D "[PUSH-OPTIONS]"; - const int msglevel =3D D_PUSH_ERRORS|M_OPTERR; + const int msglevel =3D D_PUSH_ERRORS | M_OPTERR; while (buf_parse(buf, ',', line, sizeof(line))) { - char *p[MAX_PARMS+1]; + char *p[MAX_PARMS + 1]; CLEAR(p); ++line_num; if (!apply_pull_filter(options, line)) { return false; /* Cause push/pull error and stop push processin= g */ } - if (parse_line(line, p, SIZE(p)-1, file, line_num, msglevel, &opti= ons->gc)) + if (parse_line(line, p, SIZE(p) - 1, file, line_num, msglevel, &op= tions->gc)) { - add_option(options, p, false, file, line_num, 0, msglevel, - permission_mask, option_types_found, es); + add_option(options, p, false, file, line_num, 0, msglevel, per= mission_mask, + option_types_found, es); } } return true; } void -options_server_import(struct options *o, - const char *filename, - int msglevel, - unsigned int permission_mask, - unsigned int *option_types_found, +options_server_import(struct options *o, const char *filename, int msgleve= l, + unsigned int permission_mask, unsigned int *option_t= ypes_found, struct env_set *es) { msg(D_PUSH, "OPTIONS IMPORT: reading client specific options from: %s"= , filename); - read_config_file(o, - filename, - 0, - filename, - 0, - msglevel, - permission_mask, - option_types_found, + read_config_file(o, filename, 0, filename, 0, msglevel, permission_mas= k, option_types_found, es); } void -options_string_import(struct options *options, - const char *config, - const int msglevel, - const unsigned int permission_mask, - unsigned int *option_types_found, +options_string_import(struct options *options, const char *config, const i= nt msglevel, + const unsigned int permission_mask, unsigned int *op= tion_types_found, struct env_set *es) { - read_config_string("[CONFIG-STRING]", options, config, msglevel, permi= ssion_mask, option_types_found, es); + read_config_string("[CONFIG-STRING]", options, config, msglevel, permi= ssion_mask, + option_types_found, es); } -#define VERIFY_PERMISSION(mask) { = \ - if (!verify_permission(p[0], file, line, (mask), permission_mask, = \ - option_types_found, msglevel, options, is_i= nline)) \ - { = \ - goto err; = \ - } = \ -} +#define VERIFY_PERMISSION(mask) = \ + { = \ + if (!verify_permission(p[0], file, line, (mask), permission_mask, = option_types_found, \ + msglevel, options, is_inline)) = \ + { = \ + goto err; = \ + } = \ + } static bool -verify_permission(const char *name, - const char *file, - int line, - const unsigned int type, - const unsigned int allowed, - unsigned int *found, - const int msglevel, - struct options *options, - bool is_inline) +verify_permission(const char *name, const char *file, int line, const unsi= gned int type, + const unsigned int allowed, unsigned int *found, const i= nt msglevel, + struct options *options, bool is_inline) { if (!(type & allowed)) { @@ -5651,8 +5538,7 @@ if (is_inline && !(type & OPT_P_INLINE)) { - msg(msglevel, "option '%s' is not expected to be inline (%s:%d)", = name, - file, line); + msg(msglevel, "option '%s' is not expected to be inline (%s:%d)", = name, file, line); return false; } @@ -5669,12 +5555,12 @@ * connection_list */ - if ((type & OPT_P_CONNECTION) && options->connection_list - && !(allowed & OPT_P_PULL_MODE)) + if ((type & OPT_P_CONNECTION) && options->connection_list && !(allowed= & OPT_P_PULL_MODE)) { if (file) { - msg(M_WARN, "Option '%s' in %s:%d is ignored by previous blocks ", name, file, line); + msg(M_WARN, "Option '%s' in %s:%d is ignored by previous blocks ", name, + file, line); } else { @@ -5690,13 +5576,10 @@ * many parameters. */ -#define NM_QUOTE_HINT (1<<0) +#define NM_QUOTE_HINT (1 << 0) static bool -no_more_than_n_args(const int msglevel, - char *p[], - const int max, - const unsigned int flags) +no_more_than_n_args(const int msglevel, char *p[], const int max, const un= signed int flags) { const int len =3D string_array_len((const char **)p); =20 @@ -5707,11 +5590,11 @@ if (len > max) { - msg(msglevel, "the --%s directive should have at most %d parameter= %s.%s", - p[0], - max - 1, + msg(msglevel, "the --%s directive should have at most %d parameter= %s.%s", p[0], max - 1, max >=3D 3 ? "s" : "", - (flags & NM_QUOTE_HINT) ? " To pass a list of arguments as on= e of the parameters, try enclosing them in double quotes (\"\")." : ""); + (flags & NM_QUOTE_HINT) + ? " To pass a list of arguments as one of the parameters,= try enclosing them in double quotes (\"\")." + : ""); return false; } else @@ -5727,16 +5610,15 @@ } static void -set_user_script(struct options *options, - const char **script, - const char *new_script, - const char *type, - bool in_chroot) +set_user_script(struct options *options, const char **script, const char *= new_script, + const char *type, bool in_chroot) { if (*script) { - msg(M_WARN, "Multiple --%s scripts defined. " - "The previously configured script is overridden.", type); + msg(M_WARN, + "Multiple --%s scripts defined. " + "The previously configured script is overridden.", + type); } *script =3D new_script; options->user_script_used =3D true; @@ -5744,14 +5626,12 @@ #ifndef ENABLE_SMALL { char script_name[100]; - snprintf(script_name, sizeof(script_name), - "--%s script", type); + snprintf(script_name, sizeof(script_name), "--%s script", type); if (check_cmd_access(*script, script_name, (in_chroot ? options->c= hroot_dir : NULL))) { msg(M_USAGE, "Please correct this error."); } - } #endif } @@ -5762,9 +5642,9 @@ if (comp_non_stub_enabled(info)) { msg(M_WARN, "WARNING: Compression for receiving enabled. " - "Compression has been used in the past to break encryption. " - "Compression support is deprecated and we recommend to disable= " - "it completely."); + "Compression has been used in the past to break encryp= tion. " + "Compression support is deprecated and we recommend to= disable " + "it completely."); } } @@ -5784,16 +5664,9 @@ } static void -add_option(struct options *options, - char *p[], - bool is_inline, - const char *file, - int line, - const int level, - const int msglevel, - const unsigned int permission_mask, - unsigned int *option_types_found, - struct env_set *es) +add_option(struct options *options, char *p[], bool is_inline, const char = *file, int line, + const int level, const int msglevel, const unsigned int permiss= ion_mask, + unsigned int *option_types_found, struct env_set *es) { struct gc_arena gc =3D gc_new(); const bool pull_mode =3D BOOL_CAST(permission_mask & OPT_P_PULL_MODE); @@ -5845,7 +5718,8 @@ options->config =3D p[1]; } - read_config_file(options, p[1], level, file, line, msglevel, permi= ssion_mask, option_types_found, es); + read_config_file(options, p[1], level, file, line, msglevel, permi= ssion_mask, + option_types_found, es); } #if defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL) else if (streq(p[0], "show-gateway") && !p[2]) @@ -5898,9 +5772,7 @@ * can potentially include security-sensitive strings */ if (p[1] && strncmp(p[1], "msg", 3) =3D=3D 0) { - msg(M_INFO, "%s:%s", - pull_mode ? "ECHO-PULL" : "ECHO", - BSTR(&string)); + msg(M_INFO, "%s:%s", pull_mode ? "ECHO-PULL" : "ECHO", BST= R(&string)); } #ifdef ENABLE_MANAGEMENT if (management) @@ -6015,8 +5887,7 @@ * When no option is present, assume that only PKCS1 * padding is supported */ - if (!(options->management_flags - &(MF_EXTERNAL_KEY_NOPADDING | MF_EXTERNAL_KEY_PKCS1PAD))) + if (!(options->management_flags & (MF_EXTERNAL_KEY_NOPADDING | MF_= EXTERNAL_KEY_PKCS1PAD))) { options->management_flags |=3D MF_EXTERNAL_KEY_PKCS1PAD; } @@ -6093,7 +5964,8 @@ else if (streq(p[0], "windows-driver") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL); - msg(M_WARN, "DEPRECATED OPTION: windows-driver: In OpenVPN 2.7, th= e default Windows driver is ovpn-dco. " + msg(M_WARN, + "DEPRECATED OPTION: windows-driver: In OpenVPN 2.7, the defaul= t Windows driver is ovpn-dco. " "If incompatible options are used, OpenVPN will fall back to t= ap-windows6. Wintun support has been removed."); } #endif @@ -6128,7 +6000,8 @@ { if (!pull_mode) { - msg(M_WARN, "Note: option tun-ipv6 is ignored because modern o= perating systems do not need special IPv6 tun handling anymore."); + msg(M_WARN, + "Note: option tun-ipv6 is ignored because modern operating= systems do not need special IPv6 tun handling anymore."); } } #ifdef ENABLE_IPROUTE @@ -6141,7 +6014,8 @@ else if (streq(p[0], "ifconfig") && p[1] && p[2] && !p[3]) { VERIFY_PERMISSION(OPT_P_UP); - if (ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) && ip_or_d= ns_addr_safe(p[2], options->allow_pull_fqdn)) /* FQDN -- may be DNS name */ + if (ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) + && ip_or_dns_addr_safe(p[2], options->allow_pull_fqdn)) /* FQD= N -- may be DNS name */ { options->ifconfig_local =3D p[1]; options->ifconfig_remote_netmask =3D p[2]; @@ -6157,12 +6031,12 @@ unsigned int netbits; VERIFY_PERMISSION(OPT_P_UP); - if (get_ipv6_addr( p[1], NULL, &netbits, msglevel ) - && ipv6_addr_safe( p[2] ) ) + if (get_ipv6_addr(p[1], NULL, &netbits, msglevel) && ipv6_addr_saf= e(p[2])) { if (netbits < 64 || netbits > 124) { - msg( msglevel, "ifconfig-ipv6: /netbits must be between 64= and 124, not '/%d'", netbits ); + msg(msglevel, "ifconfig-ipv6: /netbits must be between 64 = and 124, not '/%d'", + netbits); goto err; } @@ -6190,7 +6064,7 @@ { struct local_entry *e; - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); e =3D alloc_local_entry(&options->ce, M_USAGE, &options->gc); ASSERT(e); @@ -6220,7 +6094,7 @@ } else if (streq(p[0], "connection") && p[1] && !p[3]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); if (is_inline) { struct options sub; @@ -6228,11 +6102,12 @@ init_options(&sub, true); sub.ce =3D options->ce; - read_config_string("[CONNECTION-OPTIONS]", &sub, p[1], msgleve= l, - OPT_P_CONNECTION, option_types_found, es); + read_config_string("[CONNECTION-OPTIONS]", &sub, p[1], msgleve= l, OPT_P_CONNECTION, + option_types_found, es); if (!sub.ce.remote) { - msg(msglevel, "Each 'connection' block must contain exactl= y one 'remote' directive"); + msg(msglevel, + "Each 'connection' block must contain exactly one 'rem= ote' directive"); uninit_options(&sub); goto err; } @@ -6263,16 +6138,14 @@ } /* add number of options already ignored */ - for (i =3D 0; options->ignore_unknown_option - && options->ignore_unknown_option[i]; i++) + for (i =3D 0; options->ignore_unknown_option && options->ignore_un= known_option[i]; i++) { numignored++; } /* Allocate array */ - ALLOC_ARRAY_GC(ignore, const char *, numignored+1, &options->gc); - for (i =3D 0; options->ignore_unknown_option - && options->ignore_unknown_option[i]; i++) + ALLOC_ARRAY_GC(ignore, const char *, numignored + 1, &options->gc); + for (i =3D 0; options->ignore_unknown_option && options->ignore_un= known_option[i]; i++) { ignore[i] =3D options->ignore_unknown_option[i]; } @@ -6282,9 +6155,9 @@ for (j =3D 1; p[j]; j++) { /* Allow the user to specify ignore-unknown-option --opt too */ - if (p[j][0]=3D=3D'-' && p[j][1]=3D=3D'-') + if (p[j][0] =3D=3D '-' && p[j][1] =3D=3D '-') { - options->ignore_unknown_option[i] =3D (p[j]+2); + options->ignore_unknown_option[i] =3D (p[j] + 2); } else { @@ -6313,7 +6186,7 @@ re.proto =3D -1; re.af =3D 0; - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); re.remote =3D p[1]; if (p[2]) { @@ -6324,9 +6197,7 @@ const sa_family_t af =3D ascii2af(p[3]); if (proto < 0) { - msg(msglevel, - "remote: bad protocol associated with host %s: '%s= '", - p[1], p[3]); + msg(msglevel, "remote: bad protocol associated with ho= st %s: '%s'", p[1], p[3]); goto err; } re.proto =3D proto; @@ -6372,7 +6243,7 @@ } else if (streq(p[0], "connect-retry") && p[1] && !p[3]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); options->ce.connect_retry_seconds =3D positive_atoi(p[1], msglevel= ); /* * Limit the base value of retry wait interval to 16 bits to avoid @@ -6391,15 +6262,15 @@ max_int(positive_atoi(p[2], msglevel), options->ce.connect= _retry_seconds); } } - else if ((streq(p[0], "connect-timeout") || streq(p[0], "server-poll-t= imeout")) - && p[1] && !p[2]) + else if ((streq(p[0], "connect-timeout") || streq(p[0], "server-poll-t= imeout")) && p[1] + && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); options->ce.connect_timeout =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "connect-retry-max") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); options->connect_retry_max =3D positive_atoi(p[1], msglevel); } else if (streq(p[0], "ipchange") && p[1]) @@ -6409,14 +6280,12 @@ { goto err; } - set_user_script(options, - &options->ipchange, - string_substitute(p[1], ',', ' ', &options->gc), - "ipchange", true); + set_user_script(options, &options->ipchange, + string_substitute(p[1], ',', ' ', &options->gc), "= ipchange", true); } else if (streq(p[0], "float") && !p[1]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); options->ce.remote_float =3D true; } #ifdef ENABLE_DEBUG @@ -6504,7 +6373,9 @@ { if (!didit) { - msg(M_WARN, "WARNING: Multiple --daemon directives specifi= ed, ignoring --daemon %s. (Note that initscripts sometimes add their own --= daemon directive.)", p[1]); + msg(M_WARN, + "WARNING: Multiple --daemon directives specified, igno= ring --daemon %s. (Note that initscripts sometimes add their own --daemon d= irective.)", + p[1]); goto err; } } @@ -6566,7 +6437,8 @@ /* Warn when a debug verbosity is supplied when built without debu= g support */ if (options->verbosity >=3D 7) { - msg(M_WARN, "NOTE: debug verbosity (--verb %d) is enabled but = this build lacks debug support.", + msg(M_WARN, + "NOTE: debug verbosity (--verb %d) is enabled but this bui= ld lacks debug support.", options->verbosity); } #endif @@ -6622,13 +6494,13 @@ } else if ((streq(p[0], "link-mtu") || streq(p[0], "udp-mtu")) && p[1] &= & !p[2]) { - VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); options->ce.link_mtu =3D positive_atoi(p[1], msglevel); options->ce.link_mtu_defined =3D true; } else if (streq(p[0], "tun-mtu") && p[1] && !p[3]) { - VERIFY_PERMISSION(OPT_P_PUSH_MTU|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_PUSH_MTU | OPT_P_CONNECTION); options->ce.tun_mtu =3D positive_atoi(p[1], msglevel); options->ce.tun_mtu_defined =3D true; if (p[2]) @@ -6642,7 +6514,7 @@ } else if (streq(p[0], "tun-mtu-max") && p[1] && !p[3]) { - VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); int max_mtu =3D positive_atoi(p[1], msglevel); if (max_mtu < 68 || max_mtu > 65536) { @@ -6655,22 +6527,23 @@ } else if (streq(p[0], "tun-mtu-extra") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); options->ce.tun_mtu_extra =3D positive_atoi(p[1], msglevel); options->ce.tun_mtu_extra_defined =3D true; } else if (streq(p[0], "max-packet-size") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); int maxmtu =3D positive_atoi(p[1], msglevel); options->ce.tls_mtu =3D constrain_int(maxmtu, TLS_CHANNEL_MTU_MIN,= TLS_CHANNEL_BUF_SIZE); if (maxmtu < TLS_CHANNEL_MTU_MIN || maxmtu > TLS_CHANNEL_BUF_SIZE) { - msg(M_WARN, "Note: max-packet-size value outside of allowed " + msg(M_WARN, + "Note: max-packet-size value outside of allowed " "control channel packet size (%d to %d), will use %d " - "instead.", TLS_CHANNEL_MTU_MIN, TLS_CHANNEL_BUF_SIZE, - options->ce.tls_mtu); + "instead.", + TLS_CHANNEL_MTU_MIN, TLS_CHANNEL_BUF_SIZE, options->ce.tls= _mtu); } /* also set mssfix maxmtu mtu */ @@ -6681,13 +6554,13 @@ #ifdef ENABLE_FRAGMENT else if (streq(p[0], "mtu-dynamic")) { - VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); msg(msglevel, "--mtu-dynamic has been replaced by --fragment"); goto err; } else if (streq(p[0], "fragment") && p[1] && !p[3]) { - VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); options->ce.fragment =3D positive_atoi(p[1], msglevel); if (options->ce.fragment < 68) @@ -6708,7 +6581,7 @@ #endif /* ifdef ENABLE_FRAGMENT */ else if (streq(p[0], "mtu-disc") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); options->ce.mtu_discover_type =3D translate_mtu_discover_type_name= (p[1]); } else if (streq(p[0], "mtu-test") && !p[1]) @@ -6779,20 +6652,19 @@ shaper =3D atoi_warn(p[1], msglevel); if (shaper < SHAPER_MIN || shaper > SHAPER_MAX) { - msg(msglevel, "Bad shaper value, must be between %d and %d", - SHAPER_MIN, SHAPER_MAX); + msg(msglevel, "Bad shaper value, must be between %d and %d", S= HAPER_MIN, SHAPER_MAX); goto err; } options->shaper =3D shaper; } else if (streq(p[0], "port") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); options->ce.local_port =3D options->ce.remote_port =3D p[1]; } else if (streq(p[0], "lport") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); /* only trigger bind() if port is not 0 (or --local is used) */ if (!streq(p[1], "0")) @@ -6803,22 +6675,21 @@ } else if (streq(p[0], "rport") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); options->ce.remote_port =3D p[1]; } else if (streq(p[0], "bind") && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); options->ce.bind_defined =3D true; if (p[1] && streq(p[1], "ipv6only")) { options->ce.bind_ipv6_only =3D true; } - } else if (streq(p[0], "nobind") && !p[1]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); options->ce.bind_local =3D false; } else if (streq(p[0], "fast-io") && !p[1]) @@ -6836,11 +6707,12 @@ options->inactivity_minimum_bytes =3D (val < 0) ? 0 : val; if (options->inactivity_minimum_bytes > INT_MAX) { - msg(M_WARN, "WARNING: '--inactive' with a 'bytes' value" + msg(M_WARN, + "WARNING: '--inactive' with a 'bytes' value" " >2 Gbyte was silently ignored in older versions. If= " " your VPN exits unexpectedly with 'Inactivity timeout= '" " in %d seconds, revisit this value.", - options->inactivity_timeout ); + options->inactivity_timeout); } } } @@ -6853,14 +6725,12 @@ { int proto; sa_family_t af; - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); proto =3D ascii2proto(p[1]); af =3D ascii2af(p[1]); if (proto < 0) { - msg(msglevel, - "Bad protocol: '%s'. Allowed protocols with --proto option= : %s", - p[1], + msg(msglevel, "Bad protocol: '%s'. Allowed protocols with --pr= oto option: %s", p[1], proto2ascii_all(&gc)); goto err; } @@ -6883,7 +6753,7 @@ { struct http_proxy_options *ho; - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); { if (!p[2]) @@ -6929,29 +6799,30 @@ else if (streq(p[0], "http-proxy-user-pass") && p[1]) { struct http_proxy_options *ho; - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); ho =3D init_http_proxy_options_once(&options->ce.http_proxy_option= s, &options->gc); ho->auth_file_up =3D p[1]; ho->inline_creds =3D is_inline; } else if (streq(p[0], "http-proxy-retry") || streq(p[0], "socks-proxy-r= etry")) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); msg(M_WARN, "DEPRECATED OPTION: http-proxy-retry and socks-proxy-r= etry: " - "In OpenVPN 2.4 proxy connection retries are handled like regu= lar connections. " - "Use connect-retry-max 1 to get a similar behavior as before."= ); + "In OpenVPN 2.4 proxy connection retries are handled l= ike regular connections. " + "Use connect-retry-max 1 to get a similar behavior as = before."); } else if (streq(p[0], "http-proxy-timeout") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); - msg(M_WARN, "DEPRECATED OPTION: http-proxy-timeout: In OpenVPN 2.4= the timeout until a connection to a " + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); + msg(M_WARN, + "DEPRECATED OPTION: http-proxy-timeout: In OpenVPN 2.4 the tim= eout until a connection to a " "server is established is managed with a single timeout set by= connect-timeout"); } else if (streq(p[0], "http-proxy-option") && p[1] && !p[4]) { struct http_proxy_options *ho; - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); ho =3D init_http_proxy_options_once(&options->ce.http_proxy_option= s, &options->gc); if (streq(p[1], "VERSION") && p[2] && !p[3]) @@ -6981,7 +6852,8 @@ } if (!custom_header) { - msg(msglevel, "Cannot use more than %d http-proxy-option C= USTOM-HEADER : '%s'", MAX_CUSTOM_HTTP_HEADER, p[1]); + msg(msglevel, "Cannot use more than %d http-proxy-option C= USTOM-HEADER : '%s'", + MAX_CUSTOM_HTTP_HEADER, p[1]); } else { @@ -6998,7 +6870,7 @@ } else if (streq(p[0], "socks-proxy") && p[1] && !p[4]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); if (p[2]) { @@ -7041,7 +6913,7 @@ } else if (streq(p[0], "explicit-exit-notify") && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION|OPT_P_EXPLICIT_NO= TIFY); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION | OPT_P_EXPLICI= T_NOTIFY); if (p[1]) { options->ce.explicit_exit_notification =3D positive_atoi(p[1],= msglevel); @@ -7060,7 +6932,7 @@ { VERIFY_PERMISSION(OPT_P_PERSIST); msg(M_WARN, "DEPRECATED: --persist-key option ignored. " - "Keys are now always persisted across restarts. "); + "Keys are now always persisted across restarts. "); } else if (streq(p[0], "persist-local-ip") && !p[1]) { @@ -7092,7 +6964,8 @@ rol_check_alloc(options); if (pull_mode) { - if (!ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) && !i= s_special_addr(p[1])) /* FQDN -- may be DNS name */ + if (!ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) + && !is_special_addr(p[1])) /* FQDN -- may be DNS name */ { msg(msglevel, "route parameter network/IP '%s' must be a v= alid address", p[1]); goto err; @@ -7102,14 +6975,16 @@ msg(msglevel, "route parameter netmask '%s' must be an IP = address", p[2]); goto err; } - if (p[3] && !ip_or_dns_addr_safe(p[3], options->allow_pull_fqd= n) && !is_special_addr(p[3])) /* FQDN -- may be DNS name */ + if (p[3] && !ip_or_dns_addr_safe(p[3], options->allow_pull_fqd= n) + && !is_special_addr(p[3])) /* FQDN -- may be DNS name */ { msg(msglevel, "route parameter gateway '%s' must be a vali= d address", p[3]); goto err; } /* p[4] is metric, if specified */ } - add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4], = options->route_default_table_id); + add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4], + options->route_default_table_id); } else if (streq(p[0], "route-ipv6") && p[1] && !p[4]) { @@ -7129,14 +7004,15 @@ } /* p[3] is metric, if specified */ } - add_route_ipv6_to_option_list(options->routes_ipv6, p[1], p[2], p[= 3], options->route_default_table_id); + add_route_ipv6_to_option_list(options->routes_ipv6, p[1], p[2], p[= 3], + options->route_default_table_id); } else if (streq(p[0], "max-routes") && !p[2]) { msg(M_WARN, "DEPRECATED OPTION: --max-routes option ignored. " - "The number of routes is unlimited as of OpenVPN 2.4. " - "This option will be removed in a future version, " - "please remove it from your configuration."); + "The number of routes is unlimited as of OpenVPN 2.4. " + "This option will be removed in a future version, " + "please remove it from your configuration."); } else if (streq(p[0], "route-gateway") && p[1] && !p[2]) { @@ -7147,7 +7023,8 @@ } else { - if (ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) || is_= special_addr(p[1])) /* FQDN -- may be DNS name */ + if (ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) + || is_special_addr(p[1])) /* FQDN -- may be DNS name */ { options->route_default_gateway =3D p[1]; } @@ -7208,10 +7085,7 @@ { goto err; } - set_user_script(options, - &options->route_predown_script, - p[1], - "route-pre-down", true); + set_user_script(options, &options->route_predown_script, p[1], "ro= ute-pre-down", true); } else if (streq(p[0], "route-noexec") && !p[1]) { @@ -7262,11 +7136,10 @@ if (options->routes->flags & RG_ENABLE) { - msg(M_WARN, - "WARNING: You have specified redirect-gateway and " - "redirect-private at the same time (or the same option " - "multiple times). This is not well supported and may lead = to " - "unexpected results"); + msg(M_WARN, "WARNING: You have specified redirect-gateway and " + "redirect-private at the same time (or the same op= tion " + "multiple times). This is not well supported and m= ay lead to " + "unexpected results"); } options->routes->flags |=3D RG_ENABLE; @@ -7366,8 +7239,7 @@ unsigned int major, minor, patch; if (!(sscanf(p[1], "%u.%u.%u", &major, &minor, &patch) =3D=3D 3)) { - msg(msglevel, "cannot parse version number for --compat-mode: = %s", - p[1]); + msg(msglevel, "cannot parse version number for --compat-mode: = %s", p[1]); goto err; } @@ -7385,14 +7257,13 @@ } else if (streq(p[0], "mssfix") && !p[3]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); if (p[1]) { int mssfix =3D positive_atoi(p[1], msglevel); /* can be 0, but otherwise it needs to be high enough so we can * substract room for headers. */ - if (mssfix !=3D 0 - && (mssfix < TLS_CHANNEL_MTU_MIN || mssfix > UINT16_MAX)) + if (mssfix !=3D 0 && (mssfix < TLS_CHANNEL_MTU_MIN || mssfix >= UINT16_MAX)) { msg(msglevel, "--mssfix value '%s' is invalid", p[1]); goto err; @@ -7468,15 +7339,14 @@ unsigned int netbits =3D 0; VERIFY_PERMISSION(OPT_P_GENERAL); - if (!get_ipv6_addr(p[1], &network, &netbits, lev) ) + if (!get_ipv6_addr(p[1], &network, &netbits, lev)) { msg(msglevel, "error parsing --server-ipv6 parameter"); goto err; } if (netbits < 64 || netbits > 124) { - msg(msglevel, - "--server-ipv6 settings: network must be between /64 and /= 124 (not /%d)", + msg(msglevel, "--server-ipv6 settings: network must be between= /64 and /124 (not /%d)", netbits); goto err; @@ -7581,7 +7451,7 @@ unsigned int netbits =3D 0; VERIFY_PERMISSION(OPT_P_GENERAL); - if (!get_ipv6_addr(p[1], &network, &netbits, lev ) ) + if (!get_ipv6_addr(p[1], &network, &netbits, lev)) { msg(msglevel, "error parsing --ifconfig-ipv6-pool parameters"); goto err; @@ -7670,7 +7540,8 @@ else if (streq(p[0], "client-cert-not-required") && !p[1]) { VERIFY_PERMISSION(OPT_P_GENERAL); - msg(M_FATAL, "REMOVED OPTION: --client-cert-not-required, use '--v= erify-client-cert none' instead"); + msg(M_FATAL, + "REMOVED OPTION: --client-cert-not-required, use '--verify-cli= ent-cert none' instead"); } else if (streq(p[0], "verify-client-cert") && !p[2]) { @@ -7691,7 +7562,8 @@ } else if (!streq(p[1], "require")) { - msg(msglevel, "parameter to --verify-client-cert must be '= none', 'optional' or 'require'"); + msg(msglevel, + "parameter to --verify-client-cert must be 'none', 'op= tional' or 'require'"); goto err; } } @@ -7710,7 +7582,7 @@ { VERIFY_PERMISSION(OPT_P_GENERAL); msg(M_INFO, "DEPRECATION: opt-verify is deprecated and will be rem= oved " - "in OpenVPN 2.7"); + "in OpenVPN 2.7"); options->ssl_flags |=3D SSLF_OPT_VERIFY; } else if (streq(p[0], "auth-user-pass-verify") && p[1]) @@ -7732,18 +7604,19 @@ } else { - msg(msglevel, "second parm to --auth-user-pass-verify must= be 'via-env' or 'via-file'"); + msg(msglevel, + "second parm to --auth-user-pass-verify must be 'via-e= nv' or 'via-file'"); goto err; } } else { - msg(msglevel, "--auth-user-pass-verify requires a second param= eter ('via-env' or 'via-file')"); + msg(msglevel, + "--auth-user-pass-verify requires a second parameter ('via= -env' or 'via-file')"); goto err; } - set_user_script(options, - &options->auth_user_pass_verify_script, - p[1], "auth-user-pass-verify", true); + set_user_script(options, &options->auth_user_pass_verify_script, p= [1], + "auth-user-pass-verify", true); } else if (streq(p[0], "auth-gen-token")) { @@ -7767,14 +7640,12 @@ msg(msglevel, "Invalid argument to auth-gen-token: %s (%d)= ", p[i], i); } } - } else if (streq(p[0], "auth-gen-token-secret") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); options->auth_token_secret_file =3D p[1]; options->auth_token_secret_file_inline =3D is_inline; - } else if (streq(p[0], "client-connect") && p[1]) { @@ -7783,8 +7654,7 @@ { goto err; } - set_user_script(options, &options->client_connect_script, - p[1], "client-connect", true); + set_user_script(options, &options->client_connect_script, p[1], "c= lient-connect", true); } else if (streq(p[0], "client-crresponse") && p[1]) { @@ -7793,8 +7663,8 @@ { goto err; } - set_user_script(options, &options->client_crresponse_script, - p[1], "client-crresponse", true); + set_user_script(options, &options->client_crresponse_script, p[1],= "client-crresponse", + true); } else if (streq(p[0], "client-disconnect") && p[1]) { @@ -7803,8 +7673,8 @@ { goto err; } - set_user_script(options, &options->client_disconnect_script, - p[1], "client-disconnect", true); + set_user_script(options, &options->client_disconnect_script, p[1],= "client-disconnect", + true); } else if (streq(p[0], "learn-address") && p[1]) { @@ -7813,8 +7683,7 @@ { goto err; } - set_user_script(options, &options->learn_address_script, - p[1], "learn-address", true); + set_user_script(options, &options->learn_address_script, p[1], "le= arn-address", true); } else if (streq(p[0], "tmp-dir") && p[1] && !p[2]) { @@ -7889,8 +7758,8 @@ in_addr_t local, remote_netmask; VERIFY_PERMISSION(OPT_P_INSTANCE); - local =3D getaddr(GETADDR_HOST_ORDER|GETADDR_RESOLVE, p[1], 0, NUL= L, NULL); - remote_netmask =3D getaddr(GETADDR_HOST_ORDER|GETADDR_RESOLVE, p[2= ], 0, NULL, NULL); + local =3D getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, N= ULL, NULL); + remote_netmask =3D getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p= [2], 0, NULL, NULL); if (local && remote_netmask) { options->push_ifconfig_defined =3D true; @@ -7898,7 +7767,8 @@ options->push_ifconfig_remote_netmask =3D remote_netmask; if (p[3]) { - options->push_ifconfig_local_alias =3D getaddr(GETADDR_HOS= T_ORDER|GETADDR_RESOLVE, p[3], 0, NULL, NULL); + options->push_ifconfig_local_alias =3D + getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[3], 0,= NULL, NULL); } } else @@ -7912,7 +7782,7 @@ in_addr_t network, netmask; VERIFY_PERMISSION(OPT_P_GENERAL); - network =3D getaddr(GETADDR_HOST_ORDER|GETADDR_RESOLVE, p[1], 0, N= ULL, NULL); + network =3D getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0,= NULL, NULL); netmask =3D getaddr(GETADDR_HOST_ORDER, p[2], 0, NULL, NULL); if (network && netmask) { @@ -7933,7 +7803,7 @@ VERIFY_PERMISSION(OPT_P_INSTANCE); - if (!get_ipv6_addr( p[1], &local, &netbits, msglevel ) ) + if (!get_ipv6_addr(p[1], &local, &netbits, msglevel)) { msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses"); goto err; @@ -7941,19 +7811,19 @@ if (p[2]) { - if (!get_ipv6_addr( p[2], &remote, NULL, msglevel ) ) + if (!get_ipv6_addr(p[2], &remote, NULL, msglevel)) { - msg( msglevel, "cannot parse --ifconfig-ipv6-push addresse= s"); + msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses= "); goto err; } } else { if (!options->ifconfig_ipv6_local - || !get_ipv6_addr( options->ifconfig_ipv6_local, &remote, - NULL, msglevel ) ) + || !get_ipv6_addr(options->ifconfig_ipv6_local, &remote, N= ULL, msglevel)) { - msg( msglevel, "second argument to --ifconfig-ipv6-push mi= ssing and no global --ifconfig-ipv6 address set"); + msg(msglevel, + "second argument to --ifconfig-ipv6-push missing and n= o global --ifconfig-ipv6 address set"); goto err; } } @@ -7974,8 +7844,10 @@ VERIFY_PERMISSION(OPT_P_INSTANCE); if (strlen(p[1]) > USER_PASS_LEN) { - msg(msglevel, "override-username exceeds the maximum length of= %d " - "characters", USER_PASS_LEN); + msg(msglevel, + "override-username exceeds the maximum length of %d " + "characters", + USER_PASS_LEN); /* disable the connection since ignoring the request to * set another username might cause serious problems */ @@ -8011,7 +7883,7 @@ msg(msglevel, "--stale-routes-check aging time and check inter= val must be >=3D 1"); goto err; } - options->stale_routes_ageing_time =3D ageing_time; + options->stale_routes_ageing_time =3D ageing_time; options->stale_routes_check_interval =3D check_interval; } @@ -8032,7 +7904,7 @@ } else if (streq(p[0], "auth-user-pass") && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); if (p[1]) { options->auth_user_pass_file =3D p[1]; @@ -8073,15 +7945,15 @@ #ifdef _WIN32 VERIFY_PERMISSION(OPT_P_GENERAL); HANDLE process =3D GetCurrentProcess(); - HANDLE handle =3D (HANDLE) ((intptr_t) atoll(p[1])); - if (!DuplicateHandle(process, handle, process, &options->msg_chann= el, 0, - FALSE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAM= E_ACCESS)) + HANDLE handle =3D (HANDLE)((intptr_t)atoll(p[1])); + if (!DuplicateHandle(process, handle, process, &options->msg_chann= el, 0, FALSE, + DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCES= S)) { msg(msglevel, "could not duplicate service pipe handle"); goto err; } options->route_method =3D ROUTE_METHOD_SERVICE; -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ msg(msglevel, "--msg-channel is only supported on Windows"); goto err; #endif @@ -8093,8 +7965,8 @@ if (streq(p[1], "env")) { msg(M_INFO, "NOTE: --win-sys env is default from OpenVPN 2.3. = " - "This entry will now be ignored. " - "Please remove this entry from your configuration file."); + "This entry will now be ignored. " + "Please remove this entry from your configuration = file."); } else { @@ -8131,9 +8003,7 @@ if (index < 0) { - msg(msglevel, - "Bad --ip-win32 method: '%s'. Allowed methods: %s", - p[1], + msg(msglevel, "Bad --ip-win32 method: '%s'. Allowed methods: = %s", p[1], ipset2ascii_all(&gc)); goto err; } @@ -8153,7 +8023,9 @@ if (!(offset > -256 && offset < 256)) { - msg(msglevel, "--ip-win32 dynamic [offset] [lease-= time]: offset (%d) must be > -256 and < 256", offset); + msg(msglevel, + "--ip-win32 dynamic [offset] [lease-time]: off= set (%d) must be > -256 and < 256", + offset); goto err; } @@ -8168,7 +8040,9 @@ lease_time =3D atoi_warn(p[3], msglevel); if (lease_time < min_lease) { - msg(msglevel, "--ip-win32 dynamic [offset] [lease-= time]: lease time parameter (%d) must be at least %d seconds", lease_time, = min_lease); + msg(msglevel, + "--ip-win32 dynamic [offset] [lease-time]: lea= se time parameter (%d) must be at least %d seconds", + lease_time, min_lease); goto err; } to->dhcp_lease_time =3D lease_time; @@ -8218,7 +8092,8 @@ if (streq(p[1], "search-domains") && p[2]) { - dns_domain_list_append(&options->dns_options.search_domains, &= p[2], &options->dns_options.gc); + dns_domain_list_append(&options->dns_options.search_domains, &= p[2], + &options->dns_options.gc); } else if (streq(p[1], "server") && p[2] && p[3] && p[4]) { @@ -8229,7 +8104,8 @@ goto err; } - struct dns_server *server =3D dns_server_get(&options->dns_opt= ions.servers, priority, &options->dns_options.gc); + struct dns_server *server =3D + dns_server_get(&options->dns_options.servers, priority, &o= ptions->dns_options.gc); if (streq(p[3], "address") && p[4]) { @@ -8237,7 +8113,9 @@ { if (!dns_server_addr_parse(server, p[i])) { - msg(msglevel, "--dns server %ld: malformed address= or maximum exceeded '%s'", priority, p[i]); + msg(msglevel, + "--dns server %ld: malformed address or maximu= m exceeded '%s'", + priority, p[i]); goto err; } } @@ -8282,7 +8160,8 @@ } else { - msg(msglevel, "--dns server %ld: malformed transport v= alue '%s'", priority, p[4]); + msg(msglevel, "--dns server %ld: malformed transport v= alue '%s'", priority, + p[4]); goto err; } } @@ -8292,7 +8171,9 @@ } else { - msg(msglevel, "--dns server %ld: unknown option type '%s' = or missing or unknown parameter", priority, p[3]); + msg(msglevel, + "--dns server %ld: unknown option type '%s' or missing= or unknown parameter", + priority, p[3]); goto err; } } @@ -8384,10 +8265,11 @@ #endif else { - msg(msglevel, "--dhcp-option: unknown option type '%s' or miss= ing or unknown parameter", p[1]); + msg(msglevel, "--dhcp-option: unknown option type '%s' or miss= ing or unknown parameter", + p[1]); goto err; } -#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */ +#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */ setenv_foreign_option(options, (const char **)p, 3, es); #endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */ } @@ -8395,14 +8277,14 @@ else if (streq(p[0], "show-adapters") && !p[1]) { VERIFY_PERMISSION(OPT_P_GENERAL); - show_tap_win_adapters(M_INFO|M_NOPREFIX, M_WARN|M_NOPREFIX); + show_tap_win_adapters(M_INFO | M_NOPREFIX, M_WARN | M_NOPREFIX); openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */ } else if (streq(p[0], "show-net") && !p[1]) { VERIFY_PERMISSION(OPT_P_GENERAL); - show_routes(M_INFO|M_NOPREFIX); - show_adapters(M_INFO|M_NOPREFIX); + show_routes(M_INFO | M_NOPREFIX); + show_adapters(M_INFO | M_NOPREFIX); openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */ } else if (streq(p[0], "show-net-up") && !p[1]) @@ -8551,19 +8433,20 @@ if (streq(p[1], "no")) { - options->comp.flags =3D - COMP_F_ALLOW_STUB_ONLY|COMP_F_ADVERTISE_STUBS_ONLY; + options->comp.flags =3D COMP_F_ALLOW_STUB_ONLY | COMP_F_ADVERT= ISE_STUBS_ONLY; if (comp_non_stub_enabled(&options->comp)) { msg(msglevel, "'--allow-compression no' conflicts with " - " enabling compression"); + " enabling compression"); } } else if (options->comp.flags & COMP_F_ALLOW_STUB_ONLY) { /* Also printed on a push to hint at configuration problems */ - msg(msglevel, "Cannot set allow-compression to '%s' " - "after set to 'no'", p[1]); + msg(msglevel, + "Cannot set allow-compression to '%s' " + "after set to 'no'", + p[1]); goto err; } else if (streq(p[1], "asym")) @@ -8572,15 +8455,18 @@ } else if (streq(p[1], "yes")) { - msg(M_WARN, "DEPRECATED OPTION: \"--allow-compression yes\" ha= s been removed. " + msg(M_WARN, + "DEPRECATED OPTION: \"--allow-compression yes\" has been r= emoved. " "We will use \"asym\" mode instead. See the manual page fo= r more information."); options->comp.flags |=3D COMP_F_ALLOW_ASYM; } else { - msg(msglevel, "bad allow-compression option: %s -- " - "must be 'yes', 'no', or 'asym'", p[1]); + msg(msglevel, + "bad allow-compression option: %s -- " + "must be 'yes', 'no', or 'asym'", + p[1]); goto err; } } @@ -8604,7 +8490,8 @@ */ else if (!(streq(p[1], "yes") || streq(p[1], "adaptive"))) { - msg(msglevel, "bad comp-lzo option: %s -- must be 'yes', '= no', or 'adaptive'", p[1]); + msg(msglevel, "bad comp-lzo option: %s -- must be 'yes', '= no', or 'adaptive'", + p[1]); goto err; } } @@ -8626,7 +8513,7 @@ if (streq(alg, "stub")) { options->comp.alg =3D COMP_ALG_STUB; - options->comp.flags |=3D (COMP_F_SWAP|COMP_F_ADVERTISE_STUBS_O= NLY); + options->comp.flags |=3D (COMP_F_SWAP | COMP_F_ADVERTISE_STUBS= _ONLY); } else if (streq(alg, "stub-v2")) { @@ -8679,7 +8566,7 @@ { int key_direction; - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); key_direction =3D ascii2keydirection(msglevel, p[1]); if (key_direction >=3D 0) @@ -8701,7 +8588,7 @@ else if (streq(p[0], "secret") && p[1] && !p[3]) { msg(M_WARN, "DEPRECATED OPTION: The option --secret is deprecated.= "); - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); options->shared_secret_file =3D p[1]; options->shared_secret_file_inline =3D is_inline; if (!is_inline && p[2]) @@ -8723,7 +8610,6 @@ { VERIFY_PERMISSION(OPT_P_GENERAL); options->allow_deprecated_insecure_static_crypto =3D true; - } else if (streq(p[0], "genkey") && !p[4]) { @@ -8735,8 +8621,7 @@ } else { - if (streq(p[1], "secret") || streq(p[1], "tls-auth") - || streq(p[1], "tls-crypt")) + if (streq(p[1], "secret") || streq(p[1], "tls-auth") || streq(= p[1], "tls-crypt")) { options->genkey_type =3D GENKEY_SECRET; } @@ -8760,7 +8645,6 @@ { msg(msglevel, "unknown --genkey type: %s", p[1]); } - } if (p[2]) { @@ -8774,23 +8658,22 @@ } else if (streq(p[0], "cipher") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_NCP|OPT_P_INSTANCE); + VERIFY_PERMISSION(OPT_P_NCP | OPT_P_INSTANCE); options->ciphername =3D p[1]; } else if (streq(p[0], "data-ciphers-fallback") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INSTANCE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INSTANCE); options->ciphername =3D p[1]; options->enable_ncp_fallback =3D true; } - else if ((streq(p[0], "data-ciphers") || streq(p[0], "ncp-ciphers")) - && p[1] && !p[2]) + else if ((streq(p[0], "data-ciphers") || streq(p[0], "ncp-ciphers")) &= & p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INSTANCE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INSTANCE); if (streq(p[0], "ncp-ciphers")) { msg(M_INFO, "Note: Treating option '--ncp-ciphers' as " - " '--data-ciphers' (renamed in OpenVPN 2.5)."); + " '--data-ciphers' (renamed in OpenVPN 2.5)."); } options->ncp_ciphers =3D p[1]; } @@ -8852,7 +8735,7 @@ VERIFY_PERMISSION(OPT_P_GENERAL); /* always error out, this breaks the connection */ msg(M_FATAL, "--no-replay was removed in OpenVPN 2.7. " - "Update your configuration."); + "Update your configuration."); } else if (streq(p[0], "replay-window") && !p[3]) { @@ -8865,9 +8748,7 @@ if (!(MIN_SEQ_BACKTRACK <=3D replay_window && replay_window <= =3D MAX_SEQ_BACKTRACK)) { msg(msglevel, "replay-window window size parameter (%d) mu= st be between %d and %d", - replay_window, - MIN_SEQ_BACKTRACK, - MAX_SEQ_BACKTRACK); + replay_window, MIN_SEQ_BACKTRACK, MAX_SEQ_BACKTRACK); goto err; } options->replay_window =3D replay_window; @@ -8879,10 +8760,9 @@ replay_time =3D atoi_warn(p[2], msglevel); if (!(MIN_TIME_BACKTRACK <=3D replay_time && replay_time <= =3D MAX_TIME_BACKTRACK)) { - msg(msglevel, "replay-window time window parameter (%d= ) must be between %d and %d", - replay_time, - MIN_TIME_BACKTRACK, - MAX_TIME_BACKTRACK); + msg(msglevel, + "replay-window time window parameter (%d) must be = between %d and %d", + replay_time, MIN_TIME_BACKTRACK, MAX_TIME_BACKTRAC= K); goto err; } options->replay_time =3D replay_time; @@ -8951,8 +8831,8 @@ { VERIFY_PERMISSION(OPT_P_GENERAL); msg(M_WARN, "Consider setting groups/curves preference with " - "tls-groups instead of forcing a specific curve with " - "ecdh-curve."); + "tls-groups instead of forcing a specific curve with " + "ecdh-curve."); options->ecdh_curve =3D p[1]; } else if (streq(p[0], "tls-server") && !p[1]) @@ -8967,7 +8847,7 @@ } else if (streq(p[0], "ca") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); options->ca_file =3D p[1]; options->ca_file_inline =3D is_inline; } @@ -8980,33 +8860,33 @@ #endif /* ENABLE_CRYPTO_MBEDTLS */ else if (streq(p[0], "dh") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); options->dh_file =3D p[1]; options->dh_file_inline =3D is_inline; } else if (streq(p[0], "cert") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); options->cert_file =3D p[1]; options->cert_file_inline =3D is_inline; } else if (streq(p[0], "extra-certs") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); options->extra_certs_file =3D p[1]; options->extra_certs_file_inline =3D is_inline; } else if ((streq(p[0], "verify-hash") && p[1] && !p[3]) || (streq(p[0], "peer-fingerprint") && p[1] && !p[2])) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); int verify_hash_depth =3D 0; if (streq(p[0], "verify-hash")) { msg(M_WARN, "DEPRECATED OPTION: The option --verify-hash is de= precated. " - "You should switch to the either use the level 1 certifica= te as " - "--ca option, use --tls-verify or use --peer-fingerprint"); + "You should switch to the either use the level 1 c= ertificate as " + "--ca option, use --tls-verify or use --peer-finge= rprint"); /* verify level 1 cert, i.e. the CA that signed the leaf cert = */ verify_hash_depth =3D 1; } @@ -9017,8 +8897,10 @@ if (options->verify_hash && options->verify_hash_depth !=3D verify= _hash_depth) { - msg(msglevel, "ERROR: Setting %s not allowed. --verify-hash an= d" - " --peer-fingerprint are mutually exclusive", p[0]); + msg(msglevel, + "ERROR: Setting %s not allowed. --verify-hash and" + " --peer-fingerprint are mutually exclusive", + p[0]); goto err; } @@ -9031,15 +8913,16 @@ } else if (p[2] && !streq(p[2], "SHA256")) { - msg(msglevel, "invalid or unsupported hashing algorithm: %= s " - "(only SHA1 and SHA256 are supported)", p[2]); + msg(msglevel, + "invalid or unsupported hashing algorithm: %s " + "(only SHA1 and SHA256 are supported)", + p[2]); goto err; } } struct verify_hash_list *newlist; - newlist =3D parse_hash_fingerprint_multiline(p[1], digest_len, - msglevel, &options->gc); + newlist =3D parse_hash_fingerprint_multiline(p[1], digest_len, msg= level, &options->gc); /* Append the new list to the end of our current list */ if (!options->verify_hash) @@ -9068,7 +8951,7 @@ #endif else if (streq(p[0], "key") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); options->priv_key_file =3D p[1]; options->priv_key_file_inline =3D is_inline; } @@ -9091,8 +8974,7 @@ } #endif - options->ssl_flags &=3D - ~(SSLF_TLS_VERSION_MIN_MASK << SSLF_TLS_VERSION_MIN_SHIFT); + options->ssl_flags &=3D ~(SSLF_TLS_VERSION_MIN_MASK << SSLF_TLS_VE= RSION_MIN_SHIFT); options->ssl_flags |=3D (ver << SSLF_TLS_VERSION_MIN_SHIFT); } else if (streq(p[0], "tls-version-max") && p[1] && !p[2]) @@ -9105,14 +8987,13 @@ msg(msglevel, "unknown tls-version-max parameter: %s", p[1]); goto err; } - options->ssl_flags &=3D - ~(SSLF_TLS_VERSION_MAX_MASK << SSLF_TLS_VERSION_MAX_SHIFT); + options->ssl_flags &=3D ~(SSLF_TLS_VERSION_MAX_MASK << SSLF_TLS_VE= RSION_MAX_SHIFT); options->ssl_flags |=3D (ver << SSLF_TLS_VERSION_MAX_SHIFT); } #ifndef ENABLE_CRYPTO_MBEDTLS else if (streq(p[0], "pkcs12") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); options->pkcs12_file =3D p[1]; options->pkcs12_file_inline =3D is_inline; } @@ -9185,10 +9066,9 @@ VERIFY_PERMISSION(OPT_P_GENERAL); options->tls_groups =3D p[1]; } - else if (streq(p[0], "crl-verify") && p[1] && ((p[2] && streq(p[2], "d= ir")) - || !p[2])) + else if (streq(p[0], "crl-verify") && p[1] && ((p[2] && streq(p[2], "d= ir")) || !p[2])) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE); if (p[2] && streq(p[2], "dir")) { options->ssl_flags |=3D SSLF_CRL_VERIFY_DIR; @@ -9204,8 +9084,7 @@ goto err; } set_user_script(options, &options->tls_verify, - string_substitute(p[1], ',', ' ', &options->gc), - "tls-verify", true); + string_substitute(p[1], ',', ' ', &options->gc), "= tls-verify", true); } else if (streq(p[0], "tls-export-cert") && p[1] && !p[2]) { @@ -9216,14 +9095,14 @@ { VERIFY_PERMISSION(OPT_P_GENERAL); msg(msglevel, "--compat-names was removed in OpenVPN 2.5. " - "Update your configuration."); + "Update your configuration."); goto err; } else if (streq(p[0], "no-name-remapping") && !p[1]) { VERIFY_PERMISSION(OPT_P_GENERAL); msg(msglevel, "--no-name-remapping was removed in OpenVPN 2.5. " - "Update your configuration."); + "Update your configuration."); goto err; } else if (streq(p[0], "verify-x509-name") && p[1] && strlen(p[1]) && !p= [3]) @@ -9282,7 +9161,7 @@ size_t j; for (j =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j) { - sscanf(p[j], "%x", &(options->remote_cert_ku[j-1])); + sscanf(p[j], "%x", &(options->remote_cert_ku[j - 1])); } if (j =3D=3D 1) { @@ -9367,7 +9246,7 @@ { int key_direction =3D -1; - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION | OPT_P_INLINE); if (permission_mask & OPT_P_GENERAL) { @@ -9383,7 +9262,6 @@ } options->key_direction =3D key_direction; } - } else if (permission_mask & OPT_P_CONNECTION) { @@ -9404,7 +9282,7 @@ } else if (streq(p[0], "tls-crypt") && p[1] && !p[3]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION | OPT_P_INLINE); if (permission_mask & OPT_P_GENERAL) { options->tls_crypt_file =3D p[1]; @@ -9418,7 +9296,7 @@ } else if (streq(p[0], "tls-crypt-v2") && p[1] && !p[3]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION|OPT_P_INLINE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION | OPT_P_INLINE); if (permission_mask & OPT_P_GENERAL) { options->tls_crypt_v2_file =3D p[1]; @@ -9461,19 +9339,19 @@ { char *s =3D p[j]; - if (strncmp("ext:", s, 4) =3D=3D 0 && !x509_username_field_ext= _supported(s+4)) + if (strncmp("ext:", s, 4) =3D=3D 0 && !x509_username_field_ext= _supported(s + 4)) { msg(msglevel, "Unsupported x509-username-field extension: = %s", s); } - options->x509_username_field[j-1] =3D p[j]; + options->x509_username_field[j - 1] =3D p[j]; } } #endif /* ENABLE_X509ALTUSERNAME */ #ifdef ENABLE_PKCS11 else if (streq(p[0], "show-pkcs11-ids") && !p[3]) { - char *provider =3D p[1]; - bool cert_private =3D (p[2] =3D=3D NULL ? false : (atoi_warn(p[2],= msglevel) !=3D 0 )); + char *provider =3D p[1]; + bool cert_private =3D (p[2] =3D=3D NULL ? false : (atoi_warn(p[2],= msglevel) !=3D 0)); #ifdef DEFAULT_PKCS11_MODULE if (!provider) @@ -9514,7 +9392,7 @@ for (j =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j) { - options->pkcs11_providers[j-1] =3D p[j]; + options->pkcs11_providers[j - 1] =3D p[j]; } } else if (streq(p[0], "pkcs11-protected-authentication")) @@ -9525,7 +9403,8 @@ for (j =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j) { - options->pkcs11_protected_authentication[j-1] =3D atoi_warn(p[= j], msglevel) !=3D 0 ? 1 : 0; + options->pkcs11_protected_authentication[j - 1] =3D + atoi_warn(p[j], msglevel) !=3D 0 ? 1 : 0; } } else if (streq(p[0], "pkcs11-private-mode") && p[1]) @@ -9536,7 +9415,7 @@ for (j =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j) { - sscanf(p[j], "%x", &(options->pkcs11_private_mode[j-1])); + sscanf(p[j], "%x", &(options->pkcs11_private_mode[j - 1])); } } else if (streq(p[0], "pkcs11-cert-private")) @@ -9547,7 +9426,7 @@ for (j =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j) { - options->pkcs11_cert_private[j-1] =3D (bool) (atoi_warn(p[j], = msglevel)); + options->pkcs11_cert_private[j - 1] =3D (bool)(atoi_warn(p[j],= msglevel)); } } else if (streq(p[0], "pkcs11-pin-cache") && p[1] && !p[2]) @@ -9593,13 +9472,13 @@ if (strncmp(p[1], "EXPORTER", 8)) { msg(msglevel, "Keying material exporter label must begin with " - "\"EXPORTER\""); + "\"EXPORTER\""); goto err; } if (streq(p[1], EXPORT_KEY_DATA_LABEL)) { - msg(msglevel, "Keying material exporter label must not be '" - EXPORT_KEY_DATA_LABEL "'."); + msg(msglevel, + "Keying material exporter label must not be '" EXPORT_KEY_= DATA_LABEL "'."); } if (ekm_length < 16 || ekm_length > 4095) { @@ -9643,13 +9522,12 @@ } else if (streq(p[0], "vlan-pvid") && p[1] && !p[2]) { - VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INSTANCE); + VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INSTANCE); options->vlan_pvid =3D positive_atoi(p[1], msglevel); if (options->vlan_pvid < OPENVPN_8021Q_MIN_VID || options->vlan_pvid > OPENVPN_8021Q_MAX_VID) { - msg(msglevel, - "the parameter of --vlan-pvid parameters must be >=3D %u a= nd <=3D %u", + msg(msglevel, "the parameter of --vlan-pvid parameters must be= >=3D %u and <=3D %u", OPENVPN_8021Q_MIN_VID, OPENVPN_8021Q_MAX_VID); goto err; } @@ -9670,11 +9548,14 @@ } if (file) { - msg(msglevel_unknown, "Unrecognized option or missing or extra= parameter(s) in %s:%d: %s (%s)", file, line, p[0], PACKAGE_VERSION); + msg(msglevel_unknown, + "Unrecognized option or missing or extra parameter(s) in %= s:%d: %s (%s)", file, + line, p[0], PACKAGE_VERSION); } else { - msg(msglevel_unknown, "Unrecognized option or missing or extra= parameter(s): --%s (%s)", p[0], PACKAGE_VERSION); + msg(msglevel_unknown, "Unrecognized option or missing or extra= parameter(s): --%s (%s)", + p[0], PACKAGE_VERSION); } } err: diff --git a/src/openvpn/options.h b/src/openvpn/options.h index 56e85d7..0855ec8 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -122,33 +122,34 @@ const char *socks_proxy_port; const char *socks_proxy_authfile; - int tun_mtu; /* MTU of tun device */ - int occ_mtu; /* if non-null, this is the MTU we announce to pe= ers in OCC */ - int tun_mtu_max; /* maximum MTU that can be pushed */ + int tun_mtu; /* MTU of tun device */ + int occ_mtu; /* if non-null, this is the MTU we announce to p= eers in OCC */ + int tun_mtu_max; /* maximum MTU that can be pushed */ bool tun_mtu_defined; /* true if user overriding parm with command lin= e option */ int tun_mtu_extra; bool tun_mtu_extra_defined; - int link_mtu; /* MTU of device over which tunnel packets pass v= ia TCP/UDP */ + int link_mtu; /* MTU of device over which tunnel packets pass= via TCP/UDP */ bool link_mtu_defined; /* true if user overriding parm with command li= ne option */ - int tls_mtu; /* Maximum MTU for the control channel messages */ + int tls_mtu; /* Maximum MTU for the control channel messages= */ /* Advanced MTU negotiation and datagram fragmentation options */ int mtu_discover_type; /* used if OS supports setting Path MTU discove= ry options on socket */ - int fragment; /* internal fragmentation size */ - bool fragment_encap; /* true if --fragment had the "mtu" parameter to - * include overhead from IP and TCP/UDP encapsula= tion */ - int mssfix; /* Upper bound on TCP MSS */ - bool mssfix_default; /* true if --mssfix should use the default parame= ters */ - bool mssfix_encap; /* true if --mssfix had the "mtu" parameter to in= clude - * overhead from IP and TCP/UDP encapsulation */ - bool mssfix_fixed; /* use the mssfix value without any encapsulation= adjustments */ + int fragment; /* internal fragmentation size */ + bool fragment_encap; /* true if --fragment had the "mtu" parameter to + * include overhead from IP and TCP/UDP encapsu= lation */ + int mssfix; /* Upper bound on TCP MSS */ + bool mssfix_default; /* true if --mssfix should use the default para= meters */ + bool mssfix_encap; /* true if --mssfix had the "mtu" parameter to = include + * overhead from IP and TCP/UDP encapsulation */ + bool mssfix_fixed; /* use the mssfix value without any encapsulati= on adjustments */ - int explicit_exit_notification; /* Explicitly tell peer when we are ex= iting via OCC_EXIT or [RESTART] message */ + int explicit_exit_notification; /* Explicitly tell peer when we are ex= iting via OCC_EXIT or + [RESTART] message */ -#define CE_DISABLED (1<<0) -#define CE_MAN_QUERY_PROXY (1<<1) +#define CE_DISABLED (1 << 0) +#define CE_MAN_QUERY_PROXY (1 << 1) #define CE_MAN_QUERY_REMOTE_UNDEF 0 #define CE_MAN_QUERY_REMOTE_QUERY 1 #define CE_MAN_QUERY_REMOTE_ACCEPT 2 @@ -231,7 +232,8 @@ char port[RH_PORT_LEN]; }; -enum genkey_type { +enum genkey_type +{ GENKEY_SECRET, GENKEY_TLS_CRYPTV2_CLIENT, GENKEY_TLS_CRYPTV2_SERVER, @@ -338,32 +340,32 @@ bool mlock; - int keepalive_ping; /* a proxy for ping/ping-restart */ + int keepalive_ping; /* a proxy for ping/ping-restart */ int keepalive_timeout; - int inactivity_timeout; /* --inactive */ + int inactivity_timeout; /* --inactive */ int64_t inactivity_minimum_bytes; - int session_timeout; /* Force-kill session after n seconds */ + int session_timeout; /* Force-kill session after n seconds */ - int ping_send_timeout; /* Send a TCP/UDP ping to remote every n s= econds */ - int ping_rec_timeout; /* Expect a TCP/UDP ping from remote at le= ast once every n seconds */ - bool ping_timer_remote; /* Run ping timer only if we have a remote= address */ + int ping_send_timeout; /* Send a TCP/UDP ping to remote every n secon= ds */ + int ping_rec_timeout; /* Expect a TCP/UDP ping from remote at least = once every n seconds */ + bool ping_timer_remote; /* Run ping timer only if we have a remote add= ress */ #define PING_UNDEF 0 #define PING_EXIT 1 #define PING_RESTART 2 int ping_rec_timeout_action; /* What action to take on ping_rec_timeou= t (exit or restart)? */ - bool persist_tun; /* Don't close/reopen TUN/TAP dev on SIGUS= R1 or PING_RESTART */ - bool persist_local_ip; /* Don't re-resolve local address on SIGUS= R1 or PING_RESTART */ - bool persist_remote_ip; /* Don't re-resolve remote address on SIGU= SR1 or PING_RESTART */ + bool persist_tun; /* Don't close/reopen TUN/TAP dev on SIGU= SR1 or PING_RESTART */ + bool persist_local_ip; /* Don't re-resolve local address on SIGU= SR1 or PING_RESTART */ + bool persist_remote_ip; /* Don't re-resolve remote address on SIG= USR1 or PING_RESTART */ #if PASSTOS_CAPABILITY bool passtos; #endif - int resolve_retry_seconds; /* If hostname resolve fails, retry for n = seconds */ + int resolve_retry_seconds; /* If hostname resolve fails, retry for n s= econds */ bool resolve_in_advance; const char *ip_remote_hint; @@ -434,7 +436,7 @@ int route_delay_window; bool route_delay_defined; struct route_option_list *routes; - struct route_ipv6_option_list *routes_ipv6; /* IPv6 */ + struct route_ipv6_option_list *routes_ipv6; /* IPv6 */ bool block_ipv6; bool route_nopull; bool route_gateway_via_dhcp; @@ -469,13 +471,13 @@ bool server_defined; in_addr_t server_network; in_addr_t server_netmask; - bool server_ipv6_defined; /* IPv6 */ - struct in6_addr server_network_ipv6; /* IPv6 */ - unsigned int server_netbits_ipv6; /* IPv6 */ + bool server_ipv6_defined; /* IPv6 */ + struct in6_addr server_network_ipv6; /* IPv6 */ + unsigned int server_netbits_ipv6; /* IPv6 */ -#define SF_NOPOOL (1<<0) -#define SF_TCP_NODELAY_HELPER (1<<1) -#define SF_NO_PUSH_ROUTE_GATEWAY (1<<2) +#define SF_NOPOOL (1 << 0) +#define SF_TCP_NODELAY_HELPER (1 << 1) +#define SF_NO_PUSH_ROUTE_GATEWAY (1 << 2) unsigned int server_flags; bool server_bridge_proxy_dhcp; @@ -494,9 +496,9 @@ const char *ifconfig_pool_persist_filename; int ifconfig_pool_persist_refresh_freq; - bool ifconfig_ipv6_pool_defined; /* IPv6 */ - struct in6_addr ifconfig_ipv6_pool_base; /* IPv6 */ - int ifconfig_ipv6_pool_netbits; /* IPv6 */ + bool ifconfig_ipv6_pool_defined; /* IPv6 */ + struct in6_addr ifconfig_ipv6_pool_base; /* IPv6 */ + int ifconfig_ipv6_pool_netbits; /* IPv6 */ int real_hash_size; int virtual_hash_size; @@ -511,7 +513,7 @@ int n_bcast_buf; int tcp_queue_limit; struct iroute *iroutes; - struct iroute_ipv6 *iroutes_ipv6; /* IPv6 */ + struct iroute_ipv6 *iroutes_ipv6; /* IPv6 */ bool push_ifconfig_defined; in_addr_t push_ifconfig_local; in_addr_t push_ifconfig_remote_netmask; @@ -519,12 +521,12 @@ bool push_ifconfig_constraint_defined; in_addr_t push_ifconfig_constraint_network; in_addr_t push_ifconfig_constraint_netmask; - bool push_ifconfig_ipv4_blocked; /* IPv4 */ - bool push_ifconfig_ipv6_defined; /* IPv6 */ - struct in6_addr push_ifconfig_ipv6_local; /* IPv6 */ - int push_ifconfig_ipv6_netbits; /* IPv6 */ - struct in6_addr push_ifconfig_ipv6_remote; /* IPv6 */ - bool push_ifconfig_ipv6_blocked; /* IPv6 */ + bool push_ifconfig_ipv4_blocked; /* IPv4 */ + bool push_ifconfig_ipv6_defined; /* IPv6 */ + struct in6_addr push_ifconfig_ipv6_local; /* IPv6 */ + int push_ifconfig_ipv6_netbits; /* IPv6 */ + struct in6_addr push_ifconfig_ipv6_remote; /* IPv6 */ + bool push_ifconfig_ipv6_blocked; /* IPv6 */ bool enable_c2c; bool duplicate_cn; @@ -573,8 +575,8 @@ bool allow_deprecated_insecure_static_crypto; int key_direction; const char *ciphername; - bool enable_ncp_fallback; /**< If defined fall back to - * ciphername if NCP fails */ + bool enable_ncp_fallback; /**< If defined fall back to + * ciphername if NCP fails */ /** The original ncp_ciphers specified by the user in the configuratio= n*/ const char *ncp_ciphers_conf; const char *ncp_ciphers; @@ -728,40 +730,40 @@ /* * Option classes. */ -#define OPT_P_GENERAL (1<<0) -#define OPT_P_UP (1<<1) -#define OPT_P_ROUTE (1<<2) -#define OPT_P_DHCPDNS (1<<3) /* includes ip windows options lik= e */ -#define OPT_P_SCRIPT (1<<4) -#define OPT_P_SETENV (1<<5) -#define OPT_P_SHAPER (1<<6) -#define OPT_P_TIMER (1<<7) -#define OPT_P_PERSIST (1<<8) -#define OPT_P_PERSIST_IP (1<<9) -#define OPT_P_COMP (1<<10) /* TODO */ -#define OPT_P_MESSAGES (1<<11) -#define OPT_P_NCP (1<<12) /**< Negotiable crypto parameters */ -#define OPT_P_TLS_PARMS (1<<13) /* TODO */ -#define OPT_P_MTU (1<<14) /* TODO */ -#define OPT_P_NICE (1<<15) -#define OPT_P_PUSH (1<<16) -#define OPT_P_INSTANCE (1<<17) /**< allowed in ccd, client-connect = etc*/ -#define OPT_P_CONFIG (1<<18) -#define OPT_P_EXPLICIT_NOTIFY (1<<19) -#define OPT_P_ECHO (1<<20) -#define OPT_P_INHERIT (1<<21) -#define OPT_P_ROUTE_EXTRAS (1<<22) -#define OPT_P_PULL_MODE (1<<23) -#define OPT_P_PLUGIN (1<<24) -#define OPT_P_SOCKBUF (1<<25) -#define OPT_P_SOCKFLAGS (1<<26) -#define OPT_P_CONNECTION (1<<27) -#define OPT_P_PEER_ID (1<<28) -#define OPT_P_INLINE (1<<29) -#define OPT_P_PUSH_MTU (1<<30) -#define OPT_P_ROUTE_TABLE (1<<31) +#define OPT_P_GENERAL (1 << 0) +#define OPT_P_UP (1 << 1) +#define OPT_P_ROUTE (1 << 2) +#define OPT_P_DHCPDNS (1 << 3) /* includes ip windows options like= */ +#define OPT_P_SCRIPT (1 << 4) +#define OPT_P_SETENV (1 << 5) +#define OPT_P_SHAPER (1 << 6) +#define OPT_P_TIMER (1 << 7) +#define OPT_P_PERSIST (1 << 8) +#define OPT_P_PERSIST_IP (1 << 9) +#define OPT_P_COMP (1 << 10) /* TODO */ +#define OPT_P_MESSAGES (1 << 11) +#define OPT_P_NCP (1 << 12) /**< Negotiable crypto parameters = */ +#define OPT_P_TLS_PARMS (1 << 13) /* TODO */ +#define OPT_P_MTU (1 << 14) /* TODO */ +#define OPT_P_NICE (1 << 15) +#define OPT_P_PUSH (1 << 16) +#define OPT_P_INSTANCE (1 << 17) /**< allowed in ccd, client-connec= t etc*/ +#define OPT_P_CONFIG (1 << 18) +#define OPT_P_EXPLICIT_NOTIFY (1 << 19) +#define OPT_P_ECHO (1 << 20) +#define OPT_P_INHERIT (1 << 21) +#define OPT_P_ROUTE_EXTRAS (1 << 22) +#define OPT_P_PULL_MODE (1 << 23) +#define OPT_P_PLUGIN (1 << 24) +#define OPT_P_SOCKBUF (1 << 25) +#define OPT_P_SOCKFLAGS (1 << 26) +#define OPT_P_CONNECTION (1 << 27) +#define OPT_P_PEER_ID (1 << 28) +#define OPT_P_INLINE (1 << 29) +#define OPT_P_PUSH_MTU (1 << 30) +#define OPT_P_ROUTE_TABLE (1 << 31) -#define OPT_P_DEFAULT (~(OPT_P_INSTANCE|OPT_P_PULL_MODE)) +#define OPT_P_DEFAULT (~(OPT_P_INSTANCE | OPT_P_PULL_MODE)) #define PULL_DEFINED(opt) ((opt)->pull) #define PUSH_DEFINED(opt) ((opt)->push_list) @@ -794,12 +796,8 @@ #define MAN_CLIENT_AUTH_ENABLED(opt) (false) #endif -void parse_argv(struct options *options, - const int argc, - char *argv[], - const int msglevel, - const unsigned int permission_mask, - unsigned int *option_types_found, +void parse_argv(struct options *options, const int argc, char *argv[], con= st int msglevel, + const unsigned int permission_mask, unsigned int *option_t= ypes_found, struct env_set *es); void notnull(const char *arg, const char *description); @@ -827,12 +825,8 @@ const char *options_string_version(const char *s, struct gc_arena *gc); -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); +char *options_string(const struct options *o, const struct frame *frame, s= truct tuntap *tt, + openvpn_net_ctx_t *ctx, bool remote, struct gc_arena = *gc); bool options_cmp_equal_safe(char *actual, const char *expected, size_t act= ual_n); @@ -852,8 +846,8 @@ * @return gc-allocated value of option with name opt_name if option was f= ound, * or NULL otherwise. */ -char *options_string_extract_option(const char *options_string, - const char *opt_name, struct gc_arena = *gc); +char *options_string_extract_option(const char *options_string, const char= *opt_name, + struct gc_arena *gc); void options_postprocess(struct options *options, struct env_set *es); @@ -862,32 +856,21 @@ void pre_connect_restore(struct options *o, struct gc_arena *gc); -bool apply_push_options(struct options *options, - struct buffer *buf, - unsigned int permission_mask, - unsigned int *option_types_found, - struct env_set *es); +bool apply_push_options(struct options *options, struct buffer *buf, unsig= ned int permission_mask, + unsigned int *option_types_found, struct env_set *= es); void options_detach(struct options *o); -void options_server_import(struct options *o, - const char *filename, - int msglevel, - unsigned int permission_mask, - unsigned int *option_types_found, +void options_server_import(struct options *o, const char *filename, int ms= glevel, + unsigned int permission_mask, unsigned int *opt= ion_types_found, struct env_set *es); void pre_pull_default(struct options *o); void rol_check_alloc(struct options *options); -int parse_line(const char *line, - char *p[], - const int n, - const char *file, - const int line_num, - int msglevel, - struct gc_arena *gc); +int parse_line(const char *line, char *p[], const int n, const char *file,= const int line_num, + int msglevel, struct gc_arena *gc); /* * parse/print topology coding @@ -911,11 +894,8 @@ const char *auth_retry_print(void); -void options_string_import(struct options *options, - const char *config, - const int msglevel, - const unsigned int permission_mask, - unsigned int *option_types_found, +void options_string_import(struct options *options, const char *config, co= nst int msglevel, + const unsigned int permission_mask, unsigned in= t *option_types_found, struct env_set *es); bool key_is_external(const struct options *options); diff --git a/src/openvpn/options_util.c b/src/openvpn/options_util.c index 80d0c08..e2c445c 100644 --- a/src/openvpn/options_util.c +++ b/src/openvpn/options_util.c @@ -123,12 +123,11 @@ if (i < 0 || *endptr !=3D '\0' || i > INT_MAX) { - msg(msglevel, "Cannot parse argument '%s' as non-negative integer", - str); + msg(msglevel, "Cannot parse argument '%s' as non-negative integer"= , str); i =3D 0; } - return (int) i; + return (int)i; } int @@ -143,5 +142,5 @@ i =3D 0; } - return (int) i; + return (int)i; } diff --git a/src/openvpn/options_util.h b/src/openvpn/options_util.h index 2474e7f..27a97a9 100644 --- a/src/openvpn/options_util.h +++ b/src/openvpn/options_util.h @@ -27,27 +27,23 @@ #include "options.h" -const char * -parse_auth_failed_temp(struct options *o, const char *reason); +const char *parse_auth_failed_temp(struct options *o, const char *reason); /** Checks if the string is a valid integer by checking if it can be * converted to an integer */ -bool -valid_integer(const char *str, bool positive); +bool valid_integer(const char *str, bool positive); /** * Converts a str to a positive number if the string represents a postive * integer number. Otherwise print a warning with msglevel and return 0 */ -int -positive_atoi(const char *str, int msglevel); +int positive_atoi(const char *str, int msglevel); /** * Converts a str to an integer if the string can be represented as an * integer number. Otherwise print a warning with msglevel and return 0 */ -int -atoi_warn(const char *str, int msglevel); +int atoi_warn(const char *str, int msglevel); #endif /* ifndef OPTIONS_UTIL_H_ */ diff --git a/src/openvpn/otime.c b/src/openvpn/otime.c index d423067..196b175 100644 --- a/src/openvpn/otime.c +++ b/src/openvpn/otime.c @@ -84,9 +84,7 @@ tv_string(const struct timeval *tv, struct gc_arena *gc) { struct buffer out =3D alloc_buf_gc(64, gc); - buf_printf(&out, "[%" PRIi64 "/%ld]", - (int64_t)tv->tv_sec, - (long)tv->tv_usec); + buf_printf(&out, "[%" PRIi64 "/%ld]", (int64_t)tv->tv_sec, (long)tv->t= v_usec); return BSTR(&out); } @@ -98,10 +96,7 @@ const char * tv_string_abs(const struct timeval *tv, struct gc_arena *gc) { - return time_string((time_t) tv->tv_sec, - (long) tv->tv_usec, - true, - gc); + return time_string((time_t)tv->tv_sec, (long)tv->tv_usec, true, gc); } /* format a time_t as ascii, or use current time if 0 */ @@ -125,9 +120,8 @@ t =3D tv.tv_sec; struct tm *tm =3D localtime(&t); - buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d", - tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); + buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, = tm->tm_mon + 1, + tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); if (show_usec && tv.tv_usec) { @@ -197,9 +191,7 @@ t =3D time(NULL); gettimeofday(&tv, NULL); #if 1 - msg(M_INFO, "t=3D%" PRIi64 " s=3D%" PRIi64 " us=3D%ld", - (int64_t)t, - (int64_t)tv.tv_sec, + msg(M_INFO, "t=3D%" PRIi64 " s=3D%" PRIi64 " us=3D%ld", (int64_t)t= , (int64_t)tv.tv_sec, (long)tv.tv_usec); #endif } diff --git a/src/openvpn/otime.h b/src/openvpn/otime.h index 448389d..87f9a25 100644 --- a/src/openvpn/otime.h +++ b/src/openvpn/otime.h @@ -237,7 +237,7 @@ dest->tv_usec =3D usec; } -#define TV_WITHIN_SIGMA_MAX_SEC 600 +#define TV_WITHIN_SIGMA_MAX_SEC 600 #define TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000) /* @@ -260,7 +260,7 @@ { if (at > current) { - const interval_t delta =3D (interval_t) (at - current); + const interval_t delta =3D (interval_t)(at - current); if (delta < *wakeup) { *wakeup =3D delta; diff --git a/src/openvpn/ovpn_dco_freebsd.h b/src/openvpn/ovpn_dco_freebsd.h index 53f94df..2d33475 100644 --- a/src/openvpn/ovpn_dco_freebsd.h +++ b/src/openvpn/ovpn_dco_freebsd.h @@ -32,41 +32,45 @@ #include /* Maximum size of an ioctl request. */ -#define OVPN_MAX_REQUEST_SIZE 4096 +#define OVPN_MAX_REQUEST_SIZE 4096 -enum ovpn_notif_type { +enum ovpn_notif_type +{ OVPN_NOTIF_DEL_PEER, OVPN_NOTIF_ROTATE_KEY, }; -enum ovpn_del_reason { - OVPN_DEL_REASON_REQUESTED =3D 0, - OVPN_DEL_REASON_TIMEOUT =3D 1 +enum ovpn_del_reason +{ + OVPN_DEL_REASON_REQUESTED =3D 0, + OVPN_DEL_REASON_TIMEOUT =3D 1 }; -enum ovpn_key_slot { - OVPN_KEY_SLOT_PRIMARY =3D 0, +enum ovpn_key_slot +{ + OVPN_KEY_SLOT_PRIMARY =3D 0, OVPN_KEY_SLOT_SECONDARY =3D 1 }; -enum ovpn_key_cipher { - OVPN_CIPHER_ALG_NONE =3D 0, - OVPN_CIPHER_ALG_AES_GCM =3D 1, - OVPN_CIPHER_ALG_CHACHA20_POLY1305 =3D 2 +enum ovpn_key_cipher +{ + OVPN_CIPHER_ALG_NONE =3D 0, + OVPN_CIPHER_ALG_AES_GCM =3D 1, + OVPN_CIPHER_ALG_CHACHA20_POLY1305 =3D 2 }; -#define OVPN_NEW_PEER _IO('D', 1) -#define OVPN_DEL_PEER _IO('D', 2) -#define OVPN_GET_STATS _IO('D', 3) -#define OVPN_NEW_KEY _IO('D', 4) -#define OVPN_SWAP_KEYS _IO('D', 5) -#define OVPN_DEL_KEY _IO('D', 6) -#define OVPN_SET_PEER _IO('D', 7) -#define OVPN_START_VPN _IO('D', 8) -#define OVPN_SEND_PKT _IO('D', 9) -#define OVPN_POLL_PKT _IO('D', 10) -#define OVPN_GET_PKT _IO('D', 11) -#define OVPN_SET_IFMODE _IO('D', 12) -#define OVPN_GET_PEER_STATS _IO('D', 13) +#define OVPN_NEW_PEER _IO('D', 1) +#define OVPN_DEL_PEER _IO('D', 2) +#define OVPN_GET_STATS _IO('D', 3) +#define OVPN_NEW_KEY _IO('D', 4) +#define OVPN_SWAP_KEYS _IO('D', 5) +#define OVPN_DEL_KEY _IO('D', 6) +#define OVPN_SET_PEER _IO('D', 7) +#define OVPN_START_VPN _IO('D', 8) +#define OVPN_SEND_PKT _IO('D', 9) +#define OVPN_POLL_PKT _IO('D', 10) +#define OVPN_GET_PKT _IO('D', 11) +#define OVPN_SET_IFMODE _IO('D', 12) +#define OVPN_GET_PEER_STATS _IO('D', 13) #endif /* ifndef _NET_IF_OVPN_H_ */ diff --git a/src/openvpn/packet_id.c b/src/openvpn/packet_id.c index 76a81c6..9106e70 100644 --- a/src/openvpn/packet_id.c +++ b/src/openvpn/packet_id.c @@ -54,20 +54,15 @@ #define SEQ_EXPIRED ((time_t)1) #ifdef ENABLE_DEBUG -static void packet_id_debug_print(int msglevel, - const struct packet_id_rec *p, - const struct packet_id_net *pin, - const char *message, +static void packet_id_debug_print(int msglevel, const struct packet_id_rec= *p, + const struct packet_id_net *pin, const c= har *message, packet_id_print_type value); #endif /* ENABLE_DEBUG */ static inline void -packet_id_debug(int msglevel, - const struct packet_id_rec *p, - const struct packet_id_net *pin, - const char *message, - uint64_t value) +packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct = packet_id_net *pin, + const char *message, uint64_t value) { #ifdef ENABLE_DEBUG if (unlikely(check_debug_level(msglevel))) @@ -78,7 +73,8 @@ } static void -packet_id_init_recv(struct packet_id_rec *rec, int seq_backtrack, int time= _backtrack, const char *name, int unit) +packet_id_init_recv(struct packet_id_rec *rec, int seq_backtrack, int time= _backtrack, + const char *name, int unit) { rec->name =3D name; rec->unit =3D unit; @@ -93,10 +89,10 @@ rec->initialized =3D true; } void -packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack,= const char *name, int unit) +packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack,= const char *name, + int unit) { - dmsg(D_PID_DEBUG, "PID packet_id_init seq_backtrack=3D%d time_backtrac= k=3D%d", - seq_backtrack, + dmsg(D_PID_DEBUG, "PID packet_id_init seq_backtrack=3D%d time_backtrac= k=3D%d", seq_backtrack, time_backtrack); ASSERT(p); @@ -119,8 +115,7 @@ /* Reinitalise the source */ CLEAR(*src); - packet_id_init_recv(src, dest->seq_backtrack, dest->time_backtrack, - dest->name, dest->unit); + packet_id_init_recv(src, dest->seq_backtrack, dest->time_backtrack, de= st->name, dest->unit); } void @@ -146,10 +141,8 @@ * If time value increases, start a new sequence list of number * sequence for the new time point. */ - if (!CIRC_LIST_SIZE(p->seq_list) - || pin->time > p->time - || (pin->id >=3D p->seq_backtrack - && pin->id - p->seq_backtrack > p->id)) + if (!CIRC_LIST_SIZE(p->seq_list) || pin->time > p->time + || (pin->id >=3D p->seq_backtrack && pin->id - p->seq_backtrac= k > p->id)) { p->time =3D pin->time; p->id =3D 0; @@ -164,15 +157,14 @@ #ifdef PID_SIMULATE_BACKTRACK || (get_random() % 64) < 31 #endif - ) + ) { CIRC_LIST_PUSH(p->seq_list, SEQ_UNSEEN); ++p->id; } diff =3D p->id - pin->id; - if (diff < CIRC_LIST_SIZE(p->seq_list) - && local_now > SEQ_EXPIRED) + if (diff < CIRC_LIST_SIZE(p->seq_list) && local_now > SEQ_EXPIRED) { CIRC_LIST_ITEM(p->seq_list, diff) =3D local_now; } @@ -221,8 +213,7 @@ * it is a replay. */ bool -packet_id_test(struct packet_id_rec *p, - const struct packet_id_net *pin) +packet_id_test(struct packet_id_rec *p, const struct packet_id_net *pin) { uint64_t diff; @@ -258,10 +249,11 @@ if (diff > p->max_backtrack_stat) { p->max_backtrack_stat =3D diff; - packet_id_debug(D_PID_DEBUG_LOW, p, pin, "PID_ERR replay-w= indow backtrack occurred", p->max_backtrack_stat); + packet_id_debug(D_PID_DEBUG_LOW, p, pin, "PID_ERR replay-w= indow backtrack occurred", + p->max_backtrack_stat); } - if (diff >=3D (packet_id_type) CIRC_LIST_SIZE(p->seq_list)) + if (diff >=3D (packet_id_type)CIRC_LIST_SIZE(p->seq_list)) { packet_id_debug(D_PID_DEBUG_LOW, p, pin, "PID_ERR large di= ff", diff); return false; @@ -286,7 +278,7 @@ packet_id_debug(D_PID_DEBUG_LOW, p, pin, "PID_ERR time backtra= ck", 0); return false; } - else /* time moved forward */ + else /* time moved forward */ { return true; } @@ -307,7 +299,7 @@ { return false; } - else /* time moved forward */ + else /* time moved forward */ { return pin->id =3D=3D 1; } @@ -383,8 +375,7 @@ } bool -packet_id_write(struct packet_id_send *p, struct buffer *buf, bool long_fo= rm, - bool prepend) +packet_id_write(struct packet_id_send *p, struct buffer *buf, bool long_fo= rm, bool prepend) { if (!packet_id_send_update(p, long_form)) { @@ -432,8 +423,7 @@ buf_printf(&out, "[ #" packet_id_format, (packet_id_print_type)pin->id= ); if (print_timestamp && pin->time) { - buf_printf(&out, " / time =3D (" packet_id_format ") %s", - (packet_id_print_type)pin->time, + buf_printf(&out, " / time =3D (" packet_id_format ") %s", (packet_= id_print_type)pin->time, time_string(pin->time, 0, false, gc)); } @@ -473,13 +463,10 @@ if (!packet_id_persist_enabled(p)) { /* open packet-id persist file for both read and write */ - p->fd =3D platform_open(filename, - O_CREAT | O_RDWR | O_BINARY, - S_IRUSR | S_IWUSR); + p->fd =3D platform_open(filename, O_CREAT | O_RDWR | O_BINARY, S_I= RUSR | S_IWUSR); if (p->fd =3D=3D -1) { - msg(D_PID_PERSIST | M_ERRNO, - "Cannot open --replay-persist file %s for read/write", + msg(D_PID_PERSIST | M_ERRNO, "Cannot open --replay-persist fil= e %s for read/write", filename); } else @@ -500,14 +487,12 @@ { p->time =3D p->time_last_written =3D image.time; p->id =3D p->id_last_written =3D image.id; - dmsg(D_PID_PERSIST_DEBUG, "PID Persist Read from %s: %s", - p->filename, packet_id_persist_print(p, &gc)); + dmsg(D_PID_PERSIST_DEBUG, "PID Persist Read from %s: %s", = p->filename, + packet_id_persist_print(p, &gc)); } else if (n =3D=3D -1) { - msg(D_PID_PERSIST | M_ERRNO, - "Read error on --replay-persist file %s", - p->filename); + msg(D_PID_PERSIST | M_ERRNO, "Read error on --replay-persi= st file %s", p->filename); } } } @@ -518,8 +503,8 @@ void packet_id_persist_save(struct packet_id_persist *p) { - if (packet_id_persist_enabled(p) && p->time && (p->time !=3D p->time_l= ast_written - || p->id !=3D p->id_la= st_written)) + if (packet_id_persist_enabled(p) && p->time + && (p->time !=3D p->time_last_written || p->id !=3D p->id_last_wri= tten)) { struct packet_id_persist_file_image image; ssize_t n; @@ -536,20 +521,18 @@ { p->time_last_written =3D p->time; p->id_last_written =3D p->id; - dmsg(D_PID_PERSIST_DEBUG, "PID Persist Write to %s: %s", - p->filename, packet_id_persist_print(p, &gc)); + dmsg(D_PID_PERSIST_DEBUG, "PID Persist Write to %s: %s", p= ->filename, + packet_id_persist_print(p, &gc)); } else { - msg(D_PID_PERSIST | M_ERRNO, - "Cannot write to --replay-persist file %s", + msg(D_PID_PERSIST | M_ERRNO, "Cannot write to --replay-per= sist file %s", p->filename); } } else { - msg(D_PID_PERSIST | M_ERRNO, - "Cannot seek to beginning of --replay-persist file %s", + msg(D_PID_PERSIST | M_ERRNO, "Cannot seek to beginning of --re= play-persist file %s", p->filename); } gc_free(&gc); @@ -579,8 +562,7 @@ buf_printf(&out, " #" packet_id_format, (packet_id_print_type)p->i= d); if (p->time) { - buf_printf(&out, " / time =3D (" packet_id_format ") %s", - (packet_id_print_type)p->time, + buf_printf(&out, " / time =3D (" packet_id_format ") %s", (pac= ket_id_print_type)p->time, time_string(p->time, 0, false, gc)); } } @@ -592,11 +574,8 @@ #ifdef ENABLE_DEBUG static void -packet_id_debug_print(int msglevel, - const struct packet_id_rec *p, - const struct packet_id_net *pin, - const char *message, - packet_id_print_type value) +packet_id_debug_print(int msglevel, const struct packet_id_rec *p, const s= truct packet_id_net *pin, + const char *message, packet_id_print_type value) { struct gc_arena gc =3D gc_new(); struct buffer out =3D alloc_buf_gc(256, &gc); @@ -649,23 +628,13 @@ buf_printf(&out, " %" PRIi64 ":" packet_id_format, (int64_t)pin->t= ime, pin->id); } - buf_printf(&out, " t=3D%" PRIi64 "[%d]", - (int64_t)prev_now, - (int)(prev_now - tv.tv_sec)); + buf_printf(&out, " t=3D%" PRIi64 "[%d]", (int64_t)prev_now, (int)(prev= _now - tv.tv_sec)); - buf_printf(&out, " r=3D[%d,%" PRIu64 ",%d,%" PRIu64 ",%d]", - (int)(p->last_reap - tv.tv_sec), - p->seq_backtrack, - p->time_backtrack, - p->max_backtrack_stat, - (int)p->initialized); + buf_printf(&out, " r=3D[%d,%" PRIu64 ",%d,%" PRIu64 ",%d]", (int)(p->l= ast_reap - tv.tv_sec), + p->seq_backtrack, p->time_backtrack, p->max_backtrack_stat,= (int)p->initialized); if (sl !=3D NULL) { - buf_printf(&out, " sl=3D[%d,%d,%d,%d]", - sl->x_head, - sl->x_size, - sl->x_cap, - sl->x_sizeof); + buf_printf(&out, " sl=3D[%d,%d,%d,%d]", sl->x_head, sl->x_size, sl= ->x_cap, sl->x_sizeof); } @@ -705,7 +674,7 @@ /* Highest 16 bits of packet id is the epoch. * * The lower 48 bits are the per-epoch packet id counter. */ - uint64_t net_id =3D ((uint64_t) epoch) << 48 | p->id; + uint64_t net_id =3D ((uint64_t)epoch) << 48 | p->id; /* convert to network order. This ensures that the highest bytes * also become the first ones on the wire*/ diff --git a/src/openvpn/packet_id.h b/src/openvpn/packet_id.h index 6db939f..8982729 100644 --- a/src/openvpn/packet_id.h +++ b/src/openvpn/packet_id.h @@ -44,11 +44,11 @@ * These are ephemeral and are never saved to a file. */ typedef uint32_t packet_id_type; -#define PACKET_ID_MAX UINT32_MAX -#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull +#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull /** Mask of the bits that contain the 48-bit of the per-epoch packet * counter in the packet id*/ -#define PACKET_ID_MASK 0x0000ffffffffffffull +#define PACKET_ID_MASK 0x0000ffffffffffffull typedef uint32_t net_time_t; /* @@ -82,8 +82,8 @@ * sequence number due to packets arriving * out of order. */ -#define MIN_SEQ_BACKTRACK 0 -#define MAX_SEQ_BACKTRACK 65536 +#define MIN_SEQ_BACKTRACK 0 +#define MAX_SEQ_BACKTRACK 65536 #define DEFAULT_SEQ_BACKTRACK 64 /* @@ -91,8 +91,8 @@ * seconds due to packets arriving * out of order. */ -#define MIN_TIME_BACKTRACK 0 -#define MAX_TIME_BACKTRACK 600 +#define MIN_TIME_BACKTRACK 0 +#define MAX_TIME_BACKTRACK 600 #define DEFAULT_TIME_BACKTRACK 15 /* @@ -113,14 +113,14 @@ */ struct packet_id_rec { - time_t last_reap; /* last call of packet_id_reap */ - time_t time; /* highest time stamp received */ - uint64_t id; /* highest sequence number received */ - uint64_t seq_backtrack; /* set from --replay-window */ - int time_backtrack; /* set from --replay-window */ - uint64_t max_backtrack_stat; /* maximum backtrack seen so far */ - bool initialized; /* true if packet_id_init was called */ - struct seq_list *seq_list; /* packet-id "memory" */ + time_t last_reap; /* last call of packet_id_reap */ + time_t time; /* highest time stamp received */ + uint64_t id; /* highest sequence number received */ + uint64_t seq_backtrack; /* set from --replay-window */ + int time_backtrack; /* set from --replay-window */ + uint64_t max_backtrack_stat; /* maximum backtrack seen so far */ + bool initialized; /* true if packet_id_init was called */ + struct seq_list *seq_list; /* packet-id "memory" */ const char *name; int unit; }; @@ -133,16 +133,16 @@ { const char *filename; int fd; - time_t time; /* time stamp */ - packet_id_type id; /* sequence number */ + time_t time; /* time stamp */ + packet_id_type id; /* sequence number */ time_t time_last_written; packet_id_type id_last_written; }; struct packet_id_persist_file_image { - time_t time; /* time stamp */ - packet_id_type id; /* sequence number */ + time_t time; /* time stamp */ + packet_id_type id; /* sequence number */ }; /* @@ -202,7 +202,8 @@ struct packet_id_rec rec; }; -void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backt= rack, const char *name, int unit); +void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backt= rack, const char *name, + int unit); void packet_id_free(struct packet_id *p); @@ -210,16 +211,13 @@ * Move the packet id recv structure from \c src to \c dest. \c src will * be reinitialised. \c dest will be freed before the move. */ -void -packet_id_move_recv(struct packet_id_rec *dest, struct packet_id_rec *src); +void packet_id_move_recv(struct packet_id_rec *dest, struct packet_id_rec = *src); /* should we accept an incoming packet id ? */ -bool packet_id_test(struct packet_id_rec *p, - const struct packet_id_net *pin); +bool packet_id_test(struct packet_id_rec *p, const struct packet_id_net *p= in); /* change our current state to reflect an accepted packet id */ -void packet_id_add(struct packet_id_rec *p, - const struct packet_id_net *pin); +void packet_id_add(struct packet_id_rec *p, const struct packet_id_net *pi= n); /* expire TIME_BACKTRACK sequence numbers */ void packet_id_reap(struct packet_id_rec *p); @@ -263,8 +261,7 @@ * * @return true if successful, false otherwise. */ -bool packet_id_write(struct packet_id_send *p, struct buffer *buf, - bool long_form, bool prepend); +bool packet_id_write(struct packet_id_send *p, struct buffer *buf, bool lo= ng_form, bool prepend); /* * Inline functions. @@ -310,7 +307,8 @@ p->id =3D 0; } -const char *packet_id_net_print(const struct packet_id_net *pin, bool prin= t_timestamp, struct gc_arena *gc); +const char *packet_id_net_print(const struct packet_id_net *pin, bool prin= t_timestamp, + struct gc_arena *gc); static inline int packet_id_size(bool long_form) @@ -341,8 +339,7 @@ * @param buf buffer to write the packet id/epoch to * @return false if the packet id space is exhausted and cannot b= e written */ -bool -packet_id_write_epoch(struct packet_id_send *p, uint16_t epoch, struct buf= fer *buf); +bool packet_id_write_epoch(struct packet_id_send *p, uint16_t epoch, struc= t buffer *buf); /** * Reads the packet ID containing both the epoch and the per-epoch counter @@ -351,7 +348,6 @@ * @param buf buffer to read the packet id from. * @return 0 for an error/invalid id, epoch otherwise */ -uint16_t -packet_id_read_epoch(struct packet_id_net *p, struct buffer *buf); +uint16_t packet_id_read_epoch(struct packet_id_net *p, struct buffer *buf); #endif /* PACKET_ID_H */ diff --git a/src/openvpn/perf.c b/src/openvpn/perf.c index 71c00e5..78457e9 100644 --- a/src/openvpn/perf.c +++ b/src/openvpn/perf.c @@ -36,34 +36,32 @@ #include "memdbg.h" -static const char *metric_names[] =3D { - "PERF_BIO_READ_PLAINTEXT", - "PERF_BIO_WRITE_PLAINTEXT", - "PERF_BIO_READ_CIPHERTEXT", - "PERF_BIO_WRITE_CIPHERTEXT", - "PERF_TLS_MULTI_PROCESS", - "PERF_IO_WAIT", - "PERF_EVENT_LOOP", - "PERF_MULTI_CREATE_INSTANCE", - "PERF_MULTI_CLOSE_INSTANCE", - "PERF_MULTI_SHOW_STATS", - "PERF_MULTI_BCAST", - "PERF_MULTI_MCAST", - "PERF_SCRIPT", - "PERF_READ_IN_LINK", - "PERF_PROC_IN_LINK", - "PERF_READ_IN_TUN", - "PERF_PROC_IN_TUN", - "PERF_PROC_OUT_LINK", - "PERF_PROC_OUT_TUN", - "PERF_PROC_OUT_TUN_MTCP" -}; +static const char *metric_names[] =3D { "PERF_BIO_READ_PLAINTEXT", + "PERF_BIO_WRITE_PLAINTEXT", + "PERF_BIO_READ_CIPHERTEXT", + "PERF_BIO_WRITE_CIPHERTEXT", + "PERF_TLS_MULTI_PROCESS", + "PERF_IO_WAIT", + "PERF_EVENT_LOOP", + "PERF_MULTI_CREATE_INSTANCE", + "PERF_MULTI_CLOSE_INSTANCE", + "PERF_MULTI_SHOW_STATS", + "PERF_MULTI_BCAST", + "PERF_MULTI_MCAST", + "PERF_SCRIPT", + "PERF_READ_IN_LINK", + "PERF_PROC_IN_LINK", + "PERF_READ_IN_TUN", + "PERF_PROC_IN_TUN", + "PERF_PROC_OUT_LINK", + "PERF_PROC_OUT_TUN", + "PERF_PROC_OUT_TUN_MTCP" }; struct perf { -#define PS_INITIAL 0 -#define PS_METER_RUNNING 1 -#define PS_METER_INTERRUPTED 2 +#define PS_INITIAL 0 +#define PS_METER_RUNNING 1 +#define PS_METER_INTERRUPTED 2 int state; struct timeval start; @@ -139,8 +137,7 @@ { const int sindex =3D get_stack_index(0); const int newlen =3D get_stack_index(1); - if (sindex >=3D 0 && newlen >=3D 0 - && pindex >=3D 0 && pindex < PERF_N) + if (sindex >=3D 0 && newlen >=3D 0 && pindex >=3D 0 && pindex < PERF_N) { int i; for (i =3D 0; i < sindex; ++i) @@ -148,8 +145,7 @@ if (perf_set.stack[i] =3D=3D pindex) { perf_print_state(M_INFO); - msg(M_FATAL, "PERF: push_perf_index %s failed", - metric_names [pindex]); + msg(M_FATAL, "PERF: push_perf_index %s failed", metric_nam= es[pindex]); } } @@ -181,9 +177,7 @@ { if (p->state !=3D wanted) { - msg(M_FATAL, "PERF: bad state actual=3D%d wanted=3D%d", - p->state, - wanted); + msg(M_FATAL, "PERF: bad state actual=3D%d wanted=3D%d", p->state, = wanted); } } @@ -192,7 +186,7 @@ { struct timeval current; ASSERT(!gettimeofday(¤t, NULL)); - p->sofar +=3D (double) tv_subtract(¤t, &p->start, 600) / 1000000= .0; + p->sofar +=3D (double)tv_subtract(¤t, &p->start, 600) / 1000000.= 0; tv_clear(&p->start); } @@ -288,7 +282,8 @@ if (p->count > 0.0) { const double mean =3D p->sum / p->count; - msg(M_INFO, "%s n=3D%.0f mean=3D%.3f max=3D%.3f", metric_names= [i], p->count, mean*1000.0, p->max*1000.0); + msg(M_INFO, "%s n=3D%.0f mean=3D%.3f max=3D%.3f", metric_names= [i], p->count, mean * 1000.0, + p->max * 1000.0); } } } @@ -304,15 +299,8 @@ { const int j =3D perf_set.stack[i]; const struct perf *p =3D &perf_set.perf[j]; - msg(lev, "[%d] %s state=3D%d start=3D%s sofar=3D%f sum=3D%f max=3D= %f count=3D%f", - i, - metric_names[j], - p->state, - tv_string(&p->start, &gc), - p->sofar, - p->sum, - p->max, - p->count); + msg(lev, "[%d] %s state=3D%d start=3D%s sofar=3D%f sum=3D%f max=3D= %f count=3D%f", i, metric_names[j], + p->state, tv_string(&p->start, &gc), p->sofar, p->sum, p->max,= p->count); } gc_free(&gc); } diff --git a/src/openvpn/perf.h b/src/openvpn/perf.h index 5ddebeb..06d5093 100644 --- a/src/openvpn/perf.h +++ b/src/openvpn/perf.h @@ -35,27 +35,27 @@ /* * Metrics */ -#define PERF_BIO_READ_PLAINTEXT 0 -#define PERF_BIO_WRITE_PLAINTEXT 1 -#define PERF_BIO_READ_CIPHERTEXT 2 -#define PERF_BIO_WRITE_CIPHERTEXT 3 -#define PERF_TLS_MULTI_PROCESS 4 -#define PERF_IO_WAIT 5 -#define PERF_EVENT_LOOP 6 -#define PERF_MULTI_CREATE_INSTANCE 7 -#define PERF_MULTI_CLOSE_INSTANCE 8 -#define PERF_MULTI_SHOW_STATS 9 -#define PERF_MULTI_BCAST 10 -#define PERF_MULTI_MCAST 11 -#define PERF_SCRIPT 12 -#define PERF_READ_IN_LINK 13 -#define PERF_PROC_IN_LINK 14 -#define PERF_READ_IN_TUN 15 -#define PERF_PROC_IN_TUN 16 -#define PERF_PROC_OUT_LINK 17 -#define PERF_PROC_OUT_TUN 18 -#define PERF_PROC_OUT_TUN_MTCP 19 -#define PERF_N 20 +#define PERF_BIO_READ_PLAINTEXT 0 +#define PERF_BIO_WRITE_PLAINTEXT 1 +#define PERF_BIO_READ_CIPHERTEXT 2 +#define PERF_BIO_WRITE_CIPHERTEXT 3 +#define PERF_TLS_MULTI_PROCESS 4 +#define PERF_IO_WAIT 5 +#define PERF_EVENT_LOOP 6 +#define PERF_MULTI_CREATE_INSTANCE 7 +#define PERF_MULTI_CLOSE_INSTANCE 8 +#define PERF_MULTI_SHOW_STATS 9 +#define PERF_MULTI_BCAST 10 +#define PERF_MULTI_MCAST 11 +#define PERF_SCRIPT 12 +#define PERF_READ_IN_LINK 13 +#define PERF_PROC_IN_LINK 14 +#define PERF_READ_IN_TUN 15 +#define PERF_PROC_IN_TUN 16 +#define PERF_PROC_OUT_LINK 17 +#define PERF_PROC_OUT_TUN 18 +#define PERF_PROC_OUT_TUN_MTCP 19 +#define PERF_N 20 #ifdef ENABLE_PERFORMANCE_METRICS @@ -64,7 +64,7 @@ /* * Stack size */ -#define STACK_N 64 +#define STACK_N 64 void perf_push(int type); diff --git a/src/openvpn/ping.c b/src/openvpn/ping.c index f570d95..0fdca7b 100644 --- a/src/openvpn/ping.c +++ b/src/openvpn/ping.c @@ -39,10 +39,8 @@ * * PING_STRING_SIZE must be sizeof (ping_string) */ -const uint8_t ping_string[] =3D { - 0x2a, 0x18, 0x7b, 0xf3, 0x64, 0x1e, 0xb4, 0xcb, - 0x07, 0xed, 0x2d, 0x0a, 0x98, 0x1f, 0xc7, 0x48 -}; +const uint8_t ping_string[] =3D { 0x2a, 0x18, 0x7b, 0xf3, 0x64, 0x1e, 0xb4= , 0xcb, + 0x07, 0xed, 0x2d, 0x0a, 0x98, 0x1f, 0xc7, = 0x48 }; void trigger_ping_timeout_signal(struct context *c) @@ -51,8 +49,7 @@ switch (c->options.ping_rec_timeout_action) { case PING_EXIT: - msg(M_INFO, "%sInactivity timeout (--ping-exit), exiting", - format_common_name(c, &gc)); + msg(M_INFO, "%sInactivity timeout (--ping-exit), exiting", for= mat_common_name(c, &gc)); register_signal(c->sig, SIGTERM, "ping-exit"); break; diff --git a/src/openvpn/ping.h b/src/openvpn/ping.h index 4cb89b4..085b52f 100644 --- a/src/openvpn/ping.h +++ b/src/openvpn/ping.h @@ -30,7 +30,7 @@ /* * Initial default --ping-restart before --pull */ -#define PRE_PULL_INITIAL_PING_RESTART 120 /* in seconds */ +#define PRE_PULL_INITIAL_PING_RESTART 120 /* in seconds */ extern const uint8_t ping_string[]; @@ -60,11 +60,11 @@ check_ping_restart(struct context *c) { if (c->options.ping_rec_timeout - && event_timeout_trigger(&c->c2.ping_rec_interval, - &c->c2.timeval, + && event_timeout_trigger(&c->c2.ping_rec_interval, &c->c2.timeval, (!c->options.ping_timer_remote || link_socket_actual_defined(&c->c1.lin= k_socket_addrs[0].actual)) - ? ETT_DEFAULT : 15)) + ? ETT_DEFAULT + : 15)) { trigger_ping_timeout_signal(c); } @@ -77,8 +77,7 @@ check_ping_send(struct context *c) { if (c->options.ping_send_timeout - && event_timeout_trigger(&c->c2.ping_send_interval, - &c->c2.timeval, + && event_timeout_trigger(&c->c2.ping_send_interval, &c->c2.timeval, !TO_LINK_DEF(c) ? ETT_DEFAULT : 1)) { check_ping_send_dowork(c); diff --git a/src/openvpn/pkcs11.c b/src/openvpn/pkcs11.c index 00428d8..c13903e 100644 --- a/src/openvpn/pkcs11.c +++ b/src/openvpn/pkcs11.c @@ -40,51 +40,41 @@ #include "console.h" #include "pkcs11_backend.h" -static -time_t +static time_t __mytime(void) { return openvpn_time(NULL); } #if !defined(_WIN32) -static -int +static int __mygettimeofday(struct timeval *tv) { return gettimeofday(tv, NULL); } #endif -static -void +static void __mysleep(const unsigned long usec) { #if defined(_WIN32) - Sleep(usec/1000); + Sleep(usec / 1000); #else usleep(usec); #endif } -static pkcs11h_engine_system_t s_pkcs11h_sys_engine =3D { - malloc, - free, - __mytime, - __mysleep, +static pkcs11h_engine_system_t s_pkcs11h_sys_engine =3D { malloc, free, __= mytime, __mysleep, #if defined(_WIN32) - NULL + NULL #else - __mygettimeofday + __mygettimeofday #endif }; -static -unsigned -_pkcs11_msg_pkcs112openvpn( - const unsigned flags - ) +static unsigned +_pkcs11_msg_pkcs112openvpn(const unsigned flags) { unsigned openvpn_flags; @@ -122,11 +112,8 @@ return openvpn_flags; } -static -unsigned -_pkcs11_msg_openvpn2pkcs11( - const unsigned flags - ) +static unsigned +_pkcs11_msg_openvpn2pkcs11(const unsigned flags) { unsigned pkcs11_flags; @@ -162,33 +149,23 @@ return pkcs11_flags; } -static -void -_pkcs11_openvpn_log( - void *const global_data, - unsigned flags, - const char *const szFormat, - va_list args - ) +static void +_pkcs11_openvpn_log(void *const global_data, unsigned flags, const char *c= onst szFormat, + va_list args) { - char Buffer[10*1024]; + char Buffer[10 * 1024]; (void)global_data; vsnprintf(Buffer, sizeof(Buffer), szFormat, args); - Buffer[sizeof(Buffer)-1] =3D 0; + Buffer[sizeof(Buffer) - 1] =3D 0; msg(_pkcs11_msg_pkcs112openvpn(flags), "%s", Buffer); } -static -PKCS11H_BOOL -_pkcs11_openvpn_token_prompt( - void *const global_data, - void *const user_data, - const pkcs11h_token_id_t token, - const unsigned retry - ) +static PKCS11H_BOOL +_pkcs11_openvpn_token_prompt(void *const global_data, void *const user_dat= a, + const pkcs11h_token_id_t token, const unsigne= d retry) { struct user_pass token_resp; @@ -196,26 +173,16 @@ (void)user_data; (void)retry; - ASSERT(token!=3DNULL); + ASSERT(token !=3D NULL); CLEAR(token_resp); token_resp.defined =3D false; token_resp.nocache =3D true; - snprintf( - token_resp.username, - sizeof(token_resp.username), - "Please insert %s token", - token->label - ); + snprintf(token_resp.username, sizeof(token_resp.username), "Please ins= ert %s token", + token->label); - if ( - !get_user_pass( - &token_resp, - NULL, - "token-insertion-request", - GET_USER_PASS_MANAGEMENT|GET_USER_PASS_NEED_OK|GET_USER_PASS_N= OFATAL - ) - ) + if (!get_user_pass(&token_resp, NULL, "token-insertion-request", + GET_USER_PASS_MANAGEMENT | GET_USER_PASS_NEED_OK | = GET_USER_PASS_NOFATAL)) { return false; } @@ -225,16 +192,10 @@ } } -static -PKCS11H_BOOL -_pkcs11_openvpn_pin_prompt( - void *const global_data, - void *const user_data, - const pkcs11h_token_id_t token, - const unsigned retry, - char *const pin, - const size_t pin_max - ) +static PKCS11H_BOOL +_pkcs11_openvpn_pin_prompt(void *const global_data, void *const user_data, + const pkcs11h_token_id_t token, const unsigned = retry, char *const pin, + const size_t pin_max) { struct user_pass token_pass; char prompt[1024]; @@ -244,21 +205,16 @@ (void)user_data; (void)retry; - ASSERT(token!=3DNULL); + ASSERT(token !=3D NULL); snprintf(prompt, sizeof(prompt), "%s token", token->label); token_pass.defined =3D false; token_pass.nocache =3D true; - if ( - !get_user_pass( - &token_pass, - NULL, - prompt, - GET_USER_PASS_MANAGEMENT|GET_USER_PASS_PASSWORD_ONLY|GET_USER_= PASS_NOFATAL - ) - ) + if (!get_user_pass(&token_pass, NULL, prompt, + GET_USER_PASS_MANAGEMENT | GET_USER_PASS_PASSWORD_O= NLY + | GET_USER_PASS_NOFATAL)) { return false; } @@ -279,21 +235,16 @@ } bool -pkcs11_initialize( - const bool protected_auth, - const int nPINCachePeriod - ) +pkcs11_initialize(const bool protected_auth, const int nPINCachePeriod) { CK_RV rv =3D CKR_FUNCTION_FAILED; - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_initialize - entered" - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_initialize - entered"); if ((rv =3D pkcs11h_engine_setSystem(&s_pkcs11h_sys_engine)) !=3D CKR_= OK) { - msg(M_FATAL, "PKCS#11: Cannot initialize system engine %ld-'%s'", = rv, pkcs11h_getMessage(rv)); + msg(M_FATAL, "PKCS#11: Cannot initialize system engine %ld-'%s'", = rv, + pkcs11h_getMessage(rv)); goto cleanup; } @@ -331,7 +282,8 @@ if ((rv =3D pkcs11h_setProtectedAuthentication(protected_auth)) !=3D C= KR_OK) { - msg(M_FATAL, "PKCS#11: Cannot set protected authentication mode %l= d-'%s'", rv, pkcs11h_getMessage(rv)); + msg(M_FATAL, "PKCS#11: Cannot set protected authentication mode %l= d-'%s'", rv, + pkcs11h_getMessage(rv)); goto cleanup; } @@ -344,12 +296,8 @@ rv =3D CKR_OK; cleanup: - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_initialize - return %ld-'%s'", - rv, - pkcs11h_getMessage(rv) - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_initialize - return %ld-'%s'", r= v, + pkcs11h_getMessage(rv)); return rv =3D=3D CKR_OK; } @@ -357,105 +305,85 @@ void pkcs11_terminate(void) { - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_terminate - entered" - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_terminate - entered"); pkcs11h_terminate(); - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_terminate - return" - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_terminate - return"); } bool -pkcs11_addProvider( - const char *const provider, - const bool protected_auth, - const unsigned private_mode, - const bool cert_private - ) +pkcs11_addProvider(const char *const provider, const bool protected_auth, + const unsigned private_mode, const bool cert_private) { CK_RV rv =3D CKR_OK; - ASSERT(provider!=3DNULL); + ASSERT(provider !=3D NULL); - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_addProvider - entered - provider=3D'%s', private_= mode=3D%08x", - provider, - private_mode - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_addProvider - entered - provider= =3D'%s', private_mode=3D%08x", + provider, private_mode); - msg( - M_INFO, - "PKCS#11: Adding PKCS#11 provider '%s'", - provider - ); + msg(M_INFO, "PKCS#11: Adding PKCS#11 provider '%s'", provider); -#if PKCS11H_VERSION >=3D ((1<<16) | (28<<8) | (0<<0)) +#if PKCS11H_VERSION >=3D ((1 << 16) | (28 << 8) | (0 << 0)) if ((rv =3D pkcs11h_registerProvider(provider)) !=3D CKR_OK) { - msg(M_WARN, "PKCS#11: Cannot register provider '%s' %ld-'%s'", pro= vider, rv, pkcs11h_getMessage(rv)); + msg(M_WARN, "PKCS#11: Cannot register provider '%s' %ld-'%s'", pro= vider, rv, + pkcs11h_getMessage(rv)); } else { PKCS11H_BOOL allow_protected_auth =3D protected_auth; PKCS11H_BOOL cert_is_private =3D cert_private; - rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_PROP= ERTY_LOCATION, provider, strlen(provider) + 1); + rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_PROP= ERTY_LOCATION, provider, + strlen(provider) + 1); if (rv =3D=3D CKR_OK) { - rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_= PROPERTY_ALLOW_PROTECTED_AUTH, &allow_protected_auth, sizeof(allow_protecte= d_auth)); + rv =3D pkcs11h_setProviderProperty(provider, + PKCS11H_PROVIDER_PROPERTY_ALL= OW_PROTECTED_AUTH, + &allow_protected_auth, sizeof= (allow_protected_auth)); } if (rv =3D=3D CKR_OK) { - rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_= PROPERTY_MASK_PRIVATE_MODE, &private_mode, sizeof(private_mode)); + rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_= PROPERTY_MASK_PRIVATE_MODE, + &private_mode, sizeof(private= _mode)); } if (rv =3D=3D CKR_OK) { - rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_= PROPERTY_CERT_IS_PRIVATE, &cert_is_private, sizeof(cert_is_private)); + rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_= PROPERTY_CERT_IS_PRIVATE, + &cert_is_private, sizeof(cert= _is_private)); } #if defined(WIN32) && defined(PKCS11H_PROVIDER_PROPERTY_LOADER_FLAGS) if (rv =3D=3D CKR_OK && platform_absolute_pathname(provider)) { - unsigned loader_flags =3D LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | L= OAD_LIBRARY_SEARCH_DLL_LOAD_DIR; - rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_= PROPERTY_LOADER_FLAGS, &loader_flags, sizeof(loader_flags)); + unsigned loader_flags =3D + LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL= _LOAD_DIR; + rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_= PROPERTY_LOADER_FLAGS, + &loader_flags, sizeof(loader_= flags)); } #endif if (rv !=3D CKR_OK || (rv =3D pkcs11h_initializeProvider(provider)= ) !=3D CKR_OK) { - msg(M_WARN, "PKCS#11: Cannot initialize provider '%s' %ld-'%s'= ", provider, rv, pkcs11h_getMessage(rv)); + msg(M_WARN, "PKCS#11: Cannot initialize provider '%s' %ld-'%s'= ", provider, rv, + pkcs11h_getMessage(rv)); pkcs11h_removeProvider(provider); } } #else /* if PKCS11H_VERSION >=3D ((1<<16) | (28<<8) | (0<<0)) */ - if ( - (rv =3D pkcs11h_addProvider( - provider, - provider, - protected_auth, - private_mode, - PKCS11H_SLOTEVENT_METHOD_AUTO, - 0, - cert_private - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_addProvider(provider, provider, protected_auth, pr= ivate_mode, + PKCS11H_SLOTEVENT_METHOD_AUTO, 0, cert_p= rivate)) + !=3D CKR_OK) { - msg(M_WARN, "PKCS#11: Cannot initialize provider '%s' %ld-'%s'", p= rovider, rv, pkcs11h_getMessage(rv)); + msg(M_WARN, "PKCS#11: Cannot initialize provider '%s' %ld-'%s'", p= rovider, rv, + pkcs11h_getMessage(rv)); } #endif /* if PKCS11H_VERSION >=3D ((1<<16) | (28<<8) | (0<<0)) */ - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_addProvider - return rv=3D%ld-'%s'", - rv, - pkcs11h_getMessage(rv) - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_addProvider - return rv=3D%ld-'%= s'", rv, + pkcs11h_getMessage(rv)); return rv =3D=3D CKR_OK; } @@ -474,20 +402,11 @@ CK_RV rv =3D CKR_OK; int count =3D 0; - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_management_id_count - entered" - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_management_id_count - entered"); - if ( - (rv =3D pkcs11h_certificate_enumCertificateIds( - PKCS11H_ENUM_METHOD_CACHE_EXIST, - NULL, - PKCS11H_PROMPT_MASK_ALLOW_ALL, - NULL, - &id_list - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_enumCertificateIds(PKCS11H_ENUM_METHOD= _CACHE_EXIST, NULL, + PKCS11H_PROMPT_MASK_A= LLOW_ALL, NULL, &id_list)) + !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot get certificate list %ld-'%s'", rv, p= kcs11h_getMessage(rv)); goto cleanup; @@ -503,21 +422,13 @@ pkcs11h_certificate_freeCertificateIdList(id_list); id_list =3D NULL; - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_management_id_count - return count=3D%d", - count - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_management_id_count - return cou= nt=3D%d", count); return count; } bool -pkcs11_management_id_get( - const int index, - char **id, - char **base64 - ) +pkcs11_management_id_get(const int index, char **id, char **base64) { pkcs11h_certificate_id_list_t id_list =3D NULL; pkcs11h_certificate_id_list_t entry =3D NULL; @@ -534,27 +445,17 @@ int count =3D 0; bool success =3D false; - ASSERT(id!=3DNULL); - ASSERT(base64!=3DNULL); + ASSERT(id !=3D NULL); + ASSERT(base64 !=3D NULL); - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_management_id_get - entered index=3D%d", - index - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_management_id_get - entered inde= x=3D%d", index); *id =3D NULL; *base64 =3D NULL; - if ( - (rv =3D pkcs11h_certificate_enumCertificateIds( - PKCS11H_ENUM_METHOD_CACHE_EXIST, - NULL, - PKCS11H_PROMPT_MASK_ALLOW_ALL, - NULL, - &id_list - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_enumCertificateIds(PKCS11H_ENUM_METHOD= _CACHE_EXIST, NULL, + PKCS11H_PROMPT_MASK_A= LLOW_ALL, NULL, &id_list)) + !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot get certificate list %ld-'%s'", rv, p= kcs11h_getMessage(rv)); goto cleanup; @@ -570,23 +471,16 @@ if (entry =3D=3D NULL) { - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_management_id_get - no certificate at index= =3D%d", - index - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_management_id_get - no certi= ficate at index=3D%d", + index); goto cleanup; } - if ( - (rv =3D pkcs11h_certificate_serializeCertificateId( - NULL, - &max, - entry->certificate_id - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_serializeCertificateId(NULL, &max, ent= ry->certificate_id)) + !=3D CKR_OK) { - msg(M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%s'", r= v, pkcs11h_getMessage(rv)); + msg(M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%s'", r= v, + pkcs11h_getMessage(rv)); goto cleanup; } @@ -596,39 +490,24 @@ goto cleanup; } - if ( - (rv =3D pkcs11h_certificate_serializeCertificateId( - internal_id, - &max, - entry->certificate_id - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_serializeCertificateId(internal_id, &m= ax, entry->certificate_id)) + !=3D CKR_OK) { - msg(M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%s'", r= v, pkcs11h_getMessage(rv)); + msg(M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%s'", r= v, + pkcs11h_getMessage(rv)); goto cleanup; } - if ( - (rv =3D pkcs11h_certificate_create( - entry->certificate_id, - NULL, - PKCS11H_PROMPT_MASK_ALLOW_ALL, - PKCS11H_PIN_CACHE_INFINITE, - &certificate - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_create(entry->certificate_id, NULL, PK= CS11H_PROMPT_MASK_ALLOW_ALL, + PKCS11H_PIN_CACHE_INFINITE, &cert= ificate)) + !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot get certificate %ld-'%s'", rv, pkcs11= h_getMessage(rv)); goto cleanup; } - if ( - (rv =3D pkcs11h_certificate_getCertificateBlob( - certificate, - NULL, - &certificate_blob_size - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_getCertificateBlob(certificate, NULL, = &certificate_blob_size)) + !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot get certificate blob %ld-'%s'", rv, p= kcs11h_getMessage(rv)); goto cleanup; @@ -640,13 +519,9 @@ goto cleanup; } - if ( - (rv =3D pkcs11h_certificate_getCertificateBlob( - certificate, - certificate_blob, - &certificate_blob_size - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_getCertificateBlob(certificate, certif= icate_blob, + &certificate_blob_siz= e)) + !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot get certificate blob %ld-'%s'", rv, p= kcs11h_getMessage(rv)); goto cleanup; @@ -678,22 +553,15 @@ free(certificate_blob); certificate_blob =3D NULL; =20 - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: pkcs11_management_id_get - return success=3D%d, id=3D'%s= '", - success ? 1 : 0, - *id - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_management_id_get - return succe= ss=3D%d, id=3D'%s'", + success ? 1 : 0, *id); return success; } int -tls_ctx_use_pkcs11( - struct tls_root_ctx *const ssl_ctx, - bool pkcs11_id_management, - const char *const pkcs11_id - ) +tls_ctx_use_pkcs11(struct tls_root_ctx *const ssl_ctx, bool pkcs11_id_mana= gement, + const char *const pkcs11_id) { pkcs11h_certificate_id_t certificate_id =3D NULL; pkcs11h_certificate_t certificate =3D NULL; @@ -701,16 +569,13 @@ bool ok =3D false; - ASSERT(ssl_ctx!=3DNULL); - ASSERT(pkcs11_id_management || pkcs11_id!=3DNULL); + ASSERT(ssl_ctx !=3D NULL); + ASSERT(pkcs11_id_management || pkcs11_id !=3D NULL); dmsg( D_PKCS11_DEBUG, "PKCS#11: tls_ctx_use_pkcs11 - entered - ssl_ctx=3D%p, pkcs11_id_m= anagement=3D%d, pkcs11_id=3D'%s'", - (void *)ssl_ctx, - pkcs11_id_management ? 1 : 0, - pkcs11_id - ); + (void *)ssl_ctx, pkcs11_id_management ? 1 : 0, pkcs11_id); if (pkcs11_id_management) { @@ -720,30 +585,17 @@ id_resp.defined =3D false; id_resp.nocache =3D true; - snprintf( - id_resp.username, - sizeof(id_resp.username), - "Please specify PKCS#11 id to use" - ); + snprintf(id_resp.username, sizeof(id_resp.username), "Please speci= fy PKCS#11 id to use"); - if ( - !get_user_pass( - &id_resp, - NULL, - "pkcs11-id-request", - GET_USER_PASS_MANAGEMENT|GET_USER_PASS_NEED_STR|GET_USER_P= ASS_NOFATAL - ) - ) + if (!get_user_pass(&id_resp, NULL, "pkcs11-id-request", + GET_USER_PASS_MANAGEMENT | GET_USER_PASS_NEED_S= TR + | GET_USER_PASS_NOFATAL)) { goto cleanup; } - if ( - (rv =3D pkcs11h_certificate_deserializeCertificateId( - &certificate_id, - id_resp.password - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_deserializeCertificateId(&certific= ate_id, id_resp.password)) + !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkc= s11h_getMessage(rv)); goto cleanup; @@ -751,38 +603,23 @@ } else { - if ( - (rv =3D pkcs11h_certificate_deserializeCertificateId( - &certificate_id, - pkcs11_id - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_deserializeCertificateId(&certific= ate_id, pkcs11_id)) + !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkc= s11h_getMessage(rv)); goto cleanup; } } - if ( - (rv =3D pkcs11h_certificate_create( - certificate_id, - NULL, - PKCS11H_PROMPT_MASK_ALLOW_ALL, - PKCS11H_PIN_CACHE_INFINITE, - &certificate - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_create(certificate_id, NULL, PKCS11H_P= ROMPT_MASK_ALLOW_ALL, + PKCS11H_PIN_CACHE_INFINITE, &cert= ificate)) + !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot get certificate %ld-'%s'", rv, pkcs11= h_getMessage(rv)); goto cleanup; } - if ( - (pkcs11_init_tls_session( - certificate, - ssl_ctx - )) - ) + if ((pkcs11_init_tls_session(certificate, ssl_ctx))) { /* Handled by SSL context free */ certificate =3D NULL; @@ -806,26 +643,15 @@ certificate_id =3D NULL; } - dmsg( - D_PKCS11_DEBUG, - "PKCS#11: tls_ctx_use_pkcs11 - return ok=3D%d, rv=3D%ld", - ok ? 1 : 0, - rv - ); + dmsg(D_PKCS11_DEBUG, "PKCS#11: tls_ctx_use_pkcs11 - return ok=3D%d, rv= =3D%ld", ok ? 1 : 0, rv); return ok ? 1 : 0; } -static -PKCS11H_BOOL -_pkcs11_openvpn_show_pkcs11_ids_pin_prompt( - void *const global_data, - void *const user_data, - const pkcs11h_token_id_t token, - const unsigned retry, - char *const pin, - const size_t pin_max - ) +static PKCS11H_BOOL +_pkcs11_openvpn_show_pkcs11_ids_pin_prompt(void *const global_data, void *= const user_data, + const pkcs11h_token_id_t token,= const unsigned retry, + char *const pin, const size_t p= in_max) { struct gc_arena gc =3D gc_new(); struct buffer pass_prompt =3D alloc_buf_gc(128, &gc); @@ -834,11 +660,10 @@ (void)user_data; (void)retry; - ASSERT(token!=3DNULL); + ASSERT(token !=3D NULL); buf_printf(&pass_prompt, "Please enter '%s' token PIN or 'cancel': ", = token->display); - if (!query_user_SINGLE(BSTR(&pass_prompt), BLEN(&pass_prompt), - pin, pin_max, false)) + if (!query_user_SINGLE(BSTR(&pass_prompt), BLEN(&pass_prompt), pin, pi= n_max, false)) { msg(M_FATAL, "Could not retrieve the PIN"); } @@ -856,10 +681,7 @@ } void -show_pkcs11_ids( - const char *const provider, - bool cert_private - ) +show_pkcs11_ids(const char *const provider, bool cert_private) { struct gc_arena gc =3D gc_new(); pkcs11h_certificate_id_list_t user_certificates =3D NULL; @@ -882,7 +704,8 @@ if ((rv =3D pkcs11h_setProtectedAuthentication(TRUE)) !=3D CKR_OK) { - msg(M_FATAL, "PKCS#11: Cannot set protected authentication %ld-'%s= '", rv, pkcs11h_getMessage(rv)); + msg(M_FATAL, "PKCS#11: Cannot set protected authentication %ld-'%s= '", rv, + pkcs11h_getMessage(rv)); goto cleanup; } @@ -898,118 +721,77 @@ goto cleanup; } - if ( - (rv =3D pkcs11h_certificate_enumCertificateIds( - PKCS11H_ENUM_METHOD_CACHE_EXIST, - NULL, - PKCS11H_PROMPT_MASK_ALLOW_ALL, - NULL, - &user_certificates - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_enumCertificateIds(PKCS11H_ENUM_METHOD= _CACHE_EXIST, NULL, + PKCS11H_PROMPT_MASK_A= LLOW_ALL, NULL, + &user_certificates)) + !=3D CKR_OK) { msg(M_FATAL, "PKCS#11: Cannot enumerate certificates %ld-'%s'", rv= , pkcs11h_getMessage(rv)); goto cleanup; } - msg( - M_INFO|M_NOPREFIX|M_NOLF, - ( - "\n" - "The following objects are available for use.\n" - "Each object shown below may be used as parameter to\n" - "--pkcs11-id option please remember to use single quote mark.\= n" - ) - ); + msg(M_INFO | M_NOPREFIX | M_NOLF, + ("\n" + "The following objects are available for use.\n" + "Each object shown below may be used as parameter to\n" + "--pkcs11-id option please remember to use single quote mark.\n")= ); for (current =3D user_certificates; current !=3D NULL; current =3D cur= rent->next) { pkcs11h_certificate_t certificate =3D NULL; char *dn =3D NULL; - char serial[1024] =3D {0}; + char serial[1024] =3D { 0 }; char *ser =3D NULL; size_t ser_len =3D 0; - if ( - (rv =3D pkcs11h_certificate_serializeCertificateId( - NULL, - &ser_len, - current->certificate_id - )) !=3D CKR_OK - ) + if ((rv =3D pkcs11h_certificate_serializeCertificateId(NULL, &ser_= len, + current->cert= ificate_id)) + !=3D CKR_OK) { - msg(M_FATAL, "PKCS#11: Cannot serialize certificate %ld-'%s'",= rv, pkcs11h_getMessage(rv)); + msg(M_FATAL, "PKCS#11: Cannot serialize certificate %ld-'%s'",= rv, + pkcs11h_getMessage(rv)); goto cleanup1; } - if ( - rv =3D=3D CKR_OK - && (ser =3D (char *)malloc(ser_len)) =3D=3D NULL - ) + if (rv =3D=3D CKR_OK && (ser =3D (char *)malloc(ser_len)) =3D=3D N= ULL) { msg(M_FATAL, "PKCS#11: Cannot allocate memory"); goto cleanup1; } - if ( - (rv =3D pkcs11h_certificate_serializeCertificateId( - ser, - &ser_len, - current->certificate_id - )) !=3D CKR_OK - ) + if ((rv =3D + pkcs11h_certificate_serializeCertificateId(ser, &ser_len,= current->certificate_id)) + !=3D CKR_OK) { - msg(M_FATAL, "PKCS#11: Cannot serialize certificate %ld-'%s'",= rv, pkcs11h_getMessage(rv)); + msg(M_FATAL, "PKCS#11: Cannot serialize certificate %ld-'%s'",= rv, + pkcs11h_getMessage(rv)); goto cleanup1; } - if ( - (rv =3D pkcs11h_certificate_create( - current->certificate_id, - NULL, - PKCS11H_PROMPT_MASK_ALLOW_ALL, - PKCS11H_PIN_CACHE_INFINITE, - &certificate - )) - ) + if ((rv =3D pkcs11h_certificate_create(current->certificate_id, NU= LL, + PKCS11H_PROMPT_MASK_ALLOW_ALL, + PKCS11H_PIN_CACHE_INFINITE, &= certificate))) { msg(M_FATAL, "PKCS#11: Cannot create certificate %ld-'%s'", rv= , pkcs11h_getMessage(rv)); goto cleanup1; } - if ( - (dn =3D pkcs11_certificate_dn( - certificate, - &gc - )) =3D=3D NULL - ) + if ((dn =3D pkcs11_certificate_dn(certificate, &gc)) =3D=3D NULL) { goto cleanup1; } - if ( - (pkcs11_certificate_serial( - certificate, - serial, - sizeof(serial) - )) - ) + if ((pkcs11_certificate_serial(certificate, serial, sizeof(serial)= ))) { goto cleanup1; } - msg( - M_INFO|M_NOPREFIX|M_NOLF, - ( - "\n" - "Certificate\n" - " DN: %s\n" - " Serial: %s\n" - " Serialized id: %s\n" - ), - dn, - serial, - ser - ); + msg(M_INFO | M_NOPREFIX | M_NOLF, + ("\n" + "Certificate\n" + " DN: %s\n" + " Serial: %s\n" + " Serialized id: %s\n"), + dn, serial, ser); cleanup1: diff --git a/src/openvpn/pkcs11.h b/src/openvpn/pkcs11.h index 72913eb..e8f7df8 100644 --- a/src/openvpn/pkcs11.h +++ b/src/openvpn/pkcs11.h @@ -28,49 +28,24 @@ #include "ssl_common.h" -bool -pkcs11_initialize( - const bool fProtectedAuthentication, - const int nPINCachePeriod - ); +bool pkcs11_initialize(const bool fProtectedAuthentication, const int nPIN= CachePeriod); -void -pkcs11_terminate(void); +void pkcs11_terminate(void); -bool -pkcs11_addProvider( - const char *const provider, - const bool fProtectedAuthentication, - const unsigned private_mode, - const bool fCertIsPrivate - ); +bool pkcs11_addProvider(const char *const provider, const bool fProtectedA= uthentication, + const unsigned private_mode, const bool fCertIsPri= vate); -int -pkcs11_logout(void); +int pkcs11_logout(void); -int -pkcs11_management_id_count(void); +int pkcs11_management_id_count(void); -bool -pkcs11_management_id_get( - const int index, - char **id, - char **base64 - ); +bool pkcs11_management_id_get(const int index, char **id, char **base64); -int -tls_ctx_use_pkcs11( - struct tls_root_ctx *const ssl_ctx, - bool pkcs11_id_management, - const char *const pkcs11_id - ); +int tls_ctx_use_pkcs11(struct tls_root_ctx *const ssl_ctx, bool pkcs11_id_= management, + const char *const pkcs11_id); -void -show_pkcs11_ids( - const char *const provider, - bool cert_private - ); +void show_pkcs11_ids(const char *const provider, bool cert_private); -#endif /* ENABLE_PKCS11 */ +#endif /* ENABLE_PKCS11 */ -#endif /* OPENVPN_PKCS11H_H */ +#endif /* OPENVPN_PKCS11H_H */ diff --git a/src/openvpn/pkcs11_backend.h b/src/openvpn/pkcs11_backend.h index dce6822..834456f 100644 --- a/src/openvpn/pkcs11_backend.h +++ b/src/openvpn/pkcs11_backend.h @@ -57,8 +57,7 @@ * * @return 1 on failure, 0 on success */ -int pkcs11_certificate_serial(pkcs11h_certificate_t certificate, char *ser= ial, - size_t serial_len); +int pkcs11_certificate_serial(pkcs11h_certificate_t certificate, char *ser= ial, size_t serial_len); /** * Load PKCS #11 Certificate's information into the given TLS context @@ -68,8 +67,7 @@ * * @return 1 on failure, 0 on success */ -int pkcs11_init_tls_session(pkcs11h_certificate_t certificate, - struct tls_root_ctx *const ssl_ctx); +int pkcs11_init_tls_session(pkcs11h_certificate_t certificate, struct tls_= root_ctx *const ssl_ctx); #endif /* defined(ENABLE_PKCS11) */ #endif /* PKCS11_BACKEND_H_ */ diff --git a/src/openvpn/pkcs11_mbedtls.c b/src/openvpn/pkcs11_mbedtls.c index 13b8a86..21c9d47 100644 --- a/src/openvpn/pkcs11_mbedtls.c +++ b/src/openvpn/pkcs11_mbedtls.c @@ -47,16 +47,14 @@ size_t cert_blob_size =3D 0; bool ret =3D false; - if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, NULL, - &cert_blob_size) !=3D CKR_O= K) + if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, NULL, &cert_bl= ob_size) !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot retrieve certificate object size"); goto cleanup; } check_malloc_return((cert_blob =3D calloc(1, cert_blob_size))); - if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, cert_blob, - &cert_blob_size) !=3D CKR_O= K) + if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, cert_blob, &ce= rt_blob_size) !=3D CKR_OK) { msg(M_WARN, "PKCS#11: Cannot retrieve certificate object"); goto cleanup; @@ -75,16 +73,14 @@ } static bool -pkcs11_sign(void *pkcs11_cert, const void *src, size_t src_len, - void *dst, size_t dst_len) +pkcs11_sign(void *pkcs11_cert, const void *src, size_t src_len, void *dst,= size_t dst_len) { - return CKR_OK =3D=3D pkcs11h_certificate_signAny(pkcs11_cert, CKM_RSA_= PKCS, - src, src_len, dst, &dst_l= en); + return CKR_OK + =3D=3D pkcs11h_certificate_signAny(pkcs11_cert, CKM_RSA_PKCS, s= rc, src_len, dst, &dst_len); } int -pkcs11_init_tls_session(pkcs11h_certificate_t certificate, - struct tls_root_ctx *const ssl_ctx) +pkcs11_init_tls_session(pkcs11h_certificate_t certificate, struct tls_root= _ctx *const ssl_ctx) { ASSERT(NULL !=3D ssl_ctx); @@ -131,8 +127,7 @@ } int -pkcs11_certificate_serial(pkcs11h_certificate_t cert, char *serial, - size_t serial_len) +pkcs11_certificate_serial(pkcs11h_certificate_t cert, char *serial, size_t= serial_len) { int ret =3D 1; mbedtls_x509_crt mbed_crt =3D { 0 }; diff --git a/src/openvpn/pkcs11_openssl.c b/src/openvpn/pkcs11_openssl.c index e6baa43..3fc15e8 100644 --- a/src/openvpn/pkcs11_openssl.c +++ b/src/openvpn/pkcs11_openssl.c @@ -44,18 +44,21 @@ #ifdef HAVE_XKEY_PROVIDER static XKEY_EXTERNAL_SIGN_fn xkey_pkcs11h_sign; -#if PKCS11H_VERSION > ((1<<16) | (27<<8)) /* version > 1.27 */ +#if PKCS11H_VERSION > ((1 << 16) | (27 << 8)) /* version > 1.27 */ /* Table linking OpenSSL digest NID with CKM and CKG constants in PKCS#11 = */ -#define MD_TYPE(n) {NID_sha ## n, CKM_SHA ## n, CKG_MGF1_SHA ## n} +#define MD_TYPE(n) { NID_sha##n, CKM_SHA##n, CKG_MGF1_SHA##n } static const struct { int nid; unsigned long ckm_id; unsigned long mgf_id; -} mdtypes[] =3D {MD_TYPE(224), MD_TYPE(256), MD_TYPE(384), MD_TYPE(512), - {NID_sha1, CKM_SHA_1, CKG_MGF1_SHA1}, /* SHA_1 naming is an= oddity */ - {NID_undef, 0, 0}}; +} mdtypes[] =3D { MD_TYPE(224), + MD_TYPE(256), + MD_TYPE(384), + MD_TYPE(512), + { NID_sha1, CKM_SHA_1, CKG_MGF1_SHA1 }, /* SHA_1 naming is= an oddity */ + { NID_undef, 0, 0 } }; /* From sigalg, derive parameters for pss signature and fill in pss_param= s. * Its of type CK_RSA_PKCS_PSS_PARAMS struct with three fields to be fille= d in: @@ -63,15 +66,13 @@ * where hashAlg is CKM_SHA256 etc., mgf is CKG_MGF1_SHA256 etc. */ static int -set_pss_params(CK_RSA_PKCS_PSS_PARAMS *pss_params, XKEY_SIGALG sigalg, - pkcs11h_certificate_t cert) +set_pss_params(CK_RSA_PKCS_PSS_PARAMS *pss_params, XKEY_SIGALG sigalg, pkc= s11h_certificate_t cert) { int ret =3D 0; X509 *x509 =3D NULL; EVP_PKEY *pubkey =3D NULL; - if ((x509 =3D pkcs11h_openssl_getX509(cert)) =3D=3D NULL - || (pubkey =3D X509_get0_pubkey(x509)) =3D=3D NULL) + if ((x509 =3D pkcs11h_openssl_getX509(cert)) =3D=3D NULL || (pubkey = =3D X509_get0_pubkey(x509)) =3D=3D NULL) { msg(M_WARN, "PKCS#11: Unable get public key"); goto cleanup; @@ -91,8 +92,10 @@ const EVP_MD *md =3D EVP_get_digestbyname(sigalg.mdname); if (!md) { - msg(M_WARN, "WARN: set_pss_params: EVP_get_digestbyname returned N= ULL " - "for mdname =3D <%s>", sigalg.mdname); + msg(M_WARN, + "WARN: set_pss_params: EVP_get_digestbyname returned NULL " + "for mdname =3D <%s>", + sigalg.mdname); goto cleanup; } int mdsize =3D EVP_MD_get_size(md); @@ -109,14 +112,16 @@ =20 if (saltlen < 0 || pss_params->hashAlg =3D=3D 0) { - msg(M_WARN, "WARN: invalid RSA_PKCS1_PSS parameters: saltlen =3D <= %s> " - "mdname =3D <%s>.", sigalg.saltlen, sigalg.mdname); + msg(M_WARN, + "WARN: invalid RSA_PKCS1_PSS parameters: saltlen =3D <%s> " + "mdname =3D <%s>.", + sigalg.saltlen, sigalg.mdname); goto cleanup; } - pss_params->sLen =3D (unsigned long) saltlen; /* saltlen >=3D 0 at thi= s point */ + pss_params->sLen =3D (unsigned long)saltlen; /* saltlen >=3D 0 at this= point */ - msg(D_XKEY, "set_pss_params: sLen =3D %lu, hashAlg =3D %lu, mgf =3D %l= u", - pss_params->sLen, pss_params->hashAlg, pss_params->mgf); + msg(D_XKEY, "set_pss_params: sLen =3D %lu, hashAlg =3D %lu, mgf =3D %l= u", pss_params->sLen, + pss_params->hashAlg, pss_params->mgf); ret =3D 1; @@ -139,14 +144,14 @@ * is PSS in which case we return an error. */ static CK_RV -pkcs11h_certificate_signAny_ex(const pkcs11h_certificate_t cert, - const CK_MECHANISM *mech, const unsigned ch= ar *tbs, - size_t tbslen, unsigned char *sig, size_t *= siglen) +pkcs11h_certificate_signAny_ex(const pkcs11h_certificate_t cert, const CK_= MECHANISM *mech, + const unsigned char *tbs, size_t tbslen, un= signed char *sig, + size_t *siglen) { if (mech->mechanism =3D=3D CKM_RSA_PKCS_PSS) { msg(M_NONFATAL, "PKCS#11: Error: PSS padding is not supported by " - "this version of pkcs11-helper library."); + "this version of pkcs11-helper library."); return CKR_MECHANISM_INVALID; } return pkcs11h_certificate_signAny(cert, mech->mechanism, tbs, tbslen,= sig, siglen); @@ -159,12 +164,12 @@ * We support ECDSA, RSA_NO_PADDING, RSA_PKCS1_PADDING, RSA_PKCS_PSS_PADDI= NG */ static int -xkey_pkcs11h_sign(void *handle, unsigned char *sig, - size_t *siglen, const unsigned char *tbs, size_t tbslen,= XKEY_SIGALG sigalg) +xkey_pkcs11h_sign(void *handle, unsigned char *sig, size_t *siglen, const = unsigned char *tbs, + size_t tbslen, XKEY_SIGALG sigalg) { pkcs11h_certificate_t cert =3D handle; - CK_MECHANISM mech =3D {CKM_RSA_PKCS, NULL, 0}; /* default value */ - CK_RSA_PKCS_PSS_PARAMS pss_params =3D {0}; + CK_MECHANISM mech =3D { CKM_RSA_PKCS, NULL, 0 }; /* default value */ + CK_RSA_PKCS_PSS_PARAMS pss_params =3D { 0 }; unsigned char buf[EVP_MAX_MD_SIZE]; size_t buflen =3D 0; @@ -179,7 +184,7 @@ if (xkey_digest(tbs, tbslen, buf, &buflen, sigalg.mdname)) { tbs =3D buf; - tbslen =3D (size_t) buflen; + tbslen =3D (size_t)buflen; sigalg.op =3D "Sign"; } else @@ -195,8 +200,7 @@ } else if (!strcmp(sigalg.keytype, "RSA")) { - msg(D_XKEY, "xkey_pkcs11h_sign: signing with RSA key: padmode =3D = %s", - sigalg.padmode); + msg(D_XKEY, "xkey_pkcs11h_sign: signing with RSA key: padmode =3D = %s", sigalg.padmode); if (!strcmp(sigalg.padmode, "none")) { mech.mechanism =3D CKM_RSA_X_509; @@ -231,11 +235,10 @@ } else { - ASSERT(0); /* coding error -- we couldnt have created any such ke= y */ + ASSERT(0); /* coding error -- we couldnt have created any such key= */ } - if (CKR_OK !=3D pkcs11h_certificate_signAny_ex(cert, &mech, - tbs, tbslen, sig, siglen)) + if (CKR_OK !=3D pkcs11h_certificate_signAny_ex(cert, &mech, tbs, tbsle= n, sig, siglen)) { return 0; } @@ -245,7 +248,7 @@ } /* For EC keys, pkcs11 returns signature as r|s: convert to der encode= d */ - int derlen =3D ecdsa_bin2der(sig, (int) *siglen, siglen_max); + int derlen =3D ecdsa_bin2der(sig, (int)*siglen, siglen_max); if (derlen <=3D 0) { @@ -275,8 +278,7 @@ * other xkey_load_.. routines */ static int -xkey_load_from_pkcs11h(pkcs11h_certificate_t certificate, - struct tls_root_ctx *const ctx) +xkey_load_from_pkcs11h(pkcs11h_certificate_t certificate, struct tls_root_= ctx *const ctx) { int ret =3D 0; @@ -327,10 +329,8 @@ #endif /* HAVE_XKEY_PROVIDER */ int -pkcs11_init_tls_session(pkcs11h_certificate_t certificate, - struct tls_root_ctx *const ssl_ctx) +pkcs11_init_tls_session(pkcs11h_certificate_t certificate, struct tls_root= _ctx *const ssl_ctx) { - #ifdef HAVE_XKEY_PROVIDER return (xkey_load_from_pkcs11h(certificate, ssl_ctx) =3D=3D 0); /* inv= erts the return value */ #else @@ -404,7 +404,7 @@ openssl_session =3D NULL; } return ret; -#endif /* ifdef HAVE_XKEY_PROVIDER */ +#endif /* ifdef H= AVE_XKEY_PROVIDER */ } char * @@ -430,8 +430,7 @@ } int -pkcs11_certificate_serial(pkcs11h_certificate_t certificate, char *serial, - size_t serial_len) +pkcs11_certificate_serial(pkcs11h_certificate_t certificate, char *serial,= size_t serial_len) { X509 *x509 =3D NULL; BIO *bio =3D NULL; @@ -451,9 +450,9 @@ } i2a_ASN1_INTEGER(bio, X509_get_serialNumber(x509)); - n =3D BIO_read(bio, serial, serial_len-1); + n =3D BIO_read(bio, serial, serial_len - 1); - if (n<0) + if (n < 0) { serial[0] =3D '\x0'; } diff --git a/src/openvpn/platform.c b/src/openvpn/platform.c index b690192..bfab104 100644 --- a/src/openvpn/platform.c +++ b/src/openvpn/platform.c @@ -67,8 +67,10 @@ msg(M_ERR, "cd to '%s' failed", top); } msg(M_INFO, "chroot to '%s' and cd to '%s' succeeded", path, top); -#else /* ifdef HAVE_CHROOT */ - msg(M_FATAL, "Sorry but I can't chroot to '%s' because this operat= ing system doesn't appear to support the chroot() system call", path); +#else /* ifdef HAVE_CHROOT */ + msg(M_FATAL, + "Sorry but I can't chroot to '%s' because this operating syste= m doesn't appear to support the chroot() system call", + path); #endif } } @@ -95,8 +97,10 @@ } state->username =3D username; ret =3D true; -#else /* if defined(HAVE_GETPWNAM) && defined(HAVE_SETUID) */ - msg(M_FATAL, "cannot get UID for user %s -- platform lacks getpwna= me() or setuid() system calls", username); +#else /* if defined(HAVE_GETPWNAM) && defined(HAVE_SETUID) */ + msg(M_FATAL, + "cannot get UID for user %s -- platform lacks getpwname() or s= etuid() system calls", + username); #endif } return ret; @@ -139,8 +143,10 @@ } state->groupname =3D groupname; ret =3D true; -#else /* if defined(HAVE_GETGRNAM) && defined(HAVE_SETGID) */ - msg(M_FATAL, "cannot get GID for group %s -- platform lacks getgrn= am() or setgid() system calls", groupname); +#else /* if defined(HAVE_GETGRNAM) && defined(HAVE_SETGID) */ + msg(M_FATAL, + "cannot get GID for group %s -- platform lacks getgrnam() or s= etgid() system calls", + groupname); #endif } return ret; @@ -215,8 +221,7 @@ */ void platform_user_group_set(const struct platform_state_user *user_state, - const struct platform_state_group *group_state, - struct context *c) + const struct platform_state_group *group_state, st= ruct context *c) { int keep_caps =3D need_keep_caps(c); unsigned int err_flags =3D (keep_caps > 0) ? M_FATAL : M_NONFATAL; @@ -259,8 +264,8 @@ { /* -4 and -6 mean failure of setuid/gid respectively. * There is no point for us to continue if those failed. */ - msg(M_ERR, "capng_change_id('%s','%s') failed: %d", - user_state->username, group_state->groupname, res); + msg(M_ERR, "capng_change_id('%s','%s') failed: %d", user_state->us= ername, + group_state->groupname, res); } else if (res =3D=3D -3) { @@ -295,7 +300,7 @@ { msg(M_ERR, "Clearing KEEPCAPS flag failed"); } -#endif /* HAVE_LIBCAPNG */ +#endif /* HAVE_LIBCAPNG */ if (keep_caps) { @@ -322,7 +327,7 @@ { msg(M_INFO, "nice %d succeeded", niceval); } -#else /* ifdef HAVE_NICE */ +#else /* ifdef HAVE_NICE */ msg(M_WARN, "WARNING: nice %d failed (function not implemented)", = niceval); #endif } @@ -333,9 +338,9 @@ platform_getpid(void) { #ifdef _WIN32 - return (unsigned int) GetCurrentProcessId(); + return (unsigned int)GetCurrentProcessId(); #else - return (unsigned int) getpid(); + return (unsigned int)getpid(); #endif } @@ -355,12 +360,11 @@ else { msg(M_INFO, "mlock: MEMLOCK limit: soft=3D%ld KB, hard=3D%ld KB", - ((long int) rl.rlim_cur) / 1024, ((long int) rl.rlim_max) / 10= 24); - if (rl.rlim_cur < MIN_LOCKED_MEM_MB*1024*1024) + ((long int)rl.rlim_cur) / 1024, ((long int)rl.rlim_max) / 1024= ); + if (rl.rlim_cur < MIN_LOCKED_MEM_MB * 1024 * 1024) { - msg(M_INFO, "mlock: RLIMIT_MEMLOCK < %d MB, increase limit", - MIN_LOCKED_MEM_MB); - rl.rlim_cur =3D MIN_LOCKED_MEM_MB*1024*1024; + msg(M_INFO, "mlock: RLIMIT_MEMLOCK < %d MB, increase limit", M= IN_LOCKED_MEM_MB); + rl.rlim_cur =3D MIN_LOCKED_MEM_MB * 1024 * 1024; if (rl.rlim_max < rl.rlim_cur) { rl.rlim_max =3D rl.rlim_cur; @@ -398,10 +402,10 @@ res =3D _wchdir(wide_string(dir, &gc)); gc_free(&gc); return res; -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ #ifdef HAVE_CHDIR return chdir(dir); -#else /* ifdef HAVE_CHDIR */ +#else /* ifdef HAVE_CHDIR */ return -1; #endif #endif @@ -551,9 +555,8 @@ { ++attempts; - if (!snprintf(fname, sizeof(fname), fname_fmt, max_prefix_len, - prefix, (unsigned long) get_random(), - (unsigned long) get_random())) + if (!snprintf(fname, sizeof(fname), fname_fmt, max_prefix_len, pre= fix, + (unsigned long)get_random(), (unsigned long)get_rand= om())) { msg(M_WARN, "ERROR: temporary filename too long"); return NULL; @@ -577,8 +580,7 @@ else if (fd =3D=3D -1 && errno !=3D EEXIST) { /* Something else went wrong, no need to retry. */ - msg(M_WARN | M_ERRNO, "Could not create temporary file '%s'", - retfname); + msg(M_WARN | M_ERRNO, "Could not create temporary file '%s'", = retfname); return NULL; } } @@ -591,12 +593,12 @@ * Put a directory and filename together. */ const char * -platform_gen_path(const char *directory, const char *filename, - struct gc_arena *gc) +platform_gen_path(const char *directory, const char *filename, struct gc_a= rena *gc) { #ifdef _WIN32 - const int CC_PATH_RESERVED =3D CC_LESS_THAN|CC_GREATER_THAN|CC_COLON - |CC_DOUBLE_QUOTE|CC_SLASH|CC_BACKSLASH|CC= _PIPE|CC_QUESTION_MARK|CC_ASTERISK; + const int CC_PATH_RESERVED =3D CC_LESS_THAN | CC_GREATER_THAN | CC_COL= ON | CC_DOUBLE_QUOTE + | CC_SLASH | CC_BACKSLASH | CC_PIPE | CC_= QUESTION_MARK + | CC_ASTERISK; #else const int CC_PATH_RESERVED =3D CC_SLASH; #endif @@ -608,13 +610,11 @@ const char *safe_filename =3D string_mod_const(filename, CC_PRINT, CC_= PATH_RESERVED, '_', gc); - if (safe_filename - && strcmp(safe_filename, ".") - && strcmp(safe_filename, "..") + if (safe_filename && strcmp(safe_filename, ".") && strcmp(safe_filenam= e, "..") #ifdef _WIN32 && win_safe_filename(safe_filename) #endif - ) + ) { const size_t outsize =3D strlen(safe_filename) + (directory ? strl= en(directory) : 0) + 16; struct buffer out =3D alloc_buf_gc(outsize, gc); @@ -672,14 +672,12 @@ { if (errno =3D=3D EACCES) { - msg( M_WARN | M_ERRNO, "Could not access file '%s'", filen= ame); + msg(M_WARN | M_ERRNO, "Could not access file '%s'", filena= me); } } } - dmsg(D_TEST_FILE, "TEST FILE '%s' [%d]", - filename ? filename : "UNDEF", - ret); + dmsg(D_TEST_FILE, "TEST FILE '%s' [%d]", filename ? filename : "UNDEF"= , ret); return ret; } diff --git a/src/openvpn/platform.h b/src/openvpn/platform.h index 56f8909..b3b13a7 100644 --- a/src/openvpn/platform.h +++ b/src/openvpn/platform.h @@ -60,7 +60,8 @@ /* Get/Set UID of process */ -struct platform_state_user { +struct platform_state_user +{ #if defined(HAVE_GETPWNAM) && defined(HAVE_SETUID) const char *username; uid_t uid; @@ -71,7 +72,8 @@ /* Get/Set GID of process */ -struct platform_state_group { +struct platform_state_group +{ #if defined(HAVE_GETGRNAM) && defined(HAVE_SETGID) const char *groupname; gid_t gid; @@ -85,8 +87,7 @@ bool platform_group_get(const char *groupname, struct platform_state_group= *state); void platform_user_group_set(const struct platform_state_user *user_state, - const struct platform_state_group *group_stat= e, - struct context *c); + const struct platform_state_group *group_stat= e, struct context *c); /* @@ -117,7 +118,7 @@ unsigned int platform_getpid(void); -void platform_mlockall(bool print_msg); /* Disable paging */ +void platform_mlockall(bool print_msg); /* Disable paging */ int platform_chdir(const char *dir); @@ -153,8 +154,7 @@ struct gc_arena *gc); /** Put a directory and filename together. */ -const char *platform_gen_path(const char *directory, const char *filename, - struct gc_arena *gc); +const char *platform_gen_path(const char *directory, const char *filename,= struct gc_arena *gc); /** Return true if pathname is absolute. */ bool platform_absolute_pathname(const char *pathname); diff --git a/src/openvpn/plugin.c b/src/openvpn/plugin.c index bafa469..02de931 100644 --- a/src/openvpn/plugin.c +++ b/src/openvpn/plugin.c @@ -45,7 +45,7 @@ #include "win32.h" #include "memdbg.h" -#define PLUGIN_SYMBOL_REQUIRED (1<<0) +#define PLUGIN_SYMBOL_REQUIRED (1 << 0) /* used only for program aborts */ static struct plugin_common *static_plugin_common =3D NULL; /* GLOBAL */ @@ -153,7 +153,7 @@ static inline unsigned int plugin_supported_types(void) { - return ((1<n < MAX_PLUGINS) { @@ -194,7 +193,8 @@ for (i =3D 0; i < list->n; ++i) { const struct plugin_option *o =3D &list->plugins[i]; - msg(msglevel, " plugin[%d] %s '%s'", i, o->so_pathname, print_arg= v(o->argv, &gc, PA_BRACKET)); + msg(msglevel, " plugin[%d] %s '%s'", i, o->so_pathname, + print_argv(o->argv, &gc, PA_BRACKET)); } gc_free(&gc); @@ -204,24 +204,28 @@ #ifndef _WIN32 static void -libdl_resolve_symbol(void *handle, void **dest, const char *symbol, const = char *plugin_name, const unsigned int flags) +libdl_resolve_symbol(void *handle, void **dest, const char *symbol, const = char *plugin_name, + const unsigned int flags) { *dest =3D dlsym(handle, symbol); if ((flags & PLUGIN_SYMBOL_REQUIRED) && !*dest) { - msg(M_FATAL, "PLUGIN: could not find required symbol '%s' in plugi= n shared object %s: %s", symbol, plugin_name, dlerror()); + msg(M_FATAL, "PLUGIN: could not find required symbol '%s' in plugi= n shared object %s: %s", + symbol, plugin_name, dlerror()); } } #else /* ifndef _WIN32 */ static void -dll_resolve_symbol(HMODULE module, void **dest, const char *symbol, const = char *plugin_name, const unsigned int flags) +dll_resolve_symbol(HMODULE module, void **dest, const char *symbol, const = char *plugin_name, + const unsigned int flags) { *dest =3D GetProcAddress(module, symbol); if ((flags & PLUGIN_SYMBOL_REQUIRED) && !*dest) { - msg(M_FATAL, "PLUGIN: could not find required symbol '%s' in plugi= n DLL %s", symbol, plugin_name); + msg(M_FATAL, "PLUGIN: could not find required symbol '%s' in plugi= n DLL %s", symbol, + plugin_name); } } @@ -255,8 +259,7 @@ * was parsed. * */ - if (!platform_absolute_pathname(p->so_pathname) - && p->so_pathname[0] !=3D '.') + if (!platform_absolute_pathname(p->so_pathname) && p->so_pathname[0] != =3D '.') { char full[PATH_MAX]; @@ -270,24 +273,29 @@ } if (!p->handle) { - msg(M_ERR, "PLUGIN_INIT: could not load plugin shared object %s: %= s", p->so_pathname, dlerror()); + msg(M_ERR, "PLUGIN_INIT: could not load plugin shared object %s: %= s", p->so_pathname, + dlerror()); } -#define PLUGIN_SYM(var, name, flags) libdl_resolve_symbol(p->handle, (void= *)&p->var, name, p->so_pathname, flags) +#define PLUGIN_SYM(var, name, flags) \ + libdl_resolve_symbol(p->handle, (void *)&p->var, name, p->so_pathname,= flags) -#else /* ifndef _WIN32 */ +#else /* ifndef _WIN32 */ WCHAR *wpath =3D wide_string(p->so_pathname, &gc); - WCHAR normalized_plugin_path[MAX_PATH] =3D {0}; + WCHAR normalized_plugin_path[MAX_PATH] =3D { 0 }; /* Normalize the plugin path, converting any relative paths to absolut= e paths. */ if (!GetFullPathNameW(wpath, MAX_PATH, normalized_plugin_path, NULL)) { - msg(M_ERR, "PLUGIN_INIT: could not load plugin DLL: %ls. Failed to= normalize plugin path.", wpath); + msg(M_ERR, "PLUGIN_INIT: could not load plugin DLL: %ls. Failed to= normalize plugin path.", + wpath); } if (!plugin_in_trusted_dir(normalized_plugin_path)) { - msg(M_FATAL, "PLUGIN_INIT: could not load plugin DLL: %ls. The DLL= is not in a trusted directory.", normalized_plugin_path); + msg(M_FATAL, + "PLUGIN_INIT: could not load plugin DLL: %ls. The DLL is not i= n a trusted directory.", + normalized_plugin_path); } p->module =3D LoadLibraryW(normalized_plugin_path); @@ -296,7 +304,8 @@ msg(M_ERR, "PLUGIN_INIT: could not load plugin DLL: %ls", normaliz= ed_plugin_path); } -#define PLUGIN_SYM(var, name, flags) dll_resolve_symbol(p->module, (void *= )&p->var, name, p->so_pathname, flags) +#define PLUGIN_SYM(var, name, flags) \ + dll_resolve_symbol(p->module, (void *)&p->var, name, p->so_pathname, f= lags) #endif /* ifndef _WIN32 */ @@ -315,12 +324,14 @@ if (!p->open1 && !p->open2 && !p->open3) { - msg(M_FATAL, "PLUGIN: symbol openvpn_plugin_open_vX is undefined i= n plugin: %s", p->so_pathname); + msg(M_FATAL, "PLUGIN: symbol openvpn_plugin_open_vX is undefined i= n plugin: %s", + p->so_pathname); } if (!p->func1 && !p->func2 && !p->func3) { - msg(M_FATAL, "PLUGIN: symbol openvpn_plugin_func_vX is undefined i= n plugin: %s", p->so_pathname); + msg(M_FATAL, "PLUGIN: symbol openvpn_plugin_func_vX is undefined i= n plugin: %s", + p->so_pathname); } /* @@ -331,10 +342,9 @@ const int plugin_needs_version =3D (*p->min_version_required)(); if (plugin_needs_version > OPENVPN_PLUGIN_VERSION) { - msg(M_FATAL, "PLUGIN_INIT: plugin needs interface version %d, = but this version of OpenVPN only supports version %d: %s", - plugin_needs_version, - OPENVPN_PLUGIN_VERSION, - p->so_pathname); + msg(M_FATAL, + "PLUGIN_INIT: plugin needs interface version %d, but this = version of OpenVPN only supports version %d: %s", + plugin_needs_version, OPENVPN_PLUGIN_VERSION, p->so_pathna= me); } } @@ -349,7 +359,9 @@ if (rel) { - msg(M_WARN, "WARNING: plugin '%s' specified by a relative pathname= -- using an absolute pathname would be more secure", p->so_pathname); + msg(M_WARN, + "WARNING: plugin '%s' specified by a relative pathname -- usin= g an absolute pathname would be more secure", + p->so_pathname); } p->initialized =3D true; @@ -428,9 +440,9 @@ static struct openvpn_plugin_callbacks callbacks =3D { plugin_log, plugin_vlog, - secure_memzero, /* plugin_secure_memzero */ - openvpn_base64_encode, /* plugin_base64_encode */ - openvpn_base64_decode, /* plugin_base64_decode */ + secure_memzero, /* plugin_secure_memzero */ + openvpn_base64_encode, /* plugin_base64_encode */ + openvpn_base64_decode, /* plugin_base64_decode */ }; @@ -445,10 +457,8 @@ #endif static void -plugin_open_item(struct plugin *p, - const struct plugin_option *o, - struct openvpn_plugin_string_list **retlist, - const char **envp, +plugin_open_item(struct plugin *p, const struct plugin_option *o, + struct openvpn_plugin_string_list **retlist, const char *= *envp, const int init_point) { ASSERT(p->initialized); @@ -472,19 +482,20 @@ if (p->open3) { struct openvpn_plugin_args_open_in args =3D { p->plugin_type_m= ask, - (const char **cons= t) o->argv, - (const char **cons= t) envp, + (const char **cons= t)o->argv, + (const char **cons= t)envp, &callbacks, SSLAPI, PACKAGE_VERSION, OPENVPN_VERSION_MA= JOR, OPENVPN_VERSION_MI= NOR, - _OPENVPN_PATCH_LEV= EL}; + _OPENVPN_PATCH_LEV= EL }; struct openvpn_plugin_args_open_return retargs; CLEAR(retargs); retargs.return_list =3D retlist; - if ((*p->open3)(OPENVPN_PLUGINv3_STRUCTVER, &args, &retargs) = =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) + if ((*p->open3)(OPENVPN_PLUGINv3_STRUCTVER, &args, &retargs) + =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) { p->plugin_type_mask =3D retargs.type_mask; p->plugin_handle =3D retargs.handle; @@ -507,24 +518,20 @@ ASSERT(0); } - msg(D_PLUGIN, "PLUGIN_INIT: POST %s '%s' intercepted=3D%s %s", - p->so_pathname, - print_argv(o->argv, &gc, PA_BRACKET), - plugin_mask_string(p->plugin_type_mask, &gc), + msg(D_PLUGIN, "PLUGIN_INIT: POST %s '%s' intercepted=3D%s %s", p->= so_pathname, + print_argv(o->argv, &gc, PA_BRACKET), plugin_mask_string(p->pl= ugin_type_mask, &gc), (retlist && *retlist) ? "[RETLIST]" : ""); if ((p->plugin_type_mask | plugin_supported_types()) !=3D plugin_s= upported_types()) { - msg(M_FATAL, "PLUGIN_INIT: plugin %s expressed interest in uns= upported plugin types: [want=3D0x%08x, have=3D0x%08x]", - p->so_pathname, - p->plugin_type_mask, - plugin_supported_types()); + msg(M_FATAL, + "PLUGIN_INIT: plugin %s expressed interest in unsupported = plugin types: [want=3D0x%08x, have=3D0x%08x]", + p->so_pathname, p->plugin_type_mask, plugin_supported_type= s()); } if (p->plugin_handle =3D=3D NULL) { - msg(M_FATAL, "PLUGIN_INIT: plugin initialization function fail= ed: %s", - p->so_pathname); + msg(M_FATAL, "PLUGIN_INIT: plugin initialization function fail= ed: %s", p->so_pathname); } gc_free(&gc); @@ -532,15 +539,9 @@ } static int -plugin_call_item(const struct plugin *p, - void *per_client_context, - const int type, - const struct argv *av, - struct openvpn_plugin_string_list **retlist, - const char **envp, - int certdepth, - openvpn_x509_cert_t *current_cert - ) +plugin_call_item(const struct plugin *p, void *per_client_context, const i= nt type, + const struct argv *av, struct openvpn_plugin_string_list = **retlist, + const char **envp, int certdepth, openvpn_x509_cert_t *cu= rrent_cert) { int status =3D OPENVPN_PLUGIN_FUNC_SUCCESS; @@ -564,8 +565,8 @@ if (p->func3) { struct openvpn_plugin_args_func_in args =3D { type, - (const char **cons= t) a.argv, - (const char **cons= t) envp, + (const char **cons= t)a.argv, + (const char **cons= t)envp, p->plugin_handle, per_client_context, (current_cert ? ce= rtdepth : -1), @@ -579,7 +580,8 @@ } else if (p->func2) { - status =3D (*p->func2)(p->plugin_handle, type, (const char **)= a.argv, envp, per_client_context, retlist); + status =3D (*p->func2)(p->plugin_handle, type, (const char **)= a.argv, envp, + per_client_context, retlist); } else if (p->func1) { @@ -590,17 +592,13 @@ ASSERT(0); } - msg(D_PLUGIN, "PLUGIN_CALL: POST %s/%s status=3D%d", - p->so_pathname, - plugin_type_name(type), + msg(D_PLUGIN, "PLUGIN_CALL: POST %s/%s status=3D%d", p->so_pathnam= e, plugin_type_name(type), status); if (status =3D=3D OPENVPN_PLUGIN_FUNC_ERROR) { msg(M_WARN, "PLUGIN_CALL: plugin function %s failed with statu= s %d: %s", - plugin_type_name(type), - status, - p->so_pathname); + plugin_type_name(type), status, p->so_pathname); } argv_free(&a); @@ -653,8 +651,7 @@ } static void -plugin_per_client_init(const struct plugin_common *pc, - struct plugin_per_client *cli, +plugin_per_client_init(const struct plugin_common *pc, struct plugin_per_c= lient *cli, const int init_point) { const int n =3D pc->n; @@ -663,8 +660,7 @@ for (i =3D 0; i < n; ++i) { const struct plugin *p =3D &pc->plugins[i]; - if (p->plugin_handle - && (init_point < 0 || init_point =3D=3D p->requested_initializ= ation_point) + if (p->plugin_handle && (init_point < 0 || init_point =3D=3D p->re= quested_initialization_point) && p->client_constructor) { cli->per_client_context[i] =3D (*p->client_constructor)(p->plu= gin_handle); @@ -712,8 +708,7 @@ for (i =3D 0; i < list->n; ++i) { - plugin_init_item(&pc->plugins[i], - &list->plugins[i]); + plugin_init_item(&pc->plugins[i], &list->plugins[i]); pc->n =3D i + 1; } @@ -722,11 +717,8 @@ } static void -plugin_common_open(struct plugin_common *pc, - const struct plugin_option_list *list, - struct plugin_return *pr, - const struct env_set *es, - const int init_point) +plugin_common_open(struct plugin_common *pc, const struct plugin_option_li= st *list, + struct plugin_return *pr, const struct env_set *es, con= st int init_point) { struct gc_arena gc =3D gc_new(); int i; @@ -741,10 +733,7 @@ for (i =3D 0; i < pc->n; ++i) { - plugin_open_item(&pc->plugins[i], - &list->plugins[i], - pr ? &pr->list[i] : NULL, - envp, + plugin_open_item(&pc->plugins[i], &list->plugins[i], pr ? &pr->lis= t[i] : NULL, envp, init_point); } @@ -783,25 +772,17 @@ } void -plugin_list_open(struct plugin_list *pl, - const struct plugin_option_list *list, - struct plugin_return *pr, - const struct env_set *es, - const int init_point) +plugin_list_open(struct plugin_list *pl, const struct plugin_option_list *= list, + struct plugin_return *pr, const struct env_set *es, const= int init_point) { plugin_common_open(pl->common, list, pr, es, init_point); plugin_per_client_init(pl->common, &pl->per_client, init_point); } int -plugin_call_ssl(const struct plugin_list *pl, - const int type, - const struct argv *av, - struct plugin_return *pr, - struct env_set *es, - int certdepth, - openvpn_x509_cert_t *current_cert - ) +plugin_call_ssl(const struct plugin_list *pl, const int type, const struct= argv *av, + struct plugin_return *pr, struct env_set *es, int certdept= h, + openvpn_x509_cert_t *current_cert) { if (pr) { @@ -822,23 +803,16 @@ for (i =3D 0; i < n; ++i) { - const int status =3D plugin_call_item(&pl->common->plugins[i], - pl->per_client.per_client_= context[i], - type, - av, - pr ? &pr->list[i] : NULL, - envp, - certdepth, - current_cert - ); + const int status =3D + plugin_call_item(&pl->common->plugins[i], pl->per_client.p= er_client_context[i], + type, av, pr ? &pr->list[i] : NULL, envp,= certdepth, current_cert); switch (status) { case OPENVPN_PLUGIN_FUNC_SUCCESS: break; case OPENVPN_PLUGIN_FUNC_DEFERRED: - if ((type =3D=3D OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY) - && deferred_auth_done) + if ((type =3D=3D OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY)= && deferred_auth_done) { /* * Do not allow deferred auth if a deferred auth h= as @@ -855,13 +829,12 @@ * error, we bail out and exit the OpenVPN process. */ error =3D true; - msg(M_FATAL, - "Exiting due to multiple authentication plug-i= ns " - "performing deferred authentication. Only one= " - "authentication plug-in doing deferred auth is= " - "allowed. Ignoring the result and stopping no= w, " - "the current authentication result is not to b= e " - "trusted."); + msg(M_FATAL, "Exiting due to multiple authenticati= on plug-ins " + "performing deferred authentication. = Only one " + "authentication plug-in doing deferre= d auth is " + "allowed. Ignoring the result and st= opping now, " + "the current authentication result is= not to be " + "trusted."); break; } deferred_auth_done =3D true; @@ -997,8 +970,7 @@ } void -plugin_return_get_column(const struct plugin_return *src, - struct plugin_return *dest, +plugin_return_get_column(const struct plugin_return *src, struct plugin_re= turn *dest, const char *colname) { int i; @@ -1036,10 +1008,7 @@ msg(msglevel, "PLUGIN #%d (%s)", i, prefix); while (l) { - msg(msglevel, "[%d] '%s' -> '%s'\n", - ++count, - l->name, - l->value); + msg(msglevel, "[%d] '%s' -> '%s'\n", ++count, l->name, l->valu= e); l =3D l->next; } } diff --git a/src/openvpn/plugin.h b/src/openvpn/plugin.h index 5e91c60..9a7d9c6 100644 --- a/src/openvpn/plugin.h +++ b/src/openvpn/plugin.h @@ -42,17 +42,20 @@ #define MAX_PLUGINS 16 -struct plugin_option { +struct plugin_option +{ const char *so_pathname; const char **argv; }; -struct plugin_option_list { +struct plugin_option_list +{ int n; struct plugin_option plugins[MAX_PLUGINS]; }; -struct plugin { +struct plugin +{ bool initialized; const char *so_pathname; unsigned int plugin_type_mask; @@ -106,8 +109,7 @@ struct plugin_option_list *plugin_option_list_new(struct gc_arena *gc); -bool plugin_option_list_add(struct plugin_option_list *list, char **p, - struct gc_arena *gc); +bool plugin_option_list_add(struct plugin_option_list *list, char **p, str= uct gc_arena *gc); #ifndef ENABLE_SMALL void plugin_option_list_print(const struct plugin_option_list *list, int m= sglevel); @@ -116,29 +118,20 @@ struct plugin_list *plugin_list_init(const struct plugin_option_list *list= ); -void plugin_list_open(struct plugin_list *pl, - const struct plugin_option_list *list, - struct plugin_return *pr, - const struct env_set *es, - const int init_point); +void plugin_list_open(struct plugin_list *pl, const struct plugin_option_l= ist *list, + struct plugin_return *pr, const struct env_set *es, = const int init_point); struct plugin_list *plugin_list_inherit(const struct plugin_list *src); -int plugin_call_ssl(const struct plugin_list *pl, - const int type, - const struct argv *av, - struct plugin_return *pr, - struct env_set *es, - int current_cert_depth, - openvpn_x509_cert_t *current_cert - ); +int plugin_call_ssl(const struct plugin_list *pl, const int type, const st= ruct argv *av, + struct plugin_return *pr, struct env_set *es, int curr= ent_cert_depth, + openvpn_x509_cert_t *current_cert); void plugin_list_close(struct plugin_list *pl); bool plugin_defined(const struct plugin_list *pl, const int type); -void plugin_return_get_column(const struct plugin_return *src, - struct plugin_return *dest, +void plugin_return_get_column(const struct plugin_return *src, struct plug= in_return *dest, const char *colname); void plugin_return_free(struct plugin_return *pr); @@ -174,8 +167,14 @@ } #else /* ifdef ENABLE_PLUGIN */ -struct plugin_list { int dummy; }; -struct plugin_return { int dummy; }; +struct plugin_list +{ + int dummy; +}; +struct plugin_return +{ + int dummy; +}; static inline bool plugin_defined(const struct plugin_list *pl, const int type) @@ -184,14 +183,9 @@ } static inline int -plugin_call_ssl(const struct plugin_list *pl, - const int type, - const struct argv *av, - struct plugin_return *pr, - struct env_set *es, - int current_cert_depth, - openvpn_x509_cert_t *current_cert - ) +plugin_call_ssl(const struct plugin_list *pl, const int type, const struct= argv *av, + struct plugin_return *pr, struct env_set *es, int current_= cert_depth, + openvpn_x509_cert_t *current_cert) { return 0; } @@ -199,11 +193,8 @@ #endif /* ENABLE_PLUGIN */ static inline int -plugin_call(const struct plugin_list *pl, - const int type, - const struct argv *av, - struct plugin_return *pr, - struct env_set *es) +plugin_call(const struct plugin_list *pl, const int type, const struct arg= v *av, + struct plugin_return *pr, struct env_set *es) { return plugin_call_ssl(pl, type, av, pr, es, -1, NULL); } diff --git a/src/openvpn/pool.c b/src/openvpn/pool.c index ced172c..6ccfcd3 100644 --- a/src/openvpn/pool.c +++ b/src/openvpn/pool.c @@ -90,14 +90,11 @@ * Keep track of a possible allocation to us * from an earlier session. */ - if (previous_usage < 0 - && common_name - && ipe->common_name + if (previous_usage < 0 && common_name && ipe->common_name && !strcmp(common_name, ipe->common_name)) { previous_usage =3D i; } - } } @@ -126,16 +123,14 @@ if (start > end) { msg(msglevel, "--ifconfig-pool start IP [%s] is greater than end I= P [%s]", - print_in_addr_t(start, 0, &gc), - print_in_addr_t(end, 0, &gc)); + print_in_addr_t(start, 0, &gc), print_in_addr_t(end, 0, &gc)); ret =3D false; } if (end - start >=3D IFCONFIG_POOL_MAX) { - msg(msglevel, "--ifconfig-pool address range is too large [%s -> %= s]. Current maximum is %d addresses, as defined by IFCONFIG_POOL_MAX varia= ble.", - print_in_addr_t(start, 0, &gc), - print_in_addr_t(end, 0, &gc), - IFCONFIG_POOL_MAX); + msg(msglevel, + "--ifconfig-pool address range is too large [%s -> %s]. Curre= nt maximum is %d addresses, as defined by IFCONFIG_POOL_MAX variable.", + print_in_addr_t(start, 0, &gc), print_in_addr_t(end, 0, &gc), = IFCONFIG_POOL_MAX); ret =3D false; } gc_free(&gc); @@ -143,10 +138,9 @@ } struct ifconfig_pool * -ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t st= art, - in_addr_t end, const bool duplicate_cn, - const bool ipv6_pool, const struct in6_addr ipv6_base, - const int ipv6_netbits ) +ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t st= art, in_addr_t end, + const bool duplicate_cn, const bool ipv6_pool, const st= ruct in6_addr ipv6_base, + const int ipv6_netbits) { struct gc_arena gc =3D gc_new(); struct ifconfig_pool *pool =3D NULL; @@ -180,8 +174,7 @@ if (pool_ipv4_size < 2) { - msg(M_FATAL, "IPv4 pool size is too small (%d), must be at lea= st 2", - pool_ipv4_size); + msg(M_FATAL, "IPv4 pool size is too small (%d), must be at lea= st 2", pool_ipv4_size); } msg(D_IFCONFIG_POOL, "IFCONFIG POOL IPv4: base=3D%s size=3D%d", @@ -199,10 +192,8 @@ * 4 bytes, therefore we can just extract that and use it as base = in * integer form */ - uint32_t base =3D (ipv6_base.s6_addr[12] << 24) - | (ipv6_base.s6_addr[13] << 16) - | (ipv6_base.s6_addr[14] << 8) - | ipv6_base.s6_addr[15]; + uint32_t base =3D (ipv6_base.s6_addr[12] << 24) | (ipv6_base.s6_ad= dr[13] << 16) + | (ipv6_base.s6_addr[14] << 8) | ipv6_base.s6_addr= [15]; /* some bits of the last 4 bytes may still be part of the network * portion of the address, therefore we need to set them to 0 */ @@ -215,7 +206,7 @@ * the following operation first computes mask=3D0x3fffff and = then * uses mask to extract the wanted bits from base */ - uint32_t mask =3D (1 << (128 - ipv6_netbits) ) - 1; + uint32_t mask =3D (1 << (128 - ipv6_netbits)) - 1; base &=3D mask; } @@ -233,24 +224,21 @@ if (base =3D=3D 0) { msg(D_IFCONFIG_POOL, "IFCONFIG POOL IPv6: incrementing pool st= art " - "to avoid ::0 assignment"); + "to avoid ::0 assignment"); base++; pool->ipv6.base.s6_addr[15]++; } - pool_ipv6_size =3D ipv6_netbits >=3D 112 - ? (1 << (128 - ipv6_netbits)) - base - : IFCONFIG_POOL_MAX; + pool_ipv6_size =3D + ipv6_netbits >=3D 112 ? (1 << (128 - ipv6_netbits)) - base : I= FCONFIG_POOL_MAX; if (pool_ipv6_size < 2) { - msg(M_FATAL, "IPv6 pool size is too small (%d), must be at lea= st 2", - pool_ipv6_size); + msg(M_FATAL, "IPv6 pool size is too small (%d), must be at lea= st 2", pool_ipv6_size); } msg(D_IFCONFIG_POOL, "IFCONFIG POOL IPv6: base=3D%s size=3D%d netb= its=3D%d", - print_in6_addr(pool->ipv6.base, 0, &gc), pool_ipv6_size, - ipv6_netbits); + print_in6_addr(pool->ipv6.base, 0, &gc), pool_ipv6_size, ipv6_= netbits); /* if there is no v4 pool, or the v6 pool is smaller, use * v6 pool size as "unified pool size" @@ -265,16 +253,20 @@ { if (pool_ipv4_size < pool_ipv6_size) { - msg(M_INFO, "NOTE: IPv4 pool size is %d, IPv6 pool size is %d.= " + msg(M_INFO, + "NOTE: IPv4 pool size is %d, IPv6 pool size is %d. " "IPv4 pool size limits the number of clients that can be " - "served from the pool", pool_ipv4_size, pool_ipv6_size); + "served from the pool", + pool_ipv4_size, pool_ipv6_size); } else if (pool_ipv4_size > pool_ipv6_size) { - msg(M_WARN, "WARNING: IPv4 pool size is %d, IPv6 pool size is = %d. " + msg(M_WARN, + "WARNING: IPv4 pool size is %d, IPv6 pool size is %d. " "IPv6 pool size limits the number of clients that can be " "served from the pool. This is likely a MISTAKE - please c= heck " - "your configuration", pool_ipv4_size, pool_ipv6_size); + "your configuration", + pool_ipv4_size, pool_ipv6_size); } } @@ -303,7 +295,8 @@ } ifconfig_pool_handle -ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local, in_add= r_t *remote, struct in6_addr *remote_ipv6, const char *common_name) +ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *local, in_add= r_t *remote, + struct in6_addr *remote_ipv6, const char *common_nam= e) { int i; @@ -403,8 +396,7 @@ } static ifconfig_pool_handle -ifconfig_pool_ipv6_base_to_handle(const struct ifconfig_pool *pool, - const struct in6_addr *in_addr) +ifconfig_pool_ipv6_base_to_handle(const struct ifconfig_pool *pool, const = struct in6_addr *in_addr) { ifconfig_pool_handle ret; uint32_t base, addr; @@ -423,14 +415,10 @@ } } - base =3D (pool->ipv6.base.s6_addr[12] << 24) - | (pool->ipv6.base.s6_addr[13] << 16) - | (pool->ipv6.base.s6_addr[14] << 8) - | pool->ipv6.base.s6_addr[15]; + base =3D (pool->ipv6.base.s6_addr[12] << 24) | (pool->ipv6.base.s6_add= r[13] << 16) + | (pool->ipv6.base.s6_addr[14] << 8) | pool->ipv6.base.s6_addr[= 15]; - addr =3D (in_addr->s6_addr[12] << 24) - | (in_addr->s6_addr[13] << 16) - | (in_addr->s6_addr[14] << 8) + addr =3D (in_addr->s6_addr[12] << 24) | (in_addr->s6_addr[13] << 16) |= (in_addr->s6_addr[14] << 8) | in_addr->s6_addr[15]; ret =3D addr - base; @@ -479,14 +467,14 @@ /* IPv6 pools are always INDIV (--linear) */ if (pool->ipv6.enabled && hand >=3D 0 && hand < pool->size) { - ret =3D add_in6_addr( pool->ipv6.base, hand ); + ret =3D add_in6_addr(pool->ipv6.base, hand); } return ret; } static void -ifconfig_pool_set(struct ifconfig_pool *pool, const char *cn, - ifconfig_pool_handle h, const bool fixed) +ifconfig_pool_set(struct ifconfig_pool *pool, const char *cn, ifconfig_poo= l_handle h, + const bool fixed) { struct ifconfig_pool_entry *e =3D &pool->list[h]; ifconfig_pool_entry_free(e, true); @@ -558,7 +546,8 @@ if (refresh_freq > 0) { ret->fixed =3D false; - ret->file =3D status_open(filename, refresh_freq, -1, NULL, STATUS= _OUTPUT_READ|STATUS_OUTPUT_WRITE); + ret->file =3D + status_open(filename, refresh_freq, -1, NULL, STATUS_OUTPUT_RE= AD | STATUS_OUTPUT_WRITE); } else { @@ -641,8 +630,7 @@ * - CN,IP4 * - CN,,IP6 */ - if (!buf_parse(&in, ',', cn_buf, buf_size) - || !buf_parse(&in, ',', ip_buf, buf_size)) + if (!buf_parse(&in, ',', cn_buf, buf_size) || !buf_parse(&in, = ',', ip_buf, buf_size)) { continue; } @@ -652,22 +640,18 @@ if (strlen(ip_buf) > 0) { bool v4_ok =3D true; - in_addr_t addr =3D getaddr(GETADDR_HOST_ORDER, ip_buf, 0, = &v4_ok, - NULL); + in_addr_t addr =3D getaddr(GETADDR_HOST_ORDER, ip_buf, 0, = &v4_ok, NULL); if (!v4_ok) { - msg(M_WARN, "pool: invalid IPv4 (%s) for CN=3D%s", ip_= buf, - cn_buf); + msg(M_WARN, "pool: invalid IPv4 (%s) for CN=3D%s", ip_= buf, cn_buf); } else { h =3D ifconfig_pool_ip_base_to_handle(pool, addr); if (h < 0) { - msg(M_WARN, - "pool: IPv4 (%s) out of pool range for CN=3D%s= ", - ip_buf, cn_buf); + msg(M_WARN, "pool: IPv4 (%s) out of pool range for= CN=3D%s", ip_buf, cn_buf); } } } @@ -678,17 +662,14 @@ if (!get_ipv6_addr(ip6_buf, &addr6, NULL, M_WARN)) { - msg(M_WARN, "pool: invalid IPv6 (%s) for CN=3D%s", ip6= _buf, - cn_buf); + msg(M_WARN, "pool: invalid IPv6 (%s) for CN=3D%s", ip6= _buf, cn_buf); } else { h6 =3D ifconfig_pool_ipv6_base_to_handle(pool, &addr6); if (h6 < 0) { - msg(M_WARN, - "pool: IPv6 (%s) out of pool range for CN=3D%s= ", - ip6_buf, cn_buf); + msg(M_WARN, "pool: IPv6 (%s) out of pool range for= CN=3D%s", ip6_buf, cn_buf); } /* Rely on IPv6 if no IPv4 was provided or the one pro= vided @@ -708,8 +689,7 @@ */ if ((h6 >=3D 0) && (h !=3D h6)) { - msg(M_WARN, - "pool: IPv4 (%s) and IPv6 (%s) have different offsets!= Relying on IPv4", + msg(M_WARN, "pool: IPv4 (%s) and IPv6 (%s) have different = offsets! Relying on IPv4", ip_buf, ip6_buf); } @@ -760,7 +740,7 @@ CLEAR(array); msg(M_INFO | M_NOPREFIX, "************ 1"); - for (i =3D 0; i < (int) SIZE(array); ++i) + for (i =3D 0; i < (int)SIZE(array); ++i) { char *cn; ifconfig_pool_handle h; @@ -778,15 +758,12 @@ break; } msg(M_INFO | M_NOPREFIX, "IFCONFIG_POOL TEST pass 1: l=3D%s r=3D%s= cn=3D%s", - print_in_addr_t(local, 0, &gc), - print_in_addr_t(remote, 0, &gc), - cn); + print_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc= ), cn); array[i] =3D h; - } msg(M_INFO | M_NOPREFIX, "************* 2"); - for (i =3D (int) SIZE(array) / 16; i < (int) SIZE(array) / 8; ++i) + for (i =3D (int)SIZE(array) / 16; i < (int)SIZE(array) / 8; ++i) { msg(M_INFO, "Attempt to release %d cn=3D%s", array[i], p->list[i].= common_name); if (!ifconfig_pool_release(p, array[i])) @@ -799,13 +776,13 @@ CLEAR(array); msg(M_INFO | M_NOPREFIX, "**************** 3"); - for (i =3D 0; i < (int) SIZE(array); ++i) + for (i =3D 0; i < (int)SIZE(array); ++i) { char *cn; ifconfig_pool_handle h; in_addr_t local, remote; char buf[256]; - snprintf(buf, sizeof(buf), "common-name-%d", i+24); + snprintf(buf, sizeof(buf), "common-name-%d", i + 24); #ifdef DUP_CN cn =3D NULL; #else @@ -817,11 +794,8 @@ break; } msg(M_INFO | M_NOPREFIX, "IFCONFIG_POOL TEST pass 3: l=3D%s r=3D%s= cn=3D%s", - print_in_addr_t(local, 0, &gc), - print_in_addr_t(remote, 0, &gc), - cn); + print_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc= ), cn); array[i] =3D h; - } ifconfig_pool_free(p); diff --git a/src/openvpn/pool.h b/src/openvpn/pool.h index 9c3905d..39f9d98 100644 --- a/src/openvpn/pool.h +++ b/src/openvpn/pool.h @@ -30,7 +30,7 @@ #include "status.h" #define IFCONFIG_POOL_MAX 65536 -#define IFCONFIG_POOL_MIN_NETBITS 16 +#define IFCONFIG_POOL_MIN_NETBITS 16 enum pool_type { @@ -49,12 +49,14 @@ struct ifconfig_pool { bool duplicate_cn; - struct { + struct + { bool enabled; enum pool_type type; in_addr_t base; } ipv4; - struct { + struct + { bool enabled; struct in6_addr base; } ipv6; @@ -70,18 +72,18 @@ typedef int ifconfig_pool_handle; -struct ifconfig_pool *ifconfig_pool_init(const bool ipv4_pool, - enum pool_type type, in_addr_t st= art, +struct ifconfig_pool *ifconfig_pool_init(const bool ipv4_pool, enum pool_t= ype type, in_addr_t start, in_addr_t end, const bool duplica= te_cn, - const bool ipv6_pool, - const struct in6_addr ipv6_base, + const bool ipv6_pool, const struc= t in6_addr ipv6_base, const int ipv6_netbits); void ifconfig_pool_free(struct ifconfig_pool *pool); bool ifconfig_pool_verify_range(const int msglevel, const in_addr_t start,= const in_addr_t end); -ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_= addr_t *local, in_addr_t *remote, struct in6_addr *remote_ipv6, const char = *common_name); +ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_= addr_t *local, + in_addr_t *remote, struct in6_a= ddr *remote_ipv6, + const char *common_name); bool ifconfig_pool_release(struct ifconfig_pool *pool, ifconfig_pool_handl= e hand, const bool hard); diff --git a/src/openvpn/proto.c b/src/openvpn/proto.c index 90930fe..6ab40a2 100644 --- a/src/openvpn/proto.c +++ b/src/openvpn/proto.c @@ -55,8 +55,7 @@ else if (tunnel_type =3D=3D DEV_TYPE_TAP) { const struct openvpn_ethhdr *eh; - if (BLEN(buf) < (sizeof(struct openvpn_ethhdr) - + sizeof(struct openvpn_iphdr))) + if (BLEN(buf) < (sizeof(struct openvpn_ethhdr) + sizeof(struct ope= nvpn_iphdr))) { return false; } @@ -72,8 +71,7 @@ if (proto =3D=3D htons(OPENVPN_ETH_P_8021Q)) { const struct openvpn_8021qhdr *evh; - if (BLEN(buf) < (sizeof(struct openvpn_ethhdr) - + sizeof(struct openvpn_iphdr))) + if (BLEN(buf) < (sizeof(struct openvpn_ethhdr) + sizeof(struct= openvpn_iphdr))) { return false; } @@ -110,12 +108,12 @@ bool is_ipv4(int tunnel_type, struct buffer *buf) { - return is_ipv_X( tunnel_type, buf, 4 ); + return is_ipv_X(tunnel_type, buf, 4); } bool is_ipv6(int tunnel_type, struct buffer *buf) { - return is_ipv_X( tunnel_type, buf, 6 ); + return is_ipv_X(tunnel_type, buf, 6); } @@ -132,9 +130,8 @@ */ for (int i =3D 0; i < len_payload; i +=3D 2) { - sum +=3D (uint16_t)(((payload[i] << 8) & 0xFF00) - +((i + 1 < len_payload) ? (payload[i + 1] & 0xF= F) : 0)); - + sum +=3D (uint16_t)(((payload[i] << 8) & 0xFF00) + + ((i + 1 < len_payload) ? (payload[i + 1] & 0xF= F) : 0)); } /* @@ -144,7 +141,6 @@ for (int i =3D 0; i < addr_len; i +=3D 2) { sum +=3D (uint16_t)((src_addr[i] << 8) & 0xFF00) + (src_addr[i + 1= ] & 0xFF); - } for (int i =3D 0; i < addr_len; i +=3D 2) { @@ -167,17 +163,14 @@ } /* Take the one's complement of sum */ - return ((uint16_t) ~sum); + return ((uint16_t)~sum); } #ifdef PACKET_TRUNCATION_CHECK void -ipv4_packet_size_verify(const uint8_t *data, - const int size, - const int tunnel_type, - const char *prefix, - counter_type *errors) +ipv4_packet_size_verify(const uint8_t *data, const int size, const int tun= nel_type, + const char *prefix, counter_type *errors) { if (size > 0) { @@ -193,13 +186,13 @@ const char *msgstr =3D "PACKET SIZE INFO"; unsigned int msglevel =3D D_PACKET_TRUNC_DEBUG; - if (BLEN(&buf) < (int) sizeof(struct openvpn_iphdr)) + if (BLEN(&buf) < (int)sizeof(struct openvpn_iphdr)) { return; } verify_align_4(&buf); - pip =3D (struct openvpn_iphdr *) BPTR(&buf); + pip =3D (struct openvpn_iphdr *)BPTR(&buf); hlen =3D OPENVPN_IPH_GET_LEN(pip->version_len); totlen =3D ntohs(pip->tot_len); @@ -214,13 +207,8 @@ } } - msg(msglevel, "%s %s: size=3D%d totlen=3D%d hlen=3D%d errcount= =3D" counter_format, - msgstr, - prefix, - BLEN(&buf), - totlen, - hlen, - errors ? *errors : (counter_type)0); + msg(msglevel, "%s %s: size=3D%d totlen=3D%d hlen=3D%d errcount= =3D" counter_format, msgstr, + prefix, BLEN(&buf), totlen, hlen, errors ? *errors : (coun= ter_type)0); } } } diff --git a/src/openvpn/proto.h b/src/openvpn/proto.h index 11c2a49..f7f0060 100644 --- a/src/openvpn/proto.h +++ b/src/openvpn/proto.h @@ -33,15 +33,15 @@ * Tunnel types */ #define DEV_TYPE_UNDEF 0 -#define DEV_TYPE_TUN 2 /* point-to-point IP tunnel */ -#define DEV_TYPE_TAP 3 /* ethernet (802.3) tunnel */ +#define DEV_TYPE_TUN 2 /* point-to-point IP tunnel */ +#define DEV_TYPE_TAP 3 /* ethernet (802.3) tunnel */ /* TUN topologies */ -#define TOP_UNDEF 0 -#define TOP_NET30 1 -#define TOP_P2P 2 -#define TOP_SUBNET 3 +#define TOP_UNDEF 0 +#define TOP_NET30 1 +#define TOP_P2P 2 +#define TOP_SUBNET 3 /* * IP and Ethernet protocol structs. For portability, @@ -50,46 +50,45 @@ * native structs. */ -#define OPENVPN_ETH_ALEN 6 /* ethernet address length */ +#define OPENVPN_ETH_ALEN 6 /* ethernet address length */ struct openvpn_ethhdr { uint8_t dest[OPENVPN_ETH_ALEN]; /* destination ethernet addr */ uint8_t source[OPENVPN_ETH_ALEN]; /* source ethernet addr */ -#define OPENVPN_ETH_P_IPV4 0x0800 /* IPv4 protocol */ -#define OPENVPN_ETH_P_IPV6 0x86DD /* IPv6 protocol */ -#define OPENVPN_ETH_P_ARP 0x0806 /* ARP protocol */ -#define OPENVPN_ETH_P_8021Q 0x8100 /* 802.1Q protocol */ +#define OPENVPN_ETH_P_IPV4 0x0800 /* IPv4 protocol */ +#define OPENVPN_ETH_P_IPV6 0x86DD /* IPv6 protocol */ +#define OPENVPN_ETH_P_ARP 0x0806 /* ARP protocol */ +#define OPENVPN_ETH_P_8021Q 0x8100 /* 802.1Q protocol */ uint16_t proto; /* packet type ID field */ }; struct openvpn_8021qhdr { - uint8_t dest[OPENVPN_ETH_ALEN]; /* destination ethernet addr */ - uint8_t source[OPENVPN_ETH_ALEN]; /* source ethernet addr */ + uint8_t dest[OPENVPN_ETH_ALEN]; /* destination ethernet addr = */ + uint8_t source[OPENVPN_ETH_ALEN]; /* source ethernet addr */ - uint16_t tpid; /* 802.1Q Tag Protocol Identifier = */ + uint16_t tpid; /* 802.1Q Tag Protocol Identi= fier */ #define OPENVPN_8021Q_MASK_PCP htons(0xE000) /* mask PCP out of pcp_cfi_vi= d */ #define OPENVPN_8021Q_MASK_CFI htons(0x1000) /* mask CFI out of pcp_cfi_vi= d */ #define OPENVPN_8021Q_MASK_VID htons(0x0FFF) /* mask VID out of pcp_cfi_vi= d */ - uint16_t pcp_cfi_vid; /* bit fields, see IEEE 802.1Q */ - uint16_t proto; /* contained packet type ID field = */ + uint16_t pcp_cfi_vid; /* bit fields, see IEEE 802.1= Q */ + uint16_t proto; /* contained packet type ID f= ield */ }; /* * Size difference between a regular Ethernet II header and an Ethernet II * header with additional IEEE 802.1Q tagging. */ -#define SIZE_ETH_TO_8021Q_HDR (sizeof(struct openvpn_8021qhdr) \ - - sizeof(struct openvpn_ethhdr)) +#define SIZE_ETH_TO_8021Q_HDR (sizeof(struct openvpn_8021qhdr) - sizeof(st= ruct openvpn_ethhdr)) /** Version of IN6_ARE_ADDR_EQUAL that is guaranteed to work for * unaligned access. E.g. Linux uses 32bit compares which are * not safe if the struct is unaligned. */ -#define OPENVPN_IN6_ARE_ADDR_EQUAL(a, b) \ - (memcmp(a, b, sizeof(struct in6_addr)) =3D=3D 0) +#define OPENVPN_IN6_ARE_ADDR_EQUAL(a, b) (memcmp(a, b, sizeof(struct in6_a= ddr)) =3D=3D 0) -struct openvpn_iphdr { +struct openvpn_iphdr +{ #define OPENVPN_IPH_GET_VER(v) (((v) >> 4) & 0x0F) #define OPENVPN_IPH_GET_LEN(v) (((v) & 0x0F) << 2) uint8_t version_len; @@ -103,9 +102,9 @@ uint8_t ttl; -#define OPENVPN_IPPROTO_IGMP 2 /* IGMP protocol */ -#define OPENVPN_IPPROTO_TCP 6 /* TCP protocol */ -#define OPENVPN_IPPROTO_UDP 17 /* UDP protocol */ +#define OPENVPN_IPPROTO_IGMP 2 /* IGMP protocol */ +#define OPENVPN_IPPROTO_TCP 6 /* TCP protocol */ +#define OPENVPN_IPPROTO_UDP 17 /* UDP protocol */ #define OPENVPN_IPPROTO_ICMPV6 58 /* ICMPV6 protocol */ uint8_t protocol; @@ -118,31 +117,33 @@ /* * IPv6 header */ -struct openvpn_ipv6hdr { +struct openvpn_ipv6hdr +{ uint8_t version_prio; uint8_t flow_lbl[3]; uint16_t payload_len; uint8_t nexthdr; uint8_t hop_limit; - struct in6_addr saddr; - struct in6_addr daddr; + struct in6_addr saddr; + struct in6_addr daddr; }; /* * ICMPv6 header */ -struct openvpn_icmp6hdr { -#define OPENVPN_ICMP6_DESTINATION_UNREACHABLE 1 -#define OPENVPN_ND_ROUTER_SOLICIT 133 -#define OPENVPN_ND_ROUTER_ADVERT 134 -#define OPENVPN_ND_NEIGHBOR_SOLICIT 135 -#define OPENVPN_ND_NEIGHBOR_ADVERT 136 -#define OPENVPN_ND_INVERSE_SOLICIT 141 -#define OPENVPN_ND_INVERSE_ADVERT 142 +struct openvpn_icmp6hdr +{ +#define OPENVPN_ICMP6_DESTINATION_UNREACHABLE 1 +#define OPENVPN_ND_ROUTER_SOLICIT 133 +#define OPENVPN_ND_ROUTER_ADVERT 134 +#define OPENVPN_ND_NEIGHBOR_SOLICIT 135 +#define OPENVPN_ND_NEIGHBOR_ADVERT 136 +#define OPENVPN_ND_INVERSE_SOLICIT 141 +#define OPENVPN_ND_INVERSE_ADVERT 142 uint8_t icmp6_type; -#define OPENVPN_ICMP6_DU_NOROUTE 0 -#define OPENVPN_ICMP6_DU_COMMUNICATION_PROHIBTED 1 +#define OPENVPN_ICMP6_DU_NOROUTE 0 +#define OPENVPN_ICMP6_DU_COMMUNICATION_PROHIBTED 1 uint8_t icmp6_code; uint16_t icmp6_cksum; uint8_t icmp6_dataun[4]; @@ -151,7 +152,8 @@ /* * UDP header */ -struct openvpn_udphdr { +struct openvpn_udphdr +{ uint16_t source; uint16_t dest; uint16_t len; @@ -161,23 +163,24 @@ /* * TCP header, per RFC 793. */ -struct openvpn_tcphdr { - uint16_t source; /* source port */ - uint16_t dest; /* destination port */ - uint32_t seq; /* sequence number */ - uint32_t ack_seq; /* acknowledgement number */ +struct openvpn_tcphdr +{ + uint16_t source; /* source port */ + uint16_t dest; /* destination port */ + uint32_t seq; /* sequence number */ + uint32_t ack_seq; /* acknowledgement number */ #define OPENVPN_TCPH_GET_DOFF(d) (((d) & 0xF0) >> 2) uint8_t doff_res; -#define OPENVPN_TCPH_FIN_MASK (1<<0) -#define OPENVPN_TCPH_SYN_MASK (1<<1) -#define OPENVPN_TCPH_RST_MASK (1<<2) -#define OPENVPN_TCPH_PSH_MASK (1<<3) -#define OPENVPN_TCPH_ACK_MASK (1<<4) -#define OPENVPN_TCPH_URG_MASK (1<<5) -#define OPENVPN_TCPH_ECE_MASK (1<<6) -#define OPENVPN_TCPH_CWR_MASK (1<<7) +#define OPENVPN_TCPH_FIN_MASK (1 << 0) +#define OPENVPN_TCPH_SYN_MASK (1 << 1) +#define OPENVPN_TCPH_RST_MASK (1 << 2) +#define OPENVPN_TCPH_PSH_MASK (1 << 3) +#define OPENVPN_TCPH_ACK_MASK (1 << 4) +#define OPENVPN_TCPH_URG_MASK (1 << 5) +#define OPENVPN_TCPH_ECE_MASK (1 << 6) +#define OPENVPN_TCPH_CWR_MASK (1 << 7) uint8_t flags; uint16_t window; @@ -190,9 +193,11 @@ #define OPENVPN_TCPOPT_MAXSEG 2 #define OPENVPN_TCPOLEN_MAXSEG 4 -struct ip_tcp_udp_hdr { +struct ip_tcp_udp_hdr +{ struct openvpn_iphdr ip; - union { + union + { struct openvpn_tcphdr tcp; struct openvpn_udphdr udp; } u; @@ -208,30 +213,36 @@ * subtracting out new words), and "cksum" * is the checksum value to be updated. */ -#define ADJUST_CHECKSUM(acc, cksum) { \ - int _acc =3D acc; \ - _acc +=3D (cksum); \ - if (_acc < 0) { \ - _acc =3D -_acc; \ +#define ADJUST_CHECKSUM(acc, cksum) \ + { \ + int _acc =3D acc; \ + _acc +=3D (cksum); \ + if (_acc < 0) \ + { \ + _acc =3D -_acc; \ _acc =3D (_acc >> 16) + (_acc & 0xffff); \ - _acc +=3D _acc >> 16; \ - (cksum) =3D (uint16_t) ~_acc; \ - } else { \ + _acc +=3D _acc >> 16; \ + (cksum) =3D (uint16_t)~_acc; \ + } \ + else \ + { \ _acc =3D (_acc >> 16) + (_acc & 0xffff); \ - _acc +=3D _acc >> 16; \ - (cksum) =3D (uint16_t) _acc; \ - } \ -} + _acc +=3D _acc >> 16; \ + (cksum) =3D (uint16_t)_acc; \ + } \ + } -#define ADD_CHECKSUM_32(acc, u32) { \ - acc +=3D (u32) & 0xffff; \ - acc +=3D (u32) >> 16; \ -} +#define ADD_CHECKSUM_32(acc, u32) \ + { \ + acc +=3D (u32) & 0xffff; \ + acc +=3D (u32) >> 16; \ + } -#define SUB_CHECKSUM_32(acc, u32) { \ - acc -=3D (u32) & 0xffff; \ - acc -=3D (u32) >> 16; \ -} +#define SUB_CHECKSUM_32(acc, u32) \ + { \ + acc -=3D (u32) & 0xffff; \ + acc -=3D (u32) >> 16; \ + } /* * This returns an ip protocol version of packet inside tun @@ -246,7 +257,7 @@ if (tunnel_type =3D=3D DEV_TYPE_TUN) { *ip_hdr_offset =3D 0; - if (likely(BLEN(buf) >=3D (int) sizeof(struct openvpn_iphdr))) + if (likely(BLEN(buf) >=3D (int)sizeof(struct openvpn_iphdr))) { ip_ver =3D OPENVPN_IPH_GET_VER(*BPTR(buf)); } @@ -257,7 +268,7 @@ /* for tap get ip version from eth header */ if (likely(BLEN(buf) >=3D *ip_hdr_offset)) { - const struct openvpn_ethhdr *eh =3D (const struct openvpn_ethh= dr *) BPTR(buf); + const struct openvpn_ethhdr *eh =3D (const struct openvpn_ethh= dr *)BPTR(buf); uint16_t proto =3D ntohs(eh->proto); if (proto =3D=3D OPENVPN_ETH_P_IPV6) { @@ -294,17 +305,12 @@ * @param proto next - header or IP protocol of the packet * @return The calculated checksum in host order */ -uint16_t -ip_checksum(const sa_family_t af, const uint8_t *payload, const int len_pa= yload, - const uint8_t *src_addr, const uint8_t *dest_addr, const int = proto); +uint16_t ip_checksum(const sa_family_t af, const uint8_t *payload, const i= nt len_payload, + const uint8_t *src_addr, const uint8_t *dest_addr, co= nst int proto); #ifdef PACKET_TRUNCATION_CHECK -void ipv4_packet_size_verify(const uint8_t *data, - const int size, - const int tunnel_type, - const char - *prefix, - counter_type *errors); +void ipv4_packet_size_verify(const uint8_t *data, const int size, const in= t tunnel_type, + const char *prefix, counter_type *errors); #endif diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c index 0117a66..97ba650 100644 --- a/src/openvpn/proxy.c +++ b/src/openvpn/proxy.c @@ -40,11 +40,10 @@ #include "memdbg.h" #include "forward.h" -#define UP_TYPE_PROXY "HTTP Proxy" +#define UP_TYPE_PROXY "HTTP Proxy" struct http_proxy_options * -init_http_proxy_options_once(struct http_proxy_options **hpo, - struct gc_arena *gc) +init_http_proxy_options_once(struct http_proxy_options **hpo, struct gc_ar= ena *gc) { if (!*hpo) { @@ -60,13 +59,8 @@ static struct user_pass static_proxy_user_pass; static bool -recv_line(socket_descriptor_t sd, - char *buf, - int len, - const int timeout_sec, - const bool verbose, - struct buffer *lookahead, - volatile int *signal_received) +recv_line(socket_descriptor_t sd, char *buf, int len, const int timeout_se= c, const bool verbose, + struct buffer *lookahead, volatile int *signal_received) { struct buffer la; int lastc =3D 0; @@ -162,7 +156,8 @@ { if (verbose) { - msg(D_LINK_ERRORS | M_ERRNO, "recv_line: Non-ASCII cha= racter (%d) read on recv()", (int)c); + msg(D_LINK_ERRORS | M_ERRNO, + "recv_line: Non-ASCII character (%d) read on recv(= )", (int)c); } *lookahead =3D la; return false; @@ -191,11 +186,10 @@ } static bool -send_line(socket_descriptor_t sd, - const char *buf) +send_line(socket_descriptor_t sd, const char *buf) { const ssize_t size =3D send(sd, buf, strlen(buf), MSG_NOSIGNAL); - if (size !=3D (ssize_t) strlen(buf)) + if (size !=3D (ssize_t)strlen(buf)) { msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on = send()"); return false; @@ -204,8 +198,7 @@ } static bool -send_line_crlf(socket_descriptor_t sd, - const char *src) +send_line_crlf(socket_descriptor_t sd, const char *src) { bool ret; @@ -229,7 +222,7 @@ uint8_t *ret =3D NULL; char *b64out =3D NULL; ASSERT(openvpn_base64_encode((const void *)str, src_len, &b64out) >=3D= 0); - ret =3D (uint8_t *) string_alloc(b64out, gc); + ret =3D (uint8_t *)string_alloc(b64out, gc); free(b64out); return ret; } @@ -241,8 +234,7 @@ } static const char * -username_password_as_base64(const struct http_proxy_info *p, - struct gc_arena *gc) +username_password_as_base64(const struct http_proxy_info *p, struct gc_are= na *gc) { struct buffer out =3D alloc_buf_gc(strlen(p->up.username) + strlen(p->= up.password) + 2, gc); ASSERT(strlen(p->up.username) > 0); @@ -286,10 +278,7 @@ { flags |=3D GET_USER_PASS_INLINE_CREDS; } - get_user_pass(&static_proxy_user_pass, - auth_file, - UP_TYPE_PROXY, - flags); + get_user_pass(&static_proxy_user_pass, auth_file, UP_TYPE_PROXY, f= lags); static_proxy_user_pass.nocache =3D p->options.nocache; protect_user_pass(&static_proxy_user_pass); } @@ -326,9 +315,7 @@ * Consumes all headers. */ static int -get_proxy_authenticate(socket_descriptor_t sd, - int timeout, - char **data, +get_proxy_authenticate(socket_descriptor_t sd, int timeout, char **data, volatile int *signal_received) { char buf[256]; @@ -348,22 +335,22 @@ } if (ret =3D=3D HTTP_AUTH_NONE && !strncmp(buf, "Proxy-Authenticate= : ", 20)) { - if (!strncmp(buf+20, "Basic ", 6)) + if (!strncmp(buf + 20, "Basic ", 6)) { msg(D_PROXY, "PROXY AUTH BASIC: '%s'", buf); - *data =3D string_alloc(buf+26, NULL); + *data =3D string_alloc(buf + 26, NULL); ret =3D HTTP_AUTH_BASIC; } #if PROXY_DIGEST_AUTH - else if (!strncmp(buf+20, "Digest ", 7)) + else if (!strncmp(buf + 20, "Digest ", 7)) { msg(D_PROXY, "PROXY AUTH DIGEST: '%s'", buf); - *data =3D string_alloc(buf+27, NULL); + *data =3D string_alloc(buf + 27, NULL); ret =3D HTTP_AUTH_DIGEST; } #endif #if NTLM - else if (!strncmp(buf+20, "NTLM", 4)) + else if (!strncmp(buf + 20, "NTLM", 4)) { msg(D_PROXY, "PROXY AUTH NTLM: '%s'", buf); *data =3D NULL; @@ -386,18 +373,16 @@ * Return true on success, or false on parse failure. */ static bool -get_key_value(const char *str, /* source string */ - char *key, /* key stored here */ - char *value, /* value stored here */ - int max_key_len, - int max_value_len, - const char **endptr) /* next search position */ +get_key_value(const char *str, /* = source string */ + char *key, /* = key stored here */ + char *value, /* = value stored here */ + int max_key_len, int max_value_len, const char **endptr) /* = next search position */ { int c; bool starts_with_quote =3D false; bool escape =3D false; - for (c =3D max_key_len-1; (*str && (*str !=3D '=3D') && c--); ) + for (c =3D max_key_len - 1; (*str && (*str !=3D '=3D') && c--);) { *key++ =3D *str++; } @@ -416,7 +401,7 @@ starts_with_quote =3D true; } - for (c =3D max_value_len-1; *str && c--; str++) + for (c =3D max_value_len - 1; *str && c--; str++) { switch (*str) { @@ -530,7 +515,8 @@ #if NTLM else if (!strcmp(o->auth_method_string, "ntlm")) { - msg(M_WARN, "NTLM v1 authentication has been removed in OpenVP= N 2.7. Will try to use NTLM v2 authentication."); + msg(M_WARN, + "NTLM v1 authentication has been removed in OpenVPN 2.7. W= ill try to use NTLM v2 authentication."); p->auth_method =3D HTTP_AUTH_NTLM2; } else if (!strcmp(o->auth_method_string, "ntlm2")) @@ -540,8 +526,7 @@ #endif else { - msg(M_FATAL, "ERROR: unknown HTTP authentication method: '%s'", - o->auth_method_string); + msg(M_FATAL, "ERROR: unknown HTTP authentication method: '%s'"= , o->auth_method_string); } } @@ -556,7 +541,8 @@ #if !NTLM if (p->auth_method =3D=3D HTTP_AUTH_NTLM2) { - msg(M_FATAL, "Sorry, this version of " PACKAGE_NAME " was built wi= thout NTLM Proxy support."); + msg(M_FATAL, + "Sorry, this version of " PACKAGE_NAME " was built without NTL= M Proxy support."); } #endif @@ -571,10 +557,9 @@ } static bool -add_proxy_headers(struct http_proxy_info *p, - socket_descriptor_t sd, /* already open to proxy */ - const char *host /* openvpn server remote */ - ) +add_proxy_headers(struct http_proxy_info *p, socket_descriptor_t sd, /* al= ready open to proxy */ + const char *host /* op= envpn server remote */ +) { char buf[512]; int i; @@ -585,12 +570,11 @@ * If content is NULL the whole header is in name * Also remember if we already sent a Host: header */ - for (i =3D 0; i < MAX_CUSTOM_HTTP_HEADER && p->options.custom_headers= [i].name; i++) + for (i =3D 0; i < MAX_CUSTOM_HTTP_HEADER && p->options.custom_headers[= i].name; i++) { if (p->options.custom_headers[i].content) { - snprintf(buf, sizeof(buf), "%s: %s", - p->options.custom_headers[i].name, + snprintf(buf, sizeof(buf), "%s: %s", p->options.custom_headers= [i].name, p->options.custom_headers[i].content); if (!strcasecmp(p->options.custom_headers[i].name, "Host")) { @@ -599,8 +583,7 @@ } else { - snprintf(buf, sizeof(buf), "%s", - p->options.custom_headers[i].name); + snprintf(buf, sizeof(buf), "%s", p->options.custom_headers[i].= name); if (!strncasecmp(p->options.custom_headers[i].name, "Host:", 5= )) { host_header_sent =3D true; @@ -627,8 +610,7 @@ /* send User-Agent string if provided */ if (p->options.user_agent) { - snprintf(buf, sizeof(buf), "User-Agent: %s", - p->options.user_agent); + snprintf(buf, sizeof(buf), "User-Agent: %s", p->options.user_agent= ); msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); if (!send_line_crlf(sd, buf)) { @@ -642,11 +624,10 @@ bool establish_http_proxy_passthru(struct http_proxy_info *p, - socket_descriptor_t sd, /* already open to = proxy */ - const char *host, /* openvpn server r= emote */ - const char *port, /* openvpn server= port */ - struct event_timeout *server_poll_timeout, - struct buffer *lookahead, + socket_descriptor_t sd, /* already open to p= roxy */ + const char *host, /* openvpn server re= mote */ + const char *port, /* openvpn server po= rt */ + struct event_timeout *server_poll_timeout, s= truct buffer *lookahead, struct signal_info *sig_info) { struct gc_arena gc =3D gc_new(); @@ -658,8 +639,7 @@ volatile int *signal_received =3D &sig_info->signal_received; /* get user/pass if not previously given */ - if (p->auth_method =3D=3D HTTP_AUTH_BASIC - || p->auth_method =3D=3D HTTP_AUTH_DIGEST + if (p->auth_method =3D=3D HTTP_AUTH_BASIC || p->auth_method =3D=3D HTT= P_AUTH_DIGEST || p->auth_method =3D=3D HTTP_AUTH_NTLM2) { get_user_pass_http(p, false); @@ -671,7 +651,8 @@ unprotect_user_pass(&p->up); } - /* are we being called again after getting the digest server nonce in = the previous transaction? */ + /* are we being called again after getting the digest server nonce in = the previous transaction? + */ if (p->auth_method =3D=3D HTTP_AUTH_DIGEST && p->proxy_authenticate) { nparms =3D 1; @@ -680,10 +661,7 @@ else { /* format HTTP CONNECT message */ - snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", - host, - port, - p->options.http_version); + snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", host, port, p-= >options.http_version); msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); @@ -724,8 +702,7 @@ goto error; } - snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s", - ntlm_phase_1(p, &gc)); + snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s",= ntlm_phase_1(p, &gc)); msg(D_PROXY, "Attempting NTLM Proxy-Authorization phase 1"= ); dmsg(D_SHOW_KEYS, "Send to HTTP proxy: '%s'", buf); if (!send_line_crlf(sd, buf)) @@ -749,7 +726,8 @@ } /* receive reply from proxy */ - if (!recv_line(sd, buf, sizeof(buf), get_server_poll_remaining_tim= e(server_poll_timeout), true, NULL, signal_received)) + if (!recv_line(sd, buf, sizeof(buf), get_server_poll_remaining_tim= e(server_poll_timeout), + true, NULL, signal_received)) { goto error; } @@ -761,7 +739,6 @@ /* parse return string */ nparms =3D sscanf(buf, "%*s %d", &status); - } /* check for a "407 Proxy Authentication Required" response */ @@ -780,7 +757,9 @@ char buf2[512]; while (true) { - if (!recv_line(sd, buf, sizeof(buf), get_server_poll_remai= ning_time(server_poll_timeout), true, NULL, signal_received)) + if (!recv_line(sd, buf, sizeof(buf), + get_server_poll_remaining_time(server_poll_= timeout), true, NULL, + signal_received)) { goto error; } @@ -811,9 +790,7 @@ /* now send the phase 3 reply */ /* format HTTP CONNECT message */ - snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", - host, - port, + snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", host, port, p->options.http_version); msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); @@ -842,7 +819,8 @@ const char *np3 =3D ntlm_phase_3(p, buf2, &gc); if (!np3) { - msg(D_PROXY, "NTLM Proxy-Authorization phase 3 failed:= received corrupted data from proxy server"); + msg(D_PROXY, + "NTLM Proxy-Authorization phase 3 failed: received= corrupted data from proxy server"); goto error; } snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s",= np3); @@ -861,7 +839,9 @@ } /* receive reply from proxy */ - if (!recv_line(sd, buf, sizeof(buf), get_server_poll_remaining= _time(server_poll_timeout), true, NULL, signal_received)) + if (!recv_line(sd, buf, sizeof(buf), + get_server_poll_remaining_time(server_poll_time= out), true, NULL, + signal_received)) { goto error; } @@ -905,7 +885,7 @@ if (!realm || !nonce) { msg(D_LINK_ERRORS, "HTTP proxy: digest auth failed, ma= lformed response " - "from server: realm=3D or nonce=3D missing" ); + "from server: realm=3D or nonce=3D = missing"); goto error; } @@ -915,38 +895,21 @@ /* build the digest response */ - snprintf(uri, sizeof(uri), "%s:%s", - host, - port); + snprintf(uri, sizeof(uri), "%s:%s", host, port); if (opaque) { - const int len =3D strlen(opaque)+16; + const int len =3D strlen(opaque) + 16; opaque_kv =3D gc_malloc(len, false, &gc); snprintf(opaque_kv, len, ", opaque=3D\"%s\"", opaque); } - DigestCalcHA1(algor, - username, - realm, - password, - nonce, - (char *)cnonce, - session_key); - DigestCalcResponse(session_key, - nonce, - nonce_count, - (char *)cnonce, - qop, - http_method, - uri, - NULL, - response); + DigestCalcHA1(algor, username, realm, password, nonce, (ch= ar *)cnonce, session_key); + DigestCalcResponse(session_key, nonce, nonce_count, (char = *)cnonce, qop, + http_method, uri, NULL, response); /* format HTTP CONNECT message */ - snprintf(buf, sizeof(buf), "%s %s HTTP/%s", - http_method, - uri, + snprintf(buf, sizeof(buf), "%s %s HTTP/%s", http_method, u= ri, p->options.http_version); msg(D_PROXY, "Send to HTTP proxy: '%s'", buf); @@ -964,17 +927,10 @@ } /* send digest response */ - int sret =3D snprintf(buf, sizeof(buf), "Proxy-Authorizati= on: Digest username=3D\"%s\", realm=3D\"%s\", nonce=3D\"%s\", uri=3D\"%s\",= qop=3D%s, nc=3D%s, cnonce=3D\"%s\", response=3D\"%s\"%s", - username, - realm, - nonce, - uri, - qop, - nonce_count, - cnonce, - response, - opaque_kv - ); + int sret =3D snprintf( + buf, sizeof(buf), + "Proxy-Authorization: Digest username=3D\"%s\", realm= =3D\"%s\", nonce=3D\"%s\", uri=3D\"%s\", qop=3D%s, nc=3D%s, cnonce=3D\"%s\"= , response=3D\"%s\"%s", + username, realm, nonce, uri, qop, nonce_count, cnonce,= response, opaque_kv); if (sret >=3D sizeof(buf)) { goto error; @@ -993,7 +949,9 @@ secure_memzero(buf, sizeof(buf)); /* receive reply from proxy */ - if (!recv_line(sd, buf, sizeof(buf), get_server_poll_remai= ning_time(server_poll_timeout), true, NULL, signal_received)) + if (!recv_line(sd, buf, sizeof(buf), + get_server_poll_remaining_time(server_poll_= timeout), true, NULL, + signal_received)) { goto error; } @@ -1018,10 +976,8 @@ { /* figure out what kind of authentication the proxy needs */ char *pa =3D NULL; - const int method =3D get_proxy_authenticate(sd, - get_server_poll_rema= ining_time(server_poll_timeout), - &pa, - signal_received); + const int method =3D get_proxy_authenticate( + sd, get_server_poll_remaining_time(server_poll_timeout), &= pa, signal_received); if (method !=3D HTTP_AUTH_NONE) { if (pa) @@ -1030,7 +986,8 @@ } if (p->options.auth_retry =3D=3D PAR_NCT && method =3D=3D = HTTP_AUTH_BASIC) { - msg(D_PROXY, "HTTP proxy: support for basic auth and o= ther cleartext proxy auth methods is disabled"); + msg(D_PROXY, + "HTTP proxy: support for basic auth and other clea= rtext proxy auth methods is disabled"); free(pa); goto error; } @@ -1041,7 +998,8 @@ } else { - msg(D_PROXY, "HTTP proxy: do not recognize the authenticat= ion method required by proxy"); + msg(D_PROXY, + "HTTP proxy: do not recognize the authentication metho= d required by proxy"); free(pa); goto error; } @@ -1070,7 +1028,8 @@ /* SUCCESS */ /* receive line from proxy and discard */ - if (!recv_line(sd, NULL, 0, get_server_poll_remaining_time(server_poll= _timeout), true, NULL, signal_received)) + if (!recv_line(sd, NULL, 0, get_server_poll_remaining_time(server_poll= _timeout), true, NULL, + signal_received)) { goto error; } @@ -1083,7 +1042,8 @@ { } - /* reset queried_creds so that we don't think that the next creds requ= est is due to an auth error */ + /* reset queried_creds so that we don't think that the next creds requ= est is due to an auth + * error */ p->queried_creds =3D false; #if 0 diff --git a/src/openvpn/proxy.h b/src/openvpn/proxy.h index cf1fbdb..054fe8c 100644 --- a/src/openvpn/proxy.h +++ b/src/openvpn/proxy.h @@ -35,19 +35,21 @@ #define HTTP_AUTH_NTLM2 4 #define HTTP_AUTH_N 5 /* number of HTTP_AUTH methods */ -struct http_custom_header { +struct http_custom_header +{ const char *name; const char *content; }; #define MAX_CUSTOM_HTTP_HEADER 10 -struct http_proxy_options { +struct http_proxy_options +{ const char *server; const char *port; -#define PAR_NO 0 /* don't support any auth retries */ -#define PAR_ALL 1 /* allow all proxy auth protocols */ -#define PAR_NCT 2 /* disable cleartext proxy auth protocols */ +#define PAR_NO 0 /* don't support any auth retries */ +#define PAR_ALL 1 /* allow all proxy auth protocols */ +#define PAR_NCT 2 /* disable cleartext proxy auth protocols */ int auth_retry; const char *auth_method_string; @@ -57,11 +59,13 @@ const char *user_agent; struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER]; bool inline_creds; /* auth_file_up is inline credentials */ - bool first_time; /* indicates if we need to wipe user creds at the fir= st iteration of the main loop */ + bool first_time; /* indicates if we need to wipe user creds at the f= irst iteration of the main + loop */ bool nocache; }; -struct http_proxy_info { +struct http_proxy_info +{ bool defined; int auth_method; struct http_proxy_options options; @@ -78,12 +82,11 @@ void http_proxy_close(struct http_proxy_info *hp); bool establish_http_proxy_passthru(struct http_proxy_info *p, - socket_descriptor_t sd, /* already ope= n to proxy */ - const char *host, /* openvpn ser= ver remote */ - const char *port, /* openvpn s= erver port */ + socket_descriptor_t sd, /* already open= to proxy */ + const char *host, /* openvpn serv= er remote */ + const char *port, /* openvpn serv= er port */ struct event_timeout *server_poll_timeo= ut, - struct buffer *lookahead, - struct signal_info *sig_info); + struct buffer *lookahead, struct signal= _info *sig_info); uint8_t *make_base64_string2(const uint8_t *str, int str_len, struct gc_ar= ena *gc); diff --git a/src/openvpn/ps.c b/src/openvpn/ps.c index 0f2b812..65d8d1d 100644 --- a/src/openvpn/ps.c +++ b/src/openvpn/ps.c @@ -47,24 +47,25 @@ #define COMMAND_EXIT 11 /* Response codes for background -> foreground communication */ -#define RESPONSE_INIT_SUCCEEDED 20 -#define RESPONSE_INIT_FAILED 21 +#define RESPONSE_INIT_SUCCEEDED 20 +#define RESPONSE_INIT_FAILED 21 /* * Return values for proxy_connection_io functions */ -#define IOSTAT_EAGAIN_ON_READ 0 /* recv returned EAGAIN */ -#define IOSTAT_EAGAIN_ON_WRITE 1 /* send returned EAGAIN */ -#define IOSTAT_READ_ERROR 2 /* the other end of our read socket (pc)= was closed */ -#define IOSTAT_WRITE_ERROR 3 /* the other end of our write socket (pc= ->counterpart) was closed */ -#define IOSTAT_GOOD 4 /* nothing to report */ +#define IOSTAT_EAGAIN_ON_READ 0 /* recv returned EAGAIN */ +#define IOSTAT_EAGAIN_ON_WRITE 1 /* send returned EAGAIN */ +#define IOSTAT_READ_ERROR 2 /* the other end of our read socket (pc) = was closed */ +#define IOSTAT_WRITE_ERROR 3 /* the other end of our write socket (pc-= >counterpart) was closed */ +#define IOSTAT_GOOD 4 /* nothing to report */ /* * A foreign (non-OpenVPN) connection we are proxying, * usually HTTPS */ -struct proxy_connection { +struct proxy_connection +{ bool defined; struct proxy_connection *next; struct proxy_connection *counterpart; @@ -157,11 +158,11 @@ static int send_control(const socket_descriptor_t fd, int code) { - unsigned char c =3D (unsigned char) code; + unsigned char c =3D (unsigned char)code; const ssize_t size =3D write(fd, &c, sizeof(c)); if (size =3D=3D sizeof(c)) { - return (int) size; + return (int)size; } else { @@ -183,9 +184,7 @@ * send commands, data, and file descriptors to the background process. */ static void -port_share_sendmsg(const socket_descriptor_t sd, - const char command, - const struct buffer *head, +port_share_sendmsg(const socket_descriptor_t sd, const char command, const= struct buffer *head, const socket_descriptor_t sd_send) { if (socket_defined(sd)) @@ -197,8 +196,7 @@ char cmd; ssize_t status; - dmsg(D_PS_PROXY_DEBUG, "PORT SHARE: sendmsg sd=3D%d len=3D%d", - (int)sd_send, + dmsg(D_PS_PROXY_DEBUG, "PORT SHARE: sendmsg sd=3D%d len=3D%d", (in= t)sd_send, head ? BLEN(head) : -1); CLEAR(mesg); @@ -219,7 +217,7 @@ mesg.msg_iov =3D iov; mesg.msg_controllen =3D cmsg_size(); - mesg.msg_control =3D (char *) malloc(mesg.msg_controllen); + mesg.msg_control =3D (char *)malloc(mesg.msg_controllen); check_malloc_return(mesg.msg_control); mesg.msg_flags =3D 0; @@ -241,9 +239,9 @@ status =3D sendmsg(sd, &mesg, MSG_NOSIGNAL); if (status =3D=3D -1) { - msg(M_WARN|M_ERRNO, "PORT SHARE: sendmsg failed -- unable to c= ommunicate with background process (%d,%d,%d,%d)", - sd, sd_send, sd_null[0], sd_null[1] - ); + msg(M_WARN | M_ERRNO, + "PORT SHARE: sendmsg failed -- unable to communicate with = background process (%d,%d,%d,%d)", + sd, sd_send, sd_null[0], sd_null[1]); } close_socket_if_defined(sd_null[0]); @@ -346,13 +344,13 @@ slen =3D sizeof(from.addr); dlen =3D sizeof(to.addr); - if (!getpeername(pc->sd, (struct sockaddr *) &from.addr.sa, &slen) - && !getsockname(cp->sd, (struct sockaddr *) &to.addr.sa, &dlen)) + if (!getpeername(pc->sd, (struct sockaddr *)&from.addr.sa, &slen) + && !getsockname(cp->sd, (struct sockaddr *)&to.addr.sa, &dlen)) { const char *f =3D print_openvpn_sockaddr(&from, &gc); const char *t =3D print_openvpn_sockaddr(&to, &gc); - fnlen =3D strlen(journal_dir) + strlen(t) + 2; - jfn =3D (char *) malloc(fnlen); + fnlen =3D strlen(journal_dir) + strlen(t) + 2; + jfn =3D (char *)malloc(fnlen); check_malloc_return(jfn); snprintf(jfn, fnlen, "%s/%s", journal_dir, t); dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: client origin %s -> %s",= jfn, f); @@ -368,7 +366,7 @@ } else { - msg(M_WARN|M_ERRNO, "PORT SHARE: unable to write journal file = in %s", jfn); + msg(M_WARN | M_ERRNO, "PORT SHARE: unable to write journal fil= e in %s", jfn); free(jfn); } } @@ -394,11 +392,13 @@ } static inline void -proxy_connection_io_requeue(struct proxy_connection *pc, const int rwflags= _new, struct event_set *es) +proxy_connection_io_requeue(struct proxy_connection *pc, const int rwflags= _new, + struct event_set *es) { if (socket_defined(pc->sd) && pc->rwflags !=3D rwflags_new) { - /*dmsg (D_PS_PROXY_DEBUG, "PORT SHARE PROXY: requeue[%d] rwflags= =3D%d", (int)pc->sd, rwflags_new);*/ + /*dmsg (D_PS_PROXY_DEBUG, "PORT SHARE PROXY: requeue[%d] rwflags= =3D%d", (int)pc->sd, + * rwflags_new);*/ event_ctl(es, pc->sd, rwflags_new, (void *)pc); pc->rwflags =3D rwflags_new; } @@ -412,12 +412,9 @@ * on success and false on failure to connect to server. */ static bool -proxy_entry_new(struct proxy_connection **list, - struct event_set *es, - const struct openvpn_sockaddr server_addr, - const socket_descriptor_t sd_client, - struct buffer *initial_data, - const char *journal_dir) +proxy_entry_new(struct proxy_connection **list, struct event_set *es, + const struct openvpn_sockaddr server_addr, const socket_de= scriptor_t sd_client, + struct buffer *initial_data, const char *journal_dir) { socket_descriptor_t sd_server; int status; @@ -427,7 +424,7 @@ /* connect to port share server */ if ((sd_server =3D socket(server_addr.addr.sa.sa_family, SOCK_STREAM, = IPPROTO_TCP)) < 0) { - msg(M_WARN|M_ERRNO, "PORT SHARE PROXY: cannot create socket"); + msg(M_WARN | M_ERRNO, "PORT SHARE PROXY: cannot create socket"); return false; } status =3D openvpn_connect(sd_server, &server_addr.addr.sa, 5, NULL); @@ -473,11 +470,12 @@ journal_add(journal_dir, pc, cp); } - dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: NEW CONNECTION [c=3D%d s=3D%= d]", (int)sd_client, (int)sd_server); + dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: NEW CONNECTION [c=3D%d s=3D%= d]", (int)sd_client, + (int)sd_server); /* set initial i/o states */ proxy_connection_io_requeue(pc, EVENT_READ, es); - proxy_connection_io_requeue(cp, EVENT_READ|EVENT_WRITE, es); + proxy_connection_io_requeue(cp, EVENT_READ | EVENT_WRITE, es); return true; } @@ -489,12 +487,9 @@ * exit, true otherwise. */ static bool -control_message_from_parent(const socket_descriptor_t sd_control, - struct proxy_connection **list, - struct event_set *es, - const struct openvpn_sockaddr server_addr, - const int max_initial_buf, - const char *journal_dir) +control_message_from_parent(const socket_descriptor_t sd_control, struct p= roxy_connection **list, + struct event_set *es, const struct openvpn_soc= kaddr server_addr, + const int max_initial_buf, const char *journal= _dir) { /* this buffer needs to be large enough to handle the largest buffer * that might be returned by the link_socket_read call in read_incomin= g_link. */ @@ -517,7 +512,7 @@ mesg.msg_iovlen =3D 2; mesg.msg_controllen =3D cmsg_size(); - mesg.msg_control =3D (char *) malloc(mesg.msg_controllen); + mesg.msg_control =3D (char *)malloc(mesg.msg_controllen); check_malloc_return(mesg.msg_control); mesg.msg_flags =3D 0; @@ -531,10 +526,8 @@ status =3D recvmsg(sd_control, &mesg, MSG_NOSIGNAL); if (status !=3D -1) { - if (h =3D=3D NULL - || h->cmsg_len !=3D CMSG_LEN(sizeof(socket_descriptor_t)) - || h->cmsg_level !=3D SOL_SOCKET - || h->cmsg_type !=3D SCM_RIGHTS) + if (h =3D=3D NULL || h->cmsg_len !=3D CMSG_LEN(sizeof(socket_descr= iptor_t)) + || h->cmsg_level !=3D SOL_SOCKET || h->cmsg_type !=3D SCM_RIGH= TS) { msg(M_WARN, "PORT SHARE PROXY: received unknown message"); } @@ -547,12 +540,7 @@ if (status >=3D 2 && command =3D=3D COMMAND_REDIRECT) { buf.len =3D status - 1; - if (proxy_entry_new(list, - es, - server_addr, - received_fd, - &buf, - journal_dir)) + if (proxy_entry_new(list, es, server_addr, received_fd, &b= uf, journal_dir)) { CLEAR(buf); /* we gave the buffer to proxy_entry_new */ } @@ -611,7 +599,8 @@ *bytes_sent +=3D status; if (status !=3D pc->buf.len) { - dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: partial write[%d], t= ried=3D%d got=3D%d", (int)sd, pc->buf.len, status); + dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: partial write[%d], t= ried=3D%d got=3D%d", (int)sd, + pc->buf.len, status); buf_advance(&pc->buf, status); return IOSTAT_EAGAIN_ON_WRITE; } @@ -699,9 +688,7 @@ * in the proxied connection. */ static int -proxy_connection_io_dispatch(struct proxy_connection *pc, - const int rwflags, - struct event_set *es) +proxy_connection_io_dispatch(struct proxy_connection *pc, const int rwflag= s, struct event_set *es) { const int max_transfer_per_iteration =3D 10000; struct proxy_connection *cp =3D pc->counterpart; @@ -740,10 +727,8 @@ * This is the main function for the port share proxy background process. */ static void -port_share_proxy(const struct openvpn_sockaddr hostaddr, - const socket_descriptor_t sd_control, - const int max_initial_buf, - const char *journal_dir) +port_share_proxy(const struct openvpn_sockaddr hostaddr, const socket_desc= riptor_t sd_control, + const int max_initial_buf, const char *journal_dir) { if (send_control(sd_control, RESPONSE_INIT_SUCCEEDED) >=3D 0) { @@ -777,7 +762,8 @@ const struct event_set_return *e =3D &esr[i]; if (e->arg =3D=3D sd_control_marker) { - if (!control_message_from_parent(sd_control, &list= , es, hostaddr, max_initial_buf, journal_dir)) + if (!control_message_from_parent(sd_control, &list= , es, hostaddr, + max_initial_buf, = journal_dir)) { goto done; } @@ -815,9 +801,7 @@ * share proxy. */ struct port_share * -port_share_open(const char *host, - const char *port, - const int max_initial_buf, +port_share_open(const char *host, const char *port, const int max_initial_= buf, const char *journal_dir) { pid_t pid; @@ -835,9 +819,9 @@ * Get host's IP address */ - status =3D openvpn_getaddrinfo(GETADDR_RESOLVE|GETADDR_FATAL, - host, port, 0, NULL, AF_UNSPEC, &ai); - ASSERT(status=3D=3D0); + status =3D + openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_FATAL, host, port, 0= , NULL, AF_UNSPEC, &ai); + ASSERT(status =3D=3D 0); ASSERT(sizeof(hostaddr.addr) >=3D ai->ai_addrlen); memcpy(&hostaddr.addr.sa, ai->ai_addr, ai->ai_addrlen); freeaddrinfo(ai); @@ -983,7 +967,7 @@ bool is_openvpn_protocol(const struct buffer *buf) { - const unsigned char *p =3D (const unsigned char *) BSTR(buf); + const unsigned char *p =3D (const unsigned char *)BSTR(buf); const int len =3D BLEN(buf); if (len >=3D 3) { @@ -1005,7 +989,7 @@ * We don't do the 2 byte check for tls-crypt-v2 because it is= very * unrealistic to have only 2 bytes available. */ - return (plen >=3D 336 && plen < (1024 + 255)); + return (plen >=3D 336 && plen < (1024 + 255)); } else { diff --git a/src/openvpn/ps.h b/src/openvpn/ps.h index 59aecbe..1309eae 100644 --- a/src/openvpn/ps.h +++ b/src/openvpn/ps.h @@ -30,7 +30,8 @@ #include "buffer.h" #include "ssl.h" -struct port_share { +struct port_share +{ /* Foreground's socket to background process */ socket_descriptor_t foreground_fd; @@ -40,9 +41,7 @@ extern struct port_share *port_share; -struct port_share *port_share_open(const char *host, - const char *port, - const int max_initial_buf, +struct port_share *port_share_open(const char *host, const char *port, con= st int max_initial_buf, const char *journal_dir); void port_share_close(struct port_share *ps); diff --git a/src/openvpn/push.c b/src/openvpn/push.c index ad8fa3d7..921b867 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -98,7 +98,7 @@ case AR_INTERACT: ssl_purge_auth(false); - /* Intentional [[fallthrough]]; */ + /* Intentional [[fallthrough]]; */ case AR_NOINTERACT: /* SOFT-SIGTUSR1 -- Auth failure error */ @@ -117,20 +117,19 @@ /* * Save the dynamic-challenge text even when management is defined */ - if (authfail_extended - && buf_string_match_head_str(&buf, "CRV1:") && BLEN(&buf)) + if (authfail_extended && buf_string_match_head_str(&buf, "CRV1:") && B= LEN(&buf)) { ssl_put_auth_challenge(BSTR(&buf)); } #endif /* ifdef ENABLE_MANAGEMENT */ - } /* * Act on received restart message from server */ void -server_pushed_signal(struct context *c, const struct buffer *buffer, const= bool restart, const int adv) +server_pushed_signal(struct context *c, const struct buffer *buffer, const= bool restart, + const int adv) { if (c->options.pull) { @@ -253,7 +252,8 @@ } else { - msg(D_PUSH_ERRORS, "WARNING: Received INFO command is too long= , won't notify management client."); + msg(D_PUSH_ERRORS, + "WARNING: Received INFO command is too long, won't notify = management client."); } gc_free(&gc); @@ -295,20 +295,18 @@ * if the server does not push a timeout */ static void -parse_auth_pending_keywords(const struct buffer *buffer, - unsigned int *server_timeout) +parse_auth_pending_keywords(const struct buffer *buffer, unsigned int *ser= ver_timeout) { struct buffer buf =3D *buffer; /* does the buffer start with "AUTH_PENDING," ? */ - if (!buf_advance(&buf, strlen("AUTH_PENDING")) - || !(buf_read_u8(&buf) =3D=3D ',') || !BLEN(&buf)) + if (!buf_advance(&buf, strlen("AUTH_PENDING")) || !(buf_read_u8(&buf) = =3D=3D ',') || !BLEN(&buf)) { #ifdef ENABLE_MANAGEMENT if (management) { - management_set_state(management, OPENVPN_STATE_AUTH_PENDING, - "", NULL, NULL, NULL, NULL); + management_set_state(management, OPENVPN_STATE_AUTH_PENDING, "= ", NULL, NULL, NULL, + NULL); } #endif @@ -323,8 +321,8 @@ * buf_parse is called, as it will insert \0 bytes into the buffer */ if (management) { - management_set_state(management, OPENVPN_STATE_AUTH_PENDING, - BSTR(&buf), NULL, NULL, NULL, NULL); + management_set_state(management, OPENVPN_STATE_AUTH_PENDING, BSTR(= &buf), NULL, NULL, NULL, + NULL); } #endif @@ -347,17 +345,18 @@ /* Cap the increase at the maximum time we are willing stay in the * pending authentication state */ - unsigned int max_timeout =3D max_uint(c->options.renegotiate_seconds/2, - c->options.handshake_window); + unsigned int max_timeout =3D + max_uint(c->options.renegotiate_seconds / 2, c->options.handshake_= window); /* try to parse parameter keywords, default to hand-winow timeout if t= he * server does not supply a timeout */ unsigned int server_timeout =3D c->options.handshake_window; parse_auth_pending_keywords(buffer, &server_timeout); - msg(D_PUSH, "AUTH_PENDING received, extending handshake timeout from %= us " - "to %us", c->options.handshake_window, - min_uint(max_timeout, server_timeout)); + msg(D_PUSH, + "AUTH_PENDING received, extending handshake timeout from %us " + "to %us", + c->options.handshake_window, min_uint(max_timeout, server_timeout)= ); const struct key_state *ks =3D get_primary_key(c->c2.tls_multi); c->c2.push_request_timeout =3D ks->established + min_uint(max_timeout,= server_timeout); @@ -377,16 +376,16 @@ * * @return true on success, false on failure. */ -static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_li= st, - int msglevel, const char *fmt, ...) +static bool push_option_fmt(struct gc_arena *gc, struct push_list *push_li= st, int msglevel, + const char *fmt, ...) #ifdef __GNUC__ #if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 4, 5))) + __attribute__((format(gnu_printf, 4, 5))) #else -__attribute__ ((format(__printf__, 4, 5))) + __attribute__((format(__printf__, 4, 5))) #endif #endif -; + ; /* * Send auth failed message from server to client. @@ -406,7 +405,7 @@ static const char auth_failed[] =3D "AUTH_FAILED"; size_t len; - len =3D (client_reason ? strlen(client_reason)+1 : 0) + sizeof(auth_fa= iled); + len =3D (client_reason ? strlen(client_reason) + 1 : 0) + sizeof(auth_= failed); if (len > PUSH_BUNDLE_SIZE) { len =3D PUSH_BUNDLE_SIZE; @@ -422,13 +421,12 @@ /* We kill the whole session, send the AUTH_FAILED to any TLS sess= ion * that might be active */ - send_control_channel_string_dowork(&c->c2.tls_multi->session[TM_IN= ITIAL], - BSTR(&buf), D_PUSH); - send_control_channel_string_dowork(&c->c2.tls_multi->session[TM_AC= TIVE], - BSTR(&buf), D_PUSH); + send_control_channel_string_dowork(&c->c2.tls_multi->session[TM_IN= ITIAL], BSTR(&buf), + D_PUSH); + send_control_channel_string_dowork(&c->c2.tls_multi->session[TM_AC= TIVE], BSTR(&buf), + D_PUSH); reschedule_multi_process(c); - } gc_free(&gc); @@ -436,8 +434,7 @@ bool -send_auth_pending_messages(struct tls_multi *tls_multi, - struct tls_session *session, +send_auth_pending_messages(struct tls_multi *tls_multi, struct tls_session= *session, const char *extra, unsigned int timeout) { struct key_state *ks =3D &session->key[KS_PRIMARY]; @@ -449,8 +446,8 @@ /* Calculate the maximum timeout and subtract the time we already wait= ed */ - unsigned int max_timeout =3D max_uint(tls_multi->opt.renegotiate_secon= ds/2, - tls_multi->opt.handshake_window); + unsigned int max_timeout =3D + max_uint(tls_multi->opt.renegotiate_seconds / 2, tls_multi->opt.ha= ndshake_window); max_timeout =3D max_timeout - (now - ks->initial); timeout =3D min_uint(max_timeout, timeout); @@ -509,15 +506,16 @@ struct gc_arena gc =3D gc_new(); unsigned int option_types_found =3D 0; - msg(D_PUSH, "PUSH: Received control message: '%s'", sanitize_control_m= essage(BSTR(buffer), &gc)); + msg(D_PUSH, "PUSH: Received control message: '%s'", + sanitize_control_message(BSTR(buffer), &gc)); - int status =3D process_incoming_push_msg(c, buffer, c->options.pull, - pull_permission_mask(c), + int status =3D process_incoming_push_msg(c, buffer, c->options.pull, p= ull_permission_mask(c), &option_types_found); if (status =3D=3D PUSH_MSG_ERROR) { - msg(D_PUSH_ERRORS, "WARNING: Received bad push/pull message: %s", = sanitize_control_message(BSTR(buffer), &gc)); + msg(D_PUSH_ERRORS, "WARNING: Received bad push/pull message: %s", + sanitize_control_message(BSTR(buffer), &gc)); } else if (status =3D=3D PUSH_MSG_REPLY || status =3D=3D PUSH_MSG_CONTIN= UATION) { @@ -593,17 +591,14 @@ */ if (tls_multi->auth_token) { - push_option_fmt(gc, push_list, M_USAGE, "auth-token %s", - tls_multi->auth_token); + push_option_fmt(gc, push_list, M_USAGE, "auth-token %s", tls_multi= ->auth_token); char *base64user =3D NULL; int ret =3D openvpn_base64_encode(tls_multi->locked_username, - (int)strlen(tls_multi->locked_user= name), - &base64user); + (int)strlen(tls_multi->locked_user= name), &base64user); if (ret < USER_PASS_LEN && ret > 0) { - push_option_fmt(gc, push_list, M_USAGE, "auth-token-user %s", - base64user); + push_option_fmt(gc, push_list, M_USAGE, "auth-token-user %s", = base64user); } free(base64user); } @@ -619,8 +614,7 @@ * @return true on success, false on failure. */ bool -prepare_push_reply(struct context *c, struct gc_arena *gc, - struct push_list *push_list) +prepare_push_reply(struct context *c, struct gc_arena *gc, struct push_lis= t *push_list) { struct tls_multi *tls_multi =3D c->c2.tls_multi; struct options *o =3D &c->options; @@ -631,14 +625,12 @@ push_option_fmt(gc, push_list, M_USAGE, "ifconfig-ipv6 %s/%d %s", print_in6_addr(c->c2.push_ifconfig_ipv6_local, 0, = gc), c->c2.push_ifconfig_ipv6_netbits, - print_in6_addr(c->c2.push_ifconfig_ipv6_remote, - 0, gc)); + print_in6_addr(c->c2.push_ifconfig_ipv6_remote, 0,= gc)); } /* ipv4 */ if (c->c2.push_ifconfig_defined && c->c2.push_ifconfig_local - && c->c2.push_ifconfig_remote_netmask - && !o->push_ifconfig_ipv4_blocked) + && c->c2.push_ifconfig_remote_netmask && !o->push_ifconfig_ipv4_bl= ocked) { in_addr_t ifconfig_local =3D c->c2.push_ifconfig_local; if (c->c2.push_ifconfig_local_alias) @@ -647,14 +639,12 @@ } push_option_fmt(gc, push_list, M_USAGE, "ifconfig %s %s", print_in_addr_t(ifconfig_local, 0, gc), - print_in_addr_t(c->c2.push_ifconfig_remote_netmask, - 0, gc)); + print_in_addr_t(c->c2.push_ifconfig_remote_netmask= , 0, gc)); } if (tls_multi->use_peer_id) { - push_option_fmt(gc, push_list, M_USAGE, "peer-id %d", - tls_multi->peer_id); + push_option_fmt(gc, push_list, M_USAGE, "peer-id %d", tls_multi->p= eer_id); } /* * If server uses --auth-gen-token and we have an auth token @@ -716,10 +706,11 @@ push_option_fmt(gc, push_list, M_USAGE, "tun-mtu %d", o->ce.tun_mt= u); if (client_max_mtu < o->ce.tun_mtu) { - msg(M_WARN, "Warning: reported maximum MTU from client (%d) is= lower " + msg(M_WARN, + "Warning: reported maximum MTU from client (%d) is lower " "than MTU used on the server (%d). Add tun-max-mtu %d " - "to client configuration.", client_max_mtu, - o->ce.tun_mtu, o->ce.tun_mtu); + "to client configuration.", + client_max_mtu, o->ce.tun_mtu, o->ce.tun_mtu); } } @@ -727,8 +718,7 @@ } static bool -send_push_options(struct context *c, struct buffer *buf, - struct push_list *push_list, int safe_cap, +send_push_options(struct context *c, struct buffer *buf, struct push_list = *push_list, int safe_cap, bool *push_sent, bool *multi_push) { struct push_entry *e =3D push_list->head; @@ -798,15 +788,13 @@ buf_printf(&buf, "%s", push_reply_cmd); /* send options which are common to all clients */ - if (!send_push_options(c, &buf, &c->options.push_list, safe_cap, - &push_sent, &multi_push)) + if (!send_push_options(c, &buf, &c->options.push_list, safe_cap, &push= _sent, &multi_push)) { goto fail; } /* send client-specific options */ - if (!send_push_options(c, &buf, per_client_push_list, safe_cap, - &push_sent, &multi_push)) + if (!send_push_options(c, &buf, per_client_push_list, safe_cap, &push_= sent, &multi_push)) { goto fail; } @@ -816,7 +804,7 @@ buf_printf(&buf, ",push-continuation 1"); } - if (BLEN(&buf) > sizeof(push_reply_cmd)-1) + if (BLEN(&buf) > sizeof(push_reply_cmd) - 1) { const bool status =3D send_control_channel_string(c, BSTR(&buf), D= _PUSH); if (!status) @@ -851,8 +839,8 @@ } static void -push_option_ex(struct gc_arena *gc, struct push_list *push_list, - const char *opt, bool enable, int msglevel) +push_option_ex(struct gc_arena *gc, struct push_list *push_list, const cha= r *opt, bool enable, + int msglevel) { if (!string_class(opt, CC_ANY, CC_COMMA)) { @@ -894,8 +882,7 @@ push_reset(o); while (e) { - push_option_ex(&o->gc, &o->push_list, - string_alloc(e->option, &o->gc), true, M_FATAL); + push_option_ex(&o->gc, &o->push_list, string_alloc(e->option, = &o->gc), true, M_FATAL); e =3D e->next; } } @@ -910,16 +897,16 @@ } static bool -push_option_fmt(struct gc_arena *gc, struct push_list *push_list, - int msglevel, const char *format, ...) +push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int msgl= evel, const char *format, + ...) { va_list arglist; - char tmp[256] =3D {0}; + char tmp[256] =3D { 0 }; int len; va_start(arglist, format); len =3D vsnprintf(tmp, sizeof(tmp), format, arglist); va_end(arglist); - if (len > sizeof(tmp)-1) + if (len > sizeof(tmp) - 1) { return false; } @@ -946,7 +933,7 @@ } /* ifconfig-ipv6 is special, as not part of the push list */ - if (streq( p, "ifconfig-ipv6" )) + if (streq(p, "ifconfig-ipv6")) { o->push_ifconfig_ipv6_blocked =3D true; return; @@ -959,8 +946,7 @@ /* cycle through the push list */ while (e) { - if (e->enable - && strncmp( e->option, p, strlen(p) ) =3D=3D 0) + if (e->enable && strncmp(e->option, p, strlen(p)) =3D=3D 0) { msg(D_PUSH_DEBUG, "PUSH_REMOVE removing: '%s'", e->option); e->enable =3D false; @@ -1000,8 +986,7 @@ struct push_list push_list =3D { 0 }; struct gc_arena gc =3D gc_new(); - if (prepare_push_reply(c, &gc, &push_list) - && send_push_reply(c, &push_list)) + if (prepare_push_reply(c, &gc, &push_list) && send_push_reply(= c, &push_list)) { ret =3D PUSH_MSG_REQUEST; c->c2.sent_push_reply_expiry =3D now + 30; @@ -1023,9 +1008,9 @@ char line[OPTION_PARM_SIZE]; while (buf_parse(buf, ',', line, sizeof(line))) { - /* peer-id and auth-token might change on restart and this should = not trigger reopening tun */ - if (strprefix(line, "peer-id ") - || strprefix(line, "auth-token ") + /* peer-id and auth-token might change on restart and this should = not trigger reopening tun + */ + if (strprefix(line, "peer-id ") || strprefix(line, "auth-token ") || strprefix(line, "auth-token-user ")) { continue; @@ -1035,15 +1020,13 @@ { continue; } - md_ctx_update(ctx, (const uint8_t *) line, strlen(line)+1); + md_ctx_update(ctx, (const uint8_t *)line, strlen(line) + 1); } } static int -process_incoming_push_reply(struct context *c, - unsigned int permission_mask, - unsigned int *option_types_found, - struct buffer *buf) +process_incoming_push_reply(struct context *c, unsigned int permission_mas= k, + unsigned int *option_types_found, struct buffe= r *buf) { int ret =3D PUSH_MSG_ERROR; const uint8_t ch =3D buf_read_u8(buf); @@ -1056,20 +1039,14 @@ md_ctx_init(c->c2.pulled_options_state, "SHA256"); c->c2.pulled_options_digest_init_done =3D true; } - if (apply_push_options(&c->options, - buf, - permission_mask, - option_types_found, - c->c2.es)) + if (apply_push_options(&c->options, buf, permission_mask, option_t= ypes_found, c->c2.es)) { - push_update_digest(c->c2.pulled_options_state, &buf_orig, - &c->options); + push_update_digest(c->c2.pulled_options_state, &buf_orig, &c->= options); switch (c->options.push_continuation) { case 0: case 1: - md_ctx_final(c->c2.pulled_options_state, - c->c2.pulled_options_digest.digest); + md_ctx_final(c->c2.pulled_options_state, c->c2.pulled_= options_digest.digest); md_ctx_cleanup(c->c2.pulled_options_state); md_ctx_free(c->c2.pulled_options_state); c->c2.pulled_options_state =3D NULL; @@ -1092,10 +1069,8 @@ } int -process_incoming_push_msg(struct context *c, - const struct buffer *buffer, - bool honor_received_options, - unsigned int permission_mask, +process_incoming_push_msg(struct context *c, const struct buffer *buffer, + bool honor_received_options, unsigned int permis= sion_mask, unsigned int *option_types_found) { struct buffer buf =3D *buffer; @@ -1105,11 +1080,9 @@ c->c2.push_request_received =3D true; return process_incoming_push_request(c); } - else if (honor_received_options - && buf_string_compare_advance(&buf, push_reply_cmd)) + else if (honor_received_options && buf_string_compare_advance(&buf, pu= sh_reply_cmd)) { - return process_incoming_push_reply(c, permission_mask, - option_types_found, &buf); + return process_incoming_push_reply(c, permission_mask, option_type= s_found, &buf); } else { @@ -1132,13 +1105,14 @@ /* cycle through the push list */ while (e) { - char *p[MAX_PARMS+1]; + char *p[MAX_PARMS + 1]; bool enable =3D true; /* parse the push item */ CLEAR(p); if (e->enable - && parse_line(e->option, p, SIZE(p)-1, "[PUSH_ROUTE_REMOVE= ]", 1, D_ROUTE_DEBUG, &gc)) + && parse_line(e->option, p, SIZE(p) - 1, "[PUSH_ROUTE_REMO= VE]", 1, D_ROUTE_DEBUG, + &gc)) { /* is the push item a route directive? */ if (p[0] && !strcmp(p[0], "route") && !p[3] && o->iroutes) @@ -1146,7 +1120,8 @@ /* get route parameters */ bool status1, status2; const in_addr_t network =3D getaddr(GETADDR_HOST_ORDER= , p[1], 0, &status1, NULL); - const in_addr_t netmask =3D getaddr(GETADDR_HOST_ORDER= , p[2] ? p[2] : "255.255.255.255", 0, &status2, NULL); + const in_addr_t netmask =3D getaddr( + GETADDR_HOST_ORDER, p[2] ? p[2] : "255.255.255.255= ", 0, &status2, NULL); /* did route parameters parse correctly? */ if (status1 && status2) @@ -1156,7 +1131,9 @@ /* does route match an iroute? */ for (ir =3D o->iroutes; ir !=3D NULL; ir =3D ir->n= ext) { - if (network =3D=3D ir->network && netmask =3D= =3D netbits_to_netmask(ir->netbits >=3D 0 ? ir->netbits : 32)) + if (network =3D=3D ir->network + && netmask + =3D=3D netbits_to_netmask(ir->netbi= ts >=3D 0 ? ir->netbits : 32)) { enable =3D false; break; @@ -1164,8 +1141,7 @@ } } } - else if (p[0] && !strcmp(p[0], "route-ipv6") && !p[2] - && o->iroutes_ipv6) + else if (p[0] && !strcmp(p[0], "route-ipv6") && !p[2] && o= ->iroutes_ipv6) { /* get route parameters */ struct in6_addr network; diff --git a/src/openvpn/push.h b/src/openvpn/push.h index 048b4c4..84931fb 100644 --- a/src/openvpn/push.h +++ b/src/openvpn/push.h @@ -36,17 +36,16 @@ int process_incoming_push_request(struct context *c); -int process_incoming_push_msg(struct context *c, - const struct buffer *buffer, - bool honor_received_options, - unsigned int permission_mask, +int process_incoming_push_msg(struct context *c, const struct buffer *buff= er, + bool honor_received_options, unsigned int pe= rmission_mask, unsigned int *option_types_found); bool send_push_request(struct context *c); void receive_auth_failed(struct context *c, const struct buffer *buffer); -void server_pushed_signal(struct context *c, const struct buffer *buffer, = const bool restart, const int adv); +void server_pushed_signal(struct context *c, const struct buffer *buffer, = const bool restart, + const int adv); void receive_exit_message(struct context *c); @@ -60,8 +59,7 @@ void push_option(struct options *o, const char *opt, int msglevel); -void push_options(struct options *o, char **p, int msglevel, - struct gc_arena *gc); +void push_options(struct options *o, char **p, int msglevel, struct gc_are= na *gc); void push_reset(struct options *o); @@ -76,10 +74,8 @@ * doc/management-notes.txt under client-pending-auth for * more details on message format */ -bool -send_auth_pending_messages(struct tls_multi *tls_multi, - struct tls_session *session, const char *extra, - unsigned int timeout); +bool send_auth_pending_messages(struct tls_multi *tls_multi, struct tls_se= ssion *session, + const char *extra, unsigned int timeout); void send_restart(struct context *c, const char *kill_msg); @@ -98,7 +94,6 @@ * @param c The context struct * @param buffer Buffer containing the control message with AUTH_PE= NDING */ -void -receive_auth_pending(struct context *c, const struct buffer *buffer); +void receive_auth_pending(struct context *c, const struct buffer *buffer); #endif /* ifndef PUSH_H */ diff --git a/src/openvpn/pushlist.h b/src/openvpn/pushlist.h index d946a5f..f4d4370 100644 --- a/src/openvpn/pushlist.h +++ b/src/openvpn/pushlist.h @@ -26,13 +26,15 @@ /* parameters to be pushed to peer */ -struct push_entry { +struct push_entry +{ struct push_entry *next; bool enable; const char *option; }; -struct push_list { +struct push_list +{ struct push_entry *head; struct push_entry *tail; }; diff --git a/src/openvpn/reflect_filter.c b/src/openvpn/reflect_filter.c index a5bcf94..8b4ff2d 100644 --- a/src/openvpn/reflect_filter.c +++ b/src/openvpn/reflect_filter.c @@ -47,10 +47,10 @@ int64_t dropped =3D irl->curr_period_counter - irl->max_per_period; if (dropped > 0) { - msg(D_TLS_DEBUG_LOW, "Dropped %" PRId64 " initial handshake pa= ckets" - " due to --connect-freq-initial %" PRId64 " %d", dropped, - irl->max_per_period, irl->period_length); - + msg(D_TLS_DEBUG_LOW, + "Dropped %" PRId64 " initial handshake packets" + " due to --connect-freq-initial %" PRId64 " %d", + dropped, irl->max_per_period, irl->period_length); } irl->last_period_reset =3D now; irl->curr_period_counter =3D 0; @@ -63,9 +63,11 @@ if (over_limit && !irl->warning_displayed) { - msg(M_WARN, "Note: --connect-freq-initial %" PRId64 " %d rate limi= t " + msg(M_WARN, + "Note: --connect-freq-initial %" PRId64 " %d rate limit " "exceeded, dropping initial handshake packets for the next %d " - "seconds", irl->max_per_period, irl->period_length, + "seconds", + irl->max_per_period, irl->period_length, (int)(irl->last_period_reset + irl->period_length - now)); irl->warning_displayed =3D true; } diff --git a/src/openvpn/reflect_filter.h b/src/openvpn/reflect_filter.h index ae7be21..1981067 100644 --- a/src/openvpn/reflect_filter.h +++ b/src/openvpn/reflect_filter.h @@ -27,7 +27,8 @@ /** struct that handles all the rate limiting logic for initial * responses */ -struct initial_packet_rate_limit { +struct initial_packet_rate_limit +{ /** This is a hard limit for packets per seconds. */ int64_t max_per_period; @@ -51,22 +52,19 @@ * checks if the connection is still allowed to connect under the rate * limit. This also increases the internal counter at the same time */ -bool -reflect_filter_rate_limit_check(struct initial_packet_rate_limit *irl); +bool reflect_filter_rate_limit_check(struct initial_packet_rate_limit *irl= ); /** * decreases the counter of initial packets seen, so connections that * successfully completed the three-way handshake do not count against * the counter of initial connection attempts */ -void -reflect_filter_rate_limit_decrease(struct initial_packet_rate_limit *irl); +void reflect_filter_rate_limit_decrease(struct initial_packet_rate_limit *= irl); /** * allocate and initialize the initial-packet rate limiter structure */ -struct initial_packet_rate_limit * -initial_rate_limit_init(int max_per_period, int period_length); +struct initial_packet_rate_limit *initial_rate_limit_init(int max_per_peri= od, int period_length); /** * free the initial-packet rate limiter structure diff --git a/src/openvpn/reliable.c b/src/openvpn/reliable.c index 5505f56..0c3f08f 100644 --- a/src/openvpn/reliable.c +++ b/src/openvpn/reliable.c @@ -51,8 +51,7 @@ * verify that test - base < extent while allowing for base or test wrapar= ound */ static inline bool -reliable_pid_in_range1(const packet_id_type test, - const packet_id_type base, +reliable_pid_in_range1(const packet_id_type test, const packet_id_type bas= e, const unsigned int extent) { return subtract_pid(test, base) < extent; @@ -62,8 +61,7 @@ * verify that test < base + extent while allowing for base or test wrapar= ound */ static inline bool -reliable_pid_in_range2(const packet_id_type test, - const packet_id_type base, +reliable_pid_in_range2(const packet_id_type test, const packet_id_type bas= e, const unsigned int extent) { if (base + extent >=3D base) @@ -75,7 +73,7 @@ } else { - if ((test+0x80000000u) < (base+0x80000000u) + extent) + if ((test + 0x80000000u) < (base + 0x80000000u) + extent) { return true; } @@ -88,8 +86,7 @@ * verify that p1 < p2 while allowing for p1 or p2 wraparound */ static inline bool -reliable_pid_min(const packet_id_type p1, - const packet_id_type p2) +reliable_pid_min(const packet_id_type p1, const packet_id_type p2) { return !reliable_pid_in_range1(p1, p2, 0x80000000u); } @@ -145,8 +142,7 @@ bool -reliable_ack_read(struct reliable_ack *ack, - struct buffer *buf, const struct session_id *sid) +reliable_ack_read(struct reliable_ack *ack, struct buffer *buf, const stru= ct session_id *sid) { struct session_id session_id_remote; @@ -155,12 +151,11 @@ return false; } - if (ack->len >=3D 1 && (!session_id_defined(&session_id_remote) - || !session_id_equal(&session_id_remote, sid))) + if (ack->len >=3D 1 + && (!session_id_defined(&session_id_remote) || !session_id_equal(&= session_id_remote, sid))) { struct gc_arena gc =3D gc_new(); - dmsg(D_REL_LOW, - "ACK read BAD SESSION-ID FROM REMOTE, local=3D%s, remote=3D%s= ", + dmsg(D_REL_LOW, "ACK read BAD SESSION-ID FROM REMOTE, local=3D%s, = remote=3D%s", session_id_print(sid, &gc), session_id_print(&session_id_remo= te, &gc)); gc_free(&gc); return false; @@ -211,7 +206,7 @@ { ASSERT(ack->len >=3D n); /* This loop is backward to ensure the same order as in ack */ - for (int i =3D n-1; i >=3D 0; i--) + for (int i =3D n - 1; i >=3D 0; i--) { packet_id_type id =3D ack->packet_id[i]; @@ -251,9 +246,7 @@ /* write a packet ID acknowledgement record to buf, */ /* removing all acknowledged entries from ack */ bool -reliable_ack_write(struct reliable_ack *ack, - struct reliable_ack *ack_mru, - struct buffer *buf, +reliable_ack_write(struct reliable_ack *ack, struct reliable_ack *ack_mru,= struct buffer *buf, const struct session_id *sid, int max, bool prepend) { int i, j, n; @@ -285,7 +278,8 @@ packet_id_type pid =3D ack_mru->packet_id[i]; packet_id_type net_pid =3D htonpid(pid); ASSERT(buf_write(&sub, &net_pid, sizeof(net_pid))); - dmsg(D_REL_DEBUG, "ACK write ID " packet_id_format " (ack->len=3D%= d, n=3D%d)", (packet_id_print_type)pid, ack->len, n); + dmsg(D_REL_DEBUG, "ACK write ID " packet_id_format " (ack->len=3D%= d, n=3D%d)", + (packet_id_print_type)pid, ack->len, n); } if (total_acks) { @@ -294,7 +288,7 @@ } if (n) { - for (i =3D 0, j =3D n; j < ack->len; ) + for (i =3D 0, j =3D n; j < ack->len;) { ack->packet_id[i++] =3D ack->packet_id[j++]; } @@ -495,7 +489,8 @@ return true; bad: - dmsg(D_REL_DEBUG, "ACK " packet_id_format " is a replay: %s", (packet_= id_print_type)id, reliable_print_ids(rel, &gc)); + dmsg(D_REL_DEBUG, "ACK " packet_id_format " is a replay: %s", (packet_= id_print_type)id, + reliable_print_ids(rel, &gc)); gc_free(&gc); return false; } @@ -514,7 +509,8 @@ gc_free(&gc); } - dmsg(D_REL_DEBUG, "ACK RWBS rel->size=3D%d rel->packet_id=3D%08x id=3D= %08x ret=3D%d", rel->size, rel->packet_id, id, ret); + dmsg(D_REL_DEBUG, "ACK RWBS rel->size=3D%d rel->packet_id=3D%08x id=3D= %08x ret=3D%d", rel->size, + rel->packet_id, id, ret); return ret; } @@ -631,9 +627,7 @@ } } (void)n_active; /* dmsg might not generate code */ - dmsg(D_REL_DEBUG, "ACK reliable_can_send active=3D%d current=3D%d : %s= ", - n_active, - n_current, + dmsg(D_REL_DEBUG, "ACK reliable_can_send active=3D%d current=3D%d : %s= ", n_active, n_current, reliable_print_ids(rel, &gc)); gc_free(&gc); @@ -654,8 +648,7 @@ /* If N_ACK_RETRANSMIT later packets have received ACKs, we assume * that the packet was lost and resend it even if the timeout has * not expired yet. */ - if (e->active - && (e->n_acks >=3D N_ACK_RETRANSMIT || local_now >=3D e->next_= try)) + if (e->active && (e->n_acks >=3D N_ACK_RETRANSMIT || local_now >= =3D e->next_try)) { if (!best || reliable_pid_min(e->packet_id, best->packet_id)) { @@ -721,9 +714,7 @@ } } - dmsg(D_REL_DEBUG, "ACK reliable_send_timeout %d %s", - (int) ret, - reliable_print_ids(rel, &gc)); + dmsg(D_REL_DEBUG, "ACK reliable_send_timeout %d %s", (int)ret, reliabl= e_print_ids(rel, &gc)); gc_free(&gc); return ret; @@ -734,8 +725,8 @@ */ void -reliable_mark_active_incoming(struct reliable *rel, struct buffer *buf, - packet_id_type pid, int opcode) +reliable_mark_active_incoming(struct reliable *rel, struct buffer *buf, pa= cket_id_type pid, + int opcode) { for (int i =3D 0; i < rel->size; ++i) { @@ -754,11 +745,12 @@ e->next_try =3D 0; e->timeout =3D 0; e->n_acks =3D 0; - dmsg(D_REL_DEBUG, "ACK mark active incoming ID " packet_id_for= mat, (packet_id_print_type)e->packet_id); + dmsg(D_REL_DEBUG, "ACK mark active incoming ID " packet_id_for= mat, + (packet_id_print_type)e->packet_id); return; } } - ASSERT(0); /* buf not found in rel */ + ASSERT(0); /* buf not found in rel */ } /* @@ -783,11 +775,12 @@ e->opcode =3D opcode; e->next_try =3D 0; e->timeout =3D rel->initial_timeout; - dmsg(D_REL_DEBUG, "ACK mark active outgoing ID " packet_id_for= mat, (packet_id_print_type)e->packet_id); + dmsg(D_REL_DEBUG, "ACK mark active outgoing ID " packet_id_for= mat, + (packet_id_print_type)e->packet_id); return; } } - ASSERT(0); /* buf not found in rel */ + ASSERT(0); /* buf not found in rel */ } /* delete a buffer previously activated by reliable_mark_active() */ diff --git a/src/openvpn/reliable.h b/src/openvpn/reliable.h index 2cbff01..ecaec8d 100644 --- a/src/openvpn/reliable.h +++ b/src/openvpn/reliable.h @@ -41,18 +41,21 @@ * @{ */ -#define RELIABLE_ACK_SIZE 8 /**< The maximum number of packet IDs - * waiting to be acknowledged which can - * be stored in one \c reliable_ack - * structure. */ +#define RELIABLE_ACK_SIZE \ + 8 /**< The maximum number of packet IDs \ + * waiting to be acknowledged which can \ + * be stored in one \c reliable_ack \ + * structure. */ -#define RELIABLE_CAPACITY 12 /**< The maximum number of packets that - * the reliability layer for one VPN - * tunnel in one direction can store. */ +#define RELIABLE_CAPACITY \ + 12 /**< The maximum number of packets that \ + * the reliability layer for one VPN \ + * tunnel in one direction can store. */ -#define N_ACK_RETRANSMIT 3 /**< We retry sending a packet early if - * this many later packets have been - * ACKed. */ +#define N_ACK_RETRANSMIT \ + 3 /**< We retry sending a packet early if \ + * this many later packets have been \ + * ACKed. */ /** * The acknowledgment structure in which packet IDs are stored for later @@ -77,9 +80,9 @@ interval_t timeout; time_t next_try; packet_id_type packet_id; - size_t n_acks; /* Number of acks received for packets with higher PID. - * Used for fast retransmission when there were at lea= st - * N_ACK_RETRANSMIT. */ + size_t n_acks; /* Number of acks received for packets with higher PID. + * Used for fast retransmission when there were at least + * N_ACK_RETRANSMIT. */ int opcode; struct buffer buf; }; @@ -94,7 +97,7 @@ interval_t initial_timeout; packet_id_type packet_id; int offset; /**< Offset of the bufs in the reliable_entry array */ - bool hold; /* don't xmit until reliable_schedule_now is called */ + bool hold; /* don't xmit until reliable_schedule_now is called */ struct reliable_entry array[RELIABLE_CAPACITY]; }; @@ -121,8 +124,7 @@ * @li True, if processing was successful. * @li False, if an error occurs during processing. */ -bool reliable_ack_read(struct reliable_ack *ack, - struct buffer *buf, const struct session_id *sid); +bool reliable_ack_read(struct reliable_ack *ack, struct buffer *buf, const= struct session_id *sid); /** @@ -142,9 +144,8 @@ * @li True, if processing was successful. * @li False, if an error occurs during processing. */ -bool -reliable_ack_parse(struct buffer *buf, struct reliable_ack *ack, - struct session_id *session_id_remote); +bool reliable_ack_parse(struct buffer *buf, struct reliable_ack *ack, + struct session_id *session_id_remote); /** * Remove acknowledged packets from a reliable structure. @@ -213,9 +214,7 @@ * @li True, if processing was successful. * @li False, if an error occurs during processing. */ -bool reliable_ack_write(struct reliable_ack *ack, - struct reliable_ack *ack_mru, - struct buffer *buf, +bool reliable_ack_write(struct reliable_ack *ack, struct reliable_ack *ack= _mru, struct buffer *buf, const struct session_id *sid, int max, bool prepen= d); /** @} name Functions for processing outgoing acknowledgments */ @@ -338,8 +337,8 @@ * @param pid The packet's packet ID. * @param opcode The packet's opcode. */ -void reliable_mark_active_incoming(struct reliable *rel, struct buffer *bu= f, - packet_id_type pid, int opcode); +void reliable_mark_active_incoming(struct reliable *rel, struct buffer *bu= f, packet_id_type pid, + int opcode); /** * Record a packet ID for later acknowledgment. @@ -375,7 +374,6 @@ struct reliable_entry *reliable_get_entry_sequenced(struct reliable *rel); =20 - /** * Copies the first n acks from \c ack to \c ack_mru * @@ -383,8 +381,7 @@ * @param ack_mru The reliable structure to insert the acks into * @param n The number of ACKS to copy */ -void -copy_acks_to_mru(struct reliable_ack *ack, struct reliable_ack *ack_mru, i= nt n); +void copy_acks_to_mru(struct reliable_ack *ack, struct reliable_ack *ack_m= ru, int n); =20 /** @@ -427,8 +424,7 @@ * @return the number of buffer that are available for sending without * breaking ack sequence * */ -int -reliable_get_num_output_sequenced_available(struct reliable *rel); +int reliable_get_num_output_sequenced_available(struct reliable *rel); /** * Mark the reliable entry associated with the given buffer as diff --git a/src/openvpn/ring_buffer.h b/src/openvpn/ring_buffer.h new file mode 100644 index 0000000..e554296 --- /dev/null +++ b/src/openvpn/ring_buffer.h @@ -0,0 +1,124 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2002-2024 OpenVPN Inc + * 2019 Lev Stipakov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifdef _WIN32 +#ifndef OPENVPN_RING_BUFFER_H +#define OPENVPN_RING_BUFFER_H + +#include +#include + +#include +#include + +/* + * Values below are taken from Wireguard Windows client + * https://github.com/WireGuard/wireguard-go/blob/master/tun/wintun/ring_w= indows.go#L14 + */ +#define WINTUN_RING_CAPACITY 0x800000 +#define WINTUN_RING_TRAILING_BYTES 0x10000 +#define WINTUN_MAX_PACKET_SIZE 0xffff +#define WINTUN_PACKET_ALIGN 4 + +#define TUN_IOCTL_REGISTER_RINGS \ + CTL_CODE(51820U, 0x970U, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_= DATA) + +/** + * Wintun ring buffer + * See https://github.com/WireGuard/wintun#ring-layout + */ +struct tun_ring +{ + volatile ULONG head; + volatile ULONG tail; + volatile LONG alertable; + UCHAR data[WINTUN_RING_CAPACITY + WINTUN_RING_TRAILING_BYTES]; +}; + +/** + * Struct for ring buffers registration + * See https://github.com/WireGuard/wintun#registering-rings + */ +struct tun_register_rings +{ + struct + { + ULONG ring_size; + struct tun_ring *ring; + HANDLE tail_moved; + } send, receive; +}; + +struct TUN_PACKET_HEADER +{ + uint32_t size; +}; + +struct TUN_PACKET +{ + uint32_t size; + UCHAR data[WINTUN_MAX_PACKET_SIZE]; +}; + +/** + * Registers ring buffers used to exchange data between + * userspace openvpn process and wintun kernel driver, + * see https://github.com/WireGuard/wintun#registering-rings + * + * @param device handle to opened wintun device + * @param send_ring pointer to send ring + * @param receive_ring pointer to receive ring + * @param send_tail_moved event set by wintun to signal openvpn + * that data is available for reading in send r= ing + * @param receive_tail_moved event set by openvpn to signal wintun + * that data has been written to receive ring + * @return true if registration is successful, false ot= herwise - use + * GetLastError() + */ +static inline bool +register_ring_buffers(HANDLE device, struct tun_ring *send_ring, struct tu= n_ring *receive_ring, + HANDLE send_tail_moved, HANDLE receive_tail_moved) +{ + struct tun_register_rings rr; + BOOL res; + DWORD bytes_returned; + + ZeroMemory(&rr, sizeof(rr)); + + rr.send.ring =3D send_ring; + rr.send.ring_size =3D sizeof(struct tun_ring); + rr.send.tail_moved =3D send_tail_moved; + + rr.receive.ring =3D receive_ring; + rr.receive.ring_size =3D sizeof(struct tun_ring); + rr.receive.tail_moved =3D receive_tail_moved; + + res =3D DeviceIoControl(device, TUN_IOCTL_REGISTER_RINGS, &rr, sizeof(= rr), NULL, 0, + &bytes_returned, NULL); + + return res !=3D FALSE; +} + +#endif /* ifndef OPENVPN_RING_BUFFER_H */ +#endif /* ifdef _WIN32 */ diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 156262a..ff76ffe 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -47,11 +47,11 @@ #include "memdbg.h" #if defined(TARGET_LINUX) || defined(TARGET_ANDROID) -#include /* RTM_GETROUTE etc. */ +#include /* RTM_GETROUTE etc. */ #endif #if defined(TARGET_NETBSD) -#include /* RT_ROUNDUP(), RT_ADVANCE() */ +#include /* RT_ROUNDUP(), RT_ADVANCE() */ #endif #ifdef _WIN32 @@ -68,7 +68,8 @@ static int route_ipv6_ipapi(bool add, const struct route_ipv6 *, const str= uct tuntap *); -static int add_route_ipapi(const struct route_ipv4 *r, const struct tuntap= *tt, DWORD adapter_index); +static int add_route_ipapi(const struct route_ipv4 *r, const struct tuntap= *tt, + DWORD adapter_index); static bool del_route_ipapi(const struct route_ipv4 *r, const struct tunta= p *tt); @@ -90,9 +91,7 @@ int i; for (i =3D 0; i < rb->n_bypass; ++i) { - msg(D_ROUTE, "ROUTE: bypass_host_route[%d]=3D%s", - i, - print_in_addr_t(rb->bypass[i], 0, &gc)); + msg(D_ROUTE, "ROUTE: bypass_host_route[%d]=3D%s", i, print_in_addr= _t(rb->bypass[i], 0, &gc)); } gc_free(&gc); } @@ -100,9 +99,9 @@ #endif /* Route addition return status codes */ -#define RTA_ERROR 0 /* route addition failed */ -#define RTA_SUCCESS 1 /* route addition succeeded */ -#define RTA_EEXIST 2 /* route not added as it already exists */ +#define RTA_ERROR 0 /* route addition failed */ +#define RTA_SUCCESS 1 /* route addition succeeded */ +#define RTA_EEXIST 2 /* route not added as it already exists */ static bool add_bypass_address(struct route_bypass *rb, const in_addr_t a) @@ -170,7 +169,8 @@ } void -copy_route_option_list(struct route_option_list *dest, const struct route_= option_list *src, struct gc_arena *a) +copy_route_option_list(struct route_option_list *dest, const struct route_= option_list *src, + struct gc_arena *a) { *dest =3D *src; dest->gc =3D a; @@ -178,8 +178,7 @@ void copy_route_ipv6_option_list(struct route_ipv6_option_list *dest, - const struct route_ipv6_option_list *src, - struct gc_arena *a) + const struct route_ipv6_option_list *src, stru= ct gc_arena *a) { *dest =3D *src; dest->gc =3D a; @@ -189,11 +188,8 @@ route_string(const struct route_ipv4 *r, struct gc_arena *gc) { struct buffer out =3D alloc_buf_gc(256, gc); - buf_printf(&out, "ROUTE network %s netmask %s gateway %s", - print_in_addr_t(r->network, 0, gc), - print_in_addr_t(r->netmask, 0, gc), - print_in_addr_t(r->gateway, 0, gc) - ); + buf_printf(&out, "ROUTE network %s netmask %s gateway %s", print_in_ad= dr_t(r->network, 0, gc), + print_in_addr_t(r->netmask, 0, gc), print_in_addr_t(r->gate= way, 0, gc)); if (r->flags & RT_METRIC_DEFINED) { buf_printf(&out, " metric %d", r->metric); @@ -233,10 +229,7 @@ } static bool -get_special_addr(const struct route_list *rl, - const char *string, - in_addr_t *out, - bool *status) +get_special_addr(const struct route_list *rl, const char *string, in_addr_= t *out, bool *status) { if (status) { @@ -271,7 +264,8 @@ } else { - msg(M_INFO, PACKAGE_NAME " ROUTE: net_gateway undefined --= unable to get default gateway from system"); + msg(M_INFO, PACKAGE_NAME + " ROUTE: net_gateway undefined -- unable to get defaul= t gateway from system"); if (status) { *status =3D false; @@ -316,15 +310,13 @@ } static bool -init_route(struct route_ipv4 *r, - struct addrinfo **network_list, - const struct route_option *ro, +init_route(struct route_ipv4 *r, struct addrinfo **network_list, const str= uct route_option *ro, const struct route_list *rl) { const in_addr_t default_netmask =3D IPV4_NETMASK_HOST; bool status; int ret; - struct in_addr special =3D {0}; + struct in_addr special =3D { 0 }; CLEAR(*r); r->option =3D ro; @@ -338,7 +330,7 @@ /* get_special_addr replaces specialaddr with a special ip addr * like gw. getaddrinfo is called to convert a a addrinfo struct */ - if (get_special_addr(rl, ro->network, (in_addr_t *) &special.s_addr, &= status)) + if (get_special_addr(rl, ro->network, (in_addr_t *)&special.s_addr, &s= tatus)) { if (!status) { @@ -347,13 +339,12 @@ special.s_addr =3D htonl(special.s_addr); char buf[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &special, buf, sizeof(buf)); - ret =3D openvpn_getaddrinfo(0, buf, NULL, 0, NULL, - AF_INET, network_list); + ret =3D openvpn_getaddrinfo(0, buf, NULL, 0, NULL, AF_INET, networ= k_list); } else { - ret =3D openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_WARN_ON_SIGN= AL, - ro->network, NULL, 0, NULL, AF_INET, net= work_list); + ret =3D openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_WARN_ON_SIGN= AL, ro->network, NULL, 0, + NULL, AF_INET, network_list); } status =3D (ret =3D=3D 0); @@ -367,13 +358,8 @@ if (is_route_parm_defined(ro->netmask)) { - r->netmask =3D getaddr( - GETADDR_HOST_ORDER - | GETADDR_WARN_ON_SIGNAL, - ro->netmask, - 0, - &status, - NULL); + r->netmask =3D + getaddr(GETADDR_HOST_ORDER | GETADDR_WARN_ON_SIGNAL, ro->netma= sk, 0, &status, NULL); if (!status) { goto fail; @@ -390,14 +376,8 @@ { if (!get_special_addr(rl, ro->gateway, &r->gateway, &status)) { - r->gateway =3D getaddr( - GETADDR_RESOLVE - | GETADDR_HOST_ORDER - | GETADDR_WARN_ON_SIGNAL, - ro->gateway, - 0, - &status, - NULL); + r->gateway =3D getaddr(GETADDR_RESOLVE | GETADDR_HOST_ORDER | = GETADDR_WARN_ON_SIGNAL, + ro->gateway, 0, &status, NULL); } if (!status) { @@ -412,7 +392,9 @@ } else { - msg(M_WARN, PACKAGE_NAME " ROUTE: " PACKAGE_NAME " needs a gat= eway parameter for a --route option and no default was specified by either = --route-gateway or --ifconfig options"); + msg(M_WARN, PACKAGE_NAME + " ROUTE: " PACKAGE_NAME + " needs a gateway parameter for a --route option and no de= fault was specified by either --route-gateway or --ifconfig options"); goto fail; } } @@ -426,8 +408,7 @@ if (r->metric < 0) { msg(M_WARN, PACKAGE_NAME " ROUTE: route metric for network %s = (%s) must be >=3D 0", - ro->network, - ro->metric); + ro->network, ro->metric); goto fail; } r->flags |=3D RT_METRIC_DEFINED; @@ -452,13 +433,12 @@ } static bool -init_route_ipv6(struct route_ipv6 *r6, - const struct route_ipv6_option *r6o, - const struct route_ipv6_list *rl6 ) +init_route_ipv6(struct route_ipv6 *r6, const struct route_ipv6_option *r6o, + const struct route_ipv6_list *rl6) { CLEAR(*r6); - if (!get_ipv6_addr( r6o->prefix, &r6->network, &r6->netbits, M_WARN )) + if (!get_ipv6_addr(r6o->prefix, &r6->network, &r6->netbits, M_WARN)) { goto fail; } @@ -466,9 +446,9 @@ /* gateway */ if (is_route_parm_defined(r6o->gateway)) { - if (inet_pton( AF_INET6, r6o->gateway, &r6->gateway ) !=3D 1) + if (inet_pton(AF_INET6, r6o->gateway, &r6->gateway) !=3D 1) { - msg( M_WARN, PACKAGE_NAME "ROUTE6: cannot parse gateway spec '= %s'", r6o->gateway ); + msg(M_WARN, PACKAGE_NAME "ROUTE6: cannot parse gateway spec '%= s'", r6o->gateway); } } else if (rl6->spec_flags & RTSA_REMOTE_ENDPOINT) @@ -485,8 +465,7 @@ if (r6->metric < 0) { msg(M_WARN, PACKAGE_NAME " ROUTE: route metric for network %s = (%s) must be >=3D 0", - r6o->prefix, - r6o->metric); + r6o->prefix, r6o->metric); goto fail; } r6->flags |=3D RT_METRIC_DEFINED; @@ -511,12 +490,8 @@ } 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) +add_route_to_option_list(struct route_option_list *l, const char *network,= const char *netmask, + const char *gateway, const char *metric, int tabl= e_id) { struct route_option *ro; ALLOC_OBJ_GC(ro, struct route_option, l->gc); @@ -527,15 +502,11 @@ ro->table_id =3D table_id; ro->next =3D l->routes; l->routes =3D ro; - } 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) +add_route_ipv6_to_option_list(struct route_ipv6_option_list *l, const char= *prefix, + const char *gateway, const char *metric, int= table_id) { struct route_ipv6_option *ro; ALLOC_OBJ_GC(ro, struct route_ipv6_option, l->gc); @@ -562,9 +533,7 @@ } void -route_list_add_vpn_gateway(struct route_list *rl, - struct env_set *es, - const in_addr_t addr) +route_list_add_vpn_gateway(struct route_list *rl, struct env_set *es, cons= t in_addr_t addr) { ASSERT(rl); rl->spec.remote_endpoint =3D addr; @@ -573,8 +542,7 @@ } static void -add_block_local_item(struct route_list *rl, - const struct route_gateway_address *gateway, +add_block_local_item(struct route_list *rl, const struct route_gateway_add= ress *gateway, in_addr_t target) { if (rl->rgi.gateway.netmask < 0xFFFFFFFF) @@ -586,11 +554,11 @@ ALLOC_OBJ_GC(r2, struct route_ipv4, &rl->gc); /* split a route into two smaller blocking routes, and direct them= to target */ - l2 =3D ((~gateway->netmask)+1)>>1; + l2 =3D ((~gateway->netmask) + 1) >> 1; r1->flags =3D RT_DEFINED; r1->gateway =3D target; r1->network =3D gateway->addr & gateway->netmask; - r1->netmask =3D ~(l2-1); + r1->netmask =3D ~(l2 - 1); r1->next =3D rl->routes; rl->routes =3D r1; @@ -628,21 +596,15 @@ bool block_local_needed(const struct route_list *rl) { - const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED); - return (rl->flags & RG_BLOCK_LOCAL) - && (rl->rgi.flags & rgi_needed) =3D=3D rgi_needed - && (rl->spec.flags & RTSA_REMOTE_ENDPOINT) - && rl->spec.remote_host_local !=3D TLA_LOCAL; + const int rgi_needed =3D (RGI_ADDR_DEFINED | RGI_NETMASK_DEFINED); + return (rl->flags & RG_BLOCK_LOCAL) && (rl->rgi.flags & rgi_needed) = =3D=3D rgi_needed + && (rl->spec.flags & RTSA_REMOTE_ENDPOINT) && rl->spec.remote_h= ost_local !=3D TLA_LOCAL; } bool -init_route_list(struct route_list *rl, - const struct route_option_list *opt, - const char *remote_endpoint, - int default_metric, - in_addr_t remote_host, - struct env_set *es, - openvpn_net_ctx_t *ctx) +init_route_list(struct route_list *rl, const struct route_option_list *opt, + const char *remote_endpoint, int default_metric, in_addr_t= remote_host, + struct env_set *es, openvpn_net_ctx_t *ctx) { struct gc_arena gc =3D gc_new(); bool ret =3D true; @@ -684,14 +646,9 @@ if (is_route_parm_defined(remote_endpoint)) { bool defined =3D false; - rl->spec.remote_endpoint =3D getaddr( - GETADDR_RESOLVE - | GETADDR_HOST_ORDER - | GETADDR_WARN_ON_SIGNAL, - remote_endpoint, - 0, - &defined, - NULL); + rl->spec.remote_endpoint =3D + getaddr(GETADDR_RESOLVE | GETADDR_HOST_ORDER | GETADDR_WARN_ON= _SIGNAL, remote_endpoint, + 0, &defined, NULL); if (defined) { @@ -759,14 +716,13 @@ * "good enough") */ static bool -route_ipv6_match_host( const struct route_ipv6 *r6, - const struct in6_addr *host ) +route_ipv6_match_host(const struct route_ipv6 *r6, const struct in6_addr *= host) { unsigned int bits =3D r6->netbits; int i; unsigned int mask; - if (bits>128) + if (bits > 128) { return false; } @@ -784,9 +740,9 @@ return true; } - mask =3D 0xff << (8-bits); + mask =3D 0xff << (8 - bits); - if ( (r6->network.s6_addr[i] & mask) =3D=3D (host->s6_addr[i] & mask )) + if ((r6->network.s6_addr[i] & mask) =3D=3D (host->s6_addr[i] & mask)) { return true; } @@ -795,12 +751,9 @@ } bool -init_route_ipv6_list(struct route_ipv6_list *rl6, - const struct route_ipv6_option_list *opt6, - const char *remote_endpoint, - int default_metric, - const struct in6_addr *remote_host_ipv6, - struct env_set *es, +init_route_ipv6_list(struct route_ipv6_list *rl6, const struct route_ipv6_= option_list *opt6, + const char *remote_endpoint, int default_metric, + const struct in6_addr *remote_host_ipv6, struct env_s= et *es, openvpn_net_ctx_t *ctx) { struct gc_arena gc =3D gc_new(); @@ -824,7 +777,7 @@ } msg(D_ROUTE, "GDG6: remote_host_ipv6=3D%s", - remote_host_ipv6 ? print_in6_addr(*remote_host_ipv6, 0, &gc) : "n= /a" ); + remote_host_ipv6 ? print_in6_addr(*remote_host_ipv6, 0, &gc) : "n/= a"); get_default_gateway_ipv6(&rl6->rgi6, remote_host_ipv6, ctx); if (rl6->rgi6.flags & RGI_ADDR_DEFINED) @@ -839,16 +792,16 @@ dmsg(D_ROUTE, "ROUTE6: default_gateway=3DUNDEF"); } - if (is_route_parm_defined( remote_endpoint )) + if (is_route_parm_defined(remote_endpoint)) { - if (inet_pton( AF_INET6, remote_endpoint, - &rl6->remote_endpoint_ipv6) =3D=3D 1) + if (inet_pton(AF_INET6, remote_endpoint, &rl6->remote_endpoint_ipv= 6) =3D=3D 1) { rl6->spec_flags |=3D RTSA_REMOTE_ENDPOINT; } else { - msg(M_WARN, PACKAGE_NAME " ROUTE: failed to parse/resolve VPN = endpoint: %s", remote_endpoint); + msg(M_WARN, PACKAGE_NAME " ROUTE: failed to parse/resolve VPN = endpoint: %s", + remote_endpoint); ret =3D false; } } @@ -878,11 +831,11 @@ * avoiding routing loops, so ignore this part and let * need_remote_ipv6_route always evaluate to false */ - if (remote_host_ipv6 - && route_ipv6_match_host( r6, remote_host_ipv6 ) ) + if (remote_host_ipv6 && route_ipv6_match_host(r6, remote_h= ost_ipv6)) { need_remote_ipv6_route =3D true; - msg(D_ROUTE, "ROUTE6: %s/%d overlaps IPv6 remote %s, a= dding host route to VPN endpoint", + msg(D_ROUTE, + "ROUTE6: %s/%d overlaps IPv6 remote %s, adding hos= t route to VPN endpoint", print_in6_addr(r6->network, 0, &gc), r6->netbits, print_in6_addr(*remote_host_ipv6, 0, &gc)); } @@ -894,15 +847,15 @@ /* add VPN server host route if needed */ if (need_remote_ipv6_route) { - if ( (rl6->rgi6.flags & (RGI_ADDR_DEFINED|RGI_IFACE_DEFINED) ) =3D= =3D - (RGI_ADDR_DEFINED|RGI_IFACE_DEFINED) ) + if ((rl6->rgi6.flags & (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED)) + =3D=3D (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED)) { struct route_ipv6 *r6; ALLOC_OBJ_CLEAR_GC(r6, struct route_ipv6, &rl6->gc); r6->network =3D *remote_host_ipv6; r6->netbits =3D 128; - if (!(rl6->rgi6.flags & RGI_ON_LINK) ) + if (!(rl6->rgi6.flags & RGI_ON_LINK)) { r6->gateway =3D rl6->rgi6.gateway.addr_ipv6; } @@ -919,7 +872,8 @@ } else { - msg(M_WARN, "ROUTE6: IPv6 route overlaps with IPv6 remote addr= ess, but could not determine IPv6 gateway address + interface, expect failu= re\n" ); + msg(M_WARN, + "ROUTE6: IPv6 route overlaps with IPv6 remote address, but= could not determine IPv6 gateway address + interface, expect failure\n"); } } @@ -928,13 +882,8 @@ } static bool -add_route3(in_addr_t network, - in_addr_t netmask, - in_addr_t gateway, - const struct tuntap *tt, - unsigned int flags, - const struct route_gateway_info *rgi, - const struct env_set *es, +add_route3(in_addr_t network, in_addr_t netmask, in_addr_t gateway, const = struct tuntap *tt, + unsigned int flags, const struct route_gateway_info *rgi, const= struct env_set *es, openvpn_net_ctx_t *ctx) { struct route_ipv4 r; @@ -947,18 +896,13 @@ } static void -del_route3(in_addr_t network, - in_addr_t netmask, - in_addr_t gateway, - const struct tuntap *tt, - unsigned int flags, - const struct route_gateway_info *rgi, - const struct env_set *es, +del_route3(in_addr_t network, in_addr_t netmask, in_addr_t gateway, const = struct tuntap *tt, + unsigned int flags, const struct route_gateway_info *rgi, const= struct env_set *es, openvpn_net_ctx_t *ctx) { struct route_ipv4 r; CLEAR(r); - r.flags =3D RT_DEFINED|RT_ADDED; + r.flags =3D RT_DEFINED | RT_ADDED; r.network =3D network; r.netmask =3D netmask; r.gateway =3D gateway; @@ -966,56 +910,42 @@ } static bool -add_bypass_routes(struct route_bypass *rb, - in_addr_t gateway, - const struct tuntap *tt, - unsigned int flags, - const struct route_gateway_info *rgi, - const struct env_set *es, - openvpn_net_ctx_t *ctx) +add_bypass_routes(struct route_bypass *rb, in_addr_t gateway, const struct= tuntap *tt, + unsigned int flags, const struct route_gateway_info *rgi, + const struct env_set *es, openvpn_net_ctx_t *ctx) { int ret =3D true; for (int i =3D 0; i < rb->n_bypass; ++i) { if (rb->bypass[i]) { - ret =3D add_route3(rb->bypass[i], IPV4_NETMASK_HOST, gateway, = tt, - flags | ROUTE_REF_GW, rgi, es, ctx) && ret; + ret =3D add_route3(rb->bypass[i], IPV4_NETMASK_HOST, gateway, = tt, flags | ROUTE_REF_GW, + rgi, es, ctx) + && ret; } } return ret; } static void -del_bypass_routes(struct route_bypass *rb, - in_addr_t gateway, - const struct tuntap *tt, - unsigned int flags, - const struct route_gateway_info *rgi, - const struct env_set *es, - openvpn_net_ctx_t *ctx) +del_bypass_routes(struct route_bypass *rb, in_addr_t gateway, const struct= tuntap *tt, + unsigned int flags, const struct route_gateway_info *rgi, + const struct env_set *es, openvpn_net_ctx_t *ctx) { int i; for (i =3D 0; i < rb->n_bypass; ++i) { if (rb->bypass[i]) { - del_route3(rb->bypass[i], - IPV4_NETMASK_HOST, - gateway, - tt, - flags | ROUTE_REF_GW, - rgi, - es, + del_route3(rb->bypass[i], IPV4_NETMASK_HOST, gateway, tt, flag= s | ROUTE_REF_GW, rgi, es, ctx); } } } static bool -redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *= tt, - unsigned int flags, const struct env_set *es, - openvpn_net_ctx_t *ctx) +redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *= tt, unsigned int flags, + const struct env_set *es, openvpn_net_ctx_t = *ctx) { const char err[] =3D "NOTE: unable to redirect IPv4 default gateway --= "; bool ret =3D true; @@ -1065,9 +995,8 @@ if ((rl->spec.flags & RTSA_REMOTE_HOST) && rl->spec.remote_host !=3D IPV4_INVALID_ADDR) { - ret =3D add_route3(rl->spec.remote_host, IPV4_NETMASK_= HOST, - rl->rgi.gateway.addr, tt, flags | ROU= TE_REF_GW, - &rl->rgi, es, ctx); + ret =3D add_route3(rl->spec.remote_host, IPV4_NETMASK_= HOST, rl->rgi.gateway.addr, + tt, flags | ROUTE_REF_GW, &rl->rgi, e= s, ctx); if (ret) { rl->iflags |=3D RL_DID_LOCAL; @@ -1081,20 +1010,23 @@ #endif /* ifndef TARGET_ANDROID */ /* route DHCP/DNS server traffic through original default gate= way */ - ret =3D add_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.ad= dr, tt, flags, - &rl->rgi, es, ctx) && ret; + ret =3D add_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.ad= dr, tt, flags, &rl->rgi, es, + ctx) + && ret; if (rl->flags & RG_REROUTE_GW) { if (rl->flags & RG_DEF1) { /* add new default route (1st component) */ - ret =3D add_route3(0x00000000, 0x80000000, rl->spec.re= mote_endpoint, - tt, flags, &rl->rgi, es, ctx) && ret; + ret =3D add_route3(0x00000000, 0x80000000, rl->spec.re= mote_endpoint, tt, flags, + &rl->rgi, es, ctx) + && ret; /* add new default route (2nd component) */ - ret =3D add_route3(0x80000000, 0x80000000, rl->spec.re= mote_endpoint, - tt, flags, &rl->rgi, es, ctx) && ret; + ret =3D add_route3(0x80000000, 0x80000000, rl->spec.re= mote_endpoint, tt, flags, + &rl->rgi, es, ctx) + && ret; } else { @@ -1102,13 +1034,13 @@ if (rl->rgi.flags & RGI_ADDR_DEFINED) { /* delete default route */ - del_route3(0, 0, rl->rgi.gateway.addr, tt, - flags | ROUTE_REF_GW, &rl->rgi, es, ctx= ); + del_route3(0, 0, rl->rgi.gateway.addr, tt, flags |= ROUTE_REF_GW, &rl->rgi, + es, ctx); } /* add new default route */ - ret =3D add_route3(0, 0, rl->spec.remote_endpoint, tt, - flags, &rl->rgi, es, ctx) && ret; + ret =3D add_route3(0, 0, rl->spec.remote_endpoint, tt,= flags, &rl->rgi, es, ctx) + && ret; } } @@ -1120,9 +1052,8 @@ } static void -undo_redirect_default_route_to_vpn(struct route_list *rl, - const struct tuntap *tt, unsigned int f= lags, - const struct env_set *es, +undo_redirect_default_route_to_vpn(struct route_list *rl, const struct tun= tap *tt, + unsigned int flags, const struct env_se= t *es, openvpn_net_ctx_t *ctx) { if (rl && rl->iflags & RL_DID_REDIRECT_DEFAULT_GATEWAY) @@ -1130,61 +1061,35 @@ /* delete remote host route */ if (rl->iflags & RL_DID_LOCAL) { - del_route3(rl->spec.remote_host, - IPV4_NETMASK_HOST, - rl->rgi.gateway.addr, - tt, - flags | ROUTE_REF_GW, - &rl->rgi, - es, - ctx); + del_route3(rl->spec.remote_host, IPV4_NETMASK_HOST, rl->rgi.ga= teway.addr, tt, + flags | ROUTE_REF_GW, &rl->rgi, es, ctx); rl->iflags &=3D ~RL_DID_LOCAL; } /* delete special DHCP/DNS bypass route */ - del_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.addr, tt, flag= s, - &rl->rgi, es, ctx); + del_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.addr, tt, flag= s, &rl->rgi, es, ctx); if (rl->flags & RG_REROUTE_GW) { if (rl->flags & RG_DEF1) { /* delete default route (1st component) */ - del_route3(0x00000000, - 0x80000000, - rl->spec.remote_endpoint, - tt, - flags, - &rl->rgi, - es, - ctx); + del_route3(0x00000000, 0x80000000, rl->spec.remote_endpoin= t, tt, flags, &rl->rgi, + es, ctx); /* delete default route (2nd component) */ - del_route3(0x80000000, - 0x80000000, - rl->spec.remote_endpoint, - tt, - flags, - &rl->rgi, - es, - ctx); + del_route3(0x80000000, 0x80000000, rl->spec.remote_endpoin= t, tt, flags, &rl->rgi, + es, ctx); } else { /* delete default route */ - del_route3(0, - 0, - rl->spec.remote_endpoint, - tt, - flags, - &rl->rgi, - es, - ctx); + del_route3(0, 0, rl->spec.remote_endpoint, tt, flags, &rl-= >rgi, es, ctx); /* restore original default route if there was any */ if (rl->rgi.flags & RGI_ADDR_DEFINED) { - add_route3(0, 0, rl->rgi.gateway.addr, tt, - flags | ROUTE_REF_GW, &rl->rgi, es, ctx); + add_route3(0, 0, rl->rgi.gateway.addr, tt, flags | ROU= TE_REF_GW, &rl->rgi, es, + ctx); } } } @@ -1194,32 +1099,28 @@ } bool -add_routes(struct route_list *rl, struct route_ipv6_list *rl6, - const struct tuntap *tt, unsigned int flags, - const struct env_set *es, openvpn_net_ctx_t *ctx) +add_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struc= t tuntap *tt, + unsigned int flags, const struct env_set *es, openvpn_net_ctx_t= *ctx) { bool ret =3D redirect_default_route_to_vpn(rl, tt, flags, es, ctx); - if (rl && !(rl->iflags & RL_ROUTES_ADDED) ) + if (rl && !(rl->iflags & RL_ROUTES_ADDED)) { struct route_ipv4 *r; if (rl->routes && !tt->did_ifconfig_setup) { - msg(M_INFO, "WARNING: OpenVPN was configured to add an IPv4 " + msg(M_INFO, + "WARNING: OpenVPN was configured to add an IPv4 " "route. However, no IPv4 has been configured for %s, " "therefore the route installation may fail or may not work= " - "as expected.", tt->actual_name); + "as expected.", + tt->actual_name); } #ifdef ENABLE_MANAGEMENT if (management && rl->routes) { - management_set_state(management, - OPENVPN_STATE_ADD_ROUTES, - NULL, - NULL, - NULL, - NULL, + management_set_state(management, OPENVPN_STATE_ADD_ROUTES, NUL= L, NULL, NULL, NULL, NULL); } #endif @@ -1234,16 +1135,18 @@ } rl->iflags |=3D RL_ROUTES_ADDED; } - if (rl6 && !(rl6->iflags & RL_ROUTES_ADDED) ) + if (rl6 && !(rl6->iflags & RL_ROUTES_ADDED)) { struct route_ipv6 *r; if (!tt->did_ifconfig_ipv6_setup) { - msg(M_INFO, "WARNING: OpenVPN was configured to add an IPv6 " + msg(M_INFO, + "WARNING: OpenVPN was configured to add an IPv6 " "route. However, no IPv6 has been configured for %s, " "therefore the route installation may fail or may not work= " - "as expected.", tt->actual_name); + "as expected.", + tt->actual_name); } for (r =3D rl6->routes_ipv6; r; r =3D r->next) @@ -1261,9 +1164,8 @@ } void -delete_routes(struct route_list *rl, struct route_ipv6_list *rl6, - const struct tuntap *tt, unsigned int flags, - const struct env_set *es, openvpn_net_ctx_t *ctx) +delete_routes(struct route_list *rl, struct route_ipv6_list *rl6, const st= ruct tuntap *tt, + unsigned int flags, const struct env_set *es, openvpn_net_ct= x_t *ctx) { if (rl && rl->iflags & RL_ROUTES_ADDED) { @@ -1282,7 +1184,7 @@ clear_route_list(rl); } - if (rl6 && (rl6->iflags & RL_ROUTES_ADDED) ) + if (rl6 && (rl6->iflags & RL_ROUTES_ADDED)) { struct route_ipv6 *r6; for (r6 =3D rl6->routes_ipv6; r6; r6 =3D r6->next) @@ -1316,22 +1218,17 @@ static void print_route_option(const struct route_option *ro, int level) { - msg(level, " route %s/%s/%s/%s", - show_opt(ro->network), - show_opt(ro->netmask), - show_opt(ro->gateway), - show_opt(ro->metric)); + msg(level, " route %s/%s/%s/%s", show_opt(ro->network), show_opt(ro->= netmask), + show_opt(ro->gateway), show_opt(ro->metric)); } void -print_route_options(const struct route_option_list *rol, - int level) +print_route_options(const struct route_option_list *rol, int level) { struct route_option *ro; if (rol->flags & RG_ENABLE) { - msg(level, " [redirect_default_gateway local=3D%d]", - (rol->flags & RG_LOCAL) !=3D 0); + msg(level, " [redirect_default_gateway local=3D%d]", (rol->flags = & RG_LOCAL) !=3D 0); } for (ro =3D rol->routes; ro; ro =3D ro->next) { @@ -1340,8 +1237,7 @@ } void -print_default_gateway(const int msglevel, - const struct route_gateway_info *rgi, +print_default_gateway(const int msglevel, const struct route_gateway_info = *rgi, const struct route_ipv6_gateway_info *rgi6) { struct gc_arena gc =3D gc_new(); @@ -1472,23 +1368,22 @@ struct gc_arena gc =3D gc_new(); if (r6->flags & RT_DEFINED) { - struct buffer name1 =3D alloc_buf_gc( 256, &gc ); - struct buffer val =3D alloc_buf_gc( 256, &gc ); - struct buffer name2 =3D alloc_buf_gc( 256, &gc ); + struct buffer name1 =3D alloc_buf_gc(256, &gc); + struct buffer val =3D alloc_buf_gc(256, &gc); + struct buffer name2 =3D alloc_buf_gc(256, &gc); - buf_printf( &name1, "route_ipv6_network_%d", i ); - buf_printf( &val, "%s/%d", print_in6_addr( r6->network, 0, &gc ), - r6->netbits ); - setenv_str( es, BSTR(&name1), BSTR(&val) ); + buf_printf(&name1, "route_ipv6_network_%d", i); + buf_printf(&val, "%s/%d", print_in6_addr(r6->network, 0, &gc), r6-= >netbits); + setenv_str(es, BSTR(&name1), BSTR(&val)); - buf_printf( &name2, "route_ipv6_gateway_%d", i ); - setenv_str( es, BSTR(&name2), print_in6_addr( r6->gateway, 0, &gc = )); + buf_printf(&name2, "route_ipv6_gateway_%d", i); + setenv_str(es, BSTR(&name2), print_in6_addr(r6->gateway, 0, &gc)); if (r6->flags & RT_METRIC_DEFINED) { - struct buffer name3 =3D alloc_buf_gc( 256, &gc ); - buf_printf( &name3, "route_ipv6_metric_%d", i); - setenv_int( es, BSTR(&name3), r6->metric); + struct buffer name3 =3D alloc_buf_gc(256, &gc); + buf_printf(&name3, "route_ipv6_metric_%d", i); + setenv_int(es, BSTR(&name3), r6->metric); } } gc_free(&gc); @@ -1528,19 +1423,15 @@ #define LR_ERROR 2 /* caller should abort adding route */ static int -local_route(in_addr_t network, - in_addr_t netmask, - in_addr_t gateway, +local_route(in_addr_t network, in_addr_t netmask, in_addr_t gateway, const struct route_gateway_info *rgi) { /* set LR_MATCH on local host routes */ - const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED|RGI_IFA= CE_DEFINED); - if (rgi - && (rgi->flags & rgi_needed) =3D=3D rgi_needed - && gateway =3D=3D rgi->gateway.addr + const int rgi_needed =3D (RGI_ADDR_DEFINED | RGI_NETMASK_DEFINED | RGI= _IFACE_DEFINED); + if (rgi && (rgi->flags & rgi_needed) =3D=3D rgi_needed && gateway =3D= =3D rgi->gateway.addr && netmask =3D=3D 0xFFFFFFFF) { - if (((network ^ rgi->gateway.addr) & rgi->gateway.netmask) =3D=3D= 0) + if (((network ^ rgi->gateway.addr) & rgi->gateway.netmask) =3D=3D = 0) { return LR_MATCH; } @@ -1567,17 +1458,16 @@ static inline bool is_on_link(const int is_local_route, const unsigned int flags, const struc= t route_gateway_info *rgi) { - return rgi && (is_local_route =3D=3D LR_MATCH || ((flags & ROUTE_REF_G= W) && (rgi->flags & RGI_ON_LINK))); + return rgi + && (is_local_route =3D=3D LR_MATCH + || ((flags & ROUTE_REF_GW) && (rgi->flags & RGI_ON_LINK))); } #endif bool -add_route(struct route_ipv4 *r, - const struct tuntap *tt, - unsigned int flags, - const struct route_gateway_info *rgi, /* may be NULL */ - const struct env_set *es, - openvpn_net_ctx_t *ctx) +add_route(struct route_ipv4 *r, const struct tuntap *tt, unsigned int flag= s, + const struct route_gateway_info *rgi, /* may be NULL */ + const struct env_set *es, openvpn_net_ctx_t *ctx) { int status =3D 0; int is_local_route; @@ -1620,8 +1510,8 @@ status =3D RTA_SUCCESS; - int ret =3D net_route_v4_add(ctx, &r->network, netmask_to_netbits2(r->= netmask), - &r->gateway, iface, r->table_id, metric); + int ret =3D net_route_v4_add(ctx, &r->network, netmask_to_netbits2(r->= netmask), &r->gateway, + iface, r->table_id, metric); if (ret =3D=3D -EEXIST) { msg(D_ROUTE, "NOTE: Linux route add command failed because route e= xists"); @@ -1633,7 +1523,7 @@ status =3D RTA_ERROR; } -#elif defined (TARGET_ANDROID) +#elif defined(TARGET_ANDROID) char out[128]; if (rgi) @@ -1647,15 +1537,11 @@ bool ret =3D management_android_control(management, "ROUTE", out); status =3D ret ? RTA_SUCCESS : RTA_ERROR; -#elif defined (_WIN32) +#elif defined(_WIN32) { DWORD ai =3D TUN_ADAPTER_INDEX_INVALID; - argv_printf(&argv, "%s%s ADD %s MASK %s %s", - get_win_sys_path(), - WIN_ROUTE_PATH_SUFFIX, - network, - netmask, - gateway); + argv_printf(&argv, "%s%s ADD %s MASK %s %s", get_win_sys_path(), W= IN_ROUTE_PATH_SUFFIX, + network, netmask, gateway); if (r->flags & RT_METRIC_DEFINED) { argv_printf_cat(&argv, "METRIC %d", r->metric); @@ -1681,8 +1567,8 @@ else if ((flags & ROUTE_METHOD_MASK) =3D=3D ROUTE_METHOD_EXE) { netcmd_semaphore_lock(); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: Windows route add comm= and failed"); + bool ret =3D + openvpn_execve_check(&argv, es, 0, "ERROR: Windows route a= dd command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; netcmd_semaphore_release(); method =3D "route.exe"; @@ -1695,8 +1581,8 @@ { msg(D_ROUTE, "Route addition fallback to route.exe"); netcmd_semaphore_lock(); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: Windows route add = command failed [adaptive]"); + bool ret =3D openvpn_execve_check( + &argv, es, 0, "ERROR: Windows route add command failed= [adaptive]"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; netcmd_semaphore_release(); method =3D "route.exe"; @@ -1713,17 +1599,13 @@ } } -#elif defined (TARGET_SOLARIS) +#elif defined(TARGET_SOLARIS) /* example: route add 192.0.2.32 -netmask 255.255.255.224 somegateway = */ - argv_printf(&argv, "%s add", - ROUTE_PATH); + argv_printf(&argv, "%s add", ROUTE_PATH); - argv_printf_cat(&argv, "%s -netmask %s %s", - network, - netmask, - gateway); + argv_printf_cat(&argv, "%s -netmask %s %s", network, netmask, gateway); /* Solaris can only distinguish between "metric 0" =3D=3D "on-link on = the * interface where the IP address given is configured" and "metric > 0" @@ -1738,14 +1620,12 @@ } argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: Solaris route add command fail= ed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: Solaris route = add command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_FREEBSD) - argv_printf(&argv, "%s add", - ROUTE_PATH); + argv_printf(&argv, "%s add", ROUTE_PATH); #if 0 if (r->flags & RT_METRIC_DEFINED) @@ -1754,22 +1634,17 @@ } #endif - argv_printf_cat(&argv, "-net %s %s %s", - network, - gateway, - netmask); + argv_printf_cat(&argv, "-net %s %s %s", network, gateway, netmask); /* FIXME -- add on-link support for FreeBSD */ argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: FreeBSD route add command fail= ed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: FreeBSD route = add command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_DRAGONFLY) - argv_printf(&argv, "%s add", - ROUTE_PATH); + argv_printf(&argv, "%s add", ROUTE_PATH); #if 0 if (r->flags & RT_METRIC_DEFINED) @@ -1778,22 +1653,17 @@ } #endif - argv_printf_cat(&argv, "-net %s %s %s", - network, - gateway, - netmask); + argv_printf_cat(&argv, "-net %s %s %s", network, gateway, netmask); /* FIXME -- add on-link support for Dragonfly */ argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: DragonFly route add command fa= iled"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: DragonFly rout= e add command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_DARWIN) - argv_printf(&argv, "%s add", - ROUTE_PATH); + argv_printf(&argv, "%s add", ROUTE_PATH); #if 0 if (r->flags & RT_METRIC_DEFINED) @@ -1806,28 +1676,21 @@ { /* Mac OS X route syntax for ON_LINK: * route add -cloning -net 10.10.0.1 -netmask 255.255.255.255 -int= erface en0 */ - argv_printf_cat(&argv, "-cloning -net %s -netmask %s -interface %s= ", - network, - netmask, + argv_printf_cat(&argv, "-cloning -net %s -netmask %s -interface %s= ", network, netmask, rgi->iface); } else { - argv_printf_cat(&argv, "-net %s %s %s", - network, - gateway, - netmask); + argv_printf_cat(&argv, "-net %s %s %s", network, gateway, netmask); } argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: OS X route add command failed"= ); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: OS X route add= command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) - argv_printf(&argv, "%s add", - ROUTE_PATH); + argv_printf(&argv, "%s add", ROUTE_PATH); #if 0 if (r->flags & RT_METRIC_DEFINED) @@ -1836,47 +1699,36 @@ } #endif - argv_printf_cat(&argv, "-net %s %s -netmask %s", - network, - gateway, - netmask); + argv_printf_cat(&argv, "-net %s %s -netmask %s", network, gateway, net= mask); /* FIXME -- add on-link support for OpenBSD/NetBSD */ argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: OpenBSD/NetBSD route add comma= nd failed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: OpenBSD/NetBSD= route add command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_AIX) { int netbits =3D netmask_to_netbits2(r->netmask); - argv_printf(&argv, "%s add -net %s/%d %s", - ROUTE_PATH, - network, netbits, gateway); + argv_printf(&argv, "%s add -net %s/%d %s", ROUTE_PATH, network, ne= tbits, gateway); argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: AIX route add command fail= ed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: AIX route = add command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; } #elif defined(TARGET_HAIKU) /* ex: route add /dev/net/ipro1000/0 0.0.0.0 gw 192.168.1.1 netmask 12= 8.0.0.0 */ - argv_printf(&argv, "%s add %s inet %s gw %s netmask %s", - ROUTE_PATH, - rgi->iface, - network, - gateway, - netmask); + argv_printf(&argv, "%s add %s inet %s gw %s netmask %s", ROUTE_PATH, r= gi->iface, network, + gateway, netmask); argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: Haiku inet route add command f= ailed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: Haiku inet rou= te add command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; -#else /* if defined(TARGET_LINUX) */ - msg(M_FATAL, "Sorry, but I don't know how to do 'route' commands on th= is operating system. Try putting your routes in a --route-up script"); +#else /* if defined(TARGET_LINUX) */ + msg(M_FATAL, + "Sorry, but I don't know how to do 'route' commands on this operat= ing system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ done: @@ -1898,7 +1750,7 @@ void -route_ipv6_clear_host_bits( struct route_ipv6 *r6 ) +route_ipv6_clear_host_bits(struct route_ipv6 *r6) { /* clear host bit parts of route * (needed if routes are specified improperly, or if we need to @@ -1911,24 +1763,25 @@ { if (bits_to_clear >=3D 8) { - r6->network.s6_addr[byte--] =3D 0; bits_to_clear -=3D 8; + r6->network.s6_addr[byte--] =3D 0; + bits_to_clear -=3D 8; } else { - r6->network.s6_addr[byte--] &=3D (0xff << bits_to_clear); bits= _to_clear =3D 0; + r6->network.s6_addr[byte--] &=3D (0xff << bits_to_clear); + bits_to_clear =3D 0; } } } bool -add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, - unsigned int flags, const struct env_set *es, - openvpn_net_ctx_t *ctx) +add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned in= t flags, + const struct env_set *es, openvpn_net_ctx_t *ctx) { int status =3D 0; bool gateway_needed =3D false; - if (!(r6->flags & RT_DEFINED) ) + if (!(r6->flags & RT_DEFINED)) { return true; /* no error */ } @@ -1938,10 +1791,10 @@ #ifndef _WIN32 const char *device =3D tt->actual_name; - if (r6->iface !=3D NULL) /* vpn server special route */ + if (r6->iface !=3D NULL) /* vpn server special route */ { device =3D r6->iface; - if (!IN6_IS_ADDR_UNSPECIFIED(&r6->gateway) ) + if (!IN6_IS_ADDR_UNSPECIFIED(&r6->gateway)) { gateway_needed =3D true; } @@ -1949,11 +1802,10 @@ #endif route_ipv6_clear_host_bits(r6); - const char *network =3D print_in6_addr( r6->network, 0, &gc); - const char *gateway =3D print_in6_addr( r6->gateway, 0, &gc); + const char *network =3D print_in6_addr(r6->network, 0, &gc); + const char *gateway =3D print_in6_addr(r6->gateway, 0, &gc); -#if defined(TARGET_DARWIN) \ - || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ +#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_DR= AGONFLY) \ || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) /* the BSD platforms cannot specify gateway and interface independentl= y, @@ -1961,22 +1813,21 @@ * we build a combined "$gateway%$interface" gateway string */ if (r6->iface !=3D NULL && gateway_needed - && IN6_IS_ADDR_LINKLOCAL(&r6->gateway) ) /* fe80::...%intf = */ + && IN6_IS_ADDR_LINKLOCAL(&r6->gateway)) /* fe80::...%intf */ { - int len =3D strlen(gateway) + 1 + strlen(r6->iface)+1; - char *tmp =3D gc_malloc( len, true, &gc ); - snprintf( tmp, len, "%s%%%s", gateway, r6->iface ); + int len =3D strlen(gateway) + 1 + strlen(r6->iface) + 1; + char *tmp =3D gc_malloc(len, true, &gc); + snprintf(tmp, len, "%s%%%s", gateway, r6->iface); gateway =3D tmp; } #endif #ifndef _WIN32 - msg(D_ROUTE, "add_route_ipv6(%s/%d -> %s metric %d) dev %s", - network, r6->netbits, gateway, r6->metric, device ); + msg(D_ROUTE, "add_route_ipv6(%s/%d -> %s metric %d) dev %s", network, = r6->netbits, gateway, + r6->metric, device); #else - msg(D_ROUTE, "add_route_ipv6(%s/%d -> %s metric %d) IF %lu", - network, r6->netbits, gateway, r6->metric, - r6->adapter_index ? r6->adapter_index : tt->adapter_index); + msg(D_ROUTE, "add_route_ipv6(%s/%d -> %s metric %d) IF %lu", network, = r6->netbits, gateway, + r6->metric, r6->adapter_index ? r6->adapter_index : tt->adapter_in= dex); #endif /* @@ -1990,18 +1841,19 @@ * interfaces. OTOH, on "tap" interface, we must always set the * gateway unless the route is to be an on-link network */ - if (tt->type =3D=3D DEV_TYPE_TAP - && !( (r6->flags & RT_METRIC_DEFINED) && r6->metric =3D=3D 0 ) ) + if (tt->type =3D=3D DEV_TYPE_TAP && !((r6->flags & RT_METRIC_DEFINED) = && r6->metric =3D=3D 0)) { gateway_needed =3D true; } if (gateway_needed && IN6_IS_ADDR_UNSPECIFIED(&r6->gateway)) { - msg(M_WARN, "ROUTE6 WARNING: " PACKAGE_NAME " needs a gateway " + msg(M_WARN, + "ROUTE6 WARNING: " PACKAGE_NAME " needs a gateway " "parameter for a --route-ipv6 option and no default was set vi= a " "--ifconfig-ipv6 or --route-ipv6-gateway option. Not installi= ng " - "IPv6 route to %s/%d.", network, r6->netbits); + "IPv6 route to %s/%d.", + network, r6->netbits); status =3D 0; goto done; } @@ -2014,8 +1866,7 @@ } status =3D RTA_SUCCESS; - int ret =3D net_route_v6_add(ctx, &r6->network, r6->netbits, - gateway_needed ? &r6->gateway : NULL, + int ret =3D net_route_v6_add(ctx, &r6->network, r6->netbits, gateway_n= eeded ? &r6->gateway : NULL, device, r6->table_id, metric); if (ret =3D=3D -EEXIST) { @@ -2028,14 +1879,14 @@ status =3D RTA_ERROR; } -#elif defined (TARGET_ANDROID) +#elif defined(TARGET_ANDROID) char out[64]; snprintf(out, sizeof(out), "%s/%d %s", network, r6->netbits, device); status =3D management_android_control(management, "ROUTE6", out); -#elif defined (_WIN32) +#elif defined(_WIN32) if (tt->options.msg_channel) { @@ -2045,7 +1896,7 @@ { status =3D route_ipv6_ipapi(true, r6, tt); } -#elif defined (TARGET_SOLARIS) +#elif defined(TARGET_SOLARIS) /* example: route add -inet6 2001:db8::/32 somegateway 0 */ @@ -2058,11 +1909,7 @@ * use the GW addresses - it seems to still work for fe80:: addresses, * however this is done internally. NUD maybe?) */ - argv_printf(&argv, "%s add -inet6 %s/%d %s", - ROUTE_PATH, - network, - r6->netbits, - gateway ); + argv_printf(&argv, "%s add -inet6 %s/%d %s", ROUTE_PATH, network, r6->= netbits, gateway); /* on tun (not tap), not "elsewhere"? -> metric 0 */ if (tt->type =3D=3D DEV_TYPE_TUN && !r6->iface) @@ -2071,16 +1918,12 @@ } argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: Solaris route add -inet6 comma= nd failed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: Solaris route = add -inet6 command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) - argv_printf(&argv, "%s add -inet6 %s/%d", - ROUTE_PATH, - network, - r6->netbits); + argv_printf(&argv, "%s add -inet6 %s/%d", ROUTE_PATH, network, r6->net= bits); =20 if (gateway_needed) { @@ -2092,15 +1935,12 @@ } argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: *BSD route add -inet6 command = failed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: *BSD route add= -inet6 command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_DARWIN) - argv_printf(&argv, "%s add -inet6 %s -prefixlen %d", - ROUTE_PATH, - network, r6->netbits ); + argv_printf(&argv, "%s add -inet6 %s -prefixlen %d", ROUTE_PATH, netwo= rk, r6->netbits); if (gateway_needed) { @@ -2112,58 +1952,45 @@ } argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: MacOS X route add -inet6 comma= nd failed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: MacOS X route = add -inet6 command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_OPENBSD) - argv_printf(&argv, "%s add -inet6 %s -prefixlen %d %s", - ROUTE_PATH, - network, r6->netbits, gateway ); + argv_printf(&argv, "%s add -inet6 %s -prefixlen %d %s", ROUTE_PATH, ne= twork, r6->netbits, + gateway); argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: OpenBSD route add -inet6 comma= nd failed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: OpenBSD route = add -inet6 command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_NETBSD) - argv_printf(&argv, "%s add -inet6 %s/%d %s", - ROUTE_PATH, - network, r6->netbits, gateway ); + argv_printf(&argv, "%s add -inet6 %s/%d %s", ROUTE_PATH, network, r6->= netbits, gateway); argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: NetBSD route add -inet6 comman= d failed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: NetBSD route a= dd -inet6 command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_AIX) - argv_printf(&argv, "%s add -inet6 %s/%d %s", - ROUTE_PATH, - network, r6->netbits, gateway); + argv_printf(&argv, "%s add -inet6 %s/%d %s", ROUTE_PATH, network, r6->= netbits, gateway); argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: AIX route add command failed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: AIX route add = command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #elif defined(TARGET_HAIKU) /* ex: route add /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixlen = 64 */ - argv_printf(&argv, "%s add %s inet6 %s gw %s prefixlen %d", - ROUTE_PATH, - r6->iface, - network, - gateway, - r6->netbits); + argv_printf(&argv, "%s add %s inet6 %s gw %s prefixlen %d", ROUTE_PATH= , r6->iface, network, + gateway, r6->netbits); argv_msg(D_ROUTE, &argv); - bool ret =3D openvpn_execve_check(&argv, es, 0, - "ERROR: Haiku inet6 route add command = failed"); + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: Haiku inet6 ro= ute add command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; #else /* if defined(TARGET_LINUX) */ - msg(M_FATAL, "Sorry, but I don't know how to do 'route ipv6' commands = on this operating system. Try putting your routes in a --route-up script"); + msg(M_FATAL, + "Sorry, but I don't know how to do 'route ipv6' commands on this o= perating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ done: @@ -2184,12 +2011,8 @@ } static void -delete_route(struct route_ipv4 *r, - const struct tuntap *tt, - unsigned int flags, - const struct route_gateway_info *rgi, - const struct env_set *es, - openvpn_net_ctx_t *ctx) +delete_route(struct route_ipv4 *r, const struct tuntap *tt, unsigned int f= lags, + const struct route_gateway_info *rgi, const struct env_set *e= s, openvpn_net_ctx_t *ctx) { #if !defined(TARGET_LINUX) const char *network; @@ -2199,12 +2022,12 @@ #if !defined(TARGET_ANDROID) const char *gateway; #endif -#else /* if !defined(TARGET_LINUX) */ +#else /* if !defined(TARGET_LINUX) */ int metric; #endif int is_local_route; - if ((r->flags & (RT_DEFINED|RT_ADDED)) !=3D (RT_DEFINED|RT_ADDED)) + if ((r->flags & (RT_DEFINED | RT_ADDED)) !=3D (RT_DEFINED | RT_ADDED)) { return; } @@ -2235,19 +2058,16 @@ metric =3D r->metric; } - if (net_route_v4_del(ctx, &r->network, netmask_to_netbits2(r->netmask), - &r->gateway, NULL, r->table_id, metric) < 0) + if (net_route_v4_del(ctx, &r->network, netmask_to_netbits2(r->netmask)= , &r->gateway, NULL, + r->table_id, metric) + < 0) { msg(M_WARN, "ERROR: Linux route delete command failed"); } -#elif defined (_WIN32) +#elif defined(_WIN32) - argv_printf(&argv, "%s%s DELETE %s MASK %s %s", - get_win_sys_path(), - WIN_ROUTE_PATH_SUFFIX, - network, - netmask, - gateway); + argv_printf(&argv, "%s%s DELETE %s MASK %s %s", get_win_sys_path(), WI= N_ROUTE_PATH_SUFFIX, + network, netmask, gateway); argv_msg(D_ROUTE, &argv); @@ -2275,7 +2095,8 @@ { msg(D_ROUTE, "Route deletion fallback to route.exe"); netcmd_semaphore_lock(); - openvpn_execve_check(&argv, es, 0, "ERROR: Windows route delet= e command failed [adaptive]"); + openvpn_execve_check(&argv, es, 0, + "ERROR: Windows route delete command fail= ed [adaptive]"); netcmd_semaphore_release(); } } @@ -2284,35 +2105,23 @@ ASSERT(0); } -#elif defined (TARGET_SOLARIS) +#elif defined(TARGET_SOLARIS) - argv_printf(&argv, "%s delete %s -netmask %s %s", - ROUTE_PATH, - network, - netmask, - gateway); + argv_printf(&argv, "%s delete %s -netmask %s %s", ROUTE_PATH, network,= netmask, gateway); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: Solaris route delete comman= d failed"); #elif defined(TARGET_FREEBSD) - argv_printf(&argv, "%s delete -net %s %s %s", - ROUTE_PATH, - network, - gateway, - netmask); + argv_printf(&argv, "%s delete -net %s %s %s", ROUTE_PATH, network, gat= eway, netmask); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: FreeBSD route delete comman= d failed"); #elif defined(TARGET_DRAGONFLY) - argv_printf(&argv, "%s delete -net %s %s %s", - ROUTE_PATH, - network, - gateway, - netmask); + argv_printf(&argv, "%s delete -net %s %s %s", ROUTE_PATH, network, gat= eway, netmask); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: DragonFly route delete comm= and failed"); @@ -2321,19 +2130,12 @@ if (is_on_link(is_local_route, flags, rgi)) { - argv_printf(&argv, "%s delete -cloning -net %s -netmask %s -interf= ace %s", - ROUTE_PATH, - network, - netmask, - rgi->iface); + argv_printf(&argv, "%s delete -cloning -net %s -netmask %s -interf= ace %s", ROUTE_PATH, + network, netmask, rgi->iface); } else { - argv_printf(&argv, "%s delete -net %s %s %s", - ROUTE_PATH, - network, - gateway, - netmask); + argv_printf(&argv, "%s delete -net %s %s %s", ROUTE_PATH, network,= gateway, netmask); } argv_msg(D_ROUTE, &argv); @@ -2341,26 +2143,20 @@ #elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) - argv_printf(&argv, "%s delete -net %s %s -netmask %s", - ROUTE_PATH, - network, - gateway, - netmask); + argv_printf(&argv, "%s delete -net %s %s -netmask %s", ROUTE_PATH, net= work, gateway, netmask); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: OpenBSD/NetBSD route delete= command failed"); #elif defined(TARGET_ANDROID) msg(D_ROUTE_DEBUG, "Deleting routes on Android is not possible/not " - "needed. The VpnService API allows routes to be set " - "on connect only and will clean up automatically."); + "needed. The VpnService API allows routes to be set= " + "on connect only and will clean up automatically."); #elif defined(TARGET_AIX) { int netbits =3D netmask_to_netbits2(r->netmask); - argv_printf(&argv, "%s delete -net %s/%d %s", - ROUTE_PATH, - network, netbits, gateway); + argv_printf(&argv, "%s delete -net %s/%d %s", ROUTE_PATH, network,= netbits, gateway); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: AIX route delete comman= d failed"); } @@ -2368,17 +2164,14 @@ #elif defined(TARGET_HAIKU) /* ex: route delete /dev/net/ipro1000/0 inet 192.168.0.0 gw 192.168.1.= 1 netmask 255.255.0.0 */ - argv_printf(&argv, "%s delete %s inet %s gw %s netmask %s", - ROUTE_PATH, - rgi->iface, - network, - gateway, - netmask); + argv_printf(&argv, "%s delete %s inet %s gw %s netmask %s", ROUTE_PATH= , rgi->iface, network, + gateway, netmask); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: Haiku inet route delete com= mand failed"); #else /* if defined(TARGET_LINUX) */ - msg(M_FATAL, "Sorry, but I don't know how to do 'route' commands on th= is operating system. Try putting your routes in a --route-up script"); + msg(M_FATAL, + "Sorry, but I don't know how to do 'route' commands on this operat= ing system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ done: @@ -2390,13 +2183,12 @@ } void -delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, - const struct env_set *es, +delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, co= nst struct env_set *es, openvpn_net_ctx_t *ctx) { const char *network; - if ((r6->flags & (RT_DEFINED|RT_ADDED)) !=3D (RT_DEFINED|RT_ADDED)) + if ((r6->flags & (RT_DEFINED | RT_ADDED)) !=3D (RT_DEFINED | RT_ADDED)) { return; } @@ -2408,7 +2200,7 @@ #if !defined(TARGET_SOLARIS) bool gateway_needed =3D false; const char *device =3D tt->actual_name; - if (r6->iface !=3D NULL) /* vpn server special route */ + if (r6->iface !=3D NULL) /* vpn server special route */ { device =3D r6->iface; gateway_needed =3D true; @@ -2417,8 +2209,7 @@ /* if we used a gateway on "add route", we also need to specify it on * delete, otherwise some OSes will refuse to delete the route */ - if (tt->type =3D=3D DEV_TYPE_TAP - && !( (r6->flags & RT_METRIC_DEFINED) && r6->metric =3D=3D 0 ) ) + if (tt->type =3D=3D DEV_TYPE_TAP && !((r6->flags & RT_METRIC_DEFINED) = && r6->metric =3D=3D 0)) { gateway_needed =3D true; } @@ -2428,13 +2219,12 @@ struct gc_arena gc =3D gc_new(); struct argv argv =3D argv_new(); - network =3D print_in6_addr( r6->network, 0, &gc); + network =3D print_in6_addr(r6->network, 0, &gc); #if !defined(TARGET_LINUX) && !defined(_WIN32) - gateway =3D print_in6_addr( r6->gateway, 0, &gc); + gateway =3D print_in6_addr(r6->gateway, 0, &gc); #endif -#if defined(TARGET_DARWIN) \ - || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ +#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_DR= AGONFLY) \ || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) /* the BSD platforms cannot specify gateway and interface independentl= y, @@ -2442,16 +2232,16 @@ * we build a combined "$gateway%$interface" gateway string */ if (r6->iface !=3D NULL && gateway_needed - && IN6_IS_ADDR_LINKLOCAL(&r6->gateway) ) /* fe80::...%intf = */ + && IN6_IS_ADDR_LINKLOCAL(&r6->gateway)) /* fe80::...%intf */ { - int len =3D strlen(gateway) + 1 + strlen(r6->iface)+1; - char *tmp =3D gc_malloc( len, true, &gc ); - snprintf( tmp, len, "%s%%%s", gateway, r6->iface ); + int len =3D strlen(gateway) + 1 + strlen(r6->iface) + 1; + char *tmp =3D gc_malloc(len, true, &gc); + snprintf(tmp, len, "%s%%%s", gateway, r6->iface); gateway =3D tmp; } #endif - msg(D_ROUTE, "delete_route_ipv6(%s/%d)", network, r6->netbits ); + msg(D_ROUTE, "delete_route_ipv6(%s/%d)", network, r6->netbits); #if defined(TARGET_LINUX) int metric =3D -1; @@ -2460,14 +2250,14 @@ metric =3D r6->metric; } - if (net_route_v6_del(ctx, &r6->network, r6->netbits, - gateway_needed ? &r6->gateway : NULL, device, r6-= >table_id, - metric) < 0) + if (net_route_v6_del(ctx, &r6->network, r6->netbits, gateway_needed ? = &r6->gateway : NULL, + device, r6->table_id, metric) + < 0) { msg(M_WARN, "ERROR: Linux route v6 delete command failed"); } -#elif defined (_WIN32) +#elif defined(_WIN32) if (tt->options.msg_channel) { @@ -2477,25 +2267,18 @@ { route_ipv6_ipapi(false, r6, tt); } -#elif defined (TARGET_SOLARIS) +#elif defined(TARGET_SOLARIS) /* example: route delete -inet6 2001:db8::/32 somegateway */ - argv_printf(&argv, "%s delete -inet6 %s/%d %s", - ROUTE_PATH, - network, - r6->netbits, - gateway ); + argv_printf(&argv, "%s delete -inet6 %s/%d %s", ROUTE_PATH, network, r= 6->netbits, gateway); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: Solaris route delete -inet6= command failed"); #elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) - argv_printf(&argv, "%s delete -inet6 %s/%d", - ROUTE_PATH, - network, - r6->netbits ); + argv_printf(&argv, "%s delete -inet6 %s/%d", ROUTE_PATH, network, r6->= netbits); if (gateway_needed) { @@ -2511,9 +2294,7 @@ #elif defined(TARGET_DARWIN) - argv_printf(&argv, "%s delete -inet6 %s -prefixlen %d", - ROUTE_PATH, - network, r6->netbits ); + argv_printf(&argv, "%s delete -inet6 %s -prefixlen %d", ROUTE_PATH, ne= twork, r6->netbits); if (gateway_needed) { @@ -2529,48 +2310,40 @@ #elif defined(TARGET_OPENBSD) - argv_printf(&argv, "%s delete -inet6 %s -prefixlen %d %s", - ROUTE_PATH, - network, r6->netbits, gateway ); + argv_printf(&argv, "%s delete -inet6 %s -prefixlen %d %s", ROUTE_PATH,= network, r6->netbits, + gateway); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: OpenBSD route delete -inet6= command failed"); #elif defined(TARGET_NETBSD) - argv_printf(&argv, "%s delete -inet6 %s/%d %s", - ROUTE_PATH, - network, r6->netbits, gateway ); + argv_printf(&argv, "%s delete -inet6 %s/%d %s", ROUTE_PATH, network, r= 6->netbits, gateway); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: NetBSD route delete -inet6 = command failed"); #elif defined(TARGET_AIX) - argv_printf(&argv, "%s delete -inet6 %s/%d %s", - ROUTE_PATH, - network, r6->netbits, gateway); + argv_printf(&argv, "%s delete -inet6 %s/%d %s", ROUTE_PATH, network, r= 6->netbits, gateway); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: AIX route add command faile= d"); #elif defined(TARGET_ANDROID) msg(D_ROUTE_DEBUG, "Deleting routes on Android is not possible/not " - "needed. The VpnService API allows routes to be set " - "on connect only and will clean up automatically."); + "needed. The VpnService API allows routes to be set= " + "on connect only and will clean up automatically."); #elif defined(TARGET_HAIKU) /* ex: route delete /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixl= en 64 */ - argv_printf(&argv, "%s delete %s inet6 %s gw %s prefixlen %d", - ROUTE_PATH, - r6->iface, - network, - gateway, - r6->netbits); + argv_printf(&argv, "%s delete %s inet6 %s gw %s prefixlen %d", ROUTE_P= ATH, r6->iface, network, + gateway, r6->netbits); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: Haiku inet6 route delete co= mmand failed"); #else /* if defined(TARGET_LINUX) */ - msg(M_FATAL, "Sorry, but I don't know how to do 'route ipv6' commands = on this operating system. Try putting your routes in a --route-down script= "); + msg(M_FATAL, + "Sorry, but I don't know how to do 'route ipv6' commands on this o= perating system. Try putting your routes in a --route-down script"); #endif /* if defined(TARGET_LINUX) */ argv_free(&argv); @@ -2596,13 +2369,12 @@ status =3D GetIpForwardTable(NULL, &size, TRUE); if (status =3D=3D ERROR_INSUFFICIENT_BUFFER) { - rt =3D (PMIB_IPFORWARDTABLE) gc_malloc(size, false, gc); + rt =3D (PMIB_IPFORWARDTABLE)gc_malloc(size, false, gc); status =3D GetIpForwardTable(rt, &size, TRUE); if (status !=3D NO_ERROR) { msg(D_ROUTE, "NOTE: GetIpForwardTable returned error: %s (code= =3D%u)", - strerror_win32(status, gc), - (unsigned int)status); + strerror_win32(status, gc), (unsigned int)status); rt =3D NULL; } } @@ -2610,9 +2382,7 @@ } static int -test_route(const IP_ADAPTER_INFO *adapters, - const in_addr_t gateway, - DWORD *index) +test_route(const IP_ADAPTER_INFO *adapters, const in_addr_t gateway, DWORD= *index) { int count =3D 0; DWORD i =3D adapter_index_of_ip(adapters, gateway, &count, NULL); @@ -2624,11 +2394,7 @@ } static void -test_route_helper(bool *ret, - int *count, - int *good, - int *ambig, - const IP_ADAPTER_INFO *adapters, +test_route_helper(bool *ret, int *count, int *good, int *ambig, const IP_A= DAPTER_INFO *adapters, const in_addr_t gateway) { int c; @@ -2688,13 +2454,8 @@ } } - msg(D_ROUTE, "TEST ROUTES: %d/%d succeeded len=3D%d ret=3D%d a=3D%d u/= d=3D%s", - good, - count, - len, - (int)ret, - ambig, - adapter_up ? "up" : "down"); + msg(D_ROUTE, "TEST ROUTES: %d/%d succeeded len=3D%d ret=3D%d a=3D%d u/= d=3D%s", good, count, len, + (int)ret, ambig, adapter_up ? "up" : "down"); gc_free(&gc); return ret; @@ -2718,12 +2479,9 @@ const DWORD index =3D row->dwForwardIfIndex; const DWORD metric =3D row->dwForwardMetric1; - dmsg(D_ROUTE_DEBUG, "GDGR: route[%lu] %s/%s i=3D%d m=3D%d", - i, - print_in_addr_t((in_addr_t) net, 0, &gc), - print_in_addr_t((in_addr_t) mask, 0, &gc), - (int)index, - (int)metric); + dmsg(D_ROUTE_DEBUG, "GDGR: route[%lu] %s/%s i=3D%d m=3D%d", i, + print_in_addr_t((in_addr_t)net, 0, &gc), print_in_addr_t(= (in_addr_t)mask, 0, &gc), + (int)index, (int)metric); if (!net && !mask && metric < lowest_metric) { @@ -2764,8 +2522,7 @@ if (status !=3D NO_ERROR) { msg(D_ROUTE, "NOTE: GetBestInterfaceEx returned error: %s (code=3D= %u)", - strerror_win32(status, gc), - (unsigned int)status); + strerror_win32(status, gc), (unsigned int)status); goto done; } @@ -2776,13 +2533,11 @@ CLEAR(luid); SOCKADDR_INET best_src; CLEAR(best_src); - status =3D GetBestRoute2(&luid, best_if_index, NULL, - dest, 0, best_route, &best_src); + status =3D GetBestRoute2(&luid, best_if_index, NULL, dest, 0, best_rou= te, &best_src); if (status !=3D NO_ERROR) { msg(D_ROUTE, "NOTE: GetIpForwardEntry2 returned error: %s (code=3D= %u)", - strerror_win32(status, gc), - (unsigned int)status); + strerror_win32(status, gc), (unsigned int)status); goto done; } @@ -2873,13 +2628,10 @@ else if (count > 1) { msg(M_WARN, "Warning: route gateway is ambiguous: %s (%d matches)", - print_in_addr_t(r->gateway, 0, &gc), - count); + print_in_addr_t(r->gateway, 0, &gc), count); } - dmsg(D_ROUTE_DEBUG, "DEBUG: route find if: on_tun=3D%d count=3D%d inde= x=3D%d", - on_tun, - count, + dmsg(D_ROUTE_DEBUG, "DEBUG: route find if: on_tun=3D%d count=3D%d inde= x=3D%d", on_tun, count, (int)ret); gc_free(&gc); @@ -2892,8 +2644,8 @@ * https://msdn.microsoft.com/en-us/library/windows/desktop/aa814411(v=3Dv= s.85).aspx */ void -get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, - const struct in6_addr *dest, openvpn_net_ctx_t *c= tx) +get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struc= t in6_addr *dest, + openvpn_net_ctx_t *ctx) { struct gc_arena gc =3D gc_new(); CLEAR(*rgi6); @@ -2915,23 +2667,19 @@ goto done; } - msg( D_ROUTE, "GDG6: II=3D%lu DP=3D%s/%d NH=3D%s", - BestRoute.InterfaceIndex, - print_in6_addr( BestRoute.DestinationPrefix.Prefix.Ipv6.sin6_addr= , 0, &gc), - BestRoute.DestinationPrefix.PrefixLength, - print_in6_addr( BestRoute.NextHop.Ipv6.sin6_addr, 0, &gc) ); - msg( D_ROUTE, "GDG6: Metric=3D%d, Loopback=3D%d, AA=3D%d, I=3D%d", - (int) BestRoute.Metric, - (int) BestRoute.Loopback, - (int) BestRoute.AutoconfigureAddress, - (int) BestRoute.Immortal ); + msg(D_ROUTE, "GDG6: II=3D%lu DP=3D%s/%d NH=3D%s", BestRoute.InterfaceI= ndex, + print_in6_addr(BestRoute.DestinationPrefix.Prefix.Ipv6.sin6_addr, = 0, &gc), + BestRoute.DestinationPrefix.PrefixLength, + print_in6_addr(BestRoute.NextHop.Ipv6.sin6_addr, 0, &gc)); + msg(D_ROUTE, "GDG6: Metric=3D%d, Loopback=3D%d, AA=3D%d, I=3D%d", (int= )BestRoute.Metric, + (int)BestRoute.Loopback, (int)BestRoute.AutoconfigureAddress, (int= )BestRoute.Immortal); rgi6->gateway.addr_ipv6 =3D BestRoute.NextHop.Ipv6.sin6_addr; - rgi6->adapter_index =3D BestRoute.InterfaceIndex; + rgi6->adapter_index =3D BestRoute.InterfaceIndex; rgi6->flags |=3D RGI_ADDR_DEFINED | RGI_IFACE_DEFINED; /* on-link is signalled by receiving an empty (::) NextHop */ - if (IN6_IS_ADDR_UNSPECIFIED(&BestRoute.NextHop.Ipv6.sin6_addr) ) + if (IN6_IS_ADDR_UNSPECIFIED(&BestRoute.NextHop.Ipv6.sin6_addr)) { rgi6->flags |=3D RGI_ON_LINK; } @@ -2947,7 +2695,9 @@ struct gc_arena gc =3D gc_new(); int ret =3D RTA_ERROR; DWORD status; - const DWORD if_index =3D (adapter_index =3D=3D TUN_ADAPTER_INDEX_INVAL= ID) ? windows_route_find_if_index(r, tt) : adapter_index; + const DWORD if_index =3D (adapter_index =3D=3D TUN_ADAPTER_INDEX_INVAL= ID) + ? windows_route_find_if_index(r, tt) + : adapter_index; if (if_index !=3D TUN_ADAPTER_INDEX_INVALID) { @@ -2958,7 +2708,7 @@ fr.dwForwardPolicy =3D 0; fr.dwForwardNextHop =3D htonl(r->gateway); fr.dwForwardIfIndex =3D if_index; - fr.dwForwardType =3D 4; /* the next hop is not the final dest */ + fr.dwForwardType =3D 4; /* the next hop is not the final dest */ fr.dwForwardProto =3D 3; /* PROTO_IP_NETMGMT */ fr.dwForwardAge =3D 0; fr.dwForwardNextHopAS =3D 0; @@ -2971,8 +2721,7 @@ if ((r->network & r->netmask) !=3D r->network) { msg(M_WARN, "Warning: address %s is not a network address in r= elation to netmask %s", - print_in_addr_t(r->network, 0, &gc), - print_in_addr_t(r->netmask, 0, &gc)); + print_in_addr_t(r->network, 0, &gc), print_in_addr_t(r->ne= tmask, 0, &gc)); } status =3D CreateIpForwardEntry(&fr); @@ -2988,20 +2737,22 @@ else { /* failed, try increasing the metric to work around Vista issu= e */ - const unsigned int forward_metric_limit =3D 2048; /* iterative= ly retry higher metrics up to this limit */ + const unsigned int forward_metric_limit =3D + 2048; /* iteratively retry higher metrics up to this limit= */ for (; fr.dwForwardMetric1 <=3D forward_metric_limit; ++fr.dwF= orwardMetric1) { - /* try a different forward type=3D3 ("the next hop is the = final dest") in addition to 4. + /* try a different forward type=3D3 ("the next hop is the = final dest") in addition + * to 4. * --redirect-gateway over RRAS seems to need this. */ for (fr.dwForwardType =3D 4; fr.dwForwardType >=3D 3; --fr= .dwForwardType) { status =3D CreateIpForwardEntry(&fr); if (status =3D=3D NO_ERROR) { - msg(D_ROUTE, "ROUTE: CreateIpForwardEntry succeede= d with dwForwardMetric1=3D%u and dwForwardType=3D%u", - (unsigned int)fr.dwForwardMetric1, - (unsigned int)fr.dwForwardType); + msg(D_ROUTE, + "ROUTE: CreateIpForwardEntry succeeded with dw= ForwardMetric1=3D%u and dwForwardType=3D%u", + (unsigned int)fr.dwForwardMetric1, (unsigned i= nt)fr.dwForwardType); ret =3D RTA_SUCCESS; goto doublebreak; } @@ -3021,9 +2772,10 @@ } else { - msg(M_WARN, "ERROR: route addition failed using Create= IpForwardEntry: " - "%s [status=3D%u if_index=3D%u]", strerror_win32(s= tatus, &gc), - (unsigned int)status, (unsigned int)if_index); + msg(M_WARN, + "ERROR: route addition failed using CreateIpForwar= dEntry: " + "%s [status=3D%u if_index=3D%u]", + strerror_win32(status, &gc), (unsigned int)status,= (unsigned int)if_index); } } } @@ -3111,18 +2863,13 @@ return RTA_ERROR; } - route_message_t msg =3D { - .header =3D { - (add ? msg_add_route : msg_del_route), - sizeof(route_message_t), - 0 - }, - .family =3D AF_INET, - .prefix.ipv4.s_addr =3D htonl(r->network), - .gateway.ipv4.s_addr =3D htonl(r->gateway), - .iface =3D { .index =3D if_index, .name =3D "" }, - .metric =3D (r->flags & RT_METRIC_DEFINED ? r->metric : -1) - }; + route_message_t msg =3D { .header =3D { (add ? msg_add_route : msg_del= _route), + sizeof(route_message_t), 0 }, + .family =3D AF_INET, + .prefix.ipv4.s_addr =3D htonl(r->network), + .gateway.ipv4.s_addr =3D htonl(r->gateway), + .iface =3D { .index =3D if_index, .name =3D ""= }, + .metric =3D (r->flags & RT_METRIC_DEFINED ? r-= >metric : -1) }; netmask_to_netbits(r->network, r->netmask, &msg.prefix_len); if (msg.prefix_len =3D=3D -1) @@ -3152,7 +2899,7 @@ fwd_row->Metric =3D ((r->flags & RT_METRIC_DEFINED) ? r->metric : -1); fwd_row->DestinationPrefix.Prefix.si_family =3D AF_INET6; fwd_row->DestinationPrefix.Prefix.Ipv6.sin6_addr =3D r->network; - fwd_row->DestinationPrefix.PrefixLength =3D (UINT8) r->netbits; + fwd_row->DestinationPrefix.PrefixLength =3D (UINT8)r->netbits; fwd_row->NextHop.si_family =3D AF_INET6; fwd_row->NextHop.Ipv6.sin6_addr =3D r->gateway; fwd_row->InterfaceIndex =3D r->adapter_index ? r->adapter_index : tt->= adapter_index; @@ -3217,21 +2964,16 @@ do_route_ipv6_service(const bool add, const struct route_ipv6 *r, const st= ruct tuntap *tt) { int status; - route_message_t msg =3D { - .header =3D { - (add ? msg_add_route : msg_del_route), - sizeof(route_message_t), - 0 - }, - .family =3D AF_INET6, - .prefix.ipv6 =3D r->network, - .prefix_len =3D r->netbits, - .gateway.ipv6 =3D r->gateway, - .iface =3D { .index =3D tt->adapter_index, .name =3D "" }, - .metric =3D ( (r->flags & RT_METRIC_DEFINED) ? r->metric : -1) - }; + route_message_t msg =3D { .header =3D { (add ? msg_add_route : msg_del= _route), + sizeof(route_message_t), 0 }, + .family =3D AF_INET6, + .prefix.ipv6 =3D r->network, + .prefix_len =3D r->netbits, + .gateway.ipv6 =3D r->gateway, + .iface =3D { .index =3D tt->adapter_index, .na= me =3D "" }, + .metric =3D ((r->flags & RT_METRIC_DEFINED) ? = r->metric : -1) }; - if (r->adapter_index) /* vpn server special route */ + if (r->adapter_index) /* vpn server special route */ { msg.iface.index =3D r->adapter_index; } @@ -3240,8 +2982,7 @@ * The tapdrvr knows about it and will answer neighbor discovery packe= ts. * (only do this for routes actually using the tun/tap device) */ - if (tt->type =3D=3D DEV_TYPE_TUN - && msg.iface.index =3D=3D tt->adapter_index) + if (tt->type =3D=3D DEV_TYPE_TUN && msg.iface.index =3D=3D tt->adapter= _index) { inet_pton(AF_INET6, "fe80::8", &msg.gateway.ipv6); } @@ -3255,8 +2996,7 @@ status =3D do_route_service(add, &msg, sizeof(msg), tt->options.msg_ch= annel); if (status !=3D RTA_ERROR) { - msg(D_ROUTE, "IPv6 route %s via service %s", - add ? "addition" : "deletion", + msg(D_ROUTE, "IPv6 route %s via service %s", add ? "addition" : "d= eletion", (status =3D=3D RTA_SUCCESS) ? "succeeded" : "failed because ro= ute exists"); } return status; @@ -3295,17 +3035,10 @@ buf_printf(&out, "%s %s %s p=3D%d i=3D%d t=3D%d pr=3D%d a=3D%d h=3D%d = m=3D%d/%d/%d/%d/%d", print_in_addr_t(r->dwForwardDest, IA_NET_ORDER, gc), print_in_addr_t(r->dwForwardMask, IA_NET_ORDER, gc), - print_in_addr_t(r->dwForwardNextHop, IA_NET_ORDER, gc), - (int)r->dwForwardPolicy, - (int)r->dwForwardIfIndex, - (int)r->dwForwardType, - (int)r->dwForwardProto, - (int)r->dwForwardAge, - (int)r->dwForwardNextHopAS, - (int)r->dwForwardMetric1, - (int)r->dwForwardMetric2, - (int)r->dwForwardMetric3, - (int)r->dwForwardMetric4, + print_in_addr_t(r->dwForwardNextHop, IA_NET_ORDER, gc), (in= t)r->dwForwardPolicy, + (int)r->dwForwardIfIndex, (int)r->dwForwardType, (int)r->dw= ForwardProto, + (int)r->dwForwardAge, (int)r->dwForwardNextHopAS, (int)r->d= wForwardMetric1, + (int)r->dwForwardMetric2, (int)r->dwForwardMetric3, (int)r-= >dwForwardMetric4, (int)r->dwForwardMetric5); return BSTR(&out); } @@ -3354,12 +3087,11 @@ * normally on Linux. * It always fails and "ioctl(SIOCGIFCONF) failed" confuses users */ - } void -get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, - const struct in6_addr *dest, openvpn_net_ctx_t *c= tx) +get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struc= t in6_addr *dest, + openvpn_net_ctx_t *ctx) { /* Same for ipv6 */ @@ -3423,7 +3155,7 @@ if (ifr->ifr_addr.sa_family =3D=3D AF_INET) { /* get interface addr */ - addr =3D ntohl(((struct sockaddr_in *) &ifr->ifr_addr)->si= n_addr.s_addr); + addr =3D ntohl(((struct sockaddr_in *)&ifr->ifr_addr)->sin= _addr.s_addr); /* get interface name */ strncpynt(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_= name)); @@ -3441,7 +3173,7 @@ if (rgi->flags & RGI_ON_LINK) { /* check that interface name of current interface - * matches interface name of best default route */ + * matches interface name of best default route */ if (strcmp(ifreq.ifr_name, best_name)) { continue; @@ -3465,7 +3197,7 @@ { continue; } - netmask =3D ntohl(((struct sockaddr_in *) &ifreq.ifr_a= ddr)->sin_addr.s_addr); + netmask =3D ntohl(((struct sockaddr_in *)&ifreq.ifr_ad= dr)->sin_addr.s_addr); /* check that interface matches default route */ if (((rgi->gateway.addr ^ addr) & netmask) !=3D 0) @@ -3510,22 +3242,22 @@ * netlink(3), netlink(7), rtnetlink(7) * http://www.virtualbox.org/svn/vbox/trunk/src/VBox/NetworkServices/NAT/r= tmon_linux.c */ -struct rtreq { +struct rtreq +{ struct nlmsghdr nh; struct rtmsg rtm; char attrbuf[512]; }; void -get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, - const struct in6_addr *dest, openvpn_net_ctx_t *c= tx) +get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struc= t in6_addr *dest, + openvpn_net_ctx_t *ctx) { int flags; CLEAR(*rgi6); - if (net_route_v6_best_gw(ctx, dest, &rgi6->gateway.addr_ipv6, - rgi6->iface) =3D=3D 0) + if (net_route_v6_best_gw(ctx, dest, &rgi6->gateway.addr_ipv6, rgi6->if= ace) =3D=3D 0) { if (!IN6_IS_ADDR_UNSPECIFIED(&rgi6->gateway.addr_ipv6)) { @@ -3550,9 +3282,8 @@ } } -#elif defined(TARGET_DARWIN) || defined(TARGET_SOLARIS) \ - || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ - || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) +#elif defined(TARGET_DARWIN) || defined(TARGET_SOLARIS) || defined(TARGET_= FREEBSD) \ + || defined(TARGET_DRAGONFLY) || defined(TARGET_OPENBSD) || defined(TAR= GET_NETBSD) #include #include @@ -3563,7 +3294,8 @@ #include #endif -struct rtmsg { +struct rtmsg +{ struct rt_msghdr m_rtm; char m_space[512]; }; @@ -3585,26 +3317,30 @@ */ #if defined(TARGET_DARWIN) -#define ROUNDUP(a) \ - ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - 1))) : sizeof(uint32_= t)) +#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - 1))) := sizeof(uint32_t)) #elif defined(TARGET_NETBSD) #define ROUNDUP(a) RT_ROUNDUP(a) #else -#define ROUNDUP(a) \ - ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) +#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : siz= eof(long)) #endif #if defined(TARGET_SOLARIS) -#define NEXTADDR(w, u) \ - if (rtm_addrs & (w)) { \ - l =3D sizeof(u); memmove(cp, &(u), l); cp +=3D ROUNDUP(l); \ +#define NEXTADDR(w, u) \ + if (rtm_addrs & (w)) \ + { \ + l =3D sizeof(u); \ + memmove(cp, &(u), l); \ + cp +=3D ROUNDUP(l); \ } #define ADVANCE(x, n) (x +=3D ROUNDUP(sizeof(struct sockaddr_in))) -#else /* if defined(TARGET_SOLARIS) */ -#define NEXTADDR(w, u) \ - if (rtm_addrs & (w)) { \ - l =3D ((struct sockaddr *)&(u))->sa_len; memmove(cp, &(u), l); cp = +=3D ROUNDUP(l); \ +#else /* if defined(TARGET_SOLARIS) */ +#define NEXTADDR(w, u) \ + if (rtm_addrs & (w)) \ + { \ + l =3D ((struct sockaddr *)&(u))->sa_len; \ + memmove(cp, &(u), l); \ + cp +=3D ROUNDUP(l); \ } #define ADVANCE(x, n) (x +=3D ROUNDUP((n)->sa_len)) @@ -3623,7 +3359,7 @@ struct sockaddr so_dst, so_mask; char *cp =3D m_rtmsg.m_space; struct sockaddr *gate =3D NULL, *ifp =3D NULL, *sa; - struct rt_msghdr *rtm_aux; + struct rt_msghdr *rtm_aux; #define rtm m_rtmsg.m_rtm @@ -3633,7 +3369,7 @@ pid =3D getpid(); seq =3D 0; #ifdef TARGET_OPENBSD - rtm_addrs =3D RTA_DST | RTA_NETMASK; /* Kernel refuses RTA_IF= P */ + rtm_addrs =3D RTA_DST | RTA_NETMASK; /* Kernel refuses RTA_IFP */ #else rtm_addrs =3D RTA_DST | RTA_NETMASK | RTA_IFP; #endif @@ -3674,7 +3410,7 @@ } if (write(sockfd, (char *)&m_rtmsg, l) < 0) { - msg(M_WARN|M_ERRNO, "GDG: problem writing to routing socket"); + msg(M_WARN | M_ERRNO, "GDG: problem writing to routing socket"); goto done; } do @@ -3724,7 +3460,7 @@ if (ifp) { /* get interface name */ - const struct sockaddr_dl *adl =3D (struct sockaddr_dl *) ifp; + const struct sockaddr_dl *adl =3D (struct sockaddr_dl *)ifp; if (adl->sdl_nlen && adl->sdl_nlen < sizeof(rgi->iface)) { memcpy(rgi->iface, adl->sdl_data, adl->sdl_nlen); @@ -3792,15 +3528,14 @@ if (getifaddrs(&ifap) !=3D 0) { - msg(M_WARN|M_ERRNO, "GDG: getifaddrs() failed"); + msg(M_WARN | M_ERRNO, "GDG: getifaddrs() failed"); goto done; } for (ifa =3D ifap; ifa; ifa =3D ifa->ifa_next) { - if (ifa->ifa_addr !=3D NULL - && ifa->ifa_addr->sa_family =3D=3D AF_LINK - && !strncmp(ifa->ifa_name, rgi->iface, IFNAMSIZ) ) + if (ifa->ifa_addr !=3D NULL && ifa->ifa_addr->sa_family =3D=3D= AF_LINK + && !strncmp(ifa->ifa_name, rgi->iface, IFNAMSIZ)) { struct sockaddr_dl *sdl =3D (struct sockaddr_dl *)ifa->ifa= _addr; memcpy(rgi->hwaddr, LLADDR(sdl), 6); @@ -3833,10 +3568,9 @@ #endif void -get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, - const struct in6_addr *dest, openvpn_net_ctx_t *c= tx) +get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struc= t in6_addr *dest, + openvpn_net_ctx_t *ctx) { - struct rtmsg m_rtmsg; int sockfd =3D -1; int seq, l, pid, rtm_addrs; @@ -3852,7 +3586,7 @@ pid =3D getpid(); seq =3D 0; #ifdef TARGET_OPENBSD - rtm_addrs =3D RTA_DST | RTA_NETMASK; /* Kernel refuses RTA_IF= P */ + rtm_addrs =3D RTA_DST | RTA_NETMASK; /* Kernel refuses RTA_IFP */ #else rtm_addrs =3D RTA_DST | RTA_NETMASK | RTA_IFP; #endif @@ -3873,8 +3607,8 @@ so_dst.sin6_family =3D AF_INET6; so_mask.sin6_family =3D AF_INET6; - if (dest !=3D NULL /* specific host? */ - && !IN6_IS_ADDR_UNSPECIFIED(dest) ) + if (dest !=3D NULL /* specific host? */ + && !IN6_IS_ADDR_UNSPECIFIED(dest)) { so_dst.sin6_addr =3D *dest; /* :: needs /0 "netmask", host route wants "no netmask */ @@ -3902,15 +3636,14 @@ } if (write(sockfd, (char *)&m_rtmsg, l) < 0) { - msg(M_WARN|M_ERRNO, "GDG6: problem writing to routing socket"); + msg(M_WARN | M_ERRNO, "GDG6: problem writing to routing socket"); goto done; } do { l =3D read(sockfd, (char *)&m_rtmsg, sizeof(m_rtmsg)); - } - while (l > 0 && (rtm.rtm_seq !=3D seq || rtm.rtm_pid !=3D pid)); + } while (l > 0 && (rtm.rtm_seq !=3D seq || rtm.rtm_pid !=3D pid)); close(sockfd); sockfd =3D -1; @@ -3953,14 +3686,12 @@ * (KAME encodes the 16 bit scope_id in s6_addr[2] + [3], * but for a correct link-local address these must be :0000: ) */ - if (gate->sa_len =3D=3D sizeof(struct sockaddr_in6) - && IN6_IS_ADDR_LINKLOCAL(&gw) ) + if (gate->sa_len =3D=3D sizeof(struct sockaddr_in6) && IN6_IS_ADDR= _LINKLOCAL(&gw)) { gw.s6_addr[2] =3D gw.s6_addr[3] =3D 0; } - if (gate->sa_len !=3D sizeof(struct sockaddr_in6) - || IN6_IS_ADDR_UNSPECIFIED(&gw) ) + if (gate->sa_len !=3D sizeof(struct sockaddr_in6) || IN6_IS_ADDR_U= NSPECIFIED(&gw)) { rgi6->flags |=3D RGI_ON_LINK; } @@ -3974,7 +3705,7 @@ if (ifp) { /* get interface name */ - const struct sockaddr_dl *adl =3D (struct sockaddr_dl *) ifp; + const struct sockaddr_dl *adl =3D (struct sockaddr_dl *)ifp; if (adl->sdl_nlen && adl->sdl_nlen < sizeof(rgi6->iface)) { memcpy(rgi6->iface, adl->sdl_data, adl->sdl_nlen); @@ -4058,15 +3789,15 @@ address_size +=3D route.gateway->sa_len; } - interface =3D (struct ifreq *)((addr_t)interface + IF_NAMESIZE - + sizeof(struct route_entry) + addres= s_size); + interface =3D (struct ifreq *)((addr_t)interface + IF_NAMESIZE + s= izeof(struct route_entry) + + address_size); } free(buffer); } void -get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, - const struct in6_addr *dest, openvpn_net_ctx_t *c= tx) +get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struc= t in6_addr *dest, + openvpn_net_ctx_t *ctx) { /* TODO: Same for ipv6 with AF_INET6 */ CLEAR(*rgi6); @@ -4104,8 +3835,8 @@ CLEAR(*rgi); } void -get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, - const struct in6_addr *dest, openvpn_net_ctx_t *c= tx) +get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struc= t in6_addr *dest, + openvpn_net_ctx_t *ctx) { msg(D_ROUTE, "no support for get_default_gateway_ipv6() on this system= "); CLEAR(*rgi6); @@ -4185,7 +3916,8 @@ while (iplist) { bool succeed =3D false; - const in_addr_t ip =3D getaddr(GETADDR_HOST_ORDER, iplist->IpAddre= ss.String, 0, &succeed, NULL); + const in_addr_t ip =3D + getaddr(GETADDR_HOST_ORDER, iplist->IpAddress.String, 0, &succ= eed, NULL); if (succeed) { add_host_route_if_nonlocal(rb, ip); @@ -4233,7 +3965,7 @@ #else /* if defined(_WIN32) */ static void -get_bypass_addresses(struct route_bypass *rb, const unsigned int flags) = /* PLATFORM-SPECIFIC */ +get_bypass_addresses(struct route_bypass *rb, const unsigned int flags) /*= PLATFORM-SPECIFIC */ { } @@ -4254,7 +3986,8 @@ test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi) { struct gc_arena gc =3D gc_new(); - const in_addr_t nonlocal_netmask =3D 0x80000000L; /* routes with netma= sk <=3D to this are considered non-local */ + const in_addr_t nonlocal_netmask =3D + 0x80000000L; /* routes with netmask <=3D to this are considered no= n-local */ int ret =3D TLA_NONLOCAL; /* get full routing table */ @@ -4281,7 +4014,7 @@ #else /* if defined(_WIN32) */ int -test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi= ) /* PLATFORM-SPECIFIC */ +test_local_addr(const in_addr_t addr, const struct route_gateway_info *rgi= ) /* PLATFORM-SPECIFIC */ { if (rgi) { diff --git a/src/openvpn/route.h b/src/openvpn/route.h index 237375c..a3aadb7 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -37,18 +37,18 @@ /* * Windows route methods */ -#define ROUTE_METHOD_ADAPTIVE 0 /* try IP helper first then route.exe */ -#define ROUTE_METHOD_IPAPI 1 /* use IP helper API */ -#define ROUTE_METHOD_EXE 2 /* use route.exe */ -#define ROUTE_METHOD_SERVICE 3 /* use the privileged Windows service */ -#define ROUTE_METHOD_MASK 3 +#define ROUTE_METHOD_ADAPTIVE 0 /* try IP helper first then route.exe */ +#define ROUTE_METHOD_IPAPI 1 /* use IP helper API */ +#define ROUTE_METHOD_EXE 2 /* use route.exe */ +#define ROUTE_METHOD_SERVICE 3 /* use the privileged Windows service */ +#define ROUTE_METHOD_MASK 3 #endif /* * Route add/delete flags (must stay clear of ROUTE_METHOD bits) */ -#define ROUTE_DELETE_FIRST (1<<2) -#define ROUTE_REF_GW (1<<3) +#define ROUTE_DELETE_FIRST (1 << 2) +#define ROUTE_REF_GW (1 << 3) struct route_bypass { @@ -60,9 +60,9 @@ struct route_special_addr { /* bits indicating which members below are defined */ -#define RTSA_REMOTE_ENDPOINT (1<<0) -#define RTSA_REMOTE_HOST (1<<1) -#define RTSA_DEFAULT_METRIC (1<<2) +#define RTSA_REMOTE_ENDPOINT (1 << 0) +#define RTSA_REMOTE_HOST (1 << 1) +#define RTSA_DEFAULT_METRIC (1 << 2) unsigned int flags; in_addr_t remote_endpoint; @@ -73,7 +73,8 @@ int default_metric; }; -struct route_option { +struct route_option +{ struct route_option *next; const char *network; const char *netmask; @@ -83,39 +84,43 @@ }; /* redirect-gateway flags */ -#define RG_ENABLE (1<<0) -#define RG_LOCAL (1<<1) -#define RG_DEF1 (1<<2) -#define RG_BYPASS_DHCP (1<<3) -#define RG_BYPASS_DNS (1<<4) -#define RG_REROUTE_GW (1<<5) -#define RG_AUTO_LOCAL (1<<6) -#define RG_BLOCK_LOCAL (1<<7) +#define RG_ENABLE (1 << 0) +#define RG_LOCAL (1 << 1) +#define RG_DEF1 (1 << 2) +#define RG_BYPASS_DHCP (1 << 3) +#define RG_BYPASS_DNS (1 << 4) +#define RG_REROUTE_GW (1 << 5) +#define RG_AUTO_LOCAL (1 << 6) +#define RG_BLOCK_LOCAL (1 << 7) -struct route_option_list { +struct route_option_list +{ unsigned int flags; /* RG_x flags */ struct route_option *routes; struct gc_arena *gc; }; -struct route_ipv6_option { +struct route_ipv6_option +{ struct route_ipv6_option *next; - const char *prefix; /* e.g. "2001:db8:1::/64" */ - const char *gateway; /* e.g. "2001:db8:0::2" */ - const char *metric; /* e.g. "5" */ + const char *prefix; /* e.g. "2001:db8:1::/64" */ + const char *gateway; /* e.g. "2001:db8:0::2" */ + const char *metric; /* e.g. "5" */ int table_id; }; -struct route_ipv6_option_list { - unsigned int flags; /* RG_x flags, see route_option-list */ +struct route_ipv6_option_list +{ + unsigned int flags; /* RG_x flags, see route_option-list */ struct route_ipv6_option *routes_ipv6; struct gc_arena *gc; }; -struct route_ipv4 { -#define RT_DEFINED (1<<0) -#define RT_ADDED (1<<1) -#define RT_METRIC_DEFINED (1<<2) +struct route_ipv4 +{ +#define RT_DEFINED (1 << 0) +#define RT_ADDED (1 << 1) +#define RT_METRIC_DEFINED (1 << 2) struct route_ipv4 *next; unsigned int flags; const struct route_option *option; @@ -126,9 +131,10 @@ int metric; }; -struct route_ipv6 { +struct route_ipv6 +{ struct route_ipv6 *next; - unsigned int flags; /* RT_ flags, see route_ip= v4 */ + unsigned int flags; /* RT_ flags, see route_ipv4 */ struct in6_addr network; unsigned int netbits; struct in6_addr gateway; @@ -136,25 +142,27 @@ int table_id; /* gateway interface */ #ifdef _WIN32 - DWORD adapter_index; /* interface or ~0 if undefined */ + DWORD adapter_index; /* interface or ~0 if undefined */ #else - char *iface; /* interface name (null terminated) */ + char *iface; /* interface name (null terminated) */ #endif }; -struct route_gateway_address { +struct route_gateway_address +{ in_addr_t addr; in_addr_t netmask; }; -struct route_gateway_info { -#define RGI_ADDR_DEFINED (1<<0) /* set if gateway.addr defined */ -#define RGI_NETMASK_DEFINED (1<<1) /* set if gateway.netmask defined */ -#define RGI_HWADDR_DEFINED (1<<2) /* set if hwaddr is defined */ -#define RGI_IFACE_DEFINED (1<<3) /* set if iface is defined */ -#define RGI_OVERFLOW (1<<4) /* set if more interface addresses th= an will fit in addrs */ -#define RGI_ON_LINK (1<<5) +struct route_gateway_info +{ +#define RGI_ADDR_DEFINED (1 << 0) /* set if gateway.addr defined */ +#define RGI_NETMASK_DEFINED (1 << 1) /* set if gateway.netmask defined */ +#define RGI_HWADDR_DEFINED (1 << 2) /* set if hwaddr is defined */ +#define RGI_IFACE_DEFINED (1 << 3) /* set if iface is defined */ +#define RGI_OVERFLOW (1 << 4) /* set if more interface addresses th= an will fit in addrs */ +#define RGI_ON_LINK (1 << 5) unsigned int flags; /* gateway interface */ @@ -174,17 +182,19 @@ /* address/netmask pairs bound to interface */ #define RGI_N_ADDRESSES 8 - int n_addrs; /* len of addrs, may be 0 */ + int n_addrs; /* len of addrs, = may be 0 */ struct route_gateway_address addrs[RGI_N_ADDRESSES]; /* local addresse= s attached to iface */ }; -struct route_ipv6_gateway_address { +struct route_ipv6_gateway_address +{ struct in6_addr addr_ipv6; int netbits_ipv6; }; -struct route_ipv6_gateway_info { -/* RGI_ flags used as in route_gateway_info */ +struct route_ipv6_gateway_info +{ + /* RGI_ flags used as in route_gateway_info */ unsigned int flags; /* gateway interface */ @@ -211,45 +221,50 @@ /* address/netmask pairs bound to interface */ #define RGI_N_ADDRESSES 8 - int n_addrs; /* len of addrs, may be 0 */ - struct route_ipv6_gateway_address addrs[RGI_N_ADDRESSES]; /* local add= resses attached to iface */ + int n_addrs; /* len of addrs, may be 0 */ + struct route_ipv6_gateway_address + addrs[RGI_N_ADDRESSES]; /* local addresses attached to iface */ }; -struct route_list { -#define RL_DID_REDIRECT_DEFAULT_GATEWAY (1<<0) -#define RL_DID_LOCAL (1<<1) -#define RL_ROUTES_ADDED (1<<2) +struct route_list +{ +#define RL_DID_REDIRECT_DEFAULT_GATEWAY (1 << 0) +#define RL_DID_LOCAL (1 << 1) +#define RL_ROUTES_ADDED (1 << 2) unsigned int iflags; struct route_special_addr spec; struct route_gateway_info rgi; - unsigned int flags; /* RG_x flags */ + unsigned int flags; /* RG_x flags */ struct route_ipv4 *routes; struct gc_arena gc; }; -struct route_ipv6_list { - unsigned int iflags; /* RL_ flags, see route_list */ +struct route_ipv6_list +{ + unsigned int iflags; /* RL_ flags, see route_list */ - unsigned int spec_flags; /* RTSA_ flags, route_special_addr= */ + unsigned int spec_flags; /* RTSA_ flags, route_special_ad= dr */ struct in6_addr remote_endpoint_ipv6; /* inside tun */ - struct in6_addr remote_host_ipv6; /* --remote address */ + struct in6_addr remote_host_ipv6; /* --remote address */ int default_metric; struct route_ipv6_gateway_info rgi6; - unsigned int flags; /* RG_x flags, see route_option_li= st */ + unsigned int flags; /* RG_x flags, see route_option_list */ struct route_ipv6 *routes_ipv6; struct gc_arena gc; }; /* internal OpenVPN route */ -struct iroute { +struct iroute +{ in_addr_t network; int netbits; struct iroute *next; }; -struct iroute_ipv6 { +struct iroute_ipv6 +{ struct in6_addr network; unsigned int netbits; struct iroute_ipv6 *next; @@ -271,69 +286,52 @@ struct route_ipv6_option_list *new_route_ipv6_option_list(struct gc_arena = *a); -struct route_option_list *clone_route_option_list(const struct route_optio= n_list *src, struct gc_arena *a); +struct route_option_list *clone_route_option_list(const struct route_optio= n_list *src, + struct gc_arena *a); -struct route_ipv6_option_list *clone_route_ipv6_option_list(const struct r= oute_ipv6_option_list *src, struct gc_arena *a); +struct route_ipv6_option_list *clone_route_ipv6_option_list( + const struct route_ipv6_option_list *src, struct gc_arena *a); -void copy_route_option_list(struct route_option_list *dest, const struct r= oute_option_list *src, struct gc_arena *a); +void copy_route_option_list(struct route_option_list *dest, const struct r= oute_option_list *src, + struct gc_arena *a); void copy_route_ipv6_option_list(struct route_ipv6_option_list *dest, - const struct route_ipv6_option_list *src, - struct gc_arena *a); + const struct route_ipv6_option_list *src,= struct gc_arena *a); -void route_ipv6_clear_host_bits( struct route_ipv6 *r6 ); +void route_ipv6_clear_host_bits(struct route_ipv6 *r6); -bool add_route_ipv6(struct route_ipv6 *r, const struct tuntap *tt, unsigne= d int flags, const struct env_set *es, openvpn_net_ctx_t *ctx); +bool add_route_ipv6(struct route_ipv6 *r, const struct tuntap *tt, unsigne= d int flags, + const struct env_set *es, openvpn_net_ctx_t *ctx); -void delete_route_ipv6(const struct route_ipv6 *r, const struct tuntap *tt= , const struct env_set *es, openvpn_net_ctx_t *ctx); +void delete_route_ipv6(const struct route_ipv6 *r, const struct tuntap *tt, + const struct env_set *es, openvpn_net_ctx_t *ctx); bool add_route(struct route_ipv4 *r, const struct tuntap *tt, unsigned int= flags, const struct route_gateway_info *rgi, const struct env_set = *es, openvpn_net_ctx_t *ctx); -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); +void add_route_to_option_list(struct route_option_list *l, const char *net= work, const char *netmask, + const char *gateway, const char *metric, int= table_id); -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); +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); -bool init_route_list(struct route_list *rl, - const struct route_option_list *opt, - const char *remote_endpoint, - int default_metric, - in_addr_t remote_host, - struct env_set *es, - openvpn_net_ctx_t *ctx); +bool init_route_list(struct route_list *rl, const struct route_option_list= *opt, + const char *remote_endpoint, int default_metric, in_a= ddr_t remote_host, + struct env_set *es, openvpn_net_ctx_t *ctx); -bool init_route_ipv6_list(struct route_ipv6_list *rl6, - const struct route_ipv6_option_list *opt6, - const char *remote_endpoint, - int default_metric, - const struct in6_addr *remote_host, - struct env_set *es, +bool init_route_ipv6_list(struct route_ipv6_list *rl6, const struct route_= ipv6_option_list *opt6, + const char *remote_endpoint, int default_metric, + const struct in6_addr *remote_host, struct env_s= et *es, openvpn_net_ctx_t *ctx); -void route_list_add_vpn_gateway(struct route_list *rl, - struct env_set *es, - const in_addr_t addr); +void route_list_add_vpn_gateway(struct route_list *rl, struct env_set *es,= const in_addr_t addr); -bool add_routes(struct route_list *rl, struct route_ipv6_list *rl6, - const struct tuntap *tt, unsigned int flags, - const struct env_set *es, openvpn_net_ctx_t *ctx); +bool add_routes(struct route_list *rl, struct route_ipv6_list *rl6, const = struct tuntap *tt, + unsigned int flags, const struct env_set *es, openvpn_net_= ctx_t *ctx); -void delete_routes(struct route_list *rl, - struct route_ipv6_list *rl6, - const struct tuntap *tt, - unsigned int flags, - const struct env_set *es, - openvpn_net_ctx_t *ctx); +void delete_routes(struct route_list *rl, struct route_ipv6_list *rl6, con= st struct tuntap *tt, + unsigned int flags, const struct env_set *es, openvpn_n= et_ctx_t *ctx); void setenv_routes(struct env_set *es, const struct route_list *rl); @@ -348,16 +346,12 @@ * @param dest Destination IP address in host byte order. * @param ctx Pointer to a platform-specific network context struct. */ -void get_default_gateway(struct route_gateway_info *rgi, - in_addr_t dest, - openvpn_net_ctx_t *ctx); +void get_default_gateway(struct route_gateway_info *rgi, in_addr_t dest, o= penvpn_net_ctx_t *ctx); -void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, - const struct in6_addr *dest, +void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi, const s= truct in6_addr *dest, openvpn_net_ctx_t *ctx); -void print_default_gateway(const int msglevel, - const struct route_gateway_info *rgi, +void print_default_gateway(const int msglevel, const struct route_gateway_= info *rgi, const struct route_ipv6_gateway_info *rgi6); /* @@ -372,8 +366,7 @@ int test_local_addr(const in_addr_t addr, const struct route_gateway_info = *rgi); #ifndef ENABLE_SMALL -void print_route_options(const struct route_option_list *rol, - int level); +void print_route_options(const struct route_option_list *rol, int level); #endif @@ -385,7 +378,7 @@ bool test_routes(const struct route_list *rl, const struct tuntap *tt); -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ static inline bool test_routes(const struct route_list *rl, const struct tuntap *tt) { @@ -404,7 +397,7 @@ in_addr_t mask =3D 0; if (netbits > 0 && netbits <=3D addrlen) { - mask =3D IPV4_NETMASK_HOST << (addrlen-netbits); + mask =3D IPV4_NETMASK_HOST << (addrlen - netbits); } return mask; } diff --git a/src/openvpn/run_command.c b/src/openvpn/run_command.c index 8b5fa4f..5fefb55 100644 --- a/src/openvpn/run_command.c +++ b/src/openvpn/run_command.c @@ -68,7 +68,7 @@ #ifdef _WIN32 case OPENVPN_EXECVE_ERROR: buf_printf(&out, "external program did not execute -- "); - /* fall through */ + /* fall through */ default: buf_printf(&out, "returned error code %d", stat); @@ -127,20 +127,16 @@ if (exitcode =3D=3D OPENVPN_EXECVE_FAILURE) { - msg(msglevel, "%scould not execute external program (exit code= 127)", - msg_prefix); + msg(msglevel, "%scould not execute external program (exit code= 127)", msg_prefix); } else { - msg(msglevel, "%sexternal program exited with error status: %d= ", - msg_prefix, exitcode); + msg(msglevel, "%sexternal program exited with error status: %d= ", msg_prefix, exitcode); } - } else if (WIFSIGNALED(status)) { - msg(msglevel, "%sexternal program received signal %d", - msg_prefix, WTERMSIG(status)); + msg(msglevel, "%sexternal program received signal %d", msg_prefix,= WTERMSIG(status)); } return false; @@ -235,7 +231,8 @@ * Wrapper around openvpn_execve */ int -openvpn_execve_check(const struct argv *a, const struct env_set *es, const= unsigned int flags, const char *error_message) +openvpn_execve_check(const struct argv *a, const struct env_set *es, const= unsigned int flags, + const char *error_message) { struct gc_arena gc =3D gc_new(); const int stat =3D openvpn_execve(a, es, flags); @@ -261,8 +258,7 @@ } if (error_message) { - msg(((flags & S_FATAL) ? M_FATAL : M_WARN), "%s: %s", - error_message, + msg(((flags & S_FATAL) ? M_FATAL : M_WARN), "%s: %s", error_messag= e, system_error_message(stat, &gc)); } done: @@ -277,7 +273,7 @@ * associated with formatting and parsing a command line. */ int -openvpn_popen(const struct argv *a, const struct env_set *es) +openvpn_popen(const struct argv *a, const struct env_set *es) { struct gc_arena gc =3D gc_new(); int ret =3D -1; @@ -299,20 +295,20 @@ pid =3D fork(); if (pid =3D=3D (pid_t)0) /* child side */ { - close(pipe_stdout[0]); /* Close read end */ + close(pipe_stdout[0]); /* Close read end */ dup2(pipe_stdout[1], 1); execve(cmd, argv, envp); exit(OPENVPN_EXECVE_FAILURE); } - else if (pid > (pid_t)0) /* parent side */ + else if (pid > (pid_t)0) /* parent side */ { int status =3D 0; - close(pipe_stdout[1]); /* Close write end */ + close(pipe_stdout[1]); /* Close write end */ waitpid(pid, &status, 0); ret =3D pipe_stdout[0]; } - else /* fork failed */ + else /* fork failed */ { close(pipe_stdout[0]); close(pipe_stdout[1]); diff --git a/src/openvpn/run_command.h b/src/openvpn/run_command.h index e9a6fe1..d398341 100644 --- a/src/openvpn/run_command.h +++ b/src/openvpn/run_command.h @@ -28,36 +28,38 @@ #include "env_set.h" /* Script security */ -#define SSEC_NONE 0 /* strictly no calling of external programs */ -#define SSEC_BUILT_IN 1 /* only call built-in programs such as ifconfig, = route, netsh, etc.*/ -#define SSEC_SCRIPTS 2 /* allow calling of built-in programs and user-de= fined scripts */ -#define SSEC_PW_ENV 3 /* allow calling of built-in programs and user-de= fined scripts that may receive a password as an environmental variable */ +#define SSEC_NONE 0 /* strictly no calling of external programs */ +#define SSEC_BUILT_IN 1 /* only call built-in programs such as ifconfig, r= oute, netsh, etc.*/ +#define SSEC_SCRIPTS 2 /* allow calling of built-in programs and user-def= ined scripts */ +#define SSEC_PW_ENV = \ + 3 /* allow calling of built-in programs and user-defined scripts that = may receive a password \ + as an environmental variable */ -#define OPENVPN_EXECVE_ERROR -1 /* generic error while forking to ru= n an external program */ -#define OPENVPN_EXECVE_NOT_ALLOWED -2 /* external program not run due to s= cript security */ -#define OPENVPN_EXECVE_FAILURE 127 /* exit code passed back from child = when execve fails */ +#define OPENVPN_EXECVE_ERROR -1 /* generic error while forking to r= un an external program */ +#define OPENVPN_EXECVE_NOT_ALLOWED -2 /* external program not run due to = script security */ +#define OPENVPN_EXECVE_FAILURE 127 /* exit code passed back from child= when execve fails */ int script_security(void); void script_security_set(int level); /* openvpn_execve flags */ -#define S_SCRIPT (1<<0) -#define S_FATAL (1<<1) +#define S_SCRIPT (1 << 0) +#define S_FATAL (1 << 1) /** Instead of returning 1/0 for success/fail, * return exit code when between 0 and 255 and -1 otherwise */ -#define S_EXITCODE (1<<2) +#define S_EXITCODE (1 << 2) /** instead of waiting for child process to exit and report the status, * return the pid of the child process */ -#define S_NOWAITPID (1<<3) +#define S_NOWAITPID (1 << 3) /* wrapper around the execve() call */ -int openvpn_popen(const struct argv *a, const struct env_set *es); +int openvpn_popen(const struct argv *a, const struct env_set *es); bool openvpn_execve_allowed(const unsigned int flags); -int openvpn_execve_check(const struct argv *a, const struct env_set *es, - const unsigned int flags, const char *error_messa= ge); +int openvpn_execve_check(const struct argv *a, const struct env_set *es, c= onst unsigned int flags, + const char *error_message); #ifndef WIN32 @@ -73,9 +75,7 @@ * @return true if the process is still running, false if * an error condition occurred */ -bool -openvpn_waitpid_check(pid_t pid, const char *msg_prefix, - int msglevel); +bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel= ); #endif @@ -84,13 +84,12 @@ * 0 and 255, -1 otherwise */ static inline int -openvpn_run_script(const struct argv *a, const struct env_set *es, - const unsigned int flags, const char *hook) +openvpn_run_script(const struct argv *a, const struct env_set *es, const u= nsigned int flags, + const char *hook) { char msg[256]; - snprintf(msg, sizeof(msg), - "WARNING: Failed running command (%s)", hook); + snprintf(msg, sizeof(msg), "WARNING: Failed running command (%s)", hoo= k); return openvpn_execve_check(a, es, flags | S_SCRIPT, msg); } diff --git a/src/openvpn/schedule.c b/src/openvpn/schedule.c index aaa9885..0fa5838 100644 --- a/src/openvpn/schedule.c +++ b/src/openvpn/schedule.c @@ -55,15 +55,12 @@ struct gc_arena gc =3D gc_new(); if (e) { - dmsg(D_SCHEDULER, "SCHEDULE: %s wakeup=3D[%s] pri=3D%u", - caller, - tv_string_abs(&e->tv, &gc), + dmsg(D_SCHEDULER, "SCHEDULE: %s wakeup=3D[%s] pri=3D%u", caller, t= v_string_abs(&e->tv, &gc), e->pri); } else { - dmsg(D_SCHEDULER, "SCHEDULE: %s NULL", - caller); + dmsg(D_SCHEDULER, "SCHEDULE: %s NULL", caller); } gc_free(&gc); } @@ -85,8 +82,7 @@ * that keys do not collide. */ static inline int -schedule_entry_compare(const struct schedule_entry *e1, - const struct schedule_entry *e2) +schedule_entry_compare(const struct schedule_entry *e1, const struct sched= ule_entry *e2) { if (e1->tv.tv_sec < e2->tv.tv_sec) { @@ -361,12 +357,11 @@ if (s->root) { - schedule_insert(s, e); /* trivial insert into tree */ + schedule_insert(s, e); /* trivial insert into tree */ } else { s->root =3D e; /* tree was empty, we are the first element */ - } /* This is the magic of the randomized treap algorithm which * keeps the tree balanced. Move the node up the tree until @@ -447,12 +442,8 @@ * internally consistent. */ int -schedule_debug_entry(const struct schedule_entry *e, - int depth, - int *count, - struct timeval *least, - const struct timeval *min, - const struct timeval *max) +schedule_debug_entry(const struct schedule_entry *e, int depth, int *count= , struct timeval *least, + const struct timeval *min, const struct timeval *max) { struct gc_arena gc =3D gc_new(); int maxdepth =3D depth; @@ -494,13 +485,13 @@ *least =3D e->tv; } - d =3D schedule_debug_entry(e->lt, depth+1, count, least, min, &e->= tv); + d =3D schedule_debug_entry(e->lt, depth + 1, count, least, min, &e= ->tv); if (d > maxdepth) { maxdepth =3D d; } - d =3D schedule_debug_entry(e->gt, depth+1, count, least, &e->tv, m= ax); + d =3D schedule_debug_entry(e->gt, depth + 1, count, least, &e->tv,= max); if (d > maxdepth) { maxdepth =3D d; @@ -577,14 +568,8 @@ if (e) { - printf("Verification Phase count=3D%d maxlev=3D%d sru=3D%d ins=3D= %d coll=3D%d ls=3D%d l=3D%s", - count, - maxlev, - zz.sru, - zz.ins, - zz.coll, - zz.lsteps, - tv_string(&e->tv, &gc)); + printf("Verification Phase count=3D%d maxlev=3D%d sru=3D%d ins=3D= %d coll=3D%d ls=3D%d l=3D%s", count, + maxlev, zz.sru, zz.ins, zz.coll, zz.lsteps, tv_string(&e->t= v, &gc)); if (!tv_eq(&least, &e->tv)) { @@ -605,11 +590,11 @@ for (i =3D 0; i < size; ++i) { const int src =3D get_random() % size; - struct schedule_entry *tmp =3D array [i]; + struct schedule_entry *tmp =3D array[i]; if (i !=3D src) { - array [i] =3D array [src]; - array [src] =3D tmp; + array[i] =3D array[src]; + array[src] =3D tmp; } } } @@ -626,14 +611,10 @@ if (e) { printf("%s [%u] e=3D" ptr_format ", p=3D" ptr_format " lt=3D" ptr_= format " gt=3D" ptr_format "\n", - tv_string(&e->tv, &gc), - e->pri, - (ptr_type)e, - (ptr_type)e->parent, - (ptr_type)e->lt, + tv_string(&e->tv, &gc), e->pri, (ptr_type)e, (ptr_type)e->p= arent, (ptr_type)e->lt, (ptr_type)e->gt); - schedule_print_work(e->lt, indent+1); - schedule_print_work(e->gt, indent+1); + schedule_print_work(e->lt, indent + 1); + schedule_print_work(e->gt, indent + 1); } else { diff --git a/src/openvpn/schedule.h b/src/openvpn/schedule.h index 1608708..5a9db6f 100644 --- a/src/openvpn/schedule.h +++ b/src/openvpn/schedule.h @@ -43,8 +43,8 @@ struct schedule_entry { - struct timeval tv; /* wakeup time */ - unsigned int pri; /* random treap priority */ + struct timeval tv; /* wakeup time */ + unsigned int pri; /* random treap priority */ struct schedule_entry *parent; /* treap (btree) links */ struct schedule_entry *lt; struct schedule_entry *gt; @@ -53,7 +53,7 @@ struct schedule { struct schedule_entry *earliest_wakeup; /* cached earliest wakeup */ - struct schedule_entry *root; /* the root of the treap (btree)= */ + struct schedule_entry *root; /* the root of the treap (btre= e) */ }; /* Public functions */ @@ -95,9 +95,7 @@ * an opaque object. */ static inline void -schedule_add_entry(struct schedule *s, - struct schedule_entry *e, - const struct timeval *tv, +schedule_add_entry(struct schedule *s, struct schedule_entry *e, const str= uct timeval *tv, unsigned int sigma) { if (!IN_TREE(e) || !sigma || !tv_within_sigma(tv, &e->tv, sigma)) @@ -115,8 +113,7 @@ * is randomized every time an entry is re-added). */ static inline struct schedule_entry * -schedule_get_earliest_wakeup(struct schedule *s, - struct timeval *wakeup) +schedule_get_earliest_wakeup(struct schedule *s, struct timeval *wakeup) { struct schedule_entry *ret; diff --git a/src/openvpn/session_id.h b/src/openvpn/session_id.h index 5ce9a96..7a75261 100644 --- a/src/openvpn/session_id.h +++ b/src/openvpn/session_id.h @@ -45,8 +45,7 @@ #define SID_SIZE (sizeof(x_session_id_zero.id)) static inline bool -session_id_equal(const struct session_id *sid1, - const struct session_id *sid2) +session_id_equal(const struct session_id *sid1, const struct session_id *s= id2) { return !memcmp(sid1->id, sid2->id, SID_SIZE); } diff --git a/src/openvpn/shaper.c b/src/openvpn/shaper.c index 1075954..005719e 100644 --- a/src/openvpn/shaper.c +++ b/src/openvpn/shaper.c @@ -87,6 +87,5 @@ void shaper_msg(struct shaper *s) { - msg(M_INFO, "Output Traffic Shaping initialized at %d bytes per second= ", - s->bytes_per_second); + msg(M_INFO, "Output Traffic Shaping initialized at %d bytes per second= ", s->bytes_per_second); } diff --git a/src/openvpn/shaper.h b/src/openvpn/shaper.h index 2b3eeb9..b53d4ad 100644 --- a/src/openvpn/shaper.h +++ b/src/openvpn/shaper.h @@ -37,10 +37,10 @@ * the output direction. */ -#define SHAPER_MIN 100 /* bytes per second */ +#define SHAPER_MIN 100 /* bytes per second */ #define SHAPER_MAX 100000000 -#define SHAPER_MAX_TIMEOUT 10 /* seconds */ +#define SHAPER_MAX_TIMEOUT 10 /* seconds */ #define SHAPER_USE_FP @@ -126,11 +126,12 @@ /* compute delay in microseconds */ tv.tv_sec =3D 0; #ifdef SHAPER_USE_FP - tv.tv_usec =3D min_int((int)((double)max_int(nbytes, 100) * s->factor)= , (SHAPER_MAX_TIMEOUT*1000000)); + tv.tv_usec =3D + min_int((int)((double)max_int(nbytes, 100) * s->factor), (SHAPER_M= AX_TIMEOUT * 1000000)); #else tv.tv_usec =3D s->bytes_per_second - ? min_int(max_int(nbytes, 100) * s->factor, (SHAPER_MAX_T= IMEOUT*1000000)) - : 0; + ? min_int(max_int(nbytes, 100) * s->factor, (SHAPER_M= AX_TIMEOUT * 1000000)) + : 0; #endif if (tv.tv_usec) @@ -139,11 +140,9 @@ tv_add(&s->wakeup, &tv); #ifdef SHAPER_DEBUG - dmsg(D_SHAPER_DEBUG, "SHAPER shaper_wrote_bytes bytes=3D%d delay= =3D%ld sec=3D%" PRIi64 " usec=3D%ld", - nbytes, - (long)tv.tv_usec, - (int64_t)s->wakeup.tv_sec, - (long)s->wakeup.tv_usec); + dmsg(D_SHAPER_DEBUG, + "SHAPER shaper_wrote_bytes bytes=3D%d delay=3D%ld sec=3D%" PR= Ii64 " usec=3D%ld", nbytes, + (long)tv.tv_usec, (int64_t)s->wakeup.tv_sec, (long)s->wakeup.= tv_usec); #endif } } diff --git a/src/openvpn/sig.c b/src/openvpn/sig.c index 9334b10..8adfeb2 100644 --- a/src/openvpn/sig.c +++ b/src/openvpn/sig.c @@ -44,20 +44,19 @@ struct signal_info siginfo_static; /* GLOBAL */ -struct signame { +struct signame +{ int value; int priority; const char *upper; const char *lower; }; -static const struct signame signames[] =3D { - { SIGINT, 5, "SIGINT", "sigint"}, - { SIGTERM, 4, "SIGTERM", "sigterm" }, - { SIGHUP, 3, "SIGHUP", "sighup" }, - { SIGUSR1, 2, "SIGUSR1", "sigusr1" }, - { SIGUSR2, 1, "SIGUSR2", "sigusr2" } -}; +static const struct signame signames[] =3D { { SIGINT, 5, "SIGINT", "sigin= t" }, + { SIGTERM, 4, "SIGTERM", "sigte= rm" }, + { SIGHUP, 3, "SIGHUP", "sighup"= }, + { SIGUSR1, 2, "SIGUSR1", "sigus= r1" }, + { SIGUSR2, 1, "SIGUSR2", "sigus= r2" } }; /* mask for hard signals from management or windows */ static unsigned long long ignored_hard_signals_mask; @@ -210,8 +209,7 @@ if (try_throw_signal(&siginfo_static, signum, SIG_SOURCE_SOFT)) { siginfo_static.signal_text =3D signal_text; - msg(D_SIGNAL_DEBUG, "Throw signal (soft): %s (%s)", signal_name(si= gnum, true), - signal_text); + msg(D_SIGNAL_DEBUG, "Throw signal (soft): %s (%s)", signal_name(si= gnum, true), signal_text); } else { @@ -242,8 +240,7 @@ { si->source =3D SIG_SOURCE_CONNECTION_FAILED; } - msg(D_SIGNAL_DEBUG, "register signal: %s (%s)", signal_name(signum= , true), - signal_text); + msg(D_SIGNAL_DEBUG, "register signal: %s (%s)", signal_name(signum= , true), signal_text); } else { @@ -331,7 +328,8 @@ break; default: - msg(msglevel, "Unknown signal %d [%s,%s] received by %s", = si->signal_received, hs, type, t); + msg(msglevel, "Unknown signal %d [%s,%s] received by %s", = si->signal_received, hs, + type, t); break; } } @@ -366,13 +364,10 @@ if (state >=3D 0) { - management_set_state(management, - state, - si->signal_text ? si->signal_text : signa= l_name(si->signal_received, true), - NULL, - NULL, - NULL, - NULL); + management_set_state(management, state, + si->signal_text ? si->signal_text + : signal_name(si->signal_= received, true), + NULL, NULL, NULL, NULL); } } #endif /* ifdef ENABLE_MANAGEMENT */ @@ -402,7 +397,7 @@ struct sigaction sa; CLEAR(sa); - sigfillset(&block_mask); /* all signals */ + sigfillset(&block_mask); /* all signals */ sa.sa_handler =3D signal_handler; sa.sa_mask =3D block_mask; /* signals blocked inside the handler */ sa.sa_flags =3D SA_RESTART; /* match with the behaviour of signal() on= Linux and BSD */ @@ -431,9 +426,9 @@ struct sigaction sa; CLEAR(sa); - sigfillset(&block_mask); /* all signals */ + sigfillset(&block_mask); /* all signals */ sa.sa_handler =3D signal_handler; - sa.sa_mask =3D block_mask; /* signals blocked inside the handler */ + sa.sa_mask =3D block_mask; /* signals blocked inside the handler */ sa.sa_flags =3D SA_RESTART; /* match with the behaviour of signal() on= Linux and BSD */ signal_mode =3D SM_POST_INIT; @@ -499,8 +494,10 @@ status_printf(so, "Updated,%s", time_string(0, 0, false, &gc)); status_printf(so, "TUN/TAP read bytes," counter_format, c->c2.tun_read= _bytes); status_printf(so, "TUN/TAP write bytes," counter_format, c->c2.tun_wri= te_bytes); - status_printf(so, "TCP/UDP read bytes," counter_format, c->c2.link_rea= d_bytes + c->c2.dco_read_bytes); - status_printf(so, "TCP/UDP write bytes," counter_format, c->c2.link_wr= ite_bytes + c->c2.dco_write_bytes); + status_printf(so, "TCP/UDP read bytes," counter_format, + c->c2.link_read_bytes + c->c2.dco_read_bytes); + status_printf(so, "TCP/UDP write bytes," counter_format, + c->c2.link_write_bytes + c->c2.dco_write_bytes); status_printf(so, "Auth read bytes," counter_format, c->c2.link_read_b= ytes_auth); #ifdef USE_COMP if (c->c2.comp_context) @@ -566,12 +563,13 @@ void process_explicit_exit_notification_timer_wakeup(struct context *c) { - if (event_timeout_trigger(&c->c2.explicit_exit_notification_interval, - &c->c2.timeval, + if (event_timeout_trigger(&c->c2.explicit_exit_notification_interval, = &c->c2.timeval, ETT_DEFAULT)) { - ASSERT(c->c2.explicit_exit_notification_time_wait && c->options.ce= .explicit_exit_notification); - if (now >=3D c->c2.explicit_exit_notification_time_wait + c->optio= ns.ce.explicit_exit_notification) + ASSERT(c->c2.explicit_exit_notification_time_wait + && c->options.ce.explicit_exit_notification); + if (now >=3D c->c2.explicit_exit_notification_time_wait + + c->options.ce.explicit_exit_notification) { event_timeout_clear(&c->c2.explicit_exit_notification_interval= ); register_signal(c->sig, SIGTERM, "exit-with-notification"); @@ -609,8 +607,7 @@ process_sigterm(struct context *c) { bool ret =3D true; - if (c->options.ce.explicit_exit_notification - && !c->c2.explicit_exit_notification_time_wait) + if (c->options.ce.explicit_exit_notification && !c->c2.explicit_exit_n= otification_time_wait) { process_explicit_exit_notification_init(c); ret =3D false; diff --git a/src/openvpn/sig.h b/src/openvpn/sig.h index fe81af9..bd1a895 100644 --- a/src/openvpn/sig.h +++ b/src/openvpn/sig.h @@ -27,8 +27,8 @@ #include "status.h" #include "win32.h" -#define SIG_SOURCE_SOFT 0 -#define SIG_SOURCE_HARD 1 +#define SIG_SOURCE_SOFT 0 +#define SIG_SOURCE_HARD 1 /* CONNECTION_FAILED is also a "soft" status, * It is thrown if a connection attempt fails */ diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 980d8b4..62e7ae4 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -61,8 +61,7 @@ * Convert sockflags/getaddr_flags into getaddr_flags */ static unsigned int -sf2gaf(const unsigned int getaddr_flags, - const unsigned int sockflags) +sf2gaf(const unsigned int getaddr_flags, const unsigned int sockflags) { if (sockflags & SF_HOST_RANDOMIZE) { @@ -78,9 +77,8 @@ * Functions related to the translation of DNS names to IP addresses. */ static int -get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname, - void *network, unsigned int *netbits, - int resolve_retry_seconds, struct signal_info *sig_info, +get_addr_generic(sa_family_t af, unsigned int flags, const char *hostname,= void *network, + unsigned int *netbits, int resolve_retry_seconds, struct = signal_info *sig_info, int msglevel) { char *endp, *sep, *var_host =3D NULL; @@ -109,9 +107,7 @@ break; default: - msg(M_WARN, - "Unsupported AF family passed to getaddrinfo for %s (%d)", - hostname, af); + msg(M_WARN, "Unsupported AF family passed to getaddrinfo for %= s (%d)", hostname, af); goto out; } @@ -123,8 +119,7 @@ var_host =3D strdup(hostname); if (!var_host) { - msg(M_NONFATAL | M_ERRNO, - "Can't allocate hostname buffer for getaddrinfo"); + msg(M_NONFATAL | M_ERRNO, "Can't allocate hostname buffer for geta= ddrinfo"); goto out; } @@ -135,15 +130,14 @@ bits =3D strtoul(sep + 1, &endp, 10); if ((*endp !=3D '\0') || (bits > max_bits)) { - msg(msglevel, "IP prefix '%s': invalid '/bits' spec (%s)", hos= tname, - sep + 1); + msg(msglevel, "IP prefix '%s': invalid '/bits' spec (%s)", hos= tname, sep + 1); goto out; } *sep =3D '\0'; } - ret =3D openvpn_getaddrinfo(flags & ~GETADDR_HOST_ORDER, var_host, NUL= L, - resolve_retry_seconds, sig_info, af, &ai); + ret =3D openvpn_getaddrinfo(flags & ~GETADDR_HOST_ORDER, var_host, NUL= L, resolve_retry_seconds, + sig_info, af, &ai); if ((ret =3D=3D 0) && network) { struct in6_addr *ip6; @@ -168,8 +162,7 @@ default: /* can't get here because 'af' was previously checked */ - msg(M_WARN, - "Unsupported AF family for %s (%d)", var_host, af); + msg(M_WARN, "Unsupported AF family for %s (%d)", var_host,= af); goto out; } } @@ -192,19 +185,15 @@ } in_addr_t -getaddr(unsigned int flags, - const char *hostname, - int resolve_retry_seconds, - bool *succeeded, +getaddr(unsigned int flags, const char *hostname, int resolve_retry_second= s, bool *succeeded, struct signal_info *sig_info) { in_addr_t addr; int status; - status =3D get_addr_generic(AF_INET, flags, hostname, &addr, NULL, - resolve_retry_seconds, sig_info, - M_WARN); - if (status=3D=3D0) + status =3D get_addr_generic(AF_INET, flags, hostname, &addr, NULL, res= olve_retry_seconds, + sig_info, M_WARN); + if (status =3D=3D 0) { if (succeeded) { @@ -223,16 +212,15 @@ } bool -get_ipv6_addr(const char *hostname, struct in6_addr *network, - unsigned int *netbits, int msglevel) +get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int= *netbits, int msglevel) { - if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, net= bits, - 0, NULL, msglevel) < 0) + if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostname, network, net= bits, 0, NULL, msglevel) + < 0) { return false; } - return true; /* parsing OK, values set */ + return true; /* parsing OK, values set */ } static inline bool @@ -257,12 +245,8 @@ * otherwise. (like getaddrinfo) */ static int -get_cached_dns_entry(struct cached_dns_entry *dns_cache, - const char *hostname, - const char *servname, - int ai_family, - int resolve_flags, - struct addrinfo **ai) +get_cached_dns_entry(struct cached_dns_entry *dns_cache, const char *hostn= ame, const char *servname, + int ai_family, int resolve_flags, struct addrinfo **a= i) { struct cached_dns_entry *ph; int flags; @@ -272,10 +256,8 @@ for (ph =3D dns_cache; ph; ph =3D ph->next) { - if (streqnull(ph->hostname, hostname) - && streqnull(ph->servname, servname) - && ph->ai_family =3D=3D ai_family - && ph->flags =3D=3D flags) + if (streqnull(ph->hostname, hostname) && streqnull(ph->servname, s= ervname) + && ph->ai_family =3D=3D ai_family && ph->flags =3D=3D flags) { *ai =3D ph->ai; return 0; @@ -286,28 +268,19 @@ static int -do_preresolve_host(struct context *c, - const char *hostname, - const char *servname, - const int af, +do_preresolve_host(struct context *c, const char *hostname, const char *se= rvname, const int af, const int flags) { struct addrinfo *ai; int status; - if (get_cached_dns_entry(c->c1.dns_cache, - hostname, - servname, - af, - flags, - &ai) =3D=3D 0) + if (get_cached_dns_entry(c->c1.dns_cache, hostname, servname, af, flag= s, &ai) =3D=3D 0) { /* entry already cached, return success */ return 0; } - status =3D openvpn_getaddrinfo(flags, hostname, servname, - c->options.resolve_retry_seconds, NULL, + status =3D openvpn_getaddrinfo(flags, hostname, servname, c->options.r= esolve_retry_seconds, NULL, af, &ai); if (status =3D=3D 0) { @@ -334,7 +307,6 @@ } gc_addspecial(ai, &gc_freeaddrinfo_callback, &c->gc); - } return status; } @@ -343,10 +315,8 @@ do_preresolve(struct context *c) { struct connection_list *l =3D c->options.connection_list; - const unsigned int preresolve_flags =3D GETADDR_RESOLVE - |GETADDR_UPDATE_MANAGEMENT_STATE - |GETADDR_MENTION_RESOLVE_RETRY - |GETADDR_FATAL; + const unsigned int preresolve_flags =3D GETADDR_RESOLVE | GETADDR_UPDA= TE_MANAGEMENT_STATE + | GETADDR_MENTION_RESOLVE_RETRY = | GETADDR_FATAL; for (int i =3D 0; i < l->len; ++i) @@ -379,8 +349,7 @@ /* HTTP remote hostname does not need to be resolved */ if (!ce->http_proxy_options) { - status =3D do_preresolve_host(c, remote, ce->remote_port, - ce->af, flags); + status =3D do_preresolve_host(c, remote, ce->remote_port, ce->= af, flags); if (status !=3D 0) { goto err; @@ -390,11 +359,8 @@ /* Preresolve proxy */ if (ce->http_proxy_options) { - status =3D do_preresolve_host(c, - ce->http_proxy_options->server, - ce->http_proxy_options->port, - ce->af, - preresolve_flags); + status =3D do_preresolve_host(c, ce->http_proxy_options->serve= r, + ce->http_proxy_options->port, ce->= af, preresolve_flags); if (status !=3D 0) { @@ -404,11 +370,8 @@ if (ce->socks_proxy_server) { - status =3D do_preresolve_host(c, - ce->socks_proxy_server, - ce->socks_proxy_port, - ce->af, - flags); + status =3D + do_preresolve_host(c, ce->socks_proxy_server, ce->socks_pr= oxy_port, ce->af, flags); if (status !=3D 0) { goto err; @@ -434,10 +397,8 @@ { goto err; } - } } - } return; @@ -454,9 +415,11 @@ { switch (af) { - case AF_INET: return "[AF_INET]"; + case AF_INET: + return "[AF_INET]"; - case AF_INET6: return "[AF_INET6]"; + case AF_INET6: + return "[AF_INET6]"; } return ""; } @@ -466,17 +429,13 @@ * If resolve error, try again for resolve_retry_seconds seconds. */ int -openvpn_getaddrinfo(unsigned int flags, - const char *hostname, - const char *servname, - int resolve_retry_seconds, - struct signal_info *sig_info, - int ai_family, +openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *= servname, + int resolve_retry_seconds, struct signal_info *sig_inf= o, int ai_family, struct addrinfo **res) { struct addrinfo hints; int status; - struct signal_info sigrec =3D {0}; + struct signal_info sigrec =3D { 0 }; int msglevel =3D (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS; struct gc_arena gc =3D gc_new(); const char *print_hostname; @@ -501,8 +460,7 @@ msglevel |=3D M_MSG_VIRT_OUT; } - if ((flags & (GETADDR_FATAL_ON_SIGNAL|GETADDR_WARN_ON_SIGNAL)) - && !sig_info) + if ((flags & (GETADDR_FATAL_ON_SIGNAL | GETADDR_WARN_ON_SIGNAL)) && !s= ig_info) { sig_info =3D &sigrec; } @@ -534,12 +492,12 @@ status =3D getaddrinfo(hostname, servname, &hints, res); - if (status !=3D 0) /* parse as numeric address failed? */ + if (status !=3D 0) /* parse as numeric address fa= iled? */ { const int fail_wait_interval =3D 5; /* seconds */ /* Add +4 to cause integer division rounding up (1 + 4) =3D 5, (0+= 4)/5=3D0 */ - int resolve_retries =3D (flags & GETADDR_TRY_ONCE) ? 1 : - ((resolve_retry_seconds + 4)/ fail_wait_inte= rval); + int resolve_retries =3D + (flags & GETADDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) = / fail_wait_interval); const char *fmt; int level =3D 0; @@ -562,8 +520,7 @@ } fmt =3D "RESOLVE: Cannot resolve host address: %s:%s%s (%s)"; - if ((flags & GETADDR_MENTION_RESOLVE_RETRY) - && !resolve_retry_seconds) + if ((flags & GETADDR_MENTION_RESOLVE_RETRY) && !resolve_retry_seco= nds) { fmt =3D "RESOLVE: Cannot resolve host address: %s:%s%s (%s)" "(I would have retried this name query if you had " @@ -572,8 +529,8 @@ if (!(flags & GETADDR_RESOLVE) || status =3D=3D EAI_FAIL) { - msg(msglevel, "RESOLVE: Cannot parse IP address: %s:%s (%s)", - print_hostname, print_servname, gai_strerror(status)); + msg(msglevel, "RESOLVE: Cannot parse IP address: %s:%s (%s)", = print_hostname, + print_servname, gai_strerror(status)); goto done; } @@ -582,12 +539,7 @@ { if (management) { - management_set_state(management, - OPENVPN_STATE_RESOLVE, - NULL, - NULL, - NULL, - NULL, + management_set_state(management, OPENVPN_STATE_RESOLVE, NU= LL, NULL, NULL, NULL, NULL); } } @@ -604,9 +556,8 @@ #endif /* try hostname lookup */ hints.ai_flags &=3D ~AI_NUMERICHOST; - dmsg(D_SOCKET_DEBUG, - "GETADDRINFO flags=3D0x%04x ai_family=3D%d ai_socktype=3D= %d", - flags, hints.ai_family, hints.ai_socktype); + dmsg(D_SOCKET_DEBUG, "GETADDRINFO flags=3D0x%04x ai_family=3D%= d ai_socktype=3D%d", flags, + hints.ai_family, hints.ai_socktype); status =3D getaddrinfo(hostname, servname, &hints, res); if (sig_info) @@ -617,9 +568,8 @@ /* why are we overwriting SIGUSR1 ? */ if (signal_reset(sig_info, SIGUSR1) =3D=3D SIGUSR1) /*= ignore SIGUSR1 */ { - msg(level, - "RESOLVE: Ignored SIGUSR1 signal received duri= ng " - "DNS resolution attempt"); + msg(level, "RESOLVE: Ignored SIGUSR1 signal receiv= ed during " + "DNS resolution attempt"); } else { @@ -651,11 +601,7 @@ level =3D D_RESOLVE_ERRORS; } - msg(level, - fmt, - print_hostname, - print_servname, - getaddrinfo_addr_family_name(ai_family), + msg(level, fmt, print_hostname, print_servname, getaddrinfo_ad= dr_family_name(ai_family), gai_strerror(status)); if (--resolve_retries <=3D 0) @@ -680,9 +626,8 @@ /* IP address parse succeeded */ if (flags & GETADDR_RANDOMIZE) { - msg(M_WARN, - "WARNING: ignoring --remote-random-hostname because the " - "hostname is an IP address"); + msg(M_WARN, "WARNING: ignoring --remote-random-hostname becaus= e the " + "hostname is an IP address"); } } @@ -719,11 +664,11 @@ { if (a < 256 && b < 256 && c < 256 && d < 256) { - addr->s_addr =3D htonl(a<<24 | b<<16 | c<<8 | d); + addr->s_addr =3D htonl(a << 24 | b << 16 | c << 8 | d); return OIA_IP; /* good dotted quad */ } } - if (string_class(dotted_quad, CC_DIGIT|CC_DOT, 0)) + if (string_class(dotted_quad, CC_DIGIT | CC_DOT, 0)) { return OIA_ERROR; /* probably a badly formatted dotted quad */ } @@ -801,7 +746,7 @@ /* verify that string will convert to IPv6 address */ { struct in6_addr a6; - return inet_pton( AF_INET6, ipv6_text_addr, &a6 ) =3D=3D 1; + return inet_pton(AF_INET6, ipv6_text_addr, &a6) =3D=3D 1; } } @@ -811,7 +756,7 @@ if (addr) { const size_t len =3D strlen(addr); - return len > 0 && len <=3D 255 && string_class(addr, CC_ALNUM|CC_D= ASH|CC_DOT, 0); + return len > 0 && len <=3D 255 && string_class(addr, CC_ALNUM | CC= _DASH | CC_DOT, 0); } else { @@ -860,7 +805,7 @@ while ((c =3D *p++)) { - if ( (c >=3D '0' && c <=3D '9') || (c >=3D 'a' && c <=3D 'f') = || (c >=3D 'A' && c <=3D 'F') ) + if ((c >=3D '0' && c <=3D '9') || (c >=3D 'a' && c <=3D 'f') |= | (c >=3D 'A' && c <=3D 'F')) { ++nnum; if (nnum > 2) @@ -891,8 +836,7 @@ socklen_t len; len =3D sizeof(val); - if (getsockopt(sd, SOL_SOCKET, SO_SNDBUF, (void *) &val, &len) =3D=3D 0 - && len =3D=3D sizeof(val)) + if (getsockopt(sd, SOL_SOCKET, SO_SNDBUF, (void *)&val, &len) =3D=3D 0= && len =3D=3D sizeof(val)) { return val; } @@ -904,7 +848,7 @@ socket_set_sndbuf(socket_descriptor_t sd, int size) { #if defined(SOL_SOCKET) && defined(SO_SNDBUF) - if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (void *) &size, sizeof(size)= ) !=3D 0) + if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (void *)&size, sizeof(size))= !=3D 0) { msg(M_WARN, "NOTE: setsockopt SO_SNDBUF=3D%d failed", size); } @@ -919,8 +863,7 @@ socklen_t len; len =3D sizeof(val); - if (getsockopt(sd, SOL_SOCKET, SO_RCVBUF, (void *) &val, &len) =3D=3D 0 - && len =3D=3D sizeof(val)) + if (getsockopt(sd, SOL_SOCKET, SO_RCVBUF, (void *)&val, &len) =3D=3D 0= && len =3D=3D sizeof(val)) { return val; } @@ -932,7 +875,7 @@ socket_set_rcvbuf(socket_descriptor_t sd, int size) { #if defined(SOL_SOCKET) && defined(SO_RCVBUF) - if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (void *) &size, sizeof(size)= ) !=3D 0) + if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (void *)&size, sizeof(size))= !=3D 0) { msg(M_WARN, "NOTE: setsockopt SO_RCVBUF=3D%d failed", size); return false; @@ -942,31 +885,25 @@ } void -socket_set_buffers(socket_descriptor_t fd, const struct socket_buffer_size= *sbs, - bool reduce_size) +socket_set_buffers(socket_descriptor_t fd, const struct socket_buffer_size= *sbs, bool reduce_size) { if (sbs) { const int sndbuf_old =3D socket_get_sndbuf(fd); const int rcvbuf_old =3D socket_get_rcvbuf(fd); - if (sbs->sndbuf - && (reduce_size || sndbuf_old < sbs->sndbuf)) + if (sbs->sndbuf && (reduce_size || sndbuf_old < sbs->sndbuf)) { socket_set_sndbuf(fd, sbs->sndbuf); } - if (sbs->rcvbuf - && (reduce_size || rcvbuf_old < sbs->rcvbuf)) + if (sbs->rcvbuf && (reduce_size || rcvbuf_old < sbs->rcvbuf)) { socket_set_rcvbuf(fd, sbs->rcvbuf); } - msg(D_OSBUF, "Socket Buffers: R=3D[%d->%d] S=3D[%d->%d]", - rcvbuf_old, - socket_get_rcvbuf(fd), - sndbuf_old, - socket_get_sndbuf(fd)); + msg(D_OSBUF, "Socket Buffers: R=3D[%d->%d] S=3D[%d->%d]", rcvbuf_o= ld, socket_get_rcvbuf(fd), + sndbuf_old, socket_get_sndbuf(fd)); } } @@ -978,7 +915,7 @@ socket_set_tcp_nodelay(socket_descriptor_t sd, int state) { #if defined(_WIN32) || (defined(IPPROTO_TCP) && defined(TCP_NODELAY)) - if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (void *) &state, sizeof(s= tate)) !=3D 0) + if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (void *)&state, sizeof(st= ate)) !=3D 0) { msg(M_WARN, "NOTE: setsockopt TCP_NODELAY=3D%d failed", state); return false; @@ -988,7 +925,7 @@ dmsg(D_OSBUF, "Socket flags: TCP_NODELAY=3D%d succeeded", state); return true; } -#else /* if defined(_WIN32) || (defined(IPPROTO_TCP) && defined(TCP_NODEL= AY)) */ +#else /* if defined(_WIN32) || (defined(IPPROTO_TCP) && defined(TCP_NODELA= Y)) */ msg(M_WARN, "NOTE: setsockopt TCP_NODELAY=3D%d failed (No kernel suppo= rt)", state); return false; #endif @@ -998,7 +935,7 @@ socket_set_mark(socket_descriptor_t sd, int mark) { #if defined(TARGET_LINUX) && HAVE_DECL_SO_MARK - if (mark && setsockopt(sd, SOL_SOCKET, SO_MARK, (void *) &mark, sizeof= (mark)) !=3D 0) + if (mark && setsockopt(sd, SOL_SOCKET, SO_MARK, (void *)&mark, sizeof(= mark)) !=3D 0) { msg(M_WARN, "NOTE: setsockopt SO_MARK=3D%d failed", mark); } @@ -1066,8 +1003,7 @@ /* set SO_REUSEADDR on socket */ { int on =3D 1; - if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, - (void *) &on, sizeof(on)) < 0) + if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(o= n)) < 0) { msg(M_ERR, "TCP: Cannot setsockopt SO_REUSEADDR on TCP socket"= ); } @@ -1100,31 +1036,29 @@ if (addrinfo->ai_family =3D=3D AF_INET) { #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) - if (setsockopt(sd, SOL_IP, IP_PKTINFO, - (void *)&pad, sizeof(pad)) < 0) + if (setsockopt(sd, SOL_IP, IP_PKTINFO, (void *)&pad, sizeof(pa= d)) < 0) { msg(M_ERR, "UDP: failed setsockopt for IP_PKTINFO"); } #elif defined(IP_RECVDSTADDR) - if (setsockopt(sd, IPPROTO_IP, IP_RECVDSTADDR, - (void *)&pad, sizeof(pad)) < 0) + if (setsockopt(sd, IPPROTO_IP, IP_RECVDSTADDR, (void *)&pad, s= izeof(pad)) < 0) { msg(M_ERR, "UDP: failed setsockopt for IP_RECVDSTADDR"); } -#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ +#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix= syshead.h) #endif } else if (addrinfo->ai_family =3D=3D AF_INET6) { #ifndef IPV6_RECVPKTINFO /* Some older Darwin platforms require this */ - if (setsockopt(sd, IPPROTO_IPV6, IPV6_PKTINFO, - (void *)&pad, sizeof(pad)) < 0) + if (setsockopt(sd, IPPROTO_IPV6, IPV6_PKTINFO, (void *)&pad, s= izeof(pad)) < 0) #else - if (setsockopt(sd, IPPROTO_IPV6, IPV6_RECVPKTINFO, - (void *)&pad, sizeof(pad)) < 0) + if (setsockopt(sd, IPPROTO_IPV6, IPV6_RECVPKTINFO, (void *)&pa= d, sizeof(pad)) < 0) #endif - { msg(M_ERR, "UDP: failed setsockopt for IPV6_RECVPKTINFO");} + { + msg(M_ERR, "UDP: failed setsockopt for IPV6_RECVPKTINFO"); + } } } #endif /* if ENABLE_IP_PKTINFO */ @@ -1144,14 +1078,12 @@ { if (sock->socks_proxy && sock->info.proto =3D=3D PROTO_UDP) { - socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local, - ai_family, "SOCKS", false); + socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local, ai_fami= ly, "SOCKS", false); } else { - socket_bind(sock->sd, sock->info.lsa->bind_local, - ai_family, - "TCP/UDP", sock->info.bind_ipv6_only); + socket_bind(sock->sd, sock->info.lsa->bind_local, ai_family, "= TCP/UDP", + sock->info.bind_ipv6_only); } } } @@ -1199,11 +1131,12 @@ if (sock->bind_dev) { msg(M_INFO, "Using bind-dev %s", sock->bind_dev); - if (setsockopt(sock->sd, SOL_SOCKET, SO_BINDTODEVICE, sock->bind_d= ev, strlen(sock->bind_dev) + 1) !=3D 0) + if (setsockopt(sock->sd, SOL_SOCKET, SO_BINDTODEVICE, sock->bind_d= ev, + strlen(sock->bind_dev) + 1) + !=3D 0) { - msg(M_WARN|M_ERRNO, "WARN: setsockopt SO_BINDTODEVICE=3D%s fai= led", sock->bind_dev); + msg(M_WARN | M_ERRNO, "WARN: setsockopt SO_BINDTODEVICE=3D%s f= ailed", sock->bind_dev); } - } #endif @@ -1238,9 +1171,7 @@ * Functions used for establishing a TCP stream connection. */ static void -socket_do_listen(socket_descriptor_t sd, - const struct addrinfo *local, - bool do_listen, +socket_do_listen(socket_descriptor_t sd, const struct addrinfo *local, boo= l do_listen, bool do_set_nonblock) { struct gc_arena gc =3D gc_new(); @@ -1265,9 +1196,7 @@ } socket_descriptor_t -socket_do_accept(socket_descriptor_t sd, - struct link_socket_actual *act, - const bool nowait) +socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, c= onst bool nowait) { /* af_addr_size WILL return 0 in this case if AFs other than AF_INET * are compiled because act is empty here. @@ -1315,7 +1244,8 @@ /* only valid if we have remote_len_af!=3D0 */ else if (remote_len_af && remote_len !=3D remote_len_af) { - msg(D_LINK_ERRORS, "TCP: Received strange incoming connection with= unknown address length=3D%d", remote_len); + msg(D_LINK_ERRORS, + "TCP: Received strange incoming connection with unknown addres= s length=3D%d", remote_len); openvpn_close_socket(new_sd); new_sd =3D SOCKET_UNDEFINED; } @@ -1332,19 +1262,14 @@ tcp_connection_established(const struct link_socket_actual *act) { struct gc_arena gc =3D gc_new(); - msg(M_INFO, "TCP connection established with %s", - print_link_socket_actual(act, &gc)); + msg(M_INFO, "TCP connection established with %s", print_link_socket_ac= tual(act, &gc)); gc_free(&gc); } static socket_descriptor_t -socket_listen_accept(socket_descriptor_t sd, - struct link_socket_actual *act, - const char *remote_dynamic, - const struct addrinfo *local, - bool do_listen, - bool nowait, - volatile int *signal_received) +socket_listen_accept(socket_descriptor_t sd, struct link_socket_actual *ac= t, + const char *remote_dynamic, const struct addrinfo *lo= cal, bool do_listen, + bool nowait, volatile int *signal_received) { struct gc_arena gc =3D gc_new(); /* struct openvpn_sockaddr *remote =3D &act->dest; */ @@ -1398,8 +1323,7 @@ if (ai && !addrlist_match(&remote_verify, ai)) { - msg(M_WARN, - "TCP NOTE: Rejected connection attempt from %s due to = --remote setting", + msg(M_WARN, "TCP NOTE: Rejected connection attempt from %s= due to --remote setting", print_link_socket_actual(act, &gc)); if (openvpn_close_socket(new_sd)) { @@ -1431,10 +1355,7 @@ } void -socket_bind(socket_descriptor_t sd, - struct addrinfo *local, - int ai_family, - const char *prefix, +socket_bind(socket_descriptor_t sd, struct addrinfo *local, int ai_family,= const char *prefix, bool ipv6only) { struct gc_arena gc =3D gc_new(); @@ -1461,33 +1382,30 @@ } if (!cur) { - msg(M_FATAL, "%s: Socket bind failed: Addr to bind has no %s recor= d", - prefix, addr_family_name(ai_family)); + msg(M_FATAL, "%s: Socket bind failed: Addr to bind has no %s recor= d", prefix, + addr_family_name(ai_family)); } if (ai_family =3D=3D AF_INET6) { - int v6only =3D ipv6only ? 1 : 0; /* setsockopt must have an "int"= */ + int v6only =3D ipv6only ? 1 : 0; /* setsockopt must have an "int" = */ msg(M_INFO, "setsockopt(IPV6_V6ONLY=3D%d)", v6only); - if (setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, (void *) &v6only, si= zeof(v6only))) + if (setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&v6only, siz= eof(v6only))) { - msg(M_NONFATAL|M_ERRNO, "Setting IPV6_V6ONLY=3D%d failed", v6o= nly); + msg(M_NONFATAL | M_ERRNO, "Setting IPV6_V6ONLY=3D%d failed", v= 6only); } } if (bind(sd, cur->ai_addr, cur->ai_addrlen)) { - msg(M_FATAL | M_ERRNO, "%s: Socket bind failed on local address %s= ", - prefix, + msg(M_FATAL | M_ERRNO, "%s: Socket bind failed on local address %s= ", prefix, print_sockaddr_ex(local->ai_addr, ":", PS_SHOW_PORT, &gc)); } gc_free(&gc); } int -openvpn_connect(socket_descriptor_t sd, - const struct sockaddr *remote, - int connect_timeout, +openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int= connect_timeout, volatile int *signal_received) { int status =3D 0; @@ -1507,7 +1425,7 @@ #else status =3D=3D EINPROGRESS #endif - ) + ) { while (true) { @@ -1562,7 +1480,7 @@ socklen_t len; len =3D sizeof(val); - if (getsockopt(sd, SOL_SOCKET, SO_ERROR, (void *) &val, &l= en) =3D=3D 0 + if (getsockopt(sd, SOL_SOCKET, SO_ERROR, (void *)&val, &le= n) =3D=3D 0 && len =3D=3D sizeof(val)) { status =3D val; @@ -1587,43 +1505,31 @@ if (ai->ai_family =3D=3D AF_INET) { - actual->dest.addr.in4 =3D - *((struct sockaddr_in *) ai->ai_addr); + actual->dest.addr.in4 =3D *((struct sockaddr_in *)ai->ai_addr); } else if (ai->ai_family =3D=3D AF_INET6) { - actual->dest.addr.in6 =3D - *((struct sockaddr_in6 *) ai->ai_addr); + actual->dest.addr.in6 =3D *((struct sockaddr_in6 *)ai->ai_addr); } else { ASSERT(0); } - } static void -socket_connect(socket_descriptor_t *sd, - const struct sockaddr *dest, - const int connect_timeout, +socket_connect(socket_descriptor_t *sd, const struct sockaddr *dest, const= int connect_timeout, struct signal_info *sig_info) { struct gc_arena gc =3D gc_new(); int status; - msg(M_INFO, "Attempting to establish TCP connection with %s", - print_sockaddr(dest, &gc)); + msg(M_INFO, "Attempting to establish TCP connection with %s", print_so= ckaddr(dest, &gc)); #ifdef ENABLE_MANAGEMENT if (management) { - management_set_state(management, - OPENVPN_STATE_TCP_CONNECT, - NULL, - NULL, - NULL, - NULL, - NULL); + management_set_state(management, OPENVPN_STATE_TCP_CONNECT, NULL, = NULL, NULL, NULL, NULL); } #endif @@ -1638,9 +1544,8 @@ if (status) { - - msg(D_LINK_ERRORS, "TCP: connect to %s failed: %s", - print_sockaddr(dest, &gc), strerror(status)); + msg(D_LINK_ERRORS, "TCP: connect to %s failed: %s", print_sockaddr= (dest, &gc), + strerror(status)); openvpn_close_socket(*sd); *sd =3D SOCKET_UNDEFINED; @@ -1648,8 +1553,7 @@ } else { - msg(M_INFO, "TCP connection established with %s", - print_sockaddr(dest, &gc)); + msg(M_INFO, "TCP connection established with %s", print_sockaddr(d= est, &gc)); } done: @@ -1662,15 +1566,12 @@ * such as TCP. */ -static void -stream_buf_init(struct stream_buf *sb, struct buffer *buf, - const unsigned int sockflags, const int proto); +static void stream_buf_init(struct stream_buf *sb, struct buffer *buf, con= st unsigned int sockflags, + const int proto); -static void -stream_buf_close(struct stream_buf *sb); +static void stream_buf_close(struct stream_buf *sb); -static bool -stream_buf_added(struct stream_buf *sb, int length_added); +static bool stream_buf_added(struct stream_buf *sb, int length_added); /* For stream protocols, allocate a buffer to build up packet. * Called after frame has been finalized. */ @@ -1688,16 +1589,12 @@ if (link_socket_connection_oriented(sock)) { #ifdef _WIN32 - stream_buf_init(&sock->stream_buf, - &sock->reads.buf_init, - sock->sockflags, + stream_buf_init(&sock->stream_buf, &sock->reads.buf_init, sock->so= ckflags, sock->info.proto); #else alloc_buf_sock_tun(&sock->stream_buf_data, frame); - stream_buf_init(&sock->stream_buf, - &sock->stream_buf_data, - sock->sockflags, + stream_buf_init(&sock->stream_buf, &sock->stream_buf_data, sock->s= ockflags, sock->info.proto); #endif } @@ -1711,8 +1608,7 @@ /* resolve local address if undefined */ if (!sock->info.lsa->bind_local) { - int flags =3D GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL - |GETADDR_FATAL | GETADDR_PASSIVE; + int flags =3D GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL | GETADDR_F= ATAL | GETADDR_PASSIVE; int status; if (proto_is_dgram(sock->info.proto)) @@ -1721,24 +1617,19 @@ } /* will return AF_{INET|INET6}from local_host */ - status =3D get_cached_dns_entry(sock->dns_cache, - sock->local_host, - sock->local_port, - af, - flags, - &sock->info.lsa->bind_local); + status =3D get_cached_dns_entry(sock->dns_cache, sock->local_host,= sock->local_port, af, + flags, &sock->info.lsa->bind_local); if (status) { - status =3D openvpn_getaddrinfo(flags, sock->local_host, sock->= local_port, 0, - NULL, af, &sock->info.lsa->bind_l= ocal); + status =3D openvpn_getaddrinfo(flags, sock->local_host, sock->= local_port, 0, NULL, af, + &sock->info.lsa->bind_local); } - if (status !=3D0) + if (status !=3D 0) { - msg(M_FATAL, "getaddrinfo() failed for local \"%s:%s\": %s", - sock->local_host, sock->local_port, - gai_strerror(status)); + msg(M_FATAL, "getaddrinfo() failed for local \"%s:%s\": %s", s= ock->local_host, + sock->local_port, gai_strerror(status)); } /* the address family returned by openvpn_getaddrinfo() should be @@ -1760,9 +1651,7 @@ } static void -resolve_remote(struct link_socket *sock, - int phase, - const char **remote_dynamic, +resolve_remote(struct link_socket *sock, int phase, const char **remote_dy= namic, struct signal_info *sig_info) { volatile int *signal_received =3D sig_info ? &sig_info->signal_receive= d : NULL; @@ -1773,7 +1662,8 @@ { if (sock->remote_host) { - unsigned int flags =3D sf2gaf(GETADDR_RESOLVE|GETADDR_UPDATE_M= ANAGEMENT_STATE, sock->sockflags); + unsigned int flags =3D + sf2gaf(GETADDR_RESOLVE | GETADDR_UPDATE_MANAGEMENT_STATE, = sock->sockflags); int retry =3D 0; int status =3D -1; struct addrinfo *ai; @@ -1820,15 +1710,12 @@ } - status =3D get_cached_dns_entry(sock->dns_cache, - sock->remote_host, - sock->remote_port, - sock->info.af, - flags, &ai); + status =3D get_cached_dns_entry(sock->dns_cache, sock->remote_= host, sock->remote_port, + sock->info.af, flags, &ai); if (status) { - status =3D openvpn_getaddrinfo(flags, sock->remote_host, s= ock->remote_port, - retry, sig_info, sock->info.a= f, &ai); + status =3D openvpn_getaddrinfo(flags, sock->remote_host, s= ock->remote_port, retry, + sig_info, sock->info.af, &ai); } if (status =3D=3D 0) @@ -1836,19 +1723,14 @@ sock->info.lsa->remote_list =3D ai; sock->info.lsa->current_remote =3D ai; - dmsg(D_SOCKET_DEBUG, - "RESOLVE_REMOTE flags=3D0x%04x phase=3D%d rrs=3D%d si= g=3D%d status=3D%d", - flags, - phase, - retry, - signal_received ? *signal_received : -1, - status); + dmsg(D_SOCKET_DEBUG, "RESOLVE_REMOTE flags=3D0x%04x phase= =3D%d rrs=3D%d sig=3D%d status=3D%d", + flags, phase, retry, signal_received ? *signal_receiv= ed : -1, status); } if (signal_received && *signal_received) { goto done; } - if (status!=3D0) + if (status !=3D 0) { if (signal_received) { @@ -1875,8 +1757,7 @@ CLEAR(sock->info.lsa->actual); if (sock->info.lsa->current_remote) { - set_actual_address(&sock->info.lsa->actual, - sock->info.lsa->current_remote); + set_actual_address(&sock->info.lsa->actual, sock->info.lsa->cu= rrent_remote); } } @@ -1885,7 +1766,6 @@ } - struct link_socket * link_socket_new(void) { @@ -2078,8 +1958,7 @@ } ASSERT(cur); msg(msglevel, "%s link local (bound): %s", - proto2ascii(sock->info.proto, sock->info.af, true), - print_sockaddr(cur->ai_addr, &gc)); + proto2ascii(sock->info.proto, sock->info.af, true), print_sock= addr(cur->ai_addr, &gc)); } else { @@ -2088,12 +1967,8 @@ } =20 /* print active remote address */ - msg(msglevel, "%s link remote: %s", - proto2ascii(sock->info.proto, sock->info.af, true), - print_link_socket_actual_ex(&sock->info.lsa->actual, - ":", - PS_SHOW_PORT_IF_DEFINED, - &gc)); + msg(msglevel, "%s link remote: %s", proto2ascii(sock->info.proto, sock= ->info.af, true), + print_link_socket_actual_ex(&sock->info.lsa->actual, ":", PS_SHOW_= PORT_IF_DEFINED, &gc)); gc_free(&gc); } @@ -2106,26 +1981,17 @@ switch (sock->mode) { case LS_MODE_DEFAULT: - sock->sd =3D socket_listen_accept(sock->sd, - &sock->info.lsa->actual, - remote_dynamic, - sock->info.lsa->bind_local, - true, - false, - signal_received); + sock->sd =3D + socket_listen_accept(sock->sd, &sock->info.lsa->actual, re= mote_dynamic, + sock->info.lsa->bind_local, true, fal= se, signal_received); break; case LS_MODE_TCP_LISTEN: - socket_do_listen(sock->sd, - sock->info.lsa->bind_local, - true, - false); + socket_do_listen(sock->sd, sock->info.lsa->bind_local, true, f= alse); break; case LS_MODE_TCP_ACCEPT_FROM: - sock->sd =3D socket_do_accept(sock->sd, - &sock->info.lsa->actual, - false); + sock->sd =3D socket_do_accept(sock->sd, &sock->info.lsa->actua= l, false); if (!socket_defined(sock->sd)) { register_signal(sig_info, SIGTERM, "socket-undefined"); @@ -2146,10 +2012,8 @@ bool proxy_retry =3D false; do { - socket_connect(&sock->sd, - sock->info.lsa->current_remote->ai_addr, - get_server_poll_remaining_time(sock->server_poll_ti= meout), - sig_info); + socket_connect(&sock->sd, sock->info.lsa->current_remote->ai_addr, + get_server_poll_remaining_time(sock->server_poll_ti= meout), sig_info); if (sig_info->signal_received) { @@ -2158,21 +2022,14 @@ if (sock->http_proxy) { - proxy_retry =3D establish_http_proxy_passthru(sock->http_proxy, - sock->sd, - sock->proxy_dest_h= ost, - sock->proxy_dest_p= ort, - sock->server_poll_= timeout, - &sock->stream_buf.= residual, - sig_info); + proxy_retry =3D establish_http_proxy_passthru( + sock->http_proxy, sock->sd, sock->proxy_dest_host, sock->p= roxy_dest_port, + sock->server_poll_timeout, &sock->stream_buf.residual, sig= _info); } else if (sock->socks_proxy) { - establish_socks_proxy_passthru(sock->socks_proxy, - sock->sd, - sock->proxy_dest_host, - sock->proxy_dest_port, - sock->server_poll_timeout, + establish_socks_proxy_passthru(sock->socks_proxy, sock->sd, so= ck->proxy_dest_host, + sock->proxy_dest_port, sock->se= rver_poll_timeout, sig_info); } if (proxy_retry) @@ -2182,27 +2039,21 @@ } } while (proxy_retry); - } static void phase2_socks_client(struct link_socket *sock, struct signal_info *sig_info) { - socket_connect(&sock->ctrl_sd, - sock->info.lsa->current_remote->ai_addr, - get_server_poll_remaining_time(sock->server_poll_timeou= t), - sig_info); + socket_connect(&sock->ctrl_sd, sock->info.lsa->current_remote->ai_addr, + get_server_poll_remaining_time(sock->server_poll_timeou= t), sig_info); if (sig_info->signal_received) { return; } - establish_socks_proxy_udpassoc(sock->socks_proxy, - sock->ctrl_sd, - &sock->socks_relay.dest, - sock->server_poll_timeout, - sig_info); + establish_socks_proxy_udpassoc(sock->socks_proxy, sock->ctrl_sd, &sock= ->socks_relay.dest, + sock->server_poll_timeout, sig_info); if (sig_info->signal_received) { @@ -2225,8 +2076,7 @@ #if defined(_WIN32) static void -create_socket_dco_win(struct context *c, struct link_socket *sock, - struct signal_info *sig_info) +create_socket_dco_win(struct context *c, struct link_socket *sock, struct = signal_info *sig_info) { /* in P2P mode we must have remote resolved at this point */ struct addrinfo *remoteaddr =3D sock->info.lsa->current_remote; @@ -2274,14 +2124,13 @@ /* finalize socket initialization */ void -link_socket_init_phase2(struct context *c, - struct link_socket *sock) +link_socket_init_phase2(struct context *c, struct link_socket *sock) { const struct frame *frame =3D &c->c2.frame; struct signal_info *sig_info =3D c->sig; const char *remote_dynamic =3D NULL; - struct signal_info sig_save =3D {0}; + struct signal_info sig_save =3D { 0 }; ASSERT(sock); ASSERT(sig_info); @@ -2306,7 +2155,7 @@ } /* Second chance to resolv/create socket */ - resolve_remote(sock, 2, &remote_dynamic, sig_info); + resolve_remote(sock, 2, &remote_dynamic, sig_info); /* If a valid remote has been found, create the socket with its addrin= fo */ #if defined(_WIN32) @@ -2327,7 +2176,7 @@ /* If we have no --remote and have still not figured out the * protocol family to use we will use the first of the bind */ - if (sock->bind_local && !sock->remote_host && sock->info.lsa->bin= d_local) + if (sock->bind_local && !sock->remote_host && sock->info.lsa->bind= _local) { /* Warn if this is because neither v4 or v6 was specified * and we should not connect a remote */ @@ -2361,7 +2210,6 @@ else if (sock->info.proto =3D=3D PROTO_TCP_CLIENT) { phase2_tcp_client(sock, sig_info); - } else if (sock->info.proto =3D=3D PROTO_UDP && sock->socks_proxy) { @@ -2455,7 +2303,8 @@ } static void -ipchange_fmt(const bool include_cmd, struct argv *argv, const struct link_= socket_info *info, struct gc_arena *gc) +ipchange_fmt(const bool include_cmd, struct argv *argv, const struct link_= socket_info *info, + struct gc_arena *gc) { const char *host =3D print_sockaddr_ex(&info->lsa->actual.dest.addr.sa= , " ", PS_SHOW_PORT, gc); if (include_cmd) @@ -2467,13 +2316,11 @@ { argv_printf(argv, "%s", host); } - } void link_socket_connection_initiated(struct link_socket_info *info, - const struct link_socket_actual *act, - const char *common_name, + const struct link_socket_actual *act, con= st char *common_name, struct env_set *es) { struct gc_arena gc =3D gc_new(); @@ -2489,7 +2336,8 @@ { buf_printf(&out, "[%s] ", common_name); } - buf_printf(&out, "Peer Connection Initiated with %s", print_link_s= ocket_actual(&info->lsa->actual, &gc)); + buf_printf(&out, "Peer Connection Initiated with %s", + print_link_socket_actual(&info->lsa->actual, &gc)); msg(M_INFO, "%s", BSTR(&out)); } @@ -2501,7 +2349,8 @@ { struct argv argv =3D argv_new(); ipchange_fmt(false, &argv, info, &gc); - if (plugin_call(info->plugins, OPENVPN_PLUGIN_IPCHANGE, &argv, NUL= L, es) !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) + if (plugin_call(info->plugins, OPENVPN_PLUGIN_IPCHANGE, &argv, NUL= L, es) + !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) { msg(M_WARN, "WARNING: ipchange plugin call failed"); } @@ -2522,8 +2371,7 @@ } void -link_socket_bad_incoming_addr(struct buffer *buf, - const struct link_socket_info *info, +link_socket_bad_incoming_addr(struct buffer *buf, const struct link_socket= _info *info, const struct link_socket_actual *from_addr) { struct gc_arena gc =3D gc_new(); @@ -2535,8 +2383,7 @@ case AF_INET6: msg(D_LINK_ERRORS, "TCP/UDP: Incoming packet rejected from %s[%d], expected p= eer address: %s (allow this incoming source address/port by removing --remo= te or adding --float)", - print_link_socket_actual(from_addr, &gc), - (int)from_addr->dest.addr.sa.sa_family, + print_link_socket_actual(from_addr, &gc), (int)from_addr->= dest.addr.sa.sa_family, print_sockaddr_ex(info->lsa->remote_list->ai_addr, ":", PS= _SHOW_PORT, &gc)); /* print additional remote addresses */ for (ai =3D info->lsa->remote_list->ai_next; ai; ai =3D ai->ai= _next) @@ -2561,16 +2408,16 @@ { const struct link_socket_addr *lsa =3D info->lsa; -/* - * This logic supports "redirect-gateway" semantic, which - * makes sense only for PF_INET routes over PF_INET endpoints - * - * Maybe in the future consider PF_INET6 endpoints also ... - * by now just ignore it - * - * For --remote entries with multiple addresses this - * only return the actual endpoint we have successfully connected to - */ + /* + * This logic supports "redirect-gateway" semantic, which + * makes sense only for PF_INET routes over PF_INET endpoints + * + * Maybe in the future consider PF_INET6 endpoints also ... + * by now just ignore it + * + * For --remote entries with multiple addresses this + * only return the actual endpoint we have successfully connected to + */ if (lsa->actual.dest.addr.sa.sa_family !=3D AF_INET) { return IPV4_INVALID_ADDR; @@ -2582,8 +2429,7 @@ } else if (lsa->current_remote) { - return ntohl(((struct sockaddr_in *)lsa->current_remote->ai_addr) - ->sin_addr.s_addr); + return ntohl(((struct sockaddr_in *)lsa->current_remote->ai_addr)-= >sin_addr.s_addr); } else { @@ -2596,12 +2442,12 @@ { const struct link_socket_addr *lsa =3D info->lsa; -/* This logic supports "redirect-gateway" semantic, - * for PF_INET6 routes over PF_INET6 endpoints - * - * For --remote entries with multiple addresses this - * only return the actual endpoint we have successfully connected to - */ + /* This logic supports "redirect-gateway" semantic, + * for PF_INET6 routes over PF_INET6 endpoints + * + * For --remote entries with multiple addresses this + * only return the actual endpoint we have successfully connected to + */ if (lsa->actual.dest.addr.sa.sa_family !=3D AF_INET6) { return NULL; @@ -2632,20 +2478,16 @@ { if (rwflags & EVENT_READ) { - buf_printf(&out, "S%s", - (s->rwflags_debug & EVENT_READ) ? "R" : "r"); + buf_printf(&out, "S%s", (s->rwflags_debug & EVENT_READ) ? "R" = : "r"); #ifdef _WIN32 - buf_printf(&out, "%s", - overlapped_io_state_ascii(&s->reads)); + buf_printf(&out, "%s", overlapped_io_state_ascii(&s->reads)); #endif } if (rwflags & EVENT_WRITE) { - buf_printf(&out, "S%s", - (s->rwflags_debug & EVENT_WRITE) ? "W" : "w"); + buf_printf(&out, "S%s", (s->rwflags_debug & EVENT_WRITE) ? "W"= : "w"); #ifdef _WIN32 - buf_printf(&out, "%s", - overlapped_io_state_ascii(&s->writes)); + buf_printf(&out, "%s", overlapped_io_state_ascii(&s->writes)); #endif } } @@ -2672,9 +2514,7 @@ } static void -stream_buf_init(struct stream_buf *sb, - struct buffer *buf, - const unsigned int sockflags, +stream_buf_init(struct stream_buf *sb, struct buffer *buf, const unsigned = int sockflags, const int proto) { sb->buf_init =3D *buf; @@ -2683,9 +2523,8 @@ sb->residual =3D alloc_buf(sb->maxlen); sb->error =3D false; #if PORT_SHARE - sb->port_share_state =3D ((sockflags & SF_PORT_SHARE) && (proto =3D=3D= PROTO_TCP_SERVER)) - ? PS_ENABLED - : PS_DISABLED; + sb->port_share_state =3D + ((sockflags & SF_PORT_SHARE) && (proto =3D=3D PROTO_TCP_SERVER)) ?= PS_ENABLED : PS_DISABLED; #endif stream_buf_reset(sb); @@ -2700,9 +2539,7 @@ sb->next.offset =3D sb->buf.offset + sb->buf.len; sb->next.len =3D (sb->len >=3D 0 ? sb->len : sb->maxlen) - sb->buf.len; dmsg(D_STREAM_DEBUG, "STREAM: SET NEXT, buf=3D[%d,%d] next=3D[%d,%d] l= en=3D%d maxlen=3D%d", - sb->buf.offset, sb->buf.len, - sb->next.offset, sb->next.len, - sb->len, sb->maxlen); + sb->buf.offset, sb->buf.len, sb->next.offset, sb->next.len, sb->l= en, sb->maxlen); ASSERT(sb->next.len > 0); ASSERT(buf_safe(&sb->buf, sb->next.len)); } @@ -2710,8 +2547,7 @@ static inline void stream_buf_get_final(struct stream_buf *sb, struct buffer *buf) { - dmsg(D_STREAM_DEBUG, "STREAM: GET FINAL len=3D%d", - buf_defined(&sb->buf) ? sb->buf.len : -1); + dmsg(D_STREAM_DEBUG, "STREAM: GET FINAL len=3D%d", buf_defined(&sb->bu= f) ? sb->buf.len : -1); ASSERT(buf_defined(&sb->buf)); *buf =3D sb->buf; } @@ -2719,8 +2555,7 @@ static inline void stream_buf_get_next(struct stream_buf *sb, struct buffer *buf) { - dmsg(D_STREAM_DEBUG, "STREAM: GET NEXT len=3D%d", - buf_defined(&sb->next) ? sb->next.len : -1); + dmsg(D_STREAM_DEBUG, "STREAM: GET NEXT len=3D%d", buf_defined(&sb->nex= t) ? sb->next.len : -1); ASSERT(buf_defined(&sb->next)); *buf =3D sb->next; } @@ -2734,8 +2569,7 @@ ASSERT(buf_init(&sock->stream_buf.residual, 0)); sock->stream_buf.residual_fully_formed =3D stream_buf_added(&sock-= >stream_buf, 0); dmsg(D_STREAM_DEBUG, "STREAM: RESIDUAL FULLY FORMED [%s], len=3D%d= ", - sock->stream_buf.residual_fully_formed ? "YES" : "NO", - sock->stream_buf.residual.len); + sock->stream_buf.residual_fully_formed ? "YES" : "NO", sock->= stream_buf.residual.len); } if (!sock->stream_buf.residual_fully_formed) @@ -2746,8 +2580,7 @@ } static bool -stream_buf_added(struct stream_buf *sb, - int length_added) +stream_buf_added(struct stream_buf *sb, int length_added) { dmsg(D_STREAM_DEBUG, "STREAM: ADD length_added=3D%d", length_added); if (length_added > 0) @@ -2757,7 +2590,7 @@ /* if length unknown, see if we can get the length prefix from * the head of the buffer */ - if (sb->len < 0 && sb->buf.len >=3D (int) sizeof(packet_size_type)) + if (sb->len < 0 && sb->buf.len >=3D (int)sizeof(packet_size_type)) { packet_size_type net_size; @@ -2783,7 +2616,9 @@ if (sb->len < 1 || sb->len > sb->maxlen) { - msg(M_WARN, "WARNING: Bad encapsulated packet length from peer= (%d), which must be > 0 and <=3D %d -- please ensure that --tun-mtu or --l= ink-mtu is equal on both peers -- this condition could also indicate a poss= ible active attack on the TCP link -- [Attempting restart...]", sb->len, sb= ->maxlen); + msg(M_WARN, + "WARNING: Bad encapsulated packet length from peer (%d), w= hich must be > 0 and <=3D %d -- please ensure that --tun-mtu or --link-mtu = is equal on both peers -- this condition could also indicate a possible act= ive attack on the TCP link -- [Attempting restart...]", + sb->len, sb->maxlen); stream_buf_reset(sb); sb->error =3D true; return false; @@ -2800,8 +2635,7 @@ ASSERT(buf_copy_excess(&sb->residual, &sb->buf, sb->len)); } dmsg(D_STREAM_DEBUG, "STREAM: ADD returned TRUE, buf_len=3D%d, res= idual_len=3D%d", - BLEN(&sb->buf), - BLEN(&sb->residual)); + BLEN(&sb->buf), BLEN(&sb->residual)); return true; } else @@ -2832,7 +2666,7 @@ init_net_event_win32(&s->listen_handle, FD_ACCEPT, s->sd, 0); } return &s->listen_handle; -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ return s->sd; #endif } @@ -2842,9 +2676,7 @@ */ const char * -print_sockaddr_ex(const struct sockaddr *sa, - const char *separator, - const unsigned int flags, +print_sockaddr_ex(const struct sockaddr *sa, const char *separator, const = unsigned int flags, struct gc_arena *gc) { struct buffer out =3D alloc_buf_gc(128, gc); @@ -2862,7 +2694,7 @@ buf_puts(&out, "[AF_INET]"); } salen =3D sizeof(struct sockaddr_in); - addr_is_defined =3D ((struct sockaddr_in *) sa)->sin_addr.s_ad= dr !=3D 0; + addr_is_defined =3D ((struct sockaddr_in *)sa)->sin_addr.s_add= r !=3D 0; break; case AF_INET6: @@ -2871,7 +2703,7 @@ buf_puts(&out, "[AF_INET6]"); } salen =3D sizeof(struct sockaddr_in6); - addr_is_defined =3D !IN6_IS_ADDR_UNSPECIFIED(&((struct sockadd= r_in6 *) sa)->sin6_addr); + addr_is_defined =3D !IN6_IS_ADDR_UNSPECIFIED(&((struct sockadd= r_in6 *)sa)->sin6_addr); break; case AF_UNSPEC: @@ -2888,10 +2720,10 @@ ASSERT(0); } - status =3D getnameinfo(sa, salen, hostaddr, sizeof(hostaddr), - servname, sizeof(servname), NI_NUMERICHOST | NI_N= UMERICSERV); + status =3D getnameinfo(sa, salen, hostaddr, sizeof(hostaddr), servname= , sizeof(servname), + NI_NUMERICHOST | NI_NUMERICSERV); - if (status!=3D0) + if (status !=3D 0) { buf_printf(&out, "[nameinfo() err: %s]", gai_strerror(status)); return BSTR(&out); @@ -2925,7 +2757,7 @@ const char * print_link_socket_actual(const struct link_socket_actual *act, struct gc_a= rena *gc) { - return print_link_socket_actual_ex(act, ":", PS_SHOW_PORT|PS_SHOW_PKTI= NFO, gc); + return print_link_socket_actual_ex(act, ":", PS_SHOW_PORT | PS_SHOW_PK= TINFO, gc); } #ifndef IF_NAMESIZE @@ -2933,10 +2765,8 @@ #endif const char * -print_link_socket_actual_ex(const struct link_socket_actual *act, - const char *separator, - const unsigned int flags, - struct gc_arena *gc) +print_link_socket_actual_ex(const struct link_socket_actual *act, const ch= ar *separator, + const unsigned int flags, struct gc_arena *gc) { if (act) { @@ -2960,12 +2790,11 @@ #elif defined(IP_RECVDSTADDR) sa.addr.in4.sin_addr =3D act->pi.in4; ifname[0] =3D 0; -#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ +#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix= syshead.h) #endif buf_printf(&out, " (via %s%%%s)", - print_sockaddr_ex(&sa.addr.sa, separator, 0= , gc), - ifname); + print_sockaddr_ex(&sa.addr.sa, separator, 0= , gc), ifname); } break; @@ -2977,8 +2806,9 @@ sin6.sin6_family =3D AF_INET6; sin6.sin6_addr =3D act->pi.in6.ipi6_addr; if_indextoname(act->pi.in6.ipi6_ifindex, ifname); - if (getnameinfo((struct sockaddr *)&sin6, sizeof(struc= t sockaddr_in6), - buf, sizeof(buf), NULL, 0, NI_NUMERICH= OST) =3D=3D 0) + if (getnameinfo((struct sockaddr *)&sin6, sizeof(struc= t sockaddr_in6), buf, + sizeof(buf), NULL, 0, NI_NUMERICHOST) + =3D=3D 0) { buf_printf(&out, " (via %s%%%s)", buf, ifname); } @@ -3028,8 +2858,7 @@ { char *out =3D gc_malloc(INET6_ADDRSTRLEN, true, gc); - if (memcmp(&a6, &in6addr_any, sizeof(a6)) !=3D 0 - || !(flags & IA_EMPTY_IF_UNDEF)) + if (memcmp(&a6, &in6addr_any, sizeof(a6)) !=3D 0 || !(flags & IA_EMPTY= _IF_UNDEF)) { inet_ntop(AF_INET6, &a6, out, INET6_ADDRSTRLEN); } @@ -3051,30 +2880,31 @@ * (add in steps of 8 bits, taking overflow into next round) */ struct in6_addr -add_in6_addr( struct in6_addr base, uint32_t add ) +add_in6_addr(struct in6_addr base, uint32_t add) { int i; - for (i =3D 15; i>=3D0 && add > 0; i--) + for (i =3D 15; i >=3D 0 && add > 0; i--) { register int carry; register uint32_t h; - h =3D (unsigned char) base.s6_addr[i]; - base.s6_addr[i] =3D (h+add) & UINT8_MAX; + h =3D (unsigned char)base.s6_addr[i]; + base.s6_addr[i] =3D (h + add) & UINT8_MAX; /* using explicit carry for the 8-bit additions will catch * 8-bit and(!) 32-bit overruns nicely */ - carry =3D ((h & 0xff) + (add & 0xff)) >> 8; - add =3D (add>>8) + carry; + carry =3D ((h & 0xff) + (add & 0xff)) >> 8; + add =3D (add >> 8) + carry; } return base; } /* set environmental variables for ip/port in *addr */ void -setenv_sockaddr(struct env_set *es, const char *name_prefix, const struct = openvpn_sockaddr *addr, const unsigned int flags) +setenv_sockaddr(struct env_set *es, const char *name_prefix, const struct = openvpn_sockaddr *addr, + const unsigned int flags) { char name_buf[256]; @@ -3102,11 +2932,10 @@ break; case AF_INET6: - if (IN6_IS_ADDR_V4MAPPED( &addr->addr.in6.sin6_addr )) + if (IN6_IS_ADDR_V4MAPPED(&addr->addr.in6.sin6_addr)) { struct in_addr ia; - memcpy(&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12], - sizeof(ia.s_addr)); + memcpy(&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12], = sizeof(ia.s_addr)); snprintf(name_buf, sizeof(name_buf), "%s_ip", name_prefix); inet_ntop(AF_INET, &ia, buf, sizeof(buf)); } @@ -3127,7 +2956,8 @@ } void -setenv_in_addr_t(struct env_set *es, const char *name_prefix, in_addr_t ad= dr, const unsigned int flags) +setenv_in_addr_t(struct env_set *es, const char *name_prefix, in_addr_t ad= dr, + const unsigned int flags) { if (addr || !(flags & SA_SET_IF_NONZERO)) { @@ -3140,9 +2970,7 @@ } void -setenv_in6_addr(struct env_set *es, - const char *name_prefix, - const struct in6_addr *addr, +setenv_in6_addr(struct env_set *es, const char *name_prefix, const struct = in6_addr *addr, const unsigned int flags) { if (!IN6_IS_ADDR_UNSPECIFIED(addr) || !(flags & SA_SET_IF_NONZERO)) @@ -3156,10 +2984,8 @@ } void -setenv_link_socket_actual(struct env_set *es, - const char *name_prefix, - const struct link_socket_actual *act, - const unsigned int flags) +setenv_link_socket_actual(struct env_set *es, const char *name_prefix, + const struct link_socket_actual *act, const unsi= gned int flags) { setenv_sockaddr(es, name_prefix, &act->dest, flags); } @@ -3168,7 +2994,8 @@ * Convert protocol names between index and ascii form. */ -struct proto_names { +struct proto_names +{ const char *short_form; const char *display_form; sa_family_t proto_af; @@ -3177,22 +3004,22 @@ /* Indexed by PROTO_x */ static const struct proto_names proto_names[] =3D { - {"proto-uninitialized", "proto-NONE", AF_UNSPEC, PROTO_NONE}, + { "proto-uninitialized", "proto-NONE", AF_UNSPEC, PROTO_NONE }, /* try IPv4 and IPv6 (client), bind dual-stack (server) */ - {"udp", "UDP", AF_UNSPEC, PROTO_UDP}, - {"tcp-server", "TCP_SERVER", AF_UNSPEC, PROTO_TCP_SERVER}, - {"tcp-client", "TCP_CLIENT", AF_UNSPEC, PROTO_TCP_CLIENT}, - {"tcp", "TCP", AF_UNSPEC, PROTO_TCP}, + { "udp", "UDP", AF_UNSPEC, PROTO_UDP }, + { "tcp-server", "TCP_SERVER", AF_UNSPEC, PROTO_TCP_SERVER }, + { "tcp-client", "TCP_CLIENT", AF_UNSPEC, PROTO_TCP_CLIENT }, + { "tcp", "TCP", AF_UNSPEC, PROTO_TCP }, /* force IPv4 */ - {"udp4", "UDPv4", AF_INET, PROTO_UDP}, - {"tcp4-server", "TCPv4_SERVER", AF_INET, PROTO_TCP_SERVER}, - {"tcp4-client", "TCPv4_CLIENT", AF_INET, PROTO_TCP_CLIENT}, - {"tcp4", "TCPv4", AF_INET, PROTO_TCP}, + { "udp4", "UDPv4", AF_INET, PROTO_UDP }, + { "tcp4-server", "TCPv4_SERVER", AF_INET, PROTO_TCP_SERVER }, + { "tcp4-client", "TCPv4_CLIENT", AF_INET, PROTO_TCP_CLIENT }, + { "tcp4", "TCPv4", AF_INET, PROTO_TCP }, /* force IPv6 */ - {"udp6", "UDPv6", AF_INET6, PROTO_UDP}, - {"tcp6-server", "TCPv6_SERVER", AF_INET6, PROTO_TCP_SERVER}, - {"tcp6-client", "TCPv6_CLIENT", AF_INET6, PROTO_TCP_CLIENT}, - {"tcp6", "TCPv6", AF_INET6, PROTO_TCP}, + { "udp6", "UDPv6", AF_INET6, PROTO_UDP }, + { "tcp6-server", "TCPv6_SERVER", AF_INET6, PROTO_TCP_SERVER }, + { "tcp6-client", "TCPv6_CLIENT", AF_INET6, PROTO_TCP_CLIENT }, + { "tcp6", "TCPv6", AF_INET6, PROTO_TCP }, }; int @@ -3263,9 +3090,11 @@ { switch (af) { - case AF_INET: return "AF_INET"; + case AF_INET: + return "AF_INET"; - case AF_INET6: return "AF_INET6"; + case AF_INET6: + return "AF_INET6"; } return "AF_UNSPEC"; } @@ -3291,13 +3120,11 @@ return "UDPv4"; } - if ( (remote && proto =3D=3D PROTO_TCP_CLIENT) - || (!remote && proto =3D=3D PROTO_TCP_SERVER)) + if ((remote && proto =3D=3D PROTO_TCP_CLIENT) || (!remote && proto =3D= =3D PROTO_TCP_SERVER)) { return "TCPv4_SERVER"; } - if ( (remote && proto =3D=3D PROTO_TCP_SERVER) - || (!remote && proto =3D=3D PROTO_TCP_CLIENT)) + if ((remote && proto =3D=3D PROTO_TCP_SERVER) || (!remote && proto =3D= =3D PROTO_TCP_CLIENT)) { return "TCPv4_CLIENT"; } @@ -3313,9 +3140,9 @@ void bad_address_length(int actual, int expected) { - msg(M_FATAL, "ERROR: received strange incoming packet with an address = length of %d -- we only accept address lengths of %d.", - actual, - expected); + msg(M_FATAL, + "ERROR: received strange incoming packet with an address length of= %d -- we only accept address lengths of %d.", + actual, expected); } /* @@ -3323,8 +3150,7 @@ */ int -link_socket_read_tcp(struct link_socket *sock, - struct buffer *buf) +link_socket_read_tcp(struct link_socket *sock, struct buffer *buf) { int len =3D 0; @@ -3337,9 +3163,9 @@ */ if (sock->sd =3D=3D SOCKET_UNDEFINED) { - msg(M_INFO, "BUG: link_socket_read_tcp(): sock->sd=3D=3D-1, re= set client instance" ); - sock->stream_reset =3D true; /* reset client inst= ance */ - return buf->len =3D 0; /* nothing to read */ + msg(M_INFO, "BUG: link_socket_read_tcp(): sock->sd=3D=3D-1, re= set client instance"); + sock->stream_reset =3D true; /* reset client instance */ + return buf->len =3D 0; /* nothing to read */ } #ifdef _WIN32 @@ -3382,24 +3208,23 @@ * both IPv4 and IPv6 destination addresses, plus padding (see RFC 2292) */ #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) -#define PKTINFO_BUF_SIZE max_int( CMSG_SPACE(sizeof(struct in6_pktinfo)), \ - CMSG_SPACE(sizeof(struct in_pktinfo)) ) +#define PKTINFO_BUF_SIZE \ + max_int(CMSG_SPACE(sizeof(struct in6_pktinfo)), CMSG_SPACE(sizeof(stru= ct in_pktinfo))) #else -#define PKTINFO_BUF_SIZE max_int( CMSG_SPACE(sizeof(struct in6_pktinfo)), \ - CMSG_SPACE(sizeof(struct in_addr)) ) +#define PKTINFO_BUF_SIZE \ + max_int(CMSG_SPACE(sizeof(struct in6_pktinfo)), CMSG_SPACE(sizeof(stru= ct in_addr))) #endif static socklen_t -link_socket_read_udp_posix_recvmsg(struct link_socket *sock, - struct buffer *buf, +link_socket_read_udp_posix_recvmsg(struct link_socket *sock, struct buffer= *buf, struct link_socket_actual *from) { struct iovec iov; uint8_t pktinfo_buf[PKTINFO_BUF_SIZE]; - struct msghdr mesg =3D {0}; + struct msghdr mesg =3D { 0 }; socklen_t fromlen =3D sizeof(from->dest.addr); - ASSERT(sock->sd >=3D 0); /* can't happen */ + ASSERT(sock->sd >=3D 0); /* can't happen */ iov.iov_base =3D BPTR(buf); iov.iov_len =3D buf_forward_capacity_total(buf); @@ -3415,43 +3240,40 @@ struct cmsghdr *cmsg; fromlen =3D mesg.msg_namelen; cmsg =3D CMSG_FIRSTHDR(&mesg); - if (cmsg !=3D NULL - && CMSG_NXTHDR(&mesg, cmsg) =3D=3D NULL + if (cmsg !=3D NULL && CMSG_NXTHDR(&mesg, cmsg) =3D=3D NULL #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) - && cmsg->cmsg_level =3D=3D SOL_IP - && cmsg->cmsg_type =3D=3D IP_PKTINFO - && cmsg->cmsg_len >=3D CMSG_LEN(sizeof(struct in_pktinfo)) ) + && cmsg->cmsg_level =3D=3D SOL_IP && cmsg->cmsg_type =3D=3D IP= _PKTINFO + && cmsg->cmsg_len >=3D CMSG_LEN(sizeof(struct in_pktinfo))) #elif defined(IP_RECVDSTADDR) - && cmsg->cmsg_level =3D=3D IPPROTO_IP - && cmsg->cmsg_type =3D=3D IP_RECVDSTADDR - && cmsg->cmsg_len >=3D CMSG_LEN(sizeof(struct in_addr)) ) -#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ + && cmsg->cmsg_level =3D=3D IPPROTO_IP && cmsg->cmsg_type =3D= =3D IP_RECVDSTADDR + && cmsg->cmsg_len >=3D CMSG_LEN(sizeof(struct in_addr))) +#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix= syshead.h) #endif { #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) - struct in_pktinfo *pkti =3D (struct in_pktinfo *) CMSG_DATA(cm= sg); + struct in_pktinfo *pkti =3D (struct in_pktinfo *)CMSG_DATA(cms= g); from->pi.in4.ipi_ifindex =3D pkti->ipi_ifindex; from->pi.in4.ipi_spec_dst =3D pkti->ipi_spec_dst; #elif defined(IP_RECVDSTADDR) - from->pi.in4 =3D *(struct in_addr *) CMSG_DATA(cmsg); -#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ + from->pi.in4 =3D *(struct in_addr *)CMSG_DATA(cmsg); +#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix= syshead.h) #endif } - else if (cmsg !=3D NULL - && CMSG_NXTHDR(&mesg, cmsg) =3D=3D NULL - && cmsg->cmsg_level =3D=3D IPPROTO_IPV6 - && cmsg->cmsg_type =3D=3D IPV6_PKTINFO - && cmsg->cmsg_len >=3D CMSG_LEN(sizeof(struct in6_pktinfo= )) ) + else if (cmsg !=3D NULL && CMSG_NXTHDR(&mesg, cmsg) =3D=3D NULL + && cmsg->cmsg_level =3D=3D IPPROTO_IPV6 && cmsg->cmsg_typ= e =3D=3D IPV6_PKTINFO + && cmsg->cmsg_len >=3D CMSG_LEN(sizeof(struct in6_pktinfo= ))) { - struct in6_pktinfo *pkti6 =3D (struct in6_pktinfo *) CMSG_DATA= (cmsg); + struct in6_pktinfo *pkti6 =3D (struct in6_pktinfo *)CMSG_DATA(= cmsg); from->pi.in6.ipi6_ifindex =3D pkti6->ipi6_ifindex; from->pi.in6.ipi6_addr =3D pkti6->ipi6_addr; } else if (cmsg !=3D NULL) { - msg(M_WARN, "CMSG received that cannot be parsed (cmsg_level= =3D%d, cmsg_type=3D%d, cmsg=3Dlen=3D%d)", (int)cmsg->cmsg_level, (int)cmsg-= >cmsg_type, (int)cmsg->cmsg_len ); + msg(M_WARN, + "CMSG received that cannot be parsed (cmsg_level=3D%d, cms= g_type=3D%d, cmsg=3Dlen=3D%d)", + (int)cmsg->cmsg_level, (int)cmsg->cmsg_type, (int)cmsg->cm= sg_len); } } @@ -3460,15 +3282,14 @@ #endif /* if ENABLE_IP_PKTINFO */ int -link_socket_read_udp_posix(struct link_socket *sock, - struct buffer *buf, +link_socket_read_udp_posix(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from) { socklen_t fromlen =3D sizeof(from->dest.addr); socklen_t expectedlen =3D af_addr_size(sock->info.af); addr_zero_host(&from->dest); - ASSERT(sock->sd >=3D 0); /* can't happen */ + ASSERT(sock->sd >=3D 0); /* can't happen */ #if ENABLE_IP_PKTINFO /* Both PROTO_UDPv4 and PROTO_UDPv6 */ @@ -3479,8 +3300,8 @@ else #endif { - buf->len =3D recvfrom(sock->sd, BPTR(buf), buf_forward_capacity(bu= f), 0, - &from->dest.addr.sa, &fromlen); + buf->len =3D recvfrom(sock->sd, BPTR(buf), buf_forward_capacity(bu= f), 0, &from->dest.addr.sa, + &fromlen); } /* FIXME: won't do anything when sock->info.af =3D=3D AF_UNSPEC */ if (buf->len >=3D 0 && expectedlen && fromlen !=3D expectedlen) @@ -3497,9 +3318,7 @@ */ ssize_t -link_socket_write_tcp(struct link_socket *sock, - struct buffer *buf, - struct link_socket_actual *to) +link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct= link_socket_actual *to) { packet_size_type len =3D BLEN(buf); dmsg(D_STREAM_DEBUG, "STREAM: WRITE %d offset=3D%d", (int)len, buf->of= fset); @@ -3516,8 +3335,7 @@ #if ENABLE_IP_PKTINFO ssize_t -link_socket_write_udp_posix_sendmsg(struct link_socket *sock, - struct buffer *buf, +link_socket_write_udp_posix_sendmsg(struct link_socket *sock, struct buffe= r *buf, struct link_socket_actual *to) { struct iovec iov; @@ -3545,19 +3363,19 @@ cmsg->cmsg_type =3D IP_PKTINFO; { struct in_pktinfo *pkti; - pkti =3D (struct in_pktinfo *) CMSG_DATA(cmsg); + pkti =3D (struct in_pktinfo *)CMSG_DATA(cmsg); pkti->ipi_ifindex =3D to->pi.in4.ipi_ifindex; pkti->ipi_spec_dst =3D to->pi.in4.ipi_spec_dst; pkti->ipi_addr.s_addr =3D 0; } #elif defined(IP_RECVDSTADDR) - ASSERT( CMSG_SPACE(sizeof(struct in_addr)) <=3D sizeof(pktinfo= _buf) ); + ASSERT(CMSG_SPACE(sizeof(struct in_addr)) <=3D sizeof(pktinfo_= buf)); mesg.msg_controllen =3D CMSG_SPACE(sizeof(struct in_addr)); cmsg =3D CMSG_FIRSTHDR(&mesg); cmsg->cmsg_len =3D CMSG_LEN(sizeof(struct in_addr)); cmsg->cmsg_level =3D IPPROTO_IP; cmsg->cmsg_type =3D IP_RECVDSTADDR; - *(struct in_addr *) CMSG_DATA(cmsg) =3D to->pi.in4; + *(struct in_addr *)CMSG_DATA(cmsg) =3D to->pi.in4; #else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ #error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fix= syshead.h) #endif /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */ @@ -3570,7 +3388,7 @@ mesg.msg_name =3D &to->dest.addr.sa; mesg.msg_namelen =3D sizeof(struct sockaddr_in6); - ASSERT( CMSG_SPACE(sizeof(struct in6_pktinfo)) <=3D sizeof(pkt= info_buf) ); + ASSERT(CMSG_SPACE(sizeof(struct in6_pktinfo)) <=3D sizeof(pkti= nfo_buf)); mesg.msg_control =3D pktinfo_buf; mesg.msg_controllen =3D CMSG_SPACE(sizeof(struct in6_pktinfo)); mesg.msg_flags =3D 0; @@ -3579,13 +3397,14 @@ cmsg->cmsg_level =3D IPPROTO_IPV6; cmsg->cmsg_type =3D IPV6_PKTINFO; - pkti6 =3D (struct in6_pktinfo *) CMSG_DATA(cmsg); + pkti6 =3D (struct in6_pktinfo *)CMSG_DATA(cmsg); pkti6->ipi6_ifindex =3D to->pi.in6.ipi6_ifindex; pkti6->ipi6_addr =3D to->pi.in6.ipi6_addr; break; } - default: ASSERT(0); + default: + ASSERT(0); } return sendmsg(sock->sd, &mesg, 0); } @@ -3644,8 +3463,8 @@ if (socket_is_dco_win(sock)) { - status =3D ReadFile((HANDLE)sock->sd, wsabuf[0].buf, wsabuf[0]= .len, - &sock->reads.size, &sock->reads.overlapped); + status =3D ReadFile((HANDLE)sock->sd, wsabuf[0].buf, wsabuf[0]= .len, &sock->reads.size, + &sock->reads.overlapped); /* Readfile status is inverted from WSARecv */ status =3D !status; } @@ -3653,28 +3472,15 @@ { sock->reads.addr_defined =3D true; sock->reads.addrlen =3D sizeof(sock->reads.addr6); - status =3D WSARecvFrom( - sock->sd, - wsabuf, - 1, - &sock->reads.size, - &sock->reads.flags, - (struct sockaddr *) &sock->reads.addr, - &sock->reads.addrlen, - &sock->reads.overlapped, - NULL); + status =3D WSARecvFrom(sock->sd, wsabuf, 1, &sock->reads.size,= &sock->reads.flags, + (struct sockaddr *)&sock->reads.addr, &so= ck->reads.addrlen, + &sock->reads.overlapped, NULL); } else if (proto_is_tcp(sock->info.proto)) { sock->reads.addr_defined =3D false; - status =3D WSARecv( - sock->sd, - wsabuf, - 1, - &sock->reads.size, - &sock->reads.flags, - &sock->reads.overlapped, - NULL); + status =3D WSARecv(sock->sd, wsabuf, 1, &sock->reads.size, &so= ck->reads.flags, + &sock->reads.overlapped, NULL); } else { @@ -3697,8 +3503,7 @@ sock->reads.status =3D 0; dmsg(D_WIN32_IO, "WIN32 I/O: Socket Receive immediate return [= %d,%d]", - (int) wsabuf[0].len, - (int) sock->reads.size); + (int)wsabuf[0].len, (int)sock->reads.size); } else { @@ -3707,8 +3512,7 @@ { sock->reads.iostate =3D IOSTATE_QUEUED; sock->reads.status =3D status; - dmsg(D_WIN32_IO, "WIN32 I/O: Socket Receive queued [%d]", - (int) wsabuf[0].len); + dmsg(D_WIN32_IO, "WIN32 I/O: Socket Receive queued [%d]", = (int)wsabuf[0].len); } else /* error occurred */ { @@ -3716,8 +3520,7 @@ ASSERT(SetEvent(sock->reads.overlapped.hEvent)); sock->reads.iostate =3D IOSTATE_IMMEDIATE_RETURN; sock->reads.status =3D status; - dmsg(D_WIN32_IO, "WIN32 I/O: Socket Receive error [%d]: %s= ", - (int) wsabuf[0].len, + dmsg(D_WIN32_IO, "WIN32 I/O: Socket Receive error [%d]: %s= ", (int)wsabuf[0].len, strerror_win32(status, &gc)); gc_free(&gc); } @@ -3749,12 +3552,11 @@ if (socket_is_dco_win(sock)) { - status =3D WriteFile((HANDLE)sock->sd, wsabuf[0].buf, wsabuf[0= ].len, - &sock->writes.size, &sock->writes.overlappe= d); + status =3D WriteFile((HANDLE)sock->sd, wsabuf[0].buf, wsabuf[0= ].len, &sock->writes.size, + &sock->writes.overlapped); /* WriteFile status is inverted from WSASendTo */ status =3D !status; - } else if (proto_is_udp(sock->info.proto)) { @@ -3771,30 +3573,17 @@ sock->writes.addrlen =3D sizeof(sock->writes.addr); } - status =3D WSASendTo( - sock->sd, - wsabuf, - 1, - &sock->writes.size, - sock->writes.flags, - (struct sockaddr *) &sock->writes.addr, - sock->writes.addrlen, - &sock->writes.overlapped, - NULL); + status =3D WSASendTo(sock->sd, wsabuf, 1, &sock->writes.size, = sock->writes.flags, + (struct sockaddr *)&sock->writes.addr, sock= ->writes.addrlen, + &sock->writes.overlapped, NULL); } else if (proto_is_tcp(sock->info.proto)) { /* destination address for TCP writes was established on conne= ction initiation */ sock->writes.addr_defined =3D false; - status =3D WSASend( - sock->sd, - wsabuf, - 1, - &sock->writes.size, - sock->writes.flags, - &sock->writes.overlapped, - NULL); + status =3D WSASend(sock->sd, wsabuf, 1, &sock->writes.size, so= ck->writes.flags, + &sock->writes.overlapped, NULL); } else { @@ -3811,9 +3600,8 @@ sock->writes.status =3D 0; - dmsg(D_WIN32_IO, "WIN32 I/O: Socket Send immediate return [%d,= %d]", - (int) wsabuf[0].len, - (int) sock->writes.size); + dmsg(D_WIN32_IO, "WIN32 I/O: Socket Send immediate return [%d,= %d]", (int)wsabuf[0].len, + (int)sock->writes.size); } else { @@ -3823,8 +3611,7 @@ { sock->writes.iostate =3D IOSTATE_QUEUED; sock->writes.status =3D status; - dmsg(D_WIN32_IO, "WIN32 I/O: Socket Send queued [%d]", - (int) wsabuf[0].len); + dmsg(D_WIN32_IO, "WIN32 I/O: Socket Send queued [%d]", (in= t)wsabuf[0].len); } else /* error occurred */ { @@ -3833,8 +3620,7 @@ sock->writes.iostate =3D IOSTATE_IMMEDIATE_RETURN; sock->writes.status =3D status; - dmsg(D_WIN32_IO, "WIN32 I/O: Socket Send error [%d]: %s", - (int) wsabuf[0].len, + dmsg(D_WIN32_IO, "WIN32 I/O: Socket Send error [%d]: %s", = (int)wsabuf[0].len, strerror_win32(status, &gc)); gc_free(&gc); @@ -3906,7 +3692,9 @@ sa_len =3D sizeof(struct sockaddr_in); if (buf_len(buf) < sa_len) { - msg(M_FATAL, "ERROR: received incoming packet with too sho= rt length of %d -- must be at least %d.", buf_len(buf), sa_len); + msg(M_FATAL, + "ERROR: received incoming packet with too short length= of %d -- must be at least %d.", + buf_len(buf), sa_len); } memcpy(dst, sa, sa_len); buf_advance(buf, sa_len); @@ -3916,14 +3704,17 @@ sa_len =3D sizeof(struct sockaddr_in6); if (buf_len(buf) < sa_len) { - msg(M_FATAL, "ERROR: received incoming packet with too sho= rt length of %d -- must be at least %d.", buf_len(buf), sa_len); + msg(M_FATAL, + "ERROR: received incoming packet with too short length= of %d -- must be at least %d.", + buf_len(buf), sa_len); } memcpy(dst, sa, sa_len); buf_advance(buf, sa_len); break; default: - msg(M_FATAL, "ERROR: received incoming packet with invalid add= ress family %d.", sa->sa_family); + msg(M_FATAL, "ERROR: received incoming packet with invalid add= ress family %d.", + sa->sa_family); } return sa_len; @@ -3931,9 +3722,7 @@ /* Returns the number of bytes successfully read */ int -sockethandle_finalize(sockethandle_t sh, - struct overlapped_io *io, - struct buffer *buf, +sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, struct = buffer *buf, struct link_socket_actual *from) { int ret =3D -1; @@ -4026,10 +3815,7 @@ */ unsigned int -socket_set(struct link_socket *s, - struct event_set *es, - unsigned int rwflags, - void *arg, +socket_set(struct link_socket *s, struct event_set *es, unsigned int rwfla= gs, void *arg, unsigned int *persistent) { if (s) @@ -4109,20 +3895,15 @@ } =20 void -socket_bind_unix(socket_descriptor_t sd, - struct sockaddr_un *local, - const char *prefix) +socket_bind_unix(socket_descriptor_t sd, struct sockaddr_un *local, const = char *prefix) { struct gc_arena gc =3D gc_new(); const mode_t orig_umask =3D umask(0); - if (bind(sd, (struct sockaddr *) local, sizeof(struct sockaddr_un))) + if (bind(sd, (struct sockaddr *)local, sizeof(struct sockaddr_un))) { - msg(M_FATAL | M_ERRNO, - "%s: Socket bind[%d] failed on unix domain socket %s", - prefix, - (int)sd, - sockaddr_unix_name(local, "NULL")); + msg(M_FATAL | M_ERRNO, "%s: Socket bind[%d] failed on unix domain = socket %s", prefix, + (int)sd, sockaddr_unix_name(local, "NULL")); } umask(orig_umask); @@ -4130,14 +3911,13 @@ } socket_descriptor_t -socket_accept_unix(socket_descriptor_t sd, - struct sockaddr_un *remote) +socket_accept_unix(socket_descriptor_t sd, struct sockaddr_un *remote) { socklen_t remote_len =3D sizeof(struct sockaddr_un); socket_descriptor_t ret; CLEAR(*remote); - ret =3D accept(sd, (struct sockaddr *) remote, &remote_len); + ret =3D accept(sd, (struct sockaddr *)remote, &remote_len); if (ret >=3D 0) { /* set socket file descriptor to not pass across execs, so that @@ -4148,10 +3928,9 @@ } int -socket_connect_unix(socket_descriptor_t sd, - struct sockaddr_un *remote) +socket_connect_unix(socket_descriptor_t sd, struct sockaddr_un *remote) { - int status =3D connect(sd, (struct sockaddr *) remote, sizeof(struct s= ockaddr_un)); + int status =3D connect(sd, (struct sockaddr *)remote, sizeof(struct so= ckaddr_un)); if (status) { status =3D openvpn_errno(); diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index 6d71e83..f3f104e 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -65,7 +65,8 @@ struct openvpn_sockaddr { /*int dummy;*/ /* add offset to force a bug if sa not explicitly deref= erenced */ - union { + union + { struct sockaddr sa; struct sockaddr_in in4; struct sockaddr_in6 in6; @@ -73,7 +74,8 @@ }; /* struct to hold preresolved host names */ -struct cached_dns_entry { +struct cached_dns_entry +{ const char *hostname; const char *servname; int ai_family; @@ -89,7 +91,8 @@ struct openvpn_sockaddr dest; #if ENABLE_IP_PKTINFO - union { + union + { #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) struct in_pktinfo in4; #elif defined(IP_RECVDSTADDR) @@ -104,9 +107,9 @@ struct link_socket_addr { struct addrinfo *bind_local; - struct addrinfo *remote_list; /* complete remote list */ - struct addrinfo *current_remote; /* remote used in the - * current connection attempt */ + struct addrinfo *remote_list; /* complete remote list */ + struct addrinfo *current_remote; /* remote used in the + * current connection attempt */ struct link_socket_actual actual; /* reply to this address */ }; @@ -117,10 +120,10 @@ const char *ipchange_command; const struct plugin_list *plugins; bool remote_float; - int proto; /* Protocol (PROTO_x defined below) */ - sa_family_t af; /* Address family like AF_INET, AF= _INET6 or AF_UNSPEC*/ + int proto; /* Protocol (PROTO_x defined below) */ + sa_family_t af; /* Address family like AF_INET, AF_INET6 or AF_UNSPEC= */ bool bind_ipv6_only; - int mtu_changed; /* Set to true when mtu value is changed */ + int mtu_changed; /* Set to true when mtu value is changed */ }; /* @@ -136,7 +139,7 @@ struct buffer buf; struct buffer next; - int len; /* -1 if not yet known */ + int len; /* -1 if not yet known */ bool error; /* if true, fatal TCP error has occurred, * requiring that connection be restarted */ @@ -164,10 +167,8 @@ * @param sbs new sizes. * @param reduce_size apply the new size even if smaller than current one */ -void -socket_set_buffers(socket_descriptor_t fd, - const struct socket_buffer_size *sbs, - bool reduce_size); +void socket_set_buffers(socket_descriptor_t fd, const struct socket_buffer= _size *sbs, + bool reduce_size); /* * This is the main socket structure used by OpenVPN. The SOCKET_ @@ -178,10 +179,10 @@ { struct link_socket_info info; - struct event_arg ev_arg; /**< this struct will store a pointer to ei= ther mi or - * link_socket, depending on the event type= , to keep - * it accessible it's placed within the sam= e struct - * it points to. */ + struct event_arg ev_arg; /**< this struct will store a pointer to eith= er mi or + * link_socket, depending on the event type, = to keep + * it accessible it's placed within the same = struct + * it points to. */ socket_descriptor_t sd; socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */ @@ -206,9 +207,9 @@ struct cached_dns_entry *dns_cache; bool bind_local; -#define LS_MODE_DEFAULT 0 -#define LS_MODE_TCP_LISTEN 1 -#define LS_MODE_TCP_ACCEPT_FROM 2 +#define LS_MODE_DEFAULT 0 +#define LS_MODE_TCP_LISTEN 1 +#define LS_MODE_TCP_ACCEPT_FROM 2 int mode; int resolve_retry_seconds; @@ -216,15 +217,15 @@ struct socket_buffer_size socket_buffer_sizes; - int mtu; /* OS discovered MTU, or 0 if unknown */ + int mtu; /* OS discovered MTU, or 0 if unknown */ -#define SF_USE_IP_PKTINFO (1<<0) -#define SF_TCP_NODELAY (1<<1) -#define SF_PORT_SHARE (1<<2) -#define SF_HOST_RANDOMIZE (1<<3) -#define SF_GETADDRINFO_DGRAM (1<<4) -#define SF_DCO_WIN (1<<5) -#define SF_PREPEND_SA (1<<6) +#define SF_USE_IP_PKTINFO (1 << 0) +#define SF_TCP_NODELAY (1 << 1) +#define SF_PORT_SHARE (1 << 2) +#define SF_HOST_RANDOMIZE (1 << 3) +#define SF_GETADDRINFO_DGRAM (1 << 4) +#define SF_DCO_WIN (1 << 5) +#define SF_PREPEND_SA (1 << 6) unsigned int sockflags; int mark; const char *bind_dev; @@ -278,12 +279,13 @@ int socket_recv_queue(struct link_socket *sock, int maxsize); -int socket_send_queue(struct link_socket *sock, - struct buffer *buf, +int socket_send_queue(struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to); -typedef struct { - union { +typedef struct +{ + union + { SOCKET s; HANDLE h; }; @@ -291,17 +293,15 @@ bool prepend_sa; /* are incoming packets prepended with sockaddr? */ } sockethandle_t; -int sockethandle_finalize(sockethandle_t sh, - struct overlapped_io *io, - struct buffer *buf, +int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, str= uct buffer *buf, struct link_socket_actual *from); static inline BOOL SocketHandleGetOverlappedResult(sockethandle_t sh, struct overlapped_io *i= o) { - return sh.is_handle ? - GetOverlappedResult(sh.h, &io->overlapped, &io->size, FALSE) : - WSAGetOverlappedResult(sh.s, &io->overlapped, &io->size, FALSE,= &io->flags); + return sh.is_handle + ? GetOverlappedResult(sh.h, &io->overlapped, &io->size, FAL= SE) + : WSAGetOverlappedResult(sh.s, &io->overlapped, &io->size, = FALSE, &io->flags); } static inline int @@ -322,7 +322,7 @@ sh.is_handle ? SetLastError(ERROR_INVALID_FUNCTION) : WSASetLastError(= WSAEINVAL); } -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ #define openvpn_close_socket(s) close(s) @@ -330,29 +330,19 @@ struct link_socket *link_socket_new(void); -void socket_bind(socket_descriptor_t sd, - struct addrinfo *local, - int af_family, - const char *prefix, +void socket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_fa= mily, const char *prefix, bool ipv6only); -int openvpn_connect(socket_descriptor_t sd, - const struct sockaddr *remote, - int connect_timeout, +int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote,= int connect_timeout, volatile int *signal_received); - /* * Initialize link_socket object. */ -void -link_socket_init_phase1(struct context *c, - int sock_index, - int mode); +void link_socket_init_phase1(struct context *c, int sock_index, int mode); -void link_socket_init_phase2(struct context *c, - struct link_socket *sock); +void link_socket_init_phase2(struct context *c, struct link_socket *sock); void do_preresolve(struct context *c); @@ -360,75 +350,57 @@ void sd_close(socket_descriptor_t *sd); -#define PS_SHOW_PORT_IF_DEFINED (1<<0) -#define PS_SHOW_PORT (1<<1) -#define PS_SHOW_PKTINFO (1<<2) -#define PS_DONT_SHOW_ADDR (1<<3) -#define PS_DONT_SHOW_FAMILY (1<<4) +#define PS_SHOW_PORT_IF_DEFINED (1 << 0) +#define PS_SHOW_PORT (1 << 1) +#define PS_SHOW_PKTINFO (1 << 2) +#define PS_DONT_SHOW_ADDR (1 << 3) +#define PS_DONT_SHOW_FAMILY (1 << 4) -const char *print_sockaddr_ex(const struct sockaddr *addr, - const char *separator, - const unsigned int flags, - struct gc_arena *gc); +const char *print_sockaddr_ex(const struct sockaddr *addr, const char *sep= arator, + const unsigned int flags, struct gc_arena *g= c); -static inline -const char * -print_openvpn_sockaddr(const struct openvpn_sockaddr *addr, - struct gc_arena *gc) +static inline const char * +print_openvpn_sockaddr(const struct openvpn_sockaddr *addr, struct gc_aren= a *gc) { return print_sockaddr_ex(&addr->addr.sa, ":", PS_SHOW_PORT, gc); } -static inline -const char * -print_sockaddr(const struct sockaddr *addr, - struct gc_arena *gc) +static inline const char * +print_sockaddr(const struct sockaddr *addr, struct gc_arena *gc) { return print_sockaddr_ex(addr, ":", PS_SHOW_PORT, gc); } +const char *print_link_socket_actual_ex(const struct link_socket_actual *a= ct, const char *separator, + const unsigned int flags, struct g= c_arena *gc); -const char *print_link_socket_actual_ex(const struct link_socket_actual *a= ct, - const char *separator, - const unsigned int flags, - struct gc_arena *gc); - -const char *print_link_socket_actual(const struct link_socket_actual *act, - struct gc_arena *gc); +const char *print_link_socket_actual(const struct link_socket_actual *act,= struct gc_arena *gc); -#define IA_EMPTY_IF_UNDEF (1<<0) -#define IA_NET_ORDER (1<<1) +#define IA_EMPTY_IF_UNDEF (1 << 0) +#define IA_NET_ORDER (1 << 1) const char *print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_= arena *gc); const char *print_in6_addr(struct in6_addr addr6, unsigned int flags, stru= ct gc_arena *gc); const char *print_in_port_t(in_port_t port, struct gc_arena *gc); -struct in6_addr add_in6_addr( struct in6_addr base, uint32_t add ); +struct in6_addr add_in6_addr(struct in6_addr base, uint32_t add); -#define SA_IP_PORT (1<<0) -#define SA_SET_IF_NONZERO (1<<1) -void setenv_sockaddr(struct env_set *es, - const char *name_prefix, - const struct openvpn_sockaddr *addr, - const unsigned int flags); +#define SA_IP_PORT (1 << 0) +#define SA_SET_IF_NONZERO (1 << 1) +void setenv_sockaddr(struct env_set *es, const char *name_prefix, + const struct openvpn_sockaddr *addr, const unsigned i= nt flags); -void setenv_in_addr_t(struct env_set *es, - const char *name_prefix, - in_addr_t addr, +void setenv_in_addr_t(struct env_set *es, const char *name_prefix, in_addr= _t addr, const unsigned int flags); -void setenv_in6_addr(struct env_set *es, - const char *name_prefix, - const struct in6_addr *addr, +void setenv_in6_addr(struct env_set *es, const char *name_prefix, const st= ruct in6_addr *addr, const unsigned int flags); -void setenv_link_socket_actual(struct env_set *es, - const char *name_prefix, - const struct link_socket_actual *act, - const unsigned int flags); +void setenv_link_socket_actual(struct env_set *es, const char *name_prefix, + const struct link_socket_actual *act, const= unsigned int flags); void bad_address_length(int actual, int expected); @@ -438,20 +410,16 @@ #define IPV4_INVALID_ADDR 0xffffffff in_addr_t link_socket_current_remote(const struct link_socket_info *info); -const struct in6_addr *link_socket_current_remote_ipv6 - (const struct link_socket_info *info); +const struct in6_addr *link_socket_current_remote_ipv6(const struct link_s= ocket_info *info); void link_socket_connection_initiated(struct link_socket_info *info, const struct link_socket_actual *add= r, - const char *common_name, - struct env_set *es); + const char *common_name, struct env_= set *es); -void link_socket_bad_incoming_addr(struct buffer *buf, - const struct link_socket_info *info, +void link_socket_bad_incoming_addr(struct buffer *buf, const struct link_s= ocket_info *info, const struct link_socket_actual *from_a= ddr); -void set_actual_address(struct link_socket_actual *actual, - struct addrinfo *ai); +void set_actual_address(struct link_socket_actual *actual, struct addrinfo= *ai); void link_socket_bad_outgoing_addr(void); @@ -466,9 +434,9 @@ */ /* return values of openvpn_inet_aton */ -#define OIA_HOSTNAME 0 -#define OIA_IP 1 -#define OIA_ERROR -1 +#define OIA_HOSTNAME 0 +#define OIA_IP 1 +#define OIA_ERROR -1 int openvpn_inet_aton(const char *dotted_quad, struct in_addr *addr); /* integrity validation on pulled options */ @@ -482,23 +450,18 @@ socket_descriptor_t create_socket_tcp(struct addrinfo *); -socket_descriptor_t socket_do_accept(socket_descriptor_t sd, - struct link_socket_actual *act, +socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_s= ocket_actual *act, const bool nowait); #if UNIX_SOCK_SUPPORT socket_descriptor_t create_socket_unix(void); -void socket_bind_unix(socket_descriptor_t sd, - struct sockaddr_un *local, - const char *prefix); +void socket_bind_unix(socket_descriptor_t sd, struct sockaddr_un *local, c= onst char *prefix); -socket_descriptor_t socket_accept_unix(socket_descriptor_t sd, - struct sockaddr_un *remote); +socket_descriptor_t socket_accept_unix(socket_descriptor_t sd, struct sock= addr_un *remote); -int socket_connect_unix(socket_descriptor_t sd, - struct sockaddr_un *remote); +int socket_connect_unix(socket_descriptor_t sd, struct sockaddr_un *remote= ); void sockaddr_unix_init(struct sockaddr_un *local, const char *path); @@ -514,20 +477,20 @@ * DNS resolution */ -#define GETADDR_RESOLVE (1<<0) -#define GETADDR_FATAL (1<<1) -#define GETADDR_HOST_ORDER (1<<2) -#define GETADDR_MENTION_RESOLVE_RETRY (1<<3) -#define GETADDR_FATAL_ON_SIGNAL (1<<4) -#define GETADDR_WARN_ON_SIGNAL (1<<5) -#define GETADDR_MSG_VIRT_OUT (1<<6) -#define GETADDR_TRY_ONCE (1<<7) -#define GETADDR_UPDATE_MANAGEMENT_STATE (1<<8) -#define GETADDR_RANDOMIZE (1<<9) -#define GETADDR_PASSIVE (1<<10) -#define GETADDR_DATAGRAM (1<<11) +#define GETADDR_RESOLVE (1 << 0) +#define GETADDR_FATAL (1 << 1) +#define GETADDR_HOST_ORDER (1 << 2) +#define GETADDR_MENTION_RESOLVE_RETRY (1 << 3) +#define GETADDR_FATAL_ON_SIGNAL (1 << 4) +#define GETADDR_WARN_ON_SIGNAL (1 << 5) +#define GETADDR_MSG_VIRT_OUT (1 << 6) +#define GETADDR_TRY_ONCE (1 << 7) +#define GETADDR_UPDATE_MANAGEMENT_STATE (1 << 8) +#define GETADDR_RANDOMIZE (1 << 9) +#define GETADDR_PASSIVE (1 << 10) +#define GETADDR_DATAGRAM (1 << 11) -#define GETADDR_CACHE_MASK (GETADDR_DATAGRAM|GETADDR_PASSIVE) +#define GETADDR_CACHE_MASK (GETADDR_DATAGRAM | GETADDR_PASSIVE) /** * Translate an IPv4 addr or hostname from string form to in_addr_t @@ -535,24 +498,17 @@ * In case of resolve error, it will try again for * resolve_retry_seconds seconds. */ -in_addr_t getaddr(unsigned int flags, - const char *hostname, - int resolve_retry_seconds, - bool *succeeded, - struct signal_info *sig_info); +in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_re= try_seconds, + bool *succeeded, struct signal_info *sig_info); /** * Translate an IPv6 addr or hostname from string form to in6_addr */ -bool get_ipv6_addr(const char *hostname, struct in6_addr *network, - unsigned int *netbits, int msglevel); +bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigne= d int *netbits, + int msglevel); -int openvpn_getaddrinfo(unsigned int flags, - const char *hostname, - const char *servname, - int resolve_retry_seconds, - struct signal_info *sig_info, - int ai_family, +int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const ch= ar *servname, + int resolve_retry_seconds, struct signal_info *sig= _info, int ai_family, struct addrinfo **res); /* @@ -563,8 +519,9 @@ * Use enum's instead of #define to allow for easier * optional proto support */ -enum proto_num { - PROTO_NONE, /* catch for uninitialized */ +enum proto_num +{ + PROTO_NONE, /* catch for uninitialized */ PROTO_UDP, PROTO_TCP, PROTO_TCP_SERVER, @@ -666,11 +623,14 @@ } switch (addr->addr.sa.sa_family) { - case AF_INET: return addr->addr.in4.sin_addr.s_addr !=3D 0; + case AF_INET: + return addr->addr.in4.sin_addr.s_addr !=3D 0; - case AF_INET6: return !IN6_IS_ADDR_UNSPECIFIED(&addr->addr.in6.sin= 6_addr); + case AF_INET6: + return !IN6_IS_ADDR_UNSPECIFIED(&addr->addr.in6.sin6_addr); - default: return 0; + default: + return 0; } } @@ -706,17 +666,21 @@ switch (lsa->dest.addr.sa.sa_family) { #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) - case AF_INET: return lsa->pi.in4.ipi_spec_dst.s_addr !=3D 0; + case AF_INET: + return lsa->pi.in4.ipi_spec_dst.s_addr !=3D 0; #elif defined(IP_RECVDSTADDR) - case AF_INET: return lsa->pi.in4.s_addr !=3D 0; + case AF_INET: + return lsa->pi.in4.s_addr !=3D 0; #endif - case AF_INET6: return !IN6_IS_ADDR_UNSPECIFIED(&lsa->pi.in6.ipi6_a= ddr); + case AF_INET6: + return !IN6_IS_ADDR_UNSPECIFIED(&lsa->pi.in6.ipi6_addr); - default: return 0; + default: + return 0; } -#else /* if ENABLE_IP_PKTINFO */ +#else /* if ENABLE_IP_PKTINFO */ ASSERT(0); #endif return false; @@ -752,14 +716,16 @@ switch (a1->addr.sa.sa_family) { case AF_INET: - if (a1->addr.in4.sin_addr.s_addr =3D=3D ((struct sockaddr_= in *)curele->ai_addr)->sin_addr.s_addr) + if (a1->addr.in4.sin_addr.s_addr + =3D=3D ((struct sockaddr_in *)curele->ai_addr)->sin_ad= dr.s_addr) { return true; } break; case AF_INET6: - if (IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &((struct = sockaddr_in6 *) curele->ai_addr)->sin6_addr)) + if (IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, + &((struct sockaddr_in6 *)curele->ai= _addr)->sin6_addr)) { return true; } @@ -782,7 +748,8 @@ { case AF_INET: if (curele->ai_family =3D=3D AF_INET - && a1->addr.in4.sin_addr.s_addr =3D=3D ((struct sockad= dr_in *)curele->ai_addr)->sin_addr.s_addr + && a1->addr.in4.sin_addr.s_addr + =3D=3D ((struct sockaddr_in *)curele->ai_addr)-= >sin_addr.s_addr && a1->addr.in4.sin_port =3D=3D ((struct sockaddr_in *= )curele->ai_addr)->sin_port) { return true; @@ -791,8 +758,10 @@ case AF_INET6: if (curele->ai_family =3D=3D AF_INET6 - && IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &((stru= ct sockaddr_in6 *) curele->ai_addr)->sin6_addr) - && a1->addr.in6.sin6_port =3D=3D ((struct sockaddr_in6= *) curele->ai_addr)->sin6_port) + && IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, + &((struct sockaddr_in6 *)curele-= >ai_addr)->sin6_addr) + && a1->addr.in6.sin6_port + =3D=3D ((struct sockaddr_in6 *)curele->ai_addr)= ->sin6_port) { return true; } @@ -806,7 +775,6 @@ } - static inline bool addr_port_match(const struct openvpn_sockaddr *a1, const struct openvpn_so= ckaddr *a2) { @@ -825,24 +793,19 @@ } static inline bool -addr_match_proto(const struct openvpn_sockaddr *a1, - const struct openvpn_sockaddr *a2, +addr_match_proto(const struct openvpn_sockaddr *a1, const struct openvpn_s= ockaddr *a2, const int proto) { - return link_socket_proto_connection_oriented(proto) - ? addr_match(a1, a2) - : addr_port_match(a1, a2); + return link_socket_proto_connection_oriented(proto) ? addr_match(a1, a= 2) + : addr_port_match(= a1, a2); } static inline bool -addrlist_match_proto(const struct openvpn_sockaddr *a1, - struct addrinfo *addr_list, - const int proto) +addrlist_match_proto(const struct openvpn_sockaddr *a1, struct addrinfo *a= ddr_list, const int proto) { - return link_socket_proto_connection_oriented(proto) - ? addrlist_match(a1, addr_list) - : addrlist_port_match(a1, addr_list); + return link_socket_proto_connection_oriented(proto) ? addrlist_match(a= 1, addr_list) + : addrlist_port_ma= tch(a1, addr_list); } static inline void @@ -865,9 +828,11 @@ { switch (af) { - case AF_INET: return sizeof(struct sockaddr_in); + case AF_INET: + return sizeof(struct sockaddr_in); - case AF_INET6: return sizeof(struct sockaddr_in6); + case AF_INET6: + return sizeof(struct sockaddr_in6); default: #if 0 @@ -890,8 +855,7 @@ static inline bool socket_foreign_protocol_detected(const struct link_socket *sock) { - return link_socket_connection_oriented(sock) - && sock->stream_buf.port_share_state =3D=3D PS_FOREIGN; + return link_socket_connection_oriented(sock) && sock->stream_buf.port_= share_state =3D=3D PS_FOREIGN; } static inline const struct buffer * @@ -932,8 +896,7 @@ } static inline bool -link_socket_verify_incoming_addr(struct buffer *buf, - const struct link_socket_info *info, +link_socket_verify_incoming_addr(struct buffer *buf, const struct link_soc= ket_info *info, const struct link_socket_actual *from_add= r) { if (buf->len > 0) @@ -960,8 +923,7 @@ } static inline void -link_socket_get_outgoing_addr(struct buffer *buf, - const struct link_socket_info *info, +link_socket_get_outgoing_addr(struct buffer *buf, const struct link_socket= _info *info, struct link_socket_actual **act) { if (buf->len > 0) @@ -981,23 +943,18 @@ } static inline void -link_socket_set_outgoing_addr(struct link_socket_info *info, - const struct link_socket_actual *act, - const char *common_name, - struct env_set *es) +link_socket_set_outgoing_addr(struct link_socket_info *info, const struct = link_socket_actual *act, + const char *common_name, struct env_set *es) { struct link_socket_addr *lsa =3D info->lsa; if ( /* new or changed address? */ (!info->connection_established - || !addr_match_proto(&act->dest, &lsa->actual.dest, info->proto) - ) + || !addr_match_proto(&act->dest, &lsa->actual.dest, info->proto)) && /* address undef or address =3D=3D remote or --float */ (info->remote_float - || (!lsa->remote_list || addrlist_match_proto(&act->dest, lsa->re= mote_list, info->proto)) - ) - ) + || (!lsa->remote_list || addrlist_match_proto(&act->dest, lsa->re= mote_list, info->proto)))) { link_socket_connection_initiated(info, act, common_name, es); } @@ -1033,14 +990,12 @@ * Socket Read Routines */ -int link_socket_read_tcp(struct link_socket *sock, - struct buffer *buf); +int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf); #ifdef _WIN32 static inline int -link_socket_read_udp_win32(struct link_socket *sock, - struct buffer *buf, +link_socket_read_udp_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from) { sockethandle_t sh =3D { .s =3D sock->sd }; @@ -1055,17 +1010,14 @@ #else /* ifdef _WIN32 */ -int link_socket_read_udp_posix(struct link_socket *sock, - struct buffer *buf, +int link_socket_read_udp_posix(struct link_socket *sock, struct buffer *bu= f, struct link_socket_actual *from); #endif /* ifdef _WIN32 */ /* read a TCP or UDP packet from link */ static inline int -link_socket_read(struct link_socket *sock, - struct buffer *buf, - struct link_socket_actual *from) +link_socket_read(struct link_socket *sock, struct buffer *buf, struct link= _socket_actual *from) { if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock)) /* unified UDPv4 and UDPv6, for DCO-WIN the kernel @@ -1097,16 +1049,13 @@ * Socket Write routines */ -ssize_t link_socket_write_tcp(struct link_socket *sock, - struct buffer *buf, +ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to); #ifdef _WIN32 =20 static inline int -link_socket_write_win32(struct link_socket *sock, - struct buffer *buf, - struct link_socket_actual *to) +link_socket_write_win32(struct link_socket *sock, struct buffer *buf, stru= ct link_socket_actual *to) { int err =3D 0; int status =3D 0; @@ -1145,16 +1094,14 @@ } } -#else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ -ssize_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock, - struct buffer *buf, +ssize_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock, stru= ct buffer *buf, struct link_socket_actual *to); static inline ssize_t -link_socket_write_udp_posix(struct link_socket *sock, - struct buffer *buf, +link_socket_write_udp_posix(struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to) { #if ENABLE_IP_PKTINFO @@ -1165,14 +1112,12 @@ } else #endif - return sendto(sock->sd, BPTR(buf), BLEN(buf), 0, - (struct sockaddr *) &to->dest.addr.sa, - (socklen_t) af_addr_size(to->dest.addr.sa.sa_family)); + return sendto(sock->sd, BPTR(buf), BLEN(buf), 0, (struct sockaddr = *)&to->dest.addr.sa, + (socklen_t)af_addr_size(to->dest.addr.sa.sa_family)); } static inline ssize_t -link_socket_write_tcp_posix(struct link_socket *sock, - struct buffer *buf) +link_socket_write_tcp_posix(struct link_socket *sock, struct buffer *buf) { return send(sock->sd, BPTR(buf), BLEN(buf), MSG_NOSIGNAL); } @@ -1180,9 +1125,7 @@ #endif /* ifdef _WIN32 */ static inline ssize_t -link_socket_write_udp(struct link_socket *sock, - struct buffer *buf, - struct link_socket_actual *to) +link_socket_write_udp(struct link_socket *sock, struct buffer *buf, struct= link_socket_actual *to) { #ifdef _WIN32 return link_socket_write_win32(sock, buf, to); @@ -1193,9 +1136,7 @@ /* write a TCP or UDP packet to link */ static inline ssize_t -link_socket_write(struct link_socket *sock, - struct buffer *buf, - struct link_socket_actual *to) +link_socket_write(struct link_socket *sock, struct buffer *buf, struct lin= k_socket_actual *to) { if (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock)) { @@ -1223,7 +1164,7 @@ { if (sock && ipbuf) { - struct openvpn_iphdr *iph =3D (struct openvpn_iphdr *) BPTR(ipbuf); + struct openvpn_iphdr *iph =3D (struct openvpn_iphdr *)BPTR(ipbuf); sock->ptos =3D iph->tos; sock->ptos_defined =3D true; } @@ -1267,17 +1208,11 @@ event_t socket_listen_event_handle(struct link_socket *sock); -unsigned int -socket_set(struct link_socket *sock, - struct event_set *es, - unsigned int rwflags, - void *arg, - unsigned int *persistent); +unsigned int socket_set(struct link_socket *sock, struct event_set *es, un= signed int rwflags, + void *arg, unsigned int *persistent); static inline void -socket_set_listen_persistent(struct link_socket *sock, - struct event_set *es, - void *arg) +socket_set_listen_persistent(struct link_socket *sock, struct event_set *e= s, void *arg) { if (sock && !sock->listen_persistent_queued) { diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c index cc2dbdf..4ad9622 100644 --- a/src/openvpn/socks.c +++ b/src/openvpn/socks.c @@ -46,12 +46,10 @@ #include "memdbg.h" -#define UP_TYPE_SOCKS "SOCKS Proxy" +#define UP_TYPE_SOCKS "SOCKS Proxy" struct socks_proxy_info * -socks_proxy_new(const char *server, - const char *port, - const char *authfile) +socks_proxy_new(const char *server, const char *port, const char *authfile) { struct socks_proxy_info *p; @@ -84,8 +82,7 @@ } static bool -socks_username_password_auth(struct socks_proxy_info *p, - socket_descriptor_t sd, +socks_username_password_auth(struct socks_proxy_info *p, socket_descriptor= _t sd, struct event_timeout *server_poll_timeout, volatile int *signal_received) { @@ -103,24 +100,23 @@ goto cleanup; } - if ( (strlen(creds.username) > 255) || (strlen(creds.password) > 255) ) + if ((strlen(creds.username) > 255) || (strlen(creds.password) > 255)) { - msg(M_NONFATAL, - "SOCKS username and/or password exceeds 255 characters. " - "Authentication not possible."); + msg(M_NONFATAL, "SOCKS username and/or password exceeds 255 charac= ters. " + "Authentication not possible."); goto cleanup; } - int sret =3D snprintf(to_send, sizeof(to_send), "\x01%c%s%c%s", - (int) strlen(creds.username), creds.username, - (int) strlen(creds.password), creds.password); + int sret =3D snprintf(to_send, sizeof(to_send), "\x01%c%s%c%s", (int)s= trlen(creds.username), + creds.username, (int)strlen(creds.password), creds= .password); ASSERT(sret <=3D sizeof(to_send)); size =3D send(sd, to_send, strlen(to_send), MSG_NOSIGNAL); if (size !=3D strlen(to_send)) { - msg(D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TCP po= rt write failed on send()"); + msg(D_LINK_ERRORS | M_ERRNO, + "socks_username_password_auth: TCP port write failed on send()= "); goto cleanup; } @@ -148,14 +144,16 @@ /* timeout? */ if (status =3D=3D 0) { - msg(D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TC= P port read timeout expired"); + msg(D_LINK_ERRORS | M_ERRNO, + "socks_username_password_auth: TCP port read timeout expir= ed"); goto cleanup; } /* error */ if (status < 0) { - msg(D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TC= P port read failed on select()"); + msg(D_LINK_ERRORS | M_ERRNO, + "socks_username_password_auth: TCP port read failed on sel= ect()"); goto cleanup; } @@ -165,7 +163,8 @@ /* error? */ if (size !=3D 1) { - msg(D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TC= P port read failed on recv()"); + msg(D_LINK_ERRORS | M_ERRNO, + "socks_username_password_auth: TCP port read failed on rec= v()"); goto cleanup; } @@ -188,10 +187,8 @@ } static bool -socks_handshake(struct socks_proxy_info *p, - socket_descriptor_t sd, - struct event_timeout *server_poll_timeout, - volatile int *signal_received) +socks_handshake(struct socks_proxy_info *p, socket_descriptor_t sd, + struct event_timeout *server_poll_timeout, volatile int *s= ignal_received) { char buf[2]; int len =3D 0; @@ -202,7 +199,6 @@ if (p->authfile[0]) { method_sel[2] =3D 0x02; /* METHODS =3D [2 (plain login)] */ - } size =3D send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL); if (size !=3D sizeof(method_sel)) @@ -283,7 +279,8 @@ case 2: /* login/password */ if (!p->authfile[0]) { - msg(D_LINK_ERRORS, "socks_handshake: server asked for user= name/login auth but we were " + msg(D_LINK_ERRORS, + "socks_handshake: server asked for username/login auth= but we were " "not provided any credentials"); return false; } @@ -304,15 +301,13 @@ } static bool -recv_socks_reply(socket_descriptor_t sd, - struct openvpn_sockaddr *addr, - struct event_timeout *server_poll_timeout, - volatile int *signal_received) +recv_socks_reply(socket_descriptor_t sd, struct openvpn_sockaddr *addr, + struct event_timeout *server_poll_timeout, volatile int *= signal_received) { char atyp =3D '\0'; int alen =3D 0; int len =3D 0; - char buf[270]; /* 4 + alen(max 256) + 2 */ + char buf[270]; /* 4 + alen(max 256) + 2 */ if (addr !=3D NULL) { @@ -380,18 +375,18 @@ { switch (atyp) { - case '\x01': /* IP V4 */ + case '\x01': /* IP V4 */ alen =3D 4; break; - case '\x03': /* DOMAINNAME */ + case '\x03': /* DOMAINNAME */ /* RFC 1928, section 5: 1 byte length, bytes name, * so the total "address length" is (length+1) */ - alen =3D (unsigned char) c + 1; + alen =3D (unsigned char)c + 1; break; - case '\x04': /* IP V6 */ + case '\x04': /* IP V6 */ alen =3D 16; break; @@ -422,8 +417,7 @@ memcpy(&addr->addr.in4.sin_addr, buf + 4, sizeof(addr->addr.in4.si= n_addr)); memcpy(&addr->addr.in4.sin_port, buf + 8, sizeof(addr->addr.in4.si= n_port)); struct gc_arena gc =3D gc_new(); - msg(M_INFO, "SOCKS proxy wants us to send UDP to %s", - print_openvpn_sockaddr(addr, &gc)); + msg(M_INFO, "SOCKS proxy wants us to send UDP to %s", print_openvp= n_sockaddr(addr, &gc)); gc_free(&gc); } @@ -436,12 +430,12 @@ { int port =3D 0; port =3D atoi(servname); - if (port >0 && port < 65536) + if (port > 0 && port < 65536) { return port; } - struct servent *service; + struct servent *service; service =3D getservbyname(servname, NULL); if (service) { @@ -453,9 +447,9 @@ void establish_socks_proxy_passthru(struct socks_proxy_info *p, - socket_descriptor_t sd, /* already open to= proxy */ - const char *host, /* openvpn server = remote */ - const char *servname, /* openvpn server = port */ + socket_descriptor_t sd, /* already open to = proxy */ + const char *host, /* openvpn server r= emote */ + const char *servname, /* openvpn server p= ort */ struct event_timeout *server_poll_timeout, struct signal_info *sig_info) { @@ -468,32 +462,34 @@ } /* format Socks CONNECT message */ - buf[0] =3D '\x05'; /* VER =3D 5 */ - buf[1] =3D '\x01'; /* CMD =3D 1 (CONNECT) */ - buf[2] =3D '\x00'; /* RSV */ - buf[3] =3D '\x03'; /* ATYP =3D 3 (DOMAINNAME) */ + buf[0] =3D '\x05'; /* VER =3D 5 */ + buf[1] =3D '\x01'; /* CMD =3D 1 (CONNECT) */ + buf[2] =3D '\x00'; /* RSV */ + buf[3] =3D '\x03'; /* ATYP =3D 3 (DOMAINNAME) */ len =3D strlen(host); len =3D (5 + len + 2 > sizeof(buf)) ? (sizeof(buf) - 5 - 2) : len; - buf[4] =3D (char) len; + buf[4] =3D (char)len; memcpy(buf + 5, host, len); int port =3D port_from_servname(servname); - if (port =3D=3D0) + if (port =3D=3D 0) { - msg(D_LINK_ERRORS, "establish_socks_proxy_passthrough: Cannot conv= ert %s to port number", servname); + msg(D_LINK_ERRORS, "establish_socks_proxy_passthrough: Cannot conv= ert %s to port number", + servname); goto error; } - buf[5 + len] =3D (char) (port >> 8); - buf[5 + len + 1] =3D (char) (port & 0xff); + buf[5 + len] =3D (char)(port >> 8); + buf[5 + len + 1] =3D (char)(port & 0xff); { const ssize_t size =3D send(sd, buf, 5 + len + 2, MSG_NOSIGNAL); if ((int)size !=3D 5 + (int)len + 2) { - msg(D_LINK_ERRORS | M_ERRNO, "establish_socks_proxy_passthru: = TCP port write failed on send()"); + msg(D_LINK_ERRORS | M_ERRNO, + "establish_socks_proxy_passthru: TCP port write failed on = send()"); goto error; } } @@ -515,7 +511,7 @@ void establish_socks_proxy_udpassoc(struct socks_proxy_info *p, - socket_descriptor_t ctrl_sd, /* already op= en to proxy */ + socket_descriptor_t ctrl_sd, /* already ope= n to proxy */ struct openvpn_sockaddr *relay_addr, struct event_timeout *server_poll_timeout, struct signal_info *sig_info) @@ -529,12 +525,12 @@ /* send Socks UDP ASSOCIATE message */ /* VER =3D 5, CMD =3D 3 (UDP ASSOCIATE), RSV =3D 0, ATYP =3D 1 (IP= V4), * BND.ADDR =3D 0, BND.PORT =3D 0 */ - const ssize_t size =3D send(ctrl_sd, - "\x05\x03\x00\x01\x00\x00\x00\x00\x00\x0= 0", - 10, MSG_NOSIGNAL); + const ssize_t size =3D + send(ctrl_sd, "\x05\x03\x00\x01\x00\x00\x00\x00\x00\x00", 10, = MSG_NOSIGNAL); if (size !=3D 10) { - msg(D_LINK_ERRORS | M_ERRNO, "establish_socks_proxy_passthru: = TCP port write failed on send()"); + msg(D_LINK_ERRORS | M_ERRNO, + "establish_socks_proxy_passthru: TCP port write failed on = send()"); goto error; } } @@ -561,8 +557,7 @@ * Run after UDP read. */ void -socks_process_incoming_udp(struct buffer *buf, - struct link_socket_actual *from) +socks_process_incoming_udp(struct buffer *buf, struct link_socket_actual *= from) { int atyp; @@ -578,7 +573,7 @@ } atyp =3D buf_read_u8(buf); - if (atyp !=3D 1) /* ATYP =3D=3D 1 (IP V4) */ + if (atyp !=3D 1) /* ATYP =3D=3D 1 (IP V4) */ { goto error; } @@ -600,8 +595,7 @@ * Returns the size of the header. */ int -socks_process_outgoing_udp(struct buffer *buf, - const struct link_socket_actual *to) +socks_process_outgoing_udp(struct buffer *buf, const struct link_socket_ac= tual *to) { /* * Get a 10 byte subset buffer prepended to buf -- @@ -613,8 +607,8 @@ /* crash if not enough headroom in buf */ ASSERT(buf_defined(&head)); - buf_write_u16(&head, 0); /* RSV =3D 0 */ - buf_write_u8(&head, 0); /* FRAG =3D 0 */ + buf_write_u16(&head, 0); /* RSV =3D 0 */ + buf_write_u8(&head, 0); /* FRAG =3D 0 */ buf_write_u8(&head, '\x01'); /* ATYP =3D 1 (IP V4) */ buf_write(&head, &to->dest.addr.in4.sin_addr, sizeof(to->dest.addr.in4= .sin_addr)); buf_write(&head, &to->dest.addr.in4.sin_port, sizeof(to->dest.addr.in4= .sin_port)); diff --git a/src/openvpn/socks.h b/src/openvpn/socks.h index 0eaa9da..03d74d9 100644 --- a/src/openvpn/socks.h +++ b/src/openvpn/socks.h @@ -34,7 +34,8 @@ struct openvpn_sockaddr; struct link_socket_actual; -struct socks_proxy_info { +struct socks_proxy_info +{ bool defined; char server[128]; @@ -42,29 +43,26 @@ char authfile[256]; }; -struct socks_proxy_info *socks_proxy_new(const char *server, - const char *port, +struct socks_proxy_info *socks_proxy_new(const char *server, const char *p= ort, const char *authfile); =20 void socks_proxy_close(struct socks_proxy_info *sp); void establish_socks_proxy_passthru(struct socks_proxy_info *p, - socket_descriptor_t sd, /* already op= en to proxy */ - const char *host, /* openvpn se= rver remote */ - const char *servname, /* open= vpn server port */ + socket_descriptor_t sd, /* already ope= n to proxy */ + const char *host, /* openvpn ser= ver remote */ + const char *servname, /* openvpn ser= ver port */ struct event_timeout *server_poll_time= out, struct signal_info *sig_info); void establish_socks_proxy_udpassoc(struct socks_proxy_info *p, - socket_descriptor_t ctrl_sd, /* alrea= dy open to proxy */ + socket_descriptor_t ctrl_sd, /* alread= y open to proxy */ struct openvpn_sockaddr *relay_addr, struct event_timeout *server_poll_time= out, struct signal_info *sig_info); -void socks_process_incoming_udp(struct buffer *buf, - struct link_socket_actual *from); +void socks_process_incoming_udp(struct buffer *buf, struct link_socket_act= ual *from); -int socks_process_outgoing_udp(struct buffer *buf, - const struct link_socket_actual *to); +int socks_process_outgoing_udp(struct buffer *buf, const struct link_socke= t_actual *to); #endif /* ifndef SOCKS_H */ diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 9c6616a..b72aa7f 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -75,20 +75,20 @@ static int tls_packets_generated; /* GLOBAL */ static int tls_packets_sent; /* GLOBAL */ -#define INCR_SENT ++tls_packets_sent -#define INCR_GENERATED ++tls_packets_generated -#define INCR_SUCCESS ++tls_handshake_success -#define INCR_ERROR ++tls_handshake_error +#define INCR_SENT ++tls_packets_sent +#define INCR_GENERATED ++tls_packets_generated +#define INCR_SUCCESS ++tls_handshake_success +#define INCR_ERROR ++tls_handshake_error void show_tls_performance_stats(void) { msg(D_TLS_DEBUG_LOW, "TLS Handshakes, success=3D%f%% (good=3D%d, bad= =3D%d), retransmits=3D%f%%", - (double) tls_handshake_success / (tls_handshake_success + tls_hand= shake_error) * 100.0, + (double)tls_handshake_success / (tls_handshake_success + tls_hands= hake_error) * 100.0, tls_handshake_success, tls_handshake_error, - (double) (tls_packets_sent - tls_packets_generated) / tls_packets_= generated * 100.0); + (double)(tls_packets_sent - tls_packets_generated) / tls_packets_g= enerated * 100.0); } -#else /* ifdef MEASURE_TLS_HANDSHAKE_STATS */ +#else /* ifdef MEASURE_TLS_HANDSHAKE_STATS */ #define INCR_SENT #define INCR_GENERATED @@ -112,7 +112,7 @@ if (*reneg_bytes =3D=3D -1) /* Not user-specified */ { msg(M_WARN, "WARNING: cipher with small block size in use, " - "reducing reneg-bytes to 64MB to mitigate SWEET32 attacks.= "); + "reducing reneg-bytes to 64MB to mitigate SWEET32 = attacks."); *reneg_bytes =3D 64 * 1024 * 1024; } } @@ -130,9 +130,10 @@ /* set limit to 7/8 of the limit so the renegotiation can succeed befo= re * we go over the limit */ - limit =3D limit/8 * 7; + limit =3D limit / 8 * 7; - msg(D_SHOW_KEYS, "Note: AEAD cipher %s will trigger a renegotiation" + msg(D_SHOW_KEYS, + "Note: AEAD cipher %s will trigger a renegotiation" " at a sum of %" PRIi64 " blocks and packets.", ciphername, limit); return limit; @@ -153,8 +154,7 @@ overhead +=3D 10; /* tls-auth and tls-crypt */ - overhead +=3D max_int(tls_crypt_buf_overhead(), - packet_id_size(true) + OPENVPN_MAX_HMAC_SIZE); + overhead +=3D max_int(tls_crypt_buf_overhead(), packet_id_size(true) += OPENVPN_MAX_HMAC_SIZE); /* TCP length field and opcode */ overhead +=3D 3; @@ -218,8 +218,7 @@ /* Add the typical UDP overhead for an IPv6 UDP packet. TCP+IPv6 has a * larger overhead but the risk of a TCP connection getting dropped be= cause * we try to send a too large packet is basically zero */ - overhead +=3D datagram_overhead(session->untrusted_addr.dest.addr.sa.s= a_family, - PROTO_UDP); + overhead +=3D datagram_overhead(session->untrusted_addr.dest.addr.sa.s= a_family, PROTO_UDP); return overhead; } @@ -253,7 +252,8 @@ unprotect_user_pass(&passbuf); if (!strlen(passbuf.password)) { - get_user_pass(&passbuf, auth_file, UP_TYPE_PRIVATE_KEY, GET_USER_P= ASS_MANAGEMENT|GET_USER_PASS_PASSWORD_ONLY); + get_user_pass(&passbuf, auth_file, UP_TYPE_PRIVATE_KEY, + GET_USER_PASS_MANAGEMENT | GET_USER_PASS_PASSWORD_ON= LY); } } @@ -292,8 +292,7 @@ } =20 void -auth_user_pass_setup(const char *auth_file, bool is_inline, - const struct static_challenge_info *sci) +auth_user_pass_setup(const char *auth_file, bool is_inline, const struct s= tatic_challenge_info *sci) { unsigned int flags =3D GET_USER_PASS_MANAGEMENT; @@ -309,11 +308,7 @@ if (auth_challenge) /* dynamic challenge/response */ { flags |=3D GET_USER_PASS_DYNAMIC_CHALLENGE; - get_user_pass_cr(&auth_user_pass, - auth_file, - UP_TYPE_AUTH, - flags, - auth_challenge); + get_user_pass_cr(&auth_user_pass, auth_file, UP_TYPE_AUTH, fla= gs, auth_challenge); } else if (sci) /* static challenge response */ { @@ -326,11 +321,7 @@ { flags |=3D GET_USER_PASS_STATIC_CHALLENGE_CONCAT; } - get_user_pass_cr(&auth_user_pass, - auth_file, - UP_TYPE_AUTH, - flags, - sci->challenge_text); + get_user_pass_cr(&auth_user_pass, auth_file, UP_TYPE_AUTH, fla= gs, sci->challenge_text); } else #endif /* ifdef ENABLE_MANAGEMENT */ @@ -469,11 +460,10 @@ * @param crl_file_inline True if crl_file is an inline CRL. */ static void -tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, - bool crl_file_inline) +tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, boo= l crl_file_inline) { /* if something goes wrong with stat(), we'll store 0 as mtime */ - platform_stat_t crl_stat =3D {0}; + platform_stat_t crl_stat =3D { 0 }; /* * an inline CRL can't change at runtime, therefore there is no need to @@ -537,11 +527,10 @@ if (options->dh_file) { - tls_ctx_load_dh_params(new_ctx, options->dh_file, - options->dh_file_inline); + tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_= file_inline); } } - else /* if client */ + else /* if client */ { tls_ctx_client_new(new_ctx); } @@ -568,8 +557,9 @@ if (options->pkcs12_file) { - if (0 !=3D tls_ctx_load_pkcs12(new_ctx, options->pkcs12_file, - options->pkcs12_file_inline, !options= ->ca_file)) + if (0 + !=3D tls_ctx_load_pkcs12(new_ctx, options->pkcs12_file, option= s->pkcs12_file_inline, + !options->ca_file)) { goto err; } @@ -594,8 +584,7 @@ #ifdef ENABLE_MANAGEMENT else if (options->management_flags & MF_EXTERNAL_CERT) { - char *cert =3D management_query_cert(management, - options->management_certificate= ); + char *cert =3D management_query_cert(management, options->manageme= nt_certificate); tls_ctx_load_cert_file(new_ctx, cert, true); free(cert); } @@ -607,8 +596,9 @@ if (options->priv_key_file) { - if (0 !=3D tls_ctx_load_priv_file(new_ctx, options->priv_key_file, - options->priv_key_file_inline)) + if (0 + !=3D tls_ctx_load_priv_file(new_ctx, options->priv_key_file, + options->priv_key_file_inline)) { goto err; } @@ -626,15 +616,16 @@ if (options->ca_file || options->ca_path) { - tls_ctx_load_ca(new_ctx, options->ca_file, options->ca_file_inline, - options->ca_path, options->tls_server); + tls_ctx_load_ca(new_ctx, options->ca_file, options->ca_file_inline= , options->ca_path, + options->tls_server); } /* Load extra certificates that are part of our own certificate * chain but shouldn't be included in the verify chain */ if (options->extra_certs_file) { - tls_ctx_load_extra_certs(new_ctx, options->extra_certs_file, optio= ns->extra_certs_file_inline); + tls_ctx_load_extra_certs(new_ctx, options->extra_certs_file, + options->extra_certs_file_inline); } /* Check certificate notBefore and notAfter */ @@ -778,9 +769,8 @@ for (int i =3D 0; i < KEY_SCAN_SIZE; ++i) { struct key_state *ks =3D get_key_scan(multi, i); - buf_printf(&out, " [key#%d state=3D%s auth=3D%s id=3D%d sid=3D%s]"= , i, - state_name(ks->state), ks_auth_name(ks->authenticated), - ks->key_id, + buf_printf(&out, " [key#%d state=3D%s auth=3D%s id=3D%d sid=3D%s]"= , i, state_name(ks->state), + ks_auth_name(ks->authenticated), ks->key_id, session_id_print(&ks->session_id_remote, gc)); } @@ -833,8 +823,7 @@ * Build TLS object that reads/writes ciphertext * to/from memory BIOs. */ - key_state_ssl_init(&ks->ks_ssl, &session->opt->ssl_ctx, session->opt->= server, - session); + key_state_ssl_init(&ks->ks_ssl, &session->opt->ssl_ctx, session->opt->= server, session); /* Set control-channel initiation mode */ ks->initial_opcode =3D session->initial_opcode; @@ -870,14 +859,12 @@ session->opt->frame.buf.headroom, TLS_RELIABLE_N_SEND_BU= FFERS, ks->key_id ? false : session->opt->xmit_hold); reliable_init(ks->rec_reliable, BUF_SIZE(&session->opt->frame), - session->opt->frame.buf.headroom, TLS_RELIABLE_N_REC_BUF= FERS, - false); + session->opt->frame.buf.headroom, TLS_RELIABLE_N_REC_BUF= FERS, false); reliable_set_timeout(ks->send_reliable, session->opt->packet_timeout); /* init packet ID tracker */ - packet_id_init(&ks->crypto_options.packet_id, - session->opt->replay_window, session->opt->replay_time,= "SSL", - ks->key_id); + packet_id_init(&ks->crypto_options.packet_id, session->opt->replay_win= dow, + session->opt->replay_time, "SSL", ks->key_id); ks->crypto_options.pid_persist =3D NULL; @@ -889,11 +876,10 @@ * Attempt CRL reload before TLS negotiation. Won't be performed if * the file was not modified since the last reload */ - if (session->opt->crl_file - && !(session->opt->ssl_flags & SSLF_CRL_VERIFY_DIR)) + if (session->opt->crl_file && !(session->opt->ssl_flags & SSLF_CRL_VER= IFY_DIR)) { - tls_ctx_reload_crl(&session->opt->ssl_ctx, - session->opt->crl_file, session->opt->crl_file_= inline); + tls_ctx_reload_crl(&session->opt->ssl_ctx, session->opt->crl_file, + session->opt->crl_file_inline); } } @@ -964,7 +950,7 @@ #ifdef ENABLE_MANAGEMENT || management_enable_def_auth(management) #endif - ); + ); } @@ -1013,8 +999,8 @@ } else { - session->initial_opcode =3D session->opt->tls_crypt_v2 ? - P_CONTROL_HARD_RESET_CLIENT_V3 : P_CONTR= OL_HARD_RESET_CLIENT_V2; + session->initial_opcode =3D session->opt->tls_crypt_v2 ? P_CONTROL= _HARD_RESET_CLIENT_V3 + : P_CONTROL_H= ARD_RESET_CLIENT_V2; } /* Initialize control channel authentication parameters */ @@ -1022,10 +1008,8 @@ session->tls_wrap.work =3D alloc_buf(BUF_SIZE(&session->opt->frame)); /* initialize packet ID replay window for --tls-auth */ - packet_id_init(&session->tls_wrap.opt.packet_id, - session->opt->replay_window, - session->opt->replay_time, - "TLS_WRAP", session->key_id); + packet_id_init(&session->tls_wrap.opt.packet_id, session->opt->replay_= window, + session->opt->replay_time, "TLS_WRAP", session->key_id); /* If we are using tls-crypt-v2 we manipulate the packet id to be (ab)= used * to indicate early protocol negotiation */ @@ -1036,8 +1020,7 @@ } /* load most recent packet-id to replay protect on --tls-auth */ - packet_id_persist_load_obj(session->tls_wrap.opt.pid_persist, - &session->tls_wrap.opt.packet_id); + packet_id_persist_load_obj(session->tls_wrap.opt.pid_persist, &session= ->tls_wrap.opt.packet_id); key_state_init(session, &session->key[KS_PRIMARY]); @@ -1095,9 +1078,7 @@ move_session(struct tls_multi *multi, int dest, int src, bool reinit_src) { msg(D_TLS_DEBUG_LOW, "TLS: move_session: dest=3D%s src=3D%s reinit_src= =3D%d", - session_index_name(dest), - session_index_name(src), - reinit_src); + session_index_name(dest), session_index_name(src), reinit_src); ASSERT(src !=3D dest); ASSERT(src >=3D 0 && src < TM_SIZE); ASSERT(dest >=3D 0 && dest < TM_SIZE); @@ -1201,8 +1182,7 @@ */ struct tls_auth_standalone * -tls_auth_standalone_init(struct tls_options *tls_options, - struct gc_arena *gc) +tls_auth_standalone_init(struct tls_options *tls_options, struct gc_arena = *gc) { struct tls_auth_standalone *tas; @@ -1243,9 +1223,7 @@ * sets. */ void -tls_multi_init_set_options(struct tls_multi *multi, - const char *local, - const char *remote) +tls_multi_init_set_options(struct tls_multi *multi, const char *local, con= st char *remote) { /* initialize options string */ multi->opt.local_options =3D local; @@ -1291,8 +1269,7 @@ */ static void -key_source_print(const struct key_source *k, - const char *prefix) +key_source_print(const struct key_source *k, const char *prefix) { struct gc_arena gc =3D gc_new(); @@ -1300,17 +1277,11 @@ VALGRIND_MAKE_READABLE((void *)k->random1, sizeof(k->random1)); VALGRIND_MAKE_READABLE((void *)k->random2, sizeof(k->random2)); - dmsg(D_SHOW_KEY_SOURCE, - "%s pre_master: %s", - prefix, + dmsg(D_SHOW_KEY_SOURCE, "%s pre_master: %s", prefix, format_hex(k->pre_master, sizeof(k->pre_master), 0, &gc)); - dmsg(D_SHOW_KEY_SOURCE, - "%s random1: %s", - prefix, + dmsg(D_SHOW_KEY_SOURCE, "%s random1: %s", prefix, format_hex(k->random1, sizeof(k->random1), 0, &gc)); - dmsg(D_SHOW_KEY_SOURCE, - "%s random2: %s", - prefix, + dmsg(D_SHOW_KEY_SOURCE, "%s random2: %s", prefix, format_hex(k->random2, sizeof(k->random2), 0, &gc)); gc_free(&gc); @@ -1324,24 +1295,15 @@ } static bool -openvpn_PRF(const uint8_t *secret, - int secret_len, - const char *label, - const uint8_t *client_seed, - int client_seed_len, - const uint8_t *server_seed, - int server_seed_len, - const struct session_id *client_sid, - const struct session_id *server_sid, - uint8_t *output, - int output_len) +openvpn_PRF(const uint8_t *secret, int secret_len, const char *label, cons= t uint8_t *client_seed, + int client_seed_len, const uint8_t *server_seed, int server_se= ed_len, + const struct session_id *client_sid, const struct session_id *= server_sid, + uint8_t *output, int output_len) { /* concatenate seed components */ - struct buffer seed =3D alloc_buf(strlen(label) - + client_seed_len - + server_seed_len - + SID_SIZE * 2); + struct buffer seed =3D + alloc_buf(strlen(label) + client_seed_len + server_seed_len + SID_= SIZE * 2); ASSERT(buf_write(&seed, label, strlen(label))); ASSERT(buf_write(&seed, client_seed, client_seed_len)); @@ -1357,8 +1319,7 @@ } /* compute PRF */ - bool ret =3D ssl_tls1_PRF(BPTR(&seed), BLEN(&seed), secret, secret_len, - output, output_len); + bool ret =3D ssl_tls1_PRF(BPTR(&seed), BLEN(&seed), secret, secret_len= , output, output_len); buf_clear(&seed); free_buf(&seed); @@ -1368,11 +1329,8 @@ } static void -init_epoch_keys(struct key_state *ks, - struct tls_multi *multi, - const struct key_type *key_type, - bool server, - struct key2 *key2) +init_epoch_keys(struct key_state *ks, struct tls_multi *multi, const struc= t key_type *key_type, + bool server, struct key2 *key2) { /* For now we hardcode this to be 16 for the software based data chann= el * DCO based implementations/HW implementation might adjust this number @@ -1403,19 +1361,15 @@ * b) They let userspace do the key derivation and pass all the indivi= dual * keys to the DCO layer. * */ - epoch_init_key_ctx(co, key_type, &e1_send, &e1_recv, future_key_count= ); + epoch_init_key_ctx(co, key_type, &e1_send, &e1_recv, future_key_count); secure_memzero(&e1_send, sizeof(e1_send)); secure_memzero(&e1_recv, sizeof(e1_recv)); } static void -init_key_contexts(struct key_state *ks, - struct tls_multi *multi, - const struct key_type *key_type, - bool server, - struct key2 *key2, - bool dco_enabled) +init_key_contexts(struct key_state *ks, struct tls_multi *multi, const str= uct key_type *key_type, + bool server, struct key2 *key2, bool dco_enabled) { struct key_ctx_bi *key =3D &ks->crypto_options.key_ctx_bi; @@ -1429,12 +1383,10 @@ msg(M_FATAL, "FATAL: DCO does not support --auth"); } - int ret =3D init_key_dco_bi(multi, ks, key2, key_direction, - key_type->cipher, server); + int ret =3D init_key_dco_bi(multi, ks, key2, key_direction, key_ty= pe->cipher, server); if (ret < 0) { - msg(M_FATAL, "Impossible to install key material in DCO: %s", - strerror(-ret)); + msg(M_FATAL, "Impossible to install key material in DCO: %s", = strerror(-ret)); } /* encrypt/decrypt context are unused with DCO */ @@ -1446,7 +1398,8 @@ { if (!cipher_kt_mode_aead(key_type->cipher)) { - msg(M_FATAL, "AEAD cipher (currently %s) " + msg(M_FATAL, + "AEAD cipher (currently %s) " "required for epoch data format.", cipher_kt_name(key_type->cipher)); } @@ -1462,8 +1415,8 @@ generate_key_expansion_tls_export(struct tls_session *session, struct key2= *key2) { if (!key_state_export_keying_material(session, EXPORT_KEY_DATA_LABEL, - strlen(EXPORT_KEY_DATA_LABEL), - key2->keys, sizeof(key2->keys))) + strlen(EXPORT_KEY_DATA_LABEL), k= ey2->keys, + sizeof(key2->keys))) { return false; } @@ -1480,42 +1433,28 @@ const struct key_state *ks =3D &session->key[KS_PRIMARY]; const struct key_source2 *key_src =3D ks->key_src; - const struct session_id *client_sid =3D session->opt->server ? - &ks->session_id_remote : &sessio= n->session_id; - const struct session_id *server_sid =3D !session->opt->server ? - &ks->session_id_remote : &sessio= n->session_id; + const struct session_id *client_sid =3D + session->opt->server ? &ks->session_id_remote : &session->session_= id; + const struct session_id *server_sid =3D + !session->opt->server ? &ks->session_id_remote : &session->session= _id; /* debugging print of source key material */ key_source2_print(key_src); /* compute master secret */ - if (!openvpn_PRF(key_src->client.pre_master, - sizeof(key_src->client.pre_master), - KEY_EXPANSION_ID " master secret", - key_src->client.random1, - sizeof(key_src->client.random1), - key_src->server.random1, - sizeof(key_src->server.random1), - NULL, - NULL, - master, - sizeof(master))) + if (!openvpn_PRF(key_src->client.pre_master, sizeof(key_src->client.pr= e_master), + KEY_EXPANSION_ID " master secret", key_src->client.ra= ndom1, + sizeof(key_src->client.random1), key_src->server.rand= om1, + sizeof(key_src->server.random1), NULL, NULL, master, = sizeof(master))) { return false; } /* compute key expansion */ - if (!openvpn_PRF(master, - sizeof(master), - KEY_EXPANSION_ID " key expansion", - key_src->client.random2, - sizeof(key_src->client.random2), - key_src->server.random2, - sizeof(key_src->server.random2), - client_sid, - server_sid, - (uint8_t *)key2->keys, - sizeof(key2->keys))) + if (!openvpn_PRF(master, sizeof(master), KEY_EXPANSION_ID " key expans= ion", + key_src->client.random2, sizeof(key_src->client.rando= m2), + key_src->server.random2, sizeof(key_src->server.rando= m2), client_sid, + server_sid, (uint8_t *)key2->keys, sizeof(key2->keys)= )) { return false; } @@ -1531,8 +1470,7 @@ * master key. */ static bool -generate_key_expansion(struct tls_multi *multi, struct key_state *ks, - struct tls_session *session) +generate_key_expansion(struct tls_multi *multi, struct key_state *ks, stru= ct tls_session *session) { struct key_ctx_bi *key =3D &ks->crypto_options.key_ctx_bi; bool ret =3D false; @@ -1559,17 +1497,16 @@ if (!generate_key_expansion_openvpn_prf(session, &key2)) { msg(D_TLS_ERRORS, "TLS Error: PRF calculation failed. Your sys= tem " - "might not support the old TLS 1.0 PRF calculation anymore= or " - "the policy does not allow it (e.g. running in FIPS mode).= " - "The peer did not announce support for the modern TLS Expo= rt " - "feature that replaces the TLS 1.0 PRF (requires OpenVPN " - "2.6.x or higher)"); + "might not support the old TLS 1.0 PRF calcu= lation anymore or " + "the policy does not allow it (e.g. running = in FIPS mode). " + "The peer did not announce support for the m= odern TLS Export " + "feature that replaces the TLS 1.0 PRF (requ= ires OpenVPN " + "2.6.x or higher)"); goto exit; } } - key2_print(&key2, &session->opt->key_type, - "Master Encrypt", "Master Decrypt"); + key2_print(&key2, &session->opt->key_type, "Master Encrypt", "Master D= ecrypt"); /* check for weak keys */ for (int i =3D 0; i < 2; ++i) @@ -1581,8 +1518,7 @@ } } - init_key_contexts(ks, multi, &session->opt->key_type, server, &key2, - session->opt->dco_enabled); + init_key_contexts(ks, multi, &session->opt->key_type, server, &key2, s= ession->opt->dco_enabled); ret =3D true; exit: @@ -1598,11 +1534,10 @@ * can thus be called only once per session. */ bool -tls_session_generate_data_channel_keys(struct tls_multi *multi, - struct tls_session *session) +tls_session_generate_data_channel_keys(struct tls_multi *multi, struct tls= _session *session) { bool ret =3D false; - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ if (ks->authenticated <=3D KS_AUTH_FALSE) { @@ -1617,8 +1552,7 @@ msg(D_TLS_ERRORS, "TLS Error: generate_key_expansion failed"); goto cleanup; } - tls_limit_reneg_bytes(session->opt->key_type.cipher, - &session->opt->renegotiate_bytes); + tls_limit_reneg_bytes(session->opt->key_type.cipher, &session->opt->re= negotiate_bytes); session->opt->aead_usage_limit =3D tls_get_limit_aead(session->opt->ke= y_type.cipher); @@ -1632,23 +1566,18 @@ } bool -tls_session_update_crypto_params_do_work(struct tls_multi *multi, - struct tls_session *session, - struct options *options, - struct frame *frame, - struct frame *frame_fragment, - struct link_socket_info *lsi, +tls_session_update_crypto_params_do_work(struct tls_multi *multi, struct t= ls_session *session, + struct options *options, struct f= rame *frame, + struct frame *frame_fragment, str= uct link_socket_info *lsi, dco_context_t *dco) { if (session->key[KS_PRIMARY].crypto_options.key_ctx_bi.initialized) { /* keys already generated, nothing to do */ return true; - } - init_key_type(&session->opt->key_type, options->ciphername, - options->authname, true, true); + init_key_type(&session->opt->key_type, options->ciphername, options->a= uthname, true, true); bool packet_id_long_form =3D cipher_kt_mode_ofb_cfb(session->opt->key_= type.cipher); session->opt->crypto_flags &=3D ~(CO_PACKET_ID_LONG_FORM); @@ -1692,10 +1621,8 @@ * mssfix are set to update in-kernel config */ if (options->ping_send_timeout || frame->mss_fix) { - int ret =3D dco_set_peer(dco, multi->dco_peer_id, - options->ping_send_timeout, - options->ping_rec_timeout, - frame->mss_fix); + int ret =3D dco_set_peer(dco, multi->dco_peer_id, options->pin= g_send_timeout, + options->ping_rec_timeout, frame->mss_f= ix); if (ret < 0) { msg(D_DCO, "Cannot set DCO peer parameters for peer (id=3D= %u): %s", @@ -1708,11 +1635,9 @@ } bool -tls_session_update_crypto_params(struct tls_multi *multi, - struct tls_session *session, +tls_session_update_crypto_params(struct tls_multi *multi, struct tls_sessi= on *session, struct options *options, struct frame *fr= ame, - struct frame *frame_fragment, - struct link_socket_info *lsi, + struct frame *frame_fragment, struct link= _socket_info *lsi, dco_context_t *dco) { if (!check_session_cipher(session, options)) @@ -1723,19 +1648,18 @@ /* Import crypto settings that might be set by pull/push */ session->opt->crypto_flags |=3D options->imported_protocol_flags; - return tls_session_update_crypto_params_do_work(multi, session, option= s, - frame, frame_fragment,= lsi, dco); + return tls_session_update_crypto_params_do_work(multi, session, option= s, frame, frame_fragment, + lsi, dco); } static bool -random_bytes_to_buf(struct buffer *buf, - uint8_t *out, - int outlen) +random_bytes_to_buf(struct buffer *buf, uint8_t *out, int outlen) { if (!rand_bytes(out, outlen)) { - msg(M_FATAL, "ERROR: Random number generator cannot obtain entropy= for key generation [SSL]"); + msg(M_FATAL, + "ERROR: Random number generator cannot obtain entropy for key = generation [SSL]"); } if (!buf_write(buf, out, outlen)) { @@ -1745,9 +1669,7 @@ } static bool -key_source2_randomize_write(struct key_source2 *k2, - struct buffer *buf, - bool server) +key_source2_randomize_write(struct key_source2 *k2, struct buffer *buf, bo= ol server) { struct key_source *k =3D &k2->client; if (server) @@ -1778,9 +1700,7 @@ } static int -key_source2_read(struct key_source2 *k2, - struct buffer *buf, - bool server) +key_source2_read(struct key_source2 *k2, struct buffer *buf, bool server) { struct key_source *k =3D &k2->client; @@ -1830,10 +1750,10 @@ static void key_state_soft_reset(struct tls_session *session) { - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary = key */ struct key_state *ks_lame =3D &session->key[KS_LAME_DUCK]; /* retiring= key */ - ks->must_die =3D now + session->opt->transition_window; /* remaining l= ifetime of old key */ + ks->must_die =3D now + session->opt->transition_window; /* remainin= g lifetime of old key */ key_state_free(ks_lame, false); *ks_lame =3D *ks; @@ -1906,7 +1826,7 @@ { return -len; } - str[len-1] =3D '\0'; + str[len - 1] =3D '\0'; return len; } @@ -1920,14 +1840,14 @@ { return NULL; } - str =3D (char *) malloc(len); + str =3D (char *)malloc(len); check_malloc_return(str); if (!buf_read(buf, str, len)) { free(str); return NULL; } - str[len-1] =3D '\0'; + str[len - 1] =3D '\0'; return str; } @@ -2017,7 +1937,6 @@ if (tls_item_in_cipher_list("AES-128-GCM", session->opt->confi= g_ncp_ciphers) && tls_item_in_cipher_list("AES-256-GCM", session->opt->co= nfig_ncp_ciphers)) { - buf_printf(&out, "IV_NCP=3D2\n"); } } @@ -2056,7 +1975,7 @@ { buf_printf(&out, "IV_HWADDR=3D%s\n", format_hex_ex(rgi.hwa= ddr, 6, 0, 1, ":", &gc)); } - buf_printf(&out, "IV_SSL=3D%s\n", get_ssl_library_version() ); + buf_printf(&out, "IV_SSL=3D%s\n", get_ssl_library_version()); #if defined(_WIN32) buf_printf(&out, "IV_PLAT_VER=3D%s\n", win32_version_string(&g= c)); #else @@ -2078,8 +1997,7 @@ || strncmp(e->string, "IV_PLAT_VER=3D", sizeof(= "IV_PLAT_VER=3D") - 1) =3D=3D 0) && session->opt->push_peer_info_detail > 2) || (strncmp(e->string, "IV_GUI_VER=3D", sizeof("I= V_GUI_VER=3D") - 1) =3D=3D 0) - || (strncmp(e->string, "IV_SSO=3D", sizeof("IV_SS= O=3D") - 1) =3D=3D 0) - ) + || (strncmp(e->string, "IV_SSO=3D", sizeof("IV_SS= O=3D") - 1) =3D=3D 0)) && buf_safe(&out, strlen(e->string) + 1)) { buf_printf(&out, "%s\n", e->string); @@ -2126,7 +2044,7 @@ static bool key_method_2_write(struct buffer *buf, struct tls_multi *multi, struct tls= _session *session) { - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ ASSERT(buf_init(buf, 0)); @@ -2161,7 +2079,7 @@ } else #endif - if (!write_string(buf, session->opt->local_options, TLS_OPTIONS_LE= N)) + if (!write_string(buf, session->opt->local_options, TLS_OPTION= S_LEN)) { goto error; } @@ -2172,8 +2090,7 @@ { #ifdef ENABLE_MANAGEMENT auth_user_pass_setup(session->opt->auth_user_pass_file, - session->opt->auth_user_pass_file_inline, - session->opt->sci); + session->opt->auth_user_pass_file_inline, ses= sion->opt->sci); #else auth_user_pass_setup(session->opt->auth_user_pass_file, session->opt->auth_user_pass_file_inline, NUL= L); @@ -2226,8 +2143,7 @@ goto error; } - if (session->opt->server && session->opt->mode !=3D MODE_SERVER - && ks->key_id =3D=3D 0) + if (session->opt->server && session->opt->mode !=3D MODE_SERVER && ks-= >key_id =3D=3D 0) { /* tls-server option set and not P2MP server, so we * are a P2P client running in tls-server mode */ @@ -2251,18 +2167,16 @@ struct gc_arena gc =3D gc_new(); unsigned char *ekm =3D gc_malloc(session->opt->ekm_size, true, &gc= ); - if (key_state_export_keying_material(session, - session->opt->ekm_label, - session->opt->ekm_label_size, - ekm, session->opt->ekm_size)) + if (key_state_export_keying_material(session, session->opt->ekm_la= bel, + session->opt->ekm_label_size,= ekm, + session->opt->ekm_size)) { unsigned int len =3D (size * 2) + 2; const char *key =3D format_hex_ex(ekm, size, len, 0, NULL, &gc= ); setenv_str(session->opt->es, "exported_keying_material", key); - dmsg(D_TLS_DEBUG_MED, "%s: exported keying material: %s", - __func__, key); + dmsg(D_TLS_DEBUG_MED, "%s: exported keying material: %s", __fu= nc__, key); secure_memzero(ekm, size); } else @@ -2281,7 +2195,7 @@ static bool key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_= session *session) { - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ struct gc_arena gc =3D gc_new(); char *options; @@ -2293,8 +2207,7 @@ /* discard leading uint32 */ if (!buf_advance(buf, 4)) { - msg(D_TLS_ERRORS, "TLS ERROR: Plaintext buffer too short (%d bytes= ).", - buf->len); + msg(D_TLS_ERRORS, "TLS ERROR: Plaintext buffer too short (%d bytes= ).", buf->len); goto error; } @@ -2302,8 +2215,7 @@ int key_method_flags =3D buf_read_u8(buf); if ((key_method_flags & KEY_METHOD_MASK) !=3D 2) { - msg(D_TLS_ERRORS, - "TLS ERROR: Unknown key_method/flags=3D%d received from remote= host", + msg(D_TLS_ERRORS, "TLS ERROR: Unknown key_method/flags=3D%d receiv= ed from remote host", key_method_flags); goto error; } @@ -2311,7 +2223,8 @@ /* get key source material (not actual keys yet) */ if (!key_source2_read(ks->key_src, buf, session->opt->server)) { - msg(D_TLS_ERRORS, "TLS Error: Error reading remote data channel ke= y source entropy from plaintext buffer"); + msg(D_TLS_ERRORS, + "TLS Error: Error reading remote data channel key source entro= py from plaintext buffer"); goto error; } @@ -2341,13 +2254,11 @@ } free(multi->remote_ciphername); - multi->remote_ciphername =3D - options_string_extract_option(options, "cipher", NULL); + multi->remote_ciphername =3D options_string_extract_option(options, "c= ipher", NULL); multi->remote_usescomp =3D strstr(options, ",comp-lzo,"); /* In OCC we send '[null-cipher]' instead 'none' */ - if (multi->remote_ciphername - && strcmp(multi->remote_ciphername, "[null-cipher]") =3D=3D 0) + if (multi->remote_ciphername && strcmp(multi->remote_ciphername, "[nul= l-cipher]") =3D=3D 0) { free(multi->remote_ciphername); multi->remote_ciphername =3D string_alloc("none", NULL); @@ -2355,10 +2266,10 @@ if (username_len < 0 || password_len < 0) { - msg(D_TLS_ERRORS, "TLS Error: Username (%d) or password (%d) too l= ong", - abs(username_len), abs(password_len)); + msg(D_TLS_ERRORS, "TLS Error: Username (%d) or password (%d) too l= ong", abs(username_len), + abs(password_len)); auth_set_client_reason(multi, "Username or password is too long. " - "Maximum length is 128 bytes"); + "Maximum length is 128 bytes"); /* treat the same as failed username/password and do not error * out (goto error) to sent an AUTH_FAILED back to the client */ @@ -2384,8 +2295,7 @@ /* Session verification should have occurred during TLS negotiatio= n*/ if (!session->verified) { - msg(D_TLS_ERRORS, - "TLS Error: Certificate verification failed (key-method 2)= "); + msg(D_TLS_ERRORS, "TLS Error: Certificate verification failed = (key-method 2)"); goto error; } ks->authenticated =3D KS_AUTH_TRUE; @@ -2408,7 +2318,7 @@ if (multi->opt.comp_options.flags & COMP_F_MIGRATE && multi->remot= e_usescomp) { msg(D_PUSH, "Note: 'compress migrate' detected remote peer " - "with compression enabled."); + "with compression enabled."); remote_options =3D options_string_compat_lzo(remote_options, &= gc); } #endif @@ -2417,7 +2327,8 @@ if (session->opt->ssl_flags & SSLF_OPT_VERIFY) { - msg(D_TLS_ERRORS, "Option inconsistency warnings triggering di= sconnect due to --opt-verify"); + msg(D_TLS_ERRORS, + "Option inconsistency warnings triggering disconnect due t= o --opt-verify"); ks->authenticated =3D KS_AUTH_FALSE; } } @@ -2433,7 +2344,9 @@ { export_user_keying_material(session); - if (plugin_call(session->opt->plugins, OPENVPN_PLUGIN_TLS_FINAL, N= ULL, NULL, session->opt->es) !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) + if (plugin_call(session->opt->plugins, OPENVPN_PLUGIN_TLS_FINAL, N= ULL, NULL, + session->opt->es) + !=3D OPENVPN_PLUGIN_FUNC_SUCCESS) { ks->authenticated =3D KS_AUTH_FALSE; } @@ -2483,8 +2396,8 @@ * @return if the state change was succesful */ static bool -session_move_pre_start(const struct tls_session *session, - struct key_state *ks, bool skip_initial_send) +session_move_pre_start(const struct tls_session *session, struct key_state= *ks, + bool skip_initial_send) { struct buffer *buf =3D reliable_get_buf_output_sequenced(ks->send_reli= able); if (!buf) @@ -2517,17 +2430,10 @@ #ifdef ENABLE_MANAGEMENT if (management && ks->initial_opcode !=3D P_CONTROL_SOFT_RESET_V1) { - management_set_state(management, - OPENVPN_STATE_WAIT, - NULL, - NULL, - NULL, - NULL, - NULL); + management_set_state(management, OPENVPN_STATE_WAIT, NULL, NULL, N= ULL, NULL, NULL); } #endif return true; - } /** @@ -2536,8 +2442,7 @@ */ static void session_move_active(struct tls_multi *multi, struct tls_session *session, - struct link_socket_info *to_link_socket_info, - struct key_state *ks) + struct link_socket_info *to_link_socket_info, struct k= ey_state *ks) { dmsg(D_TLS_DEBUG_MED, "STATE S_ACTIVE"); @@ -2552,8 +2457,8 @@ INCR_SUCCESS; /* Set outgoing address for data channel packets */ - link_socket_set_outgoing_addr(to_link_socket_info, &ks->remote_addr, - session->common_name, session->opt->es); + link_socket_set_outgoing_addr(to_link_socket_info, &ks->remote_addr, s= ession->common_name, + session->opt->es); /* Check if we need to advance the tls_multi state machine */ if (multi->multi_state =3D=3D CAS_NOT_CONNECTED) @@ -2579,8 +2484,7 @@ } bool -session_skip_to_pre_start(struct tls_session *session, - struct tls_pre_decrypt_state *state, +session_skip_to_pre_start(struct tls_session *session, struct tls_pre_decr= ypt_state *state, struct link_socket_actual *from) { struct key_state *ks =3D &session->key[KS_PRIMARY]; @@ -2654,8 +2558,7 @@ * Returns false if an error is encountered that should abort the session. */ static bool -read_incoming_tls_ciphertext(struct buffer *buf, struct key_state *ks, - bool *continue_tls_process) +read_incoming_tls_ciphertext(struct buffer *buf, struct key_state *ks, boo= l *continue_tls_process) { int status =3D 0; if (buf->len) @@ -2663,8 +2566,7 @@ status =3D key_state_write_ciphertext(&ks->ks_ssl, buf); if (status =3D=3D -1) { - msg(D_TLS_ERRORS, - "TLS Error: Incoming Ciphertext -> TLS object write error"= ); + msg(D_TLS_ERRORS, "TLS Error: Incoming Ciphertext -> TLS objec= t write error"); return false; } } @@ -2684,14 +2586,13 @@ static bool control_packet_needs_wkc(const struct key_state *ks) { - return (ks->crypto_options.flags & CO_RESEND_WKC) - && (ks->send_reliable->packet_id =3D=3D 1); + return (ks->crypto_options.flags & CO_RESEND_WKC) && (ks->send_reliabl= e->packet_id =3D=3D 1); } static bool -read_incoming_tls_plaintext(struct key_state *ks, struct buffer *buf, - interval_t *wakeup, bool *continue_tls_process) +read_incoming_tls_plaintext(struct key_state *ks, struct buffer *buf, inte= rval_t *wakeup, + bool *continue_tls_process) { ASSERT(buf_init(buf, 0)); @@ -2746,7 +2647,8 @@ * if we have a large wrapped client key. */ if (maxlen < 16) { - msg(D_TLS_ERRORS, "Warning: --max-packet-size (%d) setting too low= . " + msg(D_TLS_ERRORS, + "Warning: --max-packet-size (%d) setting too low. " "Sending minimum sized packet.", session->opt->frame.tun_mtu); maxlen =3D 16; @@ -2763,8 +2665,7 @@ if (status =3D=3D -1) { - msg(D_TLS_ERRORS, - "TLS Error: Ciphertext -> reliable TCP/UDP transport read erro= r"); + msg(D_TLS_ERRORS, "TLS Error: Ciphertext -> reliable TCP/UDP trans= port read error"); gc_free(&gc); return false; } @@ -2820,12 +2721,9 @@ } static bool -tls_process_state(struct tls_multi *multi, - struct tls_session *session, - struct buffer *to_link, +tls_process_state(struct tls_multi *multi, struct tls_session *session, st= ruct buffer *to_link, struct link_socket_actual **to_link_addr, - struct link_socket_info *to_link_socket_info, - interval_t *wakeup) + struct link_socket_info *to_link_socket_info, interval_t= *wakeup) { /* This variable indicates if we should call this method * again to process more incoming/outgoing TLS state/data @@ -2834,7 +2732,7 @@ * should only be done after the outer loop (sending packets etc.) * has run once more */ bool continue_tls_process =3D false; - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ /* Initial handshake */ if (ks->state =3D=3D S_INITIAL) @@ -2884,8 +2782,7 @@ struct buffer b =3D *buf; INCR_SENT; - write_control_auth(session, ks, &b, to_link_addr, opcode, - CONTROL_SEND_ACK_MAX, true); + write_control_auth(session, ks, &b, to_link_addr, opcode, CONTROL_= SEND_ACK_MAX, true); *to_link =3D b; dmsg(D_TLS_DEBUG, "Reliable -> TCP/UDP"); @@ -2941,8 +2838,9 @@ /* Send Key */ buf =3D &ks->plaintext_write_buf; - if (!buf->len && ((ks->state =3D=3D S_START && !session->opt->server) - || (ks->state =3D=3D S_GOT_KEY && session->opt->serv= er))) + if (!buf->len + && ((ks->state =3D=3D S_START && !session->opt->server) + || (ks->state =3D=3D S_GOT_KEY && session->opt->server))) { if (!key_method_2_write(buf, multi, session)) { @@ -2977,8 +2875,7 @@ int status =3D key_state_write_plaintext(&ks->ks_ssl, buf); if (status =3D=3D -1) { - msg(D_TLS_ERRORS, - "TLS ERROR: Outgoing Plaintext -> TLS object write error"); + msg(D_TLS_ERRORS, "TLS ERROR: Outgoing Plaintext -> TLS object= write error"); goto error; } if (status =3D=3D 1) @@ -3025,15 +2922,13 @@ } /* Byte limit */ - if (session->opt->renegotiate_bytes > 0 - && ks->n_bytes >=3D session->opt->renegotiate_bytes) + if (session->opt->renegotiate_bytes > 0 && ks->n_bytes >=3D session->o= pt->renegotiate_bytes) { return true; } /* Packet limit */ - if (session->opt->renegotiate_packets - && ks->n_packets >=3D session->opt->renegotiate_packets) + if (session->opt->renegotiate_packets && ks->n_packets >=3D session->o= pt->renegotiate_packets) { return true; } @@ -3100,14 +2995,11 @@ * want to send to our peer. */ static bool -tls_process(struct tls_multi *multi, - struct tls_session *session, - struct buffer *to_link, - struct link_socket_actual **to_link_addr, - struct link_socket_info *to_link_socket_info, +tls_process(struct tls_multi *multi, struct tls_session *session, struct b= uffer *to_link, + struct link_socket_actual **to_link_addr, struct link_socket_i= nfo *to_link_socket_info, interval_t *wakeup) { - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary = key */ struct key_state *ks_lame =3D &session->key[KS_LAME_DUCK]; /* retiring= key */ /* Make sure we were initialized and that we're not in an error state = */ @@ -3116,21 +3008,18 @@ ASSERT(session_id_defined(&session->session_id)); /* Should we trigger a soft reset? -- new key, keeps old key for a whi= le */ - if (ks->state >=3D S_GENERATED_KEYS - && should_trigger_renegotiation(session, ks)) + if (ks->state >=3D S_GENERATED_KEYS && should_trigger_renegotiation(se= ssion, ks)) { - msg(D_TLS_DEBUG_LOW, "TLS: soft reset sec=3D%d/%d bytes=3D" counte= r_format - "/%" PRIi64 " pkts=3D" counter_format "/%" PRIi64 - " aead_limit_send=3D%" PRIu64 "/%" PRIu64 - " aead_limit_recv=3D%" PRIu64 "/%" PRIu64, - (int) (now - ks->established), session->opt->renegotiate_secon= ds, - ks->n_bytes, session->opt->renegotiate_bytes, - ks->n_packets, session->opt->renegotiate_packets, + msg(D_TLS_DEBUG_LOW, + "TLS: soft reset sec=3D%d/%d bytes=3D" counter_format "/%" PRI= i64 " pkts=3D" counter_format + "/%" PRIi64 " aead_limit_send=3D%" PRIu64 "/%" PRIu64 " aead_l= imit_recv=3D%" PRIu64 + "/%" PRIu64, + (int)(now - ks->established), session->opt->renegotiate_second= s, ks->n_bytes, + session->opt->renegotiate_bytes, ks->n_packets, session->opt->= renegotiate_packets, ks->crypto_options.key_ctx_bi.encrypt.plaintext_blocks + ks->n= _packets, session->opt->aead_usage_limit, ks->crypto_options.key_ctx_bi.decrypt.plaintext_blocks + ks->n= _packets, - session->opt->aead_usage_limit - ); + session->opt->aead_usage_limit); key_state_soft_reset(session); } @@ -3147,19 +3036,15 @@ update_time(); dmsg(D_TLS_DEBUG, "TLS: tls_process: chg=3D%d ks=3D%s lame=3D%s to= _link->len=3D%d wakeup=3D%d", - continue_tls_process, - state_name(ks->state), - state_name(ks_lame->state), - to_link->len, + continue_tls_process, state_name(ks->state), state_name(ks_la= me->state), to_link->len, *wakeup); - continue_tls_process =3D tls_process_state(multi, session, to_link= , to_link_addr, - to_link_socket_info, wake= up); + continue_tls_process =3D + tls_process_state(multi, session, to_link, to_link_addr, to_li= nk_socket_info, wakeup); if (ks->state =3D=3D S_ERROR) { return false; } - } =20 update_time(); @@ -3190,8 +3075,7 @@ { struct buffer buf =3D ks->ack_write_buf; ASSERT(buf_init(&buf, multi->opt.frame.buf.headroom)); - write_control_auth(session, ks, &buf, to_link_addr, P_ACK_V1, - RELIABLE_ACK_SIZE, false); + write_control_auth(session, ks, &buf, to_link_addr, P_ACK_V1, = RELIABLE_ACK_SIZE, false); *to_link =3D buf; dmsg(D_TLS_DEBUG, "Dedicated ACK -> TCP/UDP"); } @@ -3200,8 +3084,7 @@ /* When should we wake up again? */ if (ks->state >=3D S_INITIAL || ks->state =3D=3D S_ERROR_PRE) { - compute_earliest_wakeup(wakeup, - reliable_send_timeout(ks->send_reliable)); + compute_earliest_wakeup(wakeup, reliable_send_timeout(ks->send_rel= iable)); if (ks->must_negotiate) { @@ -3211,8 +3094,7 @@ if (ks->established && session->opt->renegotiate_seconds) { - compute_earliest_wakeup(wakeup, - ks->established + session->opt->renegotiat= e_seconds - now); + compute_earliest_wakeup(wakeup, ks->established + session->opt->re= negotiate_seconds - now); } dmsg(D_TLS_DEBUG, "TLS: tls_process: timeout set to %d", *wakeup); @@ -3258,7 +3140,7 @@ if (session->tls_wrap.work.data =3D=3D dataptr) { msg(M_INFO, "Warning buffer of freed TLS session is " - "still in use (tls_wrap.work.data)"); + "still in use (tls_wrap.work.data)"); goto used; } @@ -3276,7 +3158,8 @@ */ if (!ks->send_reliable) { - msg(M_FATAL, "ERROR: session->key[%d]->send_reliable is NULL " + msg(M_FATAL, + "ERROR: session->key[%d]->send_reliable is NULL " "while key state is %s. Exiting.", i, state_name(ks->state)); } @@ -3285,7 +3168,8 @@ { if (ks->send_reliable->array[j].buf.data =3D=3D dataptr) { - msg(M_INFO, "Warning buffer of freed TLS session is still = in" + msg(M_INFO, + "Warning buffer of freed TLS session is still in" " use (session->key[%d].send_reliable->array[%d])", i, j); @@ -3308,11 +3192,9 @@ */ int -tls_multi_process(struct tls_multi *multi, - struct buffer *to_link, +tls_multi_process(struct tls_multi *multi, struct buffer *to_link, struct link_socket_actual **to_link_addr, - struct link_socket_info *to_link_socket_info, - interval_t *wakeup) + struct link_socket_info *to_link_socket_info, interval_t= *wakeup) { struct gc_arena gc =3D gc_new(); int active =3D TLSMP_INACTIVE; @@ -3336,29 +3218,26 @@ /* set initial remote address. This triggers connecting with that * session. So we only do that if the TM_ACTIVE session is not * established */ - if (i =3D=3D TM_INITIAL && ks->state =3D=3D S_INITIAL - && get_primary_key(multi)->state <=3D S_INITIAL + if (i =3D=3D TM_INITIAL && ks->state =3D=3D S_INITIAL && get_prima= ry_key(multi)->state <=3D S_INITIAL && link_socket_actual_defined(&to_link_socket_info->lsa->actua= l)) { ks->remote_addr =3D to_link_socket_info->lsa->actual; } dmsg(D_TLS_DEBUG, - "TLS: tls_multi_process: i=3D%d state=3D%s, mysid=3D%s, store= d-sid=3D%s, stored-ip=3D%s", - i, - state_name(ks->state), - session_id_print(&session->session_id, &gc), + "TLS: tls_multi_process: i=3D%d state=3D%s, mysid=3D%s, store= d-sid=3D%s, stored-ip=3D%s", i, + state_name(ks->state), session_id_print(&session->session_id,= &gc), session_id_print(&ks->session_id_remote, &gc), print_link_socket_actual(&ks->remote_addr, &gc)); - if ((ks->state >=3D S_INITIAL || ks->state =3D=3D S_ERROR_PRE) && = link_socket_actual_defined(&ks->remote_addr)) + if ((ks->state >=3D S_INITIAL || ks->state =3D=3D S_ERROR_PRE) + && link_socket_actual_defined(&ks->remote_addr)) { struct link_socket_actual *tla =3D NULL; update_time(); - if (tls_process(multi, session, to_link, &tla, - to_link_socket_info, wakeup)) + if (tls_process(multi, session, to_link, &tla, to_link_socket_= info, wakeup)) { active =3D TLSMP_ACTIVE; } @@ -3384,14 +3263,12 @@ { ++multi->n_soft_errors; - if (i =3D=3D TM_ACTIVE - || (i =3D=3D TM_INITIAL && get_primary_key(multi)->sta= te < S_ACTIVE)) + if (i =3D=3D TM_ACTIVE || (i =3D=3D TM_INITIAL && get_prim= ary_key(multi)->state < S_ACTIVE)) { error =3D true; } - if (i =3D=3D TM_ACTIVE - && ks_lame->state >=3D S_GENERATED_KEYS + if (i =3D=3D TM_ACTIVE && ks_lame->state >=3D S_GENERATED_= KEYS && !multi->opt.single_session) { move_session(multi, TM_LAME_DUCK, TM_ACTIVE, true); @@ -3423,8 +3300,8 @@ if (ks->state =3D=3D S_ACTIVE && ks->authenticated =3D=3D KS_AUTH_= TRUE) { /* Session is now fully authenticated. - * tls_session_generate_data_channel_keys will move ks->state - * from S_ACTIVE to S_GENERATED_KEYS */ + * tls_session_generate_data_channel_keys will move ks->state + * from S_ACTIVE to S_GENERATED_KEYS */ if (!tls_session_generate_data_channel_keys(multi, session)) { msg(D_TLS_ERRORS, "TLS Error: generate_key_expansion faile= d"); @@ -3469,7 +3346,8 @@ { move_session(multi, TM_ACTIVE, TM_INITIAL, true); tas =3D tls_authentication_status(multi); - msg(D_TLS_DEBUG_LOW, "TLS: tls_multi_process: initial untrusted " + msg(D_TLS_DEBUG_LOW, + "TLS: tls_multi_process: initial untrusted " "session promoted to %strusted", tas =3D=3D TLS_AUTHENTICATION_SUCCEEDED ? "" : "semi-"); @@ -3526,8 +3404,8 @@ * try to generate a sensible error message and print it */ static void -print_key_id_not_found_reason(struct tls_multi *multi, - const struct link_socket_actual *from, int k= ey_id) +print_key_id_not_found_reason(struct tls_multi *multi, const struct link_s= ocket_actual *from, + int key_id) { struct gc_arena gc =3D gc_new(); const char *source =3D print_link_socket_actual(from, &gc); @@ -3545,17 +3423,14 @@ * session but has not generated keys. */ if (ks->state >=3D S_INITIAL && ks->state < S_GENERATED_KEYS) { - msg(D_MULTI_DROPPED, - "Key %s [%d] not initialized (yet), dropping packet.", - source, key_id); + msg(D_MULTI_DROPPED, "Key %s [%d] not initialized (yet), dropp= ing packet.", source, + key_id); gc_free(&gc); return; } if (ks->state >=3D S_ACTIVE && ks->authenticated !=3D KS_AUTH_TRUE) { - msg(D_MULTI_DROPPED, - "Key %s [%d] not authorized%s, dropping packet.", - source, key_id, + msg(D_MULTI_DROPPED, "Key %s [%d] not authorized%s, dropping p= acket.", source, key_id, (ks->authenticated =3D=3D KS_AUTH_DEFERRED) ? " (deferred)= " : ""); gc_free(&gc); return; @@ -3565,8 +3440,7 @@ msg(D_TLS_ERRORS, "TLS Error: local/remote TLS keys are out of sync: %s " "(received key id: %d, known key ids: %s)", - source, key_id, - print_key_id(multi, &gc)); + source, key_id, print_key_id(multi, &gc)); gc_free(&gc); } @@ -3578,11 +3452,8 @@ * AEAD ciphers to the start of the authenticated data. */ static inline void -handle_data_channel_packet(struct tls_multi *multi, - const struct link_socket_actual *from, - struct buffer *buf, - struct crypto_options **opt, - bool floated, +handle_data_channel_packet(struct tls_multi *multi, const struct link_sock= et_actual *from, + struct buffer *buf, struct crypto_options **opt= , bool floated, const uint8_t **ad_start) { struct gc_arena gc =3D gc_new(); @@ -3628,7 +3499,8 @@ { if (buf->len < 4) { - msg(D_TLS_ERRORS, "Protocol error: received P_DATA_V2 = from %s but length is < 4", + msg(D_TLS_ERRORS, + "Protocol error: received P_DATA_V2 from %s but le= ngth is < 4", print_link_socket_actual(from, &gc)); ++multi->n_soft_errors; goto done; @@ -3638,9 +3510,8 @@ ++ks->n_packets; ks->n_bytes +=3D buf->len; - dmsg(D_TLS_KEYSELECT, - "TLS: tls_pre_decrypt, key_id=3D%d, IP=3D%s", - key_id, print_link_socket_actual(from, &gc)); + dmsg(D_TLS_KEYSELECT, "TLS: tls_pre_decrypt, key_id=3D%d, IP= =3D%s", key_id, + print_link_socket_actual(from, &gc)); gc_free(&gc); return; } @@ -3681,14 +3552,9 @@ */ bool -tls_pre_decrypt(struct tls_multi *multi, - const struct link_socket_actual *from, - struct buffer *buf, - struct crypto_options **opt, - bool floated, - const uint8_t **ad_start) +tls_pre_decrypt(struct tls_multi *multi, const struct link_socket_actual *= from, struct buffer *buf, + struct crypto_options **opt, bool floated, const uint8_t *= *ad_start) { - if (buf->len <=3D 0) { buf->len =3D 0; @@ -3715,18 +3581,16 @@ /* control channel packet */ bool do_burst =3D false; bool new_link =3D false; - struct session_id sid; /* remote session ID */ + struct session_id sid; /* remote session ID */ /* verify legal opcode */ if (op < P_FIRST_OPCODE || op > P_LAST_OPCODE) { - if (op =3D=3D P_CONTROL_HARD_RESET_CLIENT_V1 - || op =3D=3D P_CONTROL_HARD_RESET_SERVER_V1) + if (op =3D=3D P_CONTROL_HARD_RESET_CLIENT_V1 || op =3D=3D P_CONTRO= L_HARD_RESET_SERVER_V1) { msg(D_TLS_ERRORS, "Peer tried unsupported key-method 1"); } - msg(D_TLS_ERRORS, - "TLS Error: unknown opcode received from %s op=3D%d", + msg(D_TLS_ERRORS, "TLS Error: unknown opcode received from %s op= =3D%d", print_link_socket_actual(from, &gc), op); goto error; } @@ -3735,8 +3599,8 @@ if (is_hard_reset_method2(op)) { /* verify client -> server or server -> client connection */ - if (((op =3D=3D P_CONTROL_HARD_RESET_CLIENT_V2 - || op =3D=3D P_CONTROL_HARD_RESET_CLIENT_V3) && !multi->opt.= server) + if (((op =3D=3D P_CONTROL_HARD_RESET_CLIENT_V2 || op =3D=3D P_CONT= ROL_HARD_RESET_CLIENT_V3) + && !multi->opt.server) || ((op =3D=3D P_CONTROL_HARD_RESET_SERVER_V2) && multi->opt.s= erver)) { msg(D_TLS_ERRORS, @@ -3749,8 +3613,8 @@ /* * Authenticate Packet */ - dmsg(D_TLS_DEBUG, "TLS: control channel, op=3D%s, IP=3D%s", - packet_opcode_name(op), print_link_socket_actual(from, &gc)); + dmsg(D_TLS_DEBUG, "TLS: control channel, op=3D%s, IP=3D%s", packet_opc= ode_name(op), + print_link_socket_actual(from, &gc)); /* get remote session-id */ { @@ -3758,8 +3622,7 @@ buf_advance(&tmp, 1); if (!session_id_read(&sid, &tmp) || !session_id_defined(&sid)) { - msg(D_TLS_ERRORS, - "TLS Error: session-id not found in packet from %s", + msg(D_TLS_ERRORS, "TLS Error: session-id not found in packet f= rom %s", print_link_socket_actual(from, &gc)); goto error; } @@ -3772,29 +3635,25 @@ struct tls_session *session =3D &multi->session[i]; struct key_state *ks =3D &session->key[KS_PRIMARY]; - dmsg(D_TLS_DEBUG, - "TLS: initial packet test, i=3D%d state=3D%s, mysid=3D%s, rec= -sid=3D%s, rec-ip=3D%s, stored-sid=3D%s, stored-ip=3D%s", - i, - state_name(ks->state), - session_id_print(&session->session_id, &gc), - session_id_print(&sid, &gc), - print_link_socket_actual(from, &gc), - session_id_print(&ks->session_id_remote, &gc), - print_link_socket_actual(&ks->remote_addr, &gc)); + dmsg( + D_TLS_DEBUG, + "TLS: initial packet test, i=3D%d state=3D%s, mysid=3D%s, rec-= sid=3D%s, rec-ip=3D%s, stored-sid=3D%s, stored-ip=3D%s", + i, state_name(ks->state), session_id_print(&session->session_i= d, &gc), + session_id_print(&sid, &gc), print_link_socket_actual(from, &g= c), + session_id_print(&ks->session_id_remote, &gc), + print_link_socket_actual(&ks->remote_addr, &gc)); if (session_id_equal(&ks->session_id_remote, &sid)) /* found a match */ { if (i =3D=3D TM_LAME_DUCK) { - msg(D_TLS_ERRORS, - "TLS ERROR: received control packet with stale session= -id=3D%s", + msg(D_TLS_ERRORS, "TLS ERROR: received control packet with= stale session-id=3D%s", session_id_print(&sid, &gc)); goto error; } - dmsg(D_TLS_DEBUG, - "TLS: found match, session[%d], sid=3D%s", - i, session_id_print(&sid, &gc)); + dmsg(D_TLS_DEBUG, "TLS: found match, session[%d], sid=3D%s", i, + session_id_print(&sid, &gc)); break; } } @@ -3825,8 +3684,8 @@ goto error; } - if (!read_control_auth(buf, tls_session_get_tls_wrap(session, key_= id), from, - session->opt, true)) + if (!read_control_auth(buf, tls_session_get_tls_wrap(session, key_= id), from, session->opt, + true)) { goto error; } @@ -3834,13 +3693,7 @@ #ifdef ENABLE_MANAGEMENT if (management) { - management_set_state(management, - OPENVPN_STATE_AUTH, - NULL, - NULL, - NULL, - NULL, - NULL); + management_set_state(management, OPENVPN_STATE_AUTH, NULL, NUL= L, NULL, NULL, NULL); } #endif @@ -3850,10 +3703,8 @@ * * Without --tls-auth, we leave authentication entirely up to TLS. */ - msg(D_TLS_DEBUG_LOW, - "TLS: Initial packet from %s, sid=3D%s", - print_link_socket_actual(from, &gc), - session_id_print(&sid, &gc)); + msg(D_TLS_DEBUG_LOW, "TLS: Initial packet from %s, sid=3D%s", + print_link_socket_actual(from, &gc), session_id_print(&sid, &g= c)); do_burst =3D true; new_link =3D true; @@ -3870,11 +3721,8 @@ */ if (i !=3D TM_ACTIVE && i !=3D TM_INITIAL) { - msg(D_TLS_ERRORS, - "TLS Error: Unroutable control packet received from %s (si= =3D%d op=3D%s)", - print_link_socket_actual(from, &gc), - i, - packet_opcode_name(op)); + msg(D_TLS_ERRORS, "TLS Error: Unroutable control packet receiv= ed from %s (si=3D%d op=3D%s)", + print_link_socket_actual(from, &gc), i, packet_opcode_name= (op)); goto error; } @@ -3895,17 +3743,16 @@ */ if (op =3D=3D P_CONTROL_SOFT_RESET_V1 && ks->state >=3D S_GENERATE= D_KEYS) { - if (!read_control_auth(buf, tls_session_get_tls_wrap(session, = key_id), - from, session->opt, false)) + if (!read_control_auth(buf, tls_session_get_tls_wrap(session, = key_id), from, + session->opt, false)) { goto error; } key_state_soft_reset(session); =20 - dmsg(D_TLS_DEBUG, - "TLS: received P_CONTROL_SOFT_RESET_V1 s=3D%d sid=3D%s", - i, session_id_print(&sid, &gc)); + dmsg(D_TLS_DEBUG, "TLS: received P_CONTROL_SOFT_RESET_V1 s=3D%= d sid=3D%s", i, + session_id_print(&sid, &gc)); } else { @@ -3926,8 +3773,8 @@ do_burst =3D true; } - if (!read_control_auth(buf, tls_session_get_tls_wrap(session, = key_id), - from, session->opt, initial_packet)) + if (!read_control_auth(buf, tls_session_get_tls_wrap(session, = key_id), from, + session->opt, initial_packet)) { /* if an initial packet in read_control_auth, we rather * error out than anything else */ @@ -3938,9 +3785,8 @@ goto error; } - dmsg(D_TLS_DEBUG, - "TLS: received control channel packet s#=3D%d sid=3D%s", - i, session_id_print(&sid, &gc)); + dmsg(D_TLS_DEBUG, "TLS: received control channel packet s#=3D%= d sid=3D%s", i, + session_id_print(&sid, &gc)); } } @@ -3992,9 +3838,8 @@ /* Check key_id */ if (ks->key_id !=3D key_id) { - msg(D_TLS_ERRORS, - "TLS ERROR: local/remote key IDs out of sync (%d/%d) ID: %s", - ks->key_id, key_id, print_key_id(multi, &gc)); + msg(D_TLS_ERRORS, "TLS ERROR: local/remote key IDs out of sync (%d= /%d) ID: %s", ks->key_id, + key_id, print_key_id(multi, &gc)); goto error; } @@ -4008,8 +3853,7 @@ if (!reliable_ack_read(&send_ack, buf, &session->session_id)) { - msg(D_TLS_ERRORS, - "TLS Error: reading acknowledgement record from packet"); + msg(D_TLS_ERRORS, "TLS Error: reading acknowledgement record f= rom packet"); goto error; } reliable_send_purge(ks->send_reliable, &send_ack); @@ -4032,14 +3876,14 @@ ASSERT(in); if (!buf_copy(in, buf)) { - msg(D_MULTI_DROPPED, - "Incoming control channel packet too big, drop= ping."); + msg(D_MULTI_DROPPED, "Incoming control channel pac= ket too big, dropping."); goto error; } reliable_mark_active_incoming(ks->rec_reliable, in, id= , op); } - /* Process outgoing acknowledgment for packet just receive= d, even if it's a replay */ + /* Process outgoing acknowledgment for packet just receive= d, even if it's a replay + */ reliable_ack_acknowledge_packet_id(ks->rec_ack, id); } } @@ -4088,8 +3932,7 @@ /* Choose the key with which to encrypt a data packet */ void -tls_pre_encrypt(struct tls_multi *multi, - struct buffer *buf, struct crypto_options **opt) +tls_pre_encrypt(struct tls_multi *multi, struct buffer *buf, struct crypto= _options **opt) { multi->save_ks =3D NULL; if (buf->len <=3D 0) @@ -4144,8 +3987,7 @@ ASSERT(ks); - peer =3D htonl(((P_DATA_V2 << P_OPCODE_SHIFT) | ks->key_id) << 24 - | (multi->peer_id & 0xFFFFFF)); + peer =3D htonl(((P_DATA_V2 << P_OPCODE_SHIFT) | ks->key_id) << 24 | (m= ulti->peer_id & 0xFFFFFF)); ASSERT(buf_write_prepend(buf, &peer, 4)); } @@ -4170,9 +4012,7 @@ */ bool -tls_send_payload(struct key_state *ks, - const uint8_t *data, - int size) +tls_send_payload(struct key_state *ks, const uint8_t *data, int size) { bool ret =3D false; @@ -4204,8 +4044,7 @@ } bool -tls_rec_payload(struct tls_multi *multi, - struct buffer *buf) +tls_rec_payload(struct tls_multi *multi, struct buffer *buf) { bool ret =3D false; @@ -4258,8 +4097,7 @@ } void -show_available_tls_ciphers(const char *cipher_list, - const char *cipher_list_tls13, +show_available_tls_ciphers(const char *cipher_list, const char *cipher_lis= t_tls13, const char *tls_cert_profile) { printf("Available TLS Ciphers, listed in order of preference:\n"); @@ -4276,8 +4114,7 @@ printf("\n" "Be aware that that whether a cipher suite in this list can act= ually work\n" "depends on the specific setup of both peers. See the man page = entries of\n" - "--tls-cipher and --show-tls for more details.\n\n" - ); + "--tls-cipher and --show-tls for more details.\n\n"); } /* @@ -4383,7 +4220,8 @@ } if (flags & PD_VERBOSE) { - buf_printf(&out, " tls_crypt_hmac=3D%s", format_hex(tls_crypt_= hmac, TLS_CRYPT_TAG_SIZE, 0, gc)); + buf_printf(&out, " tls_crypt_hmac=3D%s", + format_hex(tls_crypt_hmac, TLS_CRYPT_TAG_SIZE, 0, g= c)); } /* * Remainder is encrypted and optional wKc diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h index 000992d..db3e525 100644 --- a/src/openvpn/ssl.h +++ b/src/openvpn/ssl.h @@ -58,9 +58,10 @@ /* * Various timeouts */ -#define TLS_MULTI_REFRESH 15 /* call tls_multi_process once every n sec= onds */ -#define TLS_MULTI_HORIZON 2 /* call tls_multi_process frequently for n= seconds after - * every packet sent/received action */ +#define TLS_MULTI_REFRESH 15 /* call tls_multi_process once every n second= s */ +#define TLS_MULTI_HORIZON = \ + 2 /* call tls_multi_process frequently for n se= conds after \ + * every packet sent/received action */ /* * Buffer sizes (also see mtu.h). @@ -78,46 +79,46 @@ * as reserved for this reason */ /** Support P_DATA_V2 */ -#define IV_PROTO_DATA_V2 (1<<1) +#define IV_PROTO_DATA_V2 (1 << 1) /** Assume client will send a push request and server does not need * to wait for a push-request to send a push-reply */ -#define IV_PROTO_REQUEST_PUSH (1<<2) +#define IV_PROTO_REQUEST_PUSH (1 << 2) /** Supports key derivation via TLS key material exporter [RFC5705] */ -#define IV_PROTO_TLS_KEY_EXPORT (1<<3) +#define IV_PROTO_TLS_KEY_EXPORT (1 << 3) /** Supports signaling keywords with AUTH_PENDING, e.g. timeout=3Dxy */ -#define IV_PROTO_AUTH_PENDING_KW (1<<4) +#define IV_PROTO_AUTH_PENDING_KW (1 << 4) /** Support doing NCP in P2P mode. This mode works by both peers looking at * each other's IV_ variables and deterministically deciding both on the s= ame * result. */ -#define IV_PROTO_NCP_P2P (1<<5) +#define IV_PROTO_NCP_P2P (1 << 5) /** Supports the --dns option introduced in version 2.6. Not sent anymore.= */ -#define IV_PROTO_DNS_OPTION (1<<6) +#define IV_PROTO_DNS_OPTION (1 << 6) /** Support for explicit exit notify via control channel * This also includes support for the protocol-flags pushed option */ -#define IV_PROTO_CC_EXIT_NOTIFY (1<<7) +#define IV_PROTO_CC_EXIT_NOTIFY (1 << 7) /** Support for AUTH_FAIL,TEMP messages */ -#define IV_PROTO_AUTH_FAIL_TEMP (1<<8) +#define IV_PROTO_AUTH_FAIL_TEMP (1 << 8) /** Support to dynamic tls-crypt (renegotiation with TLS-EKM derived tls-c= rypt key) */ -#define IV_PROTO_DYN_TLS_CRYPT (1<<9) +#define IV_PROTO_DYN_TLS_CRYPT (1 << 9) /** Support the extended packet id and epoch format for data channel packe= ts */ -#define IV_PROTO_DATA_EPOCH (1<<10) +#define IV_PROTO_DATA_EPOCH (1 << 10) /** Supports the --dns option after all the incompatible changes */ -#define IV_PROTO_DNS_OPTION_V2 (1<<11) +#define IV_PROTO_DNS_OPTION_V2 (1 << 11) /* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN" -#define KEY_METHOD_2 2 +#define KEY_METHOD_2 2 /* key method taken from lower 4 bits */ #define KEY_METHOD_MASK 0x0F @@ -204,9 +205,7 @@ * Used to verify compatibility of local and remote option * sets. */ -void tls_multi_init_set_options(struct tls_multi *multi, - const char *local, - const char *remote); +void tls_multi_init_set_options(struct tls_multi *multi, const char *local= , const char *remote); /** * Cleanup a \c tls_multi structure and free associated memory @@ -226,9 +225,9 @@ /** @} addtogroup control_processor */ -#define TLSMP_INACTIVE 0 -#define TLSMP_ACTIVE 1 -#define TLSMP_KILL 2 +#define TLSMP_INACTIVE 0 +#define TLSMP_ACTIVE 1 +#define TLSMP_KILL 2 #define TLSMP_RECONNECT 3 /* @@ -237,11 +236,9 @@ * Basically decides if we should call tls_process for * the active or untrusted sessions. */ -int tls_multi_process(struct tls_multi *multi, - struct buffer *to_link, +int tls_multi_process(struct tls_multi *multi, struct buffer *to_link, struct link_socket_actual **to_link_addr, - struct link_socket_info *to_link_socket_info, - interval_t *wakeup); + struct link_socket_info *to_link_socket_info, interv= al_t *wakeup); /*************************************************************************= */ @@ -297,11 +294,8 @@ * @li False if the packet is a data channel packet, or if an error * occurred during processing of a control channel packet. */ -bool tls_pre_decrypt(struct tls_multi *multi, - const struct link_socket_actual *from, - struct buffer *buf, - struct crypto_options **opt, - bool floated, +bool tls_pre_decrypt(struct tls_multi *multi, const struct link_socket_act= ual *from, + struct buffer *buf, struct crypto_options **opt, bool= floated, const uint8_t **ad_start); @@ -323,8 +317,7 @@ * @param buf - The buffer containing the outgoing packet. * @param opt - Returns a crypto options structure with the security param= eters. */ -void tls_pre_encrypt(struct tls_multi *multi, - struct buffer *buf, struct crypto_options **opt); +void tls_pre_encrypt(struct tls_multi *multi, struct buffer *buf, struct c= rypto_options **opt); /** * Selects the primary encryption that should be used to encrypt data of an @@ -349,8 +342,7 @@ * * @ingroup data_crypto */ -void -tls_prepend_opcode_v1(const struct tls_multi *multi, struct buffer *buf); +void tls_prepend_opcode_v1(const struct tls_multi *multi, struct buffer *b= uf); /** * Prepend an OpenVPN data channel P_DATA_V2 header to the packet. The @@ -368,8 +360,7 @@ * * @ingroup data_crypto */ -void -tls_prepend_opcode_v2(const struct tls_multi *multi, struct buffer *buf); +void tls_prepend_opcode_v2(const struct tls_multi *multi, struct buffer *b= uf); /** * Perform some accounting for the key state used. @@ -433,15 +424,12 @@ /* * Send a payload over the TLS control channel */ -bool tls_send_payload(struct key_state *ks, - const uint8_t *data, - int size); +bool tls_send_payload(struct key_state *ks, const uint8_t *data, int size); /* * Receive a payload through the TLS control channel */ -bool tls_rec_payload(struct tls_multi *multi, - struct buffer *buf); +bool tls_rec_payload(struct tls_multi *multi, struct buffer *buf); /** * Updates remote address in TLS sessions. @@ -449,8 +437,7 @@ * @param multi - Tunnel to update * @param addr - new address */ -void tls_update_remote_addr(struct tls_multi *multi, - const struct link_socket_actual *addr); +void tls_update_remote_addr(struct tls_multi *multi, const struct link_soc= ket_actual *addr); /** * Update TLS session crypto parameters (cipher and auth) and derive data @@ -470,12 +457,9 @@ * * @return true if updating succeeded or keys are already generated, false= otherwise. */ -bool tls_session_update_crypto_params(struct tls_multi *multi, - struct tls_session *session, - struct options *options, - struct frame *frame, - struct frame *frame_fragment, - struct link_socket_info *lsi, +bool tls_session_update_crypto_params(struct tls_multi *multi, struct tls_= session *session, + struct options *options, struct fram= e *frame, + struct frame *frame_fragment, struct= link_socket_info *lsi, dco_context_t *dco); /* @@ -534,14 +518,12 @@ * protocol_dump() flags */ #define PD_TLS_AUTH_HMAC_SIZE_MASK 0xFF -#define PD_SHOW_DATA (1<<8) -#define PD_TLS (1<<9) -#define PD_VERBOSE (1<<10) -#define PD_TLS_CRYPT (1<<11) +#define PD_SHOW_DATA (1 << 8) +#define PD_TLS (1 << 9) +#define PD_VERBOSE (1 << 10) +#define PD_TLS_CRYPT (1 << 11) -const char *protocol_dump(struct buffer *buffer, - unsigned int flags, - struct gc_arena *gc); +const char *protocol_dump(struct buffer *buffer, unsigned int flags, struc= t gc_arena *gc); /* * debugging code @@ -567,10 +549,8 @@ * @param cipher_list_tls13 list of allowed TLS 1.3+ cipher, or NULL * @param tls_cert_profile TLS certificate crypto profile name. */ -void -show_available_tls_ciphers(const char *cipher_list, - const char *cipher_list_tls13, - const char *tls_cert_profile); +void show_available_tls_ciphers(const char *cipher_list, const char *ciphe= r_list_tls13, + const char *tls_cert_profile); /** @@ -579,25 +559,19 @@ * This erases the source material used to generate the data channel keys,= and * can thus be called only once per session. */ -bool -tls_session_generate_data_channel_keys(struct tls_multi *multi, - struct tls_session *session); +bool tls_session_generate_data_channel_keys(struct tls_multi *multi, struc= t tls_session *session); -void -tls_session_soft_reset(struct tls_multi *multi); +void tls_session_soft_reset(struct tls_multi *multi); /** * Load ovpn.xkey provider used for external key signing */ -void -load_xkey_provider(void); +void load_xkey_provider(void); /* Special method to skip the three way handshake RESET stages. This is * used by the HMAC code when seeing a packet that matches the previous * HMAC based stateless server state */ -bool -session_skip_to_pre_start(struct tls_session *session, - struct tls_pre_decrypt_state *state, - struct link_socket_actual *from); +bool session_skip_to_pre_start(struct tls_session *session, struct tls_pre= _decrypt_state *state, + struct link_socket_actual *from); #endif /* ifndef OPENVPN_SSL_H */ diff --git a/src/openvpn/ssl_backend.h b/src/openvpn/ssl_backend.h index 1cf9e1d..56fc397 100644 --- a/src/openvpn/ssl_backend.h +++ b/src/openvpn/ssl_backend.h @@ -102,11 +102,11 @@ * if a parse error should be flagged. */ #define TLS_VER_BAD -1 -#define TLS_VER_UNSPEC 0 /* default */ -#define TLS_VER_1_0 1 -#define TLS_VER_1_1 2 -#define TLS_VER_1_2 3 -#define TLS_VER_1_3 4 +#define TLS_VER_UNSPEC 0 /* default */ +#define TLS_VER_1_0 1 +#define TLS_VER_1_1 2 +#define TLS_VER_1_2 3 +#define TLS_VER_1_3 4 int tls_version_parse(const char *vstr, const char *extra); /** @@ -219,8 +219,7 @@ * of inline files. * @param dh_file_inline True if dh_file is an inline file. */ -void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, - bool dh_file_inline); +void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file,= bool dh_file_inline); /** * Load Elliptic Curve Parameters, and load them into the library-specific @@ -229,8 +228,7 @@ * @param ctx TLS context to use * @param curve_name The name of the elliptic curve to load. */ -void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_= name - ); +void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_= name); /** * Load PKCS #12 file for key, cert and (optionally) CA certs, and add to @@ -247,8 +245,8 @@ * @return 1 if an error occurred, 0 if parsing was * successful. */ -int tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, - bool pkcs12_file_inline, bool load_ca_file); +int tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,= bool pkcs12_file_inline, + bool load_ca_file); /** * Use Windows cryptoapi for key and cert, and add to library-specific TLS @@ -272,8 +270,7 @@ * of inline files. * @param cert_file_inline True if cert_file is an inline file. */ -void tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_fil= e, - bool cert_file_inline); +void tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_fil= e, bool cert_file_inline); /** * Load private key file into the given TLS context. @@ -319,8 +316,8 @@ * connection and should use the CA for verif= ying * client certificates */ -void tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, - bool ca_file_inline, const char *ca_path, bool tls_se= rver); +void tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, bool c= a_file_inline, + const char *ca_path, bool tls_server); /** * Load extra certificate authority certificates from the given file or pa= th. @@ -335,8 +332,7 @@ * @param extra_certs_file_inline True if extra_certs_file is an inl= ine * file. */ -void tls_ctx_load_extra_certs(struct tls_root_ctx *ctx, - const char *extra_certs_file, +void tls_ctx_load_extra_certs(struct tls_root_ctx *ctx, const char *extra_= certs_file, bool extra_certs_file_inline); #ifdef ENABLE_CRYPTO_MBEDTLS @@ -365,15 +361,14 @@ * @param is_server Initialise a server? * @param session The session associated with the given key_state */ -void key_state_ssl_init(struct key_state_ssl *ks_ssl, - const struct tls_root_ctx *ssl_ctx, bool is_server= , struct tls_session *session); +void key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_roo= t_ctx *ssl_ctx, + bool is_server, struct tls_session *session); /** * Sets a TLS session to be shutdown state, so the TLS library will genera= te * a shutdown alert. */ -void -key_state_ssl_shutdown(struct key_state_ssl *ks_ssl); +void key_state_ssl_shutdown(struct key_state_ssl *ks_ssl); /** * Free the SSL channel part of the given key state. @@ -390,12 +385,12 @@ * an array containing the inline CRL. * @param crl_inline True if crl_file is an inline CRL. */ -void backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, - const char *crl_file, bool crl_inline); +void backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *= crl_file, + bool crl_inline); -#define EXPORT_KEY_DATA_LABEL "EXPORTER-OpenVPN-datakeys" -#define EXPORT_P2P_PEERID_LABEL "EXPORTER-OpenVPN-p2p-peerid" -#define EXPORT_DYNAMIC_TLS_CRYPT_LABEL "EXPORTER-OpenVPN-dynamic-tls-cryp= t" +#define EXPORT_KEY_DATA_LABEL "EXPORTER-OpenVPN-datakeys" +#define EXPORT_P2P_PEERID_LABEL "EXPORTER-OpenVPN-p2p-peerid" +#define EXPORT_DYNAMIC_TLS_CRYPT_LABEL "EXPORTER-OpenVPN-dynamic-tls-crypt" /** * Keying Material Exporters [RFC 5705] allows additional keying material = to be * derived from existing TLS channel. This exported keying material can th= en be @@ -408,10 +403,8 @@ * @param ekm_size The size of ekm, in bytes * @returns true if exporting succeeded, false otherwise */ -bool -key_state_export_keying_material(struct tls_session *session, - const char *label, size_t label_size, - void *ekm, size_t ekm_size); +bool key_state_export_keying_material(struct tls_session *session, const c= har *label, + size_t label_size, void *ekm, size_t= ekm_size); /*************************************************************************= */ /** @addtogroup control_tls @@ -454,8 +447,7 @@ * again later to retry. * - \c -1: An error occurred. */ -int key_state_write_plaintext_const(struct key_state_ssl *ks_ssl, - const uint8_t *data, int len); +int key_state_write_plaintext_const(struct key_state_ssl *ks_ssl, const ui= nt8_t *data, int len); /** * Extract ciphertext data from the TLS module. @@ -500,8 +492,7 @@ * again later to retry. * - \c -1: An error occurred. */ -int key_state_write_ciphertext(struct key_state_ssl *ks_ssl, - struct buffer *buf); +int key_state_write_ciphertext(struct key_state_ssl *ks_ssl, struct buffer= *buf); /** * Extract plaintext data from the TLS module. @@ -549,10 +540,8 @@ * @param tls13 Select if <=3DTLS1.2 or TLS1.3+ ciphers * should be shown */ -void -show_available_tls_ciphers_list(const char *cipher_list, - const char *tls_cert_profile, - bool tls13); +void show_available_tls_ciphers_list(const char *cipher_list, const char *= tls_cert_profile, + bool tls13); /** * Show the available elliptic curves in the crypto library diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index e9dd5f2..e4814cd 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -118,15 +118,16 @@ * \ref key_generation "data channel key generation". * @ingroup control_processor */ -struct key_source { - uint8_t pre_master[48]; /**< Random used for master secret - * generation, provided only by client - * OpenVPN peer. */ - uint8_t random1[32]; /**< Seed used for master secret - * generation, provided by both client - * and server. */ - uint8_t random2[32]; /**< Seed used for key expansion, provided - * by both client and server. */ +struct key_source +{ + uint8_t pre_master[48]; /**< Random used for master secret + * generation, provided only by client + * OpenVPN peer. */ + uint8_t random1[32]; /**< Seed used for master secret + * generation, provided by both client + * and server. */ + uint8_t random2[32]; /**< Seed used for key expansion, provided + * by both client and server. */ }; @@ -135,9 +136,10 @@ * 2 \ref key_generation "data channel key generation". * @ingroup control_processor */ -struct key_source2 { - struct key_source client; /**< Random provided by client. */ - struct key_source server; /**< Random provided by server. */ +struct key_source2 +{ + struct key_source client; /**< Random provided by client. */ + struct key_source server; /**< Random provided by server. */ }; @@ -148,15 +150,16 @@ * being set to KS_AUTH_TRUE or KS_AUTH_FALSE * Only KS_AUTH_TRUE is fully authenticated */ -enum ks_auth_state { - KS_AUTH_FALSE, /**< Key state is not authenticated */ - KS_AUTH_DEFERRED, /**< Key state authentication is being defer= red, - * by async auth */ - KS_AUTH_TRUE /**< Key state is authenticated. TLS and use= r/pass - * succeeded. This includes AUTH_PENDING/OOB - * authentication as those hold the - * connection artificially in KS_AUTH_DEFERR= ED - */ +enum ks_auth_state +{ + KS_AUTH_FALSE, /**< Key state is not authenticated */ + KS_AUTH_DEFERRED, /**< Key state authentication is being deferred, + * by async auth */ + KS_AUTH_TRUE /**< Key state is authenticated. TLS and user/pass + * succeeded. This includes AUTH_PENDING/OOB + * authentication as those hold the + * connection artificially in KS_AUTH_DEFERRED + */ }; struct auth_deferred_status @@ -169,14 +172,16 @@ /* key_state_test_auth_control_file return values, these specify the * current status of a deferred authentication */ -enum auth_deferred_result { - ACF_PENDING, /**< deferred auth still pending */ - ACF_SUCCEEDED, /**< deferred auth has suceeded */ - ACF_DISABLED, /**< deferred auth is not used */ - ACF_FAILED /**< deferred auth has failed */ +enum auth_deferred_result +{ + ACF_PENDING, /**< deferred auth still pending */ + ACF_SUCCEEDED, /**< deferred auth has suceeded */ + ACF_DISABLED, /**< deferred auth is not used */ + ACF_FAILED /**< deferred auth has failed */ }; -enum dco_key_status { +enum dco_key_status +{ DCO_NOT_INSTALLED, DCO_INSTALLED_PRIMARY, DCO_INSTALLED_SECONDARY @@ -220,34 +225,34 @@ struct key_state_ssl ks_ssl; /* contains SSL object and BIOs for the c= ontrol channel */ - time_t initial; /* when we created this session */ - time_t established; /* when our state went S_ACTIVE */ - time_t must_negotiate; /* key negotiation times out if not finish= ed before this time */ - time_t must_die; /* this object is destroyed at this time */ - time_t peer_last_packet; /* Last time we received a packet in this = control session */ + time_t initial; /* when we created this session */ + time_t established; /* when our state went S_ACTIVE */ + time_t must_negotiate; /* key negotiation times out if not finis= hed before this time */ + time_t must_die; /* this object is destroyed at this time = */ + time_t peer_last_packet; /* Last time we received a packet in this= control session */ - int initial_opcode; /* our initial P_ opcode */ - struct session_id session_id_remote; /* peer's random session ID */ + int initial_opcode; /* our initial P_ opcode */ + struct session_id session_id_remote; /* peer's random session ID */ struct link_socket_actual remote_addr; /* peer's IP addr */ - struct crypto_options crypto_options;/* data channel crypto options */ + struct crypto_options crypto_options; /* data channel crypto options = */ - struct key_source2 *key_src; /* source entropy for key expansion= */ + struct key_source2 *key_src; /* source entropy for key expan= sion */ struct buffer plaintext_read_buf; struct buffer plaintext_write_buf; struct buffer ack_write_buf; struct reliable *send_reliable; /* holds a copy of outgoing packets un= til ACK received */ - struct reliable *rec_reliable; /* order incoming ciphertext packets be= fore we pass to TLS */ - struct reliable_ack *rec_ack; /* buffers all packet IDs we want to ACK= back to sender */ - struct reliable_ack *lru_acks; /* keeps the most recently acked packag= es*/ + struct reliable *rec_reliable; /* order incoming ciphertext packets b= efore we pass to TLS */ + struct reliable_ack *rec_ack; /* buffers all packet IDs we want to A= CK back to sender */ + struct reliable_ack *lru_acks; /* keeps the most recently acked packa= ges*/ /** Holds outgoing message for the control channel until ks->state rea= ches * S_ACTIVE */ struct buffer_list *paybuf; - counter_type n_bytes; /* how many bytes sent/recvd sinc= e last key exchange */ - counter_type n_packets; /* how many packets sent/recvd si= nce last key exchange */ + counter_type n_bytes; /* how many bytes sent/recvd since last key ex= change */ + counter_type n_packets; /* how many packets sent/recvd since last key = exchange */ /* * If bad username/password, TLS connection will come up but 'authenti= cated' will be false. @@ -270,19 +275,20 @@ /** Control channel wrapping (--tls-auth/--tls-crypt) context */ struct tls_wrap_ctx { - enum { - TLS_WRAP_NONE =3D 0, /**< No control channel wrapping */ - TLS_WRAP_AUTH, /**< Control channel authentication */ - TLS_WRAP_CRYPT, /**< Control channel encryption and authentication= */ - } mode; /**< Control channel wrapping mode */ - struct crypto_options opt; /**< Crypto state */ - struct buffer work; /**< Work buffer (only for --tls-crypt) */ - struct key_ctx tls_crypt_v2_server_key; /**< Decrypts client keys */ - const struct buffer *tls_crypt_v2_wkc; /**< Wrapped client key, - * sent to server */ - struct buffer tls_crypt_v2_metadata; /**< Received from client */ - bool cleanup_key_ctx; /**< opt.key_ctx_bi is owned = by - * this context */ + enum + { + TLS_WRAP_NONE =3D 0, /**< No control channel wrap= ping */ + TLS_WRAP_AUTH, /**< Control channel authentic= ation */ + TLS_WRAP_CRYPT, /**< Control channel encryptio= n and authentication */ + } mode; /**< Control channel wrapping = mode */ + struct crypto_options opt; /**< Crypto state */ + struct buffer work; /**< Work buffer (only for --t= ls-crypt) */ + struct key_ctx tls_crypt_v2_server_key; /**< Decrypts client keys */ + const struct buffer *tls_crypt_v2_wkc; /**< Wrapped client key, + * sent to server */ + struct buffer tls_crypt_v2_metadata; /**< Received from client */ + bool cleanup_key_ctx; /**< opt.key_ctx_bi is owned by + * this context */ /** original key data to be xored in to the key for dynamic tls-crypt. * * We keep the original key data to ensure that the newly generated key @@ -364,8 +370,8 @@ /* struct crypto_option flags */ unsigned int crypto_flags; - int replay_window; /* --replay-window parm */ - int replay_time; /* --replay-window parm */ + int replay_window; /* --replay-window parm */ + int replay_time; /* --replay-window parm */ const char *config_ciphername; const char *config_ncp_ciphers; @@ -393,9 +399,9 @@ const char *auth_user_pass_file; bool auth_user_pass_file_inline; - bool auth_token_generate; /**< Generate auth-tokens on successful - * user/pass auth,seet via - * options->auth_token_generate. */ + bool auth_token_generate; /**< Generate auth-tokens on successful + * user/pass auth,seet via + * options->auth_token_generate. */ bool auth_token_call_auth; /**< always call normal authentication */ unsigned int auth_token_lifetime; unsigned int auth_token_renewal; @@ -416,17 +422,17 @@ #endif /* configuration file SSL-related boolean and low-permutation options = */ -#define SSLF_CLIENT_CERT_NOT_REQUIRED (1<<0) -#define SSLF_CLIENT_CERT_OPTIONAL (1<<1) -#define SSLF_USERNAME_AS_COMMON_NAME (1<<2) -#define SSLF_AUTH_USER_PASS_OPTIONAL (1<<3) -#define SSLF_OPT_VERIFY (1<<4) -#define SSLF_CRL_VERIFY_DIR (1<<5) +#define SSLF_CLIENT_CERT_NOT_REQUIRED (1 << 0) +#define SSLF_CLIENT_CERT_OPTIONAL (1 << 1) +#define SSLF_USERNAME_AS_COMMON_NAME (1 << 2) +#define SSLF_AUTH_USER_PASS_OPTIONAL (1 << 3) +#define SSLF_OPT_VERIFY (1 << 4) +#define SSLF_CRL_VERIFY_DIR (1 << 5) #define SSLF_TLS_VERSION_MIN_SHIFT 6 -#define SSLF_TLS_VERSION_MIN_MASK 0xF /* (uses bit positions 6 to 9) = */ +#define SSLF_TLS_VERSION_MIN_MASK 0xF /* (uses bit positions 6 to 9) */ #define SSLF_TLS_VERSION_MAX_SHIFT 10 -#define SSLF_TLS_VERSION_MAX_MASK 0xF /* (uses bit positions 10 to 13= ) */ -#define SSLF_TLS_DEBUG_ENABLED (1<<14) +#define SSLF_TLS_VERSION_MAX_MASK 0xF /* (uses bit positions 10 to 13)= */ +#define SSLF_TLS_DEBUG_ENABLED (1 << 14) unsigned int ssl_flags; #ifdef ENABLE_MANAGEMENT @@ -457,10 +463,11 @@ * This is the index of \c tls_session.key * * @{ */ -#define KS_PRIMARY 0 /**< Primary %key state index. */ -#define KS_LAME_DUCK 1 /**< %Key state index that will retire - * soon. */ -#define KS_SIZE 2 /**< Size of the \c tls_session.key array.= */ +#define KS_PRIMARY 0 /**< Primary %key state index. */ +#define KS_LAME_DUCK \ + 1 /**< %Key state index that will retire \ + * soon. */ +#define KS_SIZE 2 /**< Size of the \c tls_session.key array. */ /** @} name Index of key_state objects within a tls_session structure */ /** @} addtogroup control_processor */ @@ -495,7 +502,7 @@ * tls_wrap_reneg.mode is TLS_WRAP_CRYPT, otherwise ignore it */ struct tls_wrap_ctx tls_wrap_reneg; - int initial_opcode; /* our initial P_ opcode */ + int initial_opcode; /* our initial P_ opcode */ struct session_id session_id; /* our random session ID */ /** @@ -511,7 +518,7 @@ struct cert_hash_set *cert_hash_set; - bool verified; /* true if peer certificate was verified a= gainst CA */ + bool verified; /* true if peer certificate was verified against CA */ /* not-yet-authenticated incoming client */ struct link_socket_actual untrusted_addr; @@ -536,12 +543,14 @@ * is being negotiated. * * @{ */ -#define TM_ACTIVE 0 /**< Active \c tls_session. */ -#define TM_INITIAL 1 /**< As yet un-trusted \c tls_session - * being negotiated. */ -#define TM_LAME_DUCK 2 /**< Old \c tls_session. */ -#define TM_SIZE 3 /**< Size of the \c tls_multi.session - * array. */ +#define TM_ACTIVE 0 /**< Active \c tls_session. */ +#define TM_INITIAL \ + 1 /**< As yet un-trusted \c tls_session \ + * being negotiated. */ +#define TM_LAME_DUCK 2 /**< Old \c tls_session. */ +#define TM_SIZE \ + 3 /**< Size of the \c tls_multi.session \ + * array. */ /** @} name Index of tls_session objects within a tls_multi structure */ /** @} addtogroup control_processor */ @@ -613,7 +622,7 @@ * used by tls_pre_encrypt to communicate the encrypt key * to tls_post_encrypt() */ - struct key_state *save_ks; /* temporary pointer used between pre/post= routines */ + struct key_state *save_ks; /* temporary pointer used between pre/post = routines */ /* * Used to return outgoing address from @@ -621,8 +630,8 @@ */ struct link_socket_actual to_link_addr; - int n_sessions; /**< Number of sessions negotiated thus - * far. */ + int n_sessions; /**< Number of sessions negotiated thus + * far. */ enum multi_status multi_state; /* @@ -693,8 +702,8 @@ uint32_t peer_id; bool use_peer_id; - char *remote_ciphername; /**< cipher specified in peer's config fil= e */ - bool remote_usescomp; /**< remote announced comp-lzo in OCC stri= ng */ + char *remote_ciphername; /**< cipher specified in peer's config file */ + bool remote_usescomp; /**< remote announced comp-lzo in OCC string = */ /* * Our session objects. diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index a4bb772..c619551 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -53,35 +53,28 @@ #include #if MBEDTLS_VERSION_NUMBER >=3D 0x02040000 - #include +#include #else - #include +#include #endif #include #include -static const mbedtls_x509_crt_profile openvpn_x509_crt_profile_legacy =3D -{ +static const mbedtls_x509_crt_profile openvpn_x509_crt_profile_legacy =3D { /* Hashes from SHA-1 and above */ - MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 ) - |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_RIPEMD160 ) - |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 ) - |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 ) - |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA384 ) - |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA512 ), + MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_M= D_RIPEMD160) + | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA224) | MBEDTLS_X509_ID_FLAG(M= BEDTLS_MD_SHA256) + | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) | MBEDTLS_X509_ID_FLAG(M= BEDTLS_MD_SHA512), 0xFFFFFFF, /* Any PK alg */ 0xFFFFFFF, /* Any curve */ 1024, /* RSA-1024 and larger */ }; -static const mbedtls_x509_crt_profile openvpn_x509_crt_profile_preferred = =3D -{ +static const mbedtls_x509_crt_profile openvpn_x509_crt_profile_preferred = =3D { /* SHA-2 and above */ - MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 ) - |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 ) - |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA384 ) - |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA512 ), + MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA224) | MBEDTLS_X509_ID_FLAG(MBEDTLS= _MD_SHA256) + | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) | MBEDTLS_X509_ID_FLAG(M= BEDTLS_MD_SHA512), 0xFFFFFFF, /* Any PK alg */ 0xFFFFFFF, /* Any curve */ 2048, /* RSA-2048 and larger */ @@ -185,9 +178,8 @@ * Mbed TLS stores this callback in the mbedtls_ssl_config struct and it * is used in the mbedtls_ssl_contexts set up from that config. */ int -mbedtls_ssl_export_keys_cb(void *p_expkey, const unsigned char *ms, - const unsigned char *kb, size_t maclen, - size_t keylen, size_t ivlen, +mbedtls_ssl_export_keys_cb(void *p_expkey, const unsigned char *ms, const = unsigned char *kb, + size_t maclen, size_t keylen, size_t ivlen, const unsigned char client_random[32], const unsigned char server_random[32], mbedtls_tls_prf_types tls_prf_type) @@ -196,8 +188,8 @@ struct key_state_ssl *ks_ssl =3D &session->key[KS_PRIMARY].ks_ssl; struct tls_key_cache *cache =3D &ks_ssl->tls_key_cache; - static_assert(sizeof(ks_ssl->ctx->session->master) - =3D=3D sizeof(cache->master_secret), "master size mismat= ch"); + static_assert(sizeof(ks_ssl->ctx->session->master) =3D=3D sizeof(cache= ->master_secret), + "master size mismatch"); memcpy(cache->client_server_random, client_random, 32); memcpy(cache->client_server_random + 32, server_random, 32); @@ -219,10 +211,8 @@ * mbedtls_ssl_config. It is placed in the mbedtls_ssl_context after it * has been set up. */ void -mbedtls_ssl_export_keys_cb(void *p_expkey, - mbedtls_ssl_key_export_type type, - const unsigned char *secret, - size_t secret_len, +mbedtls_ssl_export_keys_cb(void *p_expkey, mbedtls_ssl_key_export_type typ= e, + const unsigned char *secret, size_t secret_len, const unsigned char client_random[32], const unsigned char server_random[32], mbedtls_tls_prf_types tls_prf_type) @@ -242,8 +232,7 @@ * a different value, something is wrong with mbed TLS. */ if (secret_len !=3D sizeof(cache->master_secret)) { - msg(M_FATAL, - "ERROR: Incorrect TLS 1.2 master secret length: Got %zu, expec= ted %zu", + msg(M_FATAL, "ERROR: Incorrect TLS 1.2 master secret length: Got %= zu, expected %zu", secret_len, sizeof(cache->master_secret)); } @@ -258,8 +247,7 @@ bool -key_state_export_keying_material(struct tls_session *session, - const char *label, size_t label_size, +key_state_export_keying_material(struct tls_session *session, const char *= label, size_t label_size, void *ekm, size_t ekm_size) { ASSERT(strlen(label) =3D=3D label_size); @@ -268,7 +256,8 @@ /* Our version of mbed TLS has a built-in TLS-Exporter. */ mbedtls_ssl_context *ctx =3D session->key[KS_PRIMARY].ks_ssl.ctx; - if (mbed_ok(mbedtls_ssl_export_keying_material(ctx, ekm, ekm_size, lab= el, label_size, NULL, 0, 0))) + if (mbed_ok( + mbedtls_ssl_export_keying_material(ctx, ekm, ekm_size, label, = label_size, NULL, 0, 0))) { return true; } @@ -288,10 +277,8 @@ } int ret =3D mbedtls_ssl_tls_prf(cache->tls_prf_type, cache->master_sec= ret, - sizeof(cache->master_secret), - label, cache->client_server_random, - sizeof(cache->client_server_random), - ekm, ekm_size); + sizeof(cache->master_secret), label, cac= he->client_server_random, + sizeof(cache->client_server_random), ekm= , ekm_size); if (mbed_ok(ret)) { @@ -302,7 +289,7 @@ secure_memzero(ekm, session->opt->ekm_size); return false; } -#endif /* defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) */ +#endif /* defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) */ } bool @@ -325,7 +312,8 @@ if (0 !=3D strcmp(cipher_name, pair->iana_name)) { /* Deprecated name found, notify user */ - msg(M_WARN, "Deprecated cipher suite name '%s', please use IANA na= me '%s'", pair->openssl_name, pair->iana_name); + msg(M_WARN, "Deprecated cipher suite name '%s', please use IANA na= me '%s'", + pair->openssl_name, pair->iana_name); } return pair->iana_name; @@ -340,8 +328,10 @@ return; } - msg(M_WARN, "mbed TLS does not support setting tls-ciphersuites. " - "Ignoring TLS 1.3 cipher list: %s", ciphers); + msg(M_WARN, + "mbed TLS does not support setting tls-ciphersuites. " + "Ignoring TLS 1.3 cipher list: %s", + ciphers); } void @@ -360,7 +350,7 @@ int cipher_count =3D get_num_elements(ciphers, ':'); /* Allocate an array for them */ - ALLOC_ARRAY_CLEAR(ctx->allowed_ciphers, int, cipher_count+1) + ALLOC_ARRAY_CLEAR(ctx->allowed_ciphers, int, cipher_count + 1) /* Parse allowed ciphers, getting IDs */ int i =3D 0; @@ -369,8 +359,7 @@ token =3D strtok(tmp_ciphers, ":"); while (token) { - ctx->allowed_ciphers[i] =3D mbedtls_ssl_get_ciphersuite_id( - tls_translate_cipher_name(token)); + ctx->allowed_ciphers[i] =3D mbedtls_ssl_get_ciphersuite_id(tls_tra= nslate_cipher_name(token)); if (0 !=3D ctx->allowed_ciphers[i]) { i++; @@ -383,8 +372,7 @@ void tls_ctx_set_cert_profile(struct tls_root_ctx *ctx, const char *profile) { - if (!profile || 0 =3D=3D strcmp(profile, "legacy") - || 0 =3D=3D strcmp(profile, "insecure")) + if (!profile || 0 =3D=3D strcmp(profile, "legacy") || 0 =3D=3D strcmp(= profile, "insecure")) { ctx->cert_profile =3D openvpn_x509_crt_profile_legacy; } @@ -419,8 +407,7 @@ const char *token; while ((token =3D strsep(&tmp_groups, ":"))) { - const mbedtls_ecp_curve_info *ci =3D - mbedtls_ecp_curve_info_from_name(token); + const mbedtls_ecp_curve_info *ci =3D mbedtls_ecp_curve_info_from_n= ame(token); if (!ci) { msg(M_WARN, "Warning unknown curve/group specified: %s", token= ); @@ -462,13 +449,11 @@ } void -tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, - bool dh_inline) +tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, bool= dh_inline) { if (dh_inline) { - if (!mbed_ok(mbedtls_dhm_parse_dhm(ctx->dhm_ctx, - (const unsigned char *) dh_file, + if (!mbed_ok(mbedtls_dhm_parse_dhm(ctx->dhm_ctx, (const unsigned c= har *)dh_file, strlen(dh_file) + 1))) { msg(M_FATAL, "Cannot read inline DH parameters"); @@ -483,24 +468,23 @@ } msg(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with " counter_format= " bit key", - (counter_type) mbedtls_dhm_get_bitlen(ctx->dhm_ctx)); + (counter_type)mbedtls_dhm_get_bitlen(ctx->dhm_ctx)); } void -tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name - ) +tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name) { if (NULL !=3D curve_name) { msg(M_WARN, "WARNING: mbed TLS builds do not support specifying an= " - "ECDH curve with --ecdh-curve, using default curves. Use " - "--tls-groups to specify curves."); + "ECDH curve with --ecdh-curve, using default curves. U= se " + "--tls-groups to specify curves."); } } int -tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, - bool pkcs12_file_inline, bool load_ca_file) +tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, boo= l pkcs12_file_inline, + bool load_ca_file) { msg(M_FATAL, "PKCS #12 files not yet supported for mbed TLS."); return 0; @@ -515,8 +499,7 @@ #endif /* _WIN32 */ void -tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file, - bool cert_inline) +tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file, bo= ol cert_inline) { ASSERT(NULL !=3D ctx); @@ -527,8 +510,7 @@ if (cert_inline) { - if (!mbed_ok(mbedtls_x509_crt_parse(ctx->crt_chain, - (const unsigned char *)cert_fi= le, + if (!mbed_ok(mbedtls_x509_crt_parse(ctx->crt_chain, (const unsigne= d char *)cert_file, strlen(cert_file) + 1))) { msg(M_FATAL, "Cannot load inline certificate file"); @@ -544,8 +526,7 @@ } int -tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file, - bool priv_key_inline) +tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char *priv_key_file= , bool priv_key_inline) { int status; ASSERT(NULL !=3D ctx); @@ -557,40 +538,29 @@ if (priv_key_inline) { - status =3D mbedtls_compat_pk_parse_key(ctx->priv_key, - (const unsigned char *) priv_= key_file, + status =3D mbedtls_compat_pk_parse_key(ctx->priv_key, (const unsig= ned char *)priv_key_file, strlen(priv_key_file) + 1, NU= LL, 0, - mbedtls_ctr_drbg_random, - rand_ctx_get()); + mbedtls_ctr_drbg_random, rand= _ctx_get()); if (MBEDTLS_ERR_PK_PASSWORD_REQUIRED =3D=3D status) { - char passbuf[512] =3D {0}; + char passbuf[512] =3D { 0 }; pem_password_callback(passbuf, 512, 0, NULL); - status =3D mbedtls_compat_pk_parse_key(ctx->priv_key, - (const unsigned char *) p= riv_key_file, - strlen(priv_key_file) + 1, - (unsigned char *) passbuf, - strlen(passbuf), - mbedtls_ctr_drbg_random, - rand_ctx_get()); + status =3D mbedtls_compat_pk_parse_key( + ctx->priv_key, (const unsigned char *)priv_key_file, strle= n(priv_key_file) + 1, + (unsigned char *)passbuf, strlen(passbuf), mbedtls_ctr_drb= g_random, rand_ctx_get()); } } else { - status =3D mbedtls_compat_pk_parse_keyfile(ctx->priv_key, - priv_key_file, - NULL, - mbedtls_ctr_drbg_random, - rand_ctx_get()); + status =3D mbedtls_compat_pk_parse_keyfile(ctx->priv_key, priv_key= _file, NULL, + mbedtls_ctr_drbg_random, = rand_ctx_get()); if (MBEDTLS_ERR_PK_PASSWORD_REQUIRED =3D=3D status) { - char passbuf[512] =3D {0}; + char passbuf[512] =3D { 0 }; pem_password_callback(passbuf, 512, 0, NULL); - status =3D mbedtls_compat_pk_parse_keyfile(ctx->priv_key, - priv_key_file, passbu= f, - mbedtls_ctr_drbg_rand= om, - rand_ctx_get()); + status =3D mbedtls_compat_pk_parse_keyfile(ctx->priv_key, priv= _key_file, passbuf, + mbedtls_ctr_drbg_rand= om, rand_ctx_get()); } } if (!mbed_ok(status)) @@ -606,10 +576,8 @@ return 1; } - if (!mbed_ok(mbedtls_compat_pk_check_pair(&ctx->crt_chain->pk, - ctx->priv_key, - mbedtls_ctr_drbg_random, - rand_ctx_get()))) + if (!mbed_ok(mbedtls_compat_pk_check_pair(&ctx->crt_chain->pk, ctx->pr= iv_key, + mbedtls_ctr_drbg_random, ran= d_ctx_get()))) { msg(M_WARN, "Private key does not match the certificate"); return 1; @@ -637,13 +605,12 @@ * @return 0 on success, non-zero mbed TLS error code on failure. */ static inline int -external_pkcs1_sign( void *ctx_voidptr, - int (*f_rng)(void *, unsigned char *, size_t), void *= p_rng, +external_pkcs1_sign(void *ctx_voidptr, int (*f_rng)(void *, unsigned char = *, size_t), void *p_rng, #if MBEDTLS_VERSION_NUMBER < 0x03020100 - int mode, + int mode, #endif - mbedtls_md_type_t md_alg, unsigned int hashlen, const= unsigned char *hash, - unsigned char *sig ) + mbedtls_md_type_t md_alg, unsigned int hashlen, const = unsigned char *hash, + unsigned char *sig) { struct external_context *const ctx =3D ctx_voidptr; int rv; @@ -671,23 +638,22 @@ */ if (md_alg !=3D MBEDTLS_MD_NONE) { - const mbedtls_md_info_t *md_info =3D mbedtls_md_info_from_type( md= _alg ); + const mbedtls_md_info_t *md_info =3D mbedtls_md_info_from_type(md_= alg); if (md_info =3D=3D NULL) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA); } - if (!mbed_ok(mbedtls_oid_get_oid_by_md( md_alg, &oid, &oid_size ))) + if (!mbed_ok(mbedtls_oid_get_oid_by_md(md_alg, &oid, &oid_size))) { - return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA); } - hashlen =3D mbedtls_md_get_size( md_info ); + hashlen =3D mbedtls_md_get_size(md_info); asn_len =3D 10 + oid_size; } - if ((SIZE_MAX - hashlen) < asn_len - || ctx->signature_length < (asn_len + hashlen)) + if ((SIZE_MAX - hashlen) < asn_len || ctx->signature_length < (asn_len= + hashlen)) { return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; } @@ -706,12 +672,12 @@ * Digest ::=3D OCTET STRING */ *p++ =3D MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED; - *p++ =3D (unsigned char) ( 0x08 + oid_size + hashlen ); + *p++ =3D (unsigned char)(0x08 + oid_size + hashlen); *p++ =3D MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED; - *p++ =3D (unsigned char) ( 0x04 + oid_size ); + *p++ =3D (unsigned char)(0x04 + oid_size); *p++ =3D MBEDTLS_ASN1_OID; *p++ =3D oid_size & 0xFF; - memcpy( p, oid, oid_size ); + memcpy(p, oid, oid_size); p +=3D oid_size; *p++ =3D MBEDTLS_ASN1_NULL; *p++ =3D 0x00; @@ -726,8 +692,7 @@ memcpy(p, hash, hashlen); /* Call external signature function */ - if (!ctx->sign(ctx->sign_ctx, to_sign, asn_len + hashlen, sig, - ctx->signature_length)) + if (!ctx->sign(ctx->sign_ctx, to_sign, asn_len + hashlen, sig, ctx->si= gnature_length)) { rv =3D MBEDTLS_ERR_RSA_PRIVATE_FAILED; goto done; @@ -749,8 +714,8 @@ } int -tls_ctx_use_external_signing_func(struct tls_root_ctx *ctx, - external_sign_func sign_func, void *sign= _ctx) +tls_ctx_use_external_signing_func(struct tls_root_ctx *ctx, external_sign_= func sign_func, + void *sign_ctx) { ASSERT(NULL !=3D ctx); @@ -763,7 +728,7 @@ if (mbedtls_pk_get_type(&ctx->crt_chain->pk) !=3D MBEDTLS_PK_RSA) { msg(M_WARN, "ERROR: external key with mbed TLS requires a " - "certificate with an RSA key."); + "certificate with an RSA key."); return 1; } @@ -772,8 +737,8 @@ ctx->external_key.sign_ctx =3D sign_ctx; ALLOC_OBJ_CLEAR(ctx->priv_key, mbedtls_pk_context); - if (!mbed_ok(mbedtls_pk_setup_rsa_alt(ctx->priv_key, &ctx->external_ke= y, - NULL, external_pkcs1_sign, exter= nal_key_len))) + if (!mbed_ok(mbedtls_pk_setup_rsa_alt(ctx->priv_key, &ctx->external_ke= y, NULL, + external_pkcs1_sign, external_ke= y_len))) { return 1; } @@ -784,8 +749,7 @@ #ifdef ENABLE_MANAGEMENT /** Query the management interface for a signature, see external_sign_func= . */ static bool -management_sign_func(void *sign_ctx, const void *src, size_t src_len, - void *dst, size_t dst_len) +management_sign_func(void *sign_ctx, const void *src, size_t src_len, void= *dst, size_t dst_len) { bool ret =3D false; char *src_b64 =3D NULL; @@ -800,8 +764,7 @@ * We only support RSA external keys and PKCS1 signatures at the moment * in mbed TLS, so the signature parameter is hardcoded to this encodi= ng */ - if (!(dst_b64 =3D management_query_pk_sig(management, src_b64, - "RSA_PKCS1_PADDING"))) + if (!(dst_b64 =3D management_query_pk_sig(management, src_b64, "RSA_PK= CS1_PADDING"))) { goto cleanup; } @@ -828,8 +791,8 @@ #endif /* ifdef ENABLE_MANAGEMENT */ void -tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, - bool ca_inline, const char *ca_path, bool tls_server) +tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, bool ca_inl= ine, const char *ca_path, + bool tls_server) { if (ca_path) { @@ -838,8 +801,7 @@ if (ca_file && ca_inline) { - if (!mbed_ok(mbedtls_x509_crt_parse(ctx->ca_chain, - (const unsigned char *) ca_fil= e, + if (!mbed_ok(mbedtls_x509_crt_parse(ctx->ca_chain, (const unsigned= char *)ca_file, strlen(ca_file) + 1))) { msg(M_FATAL, "Cannot load inline CA certificates"); @@ -868,8 +830,7 @@ if (extra_certs_inline) { - if (!mbed_ok(mbedtls_x509_crt_parse(ctx->crt_chain, - (const unsigned char *) extra_= certs_file, + if (!mbed_ok(mbedtls_x509_crt_parse(ctx->crt_chain, (const unsigne= d char *)extra_certs_file, strlen(extra_certs_file) + 1))) { msg(M_FATAL, "Cannot load inline extra-certs file"); @@ -917,7 +878,7 @@ } static int -endless_buf_read( endless_buffer *in, unsigned char *out, size_t out_len ) +endless_buf_read(endless_buffer *in, unsigned char *out, size_t out_len) { size_t read_len =3D 0; @@ -932,8 +893,7 @@ if (block_len <=3D out_len - read_len) { buffer_entry *cur_entry =3D in->first_block; - memcpy(out + read_len, cur_entry->data + in->data_start, - block_len); + memcpy(out + read_len, cur_entry->data + in->data_start, block= _len); read_len +=3D block_len; @@ -949,8 +909,7 @@ } else { - memcpy(out + read_len, in->first_block->data + in->data_start, - out_len - read_len); + memcpy(out + read_len, in->first_block->data + in->data_start,= out_len - read_len); in->data_start +=3D out_len - read_len; read_len =3D out_len; } @@ -960,7 +919,7 @@ } static int -endless_buf_write( endless_buffer *out, const unsigned char *in, size_t le= n ) +endless_buf_write(endless_buffer *out, const unsigned char *in, size_t len) { buffer_entry *new_block =3D malloc(sizeof(buffer_entry)); if (NULL =3D=3D new_block) @@ -996,22 +955,21 @@ } static int -ssl_bio_read( void *ctx, unsigned char *out, size_t out_len) +ssl_bio_read(void *ctx, unsigned char *out, size_t out_len) { - bio_ctx *my_ctx =3D (bio_ctx *) ctx; + bio_ctx *my_ctx =3D (bio_ctx *)ctx; return endless_buf_read(&my_ctx->in, out, out_len); } static int -ssl_bio_write( void *ctx, const unsigned char *in, size_t in_len) +ssl_bio_write(void *ctx, const unsigned char *in, size_t in_len) { - bio_ctx *my_ctx =3D (bio_ctx *) ctx; + bio_ctx *my_ctx =3D (bio_ctx *)ctx; return endless_buf_write(&my_ctx->out, in, in_len); } static void -my_debug( void *ctx, int level, const char *file, int line, - const char *str ) +my_debug(void *ctx, int level, const char *file, int line, const char *str) { int my_loglevel =3D (level < 3) ? D_TLS_DEBUG_MED : D_TLS_DEBUG; msg(my_loglevel, "mbed TLS msg (%s:%d): %s", file, line, str); @@ -1023,8 +981,8 @@ void tls_ctx_personalise_random(struct tls_root_ctx *ctx) { - static char old_sha256_hash[32] =3D {0}; - unsigned char sha256_hash[32] =3D {0}; + static char old_sha256_hash[32] =3D { 0 }; + unsigned char sha256_hash[32] =3D { 0 }; mbedtls_ctr_drbg_context *cd_ctx =3D rand_ctx_get(); if (NULL !=3D ctx->crt_chain) @@ -1056,7 +1014,7 @@ #elif defined(MBEDTLS_SSL_PROTO_TLS1_2) return TLS_VER_1_2; #else - #error mbedtls is compiled without support for TLS 1.2 or 1.3 +#error mbedtls is compiled without support for TLS 1.2 or 1.3 #endif } @@ -1089,8 +1047,7 @@ } void -backend_tls_ctx_reload_crl(struct tls_root_ctx *ctx, const char *crl_file, - bool crl_inline) +backend_tls_ctx_reload_crl(struct tls_root_ctx *ctx, const char *crl_file,= bool crl_inline) { ASSERT(crl_file); @@ -1102,8 +1059,7 @@ if (crl_inline) { - if (!mbed_ok(mbedtls_x509_crl_parse(ctx->crl, - (const unsigned char *)crl_fil= e, + if (!mbed_ok(mbedtls_x509_crl_parse(ctx->crl, (const unsigned char= *)crl_file, strlen(crl_file) + 1))) { msg(M_WARN, "CRL: cannot parse inline CRL"); @@ -1125,8 +1081,7 @@ } =20 void -key_state_ssl_init(struct key_state_ssl *ks_ssl, - const struct tls_root_ctx *ssl_ctx, bool is_server, +key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_root_ctx= *ssl_ctx, bool is_server, struct tls_session *session) { ASSERT(NULL !=3D ssl_ctx); @@ -1136,8 +1091,8 @@ /* Initialise SSL config */ ALLOC_OBJ_CLEAR(ks_ssl->ssl_config, mbedtls_ssl_config); mbedtls_ssl_config_init(ks_ssl->ssl_config); - mbedtls_ssl_config_defaults(ks_ssl->ssl_config, ssl_ctx->endpoint, - MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_= PRESET_DEFAULT); + mbedtls_ssl_config_defaults(ks_ssl->ssl_config, ssl_ctx->endpoint, MBE= DTLS_SSL_TRANSPORT_STREAM, + MBEDTLS_SSL_PRESET_DEFAULT); #ifdef MBEDTLS_DEBUG_C /* We only want to have mbed TLS generate debug level logging when we = would * also display it. @@ -1153,8 +1108,7 @@ } #endif mbedtls_ssl_conf_dbg(ks_ssl->ssl_config, my_debug, NULL); - mbedtls_ssl_conf_rng(ks_ssl->ssl_config, mbedtls_ctr_drbg_random, - rand_ctx_get()); + mbedtls_ssl_conf_rng(ks_ssl->ssl_config, mbedtls_ctr_drbg_random, rand= _ctx_get()); mbedtls_ssl_conf_cert_profile(ks_ssl->ssl_config, &ssl_ctx->cert_profi= le); @@ -1169,8 +1123,8 @@ } /* Disable TLS renegotiations if the mbedtls library supports that fea= ture. - * OpenVPN's renegotiation creates new SSL sessions and does not depend= on - * this feature and TLS renegotiations have been problematic in the pas= t. */ + * OpenVPN's renegotiation creates new SSL sessions and does not depen= d on + * this feature and TLS renegotiations have been problematic in the pa= st. */ #if defined(MBEDTLS_SSL_RENEGOTIATION) mbedtls_ssl_conf_renegotiation(ks_ssl->ssl_config, MBEDTLS_SSL_RENEGOT= IATION_DISABLED); #endif /* MBEDTLS_SSL_RENEGOTIATION */ @@ -1187,12 +1141,10 @@ /* Initialise authentication information */ if (is_server) { - mbed_ok(mbedtls_ssl_conf_dh_param_ctx(ks_ssl->ssl_config, - ssl_ctx->dhm_ctx)); + mbed_ok(mbedtls_ssl_conf_dh_param_ctx(ks_ssl->ssl_config, ssl_ctx-= >dhm_ctx)); } - mbed_ok(mbedtls_ssl_conf_own_cert(ks_ssl->ssl_config, ssl_ctx->crt_cha= in, - ssl_ctx->priv_key)); + mbed_ok(mbedtls_ssl_conf_own_cert(ks_ssl->ssl_config, ssl_ctx->crt_cha= in, ssl_ctx->priv_key)); /* Initialise SSL verification */ if (session->opt->ssl_flags & SSLF_CLIENT_CERT_OPTIONAL) @@ -1211,8 +1163,7 @@ /* Initialize minimum TLS version */ { const int configured_tls_version_min =3D - (session->opt->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) - &SSLF_TLS_VERSION_MIN_MASK; + (session->opt->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF= _TLS_VERSION_MIN_MASK; /* default to TLS 1.2 */ mbedtls_ssl_protocol_version version =3D MBEDTLS_SSL_VERSION_TLS1_= 2; @@ -1228,8 +1179,7 @@ /* Initialize maximum TLS version */ { const int configured_tls_version_max =3D - (session->opt->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) - &SSLF_TLS_VERSION_MAX_MASK; + (session->opt->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF= _TLS_VERSION_MAX_MASK; mbedtls_ssl_protocol_version version =3D MBEDTLS_SSL_VERSION_UNKNO= WN; @@ -1246,10 +1196,10 @@ mbedtls_ssl_conf_max_tls_version(ks_ssl->ssl_config, version); } -#if defined(HAVE_MBEDTLS_SSL_CONF_EXPORT_KEYS_EXT_CB) && !defined(MBEDTLS_= SSL_KEYING_MATERIAL_EXPORT) +#if defined(HAVE_MBEDTLS_SSL_CONF_EXPORT_KEYS_EXT_CB) \ + && !defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) /* Initialize keying material exporter, old style. */ - mbedtls_ssl_conf_export_keys_ext_cb(ks_ssl->ssl_config, - mbedtls_ssl_export_keys_cb, sessio= n); + mbedtls_ssl_conf_export_keys_ext_cb(ks_ssl->ssl_config, mbedtls_ssl_ex= port_keys_cb, session); #endif /* Initialise SSL context */ @@ -1268,8 +1218,7 @@ /* Initialise BIOs */ ALLOC_OBJ_CLEAR(ks_ssl->bio_ctx, bio_ctx); - mbedtls_ssl_set_bio(ks_ssl->ctx, ks_ssl->bio_ctx, ssl_bio_write, - ssl_bio_read, NULL); + mbedtls_ssl_set_bio(ks_ssl->ctx, ks_ssl->bio_ctx, ssl_bio_write, ssl_b= io_read, NULL); } @@ -1318,7 +1267,7 @@ if (1 =3D=3D retval) { - memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */ + memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */ buf->len =3D 0; } @@ -1351,16 +1300,14 @@ { return 0; } - mbed_log_err(D_TLS_ERRORS, retval, - "TLS ERROR: write tls_write_plaintext_const error"); + mbed_log_err(D_TLS_ERRORS, retval, "TLS ERROR: write tls_write_pla= intext_const error"); return -1; } if (retval !=3D len) { - msg(D_TLS_ERRORS, - "TLS ERROR: write tls_write_plaintext_const incomplete %d/%d", - retval, len); + msg(D_TLS_ERRORS, "TLS ERROR: write tls_write_plaintext_const inco= mplete %d/%d", retval, + len); perf_pop(); return -1; } @@ -1447,15 +1394,14 @@ { return 0; } - mbed_log_err(D_TLS_ERRORS, retval, - "TLS ERROR: write tls_write_ciphertext error"); + mbed_log_err(D_TLS_ERRORS, retval, "TLS ERROR: write tls_write_cip= hertext error"); return -1; } if (retval !=3D buf->len) { - msg(D_TLS_ERRORS, "TLS ERROR: write tls_write_ciphertext incomplet= e %d/%d", - retval, buf->len); + msg(D_TLS_ERRORS, "TLS ERROR: write tls_write_ciphertext incomplet= e %d/%d", retval, + buf->len); perf_pop(); return -1; } @@ -1463,7 +1409,7 @@ /* successful write */ dmsg(D_HANDSHAKE_VERBOSE, "write tls_write_ciphertext %d bytes", retva= l); - memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */ + memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */ buf->len =3D 0; perf_pop(); @@ -1535,25 +1481,20 @@ char s2[256]; s1[0] =3D s2[0] =3D 0; - snprintf(s1, sizeof(s1), "%s %s, cipher %s", - prefix, - mbedtls_ssl_get_version(ks_ssl->ctx), + snprintf(s1, sizeof(s1), "%s %s, cipher %s", prefix, mbedtls_ssl_get_v= ersion(ks_ssl->ctx), mbedtls_ssl_get_ciphersuite(ks_ssl->ctx)); cert =3D mbedtls_ssl_get_peer_cert(ks_ssl->ctx); if (cert !=3D NULL) { - snprintf(s2, sizeof(s2), ", %u bit key", - (unsigned int) mbedtls_pk_get_bitlen(&cert->pk)); + snprintf(s2, sizeof(s2), ", %u bit key", (unsigned int)mbedtls_pk_= get_bitlen(&cert->pk)); } msg(D_HANDSHAKE, "%s%s", s1, s2); } void -show_available_tls_ciphers_list(const char *cipher_list, - const char *tls_cert_profile, - bool tls13) +show_available_tls_ciphers_list(const char *cipher_list, const char *tls_c= ert_profile, bool tls13) { if (tls13) { @@ -1604,8 +1545,8 @@ { static char mbedtls_version[30]; unsigned int pv =3D mbedtls_version_get_number(); - snprintf(mbedtls_version, sizeof(mbedtls_version), "mbed TLS %d.%d.%d", - (pv>>24)&0xff, (pv>>16)&0xff, (pv>>8)&0xff ); + snprintf(mbedtls_version, sizeof(mbedtls_version), "mbed TLS %d.%d.%d"= , (pv >> 24) & 0xff, + (pv >> 16) & 0xff, (pv >> 8) & 0xff); return mbedtls_version; } diff --git a/src/openvpn/ssl_mbedtls.h b/src/openvpn/ssl_mbedtls.h index 9f124cd..fcc5227 100644 --- a/src/openvpn/ssl_mbedtls.h +++ b/src/openvpn/ssl_mbedtls.h @@ -44,19 +44,22 @@ typedef struct _buffer_entry buffer_entry; -struct _buffer_entry { +struct _buffer_entry +{ size_t length; uint8_t *data; buffer_entry *next_block; }; -typedef struct { +typedef struct +{ size_t data_start; buffer_entry *first_block; buffer_entry *last_block; } endless_buffer; -typedef struct { +typedef struct +{ endless_buffer in; endless_buffer out; } bio_ctx; @@ -74,12 +77,12 @@ * * @return true if signing succeeded, false otherwise. */ -typedef bool (*external_sign_func)( - void *sign_ctx, const void *src, size_t src_size, - void *dst, size_t dst_size); +typedef bool (*external_sign_func)(void *sign_ctx, const void *src, size_t= src_size, void *dst, + size_t dst_size); /** Context used by external_pkcs1_sign() */ -struct external_context { +struct external_context +{ size_t signature_length; external_sign_func sign; void *sign_ctx; @@ -92,13 +95,16 @@ * * The constants 64 and 48 are inherent to TLS 1.2. For TLS 1.3, it is not * possible to obtain the exporter master secret from mbed TLS. */ -struct tls_key_cache { +struct tls_key_cache +{ unsigned char client_server_random[64]; mbedtls_tls_prf_types tls_prf_type; unsigned char master_secret[48]; }; -#else /* !defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) */ -struct tls_key_cache { }; +#else /* !defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) */ +struct tls_key_cache +{ +}; #endif /** @@ -107,30 +113,32 @@ * * Either \c priv_key_pkcs11 or \c priv_key must be filled in. */ -struct tls_root_ctx { - bool initialised; /**< True if the context has been initiali= sed */ +struct tls_root_ctx +{ + bool initialised; /**< True if the context has be= en initialised */ - int endpoint; /**< Whether or not this is a server or a = client */ + int endpoint; /**< Whether or not this is a s= erver or a client */ - mbedtls_dhm_context *dhm_ctx; /**< Diffie-Helmann-Merkle context= */ - mbedtls_x509_crt *crt_chain; /**< Local Certificate chain */ - mbedtls_x509_crt *ca_chain; /**< CA chain for remote verificat= ion */ - mbedtls_pk_context *priv_key; /**< Local private key */ - mbedtls_x509_crl *crl; /**< Certificate Revocation List */ - time_t crl_last_mtime; /**< CRL last modification time */ - off_t crl_last_size; /**< size of last loaded CRL */ + mbedtls_dhm_context *dhm_ctx; /**< Diffie-Helmann-Merkle cont= ext */ + mbedtls_x509_crt *crt_chain; /**< Local Certificate chain */ + mbedtls_x509_crt *ca_chain; /**< CA chain for remote verifi= cation */ + mbedtls_pk_context *priv_key; /**< Local private key */ + mbedtls_x509_crl *crl; /**< Certificate Revocation Lis= t */ + time_t crl_last_mtime; /**< CRL last modification time= */ + off_t crl_last_size; /**< size of last loaded CRL */ #ifdef ENABLE_PKCS11 - pkcs11h_certificate_t pkcs11_cert; /**< PKCS11 certificate */ + pkcs11h_certificate_t pkcs11_cert; /**< PKCS11 certificate */ #endif - struct external_context external_key; /**< External key context */ - int *allowed_ciphers; /**< List of allowed ciphers for this conn= ection */ - mbedtls_compat_group_id *groups; /**< List of allowed groups for t= his connection */ + struct external_context external_key; /**< External key context */ + int *allowed_ciphers; /**< List of allowed ciphers fo= r this connection */ + mbedtls_compat_group_id *groups; /**< List of allowed groups for= this connection */ mbedtls_x509_crt_profile cert_profile; /**< Allowed certificate types = */ }; -struct key_state_ssl { - mbedtls_ssl_config *ssl_config; /**< mbedTLS global ssl config */ - mbedtls_ssl_context *ctx; /**< mbedTLS connection context */ +struct key_state_ssl +{ + mbedtls_ssl_config *ssl_config; /**< mbedTLS global ssl config */ + mbedtls_ssl_context *ctx; /**< mbedTLS connection context */ bio_ctx *bio_ctx; struct tls_key_cache tls_key_cache; @@ -146,8 +154,7 @@ * * @return 0 if successful, 1 if an error occurred. */ -int tls_ctx_use_external_signing_func(struct tls_root_ctx *ctx, - external_sign_func sign_func, +int tls_ctx_use_external_signing_func(struct tls_root_ctx *ctx, external_s= ign_func sign_func, void *sign_ctx); static inline void diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c index 74d7b43..08bd33a 100644 --- a/src/openvpn/ssl_ncp.c +++ b/src/openvpn/ssl_ncp.c @@ -83,8 +83,7 @@ { return false; } - else if (tls_peer_info_ncp_ver(peer_info) >=3D 2 - || strstr(peer_info, "IV_CIPHERS=3D")) + else if (tls_peer_info_ncp_ver(peer_info) >=3D 2 || strstr(peer_info, = "IV_CIPHERS=3D")) { return true; } @@ -99,7 +98,7 @@ { bool error_found =3D false; - struct buffer new_list =3D alloc_buf(MAX_NCP_CIPHERS_LENGTH); + struct buffer new_list =3D alloc_buf(MAX_NCP_CIPHERS_LENGTH); char *const tmp_ciphers =3D string_alloc(list, NULL); const char *token =3D strtok(tmp_ciphers, ":"); @@ -127,22 +126,23 @@ if (nonecipher) { msg(M_WARN, "WARNING: cipher 'none' specified for --data-ciphe= rs. " - "This allows negotiation of NO encryption and " - "tunnelled data WILL then be transmitted in clear text " - "over the network! " - "PLEASE DO RECONSIDER THIS SETTING!"); + "This allows negotiation of NO encryption and " + "tunnelled data WILL then be transmitted in clear = text " + "over the network! " + "PLEASE DO RECONSIDER THIS SETTING!"); } if (!nonecipher && !cipher_valid(token)) { msg(M_WARN, "Unsupported %scipher in --data-ciphers: %s", opts= tr, token); error_found =3D error_found || !optional; } - else if (!nonecipher && !cipher_kt_mode_aead(token) - && !cipher_kt_mode_cbc(token) + else if (!nonecipher && !cipher_kt_mode_aead(token) && !cipher_kt_= mode_cbc(token) && !cipher_kt_mode_ofb_cfb(token)) { - msg(M_WARN, "Unsupported %scipher algorithm '%s'. It does not = use " - "CFB, OFB, CBC, or a supported AEAD mode", optstr, token); + msg(M_WARN, + "Unsupported %scipher algorithm '%s'. It does not use " + "CFB, OFB, CBC, or a supported AEAD mode", + optstr, token); error_found =3D error_found || !optional; } else @@ -155,7 +155,7 @@ ovpn_cipher_name =3D "none"; } - if (buf_len(&new_list)> 0) + if (buf_len(&new_list) > 0) { /* The next if condition ensure there is always space for * a : @@ -164,11 +164,10 @@ } /* Ensure buffer has capacity for cipher name + : + \0 */ - if (!(buf_forward_capacity(&new_list) > - strlen(ovpn_cipher_name) + 2)) + if (!(buf_forward_capacity(&new_list) > strlen(ovpn_cipher_nam= e) + 2)) { msg(M_WARN, "Length of --data-ciphers is over the " - "limit of 127 chars"); + "limit of 127 chars"); error_found =3D true; } else @@ -180,7 +179,6 @@ } - char *ret =3D NULL; if (!error_found && buf_len(&new_list) > 0) { @@ -201,8 +199,7 @@ size_t newlen =3D strlen(o->ncp_ciphers) + 1 + strlen(ciphername) + 1; char *ncp_ciphers =3D gc_malloc(newlen, false, &o->gc); - ASSERT(snprintf(ncp_ciphers, newlen, "%s:%s", o->ncp_ciphers, - ciphername)); + ASSERT(snprintf(ncp_ciphers, newlen, "%s:%s", o->ncp_ciphers, cipherna= me)); o->ncp_ciphers =3D ncp_ciphers; } @@ -234,7 +231,7 @@ { return iv_ciphers; } - else if (tls_peer_info_ncp_ver(peer_info)>=3D2) + else if (tls_peer_info_ncp_ver(peer_info) >=3D 2) { /* If the peer announces IV_NCP=3D2 then it supports the AES GCM * ciphers */ @@ -247,8 +244,8 @@ } char * -ncp_get_best_cipher(const char *server_list, const char *peer_info, - const char *remote_cipher, struct gc_arena *gc) +ncp_get_best_cipher(const char *server_list, const char *peer_info, const = char *remote_cipher, + struct gc_arena *gc) { /* * The gc of the parameter is tied to the VPN session, create a @@ -263,8 +260,7 @@ /* non-NCP clients without OCC? "assume nothing" */ /* For client doing the newer version of NCP (that send IV_CIPHERS) * we cannot assume that they will accept remote_cipher */ - if (remote_cipher =3D=3D NULL - || (peer_info && strstr(peer_info, "IV_CIPHERS=3D"))) + if (remote_cipher =3D=3D NULL || (peer_info && strstr(peer_info, "IV_C= IPHERS=3D"))) { remote_cipher =3D ""; } @@ -274,8 +270,7 @@ const char *token; while ((token =3D strsep(&tmp_ciphers, ":"))) { - if (tls_item_in_cipher_list(token, peer_ncp_list) - || streq(token, remote_cipher)) + if (tls_item_in_cipher_list(token, peer_ncp_list) || streq(token, = remote_cipher)) { break; } @@ -303,8 +298,7 @@ static bool tls_poor_mans_ncp(struct options *o, const char *remote_ciphername) { - if (remote_ciphername - && tls_item_in_cipher_list(remote_ciphername, o->ncp_ciphers)) + if (remote_ciphername && tls_item_in_cipher_list(remote_ciphername, o-= >ncp_ciphers)) { o->ciphername =3D string_alloc(remote_ciphername, &o->gc); msg(D_TLS_DEBUG_LOW, "Using peer cipher '%s'", o->ciphername); @@ -339,29 +333,27 @@ /* We failed negotiation, give appropriate error message */ if (c->c2.tls_multi->remote_ciphername) { - msg(D_TLS_ERRORS, "OPTIONS ERROR: failed to negotiate " + msg(D_TLS_ERRORS, + "OPTIONS ERROR: failed to negotiate " "cipher with server. Add the server's " "cipher ('%s') to --data-ciphers (currently '%s'), e.g." "--data-ciphers %s:%s if you want to connect to this server.", - c->c2.tls_multi->remote_ciphername, - c->options.ncp_ciphers_conf, c->options.ncp_ciphers_conf, - c->c2.tls_multi->remote_ciphername); + c->c2.tls_multi->remote_ciphername, c->options.ncp_ciphers_con= f, + c->options.ncp_ciphers_conf, c->c2.tls_multi->remote_ciphernam= e); return false; - } else { msg(D_TLS_ERRORS, "OPTIONS ERROR: failed to negotiate " - "cipher with server. Configure " - "--data-ciphers-fallback if you want to connect " - "to this server."); + "cipher with server. Configure " + "--data-ciphers-fallback if you want to connect " + "to this server."); return false; } } const char * -get_p2p_ncp_cipher(struct tls_session *session, const char *peer_info, - struct gc_arena *gc) +get_p2p_ncp_cipher(struct tls_session *session, const char *peer_info, str= uct gc_arena *gc) { /* we use a local gc arena to keep the temporary strings needed by str= sep */ struct gc_arena gc_local =3D gc_new(); @@ -411,8 +403,7 @@ } static void -p2p_ncp_set_options(struct tls_multi *multi, struct tls_session *session, - const char *common_cipher) +p2p_ncp_set_options(struct tls_multi *multi, struct tls_session *session, = const char *common_cipher) { /* will return 0 if peer_info is null */ const unsigned int iv_proto_peer =3D extract_iv_proto(multi->peer_info= ); @@ -434,8 +425,8 @@ session->opt->crypto_flags |=3D CO_USE_CC_EXIT_NOTIFY; } =20 - if (session->opt->data_epoch_supported && (iv_proto_peer & IV_PROTO_DA= TA_EPOCH) - && common_cipher && cipher_kt_mode_aead(common_cipher)) + if (session->opt->data_epoch_supported && (iv_proto_peer & IV_PROTO_DA= TA_EPOCH) && common_cipher + && cipher_kt_mode_aead(common_cipher)) { session->opt->crypto_flags |=3D CO_EPOCH_DATA_KEY_FORMAT; } @@ -458,20 +449,18 @@ uint8_t peerid[3]; if (!key_state_export_keying_material(session, EXPORT_P2P_PEER= ID_LABEL, - strlen(EXPORT_P2P_PEERID= _LABEL), - &peerid, 3)) + strlen(EXPORT_P2P_PEERID= _LABEL), &peerid, 3)) { /* Non DCO setup might still work but also this should nev= er * happen or very likely the TLS encryption key exporter w= ill * also fail */ msg(M_NONFATAL, "TLS key export for P2P peer id failed. " - "Continuing anyway, expect problems"); + "Continuing anyway, expect problems"); } else { multi->peer_id =3D (peerid[0] << 16) + (peerid[1] << 8) + = peerid[2]; } - } } if (iv_proto_peer & IV_PROTO_DYN_TLS_CRYPT) @@ -512,12 +501,11 @@ common_cipher =3D BSTR(&out); } - msg(D_TLS_DEBUG_LOW, "P2P mode NCP negotiation result: " + msg(D_TLS_DEBUG_LOW, + "P2P mode NCP negotiation result: " "TLS_export=3D%d, DATA_v2=3D%d, peer-id %d, epoch=3D%d, cipher=3D%= s", - (bool)(session->opt->crypto_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT= ), - multi->use_peer_id, - multi->peer_id, - (bool)(session->opt->crypto_flags & CO_EPOCH_DATA_KEY_FORMAT), + (bool)(session->opt->crypto_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT= ), multi->use_peer_id, + multi->peer_id, (bool)(session->opt->crypto_flags & CO_EPOCH_DATA_= KEY_FORMAT), common_cipher); gc_free(&gc); @@ -527,16 +515,15 @@ bool check_session_cipher(struct tls_session *session, struct options *options) { - bool cipher_allowed_as_fallback =3D options->enable_ncp_fallback - && streq(options->ciphername, sessio= n->opt->config_ciphername); + bool cipher_allowed_as_fallback =3D + options->enable_ncp_fallback && streq(options->ciphername, session= ->opt->config_ciphername); if (!session->opt->server && !cipher_allowed_as_fallback && !tls_item_in_cipher_list(options->ciphername, options->ncp_ciph= ers)) { struct gc_arena gc =3D gc_new(); msg(D_TLS_ERRORS, "Error: negotiated cipher not allowed - %s not i= n %s%s", - options->ciphername, options->ncp_ciphers_conf, - ncp_expanded_ciphers(options, &gc)); + options->ciphername, options->ncp_ciphers_conf, ncp_expanded_c= iphers(options, &gc)); /* undo cipher push, abort connection setup */ options->ciphername =3D session->opt->config_ciphername; gc_free(&gc); @@ -577,7 +564,7 @@ const char *after_default =3D def + strlen(search); buf_write(&ncp_ciphers_buf, after_default, strlen(after_default)); - o->ncp_ciphers =3D (char *) ncp_ciphers; + o->ncp_ciphers =3D (char *)ncp_ciphers; } /** @@ -588,8 +575,8 @@ void options_postprocess_setdefault_ncpciphers(struct options *o) { - bool default_in_cipher_list =3D o->ncp_ciphers - && tls_item_in_cipher_list("DEFAULT", o-= >ncp_ciphers); + bool default_in_cipher_list =3D + o->ncp_ciphers && tls_item_in_cipher_list("DEFAULT", o->ncp_cipher= s); /* preserve the values that the user put into the configuration */ o->ncp_ciphers_conf =3D o->ncp_ciphers; diff --git a/src/openvpn/ssl_ncp.h b/src/openvpn/ssl_ncp.h index 6159264..51cd4f2 100644 --- a/src/openvpn/ssl_ncp.h +++ b/src/openvpn/ssl_ncp.h @@ -39,8 +39,7 @@ * Returns whether the client supports NCP either by * announcing IV_NCP>=3D2 or the IV_CIPHERS list */ -bool -tls_peer_supports_ncp(const char *peer_info); +bool tls_peer_supports_ncp(const char *peer_info); /* forward declaration to break include dependency loop */ struct context; @@ -51,8 +50,7 @@ * * @return Wether the client NCP process suceeded or failed */ -bool -check_pull_client_ncp(struct context *c, int found); +bool check_pull_client_ncp(struct context *c, int found); =20 /** * Iterates through the ciphers in server_list and return the first @@ -74,9 +72,8 @@ * @returns NULL if no common cipher is available, otherwise the best comm= on * cipher */ -char * -ncp_get_best_cipher(const char *server_list, const char *peer_info, - const char *remote_cipher, struct gc_arena *gc); +char *ncp_get_best_cipher(const char *server_list, const char *peer_info, = const char *remote_cipher, + struct gc_arena *gc); /** @@ -87,8 +84,7 @@ * or allocated via gc. If no information is available an empty string * ("") is returned. */ -const char * -tls_peer_ncp_list(const char *peer_info, struct gc_arena *gc); +const char *tls_peer_ncp_list(const char *peer_info, struct gc_arena *gc); /** * Check whether the ciphers in the supplied list are supported. @@ -103,8 +99,7 @@ * is short than MAX_NCP_CIPHERS_LENGTH. NULL * otherwise. */ -char * -mutate_ncp_cipher_list(const char *list, struct gc_arena *gc); +char *mutate_ncp_cipher_list(const char *list, struct gc_arena *gc); /** * Appends the cipher specified by the ciphernamer parameter to to @@ -148,17 +143,15 @@ * @param gc gc arena that will be used to allocate the returne= d cipher * @return common cipher if one exist. */ -const char * -get_p2p_ncp_cipher(struct tls_session *session, const char *peer_info, - struct gc_arena *gc); +const char *get_p2p_ncp_cipher(struct tls_session *session, const char *pe= er_info, + struct gc_arena *gc); /** * Checks if the cipher is allowed, otherwise returns false and reset the * cipher to the config cipher. */ -bool -check_session_cipher(struct tls_session *session, struct options *options); +bool check_session_cipher(struct tls_session *session, struct options *opt= ions); /** * Checks for availability of Chacha20-Poly1305 and sets @@ -168,8 +161,7 @@ * If DEFAULT is in the ncp_cipher string, it will be replaced * by the default cipher string as defined above. */ -void -options_postprocess_setdefault_ncpciphers(struct options *o); +void options_postprocess_setdefault_ncpciphers(struct options *o); /** returns the o->ncp_ciphers in brackets, e.g. * (AES-256-GCM:CHACHA20-POLY1305) if o->ncp_ciphers_conf @@ -177,6 +169,5 @@ * * The returned string will be allocated in the passed \c gc */ -const char * -ncp_expanded_ciphers(struct options *o, struct gc_arena *gc); +const char *ncp_expanded_ciphers(struct options *o, struct gc_arena *gc); #endif /* ifndef OPENVPN_SSL_NCP_H */ diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 4c11cd4..2fe4b75 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -114,7 +114,7 @@ if (ERR_peek_error() !=3D 0) { crypto_msg(M_WARN, "Warning: TLS server context initialisation " - "has warnings."); + "has warnings."); } } @@ -132,7 +132,7 @@ if (ERR_peek_error() !=3D 0) { crypto_msg(M_WARN, "Warning: TLS client context initialisation " - "has warnings."); + "has warnings."); } } @@ -153,15 +153,13 @@ } bool -key_state_export_keying_material(struct tls_session *session, - const char *label, size_t label_size, +key_state_export_keying_material(struct tls_session *session, const char *= label, size_t label_size, void *ekm, size_t ekm_size) { SSL *ssl =3D session->key[KS_PRIMARY].ks_ssl.ssl; - if (SSL_export_keying_material(ssl, ekm, ekm_size, label, - label_size, NULL, 0, 0) =3D=3D 1) + if (SSL_export_keying_material(ssl, ekm, ekm_size, label, label_size, = NULL, 0, 0) =3D=3D 1) { return true; } @@ -185,16 +183,15 @@ if (where & SSL_CB_LOOP) { dmsg(D_HANDSHAKE_VERBOSE, "SSL state (%s): %s", - where & SSL_ST_CONNECT ? "connect" : - where &SSL_ST_ACCEPT ? "accept" : - "undefined", SSL_state_string_long(s)); + where & SSL_ST_CONNECT ? "connect" + : where & SSL_ST_ACCEPT ? "accept" + : "undefined", + SSL_state_string_long(s)); } else if (where & SSL_CB_ALERT) { - dmsg(D_TLS_DEBUG_LOW, "%s %s SSL alert: %s", - where & SSL_CB_READ ? "Received" : "Sent", - SSL_alert_type_string_long(ret), - SSL_alert_desc_string_long(ret)); + dmsg(D_TLS_DEBUG_LOW, "%s %s SSL alert: %s", where & SSL_CB_READ ?= "Received" : "Sent", + SSL_alert_type_string_long(ret), SSL_alert_desc_string_long(r= et)); } } @@ -233,7 +230,7 @@ return TLS_VER_1_2; #elif defined(TLS1_1_VERSION) || defined(SSL_OP_NO_TLSv1_1) return TLS_VER_1_1; -#else /* if defined(TLS1_3_VERSION) */ +#else /* if defined(TLS1_3_VERSION) */ return TLS_VER_1_0; #endif } @@ -279,10 +276,10 @@ static bool tls_ctx_set_tls_versions(struct tls_root_ctx *ctx, unsigned int ssl_flags) { - int tls_ver_min =3D openssl_tls_version( - (ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERSION_MIN_M= ASK); - int tls_ver_max =3D openssl_tls_version( - (ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_M= ASK); + int tls_ver_min =3D + openssl_tls_version((ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SS= LF_TLS_VERSION_MIN_MASK); + int tls_ver_max =3D + openssl_tls_version((ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SS= LF_TLS_VERSION_MAX_MASK); if (!tls_ver_min) { @@ -373,7 +370,8 @@ for (; begin_of_cipher < strlen(ciphers); begin_of_cipher =3D end_of_c= ipher) { end_of_cipher +=3D strcspn(&ciphers[begin_of_cipher], ":"); - cipher_pair =3D tls_get_cipher_name_pair(&ciphers[begin_of_cipher]= , end_of_cipher - begin_of_cipher); + cipher_pair =3D + tls_get_cipher_name_pair(&ciphers[begin_of_cipher], end_of_cip= her - begin_of_cipher); if (NULL =3D=3D cipher_pair) { @@ -394,11 +392,13 @@ current_cipher_len =3D strlen(current_cipher); if (end_of_cipher - begin_of_cipher =3D=3D current_cipher_len - && 0 !=3D memcmp(&ciphers[begin_of_cipher], cipher_pair->i= ana_name, - end_of_cipher - begin_of_cipher)) + && 0 + !=3D memcmp(&ciphers[begin_of_cipher], cipher_pair-= >iana_name, + end_of_cipher - begin_of_cipher)) { /* Non-IANA name used, show warning */ - msg(M_WARN, "Deprecated TLS cipher name '%s', please use I= ANA name '%s'", cipher_pair->openssl_name, cipher_pair->iana_name); + msg(M_WARN, "Deprecated TLS cipher name '%s', please use I= ANA name '%s'", + cipher_pair->openssl_name, cipher_pair->iana_name); } } @@ -406,8 +406,7 @@ if ((SIZE_MAX - openssl_ciphers_len) < current_cipher_len || (len - 1) < (openssl_ciphers_len + current_cipher_len)) { - msg(M_FATAL, - "Failed to set restricted TLS cipher list, too long (>%d).= ", + msg(M_FATAL, "Failed to set restricted TLS cipher list, too lo= ng (>%d).", (int)(len - 1)); } @@ -422,7 +421,7 @@ if (openssl_ciphers_len > 0) { - openssl_ciphers[openssl_ciphers_len-1] =3D '\0'; + openssl_ciphers[openssl_ciphers_len - 1] =3D '\0'; } } @@ -432,17 +431,18 @@ if (ciphers =3D=3D NULL) { /* Use sane default TLS cipher list */ - if (!SSL_CTX_set_cipher_list(ctx->ctx, - /* Use openssl's default list as a ba= sis */ - "DEFAULT" - /* Disable export ciphers and openssl= 's 'low' and 'medium' ciphers */ - ":!EXP:!LOW:!MEDIUM" - /* Disable static (EC)DH keys (no for= ward secrecy) */ - ":!kDH:!kECDH" - /* Disable DSA private keys */ - ":!DSS" - /* Disable unsupported TLS modes */ - ":!PSK:!SRP:!kRSA")) + if (!SSL_CTX_set_cipher_list( + ctx->ctx, + /* Use openssl's default list as a basis */ + "DEFAULT" + /* Disable export ciphers and openssl's 'low' and 'medium'= ciphers */ + ":!EXP:!LOW:!MEDIUM" + /* Disable static (EC)DH keys (no forward secrecy) */ + ":!kDH:!kECDH" + /* Disable DSA private keys */ + ":!DSS" + /* Disable unsupported TLS modes */ + ":!PSK:!SRP:!kRSA")) { crypto_msg(M_FATAL, "Failed to set default TLS cipher list."); } @@ -462,8 +462,7 @@ } static void -convert_tls13_list_to_openssl(char *openssl_ciphers, size_t len, - const char *ciphers) +convert_tls13_list_to_openssl(char *openssl_ciphers, size_t len, const cha= r *ciphers) { /* * OpenSSL (and official IANA) cipher names have _ in them. We @@ -472,9 +471,8 @@ */ if (strlen(ciphers) >=3D (len - 1)) { - msg(M_FATAL, - "Failed to set restricted TLS 1.3 cipher list, too long (>%d).= ", - (int) (len - 1)); + msg(M_FATAL, "Failed to set restricted TLS 1.3 cipher list, too lo= ng (>%d).", + (int)(len - 1)); } strncpy(openssl_ciphers, ciphers, len); @@ -499,20 +497,19 @@ } #if !defined(TLS1_3_VERSION) - crypto_msg(M_WARN, "Not compiled with OpenSSL 1.1.1 or higher. " + crypto_msg(M_WARN, + "Not compiled with OpenSSL 1.1.1 or higher. " "Ignoring TLS 1.3 only tls-ciphersuites '%s' setting.", ciphers); #else ASSERT(NULL !=3D ctx); char openssl_ciphers[4096]; - convert_tls13_list_to_openssl(openssl_ciphers, sizeof(openssl_ciphers), - ciphers); + convert_tls13_list_to_openssl(openssl_ciphers, sizeof(openssl_ciphers)= , ciphers); if (!SSL_CTX_set_ciphersuites(ctx->ctx, openssl_ciphers)) { - crypto_msg(M_FATAL, "Failed to set restricted TLS 1.3 cipher list:= %s", - openssl_ciphers); + crypto_msg(M_FATAL, "Failed to set restricted TLS 1.3 cipher list:= %s", openssl_ciphers); } #endif } @@ -521,7 +518,7 @@ tls_ctx_set_cert_profile(struct tls_root_ctx *ctx, const char *profile) { #if OPENSSL_VERSION_NUMBER > 0x10100000L \ - && (!defined(LIBRESSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x= 3060000fL) + && (!defined(LIBRESSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3= 060000fL) /* OpenSSL does not have certificate profiles, but a complex set of * callbacks that we could try to implement to achieve something simil= ar. * For now, use OpenSSL's security levels to achieve similar (but not = equal) @@ -550,8 +547,10 @@ #else /* if OPENSSL_VERSION_NUMBER > 0x10100000L */ if (profile) { - msg(M_WARN, "WARNING: OpenSSL 1.1.0 and LibreSSL do not support " - "--tls-cert-profile, ignoring user-set profile: '%s'", profile= ); + msg(M_WARN, + "WARNING: OpenSSL 1.1.0 and LibreSSL do not support " + "--tls-cert-profile, ignoring user-set profile: '%s'", + profile); } #endif /* if OPENSSL_VERSION_NUMBER > 0x10100000L */ } @@ -603,15 +602,13 @@ if (!SSL_CTX_set1_groups(ctx->ctx, glist, glistlen)) { - crypto_msg(M_FATAL, "Failed to set allowed TLS group list: %s", - groups); + crypto_msg(M_FATAL, "Failed to set allowed TLS group list: %s", gr= oups); } gc_free(&gc); #else /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ if (!SSL_CTX_set1_groups_list(ctx->ctx, groups)) { - crypto_msg(M_FATAL, "Failed to set allowed TLS group list: %s", - groups); + crypto_msg(M_FATAL, "Failed to set allowed TLS group list: %s", gr= oups); } #endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } @@ -653,8 +650,7 @@ } void -tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, - bool dh_file_inline) +tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, bool= dh_file_inline) { BIO *bio; @@ -690,8 +686,7 @@ crypto_msg(M_FATAL, "SSL_CTX_set0_tmp_dh_pkey"); } - msg(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with %d bit key", - 8 * EVP_PKEY_get_size(dh)); + msg(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with %d bit key", 8 *= EVP_PKEY_get_size(dh)); #else /* if OPENSSL_VERSION_NUMBER >=3D 0x30000000L */ DH *dh =3D PEM_read_bio_DHparams(bio, NULL, NULL, NULL); BIO_free(bio); @@ -706,8 +701,7 @@ crypto_msg(M_FATAL, "SSL_CTX_set_tmp_dh"); } - msg(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with %d bit key", - 8 * DH_size(dh)); + msg(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with %d bit key", 8 *= DH_size(dh)); DH_free(dh); #endif /* if OPENSSL_VERSION_NUMBER >=3D 0x30000000L */ @@ -720,8 +714,8 @@ if (curve_name !=3D NULL) { msg(M_WARN, "WARNING: OpenSSL 3.0+ builds do not support specifyin= g an " - "ECDH curve with --ecdh-curve, using default curves. Use " - "--tls-groups to specify groups."); + "ECDH curve with --ecdh-curve, using default curves. U= se " + "--tls-groups to specify groups."); } #elif !defined(OPENSSL_NO_EC) int nid =3D NID_undef; @@ -754,10 +748,9 @@ { /* Creating key failed, fall back on sane default */ ecdh =3D EC_KEY_new_by_curve_name(NID_secp384r1); - const char *source =3D (NULL =3D=3D curve_name) ? - "extract curve from certificate" : "use suppl= ied curve"; - msg(D_TLS_DEBUG_LOW, - "Failed to %s (%s), using secp384r1 instead.", source, sname); + const char *source =3D + (NULL =3D=3D curve_name) ? "extract curve from certificate" : = "use supplied curve"; + msg(D_TLS_DEBUG_LOW, "Failed to %s (%s), using secp384r1 instead."= , source, sname); sname =3D OBJ_nid2sn(NID_secp384r1); } @@ -771,7 +764,7 @@ EC_KEY_free(ecdh); #else /* ifndef OPENSSL_NO_EC */ msg(D_LOW, "Your OpenSSL library was built without elliptic curve supp= ort." - " Skipping ECDH parameter loading."); + " Skipping ECDH parameter loading."); #endif /* OPENSSL_NO_EC */ } @@ -795,7 +788,8 @@ { struct user_pass up; CLEAR(up); - get_user_pass(&up, NULL, "PKCS#11 token", GET_USER_PASS_MANAGE= MENT|GET_USER_PASS_PASSWORD_ONLY); + get_user_pass(&up, NULL, "PKCS#11 token", + GET_USER_PASS_MANAGEMENT | GET_USER_PASS_PASSWOR= D_ONLY); UI_set_result(ui, uis, up.password); purge_user_pass(&up, true); } @@ -846,12 +840,11 @@ { return NULL; } - pkey =3D PEM_read_bio_PrivateKey(in, NULL, - SSL_CTX_get_default_passwd_cb(ssl_ctx), + pkey =3D PEM_read_bio_PrivateKey(in, NULL, SSL_CTX_get_default_passwd_= cb(ssl_ctx), SSL_CTX_get_default_passwd_cb_userdata(= ssl_ctx)); BIO_free(in); -#else /* defined(HAVE_OPENSSL_STORE_API) */ +#else /* defined(HAVE_OPENSSL_STORE_API) */ OSSL_STORE_CTX *store_ctx =3D NULL; OSSL_STORE_INFO *info =3D NULL; @@ -864,8 +857,7 @@ } UI_method_set_reader(ui_method, ui_reader); - store_ctx =3D OSSL_STORE_open_ex(uri, tls_libctx, NULL, ui_method, ssl= _ctx, - NULL, NULL, NULL); + store_ctx =3D OSSL_STORE_open_ex(uri, tls_libctx, NULL, ui_method, ssl= _ctx, NULL, NULL, NULL); if (!store_ctx) { goto end; @@ -905,8 +897,8 @@ } int -tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, - bool pkcs12_file_inline, bool load_ca_file) +tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, boo= l pkcs12_file_inline, + bool load_ca_file) { FILE *fp; EVP_PKEY *pkey; @@ -921,8 +913,7 @@ if (pkcs12_file_inline) { BIO *b64 =3D BIO_new(BIO_f_base64()); - BIO *bio =3D BIO_new_mem_buf((void *) pkcs12_file, - (int) strlen(pkcs12_file)); + BIO *bio =3D BIO_new_mem_buf((void *)pkcs12_file, (int)strlen(pkcs= 12_file)); ASSERT(b64 && bio); BIO_push(b64, bio); p12 =3D d2i_PKCS12_bio(b64, NULL); @@ -957,7 +948,7 @@ if (!PKCS12_parse(p12, password, &pkey, &cert, &ca)) { crypto_msg(M_WARN, "Decoding PKCS12 failed. Probably wrong pas= sword " - "or unsupported/legacy encryption"); + "or unsupported/legacy encryption"); #ifdef ENABLE_MANAGEMENT if (management && (ERR_GET_REASON(ERR_peek_error()) =3D=3D PKC= S12_R_MAC_VERIFY_FAILURE)) { @@ -1003,11 +994,13 @@ X509_STORE *cert_store =3D SSL_CTX_get_cert_store(ctx->ctx= ); if (!X509_STORE_add_cert(cert_store, sk_X509_value(ca, i))) { - crypto_msg(M_FATAL, "Cannot add certificate to certifi= cate chain (X509_STORE_add_cert)"); + crypto_msg(M_FATAL, + "Cannot add certificate to certificate chai= n (X509_STORE_add_cert)"); } if (!SSL_CTX_add_client_CA(ctx->ctx, sk_X509_value(ca, i))) { - crypto_msg(M_FATAL, "Cannot add certificate to client = CA list (SSL_CTX_add_client_CA)"); + crypto_msg(M_FATAL, + "Cannot add certificate to client CA list (= SSL_CTX_add_client_CA)"); } } } @@ -1025,7 +1018,9 @@ { if (!SSL_CTX_add_extra_chain_cert(ctx->ctx, sk_X509_value(= ca, i))) { - crypto_msg(M_FATAL, "Cannot add extra certificate to c= hain (SSL_CTX_add_extra_chain_cert)"); + crypto_msg( + M_FATAL, + "Cannot add extra certificate to chain (SSL_CTX_ad= d_extra_chain_cert)"); } } } @@ -1042,7 +1037,8 @@ /* Load Certificate and Private Key */ if (!SSL_CTX_use_CryptoAPI_certificate(ctx->ctx, cryptoapi_cert)) { - crypto_msg(M_FATAL, "Cannot load certificate \"%s\" from Microsoft= Certificate Store", cryptoapi_cert); + crypto_msg(M_FATAL, "Cannot load certificate \"%s\" from Microsoft= Certificate Store", + cryptoapi_cert); } } #endif /* ENABLE_CRYPTOAPI */ @@ -1060,8 +1056,7 @@ * is found in the buffer. If loading more certificates is * optional, break without raising an error */ - if (optional - && ERR_GET_REASON(ERR_peek_error()) =3D=3D PEM_R_NO_START_= LINE) + if (optional && ERR_GET_REASON(ERR_peek_error()) =3D=3D PEM_R_= NO_START_LINE) { /* remove that error from error stack */ (void)ERR_get_error(); @@ -1110,8 +1105,8 @@ } UI_method_set_reader(ui_method, ui_reader); - store_ctx =3D OSSL_STORE_open_ex(uri, tls_libctx, NULL, ui_method, tls= _ctx->ctx, - NULL, NULL, NULL); + store_ctx =3D + OSSL_STORE_open_ex(uri, tls_libctx, NULL, ui_method, tls_ctx->ctx,= NULL, NULL, NULL); if (!store_ctx) { goto end; @@ -1188,14 +1183,13 @@ UI_destroy_method(ui_method); OSSL_STORE_INFO_free(info); OSSL_STORE_close(store_ctx); -#else /* defined(HAVE_OPENSSL_STORE_API */ +#else /* defined(HAVE_OPENSSL_STORE_API */ ASSERT(0); #endif /* defined(HAVE_OPENSSL_STORE_API */ } static void -tls_ctx_load_cert_pem_file(struct tls_root_ctx *ctx, const char *cert_file, - bool cert_file_inline) +tls_ctx_load_cert_pem_file(struct tls_root_ctx *ctx, const char *cert_file= , bool cert_file_inline) { BIO *in =3D NULL; X509 *x =3D NULL; @@ -1205,11 +1199,11 @@ if (cert_file_inline) { - in =3D BIO_new_mem_buf((char *) cert_file, -1); + in =3D BIO_new_mem_buf((char *)cert_file, -1); } else { - in =3D BIO_new_file((char *) cert_file, "r"); + in =3D BIO_new_file((char *)cert_file, "r"); } if (in =3D=3D NULL) @@ -1218,8 +1212,7 @@ goto end; } - x =3D PEM_read_bio_X509(in, NULL, - SSL_CTX_get_default_passwd_cb(ctx->ctx), + x =3D PEM_read_bio_X509(in, NULL, SSL_CTX_get_default_passwd_cb(ctx->c= tx), SSL_CTX_get_default_passwd_cb_userdata(ctx->ctx)= ); if (x =3D=3D NULL) { @@ -1256,8 +1249,7 @@ } void -tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file, - bool cert_file_inline) +tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file, bo= ol cert_file_inline) { if (cert_uri_supported() && !cert_file_inline) { @@ -1284,13 +1276,12 @@ if (priv_key_file_inline) { - in =3D BIO_new_mem_buf((char *) priv_key_file, -1); + in =3D BIO_new_mem_buf((char *)priv_key_file, -1); if (in =3D=3D NULL) { goto end; } - pkey =3D PEM_read_bio_PrivateKey(in, NULL, - SSL_CTX_get_default_passwd_cb(ctx->= ctx), + pkey =3D PEM_read_bio_PrivateKey(in, NULL, SSL_CTX_get_default_pas= swd_cb(ctx->ctx), SSL_CTX_get_default_passwd_cb_userd= ata(ctx->ctx)); } else @@ -1325,8 +1316,7 @@ } void -backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_f= ile, - bool crl_inline) +backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_f= ile, bool crl_inline) { BIO *in =3D NULL; @@ -1355,7 +1345,7 @@ if (crl_inline) { - in =3D BIO_new_mem_buf((char *) crl_file, -1); + in =3D BIO_new_mem_buf((char *)crl_file, -1); } else { @@ -1364,8 +1354,7 @@ if (in =3D=3D NULL) { - msg(M_WARN, "CRL: cannot read: %s", - print_key_filename(crl_file, crl_inline)); + msg(M_WARN, "CRL: cannot read: %s", print_key_filename(crl_file, c= rl_inline)); goto end; } @@ -1478,9 +1467,8 @@ * @return signature length or -1 on error. */ static int -get_sig_from_man(const unsigned char *dgst, unsigned int dgstlen, - unsigned char *sig, unsigned int siglen, - const char *algorithm) +get_sig_from_man(const unsigned char *dgst, unsigned int dgstlen, unsigned= char *sig, + unsigned int siglen, const char *algorithm) { char *in_b64 =3D NULL; char *out_b64 =3D NULL; @@ -1491,7 +1479,6 @@ if (management && bencret > 0) { out_b64 =3D management_query_pk_sig(management, in_b64, algorithm); - } if (out_b64) { @@ -1505,8 +1492,7 @@ /* sign arbitrary data */ static int -rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *= rsa, - int padding) +rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to, RSA *= rsa, int padding) { unsigned int len =3D RSA_size(rsa); int ret =3D -1; @@ -1534,8 +1520,7 @@ ASSERT(NULL !=3D pub_rsa); /* allocate custom RSA method object */ - rsa_meth =3D RSA_meth_new("OpenVPN external private key RSA Method", - RSA_METHOD_FLAG_NO_CHECK); + rsa_meth =3D RSA_meth_new("OpenVPN external private key RSA Method", R= SA_METHOD_FLAG_NO_CHECK); check_malloc_return(rsa_meth); RSA_meth_set_pub_enc(rsa_meth, rsa_pub_enc); RSA_meth_set_pub_dec(rsa_meth, rsa_pub_dec); @@ -1595,7 +1580,7 @@ { /* release the method structure */ const EC_KEY_METHOD *ec_meth =3D EC_KEY_get_method(ec); - EC_KEY_METHOD_free((EC_KEY_METHOD *) ec_meth); + EC_KEY_METHOD_free((EC_KEY_METHOD *)ec_meth); } /* EC_KEY_METHOD callback: sign(). @@ -1634,8 +1619,8 @@ * struct or NULL on error. */ static ECDSA_SIG * -ecdsa_sign_sig(const unsigned char *dgst, int dgstlen, const BIGNUM *in_ki= nv, - const BIGNUM *in_r, EC_KEY *ec) +ecdsa_sign_sig(const unsigned char *dgst, int dgstlen, const BIGNUM *in_ki= nv, const BIGNUM *in_r, + EC_KEY *ec) { ECDSA_SIG *ecsig =3D NULL; unsigned int len =3D ECDSA_size(ec); @@ -1733,8 +1718,7 @@ #ifdef HAVE_XKEY_PROVIDER EVP_PKEY *privkey =3D xkey_load_management_key(tls_libctx, pkey); - if (!privkey - || !SSL_CTX_use_PrivateKey(ctx->ctx, privkey)) + if (!privkey || !SSL_CTX_use_PrivateKey(ctx->ctx, privkey)) { EVP_PKEY_free(privkey); goto cleanup; @@ -1743,7 +1727,7 @@ #else /* ifdef HAVE_XKEY_PROVIDER */ #if OPENSSL_VERSION_NUMBER < 0x30000000L if (EVP_PKEY_id(pkey) =3D=3D EVP_PKEY_RSA) -#else /* OPENSSL_VERSION_NUMBER < 0x30000000L */ +#else /* OPENSSL_VERSION_NUMBER < 0x30000000L */ if (EVP_PKEY_is_a(pkey, "RSA")) #endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ { @@ -1755,7 +1739,7 @@ #if !defined(OPENSSL_NO_EC) #if OPENSSL_VERSION_NUMBER < 0x30000000L else if (EVP_PKEY_id(pkey) =3D=3D EVP_PKEY_EC) -#else /* OPENSSL_VERSION_NUMBER < 0x30000000L */ +#else /* OPENSSL_VERSION_NUMBER < 0x30000000L */ else if (EVP_PKEY_is_a(pkey, "EC")) #endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ { @@ -1797,8 +1781,8 @@ } void -tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, - bool ca_file_inline, const char *ca_path, bool tls_server) +tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, bool ca_fil= e_inline, + const char *ca_path, bool tls_server) { STACK_OF(X509_INFO) *info_stack =3D NULL; STACK_OF(X509_NAME) *cert_names =3D NULL; @@ -1893,8 +1877,7 @@ { crypto_msg(M_WARN, "Cannot load CA certificate file %s (en= try %d did not validate)", - print_key_filename(ca_file, ca_file_inl= ine), - added); + print_key_filename(ca_file, ca_file_inl= ine), added); } prev =3D cnum; } @@ -1910,8 +1893,7 @@ if (!added) { - crypto_msg(M_FATAL, - "Cannot load CA certificate file %s (no entries wer= e read)", + crypto_msg(M_FATAL, "Cannot load CA certificate file %s (no en= tries were read)", print_key_filename(ca_file, ca_file_inline)); } @@ -1919,10 +1901,10 @@ { if (cnum !=3D added) { - crypto_msg(M_FATAL, "Cannot load CA certificate file %s (o= nly %d " + crypto_msg(M_FATAL, + "Cannot load CA certificate file %s (only %d " "of %d entries were valid X509 names)", - print_key_filename(ca_file, ca_file_inline), cn= um, - added); + print_key_filename(ca_file, ca_file_inline), cn= um, added); } } @@ -1962,9 +1944,7 @@ if (in =3D=3D NULL) { crypto_msg(M_FATAL, "Cannot load extra-certs file: %s", - print_key_filename(extra_certs_file, - extra_certs_file_inline)); - + print_key_filename(extra_certs_file, extra_certs_file_i= nline)); } else { @@ -1989,10 +1969,10 @@ #warning BIO_DEBUG defined -static FILE *biofp; /* GLOBAL */ -static bool biofp_toggle; /* GLOBAL */ -static time_t biofp_last_open; /* GLOBAL */ -static const int biofp_reopen_interval =3D 600; /* GLOBAL */ +static FILE *biofp; /* GLOBAL */ +static bool biofp_toggle; /* GLOBAL */ +static time_t biofp_last_open; /* GLOBAL */ +static const int biofp_reopen_interval =3D 600; /* GLOBAL */ static void close_biofp(void) @@ -2032,8 +2012,8 @@ if (len > 0) { open_biofp(); - fprintf(biofp, "BIO_%s %s time=3D%" PRIi64 " bio=3D" ptr_format " = len=3D%d data=3D%s\n", - mode, desc, (int64_t)time(NULL), (ptr_type)bio, len, forma= t_hex(buf, len, 0, &gc)); + fprintf(biofp, "BIO_%s %s time=3D%" PRIi64 " bio=3D" ptr_format " = len=3D%d data=3D%s\n", mode, desc, + (int64_t)time(NULL), (ptr_type)bio, len, format_hex(buf, l= en, 0, &gc)); fflush(biofp); } gc_free(&gc); @@ -2043,8 +2023,8 @@ bio_debug_oc(const char *mode, BIO *bio) { open_biofp(); - fprintf(biofp, "BIO %s time=3D%" PRIi64 " bio=3D" ptr_format "\n", - mode, (int64_t)time(NULL), (ptr_type)bio); + fprintf(biofp, "BIO %s time=3D%" PRIi64 " bio=3D" ptr_format "\n", mod= e, (int64_t)time(NULL), + (ptr_type)bio); fflush(biofp); } @@ -2083,13 +2063,12 @@ } else if (i !=3D size) { - crypto_msg(D_TLS_ERRORS, "TLS ERROR: BIO write %s incomplete %= d/%d", - desc, i, size); + crypto_msg(D_TLS_ERRORS, "TLS ERROR: BIO write %s incomplete %= d/%d", desc, i, size); ret =3D -1; ERR_clear_error(); } else - { /* successful write */ + { /* successful write */ dmsg(D_HANDSHAKE_VERBOSE, "BIO write %s %d bytes", desc, i); ret =3D 1; } @@ -2105,9 +2084,9 @@ static void bio_write_post(const int status, struct buffer *buf) { - if (status =3D=3D 1) /* success status return from bio_write? */ + if (status =3D=3D 1) /* success status return from= bio_write? */ { - memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */ + memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */ buf->len =3D 0; } } @@ -2133,7 +2112,7 @@ */ int i =3D BIO_read(bio, BPTR(buf), len); - VALGRIND_MAKE_READABLE((void *) &i, sizeof(i)); + VALGRIND_MAKE_READABLE((void *)&i, sizeof(i)); #ifdef BIO_DEBUG bio_debug_data("read", bio, BPTR(buf), i, desc); @@ -2155,17 +2134,18 @@ buf->len =3D 0; } else - { /* successful read */ + { /* successful read */ dmsg(D_HANDSHAKE_VERBOSE, "BIO read %s %d bytes", desc, i); buf->len =3D i; ret =3D 1; - VALGRIND_MAKE_READABLE((void *) BPTR(buf), BLEN(buf)); + VALGRIND_MAKE_READABLE((void *)BPTR(buf), BLEN(buf)); } return ret; } void -key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_root_ctx= *ssl_ctx, bool is_server, struct tls_session *session) +key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_root_ctx= *ssl_ctx, bool is_server, + struct tls_session *session) { ASSERT(NULL !=3D ssl_ctx); ASSERT(ks_ssl); @@ -2233,8 +2213,7 @@ ASSERT(NULL !=3D ks_ssl); - ret =3D bio_write(ks_ssl->ssl_bio, BPTR(buf), BLEN(buf), - "tls_write_plaintext"); + ret =3D bio_write(ks_ssl->ssl_bio, BPTR(buf), BLEN(buf), "tls_write_pl= aintext"); bio_write_post(ret, buf); perf_pop(); @@ -2338,7 +2317,7 @@ type =3D OBJ_nid2sn(typeid); /* OpenSSL reports rsaEncryption, dsaEncryption and - * id-ecPublicKey, map these values to nicer ones */ + * id-ecPublicKey, map these values to nicer ones */ if (typeid =3D=3D EVP_PKEY_RSA) { type =3D "RSA"; @@ -2356,7 +2335,7 @@ { type =3D "unknown type"; } -#else /* OpenSSL >=3D 3 */ +#else /* OpenSSL >=3D 3 */ type =3D EVP_PKEY_get0_type_name(pkey); if (type =3D=3D NULL) { @@ -2365,8 +2344,7 @@ #endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */ } - snprintf(buf, buflen, "%d bits %s%s", - EVP_PKEY_bits(pkey), type, curve); + snprintf(buf, buflen, "%d bits %s%s", EVP_PKEY_bits(pkey), type, curve= ); } /** @@ -2386,12 +2364,10 @@ int signature_nid =3D X509_get_signature_nid(cert); if (signature_nid !=3D 0) { - snprintf(sig, sizeof(sig), ", signature: %s", - OBJ_nid2sn(signature_nid)); + snprintf(sig, sizeof(sig), ", signature: %s", OBJ_nid2sn(signature= _nid)); } - snprintf(buf, buflen, ", peer certificate: %s%s", - pkeybuf, sig); + snprintf(buf, buflen, ", peer certificate: %s%s", pkeybuf, sig); EVP_PKEY_free(pkey); } @@ -2409,8 +2385,7 @@ char pkeybuf[128] =3D { 0 }; print_pkey_details(pkey, pkeybuf, sizeof(pkeybuf)); - snprintf(buf, buflen, ", peer temporary key: %s", - pkeybuf); + snprintf(buf, buflen, ", peer temporary key: %s", pkeybuf); EVP_PKEY_free(pkey); } @@ -2472,8 +2447,7 @@ || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >=3D 0= x3090000fL) /* LibreSSL 3.7.x and 3.8.x implement this function but do not export = it * and fail linking with an unresolved symbol */ - if (SSL_get_peer_signature_type_nid(ssl, &peer_sig_type_nid) - && peer_sig_type_nid !=3D NID_undef) + if (SSL_get_peer_signature_type_nid(ssl, &peer_sig_type_nid) && peer_s= ig_type_nid !=3D NID_undef) { peer_sig_type =3D get_sigtype(peer_sig_type_nid); } @@ -2484,8 +2458,7 @@ return; } - snprintf(buf, buflen, ", peer signing digest/type: %s %s", - peer_sig, peer_sig_type); + snprintf(buf, buflen, ", peer signing digest/type: %s %s", peer_sig, p= eer_sig_type); } #if OPENSSL_VERSION_NUMBER >=3D 0x30000000L @@ -2523,11 +2496,8 @@ s1[0] =3D s2[0] =3D s3[0] =3D s4[0] =3D s5[0] =3D 0; ciph =3D SSL_get_current_cipher(ks_ssl->ssl); - snprintf(s1, sizeof(s1), "%s %s, cipher %s %s", - prefix, - SSL_get_version(ks_ssl->ssl), - SSL_CIPHER_get_version(ciph), - SSL_CIPHER_get_name(ciph)); + snprintf(s1, sizeof(s1), "%s %s, cipher %s %s", prefix, SSL_get_versio= n(ks_ssl->ssl), + SSL_CIPHER_get_version(ciph), SSL_CIPHER_get_name(ciph)); X509 *cert =3D SSL_get_peer_certificate(ks_ssl->ssl); if (cert) @@ -2545,9 +2515,7 @@ } void -show_available_tls_ciphers_list(const char *cipher_list, - const char *tls_cert_profile, - bool tls13) +show_available_tls_ciphers_list(const char *cipher_list, const char *tls_c= ert_profile, bool tls13) { struct tls_root_ctx tls_ctx; @@ -2560,8 +2528,7 @@ #if defined(TLS1_3_VERSION) if (tls13) { - SSL_CTX_set_min_proto_version(tls_ctx.ctx, - openssl_tls_version(TLS_VER_1_3)); + SSL_CTX_set_min_proto_version(tls_ctx.ctx, openssl_tls_version(TLS= _VER_1_3)); tls_ctx_restrict_ciphers_tls13(&tls_ctx, cipher_list); } else @@ -2600,8 +2567,7 @@ else if (NULL =3D=3D pair) { /* No translation found, print warning */ - printf("%s (No IANA name known to OpenVPN, use OpenSSL name.)\= n", - cipher_name); + printf("%s (No IANA name known to OpenVPN, use OpenSSL name.)\= n", cipher_name); } else { @@ -2639,7 +2605,7 @@ for (n =3D 0; n < crv_len; n++) { const char *sname; - sname =3D OBJ_nid2sn(curves[n].nid); + sname =3D OBJ_nid2sn(curves[n].nid); if (sname =3D=3D NULL) { sname =3D ""; @@ -2655,7 +2621,7 @@ free(curves); #else /* ifndef OPENSSL_NO_EC */ msg(M_WARN, "Your OpenSSL library was built without elliptic curve sup= port. " - "No curves available."); + "No curves available."); #endif /* ifndef OPENSSL_NO_EC */ } @@ -2679,7 +2645,7 @@ static int provider_unload(OSSL_PROVIDER *prov, void *unused) { - (void) unused; + (void)unused; OSSL_PROVIDER_unload(prov); return 1; } @@ -2717,7 +2683,7 @@ if (!OSSL_PROVIDER_load(tls_libctx, "ovpn.xkey")) { msg(M_NONFATAL, "ERROR: failed loading external key provider: " - "Signing with external keys will not work."); + "Signing with external keys will not work."); } } diff --git a/src/openvpn/ssl_openssl.h b/src/openvpn/ssl_openssl.h index f26b44e..48c23f3 100644 --- a/src/openvpn/ssl_openssl.h +++ b/src/openvpn/ssl_openssl.h @@ -37,17 +37,19 @@ * Structure that wraps the TLS context. Contents differ depending on the * SSL library used. */ -struct tls_root_ctx { +struct tls_root_ctx +{ SSL_CTX *ctx; time_t crl_last_mtime; off_t crl_last_size; }; -struct key_state_ssl { - SSL *ssl; /* SSL object -- new obj created for each = new key */ - BIO *ssl_bio; /* read/write plaintext from here = */ - BIO *ct_in; /* write ciphertext to here */ - BIO *ct_out; /* read ciphertext from here */ +struct key_state_ssl +{ + SSL *ssl; /* SSL object -- new obj created for each new key */ + BIO *ssl_bio; /* read/write plaintext from here */ + BIO *ct_in; /* write ciphertext to here */ + BIO *ct_out; /* read ciphertext from here */ }; /** diff --git a/src/openvpn/ssl_pkt.c b/src/openvpn/ssl_pkt.c index bfd405f..8143c88 100644 --- a/src/openvpn/ssl_pkt.c +++ b/src/openvpn/ssl_pkt.c @@ -62,8 +62,7 @@ { ASSERT(co); - const struct key_ctx *ctx =3D (incoming ? &co->key_ctx_bi.decrypt : - &co->key_ctx_bi.encrypt); + const struct key_ctx *ctx =3D (incoming ? &co->key_ctx_bi.decrypt : &c= o->key_ctx_bi.encrypt); ASSERT(ctx->hmac); { @@ -121,8 +120,7 @@ tls_wrap_control(struct tls_wrap_ctx *ctx, uint8_t header, struct buffer *= buf, struct session_id *session_id) { - if (ctx->mode =3D=3D TLS_WRAP_AUTH - || ctx->mode =3D=3D TLS_WRAP_NONE) + if (ctx->mode =3D=3D TLS_WRAP_AUTH || ctx->mode =3D=3D TLS_WRAP_NONE) { ASSERT(session_id_write_prepend(session_id, buf)); ASSERT(buf_write_prepend(buf, &header, sizeof(header))); @@ -149,8 +147,7 @@ if ((header >> P_OPCODE_SHIFT) =3D=3D P_CONTROL_HARD_RESET_CLIENT_= V3 || (header >> P_OPCODE_SHIFT) =3D=3D P_CONTROL_WKC_V1) { - if (!buf_copy(&ctx->work, - ctx->tls_crypt_v2_wkc)) + if (!buf_copy(&ctx->work, ctx->tls_crypt_v2_wkc)) { msg(D_TLS_ERRORS, "Could not append tls-crypt-v2 client ke= y"); buf->len =3D 0; @@ -165,12 +162,8 @@ } void -write_control_auth(struct tls_session *session, - struct key_state *ks, - struct buffer *buf, - struct link_socket_actual **to_link_addr, - int opcode, - int max_ack, +write_control_auth(struct tls_session *session, struct key_state *ks, stru= ct buffer *buf, + struct link_socket_actual **to_link_addr, int opcode, i= nt max_ack, bool prepend_ack) { uint8_t header =3D ks->key_id | (opcode << P_OPCODE_SHIFT); @@ -185,34 +178,30 @@ } ASSERT(link_socket_actual_defined(&ks->remote_addr)); - ASSERT(reliable_ack_write - (ks->rec_ack, ks->lru_acks, buf, &ks->session_id_remote, - max_ack, prepend_ack)); + ASSERT(reliable_ack_write(ks->rec_ack, ks->lru_acks, buf, &ks->session= _id_remote, max_ack, + prepend_ack)); msg(D_TLS_DEBUG, "%s(): %s", __func__, packet_opcode_name(opcode)); - tls_wrap_control(tls_session_get_tls_wrap(session, ks->key_id), header= , buf, &session->session_id); + tls_wrap_control(tls_session_get_tls_wrap(session, ks->key_id), header= , buf, + &session->session_id); *to_link_addr =3D &ks->remote_addr; } bool -read_control_auth(struct buffer *buf, - struct tls_wrap_ctx *ctx, - const struct link_socket_actual *from, - const struct tls_options *opt, +read_control_auth(struct buffer *buf, struct tls_wrap_ctx *ctx, + const struct link_socket_actual *from, const struct tls_= options *opt, bool initial_packet) { struct gc_arena gc =3D gc_new(); bool ret =3D false; const uint8_t opcode =3D *(BPTR(buf)) >> P_OPCODE_SHIFT; - if ((opcode =3D=3D P_CONTROL_HARD_RESET_CLIENT_V3 - || opcode =3D=3D P_CONTROL_WKC_V1) + if ((opcode =3D=3D P_CONTROL_HARD_RESET_CLIENT_V3 || opcode =3D=3D P_C= ONTROL_WKC_V1) && !tls_crypt_v2_extract_client_key(buf, ctx, opt, initial_packet)) { - msg(D_TLS_ERRORS, - "TLS Error: can not extract tls-crypt-v2 client key from %s", + msg(D_TLS_ERRORS, "TLS Error: can not extract tls-crypt-v2 client = key from %s", print_link_socket_actual(from, &gc)); goto cleanup; } @@ -224,8 +213,7 @@ /* move the hmac record to the front of the packet */ if (!swap_hmac(buf, &ctx->opt, true)) { - msg(D_TLS_ERRORS, - "TLS Error: cannot locate HMAC in incoming packet from %s", + msg(D_TLS_ERRORS, "TLS Error: cannot locate HMAC in incoming p= acket from %s", print_link_socket_actual(from, &gc)); gc_free(&gc); return false; @@ -236,12 +224,10 @@ openvpn_decrypt(buf, null, &ctx->opt, NULL, BPTR(buf)); if (!buf->len) { - msg(D_TLS_ERRORS, - "TLS Error: incoming packet authentication failed from %s", + msg(D_TLS_ERRORS, "TLS Error: incoming packet authentication f= ailed from %s", print_link_socket_actual(from, &gc)); goto cleanup; } - } else if (ctx->mode =3D=3D TLS_WRAP_CRYPT) { @@ -305,17 +291,14 @@ * on the UDP port listener in --mode server mode. */ enum first_packet_verdict -tls_pre_decrypt_lite(const struct tls_auth_standalone *tas, - struct tls_pre_decrypt_state *state, - const struct link_socket_actual *from, - const struct buffer *buf) +tls_pre_decrypt_lite(const struct tls_auth_standalone *tas, struct tls_pre= _decrypt_state *state, + const struct link_socket_actual *from, const struct b= uffer *buf) { struct gc_arena gc =3D gc_new(); /* A packet needs to have at least an opcode and session id */ if (buf->len < (1 + SID_SIZE)) { - dmsg(D_TLS_STATE_ERRORS, - "TLS State Error: Too short packet (length %d) received from= %s", + dmsg(D_TLS_STATE_ERRORS, "TLS State Error: Too short packet (lengt= h %d) received from %s", buf->len, print_link_socket_actual(from, &gc)); goto error; } @@ -329,27 +312,21 @@ * scrutinize carefully */ /* Allow only the reset packet or the first packet of the actual hands= hake. */ - if (op !=3D P_CONTROL_HARD_RESET_CLIENT_V2 - && op !=3D P_CONTROL_HARD_RESET_CLIENT_V3 - && op !=3D P_CONTROL_V1 - && op !=3D P_CONTROL_WKC_V1 - && op !=3D P_ACK_V1) + if (op !=3D P_CONTROL_HARD_RESET_CLIENT_V2 && op !=3D P_CONTROL_HARD_R= ESET_CLIENT_V3 + && op !=3D P_CONTROL_V1 && op !=3D P_CONTROL_WKC_V1 && op !=3D P_A= CK_V1) { /* * This can occur due to bogus data or DoS packets. */ - dmsg(D_TLS_STATE_ERRORS, - "TLS State Error: No TLS state for client %s, opcode=3D%d", - print_link_socket_actual(from, &gc), - op); + dmsg(D_TLS_STATE_ERRORS, "TLS State Error: No TLS state for client= %s, opcode=3D%d", + print_link_socket_actual(from, &gc), op); goto error; } if (key_id !=3D 0) { dmsg(D_TLS_STATE_ERRORS, - "TLS State Error: Unknown key ID (%d) received from %s -- 0 w= as expected", - key_id, + "TLS State Error: Unknown key ID (%d) received from %s -- 0 w= as expected", key_id, print_link_socket_actual(from, &gc)); goto error; } @@ -361,8 +338,7 @@ if (!session_id_read(&state->peer_session_id, &tmp) || !session_id_defined(&state->peer_session_id)) { - msg(D_TLS_ERRORS, - "TLS Error: session-id not found in packet from %s", + msg(D_TLS_ERRORS, "TLS Error: session-id not found in packet from = %s", print_link_socket_actual(from, &gc)); goto error; } @@ -373,8 +349,7 @@ /* HMAC test and unwrapping the encrypted part of the control message * into newbuf or just setting newbuf to point to the start of control * message */ - bool status =3D read_control_auth(&state->newbuf, &state->tls_wrap_tmp, - from, NULL, true); + bool status =3D read_control_auth(&state->newbuf, &state->tls_wrap_tmp= , from, NULL, true); if (!status) { @@ -426,11 +401,8 @@ struct buffer -tls_reset_standalone(struct tls_wrap_ctx *ctx, - struct tls_auth_standalone *tas, - struct session_id *own_sid, - struct session_id *remote_sid, - uint8_t header, +tls_reset_standalone(struct tls_wrap_ctx *ctx, struct tls_auth_standalone = *tas, + struct session_id *own_sid, struct session_id *remote= _sid, uint8_t header, bool request_resend_wkc) { /* Copy buffer here to point at the same data but allow tls_wrap_contr= ol @@ -485,12 +457,11 @@ } struct session_id -calculate_session_id_hmac(struct session_id client_sid, - const struct openvpn_sockaddr *from, - hmac_ctx_t *hmac, - int handwindow, int offset) +calculate_session_id_hmac(struct session_id client_sid, const struct openv= pn_sockaddr *from, + hmac_ctx_t *hmac, int handwindow, int offset) { - union { + union + { uint8_t hmac_result[SHA256_DIGEST_LENGTH]; struct session_id sid; } result; @@ -498,23 +469,22 @@ /* Get the valid time quantisation for our hmac, * we divide time by handwindow/2 and allow the previous * and future session time if specified by offset */ - uint32_t session_id_time =3D ntohl(now/((handwindow+1)/2) + offset); + uint32_t session_id_time =3D ntohl(now / ((handwindow + 1) / 2) + offs= et); hmac_ctx_reset(hmac); /* We do not care about endian here since it does not need to be * portable */ - hmac_ctx_update(hmac, (const uint8_t *) &session_id_time, - sizeof(session_id_time)); + hmac_ctx_update(hmac, (const uint8_t *)&session_id_time, sizeof(sessio= n_id_time)); /* add client IP and port */ switch (from->addr.sa.sa_family) { case AF_INET: - hmac_ctx_update(hmac, (const uint8_t *) &from->addr.in4, sizeo= f(struct sockaddr_in)); + hmac_ctx_update(hmac, (const uint8_t *)&from->addr.in4, sizeof= (struct sockaddr_in)); break; case AF_INET6: - hmac_ctx_update(hmac, (const uint8_t *) &from->addr.in6, sizeo= f(struct sockaddr_in6)); + hmac_ctx_update(hmac, (const uint8_t *)&from->addr.in6, sizeof= (struct sockaddr_in6)); break; } @@ -527,10 +497,8 @@ } bool -check_session_id_hmac(struct tls_pre_decrypt_state *state, - const struct openvpn_sockaddr *from, - hmac_ctx_t *hmac, - int handwindow) +check_session_id_hmac(struct tls_pre_decrypt_state *state, const struct op= envpn_sockaddr *from, + hmac_ctx_t *hmac, int handwindow) { if (!from) { @@ -575,7 +543,7 @@ } /* include the NUL byte and ensure NUL termination */ - cmdlen +=3D 1; + cmdlen +=3D 1; /* Construct a buffer that only holds the current command and * its closing NUL byte */ diff --git a/src/openvpn/ssl_pkt.h b/src/openvpn/ssl_pkt.h index 98a39d3..fd673f4 100644 --- a/src/openvpn/ssl_pkt.h +++ b/src/openvpn/ssl_pkt.h @@ -36,40 +36,40 @@ #include "ssl_common.h" /* packet opcode (high 5 bits) and key-id (low 3 bits) are combined in one= byte */ -#define P_KEY_ID_MASK 0x07 -#define P_OPCODE_SHIFT 3 +#define P_KEY_ID_MASK 0x07 +#define P_OPCODE_SHIFT 3 /* packet opcodes -- the V1 is intended to allow protocol changes in the f= uture */ -#define P_CONTROL_HARD_RESET_CLIENT_V1 1 /* initial key from client, f= orget previous state */ -#define P_CONTROL_HARD_RESET_SERVER_V1 2 /* initial key from server, f= orget previous state */ -#define P_CONTROL_SOFT_RESET_V1 3 /* new key, graceful transiti= on from old to new key */ -#define P_CONTROL_V1 4 /* control channel packet (us= ually TLS ciphertext) */ -#define P_ACK_V1 5 /* acknowledgement for packet= s received */ -#define P_DATA_V1 6 /* data channel packet */ -#define P_DATA_V2 9 /* data channel packet with p= eer-id */ +#define P_CONTROL_HARD_RESET_CLIENT_V1 1 /* initial key from client, forge= t previous state */ +#define P_CONTROL_HARD_RESET_SERVER_V1 2 /* initial key from server, forge= t previous state */ +#define P_CONTROL_SOFT_RESET_V1 3 /* new key, graceful transition f= rom old to new key */ +#define P_CONTROL_V1 4 /* control channel packet (usuall= y TLS ciphertext) */ +#define P_ACK_V1 5 /* acknowledgement for packets re= ceived */ +#define P_DATA_V1 6 /* data channel packet */ +#define P_DATA_V2 9 /* data channel packet with peer-= id */ /* indicates key_method >=3D 2 */ -#define P_CONTROL_HARD_RESET_CLIENT_V2 7 /* initial key from client, f= orget previous state */ -#define P_CONTROL_HARD_RESET_SERVER_V2 8 /* initial key from server, f= orget previous state */ +#define P_CONTROL_HARD_RESET_CLIENT_V2 7 /* initial key from client, forge= t previous state */ +#define P_CONTROL_HARD_RESET_SERVER_V2 8 /* initial key from server, forge= t previous state */ /* indicates key_method >=3D 2 and client-specific tls-crypt key */ -#define P_CONTROL_HARD_RESET_CLIENT_V3 10 /* initial key from client, f= orget previous state */ +#define P_CONTROL_HARD_RESET_CLIENT_V3 10 /* initial key from client, forg= et previous state */ /* Variant of P_CONTROL_V1 but with appended wrapped key * like P_CONTROL_HARD_RESET_CLIENT_V3 */ -#define P_CONTROL_WKC_V1 11 +#define P_CONTROL_WKC_V1 11 /* define the range of legal opcodes * Since we do no longer support key-method 1 we consider * the v1 op codes invalid */ -#define P_FIRST_OPCODE 3 -#define P_LAST_OPCODE 11 +#define P_FIRST_OPCODE 3 +#define P_LAST_OPCODE 11 /* * Define number of buffers for send and receive in the reliability layer. */ -#define TLS_RELIABLE_N_SEND_BUFFERS 6 /* also window size for reliability= layer */ -#define TLS_RELIABLE_N_REC_BUFFERS 12 +#define TLS_RELIABLE_N_SEND_BUFFERS 6 /* also window size for reliability = layer */ +#define TLS_RELIABLE_N_REC_BUFFERS 12 /* * Used in --mode server mode to check tls-auth signature on initial @@ -82,7 +82,8 @@ struct frame frame; }; -enum first_packet_verdict { +enum first_packet_verdict +{ /** This packet is a valid reset packet from the peer (all but tls-cry= pt-v2) */ VERDICT_VALID_RESET_V2, /** This is a valid v3 reset (tls-crypt-v2) */ @@ -102,7 +103,8 @@ * struct that stores the temporary data for the tls lite decrypt * functions */ -struct tls_pre_decrypt_state { +struct tls_pre_decrypt_state +{ struct tls_wrap_ctx tls_wrap_tmp; struct buffer newbuf; struct session_id peer_session_id; @@ -145,11 +147,10 @@ * @li False if the packet is not valid, did not pass the HMAC firewall * test, or some other error occurred. */ -enum first_packet_verdict -tls_pre_decrypt_lite(const struct tls_auth_standalone *tas, - struct tls_pre_decrypt_state *state, - const struct link_socket_actual *from, - const struct buffer *buf); +enum first_packet_verdict tls_pre_decrypt_lite(const struct tls_auth_stand= alone *tas, + struct tls_pre_decrypt_stat= e *state, + const struct link_socket_ac= tual *from, + const struct buffer *buf); /* Creates an SHA256 HMAC context with a random key that is used for the * session id. @@ -171,11 +172,9 @@ * @param offset offset to 'now' to use * @return the expected server session id */ -struct session_id -calculate_session_id_hmac(struct session_id client_sid, - const struct openvpn_sockaddr *from, - hmac_ctx_t *hmac, - int handwindow, int offset); +struct session_id calculate_session_id_hmac(struct session_id client_sid, + const struct openvpn_sockaddr = *from, hmac_ctx_t *hmac, + int handwindow, int offset); /** * Checks if a control packet has a correct HMAC server session id @@ -186,24 +185,15 @@ * @param handwindow the quantisation of the current time * @return the expected server session id */ -bool -check_session_id_hmac(struct tls_pre_decrypt_state *state, - const struct openvpn_sockaddr *from, - hmac_ctx_t *hmac, - int handwindow); +bool check_session_id_hmac(struct tls_pre_decrypt_state *state, const stru= ct openvpn_sockaddr *from, + hmac_ctx_t *hmac, int handwindow); /* * Write a control channel authentication record. */ -void -write_control_auth(struct tls_session *session, - struct key_state *ks, - struct buffer *buf, - struct link_socket_actual **to_link_addr, - int opcode, - int max_ack, - bool prepend_ack); - +void write_control_auth(struct tls_session *session, struct key_state *ks,= struct buffer *buf, + struct link_socket_actual **to_link_addr, int opco= de, int max_ack, + bool prepend_ack); =20 /** @@ -215,12 +205,9 @@ * @param initial_packet whether this is the initial packet for the con= nection * @return if the packet was successfully processed */ -bool -read_control_auth(struct buffer *buf, - struct tls_wrap_ctx *ctx, - const struct link_socket_actual *from, - const struct tls_options *opt, - bool initial_packet); +bool read_control_auth(struct buffer *buf, struct tls_wrap_ctx *ctx, + const struct link_socket_actual *from, const struct= tls_options *opt, + bool initial_packet); /** @@ -228,13 +215,9 @@ * from the tls pre decrypt state. * */ -struct buffer -tls_reset_standalone(struct tls_wrap_ctx *ctx, - struct tls_auth_standalone *tas, - struct session_id *own_sid, - struct session_id *remote_sid, - uint8_t header, - bool request_resend_wkc); +struct buffer tls_reset_standalone(struct tls_wrap_ctx *ctx, struct tls_au= th_standalone *tas, + struct session_id *own_sid, struct sess= ion_id *remote_sid, + uint8_t header, bool request_resend_wkc= ); /** @@ -247,8 +230,7 @@ * with length 0 if there is no message or the message has * invalid characters. */ -struct buffer -extract_command_buffer(struct buffer *buf, struct gc_arena *gc); +struct buffer extract_command_buffer(struct buffer *buf, struct gc_arena *= gc); static inline const char * packet_opcode_name(int op) @@ -324,14 +306,14 @@ * but the network time part of the packet id takes care of that. And * this is also a rather theoretical scenario as it still needs more than * 2^31 control channel packets to happen */ -#define EARLY_NEG_MASK 0xff000000 -#define EARLY_NEG_START 0x0f000000 +#define EARLY_NEG_MASK 0xff000000 +#define EARLY_NEG_START 0x0f000000 /* Early negotiation that part of the server response in the RESET_V2 pack= et. * Since clients that announce early negotiation support will treat the pa= yload * of reset packets special and parse it as TLV messages. * as TLV (type, length, value) */ -#define TLV_TYPE_EARLY_NEG_FLAGS 0x0001 -#define EARLY_NEG_FLAG_RESEND_WKC 0x0001 +#define TLV_TYPE_EARLY_NEG_FLAGS 0x0001 +#define EARLY_NEG_FLAG_RESEND_WKC 0x0001 #endif /* ifndef SSL_PKT_H */ diff --git a/src/openvpn/ssl_util.c b/src/openvpn/ssl_util.c index d3d7b2c..676a0e5 100644 --- a/src/openvpn/ssl_util.c +++ b/src/openvpn/ssl_util.c @@ -29,8 +29,7 @@ #include "ssl_util.h" char * -extract_var_peer_info(const char *peer_info, const char *var, - struct gc_arena *gc) +extract_var_peer_info(const char *peer_info, const char *var, struct gc_ar= ena *gc) { if (!peer_info) { @@ -78,8 +77,10 @@ options_string_compat_lzo(const char *options, struct gc_arena *gc) { /* Example string without and with comp-lzo, i.e. input/output of this= function */ - /* w/o comp: 'V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,a= uth SHA1,keysize 128,key-method 2,tls-server' */ - /* comp-lzo: 'V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,c= omp-lzo,auth SHA1,keysize 128,key-method 2,tls-server' */ + /* w/o comp: 'V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,a= uth SHA1,keysize + * 128,key-method 2,tls-server' */ + /* comp-lzo: 'V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,c= omp-lzo,auth SHA1,keysize + * 128,key-method 2,tls-server' */ /* Note: since this function is used only in a very limited scope it m= akes * assumptions how the string looks. Since we locally generated the st= ring @@ -119,146 +120,156 @@ * SSL/TLS Cipher suite name translation table */ static const tls_cipher_name_pair tls_cipher_name_translation_table[] =3D { - {"ADH-SEED-SHA", "TLS-DH-anon-WITH-SEED-CBC-SHA"}, - {"AES128-GCM-SHA256", "TLS-RSA-WITH-AES-128-GCM-SHA256"}, - {"AES128-SHA256", "TLS-RSA-WITH-AES-128-CBC-SHA256"}, - {"AES128-SHA", "TLS-RSA-WITH-AES-128-CBC-SHA"}, - {"AES256-GCM-SHA384", "TLS-RSA-WITH-AES-256-GCM-SHA384"}, - {"AES256-SHA256", "TLS-RSA-WITH-AES-256-CBC-SHA256"}, - {"AES256-SHA", "TLS-RSA-WITH-AES-256-CBC-SHA"}, - {"CAMELLIA128-SHA256", "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA256"}, - {"CAMELLIA128-SHA", "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA"}, - {"CAMELLIA256-SHA256", "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA256"}, - {"CAMELLIA256-SHA", "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA"}, - {"DES-CBC3-SHA", "TLS-RSA-WITH-3DES-EDE-CBC-SHA"}, - {"DES-CBC-SHA", "TLS-RSA-WITH-DES-CBC-SHA"}, - {"DH-DSS-SEED-SHA", "TLS-DH-DSS-WITH-SEED-CBC-SHA"}, - {"DHE-DSS-AES128-GCM-SHA256", "TLS-DHE-DSS-WITH-AES-128-GCM-SHA256"}, - {"DHE-DSS-AES128-SHA256", "TLS-DHE-DSS-WITH-AES-128-CBC-SHA256"}, - {"DHE-DSS-AES128-SHA", "TLS-DHE-DSS-WITH-AES-128-CBC-SHA"}, - {"DHE-DSS-AES256-GCM-SHA384", "TLS-DHE-DSS-WITH-AES-256-GCM-SHA384"}, - {"DHE-DSS-AES256-SHA256", "TLS-DHE-DSS-WITH-AES-256-CBC-SHA256"}, - {"DHE-DSS-AES256-SHA", "TLS-DHE-DSS-WITH-AES-256-CBC-SHA"}, - {"DHE-DSS-CAMELLIA128-SHA256", "TLS-DHE-DSS-WITH-CAMELLIA-128-CBC-SHA2= 56"}, - {"DHE-DSS-CAMELLIA128-SHA", "TLS-DHE-DSS-WITH-CAMELLIA-128-CBC-SHA"}, - {"DHE-DSS-CAMELLIA256-SHA256", "TLS-DHE-DSS-WITH-CAMELLIA-256-CBC-SHA2= 56"}, - {"DHE-DSS-CAMELLIA256-SHA", "TLS-DHE-DSS-WITH-CAMELLIA-256-CBC-SHA"}, - {"DHE-DSS-SEED-SHA", "TLS-DHE-DSS-WITH-SEED-CBC-SHA"}, - {"DHE-RSA-AES128-GCM-SHA256", "TLS-DHE-RSA-WITH-AES-128-GCM-SHA256"}, - {"DHE-RSA-AES128-SHA256", "TLS-DHE-RSA-WITH-AES-128-CBC-SHA256"}, - {"DHE-RSA-AES128-SHA", "TLS-DHE-RSA-WITH-AES-128-CBC-SHA"}, - {"DHE-RSA-AES256-GCM-SHA384", "TLS-DHE-RSA-WITH-AES-256-GCM-SHA384"}, - {"DHE-RSA-AES256-SHA256", "TLS-DHE-RSA-WITH-AES-256-CBC-SHA256"}, - {"DHE-RSA-AES256-SHA", "TLS-DHE-RSA-WITH-AES-256-CBC-SHA"}, - {"DHE-RSA-CAMELLIA128-SHA256", "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA2= 56"}, - {"DHE-RSA-CAMELLIA128-SHA", "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA"}, - {"DHE-RSA-CAMELLIA256-SHA256", "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA2= 56"}, - {"DHE-RSA-CAMELLIA256-SHA", "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA"}, - {"DHE-RSA-CHACHA20-POLY1305", "TLS-DHE-RSA-WITH-CHACHA20-POLY1305-SHA2= 56"}, - {"DHE-RSA-SEED-SHA", "TLS-DHE-RSA-WITH-SEED-CBC-SHA"}, - {"DH-RSA-SEED-SHA", "TLS-DH-RSA-WITH-SEED-CBC-SHA"}, - {"ECDH-ECDSA-AES128-GCM-SHA256", "TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA2= 56"}, - {"ECDH-ECDSA-AES128-SHA256", "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256"}, - {"ECDH-ECDSA-AES128-SHA", "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA"}, - {"ECDH-ECDSA-AES256-GCM-SHA384", "TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA3= 84"}, - {"ECDH-ECDSA-AES256-SHA256", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA256"}, - {"ECDH-ECDSA-AES256-SHA384", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384"}, - {"ECDH-ECDSA-AES256-SHA", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA"}, - {"ECDH-ECDSA-CAMELLIA128-SHA256", "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CB= C-SHA256"}, - {"ECDH-ECDSA-CAMELLIA128-SHA", "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-S= HA"}, - {"ECDH-ECDSA-CAMELLIA256-SHA256", "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CB= C-SHA256"}, - {"ECDH-ECDSA-CAMELLIA256-SHA", "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-S= HA"}, - {"ECDH-ECDSA-DES-CBC3-SHA", "TLS-ECDH-ECDSA-WITH-3DES-EDE-CBC-SHA"}, - {"ECDH-ECDSA-DES-CBC-SHA", "TLS-ECDH-ECDSA-WITH-DES-CBC-SHA"}, - {"ECDH-ECDSA-RC4-SHA", "TLS-ECDH-ECDSA-WITH-RC4-128-SHA"}, - {"ECDHE-ECDSA-AES128-GCM-SHA256", "TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SH= A256"}, - {"ECDHE-ECDSA-AES128-SHA256", "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256= "}, - {"ECDHE-ECDSA-AES128-SHA384", "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA384= "}, - {"ECDHE-ECDSA-AES128-SHA", "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA"}, - {"ECDHE-ECDSA-AES256-GCM-SHA384", "TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SH= A384"}, - {"ECDHE-ECDSA-AES256-SHA256", "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA256= "}, - {"ECDHE-ECDSA-AES256-SHA384", "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384= "}, - {"ECDHE-ECDSA-AES256-SHA", "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA"}, - {"ECDHE-ECDSA-CAMELLIA128-SHA256", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-= CBC-SHA256"}, - {"ECDHE-ECDSA-CAMELLIA128-SHA", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CBC= -SHA"}, - {"ECDHE-ECDSA-CAMELLIA256-SHA256", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-= CBC-SHA256"}, - {"ECDHE-ECDSA-CAMELLIA256-SHA", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-CBC= -SHA"}, - {"ECDHE-ECDSA-CHACHA20-POLY1305", "TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1= 305-SHA256"}, - {"ECDHE-ECDSA-DES-CBC3-SHA", "TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA"}, - {"ECDHE-ECDSA-DES-CBC-SHA", "TLS-ECDHE-ECDSA-WITH-DES-CBC-SHA"}, - {"ECDHE-ECDSA-RC4-SHA", "TLS-ECDHE-ECDSA-WITH-RC4-128-SHA"}, - {"ECDHE-RSA-AES128-GCM-SHA256", "TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256= "}, - {"ECDHE-RSA-AES128-SHA256", "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256"}, - {"ECDHE-RSA-AES128-SHA384", "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA384"}, - {"ECDHE-RSA-AES128-SHA", "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA"}, - {"ECDHE-RSA-AES256-GCM-SHA384", "TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384= "}, - {"ECDHE-RSA-AES256-SHA256", "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA256"}, - {"ECDHE-RSA-AES256-SHA384", "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384"}, - {"ECDHE-RSA-AES256-SHA", "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA"}, - {"ECDHE-RSA-CAMELLIA128-SHA256", "TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-= SHA256"}, - {"ECDHE-RSA-CAMELLIA128-SHA", "TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SHA= "}, - {"ECDHE-RSA-CAMELLIA256-SHA256", "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-= SHA256"}, - {"ECDHE-RSA-CAMELLIA256-SHA", "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SHA= "}, - {"ECDHE-RSA-CHACHA20-POLY1305", "TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-= SHA256"}, - {"ECDHE-RSA-DES-CBC3-SHA", "TLS-ECDHE-RSA-WITH-3DES-EDE-CBC-SHA"}, - {"ECDHE-RSA-DES-CBC-SHA", "TLS-ECDHE-RSA-WITH-DES-CBC-SHA"}, - {"ECDHE-RSA-RC4-SHA", "TLS-ECDHE-RSA-WITH-RC4-128-SHA"}, - {"ECDH-RSA-AES128-GCM-SHA256", "TLS-ECDH-RSA-WITH-AES-128-GCM-SHA256"}, - {"ECDH-RSA-AES128-SHA256", "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA256"}, - {"ECDH-RSA-AES128-SHA384", "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA384"}, - {"ECDH-RSA-AES128-SHA", "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA"}, - {"ECDH-RSA-AES256-GCM-SHA384", "TLS-ECDH-RSA-WITH-AES-256-GCM-SHA384"}, - {"ECDH-RSA-AES256-SHA256", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA256"}, - {"ECDH-RSA-AES256-SHA384", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA384"}, - {"ECDH-RSA-AES256-SHA", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA"}, - {"ECDH-RSA-CAMELLIA128-SHA256", "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SH= A256"}, - {"ECDH-RSA-CAMELLIA128-SHA", "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA"}, - {"ECDH-RSA-CAMELLIA256-SHA256", "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SH= A256"}, - {"ECDH-RSA-CAMELLIA256-SHA", "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SHA"}, - {"ECDH-RSA-DES-CBC3-SHA", "TLS-ECDH-RSA-WITH-3DES-EDE-CBC-SHA"}, - {"ECDH-RSA-DES-CBC-SHA", "TLS-ECDH-RSA-WITH-DES-CBC-SHA"}, - {"ECDH-RSA-RC4-SHA", "TLS-ECDH-RSA-WITH-RC4-128-SHA"}, - {"EDH-DSS-DES-CBC3-SHA", "TLS-DHE-DSS-WITH-3DES-EDE-CBC-SHA"}, - {"EDH-DSS-DES-CBC-SHA", "TLS-DHE-DSS-WITH-DES-CBC-SHA"}, - {"EDH-RSA-DES-CBC3-SHA", "TLS-DHE-RSA-WITH-3DES-EDE-CBC-SHA"}, - {"EDH-RSA-DES-CBC-SHA", "TLS-DHE-RSA-WITH-DES-CBC-SHA"}, - {"EXP-DES-CBC-SHA", "TLS-RSA-EXPORT-WITH-DES40-CBC-SHA"}, - {"EXP-EDH-DSS-DES-CBC-SHA", "TLS-DH-DSS-EXPORT-WITH-DES40-CBC-SHA"}, - {"EXP-EDH-RSA-DES-CBC-SHA", "TLS-DH-RSA-EXPORT-WITH-DES40-CBC-SHA"}, - {"EXP-RC2-CBC-MD5", "TLS-RSA-EXPORT-WITH-RC2-CBC-40-MD5"}, - {"EXP-RC4-MD5", "TLS-RSA-EXPORT-WITH-RC4-40-MD5"}, - {"NULL-MD5", "TLS-RSA-WITH-NULL-MD5"}, - {"NULL-SHA256", "TLS-RSA-WITH-NULL-SHA256"}, - {"NULL-SHA", "TLS-RSA-WITH-NULL-SHA"}, - {"PSK-3DES-EDE-CBC-SHA", "TLS-PSK-WITH-3DES-EDE-CBC-SHA"}, - {"PSK-AES128-CBC-SHA", "TLS-PSK-WITH-AES-128-CBC-SHA"}, - {"PSK-AES256-CBC-SHA", "TLS-PSK-WITH-AES-256-CBC-SHA"}, - {"PSK-RC4-SHA", "TLS-PSK-WITH-RC4-128-SHA"}, - {"RC4-MD5", "TLS-RSA-WITH-RC4-128-MD5"}, - {"RC4-SHA", "TLS-RSA-WITH-RC4-128-SHA"}, - {"SEED-SHA", "TLS-RSA-WITH-SEED-CBC-SHA"}, - {"SRP-DSS-3DES-EDE-CBC-SHA", "TLS-SRP-SHA-DSS-WITH-3DES-EDE-CBC-SHA"}, - {"SRP-DSS-AES-128-CBC-SHA", "TLS-SRP-SHA-DSS-WITH-AES-128-CBC-SHA"}, - {"SRP-DSS-AES-256-CBC-SHA", "TLS-SRP-SHA-DSS-WITH-AES-256-CBC-SHA"}, - {"SRP-RSA-3DES-EDE-CBC-SHA", "TLS-SRP-SHA-RSA-WITH-3DES-EDE-CBC-SHA"}, - {"SRP-RSA-AES-128-CBC-SHA", "TLS-SRP-SHA-RSA-WITH-AES-128-CBC-SHA"}, - {"SRP-RSA-AES-256-CBC-SHA", "TLS-SRP-SHA-RSA-WITH-AES-256-CBC-SHA"}, + { "ADH-SEED-SHA", "TLS-DH-anon-WITH-SEED-CBC-SHA" }, + { "AES128-GCM-SHA256", "TLS-RSA-WITH-AES-128-GCM-SHA256" }, + { "AES128-SHA256", "TLS-RSA-WITH-AES-128-CBC-SHA256" }, + { "AES128-SHA", "TLS-RSA-WITH-AES-128-CBC-SHA" }, + { "AES256-GCM-SHA384", "TLS-RSA-WITH-AES-256-GCM-SHA384" }, + { "AES256-SHA256", "TLS-RSA-WITH-AES-256-CBC-SHA256" }, + { "AES256-SHA", "TLS-RSA-WITH-AES-256-CBC-SHA" }, + { "CAMELLIA128-SHA256", "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA256" }, + { "CAMELLIA128-SHA", "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA" }, + { "CAMELLIA256-SHA256", "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA256" }, + { "CAMELLIA256-SHA", "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA" }, + { "DES-CBC3-SHA", "TLS-RSA-WITH-3DES-EDE-CBC-SHA" }, + { "DES-CBC-SHA", "TLS-RSA-WITH-DES-CBC-SHA" }, + { "DH-DSS-SEED-SHA", "TLS-DH-DSS-WITH-SEED-CBC-SHA" }, + { "DHE-DSS-AES128-GCM-SHA256", "TLS-DHE-DSS-WITH-AES-128-GCM-SHA256" }, + { "DHE-DSS-AES128-SHA256", "TLS-DHE-DSS-WITH-AES-128-CBC-SHA256" }, + { "DHE-DSS-AES128-SHA", "TLS-DHE-DSS-WITH-AES-128-CBC-SHA" }, + { "DHE-DSS-AES256-GCM-SHA384", "TLS-DHE-DSS-WITH-AES-256-GCM-SHA384" }, + { "DHE-DSS-AES256-SHA256", "TLS-DHE-DSS-WITH-AES-256-CBC-SHA256" }, + { "DHE-DSS-AES256-SHA", "TLS-DHE-DSS-WITH-AES-256-CBC-SHA" }, + { "DHE-DSS-CAMELLIA128-SHA256", "TLS-DHE-DSS-WITH-CAMELLIA-128-CBC-SHA= 256" }, + { "DHE-DSS-CAMELLIA128-SHA", "TLS-DHE-DSS-WITH-CAMELLIA-128-CBC-SHA" }, + { "DHE-DSS-CAMELLIA256-SHA256", "TLS-DHE-DSS-WITH-CAMELLIA-256-CBC-SHA= 256" }, + { "DHE-DSS-CAMELLIA256-SHA", "TLS-DHE-DSS-WITH-CAMELLIA-256-CBC-SHA" }, + { "DHE-DSS-SEED-SHA", "TLS-DHE-DSS-WITH-SEED-CBC-SHA" }, + { "DHE-RSA-AES128-GCM-SHA256", "TLS-DHE-RSA-WITH-AES-128-GCM-SHA256" }, + { "DHE-RSA-AES128-SHA256", "TLS-DHE-RSA-WITH-AES-128-CBC-SHA256" }, + { "DHE-RSA-AES128-SHA", "TLS-DHE-RSA-WITH-AES-128-CBC-SHA" }, + { "DHE-RSA-AES256-GCM-SHA384", "TLS-DHE-RSA-WITH-AES-256-GCM-SHA384" }, + { "DHE-RSA-AES256-SHA256", "TLS-DHE-RSA-WITH-AES-256-CBC-SHA256" }, + { "DHE-RSA-AES256-SHA", "TLS-DHE-RSA-WITH-AES-256-CBC-SHA" }, + { "DHE-RSA-CAMELLIA128-SHA256", "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA= 256" }, + { "DHE-RSA-CAMELLIA128-SHA", "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA" }, + { "DHE-RSA-CAMELLIA256-SHA256", "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA= 256" }, + { "DHE-RSA-CAMELLIA256-SHA", "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA" }, + { "DHE-RSA-CHACHA20-POLY1305", "TLS-DHE-RSA-WITH-CHACHA20-POLY1305-SHA= 256" }, + { "DHE-RSA-SEED-SHA", "TLS-DHE-RSA-WITH-SEED-CBC-SHA" }, + { "DH-RSA-SEED-SHA", "TLS-DH-RSA-WITH-SEED-CBC-SHA" }, + { "ECDH-ECDSA-AES128-GCM-SHA256", "TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA= 256" }, + { "ECDH-ECDSA-AES128-SHA256", "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256"= }, + { "ECDH-ECDSA-AES128-SHA", "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA" }, + { "ECDH-ECDSA-AES256-GCM-SHA384", "TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA= 384" }, + { "ECDH-ECDSA-AES256-SHA256", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA256"= }, + { "ECDH-ECDSA-AES256-SHA384", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384"= }, + { "ECDH-ECDSA-AES256-SHA", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA" }, + { "ECDH-ECDSA-CAMELLIA128-SHA256", "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-C= BC-SHA256" }, + { "ECDH-ECDSA-CAMELLIA128-SHA", "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-= SHA" }, + { "ECDH-ECDSA-CAMELLIA256-SHA256", "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-C= BC-SHA256" }, + { "ECDH-ECDSA-CAMELLIA256-SHA", "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-= SHA" }, + { "ECDH-ECDSA-DES-CBC3-SHA", "TLS-ECDH-ECDSA-WITH-3DES-EDE-CBC-SHA" }, + { "ECDH-ECDSA-DES-CBC-SHA", "TLS-ECDH-ECDSA-WITH-DES-CBC-SHA" }, + { "ECDH-ECDSA-RC4-SHA", "TLS-ECDH-ECDSA-WITH-RC4-128-SHA" }, + { "ECDHE-ECDSA-AES128-GCM-SHA256", "TLS-ECDHE-ECDSA-WITH-AES-128-GCM-S= HA256" }, + { "ECDHE-ECDSA-AES128-SHA256", "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA25= 6" }, + { "ECDHE-ECDSA-AES128-SHA384", "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA38= 4" }, + { "ECDHE-ECDSA-AES128-SHA", "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA" }, + { "ECDHE-ECDSA-AES256-GCM-SHA384", "TLS-ECDHE-ECDSA-WITH-AES-256-GCM-S= HA384" }, + { "ECDHE-ECDSA-AES256-SHA256", "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA25= 6" }, + { "ECDHE-ECDSA-AES256-SHA384", "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA38= 4" }, + { "ECDHE-ECDSA-AES256-SHA", "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA" }, + { "ECDHE-ECDSA-CAMELLIA128-SHA256", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128= -CBC-SHA256" }, + { "ECDHE-ECDSA-CAMELLIA128-SHA", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CB= C-SHA" }, + { "ECDHE-ECDSA-CAMELLIA256-SHA256", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256= -CBC-SHA256" }, + { "ECDHE-ECDSA-CAMELLIA256-SHA", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-CB= C-SHA" }, + { "ECDHE-ECDSA-CHACHA20-POLY1305", "TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY= 1305-SHA256" }, + { "ECDHE-ECDSA-DES-CBC3-SHA", "TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA" = }, + { "ECDHE-ECDSA-DES-CBC-SHA", "TLS-ECDHE-ECDSA-WITH-DES-CBC-SHA" }, + { "ECDHE-ECDSA-RC4-SHA", "TLS-ECDHE-ECDSA-WITH-RC4-128-SHA" }, + { "ECDHE-RSA-AES128-GCM-SHA256", "TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA25= 6" }, + { "ECDHE-RSA-AES128-SHA256", "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" }, + { "ECDHE-RSA-AES128-SHA384", "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA384" }, + { "ECDHE-RSA-AES128-SHA", "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA" }, + { "ECDHE-RSA-AES256-GCM-SHA384", "TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA38= 4" }, + { "ECDHE-RSA-AES256-SHA256", "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA256" }, + { "ECDHE-RSA-AES256-SHA384", "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" }, + { "ECDHE-RSA-AES256-SHA", "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA" }, + { "ECDHE-RSA-CAMELLIA128-SHA256", "TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC= -SHA256" }, + { "ECDHE-RSA-CAMELLIA128-SHA", "TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SH= A" }, + { "ECDHE-RSA-CAMELLIA256-SHA256", "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC= -SHA256" }, + { "ECDHE-RSA-CAMELLIA256-SHA", "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SH= A" }, + { "ECDHE-RSA-CHACHA20-POLY1305", "TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305= -SHA256" }, + { "ECDHE-RSA-DES-CBC3-SHA", "TLS-ECDHE-RSA-WITH-3DES-EDE-CBC-SHA" }, + { "ECDHE-RSA-DES-CBC-SHA", "TLS-ECDHE-RSA-WITH-DES-CBC-SHA" }, + { "ECDHE-RSA-RC4-SHA", "TLS-ECDHE-RSA-WITH-RC4-128-SHA" }, + { "ECDH-RSA-AES128-GCM-SHA256", "TLS-ECDH-RSA-WITH-AES-128-GCM-SHA256"= }, + { "ECDH-RSA-AES128-SHA256", "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA256" }, + { "ECDH-RSA-AES128-SHA384", "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA384" }, + { "ECDH-RSA-AES128-SHA", "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA" }, + { "ECDH-RSA-AES256-GCM-SHA384", "TLS-ECDH-RSA-WITH-AES-256-GCM-SHA384"= }, + { "ECDH-RSA-AES256-SHA256", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA256" }, + { "ECDH-RSA-AES256-SHA384", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA384" }, + { "ECDH-RSA-AES256-SHA", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA" }, + { "ECDH-RSA-CAMELLIA128-SHA256", "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-S= HA256" }, + { "ECDH-RSA-CAMELLIA128-SHA", "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA"= }, + { "ECDH-RSA-CAMELLIA256-SHA256", "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-S= HA256" }, + { "ECDH-RSA-CAMELLIA256-SHA", "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SHA"= }, + { "ECDH-RSA-DES-CBC3-SHA", "TLS-ECDH-RSA-WITH-3DES-EDE-CBC-SHA" }, + { "ECDH-RSA-DES-CBC-SHA", "TLS-ECDH-RSA-WITH-DES-CBC-SHA" }, + { "ECDH-RSA-RC4-SHA", "TLS-ECDH-RSA-WITH-RC4-128-SHA" }, + { "EDH-DSS-DES-CBC3-SHA", "TLS-DHE-DSS-WITH-3DES-EDE-CBC-SHA" }, + { "EDH-DSS-DES-CBC-SHA", "TLS-DHE-DSS-WITH-DES-CBC-SHA" }, + { "EDH-RSA-DES-CBC3-SHA", "TLS-DHE-RSA-WITH-3DES-EDE-CBC-SHA" }, + { "EDH-RSA-DES-CBC-SHA", "TLS-DHE-RSA-WITH-DES-CBC-SHA" }, + { "EXP-DES-CBC-SHA", "TLS-RSA-EXPORT-WITH-DES40-CBC-SHA" }, + { "EXP-EDH-DSS-DES-CBC-SHA", "TLS-DH-DSS-EXPORT-WITH-DES40-CBC-SHA" }, + { "EXP-EDH-RSA-DES-CBC-SHA", "TLS-DH-RSA-EXPORT-WITH-DES40-CBC-SHA" }, + { "EXP-RC2-CBC-MD5", "TLS-RSA-EXPORT-WITH-RC2-CBC-40-MD5" }, + { "EXP-RC4-MD5", "TLS-RSA-EXPORT-WITH-RC4-40-MD5" }, + { "NULL-MD5", "TLS-RSA-WITH-NULL-MD5" }, + { "NULL-SHA256", "TLS-RSA-WITH-NULL-SHA256" }, + { "NULL-SHA", "TLS-RSA-WITH-NULL-SHA" }, + { "PSK-3DES-EDE-CBC-SHA", "TLS-PSK-WITH-3DES-EDE-CBC-SHA" }, + { "PSK-AES128-CBC-SHA", "TLS-PSK-WITH-AES-128-CBC-SHA" }, + { "PSK-AES256-CBC-SHA", "TLS-PSK-WITH-AES-256-CBC-SHA" }, + { "PSK-RC4-SHA", "TLS-PSK-WITH-RC4-128-SHA" }, + { "RC4-MD5", "TLS-RSA-WITH-RC4-128-MD5" }, + { "RC4-SHA", "TLS-RSA-WITH-RC4-128-SHA" }, + { "SEED-SHA", "TLS-RSA-WITH-SEED-CBC-SHA" }, + { "SRP-DSS-3DES-EDE-CBC-SHA", "TLS-SRP-SHA-DSS-WITH-3DES-EDE-CBC-SHA" = }, + { "SRP-DSS-AES-128-CBC-SHA", "TLS-SRP-SHA-DSS-WITH-AES-128-CBC-SHA" }, + { "SRP-DSS-AES-256-CBC-SHA", "TLS-SRP-SHA-DSS-WITH-AES-256-CBC-SHA" }, + { "SRP-RSA-3DES-EDE-CBC-SHA", "TLS-SRP-SHA-RSA-WITH-3DES-EDE-CBC-SHA" = }, + { "SRP-RSA-AES-128-CBC-SHA", "TLS-SRP-SHA-RSA-WITH-AES-128-CBC-SHA" }, + { "SRP-RSA-AES-256-CBC-SHA", "TLS-SRP-SHA-RSA-WITH-AES-256-CBC-SHA" }, #ifdef ENABLE_CRYPTO_OPENSSL /* OpenSSL-specific group names */ - {"DEFAULT", "DEFAULT"}, - {"ALL", "ALL"}, - {"HIGH", "HIGH"}, {"!HIGH", "!HIGH"}, - {"MEDIUM", "MEDIUM"}, {"!MEDIUM", "!MEDIUM"}, - {"LOW", "LOW"}, {"!LOW", "!LOW"}, - {"ECDH", "ECDH"}, {"!ECDH", "!ECDH"}, - {"ECDSA", "ECDSA"}, {"!ECDSA", "!ECDSA"}, - {"EDH", "EDH"}, {"!EDH", "!EDH"}, - {"EXP", "EXP"}, {"!EXP", "!EXP"}, - {"RSA", "RSA"}, {"!RSA", "!RSA"}, - {"kRSA", "kRSA"}, {"!kRSA", "!kRSA"}, - {"SRP", "SRP"}, {"!SRP", "!SRP"}, + { "DEFAULT", "DEFAULT" }, + { "ALL", "ALL" }, + { "HIGH", "HIGH" }, + { "!HIGH", "!HIGH" }, + { "MEDIUM", "MEDIUM" }, + { "!MEDIUM", "!MEDIUM" }, + { "LOW", "LOW" }, + { "!LOW", "!LOW" }, + { "ECDH", "ECDH" }, + { "!ECDH", "!ECDH" }, + { "ECDSA", "ECDSA" }, + { "!ECDSA", "!ECDSA" }, + { "EDH", "EDH" }, + { "!EDH", "!EDH" }, + { "EXP", "EXP" }, + { "!EXP", "!EXP" }, + { "RSA", "RSA" }, + { "!RSA", "!RSA" }, + { "kRSA", "kRSA" }, + { "!kRSA", "!kRSA" }, + { "SRP", "SRP" }, + { "!SRP", "!SRP" }, #endif - {NULL, NULL} + { NULL, NULL } }; const tls_cipher_name_pair * diff --git a/src/openvpn/ssl_util.h b/src/openvpn/ssl_util.h index e50f899..6f48c23 100644 --- a/src/openvpn/ssl_util.h +++ b/src/openvpn/ssl_util.h @@ -44,8 +44,7 @@ * @return The content of the variable as NULL terminated string or NULL = if the * variable cannot be found. */ -char *extract_var_peer_info(const char *peer_info, const char *var, - struct gc_arena *gc); +char *extract_var_peer_info(const char *peer_info, const char *var, struct= gc_arena *gc); /** * Extracts the IV_PROTO variable and returns its value or 0 @@ -75,7 +74,11 @@ * @param cipher_name Can be either OpenSSL or IANA cipher name * @return tls_cipher_name_pair* if found, NULL otherwise */ -typedef struct { const char *openssl_name; const char *iana_name; } tls_ci= pher_name_pair; +typedef struct +{ + const char *openssl_name; + const char *iana_name; +} tls_cipher_name_pair; const tls_cipher_name_pair *tls_get_cipher_name_pair(const char *cipher_na= me, size_t len); /** @@ -89,7 +92,6 @@ * @param delimiter the delimiter to count, typically ':' * @return occrrences of delimiter + 1 */ -int -get_num_elements(const char *string, char delimiter); +int get_num_elements(const char *string, char delimiter); #endif /* ifndef SSL_UTIL_H_ */ diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index 41635c8..645fb86 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -150,11 +150,12 @@ /* If the username has been overridden, we accept both the original * username and the changed username */ if (strcmp(username, multi->locked_username) !=3D 0 - && (!multi->locked_original_username || strcmp(username, mult= i->locked_original_username) !=3D 0)) + && (!multi->locked_original_username + || strcmp(username, multi->locked_original_username) !=3D = 0)) { - msg(D_TLS_ERRORS, "TLS Auth Error: username attempted to chang= e from '%s' to '%s' -- tunnel disabled", - multi->locked_username, - username); + msg(D_TLS_ERRORS, + "TLS Auth Error: username attempted to change from '%s' to= '%s' -- tunnel disabled", + multi->locked_username, username); /* disable the tunnel */ tls_deauthenticate(multi); @@ -240,8 +241,8 @@ { continue; } - else if (ch1 && ch2 && !memcmp(ch1->sha256_hash, ch2->sha256_h= ash, - sizeof(ch1->sha256_hash))) + else if (ch1 && ch2 + && !memcmp(ch1->sha256_hash, ch2->sha256_hash, sizeof= (ch1->sha256_hash))) { continue; } @@ -276,8 +277,7 @@ if (ch) { ALLOC_OBJ(dest->ch[i], struct cert_hash); - memcpy(dest->ch[i]->sha256_hash, ch->sha256_hash, - sizeof(dest->ch[i]->sha256_hash)); + memcpy(dest->ch[i]->sha256_hash, ch->sha256_hash, sizeof(d= est->ch[i]->sha256_hash)); } } } @@ -321,22 +321,21 @@ * @param subject the peer's extracted common name */ static result_t -verify_peer_cert(const struct tls_options *opt, openvpn_x509_cert_t *peer_= cert, - const char *subject, const char *common_name) +verify_peer_cert(const struct tls_options *opt, openvpn_x509_cert_t *peer_= cert, const char *subject, + const char *common_name) { /* verify certificate nsCertType */ if (opt->ns_cert_type !=3D NS_CERT_CHECK_NONE) { if (SUCCESS =3D=3D x509_verify_ns_cert_type(peer_cert, opt->ns_cer= t_type)) { - msg(D_HANDSHAKE, "VERIFY OK: nsCertType=3D%s", - print_nsCertType(opt->ns_cert_type)); + msg(D_HANDSHAKE, "VERIFY OK: nsCertType=3D%s", print_nsCertTyp= e(opt->ns_cert_type)); } else { - msg(D_HANDSHAKE, "VERIFY nsCertType ERROR: %s, require nsCertT= ype=3D%s", - subject, print_nsCertType(opt->ns_cert_type)); - return FAILURE; /* Reject connection */ + msg(D_HANDSHAKE, "VERIFY nsCertType ERROR: %s, require nsCertT= ype=3D%s", subject, + print_nsCertType(opt->ns_cert_type)); + return FAILURE; /* Reject connection */ } } @@ -350,7 +349,7 @@ else { msg(D_HANDSHAKE, "VERIFY KU ERROR"); - return FAILURE; /* Reject connection */ + return FAILURE; /* Reject connection */ } } @@ -364,28 +363,27 @@ else { msg(D_HANDSHAKE, "VERIFY EKU ERROR"); - return FAILURE; /* Reject connection */ + return FAILURE; /* Reject connection */ } } /* verify X509 name or username against --verify-x509-[user]name */ if (opt->verify_x509_type !=3D VERIFY_X509_NONE) { - if ( (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_DN - && strcmp(opt->verify_x509_name, subject) =3D=3D 0) - || (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_RDN - && strcmp(opt->verify_x509_name, common_name) =3D=3D 0) - || (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_RDN_PREF= IX - && strncmp(opt->verify_x509_name, common_name, - strlen(opt->verify_x509_name)) =3D=3D 0) ) + if ((opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_DN + && strcmp(opt->verify_x509_name, subject) =3D=3D 0) + || (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_RDN + && strcmp(opt->verify_x509_name, common_name) =3D=3D 0) + || (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_RDN_PREFIX + && strncmp(opt->verify_x509_name, common_name, strlen(opt-= >verify_x509_name)) =3D=3D 0)) { msg(D_HANDSHAKE, "VERIFY X509NAME OK: %s", subject); } else { - msg(D_HANDSHAKE, "VERIFY X509NAME ERROR: %s, must be %s", - subject, opt->verify_x509_name); - return FAILURE; /* Reject connection */ + msg(D_HANDSHAKE, "VERIFY X509NAME ERROR: %s, must be %s", subj= ect, + opt->verify_x509_name); + return FAILURE; /* Reject connection */ } } @@ -398,8 +396,7 @@ */ static void verify_cert_set_env(struct env_set *es, openvpn_x509_cert_t *peer_cert, in= t cert_depth, - const char *subject, - const struct x509_track *x509_track) + const char *subject, const struct x509_track *x509_tra= ck) { char envname[64]; char *serial =3D NULL; @@ -425,13 +422,10 @@ struct buffer sha256 =3D x509_get_sha256_fingerprint(peer_cert, &g= c); snprintf(envname, sizeof(envname), "tls_digest_%d", cert_depth); - setenv_str(es, envname, - format_hex_ex(BPTR(&sha1), BLEN(&sha1), 0, 1, ":", &gc)= ); + setenv_str(es, envname, format_hex_ex(BPTR(&sha1), BLEN(&sha1), 0,= 1, ":", &gc)); - snprintf(envname, sizeof(envname), "tls_digest_sha256_%d", - cert_depth); - setenv_str(es, envname, - format_hex_ex(BPTR(&sha256), BLEN(&sha256), 0, 1, ":", = &gc)); + snprintf(envname, sizeof(envname), "tls_digest_sha256_%d", cert_de= pth); + setenv_str(es, envname, format_hex_ex(BPTR(&sha256), BLEN(&sha256)= , 0, 1, ":", &gc)); } /* export serial number as environmental variable */ @@ -475,8 +469,8 @@ * call --tls-verify plug-in(s) */ static result_t -verify_cert_call_plugin(const struct plugin_list *plugins, struct env_set = *es, - int cert_depth, openvpn_x509_cert_t *cert, char *s= ubject) +verify_cert_call_plugin(const struct plugin_list *plugins, struct env_set = *es, int cert_depth, + openvpn_x509_cert_t *cert, char *subject) { if (plugin_defined(plugins, OPENVPN_PLUGIN_TLS_VERIFY)) { @@ -485,20 +479,19 @@ argv_printf(&argv, "%d %s", cert_depth, subject); - ret =3D plugin_call_ssl(plugins, OPENVPN_PLUGIN_TLS_VERIFY, &argv,= NULL, es, cert_depth, cert); + ret =3D + plugin_call_ssl(plugins, OPENVPN_PLUGIN_TLS_VERIFY, &argv, NUL= L, es, cert_depth, cert); argv_free(&argv); if (ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) { - msg(D_HANDSHAKE, "VERIFY PLUGIN OK: depth=3D%d, %s", - cert_depth, subject); + msg(D_HANDSHAKE, "VERIFY PLUGIN OK: depth=3D%d, %s", cert_dept= h, subject); } else { - msg(D_HANDSHAKE, "VERIFY PLUGIN ERROR: depth=3D%d, %s", - cert_depth, subject); - return FAILURE; /* Reject connection */ + msg(D_HANDSHAKE, "VERIFY PLUGIN ERROR: depth=3D%d, %s", cert_d= epth, subject); + return FAILURE; /* Reject connection */ } } return SUCCESS; @@ -508,8 +501,8 @@ * run --tls-verify script */ static result_t -verify_cert_call_command(const char *verify_command, struct env_set *es, - int cert_depth, char *subject) +verify_cert_call_command(const char *verify_command, struct env_set *es, i= nt cert_depth, + char *subject) { int ret; struct gc_arena gc =3D gc_new(); @@ -528,22 +521,20 @@ if (ret) { - msg(D_HANDSHAKE, "VERIFY SCRIPT OK: depth=3D%d, %s", - cert_depth, subject); + msg(D_HANDSHAKE, "VERIFY SCRIPT OK: depth=3D%d, %s", cert_depth, s= ubject); return SUCCESS; } - msg(D_HANDSHAKE, "VERIFY SCRIPT ERROR: depth=3D%d, %s", - cert_depth, subject); - return FAILURE; /* Reject connection */ + msg(D_HANDSHAKE, "VERIFY SCRIPT ERROR: depth=3D%d, %s", cert_depth, su= bject); + return FAILURE; /* Reject connection */ } /* * check peer cert against CRL directory */ static result_t -verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_t *cert, - const char *subject, int cert_depth) +verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_t *cert, const= char *subject, + int cert_depth) { result_t ret =3D FAILURE; char fn[256]; @@ -553,8 +544,8 @@ char *serial =3D backend_x509_get_serial(cert, &gc); if (!serial) { - msg(D_HANDSHAKE, "VERIFY CRL: depth=3D%d, %s, serial number is not= available", - cert_depth, subject); + msg(D_HANDSHAKE, "VERIFY CRL: depth=3D%d, %s, serial number is not= available", cert_depth, + subject); goto cleanup; } @@ -566,8 +557,8 @@ fd =3D platform_open(fn, O_RDONLY, 0); if (fd >=3D 0) { - msg(D_HANDSHAKE, "VERIFY CRL: depth=3D%d, %s, serial=3D%s is revok= ed", - cert_depth, subject, serial); + msg(D_HANDSHAKE, "VERIFY CRL: depth=3D%d, %s, serial=3D%s is revok= ed", cert_depth, subject, + serial); goto cleanup; } @@ -601,8 +592,10 @@ char *subject =3D x509_get_subject(cert, &gc); if (!subject) { - msg(D_TLS_ERRORS, "VERIFY ERROR: depth=3D%d, could not extract X50= 9 " - "subject string from certificate", cert_depth); + msg(D_TLS_ERRORS, + "VERIFY ERROR: depth=3D%d, could not extract X509 " + "subject string from certificate", + cert_depth); goto cleanup; } @@ -614,19 +607,19 @@ struct buffer buf =3D alloc_buf_gc(256, &gc); for (int i =3D 0; opt->x509_username_field[i] !=3D NULL; i++) { - char username[TLS_USERNAME_LEN+1] =3D {0}; /* null-terminated */ + char username[TLS_USERNAME_LEN + 1] =3D { 0 }; /* null-terminated = */ - if (SUCCESS !=3D backend_x509_get_username(username, sizeof(userna= me), - opt->x509_username_field[= i], cert)) + if (SUCCESS + !=3D backend_x509_get_username(username, sizeof(username), opt= ->x509_username_field[i], + cert)) { if (!cert_depth) { - msg(D_TLS_ERRORS, "VERIFY ERROR: could not extract %s from= X509 " + msg(D_TLS_ERRORS, + "VERIFY ERROR: could not extract %s from X509 " "subject string ('%s') -- note that the field length i= s " "limited to %d characters", - opt->x509_username_field[i], - subject, - TLS_USERNAME_LEN); + opt->x509_username_field[i], subject, TLS_USERNAME_LEN= ); goto cleanup; } break; @@ -635,11 +628,11 @@ { if (!cert_depth) { - msg(D_TLS_ERRORS, "VERIFY ERROR: could not append %s from = X509 " + msg(D_TLS_ERRORS, + "VERIFY ERROR: could not append %s from X509 " "certificate -- note that the username length is " "limited to %d characters", - opt->x509_username_field[i], - buf.capacity - 1); + opt->x509_username_field[i], buf.capacity - 1); goto cleanup; } break; @@ -649,8 +642,10 @@ char *common_name =3D BSTR(&buf); if (!common_name) { - msg(D_TLS_ERRORS, "VERIFY ERROR: depth=3D%d, could not extract X50= 9 " - "username string from certificate", cert_depth); + msg(D_TLS_ERRORS, + "VERIFY ERROR: depth=3D%d, could not extract X509 " + "username string from certificate", + cert_depth); goto cleanup; } @@ -660,13 +655,15 @@ /* warn if cert chain is too deep */ if (cert_depth >=3D MAX_CERT_DEPTH) { - msg(D_TLS_ERRORS, "TLS Error: Convoluted certificate chain detecte= d with depth [%d] greater than %d", cert_depth, MAX_CERT_DEPTH); - goto cleanup; /* Reject connection */ + msg(D_TLS_ERRORS, + "TLS Error: Convoluted certificate chain detected with depth [= %d] greater than %d", + cert_depth, MAX_CERT_DEPTH); + goto cleanup; /* Reject connection */ } if (cert_depth =3D=3D opt->verify_hash_depth && opt->verify_hash) { - struct buffer cert_fp =3D {0}; + struct buffer cert_fp =3D { 0 }; switch (opt->verify_hash_algo) { @@ -684,8 +681,10 @@ * value in an enumerated type. So if this unlikely scena= rio * happens, consider this a failure */ - msg(M_WARN, "Unexpected invalid algorithm used with " - "--verify-hash (%i)", opt->verify_hash_algo); + msg(M_WARN, + "Unexpected invalid algorithm used with " + "--verify-hash (%i)", + opt->verify_hash_algo); ret =3D FAILURE; goto cleanup; } @@ -694,8 +693,7 @@ while (current_hash) { - if (memcmp_constant_time(BPTR(&cert_fp), current_hash->hash, - BLEN(&cert_fp)) =3D=3D 0) + if (memcmp_constant_time(BPTR(&cert_fp), current_hash->hash, B= LEN(&cert_fp)) =3D=3D 0) { break; } @@ -704,11 +702,12 @@ if (!current_hash) { - const char *hex_fp =3D format_hex_ex(BPTR(&cert_fp), BLEN(&cer= t_fp), - 0, 1, ":", &gc); - msg(D_TLS_ERRORS, "TLS Error: --tls-verify/--peer-fingerprint " + const char *hex_fp =3D format_hex_ex(BPTR(&cert_fp), BLEN(&cer= t_fp), 0, 1, ":", &gc); + msg(D_TLS_ERRORS, + "TLS Error: --tls-verify/--peer-fingerprint " "certificate hash verification failed. (got certificate " - "fingerprint: %s)", hex_fp); + "fingerprint: %s)", + hex_fp); goto cleanup; } } @@ -723,14 +722,14 @@ if (opt->export_peer_cert_dir) { - pem_export_fname =3D platform_create_temp_file(opt->export_peer_ce= rt_dir, - "pef", &gc); + pem_export_fname =3D platform_create_temp_file(opt->export_peer_ce= rt_dir, "pef", &gc); - if (!pem_export_fname - || !verify_cert_cert_export_env(opt->es, cert, pem_export_fnam= e)) + if (!pem_export_fname || !verify_cert_cert_export_env(opt->es, cer= t, pem_export_fname)) { - msg(D_TLS_ERRORS, "TLS Error: Failed to export certificate for= " - "--tls-export-cert in %s", opt->export_peer_cert_dir); + msg(D_TLS_ERRORS, + "TLS Error: Failed to export certificate for " + "--tls-export-cert in %s", + opt->export_peer_cert_dir); goto cleanup; } } @@ -753,8 +752,8 @@ } /* run --tls-verify script */ - if (opt->verify_command && SUCCESS !=3D verify_cert_call_command(opt->= verify_command, - opt->es= , cert_depth, subject)) + if (opt->verify_command + && SUCCESS !=3D verify_cert_call_command(opt->verify_command, opt-= >es, cert_depth, subject)) { goto cleanup; } @@ -787,7 +786,7 @@ verify_cert_cert_delete_env(opt->es, pem_export_fname); if (ret !=3D SUCCESS) { - tls_clear_error(); /* always? */ + tls_clear_error(); /* always? */ session->verified =3D false; /* double sure? */ } @@ -797,9 +796,9 @@ } /* ***********************************************************************= **** -* Functions for the management of deferred authentication when using -* user/password authentication. -**************************************************************************= * */ + * Functions for the management of deferred authentication when using + * user/password authentication. + *************************************************************************= ** */ void auth_set_client_reason(struct tls_multi *multi, const char *client_reason) @@ -885,15 +884,13 @@ * @returns false The file had an invlaid format or another error occured */ static bool -key_state_check_auth_pending_file(struct auth_deferred_status *ads, - struct tls_multi *multi, +key_state_check_auth_pending_file(struct auth_deferred_status *ads, struct= tls_multi *multi, struct tls_session *session) { bool ret =3D true; if (ads->auth_pending_file) { - struct buffer_list *lines =3D buffer_list_file(ads->auth_pending_f= ile, - 1024); + struct buffer_list *lines =3D buffer_list_file(ads->auth_pending_f= ile, 1024); if (lines && lines->head) { /* Must have at least three lines. further lines are ignored f= or @@ -901,7 +898,7 @@ if (!lines->head || !lines->head->next || !lines->head->next->= next) { msg(M_WARN, "auth pending control file is not at least " - "three lines long."); + "three lines long."); buffer_list_free(lines); return false; } @@ -928,10 +925,13 @@ char buf[128]; snprintf(buf, sizeof(buf), "Authentication failed, required pending auth " - "method '%s' not supported", pending_method); + "method '%s' not supported", + pending_method); auth_set_client_reason(multi, buf); - msg(M_INFO, "Client does not supported auth pending method= " - "'%s'", pending_method); + msg(M_INFO, + "Client does not supported auth pending method " + "'%s'", + pending_method); ret =3D false; } else @@ -976,8 +976,7 @@ * @return true if file creation was successful */ static bool -key_state_gen_auth_control_files(struct auth_deferred_status *ads, - const struct tls_options *opt) +key_state_gen_auth_control_files(struct auth_deferred_status *ads, const s= truct tls_options *opt) { struct gc_arena gc =3D gc_new(); @@ -1018,7 +1017,6 @@ { ret =3D BSTR(&reason); } - } return ret; } @@ -1089,8 +1087,7 @@ #endif ASSERT(auth_plugin < 4 && auth_script < 4 && auth_man < 4); - if (auth_plugin =3D=3D ACF_FAILED || auth_script =3D=3D ACF_FAILED - || auth_man =3D=3D ACF_FAILED) + if (auth_plugin =3D=3D ACF_FAILED || auth_script =3D=3D ACF_FAILED= || auth_man =3D=3D ACF_FAILED) { ks->authenticated =3D KS_AUTH_FALSE; return; @@ -1123,7 +1120,7 @@ * with no caching (0) here as well to have the same super quick initial * reaction. */ -static time_t cache_intervals[] =3D {0, 0, 0, 0, 0, 1, 1, 2, 2, 4, 8}; +static time_t cache_intervals[] =3D { 0, 0, 0, 0, 0, 1, 1, 2, 2, 4, 8 }; /** * uses cache_intervals times to determine if we should update the @@ -1190,8 +1187,10 @@ { struct gc_arena gc =3D gc_new(); const struct key_state *ks =3D get_primary_key(multi); - const char *plugin_message =3D key_state_check_auth_failed_message= _file(&ks->plugin_auth, &gc); - const char *script_message =3D key_state_check_auth_failed_message= _file(&ks->script_auth, &gc); + const char *plugin_message =3D + key_state_check_auth_failed_message_file(&ks->plugin_auth, &gc= ); + const char *script_message =3D + key_state_check_auth_failed_message_file(&ks->script_auth, &gc= ); if (plugin_message) { @@ -1235,7 +1234,8 @@ * to indicate auth failure/success. */ bool -tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_i= d, const bool auth, const char *client_reason) +tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_i= d, const bool auth, + const char *client_reason) { bool ret =3D false; if (multi) @@ -1271,8 +1271,7 @@ * Check if the script/plugin left a message in the auth failed message * file and relay it to the user */ static void -check_for_client_reason(struct tls_multi *multi, - struct auth_deferred_status *status) +check_for_client_reason(struct tls_multi *multi, struct auth_deferred_stat= us *status) { struct gc_arena gc =3D gc_new(); const char *msg =3D key_state_check_auth_failed_message_file(status, &= gc); @@ -1293,7 +1292,7 @@ struct argv argv =3D argv_new(); const char *tmp_file =3D ""; int retval =3D OPENVPN_PLUGIN_FUNC_ERROR; - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ /* Set environmental variables prior to calling script */ setenv_str(session->opt->es, "script_type", "user-pass-verify"); @@ -1305,8 +1304,7 @@ { struct status_output *so; - tmp_file =3D platform_create_temp_file(session->opt->tmp_dir, "up", - &gc); + tmp_file =3D platform_create_temp_file(session->opt->tmp_dir, "up"= , &gc); if (tmp_file) { so =3D status_open(tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE); @@ -1331,15 +1329,17 @@ /* pre-create files for deferred auth control */ if (!key_state_gen_auth_control_files(&ks->script_auth, session->opt)) { - msg(D_TLS_ERRORS, "TLS Auth Error (%s): " - "could not create deferred auth control file", __func__); + msg(D_TLS_ERRORS, + "TLS Auth Error (%s): " + "could not create deferred auth control file", + __func__); retval =3D OPENVPN_PLUGIN_FUNC_ERROR; goto error; } /* call command */ - int script_ret =3D openvpn_run_script(&argv, session->opt->es, S_EXITC= ODE, - "--auth-user-pass-verify"); + int script_ret =3D + openvpn_run_script(&argv, session->opt->es, S_EXITCODE, "--auth-us= er-pass-verify"); switch (script_ret) { case 0: @@ -1359,13 +1359,11 @@ { /* Check if we the plugin has written the pending auth control * file and send the pending auth to the client */ - if (!key_state_check_auth_pending_file(&ks->script_auth, - multi, session)) + if (!key_state_check_auth_pending_file(&ks->script_auth, multi, se= ssion)) { retval =3D OPENVPN_PLUGIN_FUNC_ERROR; key_state_rm_auth_control_files(&ks->script_auth); } - } else { @@ -1396,8 +1394,8 @@ struct tls_session *session =3D &multi->session[TM_ACTIVE]; setenv_str(session->opt->es, "crresponse", cr_response); - plugin_call(session->opt->plugins, OPENVPN_PLUGIN_CLIENT_CRRESPONSE, N= ULL, - NULL, session->opt->es); + plugin_call(session->opt->plugins, OPENVPN_PLUGIN_CLIENT_CRRESPONSE, N= ULL, NULL, + session->opt->es); setenv_del(session->opt->es, "crresponse"); } @@ -1406,7 +1404,6 @@ void verify_crresponse_script(struct tls_multi *multi, const char *cr_response) { - struct tls_session *session =3D &multi->session[TM_ACTIVE]; if (!session->opt->client_crresponse_script) @@ -1426,8 +1423,7 @@ if (tmp_file) { - struct status_output *so =3D status_open(tmp_file, 0, -1, NULL, - STATUS_OUTPUT_WRITE); + struct status_output *so =3D status_open(tmp_file, 0, -1, NULL, ST= ATUS_OUTPUT_WRITE); status_printf(so, "%s", cr_response); if (!status_close(so)) { @@ -1464,7 +1460,7 @@ const struct user_pass *up) { int retval =3D OPENVPN_PLUGIN_FUNC_ERROR; - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ /* set password in private env space */ setenv_str(session->opt->es, "password", up->password); @@ -1472,13 +1468,16 @@ /* generate filename for deferred auth control file */ if (!key_state_gen_auth_control_files(&ks->plugin_auth, session->opt)) { - msg(D_TLS_ERRORS, "TLS Auth Error (%s): " - "could not create deferred auth control file", __func__); + msg(D_TLS_ERRORS, + "TLS Auth Error (%s): " + "could not create deferred auth control file", + __func__); return retval; } /* call command */ - retval =3D plugin_call(session->opt->plugins, OPENVPN_PLUGIN_AUTH_USER= _PASS_VERIFY, NULL, NULL, session->opt->es); + retval =3D plugin_call(session->opt->plugins, OPENVPN_PLUGIN_AUTH_USER= _PASS_VERIFY, NULL, NULL, + session->opt->es); if (retval =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED) { @@ -1517,18 +1516,18 @@ #define KMDA_DEF 3 static int -verify_user_pass_management(struct tls_session *session, - const struct user_pass *up) +verify_user_pass_management(struct tls_session *session, const struct user= _pass *up) { int retval =3D KMDA_ERROR; - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ /* set username/password in private env space */ setenv_str(session->opt->es, "password", up->password); if (management) { - management_notify_client_needing_auth(management, ks->mda_key_id, = session->opt->mda_context, session->opt->es); + management_notify_client_needing_auth(management, ks->mda_key_id, = session->opt->mda_context, + session->opt->es); } setenv_del(session->opt->es, "password"); @@ -1540,8 +1539,7 @@ #endif /* ifdef ENABLE_MANAGEMENT */ static bool -set_verify_user_pass_env(struct user_pass *up, struct tls_multi *multi, - struct tls_session *session) +set_verify_user_pass_env(struct user_pass *up, struct tls_multi *multi, st= ruct tls_session *session) { /* Is username defined? */ if ((session->opt->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL) || strlen= (up->username)) @@ -1577,7 +1575,8 @@ msg(D_TLS_ERRORS, "TLS Auth Error: --username-as-common name specified and " "username is longer than the maximum permitted Common Name " - "length of %d characters", TLS_USERNAME_LEN); + "length of %d characters", + TLS_USERNAME_LEN); return false; } else @@ -1593,10 +1592,9 @@ * result of the username/password verification */ void -verify_user_pass(struct user_pass *up, struct tls_multi *multi, - struct tls_session *session) +verify_user_pass(struct user_pass *up, struct tls_multi *multi, struct tls= _session *session) { - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ ASSERT(up && !up->protected); @@ -1624,9 +1622,10 @@ if (multi->locked_original_username && strncmp(up->username, multi->locked_original_username, sizeof(u= p->username)) =3D=3D 0) { - msg(D_MULTI_LOW, "TLS: Replacing client provided username '%s' wit= h " - "username from override-user '%s'", up->username, - multi->locked_username); + msg(D_MULTI_LOW, + "TLS: Replacing client provided username '%s' with " + "username from override-user '%s'", + up->username, multi->locked_username); strncpy(up->username, multi->locked_username, sizeof(up->username)= ); } @@ -1662,7 +1661,8 @@ * We do not want the EXPIRED or EMPTY USER flags here so check * for equality with AUTH_TOKEN_HMAC_OK */ - msg(M_WARN, "TLS: Username/auth-token authentication " + msg(M_WARN, + "TLS: Username/auth-token authentication " "succeeded for username '%s'", up->username); skip_auth =3D true; @@ -1671,8 +1671,10 @@ { wipe_auth_token(multi); ks->authenticated =3D KS_AUTH_FALSE; - msg(M_WARN, "TLS: Username/auth-token authentication " - "failed for username '%s'", up->username); + msg(M_WARN, + "TLS: Username/auth-token authentication " + "failed for username '%s'", + up->username); return; } } @@ -1717,14 +1719,14 @@ bool plugin_ok =3D plugin_status =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS || plugin_status =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED; - bool script_ok =3D script_status =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS - || script_status =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED; + bool script_ok =3D script_status =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS + || script_status =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED; if (script_ok && plugin_ok && tls_lock_username(multi, up->username) #ifdef ENABLE_MANAGEMENT && man_def_auth !=3D KMDA_ERROR #endif - ) + ) { ks->authenticated =3D KS_AUTH_TRUE; if (plugin_status =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED @@ -1758,8 +1760,7 @@ * to store the auth-token in multi->auth_token, so * the initial timestamp and session id can be extracted from = it */ - if (!multi->auth_token - && (ks->auth_token_state_flags & AUTH_TOKEN_HMAC_OK) + if (!multi->auth_token && (ks->auth_token_state_flags & AUTH_T= OKEN_HMAC_OK) && !(ks->auth_token_state_flags & AUTH_TOKEN_EXPIRED)) { multi->auth_token =3D strdup(up->password); @@ -1773,8 +1774,7 @@ } msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for use= rname '%s' %s", - (ks->authenticated =3D=3D KS_AUTH_DEFERRED) ? "deferred" : "su= cceeded", - up->username, + (ks->authenticated =3D=3D KS_AUTH_DEFERRED) ? "deferred" : "su= cceeded", up->username, (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[C= N SET]" : ""); } else @@ -1787,7 +1787,7 @@ void verify_final_auth_checks(struct tls_multi *multi, struct tls_session *sess= ion) { - struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */ + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */ /* While it shouldn't really happen, don't allow the common name to be= NULL */ if (!session->common_name) @@ -1801,9 +1801,9 @@ const char *cn =3D session->common_name; if (cn && strcmp(cn, multi->locked_cn)) { - msg(D_TLS_ERRORS, "TLS Auth Error: TLS object CN attempted to = change from '%s' to '%s' -- tunnel disabled", - multi->locked_cn, - cn); + msg(D_TLS_ERRORS, + "TLS Auth Error: TLS object CN attempted to change from '%= s' to '%s' -- tunnel disabled", + multi->locked_cn, cn); /* change the common name back to its original value and disab= le the tunnel */ set_common_name(session, multi->locked_cn); @@ -1817,7 +1817,8 @@ const struct cert_hash_set *chs =3D session->cert_hash_set; if (chs && !cert_hash_compare(chs, multi->locked_cert_hash_set)) { - msg(D_TLS_ERRORS, "TLS Auth Error: TLS object CN=3D%s client-p= rovided SSL certs unexpectedly changed during mid-session reauth", + msg(D_TLS_ERRORS, + "TLS Auth Error: TLS object CN=3D%s client-provided SSL ce= rts unexpectedly changed during mid-session reauth", session->common_name); /* disable the tunnel */ @@ -1831,15 +1832,14 @@ struct gc_arena gc =3D gc_new(); const char *cn =3D session->common_name; - const char *path =3D platform_gen_path(session->opt->client_config= _dir_exclusive, - cn, &gc); + const char *path =3D platform_gen_path(session->opt->client_config= _dir_exclusive, cn, &gc); if (!cn || !strcmp(cn, CCD_DEFAULT) || !platform_test_file(path)) { ks->authenticated =3D KS_AUTH_FALSE; wipe_auth_token(multi); - msg(D_TLS_ERRORS, "TLS Auth Error: --client-config-dir authent= ication failed for common name '%s' file=3D'%s'", - session->common_name, - path ? path : "UNDEF"); + msg(D_TLS_ERRORS, + "TLS Auth Error: --client-config-dir authentication failed= for common name '%s' file=3D'%s'", + session->common_name, path ? path : "UNDEF"); } gc_free(&gc); @@ -1853,8 +1853,7 @@ while (item) { struct env_item *next =3D item->next; - if (item->string - && 0 =3D=3D strncmp("X509_", item->string, strlen("X509_"))) + if (item->string && 0 =3D=3D strncmp("X509_", item->string, strlen= ("X509_"))) { env_set_del(es, item->string); } diff --git a/src/openvpn/ssl_verify.h b/src/openvpn/ssl_verify.h index 9a30db0..92a760b 100644 --- a/src/openvpn/ssl_verify.h +++ b/src/openvpn/ssl_verify.h @@ -55,25 +55,27 @@ #define TLS_USERNAME_LEN 64 /** Structure containing the hash for a single certificate */ -struct cert_hash { - unsigned char sha256_hash[256/8]; +struct cert_hash +{ + unsigned char sha256_hash[256 / 8]; }; /** Structure containing the hashes for a full certificate chain */ -struct cert_hash_set { +struct cert_hash_set +{ struct cert_hash *ch[MAX_CERT_DEPTH]; /**< Array of certificate hashes= */ }; -#define VERIFY_X509_NONE 0 -#define VERIFY_X509_SUBJECT_DN 1 -#define VERIFY_X509_SUBJECT_RDN 2 -#define VERIFY_X509_SUBJECT_RDN_PREFIX 3 +#define VERIFY_X509_NONE 0 +#define VERIFY_X509_SUBJECT_DN 1 +#define VERIFY_X509_SUBJECT_RDN 2 +#define VERIFY_X509_SUBJECT_RDN_PREFIX 3 enum tls_auth_status { - TLS_AUTHENTICATION_SUCCEEDED=3D0, - TLS_AUTHENTICATION_FAILED=3D1, - TLS_AUTHENTICATION_DEFERRED=3D2 + TLS_AUTHENTICATION_SUCCEEDED =3D 0, + TLS_AUTHENTICATION_FAILED =3D 1, + TLS_AUTHENTICATION_DEFERRED =3D 2 }; /** @@ -92,8 +94,7 @@ * * @return Current authentication status of the tls_multi */ -enum tls_auth_status -tls_authentication_status(struct tls_multi *multi); +enum tls_auth_status tls_authentication_status(struct tls_multi *multi); /** Check whether the \a ks \c key_state has finished the key exchange part * of the OpenVPN hand shake. This is that the key_method_2read/write @@ -156,8 +157,7 @@ * @param session The session to set the common name for * @param common_name The name to set the common name to */ -void -set_common_name(struct tls_session *session, const char *common_name); +void set_common_name(struct tls_session *session, const char *common_name); /** * Returns the username field for the given tunnel @@ -188,8 +188,7 @@ * @param session The current TLS session * */ -void verify_user_pass(struct user_pass *up, struct tls_multi *multi, - struct tls_session *session); +void verify_user_pass(struct user_pass *up, struct tls_multi *multi, struc= t tls_session *session); /** @@ -204,8 +203,7 @@ * @return true if name is under limit or username-as-common-= name * is not active */ -bool ssl_verify_username_length(struct tls_session *session, - const char *username); +bool ssl_verify_username_length(struct tls_session *session, const char *u= sername); /** * Runs the --client-crresponse script if one is defined. @@ -215,8 +213,7 @@ * the files for the deferred auth like the management commands. * */ -void -verify_crresponse_script(struct tls_multi *multi, const char *cr_response); +void verify_crresponse_script(struct tls_multi *multi, const char *cr_resp= onse); /** * Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE. @@ -225,8 +222,7 @@ * that it does not directly participate in the authentication but rather * should set the files for the deferred auth like the management commands. */ -void -verify_crresponse_plugin(struct tls_multi *multi, const char *cr_response); +void verify_crresponse_plugin(struct tls_multi *multi, const char *cr_resp= onse); /** * Perform final authentication checks, including locking of the cn, the a= llowed @@ -243,7 +239,7 @@ { const struct x509_track *next; const char *name; -#define XT_FULL_CHAIN (1<<0) +#define XT_FULL_CHAIN (1 << 0) unsigned int flags; int nid; }; @@ -252,11 +248,11 @@ * Certificate checking for verify_nsCertType */ /** Do not perform Netscape certificate type verification */ -#define NS_CERT_CHECK_NONE (0) +#define NS_CERT_CHECK_NONE (0) /** Do not perform Netscape certificate type verification */ -#define NS_CERT_CHECK_SERVER (1<<0) +#define NS_CERT_CHECK_SERVER (1 << 0) /** Do not perform Netscape certificate type verification */ -#define NS_CERT_CHECK_CLIENT (1<<1) +#define NS_CERT_CHECK_CLIENT (1 << 1) /** Require keyUsage to be present in cert (0xFFFF is an invalid KU value)= */ #define OPENVPN_KU_REQUIRED (0xFFFF) @@ -265,7 +261,8 @@ * TODO: document */ #ifdef ENABLE_MANAGEMENT -bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_= key_id, const bool auth, const char *client_reason); +bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_= key_id, const bool auth, + const char *client_reason); #endif diff --git a/src/openvpn/ssl_verify_backend.h b/src/openvpn/ssl_verify_back= end.h index eb80cc8..87e381b 100644 --- a/src/openvpn/ssl_verify_backend.h +++ b/src/openvpn/ssl_verify_backend.h @@ -33,7 +33,11 @@ /** * Result of verification function */ -typedef enum { SUCCESS =3D 0, FAILURE =3D 1 } result_t; +typedef enum +{ + SUCCESS =3D 0, + FAILURE =3D 1 +} result_t; /* * Backend support functions. @@ -95,8 +99,7 @@ * * @return a string containing the certificate fingerprint */ -struct buffer x509_get_sha1_fingerprint(openvpn_x509_cert_t *cert, - struct gc_arena *gc); +struct buffer x509_get_sha1_fingerprint(openvpn_x509_cert_t *cert, struct = gc_arena *gc); /** * Retrieve the certificate's SHA256 fingerprint. @@ -106,8 +109,7 @@ * * @return a string containing the certificate fingerprint */ -struct buffer x509_get_sha256_fingerprint(openvpn_x509_cert_t *cert, - struct gc_arena *gc); +struct buffer x509_get_sha256_fingerprint(openvpn_x509_cert_t *cert, struc= t gc_arena *gc); /* * Retrieve the certificate's username from the specified field. @@ -122,8 +124,8 @@ * * @return \c FAILURE, \c or SUCCESS */ -result_t backend_x509_get_username(char *common_name, int cn_len, - char *x509_username_field, openvpn_x509= _cert_t *peer_cert); +result_t backend_x509_get_username(char *common_name, int cn_len, char *x5= 09_username_field, + openvpn_x509_cert_t *peer_cert); #ifdef ENABLE_X509ALTUSERNAME /** @@ -158,8 +160,7 @@ * @return String representation of the certificate's serial = number * in hex notation, or NULL on error. */ -char *backend_x509_get_serial_hex(openvpn_x509_cert_t *cert, - struct gc_arena *gc); +char *backend_x509_get_serial_hex(openvpn_x509_cert_t *cert, struct gc_are= na *gc); /* * Write the certificate to the file in PEM format. @@ -169,8 +170,7 @@ * * @return \c FAILURE, \c or SUCCESS */ -result_t backend_x509_write_pem(openvpn_x509_cert_t *cert, - const char *filename); +result_t backend_x509_write_pem(openvpn_x509_cert_t *cert, const char *fil= ename); /* * Save X509 fields to environment, using the naming convention: @@ -194,8 +194,8 @@ * @param gc Garbage collection arena for temp data * */ -void x509_track_add(const struct x509_track **ll_head, const char *name, - int msglevel, struct gc_arena *gc); +void x509_track_add(const struct x509_track **ll_head, const char *name, i= nt msglevel, + struct gc_arena *gc); /* * Save X509 fields to environment, using the naming convention: @@ -217,8 +217,8 @@ * @param cert_depth Depth of the certificate * @param cert Certificate to set the environment for */ -void x509_setenv_track(const struct x509_track *xt, struct env_set *es, - const int depth, openvpn_x509_cert_t *x509); +void x509_setenv_track(const struct x509_track *xt, struct env_set *es, co= nst int depth, + openvpn_x509_cert_t *x509); /* * Check X.509 Netscape certificate type field, if available. diff --git a/src/openvpn/ssl_verify_mbedtls.c b/src/openvpn/ssl_verify_mbed= tls.c index 25ad09c..032d07d 100644 --- a/src/openvpn/ssl_verify_mbedtls.c +++ b/src/openvpn/ssl_verify_mbedtls.c @@ -47,10 +47,9 @@ #define MAX_SUBJECT_LENGTH 256 int -verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth, - uint32_t *flags) +verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth,= uint32_t *flags) { - struct tls_session *session =3D (struct tls_session *) session_obj; + struct tls_session *session =3D (struct tls_session *)session_obj; struct gc_arena gc =3D gc_new(); ASSERT(cert); @@ -72,8 +71,7 @@ * Clearing these flags relies on verify_cert will later rejecting= a * certificate that has no matching fingerprint. */ - uint32_t flags_ignore =3D MBEDTLS_X509_BADCERT_NOT_TRUSTED - | MBEDTLS_X509_BADCERT_EXPIRED + uint32_t flags_ignore =3D MBEDTLS_X509_BADCERT_NOT_TRUSTED | MBEDT= LS_X509_BADCERT_EXPIRED | MBEDTLS_X509_BADCERT_FUTURE; *flags =3D *flags & ~flags_ignore; } @@ -86,9 +84,10 @@ char *subject =3D x509_get_subject(cert, &gc); char *serial =3D backend_x509_get_serial(cert, &gc); - ret =3D mbedtls_x509_crt_verify_info(errstr, sizeof(errstr)-1, "",= *flags); - if (ret <=3D 0 && !snprintf(errstr, sizeof(errstr), - "Could not retrieve error string, flags= =3D%" PRIx32, *flags)) + ret =3D mbedtls_x509_crt_verify_info(errstr, sizeof(errstr) - 1, "= ", *flags); + if (ret <=3D 0 + && !snprintf(errstr, sizeof(errstr), "Could not retrieve error= string, flags=3D%" PRIx32, + *flags)) { errstr[0] =3D '\0'; } @@ -99,13 +98,15 @@ if (subject) { - msg(D_TLS_ERRORS, "VERIFY ERROR: depth=3D%d, subject=3D%s, ser= ial=3D%s: %s", - cert_depth, subject, serial ? serial : "", = errstr); + msg(D_TLS_ERRORS, "VERIFY ERROR: depth=3D%d, subject=3D%s, ser= ial=3D%s: %s", cert_depth, + subject, serial ? serial : "", errstr); } else { - msg(D_TLS_ERRORS, "VERIFY ERROR: depth=3D%d, (could not extrac= t X509 " - "subject string from certificate): %s", cert_depth, errstr= ); + msg(D_TLS_ERRORS, + "VERIFY ERROR: depth=3D%d, (could not extract X509 " + "subject string from certificate): %s", + cert_depth, errstr); } /* Leave flags set to non-zero to indicate that the cert is not ok= */ @@ -128,20 +129,18 @@ #endif result_t -backend_x509_get_username(char *cn, int cn_len, - char *x509_username_field, mbedtls_x509_crt *cer= t) +backend_x509_get_username(char *cn, int cn_len, char *x509_username_field,= mbedtls_x509_crt *cert) { mbedtls_x509_name *name; - ASSERT( cn !=3D NULL ); + ASSERT(cn !=3D NULL); name =3D &cert->subject; /* Find common name */ while (name !=3D NULL) { - if (0 =3D=3D memcmp(name->oid.p, MBEDTLS_OID_AT_CN, - MBEDTLS_OID_SIZE(MBEDTLS_OID_AT_CN))) + if (0 =3D=3D memcmp(name->oid.p, MBEDTLS_OID_AT_CN, MBEDTLS_OID_SI= ZE(MBEDTLS_OID_AT_CN))) { break; } @@ -158,13 +157,13 @@ /* Found, extract CN */ if (cn_len > name->val.len) { - memcpy( cn, name->val.p, name->val.len ); + memcpy(cn, name->val.p, name->val.len); cn[name->val.len] =3D '\0'; } else { - memcpy( cn, name->val.p, cn_len); - cn[cn_len-1] =3D '\0'; + memcpy(cn, name->val.p, cn_len); + cn[cn_len - 1] =3D '\0'; } return SUCCESS; @@ -179,8 +178,7 @@ /* Transform asn1 integer serial into mbed TLS MPI */ mbedtls_mpi_init(&serial_mpi); - if (!mbed_ok(mbedtls_mpi_read_binary(&serial_mpi, cert->serial.p, - cert->serial.len))) + if (!mbed_ok(mbedtls_mpi_read_binary(&serial_mpi, cert->serial.p, cert= ->serial.len))) { msg(M_WARN, "Failed to retrieve serial from certificate."); goto end; @@ -211,7 +209,7 @@ buf =3D gc_malloc(len, true, gc); - if (mbedtls_x509_serial_gets(buf, len-1, &cert->serial) < 0) + if (mbedtls_x509_serial_gets(buf, len - 1, &cert->serial) < 0) { buf =3D NULL; } @@ -235,7 +233,7 @@ struct buffer der =3D {}; buf_set_read(&der, cert->raw.p, cert->raw.len); - if (!crypto_pem_encode("CERTIFICATE", &pem, &der, &gc)) + if (!crypto_pem_encode("CERTIFICATE", &pem, &der, &gc)) { goto err; } @@ -248,15 +246,13 @@ gc_free(&gc); return SUCCESS; err: - msg(D_TLS_DEBUG_LOW, "Error writing X509 certificate to file %s", - filename); + msg(D_TLS_DEBUG_LOW, "Error writing X509 certificate to file %s", file= name); gc_free(&gc); return FAILURE; } static struct buffer -x509_get_fingerprint(const mbedtls_md_info_t *md_info, mbedtls_x509_crt *c= ert, - struct gc_arena *gc) +x509_get_fingerprint(const mbedtls_md_info_t *md_info, mbedtls_x509_crt *c= ert, struct gc_arena *gc) { const size_t md_size =3D mbedtls_md_get_size(md_info); struct buffer fingerprint =3D alloc_buf_gc(md_size, gc); @@ -268,26 +264,24 @@ struct buffer x509_get_sha1_fingerprint(mbedtls_x509_crt *cert, struct gc_arena *gc) { - return x509_get_fingerprint(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), - cert, gc); + return x509_get_fingerprint(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1)= , cert, gc); } struct buffer x509_get_sha256_fingerprint(mbedtls_x509_crt *cert, struct gc_arena *gc) { - return x509_get_fingerprint(mbedtls_md_info_from_type(MBEDTLS_MD_SHA25= 6), - cert, gc); + return x509_get_fingerprint(mbedtls_md_info_from_type(MBEDTLS_MD_SHA25= 6), cert, gc); } char * x509_get_subject(mbedtls_x509_crt *cert, struct gc_arena *gc) { - char tmp_subject[MAX_SUBJECT_LENGTH] =3D {0}; + char tmp_subject[MAX_SUBJECT_LENGTH] =3D { 0 }; char *subject =3D NULL; int ret =3D 0; - ret =3D mbedtls_x509_dn_gets( tmp_subject, MAX_SUBJECT_LENGTH-1, &cert= ->subject ); + ret =3D mbedtls_x509_dn_gets(tmp_subject, MAX_SUBJECT_LENGTH - 1, &cer= t->subject); if (ret > 0) { /* Allocate the required space for the subject */ @@ -306,7 +300,7 @@ string_mod(value, CC_ANY, CC_CRLF, '?'); msg(D_X509_ATTR, "X509 ATTRIBUTE name=3D'%s' value=3D'%s' depth=3D%d",= name, value, depth); name_expand_size =3D 64 + strlen(name); - name_expand =3D (char *) malloc(name_expand_size); + name_expand =3D (char *)malloc(name_expand_size); check_malloc_return(name_expand); snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, name); setenv_str(es, name_expand, value); @@ -319,8 +313,7 @@ size_t i; char *val; - if (!(orig->tag =3D=3D MBEDTLS_ASN1_UTF8_STRING - || orig->tag =3D=3D MBEDTLS_ASN1_PRINTABLE_STRING + if (!(orig->tag =3D=3D MBEDTLS_ASN1_UTF8_STRING || orig->tag =3D=3D MB= EDTLS_ASN1_PRINTABLE_STRING || orig->tag =3D=3D MBEDTLS_ASN1_IA5_STRING)) { /* Only support C-string compatible types */ @@ -334,15 +327,15 @@ return string_alloc("ERROR: embedded null value", gc); } } - val =3D gc_malloc(orig->len+1, false, gc); + val =3D gc_malloc(orig->len + 1, false, gc); memcpy(val, orig->p, orig->len); val[orig->len] =3D '\0'; return val; } static void -do_setenv_name(struct env_set *es, const struct x509_track *xt, - const mbedtls_x509_crt *cert, int depth, struct gc_arena *g= c) +do_setenv_name(struct env_set *es, const struct x509_track *xt, const mbed= tls_x509_crt *cert, + int depth, struct gc_arena *gc) { const mbedtls_x509_name *xn; for (xn =3D &cert->subject; xn !=3D NULL; xn =3D xn->next) @@ -358,7 +351,8 @@ } void -x509_track_add(const struct x509_track **ll_head, const char *name, int ms= glevel, struct gc_arena *gc) +x509_track_add(const struct x509_track **ll_head, const char *name, int ms= glevel, + struct gc_arena *gc) { struct x509_track *xt; ALLOC_OBJ_CLEAR_GC(xt, struct x509_track, gc); @@ -373,8 +367,8 @@ } void -x509_setenv_track(const struct x509_track *xt, struct env_set *es, - const int depth, mbedtls_x509_crt *cert) +x509_setenv_track(const struct x509_track *xt, struct env_set *es, const i= nt depth, + mbedtls_x509_crt *cert) { struct gc_arena gc =3D gc_new(); while (xt) @@ -396,8 +390,8 @@ cert_hash =3D x509_get_sha256_fingerprint(cert, &gc); } - fingerprint =3D format_hex_ex(BPTR(&cert_hash), - BLEN(&cert_hash), 0, 1 | FHE_C= APS, ":", &gc); + fingerprint =3D + format_hex_ex(BPTR(&cert_hash), BLEN(&cert_hash), 0, 1= | FHE_CAPS, ":", &gc); do_setenv_x509(es, xt->name, fingerprint, depth); } else @@ -427,29 +421,27 @@ while (name !=3D NULL) { - char name_expand[64+8]; + char name_expand[64 + 8]; const char *shortname; - if (0 =3D=3D mbedtls_oid_get_attr_short_name(&name->oid, &shortnam= e) ) + if (0 =3D=3D mbedtls_oid_get_attr_short_name(&name->oid, &shortnam= e)) { - snprintf(name_expand, sizeof(name_expand), "X509_%d_%s", - cert_depth, shortname); + snprintf(name_expand, sizeof(name_expand), "X509_%d_%s", cert_= depth, shortname); } else { - snprintf(name_expand, sizeof(name_expand), "X509_%d_\?\?", - cert_depth); + snprintf(name_expand, sizeof(name_expand), "X509_%d_\?\?", cer= t_depth); } for (i =3D 0; i < name->val.len; i++) { - if (i >=3D (int) sizeof( s ) - 1) + if (i >=3D (int)sizeof(s) - 1) { break; } c =3D name->val.p[i]; - if (c < 32 || c =3D=3D 127 || ( c > 128 && c < 160 ) ) + if (c < 32 || c =3D=3D 127 || (c > 128 && c < 160)) { s[i] =3D '?'; } @@ -483,15 +475,13 @@ } result_t -x509_verify_cert_ku(mbedtls_x509_crt *cert, const unsigned *const expected= _ku, - int expected_len) +x509_verify_cert_ku(mbedtls_x509_crt *cert, const unsigned *const expected= _ku, int expected_len) { msg(D_HANDSHAKE, "Validating certificate key usage"); if (!mbedtls_x509_crt_has_ext_type(cert, MBEDTLS_X509_EXT_KEY_USAGE)) { - msg(D_TLS_ERRORS, - "ERROR: Certificate does not have key usage extension"); + msg(D_TLS_ERRORS, "ERROR: Certificate does not have key usage exte= nsion"); return FAILURE; } @@ -502,10 +492,9 @@ } result_t fFound =3D FAILURE; - for (size_t i =3D 0; SUCCESS !=3D fFound && i"); + X509_verify_cert_error_string(X509_STORE_CTX_get_error(ctx)), = subject, + serial ? serial : ""); ERR_clear_error(); @@ -121,8 +120,7 @@ return nid =3D=3D NID_subject_alt_name || nid =3D=3D NID_issuer_alt_na= me; } -static -bool +static bool extract_x509_extension(X509 *cert, char *fieldname, char *out, int size) { bool retval =3D false; @@ -130,8 +128,7 @@ if (!x509_username_field_ext_supported(fieldname)) { - msg(D_TLS_ERRORS, - "ERROR: --x509-username-field 'ext:%s' not supported", fieldna= me); + msg(D_TLS_ERRORS, "ERROR: --x509-username-field 'ext:%s' not suppo= rted", fieldname); return false; } @@ -149,10 +146,10 @@ numalts =3D sk_GENERAL_NAME_num(extensions); /* loop through all alternatives */ - for (i =3D 0; itype) { @@ -175,8 +172,8 @@ break; default: - msg(D_TLS_DEBUG, "%s: ignoring general name field type= %i", - __func__, name->type); + msg(D_TLS_DEBUG, "%s: ignoring general name field type= %i", __func__, + name->type); break; } } @@ -199,8 +196,7 @@ * to contain result is grounds for error). */ static result_t -extract_x509_field_ssl(X509_NAME *x509, const char *field_name, char *out, - int size) +extract_x509_field_ssl(X509_NAME *x509, const char *field_name, char *out,= int size) { int lastpos =3D -1; int tmp =3D -1; @@ -257,13 +253,12 @@ } result_t -backend_x509_get_username(char *common_name, int cn_len, - char *x509_username_field, X509 *peer_cert) +backend_x509_get_username(char *common_name, int cn_len, char *x509_userna= me_field, X509 *peer_cert) { #ifdef ENABLE_X509ALTUSERNAME if (strncmp("ext:", x509_username_field, 4) =3D=3D 0) { - if (!extract_x509_extension(peer_cert, x509_username_field+4, comm= on_name, cn_len)) + if (!extract_x509_extension(peer_cert, x509_username_field + 4, co= mmon_name, cn_len)) { return FAILURE; } @@ -272,10 +267,9 @@ { ASN1_INTEGER *asn1_i =3D X509_get_serialNumber(peer_cert); struct gc_arena gc =3D gc_new(); - char *serial =3D format_hex_ex(asn1_i->data, asn1_i->length, - 0, 1 | FHE_CAPS, NULL, &gc); + char *serial =3D format_hex_ex(asn1_i->data, asn1_i->length, 0, 1 = | FHE_CAPS, NULL, &gc); - if (!serial || cn_len <=3D strlen(serial)+2) + if (!serial || cn_len <=3D strlen(serial) + 2) { gc_free(&gc); return FAILURE; @@ -285,11 +279,12 @@ } else #endif /* ifdef ENABLE_X509ALTUSERNAME */ - if (FAILURE =3D=3D extract_x509_field_ssl(X509_get_subject_name(peer_c= ert), - x509_username_field, common_name= , cn_len)) - { - return FAILURE; - } + if (FAILURE + =3D=3D extract_x509_field_ssl(X509_get_subject_name(peer_cert)= , x509_username_field, + common_name, cn_len)) + { + return FAILURE; + } return SUCCESS; } @@ -339,8 +334,7 @@ return SUCCESS; err: BIO_free(out); - crypto_msg(D_TLS_DEBUG_LOW, "Error writing X509 certificate to file %s= ", - filename); + crypto_msg(D_TLS_DEBUG_LOW, "Error writing X509 certificate to file %s= ", filename); return FAILURE; } @@ -377,9 +371,9 @@ goto err; } - X509_NAME_print_ex(subject_bio, X509_get_subject_name(cert), - 0, XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN - |ASN1_STRFLGS_UTF8_CONVERT | ASN1_STRFLGS_ESC_CTRL); + X509_NAME_print_ex(subject_bio, X509_get_subject_name(cert), 0, + XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN | ASN1_STRFLG= S_UTF8_CONVERT + | ASN1_STRFLGS_ESC_CTRL); if (BIO_eof(subject_bio)) { @@ -421,7 +415,8 @@ */ void -x509_track_add(const struct x509_track **ll_head, const char *name, int ms= glevel, struct gc_arena *gc) +x509_track_add(const struct x509_track **ll_head, const char *name, int ms= glevel, + struct gc_arena *gc) { struct x509_track *xt; ALLOC_OBJ_CLEAR_GC(xt, struct x509_track, gc); @@ -453,7 +448,7 @@ string_mod(value, CC_ANY, CC_CRLF, '?'); msg(D_X509_ATTR, "X509 ATTRIBUTE name=3D'%s' value=3D'%s' depth=3D%d",= name, value, depth); name_expand_size =3D 64 + strlen(name); - name_expand =3D (char *) malloc(name_expand_size); + name_expand =3D (char *)malloc(name_expand_size); check_malloc_return(name_expand); snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, name); setenv_str(es, name_expand, value); @@ -488,8 +483,7 @@ fp_buf =3D x509_get_sha256_fingerprint(x509, &gc); } - fp_str =3D format_hex_ex(BPTR(&fp_buf), BLEN(&fp_buf),= 0, - 1 | FHE_CAPS, ":", &gc); + fp_str =3D format_hex_ex(BPTR(&fp_buf), BLEN(&fp_buf),= 0, 1 | FHE_CAPS, ":", &gc); do_setenv_x509(es, xt->name, fp_str, depth); } break; @@ -596,10 +590,9 @@ continue; } name_expand_size =3D 64 + strlen(objbuf); - name_expand =3D (char *) malloc(name_expand_size); + name_expand =3D (char *)malloc(name_expand_size); check_malloc_return(name_expand); - snprintf(name_expand, name_expand_size, "X509_%d_%s", cert_depth, - objbuf); + snprintf(name_expand, name_expand_size, "X509_%d_%s", cert_depth, = objbuf); string_mod(name_expand, CC_PRINT, CC_CRLF, '_'); string_mod((char *)buf, CC_PRINT, CC_CRLF, '_'); setenv_str_incr(es, name_expand, (char *)buf); @@ -621,8 +614,8 @@ * Unfortunately, X509_check_purpose() does some weird thing that * prevent it to take a const argument */ - result_t result =3D X509_check_purpose(peer_cert, X509_PURPOSE_SSL= _CLIENT, 0) ? - SUCCESS : FAILURE; + result_t result =3D + X509_check_purpose(peer_cert, X509_PURPOSE_SSL_CLIENT, 0) ? SU= CCESS : FAILURE; /* * old versions of OpenSSL allow us to make the less strict check = we used to @@ -637,7 +630,7 @@ if (result =3D=3D SUCCESS) { msg(M_WARN, "X509: Certificate is a client certificate yet= it's purpose " - "cannot be verified (check may fail in the future)"); + "cannot be verified (check may fail in the fut= ure)"); } ASN1_BIT_STRING_free(ns); } @@ -649,8 +642,8 @@ * Unfortunately, X509_check_purpose() does some weird thing that * prevent it to take a const argument */ - result_t result =3D X509_check_purpose(peer_cert, X509_PURPOSE_SSL= _SERVER, 0) ? - SUCCESS : FAILURE; + result_t result =3D + X509_check_purpose(peer_cert, X509_PURPOSE_SSL_SERVER, 0) ? SU= CCESS : FAILURE; /* * old versions of OpenSSL allow us to make the less strict check = we used to @@ -665,7 +658,7 @@ if (result =3D=3D SUCCESS) { msg(M_WARN, "X509: Certificate is a server certificate yet= it's purpose " - "cannot be verified (check may fail in the future)"); + "cannot be verified (check may fail in the fut= ure)"); } ASN1_BIT_STRING_free(ns); } @@ -676,8 +669,7 @@ } result_t -x509_verify_cert_ku(X509 *x509, const unsigned *const expected_ku, - int expected_len) +x509_verify_cert_ku(X509 *x509, const unsigned *const expected_ku, int exp= ected_len) { ASN1_BIT_STRING *ku =3D X509_get_ext_d2i(x509, NID_key_usage, NULL, NU= LL); @@ -723,8 +715,7 @@ if (fFound !=3D SUCCESS) { - msg(D_TLS_ERRORS, - "ERROR: Certificate has key usage %04x, expected one of:", nku= ); + msg(D_TLS_ERRORS, "ERROR: Certificate has key usage %04x, expected= one of:", nku); for (size_t i =3D 0; i < expected_len && expected_ku[i]; i++) { msg(D_TLS_ERRORS, " * %04x", expected_ku[i]); @@ -742,8 +733,7 @@ EXTENDED_KEY_USAGE *eku =3D NULL; result_t fFound =3D FAILURE; - if ((eku =3D (EXTENDED_KEY_USAGE *) X509_get_ext_d2i(x509, NID_ext_key= _usage, - NULL, NULL)) =3D=3D= NULL) + if ((eku =3D (EXTENDED_KEY_USAGE *)X509_get_ext_d2i(x509, NID_ext_key_= usage, NULL, NULL)) =3D=3D NULL) { msg(D_HANDSHAKE, "Certificate does not have extended key usage ext= ension"); } @@ -759,8 +749,8 @@ if (SUCCESS !=3D fFound && OBJ_obj2txt(szOid, sizeof(szOid), o= id, 0) !=3D -1) { - msg(D_HANDSHAKE, "++ Certificate has EKU (str) %s, expects= %s", - szOid, expected_oid); + msg(D_HANDSHAKE, "++ Certificate has EKU (str) %s, expects= %s", szOid, + expected_oid); if (!strcmp(expected_oid, szOid)) { fFound =3D SUCCESS; @@ -768,8 +758,8 @@ } if (SUCCESS !=3D fFound && OBJ_obj2txt(szOid, sizeof(szOid), o= id, 1) !=3D -1) { - msg(D_HANDSHAKE, "++ Certificate has EKU (oid) %s, expects= %s", - szOid, expected_oid); + msg(D_HANDSHAKE, "++ Certificate has EKU (oid) %s, expects= %s", szOid, + expected_oid); if (!strcmp(expected_oid, szOid)) { fFound =3D SUCCESS; diff --git a/src/openvpn/status.c b/src/openvpn/status.c index 4b0e516..83300ff 100644 --- a/src/openvpn/status.c +++ b/src/openvpn/status.c @@ -49,7 +49,7 @@ case STATUS_OUTPUT_READ: return "READ"; - case STATUS_OUTPUT_READ|STATUS_OUTPUT_WRITE: + case STATUS_OUTPUT_READ | STATUS_OUTPUT_WRITE: return "READ/WRITE"; default: @@ -58,11 +58,8 @@ } struct status_output * -status_open(const char *filename, - const int refresh_freq, - const int msglevel, - const struct virtual_output *vout, - const unsigned int flags) +status_open(const char *filename, const int refresh_freq, const int msglev= el, + const struct virtual_output *vout, const unsigned int flags) { struct status_output *so =3D NULL; if (filename || msglevel >=3D 0 || vout) @@ -79,21 +76,16 @@ switch (so->flags) { case STATUS_OUTPUT_WRITE: - so->fd =3D platform_open(filename, - O_CREAT | O_TRUNC | O_WRONLY, - S_IRUSR | S_IWUSR); + so->fd =3D + platform_open(filename, O_CREAT | O_TRUNC | O_WRON= LY, S_IRUSR | S_IWUSR); break; case STATUS_OUTPUT_READ: - so->fd =3D platform_open(filename, - O_RDONLY, - S_IRUSR | S_IWUSR); + so->fd =3D platform_open(filename, O_RDONLY, S_IRUSR |= S_IWUSR); break; - case STATUS_OUTPUT_READ|STATUS_OUTPUT_WRITE: - so->fd =3D platform_open(filename, - O_CREAT | O_RDWR, - S_IRUSR | S_IWUSR); + case STATUS_OUTPUT_READ | STATUS_OUTPUT_WRITE: + so->fd =3D platform_open(filename, O_CREAT | O_RDWR, S= _IRUSR | S_IWUSR); break; default: @@ -168,10 +160,10 @@ } #elif defined(HAVE_CHSIZE) { - const long off =3D (long) lseek(so->fd, (off_t)0, SEEK_CUR); + const long off =3D (long)lseek(so->fd, (off_t)0, SEEK_CUR); chsize(so->fd, off); } -#else /* if defined(HAVE_FTRUNCATE) */ +#else /* if defined(HAVE_FTRUNCATE) */ #warning both ftruncate and chsize functions appear to be missing from thi= s OS #endif @@ -223,7 +215,7 @@ { if (so && (so->flags & STATUS_OUTPUT_WRITE)) { - char buf[STATUS_PRINTF_MAXLEN+2]; /* leave extra bytes for CR, LF = */ + char buf[STATUS_PRINTF_MAXLEN + 2]; /* leave extra bytes for CR, L= F */ va_list arglist; int stat; diff --git a/src/openvpn/status.h b/src/openvpn/status.h index eaed22a..292e63a 100644 --- a/src/openvpn/status.h +++ b/src/openvpn/status.h @@ -29,10 +29,11 @@ /* * virtual function interface for status output */ -struct virtual_output { +struct virtual_output +{ void *arg; unsigned int flags_default; - void (*func) (void *arg, const unsigned int flags, const char *str); + void (*func)(void *arg, const unsigned int flags, const char *str); }; static inline void @@ -47,8 +48,8 @@ struct status_output { -#define STATUS_OUTPUT_READ (1<<0) -#define STATUS_OUTPUT_WRITE (1<<1) +#define STATUS_OUTPUT_READ (1 << 0) +#define STATUS_OUTPUT_WRITE (1 << 1) unsigned int flags; char *filename; @@ -63,11 +64,8 @@ bool errors; }; -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 status_output *status_open(const char *filename, const int refresh_= freq, const int msglevel, + const struct virtual_output *vout, const= unsigned int flags); bool status_trigger(struct status_output *so); @@ -80,12 +78,12 @@ void status_printf(struct status_output *so, const char *format, ...) #ifdef __GNUC__ #if __USE_MINGW_ANSI_STDIO -__attribute__ ((format(gnu_printf, 2, 3))) + __attribute__((format(gnu_printf, 2, 3))) #else -__attribute__ ((format(__printf__, 2, 3))) + __attribute__((format(__printf__, 2, 3))) #endif #endif -; + ; bool status_read(struct status_output *so, struct buffer *buf); diff --git a/src/openvpn/syshead.h b/src/openvpn/syshead.h index 00d7685..9b87214 100644 --- a/src/openvpn/syshead.h +++ b/src/openvpn/syshead.h @@ -29,20 +29,20 @@ /* branch prediction hints */ #if defined(__GNUC__) -#define likely(x) __builtin_expect((x), 1) -#define unlikely(x) __builtin_expect((x), 0) +#define likely(x) __builtin_expect((x), 1) +#define unlikely(x) __builtin_expect((x), 0) #else -#define likely(x) (x) -#define unlikely(x) (x) +#define likely(x) (x) +#define unlikely(x) (x) #endif #ifdef _WIN32 #include #include #include -#define sleep(x) Sleep((x)*1000) -#define random rand -#define srandom srand +#define sleep(x) Sleep((x) * 1000) +#define random rand +#define srandom srand #endif #ifdef _MSC_VER /* Visual Studio */ @@ -52,7 +52,7 @@ #if defined(__APPLE__) #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >=3D 1070 -#define __APPLE_USE_RFC_3542 1 +#define __APPLE_USE_RFC_3542 1 #endif #endif @@ -167,10 +167,10 @@ #endif #if defined(TARGET_HAIKU) -#include /* uint32, etc */ -#include /* ifconf etc */ -#include /* SIOCGRTTABLE, etc */ -#endif /* TARGET_HAIKU */ +#include /* uint32, etc */ +#include /* ifconf etc */ +#include /* SIOCGRTTABLE, etc */ +#endif /* TARGET_HAIKU */ #ifdef HAVE_ARPA_INET_H #include @@ -184,7 +184,7 @@ #include #endif -#if defined(TARGET_LINUX) || defined (TARGET_ANDROID) +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) #ifdef HAVE_LINUX_IF_TUN_H #include @@ -374,7 +374,9 @@ * Does this platform support linux-style IP_PKTINFO * or bsd-style IP_RECVDSTADDR ? */ -#if ((defined(HAVE_IN_PKTINFO) && defined(IP_PKTINFO)) || defined(IP_RECVD= STADDR)) && defined(HAVE_MSGHDR) && defined(HAVE_CMSGHDR) && defined(CMSG_F= IRSTHDR) && defined(CMSG_NXTHDR) && defined(HAVE_RECVMSG) && defined(HAVE_S= ENDMSG) +#if ((defined(HAVE_IN_PKTINFO) && defined(IP_PKTINFO)) || defined(IP_RECVD= STADDR)) \ + && defined(HAVE_MSGHDR) && defined(HAVE_CMSGHDR) && defined(CMSG_FIRST= HDR) \ + && defined(CMSG_NXTHDR) && defined(HAVE_RECVMSG) && defined(HAVE_SENDM= SG) #define ENABLE_IP_PKTINFO 1 #else #define ENABLE_IP_PKTINFO 0 @@ -423,10 +425,10 @@ * Directory separation char */ #ifdef _WIN32 -#define PATH_SEPARATOR '\\' +#define PATH_SEPARATOR '\\' #define PATH_SEPARATOR_STR "\\" #else -#define PATH_SEPARATOR '/' +#define PATH_SEPARATOR '/' #define PATH_SEPARATOR_STR "/" #endif @@ -435,11 +437,11 @@ */ #ifdef _WIN32 #define SOCKET_UNDEFINED (INVALID_SOCKET) -#define SOCKET_PRINTF "%" PRIxPTR +#define SOCKET_PRINTF "%" PRIxPTR typedef SOCKET socket_descriptor_t; #else #define SOCKET_UNDEFINED (-1) -#define SOCKET_PRINTF "%d" +#define SOCKET_PRINTF "%d" typedef int socket_descriptor_t; #endif @@ -460,7 +462,9 @@ /* * HTTPS port sharing capability */ -#if defined(ENABLE_PORT_SHARE) && defined(SCM_RIGHTS) && defined(HAVE_MSGH= DR) && defined(HAVE_CMSGHDR) && defined(CMSG_FIRSTHDR) && defined(CMSG_NXTH= DR) && defined(HAVE_RECVMSG) && defined(HAVE_SENDMSG) +#if defined(ENABLE_PORT_SHARE) && defined(SCM_RIGHTS) && defined(HAVE_MSGH= DR) \ + && defined(HAVE_CMSGHDR) && defined(CMSG_FIRSTHDR) && defined(CMSG_NXT= HDR) \ + && defined(HAVE_RECVMSG) && defined(HAVE_SENDMSG) #define PORT_SHARE 1 #else #define PORT_SHARE 0 @@ -494,8 +498,7 @@ /* * Do we have CryptoAPI capability? */ -#if defined(_WIN32) && defined(ENABLE_CRYPTO_OPENSSL) \ - && !defined(ENABLE_CRYPTO_WOLFSSL) +#if defined(_WIN32) && defined(ENABLE_CRYPTO_OPENSSL) && !defined(ENABLE_C= RYPTO_WOLFSSL) #define ENABLE_CRYPTOAPI #endif @@ -522,8 +525,7 @@ /* * Compression support */ -#if defined(ENABLE_LZO) || defined(ENABLE_LZ4) \ - || defined(ENABLE_COMP_STUB) +#if defined(ENABLE_LZO) || defined(ENABLE_LZ4) || defined(ENABLE_COMP_STUB) #define USE_COMP #endif diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c index 67e19382..f7f530c 100644 --- a/src/openvpn/tls_crypt.c +++ b/src/openvpn/tls_crypt.c @@ -41,9 +41,9 @@ const char *tls_crypt_v2_srv_pem_name =3D "OpenVPN tls-crypt-v2 server key= "; /** Metadata contains user-specified data */ -static const uint8_t TLS_CRYPT_METADATA_TYPE_USER =3D 0x00; +static const uint8_t TLS_CRYPT_METADATA_TYPE_USER =3D 0x00; /** Metadata contains a 64-bit unix timestamp in network byte order */ -static const uint8_t TLS_CRYPT_METADATA_TYPE_TIMESTAMP =3D 0x01; +static const uint8_t TLS_CRYPT_METADATA_TYPE_TIMESTAMP =3D 0x01; static struct key_type tls_crypt_kt(void) @@ -58,11 +58,10 @@ } void -tls_crypt_init_key(struct key_ctx_bi *key, struct key2 *keydata, - const char *key_file, bool key_inline, bool tls_server) +tls_crypt_init_key(struct key_ctx_bi *key, struct key2 *keydata, const cha= r *key_file, + bool key_inline, bool tls_server) { - const int key_direction =3D tls_server ? - KEY_DIRECTION_NORMAL : KEY_DIRECTION_INVERSE; + const int key_direction =3D tls_server ? KEY_DIRECTION_NORMAL : KEY_DI= RECTION_INVERSE; struct key_type kt =3D tls_crypt_kt(); if (!kt.cipher || !kt.digest) { @@ -90,7 +89,6 @@ { key->keys[k].hmac[j] =3D key->keys[k].hmac[j] ^ other->keys[k]= .hmac[j]; } - } } @@ -99,8 +97,8 @@ { struct key2 rengokeys; if (!key_state_export_keying_material(session, EXPORT_DYNAMIC_TLS_CRYP= T_LABEL, - strlen(EXPORT_DYNAMIC_TLS_CRYPT_= LABEL), - rengokeys.keys, sizeof(rengokeys= .keys))) + strlen(EXPORT_DYNAMIC_TLS_CRYPT_= LABEL), rengokeys.keys, + sizeof(rengokeys.keys))) { return false; } @@ -112,27 +110,23 @@ session->tls_wrap_reneg.work =3D alloc_buf(BUF_SIZE(&session->opt->fra= me)); session->tls_wrap_reneg.opt.pid_persist =3D NULL; - packet_id_init(&session->tls_wrap_reneg.opt.packet_id, - session->opt->replay_window, - session->opt->replay_time, - "TLS_WRAP_RENEG", session->key_id); + packet_id_init(&session->tls_wrap_reneg.opt.packet_id, session->opt->r= eplay_window, + session->opt->replay_time, "TLS_WRAP_RENEG", session->k= ey_id); - if (session->tls_wrap.mode =3D=3D TLS_WRAP_CRYPT - || session->tls_wrap.mode =3D=3D TLS_WRAP_AUTH) + if (session->tls_wrap.mode =3D=3D TLS_WRAP_CRYPT || session->tls_wrap.= mode =3D=3D TLS_WRAP_AUTH) { xor_key2(&rengokeys, &session->tls_wrap.original_wrap_keydata); } - const int key_direction =3D session->opt->server ? - KEY_DIRECTION_NORMAL : KEY_DIRECTION_INVERSE; + const int key_direction =3D session->opt->server ? KEY_DIRECTION_NORMA= L : KEY_DIRECTION_INVERSE; struct key_direction_state kds; key_direction_state_init(&kds, key_direction); struct key_type kt =3D tls_crypt_kt(); - init_key_ctx_bi(&session->tls_wrap_reneg.opt.key_ctx_bi, &rengokeys, k= ey_direction, - &kt, "dynamic tls-crypt"); + init_key_ctx_bi(&session->tls_wrap_reneg.opt.key_ctx_bi, &rengokeys, k= ey_direction, &kt, + "dynamic tls-crypt"); secure_memzero(&rengokeys, sizeof(rengokeys)); return true; @@ -140,8 +134,7 @@ bool -tls_crypt_wrap(const struct buffer *src, struct buffer *dst, - struct crypto_options *opt) +tls_crypt_wrap(const struct buffer *src, struct buffer *dst, struct crypto= _options *opt) { const struct key_ctx *ctx =3D &opt->key_ctx_bi.encrypt; struct gc_arena gc; @@ -150,12 +143,11 @@ ASSERT(ctx->cipher); ASSERT(ctx->hmac); ASSERT(packet_id_initialized(&opt->packet_id)); - ASSERT(hmac_ctx_size(ctx->hmac) =3D=3D 256/8); + ASSERT(hmac_ctx_size(ctx->hmac) =3D=3D 256 / 8); gc_init(&gc); - dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP FROM: %s", - format_hex(BPTR(src), BLEN(src), 80, &gc)); + dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP FROM: %s", format_hex(BPTR(src)= , BLEN(src), 80, &gc)); /* Get packet ID */ if (!packet_id_write(&opt->packet_id.send, dst, true, false)) @@ -164,15 +156,15 @@ goto err; } - dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP AD: %s", - format_hex(BPTR(dst), BLEN(dst), 0, &gc)); + dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP AD: %s", format_hex(BPTR(dst), = BLEN(dst), 0, &gc)); /* Buffer overflow check */ if (!buf_safe(dst, BLEN(src) + TLS_CRYPT_BLOCK_SIZE + TLS_CRYPT_TAG_SI= ZE)) { - msg(D_CRYPT_ERRORS, "TLS-CRYPT WRAP: buffer size error, " - "sc=3D%d so=3D%d sl=3D%d dc=3D%d do=3D%d dl=3D%d", src->capaci= ty, src->offset, - src->len, dst->capacity, dst->offset, dst->len); + msg(D_CRYPT_ERRORS, + "TLS-CRYPT WRAP: buffer size error, " + "sc=3D%d so=3D%d sl=3D%d dc=3D%d do=3D%d dl=3D%d", + src->capacity, src->offset, src->len, dst->capacity, dst->offs= et, dst->len); goto err; } @@ -196,15 +188,13 @@ /* Encrypt src */ { int outlen =3D 0; - ASSERT(cipher_ctx_update(ctx->cipher, BEND(dst), &outlen, - BPTR(src), BLEN(src))); + ASSERT(cipher_ctx_update(ctx->cipher, BEND(dst), &outlen, BPTR(src= ), BLEN(src))); ASSERT(buf_inc_len(dst, outlen)); ASSERT(cipher_ctx_final(ctx->cipher, BPTR(dst), &outlen)); ASSERT(buf_inc_len(dst, outlen)); } - dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP TO: %s", - format_hex(BPTR(dst), BLEN(dst), 80, &gc)); + dmsg(D_PACKET_CONTENT, "TLS-CRYPT WRAP TO: %s", format_hex(BPTR(dst), = BLEN(dst), 80, &gc)); gc_free(&gc); return true; @@ -217,8 +207,7 @@ } bool -tls_crypt_unwrap(const struct buffer *src, struct buffer *dst, - struct crypto_options *opt) +tls_crypt_unwrap(const struct buffer *src, struct buffer *dst, struct cryp= to_options *opt) { static const char error_prefix[] =3D "tls-crypt unwrap error"; const struct key_ctx *ctx =3D &opt->key_ctx_bi.decrypt; @@ -229,11 +218,9 @@ ASSERT(opt); ASSERT(src->len > 0); ASSERT(ctx->cipher); - ASSERT(packet_id_initialized(&opt->packet_id) - || (opt->flags & CO_IGNORE_PACKET_ID)); + ASSERT(packet_id_initialized(&opt->packet_id) || (opt->flags & CO_IGNO= RE_PACKET_ID)); - dmsg(D_PACKET_CONTENT, "TLS-CRYPT UNWRAP FROM: %s", - format_hex(BPTR(src), BLEN(src), 80, &gc)); + dmsg(D_PACKET_CONTENT, "TLS-CRYPT UNWRAP FROM: %s", format_hex(BPTR(sr= c), BLEN(src), 80, &gc)); if (buf_len(src) < TLS_CRYPT_OFF_CT) { @@ -254,8 +241,8 @@ { CRYPT_ERROR("cipher reset failed"); } - if (!cipher_ctx_update(ctx->cipher, BPTR(dst), &outlen, - BPTR(src) + TLS_CRYPT_OFF_CT, BLEN(src) - T= LS_CRYPT_OFF_CT)) + if (!cipher_ctx_update(ctx->cipher, BPTR(dst), &outlen, BPTR(src) = + TLS_CRYPT_OFF_CT, + BLEN(src) - TLS_CRYPT_OFF_CT)) { CRYPT_ERROR("cipher update failed"); } @@ -284,10 +271,8 @@ if (memcmp_constant_time(tag, tag_check, sizeof(tag_check))) { - dmsg(D_CRYPTO_DEBUG, "tag : %s", - format_hex(tag, sizeof(tag_check), 0, &gc)); - dmsg(D_CRYPTO_DEBUG, "tag_check: %s", - format_hex(tag_check, sizeof(tag_check), 0, &gc)); + dmsg(D_CRYPTO_DEBUG, "tag : %s", format_hex(tag, sizeof(t= ag_check), 0, &gc)); + dmsg(D_CRYPTO_DEBUG, "tag_check: %s", format_hex(tag_check, si= zeof(tag_check), 0, &gc)); CRYPT_ERROR("packet authentication failed"); } } @@ -316,30 +301,24 @@ } static inline void -tls_crypt_v2_load_client_key(struct key_ctx_bi *key, const struct key2 *ke= y2, - bool tls_server) +tls_crypt_v2_load_client_key(struct key_ctx_bi *key, const struct key2 *ke= y2, bool tls_server) { - const int key_direction =3D tls_server ? - KEY_DIRECTION_NORMAL : KEY_DIRECTION_INVERSE; + const int key_direction =3D tls_server ? KEY_DIRECTION_NORMAL : KEY_DI= RECTION_INVERSE; struct key_type kt =3D tls_crypt_kt(); if (!kt.cipher || !kt.digest) { msg(M_FATAL, "ERROR: --tls-crypt-v2 not supported"); } - init_key_ctx_bi(key, key2, key_direction, &kt, - "Control Channel Encryption"); + init_key_ctx_bi(key, key2, key_direction, &kt, "Control Channel Encryp= tion"); } void tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *original= _key, - struct buffer *wkc_buf, const char *key_file, - bool key_inline) + struct buffer *wkc_buf, const char *key_file,= bool key_inline) { - struct buffer client_key =3D alloc_buf(TLS_CRYPT_V2_CLIENT_KEY_LEN - + TLS_CRYPT_V2_MAX_WKC_LEN); + struct buffer client_key =3D alloc_buf(TLS_CRYPT_V2_CLIENT_KEY_LEN + T= LS_CRYPT_V2_MAX_WKC_LEN); - if (!read_pem_key_file(&client_key, tls_crypt_v2_cli_pem_name, - key_file, key_inline)) + if (!read_pem_key_file(&client_key, tls_crypt_v2_cli_pem_name, key_fil= e, key_inline)) { msg(M_FATAL, "ERROR: invalid tls-crypt-v2 client key format"); } @@ -357,15 +336,14 @@ } void -tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, bool encrypt, - const char *key_file, bool key_inline) +tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, bool encrypt, const = char *key_file, + bool key_inline) { struct key srv_key; struct buffer srv_key_buf; buf_set_write(&srv_key_buf, (void *)&srv_key, sizeof(srv_key)); - if (!read_pem_key_file(&srv_key_buf, tls_crypt_v2_srv_pem_name, - key_file, key_inline)) + if (!read_pem_key_file(&srv_key_buf, tls_crypt_v2_srv_pem_name, key_fi= le, key_inline)) { msg(M_FATAL, "ERROR: invalid tls-crypt-v2 server key format"); } @@ -384,14 +362,13 @@ } static bool -tls_crypt_v2_wrap_client_key(struct buffer *wkc, - const struct key2 *src_key, - const struct buffer *src_metadata, - struct key_ctx *server_key, struct gc_arena *= gc) +tls_crypt_v2_wrap_client_key(struct buffer *wkc, const struct key2 *src_ke= y, + const struct buffer *src_metadata, struct key= _ctx *server_key, + struct gc_arena *gc) { cipher_ctx_t *cipher_ctx =3D server_key->cipher; - struct buffer work =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_WKC_LEN - + cipher_ctx_block_size(cipher_ctx),= gc); + struct buffer work =3D + alloc_buf_gc(TLS_CRYPT_V2_MAX_WKC_LEN + cipher_ctx_block_size(ciph= er_ctx), gc); /* Calculate auth tag and synthetic IV */ uint8_t *tag =3D buf_write_alloc(&work, TLS_CRYPT_TAG_SIZE); @@ -400,8 +377,8 @@ msg(M_WARN, "ERROR: could not write tag"); return false; } - uint16_t net_len =3D htons(sizeof(src_key->keys) + BLEN(src_metadata) - + TLS_CRYPT_V2_TAG_SIZE + sizeof(uint16_t)); + uint16_t net_len =3D htons(sizeof(src_key->keys) + BLEN(src_metadata) = + TLS_CRYPT_V2_TAG_SIZE + + sizeof(uint16_t)); hmac_ctx_t *hmac_ctx =3D server_key->hmac; hmac_ctx_reset(hmac_ctx); hmac_ctx_update(hmac_ctx, (void *)&net_len, sizeof(net_len)); @@ -409,16 +386,13 @@ hmac_ctx_update(hmac_ctx, BPTR(src_metadata), BLEN(src_metadata)); hmac_ctx_final(hmac_ctx, tag); - dmsg(D_CRYPTO_DEBUG, "TLS-CRYPT WRAP TAG: %s", - format_hex(tag, TLS_CRYPT_TAG_SIZE, 0, gc)); + dmsg(D_CRYPTO_DEBUG, "TLS-CRYPT WRAP TAG: %s", format_hex(tag, TLS_CRY= PT_TAG_SIZE, 0, gc)); /* Use the 128 most significant bits of the tag as IV */ ASSERT(cipher_ctx_reset(cipher_ctx, tag)); /* Overflow check (OpenSSL requires an extra block in the dst buffer) = */ - if (buf_forward_capacity(&work) < (sizeof(src_key->keys) - + BLEN(src_metadata) - + sizeof(net_len) + if (buf_forward_capacity(&work) < (sizeof(src_key->keys) + BLEN(src_me= tadata) + sizeof(net_len) + cipher_ctx_block_size(cipher_ctx)= )) { msg(M_WARN, "ERROR: could not crypt: insufficient space in dst"); @@ -427,11 +401,11 @@ /* Encrypt */ int outlen =3D 0; - ASSERT(cipher_ctx_update(cipher_ctx, BEND(&work), &outlen, - (void *)src_key->keys, sizeof(src_key->keys))= ); + ASSERT(cipher_ctx_update(cipher_ctx, BEND(&work), &outlen, (void *)src= _key->keys, + sizeof(src_key->keys))); ASSERT(buf_inc_len(&work, outlen)); - ASSERT(cipher_ctx_update(cipher_ctx, BEND(&work), &outlen, - BPTR(src_metadata), BLEN(src_metadata))); + ASSERT(cipher_ctx_update(cipher_ctx, BEND(&work), &outlen, BPTR(src_me= tadata), + BLEN(src_metadata))); ASSERT(buf_inc_len(&work, outlen)); ASSERT(cipher_ctx_final(cipher_ctx, BEND(&work), &outlen)); ASSERT(buf_inc_len(&work, outlen)); @@ -442,8 +416,7 @@ static bool tls_crypt_v2_unwrap_client_key(struct key2 *client_key, struct buffer *met= adata, - struct buffer wrapped_client_key, - struct key_ctx *server_key) + struct buffer wrapped_client_key, struct ke= y_ctx *server_key) { const char *error_prefix =3D __func__; bool ret =3D false; @@ -455,9 +428,8 @@ struct buffer plaintext =3D { 0 }; dmsg(D_TLS_DEBUG_MED, "%s: unwrapping client key (len=3D%d): %s", __fu= nc__, - BLEN(&wrapped_client_key), format_hex(BPTR(&wrapped_client_key), - BLEN(&wrapped_client_key), - 0, &gc)); + BLEN(&wrapped_client_key), + format_hex(BPTR(&wrapped_client_key), BLEN(&wrapped_client_key), = 0, &gc)); if (TLS_CRYPT_V2_MAX_WKC_LEN < BLEN(&wrapped_client_key)) { @@ -472,13 +444,12 @@ { CRYPT_ERROR("failed to read length"); } - memcpy(&net_len, BEND(&wrapped_client_key) - sizeof(net_len), - sizeof(net_len)); + memcpy(&net_len, BEND(&wrapped_client_key) - sizeof(net_len), sizeof(n= et_len)); if (ntohs(net_len) !=3D BLEN(&wrapped_client_key)) { - dmsg(D_TLS_DEBUG_LOW, "%s: net_len=3D%u, BLEN=3D%i", __func__, - ntohs(net_len), BLEN(&wrapped_client_key)); + dmsg(D_TLS_DEBUG_LOW, "%s: net_len=3D%u, BLEN=3D%i", __func__, nto= hs(net_len), + BLEN(&wrapped_client_key)); CRYPT_ERROR("invalid length"); } @@ -495,8 +466,7 @@ } buf_set_write(&plaintext, plaintext_buf_data, sizeof(plaintext_buf_dat= a)); int outlen =3D 0; - if (!cipher_ctx_update(server_key->cipher, BPTR(&plaintext), &outlen, - BPTR(&wrapped_client_key), + if (!cipher_ctx_update(server_key->cipher, BPTR(&plaintext), &outlen, = BPTR(&wrapped_client_key), BLEN(&wrapped_client_key))) { CRYPT_ERROR("could not decrypt client key"); @@ -513,19 +483,16 @@ uint8_t tag_check[TLS_CRYPT_TAG_SIZE] =3D { 0 }; hmac_ctx_reset(server_key->hmac); hmac_ctx_update(server_key->hmac, (void *)&net_len, sizeof(net_len)); - hmac_ctx_update(server_key->hmac, BPTR(&plaintext), - BLEN(&plaintext)); + hmac_ctx_update(server_key->hmac, BPTR(&plaintext), BLEN(&plaintext)); hmac_ctx_final(server_key->hmac, tag_check); if (memcmp_constant_time(tag, tag_check, sizeof(tag_check))) { - dmsg(D_CRYPTO_DEBUG, "tag : %s", - format_hex(tag, sizeof(tag_check), 0, &gc)); - dmsg(D_CRYPTO_DEBUG, "tag_check: %s", - format_hex(tag_check, sizeof(tag_check), 0, &gc)); + dmsg(D_CRYPTO_DEBUG, "tag : %s", format_hex(tag, sizeof(tag_c= heck), 0, &gc)); + dmsg(D_CRYPTO_DEBUG, "tag_check: %s", format_hex(tag_check, sizeof= (tag_check), 0, &gc)); CRYPT_ERROR("client key authentication error"); msg(D_TLS_DEBUG_LOW, "This might be a client-key that was generate= d for " - "a different tls-crypt-v2 server key)"); + "a different tls-crypt-v2 server key)"); } if (buf_len(&plaintext) < sizeof(client_key->keys)) @@ -553,8 +520,7 @@ } static bool -tls_crypt_v2_verify_metadata(const struct tls_wrap_ctx *ctx, - const struct tls_options *opt) +tls_crypt_v2_verify_metadata(const struct tls_wrap_ctx *ctx, const struct = tls_options *opt) { bool ret =3D false; struct gc_arena gc =3D gc_new(); @@ -567,8 +533,7 @@ goto cleanup; } - tmp_file =3D platform_create_temp_file(opt->tmp_dir, "tls_crypt_v2_met= adata_", - &gc); + tmp_file =3D platform_create_temp_file(opt->tmp_dir, "tls_crypt_v2_met= adata_", &gc); if (!tmp_file || !buffer_write_file(tmp_file, &metadata)) { msg(M_WARN, "ERROR: could not write metadata to file"); @@ -576,8 +541,7 @@ } char metadata_type_str[4] =3D { 0 }; /* Max value: 255 */ - snprintf(metadata_type_str, sizeof(metadata_type_str), - "%i", (uint8_t) metadata_type); + snprintf(metadata_type_str, sizeof(metadata_type_str), "%i", (uint8_t)= metadata_type); struct env_set *es =3D env_set_create(NULL); setenv_str(es, "script_type", "tls-crypt-v2-verify"); setenv_str(es, "metadata_type", metadata_type_str); @@ -612,15 +576,12 @@ } bool -tls_crypt_v2_extract_client_key(struct buffer *buf, - struct tls_wrap_ctx *ctx, - const struct tls_options *opt, - bool initial_packet) +tls_crypt_v2_extract_client_key(struct buffer *buf, struct tls_wrap_ctx *c= tx, + const struct tls_options *opt, bool initia= l_packet) { if (!ctx->tls_crypt_v2_server_key.cipher) { - msg(D_TLS_ERRORS, - "Client wants tls-crypt-v2, but no server key present."); + msg(D_TLS_ERRORS, "Client wants tls-crypt-v2, but no server key pr= esent."); return false; } @@ -634,8 +595,7 @@ msg(D_TLS_ERRORS, "Can not read tls-crypt-v2 client key length"); return false; } - memcpy(&net_len, BEND(&wrapped_client_key) - sizeof(net_len), - sizeof(net_len)); + memcpy(&net_len, BEND(&wrapped_client_key) - sizeof(net_len), sizeof(n= et_len)); uint16_t wkc_len =3D ntohs(net_len); if (!buf_advance(&wrapped_client_key, BLEN(&wrapped_client_key) - wkc_= len)) @@ -658,7 +618,7 @@ * basically transforming the CONTROL_WKC_V1 into a normal CONTROL= _V1 * packet*/ msg(D_TLS_ERRORS, "control channel security already setup ignoring= " - "wrapped key part of packet."); + "wrapped key part of packet."); /* Remove client key from buffer so tls-crypt code can unwrap mess= age */ ASSERT(buf_inc_len(buf, -(BLEN(&wrapped_client_key)))); @@ -666,10 +626,8 @@ } ctx->tls_crypt_v2_metadata =3D alloc_buf(TLS_CRYPT_V2_MAX_METADATA_LEN= ); - if (!tls_crypt_v2_unwrap_client_key(&ctx->original_wrap_keydata, - &ctx->tls_crypt_v2_metadata, - wrapped_client_key, - &ctx->tls_crypt_v2_server_key)) + if (!tls_crypt_v2_unwrap_client_key(&ctx->original_wrap_keydata, &ctx-= >tls_crypt_v2_metadata, + wrapped_client_key, &ctx->tls_cryp= t_v2_server_key)) { msg(D_TLS_ERRORS, "Can not unwrap tls-crypt-v2 client key"); secure_memzero(&ctx->original_wrap_keydata, sizeof(ctx->original_w= rap_keydata)); @@ -681,8 +639,7 @@ ctx->cleanup_key_ctx =3D true; ctx->opt.flags |=3D CO_PACKET_ID_LONG_FORM; memset(&ctx->opt.key_ctx_bi, 0, sizeof(ctx->opt.key_ctx_bi)); - tls_crypt_v2_load_client_key(&ctx->opt.key_ctx_bi, - &ctx->original_wrap_keydata, true); + tls_crypt_v2_load_client_key(&ctx->opt.key_ctx_bi, &ctx->original_wrap= _keydata, true); /* Remove client key from buffer so tls-crypt code can unwrap message = */ ASSERT(buf_inc_len(buf, -(BLEN(&wrapped_client_key)))); @@ -702,16 +659,13 @@ } void -tls_crypt_v2_write_client_key_file(const char *filename, - const char *b64_metadata, - const char *server_key_file, - bool server_key_inline) +tls_crypt_v2_write_client_key_file(const char *filename, const char *b64_m= etadata, + const char *server_key_file, bool serve= r_key_inline) { struct gc_arena gc =3D gc_new(); struct key_ctx server_key =3D { 0 }; struct buffer client_key_pem =3D { 0 }; - struct buffer dst =3D alloc_buf_gc(TLS_CRYPT_V2_CLIENT_KEY_LEN - + TLS_CRYPT_V2_MAX_WKC_LEN, &gc); + struct buffer dst =3D alloc_buf_gc(TLS_CRYPT_V2_CLIENT_KEY_LEN + TLS_C= RYPT_V2_MAX_WKC_LEN, &gc); struct key2 client_key =3D { .n =3D 2 }; if (!rand_bytes((void *)client_key.keys, sizeof(client_key.keys))) @@ -727,8 +681,7 @@ size_t b64_length =3D strlen(b64_metadata); metadata =3D alloc_buf_gc(OPENVPN_BASE64_DECODED_LENGTH(b64_length= ) + 1, &gc); ASSERT(buf_write(&metadata, &TLS_CRYPT_METADATA_TYPE_USER, 1)); - int decoded_len =3D openvpn_base64_decode(b64_metadata, BEND(&meta= data), - BCAP(&metadata)); + int decoded_len =3D openvpn_base64_decode(b64_metadata, BEND(&meta= data), BCAP(&metadata)); if (decoded_len < 0) { msg(M_FATAL, "ERROR: failed to base64 decode provided metadata= "); @@ -736,9 +689,8 @@ } if (decoded_len > TLS_CRYPT_V2_MAX_METADATA_LEN - 1) { - msg(M_FATAL, - "ERROR: metadata too long (%d bytes, max %u bytes)", - decoded_len, TLS_CRYPT_V2_MAX_METADATA_LEN - 1); + msg(M_FATAL, "ERROR: metadata too long (%d bytes, max %u bytes= )", decoded_len, + TLS_CRYPT_V2_MAX_METADATA_LEN - 1); goto cleanup; } ASSERT(buf_inc_len(&metadata, decoded_len)); @@ -751,18 +703,15 @@ ASSERT(buf_write(&metadata, ×tamp, sizeof(timestamp))); } - tls_crypt_v2_init_server_key(&server_key, true, server_key_file, - server_key_inline); - if (!tls_crypt_v2_wrap_client_key(&dst, &client_key, &metadata, &serve= r_key, - &gc)) + tls_crypt_v2_init_server_key(&server_key, true, server_key_file, serve= r_key_inline); + if (!tls_crypt_v2_wrap_client_key(&dst, &client_key, &metadata, &serve= r_key, &gc)) { msg(M_FATAL, "ERROR: could not wrap generated client key"); goto cleanup; } /* PEM-encode Kc || WKc */ - if (!crypto_pem_encode(tls_crypt_v2_cli_pem_name, &client_key_pem, &ds= t, - &gc)) + if (!crypto_pem_encode(tls_crypt_v2_cli_pem_name, &client_key_pem, &ds= t, &gc)) { msg(M_FATAL, "ERROR: could not PEM-encode client key"); goto cleanup; @@ -788,17 +737,15 @@ struct buffer test_wrapped_client_key; struct key2 keydata; msg(D_GENKEY, "Testing client-side key loading..."); - tls_crypt_v2_init_client_key(&test_client_key, &keydata, &test_wrapped= _client_key, - client_file, client_inline); + tls_crypt_v2_init_client_key(&test_client_key, &keydata, &test_wrapped= _client_key, client_file, + client_inline); free_key_ctx_bi(&test_client_key); /* Sanity check: unwrap and load client key (as "server") */ - struct buffer test_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA= _LEN, - &gc); + struct buffer test_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA= _LEN, &gc); struct key2 test_client_key2 =3D { 0 }; free_key_ctx(&server_key); - tls_crypt_v2_init_server_key(&server_key, false, server_key_file, - server_key_inline); + tls_crypt_v2_init_server_key(&server_key, false, server_key_file, serv= er_key_inline); msg(D_GENKEY, "Testing server-side key loading..."); ASSERT(tls_crypt_v2_unwrap_client_key(&test_client_key2, &test_metadat= a, test_wrapped_client_key, &server= _key)); diff --git a/src/openvpn/tls_crypt.h b/src/openvpn/tls_crypt.h index 42545d1..55bb26f 100644 --- a/src/openvpn/tls_crypt.h +++ b/src/openvpn/tls_crypt.h @@ -86,21 +86,21 @@ #include "session_id.h" #include "ssl_common.h" -#define TLS_CRYPT_TAG_SIZE (256/8) -#define TLS_CRYPT_PID_SIZE (sizeof(packet_id_type) + sizeof(net_time_t)) -#define TLS_CRYPT_BLOCK_SIZE (128/8) +#define TLS_CRYPT_TAG_SIZE (256 / 8) +#define TLS_CRYPT_PID_SIZE (sizeof(packet_id_type) + sizeof(net_time_t)) +#define TLS_CRYPT_BLOCK_SIZE (128 / 8) #define TLS_CRYPT_OFF_PID (1 + SID_SIZE) #define TLS_CRYPT_OFF_TAG (TLS_CRYPT_OFF_PID + TLS_CRYPT_PID_SIZE) -#define TLS_CRYPT_OFF_CT (TLS_CRYPT_OFF_TAG + TLS_CRYPT_TAG_SIZE) +#define TLS_CRYPT_OFF_CT (TLS_CRYPT_OFF_TAG + TLS_CRYPT_TAG_SIZE) -#define TLS_CRYPT_V2_MAX_WKC_LEN (1024) +#define TLS_CRYPT_V2_MAX_WKC_LEN (1024) #define TLS_CRYPT_V2_CLIENT_KEY_LEN (2048 / 8) #define TLS_CRYPT_V2_SERVER_KEY_LEN (sizeof(struct key)) -#define TLS_CRYPT_V2_TAG_SIZE (TLS_CRYPT_TAG_SIZE) -#define TLS_CRYPT_V2_MAX_METADATA_LEN (unsigned)(TLS_CRYPT_V2_MAX_WKC_LEN \ - - (TLS_CRYPT_V2_CLIENT_KE= Y_LEN + TLS_CRYPT_V2_TAG_SIZE \ - + sizeof(uint16_t))) +#define TLS_CRYPT_V2_TAG_SIZE (TLS_CRYPT_TAG_SIZE) +#define TLS_CRYPT_V2_MAX_METADATA_LEN \ + (unsigned)(TLS_CRYPT_V2_MAX_WKC_LEN \ + - (TLS_CRYPT_V2_CLIENT_KEY_LEN + TLS_CRYPT_V2_TAG_SIZE + si= zeof(uint16_t))) /** * Initialize a key_ctx_bi structure for use with @c --tls-crypt. @@ -113,8 +113,8 @@ * otherwise. * @param tls_server Must be set to true is this is a TLS server instan= ce. */ -void tls_crypt_init_key(struct key_ctx_bi *key, struct key2 *keydata, - const char *key_file, bool key_inline, bool tls_se= rver); +void tls_crypt_init_key(struct key_ctx_bi *key, struct key2 *keydata, cons= t char *key_file, + bool key_inline, bool tls_server); /** * Generates a TLS-Crypt key to be used with dynamic tls-crypt using the @@ -125,8 +125,7 @@ * @param session session that will be used for the TLS EKM exporter * @return true iff generating the key was successful */ -bool -tls_session_generate_dynamic_tls_crypt_key(struct tls_session *session); +bool tls_session_generate_dynamic_tls_crypt_key(struct tls_session *sessio= n); /** * Returns the maximum overhead (in bytes) added to the destination buffer= by @@ -145,8 +144,7 @@ * * @returns true iff wrapping succeeded. */ -bool tls_crypt_wrap(const struct buffer *src, struct buffer *dst, - struct crypto_options *opt); +bool tls_crypt_wrap(const struct buffer *src, struct buffer *dst, struct c= rypto_options *opt); /** * Unwrap a control channel packet (decrypts, authenticates and performs @@ -159,8 +157,7 @@ * @returns true iff unwrapping succeeded (data authenticated correctly an= d was * no replay). */ -bool tls_crypt_unwrap(const struct buffer *src, struct buffer *dst, - struct crypto_options *opt); +bool tls_crypt_unwrap(const struct buffer *src, struct buffer *dst, struct= crypto_options *opt); /** * Initialize a tls-crypt-v2 server key (used to encrypt/decrypt client ke= ys). @@ -174,8 +171,8 @@ * otherwise. * */ -void tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, bool encrypt, - const char *key_file, bool key_inline); +void tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, bool encrypt, c= onst char *key_file, + bool key_inline); /** * Initialize a tls-crypt-v2 client key. @@ -192,10 +189,9 @@ * @param key_inline True if key_file contains an inline key, False * otherwise. */ -void tls_crypt_v2_init_client_key(struct key_ctx_bi *key, - struct key2 *original_key, - struct buffer *wrapped_key_buf, - const char *key_file, bool key_inline); +void tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *ori= ginal_key, + struct buffer *wrapped_key_buf, const ch= ar *key_file, + bool key_inline); /** * Extract a tls-crypt-v2 client key from a P_CONTROL_HARD_RESET_CLIENT_V3 @@ -212,10 +208,8 @@ * * @returns true if a key was successfully extracted. */ -bool tls_crypt_v2_extract_client_key(struct buffer *buf, - struct tls_wrap_ctx *ctx, - const struct tls_options *opt, - bool initial_packet); +bool tls_crypt_v2_extract_client_key(struct buffer *buf, struct tls_wrap_c= tx *ctx, + const struct tls_options *opt, bool i= nitial_packet); /** * Generate a tls-crypt-v2 server key, and write to file. @@ -234,8 +228,7 @@ * @param key_inline True if key_file contains an inline key, False * otherwise. */ -void tls_crypt_v2_write_client_key_file(const char *filename, - const char *b64_metadata, +void tls_crypt_v2_write_client_key_file(const char *filename, const char *= b64_metadata, const char *key_file, bool key_inl= ine); /** @} */ diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index d15d9eb6..2703f7b 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -85,27 +85,25 @@ #ifdef _WIN32 -const static GUID GUID_DEVCLASS_NET =3D { 0x4d36e972L, 0xe325, 0x11ce, { 0= xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } }; -const static GUID GUID_DEVINTERFACE_NET =3D { 0xcac88484, 0x7515, 0x4c03, = { 0x82, 0xe6, 0x71, 0xa8, 0x7a, 0xba, 0xc3, 0x61 } }; +const static GUID GUID_DEVCLASS_NET =3D { + 0x4d36e972L, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x0= 3, 0x18 } +}; +const static GUID GUID_DEVINTERFACE_NET =3D { + 0xcac88484, 0x7515, 0x4c03, { 0x82, 0xe6, 0x71, 0xa8, 0x7a, 0xba, 0xc3= , 0x61 } +}; -/* #define SIMULATE_DHCP_FAILED */ /* simulate bad DHCP negotiation = */ +/* #define SIMULATE_DHCP_FAILED */ /* simulate bad DHCP negotiation */ -#define NI_TEST_FIRST (1<<0) -#define NI_IP_NETMASK (1<<1) -#define NI_OPTIONS (1<<2) +#define NI_TEST_FIRST (1 << 0) +#define NI_IP_NETMASK (1 << 1) +#define NI_OPTIONS (1 << 2) -static void netsh_ifconfig(const struct tuntap_options *to, - DWORD adapter_index, - const in_addr_t ip, - const in_addr_t netmask, - const unsigned int flags); +static void netsh_ifconfig(const struct tuntap_options *to, DWORD adapter_= index, const in_addr_t ip, + const in_addr_t netmask, const unsigned int fla= gs); -static void windows_set_mtu(const int iface_index, - const short family, - const int mtu); +static void windows_set_mtu(const int iface_index, const short family, con= st int mtu); -static void netsh_set_dns6_servers(const struct in6_addr *addr_list, - const int addr_len, +static void netsh_set_dns6_servers(const struct in6_addr *addr_list, const= int addr_len, DWORD adapter_index); static void netsh_command(const struct argv *a, int n, int msglevel); @@ -122,15 +120,10 @@ struct gc_arena gc =3D gc_new(); HANDLE pipe =3D tt->options.msg_channel; - address_message_t addr =3D { - .header =3D { - (add ? msg_add_address : msg_del_address), - sizeof(address_message_t), - 0 - }, - .family =3D family, - .iface =3D { .index =3D tt->adapter_index, .name =3D "" } - }; + address_message_t addr =3D { .header =3D { (add ? msg_add_address : ms= g_del_address), + sizeof(address_message_t), 0 }, + .family =3D family, + .iface =3D { .index =3D tt->adapter_index, = .name =3D "" } }; if (addr.iface.index =3D=3D TUN_ADAPTER_INDEX_INVALID) { @@ -142,16 +135,14 @@ { addr.address.ipv4.s_addr =3D htonl(tt->local); addr.prefix_len =3D netmask_to_netbits2(tt->adapter_netmask); - msg(D_IFCONFIG, "INET address service: %s %s/%d", - add ? "add" : "remove", + msg(D_IFCONFIG, "INET address service: %s %s/%d", add ? "add" : "r= emove", print_in_addr_t(tt->local, 0, &gc), addr.prefix_len); } else { addr.address.ipv6 =3D tt->local_ipv6; addr.prefix_len =3D (tt->type =3D=3D DEV_TYPE_TUN) ? 128 : tt->net= bits_ipv6; - msg(D_IFCONFIG, "INET6 address service: %s %s/%d", - add ? "add" : "remove", + msg(D_IFCONFIG, "INET6 address service: %s %s/%d", add ? "add" : "= remove", print_in6_addr(tt->local_ipv6, 0, &gc), addr.prefix_len); } @@ -163,8 +154,8 @@ if (ack.error_number !=3D NO_ERROR) { msg(M_WARN, "TUN: %s address failed using service: %s [status=3D%u= if_index=3D%d]", - (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), - ack.error_number, addr.iface.index); + (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), ack.error_number, + addr.iface.index); goto out; } @@ -190,15 +181,11 @@ /* Use dns_cfg_msg with addr_len =3D 0 for setting only the DOMAIN */ dns_cfg_message_t dns =3D { - .header =3D { - (add ? msg_add_dns_cfg : msg_del_dns_cfg), - sizeof(dns_cfg_message_t), - 0 - }, + .header =3D { (add ? msg_add_dns_cfg : msg_del_dns_cfg), sizeof(dn= s_cfg_message_t), 0 }, .iface =3D { .index =3D tt->adapter_index, .name =3D "" }, - .domains =3D "", /* set below */ - .family =3D AF_INET, /* unused */ - .addr_len =3D 0 /* add/delete only the domain, not DNS serve= rs */ + .domains =3D "", /* set below */ + .family =3D AF_INET, /* unused */ + .addr_len =3D 0 /* add/delete only the domain, not DNS server= s */ }; /* interface name is required */ @@ -238,8 +225,8 @@ if (ack.error_number !=3D NO_ERROR) { msg(M_WARN, "TUN: %s DNS domains failed using service: %s [status= =3D%u if_name=3D%s]", - (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), - ack.error_number, dns.iface.name); + (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), ack.error_number, + dns.iface.name); goto out; } @@ -266,17 +253,12 @@ } /* Use dns_cfg_msg with domain =3D "" for setting only the DNS servers= */ - dns_cfg_message_t dns =3D { - .header =3D { - (add ? msg_add_dns_cfg : msg_del_dns_cfg), - sizeof(dns_cfg_message_t), - 0 - }, - .iface =3D { .index =3D tt->adapter_index, .name =3D "" }, - .domains =3D "", - .family =3D family, - .addr_len =3D addr_len - }; + dns_cfg_message_t dns =3D { .header =3D { (add ? msg_add_dns_cfg : msg= _del_dns_cfg), + sizeof(dns_cfg_message_t), 0 }, + .iface =3D { .index =3D tt->adapter_index, .= name =3D "" }, + .domains =3D "", + .family =3D family, + .addr_len =3D addr_len }; /* interface name is required */ strncpy(dns.iface.name, tt->actual_name, sizeof(dns.iface.name)); @@ -286,8 +268,8 @@ { addr_len =3D _countof(dns.addr); dns.addr_len =3D addr_len; - msg(M_WARN, "Number of %s DNS addresses sent to service truncated = to %d", - ip_proto_name, addr_len); + msg(M_WARN, "Number of %s DNS addresses sent to service truncated = to %d", ip_proto_name, + addr_len); } for (int i =3D 0; i < addr_len; ++i) @@ -338,15 +320,10 @@ goto out; } - wins_cfg_message_t wins =3D { - .header =3D { - (add ? msg_add_wins_cfg : msg_del_wins_cfg), - sizeof(wins_cfg_message_t), - 0 - }, - .iface =3D {.index =3D tt->adapter_index, .name =3D "" }, - .addr_len =3D addr_len - }; + wins_cfg_message_t wins =3D { .header =3D { (add ? msg_add_wins_cfg : = msg_del_wins_cfg), + sizeof(wins_cfg_message_t), 0 = }, + .iface =3D { .index =3D tt->adapter_index,= .name =3D "" }, + .addr_len =3D addr_len }; /* interface name is required */ strncpy(wins.iface.name, tt->actual_name, sizeof(wins.iface.name)); @@ -356,8 +333,7 @@ { addr_len =3D _countof(wins.addr); wins.addr_len =3D addr_len; - msg(M_WARN, "Number of WINS addresses sent to service truncated to= %d", - addr_len); + msg(M_WARN, "Number of WINS addresses sent to service truncated to= %d", addr_len); } =20 for (int i =3D 0; i < addr_len; ++i) @@ -376,8 +352,8 @@ if (ack.error_number !=3D NO_ERROR) { msg(M_WARN, "TUN: %s WINS failed using service: %s [status=3D%u if= _name=3D%s]", - (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), - ack.error_number, wins.iface.name); + (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), ack.error_number, + wins.iface.name); goto out; } @@ -395,20 +371,15 @@ struct gc_arena gc =3D gc_new(); HANDLE pipe =3D tt->options.msg_channel; const char *family_name =3D (family =3D=3D AF_INET6) ? "IPv6" : "IPv4"; - set_mtu_message_t mtu_msg =3D { - .header =3D { - msg_set_mtu, - sizeof(set_mtu_message_t), - 0 - }, - .iface =3D {.index =3D tt->adapter_index}, - .mtu =3D mtu, - .family =3D family - }; + set_mtu_message_t mtu_msg =3D { .header =3D { msg_set_mtu, sizeof(set_= mtu_message_t), 0 }, + .iface =3D { .index =3D tt->adapter_inde= x }, + .mtu =3D mtu, + .family =3D family }; strncpynt(mtu_msg.iface.name, tt->actual_name, sizeof(mtu_msg.iface.na= me)); if (family =3D=3D AF_INET6 && mtu < 1280) { - msg(M_INFO, "NOTE: IPv6 interface MTU < 1280 conflicts with IETF s= tandards and might not work"); + msg(M_INFO, + "NOTE: IPv6 interface MTU < 1280 conflicts with IETF standards= and might not work"); } if (!send_msg_iservice(pipe, &mtu_msg, sizeof(mtu_msg), &ack, "Set_mtu= ")) @@ -419,11 +390,13 @@ if (ack.error_number !=3D NO_ERROR) { msg(M_NONFATAL, "TUN: setting %s mtu using service failed: %s [sta= tus=3D%u if_index=3D%d]", - family_name, strerror_win32(ack.error_number, &gc), ack.error_= number, mtu_msg.iface.index); + family_name, strerror_win32(ack.error_number, &gc), ack.error_= number, + mtu_msg.iface.index); } else { - msg(M_INFO, "%s MTU set to %d on interface %d using service", fami= ly_name, mtu, mtu_msg.iface.index); + msg(M_INFO, "%s MTU set to %d on interface %d using service", fami= ly_name, mtu, + mtu_msg.iface.index); ret =3D true; } @@ -442,7 +415,8 @@ struct argv argv =3D argv_new(); argv_printf(&argv, "%s%s nicconfig where (InterfaceIndex=3D%ld) call S= etDNSDomain '%s'", - get_win_sys_path(), WMIC_PATH_SUFFIX, tt->adapter_index, a= dd ? tt->options.domain : ""); + get_win_sys_path(), WMIC_PATH_SUFFIX, tt->adapter_index, + add ? tt->options.domain : ""); exec_command("WMIC", &argv, 1, M_WARN); argv_free(&argv); @@ -480,12 +454,7 @@ } create_adapter_message_t msg =3D { - .header =3D { - msg_create_adapter, - sizeof(create_adapter_message_t), - 0 - }, - .adapter_type =3D t + .header =3D { msg_create_adapter, sizeof(create_adapter_message_t)= , 0 }, .adapter_type =3D t }; if (!send_msg_iservice(msg_channel, &msg, sizeof(msg), &ack, "create_a= dapter")) @@ -496,7 +465,8 @@ if (ack.error_number !=3D NO_ERROR) { msg(M_NONFATAL, "TUN: creating %s adapter using service failed: %s= [status=3D%u]", - print_tun_backend_driver(driver_type), strerror_win32(ack.erro= r_number, &gc), ack.error_number); + print_tun_backend_driver(driver_type), strerror_win32(ack.erro= r_number, &gc), + ack.error_number); } else { @@ -512,7 +482,8 @@ #endif /* ifdef _WIN32 */ #ifdef TARGET_SOLARIS -static void solaris_error_close(struct tuntap *tt, const struct env_set *e= s, const char *actual, bool unplumb_inet6); +static void solaris_error_close(struct tuntap *tt, const struct env_set *e= s, const char *actual, + bool unplumb_inet6); #include #endif @@ -583,10 +554,7 @@ * before the device is actually opened. */ const char * -guess_tuntap_dev(const char *dev, - const char *dev_type, - const char *dev_node, - struct gc_arena *gc) +guess_tuntap_dev(const char *dev, const char *dev_type, const char *dev_no= de, struct gc_arena *gc) { #ifdef _WIN32 const int dt =3D dev_type_enum(dev, dev_type); @@ -620,16 +588,17 @@ { if (looks_like_netmask) { - msg(M_WARN, "WARNING: Since you are using --dev tun with a poi= nt-to-point topology, the second argument to --ifconfig must be an IP addre= ss. You are using something (%s) that looks more like a netmask. %s", - print_in_addr_t(addr, 0, &gc), - ifconfig_warn_how_to_silence); + msg(M_WARN, + "WARNING: Since you are using --dev tun with a point-to-po= int topology, the second argument to --ifconfig must be an IP address. You= are using something (%s) that looks more like a netmask. %s", + print_in_addr_t(addr, 0, &gc), ifconfig_warn_how_to_silenc= e); } } else { if (!looks_like_netmask) { - msg(M_WARN, "WARNING: Since you are using subnet topology, the= second argument to --ifconfig must be a netmask, for example something lik= e 255.255.255.0. %s", + msg(M_WARN, + "WARNING: Since you are using subnet topology, the second = argument to --ifconfig must be a netmask, for example something like 255.25= 5.255.0. %s", ifconfig_warn_how_to_silence); } } @@ -641,10 +610,7 @@ * clash with ifconfig addresses or subnet. */ static void -check_addr_clash(const char *name, - int type, - in_addr_t public, - in_addr_t local, +check_addr_clash(const char *name, int type, in_addr_t public, in_addr_t l= ocal, in_addr_t remote_netmask) { struct gc_arena gc =3D gc_new(); @@ -661,7 +627,7 @@ if (type =3D=3D DEV_TYPE_TUN) { const in_addr_t test_netmask =3D 0xFFFFFF00; - const in_addr_t public_net =3D public &test_netmask; + const in_addr_t public_net =3D public & test_netmask; const in_addr_t local_net =3D local & test_netmask; const in_addr_t remote_net =3D remote_netmask & test_netmask; @@ -669,37 +635,28 @@ { msg(M_WARN, "WARNING: --%s address [%s] conflicts with --ifconfig = address pair [%s, %s]. %s", - name, - print_in_addr_t(public, 0, &gc), - print_in_addr_t(local, 0, &gc), - print_in_addr_t(remote_netmask, 0, &gc), - ifconfig_warn_how_to_silence); + name, print_in_addr_t(public, 0, &gc), print_in_addr_t= (local, 0, &gc), + print_in_addr_t(remote_netmask, 0, &gc), ifconfig_warn= _how_to_silence); } if (public_net =3D=3D local_net || public_net =3D=3D remote_ne= t) { msg(M_WARN, "WARNING: potential conflict between --%s address [%s]= and --ifconfig address pair [%s, %s] -- this is a warning only that is tri= ggered when local/remote addresses exist within the same /24 subnet as --if= config endpoints. %s", - name, - print_in_addr_t(public, 0, &gc), - print_in_addr_t(local, 0, &gc), - print_in_addr_t(remote_netmask, 0, &gc), - ifconfig_warn_how_to_silence); + name, print_in_addr_t(public, 0, &gc), print_in_addr_t= (local, 0, &gc), + print_in_addr_t(remote_netmask, 0, &gc), ifconfig_warn= _how_to_silence); } } else if (type =3D=3D DEV_TYPE_TAP) { - const in_addr_t public_network =3D public &remote_netmask; + const in_addr_t public_network =3D public & remote_netmask; const in_addr_t virtual_network =3D local & remote_netmask; if (public_network =3D=3D virtual_network) { msg(M_WARN, "WARNING: --%s address [%s] conflicts with --ifconfig = subnet [%s, %s] -- local and remote addresses cannot be inside of the --ifc= onfig subnet. %s", - name, - print_in_addr_t(public, 0, &gc), - print_in_addr_t(local, 0, &gc), - print_in_addr_t(remote_netmask, 0, &gc), - ifconfig_warn_how_to_silence); + name, print_in_addr_t(public, 0, &gc), print_in_addr_t= (local, 0, &gc), + print_in_addr_t(remote_netmask, 0, &gc), ifconfig_warn= _how_to_silence); } } } @@ -711,7 +668,7 @@ { struct gc_arena gc =3D gc_new(); struct route_gateway_info rgi; - const unsigned int needed =3D (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED); + const unsigned int needed =3D (RGI_ADDR_DEFINED | RGI_NETMASK_DEFINED); get_default_gateway(&rgi, 0, ctx); if ((rgi.flags & needed) =3D=3D needed) @@ -719,7 +676,8 @@ const in_addr_t lan_network =3D rgi.gateway.addr & rgi.gateway.net= mask; if (lan_network =3D=3D 0xC0A80000 || lan_network =3D=3D 0xC0A80100) { - msg(M_WARN, "NOTE: your local LAN uses the extremely common su= bnet address 192.168.0.x or 192.168.1.x. Be aware that this might create r= outing conflicts if you connect to the VPN server from public locations suc= h as internet cafes that use the same subnet."); + msg(M_WARN, + "NOTE: your local LAN uses the extremely common subnet add= ress 192.168.0.x or 192.168.1.x. Be aware that this might create routing c= onflicts if you connect to the VPN server from public locations such as int= ernet cafes that use the same subnet."); } } gc_free(&gc); @@ -737,8 +695,7 @@ { if (!is_tun_p2p(tt)) { - buf_printf(&out, "%s %s", - print_in_addr_t(tt->local & tt->remote_netmask, 0, = gc), + buf_printf(&out, "%s %s", print_in_addr_t(tt->local & tt->remo= te_netmask, 0, gc), print_in_addr_t(tt->remote_netmask, 0, gc)); } else if (tt->type =3D=3D DEV_TYPE_TUN) /* tun p2p topology */ @@ -775,20 +732,16 @@ { if (rwflags & EVENT_READ) { - buf_printf(&out, "T%s", - (tt->rwflags_debug & EVENT_READ) ? "R" : "r"); + buf_printf(&out, "T%s", (tt->rwflags_debug & EVENT_READ) ? "R"= : "r"); #ifdef _WIN32 - buf_printf(&out, "%s", - overlapped_io_state_ascii(&tt->reads)); + buf_printf(&out, "%s", overlapped_io_state_ascii(&tt->reads)); #endif } if (rwflags & EVENT_WRITE) { - buf_printf(&out, "T%s", - (tt->rwflags_debug & EVENT_WRITE) ? "W" : "w"); + buf_printf(&out, "T%s", (tt->rwflags_debug & EVENT_WRITE) ? "W= " : "w"); #ifdef _WIN32 - buf_printf(&out, "%s", - overlapped_io_state_ascii(&tt->writes)); + buf_printf(&out, "%s", overlapped_io_state_ascii(&tt->writes)); #endif } } @@ -807,8 +760,7 @@ { bool tun_p2p =3D false; - if (tt->type =3D=3D DEV_TYPE_TAP - || (tt->type =3D=3D DEV_TYPE_TUN && tt->topology =3D=3D TOP_SUBNET= )) + if (tt->type =3D=3D DEV_TYPE_TAP || (tt->type =3D=3D DEV_TYPE_TUN && t= t->topology =3D=3D TOP_SUBNET)) { tun_p2p =3D false; } @@ -818,7 +770,8 @@ } else { - msg(M_FATAL, "Error: problem with tun vs. tap setting"); /* JYFIXM= E -- needs to be caught earlier, in init_tun? */ + msg(M_FATAL, "Error: problem with tun vs. tap setting"); /* JYFIXM= E -- needs to be caught + earlie= r, in init_tun? */ } return tun_p2p; } @@ -871,20 +824,16 @@ * but don't execute yet. */ struct tuntap * -init_tun(const char *dev, /* --dev option */ - const char *dev_type, /* --dev-type option */ - int topology, /* one of the TOP_x values */ - const char *ifconfig_local_parm, /* --ifconfig parm 1 */ - const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */ - const char *ifconfig_ipv6_local_parm, /* --ifconfig parm 1 I= Pv6 */ +init_tun(const char *dev, /* --dev option */ + const char *dev_type, /* --dev-type option */ + int topology, /* one of the TOP_x val= ues */ + const char *ifconfig_local_parm, /* --ifconfig parm 1 */ + const char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */ + const char *ifconfig_ipv6_local_parm, /* --ifconfig parm 1 IP= v6 */ int ifconfig_ipv6_netbits_parm, - const char *ifconfig_ipv6_remote_parm, /* --ifconfig parm 2 I= Pv6 */ - struct addrinfo *local_public, - struct addrinfo *remote_public, - const bool strict_warn, - struct env_set *es, - openvpn_net_ctx_t *ctx, - struct tuntap *tt) + const char *ifconfig_ipv6_remote_parm, /* --ifconfig parm 2 IP= v6 */ + struct addrinfo *local_public, struct addrinfo *remote_public, co= nst bool strict_warn, + struct env_set *es, openvpn_net_ctx_t *ctx, struct tuntap *tt) { if (!tt) { @@ -906,25 +855,13 @@ * Convert arguments to binary IPv4 addresses. */ - tt->local =3D getaddr( - GETADDR_RESOLVE - | GETADDR_HOST_ORDER - | GETADDR_FATAL_ON_SIGNAL - | GETADDR_FATAL, - ifconfig_local_parm, - 0, - NULL, - NULL); + tt->local =3D + getaddr(GETADDR_RESOLVE | GETADDR_HOST_ORDER | GETADDR_FATAL_O= N_SIGNAL | GETADDR_FATAL, + ifconfig_local_parm, 0, NULL, NULL); - tt->remote_netmask =3D getaddr( - (tun_p2p ? GETADDR_RESOLVE : 0) - | GETADDR_HOST_ORDER - | GETADDR_FATAL_ON_SIGNAL - | GETADDR_FATAL, - ifconfig_remote_netmask_parm, - 0, - NULL, - NULL); + tt->remote_netmask =3D getaddr((tun_p2p ? GETADDR_RESOLVE : 0) | G= ETADDR_HOST_ORDER + | GETADDR_FATAL_ON_SIGNAL | GETAD= DR_FATAL, + ifconfig_remote_netmask_parm, 0, NULL= , NULL); /* * Look for common errors in --ifconfig parms @@ -943,12 +880,9 @@ { if (curele->ai_family =3D=3D AF_INET) { - const in_addr_t local =3D ntohl(((struct sockaddr_in *= )curele->ai_addr)->sin_addr.s_addr); - check_addr_clash("local", - tt->type, - local, - tt->local, - tt->remote_netmask); + const in_addr_t local =3D + ntohl(((struct sockaddr_in *)curele->ai_addr)->sin= _addr.s_addr); + check_addr_clash("local", tt->type, local, tt->local, = tt->remote_netmask); } } @@ -956,12 +890,9 @@ { if (curele->ai_family =3D=3D AF_INET) { - const in_addr_t remote =3D ntohl(((struct sockaddr_in = *)curele->ai_addr)->sin_addr.s_addr); - check_addr_clash("remote", - tt->type, - remote, - tt->local, - tt->remote_netmask); + const in_addr_t remote =3D + ntohl(((struct sockaddr_in *)curele->ai_addr)->sin= _addr.s_addr); + check_addr_clash("remote", tt->type, remote, tt->local= , tt->remote_netmask); } } } @@ -987,15 +918,15 @@ if (ifconfig_ipv6_local_parm && ifconfig_ipv6_remote_parm) { - /* * Convert arguments to binary IPv6 addresses. */ - if (inet_pton( AF_INET6, ifconfig_ipv6_local_parm, &tt->local_ipv6= ) !=3D 1 - || inet_pton( AF_INET6, ifconfig_ipv6_remote_parm, &tt->remote= _ipv6 ) !=3D 1) + if (inet_pton(AF_INET6, ifconfig_ipv6_local_parm, &tt->local_ipv6)= !=3D 1 + || inet_pton(AF_INET6, ifconfig_ipv6_remote_parm, &tt->remote_= ipv6) !=3D 1) { - msg( M_FATAL, "init_tun: problem converting IPv6 ifconfig addr= esses %s and %s to binary", ifconfig_ipv6_local_parm, ifconfig_ipv6_remote_= parm ); + msg(M_FATAL, "init_tun: problem converting IPv6 ifconfig addre= sses %s and %s to binary", + ifconfig_ipv6_local_parm, ifconfig_ipv6_remote_parm); } tt->netbits_ipv6 =3D ifconfig_ipv6_netbits_parm; @@ -1017,9 +948,7 @@ * Platform specific tun initializations */ void -init_tun_post(struct tuntap *tt, - const struct frame *frame, - const struct tuntap_options *options) +init_tun_post(struct tuntap *tt, const struct frame *frame, const struct t= untap_options *options) { tt->options =3D *options; #ifdef _WIN32 @@ -1046,8 +975,7 @@ * -> helper function to simplify code below */ static void -add_route_connected_v6_net(struct tuntap *tt, - const struct env_set *es) +add_route_connected_v6_net(struct tuntap *tt, const struct env_set *es) { struct route_ipv6 r6; @@ -1055,8 +983,8 @@ r6.network =3D tt->local_ipv6; r6.netbits =3D tt->netbits_ipv6; r6.gateway =3D tt->local_ipv6; - r6.metric =3D 0; /* connected route */ - r6.flags =3D RT_DEFINED | RT_METRIC_DEFINED; + r6.metric =3D 0; /* connected route */ + r6.flags =3D RT_DEFINED | RT_METRIC_DEFINED; add_route_ipv6(&r6, tt, 0, es, NULL); } @@ -1069,15 +997,16 @@ r6.network =3D tt->local_ipv6; r6.netbits =3D tt->netbits_ipv6; r6.gateway =3D tt->local_ipv6; - r6.metric =3D 0; /* connected route */ - r6.flags =3D RT_DEFINED | RT_ADDED | RT_METRIC_DEFINED; + r6.metric =3D 0; /* connected route */ + r6.flags =3D RT_DEFINED | RT_ADDED | RT_METRIC_DEFINED; route_ipv6_clear_host_bits(&r6); delete_route_ipv6(&r6, tt, NULL, NULL); } -#endif /* if defined(_WIN32) || defined(TARGET_DARWIN) || defined(TARGET_N= ETBSD) || defined(TARGET_OPENBSD) */ +#endif /* if defined(_WIN32) || defined(TARGET_DARWIN) || defined(TARGET_N= ETBSD) || \ + defined(TARGET_OPENBSD) */ -#if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ - || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD) +#if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || defined(TARGET= _NETBSD) \ + || defined(TARGET_OPENBSD) /* we can't use true subnet mode on tun on all platforms, as that * conflicts with IPv6 (wants to use ND then, which we don't do), * but the OSes want "a remote address that is different from ours" @@ -1088,11 +1017,11 @@ */ in_addr_t -create_arbitrary_remote( struct tuntap *tt ) +create_arbitrary_remote(struct tuntap *tt) { in_addr_t remote; - remote =3D (tt->local & tt->remote_netmask) +1; + remote =3D (tt->local & tt->remote_netmask) + 1; if (remote =3D=3D tt->local) { @@ -1113,8 +1042,8 @@ * @param ctx the networking API opaque context */ static void -do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu, - const struct env_set *es, openvpn_net_ctx_t *ctx) +do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, int tun_mtu, const= struct env_set *es, + openvpn_net_ctx_t *ctx) { #if !defined(TARGET_LINUX) struct argv argv =3D argv_new(); @@ -1133,16 +1062,14 @@ msg(M_FATAL, "Linux can't bring %s up", ifname); } - if (net_addr_v6_add(ctx, ifname, &tt->local_ipv6, - tt->netbits_ipv6) < 0) + if (net_addr_v6_add(ctx, ifname, &tt->local_ipv6, tt->netbits_ipv6) < = 0) { msg(M_FATAL, "Linux can't add IPv6 to interface %s", ifname); } #elif defined(TARGET_ANDROID) char out6[64]; - snprintf(out6, sizeof(out6), "%s/%d %d", - ifconfig_ipv6_local, tt->netbits_ipv6, tun_mtu); + snprintf(out6, sizeof(out6), "%s/%d %d", ifconfig_ipv6_local, tt->netb= its_ipv6, tun_mtu); management_android_control(management, "IFCONFIG6", out6); #elif defined(TARGET_SOLARIS) argv_printf(&argv, "%s %s inet6 unplumb", IFCONFIG_PATH, ifname); @@ -1153,9 +1080,8 @@ { const char *ifconfig_ipv6_remote =3D print_in6_addr(tt->remote_ipv= 6, 0, &gc); - argv_printf(&argv, "%s %s inet6 plumb %s/%d %s mtu %d up", - IFCONFIG_PATH, ifname, ifconfig_ipv6_local, - tt->netbits_ipv6, ifconfig_ipv6_remote, tun_mtu); + argv_printf(&argv, "%s %s inet6 plumb %s/%d %s mtu %d up", IFCONFI= G_PATH, ifname, + ifconfig_ipv6_local, tt->netbits_ipv6, ifconfig_ipv6_r= emote, tun_mtu); } else /* tap mode */ { @@ -1163,8 +1089,7 @@ argv_printf(&argv, "%s %s inet6 plumb up", IFCONFIG_PATH, ifname); argv_msg(M_INFO, &argv); - if (!openvpn_execve_check(&argv, es, 0, - "Solaris ifconfig IPv6 (prepare) failed"= )) + if (!openvpn_execve_check(&argv, es, 0, "Solaris ifconfig IPv6 (pr= epare) failed")) { solaris_error_close(tt, es, ifname, true); } @@ -1178,8 +1103,8 @@ /* static IPv6 addresses need to go to a subinterface (tap0:1) * and we cannot set an mtu here (must go to the "parent") */ - argv_printf(&argv, "%s %s inet6 addif %s/%d up", IFCONFIG_PATH, - ifname, ifconfig_ipv6_local, tt->netbits_ipv6 ); + argv_printf(&argv, "%s %s inet6 addif %s/%d up", IFCONFIG_PATH, if= name, ifconfig_ipv6_local, + tt->netbits_ipv6); } argv_msg(M_INFO, &argv); @@ -1190,23 +1115,19 @@ if (tt->type !=3D DEV_TYPE_TUN) { - argv_printf(&argv, "%s %s inet6 mtu %d", IFCONFIG_PATH, - ifname, tun_mtu); + argv_printf(&argv, "%s %s inet6 mtu %d", IFCONFIG_PATH, ifname, tu= n_mtu); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, es, 0, "Solaris ifconfig IPv6 mtu fail= ed"); } -#elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) \ - || defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) \ - || defined(TARGET_DRAGONFLY) - argv_printf(&argv, "%s %s inet6 %s/%d mtu %d up", IFCONFIG_PATH, ifnam= e, - ifconfig_ipv6_local, tt->netbits_ipv6, tun_mtu); +#elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD) || defined(TARGET_= DARWIN) \ + || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) + argv_printf(&argv, "%s %s inet6 %s/%d mtu %d up", IFCONFIG_PATH, ifnam= e, ifconfig_ipv6_local, + tt->netbits_ipv6, tun_mtu); argv_msg(M_INFO, &argv); =20 - openvpn_execve_check(&argv, es, S_FATAL, - "generic BSD ifconfig inet6 failed"); + openvpn_execve_check(&argv, es, S_FATAL, "generic BSD ifconfig inet6 f= ailed"); -#if defined(TARGET_FREEBSD) && __FreeBSD_version >=3D 1200000 \ - && __FreeBSD_version < 1300000 +#if defined(TARGET_FREEBSD) && __FreeBSD_version >=3D 1200000 && __FreeBSD= _version < 1300000 /* On FreeBSD 12.0-12.4, there is ipv6_activate_all_interfaces=3D"YES" * in rc.conf, which is not set by default. If it is *not* set, * "all new interfaces that are not already up" are configured by @@ -1225,27 +1146,26 @@ argv_printf(&argv, "%s %s inet6 -ifdisabled", IFCONFIG_PATH, ifname); argv_msg(M_INFO, &argv); - openvpn_execve_check(&argv, es, S_FATAL, - "FreeBSD BSD 'ifconfig inet6 -ifdisabled' failed"= ); + openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD BSD 'ifconfig inet6 = -ifdisabled' failed"); #endif #elif defined(TARGET_AIX) - argv_printf(&argv, "%s %s inet6 %s/%d mtu %d up", IFCONFIG_PATH, ifnam= e, - ifconfig_ipv6_local, tt->netbits_ipv6, tun_mtu); + argv_printf(&argv, "%s %s inet6 %s/%d mtu %d up", IFCONFIG_PATH, ifnam= e, ifconfig_ipv6_local, + tt->netbits_ipv6, tun_mtu); argv_msg(M_INFO, &argv); /* AIX ifconfig will complain if it can't find ODM path in env */ es =3D env_set_create(NULL); env_set_add(es, "ODMDIR=3D/etc/objrepos"); - openvpn_execve_check(&argv, es, S_FATAL, - "generic BSD ifconfig inet6 failed"); + openvpn_execve_check(&argv, es, S_FATAL, "generic BSD ifconfig inet6 f= ailed"); env_set_destroy(es); -#elif defined (_WIN32) +#elif defined(_WIN32) if (tt->options.ip_win32_type =3D=3D IPW32_SET_MANUAL) { - msg(M_INFO, "******** NOTE: Please manually set the v6 IP of '%s'= to %s (if it is not already set)", + msg(M_INFO, + "******** NOTE: Please manually set the v6 IP of '%s' to %s (= if it is not already set)", ifname, ifconfig_ipv6_local); } else if (tt->options.msg_channel) @@ -1276,8 +1196,8 @@ int netbits =3D (tt->type =3D=3D DEV_TYPE_TUN) ? 128 : tt->netbits= _ipv6; argv_printf(&argv, "%s%s interface ipv6 set address %lu %s/%d stor= e=3Dactive", - get_win_sys_path(), NETSH_PATH_SUFFIX, tt->adapter_ind= ex, - ifconfig_ipv6_local, netbits); + get_win_sys_path(), NETSH_PATH_SUFFIX, tt->adapter_ind= ex, ifconfig_ipv6_local, + netbits); netsh_command(&argv, 4, M_FATAL); if (tt->type =3D=3D DEV_TYPE_TUN) { @@ -1292,8 +1212,9 @@ do_dns_domain_wmic(true, tt); } } -#else /* platforms we have no IPv6 code for */ - msg(M_FATAL, "Sorry, but I don't know how to do IPv6 'ifconfig' comman= ds on this operating system. You should ifconfig your TUN/TAP device manua= lly or use an --up script."); +#else /* platforms we have no IPv6 code for */ + msg(M_FATAL, + "Sorry, but I don't know how to do IPv6 'ifconfig' commands on thi= s operating system. You should ifconfig your TUN/TAP device manually or us= e an --up script."); #endif /* outer "if defined(TARGET_xxx)" conditional */ #if !defined(TARGET_LINUX) @@ -1312,8 +1233,8 @@ * @param ctx the networking API opaque context */ static void -do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, - const struct env_set *es, openvpn_net_ctx_t *ctx) +do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, const= struct env_set *es, + openvpn_net_ctx_t *ctx) { #if !defined(_WIN32) && !defined(TARGET_ANDROID) /* @@ -1348,16 +1269,14 @@ if (tun_p2p) { - if (net_addr_ptp_v4_add(ctx, ifname, &tt->local, - &tt->remote_netmask) < 0) + if (net_addr_ptp_v4_add(ctx, ifname, &tt->local, &tt->remote_netma= sk) < 0) { msg(M_FATAL, "Linux can't add IP to interface %s", ifname); } } else { - if (net_addr_v4_add(ctx, ifname, &tt->local, - netmask_to_netbits2(tt->remote_netmask)) < 0) + if (net_addr_v4_add(ctx, ifname, &tt->local, netmask_to_netbits2(t= t->remote_netmask)) < 0) { msg(M_FATAL, "Linux can't add IP to interface %s", ifname); } @@ -1365,8 +1284,8 @@ #elif defined(TARGET_ANDROID) char out[64]; - snprintf(out, sizeof(out), "%s %s %d %s", ifconfig_local, - ifconfig_remote_netmask, tun_mtu, print_topology(tt->topology= )); + snprintf(out, sizeof(out), "%s %s %d %s", ifconfig_local, ifconfig_rem= ote_netmask, tun_mtu, + print_topology(tt->topology)); management_android_control(management, "IFCONFIG", out); #elif defined(TARGET_SOLARIS) @@ -1377,8 +1296,8 @@ */ if (tun_p2p) { - argv_printf(&argv, "%s %s %s %s mtu %d up", IFCONFIG_PATH, ifname, - ifconfig_local, ifconfig_remote_netmask, tun_mtu); + argv_printf(&argv, "%s %s %s %s mtu %d up", IFCONFIG_PATH, ifname,= ifconfig_local, + ifconfig_remote_netmask, tun_mtu); argv_msg(M_INFO, &argv); if (!openvpn_execve_check(&argv, es, 0, "Solaris ifconfig phase-1 = failed")) @@ -1386,19 +1305,16 @@ solaris_error_close(tt, es, ifname, false); } - argv_printf(&argv, "%s %s netmask 255.255.255.255", IFCONFIG_PATH, - ifname); + argv_printf(&argv, "%s %s netmask 255.255.255.255", IFCONFIG_PATH,= ifname); } else if (tt->type =3D=3D DEV_TYPE_TUN) { - argv_printf(&argv, "%s %s %s %s netmask %s mtu %d up", IFCONFIG_PA= TH, - ifname, ifconfig_local, ifconfig_local, - ifconfig_remote_netmask, tun_mtu); + argv_printf(&argv, "%s %s %s %s netmask %s mtu %d up", IFCONFIG_PA= TH, ifname, + ifconfig_local, ifconfig_local, ifconfig_remote_netmas= k, tun_mtu); } else /* tap */ { - argv_printf(&argv, "%s %s %s netmask %s up", - IFCONFIG_PATH, ifname, ifconfig_local, + argv_printf(&argv, "%s %s %s netmask %s up", IFCONFIG_PATH, ifname= , ifconfig_local, ifconfig_remote_netmask); } @@ -1423,7 +1339,7 @@ #elif defined(TARGET_OPENBSD) - in_addr_t remote_end; /* for "virtual" subnet topology */ + in_addr_t remote_end; /* for "virtual" subnet topology */ /* * On OpenBSD, tun interfaces are persistent if created with @@ -1434,24 +1350,20 @@ /* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.255.2= 55.255 up */ if (tun_p2p) { - argv_printf(&argv, - "%s %s %s %s mtu %d netmask 255.255.255.255 up -link0", - IFCONFIG_PATH, ifname, ifconfig_local, - ifconfig_remote_netmask, tun_mtu); + argv_printf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.255 up = -link0", IFCONFIG_PATH, + ifname, ifconfig_local, ifconfig_remote_netmask, tun_m= tu); } else if (tt->type =3D=3D DEV_TYPE_TUN) { - remote_end =3D create_arbitrary_remote( tt ); - argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up -link0", - IFCONFIG_PATH, ifname, ifconfig_local, - print_in_addr_t(remote_end, 0, &gc), tun_mtu, + remote_end =3D create_arbitrary_remote(tt); + argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up -link0", IFCO= NFIG_PATH, ifname, + ifconfig_local, print_in_addr_t(remote_end, 0, &gc), t= un_mtu, ifconfig_remote_netmask); } else /* tap */ { - argv_printf(&argv, "%s %s %s netmask %s mtu %d link0", - IFCONFIG_PATH, ifname, ifconfig_local, - ifconfig_remote_netmask, tun_mtu); + argv_printf(&argv, "%s %s %s netmask %s mtu %d link0", IFCONFIG_PA= TH, ifname, + ifconfig_local, ifconfig_remote_netmask, tun_mtu); } argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, es, S_FATAL, "OpenBSD ifconfig failed"); @@ -1469,20 +1381,19 @@ } #elif defined(TARGET_NETBSD) - in_addr_t remote_end =3D INADDR_ANY; /* for "virtual" subnet topology= */ + in_addr_t remote_end =3D INADDR_ANY; /* for "virtual" subnet topology = */ =20 if (tun_p2p) { - argv_printf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.255 up", - IFCONFIG_PATH, ifname, ifconfig_local, - ifconfig_remote_netmask, tun_mtu); + argv_printf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.255 up"= , IFCONFIG_PATH, ifname, + ifconfig_local, ifconfig_remote_netmask, tun_mtu); } else if (tt->type =3D=3D DEV_TYPE_TUN) { remote_end =3D create_arbitrary_remote(tt); - argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up", IFCONFIG_PA= TH, - ifname, ifconfig_local, print_in_addr_t(remote_end, 0,= &gc), - tun_mtu, ifconfig_remote_netmask); + argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up", IFCONFIG_PA= TH, ifname, + ifconfig_local, print_in_addr_t(remote_end, 0, &gc), t= un_mtu, + ifconfig_remote_netmask); } else /* tap */ { @@ -1491,8 +1402,7 @@ * so we don't need the "link0" extra parameter to specify we want= to do * tunneling at the ethernet level */ - argv_printf(&argv, "%s %s %s netmask %s mtu %d", - IFCONFIG_PATH, ifname, ifconfig_local, + argv_printf(&argv, "%s %s %s netmask %s mtu %d", IFCONFIG_PATH, if= name, ifconfig_local, ifconfig_remote_netmask, tun_mtu); } argv_msg(M_INFO, &argv); @@ -1518,28 +1428,24 @@ argv_printf(&argv, "%s %s delete", IFCONFIG_PATH, ifname); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, es, 0, NULL); - msg(M_INFO, - "NOTE: Tried to delete pre-existing tun/tap instance -- No Problem= if failure"); + msg(M_INFO, "NOTE: Tried to delete pre-existing tun/tap instance -- No= Problem if failure"); /* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.255.2= 55.255 up */ if (tun_p2p) { - argv_printf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.255 up", - IFCONFIG_PATH, ifname, ifconfig_local, - ifconfig_remote_netmask, tun_mtu); + argv_printf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.255 up"= , IFCONFIG_PATH, ifname, + ifconfig_local, ifconfig_remote_netmask, tun_mtu); } else if (tt->type =3D=3D DEV_TYPE_TUN) { - argv_printf(&argv, "%s %s %s %s netmask %s mtu %d up", - IFCONFIG_PATH, ifname, ifconfig_local, ifconfig_local, - ifconfig_remote_netmask, tun_mtu); + argv_printf(&argv, "%s %s %s %s netmask %s mtu %d up", IFCONFIG_PA= TH, ifname, + ifconfig_local, ifconfig_local, ifconfig_remote_netmas= k, tun_mtu); } else /* tap */ { - argv_printf(&argv, "%s %s %s netmask %s mtu %d up", IFCONFIG_PATH, - ifname, ifconfig_local, ifconfig_remote_netmask, - tun_mtu); + argv_printf(&argv, "%s %s %s netmask %s mtu %d up", IFCONFIG_PATH,= ifname, ifconfig_local, + ifconfig_remote_netmask, tun_mtu); } argv_msg(M_INFO, &argv); @@ -1560,17 +1466,16 @@ #elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) /* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.255.2= 55.255 up */ - if (tun_p2p) /* point-to-point tun */ + if (tun_p2p) /* point-to-point tun */ { - argv_printf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.255 up", - IFCONFIG_PATH, ifname, ifconfig_local, - ifconfig_remote_netmask, tun_mtu); + argv_printf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.255 up"= , IFCONFIG_PATH, ifname, + ifconfig_local, ifconfig_remote_netmask, tun_mtu); } - else /* tun with topology subnet and tap mode (always subne= t) */ + else /* tun with topology subnet and tap mode (always subnet) */ { int netbits =3D netmask_to_netbits2(tt->remote_netmask); - argv_printf(&argv, "%s %s %s/%d mtu %d up", IFCONFIG_PATH, - ifname, ifconfig_local, netbits, tun_mtu ); + argv_printf(&argv, "%s %s %s/%d mtu %d up", IFCONFIG_PATH, ifname,= ifconfig_local, netbits, + tun_mtu); } argv_msg(M_INFO, &argv); @@ -1580,7 +1485,7 @@ { /* AIX ifconfig will complain if it can't find ODM path in env */ struct env_set *aix_es =3D env_set_create(NULL); - env_set_add( aix_es, "ODMDIR=3D/etc/objrepos" ); + env_set_add(aix_es, "ODMDIR=3D/etc/objrepos"); =20 if (tt->type =3D=3D DEV_TYPE_TUN) { @@ -1588,23 +1493,23 @@ } /* example: ifconfig tap0 172.30.1.1 netmask 255.255.254.0 up */ - argv_printf(&argv, "%s %s %s netmask %s mtu %d up", IFCONFIG_PATH, - ifname, ifconfig_local, ifconfig_remote_netmask, tun_m= tu); + argv_printf(&argv, "%s %s %s netmask %s mtu %d up", IFCONFIG_PATH,= ifname, ifconfig_local, + ifconfig_remote_netmask, tun_mtu); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, aix_es, S_FATAL, "AIX ifconfig failed"= ); env_set_destroy(aix_es); } -#elif defined (_WIN32) +#elif defined(_WIN32) if (tt->options.ip_win32_type =3D=3D IPW32_SET_MANUAL) { msg(M_INFO, "******** NOTE: Please manually set the IP/netmask of '%s' to= %s/%s (if it is not already set)", - ifname, ifconfig_local, - ifconfig_remote_netmask); + ifname, ifconfig_local, ifconfig_remote_netmask); } - else if (tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ || tt->o= ptions.ip_win32_type =3D=3D IPW32_SET_ADAPTIVE) + else if (tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ + || tt->options.ip_win32_type =3D=3D IPW32_SET_ADAPTIVE) { /* Let the DHCP configure the interface. */ } @@ -1619,8 +1524,8 @@ { if (tt->options.ip_win32_type =3D=3D IPW32_SET_NETSH) { - netsh_ifconfig(&tt->options, tt->adapter_index, tt->local, - tt->adapter_netmask, NI_IP_NETMASK | NI_OPTIONS= ); + netsh_ifconfig(&tt->options, tt->adapter_index, tt->local, tt-= >adapter_netmask, + NI_IP_NETMASK | NI_OPTIONS); } do_dns_domain_wmic(true, tt); @@ -1637,13 +1542,14 @@ } #elif defined(TARGET_HAIKU) /* example: ifconfig tun/0 inet 1.1.1.1 255.255.255.0 mtu 1450 up */ - argv_printf(&argv, "%s %s inet %s %s mtu %d up", IFCONFIG_PATH, - ifname, ifconfig_local, ifconfig_remote_netmask, tun_mtu); + argv_printf(&argv, "%s %s inet %s %s mtu %d up", IFCONFIG_PATH, ifname= , ifconfig_local, + ifconfig_remote_netmask, tun_mtu); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, es, S_FATAL, "Haiku ifconfig failed"); #else /* if defined(TARGET_LINUX) */ - msg(M_FATAL, "Sorry, but I don't know how to do 'ifconfig' commands on= this operating system. You should ifconfig your TUN/TAP device manually o= r use an --up script."); + msg(M_FATAL, + "Sorry, but I don't know how to do 'ifconfig' commands on this ope= rating system. You should ifconfig your TUN/TAP device manually or use an = --up script."); #endif /* if defined(TARGET_LINUX) */ #if !defined(TARGET_LINUX) @@ -1654,8 +1560,8 @@ /* execute the ifconfig command through the shell */ void -do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu, - const struct env_set *es, openvpn_net_ctx_t *ctx) +do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu, const stru= ct env_set *es, + openvpn_net_ctx_t *ctx) { msg(D_LOW, "do_ifconfig, ipv4=3D%d, ipv6=3D%d", tt->did_ifconfig_setup, tt->did_ifconfig_ipv6_setup); @@ -1663,13 +1569,8 @@ #ifdef ENABLE_MANAGEMENT if (management) { - management_set_state(management, - OPENVPN_STATE_ASSIGN_IP, - NULL, - &tt->local, - &tt->local_ipv6, - NULL, - NULL); + management_set_state(management, OPENVPN_STATE_ASSIGN_IP, NULL, &t= t->local, &tt->local_ipv6, + NULL, NULL); } #endif @@ -1695,19 +1596,16 @@ if (is_tun_p2p(tt)) { - if (net_addr_ptp_v4_del(ctx, tt->actual_name, &tt->local, - &tt->remote_netmask) < 0) + if (net_addr_ptp_v4_del(ctx, tt->actual_name, &tt->local, &tt->rem= ote_netmask) < 0) { - msg(M_WARN, "Linux can't del IP from iface %s", - tt->actual_name); + msg(M_WARN, "Linux can't del IP from iface %s", tt->actual_nam= e); } } else { if (net_addr_v4_del(ctx, tt->actual_name, &tt->local, netbits) < 0) { - msg(M_WARN, "Linux can't del IP from iface %s", - tt->actual_name); + msg(M_WARN, "Linux can't del IP from iface %s", tt->actual_nam= e); } } #elif defined(TARGET_FREEBSD) @@ -1715,8 +1613,7 @@ const char *ifconfig_local =3D print_in_addr_t(tt->local, 0, &gc); struct argv argv =3D argv_new(); - argv_printf(&argv, "%s %s %s -alias", IFCONFIG_PATH, - tt->actual_name, ifconfig_local); + argv_printf(&argv, "%s %s %s -alias", IFCONFIG_PATH, tt->actual_name, = ifconfig_local); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, NULL, 0, "FreeBSD ip addr del failed"); @@ -1730,8 +1627,7 @@ undo_ifconfig_ipv6(struct tuntap *tt, openvpn_net_ctx_t *ctx) { #if defined(TARGET_LINUX) - if (net_addr_v6_del(ctx, tt->actual_name, &tt->local_ipv6, - tt->netbits_ipv6) < 0) + if (net_addr_v6_del(ctx, tt->actual_name, &tt->local_ipv6, tt->netbits= _ipv6) < 0) { msg(M_WARN, "Linux can't del IPv6 from iface %s", tt->actual_name); } @@ -1740,8 +1636,8 @@ const char *ifconfig_ipv6_local =3D print_in6_addr(tt->local_ipv6, 0, = &gc); struct argv argv =3D argv_new(); - argv_printf(&argv, "%s %s inet6 %s/%d -alias", IFCONFIG_PATH, - tt->actual_name, ifconfig_ipv6_local, tt->netbits_ipv6); + argv_printf(&argv, "%s %s inet6 %s/%d -alias", IFCONFIG_PATH, tt->actu= al_name, + ifconfig_ipv6_local, tt->netbits_ipv6); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, NULL, 0, "FreeBSD ip -6 addr del failed"); @@ -1831,7 +1727,7 @@ struct iovec iv[2]; struct openvpn_iphdr *iph; - iph =3D (struct openvpn_iphdr *) buf; + iph =3D (struct openvpn_iphdr *)buf; if (OPENVPN_IPH_GET_VER(iph->version_len) =3D=3D 6) { @@ -1894,8 +1790,7 @@ #if !(defined(_WIN32) || defined(TARGET_LINUX) || defined(TARGET_SOLARIS)) static void -open_tun_generic(const char *dev, const char *dev_type, const char *dev_no= de, - struct tuntap *tt) +open_tun_generic(const char *dev, const char *dev_type, const char *dev_no= de, struct tuntap *tt) { char tunname[256]; char dynamic_name[256]; @@ -1925,10 +1820,8 @@ #if defined(TARGET_HAIKU) sep =3D "/"; #endif - snprintf(tunname, sizeof(tunname), - "/dev/%s%s%d", dev, sep, i); - snprintf(dynamic_name, sizeof(dynamic_name), - "%s%s%d", dev, sep, i); + snprintf(tunname, sizeof(tunname), "/dev/%s%s%d", dev, sep= , i); + snprintf(dynamic_name, sizeof(dynamic_name), "%s%s%d", dev= , sep, i); if ((tt->fd =3D open(tunname, O_RDWR)) > 0) { dynamic_opened =3D true; @@ -1953,9 +1846,9 @@ if (!dynamic_opened) { /* has named device existed before? if so, don't destroy at end */ - if (if_nametoindex( dev ) > 0) + if (if_nametoindex(dev) > 0) { - msg(M_INFO, "TUN/TAP device %s exists previously, keep at prog= ram end", dev ); + msg(M_INFO, "TUN/TAP device %s exists previously, keep at prog= ram end", dev); tt->persistent_if =3D true; } @@ -1971,14 +1864,13 @@ /* tt->actual_name is passed to up and down scripts and used as the if= config dev name */ tt->actual_name =3D string_alloc(dynamic_opened ? dynamic_name : dev, = NULL); - } #endif /* !_WIN32 && !TARGET_LINUX && !TARGET_FREEBSD*/ #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) static void -open_tun_dco_generic(const char *dev, const char *dev_type, - struct tuntap *tt, openvpn_net_ctx_t *ctx) +open_tun_dco_generic(const char *dev, const char *dev_type, struct tuntap = *tt, + openvpn_net_ctx_t *ctx) { char dynamic_name[256]; bool dynamic_opened =3D false; @@ -1995,8 +1887,7 @@ { for (int i =3D 0; i < 256; ++i) { - snprintf(dynamic_name, sizeof(dynamic_name), - "%s%d", dev, i); + snprintf(dynamic_name, sizeof(dynamic_name), "%s%d", dev, i); int ret =3D open_tun_dco(tt, ctx, dynamic_name); if (ret =3D=3D 0) { @@ -2026,14 +1917,12 @@ int ret =3D open_tun_dco(tt, ctx, dev); if (ret =3D=3D -EEXIST) { - msg(M_INFO, "DCO device %s already exists, won't be destroyed = at shutdown", - dev); + msg(M_INFO, "DCO device %s already exists, won't be destroyed = at shutdown", dev); tt->persistent_if =3D true; } else if (ret < 0) { - msg(M_ERR, "Cannot open DCO device %s: %s (%d)", dev, - strerror(-ret), ret); + msg(M_ERR, "Cannot open DCO device %s: %s (%d)", dev, strerror= (-ret), ret); } else { @@ -2060,7 +1949,7 @@ } #endif /* !_WIN32 */ -#if defined (TARGET_ANDROID) +#if defined(TARGET_ANDROID) void open_tun(const char *dev, const char *dev_type, const char *dev_node, stru= ct tuntap *tt, openvpn_net_ctx_t *ctx) @@ -2100,7 +1989,7 @@ int android_method =3D managment_android_persisttun_action(management); - if (oldtunfd >=3D0 && android_method =3D=3D ANDROID_KEEP_OLD_TUN) + if (oldtunfd >=3D 0 && android_method =3D=3D ANDROID_KEEP_OLD_TUN) { /* keep the old fd */ opentun =3D true; @@ -2211,8 +2100,7 @@ } else { - msg(M_FATAL, "I don't recognize device %s as a tun or tap devi= ce", - dev); + msg(M_FATAL, "I don't recognize device %s as a tun or tap devi= ce", dev); } /* @@ -2227,7 +2115,7 @@ * Use special ioctl that configures tun/tap device with the parms * we set in ifr */ - if (ioctl(tt->fd, TUNSETIFF, (void *) &ifr) < 0) + if (ioctl(tt->fd, TUNSETIFF, (void *)&ifr) < 0) { msg(M_ERR, "ERROR: Cannot ioctl TUNSETIFF %s", dev); } @@ -2248,7 +2136,7 @@ CLEAR(netifr); strncpynt(netifr.ifr_name, ifr.ifr_name, IFNAMSIZ); netifr.ifr_qlen =3D tt->options.txqueuelen; - if (ioctl(ctl_fd, SIOCSIFTXQLEN, (void *) &netifr) >=3D 0) + if (ioctl(ctl_fd, SIOCSIFTXQLEN, (void *)&netifr) >=3D 0) { msg(D_OSBUF, "TUN/TAP TX queue length set to %d", tt->= options.txqueuelen); } @@ -2287,13 +2175,13 @@ /* TUNSETGROUP appeared in 2.6.23 */ #ifndef TUNSETGROUP -#define TUNSETGROUP _IOW('T', 206, int) +#define TUNSETGROUP _IOW('T', 206, int) #endif void -tuncfg(const char *dev, const char *dev_type, const char *dev_node, - int persist_mode, const char *username, const char *groupname, - const struct tuntap_options *options, openvpn_net_ctx_t *ctx) +tuncfg(const char *dev, const char *dev_type, const char *dev_node, int pe= rsist_mode, + const char *username, const char *groupname, const struct tuntap_op= tions *options, + openvpn_net_ctx_t *ctx) { struct tuntap *tt; @@ -2413,8 +2301,7 @@ } else { - msg(M_FATAL, "I don't recognize device %s as a tun or tap device", - dev); + msg(M_FATAL, "I don't recognize device %s as a tun or tap device",= dev); } if ((tt->ip_fd =3D open(ip_node, O_RDWR, 0)) < 0) @@ -2432,7 +2319,7 @@ /* get unit number */ if (*ptr) { - while (*ptr && !isdigit((int) *ptr)) + while (*ptr && !isdigit((int)*ptr)) { ptr++; } @@ -2445,7 +2332,7 @@ strioc_ppa.ic_len =3D sizeof(ppa); strioc_ppa.ic_dp =3D (char *)&ppa; - if (*ptr =3D=3D '\0') /* no number given, try dynamic */ + if (*ptr =3D=3D '\0') /* no number given, try dynamic */ { bool found_one =3D false; while (!found_one && ppa < 64) @@ -2453,27 +2340,28 @@ int new_ppa =3D ioctl(tt->fd, I_STR, &strioc_ppa); if (new_ppa >=3D 0) { - msg( M_INFO, "open_tun: got dynamic interface '%s%d'", dev= _tuntap_type, new_ppa ); + msg(M_INFO, "open_tun: got dynamic interface '%s%d'", dev_= tuntap_type, new_ppa); ppa =3D new_ppa; found_one =3D true; break; } if (errno !=3D EEXIST) { - msg(M_ERR, "open_tun: unexpected error trying to find free= %s interface", dev_tuntap_type ); + msg(M_ERR, "open_tun: unexpected error trying to find free= %s interface", + dev_tuntap_type); } ppa++; } if (!found_one) { - msg(M_ERR, "open_tun: could not find free %s interface, give u= p.", dev_tuntap_type ); + msg(M_ERR, "open_tun: could not find free %s interface, give u= p.", dev_tuntap_type); } } - else /* try this particular one */ + else /* try this particular one */ { if ((ppa =3D ioctl(tt->fd, I_STR, &strioc_ppa)) < 0) { - msg(M_ERR, "Can't assign PPA for new interface (%s%d)", dev_tu= ntap_type, ppa ); + msg(M_ERR, "Can't assign PPA for new interface (%s%d)", dev_tu= ntap_type, ppa); } } @@ -2490,13 +2378,13 @@ if (tt->type =3D=3D DEV_TYPE_TUN) { /* Assign ppa according to the unit number returned by tun device = */ - if (ioctl(if_fd, IF_UNITSEL, (char *) &ppa) < 0) + if (ioctl(if_fd, IF_UNITSEL, (char *)&ppa) < 0) { msg(M_ERR, "Can't set PPA %d", ppa); } } - tt->actual_name =3D (char *) malloc(32); + tt->actual_name =3D (char *)malloc(32); check_malloc_return(tt->actual_name); snprintf(tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa); @@ -2514,7 +2402,7 @@ { msg(M_ERR, "Can't set PPA %d", ppa); } - if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0) + if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0) { msg(M_ERR, "Can't get flags\n"); } @@ -2576,7 +2464,7 @@ CLEAR(ifr); strncpynt(ifr.lifr_name, tt->actual_name, sizeof(ifr.lifr_name)); - ifr.lifr_ip_muxid =3D ip_muxid; + ifr.lifr_ip_muxid =3D ip_muxid; if (tt->type =3D=3D DEV_TYPE_TAP) { ifr.lifr_arp_muxid =3D arp_muxid; @@ -2606,8 +2494,7 @@ if (tt->did_ifconfig_ipv6_setup) { struct argv argv =3D argv_new(); - argv_printf( &argv, "%s %s inet6 unplumb", - IFCONFIG_PATH, tt->actual_name ); + argv_printf(&argv, "%s %s inet6 unplumb", IFCONFIG_PATH, tt->actua= l_name); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, NULL, 0, "Solaris ifconfig inet6 unplu= mb failed"); argv_free(&argv); @@ -2670,23 +2557,19 @@ } static void -solaris_error_close(struct tuntap *tt, const struct env_set *es, - const char *actual, bool unplumb_inet6 ) +solaris_error_close(struct tuntap *tt, const struct env_set *es, const cha= r *actual, + bool unplumb_inet6) { struct argv argv =3D argv_new(); if (unplumb_inet6) { - argv_printf( &argv, "%s %s inet6 unplumb", - IFCONFIG_PATH, actual ); + argv_printf(&argv, "%s %s inet6 unplumb", IFCONFIG_PATH, actual); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, es, 0, "Solaris ifconfig inet6 unplumb= failed"); } - argv_printf(&argv, - "%s %s unplumb", - IFCONFIG_PATH, - actual); + argv_printf(&argv, "%s %s unplumb", IFCONFIG_PATH, actual); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, es, 0, "Solaris ifconfig unplumb failed"); @@ -2772,8 +2655,7 @@ /* setup command, close tun dev (clears tt->actual_name!), run command */ - argv_printf(&argv, "%s %s destroy", - IFCONFIG_PATH, tt->actual_name); + argv_printf(&argv, "%s %s destroy", IFCONFIG_PATH, tt->actual_name); close_tun_generic(tt); =20 @@ -2823,11 +2705,11 @@ if (strcmp(dev, "tap") =3D=3D 0) { struct ifreq ifr; - if ((tt->fd =3D open( "/dev/tap", O_RDWR)) < 0) + if ((tt->fd =3D open("/dev/tap", O_RDWR)) < 0) { msg(M_FATAL, "Cannot allocate NetBSD TAP dev dynamically"); } - if (ioctl( tt->fd, TAPGIFNAME, (void *)&ifr ) < 0) + if (ioctl(tt->fd, TAPGIFNAME, (void *)&ifr) < 0) { msg(M_FATAL, "Cannot query NetBSD TAP device name"); } @@ -2847,15 +2729,15 @@ if (tt->fd >=3D 0) { - int i =3D IFF_POINTOPOINT|IFF_MULTICAST; - ioctl(tt->fd, TUNSIFMODE, &i); /* multicast on */ + int i =3D IFF_POINTOPOINT | IFF_MULTICAST; + ioctl(tt->fd, TUNSIFMODE, &i); /* multicast on */ i =3D 0; - ioctl(tt->fd, TUNSLMODE, &i); /* link layer mode off */ + ioctl(tt->fd, TUNSLMODE, &i); /* link layer mode off */ if (tt->type =3D=3D DEV_TYPE_TUN) { i =3D 1; - if (ioctl(tt->fd, TUNSIFHEAD, &i) < 0) /* multi-af mode o= n */ + if (ioctl(tt->fd, TUNSIFHEAD, &i) < 0) /* multi-af mode on */ { msg(M_WARN | M_ERRNO, "ioctl(TUNSIFHEAD)"); } @@ -2886,8 +2768,7 @@ /* setup command, close tun dev (clears tt->actual_name!), run command */ - argv_printf(&argv, "%s %s destroy", - IFCONFIG_PATH, tt->actual_name); + argv_printf(&argv, "%s %s destroy", IFCONFIG_PATH, tt->actual_name); close_tun_generic(tt); @@ -2920,7 +2801,7 @@ struct iovec iv[2]; struct openvpn_iphdr *iph; - iph =3D (struct openvpn_iphdr *) buf; + iph =3D (struct openvpn_iphdr *)buf; if (OPENVPN_IPH_GET_VER(iph->version_len) =3D=3D 6) { @@ -3028,7 +2909,7 @@ { ASSERT(tt); - if (tt->persistent_if) /* keep pre-existing if around */ + if (tt->persistent_if) /* keep pre-existing if around */ { close_tun_generic(tt); free(tt); @@ -3041,14 +2922,12 @@ /* setup command, close tun dev (clears tt->actual_name!), run command */ - argv_printf(&argv, "%s %s destroy", - IFCONFIG_PATH, tt->actual_name); + argv_printf(&argv, "%s %s destroy", IFCONFIG_PATH, tt->actual_name); close_tun_generic(tt); argv_msg(M_INFO, &argv); - openvpn_execve_check(&argv, NULL, 0, - "FreeBSD 'destroy tun interface' failed (non-crit= ical)"); + openvpn_execve_check(&argv, NULL, 0, "FreeBSD 'destroy tun interface' = failed (non-critical)"); free(tt); argv_free(&argv); @@ -3063,7 +2942,7 @@ struct iovec iv[2]; struct ip *iph; - iph =3D (struct ip *) buf; + iph =3D (struct ip *)buf; if (iph->ip_v =3D=3D 6) { @@ -3158,7 +3037,7 @@ struct iovec iv[2]; struct ip *iph; - iph =3D (struct ip *) buf; + iph =3D (struct ip *)buf; if (iph->ip_v =3D=3D 6) { @@ -3234,16 +3113,14 @@ if (fd < 0) { - msg(M_INFO | M_ERRNO, "Opening utun%d failed (socket(SYSPROTO_CONT= ROL))", - utunnum); + msg(M_INFO | M_ERRNO, "Opening utun%d failed (socket(SYSPROTO_CONT= ROL))", utunnum); return -2; } if (ioctl(fd, CTLIOCGINFO, &ctlInfo) =3D=3D -1) { close(fd); - msg(M_INFO | M_ERRNO, "Opening utun%d failed (ioctl(CTLIOCGINFO))", - utunnum); + msg(M_INFO | M_ERRNO, "Opening utun%d failed (ioctl(CTLIOCGINFO))"= , utunnum); return -2; } @@ -3253,7 +3130,7 @@ sc.sc_family =3D AF_SYSTEM; sc.ss_sysaddr =3D AF_SYS_CONTROL; - sc.sc_unit =3D utunnum+1; + sc.sc_unit =3D utunnum + 1; /* If the connect is successful, a utun%d device will be created, wher= e "%d" @@ -3261,8 +3138,7 @@ if (connect(fd, (struct sockaddr *)&sc, sizeof(sc)) < 0) { - msg(M_INFO | M_ERRNO, "Opening utun%d failed (connect(AF_SYS_CONTR= OL))", - utunnum); + msg(M_INFO | M_ERRNO, "Opening utun%d failed (connect(AF_SYS_CONTR= OL))", utunnum); close(fd); return -1; } @@ -3284,20 +3160,21 @@ /* dev_node is simply utun, do the normal dynamic utun * otherwise try to parse the utun number */ - if (dev_node && (strcmp("utun", dev_node) !=3D 0 )) + if (dev_node && (strcmp("utun", dev_node) !=3D 0)) { if (sscanf(dev_node, "utun%d", &utunnum) !=3D 1) { - msg(M_FATAL, "Cannot parse 'dev-node %s' please use 'dev-node = utunX'" - "to use a utun device number X", dev_node); + msg(M_FATAL, + "Cannot parse 'dev-node %s' please use 'dev-node utunX'" + "to use a utun device number X", + dev_node); } } - CLEAR(ctlInfo); - if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof(ctlInfo.ctl_na= me)) >=3D - sizeof(ctlInfo.ctl_name)) + if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof(ctlInfo.ctl_na= me)) + >=3D sizeof(ctlInfo.ctl_name)) { msg(M_ERR, "Opening utun: UTUN_CONTROL_NAME too long"); } @@ -3317,7 +3194,7 @@ fd =3D utun_open_helper(ctlInfo, utunnum); /* Break if the fd is valid, * or if early initialization failed (-2) */ - if (fd !=3D-1) + if (fd !=3D -1) { break; } @@ -3353,13 +3230,11 @@ openvpn_net_ctx_t *ctx) { /* If dev_node does not start start with utun assume regular tun/tap */ - if ((!dev_node && tt->type=3D=3DDEV_TYPE_TUN) - || (dev_node && !strncmp(dev_node, "utun", 4))) + if ((!dev_node && tt->type =3D=3D DEV_TYPE_TUN) || (dev_node && !strnc= mp(dev_node, "utun", 4))) { - /* Check if user has specific dev_type tap and forced utun with * dev-node utun */ - if (tt->type!=3DDEV_TYPE_TUN) + if (tt->type !=3D DEV_TYPE_TUN) { msg(M_FATAL, "Cannot use utun devices with --dev-type %s", dev_type_string(dev, dev_type)); @@ -3387,12 +3262,11 @@ } else { - /* Use plain dev-node tun to select /dev/tun style * Unset dev_node variable prior to passing to open_tun_generic to * let open_tun_generic pick the first available tun device */ - if (dev_node && strcmp(dev_node, "tun")=3D=3D0) + if (dev_node && strcmp(dev_node, "tun") =3D=3D 0) { dev_node =3D NULL; } @@ -3411,11 +3285,9 @@ if (tt->did_ifconfig_ipv6_setup) { - const char *ifconfig_ipv6_local =3D - print_in6_addr(tt->local_ipv6, 0, &gc); + const char *ifconfig_ipv6_local =3D print_in6_addr(tt->local_ipv6,= 0, &gc); - argv_printf(&argv, "%s delete -inet6 %s", - ROUTE_PATH, ifconfig_ipv6_local ); + argv_printf(&argv, "%s delete -inet6 %s", ROUTE_PATH, ifconfig_ipv= 6_local); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, NULL, 0, "MacOS X 'remove inet6 route'= failed (non-critical)"); } @@ -3464,44 +3336,46 @@ if (tt->type =3D=3D DEV_TYPE_TUN) { - msg(M_FATAL, "no support for 'tun' devices on AIX" ); + msg(M_FATAL, "no support for 'tun' devices on AIX"); } - if (strncmp( dev, "tap", 3 ) !=3D 0 || dev_node) + if (strncmp(dev, "tap", 3) !=3D 0 || dev_node) { - msg(M_FATAL, "'--dev %s' and/or '--dev-node' not supported on AIX,= use '--dev tap0', 'tap1', etc.", dev ); + msg(M_FATAL, + "'--dev %s' and/or '--dev-node' not supported on AIX, use '--d= ev tap0', 'tap1', etc.", + dev); } - if (strcmp( dev, "tap" ) =3D=3D 0) /* find first free tap= dev */ - { /* (=3D no /dev/tapN node)= */ + if (strcmp(dev, "tap") =3D=3D 0) /* find first free tap dev */ + { /* (=3D no /dev/tapN node) */ int i; - for (i =3D 0; i<99; i++) + for (i =3D 0; i < 99; i++) { snprintf(tunname, sizeof(tunname), "/dev/tap%d", i); - if (access( tunname, F_OK ) < 0 && errno =3D=3D ENOENT) + if (access(tunname, F_OK) < 0 && errno =3D=3D ENOENT) { break; } } if (i >=3D 99) { - msg( M_FATAL, "cannot find unused tap device" ); + msg(M_FATAL, "cannot find unused tap device"); } - snprintf( dynamic_name, sizeof(dynamic_name), "tap%d", i ); + snprintf(dynamic_name, sizeof(dynamic_name), "tap%d", i); dev =3D dynamic_name; } - else /* name given, sanity chec= k */ + else /* name given, sanity check */ { /* ensure that dev name is "tap+" *only* */ p =3D &dev[3]; - while (isdigit(*p) ) + while (isdigit(*p)) { p++; } if (*p !=3D '\0') { - msg( M_FATAL, "TAP device name must be '--dev tapNNNN'" ); + msg(M_FATAL, "TAP device name must be '--dev tapNNNN'"); } snprintf(tunname, sizeof(tunname), "/dev/%s", dev); @@ -3509,16 +3383,15 @@ /* pre-existing device? */ - if (access( tunname, F_OK ) < 0 && errno =3D=3D ENOENT) + if (access(tunname, F_OK) < 0 && errno =3D=3D ENOENT) { - /* tunnel device must be created with 'ifconfig tapN create' */ struct argv argv =3D argv_new(); struct env_set *es =3D env_set_create(NULL); argv_printf(&argv, "%s %s create", IFCONFIG_PATH, dev); argv_msg(M_INFO, &argv); - env_set_add( es, "ODMDIR=3D/etc/objrepos" ); + env_set_add(es, "ODMDIR=3D/etc/objrepos"); openvpn_execve_check(&argv, es, S_FATAL, "AIX 'create tun interfac= e' failed"); env_set_destroy(es); argv_free(&argv); @@ -3556,18 +3429,16 @@ */ if (tt->persistent_if) { - argv_printf(&argv, "%s %s 0.0.0.0 down", - IFCONFIG_PATH, tt->actual_name); + argv_printf(&argv, "%s %s 0.0.0.0 down", IFCONFIG_PATH, tt->actual= _name); } else { - argv_printf(&argv, "%s %s destroy", - IFCONFIG_PATH, tt->actual_name); + argv_printf(&argv, "%s %s destroy", IFCONFIG_PATH, tt->actual_name= ); } close_tun_generic(tt); argv_msg(M_INFO, &argv); - env_set_add( es, "ODMDIR=3D/etc/objrepos" ); + env_set_add(es, "ODMDIR=3D/etc/objrepos"); openvpn_execve_check(&argv, es, 0, "AIX 'destroy tap interface' failed= (non-critical)"); free(tt); @@ -3607,13 +3478,8 @@ /* the overlapped read will signal this event on I/O completion */ ASSERT(ResetEvent(tt->reads.overlapped.hEvent)); - status =3D ReadFile( - tt->hand, - BPTR(&tt->reads.buf), - len, - &tt->reads.size, - &tt->reads.overlapped - ); + status =3D + ReadFile(tt->hand, BPTR(&tt->reads.buf), len, &tt->reads.size,= &tt->reads.overlapped); if (status) /* operation completed immediately? */ { @@ -3623,9 +3489,8 @@ tt->reads.iostate =3D IOSTATE_IMMEDIATE_RETURN; tt->reads.status =3D 0; - dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read immediate return [%d,%d]= ", - (int) len, - (int) tt->reads.size); + dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read immediate return [%d,%d]= ", (int)len, + (int)tt->reads.size); } else { @@ -3634,8 +3499,7 @@ { tt->reads.iostate =3D IOSTATE_QUEUED; tt->reads.status =3D err; - dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read queued [%d]", - (int) len); + dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read queued [%d]", (int)l= en); } else /* error occurred */ { @@ -3643,8 +3507,7 @@ ASSERT(SetEvent(tt->reads.overlapped.hEvent)); tt->reads.iostate =3D IOSTATE_IMMEDIATE_RETURN; tt->reads.status =3D err; - dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read error [%d] : %s", - (int) len, + dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read error [%d] : %s", (i= nt)len, strerror_win32(status, &gc)); gc_free(&gc); } @@ -3669,13 +3532,8 @@ /* the overlapped write will signal this event on I/O completion */ ASSERT(ResetEvent(tt->writes.overlapped.hEvent)); - status =3D WriteFile( - tt->hand, - BPTR(&tt->writes.buf), - BLEN(&tt->writes.buf), - &tt->writes.size, - &tt->writes.overlapped - ); + status =3D WriteFile(tt->hand, BPTR(&tt->writes.buf), BLEN(&tt->wr= ites.buf), &tt->writes.size, + &tt->writes.overlapped); =20 if (status) /* operation completed immediately? */ { @@ -3686,9 +3544,8 @@ tt->writes.status =3D 0; - dmsg(D_WIN32_IO, "WIN32 I/O: TAP Write immediate return [%d,%d= ]", - BLEN(&tt->writes.buf), - (int) tt->writes.size); + dmsg(D_WIN32_IO, "WIN32 I/O: TAP Write immediate return [%d,%d= ]", BLEN(&tt->writes.buf), + (int)tt->writes.size); } else { @@ -3697,8 +3554,7 @@ { tt->writes.iostate =3D IOSTATE_QUEUED; tt->writes.status =3D err; - dmsg(D_WIN32_IO, "WIN32 I/O: TAP Write queued [%d]", - BLEN(&tt->writes.buf)); + dmsg(D_WIN32_IO, "WIN32 I/O: TAP Write queued [%d]", BLEN(= &tt->writes.buf)); } else /* error occurred */ { @@ -3706,8 +3562,7 @@ ASSERT(SetEvent(tt->writes.overlapped.hEvent)); tt->writes.iostate =3D IOSTATE_IMMEDIATE_RETURN; tt->writes.status =3D err; - dmsg(D_WIN32_IO, "WIN32 I/O: TAP Write error [%d] : %s", - BLEN(&tt->writes.buf), + dmsg(D_WIN32_IO, "WIN32 I/O: TAP Write error [%d] : %s", B= LEN(&tt->writes.buf), strerror_win32(err, &gc)); gc_free(&gc); } @@ -3750,11 +3605,13 @@ struct device_instance_id_interface *first =3D NULL; struct device_instance_id_interface *last =3D NULL; - dev_info_set =3D SetupDiGetClassDevsEx(&GUID_DEVCLASS_NET, NULL, NULL,= DIGCF_PRESENT, NULL, NULL, NULL); + dev_info_set =3D + SetupDiGetClassDevsEx(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESEN= T, NULL, NULL, NULL); if (dev_info_set =3D=3D INVALID_HANDLE_VALUE) { err =3D GetLastError(); - msg(M_FATAL, "Error [%u] opening device information set key: %s", = (unsigned int)err, strerror_win32(err, gc)); + msg(M_FATAL, "Error [%u] opening device information set key: %s", = (unsigned int)err, + strerror_win32(err, gc)); } msg(D_TAP_WIN_DEBUG, "Enumerate device interface lists:"); @@ -3787,7 +3644,8 @@ } } - dev_key =3D SetupDiOpenDevRegKey(dev_info_set, &device_info_data, = DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE); + dev_key =3D SetupDiOpenDevRegKey(dev_info_set, &device_info_data, = DICS_FLAG_GLOBAL, 0, + DIREG_DRV, KEY_QUERY_VALUE); if (dev_key =3D=3D INVALID_HANDLE_VALUE) { continue; @@ -3795,27 +3653,23 @@ len =3D sizeof(net_cfg_instance_id); data_type =3D REG_SZ; - status =3D RegQueryValueEx(dev_key, - net_cfg_instance_id_string, - NULL, - &data_type, - net_cfg_instance_id, - &len); + status =3D RegQueryValueEx(dev_key, net_cfg_instance_id_string, NU= LL, &data_type, + net_cfg_instance_id, &len); if (status !=3D ERROR_SUCCESS) { goto next; } len =3D sizeof(device_instance_id); - res =3D SetupDiGetDeviceInstanceId(dev_info_set, &device_info_data= , device_instance_id, len, &len); + res =3D SetupDiGetDeviceInstanceId(dev_info_set, &device_info_data= , device_instance_id, len, + &len); if (!res) { goto next; } cr =3D CM_Get_Device_Interface_List_Size(&dev_interface_list_size, - (LPGUID)&GUID_DEVINTERFACE_= NET, - device_instance_id, + (LPGUID)&GUID_DEVINTERFACE_= NET, device_instance_id, CM_GET_DEVICE_INTERFACE_LIS= T_PRESENT); if (cr !=3D CR_SUCCESS) @@ -3825,8 +3679,7 @@ char *dev_interface_list =3D gc_malloc(dev_interface_list_size, fa= lse, gc); cr =3D CM_Get_Device_Interface_List((LPGUID)&GUID_DEVINTERFACE_NET= , device_instance_id, - dev_interface_list, - dev_interface_list_size, + dev_interface_list, dev_interfac= e_list_size, CM_GET_DEVICE_INTERFACE_LIST_PRE= SENT); if (cr !=3D CR_SUCCESS) { @@ -3840,12 +3693,12 @@ { struct device_instance_id_interface *dev_iif; ALLOC_OBJ_CLEAR_GC(dev_iif, struct device_instance_id_interfac= e, gc); - dev_iif->net_cfg_instance_id =3D (unsigned char *)string_alloc= ((char *)net_cfg_instance_id, gc); + dev_iif->net_cfg_instance_id =3D + (unsigned char *)string_alloc((char *)net_cfg_instance_id,= gc); dev_iif->device_interface =3D string_alloc(dev_if, gc); msg(D_TAP_WIN_DEBUG, "NetCfgInstanceId: %s, Device Interface: = %s", - dev_iif->net_cfg_instance_id, - dev_iif->device_interface); + dev_iif->net_cfg_instance_id, dev_iif->device_interface); /* link into return list */ if (!first) @@ -3880,12 +3733,7 @@ struct tap_reg *last =3D NULL; int i =3D 0; - status =3D RegOpenKeyEx( - HKEY_LOCAL_MACHINE, - ADAPTER_KEY, - 0, - KEY_READ, - &adapter_key); + status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, ADAPTER_KEY, 0, KEY_READ, = &adapter_key); if (status !=3D ERROR_SUCCESS) { @@ -3905,34 +3753,19 @@ DWORD data_type; len =3D sizeof(enum_name); - status =3D RegEnumKeyEx( - adapter_key, - i, - enum_name, - &len, - NULL, - NULL, - NULL, - NULL); + status =3D RegEnumKeyEx(adapter_key, i, enum_name, &len, NULL, NUL= L, NULL, NULL); if (status =3D=3D ERROR_NO_MORE_ITEMS) { break; } else if (status !=3D ERROR_SUCCESS) { - msg(M_FATAL, "Error enumerating registry subkeys of key: %s", - ADAPTER_KEY); + msg(M_FATAL, "Error enumerating registry subkeys of key: %s", = ADAPTER_KEY); } - snprintf(unit_string, sizeof(unit_string), "%s\\%s", - ADAPTER_KEY, enum_name); + snprintf(unit_string, sizeof(unit_string), "%s\\%s", ADAPTER_KEY, = enum_name); - status =3D RegOpenKeyEx( - HKEY_LOCAL_MACHINE, - unit_string, - 0, - KEY_READ, - &unit_key); + status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit_string, 0, KEY_RE= AD, &unit_key); if (status !=3D ERROR_SUCCESS) { @@ -3941,29 +3774,19 @@ else { len =3D sizeof(component_id); - status =3D RegQueryValueEx( - unit_key, - component_id_string, - NULL, - &data_type, - (LPBYTE)component_id, - &len); + status =3D RegQueryValueEx(unit_key, component_id_string, NULL= , &data_type, + (LPBYTE)component_id, &len); if (status !=3D ERROR_SUCCESS || data_type !=3D REG_SZ) { - dmsg(D_REGISTRY, "Error opening registry key: %s\\%s", - unit_string, component_id_string); + dmsg(D_REGISTRY, "Error opening registry key: %s\\%s", uni= t_string, + component_id_string); } else { len =3D sizeof(net_cfg_instance_id); - status =3D RegQueryValueEx( - unit_key, - net_cfg_instance_id_string, - NULL, - &data_type, - net_cfg_instance_id, - &len); + status =3D RegQueryValueEx(unit_key, net_cfg_instance_id_s= tring, NULL, &data_type, + net_cfg_instance_id, &len); if (status =3D=3D ERROR_SUCCESS && data_type =3D=3D REG_SZ) { @@ -3997,8 +3820,8 @@ } last =3D reg; - msg(D_TAP_WIN_DEBUG, "NetCfgInstanceId: %s, Driver= : %s", - reg->guid, print_tun_backend_driver(reg->windo= ws_driver)); + msg(D_TAP_WIN_DEBUG, "NetCfgInstanceId: %s, Driver= : %s", reg->guid, + print_tun_backend_driver(reg->windows_driver)); } } } @@ -4021,12 +3844,8 @@ struct panel_reg *last =3D NULL; int i =3D 0; - status =3D RegOpenKeyEx( - HKEY_LOCAL_MACHINE, - NETWORK_CONNECTIONS_KEY, - 0, - KEY_READ, - &network_connections_key); + status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0= , KEY_READ, + &network_connections_key); if (status !=3D ERROR_SUCCESS) { @@ -4043,35 +3862,20 @@ const WCHAR name_string[] =3D L"Name"; len =3D sizeof(enum_name); - status =3D RegEnumKeyEx( - network_connections_key, - i, - enum_name, - &len, - NULL, - NULL, - NULL, - NULL); + status =3D RegEnumKeyEx(network_connections_key, i, enum_name, &le= n, NULL, NULL, NULL, NULL); if (status =3D=3D ERROR_NO_MORE_ITEMS) { break; } else if (status !=3D ERROR_SUCCESS) { - msg(M_FATAL, "Error enumerating registry subkeys of key: %s", - NETWORK_CONNECTIONS_KEY); + msg(M_FATAL, "Error enumerating registry subkeys of key: %s", = NETWORK_CONNECTIONS_KEY); } - snprintf(connection_string, sizeof(connection_string), - "%s\\%s\\Connection", + snprintf(connection_string, sizeof(connection_string), "%s\\%s\\Co= nnection", NETWORK_CONNECTIONS_KEY, enum_name); - status =3D RegOpenKeyEx( - HKEY_LOCAL_MACHINE, - connection_string, - 0, - KEY_READ, - &connection_key); + status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, connection_string, 0, = KEY_READ, &connection_key); if (status !=3D ERROR_SUCCESS) { @@ -4080,18 +3884,13 @@ else { len =3D sizeof(name_data); - status =3D RegQueryValueExW( - connection_key, - name_string, - NULL, - &name_type, - (LPBYTE) name_data, - &len); + status =3D RegQueryValueExW(connection_key, name_string, NULL,= &name_type, + (LPBYTE)name_data, &len); if (status !=3D ERROR_SUCCESS || name_type !=3D REG_SZ) { - dmsg(D_REGISTRY, "Error opening registry key: %s\\%s\\%ls", - NETWORK_CONNECTIONS_KEY, connection_string, name_stri= ng); + dmsg(D_REGISTRY, "Error opening registry key: %s\\%s\\%ls"= , NETWORK_CONNECTIONS_KEY, + connection_string, name_string); } else { @@ -4144,15 +3943,14 @@ } if ((local & (~mask)) !=3D (remote & (~mask))) { - err =3D "must exist within the same 255.255.255.252 subnet. This = is a limitation of --dev tun when used with the TAP-WIN32 driver"; + err =3D + "must exist within the same 255.255.255.252 subnet. This is a= limitation of --dev tun when used with the TAP-WIN32 driver"; goto error; } - if ((local & mask) =3D=3D 0 - || (local & mask) =3D=3D 3 - || (remote & mask) =3D=3D 0 - || (remote & mask) =3D=3D 3) + if ((local & mask) =3D=3D 0 || (local & mask) =3D=3D 3 || (remote & ma= sk) =3D=3D 0 || (remote & mask) =3D=3D 3) { - err =3D "cannot use the first or last address within a given 255.2= 55.255.252 subnet. This is a limitation of --dev tun when used with the TA= P-WIN32 driver"; + err =3D + "cannot use the first or last address within a given 255.255.2= 55.252 subnet. This is a limitation of --dev tun when used with the TAP-WI= N32 driver"; goto error; } @@ -4160,10 +3958,10 @@ return; error: - msg(M_FATAL, "There is a problem in your selection of --ifconfig endpo= ints [local=3D%s, remote=3D%s]. The local and remote VPN endpoints %s. Tr= y '" PACKAGE " --show-valid-subnets' option for more info.", - print_in_addr_t(local, 0, &gc), - print_in_addr_t(remote, 0, &gc), - err); + msg(M_FATAL, + "There is a problem in your selection of --ifconfig endpoints [loc= al=3D%s, remote=3D%s]. The local and remote VPN endpoints %s. Try '" PACK= AGE + " --show-valid-subnets' option for more info.", + print_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc), e= rr); gc_free(&gc); } @@ -4187,7 +3985,7 @@ for (i =3D 0; i < 256; i +=3D 4) { - printf("[%3d,%3d] ", i+1, i+2); + printf("[%3d,%3d] ", i + 1, i + 2); if (++col > 4) { col =3D 0; @@ -4230,7 +4028,8 @@ { if (!strcmp(tr->guid, pr->guid)) { - msg(msglev, "'%s' %s %s", pr->name, tr->guid, print_tun_ba= ckend_driver(tr->windows_driver)); + msg(msglev, "'%s' %s %s", pr->name, tr->guid, + print_tun_backend_driver(tr->windows_driver)); ++links; } } @@ -4268,12 +4067,14 @@ if (warn_panel_dup) { - msg(warnlev, "WARNING: Some TAP-Windows adapters have duplicate li= nks from the Network Connections control panel"); + msg(warnlev, + "WARNING: Some TAP-Windows adapters have duplicate links from = the Network Connections control panel"); } if (warn_panel_null) { - msg(warnlev, "WARNING: Some TAP-Windows adapters have no link from= the Network Connections control panel"); + msg(warnlev, + "WARNING: Some TAP-Windows adapters have no link from the Netw= ork Connections control panel"); } gc_free(&gc); @@ -4315,7 +4116,8 @@ } static const struct tap_reg * -get_adapter_by_name(const char *name, const struct tap_reg *tap_reg, const= struct panel_reg *panel_reg) +get_adapter_by_name(const char *name, const struct tap_reg *tap_reg, + const struct panel_reg *panel_reg) { const struct panel_reg *pr; @@ -4336,8 +4138,8 @@ if (!tap_reg) { msg(M_FATAL, "There are no TAP-Windows or ovpn-dco adapters " - "on this system. You should be able to create an adapter " - "by using tapctl.exe utility."); + "on this system. You should be able to create an ada= pter " + "by using tapctl.exe utility."); } } @@ -4346,13 +4148,10 @@ * registry for the TAP device # =3D device_number. */ static const char * -get_unspecified_device_guid(const int device_number, - uint8_t *actual_name, - int actual_name_size, +get_unspecified_device_guid(const int device_number, uint8_t *actual_name,= int actual_name_size, const struct tap_reg *tap_reg_src, const struct panel_reg *panel_reg_src, - enum tun_driver_type *windows_driver, - struct gc_arena *gc) + enum tun_driver_type *windows_driver, struct g= c_arena *gc) { const struct tap_reg *tap_reg =3D tap_reg_src; struct buffer actual =3D clear_buf(); @@ -4412,13 +4211,9 @@ * returning the GUID and optional actual_name and device type */ static const char * -get_device_guid(const char *name, - uint8_t *actual_name, - int actual_name_size, - enum tun_driver_type *windows_driver, - const struct tap_reg *tap_reg, - const struct panel_reg *panel_reg, - struct gc_arena *gc) +get_device_guid(const char *name, uint8_t *actual_name, int actual_name_si= ze, + enum tun_driver_type *windows_driver, const struct tap_reg= *tap_reg, + const struct panel_reg *panel_reg, struct gc_arena *gc) { struct buffer ret =3D alloc_buf_gc(256, gc); struct buffer actual =3D clear_buf(); @@ -4488,17 +4283,15 @@ if ((status =3D GetAdaptersInfo(NULL, &size)) !=3D ERROR_BUFFER_OVERFL= OW) { - msg(M_INFO, "GetAdaptersInfo #1 failed (status=3D%u) : %s", - (unsigned int)status, + msg(M_INFO, "GetAdaptersInfo #1 failed (status=3D%u) : %s", (unsig= ned int)status, strerror_win32(status, gc)); } else { - pi =3D (PIP_ADAPTER_INFO) gc_malloc(size, false, gc); + pi =3D (PIP_ADAPTER_INFO)gc_malloc(size, false, gc); if ((status =3D GetAdaptersInfo(pi, &size)) !=3D NO_ERROR) { - msg(M_INFO, "GetAdaptersInfo #2 failed (status=3D%u) : %s", - (unsigned int)status, + msg(M_INFO, "GetAdaptersInfo #2 failed (status=3D%u) : %s", (u= nsigned int)status, strerror_win32(status, gc)); pi =3D NULL; } @@ -4517,21 +4310,19 @@ { if ((status =3D GetPerAdapterInfo(index, NULL, &size)) !=3D ERROR_= BUFFER_OVERFLOW) { - msg(M_INFO, "GetPerAdapterInfo #1 failed (status=3D%u) : %s", - (unsigned int)status, + msg(M_INFO, "GetPerAdapterInfo #1 failed (status=3D%u) : %s", = (unsigned int)status, strerror_win32(status, gc)); } else { - pi =3D (PIP_PER_ADAPTER_INFO) gc_malloc(size, false, gc); + pi =3D (PIP_PER_ADAPTER_INFO)gc_malloc(size, false, gc); if ((status =3D GetPerAdapterInfo((ULONG)index, pi, &size)) = =3D=3D ERROR_SUCCESS) { return pi; } else { - msg(M_INFO, "GetPerAdapterInfo #2 failed (status=3D%u) : %= s", - (unsigned int)status, + msg(M_INFO, "GetPerAdapterInfo #2 failed (status=3D%u) : %= s", (unsigned int)status, strerror_win32(status, gc)); } } @@ -4548,21 +4339,19 @@ if ((status =3D GetInterfaceInfo(NULL, &size)) !=3D ERROR_INSUFFICIENT= _BUFFER) { - msg(M_INFO, "GetInterfaceInfo #1 failed (status=3D%u) : %s", - (unsigned int)status, + msg(M_INFO, "GetInterfaceInfo #1 failed (status=3D%u) : %s", (unsi= gned int)status, strerror_win32(status, gc)); } else { - ii =3D (PIP_INTERFACE_INFO) gc_malloc(size, false, gc); + ii =3D (PIP_INTERFACE_INFO)gc_malloc(size, false, gc); if ((status =3D GetInterfaceInfo(ii, &size)) =3D=3D NO_ERROR) { return ii; } else { - msg(M_INFO, "GetInterfaceInfo #2 failed (status=3D%u) : %s", - (unsigned int)status, + msg(M_INFO, "GetInterfaceInfo #2 failed (status=3D%u) : %s", (= unsigned int)status, strerror_win32(status, gc)); } } @@ -4750,7 +4539,6 @@ else { ret =3D true; /* this can occur when TAP adapter is bridged */ - } return ret; } @@ -4774,7 +4562,8 @@ in_addr_t adapter_ip, adapter_netmask; if (get_adapter_ip_netmask(ai, i, &adapter_ip, &adapter_netmas= k)) { - if (adapter_ip && adapter_netmask && (ip & adapter_netmask= ) =3D=3D (adapter_ip & adapter_netmask)) + if (adapter_ip && adapter_netmask + && (ip & adapter_netmask) =3D=3D (adapter_ip & adapter= _netmask)) { if (highest_netmask && adapter_netmask > *highest_netm= ask) { @@ -4789,10 +4578,7 @@ } DWORD -adapter_index_of_ip(const IP_ADAPTER_INFO *list, - const in_addr_t ip, - int *count, - in_addr_t *netmask) +adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *= count, in_addr_t *netmask) { struct gc_arena gc =3D gc_new(); DWORD ret =3D TUN_ADAPTER_INDEX_INVALID; @@ -4843,11 +4629,8 @@ } dmsg(D_ROUTE_DEBUG, "DEBUG: IP Locate: ip=3D%s nm=3D%s index=3D%d coun= t=3D%d metric=3D%d", - print_in_addr_t(ip, 0, &gc), - print_in_addr_t(highest_netmask, 0, &gc), - (int)ret, - count ? *count : -1, - lowest_metric); + print_in_addr_t(ip, 0, &gc), print_in_addr_t(highest_netmask, 0, = &gc), (int)ret, + count ? *count : -1, lowest_metric); if (ret =3D=3D TUN_ADAPTER_INDEX_INVALID && count) { @@ -4868,9 +4651,9 @@ * is DHCP disabled. */ -#define DHCP_STATUS_UNDEF 0 -#define DHCP_STATUS_ENABLED 1 -#define DHCP_STATUS_DISABLED 2 +#define DHCP_STATUS_UNDEF 0 +#define DHCP_STATUS_ENABLED 1 +#define DHCP_STATUS_DISABLED 2 static int dhcp_status(DWORD index) @@ -4915,22 +4698,19 @@ DWORD status; const DWORD context =3D ip->Context; - if ((status =3D DeleteIPAddress((ULONG) context)) =3D=3D NO_ER= ROR) + if ((status =3D DeleteIPAddress((ULONG)context)) =3D=3D NO_ERR= OR) { msg(M_INFO, "Successfully deleted previously set dynamic I= P/netmask: %s/%s", - ip->IpAddress.String, - ip->IpMask.String); + ip->IpAddress.String, ip->IpMask.String); } else { const char *empty =3D "0.0.0.0"; - if (strcmp(ip->IpAddress.String, empty) - || strcmp(ip->IpMask.String, empty)) + if (strcmp(ip->IpAddress.String, empty) || strcmp(ip->IpMa= sk.String, empty)) { - msg(M_INFO, "NOTE: could not delete previously set dyn= amic IP/netmask: %s/%s (status=3D%u)", - ip->IpAddress.String, - ip->IpMask.String, - (unsigned int)status); + msg(M_INFO, + "NOTE: could not delete previously set dynamic IP/= netmask: %s/%s (status=3D%u)", + ip->IpAddress.String, ip->IpMask.String, (unsigned= int)status); } } ip =3D ip->Next; @@ -5100,7 +4880,7 @@ } else { - msg(M_INFO|M_NOPREFIX, "TAP-Windows device: %s [Non-admin access a= llowed]", device_path); + msg(M_INFO | M_NOPREFIX, "TAP-Windows device: %s [Non-admin access= allowed]", device_path); } } @@ -5120,7 +4900,8 @@ if (dev_node) { /* Get the device GUID for the device specified with --dev-node. */ - device_guid =3D get_device_guid(dev_node, actual_buffer, sizeof(ac= tual_buffer), NULL, tap_reg, panel_reg, &gc); + device_guid =3D get_device_guid(dev_node, actual_buffer, sizeof(ac= tual_buffer), NULL, tap_reg, + panel_reg, &gc); if (!device_guid) { @@ -5128,20 +4909,11 @@ } /* Open Windows TAP-Windows adapter */ - snprintf(device_path, sizeof(device_path), "%s%s%s", - USERMODEDEVICEDIR, - device_guid, + snprintf(device_path, sizeof(device_path), "%s%s%s", USERMODEDEVIC= EDIR, device_guid, TAP_WIN_SUFFIX); - hand =3D CreateFile( - device_path, - MAXIMUM_ALLOWED, - 0, /* was: FILE_SHARE_READ */ - 0, - OPEN_EXISTING, - FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, - 0 - ); + hand =3D CreateFile(device_path, MAXIMUM_ALLOWED, 0, /* was: FILE_= SHARE_READ */ + 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_F= LAG_OVERLAPPED, 0); if (hand =3D=3D INVALID_HANDLE_VALUE) { @@ -5158,13 +4930,8 @@ /* Try opening all TAP devices */ while (true) { - device_guid =3D get_unspecified_device_guid(device_number, - actual_buffer, - sizeof(actual_buffer= ), - tap_reg, - panel_reg, - NULL, - &gc); + device_guid =3D get_unspecified_device_guid( + device_number, actual_buffer, sizeof(actual_buffer), tap_r= eg, panel_reg, NULL, &gc); if (!device_guid) { @@ -5172,20 +4939,11 @@ } /* Open Windows TAP-Windows adapter */ - snprintf(device_path, sizeof(device_path), "%s%s%s", - USERMODEDEVICEDIR, - device_guid, + snprintf(device_path, sizeof(device_path), "%s%s%s", USERMODED= EVICEDIR, device_guid, TAP_WIN_SUFFIX); - hand =3D CreateFile( - device_path, - MAXIMUM_ALLOWED, - 0, /* was: FILE_SHARE_READ */ - 0, - OPEN_EXISTING, - FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, - 0 - ); + hand =3D CreateFile(device_path, MAXIMUM_ALLOWED, 0, /* was: F= ILE_SHARE_READ */ + 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FI= LE_FLAG_OVERLAPPED, 0); if (hand =3D=3D INVALID_HANDLE_VALUE) { @@ -5223,9 +4981,9 @@ } else { - msg(M_WARN, "NOTE: Release of DHCP-assigned IP address lease o= n TAP-Windows adapter failed: %s (code=3D%u)", - strerror_win32(status, &gc), - (unsigned int)status); + msg(M_WARN, + "NOTE: Release of DHCP-assigned IP address lease on TAP-Wi= ndows adapter failed: %s (code=3D%u)", + strerror_win32(status, &gc), (unsigned int)status); } } @@ -5236,7 +4994,8 @@ static bool dhcp_release(const struct tuntap *tt) { - if (tt && tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ && tt->= adapter_index !=3D TUN_ADAPTER_INDEX_INVALID) + if (tt && tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ + && tt->adapter_index !=3D TUN_ADAPTER_INDEX_INVALID) { return dhcp_release_by_adapter_index(tt->adapter_index); } @@ -5263,9 +5022,9 @@ } else { - msg(M_WARN, "WARNING: Failed to renew DHCP IP address lease on= TAP-Windows adapter: %s (code=3D%u)", - strerror_win32(status, &gc), - (unsigned int)status); + msg(M_WARN, + "WARNING: Failed to renew DHCP IP address lease on TAP-Win= dows adapter: %s (code=3D%u)", + strerror_win32(status, &gc), (unsigned int)status); } } gc_free(&gc); @@ -5275,7 +5034,8 @@ static bool dhcp_renew(const struct tuntap *tt) { - if (tt && tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ && tt->= adapter_index !=3D TUN_ADAPTER_INDEX_INVALID) + if (tt && tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ + && tt->adapter_index !=3D TUN_ADAPTER_INDEX_INVALID) { return dhcp_renew_by_adapter_index(tt->adapter_index); } @@ -5321,15 +5081,11 @@ msg(D_TUNTAP_INFO, "Start ipconfig commands for register-dns..."); netcmd_semaphore_lock(); - argv_printf(&argv, "%s%s /flushdns", - get_win_sys_path(), - WIN_IPCONFIG_PATH_SUFFIX); + argv_printf(&argv, "%s%s /flushdns", get_win_sys_path(), WIN_IPCONFIG_= PATH_SUFFIX); argv_msg(D_TUNTAP_INFO, &argv); openvpn_execve_check(&argv, es, 0, err); - argv_printf(&argv, "%s%s /registerdns", - get_win_sys_path(), - WIN_IPCONFIG_PATH_SUFFIX); + argv_printf(&argv, "%s%s /registerdns", get_win_sys_path(), WIN_IPCONF= IG_PATH_SUFFIX); argv_msg(D_TUNTAP_INFO, &argv); openvpn_execve_check(&argv, es, 0, err); argv_free(&argv); @@ -5430,34 +5186,28 @@ * are cleared first. */ static void -netsh_set_dns6_servers(const struct in6_addr *addr_list, - const int addr_len, - DWORD adapter_index) +netsh_set_dns6_servers(const struct in6_addr *addr_list, const int addr_le= n, DWORD adapter_index) { struct gc_arena gc =3D gc_new(); struct argv argv =3D argv_new(); /* delete existing DNS settings from TAP interface */ - argv_printf(&argv, "%s%s interface ipv6 delete dns %lu all", - get_win_sys_path(), - NETSH_PATH_SUFFIX, - adapter_index); + argv_printf(&argv, "%s%s interface ipv6 delete dns %lu all", get_win_s= ys_path(), + NETSH_PATH_SUFFIX, adapter_index); netsh_command(&argv, 2, M_FATAL); for (int i =3D 0; i < addr_len; ++i) { - const char *fmt =3D (i =3D=3D 0) ? - "%s%s interface ipv6 set dns %lu static %s" - : "%s%s interface ipv6 add dns %lu %s"; - argv_printf(&argv, fmt, get_win_sys_path(), - NETSH_PATH_SUFFIX, adapter_index, + const char *fmt =3D (i =3D=3D 0) ? "%s%s interface ipv6 set dns %l= u static %s" + : "%s%s interface ipv6 add dns %lu %s"; + argv_printf(&argv, fmt, get_win_sys_path(), NETSH_PATH_SUFFIX, ada= pter_index, print_in6_addr(addr_list[i], 0, &gc)); /* disable slow address validation */ argv_printf_cat(&argv, "%s", "validate=3Dno"); /* Treat errors while adding as non-fatal as we do not check for d= uplicates */ - netsh_command(&argv, 1, (i=3D=3D0) ? M_FATAL : M_NONFATAL); + netsh_command(&argv, 1, (i =3D=3D 0) ? M_FATAL : M_NONFATAL); } argv_free(&argv); @@ -5465,12 +5215,8 @@ } static void -netsh_ifconfig_options(const char *type, - const in_addr_t *addr_list, - const int addr_len, - const IP_ADDR_STRING *current, - DWORD adapter_index, - const bool test_first) +netsh_ifconfig_options(const char *type, const in_addr_t *addr_list, const= int addr_len, + const IP_ADDR_STRING *current, DWORD adapter_index,= const bool test_first) { struct gc_arena gc =3D gc_new(); struct argv argv =3D argv_new(); @@ -5493,11 +5239,8 @@ /* delete existing DNS/WINS settings from TAP interface */ if (delete_first) { - argv_printf(&argv, "%s%s interface ip delete %s %lu all", - get_win_sys_path(), - NETSH_PATH_SUFFIX, - type, - adapter_index); + argv_printf(&argv, "%s%s interface ip delete %s %lu all", get_win_= sys_path(), + NETSH_PATH_SUFFIX, type, adapter_index); netsh_command(&argv, 2, M_FATAL); } @@ -5509,15 +5252,10 @@ { if (delete_first || !test_first || !ip_addr_member_of(addr_lis= t[i], current)) { - const char *fmt =3D count ? - "%s%s interface ip add %s %lu %s" - : "%s%s interface ip set %s %lu static %= s"; + const char *fmt =3D count ? "%s%s interface ip add %s %lu = %s" + : "%s%s interface ip set %s %lu st= atic %s"; - argv_printf(&argv, fmt, - get_win_sys_path(), - NETSH_PATH_SUFFIX, - type, - adapter_index, + argv_printf(&argv, fmt, get_win_sys_path(), NETSH_PATH_SUF= FIX, type, adapter_index, print_in_addr_t(addr_list[i], 0, &gc)); /* disable slow address validation for DNS */ @@ -5532,9 +5270,7 @@ } else { - msg(M_INFO, "NETSH: %lu %s %s [already set]", - adapter_index, - type, + msg(M_INFO, "NETSH: %lu %s %s [already set]", adapter_inde= x, type, print_in_addr_t(addr_list[i], 0, &gc)); } } @@ -5563,11 +5299,8 @@ } static void -netsh_ifconfig(const struct tuntap_options *to, - DWORD adapter_index, - const in_addr_t ip, - const in_addr_t netmask, - const unsigned int flags) +netsh_ifconfig(const struct tuntap_options *to, DWORD adapter_index, const= in_addr_t ip, + const in_addr_t netmask, const unsigned int flags) { struct gc_arena gc =3D gc_new(); struct argv argv =3D argv_new(); @@ -5585,19 +5318,14 @@ { if (test_adapter_ip_netmask(ai, ip, netmask)) { - msg(M_INFO, "NETSH: %lu %s/%s [already set]", - adapter_index, - print_in_addr_t(ip, 0, &gc), - print_in_addr_t(netmask, 0, &gc)); + msg(M_INFO, "NETSH: %lu %s/%s [already set]", adapter_index, + print_in_addr_t(ip, 0, &gc), print_in_addr_t(netmask, 0, &= gc)); } else { /* example: netsh interface ip set address 42 static 10.3.0.1 = 255.255.255.0 */ - argv_printf(&argv, "%s%s interface ip set address %lu static %= s %s", - get_win_sys_path(), - NETSH_PATH_SUFFIX, - adapter_index, - print_in_addr_t(ip, 0, &gc), + argv_printf(&argv, "%s%s interface ip set address %lu static %= s %s", get_win_sys_path(), + NETSH_PATH_SUFFIX, adapter_index, print_in_addr_t(= ip, 0, &gc), print_in_addr_t(netmask, 0, &gc)); netsh_command(&argv, 4, M_FATAL); @@ -5611,22 +5339,14 @@ CLEAR(wins[0]); CLEAR(wins[1]); - netsh_ifconfig_options("dns", - to->dns, - to->dns_len, - pai ? &pai->DnsServerList : NULL, - adapter_index, - BOOL_CAST(flags & NI_TEST_FIRST)); + netsh_ifconfig_options("dns", to->dns, to->dns_len, pai ? &pai->Dn= sServerList : NULL, + adapter_index, BOOL_CAST(flags & NI_TEST_FI= RST)); if (ai && ai->HaveWins) { init_ip_addr_string2(wins, &ai->PrimaryWinsServer, &ai->Second= aryWinsServer); } - netsh_ifconfig_options("wins", - to->wins, - to->wins_len, - ai ? wins : NULL, - adapter_index, + netsh_ifconfig_options("wins", to->wins, to->wins_len, ai ? wins := NULL, adapter_index, BOOL_CAST(flags & NI_TEST_FIRST)); } @@ -5640,11 +5360,8 @@ struct argv argv =3D argv_new(); /* example: netsh interface ip set address 42 dhcp */ - argv_printf(&argv, - "%s%s interface ip set address %lu dhcp", - get_win_sys_path(), - NETSH_PATH_SUFFIX, - adapter_index); + argv_printf(&argv, "%s%s interface ip set address %lu dhcp", get_win_s= ys_path(), + NETSH_PATH_SUFFIX, adapter_index); netsh_command(&argv, 4, M_FATAL); @@ -5660,14 +5377,8 @@ struct gc_arena gc =3D gc_new(); HANDLE pipe =3D tt->options.msg_channel; - enable_dhcp_message_t dhcp =3D { - .header =3D { - msg_enable_dhcp, - sizeof(enable_dhcp_message_t), - 0 - }, - .iface =3D { .index =3D tt->adapter_index, .name =3D "" } - }; + enable_dhcp_message_t dhcp =3D { .header =3D { msg_enable_dhcp, sizeof= (enable_dhcp_message_t), 0 }, + .iface =3D { .index =3D tt->adapter_ind= ex, .name =3D "" } }; if (!send_msg_iservice(pipe, &dhcp, sizeof(dhcp), &ack, "Enable_dhcp")) { @@ -5691,8 +5402,7 @@ } static void -windows_set_mtu(const int iface_index, const short family, - const int mtu) +windows_set_mtu(const int iface_index, const short family, const int mtu) { DWORD err =3D 0; struct gc_arena gc =3D gc_new(); @@ -5703,7 +5413,8 @@ ipiface.InterfaceIndex =3D iface_index; if (family =3D=3D AF_INET6 && mtu < 1280) { - msg(M_INFO, "NOTE: IPv6 interface MTU < 1280 conflicts with IETF s= tandards and might not work"); + msg(M_INFO, + "NOTE: IPv6 interface MTU < 1280 conflicts with IETF standards= and might not work"); } err =3D GetIpInterfaceEntry(&ipiface); @@ -5719,12 +5430,13 @@ if (err !=3D NO_ERROR) { - msg(M_WARN, "TUN: Setting %s mtu failed: %s [status=3D%lu if_index= =3D%d]", - family_name, strerror_win32(err, &gc), err, iface_index); + msg(M_WARN, "TUN: Setting %s mtu failed: %s [status=3D%lu if_index= =3D%d]", family_name, + strerror_win32(err, &gc), err, iface_index); } else { - msg(M_INFO, "%s MTU set to %d on interface %d using SetIpInterface= Entry()", family_name, mtu, iface_index); + msg(M_INFO, "%s MTU set to %d on interface %d using SetIpInterface= Entry()", family_name, + mtu, iface_index); } } @@ -5744,13 +5456,16 @@ if (dev_node) { - guid =3D get_device_guid(dev_node, BPTR(&actual), BCAP(&actual), N= ULL, tap_reg, panel_reg, gc); + guid =3D + get_device_guid(dev_node, BPTR(&actual), BCAP(&actual), NULL, = tap_reg, panel_reg, gc); } else { - guid =3D get_unspecified_device_guid(0, BPTR(&actual), BCAP(&actua= l), tap_reg, panel_reg, NULL, gc); + guid =3D get_unspecified_device_guid(0, BPTR(&actual), BCAP(&actua= l), tap_reg, panel_reg, + NULL, gc); - if (get_unspecified_device_guid(1, NULL, 0, tap_reg, panel_reg, NU= LL, gc)) /* ambiguous if more than one TAP-Windows adapter */ + if (get_unspecified_device_guid(1, NULL, 0, tap_reg, panel_reg, NU= LL, + gc)) /* ambiguous if more than one= TAP-Windows adapter */ { guid =3D NULL; } @@ -5758,7 +5473,7 @@ if (!guid) { - return "NULL"; /* not found */ + return "NULL"; /* not found */ } else if (strcmp(BSTR(&actual), "NULL")) { @@ -5766,7 +5481,7 @@ } else { - return guid; /* no control panel name, return GUID instead */ + return guid; /* no control panel name, return GUID instead */ } } @@ -5789,13 +5504,10 @@ if (tt->standby_iter =3D=3D IPW32_SET_ADAPTIVE_TRY_NETSH) { msg(M_INFO, "NOTE: now trying netsh (this may take some time)"= ); - netsh_ifconfig(&tt->options, - tt->adapter_index, - tt->local, - tt->adapter_netmask, - NI_TEST_FIRST|NI_IP_NETMASK|NI_OPTIONS); + netsh_ifconfig(&tt->options, tt->adapter_index, tt->local, tt-= >adapter_netmask, + NI_TEST_FIRST | NI_IP_NETMASK | NI_OPTIONS); } - else if (tt->standby_iter >=3D IPW32_SET_ADAPTIVE_TRY_NETSH*2) + else if (tt->standby_iter >=3D IPW32_SET_ADAPTIVE_TRY_NETSH * 2) { ret =3D false; } @@ -5823,7 +5535,8 @@ } static void -write_dhcp_u32_array(struct buffer *buf, const int type, const uint32_t *d= ata, const unsigned int len, bool *error) +write_dhcp_u32_array(struct buffer *buf, const int type, const uint32_t *d= ata, + const unsigned int len, bool *error) { if (len > 0) { @@ -5891,7 +5604,7 @@ for (i =3D 0; i < array_len; i++) { - const char *ptr =3D str_array[i]; + const char *ptr =3D str_array[i]; if (strlen(ptr) + len + 1 > sizeof(tmp_buf)) { @@ -5910,7 +5623,7 @@ { if (*ptr =3D=3D '.' || *ptr =3D=3D '\0') { - tmp_buf[label_length_pos] =3D (len-label_length_pos)-1; + tmp_buf[label_length_pos] =3D (len - label_length_pos) - 1; label_length_pos =3D len; if (*ptr =3D=3D '\0') { @@ -5967,9 +5680,7 @@ if (o->domain_search_list_len > 0) { - write_dhcp_search_str(buf, 119, o->domain_search_list, - o->domain_search_list_len, - &error); + write_dhcp_search_str(buf, 119, o->domain_search_list, o->domain_s= earch_list_len, &error); } /* the MS DHCP server option 'Disable Netbios-over-TCP/IP @@ -5982,10 +5693,10 @@ msg(M_WARN, "build_dhcp_options_string: buffer overflow buildi= ng DHCP options"); return false; } - buf_write_u8(buf, 43); - buf_write_u8(buf, 6);/* total length field */ - buf_write_u8(buf, 0x001); - buf_write_u8(buf, 4);/* length of the vendor specified field */ + buf_write_u8(buf, 43); + buf_write_u8(buf, 6); /* total length field */ + buf_write_u8(buf, 0x001); + buf_write_u8(buf, 4); /* length of the vendor specified field */ buf_write_u32(buf, 0x002); } return !error; @@ -6082,7 +5793,9 @@ if (dsa =3D=3D local) { - msg(M_FATAL, "ERROR: There is a clash between the --ifconfig local= address and the internal DHCP server address -- both are set to %s -- plea= se use the --ip-win32 dynamic option to choose a different free address fro= m the --ifconfig subnet for the internal DHCP server", print_in_addr_t(dsa,= 0, &gc)); + msg(M_FATAL, + "ERROR: There is a clash between the --ifconfig local address = and the internal DHCP server address -- both are set to %s -- please use th= e --ip-win32 dynamic option to choose a different free address from the --i= fconfig subnet for the internal DHCP server", + print_in_addr_t(dsa, 0, &gc)); } if ((local & netmask) !=3D (dsa & netmask)) @@ -6100,38 +5813,38 @@ ULONG info[3]; DWORD len; CLEAR(info); - if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_VERSION, - &info, sizeof(info), - &info, sizeof(info), &len, NULL)) + if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_VERSION, &info, sizeof= (info), &info, + sizeof(info), &len, NULL)) { - msg(D_TUNTAP_INFO, "TAP-Windows Driver Version %d.%d %s", - (int)info[0], - (int)info[1], + msg(D_TUNTAP_INFO, "TAP-Windows Driver Version %d.%d %s", (int)inf= o[0], (int)info[1], (info[2] ? "(DEBUG)" : "")); - } if (!(info[0] =3D=3D TAP_WIN_MIN_MAJOR && info[1] >=3D TAP_WIN_MIN_MIN= OR)) { - msg(M_FATAL, "ERROR: This version of " PACKAGE_NAME " requires a = TAP-Windows driver that is at least version %d.%d -- If you recently upgrad= ed your " PACKAGE_NAME " distribution, a reboot is probably required at thi= s point to get Windows to see the new driver.", - TAP_WIN_MIN_MAJOR, - TAP_WIN_MIN_MINOR); + msg(M_FATAL, + "ERROR: This version of " PACKAGE_NAME + " requires a TAP-Windows driver that is at least version %d.%d= -- If you recently upgraded your " PACKAGE_NAME + " distribution, a reboot is probably required at this point to= get Windows to see the new driver.", + TAP_WIN_MIN_MAJOR, TAP_WIN_MIN_MINOR); } /* usage of numeric constants is ugly, but this is really tied to * *this* version of the driver */ - if (tt->type =3D=3D DEV_TYPE_TUN - && info[0] =3D=3D 9 && info[1] < 8) + if (tt->type =3D=3D DEV_TYPE_TUN && info[0] =3D=3D 9 && info[1] < 8) { - msg(M_INFO, "WARNING: Tap-Win32 driver version %d.%d does not sup= port IPv6 in TUN mode. IPv6 will not work. Upgrade your Tap-Win32 driver.",= (int)info[0], (int)info[1]); + msg(M_INFO, + "WARNING: Tap-Win32 driver version %d.%d does not support IPv= 6 in TUN mode. IPv6 will not work. Upgrade your Tap-Win32 driver.", + (int)info[0], (int)info[1]); } /* tap driver 9.8 (2.2.0 and 2.2.1 release) is buggy */ - if (tt->type =3D=3D DEV_TYPE_TUN - && info[0] =3D=3D 9 && info[1] =3D=3D 8) + if (tt->type =3D=3D DEV_TYPE_TUN && info[0] =3D=3D 9 && info[1] =3D=3D= 8) { - msg(M_FATAL, "ERROR: Tap-Win32 driver version %d.%d is buggy rega= rding small IPv4 packets in TUN mode. Upgrade your Tap-Win32 driver.", (int= )info[0], (int)info[1]); + msg(M_FATAL, + "ERROR: Tap-Win32 driver version %d.%d is buggy regarding sma= ll IPv4 packets in TUN mode. Upgrade your Tap-Win32 driver.", + (int)info[0], (int)info[1]); } } @@ -6140,43 +5853,33 @@ { ULONG mtu =3D 0; DWORD len; - if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_MTU, - &mtu, sizeof(mtu), - &mtu, sizeof(mtu), &len, NULL)) + if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_MTU, &mtu, sizeof(mtu)= , &mtu, sizeof(mtu), &len, + NULL)) { msg(D_MTU_INFO, "TAP-Windows MTU=3D%d", (int)mtu); } } static void -tuntap_set_ip_addr(struct tuntap *tt, - const char *device_guid, - bool dhcp_masq_post) +tuntap_set_ip_addr(struct tuntap *tt, const char *device_guid, bool dhcp_m= asq_post) { struct gc_arena gc =3D gc_new(); const DWORD index =3D tt->adapter_index; /* flush arp cache */ - if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6 - && index !=3D TUN_ADAPTER_INDEX_INVALID) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6 && index != =3D TUN_ADAPTER_INDEX_INVALID) { DWORD status =3D -1; if (tt->options.msg_channel) { ack_message_t ack; - flush_neighbors_message_t msg =3D { - .header =3D { - msg_flush_neighbors, - sizeof(flush_neighbors_message_t), - 0 - }, - .family =3D AF_INET, - .iface =3D {.index =3D index, .name =3D "" } - }; + flush_neighbors_message_t msg =3D { .header =3D { msg_flush_ne= ighbors, + sizeof(flush_nei= ghbors_message_t), 0 }, + .family =3D AF_INET, + .iface =3D { .index =3D inde= x, .name =3D "" } }; - if (send_msg_iservice(tt->options.msg_channel, &msg, sizeof(ms= g), - &ack, "TUN")) + if (send_msg_iservice(tt->options.msg_channel, &msg, sizeof(ms= g), &ack, "TUN")) { status =3D ack.error_number; } @@ -6188,17 +5891,13 @@ if (status =3D=3D NO_ERROR) { - msg(M_INFO, "Successful ARP Flush on interface [%lu] %s", - index, - device_guid); + msg(M_INFO, "Successful ARP Flush on interface [%lu] %s", inde= x, device_guid); } else if (status !=3D -1) { - msg(D_TUNTAP_INFO, "NOTE: FlushIpNetTable failed on interface = [%lu] %s (status=3D%lu) : %s", - index, - device_guid, - status, - strerror_win32(status, &gc)); + msg(D_TUNTAP_INFO, + "NOTE: FlushIpNetTable failed on interface [%lu] %s (statu= s=3D%lu) : %s", index, + device_guid, status, strerror_win32(status, &gc)); } /* @@ -6211,7 +5910,8 @@ /* check dhcp enable status */ if (dhcp_status(index) =3D=3D DHCP_STATUS_DISABLED) { - msg(M_WARN, "WARNING: You have selected '--ip-win32 dynami= c', which will not work unless the TAP-Windows TCP/IP properties are set to= 'Obtain an IP address automatically'"); + msg(M_WARN, + "WARNING: You have selected '--ip-win32 dynamic', whic= h will not work unless the TAP-Windows TCP/IP properties are set to 'Obtain= an IP address automatically'"); } /* force an explicit DHCP lease renewal on TAP adapter? */ @@ -6233,20 +5933,21 @@ if (tt->did_ifconfig_setup && tt->options.ip_win32_type =3D=3D IPW32_S= ET_IPAPI) { DWORD status; - const char *error_suffix =3D "I am having trouble using the Window= s 'IP helper API' to automatically set the IP address -- consider using oth= er --ip-win32 methods (not 'ipapi')"; + const char *error_suffix =3D + "I am having trouble using the Windows 'IP helper API' to auto= matically set the IP address -- consider using other --ip-win32 methods (no= t 'ipapi')"; /* couldn't get adapter index */ if (index =3D=3D TUN_ADAPTER_INDEX_INVALID) { - msg(M_FATAL, "ERROR: unable to get adapter index for interface= %s -- %s", - device_guid, + msg(M_FATAL, "ERROR: unable to get adapter index for interface= %s -- %s", device_guid, error_suffix); } /* check dhcp enable status */ if (dhcp_status(index) =3D=3D DHCP_STATUS_DISABLED) { - msg(M_WARN, "NOTE: You have selected (explicitly or by default= ) '--ip-win32 ipapi', which has a better chance of working correctly if the= TAP-Windows TCP/IP properties are set to 'Obtain an IP address automatical= ly'"); + msg(M_WARN, + "NOTE: You have selected (explicitly or by default) '--ip-= win32 ipapi', which has a better chance of working correctly if the TAP-Win= dows TCP/IP properties are set to 'Obtain an IP address automatically'"); } /* delete previously added IP addresses which were not @@ -6254,28 +5955,21 @@ delete_temp_addresses(index); /* add a new IP address */ - if ((status =3D AddIPAddress(htonl(tt->local), - htonl(tt->adapter_netmask), - index, - &tt->ipapi_context, - &tt->ipapi_instance)) =3D=3D NO_ERROR) + if ((status =3D AddIPAddress(htonl(tt->local), htonl(tt->adapter_n= etmask), index, + &tt->ipapi_context, &tt->ipapi_instance= )) + =3D=3D NO_ERROR) { - msg(M_INFO, "Succeeded in adding a temporary IP/netmask of %s/= %s to interface %s using the Win32 IP Helper API", - print_in_addr_t(tt->local, 0, &gc), - print_in_addr_t(tt->adapter_netmask, 0, &gc), - device_guid - ); + msg(M_INFO, + "Succeeded in adding a temporary IP/netmask of %s/%s to in= terface %s using the Win32 IP Helper API", + print_in_addr_t(tt->local, 0, &gc), print_in_addr_t(tt->ad= apter_netmask, 0, &gc), + device_guid); } else { - msg(M_FATAL, "ERROR: AddIPAddress %s/%s failed on interface %s= , index=3D%lu, status=3D%lu (windows error: '%s') -- %s", - print_in_addr_t(tt->local, 0, &gc), - print_in_addr_t(tt->adapter_netmask, 0, &gc), - device_guid, - index, - status, - strerror_win32(status, &gc), - error_suffix); + msg(M_FATAL, + "ERROR: AddIPAddress %s/%s failed on interface %s, index= =3D%lu, status=3D%lu (windows error: '%s') -- %s", + print_in_addr_t(tt->local, 0, &gc), print_in_addr_t(tt->ad= apter_netmask, 0, &gc), + device_guid, index, status, strerror_win32(status, &gc), e= rror_suffix); } tt->ipapi_context_defined =3D true; } @@ -6288,11 +5982,11 @@ { ULONG status =3D TRUE; DWORD len; - if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_SET_MEDIA_STATUS, - &status, sizeof(status), - &status, sizeof(status), &len, NULL)) + if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_SET_MEDIA_STATUS, &status= , sizeof(status), &status, + sizeof(status), &len, NULL)) { - msg(M_WARN, "WARNING: The TAP-Windows driver rejected a TAP_WIN_IO= CTL_SET_MEDIA_STATUS DeviceIoControl call."); + msg(M_WARN, + "WARNING: The TAP-Windows driver rejected a TAP_WIN_IOCTL_SET_= MEDIA_STATUS DeviceIoControl call."); } int s =3D tt->options.tap_sleep; @@ -6326,17 +6020,16 @@ ep[1] =3D htonl(tt->local & tt->remote_netmask); ep[2] =3D htonl(tt->remote_netmask); - status =3D DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_TUN, - ep, sizeof(ep), - ep, sizeof(ep), &len, NULL); + status =3D DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_TUN, ep,= sizeof(ep), ep, sizeof(ep), + &len, NULL); if (tt->did_ifconfig_setup) { - msg(status ? M_INFO : M_FATAL, "Set TAP-Windows TUN subnet mod= e network/local/netmask =3D %s/%s/%s [%s]", + msg(status ? M_INFO : M_FATAL, + "Set TAP-Windows TUN subnet mode network/local/netmask =3D= %s/%s/%s [%s]", print_in_addr_t(ep[1], IA_NET_ORDER, &gc), print_in_addr_t(ep[0], IA_NET_ORDER, &gc), - print_in_addr_t(ep[2], IA_NET_ORDER, &gc), - status ? "SUCCEEDED" : "FAILED"); + print_in_addr_t(ep[2], IA_NET_ORDER, &gc), status ? "SUCCE= EDED" : "FAILED"); } else { @@ -6350,11 +6043,11 @@ ep[0] =3D htonl(tt->local); ep[1] =3D htonl(tt->remote_netmask); - if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT, - ep, sizeof(ep), - ep, sizeof(ep), &len, NULL)) + if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT= , ep, sizeof(ep), ep, + sizeof(ep), &len, NULL)) { - msg(M_FATAL, "ERROR: The TAP-Windows driver rejected a DeviceI= oControl call to set Point-to-Point mode, which is required for --dev tun"); + msg(M_FATAL, + "ERROR: The TAP-Windows driver rejected a DeviceIoControl = call to set Point-to-Point mode, which is required for --dev tun"); } } @@ -6377,7 +6070,9 @@ { if (tt->topology =3D=3D TOP_SUBNET) { - ep[2] =3D dhcp_masq_addr(tt->local, tt->remote_netmask, tt->op= tions.dhcp_masq_custom_offset ? tt->options.dhcp_masq_offset : 0); + ep[2] =3D dhcp_masq_addr( + tt->local, tt->remote_netmask, + tt->options.dhcp_masq_custom_offset ? tt->options.dhcp_mas= q_offset : 0); } else { @@ -6387,7 +6082,9 @@ else { ASSERT(tt->type =3D=3D DEV_TYPE_TAP); - ep[2] =3D dhcp_masq_addr(tt->local, tt->adapter_netmask, tt->optio= ns.dhcp_masq_custom_offset ? tt->options.dhcp_masq_offset : 0); + ep[2] =3D + dhcp_masq_addr(tt->local, tt->adapter_netmask, + tt->options.dhcp_masq_custom_offset ? tt->optio= ns.dhcp_masq_offset : 0); } /* lease time in seconds */ @@ -6396,20 +6093,17 @@ ASSERT(ep[3] > 0); #ifndef SIMULATE_DHCP_FAILED /* this code is disabled to simulate bad DHCP= negotiation */ - if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_DHCP_MASQ, - ep, sizeof(ep), - ep, sizeof(ep), &len, NULL)) + if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_DHCP_MASQ, ep, siz= eof(ep), ep, sizeof(ep), + &len, NULL)) { - msg(M_FATAL, "ERROR: The TAP-Windows driver rejected a DeviceIoCon= trol call to set TAP_WIN_IOCTL_CONFIG_DHCP_MASQ mode"); + msg(M_FATAL, + "ERROR: The TAP-Windows driver rejected a DeviceIoControl call= to set TAP_WIN_IOCTL_CONFIG_DHCP_MASQ mode"); } - msg(M_INFO, "Notified TAP-Windows driver to set a DHCP IP/netmask of %= s/%s on interface %s [DHCP-serv: %s, lease-time: %d]", - print_in_addr_t(tt->local, 0, &gc), - print_in_addr_t(tt->adapter_netmask, 0, &gc), - device_guid, - print_in_addr_t(ep[2], IA_NET_ORDER, &gc), - ep[3] - ); + msg(M_INFO, + "Notified TAP-Windows driver to set a DHCP IP/netmask of %s/%s on = interface %s [DHCP-serv: %s, lease-time: %d]", + print_in_addr_t(tt->local, 0, &gc), print_in_addr_t(tt->adapter_ne= tmask, 0, &gc), + device_guid, print_in_addr_t(ep[2], IA_NET_ORDER, &gc), ep[3]); /* user-supplied DHCP options capability */ if (tt->options.dhcp_options) @@ -6418,11 +6112,11 @@ if (build_dhcp_options_string(&buf, &tt->options)) { msg(D_DHCP_OPT, "DHCP option string: %s", format_hex(BPTR(&buf= ), BLEN(&buf), 0, &gc)); - if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_DHCP_SET_O= PT, - BPTR(&buf), BLEN(&buf), - BPTR(&buf), BLEN(&buf), &len, NULL)) + if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_DHCP_SET_O= PT, BPTR(&buf), + BLEN(&buf), BPTR(&buf), BLEN(&buf), &len,= NULL)) { - msg(M_FATAL, "ERROR: The TAP-Windows driver rejected a TAP= _WIN_IOCTL_CONFIG_DHCP_SET_OPT DeviceIoControl call"); + msg(M_FATAL, + "ERROR: The TAP-Windows driver rejected a TAP_WIN_IOCT= L_CONFIG_DHCP_SET_OPT DeviceIoControl call"); } } else @@ -6431,13 +6125,14 @@ } free_buf(&buf); } -#endif /* ifndef SIMULATE_DHCP_FAILED */ +#endif /* ifndef SIMULATE_DHCP_FAILED */ gc_free(&gc); } static bool -tun_try_open_device(struct tuntap *tt, const char *device_guid, const stru= ct device_instance_id_interface *device_instance_id_interface) +tun_try_open_device(struct tuntap *tt, const char *device_guid, + const struct device_instance_id_interface *device_inst= ance_id_interface) { const char *path =3D NULL; char tuntap_device_path[256]; @@ -6456,8 +6151,7 @@ if (tt->backend_driver =3D=3D DRIVER_DCO) { char *last_sep =3D strrchr(dev_if->device_interface, '\\'); - if (!last_sep - || strcmp(last_sep + 1, DCO_WIN_REFERENCE_STRING) !=3D= 0) + if (!last_sep || strcmp(last_sep + 1, DCO_WIN_REFERENCE_ST= RING) !=3D 0) { continue; } @@ -6474,25 +6168,19 @@ else { /* Open TAP-Windows */ - snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s", - USERMODEDEVICEDIR, - device_guid, - TAP_WIN_SUFFIX); + snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",= USERMODEDEVICEDIR, + device_guid, TAP_WIN_SUFFIX); path =3D tuntap_device_path; } msg(D_TAP_WIN_DEBUG, "Using device interface: %s", path); - tt->hand =3D CreateFile(path, - GENERIC_READ | GENERIC_WRITE, - 0, /* was: FILE_SHARE_READ */ - 0, - OPEN_EXISTING, - FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, - 0); + tt->hand =3D CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, /* was:= FILE_SHARE_READ */ + 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_F= LAG_OVERLAPPED, 0); if (tt->hand =3D=3D INVALID_HANDLE_VALUE) { - msg(D_TUNTAP_INFO | M_ERRNO, "CreateFile failed on %s device: %s",= print_tun_backend_driver(tt->backend_driver), path); + msg(D_TUNTAP_INFO | M_ERRNO, "CreateFile failed on %s device: %s", + print_tun_backend_driver(tt->backend_driver), path); return false; } @@ -6500,11 +6188,13 @@ } void -tun_open_device(struct tuntap *tt, const char *dev_node, const char **devi= ce_guid, struct gc_arena *gc) +tun_open_device(struct tuntap *tt, const char *dev_node, const char **devi= ce_guid, + struct gc_arena *gc) { const struct tap_reg *tap_reg =3D get_tap_reg(gc); const struct panel_reg *panel_reg =3D get_panel_reg(gc); - const struct device_instance_id_interface *device_instance_id_interfac= e =3D get_device_instance_id_interface(gc); + const struct device_instance_id_interface *device_instance_id_interfac= e =3D + get_device_instance_id_interface(gc); uint8_t actual_buffer[256]; @@ -6516,7 +6206,8 @@ enum tun_driver_type windows_driver =3D WINDOWS_DRIVER_UNSPECIFIED; /* Get the device GUID for the device specified with --dev-node. */ - *device_guid =3D get_device_guid(dev_node, actual_buffer, sizeof(a= ctual_buffer), &windows_driver, tap_reg, panel_reg, gc); + *device_guid =3D get_device_guid(dev_node, actual_buffer, sizeof(a= ctual_buffer), + &windows_driver, tap_reg, panel_reg= , gc); if (!*device_guid) { @@ -6525,13 +6216,16 @@ if (tt->backend_driver !=3D windows_driver) { - msg(M_FATAL, "Adapter '%s' is using %s driver, %s expected. If= you want to use this device, adjust --windows-driver.", - dev_node, print_tun_backend_driver(windows_driver), print_= tun_backend_driver(tt->backend_driver)); + msg(M_FATAL, + "Adapter '%s' is using %s driver, %s expected. If you want= to use this device, adjust --windows-driver.", + dev_node, print_tun_backend_driver(windows_driver), + print_tun_backend_driver(tt->backend_driver)); } if (!tun_try_open_device(tt, *device_guid, device_instance_id_inte= rface)) { - msg(M_FATAL, "Failed to open %s adapter: %s", print_tun_backen= d_driver(tt->backend_driver), dev_node); + msg(M_FATAL, "Failed to open %s adapter: %s", + print_tun_backend_driver(tt->backend_driver), dev_node); } } else @@ -6543,20 +6237,18 @@ while (true) { enum tun_driver_type windows_driver =3D WINDOWS_DRIVER_UNSPECI= FIED; - *device_guid =3D get_unspecified_device_guid(device_number, - actual_buffer, - sizeof(actual_buffe= r), - tap_reg, - panel_reg, - &windows_driver, - gc); + *device_guid =3D + get_unspecified_device_guid(device_number, actual_buffer, = sizeof(actual_buffer), + tap_reg, panel_reg, &windows_d= river, gc); if (!*device_guid) { /* try to create an adapter a few times if we have a servi= ce pipe handle */ - if ((++adapters_created > 10) || !do_create_adapter_servic= e(tt->options.msg_channel, tt->backend_driver)) + if ((++adapters_created > 10) + || !do_create_adapter_service(tt->options.msg_channel,= tt->backend_driver)) { - msg(M_FATAL, "All %s adapters on this system are curre= ntly in use or disabled.", print_tun_backend_driver(tt->backend_driver)); + msg(M_FATAL, "All %s adapters on this system are curre= ntly in use or disabled.", + print_tun_backend_driver(tt->backend_driver)); } else { @@ -6623,10 +6315,7 @@ */ if (dhcp_status(tt->adapter_index) !=3D DHCP_STATUS_ENABLED) { - netsh_ifconfig(&tt->options, - tt->adapter_index, - tt->local, - tt->adapter_netmask, + netsh_ifconfig(&tt->options, tt->adapter_index, tt->local, tt-= >adapter_netmask, NI_TEST_FIRST | NI_IP_NETMASK | NI_OPTIONS); } else @@ -6687,9 +6376,11 @@ if ((tt->options.dhcp_options & DHCP_OPTIONS_DHCP_REQUIRED) && tt->backend_driver !=3D WINDOWS_DRIVER_TAP_WINDOWS6) { - msg(M_WARN, "Some --dhcp-option or --dns options require DHCP serv= er," + msg(M_WARN, + "Some --dhcp-option or --dns options require DHCP server," " which is not supported by the selected %s driver. They will = be" - " ignored.", print_tun_backend_driver(tt->backend_driver)); + " ignored.", + print_tun_backend_driver(tt->backend_driver)); } /* dco-win already opened the device, which handle we treat as socket = */ @@ -6702,11 +6393,11 @@ /*netcmd_semaphore_lock ();*/ - msg( M_INFO, "open_tun"); + msg(M_INFO, "open_tun"); if (tt->type !=3D DEV_TYPE_TAP && tt->type !=3D DEV_TYPE_TUN) { - msg(M_FATAL|M_NOPREFIX, "Unknown virtual device type: '%s'", dev); + msg(M_FATAL | M_NOPREFIX, "Unknown virtual device type: '%s'", dev= ); } struct gc_arena gc =3D gc_new(); /* used also for device_guid allocati= on */ @@ -6726,10 +6417,8 @@ { struct buffer out =3D alloc_buf_gc(256, gc); DWORD len; - if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_INFO, - BSTR(&out), BCAP(&out), - BSTR(&out), BCAP(&out), - &len, NULL)) + if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_INFO, BSTR(&out), = BCAP(&out), BSTR(&out), + BCAP(&out), &len, NULL)) { return BSTR(&out); } @@ -6744,10 +6433,8 @@ { struct buffer out =3D alloc_buf(1024); DWORD len; - while (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_LOG_LINE, - BSTR(&out), BCAP(&out), - BSTR(&out), BCAP(&out), - &len, NULL)) + while (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_LOG_LINE, BSTR(= &out), BCAP(&out), + BSTR(&out), BCAP(&out), &len, NULL)) { msg(D_TAP_WIN_DEBUG, "TAP-Windows: %s", BSTR(&out)); } @@ -6765,22 +6452,15 @@ int len =3D ipv6 ? tt->options.dns6_len : tt->options.dns_len; if (len > 0) { - argv_printf(&argv, - "%s%s interface %s delete dns %lu all", - get_win_sys_path(), - NETSH_PATH_SUFFIX, - ipv6 ? "ipv6" : "ipv4", - tt->adapter_index); + argv_printf(&argv, "%s%s interface %s delete dns %lu all", get_win= _sys_path(), + NETSH_PATH_SUFFIX, ipv6 ? "ipv6" : "ipv4", tt->adapter= _index); netsh_command(&argv, 1, M_WARN); } if (!ipv6 && tt->options.wins_len > 0) { - argv_printf(&argv, - "%s%s interface ipv4 delete winsservers %lu all", - get_win_sys_path(), - NETSH_PATH_SUFFIX, - tt->adapter_index); + argv_printf(&argv, "%s%s interface ipv4 delete winsservers %lu all= ", get_win_sys_path(), + NETSH_PATH_SUFFIX, tt->adapter_index); netsh_command(&argv, 1, M_WARN); } @@ -6802,13 +6482,8 @@ { ifconfig_ip_local =3D print_in_addr_t(tt->local, 0, gc); } - argv_printf(&argv, - "%s%s interface %s delete address %lu %s store=3Dactive", - get_win_sys_path(), - NETSH_PATH_SUFFIX, - ipv6 ? "ipv6" : "ipv4", - tt->adapter_index, - ifconfig_ip_local); + argv_printf(&argv, "%s%s interface %s delete address %lu %s store=3Dac= tive", get_win_sys_path(), + NETSH_PATH_SUFFIX, ipv6 ? "ipv6" : "ipv4", tt->adapter_ind= ex, ifconfig_ip_local); netsh_command(&argv, 1, M_WARN); argv_free(&argv); @@ -6886,7 +6561,8 @@ { /* We didn't do ifconfig. */ } - else if (tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ || t= t->options.ip_win32_type =3D=3D IPW32_SET_ADAPTIVE) + else if (tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ + || tt->options.ip_win32_type =3D=3D IPW32_SET_ADAPTIVE) { /* We don't have to clean the configuration with DHCP. */ } @@ -6913,10 +6589,9 @@ DWORD status; if ((status =3D DeleteIPAddress(tt->ipapi_context)) !=3D NO_ERROR) { - msg(M_WARN, "Warning: DeleteIPAddress[%u] failed on TAP-Window= s adapter, status=3D%u : %s", - (unsigned int)tt->ipapi_context, - (unsigned int)status, - strerror_win32(status, &gc)); + msg(M_WARN, + "Warning: DeleteIPAddress[%u] failed on TAP-Windows adapte= r, status=3D%u : %s", + (unsigned int)tt->ipapi_context, (unsigned int)status, str= error_win32(status, &gc)); } } @@ -6935,17 +6610,14 @@ * Convert --ip-win32 constants between index and ascii form. */ -struct ipset_names { +struct ipset_names +{ const char *short_form; }; /* Indexed by IPW32_SET_x */ static const struct ipset_names ipset_names[] =3D { - {"manual"}, - {"netsh"}, - {"ipapi"}, - {"dynamic"}, - {"adaptive"} + { "manual" }, { "netsh" }, { "ipapi" }, { "dynamic" }, { "adaptive" } }; int @@ -6995,7 +6667,7 @@ return BSTR(&out); } -#else /* generic */ +#else /* generic */ void open_tun(const char *dev, const char *dev_type, const char *dev_node, stru= ct tuntap *tt, @@ -7025,4 +6697,4 @@ return read(tt->fd, buf, len); } -#endif /* if defined (TARGET_ANDROID) */ +#endif /* if defined (TARGET_ANDROID) */ diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index 5407e47..1c0f6f50 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -41,7 +41,8 @@ #include "networking.h" #include "dco.h" -enum tun_driver_type { +enum tun_driver_type +{ WINDOWS_DRIVER_UNSPECIFIED, WINDOWS_DRIVER_TAP_WINDOWS6, DRIVER_GENERIC_TUNTAP, @@ -68,19 +69,20 @@ #define IPW32_SET_ADAPTIVE_TRY_NETSH 20 /* bit flags for DHCP options */ -#define DHCP_OPTIONS_DHCP_OPTIONAL (1<<0) -#define DHCP_OPTIONS_DHCP_REQUIRED (1<<1) +#define DHCP_OPTIONS_DHCP_OPTIONAL (1 << 0) +#define DHCP_OPTIONS_DHCP_REQUIRED (1 << 1) -struct tuntap_options { +struct tuntap_options +{ /* --ip-win32 options */ bool ip_win32_defined; -#define IPW32_SET_MANUAL 0 /* "--ip-win32 manual" */ -#define IPW32_SET_NETSH 1 /* "--ip-win32 netsh" */ -#define IPW32_SET_IPAPI 2 /* "--ip-win32 ipapi" */ -#define IPW32_SET_DHCP_MASQ 3 /* "--ip-win32 dynamic" */ -#define IPW32_SET_ADAPTIVE 4 /* "--ip-win32 adaptive" */ -#define IPW32_SET_N 5 +#define IPW32_SET_MANUAL 0 /* "--ip-win32 manual" */ +#define IPW32_SET_NETSH 1 /* "--ip-win32 netsh" */ +#define IPW32_SET_IPAPI 2 /* "--ip-win32 ipapi" */ +#define IPW32_SET_DHCP_MASQ 3 /* "--ip-win32 dynamic" */ +#define IPW32_SET_ADAPTIVE 4 /* "--ip-win32 adaptive" */ +#define IPW32_SET_N 5 int ip_win32_type; #ifdef _WIN32 @@ -99,14 +101,15 @@ int dhcp_options; - const char *domain; /* DOMAIN (15) */ + const char *domain; /* DOMAIN (15) */ const char *netbios_scope; /* NBS (47) */ - int netbios_node_type; /* NBT 1,2,4,8 (46) */ + int netbios_node_type; /* NBT 1,2,4,8 (46) */ -#define N_DHCP_ADDR 4 /* Max # of addresses allowed for - * DNS, WINS, etc. */ +#define N_DHCP_ADDR \ + 4 /* Max # of addresses allowed for \ + * DNS, WINS, etc. */ /* DNS (6) */ in_addr_t dns[N_DHCP_ADDR]; @@ -148,13 +151,15 @@ #elif defined(TARGET_LINUX) -struct tuntap_options { +struct tuntap_options +{ int txqueuelen; }; #else /* if defined(_WIN32) || defined(TARGET_ANDROID) */ -struct tuntap_options { +struct tuntap_options +{ int dummy; /* not used */ }; @@ -170,7 +175,8 @@ } afunix_context_t; #else /* ifndef WIN32 */ -typedef struct { +typedef struct +{ int dummy; } afunix_context_t; #endif @@ -196,11 +202,11 @@ * been set up. This does NOT mean ifconfig has been called */ bool did_ifconfig_ipv6_setup; - bool persistent_if; /* if existed before, keep on program end = */ + bool persistent_if; /* if existed before, keep on program e= nd */ struct tuntap_options options; /* options set on command line */ - char *actual_name; /* actual name of TUN/TAP dev, usually including un= it number */ + char *actual_name; /* actual name of TUN/TAP dev, usually = including unit number */ /* ifconfig parameters */ in_addr_t local; @@ -231,7 +237,7 @@ int standby_iter; - #else /* ifdef _WIN32 */ +#else /* ifdef _WIN32 */ int fd; /* file descriptor for TUN/TAP dev */ #endif /* ifdef _WIN32 */ @@ -260,13 +266,13 @@ * Function prototypes */ -void open_tun(const char *dev, const char *dev_type, const char *dev_node, - struct tuntap *tt, openvpn_net_ctx_t *ctx); +void open_tun(const char *dev, const char *dev_type, const char *dev_node,= struct tuntap *tt, + openvpn_net_ctx_t *ctx); void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx); -void tun_open_device(struct tuntap *tt, const char *dev_node, - const char **device_guid, struct gc_arena *gc); +void tun_open_device(struct tuntap *tt, const char *dev_node, const char *= *device_guid, + struct gc_arena *gc); void close_tun_handle(struct tuntap *tt); @@ -274,37 +280,29 @@ int read_tun(struct tuntap *tt, uint8_t *buf, int len); -void tuncfg(const char *dev, const char *dev_type, const char *dev_node, - int persist_mode, const char *username, - const char *groupname, const struct tuntap_options *options, +void tuncfg(const char *dev, const char *dev_type, const char *dev_node, i= nt persist_mode, + const char *username, const char *groupname, const struct tunt= ap_options *options, openvpn_net_ctx_t *ctx); -const char *guess_tuntap_dev(const char *dev, - const char *dev_type, - const char *dev_node, +const char *guess_tuntap_dev(const char *dev, const char *dev_type, const = char *dev_node, struct gc_arena *gc); -struct tuntap *init_tun(const char *dev, /* --dev option */ - const char *dev_type, /* --dev-type option */ - int topology, /* one of the TOP_x values= */ - const char *ifconfig_local_parm, /* --if= config parm 1 */ - const char *ifconfig_remote_netmask_parm, /* --if= config parm 2 */ - const char *ifconfig_ipv6_local_parm, /* --if= config parm 1 / IPv6 */ - int ifconfig_ipv6_netbits_parm, /* --if= config parm 1 / bits */ - const char *ifconfig_ipv6_remote_parm, /* --if= config parm 2 / IPv6 */ - struct addrinfo *local_public, - struct addrinfo *remote_public, - const bool strict_warn, - struct env_set *es, - openvpn_net_ctx_t *ctx, +struct tuntap *init_tun(const char *dev, /* --dev= option */ + const char *dev_type, /* --dev= -type option */ + int topology, /* one o= f the TOP_x values */ + const char *ifconfig_local_parm, /* --ifc= onfig parm 1 */ + const char *ifconfig_remote_netmask_parm, /* --ifc= onfig parm 2 */ + const char *ifconfig_ipv6_local_parm, /* --ifc= onfig parm 1 / IPv6 */ + int ifconfig_ipv6_netbits_parm, /* --ifc= onfig parm 1 / bits */ + const char *ifconfig_ipv6_remote_parm, /* --ifc= onfig parm 2 / IPv6 */ + struct addrinfo *local_public, struct addrinfo *re= mote_public, + const bool strict_warn, struct env_set *es, openvp= n_net_ctx_t *ctx, struct tuntap *tt); -void init_tun_post(struct tuntap *tt, - const struct frame *frame, +void init_tun_post(struct tuntap *tt, const struct frame *frame, const struct tuntap_options *options); -void do_ifconfig_setenv(const struct tuntap *tt, - struct env_set *es); +void do_ifconfig_setenv(const struct tuntap *tt, struct env_set *es); /** * do_ifconfig - configure the tunnel interface @@ -315,8 +313,8 @@ * @param es the environment to be used when executing the commands * @param ctx the networking API opaque context */ -void do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu, - const struct env_set *es, openvpn_net_ctx_t *ctx); +void do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu, const= struct env_set *es, + openvpn_net_ctx_t *ctx); /** * undo_ifconfig - undo configuration of the tunnel interface @@ -332,7 +330,8 @@ const char *dev_type_string(const char *dev, const char *dev_type); -const char *ifconfig_options_string(const struct tuntap *tt, bool remote, = bool disable, struct gc_arena *gc); +const char *ifconfig_options_string(const struct tuntap *tt, bool remote, = bool disable, + struct gc_arena *gc); bool is_tun_p2p(const struct tuntap *tt); @@ -341,8 +340,7 @@ /** * Return a string representation of the tun backed driver type */ -const char * -print_tun_backend_driver(enum tun_driver_type driver); +const char *print_tun_backend_driver(enum tun_driver_type driver); /* * Should ifconfig be called before or after @@ -352,7 +350,7 @@ #define IFCONFIG_BEFORE_TUN_OPEN 0 #define IFCONFIG_AFTER_TUN_OPEN 1 -#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPEN +#define IFCONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPEN static inline int ifconfig_order(struct tuntap *tt) @@ -375,13 +373,13 @@ return IFCONFIG_AFTER_TUN_OPEN; #elif defined(TARGET_ANDROID) return IFCONFIG_BEFORE_TUN_OPEN; -#else /* if defined(TARGET_LINUX) */ +#else /* if defined(TARGET_LINUX) */ return IFCONFIG_DEFAULT; #endif } -#define ROUTE_BEFORE_TUN 0 -#define ROUTE_AFTER_TUN 1 +#define ROUTE_BEFORE_TUN 0 +#define ROUTE_AFTER_TUN 1 #define ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN static inline int @@ -442,11 +440,10 @@ bool is_adapter_up(const struct tuntap *tt, const IP_ADAPTER_INFO *list); -bool is_ip_in_adapter_subnet(const IP_ADAPTER_INFO *ai, const in_addr_t ip= , in_addr_t *highest_netmask); +bool is_ip_in_adapter_subnet(const IP_ADAPTER_INFO *ai, const in_addr_t ip, + in_addr_t *highest_netmask); -DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, - const in_addr_t ip, - int *count, +DWORD adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip,= int *count, in_addr_t *netmask); void show_tap_win_adapters(int msglev, int warnlev); @@ -600,10 +597,7 @@ } static inline void -tun_set(struct tuntap *tt, - struct event_set *es, - unsigned int rwflags, - void *arg, +tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, voi= d *arg, unsigned int *persistent) { if (!tuntap_defined(tt) || tuntap_is_dco_win(tt)) @@ -627,7 +621,6 @@ } #endif tt->rwflags_debug =3D rwflags; - } const char *tun_stat(const struct tuntap *tt, unsigned int rwflags, struct= gc_arena *gc); diff --git a/src/openvpn/tun_afunix.c b/src/openvpn/tun_afunix.c index 50ef765..fb8da91 100644 --- a/src/openvpn/tun_afunix.c +++ b/src/openvpn/tun_afunix.c @@ -48,7 +48,6 @@ #include - static void tun_afunix_exec_child(const char *dev_node, struct tuntap *tt, struct env_= set *env) { @@ -61,8 +60,7 @@ argv_printf(&argv, "%s", program); - tt->afunix.childprocess =3D openvpn_execve_check(&argv, env, S_NOWAITP= ID, - msgprefix); + tt->afunix.childprocess =3D openvpn_execve_check(&argv, env, S_NOWAITP= ID, msgprefix); if (!openvpn_waitpid_check(tt->afunix.childprocess, msgprefix, M_WARN)) { tt->afunix.childprocess =3D 0; @@ -71,10 +69,7 @@ } void -open_tun_afunix(struct options *o, - int mtu, - struct tuntap *tt, - struct env_set *orig_env) +open_tun_afunix(struct options *o, int mtu, struct tuntap *tt, struct env_= set *orig_env) { struct gc_arena gc =3D gc_new(); @@ -82,14 +77,14 @@ if (!(socketpair(AF_UNIX, SOCK_DGRAM, 0, fds) =3D=3D 0)) { msg(M_ERR, "Cannot create socket pair for AF_UNIX socket to extern= al " - "program"); + "program"); return; } /* Ensure that the buffer sizes are decently sized. Otherwise macOS wi= ll * just have 2048 */ - struct socket_buffer_size newsizes =3D {65536, 65536 }; + struct socket_buffer_size newsizes =3D { 65536, 65536 }; socket_set_buffers(fds[0], &newsizes, false); socket_set_buffers(fds[1], &newsizes, false); @@ -168,8 +163,8 @@ } #else /* ifndef WIN32 */ void -open_tun_afunix(const char *dev, const char *dev_type, int mtu, - struct tuntap *tt, struct env_set env) +open_tun_afunix(const char *dev, const char *dev_type, int mtu, struct tun= tap *tt, + struct env_set env) { msg(M_ERR, "AF_UNIX socket support not available on this platform"); } diff --git a/src/openvpn/tun_afunix.h b/src/openvpn/tun_afunix.h index 21ae676..1a3467c 100644 --- a/src/openvpn/tun_afunix.h +++ b/src/openvpn/tun_afunix.h @@ -32,31 +32,24 @@ * the user provided taking care of implementing the actual tun * device. */ -void -open_tun_afunix(struct options *o, - int mtu, - struct tuntap *tt, - struct env_set *env); +void open_tun_afunix(struct options *o, int mtu, struct tuntap *tt, struct= env_set *env); /** * Closes the socket used for the AF_UNIX based device. Also sends a * SIGINT to the child process that was spawned to handle the tun device */ -void -close_tun_afunix(struct tuntap *tt); +void close_tun_afunix(struct tuntap *tt); /** * Writes a packet to a AF_UNIX based tun device. */ -ssize_t -write_tun_afunix(struct tuntap *tt, uint8_t *buf, int len); +ssize_t write_tun_afunix(struct tuntap *tt, uint8_t *buf, int len); /** * Reads a packet from a AF_UNIX based tun device. */ -ssize_t -read_tun_afunix(struct tuntap *tt, uint8_t *buf, int len); +ssize_t read_tun_afunix(struct tuntap *tt, uint8_t *buf, int len); #endif /* AFUNIX_TUN_H */ diff --git a/src/openvpn/vlan.c b/src/openvpn/vlan.c index d0beb48..638554d 100644 --- a/src/openvpn/vlan.c +++ b/src/openvpn/vlan.c @@ -53,8 +53,8 @@ static void vlanhdr_set_vid(struct openvpn_8021qhdr *hdr, const uint16_t vid) { - hdr->pcp_cfi_vid =3D (hdr->pcp_cfi_vid & ~OPENVPN_8021Q_MASK_VID) - | (htons(vid) & OPENVPN_8021Q_MASK_VID); + hdr->pcp_cfi_vid =3D + (hdr->pcp_cfi_vid & ~OPENVPN_8021Q_MASK_VID) | (htons(vid) & OPENV= PN_8021Q_MASK_VID); } /* @@ -97,15 +97,13 @@ /* reject untagged frame */ if (c->options.vlan_accept =3D=3D VLAN_ONLY_TAGGED) { - msg(D_VLAN_DEBUG, - "dropping frame without vlan-tag (proto/len 0x%04x)", + msg(D_VLAN_DEBUG, "dropping frame without vlan-tag (proto/len = 0x%04x)", ntohs(ethhdr->proto)); goto drop; } /* untagged frame is accepted and associated with the global VID */ - msg(D_VLAN_DEBUG, - "assuming pvid for frame without vlan-tag, pvid: %u (proto/len= 0x%04x)", + msg(D_VLAN_DEBUG, "assuming pvid for frame without vlan-tag, pvid:= %u (proto/len 0x%04x)", c->options.vlan_pvid, ntohs(ethhdr->proto)); return c->options.vlan_pvid; @@ -126,8 +124,8 @@ /* VLAN-tagged frame: drop packet */ if (vid !=3D 0) { - msg(D_VLAN_DEBUG, "dropping frame with vlan-tag, vid: %u (= proto/len 0x%04x)", - vid, ntohs(vlanhdr->proto)); + msg(D_VLAN_DEBUG, "dropping frame with vlan-tag, vid: %u (= proto/len 0x%04x)", vid, + ntohs(vlanhdr->proto)); goto drop; } @@ -149,8 +147,7 @@ /* here we have a proper VLAN tagged frame: perform decapsulat= ion * and return embedded VID */ - msg(D_VLAN_DEBUG, - "removing vlan-tag from frame: vid: %u, wrapped proto/len:= 0x%04x", + msg(D_VLAN_DEBUG, "removing vlan-tag from frame: vid: %u, wrap= ped proto/len: 0x%04x", vid, ntohs(vlanhdr->proto)); /* save inner protocol to be restored later after decapsulatio= n */ @@ -225,8 +222,7 @@ goto drop; } - vlanhdr =3D (struct openvpn_8021qhdr *)buf_prepend(buf, - SIZE_ETH_TO_8021Q= _HDR); + vlanhdr =3D (struct openvpn_8021qhdr *)buf_prepend(buf, SIZE_ETH_T= O_8021Q_HDR); /* Initialise VLAN/802.1q header. * Move the Eth header so to keep dst/src addresses the same and t= hen @@ -245,8 +241,8 @@ /* set the VID corresponding to the current context (client) */ vlanhdr_set_vid(vlanhdr, c->options.vlan_pvid); - msg(D_VLAN_DEBUG, "tagging frame: vid %u (wrapping proto/len: %04x)", - c->options.vlan_pvid, vlanhdr->proto); + msg(D_VLAN_DEBUG, "tagging frame: vid %u (wrapping proto/len: %04x)", = c->options.vlan_pvid, + vlanhdr->proto); return; drop: diff --git a/src/openvpn/vlan.h b/src/openvpn/vlan.h index f6cf385..30f2c2d 100644 --- a/src/openvpn/vlan.h +++ b/src/openvpn/vlan.h @@ -32,13 +32,10 @@ struct multi_context; struct multi_instance; -int16_t -vlan_decapsulate(const struct context *c, struct buffer *buf); +int16_t vlan_decapsulate(const struct context *c, struct buffer *buf); -bool -vlan_is_tagged(const struct buffer *buf); +bool vlan_is_tagged(const struct buffer *buf); -void -vlan_process_outgoing_tun(struct multi_context *m, struct multi_instance *= mi); +void vlan_process_outgoing_tun(struct multi_context *m, struct multi_insta= nce *mi); #endif /* VLAN_H */ diff --git a/src/openvpn/wfp_block.c b/src/openvpn/wfp_block.c index 2f13001..b7cb511 100644 --- a/src/openvpn/wfp_block.c +++ b/src/openvpn/wfp_block.c @@ -49,68 +49,33 @@ #endif /* c38d57d1-05a7-4c33-904f-7fbceee60e82 */ -DEFINE_GUID( - FWPM_LAYER_ALE_AUTH_CONNECT_V4, - 0xc38d57d1, - 0x05a7, - 0x4c33, - 0x90, 0x4f, 0x7f, 0xbc, 0xee, 0xe6, 0x0e, 0x82 - ); +DEFINE_GUID(FWPM_LAYER_ALE_AUTH_CONNECT_V4, 0xc38d57d1, 0x05a7, 0x4c33, 0x= 90, 0x4f, 0x7f, 0xbc, + 0xee, 0xe6, 0x0e, 0x82); /* 4a72393b-319f-44bc-84c3-ba54dcb3b6b4 */ -DEFINE_GUID( - FWPM_LAYER_ALE_AUTH_CONNECT_V6, - 0x4a72393b, - 0x319f, - 0x44bc, - 0x84, 0xc3, 0xba, 0x54, 0xdc, 0xb3, 0xb6, 0xb4 - ); +DEFINE_GUID(FWPM_LAYER_ALE_AUTH_CONNECT_V6, 0x4a72393b, 0x319f, 0x44bc, 0x= 84, 0xc3, 0xba, 0x54, + 0xdc, 0xb3, 0xb6, 0xb4); /* d78e1e87-8644-4ea5-9437-d809ecefc971 */ -DEFINE_GUID( - FWPM_CONDITION_ALE_APP_ID, - 0xd78e1e87, - 0x8644, - 0x4ea5, - 0x94, 0x37, 0xd8, 0x09, 0xec, 0xef, 0xc9, 0x71 - ); +DEFINE_GUID(FWPM_CONDITION_ALE_APP_ID, 0xd78e1e87, 0x8644, 0x4ea5, 0x94, 0= x37, 0xd8, 0x09, 0xec, + 0xef, 0xc9, 0x71); /* c35a604d-d22b-4e1a-91b4-68f674ee674b */ -DEFINE_GUID( - FWPM_CONDITION_IP_REMOTE_PORT, - 0xc35a604d, - 0xd22b, - 0x4e1a, - 0x91, 0xb4, 0x68, 0xf6, 0x74, 0xee, 0x67, 0x4b - ); +DEFINE_GUID(FWPM_CONDITION_IP_REMOTE_PORT, 0xc35a604d, 0xd22b, 0x4e1a, 0x9= 1, 0xb4, 0x68, 0xf6, 0x74, + 0xee, 0x67, 0x4b); /* 4cd62a49-59c3-4969-b7f3-bda5d32890a4 */ -DEFINE_GUID( - FWPM_CONDITION_IP_LOCAL_INTERFACE, - 0x4cd62a49, - 0x59c3, - 0x4969, - 0xb7, 0xf3, 0xbd, 0xa5, 0xd3, 0x28, 0x90, 0xa4 - ); +DEFINE_GUID(FWPM_CONDITION_IP_LOCAL_INTERFACE, 0x4cd62a49, 0x59c3, 0x4969,= 0xb7, 0xf3, 0xbd, 0xa5, + 0xd3, 0x28, 0x90, 0xa4); /* 632ce23b-5167-435c-86d7-e903684aa80c */ -DEFINE_GUID( - FWPM_CONDITION_FLAGS, - 0x632ce23b, - 0x5167, - 0x435c, - 0x86, 0xd7, 0xe9, 0x03, 0x68, 0x4a, 0xa8, 0x0c - ); +DEFINE_GUID(FWPM_CONDITION_FLAGS, 0x632ce23b, 0x5167, 0x435c, 0x86, 0xd7, = 0xe9, 0x03, 0x68, 0x4a, + 0xa8, 0x0c); /* UUID of WFP sublayer used by all instances of openvpn * 2f660d7e-6a37-11e6-a181-001e8c6e04a2 */ -DEFINE_GUID( - OPENVPN_WFP_BLOCK_SUBLAYER, - 0x2f660d7e, - 0x6a37, - 0x11e6, - 0xa1, 0x81, 0x00, 0x1e, 0x8c, 0x6e, 0x04, 0xa2 - ); +DEFINE_GUID(OPENVPN_WFP_BLOCK_SUBLAYER, 0x2f660d7e, 0x6a37, 0x11e6, 0xa1, = 0x81, 0x00, 0x1e, 0x8c, + 0x6e, 0x04, 0xa2); static WCHAR *FIREWALL_NAME =3D L"OpenVPN"; @@ -124,7 +89,11 @@ } #define OUT_ON_ERROR(err, msg) \ - if (err) { msg_handler(err, msg); goto out; } + if (err) \ + { \ + msg_handler(err, msg); \ + goto out; \ + } /* * Add a persistent sublayer with specified uuid. @@ -182,24 +151,21 @@ */ DWORD -add_wfp_block_filters(HANDLE *engine_handle, - int index, - const WCHAR *exe_path, - wfp_block_msg_handler_t msg_handler, - BOOL dns_only) +add_wfp_block_filters(HANDLE *engine_handle, int index, const WCHAR *exe_p= ath, + wfp_block_msg_handler_t msg_handler, BOOL dns_only) { - FWPM_SESSION0 session =3D {0}; + FWPM_SESSION0 session =3D { 0 }; FWPM_SUBLAYER0 *sublayer_ptr =3D NULL; NET_LUID itf_luid; UINT64 filterid; FWP_BYTE_BLOB *openvpnblob =3D NULL; - FWPM_FILTER0 Filter =3D {0}; + FWPM_FILTER0 Filter =3D { 0 }; FWPM_FILTER_CONDITION0 Condition[2]; - FWPM_FILTER_CONDITION0 match_openvpn =3D {0}; - FWPM_FILTER_CONDITION0 match_port_53 =3D {0}; - FWPM_FILTER_CONDITION0 match_interface =3D {0}; - FWPM_FILTER_CONDITION0 match_loopback =3D {0}; - FWPM_FILTER_CONDITION0 match_not_loopback =3D {0}; + FWPM_FILTER_CONDITION0 match_openvpn =3D { 0 }; + FWPM_FILTER_CONDITION0 match_port_53 =3D { 0 }; + FWPM_FILTER_CONDITION0 match_interface =3D { 0 }; + FWPM_FILTER_CONDITION0 match_loopback =3D { 0 }; + FWPM_FILTER_CONDITION0 match_not_loopback =3D { 0 }; DWORD err =3D 0; if (!msg_handler) @@ -224,8 +190,8 @@ FwpmFreeMemory0((void **)&sublayer_ptr); } else - { /* Add a new sublayer -- as another process may add it in the meant= ime, - * do not treat "already exists" as an error */ + { /* Add a new sublayer -- as another process may add it in the meanti= me, + * do not treat "already exists" as an error */ err =3D add_sublayer(OPENVPN_WFP_BLOCK_SUBLAYER); if (err =3D=3D FWP_E_ALREADY_EXISTS || err =3D=3D ERROR_SUCCESS) @@ -440,8 +406,7 @@ */ DWORD -set_interface_metric(const NET_IFINDEX index, const ADDRESS_FAMILY family, - const ULONG metric) +set_interface_metric(const NET_IFINDEX index, const ADDRESS_FAMILY family,= const ULONG metric) { DWORD err =3D 0; MIB_IPINTERFACE_ROW ipiface; diff --git a/src/openvpn/wfp_block.h b/src/openvpn/wfp_block.h index fc5ec7e..0fb2554 100644 --- a/src/openvpn/wfp_block.h +++ b/src/openvpn/wfp_block.h @@ -33,7 +33,7 @@ /* Any value less than 5 should work fine. 3 is chosen without any real re= ason. */ #define WFP_BLOCK_IFACE_METRIC 3 -typedef void (*wfp_block_msg_handler_t) (DWORD err, const char *msg); +typedef void (*wfp_block_msg_handler_t)(DWORD err, const char *msg); DWORD delete_wfp_block_filters(HANDLE engine); @@ -52,8 +52,7 @@ * * @return positive interface metric on success or -1 on error */ -int -get_interface_metric(const NET_IFINDEX index, const ADDRESS_FAMILY family,= int *is_auto); +int get_interface_metric(const NET_IFINDEX index, const ADDRESS_FAMILY fam= ily, int *is_auto); /** * Sets interface metric value for specified interface index. @@ -66,8 +65,7 @@ */ DWORD -set_interface_metric(const NET_IFINDEX index, const ADDRESS_FAMILY family, - const ULONG metric); +set_interface_metric(const NET_IFINDEX index, const ADDRESS_FAMILY family,= const ULONG metric); #endif /* ifndef WFP_BLOCK_H */ #endif /* ifdef _WIN32 */ diff --git a/src/openvpn/win32-util.c b/src/openvpn/win32-util.c index dd55743..9c45842 100644 --- a/src/openvpn/win32-util.c +++ b/src/openvpn/win32-util.c @@ -162,7 +162,7 @@ if (WideCharToMultiByte(CP_UTF8, 0, wtmpdir, -1, NULL, 0, NULL, NULL) = > sizeof(tmpdir)) { msg(M_WARN, "Could not get temporary directory. Path is too long." - " Consider using --tmp-dir"); + " Consider using --tmp-dir"); return NULL; } diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index 8d6f9c3..a0cc62e 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -102,8 +102,7 @@ /** * Set OpenSSL environment variables to a safe directory */ -static void -set_openssl_env_vars(void); +static void set_openssl_env_vars(void); void init_win32(void) @@ -168,9 +167,7 @@ } void -overlapped_io_init(struct overlapped_io *o, - const struct frame *frame, - BOOL event_state) +overlapped_io_init(struct overlapped_io *o, const struct frame *frame, BOO= L event_state) { CLEAR(*o); @@ -220,7 +217,8 @@ */ void -init_net_event_win32(struct rw_handle *event, long network_events, socket_= descriptor_t sd, unsigned int flags) +init_net_event_win32(struct rw_handle *event, long network_events, socket_= descriptor_t sd, + unsigned int flags) { /* manual reset events, initially set to unsignaled */ @@ -293,7 +291,8 @@ { if (!CloseHandle(event->read)) { - msg(M_WARN | M_ERRNO, "Warning: CloseHandle (read) failed = in close_net_event_win32"); + msg(M_WARN | M_ERRNO, + "Warning: CloseHandle (read) failed in close_net_event= _win32"); } event->read =3D NULL; } @@ -309,7 +308,8 @@ { if (!CloseHandle(event->write)) { - msg(M_WARN | M_ERRNO, "Warning: CloseHandle (write) failed= in close_net_event_win32"); + msg(M_WARN | M_ERRNO, + "Warning: CloseHandle (write) failed in close_net_even= t_win32"); } event->write =3D NULL; } @@ -333,7 +333,7 @@ ASSERT(!socket_defined(ne->sd)); ne->sd =3D sd; ne->event_mask =3D 0; - init_net_event_win32(&ne->handle, network_events, sd, NE32_PERSIST_EVE= NT|NE32_WRITE_EVENT); + init_net_event_win32(&ne->handle, network_events, sd, NE32_PERSIST_EVE= NT | NE32_WRITE_EVENT); } void @@ -407,7 +407,7 @@ ir.Event.KeyEvent.bKeyDown =3D true; if (!stdin_handle || !WriteConsoleInput(stdin_handle, &ir, 1, &tmp= )) { - msg(M_WARN|M_ERRNO, "WARN: win_trigger_event: WriteConsoleInpu= t"); + msg(M_WARN | M_ERRNO, "WARN: win_trigger_event: WriteConsoleIn= put"); } } } @@ -418,7 +418,7 @@ static bool WINAPI win_ctrl_handler(DWORD signum) { - msg(D_LOW, "win_ctrl_handler: signal received (code=3D%lu)", (unsigned= long) signum); + msg(D_LOW, "win_ctrl_handler: signal received (code=3D%lu)", (unsigned= long)signum); if (siginfo_static.signal_received =3D=3D SIGTERM) { @@ -436,7 +436,7 @@ break; default: - msg(D_LOW, "win_ctrl_handler: signal (code=3D%lu) not handled"= , (unsigned long) signum); + msg(D_LOW, "win_ctrl_handler: signal (code=3D%lu) not handled"= , (unsigned long)signum); break; } /* pass all other signals to the next handler */ @@ -450,9 +450,7 @@ } void -win32_signal_open(struct win32_signal *ws, - int force, - const char *exit_event_name, +win32_signal_open(struct win32_signal *ws, int force, const char *exit_eve= nt_name, bool exit_event_initial_state) { CLEAR(*ws); @@ -474,12 +472,10 @@ if (GetConsoleMode(ws->in.read, &ws->console_mode_save)) { /* running on a console */ - const DWORD new_console_mode =3D ws->console_mode_save - & ~(ENABLE_WINDOW_INPUT - | ENABLE_PROCESSED_INPUT - | ENABLE_LINE_INPUT - | ENABLE_ECHO_INPUT - | ENABLE_MOUSE_INPUT); + const DWORD new_console_mode =3D + ws->console_mode_save + & ~(ENABLE_WINDOW_INPUT | ENABLE_PROCESSED_INPUT | ENA= BLE_LINE_INPUT + | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT); if (new_console_mode !=3D ws->console_mode_save) { @@ -502,8 +498,8 @@ * If console open failed, assume we are running * as a service. */ - if ((force =3D=3D WSO_NOFORCE || force =3D=3D WSO_FORCE_SERVICE) - && !HANDLE_DEFINED(ws->in.read) && exit_event_name) + if ((force =3D=3D WSO_NOFORCE || force =3D=3D WSO_FORCE_SERVICE) && !H= ANDLE_DEFINED(ws->in.read) + && exit_event_name) { struct security_attributes sa; struct gc_arena gc =3D gc_new(); @@ -514,11 +510,11 @@ msg(M_ERR, "Error: win32_signal_open: init SA failed"); } - ws->in.read =3D CreateEventW(&sa.sa, TRUE, exit_event_initial_stat= e ? TRUE : FALSE, - exit_event_nameW); + ws->in.read =3D + CreateEventW(&sa.sa, TRUE, exit_event_initial_state ? TRUE : F= ALSE, exit_event_nameW); if (ws->in.read =3D=3D NULL) { - msg(M_WARN|M_ERRNO, "NOTE: CreateEventW '%s' failed", exit_eve= nt_name); + msg(M_WARN | M_ERRNO, "NOTE: CreateEventW '%s' failed", exit_e= vent_name); } else { @@ -534,9 +530,9 @@ gc_free(&gc); } /* set the ctrl handler in both console and service modes */ - if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) win_ctrl_handler, true)) + if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)win_ctrl_handler, true)) { - msg(M_WARN|M_ERRNO, "WARN: SetConsoleCtrlHandler failed"); + msg(M_WARN | M_ERRNO, "WARN: SetConsoleCtrlHandler failed"); } } @@ -563,8 +559,7 @@ return ir->Event.KeyEvent.wVirtualScanCode; } - if ((ir->Event.KeyEvent.dwControlKeyState - & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) + if ((ir->Event.KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_= ALT_PRESSED)) && (ir->Event.KeyEvent.wVirtualKeyCode !=3D 18)) { return ir->Event.KeyEvent.wVirtualScanCode * 256; @@ -626,8 +621,7 @@ { if (ws->mode =3D=3D WSO_MODE_SERVICE) { - if (HANDLE_DEFINED(ws->in.read) - && WaitForSingleObject(ws->in.read, 0) =3D=3D WAIT_OBJECT_0) + if (HANDLE_DEFINED(ws->in.read) && WaitForSingleObject(ws->in.read= , 0) =3D=3D WAIT_OBJECT_0) { return true; } @@ -684,7 +678,7 @@ { if (ws->mode =3D=3D WSO_MODE_CONSOLE && HANDLE_DEFINED(ws->in.read)) { - msg(M_INFO|M_NOPREFIX, "Press any key to continue..."); + msg(M_INFO | M_NOPREFIX, "Press any key to continue..."); do { WaitForSingleObject(ws->in.read, INFINITE); @@ -735,7 +729,8 @@ { title =3D ""; } - buf_printf(&out, "[%s] " PACKAGE_NAME " " PACKAGE_VERSION " F4:EXIT F1= :USR1 F2:USR2 F3:HUP", title); + buf_printf(&out, "[%s] " PACKAGE_NAME " " PACKAGE_VERSION " F4:EXIT F1= :USR1 F2:USR2 F3:HUP", + title); SetConsoleTitle(BSTR(&out)); gc_free(&gc); } @@ -764,7 +759,7 @@ if (s->hand =3D=3D NULL) { - msg(M_WARN|M_ERRNO, "WARNING: Cannot create Win32 semaphore '%s'",= name); + msg(M_WARN | M_ERRNO, "WARNING: Cannot create Win32 semaphore '%s'= ", name); } else { @@ -782,9 +777,10 @@ DWORD status; ASSERT(!s->locked); - dmsg(D_SEMAPHORE_LOW, "Attempting to lock Win32 semaphore '%s' pri= or to net shell command (timeout =3D %d sec)", - s->name, - timeout_milliseconds / 1000); + dmsg( + D_SEMAPHORE_LOW, + "Attempting to lock Win32 semaphore '%s' prior to net shell co= mmand (timeout =3D %d sec)", + s->name, timeout_milliseconds / 1000); status =3D WaitForSingleObject(s->hand, timeout_milliseconds); if (status =3D=3D WAIT_FAILED) { @@ -799,8 +795,7 @@ else { dmsg(D_SEMAPHORE, "Wait on Win32 semaphore '%s' timed out afte= r %d milliseconds", - s->name, - timeout_milliseconds); + s->name, timeout_milliseconds); } } return ret; @@ -815,8 +810,7 @@ dmsg(D_SEMAPHORE, "Releasing Win32 semaphore '%s'", s->name); if (!ReleaseSemaphore(s->hand, 1, NULL)) { - msg(M_WARN | M_ERRNO, "ReleaseSemaphore failed on Win32 semaph= ore '%s'", - s->name); + msg(M_WARN | M_ERRNO, "ReleaseSemaphore failed on Win32 semaph= ore '%s'", s->name); } s->locked =3D false; } @@ -907,9 +901,9 @@ nchars +=3D strlen(e->string) + 1; } - nchars +=3D strlen(force_path)+1; + nchars +=3D strlen(force_path) + 1; - ret =3D (char *) malloc(nchars); + ret =3D (char *)malloc(nchars); check_malloc_return(ret); p =3D ret; @@ -920,7 +914,7 @@ strcpy(p, e->string); p +=3D strlen(e->string) + 1; } - if (strncmp(e->string, "PATH=3D", 5 ) =3D=3D 0) + if (strncmp(e->string, "PATH=3D", 5) =3D=3D 0) { path_seen =3D true; } @@ -929,8 +923,8 @@ /* make sure PATH is set */ if (!path_seen) { - msg( M_INFO, "env_block: add %s", force_path ); - strcpy( p, force_path ); + msg(M_INFO, "env_block: add %s", force_path); + strcpy(p, force_path); p +=3D strlen(force_path) + 1; } @@ -976,7 +970,7 @@ { const char *arg =3D a->argv[i]; strcpy(work, arg); - string_mod(work, CC_PRINT, CC_DOUBLE_QUOTE|CC_CRLF, '_'); + string_mod(work, CC_PRINT, CC_DOUBLE_QUOTE | CC_CRLF, '_'); if (i) { buf_printf(&buf, " "); @@ -1027,7 +1021,8 @@ start_info.dwFlags =3D STARTF_USESHOWWINDOW; start_info.wShowWindow =3D SW_HIDE; - if (CreateProcessW(cmd, cl, NULL, NULL, FALSE, proc_flags, env= , NULL, &start_info, &proc_info)) + if (CreateProcessW(cmd, cl, NULL, NULL, FALSE, proc_flags, env= , NULL, &start_info, + &proc_info)) { DWORD exit_status =3D 0; CloseHandle(proc_info.hThread); @@ -1038,13 +1033,13 @@ } else { - msg(M_WARN|M_ERRNO, "openvpn_execve: GetExitCodeProces= s %ls failed", cmd); + msg(M_WARN | M_ERRNO, "openvpn_execve: GetExitCodeProc= ess %ls failed", cmd); } CloseHandle(proc_info.hProcess); } else { - msg(M_WARN|M_ERRNO, "openvpn_execve: CreateProcess %ls fai= led", cmd); + msg(M_WARN | M_ERRNO, "openvpn_execve: CreateProcess %ls f= ailed", cmd); } free(env); gc_free(&gc); @@ -1085,7 +1080,8 @@ status =3D GetModuleFileName(NULL, self_exe, sizeof(self_exe)); if (status =3D=3D 0 || status =3D=3D sizeof(self_exe)) { - msg(M_WARN|M_ERRNO, "fork_to_self: CreateProcess failed: cannot ge= t module name via GetModuleFileName"); + msg(M_WARN | M_ERRNO, + "fork_to_self: CreateProcess failed: cannot get module name vi= a GetModuleFileName"); goto done; } @@ -1102,7 +1098,7 @@ } else { - msg(M_WARN|M_ERRNO, "fork_to_self: CreateProcess failed: %s", cmdl= ine); + msg(M_WARN | M_ERRNO, "fork_to_self: CreateProcess failed: %s", cm= dline); } done: @@ -1135,7 +1131,8 @@ } if (status > sizeof(buf) - 1) { - msg(M_FATAL, "String overflow attempting to read environmental var= iable %s", SYS_PATH_ENV_VAR_NAME); + msg(M_FATAL, "String overflow attempting to read environmental var= iable %s", + SYS_PATH_ENV_VAR_NAME); } set_win_sys_path(buf, es); } @@ -1146,7 +1143,7 @@ DWORD status =3D GetModuleFileNameW(NULL, path, size); if (status =3D=3D 0 || status =3D=3D size) { - msg(M_WARN|M_ERRNO, "cannot get executable path"); + msg(M_WARN | M_ERRNO, "cannot get executable path"); return false; } return true; @@ -1163,8 +1160,7 @@ } else { - msg(M_WARN, "Error in WFP: %s : %s [status=3D0x%lx]", - msg, strerror_win32(err, &gc), err); + msg(M_WARN, "Error in WFP: %s : %s [status=3D0x%lx]", msg, strerro= r_win32(err, &gc), err); } gc_free(&gc); @@ -1177,15 +1173,10 @@ ack_message_t ack; struct gc_arena gc =3D gc_new(); - wfp_block_message_t data =3D { - .header =3D { - (add ? msg_add_wfp_block : msg_del_wfp_block), - sizeof(wfp_block_message_t), - 0 - }, - .flags =3D dns_only ? wfp_block_dns : wfp_block_local, - .iface =3D { .index =3D index, .name =3D "" } - }; + wfp_block_message_t data =3D { .header =3D { (add ? msg_add_wfp_block = : msg_del_wfp_block), + sizeof(wfp_block_message_t), = 0 }, + .flags =3D dns_only ? wfp_block_dns : wfp= _block_local, + .iface =3D { .index =3D index, .name =3D = "" } }; if (!send_msg_iservice(pipe, &data, sizeof(data), &ack, "WFP block")) { @@ -1194,9 +1185,10 @@ if (ack.error_number !=3D NO_ERROR) { - msg(M_WARN, "WFP block: %s block filters using service failed: %s = [status=3D0x%x if_index=3D%d]", - (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), - ack.error_number, data.iface.index); + msg(M_WARN, + "WFP block: %s block filters using service failed: %s [status= =3D0x%x if_index=3D%d]", + (add ? "adding" : "deleting"), strerror_win32(ack.error_number= , &gc), ack.error_number, + data.iface.index); goto out; } @@ -1227,8 +1219,8 @@ goto out; } - status =3D add_wfp_block_filters(&m_hEngineHandle, index, openvpnpath, - win_wfp_msg_handler, dns_only); + status =3D + add_wfp_block_filters(&m_hEngineHandle, index, openvpnpath, win_wf= p_msg_handler, dns_only); if (status =3D=3D 0) { int is_auto =3D 0; @@ -1283,7 +1275,8 @@ return true; } -typedef enum { +typedef enum +{ ARCH_X86, ARCH_AMD64, ARCH_ARM64, @@ -1297,9 +1290,9 @@ *process_arch =3D ARCH_UNKNOWN; *host_arch =3D ARCH_NATIVE; - typedef BOOL (WINAPI *is_wow64_process2_t)(HANDLE, USHORT *, USHORT *); - is_wow64_process2_t is_wow64_process2 =3D (is_wow64_process2_t) - GetProcAddress(GetModuleHandle= ("Kernel32.dll"), "IsWow64Process2"); + typedef BOOL(WINAPI * is_wow64_process2_t)(HANDLE, USHORT *, USHORT *); + is_wow64_process2_t is_wow64_process2 =3D + (is_wow64_process2_t)GetProcAddress(GetModuleHandle("Kernel32.dll"= ), "IsWow64Process2"); USHORT process_machine =3D 0; USHORT native_machine =3D 0; @@ -1311,8 +1304,7 @@ if (is_wow64_process2) { /* this could be amd64 on arm64 */ - BOOL is_wow64 =3D is_wow64_process2(GetCurrentProcess(), - &process_machine, &native_machin= e); + BOOL is_wow64 =3D is_wow64_process2(GetCurrentProcess(), &process_= machine, &native_machine); if (is_wow64 && native_machine =3D=3D IMAGE_FILE_MACHINE_ARM64) { *host_arch =3D ARCH_ARM64; @@ -1324,8 +1316,7 @@ if (is_wow64_process2) { /* check if we're running on arm64 or amd64 machine */ - BOOL is_wow64 =3D is_wow64_process2(GetCurrentProcess(), - &process_machine, &native_machin= e); + BOOL is_wow64 =3D is_wow64_process2(GetCurrentProcess(), &process_= machine, &native_machine); if (is_wow64) { switch (native_machine) @@ -1384,7 +1375,7 @@ } } =20 -typedef LONG (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); +typedef LONG(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); const char * win32_version_string(struct gc_arena *gc) @@ -1429,18 +1420,16 @@ } bool -send_msg_iservice(HANDLE pipe, const void *data, size_t size, - ack_message_t *ack, const char *context) +send_msg_iservice(HANDLE pipe, const void *data, size_t size, ack_message_= t *ack, + const char *context) { struct gc_arena gc =3D gc_new(); DWORD len; bool ret =3D true; - if (!WriteFile(pipe, data, size, &len, NULL) - || !ReadFile(pipe, ack, sizeof(*ack), &len, NULL)) + if (!WriteFile(pipe, data, size, &len, NULL) || !ReadFile(pipe, ack, s= izeof(*ack), &len, NULL)) { - msg(M_WARN, "%s: could not talk to service: %s [%lu]", - context ? context : "Unknown", + msg(M_WARN, "%s: could not talk to service: %s [%lu]", context ? c= ontext : "Unknown", strerror_win32(GetLastError(), &gc), GetLastError()); ret =3D false; } @@ -1488,14 +1477,13 @@ install_path[wcslen(install_path) - 1] =3D L'\0'; } - static struct { + static struct + { WCHAR *name; WCHAR *value; - } ossl_env[] =3D { - {L"OPENSSL_CONF", L"openssl.cnf"}, - {L"OPENSSL_ENGINES", L"engines"}, - {L"OPENSSL_MODULES", L"modules"} - }; + } ossl_env[] =3D { { L"OPENSSL_CONF", L"openssl.cnf" }, + { L"OPENSSL_ENGINES", L"engines" }, + { L"OPENSSL_MODULES", L"modules" } }; for (size_t i =3D 0; i < SIZE(ossl_env); ++i) { @@ -1504,7 +1492,7 @@ _wgetenv_s(&size, NULL, 0, ossl_env[i].name); if (size =3D=3D 0) { - WCHAR val[MAX_PATH] =3D {0}; + WCHAR val[MAX_PATH] =3D { 0 }; swprintf(val, _countof(val), L"%ls\\ssl\\%ls", install_path, o= ssl_env[i].value); _wputenv_s(ossl_env[i].name, val); } @@ -1525,7 +1513,7 @@ { if (n > 0) { - Sleep(n*1000); + Sleep(n * 1000); } return; } @@ -1535,9 +1523,8 @@ while (expire >=3D now) { - DWORD status =3D WaitForSingleObject(win32_signal.in.read, (expire= -now)*1000); - if ((status =3D=3D WAIT_OBJECT_0 && win32_signal_get(&win32_signal= )) - || status =3D=3D WAIT_TIMEOUT) + DWORD status =3D WaitForSingleObject(win32_signal.in.read, (expire= - now) * 1000); + if ((status =3D=3D WAIT_OBJECT_0 && win32_signal_get(&win32_signal= )) || status =3D=3D WAIT_TIMEOUT) { return; } @@ -1548,7 +1535,7 @@ { if (expire > now) { - Sleep((expire-now)*1000); + Sleep((expire - now) * 1000); } return; } @@ -1600,8 +1587,8 @@ } /* Check if the plugin path resides within the plugin/install director= y */ - if ((wcslen(normalized_plugin_dir) > 0) && (wcsnicmp(normalized_plugin= _dir, - plugin_path, wcsl= en(normalized_plugin_dir)) =3D=3D 0)) + if ((wcslen(normalized_plugin_dir) > 0) + && (wcsnicmp(normalized_plugin_dir, plugin_path, wcslen(normalized= _plugin_dir)) =3D=3D 0)) { return true; } diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h index 4b07d9e..34f622d 100644 --- a/src/openvpn/win32.h +++ b/src/openvpn/win32.h @@ -35,12 +35,13 @@ #include "win32-util.h" /* location of executables */ -#define SYS_PATH_ENV_VAR_NAME "SystemRoot" /* environmental variable name= that normally contains the system path */ -#define NETSH_PATH_SUFFIX "\\system32\\netsh.exe" -#define WIN_ROUTE_PATH_SUFFIX "\\system32\\route.exe" +#define SYS_PATH_ENV_VAR_NAME \ + "SystemRoot" /* environmental variable name that normally contains the= system path */ +#define NETSH_PATH_SUFFIX "\\system32\\netsh.exe" +#define WIN_ROUTE_PATH_SUFFIX "\\system32\\route.exe" #define WIN_IPCONFIG_PATH_SUFFIX "\\system32\\ipconfig.exe" -#define WIN_NET_PATH_SUFFIX "\\system32\\net.exe" -#define WMIC_PATH_SUFFIX "\\system32\\wbem\\wmic.exe" +#define WIN_NET_PATH_SUFFIX "\\system32\\net.exe" +#define WMIC_PATH_SUFFIX "\\system32\\wbem\\wmic.exe" /* * Win32-specific OpenVPN code, targeted at the mingw @@ -76,7 +77,8 @@ char old_window_title[256]; }; -struct rw_handle { +struct rw_handle +{ HANDLE read; HANDLE write; }; @@ -85,8 +87,8 @@ * Event-based notification of incoming TCP connections */ -#define NE32_PERSIST_EVENT (1<<0) -#define NE32_WRITE_EVENT (1<<1) +#define NE32_PERSIST_EVENT (1 << 0) +#define NE32_WRITE_EVENT (1 << 1) static inline bool defined_net_event_win32(const struct rw_handle *event) @@ -94,7 +96,8 @@ return event->read !=3D NULL; } -void init_net_event_win32(struct rw_handle *event, long network_events, so= cket_descriptor_t sd, unsigned int flags); +void init_net_event_win32(struct rw_handle *event, long network_events, so= cket_descriptor_t sd, + unsigned int flags); long reset_net_event_win32(struct rw_handle *event, socket_descriptor_t sd= ); @@ -150,7 +153,8 @@ /* * Signal handling */ -struct win32_signal { +struct win32_signal +{ #define WSO_MODE_UNDEF 0 #define WSO_MODE_SERVICE 1 #define WSO_MODE_CONSOLE 2 @@ -170,10 +174,8 @@ #define WSO_FORCE_SERVICE 1 #define WSO_FORCE_CONSOLE 2 -void win32_signal_open(struct win32_signal *ws, - int force, /* set to WSO force parm */ - const char *exit_event_name, - bool exit_event_initial_state); +void win32_signal_open(struct win32_signal *ws, int force, /* set to WSO f= orce parm */ + const char *exit_event_name, bool exit_event_initia= l_state); void win32_signal_close(struct win32_signal *ws); @@ -199,17 +201,19 @@ * We try to do all Win32 I/O using overlapped * (i.e. asynchronous) I/O for a performance win. */ -struct overlapped_io { +struct overlapped_io +{ #define IOSTATE_INITIAL 0 -#define IOSTATE_QUEUED 1 /* overlapped I/O has been queued */ -#define IOSTATE_IMMEDIATE_RETURN 2 /* I/O function returned immediately w= ithout queueing */ +#define IOSTATE_QUEUED 1 /* overlapped I/O has been queued */ +#define IOSTATE_IMMEDIATE_RETURN 2 /* I/O function returned immediately wi= thout queueing */ int iostate; OVERLAPPED overlapped; DWORD size; DWORD flags; int status; bool addr_defined; - union { + union + { struct sockaddr_in addr; struct sockaddr_in6 addr6; }; @@ -218,9 +222,7 @@ struct buffer buf; }; -void overlapped_io_init(struct overlapped_io *o, - const struct frame *frame, - BOOL event_state); +void overlapped_io_init(struct overlapped_io *o, const struct frame *frame= , BOOL event_state); void overlapped_io_close(struct overlapped_io *o); @@ -305,14 +307,13 @@ * and read the result in |ack|. Returns false on communication error. * The string in |context| is used to prefix error messages. */ -bool send_msg_iservice(HANDLE pipe, const void *data, size_t size, - ack_message_t *ack, const char *context); +bool send_msg_iservice(HANDLE pipe, const void *data, size_t size, ack_mes= sage_t *ack, + const char *context); /* * Attempt to simulate fork/execve on Windows */ -int -openvpn_execve(const struct argv *a, const struct env_set *es, const unsig= ned int flags); +int openvpn_execve(const struct argv *a, const struct env_set *es, const u= nsigned int flags); /* Sleep that can be interrupted by signals and exit event */ void win32_sleep(const int n); @@ -325,8 +326,7 @@ * @param size Size of `value` buffer in bytes. * @return `true` if successful, `false` otherwise. */ -bool -get_openvpn_reg_value(const WCHAR *key, WCHAR *value, DWORD size); +bool get_openvpn_reg_value(const WCHAR *key, WCHAR *value, DWORD size); /** * @brief Checks if a plugin is located in a trusted directory. @@ -341,8 +341,7 @@ * @param plugin_path Normalized path to the plugin. * @return \c true if the plugin is in a trusted directory and not a UNC p= ath; \c false otherwise. */ -bool -plugin_in_trusted_dir(const WCHAR *plugin_path); +bool plugin_in_trusted_dir(const WCHAR *plugin_path); /** * Encrypt a region of memory using CryptProtectMemory() @@ -352,8 +351,7 @@ * - len number of bytes to encrypt -- must be a multiple of * CRYPTPROTECTMEMORY_BLOCK_SIZE =3D 16 */ -bool -protect_buffer_win32(char *buf, size_t len); +bool protect_buffer_win32(char *buf, size_t len); /** * Decrypt a previously encrypted region of memory using CryptUnProtectMem= ory() @@ -363,8 +361,7 @@ * - len number of bytes to encrypt -- must be a multiple of * CRYPTPROTECTMEMORY_BLOCK_SIZE =3D 16 */ -bool -unprotect_buffer_win32(char *buf, size_t len); +bool unprotect_buffer_win32(char *buf, size_t len); #endif /* ifndef OPENVPN_WIN32_H */ #endif /* ifdef _WIN32 */ diff --git a/src/openvpn/xkey_common.h b/src/openvpn/xkey_common.h index 84c6329..3f63919 100644 --- a/src/openvpn/xkey_common.h +++ b/src/openvpn/xkey_common.h @@ -47,12 +47,13 @@ * Struct to encapsulate signature algorithm parameters to pass * to sign operation. */ -typedef struct { +typedef struct +{ const char *padmode; /**< "pkcs1", "pss" or "none" */ - const char *mdname; /**< "SHA256" or "SHA2-256" etc. */ + const char *mdname; /**< "SHA256" or "SHA2-256" etc. */ const char *saltlen; /**< "digest", "auto" or "max" */ const char *keytype; /**< "EC" or "RSA" */ - const char *op; /**< "Sign" or "DigestSign" */ + const char *op; /**< "Sign" or "DigestSign" */ } XKEY_SIGALG; /** @@ -79,15 +80,14 @@ * before signing. The digest algorithm used (or to be used) is passed in = the sigalg * structure. */ -typedef int (XKEY_EXTERNAL_SIGN_fn)(void *handle, unsigned char *sig, size= _t *siglen, - const unsigned char *tbs, size_t tbsle= n, - XKEY_SIGALG sigalg); +typedef int(XKEY_EXTERNAL_SIGN_fn)(void *handle, unsigned char *sig, size_= t *siglen, + const unsigned char *tbs, size_t tbslen= , XKEY_SIGALG sigalg); /** * Signature of private key free function callback used * to free the opaque private key handle obtained from the * backend. Not required for management-external-key. */ -typedef void (XKEY_PRIVKEY_FREE_fn)(void *handle); +typedef void(XKEY_PRIVKEY_FREE_fn)(void *handle); /** * Generate an encapsulated EVP_PKEY for management-external-key @@ -116,9 +116,8 @@ * to the required size and false is returned. * */ -bool -encode_pkcs1(unsigned char *enc, size_t *enc_len, const char *mdname, - const unsigned char *tbs, size_t tbslen); +bool encode_pkcs1(unsigned char *enc, size_t *enc_len, const char *mdname,= const unsigned char *tbs, + size_t tbslen); /** * Compute message digest @@ -134,9 +133,8 @@ * On successful return *buflen is set to the actual size of the result. * TIP: EVP_MD_MAX_SIZE should be enough capacity of buf for al algorithms. */ -int -xkey_digest(const unsigned char *src, size_t srclen, unsigned char *buf, - size_t *buflen, const char *mdname); +int xkey_digest(const unsigned char *src, size_t srclen, unsigned char *bu= f, size_t *buflen, + const char *mdname); /** * Load a generic external key with custom sign and free ops @@ -151,9 +149,8 @@ * IMPORTANT: a reference to the handle is retained by the provider and * relased by calling free_op. The caller should not free it. */ -EVP_PKEY * -xkey_load_generic_key(OSSL_LIB_CTX *libctx, void *handle, EVP_PKEY *pubkey, - XKEY_EXTERNAL_SIGN_fn *sign_op, XKEY_PRIVKEY_FREE_fn= *free_op); +EVP_PKEY *xkey_load_generic_key(OSSL_LIB_CTX *libctx, void *handle, EVP_PK= EY *pubkey, + XKEY_EXTERNAL_SIGN_fn *sign_op, XKEY_PRIVK= EY_FREE_fn *free_op); extern OSSL_LIB_CTX *tls_libctx; /* Global */ @@ -167,7 +164,7 @@ static inline int xkey_max_saltlen(int modBits, int hLen) { - int emLen =3D (modBits - 1 + 7)/8; /* ceil((modBits - 1)/8) */ + int emLen =3D (modBits - 1 + 7) / 8; /* ceil((modBits - 1)/8) */ return emLen - hLen - 2; } @@ -182,8 +179,7 @@ * @returns the size of the converted signature or <=3D 0 on error. * On success, buf is overwritten by its DER encoding */ -int -ecdsa_bin2der(unsigned char *buf, int len, size_t capacity); +int ecdsa_bin2der(unsigned char *buf, int len, size_t capacity); #endif /* HAVE_XKEY_PROVIDER */ diff --git a/src/openvpn/xkey_helper.c b/src/openvpn/xkey_helper.c index b5ed73c..2ff9e4b 100644 --- a/src/openvpn/xkey_helper.c +++ b/src/openvpn/xkey_helper.c @@ -60,8 +60,8 @@ /** helper to compute digest */ int -xkey_digest(const unsigned char *src, size_t srclen, unsigned char *buf, - size_t *buflen, const char *mdname) +xkey_digest(const unsigned char *src, size_t srclen, unsigned char *buf, s= ize_t *buflen, + const char *mdname) { dmsg(D_XKEY, "In xkey_digest"); EVP_MD *md =3D EVP_MD_fetch(NULL, mdname, NULL); /* from default conte= xt */ @@ -71,7 +71,7 @@ return 0; } - unsigned int len =3D (unsigned int) *buflen; + unsigned int len =3D (unsigned int)*buflen; if (EVP_Digest(src, srclen, buf, &len, md, NULL) !=3D 1) { msg(M_WARN, "WARN: xkey_digest: EVP_Digest failed"); @@ -122,18 +122,17 @@ =20 /* UTF8 string pointers in here are only read from, so cast is safe */ OSSL_PARAM params[] =3D { - {"xkey-origin", OSSL_PARAM_UTF8_STRING, (char *) origin, 0, 0}, - {"pubkey", OSSL_PARAM_OCTET_STRING, &pubkey, sizeof(pubkey), 0}, - {"handle", OSSL_PARAM_OCTET_PTR, &handle, sizeof(handle), 0}, - {"sign_op", OSSL_PARAM_OCTET_PTR, (void **) &sign_op, sizeof(sign_= op), 0}, - {"free_op", OSSL_PARAM_OCTET_PTR, (void **) &free_op, sizeof(free_= op), 0}, - {NULL, 0, NULL, 0, 0} + { "xkey-origin", OSSL_PARAM_UTF8_STRING, (char *)origin, 0, 0 }, + { "pubkey", OSSL_PARAM_OCTET_STRING, &pubkey, sizeof(pubkey), 0 }, + { "handle", OSSL_PARAM_OCTET_PTR, &handle, sizeof(handle), 0 }, + { "sign_op", OSSL_PARAM_OCTET_PTR, (void **)&sign_op, sizeof(sign_= op), 0 }, + { "free_op", OSSL_PARAM_OCTET_PTR, (void **)&free_op, sizeof(free_= op), 0 }, + { NULL, 0, NULL, 0, 0 } }; /* Do not use EVP_PKEY_new_from_pkey as that will take keymgmt from pu= bkey */ EVP_PKEY_CTX *ctx =3D EVP_PKEY_CTX_new_from_name(libctx, EVP_PKEY_get0= _type_name(pubkey), props); - if (!ctx - || EVP_PKEY_fromdata_init(ctx) !=3D 1 + if (!ctx || EVP_PKEY_fromdata_init(ctx) !=3D 1 || EVP_PKEY_fromdata(ctx, &pkey, EVP_PKEY_KEYPAIR, params) !=3D 1) { print_openssl_errors(); @@ -162,13 +161,12 @@ * @return signature length or -1 on error. */ int -xkey_management_sign(void *unused, unsigned char *sig, size_t *siglen, - const unsigned char *tbs, size_t tbslen, XKEY_SIGALG = alg) +xkey_management_sign(void *unused, unsigned char *sig, size_t *siglen, con= st unsigned char *tbs, + size_t tbslen, XKEY_SIGALG alg) { - dmsg(D_XKEY, "In xkey_management_sign with keytype =3D %s, op =3D %s", - alg.keytype, alg.op); + dmsg(D_XKEY, "In xkey_management_sign with keytype =3D %s, op =3D %s",= alg.keytype, alg.op); - (void) unused; + (void)unused; char alg_str[128]; unsigned char buf[EVP_MAX_MD_SIZE]; /* for computing digest if require= d */ size_t buflen =3D sizeof(buf); @@ -229,8 +227,7 @@ /* For undigested message, add hashalg=3Ddigest parameter */ else { - snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s", - "RSA_PKCS1_PADDING", alg.mdname); + snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s", "RSA_PKC= S1_PADDING", alg.mdname); } } else if (!strcmp(alg.padmode, "none") && (flags & MF_EXTERNAL_KEY_NOPA= DDING) @@ -240,13 +237,12 @@ } else if (!strcmp(alg.padmode, "pss") && (flags & MF_EXTERNAL_KEY_PSSPA= D)) { - snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s,saltlen=3D%s", - "RSA_PKCS1_PSS_PADDING", alg.mdname, alg.saltlen); + snprintf(alg_str, sizeof(alg_str), "%s,hashalg=3D%s,saltlen=3D%s",= "RSA_PKCS1_PSS_PADDING", + alg.mdname, alg.saltlen); } else { - msg(M_NONFATAL, "RSA padding mode not supported by management-clie= nt <%s>", - alg.padmode); + msg(M_NONFATAL, "RSA padding mode not supported by management-clie= nt <%s>", alg.padmode); return 0; } @@ -261,7 +257,7 @@ char *out_b64 =3D NULL; int len =3D -1; - int bencret =3D openvpn_base64_encode(tbs, (int) tbslen, &in_b64); + int bencret =3D openvpn_base64_encode(tbs, (int)tbslen, &in_b64); if (management && bencret > 0) { @@ -269,7 +265,7 @@ } if (out_b64) { - len =3D openvpn_base64_decode(out_b64, sig, (int) *siglen); + len =3D openvpn_base64_decode(out_b64, sig, (int)*siglen); } free(in_b64); free(out_b64); @@ -296,8 +292,8 @@ * to the required size and false is returned. */ bool -encode_pkcs1(unsigned char *enc, size_t *enc_len, const char *mdname, - const unsigned char *tbs, size_t tbslen) +encode_pkcs1(unsigned char *enc, size_t *enc_len, const char *mdname, cons= t unsigned char *tbs, + size_t tbslen) { ASSERT(enc_len !=3D NULL); ASSERT(tbs !=3D NULL); @@ -310,32 +306,34 @@ * Also see the table in RFC 8017 section 9.2, Note 1. */ - const unsigned char sha1[] =3D {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x= 2b, - 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04= , 0x14}; - const unsigned char sha256[] =3D {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, = 0x60, 0x86, 0x48, - 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x= 05, 0x00, 0x04, 0x20}; - const unsigned char sha384[] =3D {0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, = 0x60, 0x86, 0x48, - 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x= 05, 0x00, 0x04, 0x30}; - const unsigned char sha512[] =3D {0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, = 0x60, 0x86, 0x48, - 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x= 05, 0x00, 0x04, 0x40}; - const unsigned char sha224[] =3D {0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, = 0x60, 0x86, 0x48, - 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x= 05, 0x00, 0x04, 0x1c}; - const unsigned char sha512_224[] =3D {0x30, 0x2d, 0x30, 0x0d, 0x06, 0x= 09, 0x60, 0x86, 0x48, - 0x01, 0x65, 0x03, 0x04, 0x02, 0x05= , 0x05, 0x00, 0x04, 0x1c}; - const unsigned char sha512_256[] =3D {0x30, 0x31, 0x30, 0x0d, 0x06, 0x= 09, 0x60, 0x86, 0x48, - 0x01, 0x65, 0x03, 0x04, 0x02, 0x06= , 0x05, 0x00, 0x04, 0x20}; + const unsigned char sha1[] =3D { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0= x2b, 0x0e, + 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x1= 4 }; + const unsigned char sha256[] =3D { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09,= 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0= x00, 0x04, 0x20 }; + const unsigned char sha384[] =3D { 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09,= 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0= x00, 0x04, 0x30 }; + const unsigned char sha512[] =3D { 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09,= 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0= x00, 0x04, 0x40 }; + const unsigned char sha224[] =3D { 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09,= 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0= x00, 0x04, 0x1c }; + const unsigned char sha512_224[] =3D { 0x30, 0x2d, 0x30, 0x0d, 0x06, 0= x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x05, 0x0= 5, 0x00, 0x04, 0x1c }; + const unsigned char sha512_256[] =3D { 0x30, 0x31, 0x30, 0x0d, 0x06, 0= x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x06, 0x0= 5, 0x00, 0x04, 0x20 }; - typedef struct { + typedef struct + { const int nid; const unsigned char *header; size_t sz; } DIG_INFO; -#define MAKE_DI(x) {NID_ ## x, x, sizeof(x)} +#define MAKE_DI(x) { NID_##x, x, sizeof(x) } - DIG_INFO dinfo[] =3D {MAKE_DI(sha1), MAKE_DI(sha256), MAKE_DI(sha384), - MAKE_DI(sha512), MAKE_DI(sha224), MAKE_DI(sha512_2= 24), - MAKE_DI(sha512_256), {0, NULL, 0}}; + DIG_INFO dinfo[] =3D { + MAKE_DI(sha1), MAKE_DI(sha256), MAKE_DI(sha384), MAKE_DI= (sha512), + MAKE_DI(sha224), MAKE_DI(sha512_224), MAKE_DI(sha512_256), { 0, NU= LL, 0 } + }; size_t out_len =3D 0; bool ret =3D false; @@ -388,8 +386,7 @@ /* combine header and digest */ memcpy(enc, di->header, di->sz); memcpy(enc + di->sz, tbs, tbslen); - dmsg(D_XKEY, "encode_pkcs1: digest length =3D %zu encoded length = =3D %zu", - tbslen, out_len); + dmsg(D_XKEY, "encode_pkcs1: digest length =3D %zu encoded length = =3D %zu", tbslen, out_len); ret =3D true; } @@ -409,9 +406,9 @@ ecdsa_bin2der(unsigned char *buf, int len, size_t capacity) { ECDSA_SIG *ecsig =3D NULL; - int rlen =3D len/2; + int rlen =3D len / 2; BIGNUM *r =3D BN_bin2bn(buf, rlen, NULL); - BIGNUM *s =3D BN_bin2bn(buf+rlen, rlen, NULL); + BIGNUM *s =3D BN_bin2bn(buf + rlen, rlen, NULL); if (!r || !s) { goto err; @@ -428,7 +425,7 @@ } int derlen =3D i2d_ECDSA_SIG(ecsig, NULL); - if (derlen > (int) capacity) + if (derlen > (int)capacity) { ECDSA_SIG_free(ecsig); msg(M_NONFATAL, "Error: DER encoded ECDSA signature is too long (%= d)\n", derlen); diff --git a/src/openvpn/xkey_provider.c b/src/openvpn/xkey_provider.c index deaca38..cbc9033 100644 --- a/src/openvpn/xkey_provider.c +++ b/src/openvpn/xkey_provider.c @@ -47,15 +47,16 @@ typedef struct { - OSSL_LIB_CTX *libctx; /**< a child libctx for our own use */ + OSSL_LIB_CTX *libctx; /**< a child libctx for our own use */ } XKEY_PROVIDER_CTX; /* helper to print debug messages */ -#define xkey_dmsg(f, ...) \ - do { \ - dmsg(f|M_NOLF, "xkey_provider: In %s: ", __func__); \ - dmsg(f|M_NOPREFIX, __VA_ARGS__); \ - } while(0) +#define xkey_dmsg(f, ...) \ + do \ + { \ + dmsg(f | M_NOLF, "xkey_provider: In %s: ", __func__); \ + dmsg(f | M_NOPREFIX, __VA_ARGS__); \ + } while (0) typedef enum { @@ -94,7 +95,7 @@ /** keydata handle free function of backend */ XKEY_PRIVKEY_FREE_fn *free; XKEY_PROVIDER_CTX *prov; - int refcount; /**< reference count */ + int refcount; /**< reference count */ } XKEY_KEYDATA; static inline const char * @@ -129,9 +130,8 @@ * Helper sign function for native keys * Implemented using OpenSSL calls. */ -int -xkey_native_sign(XKEY_KEYDATA *key, unsigned char *sig, size_t *siglen, - const unsigned char *tbs, size_t tbslen, XKEY_SIGALG siga= lg); +int xkey_native_sign(XKEY_KEYDATA *key, unsigned char *sig, size_t *siglen, + const unsigned char *tbs, size_t tbslen, XKEY_SIGALG = sigalg); /* keymgmt provider */ @@ -151,8 +151,7 @@ static OSSL_FUNC_keymgmt_query_operation_name_fn rsa_keymgmt_name; static OSSL_FUNC_keymgmt_query_operation_name_fn ec_keymgmt_name; -static int -keymgmt_import_helper(XKEY_KEYDATA *key, const OSSL_PARAM params[]); +static int keymgmt_import_helper(XKEY_KEYDATA *key, const OSSL_PARAM param= s[]); static XKEY_KEYDATA * keydata_new(void) @@ -274,9 +273,8 @@ int selection_pub =3D selection & ~OSSL_KEYMGMT_SELECT_PRIVATE_KEY; EVP_PKEY_CTX *ctx =3D EVP_PKEY_CTX_new_from_name(key->prov->libctx, na= me, NULL); - if (!ctx - || (EVP_PKEY_fromdata_init(ctx) !=3D 1) - || (EVP_PKEY_fromdata(ctx, &pkey, selection_pub, (OSSL_PARAM *) pa= rams) !=3D1)) + if (!ctx || (EVP_PKEY_fromdata_init(ctx) !=3D 1) + || (EVP_PKEY_fromdata(ctx, &pkey, selection_pub, (OSSL_PARAM *)par= ams) !=3D 1)) { msg(M_WARN, "Error: keymgmt_import failed for key type <%s>", name= ); if (pkey) @@ -296,10 +294,10 @@ { /* create private key */ pkey =3D NULL; - if (EVP_PKEY_fromdata(ctx, &pkey, selection, (OSSL_PARAM *) params= ) =3D=3D 1) + if (EVP_PKEY_fromdata(ctx, &pkey, selection, (OSSL_PARAM *)params)= =3D=3D 1) { key->handle =3D pkey; - key->free =3D (XKEY_PRIVKEY_FREE_fn *) EVP_PKEY_free; + key->free =3D (XKEY_PRIVKEY_FREE_fn *)EVP_PKEY_free; } } EVP_PKEY_CTX_free(ctx); @@ -420,12 +418,10 @@ { xkey_dmsg(D_XKEY, "entry"); - static OSSL_PARAM gettable[] =3D { - OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS, NULL), - OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL), - OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE, NULL), - OSSL_PARAM_END - }; + static OSSL_PARAM gettable[] =3D { OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS= , NULL), + OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURI= TY_BITS, NULL), + OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SI= ZE, NULL), + OSSL_PARAM_END }; return gettable; } @@ -472,14 +468,14 @@ /* only check params we understand and ignore the rest */ p =3D OSSL_PARAM_locate_const(params, "pubkey"); /*setting pubkey on o= ur keydata */ - if (p && p->data_type =3D=3D OSSL_PARAM_OCTET_STRING - && p->data_size =3D=3D sizeof(pkey)) + if (p && p->data_type =3D=3D OSSL_PARAM_OCTET_STRING && p->data_size = =3D=3D sizeof(pkey)) { pkey =3D *(EVP_PKEY **)p->data; ASSERT(pkey); int id =3D EVP_PKEY_get_id(pkey); - if (id !=3D EVP_PKEY_RSA && id !=3D EVP_PKEY_EC && id !=3D EVP_PKE= Y_ED25519 && id !=3D EVP_PKEY_ED448) + if (id !=3D EVP_PKEY_RSA && id !=3D EVP_PKEY_EC && id !=3D EVP_PKE= Y_ED25519 + && id !=3D EVP_PKEY_ED448) { msg(M_WARN, "Error: xkey keymgmt_import: unknown key type (%d)= ", id); return 0; @@ -494,8 +490,7 @@ } p =3D OSSL_PARAM_locate_const(params, "handle"); /*setting privkey */ - if (p && p->data_type =3D=3D OSSL_PARAM_OCTET_PTR - && p->data_size =3D=3D sizeof(key->handle)) + if (p && p->data_type =3D=3D OSSL_PARAM_OCTET_PTR && p->data_size =3D= =3D sizeof(key->handle)) { key->handle =3D *(void **)p->data; /* caller should keep the reference alive until we call free */ @@ -503,8 +498,7 @@ } p =3D OSSL_PARAM_locate_const(params, "sign_op"); /*setting sign_op */ - if (p && p->data_type =3D=3D OSSL_PARAM_OCTET_PTR - && p->data_size =3D=3D sizeof(key->sign)) + if (p && p->data_type =3D=3D OSSL_PARAM_OCTET_PTR && p->data_size =3D= =3D sizeof(key->sign)) { key->sign =3D *(void **)p->data; ASSERT(key->sign); /* fix your params array */ @@ -512,8 +506,7 @@ /* optional parameters */ p =3D OSSL_PARAM_locate_const(params, "free_op"); /*setting free_op */ - if (p && p->data_type =3D=3D OSSL_PARAM_OCTET_PTR - && p->data_size =3D=3D sizeof(key->free)) + if (p && p->data_type =3D=3D OSSL_PARAM_OCTET_PTR && p->data_size =3D= =3D sizeof(key->free)) { key->free =3D *(void **)p->data; } @@ -587,75 +580,80 @@ } static const OSSL_DISPATCH rsa_keymgmt_functions[] =3D { - {OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgmt_new}, - {OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free}, - {OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load}, - {OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has}, - {OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match}, - {OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))rsa_keymgmt_import}, - {OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types}, - {OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_p= arams}, - {OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params}, - {OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params}, - {OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_p= arams}, /* same as gettable */ - {OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME, (void (*)(void))rsa_keymgmt_n= ame}, - {0, NULL } + { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgmt_new }, + { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free }, + { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load }, + { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has }, + { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match }, + { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))rsa_keymgmt_import }, + { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types= }, + { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_= params }, + { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params }, + { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params }, + { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, + (void (*)(void))keymgmt_gettable_params }, /* same as gettable */ + { OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME, (void (*)(void))rsa_keymgmt_= name }, + { 0, NULL } }; static const OSSL_DISPATCH ec_keymgmt_functions[] =3D { - {OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgmt_new}, - {OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free}, - {OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load}, - {OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has}, - {OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match}, - {OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ec_keymgmt_import}, - {OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types}, - {OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_p= arams}, - {OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params}, - {OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params}, - {OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_p= arams}, /* same as gettable */ - {OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME, (void (*)(void))ec_keymgmt_na= me}, - {0, NULL } + { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgmt_new }, + { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free }, + { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load }, + { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has }, + { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match }, + { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ec_keymgmt_import }, + { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types= }, + { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_= params }, + { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params }, + { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params }, + { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, + (void (*)(void))keymgmt_gettable_params }, /* same as gettable */ + { OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME, (void (*)(void))ec_keymgmt_n= ame }, + { 0, NULL } }; static const OSSL_DISPATCH ed448_keymgmt_functions[] =3D { - {OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgmt_new}, - {OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free}, - {OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load}, - {OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has}, - {OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match}, - {OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ed448_keymgmt_import}, - {OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types}, - {OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_p= arams}, - {OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params}, - {OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params}, - {OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_p= arams}, /* same as gettable */ - {0, NULL } + { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgmt_new }, + { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free }, + { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load }, + { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has }, + { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match }, + { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ed448_keymgmt_import }, + { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types= }, + { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_= params }, + { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params }, + { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params }, + { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, + (void (*)(void))keymgmt_gettable_params }, /* same as gettable */ + { 0, NULL } }; static const OSSL_DISPATCH ed25519_keymgmt_functions[] =3D { - {OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgmt_new}, - {OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free}, - {OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load}, - {OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has}, - {OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match}, - {OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ed25519_keymgmt_import}, - {OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types}, - {OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_p= arams}, - {OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params}, - {OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params}, - {OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_p= arams}, /* same as gettable */ - {0, NULL } + { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgmt_new }, + { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free }, + { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load }, + { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has }, + { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match }, + { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ed25519_keymgmt_import }, + { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types= }, + { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_= params }, + { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params }, + { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params }, + { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, + (void (*)(void))keymgmt_gettable_params }, /* same as gettable */ + { 0, NULL } }; const OSSL_ALGORITHM keymgmts[] =3D { - {"RSA:rsaEncryption", XKEY_PROV_PROPS, rsa_keymgmt_functions, "OpenVPN= xkey RSA Key Manager"}, - {"RSA-PSS:RSASSA-PSS", XKEY_PROV_PROPS, rsa_keymgmt_functions, "OpenVP= N xkey RSA-PSS Key Manager"}, - {"EC:id-ecPublicKey", XKEY_PROV_PROPS, ec_keymgmt_functions, "OpenVPN = xkey EC Key Manager"}, - {"ED448", XKEY_PROV_PROPS, ed448_keymgmt_functions, "OpenVPN xkey ED44= 8 Key Manager"}, - {"ED25519", XKEY_PROV_PROPS, ed25519_keymgmt_functions, "OpenVPN xkey = ED25519 Key Manager"}, - {NULL, NULL, NULL, NULL} + { "RSA:rsaEncryption", XKEY_PROV_PROPS, rsa_keymgmt_functions, "OpenVP= N xkey RSA Key Manager" }, + { "RSA-PSS:RSASSA-PSS", XKEY_PROV_PROPS, rsa_keymgmt_functions, + "OpenVPN xkey RSA-PSS Key Manager" }, + { "EC:id-ecPublicKey", XKEY_PROV_PROPS, ec_keymgmt_functions, "OpenVPN= xkey EC Key Manager" }, + { "ED448", XKEY_PROV_PROPS, ed448_keymgmt_functions, "OpenVPN xkey ED4= 48 Key Manager" }, + { "ED25519", XKEY_PROV_PROPS, ed25519_keymgmt_functions, "OpenVPN xkey= ED25519 Key Manager" }, + { NULL, NULL, NULL, NULL } }; @@ -682,29 +680,39 @@ XKEY_SIGALG sigalg; } XKEY_SIGNATURE_CTX; -static const XKEY_SIGALG default_sigalg =3D { .mdname =3D "MD5-SHA1", .sal= tlen =3D "digest", - .padmode =3D "pkcs1", .keytype= =3D "RSA"}; +static const XKEY_SIGALG default_sigalg =3D { + .mdname =3D "MD5-SHA1", .saltlen =3D "digest", .padmode =3D "pkcs1", .= keytype =3D "RSA" +}; -const struct { +const struct +{ int nid; const char *name; -} digest_names[] =3D {{NID_md5_sha1, "MD5-SHA1"}, {NID_sha1, "SHA1"}, - {NID_sha224, "SHA224", }, {NID_sha256, "SHA256"}, {NID= _sha384, "SHA384"}, - {NID_sha512, "SHA512"}, {0, NULL}}; +} digest_names[] =3D { { NID_md5_sha1, "MD5-SHA1" }, + { NID_sha1, "SHA1" }, + { + NID_sha224, + "SHA224", + }, + { NID_sha256, "SHA256" }, + { NID_sha384, "SHA384" }, + { NID_sha512, "SHA512" }, + { 0, NULL } }; /* Use of NIDs as opposed to EVP_MD_fetch is okay here * as these are only used for converting names passed in * by OpenSSL to const strings. */ -static struct { +static struct +{ int id; const char *name; -} padmode_names[] =3D {{RSA_PKCS1_PADDING, "pkcs1"}, - {RSA_PKCS1_PSS_PADDING, "pss"}, - {RSA_NO_PADDING, "none"}, - {0, NULL}}; +} padmode_names[] =3D { { RSA_PKCS1_PADDING, "pkcs1" }, + { RSA_PKCS1_PSS_PADDING, "pss" }, + { RSA_NO_PADDING, "none" }, + { 0, NULL } }; -static const char *saltlen_names[] =3D {"digest", "max", "auto", NULL}; +static const char *saltlen_names[] =3D { "digest", "max", "auto", NULL }; /* Return a string literal for digest name - normalizes * alternate names like SHA2-256 to SHA256 etc. @@ -725,7 +733,7 @@ { i++; } - return digest_names[i].name ? digest_names[i].name : "MD5-SHA1"; + return digest_names[i].name ? digest_names[i].name : "MD5-SHA1"; } static void * @@ -733,7 +741,7 @@ { xkey_dmsg(D_XKEY, "entry"); - (void) propq; /* unused */ + (void)propq; /* unused */ XKEY_SIGNATURE_CTX *sctx =3D OPENSSL_zalloc(sizeof(*sctx)); if (!sctx) @@ -768,8 +776,7 @@ static OSSL_PARAM settable[] =3D { OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE, NULL, 0), OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0), - OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PSS_SALTLEN, NULL, 0), - OSSL_PARAM_END + OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PSS_SALTLEN, NULL, 0),= OSSL_PARAM_END }; return settable; @@ -785,7 +792,7 @@ if (params =3D=3D NULL) { - return 1; /* not an error */ + return 1; /* not an error */ } p =3D OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_PAD_MODE); if (p && p->data_type =3D=3D OSSL_PARAM_UTF8_STRING) @@ -801,8 +808,7 @@ } if (sctx->sigalg.padmode =3D=3D NULL) { - msg(M_WARN, "xkey signature_ctx: padmode <%s>, treating as ", - (char *)p->data); + msg(M_WARN, "xkey signature_ctx: padmode <%s>, treating as ", (char *)p->data); sctx->sigalg.padmode =3D "none"; } xkey_dmsg(D_XKEY, "setting padmode as %s", sctx->sigalg.padmode); @@ -835,7 +841,7 @@ } p =3D OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST); - if (p && p->data_type =3D=3D OSSL_PARAM_UTF8_STRING) + if (p && p->data_type =3D=3D OSSL_PARAM_UTF8_STRING) { sctx->sigalg.mdname =3D xkey_mdname(p->data); xkey_dmsg(D_XKEY, "setting hashalg as %s", sctx->sigalg.mdname); @@ -859,8 +865,7 @@ } if (sctx->sigalg.saltlen =3D=3D NULL) { - msg(M_WARN, "xkey_signature_params: unknown saltlen <%s>", - (char *)p->data); + msg(M_WARN, "xkey_signature_params: unknown saltlen <%s>", (ch= ar *)p->data); sctx->sigalg.saltlen =3D "digest"; /* most common */ } xkey_dmsg(D_XKEY, "setting saltlen to %s", sctx->sigalg.saltlen); @@ -925,7 +930,8 @@ else if (sign) { ret =3D sign(sctx->keydata->handle, sig, siglen, tbs, tbslen, sctx= ->sigalg); - xkey_dmsg(D_XKEY, "xkey_provider: external sign op returned ret = =3D %d siglen =3D %d", ret, (int) *siglen); + xkey_dmsg(D_XKEY, "xkey_provider: external sign op returned ret = =3D %d siglen =3D %d", ret, + (int)*siglen); } else { @@ -980,8 +986,7 @@ } static int -signature_digest_sign_init(void *ctx, const char *mdname, - void *provkey, const OSSL_PARAM params[]) +signature_digest_sign_init(void *ctx, const char *mdname, void *provkey, c= onst OSSL_PARAM params[]) { xkey_dmsg(D_XKEY, "mdname =3D <%s>", mdname); @@ -1023,8 +1028,8 @@ } static int -signature_digest_sign(void *ctx, unsigned char *sig, size_t *siglen, - size_t sigsize, const unsigned char *tbs, size_t tbs= len) +signature_digest_sign(void *ctx, unsigned char *sig, size_t *siglen, size_= t sigsize, + const unsigned char *tbs, size_t tbslen) { xkey_dmsg(D_XKEY, "entry"); @@ -1073,8 +1078,8 @@ /* Sign digest using native sign function -- will only work for native keys */ int -xkey_native_sign(XKEY_KEYDATA *key, unsigned char *sig, size_t *siglen, - const unsigned char *tbs, size_t tbslen, XKEY_SIGALG siga= lg) +xkey_native_sign(XKEY_KEYDATA *key, unsigned char *sig, size_t *siglen, co= nst unsigned char *tbs, + size_t tbslen, XKEY_SIGALG sigalg) { xkey_dmsg(D_XKEY, "entry"); @@ -1101,13 +1106,17 @@ OSSL_PARAM params[6]; if (EVP_PKEY_get_id(pkey) =3D=3D EVP_PKEY_RSA) { - params[i++] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PA= RAM_DIGEST, (char *)mdname, 0); - params[i++] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PA= RAM_PAD_MODE, (char *)padmode, 0); + params[i++] =3D + OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, = (char *)mdname, 0); + params[i++] =3D + OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE= , (char *)padmode, 0); if (!strcmp(sigalg.padmode, "pss")) { - params[i++] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATUR= E_PARAM_PSS_SALTLEN, (char *) saltlen, 0); + params[i++] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATUR= E_PARAM_PSS_SALTLEN, + (char *)saltlen= , 0); /* same digest for mgf1 */ - params[i++] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATUR= E_PARAM_MGF1_DIGEST, (char *) mdname, 0); + params[i++] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATUR= E_PARAM_MGF1_DIGEST, + (char *)mdname,= 0); } } params[i++] =3D OSSL_PARAM_construct_end(); @@ -1134,27 +1143,27 @@ } static const OSSL_DISPATCH signature_functions[] =3D { - {OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))signature_newctx}, - {OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))signature_freectx}, - {OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))signature_sign_init}, - {OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))signature_sign}, - {OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, (void (*)(void))signature_dig= est_verify_init}, - {OSSL_FUNC_SIGNATURE_DIGEST_VERIFY, (void (*)(void))signature_digest_v= erify}, - {OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, (void (*)(void))signature_diges= t_sign_init}, - {OSSL_FUNC_SIGNATURE_DIGEST_SIGN, (void (*)(void))signature_digest_sig= n}, - {OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))signature_set_ctx= _params}, - {OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, (void (*)(void))signature_se= ttable_ctx_params}, - {OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))signature_get_ctx= _params}, - {OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, (void (*)(void))signature_ge= ttable_ctx_params}, - {0, NULL } + { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))signature_newctx }, + { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))signature_freectx }, + { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))signature_sign_init }, + { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))signature_sign }, + { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, (void (*)(void))signature_di= gest_verify_init }, + { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY, (void (*)(void))signature_digest_= verify }, + { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, (void (*)(void))signature_dige= st_sign_init }, + { OSSL_FUNC_SIGNATURE_DIGEST_SIGN, (void (*)(void))signature_digest_si= gn }, + { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))signature_set_ct= x_params }, + { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, (void (*)(void))signature_s= ettable_ctx_params }, + { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))signature_get_ct= x_params }, + { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, (void (*)(void))signature_g= ettable_ctx_params }, + { 0, NULL } }; const OSSL_ALGORITHM signatures[] =3D { - {"RSA:rsaEncryption", XKEY_PROV_PROPS, signature_functions, "OpenVPN x= key RSA Signature"}, - {"ECDSA", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey ECDSA Si= gnature"}, - {"ED448", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey Ed448 Si= gnature"}, - {"ED25519", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey Ed2551= 9 Signature"}, - {NULL, NULL, NULL, NULL} + { "RSA:rsaEncryption", XKEY_PROV_PROPS, signature_functions, "OpenVPN = xkey RSA Signature" }, + { "ECDSA", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey ECDSA S= ignature" }, + { "ED448", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey Ed448 S= ignature" }, + { "ED25519", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey Ed255= 19 Signature" }, + { NULL, NULL, NULL, NULL } }; /* main provider interface */ @@ -1193,8 +1202,7 @@ xkey_dmsg(D_XKEY, "entry"); static const OSSL_PARAM param_types[] =3D { - OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0= ), - OSSL_PARAM_END + OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0= ), OSSL_PARAM_END }; =20 return param_types; @@ -1229,11 +1237,11 @@ } static const OSSL_DISPATCH dispatch_table[] =3D { - {OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))gettable_params}, - {OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))get_params}, - {OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))query_operation}, - {OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))teardown}, - {0, NULL} + { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))gettable_params = }, + { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))get_params }, + { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))query_operation = }, + { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))teardown }, + { 0, NULL } }; int diff --git a/src/openvpnmsica/dllmain.c b/src/openvpnmsica/dllmain.c index 6f14a5c..242b804 100644 --- a/src/openvpnmsica/dllmain.c +++ b/src/openvpnmsica/dllmain.c @@ -42,10 +42,7 @@ * DLL entry point */ BOOL WINAPI -DllMain( - _In_ HINSTANCE hinstDLL, - _In_ DWORD dwReason, - _In_ LPVOID lpReserved) +DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD dwReason, _In_ LPVOID lpReserv= ed) { UNREFERENCED_PARAMETER(hinstDLL); UNREFERENCED_PARAMETER(lpReserved); @@ -59,12 +56,13 @@ { return FALSE; } - /* Fall through. */ + /* Fall through. */ case DLL_THREAD_ATTACH: { /* Create thread local storage data. */ - struct openvpnmsica_thread_data *s =3D (struct openvpnmsica_th= read_data *)calloc(1, sizeof(struct openvpnmsica_thread_data)); + struct openvpnmsica_thread_data *s =3D (struct openvpnmsica_th= read_data *)calloc( + 1, sizeof(struct openvpnmsica_thread_data)); if (s =3D=3D NULL) { return FALSE; @@ -108,7 +106,8 @@ /* Secure last error before it is overridden. */ DWORD dwResult =3D (flags & M_ERRNO) !=3D 0 ? GetLastError() : ERROR_S= UCCESS; - struct openvpnmsica_thread_data *s =3D (struct openvpnmsica_thread_dat= a *)TlsGetValue(openvpnmsica_thread_data_idx); + struct openvpnmsica_thread_data *s =3D + (struct openvpnmsica_thread_data *)TlsGetValue(openvpnmsica_thread= _data_idx); if (s->hInstall =3D=3D 0) { /* No MSI session, no fun. */ @@ -161,16 +160,13 @@ /* Field 4: The Windows error description. */ LPWSTR szErrMessage =3D NULL; - if (FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFE= R | FORMAT_MESSAGE_IGNORE_INSERTS, - 0, - dwResult, - 0, - (LPWSTR)&szErrMessage, - 0, - NULL) && szErrMessage) + if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLO= CATE_BUFFER + | FORMAT_MESSAGE_IGNORE_INSERTS, + 0, dwResult, 0, (LPWSTR)&szErrMessage, 0, NULL) + && szErrMessage) { - /* Trim trailing whitespace. Set terminator after the last non= -whitespace character. This prevents excessive trailing line breaks. */ + /* Trim trailing whitespace. Set terminator after the last non= -whitespace character. + * This prevents excessive trailing line breaks. */ for (size_t i =3D 0, i_last =3D 0;; i++) { if (szErrMessage[i]) @@ -191,6 +187,7 @@ } } - MsiProcessMessage(s->hInstall, (flags & M_WARN) ? INSTALLMESSAGE_INFO = : INSTALLMESSAGE_ERROR, hRecordProg); + MsiProcessMessage(s->hInstall, (flags & M_WARN) ? INSTALLMESSAGE_INFO = : INSTALLMESSAGE_ERROR, + hRecordProg); MsiCloseHandle(hRecordProg); } diff --git a/src/openvpnmsica/msica_arg.c b/src/openvpnmsica/msica_arg.c index 0f5b2fb..2f1bbba 100644 --- a/src/openvpnmsica/msica_arg.c +++ b/src/openvpnmsica/msica_arg.c @@ -52,15 +52,14 @@ void -msica_arg_seq_add_head( - _Inout_ struct msica_arg_seq *seq, - _In_z_ LPCWSTR argument) +msica_arg_seq_add_head(_Inout_ struct msica_arg_seq *seq, _In_z_ LPCWSTR a= rgument) { size_t argument_size =3D (wcslen(argument) + 1) * sizeof(WCHAR); struct msica_arg *p =3D malloc(sizeof(struct msica_arg) + argument_siz= e); if (p =3D=3D NULL) { - msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, sizeof(struct = msica_arg) + argument_size); + msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, + sizeof(struct msica_arg) + argument_size); } memcpy(p->val, argument, argument_size); p->next =3D seq->head; @@ -73,15 +72,14 @@ void -msica_arg_seq_add_tail( - _Inout_ struct msica_arg_seq *seq, - _Inout_ LPCWSTR argument) +msica_arg_seq_add_tail(_Inout_ struct msica_arg_seq *seq, _Inout_ LPCWSTR = argument) { size_t argument_size =3D (wcslen(argument) + 1) * sizeof(WCHAR); struct msica_arg *p =3D malloc(sizeof(struct msica_arg) + argument_siz= e); if (p =3D=3D NULL) { - msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, sizeof(struct = msica_arg) + argument_size); + msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, + sizeof(struct msica_arg) + argument_size); } memcpy(p->val, argument, argument_size); p->next =3D NULL; @@ -111,10 +109,13 @@ #ifdef _MSC_VER #pragma warning(push) -#pragma warning(disable: 4996) /* Using unsafe string functions: The space= in s and termination of p->val has been implicitly verified at the beginni= ng of this function. */ +#pragma warning( = \ + disable : 4996) /* Using unsafe string functions: The space in s and t= ermination of p->val has \ + been implicitly verified at the beginning of this f= unction. */ #endif - /* Dummy argv[0] (i.e. executable name), for CommandLineToArgvW to wor= k correctly when parsing this string. */ + /* Dummy argv[0] (i.e. executable name), for CommandLineToArgvW to wor= k correctly when parsing + * this string. */ wcscpy(str, L"x"); /* Join. */ diff --git a/src/openvpnmsica/msica_arg.h b/src/openvpnmsica/msica_arg.h index 2a3e931..67bddde 100644 --- a/src/openvpnmsica/msica_arg.h +++ b/src/openvpnmsica/msica_arg.h @@ -28,7 +28,7 @@ #ifdef _MSC_VER #pragma warning(push) -#pragma warning(disable: 4200) /* Using zero-sized arrays in struct/union.= */ +#pragma warning(disable : 4200) /* Using zero-sized arrays in struct/union= . */ #endif =20 @@ -57,8 +57,7 @@ * * @param seq Pointer to uninitialized argument sequence */ -void -msica_arg_seq_init(_Inout_ struct msica_arg_seq *seq); +void msica_arg_seq_init(_Inout_ struct msica_arg_seq *seq); /** @@ -66,8 +65,7 @@ * * @param seq Pointer to the argument sequence */ -void -msica_arg_seq_free(_Inout_ struct msica_arg_seq *seq); +void msica_arg_seq_free(_Inout_ struct msica_arg_seq *seq); /** @@ -77,10 +75,7 @@ * * @param argument Zero-terminated argument string to insert. */ -void -msica_arg_seq_add_head( - _Inout_ struct msica_arg_seq *seq, - _In_z_ LPCWSTR argument); +void msica_arg_seq_add_head(_Inout_ struct msica_arg_seq *seq, _In_z_ LPCW= STR argument); /** @@ -90,10 +85,7 @@ * * @param argument Zero-terminated argument string to append. */ -void -msica_arg_seq_add_tail( - _Inout_ struct msica_arg_seq *seq, - _Inout_ LPCWSTR argument); +void msica_arg_seq_add_tail(_Inout_ struct msica_arg_seq *seq, _Inout_ LPC= WSTR argument); /** * Join arguments of the argument sequence into a space delimited string diff --git a/src/openvpnmsica/msiex.c b/src/openvpnmsica/msiex.c index c0f5853..ddf078f 100644 --- a/src/openvpnmsica/msiex.c +++ b/src/openvpnmsica/msiex.c @@ -35,10 +35,7 @@ UINT -msi_get_string( - _In_ MSIHANDLE hInstall, - _In_z_ LPCWSTR szName, - _Out_ LPWSTR *pszValue) +msi_get_string(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Out_ LPWST= R *pszValue) { if (pszValue =3D=3D NULL) { @@ -85,7 +82,8 @@ } else { - SetLastError(uiResult); /* MSDN does not mention MsiGetProperty() = to set GetLastError(). But we do have an error code. Set last error manuall= y. */ + SetLastError(uiResult); /* MSDN does not mention MsiGetProperty() = to set GetLastError(). But + we do have an error code. Set last erro= r manually. */ msg(M_NONFATAL | M_ERRNO, "%s: MsiGetProperty failed", __FUNCTION_= _); return uiResult; } @@ -93,10 +91,7 @@ UINT -msi_get_record_string( - _In_ MSIHANDLE hRecord, - _In_ unsigned int iField, - _Out_ LPWSTR *pszValue) +msi_get_record_string(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _O= ut_ LPWSTR *pszValue) { if (pszValue =3D=3D NULL) { @@ -143,7 +138,8 @@ } else { - SetLastError(uiResult); /* MSDN does not mention MsiRecordGetStrin= g() to set GetLastError(). But we do have an error code. Set last error man= ually. */ + SetLastError(uiResult); /* MSDN does not mention MsiRecordGetStrin= g() to set GetLastError(). + But we do have an error code. Set last = error manually. */ msg(M_NONFATAL | M_ERRNO, "%s: MsiRecordGetString failed", __FUNCT= ION__); return uiResult; } @@ -151,10 +147,7 @@ UINT -msi_format_record( - _In_ MSIHANDLE hInstall, - _In_ MSIHANDLE hRecord, - _Out_ LPWSTR *pszValue) +msi_format_record(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Out_ L= PWSTR *pszValue) { if (pszValue =3D=3D NULL) { @@ -201,7 +194,8 @@ } else { - SetLastError(uiResult); /* MSDN does not mention MsiFormatRecord()= to set GetLastError(). But we do have an error code. Set last error manual= ly. */ + SetLastError(uiResult); /* MSDN does not mention MsiFormatRecord()= to set GetLastError(). + But we do have an error code. Set last = error manually. */ msg(M_NONFATAL | M_ERRNO, "%s: MsiFormatRecord failed", __FUNCTION= __); return uiResult; } @@ -209,11 +203,8 @@ UINT -msi_format_field( - _In_ MSIHANDLE hInstall, - _In_ MSIHANDLE hRecord, - _In_ unsigned int iField, - _Out_ LPWSTR *pszValue) +msi_format_field(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _In_ uns= igned int iField, + _Out_ LPWSTR *pszValue) { if (pszValue =3D=3D NULL) { @@ -247,7 +238,8 @@ uiResult =3D MsiRecordSetString(hRecordEx, 0, szValue); if (uiResult !=3D ERROR_SUCCESS) { - SetLastError(uiResult); /* MSDN does not mention MsiRecordSetStrin= g() to set GetLastError(). But we do have an error code. Set last error man= ually. */ + SetLastError(uiResult); /* MSDN does not mention MsiRecordSetStrin= g() to set GetLastError(). + But we do have an error code. Set last = error manually. */ msg(M_NONFATAL | M_ERRNO, "%s: MsiRecordSetString failed", __FUNCT= ION__); goto cleanup_hRecordEx; } diff --git a/src/openvpnmsica/msiex.h b/src/openvpnmsica/msiex.h index ab029cc..3fb1b90 100644 --- a/src/openvpnmsica/msiex.h +++ b/src/openvpnmsica/msiex.h @@ -38,11 +38,7 @@ * * @return ERROR_SUCCESS on success; Win32 error code otherwise */ -UINT -msi_get_string( - _In_ MSIHANDLE hInstall, - _In_z_ LPCWSTR szName, - _Out_ LPWSTR *pszValue); +UINT msi_get_string(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Out_ = LPWSTR *pszValue); =20 /** @@ -57,11 +53,8 @@ * * @return ERROR_SUCCESS on success; Win32 error code otherwise */ -UINT -msi_get_record_string( - _In_ MSIHANDLE hRecord, - _In_ unsigned int iField, - _Out_ LPWSTR *pszValue); +UINT msi_get_record_string(_In_ MSIHANDLE hRecord, _In_ unsigned int iFiel= d, + _Out_ LPWSTR *pszValue); /** @@ -79,11 +72,7 @@ * * @return ERROR_SUCCESS on success; Win32 error code otherwise */ -UINT -msi_format_record( - _In_ MSIHANDLE hInstall, - _In_ MSIHANDLE hRecord, - _Out_ LPWSTR *pszValue); +UINT msi_format_record(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _O= ut_ LPWSTR *pszValue); /** @@ -102,11 +91,7 @@ * * @return ERROR_SUCCESS on success; Win32 error code otherwise */ -UINT -msi_format_field( - _In_ MSIHANDLE hInstall, - _In_ MSIHANDLE hRecord, - _In_ unsigned int iField, - _Out_ LPWSTR *pszValue); +UINT msi_format_field(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _In= _ unsigned int iField, + _Out_ LPWSTR *pszValue); #endif /* ifndef MSIHLP_H */ diff --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsic= a.c index 003da6e..188f6bc 100644 --- a/src/openvpnmsica/openvpnmsica.c +++ b/src/openvpnmsica/openvpnmsica.c @@ -60,9 +60,9 @@ */ /** Amount of tick space to reserve for one TAP/TUN adapter creation/delet= ition. */ -#define MSICA_ADAPTER_TICK_SIZE (16 * 1024) +#define MSICA_ADAPTER_TICK_SIZE (16 * 1024) -#define FILE_NEED_REBOOT L".ovpn_need_reboot" +#define FILE_NEED_REBOOT L".ovpn_need_reboot" #define OPENVPN_CONNECT_ADAPTER_SUBSTR L"OpenVPN Connect" @@ -78,10 +78,7 @@ * @return ERROR_SUCCESS on success; An error code otherwise */ static UINT -setup_sequence( - _In_ MSIHANDLE hInstall, - _In_z_ LPCWSTR szProperty, - _In_ struct msica_arg_seq *seq) +setup_sequence(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szProperty, _In_ st= ruct msica_arg_seq *seq) { UINT uiResult; LPWSTR szSequence =3D msica_arg_seq_join(seq); @@ -111,12 +108,11 @@ static void _debug_popup(_In_z_ LPCSTR szFunctionName) { - WCHAR szTitle[0x100], szMessage[0x100+MAX_PATH], szProcessPath[MAX_PAT= H]; + WCHAR szTitle[0x100], szMessage[0x100 + MAX_PATH], szProcessPath[MAX_P= ATH]; /* Compose pop-up title. The dialog title will contain function name t= o ease the process * locating. Mind that Visual Studio displays window titles on the pro= cess list. */ - swprintf_s(szTitle, _countof(szTitle), L"%hs v%ls", - szFunctionName, _L(PACKAGE_VERSION)); + swprintf_s(szTitle, _countof(szTitle), L"%hs v%ls", szFunctionName, _L= (PACKAGE_VERSION)); /* Get process name. */ GetModuleFileName(NULL, szProcessPath, _countof(szProcessPath)); @@ -132,9 +128,7 @@ L"If you would like to debug the custom action, attach a debugger = to this process and set breakpoints before dismissing this dialog.\r\n" L"\r\n" L"If you are not debugging this custom action, you can safely igno= re this message.", - szProcessName, - GetCurrentProcessId(), - szFunctionName); + szProcessName, GetCurrentProcessId(), szFunctionName); MessageBox(NULL, szMessage, szTitle, MB_OK); } @@ -145,11 +139,8 @@ #endif /* ifdef _DEBUG */ static void -find_adapters( - _In_ MSIHANDLE hInstall, - _In_z_ LPCWSTR szzHardwareIDs, - _In_z_ LPCWSTR szAdaptersPropertyName, - _In_z_ LPCWSTR szActiveAdaptersPropertyName) +find_adapters(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szzHardwareIDs, + _In_z_ LPCWSTR szAdaptersPropertyName, _In_z_ LPCWSTR szActi= veAdaptersPropertyName) { UINT uiResult; @@ -166,24 +157,26 @@ return; } - /* Get IPv4/v6 info for all network adapters. Actually, we're interest= ed in link status only: up/down? */ + /* Get IPv4/v6 info for all network adapters. Actually, we're interest= ed in link status only: + * up/down? */ PIP_ADAPTER_ADDRESSES pAdapterAdresses =3D NULL; - ULONG ulAdapterAdressesSize =3D 16*1024; + ULONG ulAdapterAdressesSize =3D 16 * 1024; for (size_t iteration =3D 0; iteration < 2; iteration++) { pAdapterAdresses =3D (PIP_ADAPTER_ADDRESSES)malloc(ulAdapterAdress= esSize); if (pAdapterAdresses =3D=3D NULL) { msg(M_NONFATAL, "%s: malloc(%u) failed", __FUNCTION__, ulAdapt= erAdressesSize); - uiResult =3D ERROR_OUTOFMEMORY; goto cleanup_pAdapterList; + uiResult =3D ERROR_OUTOFMEMORY; + goto cleanup_pAdapterList; } ULONG ulResult =3D GetAdaptersAddresses( AF_UNSPEC, - GAA_FLAG_SKIP_UNICAST | GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_= MULTICAST | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME | GAA_FL= AG_INCLUDE_ALL_INTERFACES, - NULL, - pAdapterAdresses, - &ulAdapterAdressesSize); + GAA_FLAG_SKIP_UNICAST | GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_= MULTICAST + | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME + | GAA_FLAG_INCLUDE_ALL_INTERFACES, + NULL, pAdapterAdresses, &ulAdapterAdressesSize); if (ulResult =3D=3D ERROR_SUCCESS) { @@ -193,9 +186,12 @@ free(pAdapterAdresses); if (ulResult !=3D ERROR_BUFFER_OVERFLOW) { - SetLastError(ulResult); /* MSDN does not mention GetAdaptersAd= dresses() to set GetLastError(). But we do have an error code. Set last err= or manually. */ + SetLastError( + ulResult); /* MSDN does not mention GetAdaptersAddresses()= to set GetLastError(). + But we do have an error code. Set last error= manually. */ msg(M_NONFATAL | M_ERRNO, "%s: GetAdaptersAddresses() failed",= __FUNCTION__); - uiResult =3D ulResult; goto cleanup_pAdapterList; + uiResult =3D ulResult; + goto cleanup_pAdapterList; } } @@ -208,26 +204,33 @@ /* Prepare semicolon delimited list of TAP adapter ID(s) and active TA= P adapter ID(s). */ LPWSTR - szAdapters =3D (LPWSTR)malloc(adapter_count * (38 /*GUID*/ + 1= /*separator/terminator*/) * sizeof(WCHAR)), - szAdaptersTail =3D szAdapters; + szAdapters =3D + (LPWSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/termin= ator*/) * sizeof(WCHAR)), + szAdaptersTail =3D szAdapters; if (szAdapters =3D=3D NULL) { - msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count = * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR)); - uiResult =3D ERROR_OUTOFMEMORY; goto cleanup_pAdapterAdresses; + msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, + adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * s= izeof(WCHAR)); + uiResult =3D ERROR_OUTOFMEMORY; + goto cleanup_pAdapterAdresses; } LPWSTR - szAdaptersActive =3D (LPWSTR)malloc(adapter_count * (38 /*GUID= */ + 1 /*separator/terminator*/) * sizeof(WCHAR)), - szAdaptersActiveTail =3D szAdaptersActive; + szAdaptersActive =3D + (LPWSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/termin= ator*/) * sizeof(WCHAR)), + szAdaptersActiveTail =3D szAdaptersActive; if (szAdaptersActive =3D=3D NULL) { - msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count = * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR)); - uiResult =3D ERROR_OUTOFMEMORY; goto cleanup_szAdapters; + msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, + adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * s= izeof(WCHAR)); + uiResult =3D ERROR_OUTOFMEMORY; + goto cleanup_szAdapters; } for (struct tap_adapter_node *pAdapter =3D pAdapterList; pAdapter; pAd= apter =3D pAdapter->pNext) { - /* exclude adapters created by OpenVPN Connect, since they're remo= ved on Connect uninstallation */ + /* exclude adapters created by OpenVPN Connect, since they're remo= ved on Connect + * uninstallation */ if (wcsstr(pAdapter->szName, OPENVPN_CONNECT_ADAPTER_SUBSTR)) { msg(M_WARN, "%s: skip OpenVPN Connect adapter '%ls'", __FUNCTI= ON__, pAdapter->szName); @@ -251,7 +254,9 @@ { OLECHAR szId[38 /*GUID*/ + 1 /*terminator*/]; GUID guid; - if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, p->AdapterName= , -1, szId, _countof(szId)) > 0 + if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, p->AdapterName= , -1, szId, + _countof(szId)) + > 0 && SUCCEEDED(IIDFromString(szId, &guid)) && memcmp(&guid, &pAdapter->guid, sizeof(GUID)) =3D=3D 0) { @@ -270,22 +275,26 @@ } CoTaskMemFree(szAdapterId); } - szAdaptersTail [0] =3D 0; + szAdaptersTail[0] =3D 0; szAdaptersActiveTail[0] =3D 0; /* Set Installer properties. */ uiResult =3D MsiSetProperty(hInstall, szAdaptersPropertyName, szAdapte= rs); if (uiResult !=3D ERROR_SUCCESS) { - SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() = to set GetLastError(). But we do have an error code. Set last error manuall= y. */ - msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"%s\") failed", __F= UNCTION__, szAdaptersPropertyName); + SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() = to set GetLastError(). But + we do have an error code. Set last erro= r manually. */ + msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"%s\") failed", __F= UNCTION__, + szAdaptersPropertyName); goto cleanup_szAdaptersActive; } uiResult =3D MsiSetProperty(hInstall, szActiveAdaptersPropertyName, sz= AdaptersActive); if (uiResult !=3D ERROR_SUCCESS) { - SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() = to set GetLastError(). But we do have an error code. Set last error manuall= y. */ - msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"%s\") failed", __F= UNCTION__, szActiveAdaptersPropertyName); + SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() = to set GetLastError(). But + we do have an error code. Set last erro= r manually. */ + msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"%s\") failed", __F= UNCTION__, + szActiveAdaptersPropertyName); goto cleanup_szAdaptersActive; } @@ -300,8 +309,7 @@ } -UINT __stdcall -FindSystemInfo(_In_ MSIHANDLE hInstall) +UINT __stdcall FindSystemInfo(_In_ MSIHANDLE hInstall) { #ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) @@ -313,16 +321,12 @@ OPENVPNMSICA_SAVE_MSI_SESSION(hInstall); - find_adapters( - hInstall, - L"root\\" _L(TAP_WIN_COMPONENT_ID) L"\0" _L(TAP_WIN_COMPONENT_ID) = L"\0", - L"TAPWINDOWS6ADAPTERS", - L"ACTIVETAPWINDOWS6ADAPTERS"); - find_adapters( - hInstall, - L"ovpn-dco" L"\0", - L"OVPNDCOADAPTERS", - L"ACTIVEOVPNDCOADAPTERS"); + find_adapters(hInstall, L"root\\" _L(TAP_WIN_COMPONENT_ID) L"\0" _L(TA= P_WIN_COMPONENT_ID) L"\0", + L"TAPWINDOWS6ADAPTERS", L"ACTIVETAPWINDOWS6ADAPTERS"); + find_adapters(hInstall, + L"ovpn-dco" + L"\0", + L"OVPNDCOADAPTERS", L"ACTIVEOVPNDCOADAPTERS"); if (bIsCoInitialized) { @@ -332,13 +336,13 @@ } -UINT __stdcall -CloseOpenVPNGUI(_In_ MSIHANDLE hInstall) +UINT __stdcall CloseOpenVPNGUI(_In_ MSIHANDLE hInstall) { #ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) #endif - UNREFERENCED_PARAMETER(hInstall); /* This CA is does not interact with= MSI session (report errors, access properties, tables, etc.). */ + UNREFERENCED_PARAMETER(hInstall); /* This CA is does not interact with= MSI session (report + errors, access properties, tables= , etc.). */ debug_popup(__FUNCTION__); @@ -346,7 +350,8 @@ HWND hWnd =3D FindWindow(L"OpenVPN-GUI", NULL); if (hWnd) { - /* Ask it to close and wait for 100ms. Unfortunately, this will su= cceed only for recent OpenVPN GUI that do not run elevated. */ + /* Ask it to close and wait for 100ms. Unfortunately, this will su= cceed only for recent + * OpenVPN GUI that do not run elevated. */ SendMessage(hWnd, WM_CLOSE, 0, 0); Sleep(100); } @@ -355,8 +360,7 @@ } -UINT __stdcall -StartOpenVPNGUI(_In_ MSIHANDLE hInstall) +UINT __stdcall StartOpenVPNGUI(_In_ MSIHANDLE hInstall) { #ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) @@ -380,7 +384,8 @@ uiResult =3D MsiRecordSetString(hRecord, 0, L"\"[#bin.openvpn_gui.exe]= \""); if (uiResult !=3D ERROR_SUCCESS) { - SetLastError(uiResult); /* MSDN does not mention MsiRecordSetStrin= g() to set GetLastError(). But we do have an error code. Set last error man= ually. */ + SetLastError(uiResult); /* MSDN does not mention MsiRecordSetStrin= g() to set GetLastError(). + But we do have an error code. Set last = error manually. */ msg(M_NONFATAL | M_ERRNO, "%s: MsiRecordSetString failed", __FUNCT= ION__); goto cleanup_MsiCreateRecord; } @@ -397,25 +402,26 @@ if (szPath =3D=3D NULL) { msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, dwPathSize= * sizeof(WCHAR)); - uiResult =3D ERROR_OUTOFMEMORY; goto cleanup_MsiCreateRecord; + uiResult =3D ERROR_OUTOFMEMORY; + goto cleanup_MsiCreateRecord; } uiResult =3D MsiFormatRecord(hInstall, hRecord, szPath, &dwPathSiz= e); } if (uiResult !=3D ERROR_SUCCESS) { - SetLastError(uiResult); /* MSDN does not mention MsiFormatRecord()= to set GetLastError(). But we do have an error code. Set last error manual= ly. */ + SetLastError(uiResult); /* MSDN does not mention MsiFormatRecord()= to set GetLastError(). + But we do have an error code. Set last = error manually. */ msg(M_NONFATAL | M_ERRNO, "%s: MsiFormatRecord failed", __FUNCTION= __); goto cleanup_malloc_szPath; } /* Launch the OpenVPN GUI. */ - SHELLEXECUTEINFO sei =3D { - .cbSize =3D sizeof(SHELLEXECUTEINFO), - .fMask =3D SEE_MASK_FLAG_NO_UI, /* Don't show error UI, we'll dis= play it. */ - .lpFile =3D szPath, - .nShow =3D SW_SHOWNORMAL - }; + SHELLEXECUTEINFO sei =3D { .cbSize =3D sizeof(SHELLEXECUTEINFO), + .fMask =3D + SEE_MASK_FLAG_NO_UI, /* Don't show error = UI, we'll display it. */ + .lpFile =3D szPath, + .nShow =3D SW_SHOWNORMAL }; if (!ShellExecuteEx(&sei)) { uiResult =3D GetLastError(); @@ -462,12 +468,9 @@ * @return ERROR_SUCCESS on success; An error code otherwise */ static DWORD -schedule_adapter_create( - _Inout_ struct msica_arg_seq *seq, - _Inout_opt_ struct msica_arg_seq *seqRollback, - _In_z_ LPCWSTR szDisplayName, - _In_z_ LPCWSTR szHardwareId, - _Inout_ int *iTicks) +schedule_adapter_create(_Inout_ struct msica_arg_seq *seq, + _Inout_opt_ struct msica_arg_seq *seqRollback, _In= _z_ LPCWSTR szDisplayName, + _In_z_ LPCWSTR szHardwareId, _Inout_ int *iTicks) { /* Get existing network adapters. */ struct tap_adapter_node *pAdapterList =3D NULL; @@ -478,28 +481,25 @@ } /* Does adapter exist? */ - for (struct tap_adapter_node *pAdapterOther =3D pAdapterList;; pAdapte= rOther =3D pAdapterOther->pNext) + for (struct tap_adapter_node *pAdapterOther =3D pAdapterList;; + pAdapterOther =3D pAdapterOther->pNext) { if (pAdapterOther =3D=3D NULL) { /* No adapter with a same name found. */ - WCHAR szArgument[10 /*create=3D""|deleteN=3D""*/ + MAX_PATH /*= szDisplayName*/ + 1 /*|*/ + MAX_PATH /*szHardwareId*/ + 1 /*terminator*/]; + WCHAR szArgument[10 /*create=3D""|deleteN=3D""*/ + MAX_PATH /*= szDisplayName*/ + 1 /*|*/ + + MAX_PATH /*szHardwareId*/ + 1 /*terminator*= /]; /* InstallTUNTAPAdapters will create the adapter. */ - swprintf_s( - szArgument, _countof(szArgument), - L"create=3D\"%.*s|%.*s\"", - MAX_PATH, szDisplayName, - MAX_PATH, szHardwareId); + swprintf_s(szArgument, _countof(szArgument), L"create=3D\"%.*s= |%.*s\"", MAX_PATH, + szDisplayName, MAX_PATH, szHardwareId); msica_arg_seq_add_tail(seq, szArgument); if (seqRollback) { /* InstallTUNTAPAdaptersRollback will delete the adapter. = */ - swprintf_s( - szArgument, _countof(szArgument), - L"deleteN=3D\"%.*s\"", - MAX_PATH, szDisplayName); + swprintf_s(szArgument, _countof(szArgument), L"deleteN=3D\= "%.*s\"", MAX_PATH, + szDisplayName); msica_arg_seq_add_head(seqRollback, szArgument); } @@ -514,13 +514,15 @@ if (hwid[0] =3D=3D 0) { /* This adapter has a different hardware ID. */ - msg(M_NONFATAL, "%s: Adapter with name \"%ls\" already= exists", __FUNCTION__, pAdapterOther->szName); + msg(M_NONFATAL, "%s: Adapter with name \"%ls\" already= exists", __FUNCTION__, + pAdapterOther->szName); dwResult =3D ERROR_ALREADY_EXISTS; goto cleanup_pAdapterList; } else if (wcsicmp(hwid, szHardwareId) =3D=3D 0) { - /* This is an adapter with the requested hardware ID. = We already have what we want! */ + /* This is an adapter with the requested hardware ID. = We already have what we + * want! */ break; } } @@ -562,13 +564,10 @@ * @return ERROR_SUCCESS on success; An error code otherwise */ static DWORD -schedule_adapter_delete( - _Inout_ struct msica_arg_seq *seq, - _Inout_opt_ struct msica_arg_seq *seqCommit, - _Inout_opt_ struct msica_arg_seq *seqRollback, - _In_z_ LPCWSTR szDisplayName, - _In_z_ LPCWSTR szzHardwareIDs, - _Inout_ int *iTicks) +schedule_adapter_delete(_Inout_ struct msica_arg_seq *seq, + _Inout_opt_ struct msica_arg_seq *seqCommit, + _Inout_opt_ struct msica_arg_seq *seqRollback, _In= _z_ LPCWSTR szDisplayName, + _In_z_ LPCWSTR szzHardwareIDs, _Inout_ int *iTicks) { /* Get adapters with given hardware ID. */ struct tap_adapter_node *pAdapterList =3D NULL; @@ -579,42 +578,36 @@ } /* Does adapter exist? */ - for (struct tap_adapter_node *pAdapter =3D pAdapterList; pAdapter !=3D= NULL; pAdapter =3D pAdapter->pNext) + for (struct tap_adapter_node *pAdapter =3D pAdapterList; pAdapter !=3D= NULL; + pAdapter =3D pAdapter->pNext) { if (wcsicmp(szDisplayName, pAdapter->szName) =3D=3D 0) { /* Adapter found. */ - WCHAR szArgument[8 /*disable=3D|enable=3D|delete=3D*/ + 38 /*{= xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}*/ + 1 /*terminator*/]; + WCHAR szArgument[8 /*disable=3D|enable=3D|delete=3D*/ + + 38 /*{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}= */ + 1 /*terminator*/]; if (seqCommit && seqRollback) { /* UninstallTUNTAPAdapters will disable the adapter. */ - swprintf_s( - szArgument, _countof(szArgument), - L"disable=3D" _L(PRIXGUID), - PRIGUID_PARAM(pAdapter->guid)); + swprintf_s(szArgument, _countof(szArgument), L"disable=3D"= _L(PRIXGUID), + PRIGUID_PARAM(pAdapter->guid)); msica_arg_seq_add_tail(seq, szArgument); /* UninstallTUNTAPAdaptersRollback will re-enable the adap= ter. */ - swprintf_s( - szArgument, _countof(szArgument), - L"enable=3D" _L(PRIXGUID), - PRIGUID_PARAM(pAdapter->guid)); + swprintf_s(szArgument, _countof(szArgument), L"enable=3D" = _L(PRIXGUID), + PRIGUID_PARAM(pAdapter->guid)); msica_arg_seq_add_head(seqRollback, szArgument); /* UninstallTUNTAPAdaptersCommit will delete the adapter. = */ - swprintf_s( - szArgument, _countof(szArgument), - L"delete=3D" _L(PRIXGUID), - PRIGUID_PARAM(pAdapter->guid)); + swprintf_s(szArgument, _countof(szArgument), L"delete=3D" = _L(PRIXGUID), + PRIGUID_PARAM(pAdapter->guid)); msica_arg_seq_add_tail(seqCommit, szArgument); } else { /* UninstallTUNTAPAdapters will delete the adapter. */ - swprintf_s( - szArgument, _countof(szArgument), - L"delete=3D" _L(PRIXGUID), - PRIGUID_PARAM(pAdapter->guid)); + swprintf_s(szArgument, _countof(szArgument), L"delete=3D" = _L(PRIXGUID), + PRIGUID_PARAM(pAdapter->guid)); msica_arg_seq_add_tail(seq, szArgument); } @@ -628,8 +621,7 @@ } -UINT __stdcall -EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall) +UINT __stdcall EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall) { #ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) @@ -642,13 +634,8 @@ OPENVPNMSICA_SAVE_MSI_SESSION(hInstall); - struct msica_arg_seq - seqInstall, - seqInstallCommit, - seqInstallRollback, - seqUninstall, - seqUninstallCommit, - seqUninstallRollback; + struct msica_arg_seq seqInstall, seqInstallCommit, seqInstallRollback,= seqUninstall, + seqUninstallCommit, seqUninstallRollback; msica_arg_seq_init(&seqInstall); msica_arg_seq_init(&seqInstallCommit); msica_arg_seq_init(&seqInstallRollback); @@ -657,7 +644,8 @@ msica_arg_seq_init(&seqUninstallRollback); /* Check rollback state. */ - bool bRollbackEnabled =3D MsiEvaluateCondition(hInstall, L"RollbackDis= abled") !=3D MSICONDITION_TRUE; + bool bRollbackEnabled =3D + MsiEvaluateCondition(hInstall, L"RollbackDisabled") !=3D MSICONDIT= ION_TRUE; /* Open MSI database. */ MSIHANDLE hDatabase =3D MsiGetActiveDatabase(hInstall); @@ -672,7 +660,8 @@ switch (MsiDatabaseIsTablePersistent(hDatabase, L"TUNTAPAdapter")) { case MSICONDITION_FALSE: - case MSICONDITION_TRUE: break; + case MSICONDITION_TRUE: + break; default: uiResult =3D ERROR_SUCCESS; @@ -681,11 +670,14 @@ /* Prepare a query to get a list/view of adapters. */ MSIHANDLE hViewST =3D 0; - LPCWSTR szQuery =3D L"SELECT `Adapter`,`DisplayName`,`Condition`,`Comp= onent_`,`HardwareId` FROM `TUNTAPAdapter`"; + LPCWSTR szQuery =3D + L"SELECT `Adapter`,`DisplayName`,`Condition`,`Component_`,`Hardwar= eId` FROM `TUNTAPAdapter`"; uiResult =3D MsiDatabaseOpenView(hDatabase, szQuery, &hViewST); if (uiResult !=3D ERROR_SUCCESS) { - SetLastError(uiResult); /* MSDN does not mention MsiDatabaseOpenVi= ew() to set GetLastError(). But we do have an error code. Set last error ma= nually. */ + SetLastError( + uiResult); /* MSDN does not mention MsiDatabaseOpenView() to s= et GetLastError(). But we + do have an error code. Set last error manually. = */ msg(M_NONFATAL | M_ERRNO, "%s: MsiDatabaseOpenView(\"%ls\") failed= ", __FUNCTION__, szQuery); goto cleanup_hDatabase; } @@ -694,7 +686,8 @@ uiResult =3D MsiViewExecute(hViewST, 0); if (uiResult !=3D ERROR_SUCCESS) { - SetLastError(uiResult); /* MSDN does not mention MsiViewExecute() = to set GetLastError(). But we do have an error code. Set last error manuall= y. */ + SetLastError(uiResult); /* MSDN does not mention MsiViewExecute() = to set GetLastError(). But + we do have an error code. Set last erro= r manually. */ msg(M_NONFATAL | M_ERRNO, "%s: MsiViewExecute(\"%ls\") failed", __= FUNCTION__, szQuery); goto cleanup_hViewST; } @@ -708,7 +701,7 @@ goto cleanup_hViewST_close; } - for (;; ) + for (;;) { /* Fetch one record from the view. */ MSIHANDLE hRecord =3D 0; @@ -720,7 +713,8 @@ } else if (uiResult !=3D ERROR_SUCCESS) { - SetLastError(uiResult); /* MSDN does not mention MsiViewFetch(= ) to set GetLastError(). But we do have an error code. Set last error manua= lly. */ + SetLastError(uiResult); /* MSDN does not mention MsiViewFetch(= ) to set GetLastError(). + But we do have an error code. Set l= ast error manually. */ msg(M_NONFATAL | M_ERRNO, "%s: MsiViewFetch failed", __FUNCTIO= N__); goto cleanup_hRecordProg; } @@ -739,8 +733,11 @@ uiResult =3D MsiGetComponentState(hInstall, szValue, &iInstall= ed, &iAction); if (uiResult !=3D ERROR_SUCCESS) { - SetLastError(uiResult); /* MSDN does not mention MsiGetCom= ponentState() to set GetLastError(). But we do have an error code. Set last= error manually. */ - msg(M_NONFATAL | M_ERRNO, "%s: MsiGetComponentState(\"%ls\= ") failed", __FUNCTION__, szValue); + SetLastError(uiResult); /* MSDN does not mention MsiGetCom= ponentState() to set + GetLastError(). But we do have = an error code. Set last + error manually. */ + msg(M_NONFATAL | M_ERRNO, "%s: MsiGetComponentState(\"%ls\= ") failed", __FUNCTION__, + szValue); free(szValue); goto cleanup_hRecord; } @@ -754,7 +751,9 @@ { goto cleanup_hRecord; } - /* `DisplayName` field type is [Filename](https://docs.microsoft.c= om/en-us/windows/win32/msi/filename), which is either "8.3|long name" or "8= .3". */ + /* `DisplayName` field type is + * [Filename](https://docs.microsoft.com/en-us/windows/win32/msi/f= ilename), which is either + * "8.3|long name" or "8.3". */ LPWSTR szDisplayNameEx =3D wcschr(szDisplayName, L'|'); szDisplayNameEx =3D szDisplayNameEx !=3D NULL ? szDisplayNameEx + = 1 : szDisplayName; @@ -767,7 +766,10 @@ { goto cleanup_szDisplayName; } - memcpy_s(szzHardwareIDs, sizeof(szzHardwareIDs) - 2*sizeof(WCH= AR) /*requires double zero termination*/, szHwId, wcslen(szHwId)*sizeof(WCH= AR)); + memcpy_s(szzHardwareIDs, + sizeof(szzHardwareIDs) + - 2 * sizeof(WCHAR) /*requires double zero termin= ation*/, + szHwId, wcslen(szHwId) * sizeof(WCHAR)); free(szHwId); } @@ -800,7 +802,8 @@ case MSICONDITION_ERROR: uiResult =3D ERROR_INVALID_FIELD; - msg(M_NONFATAL | M_ERRNO, "%s: MsiEvaluateConditio= n(\"%ls\") failed", __FUNCTION__, szValue); + msg(M_NONFATAL | M_ERRNO, "%s: MsiEvaluateConditio= n(\"%ls\") failed", + __FUNCTION__, szValue); free(szValue); goto cleanup_szDisplayName; } @@ -810,12 +813,10 @@ free(szValue); /* Component is or should be installed. Schedule adapter c= reation. */ - if (schedule_adapter_create( - &seqInstall, - bRollbackEnabled ? &seqInstallRollback : NULL, - szDisplayNameEx, - szzHardwareIDs, - &iTicks) !=3D ERROR_SUCCESS) + if (schedule_adapter_create(&seqInstall, + bRollbackEnabled ? &seqInstall= Rollback : NULL, + szDisplayNameEx, szzHardwareID= s, &iTicks) + !=3D ERROR_SUCCESS) { uiResult =3D ERROR_INSTALL_FAILED; goto cleanup_szDisplayName; @@ -823,18 +824,16 @@ } else { - /* Component is installed, but should be degraded to adver= tised/removed. Schedule adapter deletition. + /* Component is installed, but should be degraded to adver= tised/removed. Schedule + * adapter deletition. * - * Note: On adapter removal (product is being uninstalled)= , we tolerate dwResult error. - * Better a partial uninstallation than no uninstallation = at all. + * Note: On adapter removal (product is being uninstalled)= , we tolerate dwResult + * error. Better a partial uninstallation than no uninstal= lation at all. */ - schedule_adapter_delete( - &seqUninstall, - bRollbackEnabled ? &seqUninstallCommit : NULL, - bRollbackEnabled ? &seqUninstallRollback : NULL, - szDisplayNameEx, - szzHardwareIDs, - &iTicks); + schedule_adapter_delete(&seqUninstall, + bRollbackEnabled ? &seqUninstallCo= mmit : NULL, + bRollbackEnabled ? &seqUninstallRo= llback : NULL, + szDisplayNameEx, szzHardwareIDs, &= iTicks); } /* Arrange the amount of tick space to add to the progress ind= icator. @@ -872,12 +871,21 @@ msica_arg_seq_add_tail(&seqUninstallRollback, str); /* Store deferred custom action parameters. */ - if ((uiResult =3D setup_sequence(hInstall, L"InstallTUNTAPAdapters", &= seqInstall )) !=3D ERROR_SUCCESS - || (uiResult =3D setup_sequence(hInstall, L"InstallTUNTAPAdaptersC= ommit", &seqInstallCommit )) !=3D ERROR_SUCCESS - || (uiResult =3D setup_sequence(hInstall, L"InstallTUNTAPAdaptersR= ollback", &seqInstallRollback )) !=3D ERROR_SUCCESS - || (uiResult =3D setup_sequence(hInstall, L"UninstallTUNTAPAdapter= s", &seqUninstall )) !=3D ERROR_SUCCESS - || (uiResult =3D setup_sequence(hInstall, L"UninstallTUNTAPAdapter= sCommit", &seqUninstallCommit )) !=3D ERROR_SUCCESS - || (uiResult =3D setup_sequence(hInstall, L"UninstallTUNTAPAdapter= sRollback", &seqUninstallRollback)) !=3D ERROR_SUCCESS) + if ((uiResult =3D setup_sequence(hInstall, L"InstallTUNTAPAdapters", &= seqInstall)) + !=3D ERROR_SUCCESS + || (uiResult =3D setup_sequence(hInstall, L"InstallTUNTAPAdaptersC= ommit", &seqInstallCommit)) + !=3D ERROR_SUCCESS + || (uiResult =3D + setup_sequence(hInstall, L"InstallTUNTAPAdaptersRollback",= &seqInstallRollback)) + !=3D ERROR_SUCCESS + || (uiResult =3D setup_sequence(hInstall, L"UninstallTUNTAPAdapter= s", &seqUninstall)) + !=3D ERROR_SUCCESS + || (uiResult =3D + setup_sequence(hInstall, L"UninstallTUNTAPAdaptersCommit",= &seqUninstallCommit)) + !=3D ERROR_SUCCESS + || (uiResult =3D + setup_sequence(hInstall, L"UninstallTUNTAPAdaptersRollback= ", &seqUninstallRollback)) + !=3D ERROR_SUCCESS) { goto cleanup_hRecordProg; } @@ -917,9 +925,7 @@ * @return TRUE on success; FALSE otherwise */ static BOOL -parse_guid( - _In_z_ LPCWSTR szArg, - _Out_ GUID *guid) +parse_guid(_In_z_ LPCWSTR szArg, _Out_ GUID *guid) { if (swscanf_s(szArg, _L(PRIXGUID), PRIGUID_PARAM_REF(*guid)) !=3D 11) { @@ -946,7 +952,8 @@ msg(M_WARN, "%s: Reboot required, create reboot indication file \"%ls\= "", __FUNCTION__, path); - HANDLE file =3D CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAY= S, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE file =3D + CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTR= IBUTE_NORMAL, NULL); if (file =3D=3D INVALID_HANDLE_VALUE) { msg(M_NONFATAL | M_ERRNO, "%s: CreateFile(\"%ls\") failed", __FUNC= TION__, path); @@ -957,8 +964,7 @@ } } -UINT __stdcall -ProcessDeferredAction(_In_ MSIHANDLE hInstall) +UINT __stdcall ProcessDeferredAction(_In_ MSIHANDLE hInstall) { #ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) @@ -968,13 +974,15 @@ UINT uiResult; BOOL bIsCoInitialized =3D SUCCEEDED(CoInitialize(NULL)); - WCHAR tmpDir[MAX_PATH] =3D {0}; + WCHAR tmpDir[MAX_PATH] =3D { 0 }; OPENVPNMSICA_SAVE_MSI_SESSION(hInstall); - BOOL bIsCleanup =3D MsiGetMode(hInstall, MSIRUNMODE_COMMIT) || MsiGetM= ode(hInstall, MSIRUNMODE_ROLLBACK); + BOOL bIsCleanup =3D + MsiGetMode(hInstall, MSIRUNMODE_COMMIT) || MsiGetMode(hInstall, MS= IRUNMODE_ROLLBACK); - /* Get sequence arguments. Always Unicode as CommandLineToArgvW() is a= vailable as Unicode-only. */ + /* Get sequence arguments. Always Unicode as CommandLineToArgvW() is a= vailable as Unicode-only. + */ LPWSTR szSequence =3D NULL; uiResult =3D msi_get_string(hInstall, L"CustomActionData", &szSequence= ); if (uiResult !=3D ERROR_SUCCESS) @@ -986,7 +994,8 @@ if (szArg =3D=3D NULL) { uiResult =3D GetLastError(); - msg(M_NONFATAL | M_ERRNO, "%s: CommandLineToArgvW(\"%ls\") failed"= , __FUNCTION__, szSequence); + msg(M_NONFATAL | M_ERRNO, "%s: CommandLineToArgvW(\"%ls\") failed"= , __FUNCTION__, + szSequence); goto cleanup_szSequence; } @@ -1038,8 +1047,8 @@ dwResult =3D tap_create_adapter(NULL, NULL, szHardwareId, &bRe= bootRequired, &guidAdapter); if (dwResult =3D=3D ERROR_SUCCESS) { - /* Set adapter name. May fail on some machines, but that i= s not critical - use silent - * flag to mute messagebox and print error only to log */ + /* Set adapter name. May fail on some machines, but that i= s not critical - use + * silent flag to mute messagebox and print error only to = log */ tap_set_adapter_name(&guidAdapter, szName, TRUE); } } @@ -1068,7 +1077,8 @@ if (dwResult =3D=3D ERROR_SUCCESS) { /* Does the adapter exist? */ - for (struct tap_adapter_node *pAdapter =3D pAdapterList; p= Adapter !=3D NULL; pAdapter =3D pAdapter->pNext) + for (struct tap_adapter_node *pAdapter =3D pAdapterList; p= Adapter !=3D NULL; + pAdapter =3D pAdapter->pNext) { if (wcsicmp(szName, pAdapter->szName) =3D=3D 0) { @@ -1157,8 +1167,7 @@ return uiResult; } -UINT __stdcall -CheckAndScheduleReboot(_In_ MSIHANDLE hInstall) +UINT __stdcall CheckAndScheduleReboot(_In_ MSIHANDLE hInstall) { #ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) diff --git a/src/openvpnmsica/openvpnmsica.h b/src/openvpnmsica/openvpnmsic= a.h index b4e3aa8..30def53 100644 --- a/src/openvpnmsica/openvpnmsica.h +++ b/src/openvpnmsica/openvpnmsica.h @@ -51,10 +51,11 @@ /** * Set MSI session handle in thread local storage. */ -#define OPENVPNMSICA_SAVE_MSI_SESSION(hInstall) \ - { \ - struct openvpnmsica_thread_data *s =3D (struct openvpnmsica_thread= _data *)TlsGetValue(openvpnmsica_thread_data_idx); \ - s->hInstall =3D (hInstall); \ +#define OPENVPNMSICA_SAVE_MSI_SESSION(hInstall) = \ + { = \ + struct openvpnmsica_thread_data *s =3D = \ + (struct openvpnmsica_thread_data *)TlsGetValue(openvpnmsica_th= read_data_idx); \ + s->hInstall =3D (hInstall); = \ } @@ -63,7 +64,8 @@ */ #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif /* Ensure that clang-cl, which does not understand the cl specific @@ -78,90 +80,84 @@ #endif -/** - * Determines Windows information: - * - * - Sets `OPENVPNSERVICE` MSI property to PID of OpenVPN Service if runni= ng, or its EXE path if - * configured for auto-start. - * - * - Finds existing TAP-Windows6 adapters and set TAPWINDOWS6ADAPTERS and - * ACTIVETAPWINDOWS6ADAPTERS properties with semicolon delimited list of= all installed adapter - * GUIDs and active adapter GUIDs respectively. - * - * - Finds existing ovpn-dco adapters and set OVPNDCOADAPTERS and ACTIVEOV= PNDCOADAPTERS properties - * with semicolon delimited list of all installed adapter GUIDs and acti= ve adapter GUIDs - * respectively. - * - * @param hInstall Handle to the installation provided to the DLL cus= tom action - * - * @return ERROR_SUCCESS on success; An error code otherwise - * See: https://msdn.microsoft.com/en-us/library/windows/desktop/a= a368072.aspx - */ -DLLEXP_DECL UINT __stdcall -FindSystemInfo(_In_ MSIHANDLE hInstall); + /** + * Determines Windows information: + * + * - Sets `OPENVPNSERVICE` MSI property to PID of OpenVPN Service if r= unning, or its EXE path if + * configured for auto-start. + * + * - Finds existing TAP-Windows6 adapters and set TAPWINDOWS6ADAPTERS = and + * ACTIVETAPWINDOWS6ADAPTERS properties with semicolon delimited lis= t of all installed adapter + * GUIDs and active adapter GUIDs respectively. + * + * - Finds existing ovpn-dco adapters and set OVPNDCOADAPTERS and ACTI= VEOVPNDCOADAPTERS + * properties with semicolon delimited list of all installed adapter G= UIDs and active adapter + * GUIDs respectively. + * + * @param hInstall Handle to the installation provided to the DLL= custom action + * + * @return ERROR_SUCCESS on success; An error code otherwise + * See: https://msdn.microsoft.com/en-us/library/windows/deskt= op/aa368072.aspx + */ + DLLEXP_DECL UINT __stdcall FindSystemInfo(_In_ MSIHANDLE hInstall); -/** - * Find OpenVPN GUI window and send it a WM_CLOSE message. - * - * @param hInstall Handle to the installation provided to the DLL cus= tom action - * - * @return ERROR_SUCCESS on success; An error code otherwise - * See: https://msdn.microsoft.com/en-us/library/windows/desktop/a= a368072.aspx - */ -DLLEXP_DECL UINT __stdcall -CloseOpenVPNGUI(_In_ MSIHANDLE hInstall); + /** + * Find OpenVPN GUI window and send it a WM_CLOSE message. + * + * @param hInstall Handle to the installation provided to the DLL= custom action + * + * @return ERROR_SUCCESS on success; An error code otherwise + * See: https://msdn.microsoft.com/en-us/library/windows/deskt= op/aa368072.aspx + */ + DLLEXP_DECL UINT __stdcall CloseOpenVPNGUI(_In_ MSIHANDLE hInstall); -/** - * Launches OpenVPN GUI. It's path is obtained by expanding the `[#bin.ope= nvpn_gui.exe]` - * therefore, its Id field in File table must be "bin.openvpn_gui.exe". - * - * @param hInstall Handle to the installation provided to the DLL cus= tom action - * - * @return ERROR_SUCCESS on success; An error code otherwise - * See: https://msdn.microsoft.com/en-us/library/windows/desktop/a= a368072.aspx - */ -DLLEXP_DECL UINT __stdcall -StartOpenVPNGUI(_In_ MSIHANDLE hInstall); + /** + * Launches OpenVPN GUI. It's path is obtained by expanding the `[#bin= .openvpn_gui.exe]` + * therefore, its Id field in File table must be "bin.openvpn_gui.exe". + * + * @param hInstall Handle to the installation provided to the DLL= custom action + * + * @return ERROR_SUCCESS on success; An error code otherwise + * See: https://msdn.microsoft.com/en-us/library/windows/deskt= op/aa368072.aspx + */ + DLLEXP_DECL UINT __stdcall StartOpenVPNGUI(_In_ MSIHANDLE hInstall); -/** - * Evaluate the TUNTAPAdapter table of the MSI package database and prepar= e a list of TAP - * adapters to install/remove. - * - * @param hInstall Handle to the installation provided to the DLL cus= tom action - * - * @return ERROR_SUCCESS on success; An error code otherwise - * See: https://msdn.microsoft.com/en-us/library/windows/desktop/a= a368072.aspx - */ -DLLEXP_DECL UINT __stdcall -EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall); + /** + * Evaluate the TUNTAPAdapter table of the MSI package database and pr= epare a list of TAP + * adapters to install/remove. + * + * @param hInstall Handle to the installation provided to the DLL= custom action + * + * @return ERROR_SUCCESS on success; An error code otherwise + * See: https://msdn.microsoft.com/en-us/library/windows/deskt= op/aa368072.aspx + */ + DLLEXP_DECL UINT __stdcall EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInst= all); -/** - * Perform scheduled deferred action. - * - * @param hInstall Handle to the installation provided to the DLL cus= tom action - * - * @return ERROR_SUCCESS on success; An error code otherwise - * See: https://msdn.microsoft.com/en-us/library/windows/desktop/a= a368072.aspx - */ -DLLEXP_DECL UINT __stdcall -ProcessDeferredAction(_In_ MSIHANDLE hInstall); + /** + * Perform scheduled deferred action. + * + * @param hInstall Handle to the installation provided to the DLL= custom action + * + * @return ERROR_SUCCESS on success; An error code otherwise + * See: https://msdn.microsoft.com/en-us/library/windows/deskt= op/aa368072.aspx + */ + DLLEXP_DECL UINT __stdcall ProcessDeferredAction(_In_ MSIHANDLE hInsta= ll); -/** - * Schedule reboot after installation if reboot - * indication file is found in user's temp directory - * - * @param hInstall Handle to the installation provided to the DLL cus= tom action - * - * @return ERROR_SUCCESS on success; An error code otherwise - * See: https://msdn.microsoft.com/en-us/library/windows/desktop/a= a368072.aspx - */ -DLLEXP_DECL UINT __stdcall -CheckAndScheduleReboot(_In_ MSIHANDLE hInstall); + /** + * Schedule reboot after installation if reboot + * indication file is found in user's temp directory + * + * @param hInstall Handle to the installation provided to the DLL= custom action + * + * @return ERROR_SUCCESS on success; An error code otherwise + * See: https://msdn.microsoft.com/en-us/library/windows/deskt= op/aa368072.aspx + */ + DLLEXP_DECL UINT __stdcall CheckAndScheduleReboot(_In_ MSIHANDLE hInst= all); #ifdef __cplusplus } diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index fe360fa..55cdbbe 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -30,12 +30,11 @@ static DWORD GetRegString(HKEY key, LPCWSTR value, LPWSTR data, DWORD size, LPCWSTR def= ault_value) { - LONG status =3D RegGetValue(key, NULL, value, RRF_RT_REG_SZ, - NULL, (LPBYTE) data, &size); + LONG status =3D RegGetValue(key, NULL, value, RRF_RT_REG_SZ, NULL, (LP= BYTE)data, &size); if (status =3D=3D ERROR_FILE_NOT_FOUND && default_value) { - size_t len =3D size/sizeof(data[0]); + size_t len =3D size / sizeof(data[0]); if (swprintf(data, len, default_value)) { status =3D ERROR_SUCCESS; @@ -45,7 +44,10 @@ if (status !=3D ERROR_SUCCESS) { SetLastError(status); - return MsgToEventLog(M_SYSERR, L"Error querying registry value: HK= LM\\SOFTWARE\\" _L(PACKAGE_NAME) L"%ls\\%ls", service_instance, value); + return MsgToEventLog( + M_SYSERR, + L"Error querying registry value: HKLM\\SOFTWARE\\" _L(PACKAGE_= NAME) L"%ls\\%ls", + service_instance, value); } return ERROR_SUCCESS; @@ -69,7 +71,8 @@ if (status !=3D ERROR_SUCCESS) { SetLastError(status); - return MsgToEventLog(M_SYSERR, L"Could not open Registry key HKLM\= \%ls not found", reg_path); + return MsgToEventLog(M_SYSERR, L"Could not open Registry key HKLM\= \%ls not found", + reg_path); } /* The default value of REG_KEY is the install path */ @@ -80,8 +83,7 @@ goto out; } - swprintf(default_value, _countof(default_value), L"%ls\\bin\\openvpn.e= xe", - install_path); + swprintf(default_value, _countof(default_value), L"%ls\\bin\\openvpn.e= xe", install_path); error =3D GetRegString(key, L"exe_path", s->exe_path, sizeof(s->exe_pa= th), default_value); if (error !=3D ERROR_SUCCESS) { @@ -89,23 +91,20 @@ } swprintf(default_value, _countof(default_value), L"%ls\\config", insta= ll_path); - error =3D GetRegString(key, L"config_dir", s->config_dir, sizeof(s->co= nfig_dir), - default_value); + error =3D GetRegString(key, L"config_dir", s->config_dir, sizeof(s->co= nfig_dir), default_value); if (error !=3D ERROR_SUCCESS) { goto out; } swprintf(default_value, _countof(default_value), L"%ls\\bin", install_= path); - error =3D GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), - default_value); + error =3D GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir)= , default_value); if (error !=3D ERROR_SUCCESS) { goto out; } - error =3D GetRegString(key, L"config_ext", s->ext_string, sizeof(s->ex= t_string), - L".ovpn"); + error =3D GetRegString(key, L"config_ext", s->ext_string, sizeof(s->ex= t_string), L".ovpn"); if (error !=3D ERROR_SUCCESS) { goto out; @@ -118,8 +117,7 @@ goto out; } - error =3D GetRegString(key, L"priority", priority, sizeof(priority), - L"NORMAL_PRIORITY_CLASS"); + error =3D GetRegString(key, L"priority", priority, sizeof(priority), L= "NORMAL_PRIORITY_CLASS"); if (error !=3D ERROR_SUCCESS) { goto out; @@ -132,8 +130,8 @@ } /* read if present, else use default */ - error =3D GetRegString(key, L"ovpn_admin_group", s->ovpn_admin_group, - sizeof(s->ovpn_admin_group), OVPN_ADMIN_GROUP); + error =3D GetRegString(key, L"ovpn_admin_group", s->ovpn_admin_group, = sizeof(s->ovpn_admin_group), + OVPN_ADMIN_GROUP); if (error !=3D ERROR_SUCCESS) { goto out; @@ -186,7 +184,8 @@ else { SetLastError(ERROR_INVALID_DATA); - error =3D MsgToEventLog(M_ERR, L"Log file append flag (given as '%= ls') must be '0' or '1'", append); + error =3D MsgToEventLog(M_ERR, L"Log file append flag (given as '%= ls') must be '0' or '1'", + append); goto out; } @@ -205,10 +204,11 @@ LPWSTR tmp =3D NULL; error =3D GetLastError(); - len =3D FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_= FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, + len =3D FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_= FROM_SYSTEM + | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, error, LANG_NEUTRAL, tmp, 0, NULL); - if (len =3D=3D 0 || (long) _countof(buf) < (long) len + 14) + if (len =3D=3D 0 || (long)_countof(buf) < (long)len + 14) { buf[0] =3D L'\0'; } @@ -245,8 +245,7 @@ hEventSource =3D RegisterEventSource(NULL, APPNAME); if (hEventSource !=3D NULL) { - swprintf(msg[0], _countof(msg[0]), - L"%ls%ls%ls: %ls", APPNAME, service_instance, + swprintf(msg[0], _countof(msg[0]), L"%ls%ls%ls: %ls", APPNAME, ser= vice_instance, (flags & MSG_FLAGS_ERROR) ? L" error" : L"", err_msg); va_start(arglist, format); @@ -254,9 +253,9 @@ va_end(arglist); const WCHAR *mesg[] =3D { msg[0], msg[1] }; - ReportEvent(hEventSource, flags & MSG_FLAGS_ERROR ? - EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE, - 0, 0, NULL, 2, 0, mesg, NULL); + ReportEvent(hEventSource, + flags & MSG_FLAGS_ERROR ? EVENTLOG_ERROR_TYPE : EVENTL= OG_INFORMATION_TYPE, 0, 0, + NULL, 2, 0, mesg, NULL); DeregisterEventSource(hEventSource); } diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 628a96b..d7fa6fd 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -41,32 +41,30 @@ #include "validate.h" #include "wfp_block.h" -#define IO_TIMEOUT 2000 /*ms*/ +#define IO_TIMEOUT 2000 /*ms*/ -#define ERROR_OPENVPN_STARTUP 0x20000000 -#define ERROR_STARTUP_DATA 0x20000001 -#define ERROR_MESSAGE_DATA 0x20000002 -#define ERROR_MESSAGE_TYPE 0x20000003 +#define ERROR_OPENVPN_STARTUP 0x20000000 +#define ERROR_STARTUP_DATA 0x20000001 +#define ERROR_MESSAGE_DATA 0x20000002 +#define ERROR_MESSAGE_TYPE 0x20000003 static SERVICE_STATUS_HANDLE service; static SERVICE_STATUS status =3D { .dwServiceType =3D SERVICE_WIN32_SHARE_= PROCESS }; static HANDLE exit_event =3D NULL; static settings_t settings; static HANDLE rdns_semaphore =3D NULL; -#define RDNS_TIMEOUT 600 /* seconds to wait for the semaphore */ +#define RDNS_TIMEOUT 600 /* seconds to wait for the semaphore */ -#define TUN_IOCTL_REGISTER_RINGS CTL_CODE(51820U, 0x970U, METHOD_BUFFERED,= FILE_READ_DATA | FILE_WRITE_DATA) +#define TUN_IOCTL_REGISTER_RINGS \ + CTL_CODE(51820U, 0x970U, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_= DATA) -openvpn_service_t interactive_service =3D { - interactive, - _L(PACKAGE_NAME) L"ServiceInteractive", - _L(PACKAGE_NAME) L" Interactive Service", - SERVICE_DEPENDENCIES, - SERVICE_AUTO_START -}; +openvpn_service_t interactive_service =3D { interactive, _L(PACKAGE_NAME) = L"ServiceInteractive", + _L(PACKAGE_NAME) L" Interactive = Service", + SERVICE_DEPENDENCIES, SERVICE_AU= TO_START }; -typedef struct { +typedef struct +{ WCHAR *directory; WCHAR *options; WCHAR *std_input; @@ -74,14 +72,16 @@ /* Datatype for linked lists */ -typedef struct _list_item { +typedef struct _list_item +{ struct _list_item *next; LPVOID data; } list_item_t; /* Datatypes for undo information */ -typedef enum { +typedef enum +{ address, route, wfp_block, @@ -94,19 +94,22 @@ } undo_type_t; typedef list_item_t *undo_lists_t[_undo_type_max]; -typedef struct { +typedef struct +{ HANDLE engine; int index; int metric_v4; int metric_v6; } wfp_block_data_t; -typedef struct { +typedef struct +{ char itf_name[256]; PWSTR domains; } dns_domains_undo_data_t; -typedef union { +typedef union +{ message_header_t header; address_message_t address; route_message_t route; @@ -120,7 +123,8 @@ create_adapter_message_t create_adapter; } pipe_message_t; -typedef struct { +typedef struct +{ CHAR addresses[NRPT_ADDR_NUM * NRPT_ADDR_SIZE]; WCHAR domains[512]; /* MULTI_SZ string */ DWORD domains_size; /* bytes in domains */ @@ -143,7 +147,7 @@ return NO_ERROR; } -typedef BOOL (*match_fn_t) (LPVOID item, LPVOID ctx); +typedef BOOL (*match_fn_t)(LPVOID item, LPVOID ctx); static LPVOID RemoveListItem(list_item_t **pfirst, match_fn_t match, LPVOID ctx) @@ -202,7 +206,8 @@ } -typedef enum { +typedef enum +{ peek, read, write @@ -249,8 +254,7 @@ handles[i + 1] =3D events[i]; } - res =3D WaitForMultipleObjects(count + 1, handles, FALSE, - op =3D=3D peek ? INFINITE : IO_TIMEOUT); + res =3D WaitForMultipleObjects(count + 1, handles, FALSE, op =3D=3D pe= ek ? INFINITE : IO_TIMEOUT); if (res !=3D WAIT_OBJECT_0) { CancelIo(pipe); @@ -310,32 +314,25 @@ { DWORD result_len; LPWSTR result =3D L"0xffffffff\nFormatMessage failed\nCould not return= result"; - DWORD_PTR args[] =3D { - (DWORD_PTR) error, - (DWORD_PTR) func, - (DWORD_PTR) "" - }; + DWORD_PTR args[] =3D { (DWORD_PTR)error, (DWORD_PTR)func, (DWORD_PTR) = "" }; if (error !=3D ERROR_OPENVPN_STARTUP) { - FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM - |FORMAT_MESSAGE_ALLOCATE_BUFFER - |FORMAT_MESSAGE_IGNORE_INSERTS, - 0, error, 0, (LPWSTR) &args[2], 0, NULL); + FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCAT= E_BUFFER + | FORMAT_MESSAGE_IGNORE_INSERTS, + 0, error, 0, (LPWSTR)&args[2], 0, NULL); } - result_len =3D FormatMessageW(FORMAT_MESSAGE_FROM_STRING - |FORMAT_MESSAGE_ALLOCATE_BUFFER - |FORMAT_MESSAGE_ARGUMENT_ARRAY, - L"0x%1!08x!\n%2!s!\n%3!s!", 0, 0, - (LPWSTR) &result, 0, (va_list *) args); + result_len =3D FormatMessageW( + FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORM= AT_MESSAGE_ARGUMENT_ARRAY, + L"0x%1!08x!\n%2!s!\n%3!s!", 0, 0, (LPWSTR)&result, 0, (va_list *)a= rgs); WritePipeAsync(pipe, result, (DWORD)(wcslen(result) * 2), count, event= s); MsgToEventLog(MSG_FLAGS_ERROR, result); if (error !=3D ERROR_OPENVPN_STARTUP) { - LocalFree((LPVOID) args[2]); + LocalFree((LPVOID)args[2]); } if (result_len) { @@ -356,7 +353,8 @@ * Returns true on success, false on error with reason set in errmsg. */ static BOOL -ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options, W= CHAR *errmsg, DWORD capacity) +ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options, W= CHAR *errmsg, + DWORD capacity) { WCHAR **argv; int argc; @@ -381,7 +379,7 @@ } /* Note: argv[0] is the first option */ - if (argc < 1) /* no options */ + if (argc < 1) /* no options */ { ret =3D TRUE; goto out; @@ -396,8 +394,7 @@ if (!CheckOption(workdir, 2, argv_tmp, &settings)) { - swprintf(errmsg, capacity, msg1, argv[0], workdir, - settings.ovpn_admin_group); + swprintf(errmsg, capacity, msg1, argv[0], workdir, settings.ov= pn_admin_group); } goto out; } @@ -409,17 +406,15 @@ continue; } - if (!CheckOption(workdir, argc-i, &argv[i], &settings)) + if (!CheckOption(workdir, argc - i, &argv[i], &settings)) { - if (wcscmp(L"--config", argv[i]) =3D=3D 0 && argc-i > 1) + if (wcscmp(L"--config", argv[i]) =3D=3D 0 && argc - i > 1) { - swprintf(errmsg, capacity, msg1, argv[i+1], workdir, - settings.ovpn_admin_group); + swprintf(errmsg, capacity, msg1, argv[i + 1], workdir, set= tings.ovpn_admin_group); } else { - swprintf(errmsg, capacity, msg2, argv[i], - settings.ovpn_admin_group); + swprintf(errmsg, capacity, msg2, argv[i], settings.ovpn_ad= min_group); } goto out; } @@ -506,7 +501,7 @@ return TRUE; err: - sud->directory =3D NULL; /* caller must not free() */ + sud->directory =3D NULL; /* caller must not free() */ free(data); return FALSE; } @@ -581,7 +576,7 @@ InitializeUnicastIpAddressEntry(addr_row); addr_row->Address =3D sockaddr_inet(msg->family, &msg->address); - addr_row->OnLinkPrefixLength =3D (UINT8) msg->prefix_len; + addr_row->OnLinkPrefixLength =3D (UINT8)msg->prefix_len; if (msg->iface.index !=3D -1) { @@ -663,7 +658,7 @@ fwd_row->Protocol =3D MIB_IPPROTO_NETMGMT; fwd_row->Metric =3D msg->metric; fwd_row->DestinationPrefix.Prefix =3D sockaddr_inet(msg->family, &msg-= >prefix); - fwd_row->DestinationPrefix.PrefixLength =3D (UINT8) msg->prefix_len; + fwd_row->DestinationPrefix.PrefixLength =3D (UINT8)msg->prefix_len; fwd_row->NextHop =3D sockaddr_inet(msg->family, &msg->gateway); if (msg->iface.index !=3D -1) @@ -741,7 +736,7 @@ err_str =3D L"Unknown Win32 Error"; if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_= SYSTEM - | FORMAT_MESSAGE_ARGUMENT_ARRAY, + | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, err, 0, buf, sizeof(buf), NULL)) { err_str =3D buf; @@ -768,13 +763,11 @@ err =3D delete_wfp_block_filters(block_data->engine); if (block_data->metric_v4 >=3D 0) { - set_interface_metric(msg->iface.index, AF_INET, - block_data->metric_v4); + set_interface_metric(msg->iface.index, AF_INET, block_data->me= tric_v4); } if (block_data->metric_v6 >=3D 0) { - set_interface_metric(msg->iface.index, AF_INET6, - block_data->metric_v6); + set_interface_metric(msg->iface.index, AF_INET6, block_data->m= etric_v6); } free(block_data); } @@ -810,14 +803,12 @@ block_data->engine =3D engine; block_data->index =3D msg->iface.index; int is_auto =3D 0; - block_data->metric_v4 =3D get_interface_metric(msg->iface.index, - AF_INET, &is_auto); + block_data->metric_v4 =3D get_interface_metric(msg->iface.index, A= F_INET, &is_auto); if (is_auto) { block_data->metric_v4 =3D 0; } - block_data->metric_v6 =3D get_interface_metric(msg->iface.index, - AF_INET6, &is_auto); + block_data->metric_v6 =3D get_interface_metric(msg->iface.index, A= F_INET6, &is_auto); if (is_auto) { block_data->metric_v6 =3D 0; @@ -826,8 +817,7 @@ err =3D AddListItem(&(*lists)[wfp_block], block_data); if (!err) { - err =3D set_interface_metric(msg->iface.index, AF_INET, - WFP_BLOCK_IFACE_METRIC); + err =3D set_interface_metric(msg->iface.index, AF_INET, WFP_BL= OCK_IFACE_METRIC); if (!err) { /* for IPv6, we intentionally ignore errors, because @@ -835,8 +825,7 @@ * admin has disabled IPv6 on the tun/tap/dco interface * (if OpenVPN wants IPv6 ifconfig, we'll fail there) */ - set_interface_metric(msg->iface.index, AF_INET6, - WFP_BLOCK_IFACE_METRIC); + set_interface_metric(msg->iface.index, AF_INET6, WFP_BLOCK= _IFACE_METRIC); } if (err) { @@ -881,7 +870,7 @@ DWORD exit_code; STARTUPINFOW si; PROCESS_INFORMATION pi; - DWORD proc_flags =3D CREATE_NO_WINDOW|CREATE_UNICODE_ENVIRONMENT; + DWORD proc_flags =3D CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT; WCHAR *cmdline_dup =3D NULL; ZeroMemory(&si, sizeof(si)); @@ -891,8 +880,8 @@ /* CreateProcess needs a modifiable cmdline: make a copy */ cmdline_dup =3D _wcsdup(cmdline); - if (cmdline_dup && CreateProcessW(argv0, cmdline_dup, NULL, NULL, FALS= E, - proc_flags, NULL, NULL, &si, &pi) ) + if (cmdline_dup + && CreateProcessW(argv0, cmdline_dup, NULL, NULL, FALSE, proc_flag= s, NULL, NULL, &si, &pi)) { WaitForSingleObject(pi.hProcess, timeout ? timeout : INFINITE); if (!GetExitCodeProcess(pi.hProcess, &exit_code)) @@ -906,13 +895,12 @@ /* kill without impunity */ TerminateProcess(pi.hProcess, exit_code); - MsgToEventLog(M_ERR, L"ExecCommand: \"%ls %ls\" killed after t= imeout", - argv0, cmdline); + MsgToEventLog(M_ERR, L"ExecCommand: \"%ls %ls\" killed after t= imeout", argv0, cmdline); } else if (exit_code) { - MsgToEventLog(M_ERR, L"ExecCommand: \"%ls %ls\" exited with st= atus =3D %lu", - argv0, cmdline, exit_code); + MsgToEventLog(M_ERR, L"ExecCommand: \"%ls %ls\" exited with st= atus =3D %lu", argv0, + cmdline, exit_code); } else { @@ -925,8 +913,7 @@ else { exit_code =3D GetLastError(); - MsgToEventLog(M_SYSERR, L"ExecCommand: could not run \"%ls %ls\" := ", - argv0, cmdline); + MsgToEventLog(M_SYSERR, L"ExecCommand: could not run \"%ls %ls\" := ", argv0, cmdline); } free(cmdline_dup); @@ -951,12 +938,12 @@ WCHAR *argv0; WCHAR *cmdline; DWORD timeout; - } cmds [] =3D { - { ipcfg, L"ipconfig /flushdns", timeout }, + } cmds[] =3D { + { ipcfg, L"ipconfig /flushdns", timeout }, { ipcfg, L"ipconfig /registerdns", timeout }, }; - HANDLE wait_handles[2] =3D {rdns_semaphore, exit_event}; + HANDLE wait_handles[2] =3D { rdns_semaphore, exit_event }; swprintf(ipcfg, MAX_PATH, L"%ls\\%ls", get_win_sys_path(), L"ipconfig.= exe"); @@ -968,9 +955,10 @@ ExecCommand(cmds[i].argv0, cmds[i].cmdline, cmds[i].timeout); } err =3D 0; - if (!ReleaseSemaphore(rdns_semaphore, 1, NULL) ) + if (!ReleaseSemaphore(rdns_semaphore, 1, NULL)) { - err =3D MsgToEventLog(M_SYSERR, L"RegisterDNS: Failed to relea= se regsiter-dns semaphore:"); + err =3D + MsgToEventLog(M_SYSERR, L"RegisterDNS: Failed to release r= egsiter-dns semaphore:"); } } else @@ -1047,7 +1035,7 @@ /* max cmdline length in wchars -- include room for worst case and som= e */ size_t ncmdline =3D wcslen(fmt) + wcslen(if_name) + wcslen(action) + w= cslen(addr) - +wcslen(addr_static) + 32 + 1; + + wcslen(addr_static) + 32 + 1; cmdline =3D malloc(ncmdline * sizeof(wchar_t)); if (!cmdline) { @@ -1079,13 +1067,8 @@ static BOOL ApplyGpolSettings32(void) { - typedef NTSTATUS (__stdcall *publish_fn_t)( - DWORD StateNameLo, - DWORD StateNameHi, - DWORD TypeId, - DWORD Buffer, - DWORD Length, - DWORD ExplicitScope); + typedef NTSTATUS(__stdcall * publish_fn_t)(DWORD StateNameLo, DWORD St= ateNameHi, DWORD TypeId, + DWORD Buffer, DWORD Length,= DWORD ExplicitScope); publish_fn_t RtlPublishWnfStateData; const DWORD WNF_GPOL_SYSTEM_CHANGES_HI =3D 0x0D891E2A; const DWORD WNF_GPOL_SYSTEM_CHANGES_LO =3D 0xA3BC0875; @@ -1096,13 +1079,14 @@ return FALSE; } - RtlPublishWnfStateData =3D (publish_fn_t) GetProcAddress(ntdll, "RtlPu= blishWnfStateData"); + RtlPublishWnfStateData =3D (publish_fn_t)GetProcAddress(ntdll, "RtlPub= lishWnfStateData"); if (RtlPublishWnfStateData =3D=3D NULL) { return FALSE; } - if (RtlPublishWnfStateData(WNF_GPOL_SYSTEM_CHANGES_LO, WNF_GPOL_SYSTEM= _CHANGES_HI, 0, 0, 0, 0) !=3D ERROR_SUCCESS) + if (RtlPublishWnfStateData(WNF_GPOL_SYSTEM_CHANGES_LO, WNF_GPOL_SYSTEM= _CHANGES_HI, 0, 0, 0, 0) + !=3D ERROR_SUCCESS) { return FALSE; } @@ -1119,12 +1103,8 @@ static BOOL ApplyGpolSettings64(void) { - typedef NTSTATUS (*publish_fn_t)( - INT64 StateName, - INT64 TypeId, - INT64 Buffer, - unsigned int Length, - INT64 ExplicitScope); + typedef NTSTATUS (*publish_fn_t)(INT64 StateName, INT64 TypeId, INT64 = Buffer, + unsigned int Length, INT64 ExplicitSc= ope); publish_fn_t RtlPublishWnfStateData; const INT64 WNF_GPOL_SYSTEM_CHANGES =3D 0x0D891E2AA3BC0875; @@ -1134,7 +1114,7 @@ return FALSE; } - RtlPublishWnfStateData =3D (publish_fn_t) GetProcAddress(ntdll, "RtlPu= blishWnfStateData"); + RtlPublishWnfStateData =3D (publish_fn_t)GetProcAddress(ntdll, "RtlPub= lishWnfStateData"); if (RtlPublishWnfStateData =3D=3D NULL) { return FALSE; @@ -1184,24 +1164,21 @@ scm =3D OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (scm =3D=3D NULL) { - MsgToEventLog(M_ERR, L"%S: OpenSCManager call failed (%lu)", - __func__, GetLastError()); + MsgToEventLog(M_ERR, L"%S: OpenSCManager call failed (%lu)", __fun= c__, GetLastError()); goto out; } dnssvc =3D OpenServiceA(scm, "Dnscache", SERVICE_PAUSE_CONTINUE); if (dnssvc =3D=3D NULL) { - MsgToEventLog(M_ERR, L"%S: OpenService call failed (%lu)", - __func__, GetLastError()); + MsgToEventLog(M_ERR, L"%S: OpenService call failed (%lu)", __func_= _, GetLastError()); goto out; } SERVICE_STATUS status; if (ControlService(dnssvc, SERVICE_CONTROL_PARAMCHANGE, &status) =3D= =3D 0) { - MsgToEventLog(M_ERR, L"%S: ControlService call failed (%lu)", - __func__, GetLastError()); + MsgToEventLog(M_ERR, L"%S: ControlService call failed (%lu)", __fu= nc__, GetLastError()); goto out; } @@ -1329,8 +1306,7 @@ *gpol =3D FALSE; /* Try the group policy search list */ - err =3D RegOpenKeyExA(HKEY_LOCAL_MACHINE, - "SOFTWARE\\Policies\\Microsoft\\Windows NT\\DNSCli= ent", + err =3D RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Microso= ft\\Windows NT\\DNSClient", 0, KEY_ALL_ACCESS, key); if (!err) { @@ -1343,9 +1319,9 @@ } /* Try the system-wide search list */ - err =3D RegOpenKeyExA(HKEY_LOCAL_MACHINE, - "System\\CurrentControlSet\\Services\\TCPIP\\Param= eters", - 0, KEY_ALL_ACCESS, key); + err =3D + RegOpenKeyExA(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Serv= ices\\TCPIP\\Parameters", + 0, KEY_ALL_ACCESS, key); if (!err) { if (HasValidSearchList(*key)) @@ -1363,9 +1339,10 @@ if (!iid_err) { HKEY itfs; - err =3D RegOpenKeyExA(HKEY_LOCAL_MACHINE, - "System\\CurrentControlSet\\Services\\TCPI= P\\Parameters\\Interfaces", - 0, KEY_ALL_ACCESS, &itfs); + err =3D + RegOpenKeyExA(HKEY_LOCAL_MACHINE, + "System\\CurrentControlSet\\Services\\TCPIP\= \Parameters\\Interfaces", + 0, KEY_ALL_ACCESS, &itfs); if (!err) { err =3D RegOpenKeyExW(itfs, iid, 0, KEY_ALL_ACCESS, key); @@ -1401,8 +1378,7 @@ { return FALSE; } - MsgToEventLog(M_ERR, L"%S: failed to get InitialSearchList (%lu)", - __func__, err); + MsgToEventLog(M_ERR, L"%S: failed to get InitialSearchList (%lu)",= __func__, err); } return TRUE; @@ -1437,8 +1413,7 @@ LSTATUS err =3D RegSetValueExW(key, L"InitialSearchList", 0, REG_SZ, (= PBYTE)list, size); if (err) { - MsgToEventLog(M_ERR, L"%S: failed to set InitialSearchList value (= %lu)", - __func__, err); + MsgToEventLog(M_ERR, L"%S: failed to set InitialSearchList value (= %lu)", __func__, err); return FALSE; } @@ -1458,7 +1433,7 @@ AddDnsSearchDomains(HKEY key, BOOL have_list, PCWSTR domains) { LSTATUS err; - WCHAR list[2048] =3D {0}; + WCHAR list[2048] =3D { 0 }; DWORD size =3D sizeof(list); if (have_list) @@ -1466,8 +1441,8 @@ err =3D RegGetValueW(key, NULL, L"SearchList", RRF_RT_REG_SZ, NULL= , list, &size); if (err) { - MsgToEventLog(M_SYSERR, L"%S: could not get SearchList from re= gistry (%lu)", - __func__, err); + MsgToEventLog(M_SYSERR, L"%S: could not get SearchList from re= gistry (%lu)", __func__, + err); return FALSE; } @@ -1499,8 +1474,7 @@ err =3D RegSetValueExW(key, L"SearchList", 0, REG_SZ, (PBYTE)list, siz= e); if (err) { - MsgToEventLog(M_SYSERR, L"%S: could not set SearchList to registry= (%lu)", - __func__, err); + MsgToEventLog(M_SYSERR, L"%S: could not set SearchList to registry= (%lu)", __func__, err); return FALSE; } @@ -1541,8 +1515,7 @@ err =3D RegSetValueExW(key, L"SearchList", 0, REG_SZ, (PBYTE)list, siz= e); if (err) { - MsgToEventLog(M_SYSERR, L"%S: could not set SearchList in registry= (%lu)", - __func__, err); + MsgToEventLog(M_SYSERR, L"%S: could not set SearchList in registry= (%lu)", __func__, err); goto out; } @@ -1569,8 +1542,7 @@ err =3D RegGetValueW(key, NULL, L"SearchList", RRF_RT_REG_SZ, NULL, li= st, &size); if (err) { - MsgToEventLog(M_SYSERR, L"%S: could not get SearchList from regist= ry (%lu)", - __func__, err); + MsgToEventLog(M_SYSERR, L"%S: could not get SearchList from regist= ry (%lu)", __func__, err); return; } @@ -1614,8 +1586,7 @@ err =3D RegSetValueExW(key, L"SearchList", 0, REG_SZ, (PBYTE)list, siz= e); if (err) { - MsgToEventLog(M_SYSERR, L"%S: could not set SearchList in registry= (%lu)", - __func__, err); + MsgToEventLog(M_SYSERR, L"%S: could not set SearchList in registry= (%lu)", __func__, err); } } @@ -1733,8 +1704,8 @@ GetInterfacesKey(short family, PHKEY key) { PCSTR itfs_key =3D family =3D=3D AF_INET6 - ? "SYSTEM\\CurrentControlSet\\Services\\Tcpip6\\Parameters\\Interf= aces" - : "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfa= ces"; + ? "SYSTEM\\CurrentControlSet\\Services\\Tcpip6\\P= arameters\\Interfaces" + : "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Pa= rameters\\Interfaces"; LSTATUS err =3D RegOpenKeyExA(HKEY_LOCAL_MACHINE, itfs_key, 0, KEY_ALL= _ACCESS, key); if (err) @@ -1843,11 +1814,12 @@ return ERROR_MESSAGE_DATA; } - /* use a non-const reference with limited scope to enforce null-termin= ation of strings from client */ + /* use a non-const reference with limited scope to enforce null-termin= ation of strings from + * client */ { - dns_cfg_message_t *msgptr =3D (dns_cfg_message_t *) msg; - msgptr->iface.name[_countof(msg->iface.name)-1] =3D '\0'; - msgptr->domains[_countof(msg->domains)-1] =3D '\0'; + dns_cfg_message_t *msgptr =3D (dns_cfg_message_t *)msg; + msgptr->iface.name[_countof(msg->iface.name) - 1] =3D '\0'; + msgptr->domains[_countof(msg->domains) - 1] =3D '\0'; } WCHAR iid[64]; @@ -1879,7 +1851,7 @@ err =3D SetDnsSearchDomains(msg->iface.name, NULL, &gpol, list= s); } ApplyDnsSettings(gpol); - return err; /* job done */ + return err; /* job done */ } if (msg->addr_len > 0) @@ -2101,8 +2073,7 @@ s--; } - if (inet_ntop(AF_INET6, &in_addrs[i], - pos, s) !=3D NULL) + if (inet_ntop(AF_INET6, &in_addrs[i], pos, s) !=3D NULL) { *size =3D 0; return ERROR_MORE_DATA; @@ -2189,7 +2160,7 @@ LSTATUS err =3D ERROR_FILE_NOT_FOUND; const DWORD buf_size =3D *size; const size_t one_glyph =3D sizeof(*domains); - PWSTR values[] =3D { L"SearchList", L"Domain", L"DhcpDomainSearchList"= , L"DhcpDomain", NULL}; + PWSTR values[] =3D { L"SearchList", L"Domain", L"DhcpDomainSearchList"= , L"DhcpDomain", NULL }; =20 for (int i =3D 0; values[i]; i++) { @@ -2285,7 +2256,8 @@ /* Get GUID from string */ if (IIDFromString(iid_str, &iid) !=3D S_OK) { - MsgToEventLog(M_SYSERR, L"%S: could not convert interface %s GUID = string", __func__, iid_str); + MsgToEventLog(M_SYSERR, L"%S: could not convert interface %s GUID = string", __func__, + iid_str); goto out; } @@ -2327,8 +2299,7 @@ HKEY v4_itfs =3D INVALID_HANDLE_VALUE; HKEY v6_itfs =3D INVALID_HANDLE_VALUE; - if (!GetInterfacesKey(AF_INET, &v4_itfs) - || !GetInterfacesKey(AF_INET6, &v6_itfs)) + if (!GetInterfacesKey(AF_INET, &v4_itfs) || !GetInterfacesKey(AF_INET6= , &v6_itfs)) { goto out; } @@ -2339,8 +2310,8 @@ { WCHAR itf_guid[MAX_PATH]; DWORD itf_guid_len =3D _countof(itf_guid); - LSTATUS err =3D RegEnumKeyExW(v4_itfs, enum_index++, itf_guid, &it= f_guid_len, - NULL, NULL, NULL, NULL); + LSTATUS err =3D + RegEnumKeyExW(v4_itfs, enum_index++, itf_guid, &itf_guid_len, = NULL, NULL, NULL, NULL); if (err) { if (err !=3D ERROR_NO_MORE_ITEMS) @@ -2359,7 +2330,8 @@ HKEY v4_itf; if (RegOpenKeyExW(v4_itfs, itf_guid, 0, KEY_READ, &v4_itf) !=3D NO= _ERROR) { - MsgToEventLog(M_SYSERR, L"%S: could not open interface %s v4 r= egistry key", __func__, itf_guid); + MsgToEventLog(M_SYSERR, L"%S: could not open interface %s v4 r= egistry key", __func__, + itf_guid); goto out; } @@ -2371,7 +2343,8 @@ { if (err !=3D ERROR_FILE_NOT_FOUND) { - MsgToEventLog(M_SYSERR, L"%S: could not read interface %s = domain suffix", __func__, itf_guid); + MsgToEventLog(M_SYSERR, L"%S: could not read interface %s = domain suffix", __func__, + itf_guid); } goto next_itf; } @@ -2394,7 +2367,8 @@ HKEY v6_itf; if (RegOpenKeyExW(v6_itfs, itf_guid, 0, KEY_READ, &v6_itf) != =3D NO_ERROR) { - MsgToEventLog(M_SYSERR, L"%S: could not open interface %s = v6 registry key", __func__, itf_guid); + MsgToEventLog(M_SYSERR, L"%S: could not open interface %s = v6 registry key", + __func__, itf_guid); goto next_itf; } err =3D GetItfDnsServersV6(v6_itf, v6_addrs, &v6_addrs_size); @@ -2442,8 +2416,8 @@ * @return NO_ERROR on success, or Windows error code */ static DWORD -SetNrptRule(HKEY nrpt_key, PCWSTR subkey, PCSTR address, - PCWSTR domains, DWORD dom_size, BOOL dnssec) +SetNrptRule(HKEY nrpt_key, PCWSTR subkey, PCSTR address, PCWSTR domains, D= WORD dom_size, + BOOL dnssec) { /* Create rule subkey */ DWORD err =3D NO_ERROR; @@ -2462,7 +2436,8 @@ } /* Set DNS Server address */ - err =3D RegSetValueExA(rule_key, "GenericDNSServers", 0, REG_SZ, (PBYT= E)address, strlen(address) + 1); + err =3D RegSetValueExA(rule_key, "GenericDNSServers", 0, REG_SZ, (PBYT= E)address, + strlen(address) + 1); if (err) { goto out; @@ -2473,21 +2448,24 @@ if (dnssec) { reg_val =3D 1; - err =3D RegSetValueExA(rule_key, "DNSSECValidationRequired", 0, RE= G_DWORD, (PBYTE)®_val, sizeof(reg_val)); + err =3D RegSetValueExA(rule_key, "DNSSECValidationRequired", 0, RE= G_DWORD, (PBYTE)®_val, + sizeof(reg_val)); if (err) { goto out; } reg_val =3D 0; - err =3D RegSetValueExA(rule_key, "DNSSECQueryIPSECRequired", 0, RE= G_DWORD, (PBYTE)®_val, sizeof(reg_val)); + err =3D RegSetValueExA(rule_key, "DNSSECQueryIPSECRequired", 0, RE= G_DWORD, (PBYTE)®_val, + sizeof(reg_val)); if (err) { goto out; } reg_val =3D 0; - err =3D RegSetValueExA(rule_key, "DNSSECQueryIPSECEncryption", 0, = REG_DWORD, (PBYTE)®_val, sizeof(reg_val)); + err =3D RegSetValueExA(rule_key, "DNSSECQueryIPSECEncryption", 0, = REG_DWORD, (PBYTE)®_val, + sizeof(reg_val)); if (err) { goto out; @@ -2496,7 +2474,8 @@ /* Set NRPT config options */ reg_val =3D dnssec ? 0x0000000A : 0x00000008; - err =3D RegSetValueExA(rule_key, "ConfigOptions", 0, REG_DWORD, (const= PBYTE)®_val, sizeof(reg_val)); + err =3D RegSetValueExA(rule_key, "ConfigOptions", 0, REG_DWORD, (const= PBYTE)®_val, + sizeof(reg_val)); if (err) { goto out; @@ -2654,7 +2633,8 @@ * remains in the registry even if the last GP-NRPT rule is deleted. */ static PCSTR gpol_key =3D "SOFTWARE\\Policies\\Microsoft\\Windows NT\\= DNSClient\\DnsPolicyConfig"; - static PCSTR sys_key =3D "SYSTEM\\CurrentControlSet\\Services\\Dnscach= e\\Parameters\\DnsPolicyConfig"; + static PCSTR sys_key =3D + "SYSTEM\\CurrentControlSet\\Services\\Dnscache\\Parameters\\DnsPol= icyConfig"; HKEY nrpt; *gpol =3D TRUE; @@ -2662,7 +2642,8 @@ if (err =3D=3D ERROR_FILE_NOT_FOUND) { *gpol =3D FALSE; - err =3D RegCreateKeyExA(HKEY_LOCAL_MACHINE, sys_key, 0, NULL, 0, K= EY_ALL_ACCESS, NULL, &nrpt, NULL); + err =3D RegCreateKeyExA(HKEY_LOCAL_MACHINE, sys_key, 0, NULL, 0, K= EY_ALL_ACCESS, NULL, &nrpt, + NULL); if (err) { nrpt =3D INVALID_HANDLE_VALUE; @@ -2764,15 +2745,14 @@ * @return NO_ERROR on success, or a Windows error code */ static DWORD -HandleDNSConfigNrptMessage(const nrpt_dns_cfg_message_t *msg, - DWORD ovpn_pid, undo_lists_t *lists) +HandleDNSConfigNrptMessage(const nrpt_dns_cfg_message_t *msg, DWORD ovpn_p= id, undo_lists_t *lists) { /* * Use a non-const reference with limited scope to * enforce null-termination of strings from client */ { - nrpt_dns_cfg_message_t *msgptr =3D (nrpt_dns_cfg_message_t *) msg; + nrpt_dns_cfg_message_t *msgptr =3D (nrpt_dns_cfg_message_t *)msg; msgptr->iface.name[_countof(msg->iface.name) - 1] =3D '\0'; msgptr->search_domains[_countof(msg->search_domains) - 1] =3D '\0'; msgptr->resolve_domains[_countof(msg->resolve_domains) - 1] =3D '\= 0'; @@ -2865,7 +2845,8 @@ /* Set NRPT rules */ BOOL dnssec =3D (msg->flags & nrpt_dnssec) !=3D 0; - err =3D SetNrptRules(key, msg->addresses, msg->resolve_domains, msg->s= earch_domains, dnssec, ovpn_pid); + err =3D SetNrptRules(key, msg->addresses, msg->resolve_domains, msg->s= earch_domains, dnssec, + ovpn_pid); if (err) { goto out; @@ -2908,7 +2889,8 @@ return ERROR_MESSAGE_DATA; } - /* use a non-const reference with limited scope to enforce null-termin= ation of strings from client */ + /* use a non-const reference with limited scope to enforce null-termin= ation of strings from + * client */ { wins_cfg_message_t *msgptr =3D (wins_cfg_message_t *)msg; msgptr->iface.name[_countof(msg->iface.name) - 1] =3D '\0'; @@ -2935,7 +2917,7 @@ if (msg->header.type =3D=3D msg_del_wins_cfg) { - goto out; /* job done */ + goto out; /* job done */ } for (int i =3D 0; i < addr_len; ++i) @@ -2989,7 +2971,7 @@ * 10 chars for 32 bit int in decimal and +1 for NUL */ size_t ncmdline =3D wcslen(fmt) + 10 + 1; - wchar_t *cmdline =3D malloc(ncmdline*sizeof(wchar_t)); + wchar_t *cmdline =3D malloc(ncmdline * sizeof(wchar_t)); if (!cmdline) { err =3D ERROR_OUTOFMEMORY; @@ -3074,16 +3056,12 @@ } static VOID -HandleMessage(HANDLE pipe, PPROCESS_INFORMATION proc_info, - DWORD bytes, DWORD count, LPHANDLE events, undo_lists_t *lis= ts) +HandleMessage(HANDLE pipe, PPROCESS_INFORMATION proc_info, DWORD bytes, DW= ORD count, + LPHANDLE events, undo_lists_t *lists) { pipe_message_t msg; ack_message_t ack =3D { - .header =3D { - .type =3D msg_acknowledgement, - .size =3D sizeof(ack), - .message_id =3D -1 - }, + .header =3D { .type =3D msg_acknowledgement, .size =3D sizeof(ack)= , .message_id =3D -1 }, .error_number =3D ERROR_MESSAGE_DATA }; @@ -3265,27 +3243,24 @@ STARTUPINFOW startup_info; PROCESS_INFORMATION proc_info; LPVOID user_env =3D NULL; - WCHAR ovpn_pipe_name[256]; /* The entire pipe name string can be up to= 256 characters long according to MSDN. */ + WCHAR ovpn_pipe_name[256]; /* The entire pipe name string can be up to= 256 characters long + according to MSDN. */ LPCWSTR exe_path; WCHAR *cmdline =3D NULL; size_t cmdline_size; undo_lists_t undo_lists; WCHAR errmsg[512] =3D L""; - SECURITY_ATTRIBUTES inheritable =3D { - .nLength =3D sizeof(inheritable), - .lpSecurityDescriptor =3D NULL, - .bInheritHandle =3D TRUE - }; + SECURITY_ATTRIBUTES inheritable =3D { .nLength =3D sizeof(inheritable), + .lpSecurityDescriptor =3D NULL, + .bInheritHandle =3D TRUE }; PACL ovpn_dacl; EXPLICIT_ACCESS ea[2]; SECURITY_DESCRIPTOR ovpn_sd; - SECURITY_ATTRIBUTES ovpn_sa =3D { - .nLength =3D sizeof(ovpn_sa), - .lpSecurityDescriptor =3D &ovpn_sd, - .bInheritHandle =3D FALSE - }; + SECURITY_ATTRIBUTES ovpn_sa =3D { .nLength =3D sizeof(ovpn_sa), + .lpSecurityDescriptor =3D &ovpn_sd, + .bInheritHandle =3D FALSE }; ZeroMemory(&ea, sizeof(ea)); ZeroMemory(&startup_info, sizeof(startup_info)); @@ -3371,7 +3346,8 @@ * OR user is authorized to run any config. */ if (!ValidateOptions(pipe, sud.directory, sud.options, errmsg, _counto= f(errmsg)) - && !IsAuthorizedUser(ovpn_user->User.Sid, imp_token, settings.ovpn= _admin_group, settings.ovpn_service_user)) + && !IsAuthorizedUser(ovpn_user->User.Sid, imp_token, settings.ovpn= _admin_group, + settings.ovpn_service_user)) { ReturnError(pipe, ERROR_STARTUP_DATA, errmsg, 1, &exit_event); goto out; @@ -3383,14 +3359,14 @@ ea[0].grfInheritance =3D NO_INHERITANCE; ea[0].Trustee.TrusteeForm =3D TRUSTEE_IS_SID; ea[0].Trustee.TrusteeType =3D TRUSTEE_IS_UNKNOWN; - ea[0].Trustee.ptstrName =3D (LPWSTR) svc_user->User.Sid; - ea[1].grfAccessPermissions =3D READ_CONTROL | SYNCHRONIZE | PROCESS_VM= _READ - |SYNCHRONIZE | PROCESS_TERMINATE | PROCES= S_QUERY_INFORMATION; + ea[0].Trustee.ptstrName =3D (LPWSTR)svc_user->User.Sid; + ea[1].grfAccessPermissions =3D READ_CONTROL | SYNCHRONIZE | PROCESS_VM= _READ | SYNCHRONIZE + | PROCESS_TERMINATE | PROCESS_QUERY_INFOR= MATION; ea[1].grfAccessMode =3D SET_ACCESS; ea[1].grfInheritance =3D NO_INHERITANCE; ea[1].Trustee.TrusteeForm =3D TRUSTEE_IS_SID; ea[1].Trustee.TrusteeType =3D TRUSTEE_IS_UNKNOWN; - ea[1].Trustee.ptstrName =3D (LPWSTR) ovpn_user->User.Sid; + ea[1].Trustee.ptstrName =3D (LPWSTR)ovpn_user->User.Sid; /* Set owner and DACL of OpenVPN security descriptor */ if (!SetSecurityDescriptorOwner(&ovpn_sd, svc_user->User.Sid, FALSE)) @@ -3417,8 +3393,8 @@ } /* use /dev/null for stdout of openvpn (client should use --log for ou= tput) */ - stdout_write =3D CreateFile(_L("NUL"), GENERIC_WRITE, FILE_SHARE_WRITE, - &inheritable, OPEN_EXISTING, 0, NULL); + stdout_write =3D CreateFile(_L("NUL"), GENERIC_WRITE, FILE_SHARE_WRITE= , &inheritable, + OPEN_EXISTING, 0, NULL); if (stdout_write =3D=3D INVALID_HANDLE_VALUE) { ReturnLastError(pipe, L"CreateFile for stdout"); @@ -3433,18 +3409,19 @@ } swprintf(ovpn_pipe_name, _countof(ovpn_pipe_name), - L"\\\\.\\pipe\\" _L(PACKAGE) L"%ls\\service_%lu", service_ins= tance, GetCurrentThreadId()); - ovpn_pipe =3D CreateNamedPipe(ovpn_pipe_name, - PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_= INSTANCE | FILE_FLAG_OVERLAPPED, - PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE = | PIPE_WAIT, 1, 128, 128, 0, NULL); + L"\\\\.\\pipe\\" _L(PACKAGE) L"%ls\\service_%lu", service_ins= tance, + GetCurrentThreadId()); + ovpn_pipe =3D CreateNamedPipe( + ovpn_pipe_name, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE= | FILE_FLAG_OVERLAPPED, + PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, 128, 128= , 0, NULL); if (ovpn_pipe =3D=3D INVALID_HANDLE_VALUE) { ReturnLastError(pipe, L"CreateNamedPipe"); goto out; } - svc_pipe =3D CreateFile(ovpn_pipe_name, GENERIC_READ | GENERIC_WRITE, = 0, - &inheritable, OPEN_EXISTING, 0, NULL); + svc_pipe =3D CreateFile(ovpn_pipe_name, GENERIC_READ | GENERIC_WRITE, = 0, &inheritable, + OPEN_EXISTING, 0, NULL); if (svc_pipe =3D=3D INVALID_HANDLE_VALUE) { ReturnLastError(pipe, L"CreateFile"); @@ -3468,8 +3445,8 @@ /* there seem to be no common printf specifier that works on all * mingw/msvc platforms without trickery, so convert to void* and use * PRIuPTR to print that as best compromise */ - swprintf(cmdline, cmdline_size, L"openvpn %ls --msg-channel %" PRIuPTR, - sud.options, (uintptr_t)svc_pipe); + swprintf(cmdline, cmdline_size, L"openvpn %ls --msg-channel %" PRIuPTR= , sud.options, + (uintptr_t)svc_pipe); if (!CreateEnvironmentBlock(&user_env, imp_token, FALSE)) { @@ -3528,7 +3505,10 @@ if (bytes > sizeof(pipe_message_t)) { /* process at the other side of the pipe is misbehaving, shut = it down */ - MsgToEventLog(MSG_FLAGS_ERROR, L"OpenVPN process sent too larg= e payload length to the pipe (%lu bytes), it will be terminated", bytes); + MsgToEventLog( + MSG_FLAGS_ERROR, + L"OpenVPN process sent too large payload length to the pip= e (%lu bytes), it will be terminated", + bytes); break; } @@ -3544,8 +3524,7 @@ else if (exit_code !=3D 0) { WCHAR buf[256]; - swprintf(buf, _countof(buf), - L"OpenVPN exited with error: exit code =3D %lu", exit_cod= e); + swprintf(buf, _countof(buf), L"OpenVPN exited with error: exit cod= e =3D %lu", exit_code); ReturnError(pipe, ERROR_OPENVPN_STARTUP, buf, 1, &exit_event); } Undo(&undo_lists); @@ -3608,17 +3587,19 @@ * allow read/write for authenticated users * deny all access to anonymous */ - const WCHAR *sddlString =3D L"D:(A;OICI;GA;;;S-1-5-18)(D;OICI;0x4;;;S-= 1-1-0)(A;OICI;GRGW;;;S-1-5-11)(D;;GA;;;S-1-5-7)"; + const WCHAR *sddlString =3D + L"D:(A;OICI;GA;;;S-1-5-18)(D;OICI;0x4;;;S-1-1-0)(A;OICI;GRGW;;;S-1= -5-11)(D;;GA;;;S-1-5-7)"; PSECURITY_DESCRIPTOR sd =3D NULL; - if (!ConvertStringSecurityDescriptorToSecurityDescriptor(sddlString, S= DDL_REVISION_1, &sd, NULL)) + if (!ConvertStringSecurityDescriptorToSecurityDescriptor(sddlString, S= DDL_REVISION_1, &sd, + NULL)) { MsgToEventLog(M_SYSERR, L"ConvertStringSecurityDescriptorToSecurit= yDescriptor failed."); return INVALID_HANDLE_VALUE; } /* Set up SECURITY_ATTRIBUTES */ - SECURITY_ATTRIBUTES sa =3D {0}; + SECURITY_ATTRIBUTES sa =3D { 0 }; sa.nLength =3D sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor =3D sd; sa.bInheritHandle =3D FALSE; @@ -3632,11 +3613,13 @@ first =3D FALSE; } - WCHAR pipe_name[256]; /* The entire pipe name string can be up to 256 = characters long according to MSDN. */ - swprintf(pipe_name, _countof(pipe_name), L"\\\\.\\pipe\\" _L(PACKAGE) = L"%ls\\service", service_instance); - HANDLE pipe =3D CreateNamedPipe(pipe_name, flags, - PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAG= E | PIPE_REJECT_REMOTE_CLIENTS, - PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0,= &sa); + WCHAR pipe_name[256]; /* The entire pipe name string can be up to 256 = characters long according + to MSDN. */ + swprintf(pipe_name, _countof(pipe_name), L"\\\\.\\pipe\\" _L(PACKAGE) = L"%ls\\service", + service_instance); + HANDLE pipe =3D CreateNamedPipe( + pipe_name, flags, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE= _REJECT_REMOTE_CLIENTS, + PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, &sa); LocalFree(sd); @@ -3651,8 +3634,8 @@ static DWORD -UpdateWaitHandles(LPHANDLE *handles_ptr, LPDWORD count, - HANDLE io_event, HANDLE exit_event, list_item_t *threads) +UpdateWaitHandles(LPHANDLE *handles_ptr, LPDWORD count, HANDLE io_event, H= ANDLE exit_event, + list_item_t *threads) { static DWORD size =3D 10; static LPHANDLE handles =3D NULL; @@ -3763,7 +3746,8 @@ PHANDLE handles =3D NULL; DWORD handle_count; - service =3D RegisterServiceCtrlHandlerEx(interactive_service.name, Ser= viceCtrlInteractive, &status); + service =3D + RegisterServiceCtrlHandlerEx(interactive_service.name, ServiceCtrl= Interactive, &status); if (!service) { return; @@ -3818,8 +3802,7 @@ while (TRUE) { - if (ConnectNamedPipe(pipe, &overlapped) =3D=3D FALSE - && GetLastError() !=3D ERROR_PIPE_CONNECTED + if (ConnectNamedPipe(pipe, &overlapped) =3D=3D FALSE && GetLastErr= or() !=3D ERROR_PIPE_CONNECTED && GetLastError() !=3D ERROR_IO_PENDING) { MsgToEventLog(M_SYSERR, L"Could not connect pipe"); @@ -3837,11 +3820,13 @@ error =3D AddListItem(&threads, thread); if (!error) { - error =3D UpdateWaitHandles(&handles, &handle_count, i= o_event, exit_event, threads); + error =3D + UpdateWaitHandles(&handles, &handle_count, io_even= t, exit_event, threads); } if (error) { - ReturnError(pipe, error, L"Insufficient resources to s= ervice new clients", 1, &exit_event); + ReturnError(pipe, error, L"Insufficient resources to s= ervice new clients", 1, + &exit_event); /* Update wait handles again after removing the last w= orker thread */ RemoveListItem(&threads, CmpHandle, thread); UpdateWaitHandles(&handles, &handle_count, io_event, e= xit_event, threads); diff --git a/src/openvpnserv/service.c b/src/openvpnserv/service.c index a76dce7..04b20d7 100644 --- a/src/openvpnserv/service.c +++ b/src/openvpnserv/service.c @@ -33,8 +33,7 @@ status->dwControlsAccepted =3D SERVICE_ACCEPT_STOP; } - if (status->dwCurrentState =3D=3D SERVICE_RUNNING - || status->dwCurrentState =3D=3D SERVICE_STOPPED) + if (status->dwCurrentState =3D=3D SERVICE_RUNNING || status->dwCurrent= State =3D=3D SERVICE_STOPPED) { status->dwCheckPoint =3D 0; } @@ -79,16 +78,10 @@ for (i =3D 0; i < _service_max; i++) { - service =3D CreateService(svc_ctl_mgr, - openvpn_service[i].name, - openvpn_service[i].display_name, - SERVICE_QUERY_STATUS, - SERVICE_WIN32_SHARE_PROCESS, - openvpn_service[i].start_type, - SERVICE_ERROR_NORMAL, - path, NULL, NULL, - openvpn_service[i].dependencies, - NULL, NULL); + service =3D CreateService( + svc_ctl_mgr, openvpn_service[i].name, openvpn_service[i].displ= ay_name, + SERVICE_QUERY_STATUS, SERVICE_WIN32_SHARE_PROCESS, openvpn_ser= vice[i].start_type, + SERVICE_ERROR_NORMAL, path, NULL, NULL, openvpn_service[i].dep= endencies, NULL, NULL); if (service) { wprintf(L"%ls installed.\n", openvpn_service[i].display_name); @@ -163,8 +156,8 @@ for (i =3D 0; i < _service_max; i++) { openvpn_service_t *ovpn_svc =3D &openvpn_service[i]; - service =3D OpenService(svc_ctl_mgr, ovpn_svc->name, - DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS= ); + service =3D + OpenService(svc_ctl_mgr, ovpn_svc->name, DELETE | SERVICE_STOP= | SERVICE_QUERY_STATUS); if (service =3D=3D NULL) { wprintf(L"OpenService failed - %ls\n", GetLastErrorText()); @@ -228,15 +221,12 @@ * This is the default. */ const SERVICE_TABLE_ENTRY dispatchTable_shared[] =3D { - { interactive_service.name, ServiceStartInteractive }, - { NULL, NULL } + { interactive_service.name, ServiceStartInteractive }, { NULL, NUL= L } }; /* Interactive service only (as a SERVICE_WIN32_OWN_PROCESS) */ - const SERVICE_TABLE_ENTRY dispatchTable_interactive[] =3D { - { L"", ServiceStartInteractiveOwn }, - { NULL, NULL } - }; + const SERVICE_TABLE_ENTRY dispatchTable_interactive[] =3D { { L"", Ser= viceStartInteractiveOwn }, + { NULL, NULL= } }; =20 const SERVICE_TABLE_ENTRY *dispatchTable =3D dispatchTable_shared; @@ -260,7 +250,7 @@ } else if (argc > i + 2 && _wcsicmp(L"instance", argv[i] + 1) = =3D=3D 0) { - if (_wcsicmp(L"interactive", argv[i+1]) =3D=3D 0) + if (_wcsicmp(L"interactive", argv[i + 1]) =3D=3D 0) { dispatchTable =3D dispatchTable_interactive; service_instance =3D argv[i + 2]; @@ -268,22 +258,28 @@ } else { - MsgToEventLog(M_ERR, L"Invalid argument to -instance <= %s>. Service not started.", argv[i+1]); + MsgToEventLog(M_ERR, + L"Invalid argument to -instance <%s>. Se= rvice not started.", + argv[i + 1]); return 1; } } else { wprintf(L"%ls -install to install the interactive s= ervice\n", APPNAME); - wprintf(L"%ls -start [name] to start the service (name = =3D \"interactive\") is optional\n", APPNAME); + wprintf( + L"%ls -start [name] to start the service (name =3D \= "interactive\") is optional\n", + APPNAME); wprintf(L"%ls -remove to remove the service\n", AP= PNAME); wprintf(L"\nService run-time parameters:\n"); wprintf(L"-instance interactive \n" L" Runs the service as an alternate instance.\n" L" The service settings will be loaded from\n" - L" HKLM\\Software\\" _L(PACKAGE_NAME) L" reg= istry key, and the service will accept\n" - L" requests on \\\\.\\pipe\\" _L(PACKAGE) L"= \\service named pipe.\n"); + L" HKLM\\Software\\" _L( + PACKAGE_NAME) L" registry key, and the ser= vice will accept\n" + L" requests on \\\\.\\pipe\\" = _L( + PACKAGE) L"\\service nam= ed pipe.\n"); return 0; } diff --git a/src/openvpnserv/service.h b/src/openvpnserv/service.h index bfbe466..4539262 100644 --- a/src/openvpnserv/service.h +++ b/src/openvpnserv/service.h @@ -34,24 +34,26 @@ #include #include "../tapctl/basic.h" =20 -#define APPNAME _L(PACKAGE) L"serv" -#define SERVICE_DEPENDENCIES _L(TAP_WIN_COMPONENT_ID) L"\0Dhcp\0\0" +#define APPNAME _L(PACKAGE) L"serv" +#define SERVICE_DEPENDENCIES _L(TAP_WIN_COMPONENT_ID) L"\0Dhcp\0\0" /* * Message handling */ -#define MSG_FLAGS_ERROR (1<<0) -#define MSG_FLAGS_SYS_CODE (1<<1) -#define M_INFO (0) /* informational */ -#define M_SYSERR (MSG_FLAGS_ERROR|MSG_FLAGS_SYS_CODE) /* error + system c= ode */ -#define M_ERR (MSG_FLAGS_ERROR) /* error */ +#define MSG_FLAGS_ERROR (1 << 0) +#define MSG_FLAGS_SYS_CODE (1 << 1) +#define M_INFO (0) /* infor= mational */ +#define M_SYSERR (MSG_FLAGS_ERROR | MSG_FLAGS_SYS_CODE) /* error= + system code */ +#define M_ERR (MSG_FLAGS_ERROR) /* error= */ -typedef enum { +typedef enum +{ interactive, _service_max } openvpn_service_type; -typedef struct { +typedef struct +{ openvpn_service_type type; WCHAR *name; WCHAR *display_name; @@ -60,7 +62,8 @@ } openvpn_service_t; #define MAX_NAME 256 -typedef struct { +typedef struct +{ WCHAR exe_path[MAX_PATH]; WCHAR config_dir[MAX_PATH]; WCHAR bin_dir[MAX_PATH]; diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c index 9231417..1547949 100644 --- a/src/openvpnserv/validate.c +++ b/src/openvpnserv/validate.c @@ -27,8 +27,7 @@ #include #include -static const WCHAR *white_list[] =3D -{ +static const WCHAR *white_list[] =3D { L"auth-retry", L"config", L"log", @@ -47,7 +46,7 @@ L"pull-filter", L"script-security", - NULL /* last value */ + NULL /* last value */ }; static BOOL IsUserInGroup(PSID sid, const PTOKEN_GROUPS groups, const WCHA= R *group_name); @@ -66,7 +65,7 @@ const WCHAR *config_dir =3D NULL; /* convert fname to full path */ - if (PathIsRelativeW(fname) ) + if (PathIsRelativeW(fname)) { swprintf(tmp, _countof(tmp), L"%ls\\%ls", workdir, fname); config_file =3D tmp; @@ -129,7 +128,7 @@ return FALSE; } - b =3D CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, admin_sid,= &sid_size); + b =3D CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, admin_sid,= &sid_size); if (b) { b =3D LookupAccountSidW(NULL, admin_sid, name, &nlen, domain, &dle= n, &snu); @@ -141,7 +140,8 @@ } BOOL -IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR *ovpn_admin_gro= up, const WCHAR *ovpn_service_user) +IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR *ovpn_admin_gro= up, + const WCHAR *ovpn_service_user) { const WCHAR *admin_group[2]; WCHAR username[MAX_NAME]; @@ -172,7 +172,8 @@ } else { - MsgToEventLog(M_SYSERR, L"Failed to get the name of Administrators= group. Using the default."); + MsgToEventLog(M_SYSERR, + L"Failed to get the name of Administrators group. Us= ing the default."); /* use the default value */ admin_group[0] =3D SYSTEM_ADMIN_GROUP; } @@ -184,7 +185,8 @@ ret =3D IsUserInGroup(sid, token_groups, admin_group[i]); if (ret) { - MsgToEventLog(M_INFO, L"Authorizing user '%ls@%ls' by virtue o= f membership in group '%ls'", + MsgToEventLog(M_INFO, + L"Authorizing user '%ls@%ls' by virtue of member= ship in group '%ls'", username, domain, admin_group[i]); goto out; } @@ -266,11 +268,11 @@ int nloop =3D 0; /* a counter used to not get stuck in the do .. while= () */ /* first check in the token groups */ - if (token_groups && LookupSID(group_name, (PSID) grp_sid, _countof(grp= _sid))) + if (token_groups && LookupSID(group_name, (PSID)grp_sid, _countof(grp_= sid))) { for (DWORD i =3D 0; i < token_groups->GroupCount; ++i) { - if (EqualSid((PSID) grp_sid, token_groups->Groups[i].Sid)) + if (EqualSid((PSID)grp_sid, token_groups->Groups[i].Sid)) { return TRUE; } @@ -286,8 +288,8 @@ { DWORD nread, nmax; LOCALGROUP_MEMBERS_INFO_0 *members =3D NULL; - err =3D NetLocalGroupGetMembers(NULL, group_name, 0, (LPBYTE *) &m= embers, - MAX_PREFERRED_LENGTH, &nread, &nmax,= &resume); + err =3D NetLocalGroupGetMembers(NULL, group_name, 0, (LPBYTE *)&me= mbers, MAX_PREFERRED_LENGTH, + &nread, &nmax, &resume); if ((err !=3D NERR_Success && err !=3D ERROR_MORE_DATA)) { break; @@ -320,16 +322,13 @@ { /* Do not modify argv or *argv -- ideally it should be const WCHAR *co= nst *, but alas...*/ - if (wcscmp(argv[0], L"--config") =3D=3D 0 - && argc > 1 - && !CheckConfigPath(workdir, argv[1], s) - ) + if (wcscmp(argv[0], L"--config") =3D=3D 0 && argc > 1 && !CheckConfigP= ath(workdir, argv[1], s)) { return FALSE; } /* option name starts at 2 characters from argv[i] */ - if (OptionLookup(argv[0] + 2, white_list) =3D=3D -1) /* not found */ + if (OptionLookup(argv[0] + 2, white_list) =3D=3D -1) /* not found */ { return FALSE; } diff --git a/src/openvpnserv/validate.h b/src/openvpnserv/validate.h index 3ef577b..4c55356 100644 --- a/src/openvpnserv/validate.h +++ b/src/openvpnserv/validate.h @@ -29,19 +29,20 @@ /* Authorized groups who can use any options and config locations */ #define SYSTEM_ADMIN_GROUP L"Administrators" -#define OVPN_ADMIN_GROUP L"OpenVPN Administrators" /* may be set in HKLM\S= oftware\OpenVPN\ovpn_admin_group */ -#define OVPN_SERVICE_USER L"OpenVPNService" /* may be set in HKLM\Software= \OpenVPN\ovpn_service_user */ +#define OVPN_ADMIN_GROUP \ + L"OpenVPN Administrators" /* may be set in HKLM\Software\OpenVPN\ovpn_= admin_group */ +#define OVPN_SERVICE_USER \ + L"OpenVPNService" /* may be set in HKLM\Software\OpenVPN\ovpn_= service_user */ /* * Check whether user is a member of Administrators group or * the group specified in ovpn_admin_group or * OpenVPN Virtual Service Account user */ -BOOL -IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR *ovpn_admin_gro= up, const WCHAR *ovpn_service_user); +BOOL IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR *ovpn_admi= n_group, + const WCHAR *ovpn_service_user); -BOOL -CheckOption(const WCHAR *workdir, int narg, WCHAR *argv[], const settings_= t *s); +BOOL CheckOption(const WCHAR *workdir, int narg, WCHAR *argv[], const sett= ings_t *s); static inline BOOL IsOption(const WCHAR *o) diff --git a/src/plugins/auth-pam/auth-pam.c b/src/plugins/auth-pam/auth-pa= m.c index 8692806..c1092a0 100644 --- a/src/plugins/auth-pam/auth-pam.c +++ b/src/plugins/auth-pam/auth-pam.c @@ -100,12 +100,14 @@ #define N_NAME_VALUE 16 -struct name_value { +struct name_value +{ const char *name; const char *value; }; -struct name_value_list { +struct name_value_list +{ int len; struct name_value data[N_NAME_VALUE]; }; @@ -114,7 +116,8 @@ * Used to pass the username/password * to the PAM conversation function. */ -struct user_pass { +struct user_pass +{ int verb; char username[128]; @@ -127,7 +130,8 @@ }; /* Background process function */ -static void pam_server(int fd, const char *service, int verb, const struct= name_value_list *name_value_list); +static void pam_server(int fd, const char *service, int verb, + const struct name_value_list *name_value_list); /* @@ -153,11 +157,11 @@ static int send_control(int fd, int code) { - unsigned char c =3D (unsigned char) code; + unsigned char c =3D (unsigned char)code; const ssize_t size =3D write(fd, &c, sizeof(c)); if (size =3D=3D sizeof(c)) { - return (int) size; + return (int)size; } else { @@ -173,7 +177,7 @@ ssize_t size; memset(buffer, 0, len); size =3D read(fd, buffer, len); - buffer[len-1] =3D 0; + buffer[len - 1] =3D 0; if (size >=3D 1) { return (int)size; @@ -189,7 +193,7 @@ const ssize_t size =3D write(fd, string, len); if (size =3D=3D len) { - return (int) size; + return (int)size; } else { @@ -222,7 +226,7 @@ #endif if (daemon(0, 0) < 0) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "daemonization failed"= ); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "daemonization faile= d"); } #if defined(__APPLE__) && defined(__clang__) #pragma clang diagnostic pop @@ -323,11 +327,11 @@ } *resp++ =3D '\0'; - int n =3D plugin_base64_decode(pass, up->password, sizeof(up->password= )-1); + int n =3D plugin_base64_decode(pass, up->password, sizeof(up->password= ) - 1); if (n >=3D 0) { up->password[n] =3D '\0'; - n =3D plugin_base64_decode(resp, up->response, sizeof(up->response= )-1); + n =3D plugin_base64_decode(resp, up->response, sizeof(up->response= ) - 1); if (n >=3D 0) { up->response[n] =3D '\0'; @@ -355,8 +359,7 @@ } OPENVPN_EXPORT int -openvpn_plugin_open_v3(const int v3structver, - struct openvpn_plugin_args_open_in const *args, +openvpn_plugin_open_v3(const int v3structver, struct openvpn_plugin_args_o= pen_in const *args, struct openvpn_plugin_args_open_return *ret) { pid_t pid; @@ -373,14 +376,15 @@ /* Check API compatibility -- struct version 5 or higher needed */ if (v3structver < 5) { - fprintf(stderr, "AUTH-PAM: This plugin is incompatible with the ru= nning version of OpenVPN\n"); + fprintf(stderr, + "AUTH-PAM: This plugin is incompatible with the running ve= rsion of OpenVPN\n"); return OPENVPN_PLUGIN_FUNC_ERROR; } /* * Allocate our context */ - context =3D (struct auth_pam_context *) calloc(1, sizeof(struct auth_p= am_context)); + context =3D (struct auth_pam_context *)calloc(1, sizeof(struct auth_pa= m_context)); if (!context) { goto error; @@ -428,7 +432,7 @@ { const int base =3D base_parms + i * 2; name_value_list.data[i].name =3D argv[base]; - name_value_list.data[i].value =3D argv[base+1]; + name_value_list.data[i].value =3D argv[base + 1]; } } @@ -449,7 +453,7 @@ */ if (socketpair(PF_UNIX, SOCK_DGRAM, 0, fd) =3D=3D -1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "socketpair call failed"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "socketpair call failed"= ); goto error; } @@ -475,7 +479,8 @@ /* don't let future subprocesses inherit child socket */ if (fcntl(fd[0], F_SETFD, FD_CLOEXEC) < 0) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "Set FD_CLOEXEC flag o= n socket file descriptor failed"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, + "Set FD_CLOEXEC flag on socket file descriptor fail= ed"); } /* wait for background child process to initialize */ @@ -483,8 +488,8 @@ if (status =3D=3D RESPONSE_INIT_SUCCEEDED) { context->foreground_fd =3D fd[0]; - ret->handle =3D (openvpn_plugin_handle_t *) context; - plugin_log( PLOG_NOTE, MODULE, "initialization succeeded (fg)"= ); + ret->handle =3D (openvpn_plugin_handle_t *)context; + plugin_log(PLOG_NOTE, MODULE, "initialization succeeded (fg)"); return OPENVPN_PLUGIN_FUNC_SUCCESS; } } @@ -520,9 +525,10 @@ } OPENVPN_EXPORT int -openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], const char *envp[]) +openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], + const char *envp[]) { - struct auth_pam_context *context =3D (struct auth_pam_context *) handl= e; + struct auth_pam_context *context =3D (struct auth_pam_context *)handle; if (type =3D=3D OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY && context->foreg= round_fd >=3D 0) { @@ -551,8 +557,7 @@ { if (DEBUG(context->verb)) { - plugin_log(PLOG_NOTE, MODULE, "do deferred auth '%s'", - auth_control_file); + plugin_log(PLOG_NOTE, MODULE, "do deferred auth '%s'", aut= h_control_file); } } else @@ -569,7 +574,8 @@ || send_string(context->foreground_fd, auth_control_file) = =3D=3D -1 || send_string(context->foreground_fd, remote) =3D=3D -1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "Error sending aut= h info to background process"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, + "Error sending auth info to background process"= ); } else { @@ -588,7 +594,8 @@ } if (status =3D=3D -1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "Error receivi= ng auth confirmation from background process"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, + "Error receiving auth confirmation from bac= kground process"); } } } @@ -599,7 +606,7 @@ OPENVPN_EXPORT void openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) { - struct auth_pam_context *context =3D (struct auth_pam_context *) handl= e; + struct auth_pam_context *context =3D (struct auth_pam_context *)handle; if (DEBUG(context->verb)) { @@ -611,7 +618,7 @@ /* tell background process to exit */ if (send_control(context->foreground_fd, COMMAND_EXIT) =3D=3D -1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "Error signaling backg= round process to exit"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "Error signaling bac= kground process to exit"); } /* wait for background process to exit */ @@ -630,7 +637,7 @@ OPENVPN_EXPORT void openvpn_plugin_abort_v1(openvpn_plugin_handle_t handle) { - struct auth_pam_context *context =3D (struct auth_pam_context *) handl= e; + struct auth_pam_context *context =3D (struct auth_pam_context *)handle; /* tell background process to exit */ if (context && context->foreground_fd >=3D 0) @@ -645,10 +652,10 @@ * PAM conversation function */ static int -my_conv(int n, const struct pam_message **msg_array, - struct pam_response **response_array, void *appdata_ptr) +my_conv(int n, const struct pam_message **msg_array, struct pam_response *= *response_array, + void *appdata_ptr) { - const struct user_pass *up =3D ( const struct user_pass *) appdata_ptr; + const struct user_pass *up =3D (const struct user_pass *)appdata_ptr; struct pam_response *aresp; int i; int ret =3D PAM_SUCCESS; @@ -673,10 +680,8 @@ if (DEBUG(up->verb)) { - plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: my_conv[%d] query= =3D'%s' style=3D%d", - i, - msg->msg ? msg->msg : "NULL", - msg->msg_style); + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: my_conv[%d] query= =3D'%s' style=3D%d", i, + msg->msg ? msg->msg : "NULL", msg->msg_style); } if (up->name_value_list && up->name_value_list->len > 0) @@ -698,10 +703,10 @@ if (DEBUG(up->verb)) { - plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: name ma= tch found, query/match-string ['%s', '%s'] =3D '%s'", - msg->msg, - match_name, - match_value); + plugin_log( + PLOG_NOTE, MODULE, + "BACKGROUND: name match found, query/match-str= ing ['%s', '%s'] =3D '%s'", + msg->msg, match_name, match_value); } if (strstr(match_value, "USERNAME")) @@ -714,7 +719,8 @@ } else if (strstr(match_value, "COMMONNAME")) { - aresp[i].resp =3D searchandreplace(match_value, "C= OMMONNAME", up->common_name); + aresp[i].resp =3D + searchandreplace(match_value, "COMMONNAME", up= ->common_name); } else if (strstr(match_value, "OTP")) { @@ -825,8 +831,7 @@ if (!ret) { plugin_log(PLOG_ERR, MODULE, "BACKGROUND: user '%s' failed to = authenticate: %s", - up->username, - pam_strerror(pamh, status)); + up->username, pam_strerror(pamh, status)); } /* Close PAM */ @@ -847,12 +852,12 @@ */ static void -do_deferred_pam_auth(int fd, const char *ac_file_name, - const char *service, const struct user_pass *up) +do_deferred_pam_auth(int fd, const char *ac_file_name, const char *service, + const struct user_pass *up) { if (send_control(fd, RESPONSE_DEFER) =3D=3D -1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: write error o= n response socket [4]"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "BACKGROUND: write error= on response socket [4]"); return; } @@ -861,52 +866,50 @@ if (p1 < 0) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: fork(1) faile= d"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "BACKGROUND: fork(1) fai= led"); return; } - if (p1 !=3D 0) /* parent */ + if (p1 !=3D 0) /* parent */ { waitpid(p1, NULL, 0); - return; /* parent's job succeeded */ + return; /* parent's job succeeded */ } /* child */ - close(fd); /* socketpair no longer needed= */ + close(fd); /* socketpair no longer needed */ pid_t p2 =3D fork(); if (p2 < 0) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: fork(2) faile= d"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "BACKGROUND: fork(2) fai= led"); exit(1); } - if (p2 !=3D 0) /* new parent: exit right aw= ay */ + if (p2 !=3D 0) /* new parent: exit right away */ { exit(0); } /* grandchild */ - plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: deferred auth for '%s', pid= =3D%d", - up->username, (int) getpid() ); + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: deferred auth for '%s', pid= =3D%d", up->username, + (int)getpid()); /* the rest is very simple: do PAM, write status byte to file, done */ - int ac_fd =3D open( ac_file_name, O_WRONLY ); + int ac_fd =3D open(ac_file_name, O_WRONLY); if (ac_fd < 0) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "cannot open '%s' for writ= ing", - ac_file_name ); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "cannot open '%s' for wr= iting", ac_file_name); exit(1); } int pam_success =3D pam_auth(service, up); - if (write( ac_fd, pam_success ? "1" : "0", 1 ) !=3D 1) + if (write(ac_fd, pam_success ? "1" : "0", 1) !=3D 1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "cannot write to '%s'", - ac_file_name ); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "cannot write to '%s'", = ac_file_name); } close(ac_fd); - plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: %s: deferred auth: PAM %s", - up->username, pam_success ? "succeeded" : "rejected" ); + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: %s: deferred auth: PAM %s",= up->username, + pam_success ? "succeeded" : "rejected"); exit(0); } @@ -937,7 +940,8 @@ */ if (!dlopen_pam(pam_so)) { - plugin_log(PLOG_ERR, MODULE, "BACKGROUND: could not load PAM lib %= s: %s", pam_so, dlerror()); + plugin_log(PLOG_ERR, MODULE, "BACKGROUND: could not load PAM lib %= s: %s", pam_so, + dlerror()); send_control(fd, RESPONSE_INIT_FAILED); goto done; } @@ -948,7 +952,7 @@ */ if (send_control(fd, RESPONSE_INIT_SUCCEEDED) =3D=3D -1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: write error o= n response socket [1]"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "BACKGROUND: write error= on response socket [1]"); goto done; } @@ -980,7 +984,8 @@ || recv_string(fd, ac_file_name, sizeof(ac_file_name))= =3D=3D -1 || recv_string(fd, up.remote, sizeof(up.remote)) =3D= =3D -1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: r= ead error on command channel: code=3D%d, exiting", + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, + "BACKGROUND: read error on command channel:= code=3D%d, exiting", command); goto done; } @@ -1015,7 +1020,8 @@ { if (send_control(fd, RESPONSE_VERIFY_SUCCEEDED) =3D=3D= -1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUN= D: write error on response socket [2]"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, + "BACKGROUND: write error on response so= cket [2]"); goto done; } } @@ -1023,7 +1029,8 @@ { if (send_control(fd, RESPONSE_VERIFY_FAILED) =3D=3D -1) { - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUN= D: write error on response socket [3]"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, + "BACKGROUND: write error on response so= cket [3]"); goto done; } } @@ -1034,7 +1041,8 @@ goto done; case -1: - plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: read = error on command channel"); + plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, + "BACKGROUND: read error on command channel"); goto done; default: diff --git a/src/plugins/auth-pam/pamdl.c b/src/plugins/auth-pam/pamdl.c index 02ea71a..c1ecfa0 100644 --- a/src/plugins/auth-pam/pamdl.c +++ b/src/plugins/auth-pam/pamdl.c @@ -19,14 +19,20 @@ static void *libpam_h =3D NULL; -#define RESOLVE_PAM_FUNCTION(x, y, z, err) \ - { \ - union { const void *tpointer; y(*fn) z; } fptr; \ - fptr.tpointer =3D dlsym(libpam_h, #x); real_ ## x =3D fptr.fn; \ - if (real_ ## x =3D=3D NULL) { \ +#define RESOLVE_PAM_FUNCTION(x, y, z, err) = \ + { = \ + union = \ + { = \ + const void *tpointer; = \ + y(*fn) z; = \ + } fptr; = \ + fptr.tpointer =3D dlsym(libpam_h, #x); = \ + real_##x =3D fptr.fn; = \ + if (real_##x =3D=3D NULL) = \ + { = \ fprintf(stderr, "PAMDL: unable to resolve '%s': %s\n", #x, dle= rror()); \ - return err; \ - } \ + return err; = \ + } = \ } int @@ -34,7 +40,7 @@ { if (libpam_h =3D=3D NULL) { - libpam_h =3D dlopen(so, RTLD_GLOBAL|RTLD_NOW); + libpam_h =3D dlopen(so, RTLD_GLOBAL | RTLD_NOW); } return libpam_h !=3D NULL; } @@ -50,16 +56,13 @@ } int -pam_start(const char *service_name, const char *user, - const struct pam_conv *pam_conversation, +pam_start(const char *service_name, const char *user, const struct pam_con= v *pam_conversation, pam_handle_t **pamh) { - int (*real_pam_start)(const char *, const char *, - const struct pam_conv *, - pam_handle_t **); - RESOLVE_PAM_FUNCTION(pam_start, int, (const char *, const char *, - const struct pam_conv *, - pam_handle_t **), PAM_ABORT); + int (*real_pam_start)(const char *, const char *, const struct pam_con= v *, pam_handle_t **); + RESOLVE_PAM_FUNCTION(pam_start, int, + (const char *, const char *, const struct pam_con= v *, pam_handle_t **), + PAM_ABORT); return real_pam_start(service_name, user, pam_conversation, pamh); } @@ -75,8 +78,7 @@ pam_set_item(pam_handle_t *pamh, int item_type, const void *item) { int (*real_pam_set_item)(pam_handle_t *, int, const void *); - RESOLVE_PAM_FUNCTION(pam_set_item, int, - (pam_handle_t *, int, const void *), PAM_ABORT); + RESOLVE_PAM_FUNCTION(pam_set_item, int, (pam_handle_t *, int, const vo= id *), PAM_ABORT); return real_pam_set_item(pamh, item_type, item); } @@ -84,9 +86,7 @@ pam_get_item(const pam_handle_t *pamh, int item_type, const void **item) { int (*real_pam_get_item)(const pam_handle_t *, int, const void **); - RESOLVE_PAM_FUNCTION(pam_get_item, int, - (const pam_handle_t *, int, const void **), - PAM_ABORT); + RESOLVE_PAM_FUNCTION(pam_get_item, int, (const pam_handle_t *, int, co= nst void **), PAM_ABORT); return real_pam_get_item(pamh, item_type, item); } @@ -94,8 +94,7 @@ pam_fail_delay(pam_handle_t *pamh, unsigned int musec_delay) { int (*real_pam_fail_delay)(pam_handle_t *, unsigned int); - RESOLVE_PAM_FUNCTION(pam_fail_delay, int, (pam_handle_t *, unsigned in= t), - PAM_ABORT); + RESOLVE_PAM_FUNCTION(pam_fail_delay, int, (pam_handle_t *, unsigned in= t), PAM_ABORT); return real_pam_fail_delay(pamh, musec_delay); } @@ -105,8 +104,7 @@ pam_strerror(pam_handle_t *pamh, int errnum) { const_char_pointer (*real_pam_strerror)(pam_handle_t *, int); - RESOLVE_PAM_FUNCTION(pam_strerror, const_char_pointer, - (pam_handle_t *, int), NULL); + RESOLVE_PAM_FUNCTION(pam_strerror, const_char_pointer, (pam_handle_t *= , int), NULL); return real_pam_strerror(pamh, errnum); } @@ -114,8 +112,7 @@ pam_putenv(pam_handle_t *pamh, const char *name_value) { int (*real_pam_putenv)(pam_handle_t *, const char *); - RESOLVE_PAM_FUNCTION(pam_putenv, int, (pam_handle_t *, const char *), - PAM_ABORT); + RESOLVE_PAM_FUNCTION(pam_putenv, int, (pam_handle_t *, const char *), = PAM_ABORT); return real_pam_putenv(pamh, name_value); } @@ -123,8 +120,7 @@ pam_getenv(pam_handle_t *pamh, const char *name) { const_char_pointer (*real_pam_getenv)(pam_handle_t *, const char *); - RESOLVE_PAM_FUNCTION(pam_getenv, const_char_pointer, - (pam_handle_t *, const char *), NULL); + RESOLVE_PAM_FUNCTION(pam_getenv, const_char_pointer, (pam_handle_t *, = const char *), NULL); return real_pam_getenv(pamh, name); } @@ -133,8 +129,7 @@ pam_getenvlist(pam_handle_t *pamh) { char_ppointer (*real_pam_getenvlist)(pam_handle_t *); - RESOLVE_PAM_FUNCTION(pam_getenvlist, char_ppointer, (pam_handle_t *), - NULL); + RESOLVE_PAM_FUNCTION(pam_getenvlist, char_ppointer, (pam_handle_t *), = NULL); return real_pam_getenvlist(pamh); } @@ -144,8 +139,7 @@ pam_authenticate(pam_handle_t *pamh, int flags) { int (*real_pam_authenticate)(pam_handle_t *, int); - RESOLVE_PAM_FUNCTION(pam_authenticate, int, (pam_handle_t *, int), - PAM_ABORT); + RESOLVE_PAM_FUNCTION(pam_authenticate, int, (pam_handle_t *, int), PAM= _ABORT); return real_pam_authenticate(pamh, flags); } @@ -173,8 +167,7 @@ pam_open_session(pam_handle_t *pamh, int flags) { int (*real_pam_open_session)(pam_handle_t *, int); - RESOLVE_PAM_FUNCTION(pam_open_session, int, (pam_handle_t *, int), - PAM_ABORT); + RESOLVE_PAM_FUNCTION(pam_open_session, int, (pam_handle_t *, int), PAM= _ABORT); return real_pam_open_session(pamh, flags); } @@ -182,8 +175,7 @@ pam_close_session(pam_handle_t *pamh, int flags) { int (*real_pam_close_session)(pam_handle_t *, int); - RESOLVE_PAM_FUNCTION(pam_close_session, int, (pam_handle_t *, int), - PAM_ABORT); + RESOLVE_PAM_FUNCTION(pam_close_session, int, (pam_handle_t *, int), PA= M_ABORT); return real_pam_close_session(pamh, flags); } diff --git a/src/plugins/auth-pam/utils.c b/src/plugins/auth-pam/utils.c index a6ccfbf..68216e4 100644 --- a/src/plugins/auth-pam/utils.c +++ b/src/plugins/auth-pam/utils.c @@ -56,7 +56,8 @@ return NULL; } - bool is_potential_integer_overflow =3D (templen =3D=3D SIZE_MAX) || (= templen / tosearchlen !=3D replacewithlen); + bool is_potential_integer_overflow =3D + (templen =3D=3D SIZE_MAX) || (templen / tosearchlen !=3D replacewi= thlen); if (is_potential_integer_overflow) { @@ -68,7 +69,7 @@ const char *searching =3D tosearch; char *scratch; - char temp[templen+1]; + char temp[templen + 1]; temp[0] =3D 0; scratch =3D strstr(searching, searchfor); @@ -79,10 +80,10 @@ while (scratch) { - strncat(temp, searching, scratch-searching); + strncat(temp, searching, scratch - searching); strcat(temp, replacewith); - searching =3D scratch+strlen(searchfor); + searching =3D scratch + strlen(searchfor); scratch =3D strstr(searching, searchfor); } return strdup(temp); diff --git a/src/plugins/auth-pam/utils.h b/src/plugins/auth-pam/utils.h index 844d2d1..916584a 100644 --- a/src/plugins/auth-pam/utils.h +++ b/src/plugins/auth-pam/utils.h @@ -35,11 +35,10 @@ * @param searchfor needle to search for in the haystack * @param replacewith when a match is found, replace needle with this s= tring * - * @return Returns NULL when any parameter is NULL or the worst-case resu= lt is to large ( >=3D SIZE_MAX). - * Otherwise it returns a pointer to a new buffer containing the = modified input + * @return Returns NULL when any parameter is NULL or the worst-case resu= lt is to large ( >=3D + * SIZE_MAX). Otherwise it returns a pointer to a new buffer containing th= e modified input */ -char * -searchandreplace(const char *tosearch, const char *searchfor, const char *= replacewith); +char *searchandreplace(const char *tosearch, const char *searchfor, const = char *replacewith); /** * Given an environmental variable name, search @@ -48,10 +47,10 @@ * @param name Environment variable to look up * @param envp Environment variable table with all key/value pairs * - * @return Returns a pointer to the value of the environment variable if f= ound, otherwise NULL is returned. + * @return Returns a pointer to the value of the environment variable if f= ound, otherwise NULL is + * returned. */ -const char * -get_env(const char *name, const char *envp[]); +const char *get_env(const char *name, const char *envp[]); /** * Return the length of a string array @@ -59,7 +58,6 @@ * @param array Pointer to the array to calculate size of * */ -int -string_array_len(const char *array[]); +int string_array_len(const char *array[]); #endif diff --git a/src/plugins/down-root/down-root.c b/src/plugins/down-root/down= -root.c index 253adcd..795a887 100644 --- a/src/plugins/down-root/down-root.c +++ b/src/plugins/down-root/down-root.c @@ -144,11 +144,11 @@ static int send_control(int fd, int code) { - unsigned char c =3D (unsigned char) code; + unsigned char c =3D (unsigned char)code; const ssize_t size =3D write(fd, &c, sizeof(c)); if (size =3D=3D sizeof(c)) { - return (int) size; + return (int)size; } else { @@ -254,7 +254,7 @@ int ret =3D 0; pid =3D fork(); - if (pid =3D=3D (pid_t)0) /* child side */ + if (pid =3D=3D (pid_t)0) /* child side */ { execve(argv[0], argv, envp); /* If execve() fails to run, exit child with exit code 127 */ @@ -265,12 +265,13 @@ warn("DOWN-ROOT: Failed to fork child to run %s", argv[0]); return -1; } - else /* parent side */ + else /* parent side */ { if (waitpid(pid, &ret, 0) !=3D pid) { /* waitpid does not return error information via errno */ - fprintf(stderr, "DOWN-ROOT: waitpid() failed, don't know exit = code of child (%s)\n", argv[0]); + fprintf(stderr, "DOWN-ROOT: waitpid() failed, don't know exit = code of child (%s)\n", + argv[0]); return -1; } } @@ -286,7 +287,7 @@ /* * Allocate our context */ - context =3D (struct down_root_context *) calloc(1, sizeof(struct down_= root_context)); + context =3D (struct down_root_context *)calloc(1, sizeof(struct down_r= oot_context)); if (!context) { warn("DOWN-ROOT: Could not allocate memory for plug-in context"); @@ -322,7 +323,7 @@ /* Ignore argv[0], as it contains just the plug-in file name */ for (i =3D 1; i < string_array_len(argv); i++) { - context->command[i-1] =3D (char *) argv[i]; + context->command[i - 1] =3D (char *)argv[i]; } /* @@ -336,7 +337,7 @@ } } - return (openvpn_plugin_handle_t) context; + return (openvpn_plugin_handle_t)context; error: free_context(context); @@ -344,11 +345,13 @@ } OPENVPN_EXPORT int -openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], const char *envp[]) +openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, con= st char *argv[], + const char *envp[]) { - struct down_root_context *context =3D (struct down_root_context *) han= dle; + struct down_root_context *context =3D (struct down_root_context *)hand= le; - if (type =3D=3D OPENVPN_PLUGIN_UP && context->foreground_fd =3D=3D -1)= /* fork off a process to hold onto root */ + if (type =3D=3D OPENVPN_PLUGIN_UP + && context->foreground_fd =3D=3D -1) /* fork off a process to hold= onto root */ { pid_t pid; int fd[2]; @@ -412,7 +415,7 @@ daemonize(envp); /* execute the event loop */ - down_root_server(fd[1], context->command, (char *const *) envp= , context->verb); + down_root_server(fd[1], context->command, (char *const *)envp,= context->verb); close(fd[1]); exit(0); @@ -434,7 +437,8 @@ } if (status =3D=3D -1) { - warn("DOWN-ROOT: Error receiving script execution confirma= tion from background process"); + warn( + "DOWN-ROOT: Error receiving script execution confirmat= ion from background process"); } } } @@ -444,7 +448,7 @@ OPENVPN_EXPORT void openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) { - struct down_root_context *context =3D (struct down_root_context *) han= dle; + struct down_root_context *context =3D (struct down_root_context *)hand= le; if (DEBUG(context->verb)) { @@ -475,7 +479,7 @@ OPENVPN_EXPORT void openvpn_plugin_abort_v1(openvpn_plugin_handle_t handle) { - struct down_root_context *context =3D (struct down_root_context *) han= dle; + struct down_root_context *context =3D (struct down_root_context *)hand= le; if (context && context->foreground_fd >=3D 0) { @@ -528,7 +532,7 @@ switch (command_code) { case COMMAND_RUN_SCRIPT: - if ( (exit_code =3D run_script(argv, envp)) =3D=3D 0) /* S= ucceeded */ + if ((exit_code =3D run_script(argv, envp)) =3D=3D 0) /* Su= cceeded */ { if (send_control(fd, RESPONSE_SCRIPT_SUCCEEDED) =3D=3D= -1) { @@ -538,7 +542,8 @@ } else /* Failed */ { - fprintf(stderr, "DOWN-ROOT: BACKGROUND: %s exited with= exit code %i\n", argv[0], exit_code); + fprintf(stderr, "DOWN-ROOT: BACKGROUND: %s exited with= exit code %i\n", argv[0], + exit_code); if (send_control(fd, RESPONSE_SCRIPT_FAILED) =3D=3D -1) { warn("DOWN-ROOT: BACKGROUND: write error on respon= se socket [3]"); diff --git a/src/tapctl/basic.h b/src/tapctl/basic.h index 3814db1..ad8b3fa 100644 --- a/src/tapctl/basic.h +++ b/src/tapctl/basic.h @@ -27,14 +27,16 @@ #define UNICODE #endif -#define PRIXGUID "{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hh= X%02hhX%02hhX%02hhX}" -#define PRIGUID_PARAM(g) \ - (g).Data1, (g).Data2, (g).Data3, (g).Data4[0], (g).Data4[1], (g).Data4= [2], (g).Data4[3], (g).Data4[4], (g).Data4[5], (g).Data4[6], (g).Data4[7] -#define PRIGUID_PARAM_REF(g) \ - &(g).Data1, &(g).Data2, &(g).Data3, &(g).Data4[0], &(g).Data4[1], &(g)= .Data4[2], &(g).Data4[3], &(g).Data4[4], &(g).Data4[5], &(g).Data4[6], &(g)= .Data4[7] +#define PRIXGUID "{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX= %02hhX%02hhX}" +#define PRIGUID_PARAM(g) = \ + (g).Data1, (g).Data2, (g).Data3, (g).Data4[0], (g).Data4[1], (g).Data4= [2], (g).Data4[3], \ + (g).Data4[4], (g).Data4[5], (g).Data4[6], (g).Data4[7] +#define PRIGUID_PARAM_REF(g) = \ + &(g).Data1, &(g).Data2, &(g).Data3, &(g).Data4[0], &(g).Data4[1], &(g)= .Data4[2], \ + &(g).Data4[3], &(g).Data4[4], &(g).Data4[5], &(g).Data4[6], &(g).D= ata4[7] -#define __L(q) L ## q -#define _L(q) __L(q) +#define __L(q) L##q +#define _L(q) __L(q) #ifndef _In_ #define _In_ diff --git a/src/tapctl/error.h b/src/tapctl/error.h index 42c175e..382d9eb 100644 --- a/src/tapctl/error.h +++ b/src/tapctl/error.h @@ -35,27 +35,27 @@ /* msg() flags */ -#define M_DEBUG_LEVEL (0x0F) /* debug level mask */ +#define M_DEBUG_LEVEL (0x0F) /* debug level mask */ -#define M_FATAL (1<<4) /* exit program */ -#define M_NONFATAL (1<<5) /* non-fatal error */ -#define M_WARN (1<<6) /* call syslog with LOG_WARNING */ -#define M_DEBUG (1<<7) +#define M_FATAL (1 << 4) /* exit program */ +#define M_NONFATAL (1 << 5) /* non-fatal error */ +#define M_WARN (1 << 6) /* call syslog with LOG_WARNING */ +#define M_DEBUG (1 << 7) -#define M_ERRNO (1<<8) /* show errno description */ +#define M_ERRNO (1 << 8) /* show errno description */ =20 -#define M_NOMUTE (1<<11) /* don't do mute processing */ -#define M_NOPREFIX (1<<12) /* don't show date/time prefix */ -#define M_USAGE_SMALL (1<<13) /* fatal options error, call usag= e_small */ -#define M_MSG_VIRT_OUT (1<<14) /* output message through msg_sta= tus_output callback */ -#define M_OPTERR (1<<15) /* print "Options error:" prefix = */ -#define M_NOLF (1<<16) /* don't print new line */ -#define M_NOIPREFIX (1<<17) /* don't print instance prefix */ +#define M_NOMUTE (1 << 11) /* don't do mute processing */ +#define M_NOPREFIX (1 << 12) /* don't show date/time prefix */ +#define M_USAGE_SMALL (1 << 13) /* fatal options error, call usage_small = */ +#define M_MSG_VIRT_OUT (1 << 14) /* output message through msg_status_outp= ut callback */ +#define M_OPTERR (1 << 15) /* print "Options error:" prefix */ +#define M_NOLF (1 << 16) /* don't print new line */ +#define M_NOIPREFIX (1 << 17) /* don't print instance prefix */ /* flag combinations which are frequently used */ -#define M_ERR (M_FATAL | M_ERRNO) -#define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR) -#define M_CLIENT (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX) +#define M_ERR (M_FATAL | M_ERRNO) +#define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR) +#define M_CLIENT (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX) /** Check muting filter */ @@ -63,18 +63,42 @@ /* Macro to ensure (and teach static analysis tools) we exit on fatal erro= rs */ #ifdef _MSC_VER -#pragma warning(disable: 4127) /* EXIT_FATAL(flags) macro raises "warning = C4127: conditional expression is constant" on each non M_FATAL invocation. = */ +#pragma warning(disable : 4127) /* EXIT_FATAL(flags) macro raises "warning= C4127: conditional \ + expression is constant" on each non M_F= ATAL invocation. */ #endif -#define EXIT_FATAL(flags) do { if ((flags) & M_FATAL) {_exit(1);}} while (= false) +#define EXIT_FATAL(flags) \ + do \ + { \ + if ((flags) & M_FATAL) \ + { \ + _exit(1); \ + } \ + } while (false) -#define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARG= S__);} EXIT_FATAL(flags); } while (false) +#define msg(flags, ...) \ + do \ + { \ + if (msg_test(flags)) \ + { \ + x_msg((flags), __VA_ARGS__); \ + } \ + EXIT_FATAL(flags); \ + } while (false) #ifdef ENABLE_DEBUG -#define dmsg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_AR= GS__);} EXIT_FATAL(flags); } while (false) +#define dmsg(flags, ...) \ + do \ + { \ + if (msg_test(flags)) \ + { \ + x_msg((flags), __VA_ARGS__); \ + } \ + EXIT_FATAL(flags); \ + } while (false) #else #define dmsg(flags, ...) #endif -void x_msg(const unsigned int flags, const char *format, ...); /* shou= ld be called via msg above */ +void x_msg(const unsigned int flags, const char *format, ...); /* should b= e called via msg above */ void x_msg_va(const unsigned int flags, const char *format, va_list arglis= t); diff --git a/src/tapctl/main.c b/src/tapctl/main.c index a67540d..2d1ccc3 100644 --- a/src/tapctl/main.c +++ b/src/tapctl/main.c @@ -121,9 +121,7 @@ static void usage(void) { - fwprintf(stderr, - usage_message, - title_string); + fwprintf(stderr, usage_message, title_string); } /** @@ -140,8 +138,10 @@ { LPOLESTR adapter_id =3D NULL; StringFromIID((REFIID)&a->guid, &adapter_id); - fwprintf(stderr, L"Adapter \"%ls\" already exists (GUID %" - L"ls).\n", a->szName, adapter_id); + fwprintf(stderr, + L"Adapter \"%ls\" already exists (GUID %" + L"ls).\n", + a->szName, adapter_id); CoTaskMemFree(adapter_id); } @@ -205,8 +205,7 @@ /** * Program entry point */ -int __cdecl -wmain(int argc, LPCWSTR argv[]) +int __cdecl wmain(int argc, LPCWSTR argv[]) { int iResult; BOOL bRebootRequired =3D FALSE; @@ -240,8 +239,10 @@ } else { - fwprintf(stderr, L"Unknown command \"%ls" - L"\". Please, use \"tapctl help\" to list supported c= ommands.\n", argv[2]); + fwprintf(stderr, + L"Unknown command \"%ls" + L"\". Please, use \"tapctl help\" to list supported c= ommands.\n", + argv[2]); } return 1; @@ -264,25 +265,24 @@ } else { - fwprintf(stderr, L"Unknown option \"%ls" - L"\". Please, use \"tapctl help create\" to list = supported options. Ignored.\n", - argv[i]); + fwprintf( + stderr, + L"Unknown option \"%ls" + L"\". Please, use \"tapctl help create\" to list suppo= rted options. Ignored.\n", + argv[i]); } } /* Create TUN/TAP adapter. */ GUID guidAdapter; LPOLESTR szAdapterId =3D NULL; - DWORD dwResult =3D tap_create_adapter( - NULL, - L"Virtual Ethernet", - szHwId, - &bRebootRequired, - &guidAdapter); + DWORD dwResult =3D + tap_create_adapter(NULL, L"Virtual Ethernet", szHwId, &bReboot= Required, &guidAdapter); if (dwResult !=3D ERROR_SUCCESS) { fwprintf(stderr, L"Creating TUN/TAP adapter failed (error 0x%x= ).\n", dwResult); - iResult =3D 1; goto quit; + iResult =3D 1; + goto quit; } /* Get existing network adapters. */ @@ -295,7 +295,8 @@ goto create_delete_adapter; } - LPWSTR adapter_name =3D szName ? wcsdup(szName) : get_unique_adapt= er_name(szHwId, pAdapterList); + LPWSTR adapter_name =3D + szName ? wcsdup(szName) : get_unique_adapter_name(szHwId, pAda= pterList); if (adapter_name) { /* Check for duplicates when name was specified, @@ -311,11 +312,13 @@ if (dwResult !=3D ERROR_SUCCESS) { StringFromIID((REFIID)&guidAdapter, &szAdapterId); - fwprintf(stderr, L"Renaming TUN/TAP adapter %ls" + fwprintf(stderr, + L"Renaming TUN/TAP adapter %ls" L" to \"%ls\" failed (error 0x%x).\n", szAdapterId, adapter_name, dwResult); CoTaskMemFree(szAdapterId); - iResult =3D 1; goto quit; + iResult =3D 1; + goto quit; } } @@ -335,21 +338,19 @@ fwprintf(stdout, L"%ls\n", szAdapterId); CoTaskMemFree(szAdapterId); - iResult =3D 0; goto quit; + iResult =3D 0; + goto quit; create_delete_adapter: - tap_delete_adapter( - NULL, - &guidAdapter, - &bRebootRequired); - iResult =3D 1; goto quit; + tap_delete_adapter(NULL, &guidAdapter, &bRebootRequired); + iResult =3D 1; + goto quit; } else if (wcsicmp(argv[1], L"list") =3D=3D 0) { WCHAR szzHwId[0x100] =3D - L"root\\" _L(TAP_WIN_COMPONENT_ID) L"\0" - _L(TAP_WIN_COMPONENT_ID) L"\0" - L"ovpn-dco\0"; + L"root\\" _L(TAP_WIN_COMPONENT_ID) L"\0" _L(TAP_WIN_COMPONENT_= ID) L"\0" + = L"ovpn-dco\0"; /* Parse options. */ for (int i =3D 2; i < argc; i++) @@ -358,13 +359,17 @@ { memset(szzHwId, 0, sizeof(szzHwId)); ++i; - memcpy_s(szzHwId, sizeof(szzHwId) - 2*sizeof(WCHAR) /*requ= ires double zero termination*/, argv[i], wcslen(argv[i])*sizeof(WCHAR)); + memcpy_s(szzHwId, + sizeof(szzHwId) - 2 * sizeof(WCHAR) /*requires do= uble zero termination*/, + argv[i], wcslen(argv[i]) * sizeof(WCHAR)); } else { - fwprintf(stderr, L"Unknown option \"%ls" - L"\". Please, use \"tapctl help list\" to list su= pported options. Ignored.\n", - argv[i]); + fwprintf( + stderr, + L"Unknown option \"%ls" + L"\". Please, use \"tapctl help list\" to list support= ed options. Ignored.\n", + argv[i]); } } @@ -374,15 +379,18 @@ if (dwResult !=3D ERROR_SUCCESS) { fwprintf(stderr, L"Enumerating TUN/TAP adapters failed (error = 0x%x).\n", dwResult); - iResult =3D 1; goto quit; + iResult =3D 1; + goto quit; } for (struct tap_adapter_node *pAdapter =3D pAdapterList; pAdapter;= pAdapter =3D pAdapter->pNext) { LPOLESTR szAdapterId =3D NULL; StringFromIID((REFIID)&pAdapter->guid, &szAdapterId); - fwprintf(stdout, L"%ls\t%" - L"ls\n", szAdapterId, pAdapter->szName); + fwprintf(stdout, + L"%ls\t%" + L"ls\n", + szAdapterId, pAdapter->szName); CoTaskMemFree(szAdapterId); } @@ -393,7 +401,9 @@ { if (argc < 3) { - fwprintf(stderr, L"Missing adapter GUID or name. Please, use \= "tapctl help delete\" for usage info.\n"); + fwprintf( + stderr, + L"Missing adapter GUID or name. Please, use \"tapctl help = delete\" for usage info.\n"); return 1; } @@ -406,7 +416,8 @@ if (dwResult !=3D ERROR_SUCCESS) { fwprintf(stderr, L"Enumerating TUN/TAP adapters failed (er= ror 0x%x).\n", dwResult); - iResult =3D 1; goto quit; + iResult =3D 1; + goto quit; } for (struct tap_adapter_node *pAdapter =3D pAdapterList;; pAda= pter =3D pAdapter->pNext) @@ -414,7 +425,8 @@ if (pAdapter =3D=3D NULL) { fwprintf(stderr, L"\"%ls\" adapter not found.\n", argv= [2]); - iResult =3D 1; goto delete_cleanup_pAdapterList; + iResult =3D 1; + goto delete_cleanup_pAdapterList; } else if (wcsicmp(argv[2], pAdapter->szName) =3D=3D 0) { @@ -434,23 +446,26 @@ } /* Delete the network adapter. */ - DWORD dwResult =3D tap_delete_adapter( - NULL, - &guidAdapter, - &bRebootRequired); + DWORD dwResult =3D tap_delete_adapter(NULL, &guidAdapter, &bReboot= Required); if (dwResult !=3D ERROR_SUCCESS) { - fwprintf(stderr, L"Deleting adapter \"%ls" - L"\" failed (error 0x%x).\n", argv[2], dwResult); - iResult =3D 1; goto quit; + fwprintf(stderr, + L"Deleting adapter \"%ls" + L"\" failed (error 0x%x).\n", + argv[2], dwResult); + iResult =3D 1; + goto quit; } - iResult =3D 0; goto quit; + iResult =3D 0; + goto quit; } else { - fwprintf(stderr, L"Unknown command \"%ls" - L"\". Please, use \"tapctl help\" to list supported comma= nds.\n", argv[1]); + fwprintf(stderr, + L"Unknown command \"%ls" + L"\". Please, use \"tapctl help\" to list supported comma= nds.\n", + argv[1]); return 1; } @@ -485,16 +500,13 @@ /* Output system error message (if possible). */ DWORD dwResult =3D GetLastError(); LPWSTR szErrMessage =3D NULL; - if (FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFE= R | FORMAT_MESSAGE_IGNORE_INSERTS, - 0, - dwResult, - 0, - (LPWSTR)&szErrMessage, - 0, - NULL) && szErrMessage) + if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLO= CATE_BUFFER + | FORMAT_MESSAGE_IGNORE_INSERTS, + 0, dwResult, 0, (LPWSTR)&szErrMessage, 0, NULL) + && szErrMessage) { - /* Trim trailing whitespace. Set terminator after the last non= -whitespace character. This prevents excessive trailing line breaks. */ + /* Trim trailing whitespace. Set terminator after the last non= -whitespace character. + * This prevents excessive trailing line breaks. */ for (size_t i =3D 0, i_last =3D 0;; i++) { if (szErrMessage[i]) diff --git a/src/tapctl/tap.c b/src/tapctl/tap.c index 39b43ac..eb4432a 100644 --- a/src/tapctl/tap.c +++ b/src/tapctl/tap.c @@ -41,10 +41,15 @@ #endif -const static GUID GUID_DEVCLASS_NET =3D { 0x4d36e972L, 0xe325, 0x11ce, { 0= xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } }; +const static GUID GUID_DEVCLASS_NET =3D { + 0x4d36e972L, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x0= 3, 0x18 } +}; -const static WCHAR szAdapterRegKeyPathTemplate[] =3D L"SYSTEM\\CurrentCont= rolSet\\Control\\Network\\%ls\\%ls\\Connection"; -#define ADAPTER_REGKEY_PATH_MAX (_countof(L"SYSTEM\\CurrentControlSet\\Con= trol\\Network\\") - 1 + 38 + _countof(L"\\") - 1 + 38 + _countof(L"\\Connec= tion")) +const static WCHAR szAdapterRegKeyPathTemplate[] =3D + L"SYSTEM\\CurrentControlSet\\Control\\Network\\%ls\\%ls\\Connection"; +#define ADAPTER_REGKEY_PATH_MAX = \ + (_countof(L"SYSTEM\\CurrentControlSet\\Control\\Network\\") - 1 + 38 += _countof(L"\\") - 1 \ + + 38 + _countof(L"\\Connection")) /** * Dynamically load a library and find a function in it @@ -155,10 +160,8 @@ * * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ -typedef DWORD (*devop_func_t)( - _In_ HDEVINFO hDeviceInfoSet, - _In_ PSP_DEVINFO_DATA pDeviceInfoData, - _Inout_ LPBOOL pbRebootRequired); +typedef DWORD (*devop_func_t)(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVIN= FO_DATA pDeviceInfoData, + _Inout_ LPBOOL pbRebootRequired); /** @@ -178,10 +181,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ static DWORD -check_reboot( - _In_ HDEVINFO hDeviceInfoSet, - _In_ PSP_DEVINFO_DATA pDeviceInfoData, - _Inout_ LPBOOL pbRebootRequired) +check_reboot(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceIn= foData, + _Inout_ LPBOOL pbRebootRequired) { if (pbRebootRequired =3D=3D NULL) { @@ -189,10 +190,7 @@ } SP_DEVINSTALL_PARAMS devinstall_params =3D { .cbSize =3D sizeof(SP_DEV= INSTALL_PARAMS) }; - if (!SetupDiGetDeviceInstallParams( - hDeviceInfoSet, - pDeviceInfoData, - &devinstall_params)) + if (!SetupDiGetDeviceInstallParams(hDeviceInfoSet, pDeviceInfoData, &d= evinstall_params)) { DWORD dwResult =3D GetLastError(); msg(M_NONFATAL | M_ERRNO, "%s: SetupDiGetDeviceInstallParams faile= d", __FUNCTION__); @@ -225,10 +223,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ static DWORD -delete_device( - _In_ HDEVINFO hDeviceInfoSet, - _In_ PSP_DEVINFO_DATA pDeviceInfoData, - _Inout_ LPBOOL pbRebootRequired) +delete_device(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceI= nfoData, + _Inout_ LPBOOL pbRebootRequired) { SP_REMOVEDEVICE_PARAMS params =3D { @@ -242,11 +238,8 @@ }; /* Set class installer parameters for DIF_REMOVE. */ - if (!SetupDiSetClassInstallParams( - hDeviceInfoSet, - pDeviceInfoData, - ¶ms.ClassInstallHeader, - sizeof(SP_REMOVEDEVICE_PARAMS))) + if (!SetupDiSetClassInstallParams(hDeviceInfoSet, pDeviceInfoData, &pa= rams.ClassInstallHeader, + sizeof(SP_REMOVEDEVICE_PARAMS))) { DWORD dwResult =3D GetLastError(); msg(M_NONFATAL | M_ERRNO, "%s: SetupDiSetClassInstallParams failed= ", __FUNCTION__); @@ -254,10 +247,7 @@ } /* Call appropriate class installer. */ - if (!SetupDiCallClassInstaller( - DIF_REMOVE, - hDeviceInfoSet, - pDeviceInfoData)) + if (!SetupDiCallClassInstaller(DIF_REMOVE, hDeviceInfoSet, pDeviceInfo= Data)) { DWORD dwResult =3D GetLastError(); msg(M_NONFATAL | M_ERRNO, "%s: SetupDiCallClassInstaller(DIF_REMOV= E) failed", __FUNCTION__); @@ -289,11 +279,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ static DWORD -change_device_state( - _In_ HDEVINFO hDeviceInfoSet, - _In_ PSP_DEVINFO_DATA pDeviceInfoData, - _In_ BOOL bEnable, - _Inout_ LPBOOL pbRebootRequired) +change_device_state(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pD= eviceInfoData, + _In_ BOOL bEnable, _Inout_ LPBOOL pbRebootRequired) { SP_PROPCHANGE_PARAMS params =3D { @@ -308,11 +295,8 @@ }; /* Set class installer parameters for DIF_PROPERTYCHANGE. */ - if (!SetupDiSetClassInstallParams( - hDeviceInfoSet, - pDeviceInfoData, - ¶ms.ClassInstallHeader, - sizeof(SP_PROPCHANGE_PARAMS))) + if (!SetupDiSetClassInstallParams(hDeviceInfoSet, pDeviceInfoData, &pa= rams.ClassInstallHeader, + sizeof(SP_PROPCHANGE_PARAMS))) { DWORD dwResult =3D GetLastError(); msg(M_NONFATAL | M_ERRNO, "%s: SetupDiSetClassInstallParams failed= ", __FUNCTION__); @@ -320,13 +304,11 @@ } /* Call appropriate class installer. */ - if (!SetupDiCallClassInstaller( - DIF_PROPERTYCHANGE, - hDeviceInfoSet, - pDeviceInfoData)) + if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDeviceInfoSet, pDe= viceInfoData)) { DWORD dwResult =3D GetLastError(); - msg(M_NONFATAL | M_ERRNO, "%s: SetupDiCallClassInstaller(DIF_PROPE= RTYCHANGE) failed", __FUNCTION__); + msg(M_NONFATAL | M_ERRNO, "%s: SetupDiCallClassInstaller(DIF_PROPE= RTYCHANGE) failed", + __FUNCTION__); return dwResult; } @@ -353,10 +335,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ static DWORD -enable_device( - _In_ HDEVINFO hDeviceInfoSet, - _In_ PSP_DEVINFO_DATA pDeviceInfoData, - _Inout_ LPBOOL pbRebootRequired) +enable_device(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceI= nfoData, + _Inout_ LPBOOL pbRebootRequired) { return change_device_state(hDeviceInfoSet, pDeviceInfoData, TRUE, pbRe= bootRequired); } @@ -379,10 +359,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ static DWORD -disable_device( - _In_ HDEVINFO hDeviceInfoSet, - _In_ PSP_DEVINFO_DATA pDeviceInfoData, - _Inout_ LPBOOL pbRebootRequired) +disable_device(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDevice= InfoData, + _Inout_ LPBOOL pbRebootRequired) { return change_device_state(hDeviceInfoSet, pDeviceInfoData, FALSE, pbR= ebootRequired); } @@ -403,10 +381,7 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise */ static DWORD -get_reg_string( - _In_ HKEY hKey, - _In_ LPCWSTR szName, - _Out_ LPWSTR *pszValue) +get_reg_string(_In_ HKEY hKey, _In_ LPCWSTR szName, _Out_ LPWSTR *pszValue) { if (pszValue =3D=3D NULL) { @@ -414,17 +389,13 @@ } DWORD dwValueType =3D REG_NONE, dwSize =3D 0; - DWORD dwResult =3D RegQueryValueEx( - hKey, - szName, - NULL, - &dwValueType, - NULL, - &dwSize); + DWORD dwResult =3D RegQueryValueEx(hKey, szName, NULL, &dwValueType, N= ULL, &dwSize); if (dwResult !=3D ERROR_SUCCESS) { - SetLastError(dwResult); /* MSDN does not mention RegQueryValueEx()= to set GetLastError(). But we do have an error code. Set last error manual= ly. */ - msg(M_NONFATAL | M_ERRNO, "%s: enumerating \"%ls\" registry value = failed", __FUNCTION__, szName); + SetLastError(dwResult); /* MSDN does not mention RegQueryValueEx()= to set GetLastError(). + But we do have an error code. Set last = error manually. */ + msg(M_NONFATAL | M_ERRNO, "%s: enumerating \"%ls\" registry value = failed", __FUNCTION__, + szName); return dwResult; } @@ -441,17 +412,14 @@ return ERROR_OUTOFMEMORY; } - dwResult =3D RegQueryValueEx( - hKey, - szName, - NULL, - NULL, - (LPBYTE)szValue, - &dwSize); + dwResult =3D RegQueryValueEx(hKey, szName, NULL, NULL, (LPBYTE= )szValue, &dwSize); if (dwResult !=3D ERROR_SUCCESS) { - SetLastError(dwResult); /* MSDN does not mention RegQueryV= alueEx() to set GetLastError(). But we do have an error code. Set last erro= r manually. */ - msg(M_NONFATAL | M_ERRNO, "%s: reading \"%ls\" registry va= lue failed", __FUNCTION__, szName); + SetLastError( + dwResult); /* MSDN does not mention RegQueryValueEx() = to set GetLastError(). But + we do have an error code. Set last error= manually. */ + msg(M_NONFATAL | M_ERRNO, "%s: reading \"%ls\" registry va= lue failed", __FUNCTION__, + szName); free(szValue); return dwResult; } @@ -460,12 +428,12 @@ { /* Expand the environment strings. */ DWORD - dwSizeExp =3D dwSize * 2, - dwCountExp =3D + dwSizeExp =3D dwSize * 2, dwCountExp =3D #ifdef UNICODE - dwSizeExp / sizeof(WCHAR); + dwSizeExp / sizeof(WCHAR); #else - dwSizeExp / sizeof(WCHAR) - 1; /* Note: ANSI versi= on requires one extra char. */ + dwSizeExp / sizeof(WCHAR) + - 1; /* Note: ANSI version req= uires one extra char. */ #endif LPWSTR szValueExp =3D (LPWSTR)malloc(dwSizeExp); if (szValueExp =3D=3D NULL) @@ -475,13 +443,11 @@ return ERROR_OUTOFMEMORY; } - DWORD dwCountExpResult =3D ExpandEnvironmentStrings( - szValue, - szValueExp, dwCountExp - ); + DWORD dwCountExpResult =3D ExpandEnvironmentStrings(szValu= e, szValueExp, dwCountExp); if (dwCountExpResult =3D=3D 0) { - msg(M_NONFATAL | M_ERRNO, "%s: expanding \"%ls\" regis= try value failed", __FUNCTION__, szName); + msg(M_NONFATAL | M_ERRNO, "%s: expanding \"%ls\" regis= try value failed", + __FUNCTION__, szName); free(szValueExp); free(szValue); return dwResult; @@ -512,9 +478,7 @@ return ERROR_OUTOFMEMORY; } - dwCountExpResult =3D ExpandEnvironmentStrings( - szValue, - szValueExp, dwCountExp); + dwCountExpResult =3D ExpandEnvironmentStrings(szValue,= szValueExp, dwCountExp); free(szValue); *pszValue =3D szValueExp; return ERROR_SUCCESS; @@ -528,7 +492,8 @@ } default: - msg(M_NONFATAL, "%s: \"%ls\" registry value is not string (typ= e %u)", __FUNCTION__, dwValueType); + msg(M_NONFATAL, "%s: \"%ls\" registry value is not string (typ= e %u)", __FUNCTION__, + dwValueType); return ERROR_UNSUPPORTED_TYPE; } } @@ -553,11 +518,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ static DWORD -get_net_adapter_guid( - _In_ HDEVINFO hDeviceInfoSet, - _In_ PSP_DEVINFO_DATA pDeviceInfoData, - _In_ int iNumAttempts, - _Out_ LPGUID pguidAdapter) +get_net_adapter_guid(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA p= DeviceInfoData, + _In_ int iNumAttempts, _Out_ LPGUID pguidAdapter) { DWORD dwResult =3D ERROR_BAD_ARGUMENTS; @@ -567,13 +529,8 @@ } /* Open HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\\ registry key. */ - HKEY hKey =3D SetupDiOpenDevRegKey( - hDeviceInfoSet, - pDeviceInfoData, - DICS_FLAG_GLOBAL, - 0, - DIREG_DRV, - KEY_READ); + HKEY hKey =3D SetupDiOpenDevRegKey(hDeviceInfoSet, pDeviceInfoData, DI= CS_FLAG_GLOBAL, 0, + DIREG_DRV, KEY_READ); if (hKey =3D=3D INVALID_HANDLE_VALUE) { dwResult =3D GetLastError(); @@ -583,7 +540,8 @@ while (iNumAttempts > 0) { - /* Query the NetCfgInstanceId value. Using get_reg_string() right = on might clutter the output with error messages while the registry is still= being populated. */ + /* Query the NetCfgInstanceId value. Using get_reg_string() right = on might clutter the + * output with error messages while the registry is still being po= pulated. */ LPWSTR szCfgGuidString =3D NULL; dwResult =3D RegQueryValueEx(hKey, L"NetCfgInstanceId", NULL, NULL= , NULL, NULL); if (dwResult !=3D ERROR_SUCCESS) @@ -595,22 +553,24 @@ continue; } - SetLastError(dwResult); /* MSDN does not mention RegQueryValue= Ex() to set GetLastError(). But we do have an error code. Set last error ma= nually. */ - msg(M_NONFATAL | M_ERRNO, "%s: querying \"NetCfgInstanceId\" r= egistry value failed", __FUNCTION__); + SetLastError( + dwResult); /* MSDN does not mention RegQueryValueEx() to s= et GetLastError(). But we + do have an error code. Set last error manual= ly. */ + msg(M_NONFATAL | M_ERRNO, "%s: querying \"NetCfgInstanceId\" r= egistry value failed", + __FUNCTION__); break; } /* Read the NetCfgInstanceId value now. */ - dwResult =3D get_reg_string( - hKey, - L"NetCfgInstanceId", - &szCfgGuidString); + dwResult =3D get_reg_string(hKey, L"NetCfgInstanceId", &szCfgGuidS= tring); if (dwResult !=3D ERROR_SUCCESS) { break; } - dwResult =3D SUCCEEDED(CLSIDFromString(szCfgGuidString, (LPCLSID)p= guidAdapter)) ? ERROR_SUCCESS : ERROR_INVALID_DATA; + dwResult =3D SUCCEEDED(CLSIDFromString(szCfgGuidString, (LPCLSID)p= guidAdapter)) + ? ERROR_SUCCESS + : ERROR_INVALID_DATA; free(szCfgGuidString); break; } @@ -642,12 +602,9 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ static DWORD -get_device_reg_property( - _In_ HDEVINFO hDeviceInfoSet, - _In_ PSP_DEVINFO_DATA pDeviceInfoData, - _In_ DWORD dwProperty, - _Out_opt_ LPDWORD pdwPropertyRegDataType, - _Out_ LPVOID *ppData) +get_device_reg_property(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DAT= A pDeviceInfoData, + _In_ DWORD dwProperty, _Out_opt_ LPDWORD pdwProper= tyRegDataType, + _Out_ LPVOID *ppData) { DWORD dwResult =3D ERROR_BAD_ARGUMENTS; @@ -659,14 +616,9 @@ /* Try with stack buffer first. */ BYTE bBufStack[128]; DWORD dwRequiredSize =3D 0; - if (SetupDiGetDeviceRegistryProperty( - hDeviceInfoSet, - pDeviceInfoData, - dwProperty, - pdwPropertyRegDataType, - bBufStack, - sizeof(bBufStack), - &dwRequiredSize)) + if (SetupDiGetDeviceRegistryProperty(hDeviceInfoSet, pDeviceInfoData, = dwProperty, + pdwPropertyRegDataType, bBufStack= , sizeof(bBufStack), + &dwRequiredSize)) { /* Copy from stack. */ *ppData =3D malloc(dwRequiredSize); @@ -692,27 +644,24 @@ return ERROR_OUTOFMEMORY; } - if (SetupDiGetDeviceRegistryProperty( - hDeviceInfoSet, - pDeviceInfoData, - dwProperty, - pdwPropertyRegDataType, - *ppData, - dwRequiredSize, - &dwRequiredSize)) + if (SetupDiGetDeviceRegistryProperty(hDeviceInfoSet, pDeviceIn= foData, dwProperty, + pdwPropertyRegDataType, *= ppData, dwRequiredSize, + &dwRequiredSize)) { return ERROR_SUCCESS; } else { dwResult =3D GetLastError(); - msg(M_NONFATAL | M_ERRNO, "%s: SetupDiGetDeviceRegistryPro= perty(%u) failed", __FUNCTION__, dwProperty); + msg(M_NONFATAL | M_ERRNO, "%s: SetupDiGetDeviceRegistryPro= perty(%u) failed", + __FUNCTION__, dwProperty); return dwResult; } } else { - msg(M_NONFATAL | M_ERRNO, "%s: SetupDiGetDeviceRegistryPropert= y(%u) failed", __FUNCTION__, dwProperty); + msg(M_NONFATAL | M_ERRNO, "%s: SetupDiGetDeviceRegistryPropert= y(%u) failed", + __FUNCTION__, dwProperty); return dwResult; } } @@ -720,19 +669,13 @@ DWORD -tap_create_adapter( - _In_opt_ HWND hwndParent, - _In_opt_ LPCWSTR szDeviceDescription, - _In_ LPCWSTR szHwId, - _Inout_ LPBOOL pbRebootRequired, - _Out_ LPGUID pguidAdapter) +tap_create_adapter(_In_opt_ HWND hwndParent, _In_opt_ LPCWSTR szDeviceDesc= ription, + _In_ LPCWSTR szHwId, _Inout_ LPBOOL pbRebootRequired, _= Out_ LPGUID pguidAdapter) { DWORD dwResult; HMODULE libnewdev =3D NULL; - if (szHwId =3D=3D NULL - || pbRebootRequired =3D=3D NULL - || pguidAdapter =3D=3D NULL) + if (szHwId =3D=3D NULL || pbRebootRequired =3D=3D NULL || pguidAdapter= =3D=3D NULL) { return ERROR_BAD_ARGUMENTS; } @@ -748,11 +691,7 @@ /* Get the device class name from GUID. */ WCHAR szClassName[MAX_CLASS_NAME_LEN]; - if (!SetupDiClassNameFromGuid( - &GUID_DEVCLASS_NET, - szClassName, - _countof(szClassName), - NULL)) + if (!SetupDiClassNameFromGuid(&GUID_DEVCLASS_NET, szClassName, _counto= f(szClassName), NULL)) { dwResult =3D GetLastError(); msg(M_NONFATAL, "%s: SetupDiClassNameFromGuid failed", __FUNCTION_= _); @@ -761,14 +700,8 @@ /* Create a new device info element and add it to the device info set.= */ SP_DEVINFO_DATA devinfo_data =3D { .cbSize =3D sizeof(SP_DEVINFO_DATA)= }; - if (!SetupDiCreateDeviceInfo( - hDevInfoList, - szClassName, - &GUID_DEVCLASS_NET, - szDeviceDescription, - hwndParent, - DICD_GENERATE_ID, - &devinfo_data)) + if (!SetupDiCreateDeviceInfo(hDevInfoList, szClassName, &GUID_DEVCLASS= _NET, szDeviceDescription, + hwndParent, DICD_GENERATE_ID, &devinfo_da= ta)) { dwResult =3D GetLastError(); msg(M_NONFATAL, "%s: SetupDiCreateDeviceInfo failed", __FUNCTION__= ); @@ -776,9 +709,7 @@ } /* Set a device information element as the selected member of a device= information set. */ - if (!SetupDiSetSelectedDevice( - hDevInfoList, - &devinfo_data)) + if (!SetupDiSetSelectedDevice(hDevInfoList, &devinfo_data)) { dwResult =3D GetLastError(); msg(M_NONFATAL, "%s: SetupDiSetSelectedDevice failed", __FUNCTION_= _); @@ -786,11 +717,9 @@ } /* Set Plug&Play device hardware ID property. */ - if (!SetupDiSetDeviceRegistryProperty( - hDevInfoList, - &devinfo_data, - SPDRP_HARDWAREID, - (const BYTE *)szHwId, (DWORD)((wcslen(szHwId) + 1) * sizeof(WC= HAR)))) + if (!SetupDiSetDeviceRegistryProperty(hDevInfoList, &devinfo_data, SPD= RP_HARDWAREID, + (const BYTE *)szHwId, + (DWORD)((wcslen(szHwId) + 1) * s= izeof(WCHAR)))) { dwResult =3D GetLastError(); msg(M_NONFATAL, "%s: SetupDiSetDeviceRegistryProperty failed", __F= UNCTION__); @@ -798,10 +727,7 @@ } /* Register the device instance with the PnP Manager */ - if (!SetupDiCallClassInstaller( - DIF_REGISTERDEVICE, - hDevInfoList, - &devinfo_data)) + if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, hDevInfoList, &devi= nfo_data)) { dwResult =3D GetLastError(); msg(M_NONFATAL, "%s: SetupDiCallClassInstaller(DIF_REGISTERDEVICE)= failed", __FUNCTION__); @@ -817,10 +743,9 @@ if (!DiInstallDevice(hwndParent, hDevInfoList, &devinfo_data, NULL, 0,= pbRebootRequired)) #else /* mingw does not resolve DiInstallDevice, so load it at run time. */ - typedef BOOL (WINAPI *DiInstallDeviceFn)(HWND, HDEVINFO, SP_DEVINFO_DA= TA *, - SP_DRVINFO_DATA *, DWORD, BOO= L *); - DiInstallDeviceFn installfn - =3D find_function(L"newdev.dll", "DiInstallDevice", &libnewdev); + typedef BOOL(WINAPI * DiInstallDeviceFn)(HWND, HDEVINFO, SP_DEVINFO_DA= TA *, SP_DRVINFO_DATA *, + DWORD, BOOL *); + DiInstallDeviceFn installfn =3D find_function(L"newdev.dll", "DiInstal= lDevice", &libnewdev); if (!installfn) { @@ -856,24 +781,20 @@ }; /* Set class installer parameters for DIF_REMOVE. */ - if (SetupDiSetClassInstallParams( - hDevInfoList, - &devinfo_data, - &removedevice_params.ClassInstallHeader, - sizeof(SP_REMOVEDEVICE_PARAMS))) + if (SetupDiSetClassInstallParams(hDevInfoList, &devinfo_data, + &removedevice_params.ClassInstall= Header, + sizeof(SP_REMOVEDEVICE_PARAMS))) { /* Call appropriate class installer. */ - if (SetupDiCallClassInstaller( - DIF_REMOVE, - hDevInfoList, - &devinfo_data)) + if (SetupDiCallClassInstaller(DIF_REMOVE, hDevInfoList, &devin= fo_data)) { /* Check if a system reboot is required. */ check_reboot(hDevInfoList, &devinfo_data, pbRebootRequired= ); } else { - msg(M_NONFATAL | M_ERRNO, "%s: SetupDiCallClassInstaller(D= IF_REMOVE) failed", __FUNCTION__); + msg(M_NONFATAL | M_ERRNO, "%s: SetupDiCallClassInstaller(D= IF_REMOVE) failed", + __FUNCTION__); } } else @@ -913,11 +834,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ static DWORD -execute_on_first_adapter( - _In_opt_ HWND hwndParent, - _In_ LPCGUID pguidAdapter, - _In_ devop_func_t funcOperation, - _Inout_ LPBOOL pbRebootRequired) +execute_on_first_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapt= er, + _In_ devop_func_t funcOperation, _Inout_ LPBOOL p= bRebootRequired) { DWORD dwResult; @@ -927,14 +845,8 @@ } /* Create a list of network devices. */ - HDEVINFO hDevInfoList =3D SetupDiGetClassDevsEx( - &GUID_DEVCLASS_NET, - NULL, - hwndParent, - DIGCF_PRESENT, - NULL, - NULL, - NULL); + HDEVINFO hDevInfoList =3D SetupDiGetClassDevsEx(&GUID_DEVCLASS_NET, NU= LL, hwndParent, + DIGCF_PRESENT, NULL, NUL= L, NULL); if (hDevInfoList =3D=3D INVALID_HANDLE_VALUE) { dwResult =3D GetLastError(); @@ -943,7 +855,8 @@ } /* Retrieve information associated with a device information set. */ - SP_DEVINFO_LIST_DETAIL_DATA devinfo_list_detail_data =3D { .cbSize =3D= sizeof(SP_DEVINFO_LIST_DETAIL_DATA) }; + SP_DEVINFO_LIST_DETAIL_DATA devinfo_list_detail_data =3D { .cbSize =3D= sizeof( + SP_DEVINF= O_LIST_DETAIL_DATA) }; if (!SetupDiGetDeviceInfoListDetail(hDevInfoList, &devinfo_list_detail= _data)) { dwResult =3D GetLastError(); @@ -956,10 +869,7 @@ { /* Get the device from the list. */ SP_DEVINFO_DATA devinfo_data =3D { .cbSize =3D sizeof(SP_DEVINFO_D= ATA) }; - if (!SetupDiEnumDeviceInfo( - hDevInfoList, - dwIndex, - &devinfo_data)) + if (!SetupDiEnumDeviceInfo(hDevInfoList, dwIndex, &devinfo_data)) { if (GetLastError() =3D=3D ERROR_NO_MORE_ITEMS) { @@ -973,7 +883,8 @@ else { /* Something is wrong with this device. Skip it. */ - msg(M_WARN | M_ERRNO, "%s: SetupDiEnumDeviceInfo(%u) faile= d", __FUNCTION__, dwIndex); + msg(M_WARN | M_ERRNO, "%s: SetupDiEnumDeviceInfo(%u) faile= d", __FUNCTION__, + dwIndex); continue; } } @@ -1002,23 +913,19 @@ DWORD -tap_delete_adapter( - _In_opt_ HWND hwndParent, - _In_ LPCGUID pguidAdapter, - _Inout_ LPBOOL pbRebootRequired) +tap_delete_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter, + _Inout_ LPBOOL pbRebootRequired) { return execute_on_first_adapter(hwndParent, pguidAdapter, delete_devic= e, pbRebootRequired); } DWORD -tap_enable_adapter( - _In_opt_ HWND hwndParent, - _In_ LPCGUID pguidAdapter, - _In_ BOOL bEnable, - _Inout_ LPBOOL pbRebootRequired) +tap_enable_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter, _I= n_ BOOL bEnable, + _Inout_ LPBOOL pbRebootRequired) { - return execute_on_first_adapter(hwndParent, pguidAdapter, bEnable ? en= able_device : disable_device, pbRebootRequired); + return execute_on_first_adapter(hwndParent, pguidAdapter, + bEnable ? enable_device : disable_devi= ce, pbRebootRequired); } /* stripped version of ExecCommand in interactive.c */ @@ -1038,8 +945,8 @@ /* CreateProcess needs a modifiable cmdline: make a copy */ cmdline_dup =3D _wcsdup(cmdline); - if (cmdline_dup && CreateProcessW(NULL, cmdline_dup, NULL, NULL, FALSE, - proc_flags, NULL, NULL, &si, &pi)) + if (cmdline_dup + && CreateProcessW(NULL, cmdline_dup, NULL, NULL, FALSE, proc_flags= , NULL, NULL, &si, &pi)) { WaitForSingleObject(pi.hProcess, INFINITE); if (!GetExitCodeProcess(pi.hProcess, &exit_code)) @@ -1060,10 +967,7 @@ } DWORD -tap_set_adapter_name( - _In_ LPCGUID pguidAdapter, - _In_ LPCWSTR szName, - _In_ BOOL bSilent) +tap_set_adapter_name(_In_ LPCGUID pguidAdapter, _In_ LPCWSTR szName, _In_ = BOOL bSilent) { DWORD dwResult; int msg_flag =3D bSilent ? M_WARN : M_NONFATAL; @@ -1084,23 +988,16 @@ /* Render registry key path. */ WCHAR szRegKey[ADAPTER_REGKEY_PATH_MAX]; - swprintf_s( - szRegKey, _countof(szRegKey), - szAdapterRegKeyPathTemplate, - szDevClassNetId, - szAdapterId); + swprintf_s(szRegKey, _countof(szRegKey), szAdapterRegKeyPathTemplate, = szDevClassNetId, + szAdapterId); /* Open network adapter registry key. */ HKEY hKey =3D NULL; - dwResult =3D RegOpenKeyEx( - HKEY_LOCAL_MACHINE, - szRegKey, - 0, - KEY_QUERY_VALUE, - &hKey); + dwResult =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_V= ALUE, &hKey); if (dwResult !=3D ERROR_SUCCESS) { - SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx() to= set GetLastError(). But we do have an error code. Set last error manually.= */ + SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx() to= set GetLastError(). But + we do have an error code. Set last erro= r manually. */ msg(msg_flag, "%s: RegOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION= __, szRegKey); goto cleanup_szAdapterId; } @@ -1143,10 +1040,8 @@ DWORD -tap_list_adapters( - _In_opt_ HWND hwndParent, - _In_opt_ LPCWSTR szzHwIDs, - _Out_ struct tap_adapter_node **ppAdapter) +tap_list_adapters(_In_opt_ HWND hwndParent, _In_opt_ LPCWSTR szzHwIDs, + _Out_ struct tap_adapter_node **ppAdapter) { DWORD dwResult; @@ -1156,14 +1051,8 @@ } /* Create a list of network devices. */ - HDEVINFO hDevInfoList =3D SetupDiGetClassDevsEx( - &GUID_DEVCLASS_NET, - NULL, - hwndParent, - DIGCF_PRESENT, - NULL, - NULL, - NULL); + HDEVINFO hDevInfoList =3D SetupDiGetClassDevsEx(&GUID_DEVCLASS_NET, NU= LL, hwndParent, + DIGCF_PRESENT, NULL, NUL= L, NULL); if (hDevInfoList =3D=3D INVALID_HANDLE_VALUE) { dwResult =3D GetLastError(); @@ -1172,7 +1061,8 @@ } /* Retrieve information associated with a device information set. */ - SP_DEVINFO_LIST_DETAIL_DATA devinfo_list_detail_data =3D { .cbSize =3D= sizeof(SP_DEVINFO_LIST_DETAIL_DATA) }; + SP_DEVINFO_LIST_DETAIL_DATA devinfo_list_detail_data =3D { .cbSize =3D= sizeof( + SP_DEVINF= O_LIST_DETAIL_DATA) }; if (!SetupDiGetDeviceInfoListDetail(hDevInfoList, &devinfo_list_detail= _data)) { dwResult =3D GetLastError(); @@ -1191,10 +1081,7 @@ { /* Get the device from the list. */ SP_DEVINFO_DATA devinfo_data =3D { .cbSize =3D sizeof(SP_DEVINFO_D= ATA) }; - if (!SetupDiEnumDeviceInfo( - hDevInfoList, - dwIndex, - &devinfo_data)) + if (!SetupDiEnumDeviceInfo(hDevInfoList, dwIndex, &devinfo_data)) { if (GetLastError() =3D=3D ERROR_NO_MORE_ITEMS) { @@ -1203,7 +1090,8 @@ else { /* Something is wrong with this device. Skip it. */ - msg(M_WARN | M_ERRNO, "%s: SetupDiEnumDeviceInfo(%u) faile= d", __FUNCTION__, dwIndex); + msg(M_WARN | M_ERRNO, "%s: SetupDiEnumDeviceInfo(%u) faile= d", __FUNCTION__, + dwIndex); continue; } } @@ -1211,12 +1099,8 @@ /* Get device hardware ID(s). */ DWORD dwDataType =3D REG_NONE; LPWSTR szzDeviceHardwareIDs =3D NULL; - dwResult =3D get_device_reg_property( - hDevInfoList, - &devinfo_data, - SPDRP_HARDWAREID, - &dwDataType, - (LPVOID)&szzDeviceHardwareIDs); + dwResult =3D get_device_reg_property(hDevInfoList, &devinfo_data, = SPDRP_HARDWAREID, + &dwDataType, (LPVOID)&szzDevice= HardwareIDs); if (dwResult !=3D ERROR_SUCCESS) { /* Something is wrong with this device. Skip it. */ @@ -1272,48 +1156,42 @@ /* Render registry key path. */ WCHAR szRegKey[ADAPTER_REGKEY_PATH_MAX]; - swprintf_s( - szRegKey, _countof(szRegKey), - szAdapterRegKeyPathTemplate, - szDevClassNetId, - szAdapterId); + swprintf_s(szRegKey, _countof(szRegKey), szAdapterRegKeyPathTempla= te, szDevClassNetId, + szAdapterId); /* Open network adapter registry key. */ HKEY hKey =3D NULL; - dwResult =3D RegOpenKeyEx( - HKEY_LOCAL_MACHINE, - szRegKey, - 0, - KEY_READ, - &hKey); + dwResult =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_REA= D, &hKey); if (dwResult !=3D ERROR_SUCCESS) { - SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx(= ) to set GetLastError(). But we do have an error code. Set last error manua= lly. */ + SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx(= ) to set GetLastError(). + But we do have an error code. Set l= ast error manually. */ msg(M_WARN | M_ERRNO, "%s: RegOpenKeyEx(HKLM, \"%ls\") failed"= , __FUNCTION__, szRegKey); goto cleanup_szAdapterId; } /* Read adapter name. */ LPWSTR szName =3D NULL; - dwResult =3D get_reg_string( - hKey, - L"Name", - &szName); + dwResult =3D get_reg_string(hKey, L"Name", &szName); if (dwResult !=3D ERROR_SUCCESS) { SetLastError(dwResult); - msg(M_WARN | M_ERRNO, "%s: Cannot determine %ls adapter name",= __FUNCTION__, szAdapterId); + msg(M_WARN | M_ERRNO, "%s: Cannot determine %ls adapter name",= __FUNCTION__, + szAdapterId); goto cleanup_hKey; } /* Append to the list. */ size_t hwid_size =3D (wcszlen(szzDeviceHardwareIDs) + 1) * sizeof(= WCHAR); size_t name_size =3D (wcslen(szName) + 1) * sizeof(WCHAR); - struct tap_adapter_node *node =3D (struct tap_adapter_node *)mallo= c(sizeof(struct tap_adapter_node) + hwid_size + name_size); + struct tap_adapter_node *node =3D (struct tap_adapter_node *)mallo= c( + sizeof(struct tap_adapter_node) + hwid_size + name_size); if (node =3D=3D NULL) { - msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, sizeof(str= uct tap_adapter_node) + hwid_size + name_size); - dwResult =3D ERROR_OUTOFMEMORY; goto cleanup_szName; + msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, + sizeof(struct tap_adapter_node) + hwid_size + name_size); + dwResult =3D ERROR_OUTOFMEMORY; + goto cleanup_szName; } memcpy(&node->guid, &guidAdapter, sizeof(GUID)); @@ -1352,8 +1230,7 @@ void -tap_free_adapter_list( - _In_ struct tap_adapter_node *pAdapterList) +tap_free_adapter_list(_In_ struct tap_adapter_node *pAdapterList) { /* Iterate over all nodes of the list. */ while (pAdapterList) diff --git a/src/tapctl/tap.h b/src/tapctl/tap.h index 1ca512a..3d9fb4c 100644 --- a/src/tapctl/tap.h +++ b/src/tapctl/tap.h @@ -50,12 +50,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ DWORD -tap_create_adapter( - _In_opt_ HWND hwndParent, - _In_opt_ LPCWSTR szDeviceDescription, - _In_ LPCWSTR szHwId, - _Inout_ LPBOOL pbRebootRequired, - _Out_ LPGUID pguidAdapter); +tap_create_adapter(_In_opt_ HWND hwndParent, _In_opt_ LPCWSTR szDeviceDesc= ription, + _In_ LPCWSTR szHwId, _Inout_ LPBOOL pbRebootRequired, _= Out_ LPGUID pguidAdapter); /** @@ -77,10 +73,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ DWORD -tap_delete_adapter( - _In_opt_ HWND hwndParent, - _In_ LPCGUID pguidAdapter, - _Inout_ LPBOOL pbRebootRequired); +tap_delete_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter, + _Inout_ LPBOOL pbRebootRequired); /** @@ -104,11 +98,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ DWORD -tap_enable_adapter( - _In_opt_ HWND hwndParent, - _In_ LPCGUID pguidAdapter, - _In_ BOOL bEnable, - _Inout_ LPBOOL pbRebootRequired); +tap_enable_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter, _I= n_ BOOL bEnable, + _Inout_ LPBOOL pbRebootRequired); /** @@ -124,10 +115,7 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise **/ DWORD -tap_set_adapter_name( - _In_ LPCGUID pguidAdapter, - _In_ LPCWSTR szName, - _In_ BOOL bSilent); +tap_set_adapter_name(_In_ LPCGUID pguidAdapter, _In_ LPCWSTR szName, _In_ = BOOL bSilent); /** @@ -135,9 +123,9 @@ */ struct tap_adapter_node { - GUID guid; /**< Adapter GUID */ - LPWSTR szzHardwareIDs; /**< Device hardware ID(s) */ - LPWSTR szName; /**< Adapter name */ + GUID guid; /**< Adapter GUID */ + LPWSTR szzHardwareIDs; /**< Device hardware ID(s) */ + LPWSTR szName; /**< Adapter name */ struct tap_adapter_node *pNext; /**< Pointer to next adapter */ }; @@ -163,10 +151,8 @@ * @return ERROR_SUCCESS on success; Win32 error code otherwise */ DWORD -tap_list_adapters( - _In_opt_ HWND hwndParent, - _In_opt_ LPCWSTR szzHwIDs, - _Out_ struct tap_adapter_node **ppAdapterList); +tap_list_adapters(_In_opt_ HWND hwndParent, _In_opt_ LPCWSTR szzHwIDs, + _Out_ struct tap_adapter_node **ppAdapterList); /** @@ -174,8 +160,6 @@ * * @param pAdapterList A pointer to the first adapter in the list to free. */ -void -tap_free_adapter_list( - _In_ struct tap_adapter_node *pAdapterList); +void tap_free_adapter_list(_In_ struct tap_adapter_node *pAdapterList); #endif /* ifndef TAP_H */ diff --git a/tests/ntlm_support.c b/tests/ntlm_support.c index f5eba88..788f132 100644 --- a/tests/ntlm_support.c +++ b/tests/ntlm_support.c @@ -50,7 +50,7 @@ crypto_unload_provider("legacy", legacy); crypto_unload_provider("default", def); #endif -#else /* ifdef NTLM */ +#else /* ifdef NTLM */ msg(M_FATAL, "NTLM support not compiled in"); #endif } diff --git a/tests/unit_tests/example_test/test.c b/tests/unit_tests/exampl= e_test/test.c index c174025..139e06f 100644 --- a/tests/unit_tests/example_test/test.c +++ b/tests/unit_tests/example_test/test.c @@ -10,7 +10,7 @@ static int setup(void **state) { - int *answer =3D malloc(sizeof(int)); + int *answer =3D malloc(sizeof(int)); *answer =3D 42; *state =3D answer; @@ -29,7 +29,7 @@ static void null_test_success(void **state) { - (void) state; + (void)state; } static void @@ -39,8 +39,7 @@ assert_int_equal(*answer, 42); } -__attribute__((unused)) -static void +__attribute__((unused)) static void failing_test(void **state) { /* This tests fails to test that make check fails */ @@ -53,7 +52,7 @@ const struct CMUnitTest tests[] =3D { cmocka_unit_test(null_test_success), cmocka_unit_test_setup_teardown(int_test_success, setup, teardown), -/* cmocka_unit_test(failing_test), */ + /* cmocka_unit_test(failing_test), */ }; return cmocka_run_group_tests_name("success_test", tests, NULL, NULL); diff --git a/tests/unit_tests/example_test/test2.c b/tests/unit_tests/examp= le_test/test2.c index bb54633..3089432 100644 --- a/tests/unit_tests/example_test/test2.c +++ b/tests/unit_tests/example_test/test2.c @@ -11,7 +11,7 @@ static void test_true(void **state) { - (void) state; + (void)state; } diff --git a/tests/unit_tests/openvpn/cert_data.h b/tests/unit_tests/openvp= n/cert_data.h index bbf3736..53b5cda 100644 --- a/tests/unit_tests/openvpn/cert_data.h +++ b/tests/unit_tests/openvpn/cert_data.h @@ -53,12 +53,11 @@ "srXMaPe0lAea4etMSZsjIRPwGRMXBrwbRmb6iN2Cq40867HdaJoAryYig7IiDwSX\n" "htCbOA6sX+60+FEOYDEx5cmkogl633Pw7LJ3ICkyzIrUSEt6BOT1Gsc1eQ=3D=3D\n" "-----END CERTIFICATE-----\n"; -static const char *const key1 =3D - "-----BEGIN PRIVATE KEY-----\n" - "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg5Xpw/lLvBrWjAWDq\n" - "L6dm/4a1or6AQ6O3yXYgw78B23ihRANCAAR4SRvnSuGdJmPitKbqcFbcgyzsMBlh\n" - "4wWOrty4I0ZlIXxY2qEnyb3YKz4OdMGzpK7FLfQZehHg6LGblcLs4EW7\n" - "-----END PRIVATE KEY-----\n"; +static const char *const key1 =3D "-----BEGIN PRIVATE KEY-----\n" + "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wa= wIBAQQg5Xpw/lLvBrWjAWDq\n" + "L6dm/4a1or6AQ6O3yXYgw78B23ihRANCAAR4SRvnS= uGdJmPitKbqcFbcgyzsMBlh\n" + "4wWOrty4I0ZlIXxY2qEnyb3YKz4OdMGzpK7FLfQZe= hHg6LGblcLs4EW7\n" + "-----END PRIVATE KEY-----\n"; static const char *const hash1 =3D "A4B74F1D68AF50691F62CBD675E24C86553695= 67"; static const char *const cname1 =3D "ovpn-test-ec1"; @@ -105,35 +104,34 @@ "F6MgVGSxl6eylJgDYckvJiAbmcp2PD/LRQQOxQA0yqeAMg2cbdvclETuYD6zoFfu\n" "Y8aO7dvDlw=3D=3D\n" "-----END CERTIFICATE-----\n"; -static const char *const key3 =3D - "-----BEGIN PRIVATE KEY-----\n" - "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC7xFoR6fmoyfsJ\n" - "IQDKKgbYgFw0MzVuDAmpRx6KTEihgTchkQx9fHddWbKiOUbcEnQi3LNux7P4QVl/\n" - "4dRR3skisBug6Vd5LXeBGZqmpu5XZiF4DgLz1lX21G0aOogFWkie2qGEcso40159\n" - "x9FBDl5A3sLP18ubeex0pd/BzDFv6SLOTyVWO/GCNc8IX/i0uN4mLvoVU00SeqwT\n" - "PnS+CRXrSq4JjGDJLsXl0/PlxkjsgU0yOOA0Z2d8Fzk3wClwP6Hc49BOMWKstUIh\n" - "LbG2DcIv8l29EuEj2w3ju/7gkewol96XQ2twpPvpoVAaiVh/m7hQUcQORQCD6eJc\n" - "DjOZVCArAgMBAAECggEACqkuWAAJ3cyCBVWrXs8eDmLTWV9i9DmYvtS75ixIn2rf\n" - "v3cl12YevN0f6FgKLuqZT3Vqdqq+DCVhuIIQ9QkKMH8BQpSdE9NCCsFyZ23o8Gtr\n" - "EQ7ymfecb+RFwYx7NpqWrvZI32VJGArgPZH/zorLTTGYrAZbmBtHEqRsXOuEDw97\n" - "slwwcWaa9ztaYC8/N/7fgsnydaCFSaOByRlWuyvSmHvn6ZwLv8ANOshY6fstC0Jb\n" - "BW0GpSe9eZPjpl71VT2RtpghqLV5+iAoFDHoT+eZvBospcUGtfcZSU7RrBjKB8+a\n" - "U1d6hwKhduVs2peIQzl+FiOSdWriLcsZv79q4sBhsQKBgQDUDVTf5BGJ8apOs/17\n" - "YVk+Ad8Ey8sXvsfk49psmlCRa8Z4g0LVXfrP94qzhtl8U5kE9hs3nEF4j/kX1ZWG\n" - "k11tdsNTZN5x5bbAgEgPA6Ap6J/uto0HS8G0vSv0lyBymdKA3p/i5Dx+8Nc9cGns\n" - "LGI9MvviLX7pQFIkvbaCkdKwYwKBgQDirowjWZnm7BgVhF0G1m3DY9nQTYYU185W\n" - "UESaO5/nVzwUrA+FypJamD+AvmlSuY8rJeQAGAS6nQr9G8/617r+GwJnzRtxC6Vl\n" - "4OF5BJRsD70oX4CFOOlycMoJ8tzcYVH7NI8KVocjxb+QW82hqSvEwSsvnwwn3eOW\n" - "nr5u5vIHmQKBgCuc3lL6Dl1ntdZgEIdau0cUjXDoFUo589TwxBDIID/4gaZxoMJP\n" - "hPFXAVDxMDPw4azyjSB/47tPKTUsuYcnMfT8kynIujOEwnSPLcLgxQU5kgM/ynuw\n" - "qhNpQOwaVRMc7f2RTCMXPBYDpNE/GJn5eu8JWGLpZovEreBeoHX0VffvAoGAVrWn\n" - "+3mxykhzaf+oyg3KDNysG+cbq+tlDVVE+K5oG0kePVYX1fjIBQmJ+QhdJ3y9jCbB\n" - "UVveqzeZVXqHEw/kgoD4aZZmsdZfnVnpRa5/y9o1ZDUr50n+2nzUe/u/ijlb77iK\n" - "Is04gnGJNoI3ZWhdyrSNfXjcYH+bKClu9OM4n7kCgYAorc3PAX7M0bsQrrqYxUS8\n" - "56UU0YdhAgYitjM7Fm/0iIm0vDpSevxL9js4HnnsSMVR77spCBAGOCCZrTcI3Ejg\n" - "xKDYzh1xlfMRjJBuBu5Pd55ZAv9NXFGpsX5SO8fDZQJMwpcbQH36+UdqRRFDpjJ0\n" - "ZbX6nKcJ7jciJVKJds59Jg=3D=3D\n" - "-----END PRIVATE KEY-----\n"; +static const char *const key3 =3D "-----BEGIN PRIVATE KEY-----\n" + "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiA= gEAAoIBAQC7xFoR6fmoyfsJ\n" + "IQDKKgbYgFw0MzVuDAmpRx6KTEihgTchkQx9fHddW= bKiOUbcEnQi3LNux7P4QVl/\n" + "4dRR3skisBug6Vd5LXeBGZqmpu5XZiF4DgLz1lX21= G0aOogFWkie2qGEcso40159\n" + "x9FBDl5A3sLP18ubeex0pd/BzDFv6SLOTyVWO/GCN= c8IX/i0uN4mLvoVU00SeqwT\n" + "PnS+CRXrSq4JjGDJLsXl0/PlxkjsgU0yOOA0Z2d8F= zk3wClwP6Hc49BOMWKstUIh\n" + "LbG2DcIv8l29EuEj2w3ju/7gkewol96XQ2twpPvpo= VAaiVh/m7hQUcQORQCD6eJc\n" + "DjOZVCArAgMBAAECggEACqkuWAAJ3cyCBVWrXs8eD= mLTWV9i9DmYvtS75ixIn2rf\n" + "v3cl12YevN0f6FgKLuqZT3Vqdqq+DCVhuIIQ9QkKM= H8BQpSdE9NCCsFyZ23o8Gtr\n" + "EQ7ymfecb+RFwYx7NpqWrvZI32VJGArgPZH/zorLT= TGYrAZbmBtHEqRsXOuEDw97\n" + "slwwcWaa9ztaYC8/N/7fgsnydaCFSaOByRlWuyvSm= Hvn6ZwLv8ANOshY6fstC0Jb\n" + "BW0GpSe9eZPjpl71VT2RtpghqLV5+iAoFDHoT+eZv= BospcUGtfcZSU7RrBjKB8+a\n" + "U1d6hwKhduVs2peIQzl+FiOSdWriLcsZv79q4sBhs= QKBgQDUDVTf5BGJ8apOs/17\n" + "YVk+Ad8Ey8sXvsfk49psmlCRa8Z4g0LVXfrP94qzh= tl8U5kE9hs3nEF4j/kX1ZWG\n" + "k11tdsNTZN5x5bbAgEgPA6Ap6J/uto0HS8G0vSv0l= yBymdKA3p/i5Dx+8Nc9cGns\n" + "LGI9MvviLX7pQFIkvbaCkdKwYwKBgQDirowjWZnm7= BgVhF0G1m3DY9nQTYYU185W\n" + "UESaO5/nVzwUrA+FypJamD+AvmlSuY8rJeQAGAS6n= Qr9G8/617r+GwJnzRtxC6Vl\n" + "4OF5BJRsD70oX4CFOOlycMoJ8tzcYVH7NI8KVocjx= b+QW82hqSvEwSsvnwwn3eOW\n" + "nr5u5vIHmQKBgCuc3lL6Dl1ntdZgEIdau0cUjXDoF= Uo589TwxBDIID/4gaZxoMJP\n" + "hPFXAVDxMDPw4azyjSB/47tPKTUsuYcnMfT8kynIu= jOEwnSPLcLgxQU5kgM/ynuw\n" + "qhNpQOwaVRMc7f2RTCMXPBYDpNE/GJn5eu8JWGLpZ= ovEreBeoHX0VffvAoGAVrWn\n" + "+3mxykhzaf+oyg3KDNysG+cbq+tlDVVE+K5oG0keP= VYX1fjIBQmJ+QhdJ3y9jCbB\n" + "UVveqzeZVXqHEw/kgoD4aZZmsdZfnVnpRa5/y9o1Z= DUr50n+2nzUe/u/ijlb77iK\n" + "Is04gnGJNoI3ZWhdyrSNfXjcYH+bKClu9OM4n7kCg= YAorc3PAX7M0bsQrrqYxUS8\n" + "56UU0YdhAgYitjM7Fm/0iIm0vDpSevxL9js4HnnsS= MVR77spCBAGOCCZrTcI3Ejg\n" + "xKDYzh1xlfMRjJBuBu5Pd55ZAv9NXFGpsX5SO8fDZ= QJMwpcbQH36+UdqRRFDpjJ0\n" + "ZbX6nKcJ7jciJVKJds59Jg=3D=3D\n" + "-----END PRIVATE KEY-----\n"; static const char *const hash3 =3D "2463628674E362578113F508BA05F29EF142E9= 79"; static const char *const cname3 =3D "ovpn-test-rsa1"; @@ -163,4 +161,4 @@ static const char *const hash4 =3D "E1401D4497C944783E3D62CDBD2A1F69F5E507= 1E"; #define cname4 cname3 /* same CN as that of cert3 */ -#endif /* CERT_DATA_H */ +#endif /* CERT_DATA_H */ diff --git a/tests/unit_tests/openvpn/mock_management.c b/tests/unit_tests/= openvpn/mock_management.c index c3e38b9..2adade5 100644 --- a/tests/unit_tests/openvpn/mock_management.c +++ b/tests/unit_tests/openvpn/mock_management.c @@ -43,8 +43,7 @@ } char * -management_query_pk_sig(struct management *man, const char *b64_data, - const char *algorithm) +management_query_pk_sig(struct management *man, const char *b64_data, cons= t char *algorithm) { return NULL; } diff --git a/tests/unit_tests/openvpn/mock_msg.c b/tests/unit_tests/openvpn= /mock_msg.c index b6ec744..6970ad8 100644 --- a/tests/unit_tests/openvpn/mock_msg.c +++ b/tests/unit_tests/openvpn/mock_msg.c @@ -72,8 +72,7 @@ } void -x_msg_va(const unsigned int flags, const char *format, - va_list arglist) +x_msg_va(const unsigned int flags, const char *format, va_list arglist) { if (flags & M_FATAL) { @@ -108,7 +107,7 @@ /* Keep compiler happy. Should not happen, mock_assert() does not ret= urn */ exit(1); } -#else /* ifndef NO_CMOCKA */ +#else /* ifndef NO_CMOCKA */ void assert_failed(const char *filename, int line, const char *condition) { diff --git a/tests/unit_tests/openvpn/mock_msg.h b/tests/unit_tests/openvpn= /mock_msg.h index bc2ee5d..ffac529 100644 --- a/tests/unit_tests/openvpn/mock_msg.h +++ b/tests/unit_tests/openvpn/mock_msg.h @@ -36,13 +36,10 @@ extern bool fatal_error_triggered; extern char mock_msg_buf[MOCK_MSG_BUF]; -void -mock_set_debug_level(int level); +void mock_set_debug_level(int level); -int -mock_get_debug_level(void); +int mock_get_debug_level(void); -void -mock_set_print_debug_level(int level); +void mock_set_print_debug_level(int level); #endif /* MOCK_MSG */ diff --git a/tests/unit_tests/openvpn/mock_ssl_dependencies.c b/tests/unit_= tests/openvpn/mock_ssl_dependencies.c index 5cfe8d0..7ae0e69 100644 --- a/tests/unit_tests/openvpn/mock_ssl_dependencies.c +++ b/tests/unit_tests/openvpn/mock_ssl_dependencies.c @@ -38,8 +38,8 @@ #include "ssl_verify.h" int -parse_line(const char *line, char **p, const int n, const char *file, - const int line_num, int msglevel, struct gc_arena *gc) +parse_line(const char *line, char **p, const int n, const char *file, cons= t int line_num, + int msglevel, struct gc_arena *gc) { /* Dummy function to get the linker happy, should never be called */ assert_true(false); diff --git a/tests/unit_tests/openvpn/pkey_test_utils.c b/tests/unit_tests/= openvpn/pkey_test_utils.c index 9a044ec..4af80ac 100644 --- a/tests/unit_tests/openvpn/pkey_test_utils.c +++ b/tests/unit_tests/openvpn/pkey_test_utils.c @@ -57,14 +57,14 @@ size_t siglen =3D 0; int ret =3D 0; - OSSL_PARAM params[2] =3D {OSSL_PARAM_END}; + OSSL_PARAM params[2] =3D { OSSL_PARAM_END }; const char *mdname =3D "SHA256"; if (EVP_PKEY_get_id(privkey) =3D=3D EVP_PKEY_RSA) { const char *padmode =3D "pss"; /* RSA_PSS: for all other params, u= se defaults */ - params[0] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARA= M_PAD_MODE, - (char *)padmode, 0); + params[0] =3D + OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE= , (char *)padmode, 0); params[1] =3D OSSL_PARAM_construct_end(); } else if (EVP_PKEY_get_id(privkey) =3D=3D EVP_PKEY_EC) @@ -80,8 +80,7 @@ EVP_PKEY_CTX *pctx =3D NULL; EVP_MD_CTX *mctx =3D EVP_MD_CTX_new(); - if (!mctx - || EVP_DigestSignInit_ex(mctx, &pctx, mdname, tls_libctx, NULL, pr= ivkey, params) <=3D 0) + if (!mctx || EVP_DigestSignInit_ex(mctx, &pctx, mdname, tls_libctx, NU= LL, privkey, params) <=3D 0) { /* cmocka assert output for these kinds of failures is hardly expl= anatory, * print a message and assert in caller. */ @@ -116,7 +115,7 @@ mctx =3D EVP_MD_CTX_new(); pctx =3D NULL; if (!mctx - || EVP_DigestVerifyInit_ex(mctx, &pctx, mdname, tls_libctx, NULL, = pubkey, params) <=3D 0) + || EVP_DigestVerifyInit_ex(mctx, &pctx, mdname, tls_libctx, NULL, = pubkey, params) <=3D 0) { print_error("Failed to initialize EVP_DigestVerifyInit_ex()"); goto done; diff --git a/tests/unit_tests/openvpn/test_argv.c b/tests/unit_tests/openvp= n/test_argv.c index 33b3dec..a65857b 100644 --- a/tests/unit_tests/openvpn/test_argv.c +++ b/tests/unit_tests/openvpn/test_argv.c @@ -15,15 +15,15 @@ #include "test_common.h" /* Defines for use in the tests and the mock parse_line() */ -#define PATH1 "/s p a c e" -#define PATH2 "/foo bar/baz" -#define PARAM1 "param1" -#define PARAM2 "param two" -#define SCRIPT_CMD "\"" PATH1 PATH2 "\"" PARAM1 "\"" PARAM2 "\"" +#define PATH1 "/s p a c e" +#define PATH2 "/foo bar/baz" +#define PARAM1 "param1" +#define PARAM2 "param two" +#define SCRIPT_CMD "\"" PATH1 PATH2 "\"" PARAM1 "\"" PARAM2 "\"" int -__wrap_parse_line(const char *line, char **p, const int n, const char *fil= e, - const int line_num, int msglevel, struct gc_arena *gc) +__wrap_parse_line(const char *line, char **p, const int n, const char *fil= e, const int line_num, + int msglevel, struct gc_arena *gc) { p[0] =3D PATH1 PATH2; p[1] =3D PARAM1; @@ -201,10 +201,10 @@ argv_printf_cat(&a, "%s", PARAM2); argv_printf_cat(&a, "%d", -1); argv_printf_cat(&a, "%u", -1); - argv_printf_cat(&a, "%lu", 1L ); + argv_printf_cat(&a, "%lu", 1L); output =3D argv_str(&a, &gc, PA_BRACKET); assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 = "]" - " [-1] [4294967295] [1]"); + " [-1] [4294967295] [1]"); argv_free(&a); gc_free(&gc); diff --git a/tests/unit_tests/openvpn/test_auth_token.c b/tests/unit_tests/= openvpn/test_auth_token.c index be3b2b7..ba2a1d0 100644 --- a/tests/unit_tests/openvpn/test_auth_token.c +++ b/tests/unit_tests/openvpn/test_auth_token.c @@ -37,7 +37,8 @@ #include "auth_token.c" #include "test_common.h" -struct test_context { +struct test_context +{ struct tls_multi multi; struct key_type kt; struct user_pass up; @@ -53,10 +54,10 @@ void auth_set_client_reason(struct tls_multi *multi, const char *reason) { - } -static const char *now0key0 =3D "SESS_ID_AT_0123456789abcdefAAAAAAAAAAAAAA= AAAAAAAE5JsQJOVfo8jnI3RL3tBaR5NkE4yPfcylFUHmHSc5Bu"; +static const char *now0key0 =3D + "SESS_ID_AT_0123456789abcdefAAAAAAAAAAAAAAAAAAAAAE5JsQJOVfo8jnI3RL3tBa= R5NkE4yPfcylFUHmHSc5Bu"; static const char *zeroinline =3D "-----BEGIN OpenVPN auth-token server ke= y-----\n" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= AAAAAAAAAAAAAAAAAAAAAAA\n" @@ -64,21 +65,24 @@ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= AA=3D\n" "-----END OpenVPN auth-token server key---= --"; -static const char *allx01inline =3D "-----BEGIN OpenVPN auth-token server = key-----\n" - "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE= BAQEBAQEBAQEBAQEBAQEBAQEB\n" - "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE= BAQEBAQEBAQEBAQEBAQEBAQEB\n" - "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE= BAQE=3D\n" - "-----END OpenVPN auth-token server key-= ----"; +static const char *allx01inline =3D + "-----BEGIN OpenVPN auth-token server key-----\n" + "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n" + "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n" + "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=3D\n" + "-----END OpenVPN auth-token server key-----"; -static const char *random_key =3D "-----BEGIN OpenVPN auth-token server ke= y-----\n" - "+mmmf7IQ5cymtMVjKYTWk8IOcYanRlpQmV9Tb3Ejk= HYxueBVDg3yqRgzeBlVGzNLD//rAPiOVhau\n" - "3NDBjNOQB8951bfs7Cc2mYfay92Bh2gRJ5XEM/DMf= zCWN+7uU6NWoTTHr4FuojnIQtjtqVAj/JS9\n" - "w+dTSp/vYHl+c7uHd19uVRu/qLqV85+rm4tUGIjO7= FfYuwyPqwmhuIsi3hs9QkSimh888FmBpoKY\n" - "/tbKVTJZmSERKti9KEwtV2eVAR0znN5KW7lCB3mHV= AhN7bUpcoDjfCzYIFARxwswTFu9gFkwqUMY\n" - "I1KUOgIsVNs4llACioeXplYekWETR+YkJwDc/A=3D= =3D\n" - "-----END OpenVPN auth-token server key---= --"; +static const char *random_key =3D + "-----BEGIN OpenVPN auth-token server key-----\n" + "+mmmf7IQ5cymtMVjKYTWk8IOcYanRlpQmV9Tb3EjkHYxueBVDg3yqRgzeBlVGzNLD//rA= PiOVhau\n" + "3NDBjNOQB8951bfs7Cc2mYfay92Bh2gRJ5XEM/DMfzCWN+7uU6NWoTTHr4FuojnIQtjtq= VAj/JS9\n" + "w+dTSp/vYHl+c7uHd19uVRu/qLqV85+rm4tUGIjO7FfYuwyPqwmhuIsi3hs9QkSimh888= FmBpoKY\n" + "/tbKVTJZmSERKti9KEwtV2eVAR0znN5KW7lCB3mHVAhN7bUpcoDjfCzYIFARxwswTFu9g= FkwqUMY\n" + "I1KUOgIsVNs4llACioeXplYekWETR+YkJwDc/A=3D=3D\n" + "-----END OpenVPN auth-token server key-----"; -static const char *random_token =3D "SESS_ID_AT_ThhRItzOKNKrh3dfAAAAAFwzHp= wAAAAAXDMenDdrq0RoH3dkA1f7O3wO+7kZcx2DusVZrRmFlWQM9HOb"; +static const char *random_token =3D + "SESS_ID_AT_ThhRItzOKNKrh3dfAAAAAFwzHpwAAAAAXDMenDdrq0RoH3dkA1f7O3wO+7= kZcx2DusVZrRmFlWQM9HOb"; static int @@ -88,7 +92,7 @@ *state =3D ctx; struct key_parameters key =3D { 0 }; - key.hmac_size =3D MAX_HMAC_KEY_LENGTH; /* 64 byte of 0 */ + key.hmac_size =3D MAX_HMAC_KEY_LENGTH; /* 64 byte of 0 */ ctx->kt =3D auth_token_kt(); if (!ctx->kt.digest) @@ -116,7 +120,7 @@ static int teardown(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; free_key_ctx(&ctx->multi.opt.auth_token_key); wipe_auth_token(&ctx->multi); @@ -130,23 +134,21 @@ static void auth_token_basic_test(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; generate_auth_token(&ctx->up, &ctx->multi); strcpy(ctx->up.password, ctx->multi.auth_token); - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); } static void auth_token_fail_invalid_key(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; generate_auth_token(&ctx->up, &ctx->multi); strcpy(ctx->up.password, ctx->multi.auth_token); - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); /* Change auth-token key */ struct key_parameters key; @@ -162,15 +164,13 @@ memset(&key.hmac, 0, sizeof(key.hmac)); free_key_ctx(&ctx->multi.opt.auth_token_key); init_key_ctx(&ctx->multi.opt.auth_token_key, &key, &ctx->kt, false, "T= EST"); - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); - + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); } static void auth_token_test_timeout(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; now =3D 100000; generate_auth_token(&ctx->up, &ctx->multi); @@ -180,33 +180,31 @@ ctx->multi.auth_token_initial =3D NULL; /* No time has passed */ - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); /* Token before validity, should be rejected */ now =3D 100000 - 100; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED); + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); /* Token no valid for renegotiate_seconds but still for renewal_time */ - now =3D 100000 + 2*ctx->session->opt->renegotiate_seconds - 20; + now =3D 100000 + 2 * ctx->session->opt->renegotiate_seconds - 20; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED); + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); - now =3D 100000 + 2*ctx->session->opt->auth_token_renewal - 20; - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); + now =3D 100000 + 2 * ctx->session->opt->auth_token_renewal - 20; + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); /* Token past validity, should be rejected */ - now =3D 100000 + 2*ctx->session->opt->renegotiate_seconds + 20; + now =3D 100000 + 2 * ctx->session->opt->renegotiate_seconds + 20; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED); + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); /* But not when we reached our timeout */ now =3D 100000 + ctx->session->opt->auth_token_lifetime + 1; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED); + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); free(ctx->multi.auth_token_initial); ctx->multi.auth_token_initial =3D NULL; @@ -224,26 +222,25 @@ assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED); + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); ctx->multi.opt.auth_token_lifetime =3D 0; /* Non expiring token should be fine */ - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); } static void zerohmac(char *token) { - char *hmacstart =3D token + AUTH_TOKEN_SESSION_ID_LEN - + strlen(SESSION_ID_PREFIX) + 2*sizeof(uint64_t); + char *hmacstart =3D + token + AUTH_TOKEN_SESSION_ID_LEN + strlen(SESSION_ID_PREFIX) + 2 = * sizeof(uint64_t); memset(hmacstart, 0x8d, strlen(hmacstart)); } static void auth_token_test_known_keys(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; now =3D 0; /* Preload the session id so the same session id is used here */ @@ -258,8 +255,7 @@ assert_string_equal(now0key0, ctx->multi.auth_token); strcpy(ctx->up.password, ctx->multi.auth_token); - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); } static const char *lastsesion_statevalue; @@ -275,13 +271,12 @@ void auth_token_test_session_mismatch(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; /* Generate first auth token and check it is correct */ generate_auth_token(&ctx->up, &ctx->multi); strcpy(ctx->up.password, ctx->multi.auth_token); - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); char *token_sessiona =3D strdup(ctx->multi.auth_token); @@ -290,8 +285,7 @@ generate_auth_token(&ctx->up, &ctx->multi); strcpy(ctx->up.password, ctx->multi.auth_token); - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); assert_int_not_equal(0, memcmp(ctx->multi.auth_token_initial + strlen(= SESSION_ID_PREFIX), token_sessiona + strlen(SESSION_ID_PREF= IX), @@ -307,39 +301,37 @@ static void auth_token_test_empty_user(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; CLEAR(ctx->up.username); now =3D 0; generate_auth_token(&ctx->up, &ctx->multi); strcpy(ctx->up.password, ctx->multi.auth_token); - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK); + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); now =3D 100000; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED); + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); strcpy(ctx->up.username, "test user name"); now =3D 0; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_VALID_EMPTYUSER); + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_VALID_EMPTYUSER); strcpy(ctx->up.username, "test user name"); now =3D 100000; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED|AUTH_TOKEN_VALI= D_EMPTYUSER); + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED | AUTH_TOKEN_= VALID_EMPTYUSER); zerohmac(ctx->up.password); - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - 0); + assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), 0); } static void auth_token_test_env(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; =20 struct key_state *ks =3D &ctx->multi.session[TM_ACTIVE].key[KS_PRIMARY= ]; @@ -357,15 +349,16 @@ add_session_token_env(ctx->session, &ctx->multi, &ctx->up); assert_string_equal(lastsesion_statevalue, "Authenticated"); - ks->auth_token_state_flags =3D AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED; + ks->auth_token_state_flags =3D AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED; add_session_token_env(ctx->session, &ctx->multi, &ctx->up); assert_string_equal(lastsesion_statevalue, "Expired"); - ks->auth_token_state_flags =3D AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_VALID_EMP= TYUSER; + ks->auth_token_state_flags =3D AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_VALID_E= MPTYUSER; add_session_token_env(ctx->session, &ctx->multi, &ctx->up); assert_string_equal(lastsesion_statevalue, "AuthenticatedEmptyUser"); - ks->auth_token_state_flags =3D AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED|A= UTH_TOKEN_VALID_EMPTYUSER; + ks->auth_token_state_flags =3D + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED | AUTH_TOKEN_VALID_EMPTYUS= ER; add_session_token_env(ctx->session, &ctx->multi, &ctx->up); assert_string_equal(lastsesion_statevalue, "ExpiredEmptyUser"); } @@ -373,7 +366,7 @@ static void auth_token_test_random_keys(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; now =3D 0x5c331e9c; /* Preload the session id so the same session id is used here */ @@ -398,7 +391,7 @@ static void auth_token_test_key_load(void **state) { - struct test_context *ctx =3D (struct test_context *) *state; + struct test_context *ctx =3D (struct test_context *)*state; free_key_ctx(&ctx->multi.opt.auth_token_key); auth_token_init_secret(&ctx->multi.opt.auth_token_key, zeroinline, tru= e); diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/open= vpn/test_buffer.c index 3a1007a..c5d5557 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -44,13 +44,13 @@ assert_false(strprefix("12", "123")); } -#define testsep "," +#define testsep "," #define testnosep "" -#define teststr1 "one" -#define teststr2 "two" -#define teststr3 "three" +#define teststr1 "one" +#define teststr2 "two" +#define teststr3 "three" -#define assert_buf_equals_str(buf, str) \ +#define assert_buf_equals_str(buf, str) \ assert_int_equal(BLEN(buf), strlen(str)); \ assert_memory_equal(BPTR(buf), str, BLEN(buf)); @@ -83,9 +83,7 @@ test_buffer_format_hex_ex(void **state) { const int input_size =3D 10; - const uint8_t input[] =3D { - 0x01, 0x00, 0xff, 0x10, 0xff, 0x00, 0xf0, 0x0f, 0x09, 0x0a - }; + const uint8_t input[] =3D { 0x01, 0x00, 0xff, 0x10, 0xff, 0x00, 0xf0, = 0x0f, 0x09, 0x0a }; char *output; struct gc_arena gc =3D gc_new(); @@ -114,7 +112,8 @@ gc_free(&gc); } -struct test_buffer_list_aggregate_ctx { +struct test_buffer_list_aggregate_ctx +{ struct buffer_list *empty; struct buffer_list *one_two_three; struct buffer_list *zero_length_strings; @@ -124,7 +123,7 @@ static int test_buffer_list_setup(void **state) { - struct test_buffer_list_aggregate_ctx *ctx =3D calloc(1, sizeof(*ctx)= ); + struct test_buffer_list_aggregate_ctx *ctx =3D calloc(1, sizeof(*ctx)); ctx->empty =3D buffer_list_new(); ctx->one_two_three =3D buffer_list_new(); @@ -189,8 +188,7 @@ /* Aggregate the first two elements * (add 1 to max_len to test if "three" is not sneaked in too) */ - buffer_list_aggregate_separator(ctx->one_two_three, strlen(expected) += 1, - testsep); + buffer_list_aggregate_separator(ctx->one_two_three, strlen(expected) += 1, testsep); assert_int_equal(ctx->one_two_three->size, 2); struct buffer *buf =3D buffer_list_peek(ctx->one_two_three); assert_buf_equals_str(buf, expected); @@ -202,11 +200,10 @@ struct test_buffer_list_aggregate_ctx *ctx =3D *state; /* Aggregate all */ - buffer_list_aggregate_separator(ctx->one_two_three, 1<<16, testsep); + buffer_list_aggregate_separator(ctx->one_two_three, 1 << 16, testsep); assert_int_equal(ctx->one_two_three->size, 1); struct buffer *buf =3D buffer_list_peek(ctx->one_two_three); - assert_buf_equals_str(buf, - teststr1 testsep teststr2 testsep teststr3 tests= ep); + assert_buf_equals_str(buf, teststr1 testsep teststr2 testsep teststr3 = testsep); } static void @@ -215,7 +212,7 @@ struct test_buffer_list_aggregate_ctx *ctx =3D *state; /* Aggregate all */ - buffer_list_aggregate_separator(ctx->one_two_three, 1<<16, testnosep); + buffer_list_aggregate_separator(ctx->one_two_three, 1 << 16, testnosep= ); assert_int_equal(ctx->one_two_three->size, 1); struct buffer *buf =3D buffer_list_peek(ctx->one_two_three); assert_buf_equals_str(buf, teststr1 teststr2 teststr3); @@ -228,7 +225,7 @@ struct buffer_list *bl_zerolen =3D ctx->zero_length_strings; /* Aggregate all */ - buffer_list_aggregate_separator(bl_zerolen, 1<<16, testnosep); + buffer_list_aggregate_separator(bl_zerolen, 1 << 16, testnosep); assert_int_equal(bl_zerolen->size, 1); struct buffer *buf =3D buffer_list_peek(bl_zerolen); assert_buf_equals_str(buf, ""); @@ -241,7 +238,7 @@ struct buffer_list *bl_emptybuffers =3D ctx->empty_buffers; /* Aggregate all */ - buffer_list_aggregate_separator(bl_emptybuffers, 1<<16, testnosep); + buffer_list_aggregate_separator(bl_emptybuffers, 1 << 16, testnosep); assert_int_equal(bl_emptybuffers->size, 1); struct buffer *buf =3D buffer_list_peek(bl_emptybuffers); assert_int_equal(BLEN(buf), 0); @@ -345,11 +342,12 @@ assert_string_equal(buf, "There.is...a.nice......year.old.tr..ee."); strcpy(buf, "There is \x01 a 'nice' \"1234\"\n year old \ntr\x7f ee!"); - assert_false(string_mod(buf, CC_ALPHA|CC_DIGIT|CC_NEWLINE|CC_SINGLE_QU= OTE, CC_DOUBLE_QUOTE|CC_BLANK, '.')); + assert_false(string_mod(buf, CC_ALPHA | CC_DIGIT | CC_NEWLINE | CC_SIN= GLE_QUOTE, + CC_DOUBLE_QUOTE | CC_BLANK, '.')); assert_string_equal(buf, "There.is...a.'nice'..1234.\n.year.old.\ntr..= ee."); strcpy(buf, "There is a \\'nice\\' \"1234\" [*] year old \ntree!"); - assert_false(string_mod(buf, CC_PRINT, CC_BACKSLASH|CC_ASTERISK, '.')); + assert_false(string_mod(buf, CC_PRINT, CC_BACKSLASH | CC_ASTERISK, '.'= )); assert_string_equal(buf, "There is a .'nice.' \"1234\" [.] year old .t= ree!"); } @@ -361,7 +359,7 @@ =20 struct buffer buf =3D alloc_buf_gc(1024, &gc); - const char test1[] =3D "There is a nice 1234\x00 year old tree!"; + const char test1[] =3D "There is a nice 1234\x00 year old tree!"; buf_write(&buf, test1, sizeof(test1)); /* allow the null bytes and string but not the ! */ @@ -433,7 +431,7 @@ struct gc_arena gc =3D gc_new(); struct buffer buf =3D alloc_buf_gc(1024, &gc); - const char test1[] =3D "There is a nice 1234 year old tree!\n\r"; + const char test1[] =3D "There is a nice 1234 year old tree!\n\r"; buf_write(&buf, test1, sizeof(test1)); buf_chomp(&buf); /* Check that our own method agrees */ @@ -441,7 +439,7 @@ assert_string_equal(BSTR(&buf), "There is a nice 1234 year old tree!"); struct buffer buf2 =3D alloc_buf_gc(1024, &gc); - const char test2[] =3D "CR_RESPONSE,MTIx\x0a\x00"; + const char test2[] =3D "CR_RESPONSE,MTIx\x0a\x00"; buf_write(&buf2, test2, sizeof(test2)); buf_chomp(&buf2); @@ -462,26 +460,19 @@ cmocka_unit_test(test_buffer_printf_catrunc), cmocka_unit_test(test_buffer_format_hex_ex), cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separat= or_empty, - test_buffer_list_setup, - test_buffer_list_teardown), + test_buffer_list_setup, test_buffe= r_list_teardown), cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separat= or_noop, - test_buffer_list_setup, - test_buffer_list_teardown), + test_buffer_list_setup, test_buffe= r_list_teardown), cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separat= or_two, - test_buffer_list_setup, - test_buffer_list_teardown), + test_buffer_list_setup, test_buffe= r_list_teardown), cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separat= or_all, - test_buffer_list_setup, - test_buffer_list_teardown), + test_buffer_list_setup, test_buffe= r_list_teardown), cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separat= or_nosep, - test_buffer_list_setup, - test_buffer_list_teardown), + test_buffer_list_setup, test_buffe= r_list_teardown), cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separat= or_zerolen, - test_buffer_list_setup, - test_buffer_list_teardown), + test_buffer_list_setup, test_buffe= r_list_teardown), cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separat= or_emptybuffers, - test_buffer_list_setup, - test_buffer_list_teardown), + test_buffer_list_setup, test_buffe= r_list_teardown), cmocka_unit_test(test_buffer_free_gc_one), cmocka_unit_test(test_buffer_free_gc_two), cmocka_unit_test(test_buffer_gc_realloc), diff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_tests/open= vpn/test_crypto.c index 5b583c7..c06d0f9 100644 --- a/tests/unit_tests/openvpn/test_crypto.c +++ b/tests/unit_tests/openvpn/test_crypto.c @@ -157,7 +157,7 @@ const size_t seed_len =3D strlen(seedstr); - const unsigned char *secret =3D (const unsigned char *) ipsumlorem; + const unsigned char *secret =3D (const unsigned char *)ipsumlorem; size_t secret_len =3D strlen((const char *)secret); @@ -169,18 +169,16 @@ assert_false(ret); #else assert_true(ret); - uint8_t good_prf[32] =3D {0xd9, 0x8c, 0x85, 0x18, 0xc8, 0x5e, 0x94, 0x= 69, - 0x27, 0x91, 0x6a, 0xcf, 0xc2, 0xd5, 0x92, 0xfb, - 0xb1, 0x56, 0x7e, 0x4b, 0x4b, 0x14, 0x59, 0xe6, - 0xa9, 0x04, 0xac, 0x2d, 0xda, 0xb7, 0x2d, 0x67= }; + uint8_t good_prf[32] =3D { 0xd9, 0x8c, 0x85, 0x18, 0xc8, 0x5e, 0x94, 0= x69, 0x27, 0x91, 0x6a, + 0xcf, 0xc2, 0xd5, 0x92, 0xfb, 0xb1, 0x56, 0x7= e, 0x4b, 0x4b, 0x14, + 0x59, 0xe6, 0xa9, 0x04, 0xac, 0x2d, 0xda, 0xb= 7, 0x2d, 0x67 }; assert_memory_equal(good_prf, out, sizeof(out)); #endif } -static uint8_t testkey[20] =3D {0x0b, 0x00}; -static uint8_t goodhash[20] =3D {0x58, 0xea, 0x5a, 0xf0, 0x42, 0x94, 0xe9,= 0x17, - 0xed, 0x84, 0xb9, 0xf0, 0x83, 0x30, 0x23, 0= xae, - 0x8b, 0xa7, 0x7e, 0xb8}; +static uint8_t testkey[20] =3D { 0x0b, 0x00 }; +static uint8_t goodhash[20] =3D { 0x58, 0xea, 0x5a, 0xf0, 0x42, 0x94, 0xe9= , 0x17, 0xed, 0x84, + 0xb9, 0xf0, 0x83, 0x30, 0x23, 0xae, 0x8b, = 0xa7, 0x7e, 0xb8 }; static void crypto_test_hmac(void **state) @@ -193,8 +191,8 @@ memcpy(key, testkey, sizeof(key)); hmac_ctx_init(hmac, key, "SHA1"); - hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int) strlen(ipsuml= orem)); - hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int) strlen(ipsuml= orem)); + hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int)strlen(ipsumlo= rem)); + hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int)strlen(ipsumlo= rem)); uint8_t hash[20]; hmac_ctx_final(hmac, hash); @@ -204,8 +202,8 @@ /* try again */ hmac_ctx_reset(hmac); - hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int) strlen(ipsuml= orem)); - hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int) strlen(ipsuml= orem)); + hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int)strlen(ipsumlo= rem)); + hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int)strlen(ipsumlo= rem)); hmac_ctx_final(hmac, hash); assert_memory_equal(hash, goodhash, sizeof(hash)); @@ -214,8 +212,8 @@ memset(key, 0x55, sizeof(key)); hmac_ctx_reset(hmac); - hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int) strlen(ipsuml= orem)); - hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int) strlen(ipsuml= orem)); + hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int)strlen(ipsumlo= rem)); + hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int)strlen(ipsumlo= rem)); hmac_ctx_final(hmac, hash); assert_memory_equal(hash, goodhash, sizeof(hash)); @@ -482,22 +480,16 @@ crypto_test_hkdf_expand_testa1(void **state) { /* RFC 5889 A.1 Test Case 1 */ - uint8_t prk[32] =3D - {0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, - 0x0d, 0xdc, 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63, - 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31, - 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5}; + uint8_t prk[32] =3D { 0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, = 0x0d, 0xdc, 0x3f, + 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7, 0x= 3b, 0xb5, 0x0f, + 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0x= b3, 0xe5 }; - uint8_t info[10] =3D {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, - 0xf6, 0xf7, 0xf8, 0xf9}; + uint8_t info[10] =3D { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,= 0xf8, 0xf9 }; - uint8_t okm[42] =3D - {0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, - 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, - 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c, - 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, - 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, - 0x58, 0x65}; + uint8_t okm[42] =3D { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, = 0x90, 0x43, 0x4f, + 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x= 90, 0xcf, 0x1a, + 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0x= c5, 0xbf, 0x34, + 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x= 65 }; uint8_t out[42]; ovpn_hkdf_expand(prk, info, sizeof(info), out, sizeof(out)); @@ -509,39 +501,28 @@ crypto_test_hkdf_expand_testa2(void **state) { /* RFC 5889 A.2 Test Case 2 */ - uint8_t prk[32] =3D - {0x06, 0xa6, 0xb8, 0x8c, 0x58, 0x53, 0x36, 0x1a, - 0x06, 0x10, 0x4c, 0x9c, 0xeb, 0x35, 0xb4, 0x5c, - 0xef, 0x76, 0x00, 0x14, 0x90, 0x46, 0x71, 0x01, - 0x4a, 0x19, 0x3f, 0x40, 0xc1, 0x5f, 0xc2, 0x44}; + uint8_t prk[32] =3D { 0x06, 0xa6, 0xb8, 0x8c, 0x58, 0x53, 0x36, 0x1a, = 0x06, 0x10, 0x4c, + 0x9c, 0xeb, 0x35, 0xb4, 0x5c, 0xef, 0x76, 0x00, 0x= 14, 0x90, 0x46, + 0x71, 0x01, 0x4a, 0x19, 0x3f, 0x40, 0xc1, 0x5f, 0x= c2, 0x44 }; - uint8_t info[80] =3D - {0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, - 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, - 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}; + uint8_t info[80] =3D { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,= 0xb8, 0xb9, 0xba, 0xbb, + 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0= xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0= xd0, 0xd1, 0xd2, 0xd3, + 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0= xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0= xe8, 0xe9, 0xea, 0xeb, + 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0= xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; const int L =3D 82; - uint8_t okm[82] =3D - {0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, - 0xc8, 0xe7, 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34, - 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e, 0xfa, 0xd8, - 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, - 0x59, 0x04, 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72, - 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, 0x0e, 0x09, - 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8, - 0x36, 0x77, 0x93, 0xa9, 0xac, 0xa3, 0xdb, 0x71, - 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec, 0x3e, 0x87, - 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f, - 0x1d, 0x87}; + uint8_t okm[82] =3D { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, = 0xc8, 0xe7, 0xf7, 0x8c, + 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda, 0x= 2d, 0x4e, 0xfa, 0xd8, + 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, 0x= 59, 0x04, 0x5a, 0x99, + 0xca, 0xc7, 0x82, 0x72, 0x71, 0xcb, 0x41, 0xc6, 0x= 5e, 0x59, 0x0e, 0x09, + 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8, 0x= 36, 0x77, 0x93, 0xa9, + 0xac, 0xa3, 0xdb, 0x71, 0xcc, 0x30, 0xc5, 0x81, 0x= 79, 0xec, 0x3e, 0x87, + 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f, 0x= 1d, 0x87 }; - uint8_t out[82] =3D {0xaa}; + uint8_t out[82] =3D { 0xaa }; ovpn_hkdf_expand(prk, info, sizeof(info), out, L); assert_memory_equal(out, okm, L); @@ -551,22 +532,17 @@ crypto_test_hkdf_expand_testa3(void **state) { /* RFC 5889 A.3 Test Case 3 */ - uint8_t prk[32] =3D - {0x19, 0xef, 0x24, 0xa3, 0x2c, 0x71, 0x7b, 0x16, - 0x7f, 0x33, 0xa9, 0x1d, 0x6f, 0x64, 0x8b, 0xdf, - 0x96, 0x59, 0x67, 0x76, 0xaf, 0xdb, 0x63, 0x77, - 0xac, 0x43, 0x4c, 0x1c, 0x29, 0x3c, 0xcb, 0x04}; + uint8_t prk[32] =3D { 0x19, 0xef, 0x24, 0xa3, 0x2c, 0x71, 0x7b, 0x16, = 0x7f, 0x33, 0xa9, + 0x1d, 0x6f, 0x64, 0x8b, 0xdf, 0x96, 0x59, 0x67, 0x= 76, 0xaf, 0xdb, + 0x63, 0x77, 0xac, 0x43, 0x4c, 0x1c, 0x29, 0x3c, 0x= cb, 0x04 }; uint8_t info[] =3D {}; int L =3D 42; - uint8_t okm[42] =3D - {0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, - 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31, - 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e, - 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, - 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a, - 0x96, 0xc8}; + uint8_t okm[42] =3D { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, = 0x71, 0x5f, 0x80, + 0x2a, 0x06, 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x= 5c, 0x5e, 0xe1, + 0x87, 0x9e, 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x= 8d, 0x2d, 0x9d, + 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a, 0x96, 0x= c8 }; uint8_t out[42]; ovpn_hkdf_expand(prk, info, 0, out, L); @@ -580,23 +556,17 @@ /* tests the HDKF with a label/okm that OpenVPN itself uses in OpenSSL= 3 * HDKF unit test*/ - uint8_t prk[32] =3D - {0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, - 0x0d, 0xdc, 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63, - 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31, - 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5}; + uint8_t prk[32] =3D { 0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, = 0x0d, 0xdc, 0x3f, + 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7, 0x= 3b, 0xb5, 0x0f, + 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0x= b3, 0xe5 }; - uint8_t info[18] =3D - {0x00, 0x1b, 0x0e, 0x6f, 0x76, 0x70, 0x6e, 0x20, - 0x75, 0x6e, 0x69, 0x74, 0x20, 0x74, 0x65, 0x73, - 0x74, 0x00}; + uint8_t info[18] =3D { 0x00, 0x1b, 0x0e, 0x6f, 0x76, 0x70, 0x6e, 0x20,= 0x75, + 0x6e, 0x69, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, 0= x00 }; =20 int L =3D 27; - uint8_t okm[27] =3D - {0x87, 0x5a, 0x8e, 0xec, 0x18, 0x55, 0x63, 0x80, - 0xb8, 0xd9, 0x33, 0xed, 0x32, 0x3c, 0x2d, 0xf8, - 0xe8, 0xec, 0xcf, 0x49, 0x72, 0xe6, 0x83, 0xf0, - 0x6a, 0x83, 0xac }; + uint8_t okm[27] =3D { 0x87, 0x5a, 0x8e, 0xec, 0x18, 0x55, 0x63, 0x80, = 0xb8, + 0xd9, 0x33, 0xed, 0x32, 0x3c, 0x2d, 0xf8, 0xe8, 0x= ec, + 0xcf, 0x49, 0x72, 0xe6, 0x83, 0xf0, 0x6a, 0x83, 0x= ac }; uint8_t out[27]; ovpn_hkdf_expand(prk, info, sizeof(info), out, L); @@ -607,19 +577,16 @@ void crypto_test_ovpn_label_expand(void **state) { - uint8_t secret[32] =3D - {0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, - 0x0d, 0xdc, 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63, - 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31, - 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5}; + uint8_t secret[32] =3D { 0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xd= f, 0x0d, 0xdc, 0x3f, + 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7,= 0x3b, 0xb5, 0x0f, + 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2,= 0xb3, 0xe5 }; - const uint8_t *label =3D (const uint8_t *) ("unit test"); + const uint8_t *label =3D (const uint8_t *)("unit test"); uint8_t out[16]; ovpn_expand_label(secret, sizeof(secret), label, 9, NULL, 0, out, size= of(out)); - uint8_t out_expected[16] =3D - {0x18, 0x5e, 0xaa, 0x1c, 0x7f, 0x22, 0x8a, 0xb8, - 0xeb, 0x29, 0x77, 0x32, 0x14, 0xd9, 0x20, 0x46}; + uint8_t out_expected[16] =3D { 0x18, 0x5e, 0xaa, 0x1c, 0x7f, 0x22, 0x8= a, 0xb8, + 0xeb, 0x29, 0x77, 0x32, 0x14, 0xd9, 0x20,= 0x46 }; assert_memory_equal(out, out_expected, 16); } @@ -631,15 +598,13 @@ * openvpn_PRF ifdef maze */ bool -ossl_expand_label(const uint8_t *secret, size_t secret_len, - const uint8_t *label, size_t label_len, - const uint8_t *context, size_t context_len, - uint8_t *out, uint16_t out_len) +ossl_expand_label(const uint8_t *secret, size_t secret_len, const uint8_t = *label, size_t label_len, + const uint8_t *context, size_t context_len, uint8_t *out= , uint16_t out_len) { OSSL_LIB_CTX *libctx =3D NULL; const char *properties =3D NULL; =20 - const uint8_t *label_prefix =3D (const uint8_t *) ("ovpn "); + const uint8_t *label_prefix =3D (const uint8_t *)("ovpn "); const size_t label_prefix_len =3D 5; EVP_KDF *kdf =3D EVP_KDF_fetch(libctx, OSSL_KDF_NAME_TLS1_3_KDF, prope= rties); @@ -658,15 +623,12 @@ int mode =3D EVP_PKEY_HKDEF_MODE_EXPAND_ONLY; *p++ =3D OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode); - *p++ =3D OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, - (char *) mdname, 0); - *p++ =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, - (unsigned char *) secret, has= hlen); - *p++ =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PREFIX, - (unsigned char *) label_prefi= x, + *p++ =3D OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, (char= *)mdname, 0); + *p++ =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (unsign= ed char *)secret, hashlen); + *p++ =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PREFIX, (uns= igned char *)label_prefix, label_prefix_len); - *p++ =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_LABEL, - (unsigned char *) label, labe= l_len); + *p++ =3D + OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_LABEL, (unsigned = char *)label, label_len); *p++ =3D OSSL_PARAM_construct_end(); @@ -681,13 +643,11 @@ void crypto_test_ovpn_expand_openssl3(void **state) { - uint8_t secret[32] =3D - {0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, - 0x0d, 0xdc, 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63, - 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31, - 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5}; + uint8_t secret[32] =3D { 0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xd= f, 0x0d, 0xdc, 0x3f, + 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7,= 0x3b, 0xb5, 0x0f, + 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2,= 0xb3, 0xe5 }; - const uint8_t *label =3D (const uint8_t *) ("unit test"); + const uint8_t *label =3D (const uint8_t *)("unit test"); const size_t labellen =3D 9; uint8_t out[27]; @@ -726,11 +686,10 @@ init_key_type(&data->kt, "AES-128-GCM", "none", true, false); /* have an epoch key that uses 0x23 for the key for all bytes */ - struct epoch_key epoch1send =3D { .epoch =3D 1, .epoch_key =3D {0x23} = }; - struct epoch_key epoch1recv =3D { .epoch =3D 1, .epoch_key =3D {0x27} = }; + struct epoch_key epoch1send =3D { .epoch =3D 1, .epoch_key =3D { 0x23 = } }; + struct epoch_key epoch1recv =3D { .epoch =3D 1, .epoch_key =3D { 0x27 = } }; - epoch_init_key_ctx(&data->co, &data->kt, &epoch1send, - &epoch1recv, *num_future_keys); + epoch_init_key_ctx(&data->co, &data->kt, &epoch1send, &epoch1recv, *nu= m_future_keys); *state =3D data; return 0; @@ -914,7 +873,7 @@ void epoch_test_derive_data_key(void **state) { - struct epoch_key e17 =3D { .epoch =3D 17, .epoch_key =3D { 19, 12 }}; + struct epoch_key e17 =3D { .epoch =3D 17, .epoch_key =3D { 19, 12 } }; struct key_type kt =3D { 0 }; struct key_parameters key_parameters =3D { 0 }; init_key_type(&kt, "AES-192-GCM", "none", true, false); @@ -925,13 +884,12 @@ assert_int_equal(key_parameters.cipher_size, 24); assert_int_equal(key_parameters.hmac_size, 12); - uint8_t exp_cipherkey[24] =3D - {0xed, 0x85, 0x33, 0xdb, 0x1c, 0x28, 0xac, 0xe4, - 0x18, 0xe9, 0x00, 0x6a, 0xb2, 0x9c, 0x17, 0x41, - 0x7d, 0x60, 0xeb, 0xe6, 0xcd, 0x90, 0xbf, 0x0a}; + uint8_t exp_cipherkey[24] =3D { 0xed, 0x85, 0x33, 0xdb, 0x1c, 0x28, 0x= ac, 0xe4, + 0x18, 0xe9, 0x00, 0x6a, 0xb2, 0x9c, 0x17= , 0x41, + 0x7d, 0x60, 0xeb, 0xe6, 0xcd, 0x90, 0xbf= , 0x0a }; - uint8_t exp_impl_iv[12] =3D - {0x86, 0x89, 0x0a, 0xab, 0xf0, 0x32, 0xcb, 0x59, 0xf4, 0xcf, 0xa3, 0x4= e}; + uint8_t exp_impl_iv[12] =3D { 0x86, 0x89, 0x0a, 0xab, 0xf0, 0x32, + 0xcb, 0x59, 0xf4, 0xcf, 0xa3, 0x4e }; assert_memory_equal(key_parameters.cipher, exp_cipherkey, sizeof(exp_c= ipherkey)); assert_memory_equal(key_parameters.hmac, exp_impl_iv, sizeof(exp_impl_= iv)); @@ -961,20 +919,16 @@ cmocka_unit_test(crypto_test_ovpn_expand_openssl3), cmocka_unit_test_prestate_setup_teardown(crypto_test_epoch_key_gen= eration, crypto_test_epoch_setup, - crypto_test_epoch_teardow= n, - &prestate_num16), + crypto_test_epoch_teardow= n, &prestate_num16), cmocka_unit_test_prestate_setup_teardown(crypto_test_epoch_key_rot= ation, crypto_test_epoch_setup, - crypto_test_epoch_teardow= n, - &prestate_num13), + crypto_test_epoch_teardow= n, &prestate_num13), cmocka_unit_test_prestate_setup_teardown(crypto_test_epoch_key_rec= eive_lookup, crypto_test_epoch_setup, - crypto_test_epoch_teardow= n, - &prestate_num13), + crypto_test_epoch_teardow= n, &prestate_num13), cmocka_unit_test_prestate_setup_teardown(crypto_test_epoch_key_ove= rflow, crypto_test_epoch_setup, - crypto_test_epoch_teardow= n, - &prestate_num32), + crypto_test_epoch_teardow= n, &prestate_num32), cmocka_unit_test(epoch_test_derive_data_key) }; diff --git a/tests/unit_tests/openvpn/test_cryptoapi.c b/tests/unit_tests/o= penvpn/test_cryptoapi.c index 9225b4d..4ee624e 100644 --- a/tests/unit_tests/openvpn/test_cryptoapi.c +++ b/tests/unit_tests/openvpn/test_cryptoapi.c @@ -32,7 +32,7 @@ #include "xkey_common.h" #include "cert_data.h" -#if defined(HAVE_XKEY_PROVIDER) && defined (ENABLE_CRYPTOAPI) +#if defined(HAVE_XKEY_PROVIDER) && defined(ENABLE_CRYPTOAPI) #include #include #include @@ -43,19 +43,18 @@ #include "test_common.h" #include -#include /* pull-in the whole file to test static functions = */ +#include /* pull-in the whole file to test static fu= nctions */ struct management *management; /* global */ static OSSL_PROVIDER *prov[2]; /* mock a management function that xkey_provider needs */ char * -management_query_pk_sig(struct management *man, const char *b64_data, - const char *algorithm) +management_query_pk_sig(struct management *man, const char *b64_data, cons= t char *algorithm) { - (void) man; - (void) b64_data; - (void) algorithm; + (void)man; + (void)b64_data; + (void)algorithm; return NULL; } @@ -74,14 +73,12 @@ OSSL_LIB_CTX *tls_libctx; #ifndef _countof -#define _countof(x) sizeof((x))/sizeof(*(x)) +#define _countof(x) sizeof((x)) / sizeof(*(x)) #endif /* test data */ -static const uint8_t test_hash[] =3D { - 0x77, 0x38, 0x65, 0x00, 0x1e, 0x96, 0x48, 0xc6, 0x57, 0x0b, 0xae, - 0xc0, 0xb7, 0x96, 0xf9, 0x66, 0x4d, 0x5f, 0xd0, 0xb7 -}; +static const uint8_t test_hash[] =3D { 0x77, 0x38, 0x65, 0x00, 0x1e, 0x96,= 0x48, 0xc6, 0x57, 0x0b, + 0xae, 0xc0, 0xb7, 0x96, 0xf9, 0x66, 0= x4d, 0x5f, 0xd0, 0xb7 }; /* valid test strings to test with and without embedded and trailing space= s */ static const char *valid_str[] =3D { @@ -102,13 +99,13 @@ */ static struct test_cert { - const char *const cert; /* certificate as PEM */ - const char *const key; /* key as unencrypted PEM */ - const char *const cname; /* common-name */ - const char *const issuer; /* issuer common-name */ - const char *const friendly_name; /* identifies certs loaded to the = store -- keep unique */ - const char *hash; /* SHA1 fingerprint */ - int valid; /* nonzero if certificate has not = expired */ + const char *const cert; /* certificate as PEM */ + const char *const key; /* key as unencrypted PEM */ + const char *const cname; /* common-name */ + const char *const issuer; /* issuer common-name */ + const char *const friendly_name; /* identifies certs loaded to the sto= re -- keep unique */ + const char *hash; /* SHA1 fingerprint */ + int valid; /* nonzero if certificate has not exp= ired */ } certs[5]; static bool certs_loaded; @@ -119,11 +116,11 @@ init_cert_data(void) { struct test_cert certs_local[] =3D { - {cert1, key1, cname1, "OVPN TEST CA1", "OVPN Test Cert 1", ha= sh1, 1}, - {cert2, key2, cname2, "OVPN TEST CA2", "OVPN Test Cert 2", ha= sh2, 1}, - {cert3, key3, cname3, "OVPN TEST CA1", "OVPN Test Cert 3", ha= sh3, 1}, - {cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", ha= sh4, 0}, - {0} + { cert1, key1, cname1, "OVPN TEST CA1", "OVPN Test Cert 1", hash1,= 1 }, + { cert2, key2, cname2, "OVPN TEST CA2", "OVPN Test Cert 2", hash2,= 1 }, + { cert3, key3, cname3, "OVPN TEST CA1", "OVPN Test Cert 3", hash3,= 1 }, + { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", hash4,= 0 }, + { 0 } }; assert(sizeof(certs_local) =3D=3D sizeof(certs)); memcpy(certs, certs_local, sizeof(certs_local)); @@ -145,20 +142,21 @@ static void import_certs(void **state) { - (void) state; + (void)state; if (certs_loaded) { return; } init_cert_data(); - user_store =3D CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM= _STORE_CURRENT_USER - |CERT_STORE_OPEN_EXISTING_FLAG, L"MY"); + user_store =3D + CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, + CERT_SYSTEM_STORE_CURRENT_USER | CERT_STORE_OPEN_EXI= STING_FLAG, L"MY"); assert_non_null(user_store); for (struct test_cert *c =3D certs; c->cert; c++) { /* Convert PEM cert & key to pkcs12 and import */ - const char *pass =3D "opensesame"; /* some password */ - const wchar_t *wpass =3D L"opensesame"; /* same as a wide string= */ + const char *pass =3D "opensesame"; /* some password */ + const wchar_t *wpass =3D L"opensesame"; /* same as a wide string */ X509 *x509 =3D NULL; EVP_PKEY *pkey =3D NULL; @@ -192,7 +190,7 @@ return; } - CRYPT_DATA_BLOB blob =3D {.cbData =3D 0, .pbData =3D NULL}; + CRYPT_DATA_BLOB blob =3D { .cbData =3D 0, .pbData =3D NULL }; int len =3D i2d_PKCS12(p12, &blob.pbData); /* pbData will be alloc= ated by OpenSSL */ if (len <=3D 0) { @@ -201,7 +199,7 @@ } blob.cbData =3D len; - DWORD flags =3D PKCS12_ALLOW_OVERWRITE_KEY|PKCS12_ALWAYS_CNG_KSP; + DWORD flags =3D PKCS12_ALLOW_OVERWRITE_KEY | PKCS12_ALWAYS_CNG_KSP; HCERTSTORE tmp_store =3D PFXImportCertStore(&blob, wpass, flags); PKCS12_free(p12); OPENSSL_free(blob.pbData); @@ -229,7 +227,7 @@ static int cleanup(void **state) { - (void) state; + (void)state; struct gc_arena gc =3D gc_new(); if (user_store) /* delete all certs we imported */ { @@ -261,7 +259,7 @@ static void test_find_cert_bythumb(void **state) { - (void) state; + (void)state; char select_string[64]; struct gc_arena gc =3D gc_new(); const CERT_CONTEXT *ctx; @@ -294,7 +292,7 @@ static void test_find_cert_byname(void **state) { - (void) state; + (void)state; char select_string[64]; struct gc_arena gc =3D gc_new(); const CERT_CONTEXT *ctx; @@ -327,7 +325,7 @@ static void test_find_cert_byissuer(void **state) { - (void) state; + (void)state; char select_string[64]; struct gc_arena gc =3D gc_new(); const CERT_CONTEXT *ctx; @@ -360,7 +358,7 @@ static int setup_xkey_provider(void **state) { - (void) state; + (void)state; /* Initialize providers in a way matching what OpenVPN core does */ tls_libctx =3D OSSL_LIB_CTX_new(); prov[0] =3D OSSL_PROVIDER_load(tls_libctx, "default"); @@ -375,7 +373,7 @@ static int teardown_xkey_provider(void **state) { - (void) state; + (void)state; for (size_t i =3D 0; i < _countof(prov); i++) { if (prov[i]) @@ -397,7 +395,7 @@ void test_cryptoapi_sign(void **state) { - (void) state; + (void)state; char select_string[64]; X509 *x509 =3D NULL; EVP_PKEY *privkey =3D NULL; @@ -431,7 +429,7 @@ void test_ssl_ctx_use_cryptoapicert(void **state) { - (void) state; + (void)state; char select_string[64]; import_certs(state); /* a no-op if already imported */ @@ -455,7 +453,8 @@ /* Use OpenSSL to check that the cert and private key in ssl_ctx "= match" */ if (!SSL_CTX_check_private_key(ssl_ctx)) { - fail_msg("Certificate and private key in ssl_ctx do not match = for <%s>", c->friendly_name); + fail_msg("Certificate and private key in ssl_ctx do not match = for <%s>", + c->friendly_name); return; } @@ -467,7 +466,7 @@ test_parse_hexstring(void **state) { unsigned char hash[255]; - (void) state; + (void)state; for (int i =3D 0; i < _countof(valid_str); i++) { @@ -513,4 +512,4 @@ return 0; } -#endif /* ifdef HAVE_XKEY_PROVIDER */ +#endif /* ifdef HAVE_XKEY_PROVIDER */ diff --git a/tests/unit_tests/openvpn/test_misc.c b/tests/unit_tests/openvp= n/test_misc.c index 0c604ff..337b6aa 100644 --- a/tests/unit_tests/openvpn/test_misc.c +++ b/tests/unit_tests/openvpn/test_misc.c @@ -45,14 +45,18 @@ { struct gc_arena gc =3D gc_new(); - const char *input =3D "V4,dev-type tun,link-mtu 1457,tun-mtu 1400,prot= o UDPv4,auth SHA1,keysize 128,key-method 2,tls-server"; + const char *input =3D + "V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,= keysize 128,key-method 2,tls-server"; const char *output =3D options_string_compat_lzo(input, &gc); - assert_string_equal(output, "V4,dev-type tun,link-mtu 1458,tun-mtu 140= 0,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo"); + assert_string_equal( + output, + "V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,auth SHA1,= keysize 128,key-method 2,tls-server,comp-lzo"); /* This string is has a much too small link-mtu so we should fail on i= t" */ - input =3D "V4,dev-type tun,link-mtu 2,tun-mtu 1400,proto UDPv4,auth SH= A1,keysize 128,key-method 2,tls-server"; + input =3D + "V4,dev-type tun,link-mtu 2,tun-mtu 1400,proto UDPv4,auth SHA1,key= size 128,key-method 2,tls-server"; output =3D options_string_compat_lzo(input, &gc); @@ -65,11 +69,14 @@ assert_string_equal(input, output); - input =3D "V4,dev-type tun,link-mtu 999,tun-mtu 1400,proto UDPv4,auth = SHA1,keysize 128,key-method 2,tls-server"; + input =3D + "V4,dev-type tun,link-mtu 999,tun-mtu 1400,proto UDPv4,auth SHA1,k= eysize 128,key-method 2,tls-server"; output =3D options_string_compat_lzo(input, &gc); /* 999 -> 1000, 3 to 4 chars */ - assert_string_equal(output, "V4,dev-type tun,link-mtu 1000,tun-mtu 140= 0,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo"); + assert_string_equal( + output, + "V4,dev-type tun,link-mtu 1000,tun-mtu 1400,proto UDPv4,auth SHA1,= keysize 128,key-method 2,tls-server,comp-lzo"); gc_free(&gc); } @@ -111,7 +118,6 @@ } - struct word { const char *word; @@ -122,7 +128,7 @@ static uint32_t word_hash_function(const void *key, uint32_t iv) { - const char *str =3D (const char *) key; + const char *str =3D (const char *)key; const int len =3D strlen(str); return hash_func((const uint8_t *)str, len, iv); } @@ -162,11 +168,10 @@ static void test_list(void **state) { - -/* - * Test the hash code by implementing a simple - * word frequency algorithm. - */ + /* + * Test the hash code by implementing a simple + * word frequency algorithm. + */ struct gc_arena gc =3D gc_new(); struct hash *hash =3D hash_init(10000, get_random(), word_hash_functio= n, word_compare_function); @@ -175,7 +180,7 @@ printf("hash_init n_buckets=3D%d mask=3D0x%08x\n", hash->n_buckets, ha= sh->mask); =20 char wordfile[PATH_MAX] =3D { 0 }; - openvpn_test_get_srcdir_dir(wordfile, PATH_MAX, "/../../../COPYRIGHT.G= PL" ); + openvpn_test_get_srcdir_dir(wordfile, PATH_MAX, "/../../../COPYRIGHT.G= PL"); FILE *words =3D fopen(wordfile, "r"); assert_non_null(words); @@ -201,7 +206,7 @@ c =3D buf[bi++]; if (isalnum(c) || c =3D=3D '_') { - assert_true(wbi < (int) sizeof(wordbuf)); + assert_true(wbi < (int)sizeof(wordbuf)); wordbuf[wbi++] =3D c; } else @@ -210,13 +215,13 @@ { wordcount++; - ASSERT(wbi < (int) sizeof(wordbuf)); + ASSERT(wbi < (int)sizeof(wordbuf)); wordbuf[wbi++] =3D '\0'; /* word is parsed from stdin */ /* does it already exist in table? */ - struct word *w =3D (struct word *) hash_lookup(hash, w= ordbuf); + struct word *w =3D (struct word *)hash_lookup(hash, wo= rdbuf); if (w) { @@ -231,13 +236,13 @@ w->word =3D string_alloc(wordbuf, &gc); w->n =3D 1; assert_true(hash_add(hash, w->word, w, false)); - assert_true(hash_add(nhash, w->word, (void *) ((pt= r_type )(random() & 0x0F) + 1), false)); + assert_true(hash_add(nhash, w->word, + (void *)((ptr_type)(random() = & 0x0F) + 1), false)); } } wbi =3D 0; } - } - while (c); + } while (c); } assert_int_equal(wordcount, 2978); @@ -262,7 +267,7 @@ while ((he =3D hash_iterator_next(&hi))) { - struct word *w =3D (struct word *) he->value; + struct word *w =3D (struct word *)he->value; /*printf("%6d '%s'\n", w->n, w->word); */ ++count; /* check a few words to match prior results */ @@ -270,19 +275,19 @@ { assert_int_equal(w->n, 49); } - else if (!strcmp(w->word, "redistribute")) + else if (!strcmp(w->word, "redistribute")) { assert_int_equal(w->n, 5); } - else if (!strcmp(w->word, "circumstances")) + else if (!strcmp(w->word, "circumstances")) { assert_int_equal(w->n, 1); } - else if (!strcmp(w->word, "so")) + else if (!strcmp(w->word, "so")) { assert_int_equal(w->n, 8); } - else if (!strcmp(w->word, "BECAUSE")) + else if (!strcmp(w->word, "BECAUSE")) { assert_int_equal(w->n, 1); } @@ -297,12 +302,12 @@ { for (ptr_type i =3D 1; i <=3D 16; ++i) { - struct hash_element *item =3D hash_lookup_by_value(nhash, (voi= d *) i); - hash_remove_by_value(nhash, (void *) i); + struct hash_element *item =3D hash_lookup_by_value(nhash, (voi= d *)i); + hash_remove_by_value(nhash, (void *)i); /* check item got removed if it was present before */ if (item) { - assert_null(hash_lookup_by_value(nhash, (void *) i)); + assert_null(hash_lookup_by_value(nhash, (void *)i)); } } } @@ -379,14 +384,12 @@ mock_set_debug_level(saved_log_level); } -const struct CMUnitTest misc_tests[] =3D { - cmocka_unit_test(test_compat_lzo_string), - cmocka_unit_test(test_auth_fail_temp_no_flags), - cmocka_unit_test(test_auth_fail_temp_flags), - cmocka_unit_test(test_auth_fail_temp_flags_msg), - cmocka_unit_test(test_list), - cmocka_unit_test(test_atoi_variants) -}; +const struct CMUnitTest misc_tests[] =3D { cmocka_unit_test(test_compat_lz= o_string), + cmocka_unit_test(test_auth_fail_t= emp_no_flags), + cmocka_unit_test(test_auth_fail_t= emp_flags), + cmocka_unit_test(test_auth_fail_t= emp_flags_msg), + cmocka_unit_test(test_list), + cmocka_unit_test(test_atoi_varian= ts) }; int main(void) diff --git a/tests/unit_tests/openvpn/test_ncp.c b/tests/unit_tests/openvpn= /test_ncp.c index 9c40f5c..16bf1cf 100644 --- a/tests/unit_tests/openvpn/test_ncp.c +++ b/tests/unit_tests/openvpn/test_ncp.c @@ -47,8 +47,7 @@ /* Define this function here as dummy since including the ssl_*.c files * leads to having to include even more unrelated code */ bool -key_state_export_keying_material(struct tls_session *session, - const char *label, size_t label_size, +key_state_export_keying_material(struct tls_session *session, const char *= label, size_t label_size, void *ekm, size_t ekm_size) { ASSERT(0); @@ -73,8 +72,7 @@ bool have_blowfish =3D cipher_valid("BF-CBC"); assert_string_equal(mutate_ncp_cipher_list("none", &gc), "none"); - assert_string_equal(mutate_ncp_cipher_list("AES-256-GCM:none", &gc), - "AES-256-GCM:none"); + assert_string_equal(mutate_ncp_cipher_list("AES-256-GCM:none", &gc), "= AES-256-GCM:none"); assert_string_equal(mutate_ncp_cipher_list(aes_ciphers, &gc), aes_ciph= ers); @@ -86,8 +84,7 @@ if (have_chacha && have_blowfish) { assert_string_equal(mutate_ncp_cipher_list(bf_chacha, &gc), bf_cha= cha); - assert_string_equal(mutate_ncp_cipher_list("BF-CBC:CHACHA20-POLY13= 05", &gc), - bf_chacha); + assert_string_equal(mutate_ncp_cipher_list("BF-CBC:CHACHA20-POLY13= 05", &gc), bf_chacha); } else { @@ -99,14 +96,14 @@ aes_ciphers); /* Check that optional ciphers work */ - assert_string_equal(mutate_ncp_cipher_list("?AES-256-GCM:?AES-128-GCM"= , &gc), - aes_ciphers); + assert_string_equal(mutate_ncp_cipher_list("?AES-256-GCM:?AES-128-GCM"= , &gc), aes_ciphers); /* All unsupported should still yield an empty list */ assert_ptr_equal(mutate_ncp_cipher_list("?kugelfisch:?grasshopper", &g= c), NULL); /* If the last is optional, previous invalid ciphers should be ignored= */ - assert_ptr_equal(mutate_ncp_cipher_list("Vollbit:Littlebit:AES-256-CBC= :BF-CBC:?nixbit", &gc), NULL); + assert_ptr_equal(mutate_ncp_cipher_list("Vollbit:Littlebit:AES-256-CBC= :BF-CBC:?nixbit", &gc), + NULL); /* We do not support CCM ciphers */ assert_ptr_equal(mutate_ncp_cipher_list("AES-256-GCM:AES-128-CCM", &gc= ), NULL); @@ -127,19 +124,19 @@ assert_ptr_equal(mutate_ncp_cipher_list("AES-256-GCM:vollbit", &gc), N= ULL); assert_ptr_equal(mutate_ncp_cipher_list("", &gc), NULL); - assert_ptr_equal(mutate_ncp_cipher_list( - "ChaCha20-Poly1305:ChaCha20-Poly1305:ChaCha20-Pol= y1305:" - "ChaCha20-Poly1305:ChaCha20-Poly1305:ChaCha20-Pol= y1305:" - "ChaCha20-Poly1305", &gc), NULL); + assert_ptr_equal(mutate_ncp_cipher_list("ChaCha20-Poly1305:ChaCha20-Po= ly1305:ChaCha20-Poly1305:" + "ChaCha20-Poly1305:ChaCha20-Po= ly1305:ChaCha20-Poly1305:" + "ChaCha20-Poly1305", + &gc), + NULL); #ifdef ENABLE_CRYPTO_OPENSSL - assert_string_equal(mutate_ncp_cipher_list("id-aes128-GCM:id-aes256-GC= M", - &gc), "AES-128-GCM:AES-256-= GCM"); + assert_string_equal(mutate_ncp_cipher_list("id-aes128-GCM:id-aes256-GC= M", &gc), + "AES-128-GCM:AES-256-GCM"); #else if (have_blowfish) { - assert_string_equal(mutate_ncp_cipher_list("BLOWFISH-CBC", - &gc), "BF-CBC"); + assert_string_equal(mutate_ncp_cipher_list("BLOWFISH-CBC", &gc), "= BF-CBC"); } #endif gc_free(&gc); @@ -193,37 +190,28 @@ const char *serverlist =3D "CHACHA20_POLY1305:AES-128-GCM"; const char *serverlistbfcbc =3D "CHACHA20_POLY1305:AES-128-GCM:BF-CBC:= none"; - best_cipher =3D ncp_get_best_cipher(serverlist, - "IV_YOLO=3DNO\nIV_BAR=3D7", - "BF-CBC", &gc); + best_cipher =3D ncp_get_best_cipher(serverlist, "IV_YOLO=3DNO\nIV_BAR= =3D7", "BF-CBC", &gc); assert_ptr_equal(best_cipher, NULL); - best_cipher =3D ncp_get_best_cipher(serverlistbfcbc, - "IV_YOLO=3DNO\nIV_BAR=3D7", - "BF-CBC", &gc); + best_cipher =3D ncp_get_best_cipher(serverlistbfcbc, "IV_YOLO=3DNO\nIV= _BAR=3D7", "BF-CBC", &gc); assert_string_equal(best_cipher, "BF-CBC"); - best_cipher =3D ncp_get_best_cipher(serverlist, - "IV_NCP=3D1\nIV_BAR=3D7", - "AES-128-GCM", &gc); + best_cipher =3D ncp_get_best_cipher(serverlist, "IV_NCP=3D1\nIV_BAR=3D= 7", "AES-128-GCM", &gc); assert_string_equal(best_cipher, "AES-128-GCM"); - best_cipher =3D ncp_get_best_cipher(serverlist, NULL, - "AES-128-GCM", &gc); + best_cipher =3D ncp_get_best_cipher(serverlist, NULL, "AES-128-GCM", &= gc); assert_string_equal(best_cipher, "AES-128-GCM"); - best_cipher =3D ncp_get_best_cipher(serverlist, NULL, - "none", &gc); + best_cipher =3D ncp_get_best_cipher(serverlist, NULL, "none", &gc); assert_ptr_equal(best_cipher, NULL); - best_cipher =3D ncp_get_best_cipher(serverlistbfcbc, NULL, - "none", &gc); + best_cipher =3D ncp_get_best_cipher(serverlistbfcbc, NULL, "none", &gc= ); assert_string_equal(best_cipher, "none"); best_cipher =3D ncp_get_best_cipher(serverlist, NULL, NULL, &gc); @@ -241,28 +229,23 @@ const char *serverlist =3D "CHACHA20_POLY1305:AES-128-GCM:AES-256-GCM"; - best_cipher =3D ncp_get_best_cipher(serverlist, - "IV_YOLO=3DNO\nIV_NCP=3D2\nIV_BAR=3D= 7", - "BF-CBC", &gc); + best_cipher =3D ncp_get_best_cipher(serverlist, "IV_YOLO=3DNO\nIV_NCP= =3D2\nIV_BAR=3D7", "BF-CBC", &gc); assert_string_equal(best_cipher, "AES-128-GCM"); /* Best cipher is in --cipher of client */ - best_cipher =3D ncp_get_best_cipher(serverlist, "IV_NCP=3D2\nIV_BAR=3D= 7", - "CHACHA20_POLY1305", &gc); + best_cipher =3D ncp_get_best_cipher(serverlist, "IV_NCP=3D2\nIV_BAR=3D= 7", "CHACHA20_POLY1305", &gc); assert_string_equal(best_cipher, "CHACHA20_POLY1305"); /* Best cipher is in --cipher of client */ - best_cipher =3D ncp_get_best_cipher(serverlist, "IV_CIPHERS=3DAES-128-= GCM", - "AES-256-CBC", &gc); + best_cipher =3D ncp_get_best_cipher(serverlist, "IV_CIPHERS=3DAES-128-= GCM", "AES-256-CBC", &gc); assert_string_equal(best_cipher, "AES-128-GCM"); /* IV_NCP=3D2 should be ignored if IV_CIPHERS is sent */ - best_cipher =3D ncp_get_best_cipher(serverlist, - "IV_FOO=3D7\nIV_CIPHERS=3DAES-256-GC= M\nIV_NCP=3D2", + best_cipher =3D ncp_get_best_cipher(serverlist, "IV_FOO=3D7\nIV_CIPHER= S=3DAES-256-GCM\nIV_NCP=3D2", "AES-256-CBC", &gc); assert_string_equal(best_cipher, "AES-256-GCM"); @@ -313,11 +296,14 @@ if (have_chacha) { - assert_string_equal(o.ncp_ciphers, "BF-CBC:AES-256-GCM:AES-128-GCM= :CHACHA20-POLY1305:AES-128-CBC:AES-256-CBC"); + assert_string_equal( + o.ncp_ciphers, + "BF-CBC:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-128-CBC:= AES-256-CBC"); } else { - assert_string_equal(o.ncp_ciphers, "BF-CBC:AES-256-GCM:AES-128-GCM= :AES-128-CBC:AES-256-CBC"); + assert_string_equal(o.ncp_ciphers, + "BF-CBC:AES-256-GCM:AES-128-GCM:AES-128-CBC:AE= S-256-CBC"); } assert_string_equal(o.ncp_ciphers_conf, "BF-CBC:DEFAULT:AES-128-CBC:AE= S-256-CBC"); @@ -327,7 +313,8 @@ if (have_chacha) { - assert_string_equal(o.ncp_ciphers, "AES-256-GCM:AES-128-GCM:CHACHA= 20-POLY1305:AES-128-CBC:AES-192-CBC"); + assert_string_equal(o.ncp_ciphers, + "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES= -128-CBC:AES-192-CBC"); } else { @@ -341,7 +328,8 @@ if (have_chacha) { - assert_string_equal(o.ncp_ciphers, "AES-192-GCM:AES-128-CBC:AES-25= 6-GCM:AES-128-GCM:CHACHA20-POLY1305"); + assert_string_equal(o.ncp_ciphers, + "AES-192-GCM:AES-128-CBC:AES-256-GCM:AES-128-G= CM:CHACHA20-POLY1305"); } else { @@ -356,7 +344,7 @@ test_ncp_expand(void **state) { bool have_chacha =3D cipher_valid("CHACHA20-POLY1305"); - struct options o =3D {0}; + struct options o =3D { 0 }; o.gc =3D gc_new(); struct gc_arena gc =3D gc_new(); diff --git a/tests/unit_tests/openvpn/test_networking.c b/tests/unit_tests/= openvpn/test_networking.c index 0434707..f2da83e 100644 --- a/tests/unit_tests/openvpn/test_networking.c +++ b/tests/unit_tests/openvpn/test_networking.c @@ -110,12 +110,10 @@ printf("\n"); return net_route_v4_add(NULL, &dst, prefixlen, NULL, iface, 0, metric); - } static int -net__route_v4_add_gw(const char *dst_str, int prefixlen, const char *gw_st= r, - int metric) +net__route_v4_add_gw(const char *dst_str, int prefixlen, const char *gw_st= r, int metric) { in_addr_t dst, gw; int ret; @@ -140,8 +138,7 @@ dst =3D ntohl(dst); gw =3D ntohl(gw); - printf("CMD: ip route add %s/%d dev %s via %s", dst_str, prefixlen, if= ace, - gw_str); + printf("CMD: ip route add %s/%d dev %s via %s", dst_str, prefixlen, if= ace, gw_str); if (metric > 0) { printf(" metric %d", metric); @@ -176,12 +173,10 @@ printf("\n"); return net_route_v6_add(NULL, &dst, prefixlen, NULL, iface, 0, metric); - } static int -net__route_v6_add_gw(const char *dst_str, int prefixlen, const char *gw_st= r, - int metric) +net__route_v6_add_gw(const char *dst_str, int prefixlen, const char *gw_st= r, int metric) { struct in6_addr dst, gw; int ret; @@ -203,8 +198,7 @@ return -1; } - printf("CMD: ip -6 route add %s/%d dev %s via %s", dst_str, prefixlen, - iface, gw_str); + printf("CMD: ip -6 route add %s/%d dev %s via %s", dst_str, prefixlen,= iface, gw_str); if (metric > 0) { printf(" metric %d", metric); diff --git a/tests/unit_tests/openvpn/test_packet_id.c b/tests/unit_tests/o= penvpn/test_packet_id.c index 312a6b3d..ae6eeec 100644 --- a/tests/unit_tests/openvpn/test_packet_id.c +++ b/tests/unit_tests/openvpn/test_packet_id.c @@ -37,8 +37,10 @@ #include "reliable.h" #include "test_common.h" -struct test_packet_id_write_data { - struct { +struct test_packet_id_write_data +{ + struct + { uint32_t buf_id; uint32_t buf_time; } test_buf_data; @@ -50,15 +52,14 @@ static int test_packet_id_write_setup(void **state) { - struct test_packet_id_write_data *data =3D - calloc(1, sizeof(struct test_packet_id_write_data)); + struct test_packet_id_write_data *data =3D calloc(1, sizeof(struct tes= t_packet_id_write_data)); if (!data) { return -1; } - data->test_buf.data =3D (void *) &data->test_buf_data; + data->test_buf.data =3D (void *)&data->test_buf_data; data->test_buf.capacity =3D sizeof(data->test_buf_data); data->gc =3D gc_new(); @@ -163,7 +164,6 @@ static void test_get_num_output_sequenced_available(void **state) { - struct reliable *rel =3D malloc(sizeof(struct reliable)); reliable_init(rel, 100, 50, 8, false); @@ -181,14 +181,14 @@ /* test ids close to int/unsigned int barrier */ rel->array[5].active =3D true; - rel->array[5].packet_id =3D (0x80000000u -3); + rel->array[5].packet_id =3D (0x80000000u - 3); rel->array[6].active =3D false; - rel->packet_id =3D (0x80000000u -1); + rel->packet_id =3D (0x80000000u - 1); assert_int_equal(6, reliable_get_num_output_sequenced_available(rel)); rel->array[5].active =3D true; - rel->array[5].packet_id =3D (0x80000000u -3); + rel->array[5].packet_id =3D (0x80000000u - 3); rel->packet_id =3D 0x80000001u; assert_int_equal(4, reliable_get_num_output_sequenced_available(rel)); @@ -196,7 +196,7 @@ /* test wrapping */ rel->array[5].active =3D true; - rel->array[5].packet_id =3D (0xffffffffu -3); + rel->array[5].packet_id =3D (0xffffffffu - 3); rel->array[6].active =3D false; rel->packet_id =3D (0xffffffffu - 1); @@ -224,7 +224,7 @@ assert_true(packet_id_write_epoch(&data->pis, 0x23, &buf)); assert_int_equal(buf.len, 8); - uint8_t expected_header[8] =3D { 0x00, 0x23, 0, 0, 0, 0, 0, 1}; + uint8_t expected_header[8] =3D { 0x00, 0x23, 0, 0, 0, 0, 0, 1 }; assert_memory_equal(BPTR(&buf), expected_header, 8); /* too small buffer should error out */ @@ -235,7 +235,7 @@ data->pis.id =3D 0xfa079ab9d2e8; struct buffer buf_48 =3D alloc_buf_gc(128, &data->gc); assert_true(packet_id_write_epoch(&data->pis, 0xfffe, &buf_48)); - uint8_t expected_header_48[8] =3D { 0xff, 0xfe, 0xfa, 0x07, 0x9a, 0xb9= , 0xd2, 0xe9}; + uint8_t expected_header_48[8] =3D { 0xff, 0xfe, 0xfa, 0x07, 0x9a, 0xb9= , 0xd2, 0xe9 }; assert_memory_equal(BPTR(&buf_48), expected_header_48, 8); /* test writing/checking the 48 bit per epoch packet counter @@ -243,7 +243,7 @@ data->pis.id =3D 0xfffffffffffe; struct buffer buf_of =3D alloc_buf_gc(128, &data->gc); assert_true(packet_id_write_epoch(&data->pis, 0xf00f, &buf_of)); - uint8_t expected_header_of[8] =3D { 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff= , 0xff, 0xff}; + uint8_t expected_header_of[8] =3D { 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff= , 0xff, 0xff }; assert_memory_equal(BPTR(&buf_of), expected_header_of, 8); /* This is go over 2^48 - 1 and should error out. */ @@ -265,9 +265,9 @@ static void test_copy_acks_to_lru(void **state) { - struct reliable_ack ack =3D { .len =3D 4, .packet_id =3D {2, 1, 3, 2} = }; + struct reliable_ack ack =3D { .len =3D 4, .packet_id =3D { 2, 1, 3, 2 = } }; - struct reliable_ack mru_ack =3D {0 }; + struct reliable_ack mru_ack =3D { 0 }; /* Test copying to empty ack structure */ copy_acks_to_mru(&ack, &mru_ack, 4); @@ -293,7 +293,7 @@ /* Adding just two packets shoudl ignore the 42 in array and * reorder the order in the MRU */ - struct reliable_ack ack2 =3D { .len =3D 3, .packet_id =3D {3, 2, 42} }; + struct reliable_ack ack2 =3D { .len =3D 3, .packet_id =3D { 3, 2, 42 }= }; copy_acks_to_mru(&ack2, &mru_ack2, 2); assert_int_equal(mru_ack2.packet_id[0], 3); assert_int_equal(mru_ack2.packet_id[1], 2); @@ -314,12 +314,12 @@ assert_int_equal(mru_ack.packet_id[1], 1); assert_int_equal(mru_ack.packet_id[2], 3); - struct reliable_ack ack3 =3D { .len =3D 7, .packet_id =3D {5, 6, 7, 8,= 9, 10, 11}}; + struct reliable_ack ack3 =3D { .len =3D 7, .packet_id =3D { 5, 6, 7, 8= , 9, 10, 11 } }; /* Adding multiple acks tests if the a full array is handled correctly= */ copy_acks_to_mru(&ack3, &mru_ack, 7); - struct reliable_ack expected_ack =3D { .len =3D 8, .packet_id =3D {5, = 6, 7, 8, 9, 10, 11, 2}}; + struct reliable_ack expected_ack =3D { .len =3D 8, .packet_id =3D { 5,= 6, 7, 8, 9, 10, 11, 2 } }; assert_int_equal(mru_ack.len, expected_ack.len); assert_memory_equal(mru_ack.packet_id, expected_ack.packet_id, sizeof(= expected_ack.packet_id)); @@ -330,26 +330,19 @@ { openvpn_unit_test_setup(); const struct CMUnitTest tests[] =3D { - cmocka_unit_test_setup_teardown(test_packet_id_write_short, - test_packet_id_write_setup, + cmocka_unit_test_setup_teardown(test_packet_id_write_short, test_p= acket_id_write_setup, test_packet_id_write_teardown), - cmocka_unit_test_setup_teardown(test_packet_id_write_long, - test_packet_id_write_setup, + cmocka_unit_test_setup_teardown(test_packet_id_write_long, test_pa= cket_id_write_setup, test_packet_id_write_teardown), cmocka_unit_test_setup_teardown(test_packet_id_write_short_prepend, - test_packet_id_write_setup, - test_packet_id_write_teardown), + test_packet_id_write_setup, test_p= acket_id_write_teardown), cmocka_unit_test_setup_teardown(test_packet_id_write_long_prepend, - test_packet_id_write_setup, + test_packet_id_write_setup, test_p= acket_id_write_teardown), + cmocka_unit_test_setup_teardown(test_packet_id_write_short_wrap, t= est_packet_id_write_setup, test_packet_id_write_teardown), - cmocka_unit_test_setup_teardown(test_packet_id_write_short_wrap, - test_packet_id_write_setup, + cmocka_unit_test_setup_teardown(test_packet_id_write_long_wrap, te= st_packet_id_write_setup, test_packet_id_write_teardown), - cmocka_unit_test_setup_teardown(test_packet_id_write_long_wrap, - test_packet_id_write_setup, - test_packet_id_write_teardown), - cmocka_unit_test_setup_teardown(test_packet_id_write_epoch, - test_packet_id_write_setup, + cmocka_unit_test_setup_teardown(test_packet_id_write_epoch, test_p= acket_id_write_setup, test_packet_id_write_teardown), cmocka_unit_test(test_get_num_output_sequenced_available), diff --git a/tests/unit_tests/openvpn/test_pkcs11.c b/tests/unit_tests/open= vpn/test_pkcs11.c index adad40b..9327523 100644 --- a/tests/unit_tests/openvpn/test_pkcs11.c +++ b/tests/unit_tests/openvpn/test_pkcs11.c @@ -40,8 +40,8 @@ #include "test_common.h" #define token_name "Test Token" -#define PIN "12345" -#define HASHSIZE 20 +#define PIN "12345" +#define HASHSIZE 20 struct management *management; /* global */ @@ -59,8 +59,8 @@ /* stubs for some unused functions instead of pulling in too many dependen= cies */ int -parse_line(const char *line, char **p, const int n, const char *file, - const int line_num, int msglevel, struct gc_arena *gc) +parse_line(const char *line, char **p, const int n, const char *file, cons= t int line_num, + int msglevel, struct gc_arena *gc) { assert_true(0); return 0; @@ -92,45 +92,43 @@ void query_user_add(char *prompt, size_t prompt_len, char *resp, size_t resp_le= n, bool echo) { - (void) prompt; - (void) prompt_len; - (void) resp; - (void) resp_len; - (void) echo; + (void)prompt; + (void)prompt_len; + (void)resp; + (void)resp_len; + (void)echo; assert_true(0); } void purge_user_pass(struct user_pass *up, const bool force) { - (void) force; + (void)force; secure_memzero(up, sizeof(*up)); } char * -management_query_pk_sig(struct management *man, const char *b64_data, - const char *algorithm) +management_query_pk_sig(struct management *man, const char *b64_data, cons= t char *algorithm) { - (void) man; - (void) b64_data; - (void) algorithm; + (void)man; + (void)b64_data; + (void)algorithm; return NULL; } -int -digest_sign_verify(EVP_PKEY *privkey, EVP_PKEY *pubkey); +int digest_sign_verify(EVP_PKEY *privkey, EVP_PKEY *pubkey); /* Test certificate database: data for cert1, cert2 .. key1, key2 etc. * are defined in cert_data.h */ static struct test_cert { - const char *const cert; /* certificate as PEM */ - const char *const key; /* key as unencrypted PEM */ - const char *const cname; /* common-name */ - const char *const issuer; /* issuer common-name */ - const char *const friendly_name; /* identifies certs loaded to the = store -- keep unique */ - uint8_t hash[HASHSIZE]; /* SHA1 fingerprint: computed and = filled in later */ - char *p11_id; /* PKCS#11 id -- filled in later */ + const char *const cert; /* certificate as PEM */ + const char *const key; /* key as unencrypted PEM */ + const char *const cname; /* common-name */ + const char *const issuer; /* issuer common-name */ + const char *const friendly_name; /* identifies certs loaded to the sto= re -- keep unique */ + uint8_t hash[HASHSIZE]; /* SHA1 fingerprint: computed and fil= led in later */ + char *p11_id; /* PKCS#11 id -- filled in later */ } certs[5]; static bool pkcs11_id_management; @@ -145,11 +143,11 @@ init_cert_data(void) { struct test_cert certs_local[] =3D { - {cert1, key1, cname1, "OVPN TEST CA1", "OVPN Test Cert 1", {0= }, NULL}, - {cert2, key2, cname2, "OVPN TEST CA2", "OVPN Test Cert 2", {0= }, NULL}, - {cert3, key3, cname3, "OVPN TEST CA1", "OVPN Test Cert 3", {0= }, NULL}, - {cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", {0= }, NULL}, - {0} + { cert1, key1, cname1, "OVPN TEST CA1", "OVPN Test Cert 1", { 0 },= NULL }, + { cert2, key2, cname2, "OVPN TEST CA2", "OVPN Test Cert 2", { 0 },= NULL }, + { cert3, key3, cname3, "OVPN TEST CA1", "OVPN Test Cert 3", { 0 },= NULL }, + { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", { 0 },= NULL }, + { 0 } }; assert(sizeof(certs_local) =3D=3D sizeof(certs)); memcpy(certs, certs_local, sizeof(certs_local)); @@ -160,9 +158,9 @@ get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *= prefix, const unsigned int flags, const char *unused) { - (void) unused; + (void)unused; bool ret =3D true; - if (!strcmp(prefix, "pkcs11-id-request") && flags&GET_USER_PASS_NEED_S= TR) + if (!strcmp(prefix, "pkcs11-id-request") && flags & GET_USER_PASS_NEED= _STR) { assert_true(pkcs11_id_management); strncpynt(up->password, pkcs11_id_current, sizeof(up->password)); @@ -196,15 +194,16 @@ static int init(void **state) { - (void) state; + (void)state; - umask(0077); /* ensure all files and directories we create get user o= nly access */ + umask(0077); /* ensure all files and directories we create get user on= ly access */ char config[256]; init_cert_data(); if (!mkdtemp(softhsm2_tokens_path)) { - fail_msg("make tmpdir using template <%s> failed (error =3D %d)", = softhsm2_tokens_path, errno); + fail_msg("make tmpdir using template <%s> failed (error =3D %d)", = softhsm2_tokens_path, + errno); } int fd =3D mkstemp(softhsm2_conf_path); @@ -212,8 +211,7 @@ { fail_msg("make tmpfile using template <%s> failed (error =3D %d)",= softhsm2_conf_path, errno); } - snprintf(config, sizeof(config), "directories.tokendir=3D%s/", - softhsm2_tokens_path); + snprintf(config, sizeof(config), "directories.tokendir=3D%s/", softhsm= 2_tokens_path); assert_int_equal(write(fd, config, strlen(config)), strlen(config)); close(fd); @@ -261,14 +259,16 @@ argv_free(&a); a =3D argv_new(); /* Use numcerts+1 as a unique id of the object -- same id for mat= ching cert and key */ - argv_printf(&a, "%s --provider %s --load-certificate %s --label \"= %s\" --id %08x --login --write", - P11TOOL_PATH, SOFTHSM2_MODULE_PATH, cert, c->friendly_= name, num_certs+1); + argv_printf( + &a, "%s --provider %s --load-certificate %s --label \"%s\" --i= d %08x --login --write", + P11TOOL_PATH, SOFTHSM2_MODULE_PATH, cert, c->friendly_name, nu= m_certs + 1); assert_true(openvpn_execve_check(&a, es, 0, "Failed to upload cert= ificate into token")); argv_free(&a); a =3D argv_new(); - argv_printf(&a, "%s --provider %s --load-privkey %s --label \"%s\"= --id %08x --login --write", - P11TOOL_PATH, SOFTHSM2_MODULE_PATH, key, c->friendly_n= ame, num_certs+1); + argv_printf(&a, + "%s --provider %s --load-privkey %s --label \"%s\" --i= d %08x --login --write", + P11TOOL_PATH, SOFTHSM2_MODULE_PATH, key, c->friendly_n= ame, num_certs + 1); assert_true(openvpn_execve_check(&a, es, 0, "Failed to upload key = into token")); assert_int_equal(ftruncate(cert_fd, 0), 0); @@ -289,7 +289,7 @@ static int cleanup(void **state) { - (void) state; + (void)state; struct argv a =3D argv_new(); argv_printf(&a, "%s --delete-token --token \"%s\"", SOFTHSM2_UTIL_PATH= , token_name); @@ -411,7 +411,7 @@ static void test_tls_ctx_use_pkcs11(void **state) { - (void) state; + (void)state; struct tls_root_ctx tls_ctx =3D {}; uint8_t sha1[HASHSIZE]; for (struct test_cert *c =3D certs; c->cert; c++) @@ -452,7 +452,8 @@ #else if (!SSL_CTX_check_private_key(tls_ctx.ctx)) { - fail_msg("Certificate and private key in ssl_ctx do not match = for <%s>", c->friendly_name); + fail_msg("Certificate and private key in ssl_ctx do not match = for <%s>", + c->friendly_name); return; } #endif @@ -473,10 +474,8 @@ { openvpn_unit_test_setup(); const struct CMUnitTest tests[] =3D { - cmocka_unit_test_setup_teardown(test_pkcs11_ids, setup_pkcs11, - teardown_pkcs11), - cmocka_unit_test_setup_teardown(test_tls_ctx_use_pkcs11, setup_pkc= s11, - teardown_pkcs11), + cmocka_unit_test_setup_teardown(test_pkcs11_ids, setup_pkcs11, tea= rdown_pkcs11), + cmocka_unit_test_setup_teardown(test_tls_ctx_use_pkcs11, setup_pkc= s11, teardown_pkcs11), cmocka_unit_test_setup_teardown(test_tls_ctx_use_pkcs11__managemen= t, setup_pkcs11, teardown_pkcs11), }; diff --git a/tests/unit_tests/openvpn/test_pkt.c b/tests/unit_tests/openvpn= /test_pkt.c index ebffabe..b3b9680 100644 --- a/tests/unit_tests/openvpn/test_pkt.c +++ b/tests/unit_tests/openvpn/test_pkt.c @@ -45,8 +45,8 @@ #include "reliable.h" int -parse_line(const char *line, char **p, const int n, const char *file, - const int line_num, int msglevel, struct gc_arena *gc) +parse_line(const char *line, char **p, const int n, const char *file, cons= t int line_num, + int msglevel, struct gc_arena *gc) { /* Dummy function to get the linker happy, should never be called */ assert_true(false); @@ -56,8 +56,7 @@ /* Define this function here as dummy since including the ssl_*.c files * leads to having to include even more unrelated code */ bool -key_state_export_keying_material(struct tls_session *session, - const char *label, size_t label_size, +key_state_export_keying_material(struct tls_session *session, const char *= label, size_t label_size, void *ekm, size_t ekm_size) { ASSERT(0); @@ -90,104 +89,73 @@ "-----END OpenVPN Static key V1-----\n" "\n"; -const uint8_t client_reset_v2_none[] =3D -{ 0x38, 0x68, 0x91, 0x92, 0x3f, 0xa3, 0x10, 0x34, - 0x37, 0x00, 0x00, 0x00, 0x00, 0x00 }; +const uint8_t client_reset_v2_none[] =3D { 0x38, 0x68, 0x91, 0x92, 0x3f, 0= xa3, 0x10, + 0x34, 0x37, 0x00, 0x00, 0x00, 0x0= 0, 0x00 }; -const uint8_t client_reset_v2_tls_auth[] =3D -{ 0x38, 0xde, 0x69, 0x4c, 0x5c, 0x7b, 0xfb, 0xa2, - 0x74, 0x93, 0x53, 0x7c, 0x1d, 0xed, 0x4e, 0x78, - 0x15, 0x29, 0xae, 0x7c, 0xfe, 0x4b, 0x8c, 0x6d, - 0x6b, 0x2b, 0x51, 0xf0, 0x5a, 0x00, 0x00, 0x00, - 0x01, 0x61, 0xd3, 0xbf, 0x6c, 0x00, 0x00, 0x00, - 0x00, 0x00}; +const uint8_t client_reset_v2_tls_auth[] =3D { 0x38, 0xde, 0x69, 0x4c, 0x5= c, 0x7b, 0xfb, 0xa2, 0x74, + 0x93, 0x53, 0x7c, 0x1d, 0xed,= 0x4e, 0x78, 0x15, 0x29, + 0xae, 0x7c, 0xfe, 0x4b, 0x8c,= 0x6d, 0x6b, 0x2b, 0x51, + 0xf0, 0x5a, 0x00, 0x00, 0x00,= 0x01, 0x61, 0xd3, 0xbf, + 0x6c, 0x00, 0x00, 0x00, 0x00,= 0x00 }; -const uint8_t client_reset_v2_tls_crypt[] =3D -{0x38, 0xf4, 0x19, 0xcb, 0x12, 0xd1, 0xf9, 0xe4, - 0x8f, 0x00, 0x00, 0x00, 0x01, 0x61, 0xd3, 0xf8, - 0xe1, 0x33, 0x02, 0x06, 0xf5, 0x68, 0x02, 0xbe, - 0x44, 0xfb, 0xed, 0x90, 0x50, 0x64, 0xe3, 0xdb, - 0x43, 0x41, 0x6b, 0xec, 0x5e, 0x52, 0x67, 0x19, - 0x46, 0x2b, 0x7e, 0xb9, 0x0c, 0x96, 0xde, 0xfc, - 0x9b, 0x05, 0xc4, 0x48, 0x79, 0xf7}; +const uint8_t client_reset_v2_tls_crypt[] =3D { + 0x38, 0xf4, 0x19, 0xcb, 0x12, 0xd1, 0xf9, 0xe4, 0x8f, 0x00, 0x00, 0x00= , 0x01, 0x61, + 0xd3, 0xf8, 0xe1, 0x33, 0x02, 0x06, 0xf5, 0x68, 0x02, 0xbe, 0x44, 0xfb= , 0xed, 0x90, + 0x50, 0x64, 0xe3, 0xdb, 0x43, 0x41, 0x6b, 0xec, 0x5e, 0x52, 0x67, 0x19= , 0x46, 0x2b, + 0x7e, 0xb9, 0x0c, 0x96, 0xde, 0xfc, 0x9b, 0x05, 0xc4, 0x48, 0x79, 0xf7 +}; /* Valid tls-auth client CONTROL_V1 packet with random server id */ const uint8_t client_ack_tls_auth_randomid[] =3D { - 0x20, 0x14, 0x01, 0x4e, 0xbc, 0x80, 0xc6, 0x14, - 0x2b, 0x7b, 0xc8, 0x76, 0xfb, 0xc5, 0x2e, 0x27, - 0xb1, 0xc5, 0x07, 0x35, 0x5b, 0xb6, 0x00, 0x6b, - 0xae, 0x71, 0xba, 0x4e, 0x38, 0x00, 0x00, 0x00, - 0x03, 0x61, 0xd3, 0xff, 0x53, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x16, 0x03, 0x01, 0x01, 0x0c, 0x01, - 0x00, 0x01, 0x08, 0x03, 0x03, 0x8c, 0xaa, 0xac, - 0x3a, 0x1a, 0x07, 0xbd, 0xe7, 0xb7, 0x50, 0x06, - 0x9b, 0x94, 0x0c, 0x34, 0x4b, 0x5a, 0x35, 0xca, - 0xc4, 0x79, 0xbd, 0xc9, 0x09, 0xb0, 0x7b, 0xd9, - 0xee, 0xbb, 0x7d, 0xe7, 0x25, 0x20, 0x39, 0x38, - 0xe2, 0x18, 0x33, 0x36, 0x14, 0x9f, 0x34, 0xf0, - 0x44, 0x59, 0x96, 0x8d, 0x0e, 0xd2, 0x47, 0x76, - 0x64, 0x88, 0x59, 0xe9, 0x38, 0x03, 0x97, 0x96, - 0x98, 0x45, 0xfb, 0xf5, 0xff, 0x23, 0x00, 0x32, - 0x13, 0x02, 0x13, 0x03, 0x13, 0x01, 0xc0, 0x2c, - 0xc0, 0x30, 0x00, 0x9f, 0xcc, 0xa9, 0xcc, 0xa8, - 0xcc, 0xaa, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e, - 0xc0, 0x24, 0xc0, 0x28, 0x00, 0x6b, 0xc0, 0x23, - 0xc0, 0x27, 0x00, 0x67, 0xc0, 0x0a, 0xc0, 0x14, - 0x00, 0x39, 0xc0, 0x09, 0xc0, 0x13, 0x00, 0x33, - 0x00, 0xff, 0x01, 0x00, 0x00, 0x8d, 0x00, 0x0b, - 0x00, 0x04, 0x03, 0x00, 0x01, 0x02, 0x00, 0x0a, - 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x1d, 0x00, 0x17, - 0x00, 0x1e, 0x00, 0x19, 0x00, 0x18, 0x00, 0x16, - 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x0d, - 0x00, 0x30, 0x00, 0x2e, 0x04, 0x03, 0x05, 0x03, - 0x06, 0x03, 0x08, 0x07, 0x08, 0x08, 0x08, 0x09, - 0x08, 0x0a, 0x08, 0x0b, 0x08, 0x04, 0x08, 0x05, - 0x08, 0x06, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, - 0x03, 0x03, 0x02, 0x03, 0x03, 0x01, 0x02, 0x01, - 0x03, 0x02, 0x02, 0x02, 0x04, 0x02, 0x05, 0x02, - 0x06, 0x02, 0x00, 0x2b, 0x00, 0x05, 0x04, 0x03, - 0x04, 0x03, 0x03, 0x00, 0x2d, 0x00, 0x02, 0x01, - 0x01, 0x00, 0x33, 0x00, 0x26, 0x00, 0x24, 0x00, - 0x1d, 0x00, 0x20, 0x0e, 0xc9, 0x7a, 0xff, 0x58, - 0xdb, 0x56, 0xf6, 0x40, 0xd1, 0xed, 0xdb, 0x91, - 0x81, 0xd6, 0xef, 0x83, 0x86, 0x8a, 0xb2, 0x3d, - 0x88, 0x92, 0x3f, 0xd8, 0x51, 0x9c, 0xd6, 0x26, - 0x56, 0x33, 0x6b + 0x20, 0x14, 0x01, 0x4e, 0xbc, 0x80, 0xc6, 0x14, 0x2b, 0x7b, 0xc8, 0x76= , 0xfb, 0xc5, 0x2e, 0x27, + 0xb1, 0xc5, 0x07, 0x35, 0x5b, 0xb6, 0x00, 0x6b, 0xae, 0x71, 0xba, 0x4e= , 0x38, 0x00, 0x00, 0x00, + 0x03, 0x61, 0xd3, 0xff, 0x53, 0x00, 0x00, 0x00, 0x00, 0x01, 0x16, 0x03= , 0x01, 0x01, 0x0c, 0x01, + 0x00, 0x01, 0x08, 0x03, 0x03, 0x8c, 0xaa, 0xac, 0x3a, 0x1a, 0x07, 0xbd= , 0xe7, 0xb7, 0x50, 0x06, + 0x9b, 0x94, 0x0c, 0x34, 0x4b, 0x5a, 0x35, 0xca, 0xc4, 0x79, 0xbd, 0xc9= , 0x09, 0xb0, 0x7b, 0xd9, + 0xee, 0xbb, 0x7d, 0xe7, 0x25, 0x20, 0x39, 0x38, 0xe2, 0x18, 0x33, 0x36= , 0x14, 0x9f, 0x34, 0xf0, + 0x44, 0x59, 0x96, 0x8d, 0x0e, 0xd2, 0x47, 0x76, 0x64, 0x88, 0x59, 0xe9= , 0x38, 0x03, 0x97, 0x96, + 0x98, 0x45, 0xfb, 0xf5, 0xff, 0x23, 0x00, 0x32, 0x13, 0x02, 0x13, 0x03= , 0x13, 0x01, 0xc0, 0x2c, + 0xc0, 0x30, 0x00, 0x9f, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x2b= , 0xc0, 0x2f, 0x00, 0x9e, + 0xc0, 0x24, 0xc0, 0x28, 0x00, 0x6b, 0xc0, 0x23, 0xc0, 0x27, 0x00, 0x67= , 0xc0, 0x0a, 0xc0, 0x14, + 0x00, 0x39, 0xc0, 0x09, 0xc0, 0x13, 0x00, 0x33, 0x00, 0xff, 0x01, 0x00= , 0x00, 0x8d, 0x00, 0x0b, + 0x00, 0x04, 0x03, 0x00, 0x01, 0x02, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a= , 0x00, 0x1d, 0x00, 0x17, + 0x00, 0x1e, 0x00, 0x19, 0x00, 0x18, 0x00, 0x16, 0x00, 0x00, 0x00, 0x17= , 0x00, 0x00, 0x00, 0x0d, + 0x00, 0x30, 0x00, 0x2e, 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x08, 0x07= , 0x08, 0x08, 0x08, 0x09, + 0x08, 0x0a, 0x08, 0x0b, 0x08, 0x04, 0x08, 0x05, 0x08, 0x06, 0x04, 0x01= , 0x05, 0x01, 0x06, 0x01, + 0x03, 0x03, 0x02, 0x03, 0x03, 0x01, 0x02, 0x01, 0x03, 0x02, 0x02, 0x02= , 0x04, 0x02, 0x05, 0x02, + 0x06, 0x02, 0x00, 0x2b, 0x00, 0x05, 0x04, 0x03, 0x04, 0x03, 0x03, 0x00= , 0x2d, 0x00, 0x02, 0x01, + 0x01, 0x00, 0x33, 0x00, 0x26, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0x0e= , 0xc9, 0x7a, 0xff, 0x58, + 0xdb, 0x56, 0xf6, 0x40, 0xd1, 0xed, 0xdb, 0x91, 0x81, 0xd6, 0xef, 0x83= , 0x86, 0x8a, 0xb2, 0x3d, + 0x88, 0x92, 0x3f, 0xd8, 0x51, 0x9c, 0xd6, 0x26, 0x56, 0x33, 0x6b }; =20 /* This is a truncated packet as we do not care for the TLS payload in the * unit test */ -const uint8_t client_control_with_ack[] =3D { - 0x20, 0x78, 0x19, 0xbf, 0x2e, 0xbc, 0xd1, 0x9a, - 0x45, 0x01, 0x00, 0x00, 0x00, 0x00, 0xea, - 0xfe, 0xbf, 0xa4, 0x41, 0x8a, 0xe3, 0x1b, - 0x00, 0x00, 0x00, 0x01, 0x16, 0x03, 0x01 -}; +const uint8_t client_control_with_ack[] =3D { 0x20, 0x78, 0x19, 0xbf, 0x2e= , 0xbc, 0xd1, 0x9a, + 0x45, 0x01, 0x00, 0x00, 0x00, = 0x00, 0xea, 0xfe, + 0xbf, 0xa4, 0x41, 0x8a, 0xe3, = 0x1b, 0x00, 0x00, + 0x00, 0x01, 0x16, 0x03, 0x01 }; -const uint8_t client_ack_none_random_id[] =3D { - 0x28, 0xae, 0xb9, 0xaf, 0xe1, 0xf0, 0x1d, 0x79, - 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0xdd, - 0x85, 0xdb, 0x53, 0x56, 0x23, 0xb0, 0x2e -}; +const uint8_t client_ack_none_random_id[] =3D { 0x28, 0xae, 0xb9, 0xaf, 0x= e1, 0xf0, 0x1d, 0x79, + 0xc8, 0x01, 0x00, 0x00, 0x00= , 0x00, 0xdd, 0x85, + 0xdb, 0x53, 0x56, 0x23, 0xb0= , 0x2e }; struct tls_auth_standalone init_tas_auth(int key_direction) { struct tls_auth_standalone tas =3D { 0 }; - struct frame frame =3D { {.headroom =3D 200, .payload_size =3D 1400}, = 0}; + struct frame frame =3D { { .headroom =3D 200, .payload_size =3D 1400 }= , 0 }; tas.frame =3D frame; tas.tls_wrap.mode =3D TLS_WRAP_AUTH; /* we ignore packet ids on for the first packet check */ - tas.tls_wrap.opt.flags |=3D (CO_IGNORE_PACKET_ID|CO_PACKET_ID_LONG_FOR= M); + tas.tls_wrap.opt.flags |=3D (CO_IGNORE_PACKET_ID | CO_PACKET_ID_LONG_F= ORM); struct key_type tls_crypt_kt; init_key_type(&tls_crypt_kt, "none", "SHA1", true, false); - crypto_read_openvpn_key(&tls_crypt_kt, &tas.tls_wrap.opt.key_ctx_bi, - static_key, true, key_direction, - "Control Channel Authentication", "tls-auth", - NULL); + crypto_read_openvpn_key(&tls_crypt_kt, &tas.tls_wrap.opt.key_ctx_bi, s= tatic_key, true, + key_direction, "Control Channel Authentication= ", "tls-auth", NULL); tas.workbuf =3D alloc_buf(1600); return tas; @@ -198,11 +166,10 @@ { struct tls_auth_standalone tas =3D { 0 }; tas.tls_wrap.mode =3D TLS_WRAP_CRYPT; - tas.tls_wrap.opt.flags |=3D (CO_IGNORE_PACKET_ID|CO_PACKET_ID_LONG_FOR= M); + tas.tls_wrap.opt.flags |=3D (CO_IGNORE_PACKET_ID | CO_PACKET_ID_LONG_F= ORM); - tls_crypt_init_key(&tas.tls_wrap.opt.key_ctx_bi, - &tas.tls_wrap.original_wrap_keydata, static_key, - true, server); + tls_crypt_init_key(&tas.tls_wrap.opt.key_ctx_bi, &tas.tls_wrap.origina= l_wrap_keydata, + static_key, true, server); tas.workbuf =3D alloc_buf(1600); tas.tls_wrap.work =3D alloc_buf(1600); @@ -249,7 +216,7 @@ free_tls_pre_decrypt_state(&state); /* flip a byte in various places */ - for (int i =3D 0; isettings.flags =3D MF_EXTERNAL_KEY|MF_EXTERNAL_KEY_PSS= PAD; + management->settings.flags =3D MF_EXTERNAL_KEY | MF_EXTERNAL_KEY_P= SSPAD; /* first without digest support in management client */ again: @@ -329,8 +329,8 @@ } static int -xkey_sign(void *handle, unsigned char *sig, size_t *siglen, - const unsigned char *tbs, size_t tbslen, XKEY_SIGALG s) +xkey_sign(void *handle, unsigned char *sig, size_t *siglen, const unsigned= char *tbs, size_t tbslen, + XKEY_SIGALG s) { if (!sig) { @@ -387,7 +387,8 @@ pubkey =3D load_pubkey(pubkeys[i]); assert_true(pubkey !=3D NULL); - EVP_PKEY *privkey =3D xkey_load_generic_key(NULL, (void *)dummy, p= ubkey, xkey_sign, xkey_free); + EVP_PKEY *privkey =3D + xkey_load_generic_key(NULL, (void *)dummy, pubkey, xkey_sign, = xkey_free); assert_true(privkey !=3D NULL); xkey_sign_called =3D 0; diff --git a/tests/unit_tests/openvpn/test_ssl.c b/tests/unit_tests/openvpn= /test_ssl.c index 2a05c4f..058883b 100644 --- a/tests/unit_tests/openvpn/test_ssl.c +++ b/tests/unit_tests/openvpn/test_ssl.c @@ -160,7 +160,7 @@ static int init(void **state) { - (void) state; + (void)state; global_state.gc =3D gc_new(); global_state.certfile =3D platform_create_temp_file(get_tmp_dir(), "ce= rt", &global_state.gc); global_state.keyfile =3D platform_create_temp_file(get_tmp_dir(), "key= ", &global_state.gc); @@ -181,7 +181,7 @@ static int cleanup(void **state) { - (void) state; + (void)state; unlink(global_state.certfile); unlink(global_state.keyfile); gc_free(&global_state.gc); @@ -221,7 +221,7 @@ static void test_load_certificate_and_key(void **state) { - (void) state; + (void)state; struct tls_root_ctx ctx =3D { 0 }; /* test loading of inlined cert and key. @@ -243,11 +243,11 @@ static void test_load_certificate_and_key_uri(void **state) { - (void) state; + (void)state; #if !defined(HAVE_OPENSSL_STORE) skip(); -#else /* HAVE_OPENSSL_STORE */ +#else /* HAVE_OPENSSL_STORE */ struct tls_root_ctx ctx =3D { 0 }; const char *certfile =3D global_state.certfile; @@ -307,7 +307,6 @@ frame->buf.tailroom =3D overhead; frame->tun_mtu =3D tls_mtu; - } static void @@ -334,7 +333,6 @@ /* Test encryption, decryption for all packet sizes */ for (int i =3D 1; i <=3D frame.buf.payload_size; ++i) { - /* msg(M_INFO, "TESTING ENCRYPT/DECRYPT of packet length=3D%d", i)= ; */ /* @@ -414,7 +412,6 @@ static void check_aead_limits(struct crypto_options *co, bool chachapoly) { - /* Check that we correctly react when we have a nearing AEAD limits */ /* manually increase the send counter to be past @@ -446,9 +443,8 @@ { /* Check always against the GCM usage limit here to see if that * check works */ - assert_true(aead_usage_limit_reached((1ull << 36), - &co->key_ctx_bi.encrypt, - co->packet_id.send.id)); + assert_true( + aead_usage_limit_reached((1ull << 36), &co->key_ctx_bi.encrypt= , co->packet_id.send.id)); return; } @@ -465,10 +461,9 @@ static struct crypto_options -init_crypto_options(const char *cipher, const char *auth, bool epoch, - struct key2 *statickey) +init_crypto_options(const char *cipher, const char *auth, bool epoch, stru= ct key2 *statickey) { - struct key2 key2 =3D { .n =3D 2}; + struct key2 key2 =3D { .n =3D 2 }; if (statickey) { @@ -489,7 +484,7 @@ if (epoch) { - struct epoch_key e1 =3D { .epoch =3D 1, .epoch_key =3D { 0 }}; + struct epoch_key e1 =3D { .epoch =3D 1, .epoch_key =3D { 0 } }; memcpy(e1.epoch_key, key2.keys[0].cipher, sizeof(e1.epoch_key)); co.flags |=3D CO_EPOCH_DATA_KEY_FORMAT; epoch_init_key_ctx(&co, &kt, &e1, &e1, 5); @@ -634,11 +629,11 @@ static struct key2 create_key(void) { - struct key2 key2 =3D {.n =3D 2}; + struct key2 key2 =3D { .n =3D 2 }; - const uint8_t key[] =3D - {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '0', '1', '2', '3', '4', '5',= '6', '7', 'A', 'B', 'C', 'D', 'E', 'F', - 'G', 'H', 'j', 'k', 'u', 'c', 'h', 'e', 'n', 'l'}; + const uint8_t key[] =3D { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '0',= '1', '2', + '3', '4', '5', '6', '7', 'A', 'B', 'C', 'D', '= E', 'F', + 'G', 'H', 'j', 'k', 'u', 'c', 'h', 'e', 'n', '= l' }; static_assert(sizeof(key) =3D=3D 32, "Size of key should be 32 bytes"); @@ -648,7 +643,7 @@ for (int i =3D 0; i < sizeof(key2.keys); i++) { - keydata[i] =3D (uint8_t) (key[i % sizeof(key)] ^ i); + keydata[i] =3D (uint8_t)(key[i % sizeof(key)] ^ i); } ASSERT(memcpy(key2.keys[0].cipher, keydata, sizeof(key2.keys[0].cipher= ))); @@ -664,8 +659,7 @@ { struct key2 key2 =3D create_key(); - struct crypto_options co =3D init_crypto_options("AES-256-GCM", "none"= , epoch, - &key2); + struct crypto_options co =3D init_crypto_options("AES-256-GCM", "none"= , epoch, &key2); struct gc_arena gc =3D gc_new(); @@ -717,41 +711,40 @@ if (epoch) { - uint8_t packetid1[8] =3D {0, 0x04, 0, 0, 0, 0, 0, 1}; + uint8_t packetid1[8] =3D { 0, 0x04, 0, 0, 0, 0, 0, 1 }; assert_memory_equal(BPTR(&buf), packetid1, 8); } else { - uint8_t packetid1[4] =3D {0, 0, 0, 1}; + uint8_t packetid1[4] =3D { 0, 0, 0, 1 }; assert_memory_equal(BPTR(&buf), packetid1, 4); } if (epoch) { uint8_t *tag_location =3D BEND(&buf) - OPENVPN_AEAD_TAG_LENGTH; - const uint8_t exp_tag_epoch[16] =3D - {0x0f, 0xff, 0xf5, 0x91, 0x3d, 0x39, 0xd7, 0x5b, - 0x18, 0x57, 0x3b, 0x57, 0x48, 0x58, 0x9a, 0x7d}; + const uint8_t exp_tag_epoch[16] =3D { 0x0f, 0xff, 0xf5, 0x91, 0x3d= , 0x39, 0xd7, 0x5b, + 0x18, 0x57, 0x3b, 0x57, 0x48, = 0x58, 0x9a, 0x7d }; assert_memory_equal(tag_location, exp_tag_epoch, OPENVPN_AEAD_TAG_= LENGTH); } else { uint8_t *tag_location =3D BPTR(&buf) + 4; - const uint8_t exp_tag_noepoch[16] =3D - {0x1f, 0xdd, 0x90, 0x8f, 0x0e, 0x9d, 0xc2, 0x5e, 0x79, 0xd8, 0x32,= 0x02, 0x0d, 0x58, 0xe7, 0x3f}; + const uint8_t exp_tag_noepoch[16] =3D { 0x1f, 0xdd, 0x90, 0x8f, 0x= 0e, 0x9d, 0xc2, 0x5e, + 0x79, 0xd8, 0x32, 0x02, 0x0d= , 0x58, 0xe7, 0x3f }; assert_memory_equal(tag_location, exp_tag_noepoch, OPENVPN_AEAD_TA= G_LENGTH); } /* Check some bytes at the beginning of the encrypted part */ if (epoch) { - const uint8_t bytesat14[6] =3D {0x36, 0xaa, 0xb4, 0xd4, 0x9c, 0xe6= }; + const uint8_t bytesat14[6] =3D { 0x36, 0xaa, 0xb4, 0xd4, 0x9c, 0xe= 6 }; assert_memory_equal(BPTR(&buf) + 14, bytesat14, sizeof(bytesat14)); } else { - const uint8_t bytesat30[6] =3D {0xa8, 0x2e, 0x6b, 0x17, 0x06, 0xd9= }; + const uint8_t bytesat30[6] =3D { 0xa8, 0x2e, 0x6b, 0x17, 0x06, 0xd= 9 }; assert_memory_equal(BPTR(&buf) + 30, bytesat30, sizeof(bytesat30)); } diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/o= penvpn/test_tls_crypt.c index cc415c8..96a1fc8 100644 --- a/tests/unit_tests/openvpn/test_tls_crypt.c +++ b/tests/unit_tests/openvpn/test_tls_crypt.c @@ -40,8 +40,7 @@ /* Define this function here as dummy since including the ssl_*.c files * leads to having to include even more unrelated code */ bool -key_state_export_keying_material(struct tls_session *session, - const char *label, size_t label_size, +key_state_export_keying_material(struct tls_session *session, const char *= label, size_t label_size, void *ekm, size_t ekm_size) { memset(ekm, 0xba, ekm_size); @@ -49,22 +48,22 @@ } -#define TESTBUF_SIZE 128 +#define TESTBUF_SIZE 128 /* Defines for use in the tests and the mock parse_line() */ -#define PATH1 "/s p a c e" -#define PATH2 "/foo bar/baz" -#define PARAM1 "param1" -#define PARAM2 "param two" +#define PATH1 "/s p a c e" +#define PATH2 "/foo bar/baz" +#define PARAM1 "param1" +#define PARAM2 "param two" -static const char *test_server_key =3D \ +static const char *test_server_key =3D "-----BEGIN OpenVPN tls-crypt-v2 server key-----\n" "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v\n" "MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\n" "YGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn8=3D\n" "-----END OpenVPN tls-crypt-v2 server key-----\n"; -static const char *test_client_key =3D \ +static const char *test_client_key =3D "-----BEGIN OpenVPN tls-crypt-v2 client key-----\n" "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v\n" "MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\n" @@ -82,7 +81,7 @@ =20 /* Has custom metadata of AABBCCDD (base64) */ -static const char *test_client_key_metadata =3D \ +static const char *test_client_key_metadata =3D "-----BEGIN OpenVPN tls-crypt-v2 client key-----\n" "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v\n" "MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\n" @@ -99,8 +98,8 @@ "-----END OpenVPN tls-crypt-v2 client key-----\n"; int -__wrap_parse_line(const char *line, char **p, const int n, const char *fil= e, - const int line_num, int msglevel, struct gc_arena *gc) +__wrap_parse_line(const char *line, char **p, const int n, const char *fil= e, const int line_num, + int msglevel, struct gc_arena *gc) { p[0] =3D PATH1 PATH2; p[1] =3D PARAM1; @@ -142,7 +141,8 @@ return true; } -struct test_tls_crypt_context { +struct test_tls_crypt_context +{ struct crypto_options co; struct key_type kt; struct buffer source; @@ -157,8 +157,10 @@ struct test_tls_crypt_context *ctx =3D calloc(1, sizeof(*ctx)); *state =3D ctx; - struct key_parameters key =3D { .cipher =3D { 0 }, .hmac =3D { 0 }, - .hmac_size =3D MAX_HMAC_KEY_LENGTH, .cip= her_size =3D MAX_CIPHER_KEY_LENGTH }; + struct key_parameters key =3D { .cipher =3D { 0 }, + .hmac =3D { 0 }, + .hmac_size =3D MAX_HMAC_KEY_LENGTH, + .cipher_size =3D MAX_CIPHER_KEY_LENGTH }; ctx->kt =3D tls_crypt_kt(); if (!ctx->kt.cipher || !ctx->kt.digest) @@ -188,8 +190,7 @@ static int test_tls_crypt_teardown(void **state) { - struct test_tls_crypt_context *ctx =3D - (struct test_tls_crypt_context *)*state; + struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *)*state; free_buf(&ctx->source); free_buf(&ctx->ciphertext); @@ -217,7 +218,7 @@ static void tls_crypt_loopback(void **state) { - struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *) *state; + struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *)*state; skip_if_tls_crypt_not_supported(ctx); @@ -225,8 +226,7 @@ assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); assert_true(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->= co)); assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped)); - assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), - BLEN(&ctx->source)); + assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), BLEN(&c= tx->source)); } @@ -236,8 +236,7 @@ static void test_tls_crypt_secure_reneg_key(void **state) { - struct test_tls_crypt_context *ctx =3D - (struct test_tls_crypt_context *)*state; + struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *)*state; struct gc_arena gc =3D gc_new(); @@ -256,19 +255,19 @@ tls_crypt_wrap(&ctx->source, &rctx->work, &rctx->opt); assert_int_equal(buf_len(&ctx->source) + 40, buf_len(&rctx->work)); - uint8_t expected_ciphertext[] =3D { - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x19, 0x27, = 0x7f, 0x1c, 0x8d, 0x6e, 0x6a, - 0x77, 0x96, 0xa8, 0x55, 0x33, 0x7b, 0x9c, 0xfb, 0x56, 0xe1, 0xf1, = 0x3a, 0x87, 0x0e, 0x66, 0x47, - 0xdf, 0xa1, 0x95, 0xc9, 0x2c, 0x17, 0xa0, 0x15, 0xba, 0x49, 0x67, = 0xa1, 0x1d, 0x55, 0xea, 0x1a, - 0x06, 0xa7 - }; + uint8_t expected_ciphertext[] =3D { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00= , 0x00, 0x00, 0xe3, 0x19, + 0x27, 0x7f, 0x1c, 0x8d, 0x6e, 0x6a, = 0x77, 0x96, 0xa8, 0x55, + 0x33, 0x7b, 0x9c, 0xfb, 0x56, 0xe1, = 0xf1, 0x3a, 0x87, 0x0e, + 0x66, 0x47, 0xdf, 0xa1, 0x95, 0xc9, = 0x2c, 0x17, 0xa0, 0x15, + 0xba, 0x49, 0x67, 0xa1, 0x1d, 0x55, = 0xea, 0x1a, 0x06, 0xa7 }; assert_memory_equal(BPTR(&rctx->work), expected_ciphertext, buf_len(&r= ctx->work)); tls_wrap_free(&session.tls_wrap_reneg); /* Use previous tls-crypt key as 0x00, with xor we should have the sam= e key * and expect the same result */ session.tls_wrap.mode =3D TLS_WRAP_CRYPT; - memset(&session.tls_wrap.original_wrap_keydata.keys, 0x00, sizeof(sess= ion.tls_wrap.original_wrap_keydata.keys)); + memset(&session.tls_wrap.original_wrap_keydata.keys, 0x00, + sizeof(session.tls_wrap.original_wrap_keydata.keys)); session.tls_wrap.original_wrap_keydata.n =3D 2; tls_session_generate_dynamic_tls_crypt_key(&session); @@ -279,7 +278,8 @@ tls_wrap_free(&session.tls_wrap_reneg); /* XOR should not force a different key */ - memset(&session.tls_wrap.original_wrap_keydata.keys, 0x42, sizeof(sess= ion.tls_wrap.original_wrap_keydata.keys)); + memset(&session.tls_wrap.original_wrap_keydata.keys, 0x42, + sizeof(session.tls_wrap.original_wrap_keydata.keys)); tls_session_generate_dynamic_tls_crypt_key(&session); tls_crypt_wrap(&ctx->source, &rctx->work, &rctx->opt); @@ -303,7 +303,7 @@ static void tls_crypt_loopback_zero_len(void **state) { - struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *) *state; + struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *)*state; skip_if_tls_crypt_not_supported(ctx); @@ -313,8 +313,7 @@ assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); assert_true(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->= co)); assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped)); - assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), - BLEN(&ctx->source)); + assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), BLEN(&c= tx->source)); } /** @@ -323,20 +322,19 @@ static void tls_crypt_loopback_max_len(void **state) { - struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *) *state; + struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *)*state; skip_if_tls_crypt_not_supported(ctx); buf_clear(&ctx->source); - assert_non_null(buf_write_alloc(&ctx->source, - TESTBUF_SIZE - BLEN(&ctx->ciphertext) = - tls_crypt_buf_overhead())); + assert_non_null(buf_write_alloc(&ctx->source, TESTBUF_SIZE - BLEN(&ctx= ->ciphertext) + - tls_crypt_buf_over= head())); assert_true(tls_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)); assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); assert_true(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->= co)); assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped)); - assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), - BLEN(&ctx->source)); + assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), BLEN(&c= tx->source)); } /** @@ -345,13 +343,13 @@ static void tls_crypt_fail_msg_too_long(void **state) { - struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *) *state; + struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *)*state; skip_if_tls_crypt_not_supported(ctx); buf_clear(&ctx->source); - assert_non_null(buf_write_alloc(&ctx->source, - TESTBUF_SIZE - BLEN(&ctx->ciphertext) = - tls_crypt_buf_overhead() + 1)); + assert_non_null(buf_write_alloc(&ctx->source, TESTBUF_SIZE - BLEN(&ctx= ->ciphertext) + - tls_crypt_buf_over= head() + 1)); assert_false(tls_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)); } @@ -362,13 +360,15 @@ static void tls_crypt_fail_invalid_key(void **state) { - struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *) *state; + struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *)*state; skip_if_tls_crypt_not_supported(ctx); /* Change decrypt key */ - struct key_parameters key =3D { .cipher =3D { 1 }, .hmac =3D { 1 }, - .cipher_size =3D MAX_CIPHER_KEY_LENGTH, = .hmac_size =3D MAX_HMAC_KEY_LENGTH }; + struct key_parameters key =3D { .cipher =3D { 1 }, + .hmac =3D { 1 }, + .cipher_size =3D MAX_CIPHER_KEY_LENGTH, + .hmac_size =3D MAX_HMAC_KEY_LENGTH }; free_key_ctx(&ctx->co.key_ctx_bi.decrypt); init_key_ctx(&ctx->co.key_ctx_bi.decrypt, &key, &ctx->kt, false, "TEST= "); @@ -383,7 +383,7 @@ static void tls_crypt_fail_replay(void **state) { - struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *) *state; + struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *)*state; skip_if_tls_crypt_not_supported(ctx); @@ -403,7 +403,7 @@ static void tls_crypt_ignore_replay(void **state) { - struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *) *state; + struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context = *)*state; skip_if_tls_crypt_not_supported(ctx); @@ -417,7 +417,8 @@ assert_true(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->= co)); } -struct test_tls_crypt_v2_context { +struct test_tls_crypt_v2_context +{ struct gc_arena gc; struct key2 server_key2; struct key_ctx_bi server_keys; @@ -437,17 +438,15 @@ ctx->gc =3D gc_new(); /* Slightly longer buffers to be able to test too-long data */ - ctx->metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN+16, &ctx-= >gc); - ctx->unwrapped_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN= +16, - &ctx->gc); - ctx->wkc =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_WKC_LEN+16, &ctx->gc); + ctx->metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN + 16, &ct= x->gc); + ctx->unwrapped_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN= + 16, &ctx->gc); + ctx->wkc =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_WKC_LEN + 16, &ctx->gc); /* Generate server key */ rand_bytes((void *)ctx->server_key2.keys, sizeof(ctx->server_key2.keys= )); ctx->server_key2.n =3D 2; struct key_type kt =3D tls_crypt_kt(); - init_key_ctx_bi(&ctx->server_keys, &ctx->server_key2, - KEY_DIRECTION_BIDIRECTIONAL, &kt, + init_key_ctx_bi(&ctx->server_keys, &ctx->server_key2, KEY_DIRECTION_BI= DIRECTIONAL, &kt, "tls-crypt-v2 server key"); /* Generate client key */ @@ -460,8 +459,7 @@ static int test_tls_crypt_v2_teardown(void **state) { - struct test_tls_crypt_v2_context *ctx =3D - (struct test_tls_crypt_v2_context *) *state; + struct test_tls_crypt_v2_context *ctx =3D (struct test_tls_crypt_v2_co= ntext *)*state; free_key_ctx_bi(&ctx->server_keys); free_key_ctx_bi(&ctx->client_key); @@ -479,27 +477,20 @@ static void tls_crypt_v2_wrap_unwrap_no_metadata(void **state) { - struct test_tls_crypt_v2_context *ctx =3D - (struct test_tls_crypt_v2_context *) *state; + struct test_tls_crypt_v2_context *ctx =3D (struct test_tls_crypt_v2_co= ntext *)*state; - struct buffer wrapped_client_key =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_WKC= _LEN, - &ctx->gc); - assert_true(tls_crypt_v2_wrap_client_key(&wrapped_client_key, - &ctx->client_key2, - &ctx->metadata, - &ctx->server_keys.encrypt, - &ctx->gc)); + struct buffer wrapped_client_key =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_WKC= _LEN, &ctx->gc); + assert_true(tls_crypt_v2_wrap_client_key(&wrapped_client_key, &ctx->cl= ient_key2, &ctx->metadata, + &ctx->server_keys.encrypt, &c= tx->gc)); - struct buffer unwrap_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADA= TA_LEN, - &ctx->gc); + struct buffer unwrap_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADA= TA_LEN, &ctx->gc); struct key2 unwrapped_client_key2 =3D { 0 }; - assert_true(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, - &unwrap_metadata, - wrapped_client_key, - &ctx->server_keys.decrypt)); + assert_true(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, &un= wrap_metadata, + wrapped_client_key, &ctx->s= erver_keys.decrypt)); - assert_true(0 =3D=3D memcmp(ctx->client_key2.keys, unwrapped_client_ke= y2.keys, - sizeof(ctx->client_key2.keys))); + assert_true(0 + =3D=3D memcmp(ctx->client_key2.keys, unwrapped_client_key2= .keys, + sizeof(ctx->client_key2.keys))); } /** @@ -509,26 +500,21 @@ static void tls_crypt_v2_wrap_unwrap_max_metadata(void **state) { - struct test_tls_crypt_v2_context *ctx =3D - (struct test_tls_crypt_v2_context *) *state; + struct test_tls_crypt_v2_context *ctx =3D (struct test_tls_crypt_v2_co= ntext *)*state; - uint8_t *metadata =3D - buf_write_alloc(&ctx->metadata, TLS_CRYPT_V2_MAX_METADATA_LEN); + uint8_t *metadata =3D buf_write_alloc(&ctx->metadata, TLS_CRYPT_V2_MAX= _METADATA_LEN); assert_true(rand_bytes(metadata, TLS_CRYPT_V2_MAX_METADATA_LEN)); - assert_true(tls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2, - &ctx->metadata, - &ctx->server_keys.encrypt, - &ctx->gc)); + assert_true(tls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2,= &ctx->metadata, + &ctx->server_keys.encrypt, &c= tx->gc)); - struct buffer unwrap_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADA= TA_LEN, - &ctx->gc); + struct buffer unwrap_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADA= TA_LEN, &ctx->gc); struct key2 unwrapped_client_key2 =3D { 0 }; - assert_true(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, - &unwrap_metadata, ctx->wkc, + assert_true(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, &un= wrap_metadata, ctx->wkc, &ctx->server_keys.decrypt)); - assert_true(0 =3D=3D memcmp(ctx->client_key2.keys, unwrapped_client_ke= y2.keys, - sizeof(ctx->client_key2.keys))); + assert_true(0 + =3D=3D memcmp(ctx->client_key2.keys, unwrapped_client_key2= .keys, + sizeof(ctx->client_key2.keys))); assert_true(buf_equal(&ctx->metadata, &unwrap_metadata)); struct tls_wrap_ctx wrap_ctx =3D { @@ -546,14 +532,11 @@ static void tls_crypt_v2_wrap_too_long_metadata(void **state) { - struct test_tls_crypt_v2_context *ctx =3D - (struct test_tls_crypt_v2_context *) *state; + struct test_tls_crypt_v2_context *ctx =3D (struct test_tls_crypt_v2_co= ntext *)*state; - assert_true(buf_inc_len(&ctx->metadata, TLS_CRYPT_V2_MAX_METADATA_LEN+= 1)); - assert_false(tls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2, - &ctx->metadata, - &ctx->server_keys.encrypt, - &ctx->gc)); + assert_true(buf_inc_len(&ctx->metadata, TLS_CRYPT_V2_MAX_METADATA_LEN = + 1)); + assert_false(tls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2= , &ctx->metadata, + &ctx->server_keys.encrypt, &= ctx->gc)); } /** @@ -563,28 +546,22 @@ static void tls_crypt_v2_wrap_unwrap_wrong_key(void **state) { - struct test_tls_crypt_v2_context *ctx =3D - (struct test_tls_crypt_v2_context *) *state; + struct test_tls_crypt_v2_context *ctx =3D (struct test_tls_crypt_v2_co= ntext *)*state; - assert_true(tls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2, - &ctx->metadata, - &ctx->server_keys.encrypt, - &ctx->gc)); + assert_true(tls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2,= &ctx->metadata, + &ctx->server_keys.encrypt, &c= tx->gc)); /* Change server key */ struct key_type kt =3D tls_crypt_kt(); free_key_ctx_bi(&ctx->server_keys); memset(&ctx->server_key2.keys, 0, sizeof(ctx->server_key2.keys)); - init_key_ctx_bi(&ctx->server_keys, &ctx->server_key2, - KEY_DIRECTION_BIDIRECTIONAL, &kt, + init_key_ctx_bi(&ctx->server_keys, &ctx->server_key2, KEY_DIRECTION_BI= DIRECTIONAL, &kt, "wrong tls-crypt-v2 server key"); struct key2 unwrapped_client_key2 =3D { 0 }; - assert_false(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, - &ctx->unwrapped_metadata, - ctx->wkc, - &ctx->server_keys.decrypt)= ); + assert_false(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, &c= tx->unwrapped_metadata, + ctx->wkc, &ctx->server_key= s.decrypt)); const struct key2 zero =3D { 0 }; assert_true(0 =3D=3D memcmp(&unwrapped_client_key2, &zero, sizeof(zero= ))); @@ -598,23 +575,17 @@ static void tls_crypt_v2_wrap_unwrap_dst_too_small(void **state) { - struct test_tls_crypt_v2_context *ctx =3D - (struct test_tls_crypt_v2_context *) *state; + struct test_tls_crypt_v2_context *ctx =3D (struct test_tls_crypt_v2_co= ntext *)*state; - uint8_t *metadata =3D - buf_write_alloc(&ctx->metadata, TLS_CRYPT_V2_MAX_METADATA_LEN); + uint8_t *metadata =3D buf_write_alloc(&ctx->metadata, TLS_CRYPT_V2_MAX= _METADATA_LEN); assert_true(rand_bytes(metadata, TLS_CRYPT_V2_MAX_METADATA_LEN)); - assert_true(tls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2, - &ctx->metadata, - &ctx->server_keys.encrypt, - &ctx->gc)); + assert_true(tls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2,= &ctx->metadata, + &ctx->server_keys.encrypt, &c= tx->gc)); struct key2 unwrapped_client_key2 =3D { 0 }; - struct buffer unwrapped_metadata =3D - alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN-1, &ctx->gc); - assert_false(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, - &unwrapped_metadata, ctx->= wkc, - &ctx->server_keys.decrypt)= ); + struct buffer unwrapped_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_MET= ADATA_LEN - 1, &ctx->gc); + assert_false(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, &u= nwrapped_metadata, + ctx->wkc, &ctx->server_key= s.decrypt)); const struct key2 zero =3D { 0 }; assert_true(0 =3D=3D memcmp(&unwrapped_client_key2, &zero, sizeof(zero= ))); @@ -627,8 +598,7 @@ const char *filename =3D "testfilename.key"; expect_string(__wrap_buffer_write_file, filename, filename); - expect_memory(__wrap_buffer_write_file, pem, test_server_key, - strlen(test_server_key)); + expect_memory(__wrap_buffer_write_file, pem, test_server_key, strlen(t= est_server_key)); will_return(__wrap_buffer_write_file, true); tls_crypt_v2_write_server_key_file(filename); @@ -641,8 +611,7 @@ /* Test writing the client key */ expect_string(__wrap_buffer_write_file, filename, filename); - expect_memory(__wrap_buffer_write_file, pem, test_client_key, - strlen(test_client_key)); + expect_memory(__wrap_buffer_write_file, pem, test_client_key, strlen(t= est_client_key)); will_return(__wrap_buffer_write_file, true); /* Key generation re-reads the created file as a sanity check */ @@ -668,8 +637,7 @@ expect_string(__wrap_buffer_read_from_file, filename, filename); will_return(__wrap_buffer_read_from_file, test_client_key_metadata); - tls_crypt_v2_write_client_key_file(filename, b64metadata, test_server_= key, - true); + tls_crypt_v2_write_client_key_file(filename, b64metadata, test_server_= key, true); } int @@ -677,44 +645,31 @@ { openvpn_unit_test_setup(); const struct CMUnitTest tests[] =3D { - cmocka_unit_test_setup_teardown(tls_crypt_loopback, - test_tls_crypt_setup, + cmocka_unit_test_setup_teardown(tls_crypt_loopback, test_tls_crypt= _setup, test_tls_crypt_teardown), - cmocka_unit_test_setup_teardown(tls_crypt_loopback_zero_len, - test_tls_crypt_setup, + cmocka_unit_test_setup_teardown(tls_crypt_loopback_zero_len, test_= tls_crypt_setup, test_tls_crypt_teardown), - cmocka_unit_test_setup_teardown(tls_crypt_loopback_max_len, - test_tls_crypt_setup, + cmocka_unit_test_setup_teardown(tls_crypt_loopback_max_len, test_t= ls_crypt_setup, test_tls_crypt_teardown), - cmocka_unit_test_setup_teardown(tls_crypt_fail_msg_too_long, - test_tls_crypt_setup, + cmocka_unit_test_setup_teardown(tls_crypt_fail_msg_too_long, test_= tls_crypt_setup, test_tls_crypt_teardown), - cmocka_unit_test_setup_teardown(tls_crypt_fail_invalid_key, - test_tls_crypt_setup, + cmocka_unit_test_setup_teardown(tls_crypt_fail_invalid_key, test_t= ls_crypt_setup, test_tls_crypt_teardown), - cmocka_unit_test_setup_teardown(tls_crypt_fail_replay, - test_tls_crypt_setup, + cmocka_unit_test_setup_teardown(tls_crypt_fail_replay, test_tls_cr= ypt_setup, test_tls_crypt_teardown), - cmocka_unit_test_setup_teardown(tls_crypt_ignore_replay, - test_tls_crypt_setup, + cmocka_unit_test_setup_teardown(tls_crypt_ignore_replay, test_tls_= crypt_setup, test_tls_crypt_teardown), cmocka_unit_test_setup_teardown(tls_crypt_v2_wrap_unwrap_no_metada= ta, - test_tls_crypt_v2_setup, - test_tls_crypt_v2_teardown), + test_tls_crypt_v2_setup, test_tls_= crypt_v2_teardown), cmocka_unit_test_setup_teardown(tls_crypt_v2_wrap_unwrap_max_metad= ata, - test_tls_crypt_v2_setup, - test_tls_crypt_v2_teardown), + test_tls_crypt_v2_setup, test_tls_= crypt_v2_teardown), cmocka_unit_test_setup_teardown(tls_crypt_v2_wrap_too_long_metadat= a, - test_tls_crypt_v2_setup, - test_tls_crypt_v2_teardown), - cmocka_unit_test_setup_teardown(tls_crypt_v2_wrap_unwrap_wrong_key, - test_tls_crypt_v2_setup, + test_tls_crypt_v2_setup, test_tls_= crypt_v2_teardown), + cmocka_unit_test_setup_teardown(tls_crypt_v2_wrap_unwrap_wrong_key= , test_tls_crypt_v2_setup, test_tls_crypt_v2_teardown), cmocka_unit_test_setup_teardown(tls_crypt_v2_wrap_unwrap_dst_too_s= mall, - test_tls_crypt_v2_setup, - test_tls_crypt_v2_teardown), - cmocka_unit_test_setup_teardown(test_tls_crypt_secure_reneg_key, - test_tls_crypt_setup, + test_tls_crypt_v2_setup, test_tls_= crypt_v2_teardown), + cmocka_unit_test_setup_teardown(test_tls_crypt_secure_reneg_key, t= est_tls_crypt_setup, test_tls_crypt_teardown), cmocka_unit_test(test_tls_crypt_v2_write_server_key_file), cmocka_unit_test(test_tls_crypt_v2_write_client_key_file), diff --git a/tests/unit_tests/openvpn/test_user_pass.c b/tests/unit_tests/o= penvpn/test_user_pass.c index 400c0f4..e727c4e 100644 --- a/tests/unit_tests/openvpn/test_user_pass.c +++ b/tests/unit_tests/openvpn/test_user_pass.c @@ -65,19 +65,16 @@ assert_true(0); } bool -management_query_user_pass(struct management *man, - struct user_pass *up, - const char *type, - const unsigned int flags, - const char *static_challenge) +management_query_user_pass(struct management *man, struct user_pass *up, c= onst char *type, + const unsigned int flags, const char *static_ch= allenge) { assert_true(0); return false; } /* stubs for some unused functions instead of pulling in too many dependen= cies */ int -parse_line(const char *line, char **p, const int n, const char *file, - const int line_num, int msglevel, struct gc_arena *gc) +parse_line(const char *line, char **p, const int n, const char *file, cons= t int line_num, + int msglevel, struct gc_arena *gc) { assert_true(0); return 0; @@ -163,7 +160,9 @@ /*FIXME: query_user_exec() called even though nothing queued */ will_return(query_user_exec_builtin, true); /* FIXME? content after first two lines just ignored */ - assert_true(get_user_pass_cr(&up, "#iuser and =EC=BB=A4=EB=AE=A4=EB=8B= =88=ED=8B=B0\n//ipassw=C3=B6rd!\nsome other content\nnot relevant", "UT", f= lags, NULL)); + assert_true( + get_user_pass_cr(&up, "#iuser and =EC=BB=A4=EB=AE=A4=EB=8B=88=ED= =8B=B0\n//ipassw=C3=B6rd!\nsome other content\nnot relevant", + "UT", flags, NULL)); assert_true(up.defined); assert_string_equal(up.username, "#iuser and =EC=BB=A4=EB=AE=A4=EB=8B= =88=ED=8B=B0"); assert_string_equal(up.password, "//ipassw=C3=B6rd!"); @@ -251,7 +250,7 @@ unsigned int flags =3D 0; char authfile[PATH_MAX] =3D { 0 }; - openvpn_test_get_srcdir_dir(authfile, PATH_MAX, "input/user_pass.txt" = ); + openvpn_test_get_srcdir_dir(authfile, PATH_MAX, "input/user_pass.txt"); /*FIXME: query_user_exec() called even though nothing queued */ will_return(query_user_exec_builtin, true); @@ -293,7 +292,8 @@ const char *challenge =3D "CRV1:R,E:Om01u7Fh4LrGBS7uh0SWmzwabUiGiW6l:Y= 3Ix:Please enter token PIN"; unsigned int flags =3D GET_USER_PASS_DYNAMIC_CHALLENGE; - expect_string(query_user_exec_builtin, query_user[i].prompt, "CHALLENG= E: Please enter token PIN"); + expect_string(query_user_exec_builtin, query_user[i].prompt, + "CHALLENGE: Please enter token PIN"); will_return(query_user_exec_builtin, "challenge_response"); will_return(query_user_exec_builtin, true); assert_true(get_user_pass_cr(&up, NULL, "UT", flags, challenge)); @@ -315,7 +315,8 @@ expect_string(query_user_exec_builtin, query_user[i].prompt, "Enter UT= Password:"); will_return(query_user_exec_builtin, "cpassword"); will_return(query_user_exec_builtin, true); - expect_string(query_user_exec_builtin, query_user[i].prompt, "CHALLENG= E: Please enter token PIN"); + expect_string(query_user_exec_builtin, query_user[i].prompt, + "CHALLENGE: Please enter token PIN"); will_return(query_user_exec_builtin, "challenge_response"); will_return(query_user_exec_builtin, true); assert_true(get_user_pass_cr(&up, NULL, "UT", flags, challenge)); @@ -333,7 +334,8 @@ expect_string(query_user_exec_builtin, query_user[i].prompt, "Enter UT= Password:"); will_return(query_user_exec_builtin, "c1password"); will_return(query_user_exec_builtin, true); - expect_string(query_user_exec_builtin, query_user[i].prompt, "CHALLENG= E: Please enter token PIN"); + expect_string(query_user_exec_builtin, query_user[i].prompt, + "CHALLENGE: Please enter token PIN"); will_return(query_user_exec_builtin, "0123456"); will_return(query_user_exec_builtin, true); assert_true(get_user_pass_cr(&up, NULL, "UT", flags, challenge)); @@ -344,11 +346,12 @@ reset_user_pass(&up); - flags =3D GET_USER_PASS_STATIC_CHALLENGE|GET_USER_PASS_INLINE_CREDS; + flags =3D GET_USER_PASS_STATIC_CHALLENGE | GET_USER_PASS_INLINE_CREDS; /*FIXME: query_user_exec() called even though nothing queued */ will_return(query_user_exec_builtin, true); - expect_string(query_user_exec_builtin, query_user[i].prompt, "CHALLENG= E: Please enter token PIN"); + expect_string(query_user_exec_builtin, query_user[i].prompt, + "CHALLENGE: Please enter token PIN"); will_return(query_user_exec_builtin, "challenge_response"); will_return(query_user_exec_builtin, true); assert_true(get_user_pass_cr(&up, "iuser\nipassword", "UT", flags, cha= llenge)); diff --git a/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c b/= tests/unit_tests/plugins/auth-pam/test_search_and_replace.c index d40467f..5875c8e 100644 --- a/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c +++ b/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c @@ -11,7 +11,6 @@ static void pass_any_null_param__returns_null(void **state) { - char DUMMY[] =3D "DUMMY"; assert_null(searchandreplace(NULL, DUMMY, DUMMY)); @@ -22,7 +21,6 @@ static void pass_any_empty_string__returns_null(void **state) { - char DUMMY[] =3D "DUMMY"; char EMPTY[] =3D ""; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/791?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I2566ad493629e1f5fdfa6f6483b8973463404e3e Gerrit-Change-Number: 791 Gerrit-PatchSet: 22 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: cron2 Gerrit-CC: openvpn-devel Gerrit-CC: ordex Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: ordex Gerrit-MessageType: newpatchset --Ec64+lHvvb8= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, ordex, plaisthos.

flichtenheld uploaded patch set #22 to this change.

=

View C= hange

Reformat the whole project with clang-format

Done with pre= -commit run -a, so the version
defined in pre-commit config is used.
=
Change-Id: I2566ad493629e1f5fdfa6f6483b8973463404e3e
Signed-off-by: = Frank Lichtenheld <frank@...2641...>
---
M include/openvpn-msg.= h
M sample/sample-plugins/client-connect/sample-client-connect.c
M sa= mple/sample-plugins/defer/multi-auth.c
M sample/sample-plugins/keying-ma= terial-exporter-demo/keyingmaterialexporter.c
M sample/sample-plugins/lo= g/log.c
M sample/sample-plugins/log/log_v3.c
M sample/sample-plugins/= simple/base64.c
M sample/sample-plugins/simple/simple.c
M src/compat/= compat-basename.c
M src/compat/compat-dirname.c
M src/compat/compat-g= ettimeofday.c
M src/openvpn/argv.c
M src/openvpn/argv.h
M src/open= vpn/auth_token.c
M src/openvpn/auth_token.h
M src/openvpn/base64.cM src/openvpn/base64.h
M src/openvpn/basic.h
M src/openvpn/buffer.c<= br>M src/openvpn/buffer.h
M src/openvpn/circ_list.h
M src/openvpn/cli= nat.c
M src/openvpn/clinat.h
M src/openvpn/common.h
M src/openvpn/= comp-lz4.c
M src/openvpn/comp.c
M src/openvpn/comp.h
M src/openvpn= /compstub.c
M src/openvpn/console.c
M src/openvpn/console.h
M src/= openvpn/console_builtin.c
M src/openvpn/console_systemd.c
M src/openv= pn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/crypto_backend.h
= M src/openvpn/crypto_epoch.c
M src/openvpn/crypto_epoch.h
M src/openv= pn/crypto_mbedtls.c
M src/openvpn/crypto_mbedtls.h
M src/openvpn/cryp= to_openssl.c
M src/openvpn/crypto_openssl.h
M src/openvpn/cryptoapi.c=
M src/openvpn/dco.c
M src/openvpn/dco.h
M src/openvpn/dco_freebsd= .c
M src/openvpn/dco_freebsd.h
M src/openvpn/dco_internal.h
M src/= openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/dco_win.c=
M src/openvpn/dco_win.h
M src/openvpn/dhcp.c
M src/openvpn/dhcp.h=
M src/openvpn/dns.c
M src/openvpn/dns.h
M src/openvpn/env_set.cM src/openvpn/env_set.h
M src/openvpn/errlevel.h
M src/openvpn/erro= r.c
M src/openvpn/error.h
M src/openvpn/event.c
M src/openvpn/even= t.h
M src/openvpn/fdmisc.c
M src/openvpn/fdmisc.h
M src/openvpn/fo= rward.c
M src/openvpn/forward.h
M src/openvpn/fragment.c
M src/ope= nvpn/fragment.h
M src/openvpn/gremlin.c
M src/openvpn/gremlin.h
M = src/openvpn/helper.c
M src/openvpn/httpdigest.c
M src/openvpn/httpdig= est.h
M src/openvpn/init.c
M src/openvpn/init.h
M src/openvpn/inte= ger.h
M src/openvpn/interval.c
M src/openvpn/interval.h
M src/open= vpn/list.c
M src/openvpn/list.h
M src/openvpn/lladdr.c
M src/openv= pn/lzo.c
M src/openvpn/lzo.h
M src/openvpn/manage.c
M src/openvpn/= manage.h
M src/openvpn/mbedtls_compat.h
M src/openvpn/mbuf.c
M src= /openvpn/mbuf.h
M src/openvpn/memdbg.h
M src/openvpn/misc.c
M src/= openvpn/misc.h
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src= /openvpn/mss.c
M src/openvpn/mss.h
M src/openvpn/mstats.c
M src/op= envpn/mstats.h
M src/openvpn/mtcp.c
M src/openvpn/mtcp.h
M src/ope= nvpn/mtu.c
M src/openvpn/mtu.h
M src/openvpn/mudp.c
M src/openvpn/= multi.c
M src/openvpn/multi.h
M src/openvpn/multi_io.c
M src/openv= pn/networking.h
M src/openvpn/networking_freebsd.c
M src/openvpn/netw= orking_iproute2.c
M src/openvpn/networking_sitnl.c
M src/openvpn/ntlm= .c
M src/openvpn/occ.c
M src/openvpn/occ.h
M src/openvpn/openssl_c= ompat.h
M src/openvpn/openvpn.c
M src/openvpn/openvpn.h
M src/open= vpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.cM src/openvpn/options_util.h
M src/openvpn/otime.c
M src/openvpn/oti= me.h
M src/openvpn/ovpn_dco_freebsd.h
M src/openvpn/packet_id.c
M = src/openvpn/packet_id.h
M src/openvpn/perf.c
M src/openvpn/perf.h
= M src/openvpn/ping.c
M src/openvpn/ping.h
M src/openvpn/pkcs11.c
M= src/openvpn/pkcs11.h
M src/openvpn/pkcs11_backend.h
M src/openvpn/pk= cs11_mbedtls.c
M src/openvpn/pkcs11_openssl.c
M src/openvpn/platform.= c
M src/openvpn/platform.h
M src/openvpn/plugin.c
M src/openvpn/pl= ugin.h
M src/openvpn/pool.c
M src/openvpn/pool.h
M src/openvpn/pro= to.c
M src/openvpn/proto.h
M src/openvpn/proxy.c
M src/openvpn/pro= xy.h
M src/openvpn/ps.c
M src/openvpn/ps.h
M src/openvpn/push.cM src/openvpn/push.h
M src/openvpn/pushlist.h
M src/openvpn/reflect_= filter.c
M src/openvpn/reflect_filter.h
M src/openvpn/reliable.c
M= src/openvpn/reliable.h
A src/openvpn/ring_buffer.h
M src/openvpn/rou= te.c
M src/openvpn/route.h
M src/openvpn/run_command.c
M src/openv= pn/run_command.h
M src/openvpn/schedule.c
M src/openvpn/schedule.hM src/openvpn/session_id.h
M src/openvpn/shaper.c
M src/openvpn/shap= er.h
M src/openvpn/sig.c
M src/openvpn/sig.h
M src/openvpn/socket.= c
M src/openvpn/socket.h
M src/openvpn/socks.c
M src/openvpn/socks= .h
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M src/openvpn/ssl_backe= nd.h
M src/openvpn/ssl_common.h
M src/openvpn/ssl_mbedtls.c
M src/= openvpn/ssl_mbedtls.h
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_ncp.h=
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_openssl.h
M src/ope= nvpn/ssl_pkt.c
M src/openvpn/ssl_pkt.h
M src/openvpn/ssl_util.c
M = src/openvpn/ssl_util.h
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_v= erify.h
M src/openvpn/ssl_verify_backend.h
M src/openvpn/ssl_verify_m= bedtls.c
M src/openvpn/ssl_verify_mbedtls.h
M src/openvpn/ssl_verify_= openssl.c
M src/openvpn/status.c
M src/openvpn/status.h
M src/open= vpn/syshead.h
M src/openvpn/tls_crypt.c
M src/openvpn/tls_crypt.h
= M src/openvpn/tun.c
M src/openvpn/tun.h
M src/openvpn/tun_afunix.cM src/openvpn/tun_afunix.h
M src/openvpn/vlan.c
M src/openvpn/vlan.h=
M src/openvpn/wfp_block.c
M src/openvpn/wfp_block.h
M src/openvpn= /win32-util.c
M src/openvpn/win32.c
M src/openvpn/win32.h
M src/op= envpn/xkey_common.h
M src/openvpn/xkey_helper.c
M src/openvpn/xkey_pr= ovider.c
M src/openvpnmsica/dllmain.c
M src/openvpnmsica/msica_arg.c<= br>M src/openvpnmsica/msica_arg.h
M src/openvpnmsica/msiex.c
M src/op= envpnmsica/msiex.h
M src/openvpnmsica/openvpnmsica.c
M src/openvpnmsi= ca/openvpnmsica.h
M src/openvpnserv/common.c
M src/openvpnserv/intera= ctive.c
M src/openvpnserv/service.c
M src/openvpnserv/service.h
M = src/openvpnserv/validate.c
M src/openvpnserv/validate.h
M src/plugins= /auth-pam/auth-pam.c
M src/plugins/auth-pam/pamdl.c
M src/plugins/aut= h-pam/utils.c
M src/plugins/auth-pam/utils.h
M src/plugins/down-root/= down-root.c
M src/tapctl/basic.h
M src/tapctl/error.h
M src/tapctl= /main.c
M src/tapctl/tap.c
M src/tapctl/tap.h
M tests/ntlm_support= .c
M tests/unit_tests/example_test/test.c
M tests/unit_tests/example_= test/test2.c
M tests/unit_tests/openvpn/cert_data.h
M tests/unit_test= s/openvpn/mock_management.c
M tests/unit_tests/openvpn/mock_msg.c
M t= ests/unit_tests/openvpn/mock_msg.h
M tests/unit_tests/openvpn/mock_ssl_d= ependencies.c
M tests/unit_tests/openvpn/pkey_test_utils.c
M tests/un= it_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_auth_token.= c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn= /test_crypto.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/un= it_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_ncp.c
M = tests/unit_tests/openvpn/test_networking.c
M tests/unit_tests/openvpn/te= st_packet_id.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_= tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_provider.c
M= tests/unit_tests/openvpn/test_ssl.c
M tests/unit_tests/openvpn/test_tls= _crypt.c
M tests/unit_tests/openvpn/test_user_pass.c
M tests/unit_tes= ts/plugins/auth-pam/test_search_and_replace.c
255 files changed, 11,864 = insertions(+), 15,015 deletions(-)

git pull ssh://gerrit.openvpn.=
net:29418/openvpn refs/changes/91/791/22
diff --git a/include/openv=
pn-msg.h b/include/openvpn-msg.h
index e0d0bb0..6e43588 100= 644
--- a/include/openvpn-msg.h
+++ b/inclu= de/openvpn-msg.h
@@ -27,7 +27,8 @@
#includ= e <windef.h>
#include <ws2tcpip.h>
<= span>
-typedef enum {<= /span>
+typedef enum<= br>+{
msg_= acknowledgement,
msg_add_address,
= msg_del_address,
@@ -51,28 +52,33 @@
= msg_create_adapter
} message_type_t;

-typedef struct {+typedef struct
+{

message_ty= pe_t type;
size_t size;
int messa= ge_id;
} message_header_t;

-typedef union {

+typedef union
+{
struct in_addr ipv4;
struct in6_addr ipv6;
} inet_address_t= ;

-ty= pedef struct {
+typed= ef struct
+{ int index;
char name[256];
} interface_t;


-typedef enum {
- wfp_block_local =3D 1<<0,
- wfp_block_dns =3D 1<<1
+typedef enum
+{
+ wfp_block_local =3D 1 << 0,
+ wfp_block_dns =3D 1 << 1
} wfp_block_flags_t;

-typedef struct {
+typedef struct
+{
message_header_t header;
short family;
inet_address_t address;@@ -80,7 +86,8 @@
interface_t iface;
= } address_message_t;

-typedef struct {
+typedef struct
+{
message_header_t header;
<= span> short family;
inet_address_t prefix;<= br>@@ -90,7 +97,8 @@
int metric;
} route_message_t;

-typedef struct {
+typedef struct
+{
message_header_t header;
= interface_t iface;
char domains[512];
@@ -100,14 +108,16 @@
} dns_cfg_message_t;


-typedef enum {
+typ= edef enum
+{ nrpt_dnssec
} nrpt_flags_t;
=
-#define NRPT_ADDR_NUM= 8 /* Max. number of addresses */
+#define NRPT_ADDR_NUM 8 /* Max. number of addresses */

#define NRPT_ADDR_SIZE 48 /* Max. address strlen + some */
typedef char nrpt_address_t[NRPT_ADDR_SIZE];
-typedef struct {

+typedef struct
+{
message_header_t head= er;
interface_t iface;
nrpt_addre= ss_t addresses[NRPT_ADDR_NUM];
@@ -116,14 +126,16 @@=
nrpt_flags_t flags;
} nrpt_dns_cfg_message_= t;

-t= ypedef struct {
+type= def struct
+{<= br> message_header_t header;
interface_t ifa= ce;
int addr_len;
inet_address_t = addr[4]; /* support up to 4 dns addresses */
} wins_cfg_me= ssage_t;

-typedef struct {
+typedef struct
+{
message_header_t header;
interface= _t iface;
int disable_nbt;
@@ -135,41 = +147,48 @@

/* TODO: NTP */

-typedef struct {<= /span>
+typedef struct

+{
me= ssage_header_t header;
short family;
= interface_t iface;
} flush_neighbors_message_t;=

-typedef st= ruct {
+typedef struc= t
+{
= message_header_t header;
int error_number;=
} ack_message_t;

-typedef struct {
+typedef struct
+{
message_header_t header;
<= span> wfp_block_flags_t flags;
interface_t iface;<= /span>
} wfp_block_message_t;

-typedef struct {
+typedef struct
+{
message_header_t header= ;
interface_t iface;
} enable_dhcp_me= ssage_t;

-typedef struct {
+typedef struct
+{
message_header_t header;
interface= _t iface;
short family;
int mtu;<= /span>
} set_mtu_message_t;

-typedef enum {
+typedef enum
+{
ADAPTER_TYPE_DCO,
ADAPTER_TYPE_TAP,

} adapter_type_t;

-typedef struct {<= /span>
+typedef struct
+{
me= ssage_header_t header;
adapter_type_t adapter_type;
} create_adapter_message_t;
diff --git a/sam= ple/sample-plugins/client-connect/sample-client-connect.c b/sample/sample-p= lugins/client-connect/sample-client-connect.c
index 18c2c6f= ..b180002 100644
--- a/sample/sample-plugins/client-connect= /sample-client-connect.c
+++ b/sample/sample-plugins/client= -connect/sample-client-connect.c
@@ -59,8 +59,9 @@ * Our context, where we keep our state.
*/


-struct p= lugin_context {
- in= t verb; /* logging verbosity */
+struct plugin_context
+{
+ int verb; /* logging verbosity */
};

/* this is used for the CLIENT_CONN= ECT_V2 async/deferred handler
@@ -69,8 +70,9 @@
<= span> * this, and the "CLIENT_CONNECT_DEFER_V2" handler looks at= it to see
* if it's time yet to succeed/fail<= br> */
-struct p= lugin_per_client_context {
- time_t sleep_until; /* wakeup time (time() + sleep= ) */
+struct plugin_p= er_client_context
+{<= /span>
+ time_t sleep_unt= il; /* wakeup time (time() + sleep) */
bool want_fail;=
bool want_disable;
const char *c= lient_config;
@@ -119,8 +121,7 @@
<= br> /* use v3 functions so we can use openvpn's logging and base6= 4 etc. */
OPENVPN_EXPORT int
-openvpn_plugin_open_v3(const int v3structver,

- stru= ct openvpn_plugin_args_open_in const *args,
+openvpn_plugin_open_v3(const int v3structver, struc= t openvpn_plugin_args_open_in const *args,
= struct openvpn_plugin_args_open_return *ret)
{

/* const char **argv =3D args->argv; */ /* command lin= e arguments (unused) */
@@ -129,7 +130,9 @@
/* Check API compatibility -- struct version 5 or higher needed */
if (v3structver < 5)
{- fprintf(stderr, "s= ample-client-connect: this plugin is incompatible with the running version = of OpenVPN\n");
= + fprintf(
+ = stderr,
+ = "sample-client-connect: this plugin is incompatible with the= running version of OpenVPN\n");
return OPENV= PN_PLUGIN_FUNC_ERROR;
}

@@ -145,18 +148,17 @@
/*
* I= ntercept just about everything...
*/
- ret->type_mask =3D
- OPENVPN_PLUGIN_MASK(OPENVP= N_PLUGIN_UP)
- |= OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_ROUTE_UP)

- |OPENVPN_PLUGIN_= MASK(OPENVPN_PLUGIN_IPCHANGE)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY)
<= span style=3D"color: hsl(0, 100%, 40%);">- |OPENVPN_PLUGIN_MASK(OPEN= VPN_PLUGIN_CLIENT_CONNECT)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2)<= br>- |OPENVPN_PLUGIN_MASK(= OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCON= NECT)
- |OPENVPN= _PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL)= ;
+ ret->type_m= ask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_UP)
+ | OPENVPN_PLUGIN_MASK(OPENV= PN_PLUGIN_DOWN)
+ = | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_ROUTE_UP)
<= span style=3D"color: hsl(120, 100%, 40%);">+ | OPENVPN_= PLUGIN_MASK(OPENVPN_PLUGIN_IPCHANGE)
+ | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_= TLS_VERIFY)
+ = | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT)+ | OPENVP= N_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2)
+ | OPENVPN_PLUGIN_MASK(OPEN= VPN_PLUGIN_CLIENT_CONNECT_DEFER_V2)
+ | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_C= LIENT_DISCONNECT)
+ = | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS)
+ | O= PENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL);

<= span> /* Save global pointers to functions exported from openvpn */
plugin_log =3D args->callbacks->plugin_log;<= br>@@ -168,7 +170,7 @@
*/
= context->verb =3D atoi_null0(get_env("verb", envp));
- ret->h= andle =3D (openvpn_plugin_handle_t *) context;
+ ret->handle =3D (openvpn_plugin_handle_t = *)context;
plugin_log(PLOG_NOTE, MODULE, "initial= ization succeeded");
return OPENVPN_PLUGIN_FUNC_S= UCCESS;

@@ -244,8 +246,10 @@
const char *ccd_file =3D get_env("client_connect_deferred_fil= e", envp);

if (!ccd_file)
{<= /span>
- plugin_log(PLO= G_NOTE, MODULE, "env has UV_WANT_CC_ASYNC=3D%d, but "
<= span style=3D"color: hsl(0, 100%, 40%);">- "'cli= ent_connect_deferred_file' not set -> fail", seconds);
+ plugin_log(PLOG_NOTE= , MODULE,
+ = "env has UV_WANT_CC_ASYNC=3D%d, but "
+ "'client_c= onnect_deferred_file' not set -> fail",
+ seconds);
return OPENVPN_PLUGIN_FUNC_ERROR;
}


@@ -259,13 +263,13 @@
int= fd =3D open(ccd_file, O_WRONLY);
if (fd < 0)
{
- = plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "open('%s') failed= ", ccd_file);
+ = plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "open('%s') f= ailed", ccd_file);
return OPENVPN_PLUGIN_FUNC= _ERROR;
}

if (w= rite(fd, "2", 1) !=3D 1)
{
- plugin_log(PLOG_ERR|PLOG_ERRNO,= MODULE, "write to '%s' failed", ccd_file );
+ plugin_log(PLOG_ERR | PL= OG_ERRNO, MODULE, "write to '%s' failed", ccd_file);
close(fd);
return OPENVPN_PLU= GIN_FUNC_ERROR;
}
@@ -279,11 +283,11 @= @

/* fork, sleep, succeed/fail accor= ding to env vars */
pid_t p1 =3D fork();
- if (p1 < 0) = /* Fork failed */

+ = if (p1 < 0) /* Fork failed */
{
= return OPENVPN_PLUGIN_FUNC_ERROR;
}
= - if (p1 > 0) = /* parent process */
+ if (p1 > 0) /* parent process */
{ waitpid(p1, NULL, 0);
return OPEN= VPN_PLUGIN_FUNC_DEFERRED;
@@ -293,10 +297,10 @@
<= span> pid_t p2 =3D fork();
if (p2 < 0) {
- = plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: fork(2) failed&q= uot;);
+ plugi= n_log(PLOG_ERR | PLOG_ERRNO, MODULE, "BACKGROUND: fork(2) failed"= );
exit(1);
}
- if (p2 > 0) /*= new parent: exit right away */
+ if (p2 > 0) /* new parent: exit right away */
= {
exit(0);
}

@@ -326,16 +330,16 @@
fd =3D open(ccd_file,= O_WRONLY);
if (fd < 0)
{
- plugin_log(PLOG_ER= R|PLOG_ERRNO, MODULE, "open('%s') failed", ccd_file);
+ plugin_log(PLOG= _ERR | PLOG_ERRNO, MODULE, "open('%s') failed", ccd_file)= ;
exit(1);
}
=
plugin_log(PLOG_NOTE, MODULE, "cc_handle_deferr= ed_v1: done, signalling %s",
- (ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) ? "= ;success" : "fail" );
+ (ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) ? = "success" : "fail");

= if (write(fd, (ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS) ? "1"= : "0", 1) !=3D 1)
{
- plugin_log(PLOG_ERR|PLOG_ERRNO, MOD= ULE, "write to '%s' failed", ccd_file );
+ plugin_log(PLOG_ERR | PLOG_E= RRNO, MODULE, "write to '%s' failed", ccd_file); }
close(fd);

= @@ -343,14 +347,12 @@
}

= int
-openvpn_plu= gin_client_connect(struct plugin_context *context,
- const char **arg= v,
- = const char **envp)
+openvpn_plugin_client_connect(struct plugin_context *context, con= st char **argv, const char **envp)
{
= /* log environment variables handed to us by OpenVPN, but
= * only if "setenv verb" is 3 or higher (arbitrary number)
*/
= - if (context->verb>=3D3)
+ if (context->verb >=3D 3)
{
for (int i =3D 0; argv[i]; i++)
= {
@@ -391,8 +393,7 @@

int

openvpn_plugin_client_connect_v2(struct plugin_con= text *context,
- = struct plugin_per_client_context *pcc,
= - = const char **envp,
+= struct plugin_per_client_context *pcc, con= st char **envp,
struct op= envpn_plugin_string_list **return_list)
{
= /* by setting "UV_WANT_CC2_ASYNC" we go to async/deferred mo= de */
@@ -422,7 +423,8 @@
pcc->= want_fail =3D (want_fail !=3D NULL);
pcc->want_= disable =3D (want_disable !=3D NULL);
pcc->clie= nt_config =3D client_config;
- plugin_log(PLOG_NOTE, MODULE, "env has UV_WANT_CC2_ASYN= C=3D%s -> set up deferred handler", want_async);
+ plugin_log(PLOG_NOTE, MODULE, = "env has UV_WANT_CC2_ASYNC=3D%s -> set up deferred handler",
+ wa= nt_async);
return OPENVPN_PLUGIN_FUNC_DEFERRED;
}

@@ -433,8 +435,7 @@<= /span>
return OPENVPN_PLUGIN_FUNC_ERROR;
= }

- calloc(1, sizeof(struct openvpn_plugin_s= tring_list));
+ st= ruct openvpn_plugin_string_list *rl =3D calloc(1, sizeof(struct openvpn_plu= gin_string_list));
if (!rl)
{
plugin_log(PLOG_ERR, MODULE, "malloc(return_list= ) failed");
@@ -468,12 +469,10 @@
int=
openvpn_plugin_client_connect_defer_v2(struct plugin_cont= ext *context,
struc= t plugin_per_client_context *pcc,
- struct openvpn_plugin_st= ring_list
- = **return_list)
+ struct openvpn= _plugin_string_list **return_list)
{
= time_t time_left =3D pcc->sleep_until - time(NULL);
- plugin_log(PLOG_NOTE, MODULE, "de= fer_v2: seconds left=3D%d",
- (int) time_left);
+ plugin_log(PLOG_NOTE, MODULE, "defer_v2: s= econds left=3D%d", (int)time_left);

= /* not yet due? */
if (time_left > 0)@@ -484,15 +483,14 @@
/* client wants fail? */=
if (pcc->want_fail)
{<= br>- plugin_log(PLOG_NOTE,= MODULE, "env has UV_WANT_CC2_FAIL -> fail" );
+ plugin_log(PLOG_NOTE, MODUL= E, "env has UV_WANT_CC2_FAIL -> fail");

= return OPENVPN_PLUGIN_FUNC_ERROR;
}

/* fill in RL according to with-disable / without-d= isable */

/* TODO: unify this with n= on-deferred case */
- = struct openvpn_plugin_string_list *rl =3D
- calloc(1, sizeof(struct openvpn_plugin_string= _list));
+ struct = openvpn_plugin_string_list *rl =3D calloc(1, sizeof(struct openvpn_plugin_s= tring_list));
if (!rl)
{ plugin_log(PLOG_ERR, MODULE, "malloc(return_list) fai= led");
@@ -524,15 +522,12 @@
}=

OPENVPN_EXPORT int
-openvpn_plugin_func_v2(openvpn_plugin_handle_t ha= ndle,
- = const int type,
= - const char *argv[],
- const char *envp[],
= - void *per= _client_context,
+ope= nvpn_plugin_func_v2(openvpn_plugin_handle_t handle, const int type, const c= har *argv[],
+ = const char *envp[], void *per_client_context,
struct openvpn_plugin_string_list **return_list)=

{
- = struct plugin_context *context =3D (struct plugin_context *) handle;
- struct plugin_per_clie= nt_context *pcc =3D (struct plugin_per_client_context *) per_client_context= ;
+ struct plugin_= context *context =3D (struct plugin_context *)handle;
+ struct plugin_per_client_context *pcc= =3D (struct plugin_per_client_context *)per_client_context;

/* for most functions, we just "don't do = anything" but log the
* event received (so one c= an follow it in the log and understand
@@ -566,13 +561,11 @= @

case OPENVPN_PLUGIN_CLIENT_CON= NECT_V2:
plugin_log(PLOG_NOTE, MODULE, "O= PENVPN_PLUGIN_CLIENT_CONNECT_V2");
- return openvpn_plugin_client_connect_v2(conte= xt, pcc, envp,
- = return_list);
+ return openvpn_plugin_cl= ient_connect_v2(context, pcc, envp, return_list);
<= br> case OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2:
plugin_log(PLOG_NOTE, MODULE, "OPENVPN_PLUGIN_CLIENT_= CONNECT_DEFER_V2");

- = return_list);
+ return openvpn_plugin_client_conn= ect_defer_v2(context, pcc, return_list);

= case OPENVPN_PLUGIN_CLIENT_DISCONNECT:
= plugin_log(PLOG_NOTE, MODULE, "OPENVPN_PLUGIN_CLIENT_DISCONNECT"= ;);
@@ -609,7 +602,7 @@
OPENVPN_EXPORT voi= d
openvpn_plugin_close_v1(openvpn_plugin_handle_t handle)<= /span>
{
- = struct plugin_context *context =3D (struct plugin_context *) handle;
+ struct plugin_context= *context =3D (struct plugin_context *)handle;
printf(= "FUNC: openvpn_plugin_close_v1\n");
free(con= text);
}
diff --git a/sample/sample-plugin= s/defer/multi-auth.c b/sample/sample-plugins/defer/multi-auth.c
<= span>index 38db07f..9f98391 100644

--- a/sample/sample-plug= ins/defer/multi-auth.c
+++ b/sample/sample-plugins/defer/mu= lti-auth.c
@@ -63,7 +63,8 @@
* Our contex= t, where we keep our state.
*/
-struct plugin_context {=
+struct plugin_context
+{
i= nt test_deferred_auth;
char *authid;
= char *test_valid_user;
@@ -104,11 +105,12 @@
= * structver '5' here to indicate a desire for modern openvp= n, rather
* than a need for any particular feature found = in structver beyond '1'.
*/
-#define OPENVPN_PLUGIN_VERSION_MIN 3=
+#define OPENVPN_PLUGIN_VER= SION_MIN 3
#define OPENVPN_PLUGIN_STRUCTVER_MIN 5=


-struct plugin_per_client_context {
+struct plugin_per_client_context
+{
int n_calls;
bool generated_pf_file;
};
@@ -177,13 +179,13 @@


/* use v3 funct= ions so we can use openvpn's logging and base64 etc. */
OPENVPN_EXPORT int

-o= penvpn_plugin_open_v3(const int v3structver,
- struct openvpn_plugin_args_op= en_in const *args,
+o= penvpn_plugin_open_v3(const int v3structver, struct openvpn_plugin_args_ope= n_in const *args,
struct openvpn_pl= ugin_args_open_return *ret)
{
if (v3s= tructver < OPENVPN_PLUGIN_STRUCTVER_MIN)
{- fprintf(stderr, "= %s: this plugin is incompatible with the running version of OpenVPN\n"= , MODULE);
+ f= printf(stderr, "%s: this plugin is incompatible with the running versi= on of OpenVPN\n",
- context =3D (struct pl= ugin_context *) calloc(1, sizeof(struct plugin_context));
+ context =3D (struct plugin_contex= t *)calloc(1, sizeof(struct plugin_context));
if (!con= text)
{
goto error;@@ -240,7 +242,7 @@
* Which callbacks to inter= cept.
*/
ret->type_mask =3D O= PENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY);
- ret->handle =3D (openvpn_plugin_= handle_t *) context;
= + ret->handle =3D (openvpn_plugin_handle_t *)context;

plog(context, PLOG_NOTE, "initialization succe= eded");
return OPENVPN_PLUGIN_FUNC_SUCCESS;
@@ -255,29 +257,22 @@
}

static bool
-do_auth_user_pass(struct plugin_context *context,
- const char *username, con= st char *password)
+d= o_auth_user_pass(struct plugin_context *context, const char *username, cons= t char *password)
{
- plog(context, PLOG_NOTE,
- "expect_user=3D%s, received_user=3D%s, = expect_passw=3D%s, received_passw=3D%s",
- np(context->test_valid_user),- np(username),- np(context->test_v= alid_pass),
- n= p(password));
+ pl= og(context, PLOG_NOTE, "expect_user=3D%s, received_user=3D%s, expect_p= assw=3D%s, received_passw=3D%s",
+ np(context->test_valid_user), np(username), n= p(context->test_valid_pass), np(password));

= if (context->test_valid_user && context->test_vali= d_pass)
{
if ((strcmp(context= ->test_valid_user, username) !=3D 0)
|| (st= rcmp(context->test_valid_pass, password) !=3D 0))
= {
- plog(= context, PLOG_ERR,
- = "User/Password auth result: FAIL");
+ plog(context, PLOG_ERR,= "User/Password auth result: FAIL");

= return false;
}
else
{
- plog(context, PLOG_NOTE,
- "User/Password auth result: PASS&quo= t;);
+ plo= g(context, PLOG_NOTE, "User/Password auth result: PASS");<= br> return true;
}
}

@@ -286,8 +281,7 @@

<= span>

static int
-auth_user_pass_verify(struct plugin_context *context,- struct p= lugin_per_client_context *pcc,
+auth_user_pass_verify(struct plugin_context *context, struct plu= gin_per_client_context *pcc,
const c= har *argv[], const char *envp[])
{
/*= get username/password from envp string array */
@@ -297,8 = +291,8 @@
if (!context->test_deferred_auth)<= br> {
plog(context, PLOG_NOTE, "Dir= ect authentication");
- return do_auth_user_pass(context, username, password) ?=
- OPENVPN_PLUGI= N_FUNC_SUCCESS : OPENVPN_PLUGIN_FUNC_ERROR;
+ return do_auth_user_pass(context, username,= password) ? OPENVPN_PLUGIN_FUNC_SUCCESS
+ = : OPENVPN_PLUGIN_FUNC_ERROR;
}

/* get auth_control_file filename from envp string = array*/
@@ -319,11 +313,11 @@

<= span> /* fork, sleep, succeed (no "real" auth done =3D always= succeed) */

pid_t p1 =3D fork();
- if (p1 < 0) /* Fork= failed */
+ if (p= 1 < 0) /* Fork failed */
{
= return OPENVPN_PLUGIN_FUNC_ERROR;
}
- if (p1 > 0) /* p= arent process */
+ = if (p1 > 0) /* parent process */
{
waitpid(p1, NULL, 0);

return OPENVPN_PLU= GIN_FUNC_DEFERRED;
@@ -333,11 +327,11 @@
= pid_t p2 =3D fork();
if (p2 < 0)
{
- plog(c= ontext, PLOG_ERR|PLOG_ERRNO, "BACKGROUND: fork(2) failed");

+ plog(context, PLO= G_ERR | PLOG_ERRNO, "BACKGROUND: fork(2) failed");
exit(1);
}

- if (p2 !=3D 0) = /* new parent: exit right away */
+ if (p2 !=3D 0) /* new parent: exit right away *= /
{
exit(0);
= }
@@ -350,15 +344,14 @@

/* do mighty complicated work that will really take time here... *= /
plog(context, PLOG_NOTE, "in async/deferred han= dler, usleep(%d)",
- context->test_deferred_auth*1000);
- usleep(context->test_deferred_auth*1000);=
+ context-&g= t;test_deferred_auth * 1000);
+ usleep(context->test_deferred_auth * 1000);

/* now signal success state to openvpn */ int fd =3D open(auth_control_file, O_WRONLY);
= if (fd < 0)
{
- plog(context, PLOG_ERR|PLOG_ERRNO,
<= span style=3D"color: hsl(0, 100%, 40%);">- "open('%s&#= 39;) failed", auth_control_file);
+ plog(context, PLOG_ERR | PLOG_ERRNO, "open(= '%s') failed", auth_control_file);
ex= it(1);
}

@@ -370,7 += 363,7 @@

if (write(fd, result, 1) != =3D 1)
{
- plog(context, PLOG_ERR|PLOG_ERRNO, "write to '%s&#= 39; failed", auth_control_file );
+ plog(context, PLOG_ERR | PLOG_ERRNO, "write= to '%s' failed", auth_control_file);
}
close(fd);

@@ -379,19= +372,20 @@


OPENVPN_EX= PORT int
-openvpn_plugi= n_func_v3(const int v3structver,
- struct openvpn_plugin_args_func_in const = *args,
+openvpn_plugi= n_func_v3(const int v3structver, struct openvpn_plugin_args_func_in const *= args,
struct openvpn_plugin_args_fu= nc_return *ret)
{
if (v3structver <= ; OPENVPN_PLUGIN_STRUCTVER_MIN)
{
- fprintf(stderr, "%s: this plu= gin is incompatible with the running version of OpenVPN\n", MODULE);
+ fprintf(stder= r, "%s: this plugin is incompatible with the running version of OpenVP= N\n",
+ = MODULE);
return OPENVPN_PLUGIN_FUNC_ERROR;<= /span>
}
const char **argv =3D args->= argv;
const char **envp =3D args->envp;
<= span style=3D"color: hsl(0, 100%, 40%);">- struct plugin_context *contex= t =3D (struct plugin_context *) args->handle;

- struct plugin_per_client_context *pcc =3D (s= truct plugin_per_client_context *) args->per_client_context;
<= span style=3D"color: hsl(120, 100%, 40%);">+ struct plugin_context *cont= ext =3D (struct plugin_context *)args->handle;

+ struct plugin_per_client_context *pcc =3D=
+ (struct plu= gin_per_client_context *)args->per_client_context;
= switch (args->type)
{
case= OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY:
@@ -407,7 +401,7 @@<= /span>
OPENVPN_EXPORT void *
openvpn_plugin_clie= nt_constructor_v1(openvpn_plugin_handle_t handle)
{=
- struct plugin_context *c= ontext =3D (struct plugin_context *) handle;
+ struct plugin_context *context =3D (struct plu= gin_context *)handle;
plog(context, PLOG_NOTE, "F= UNC: openvpn_plugin_client_constructor_v1");
retu= rn calloc(1, sizeof(struct plugin_per_client_context));
}<= /span>
@@ -415,7 +409,7 @@
OPENVPN_EXPORT void

openvpn_plugin_client_destructor_v1(openvpn_plugin_handle_t = handle, void *per_client_context)
{
- struct plugin_context *context =3D (str= uct plugin_context *) handle;
+ struct plugin_context *context =3D (struct plugin_context *)h= andle;
plog(context, PLOG_NOTE, "FUNC: openvpn_pl= ugin_client_destructor_v1");
free(per_client_cont= ext);
}
@@ -423,7 +417,7 @@
OPENVPN_EXPORT void
openvpn_plugin_close_v1(openvpn_plu= gin_handle_t handle)
{
- struct plugin_context *context =3D (struct plugin_con= text *) handle;
+ = struct plugin_context *context =3D (struct plugin_context *)handle;<= br> plog(context, PLOG_NOTE, "FUNC: openvpn_plugin_close_v1&= quot;);
free(context);
}
diff --git a/sample/sample-plugins/keying-material-exporter-demo/keying= materialexporter.c b/sample/sample-plugins/keying-material-exporter-demo/ke= yingmaterialexporter.c
index cc256dd..137cf20 100644=
--- a/sample/sample-plugins/keying-material-exporter-demo/keyingm= aterialexporter.c
+++ b/sample/sample-plugins/keying-materi= al-exporter-demo/keyingmaterialexporter.c
@@ -38,22 +38,25 = @@
#define MAXPATH 1024
#endif
=
-#define ovpn_e= rr(fmt, ...) \
- plu= gin->log(PLOG_ERR, "SSO", fmt, ## __VA_ARGS__)
-#define ovpn_dbg(fmt, ...) \=
- plugin->log(PLOG_DEBU= G, "SSO", fmt, ## __VA_ARGS__)
-#define ovpn_note(fmt, ...) \
- plugin->log(PLOG_NOTE, "SSO", = fmt, ## __VA_ARGS__)
= +#define ovpn_err(fmt, ...) plugin->log(PLOG_ERR, "SSO", fmt,= ##__VA_ARGS__)
+#def= ine ovpn_dbg(fmt, ...) plugin->log(PLOG_DEBUG, "SSO", fmt, ##= __VA_ARGS__)
+#define= ovpn_note(fmt, ...) plugin->log(PLOG_NOTE, "SSO", fmt, ##__VA= _ARGS__)

-enum endpoint { CLIENT =3D 1, SERVER =3D 2 };
+enum endpoint
+{
+ CLIENT =3D 1,
+ SERVER =3D 2
+};

= -struct plugin {
+str= uct plugin
+{<= br> plugin_log_t log;
enum endpoint type;

int mask;
};
-struct session {
+struct session
+{
char user[48];<= /span>
char key[48];
};
@@ -= 87,8 +90,7 @@
}

OPENVPN= _EXPORT int
-openvpn_pl= ugin_open_v3(const int version,
- struct openvpn_plugin_args_open_in const *= args,
+openvpn_plugin= _open_v3(const int version, struct openvpn_plugin_args_open_in const *args,=
struct openvpn_plugin_args_open_re= turn *rv)
{
struct plugin *plugin =3D= calloc(1, sizeof(*plugin));
@@ -100,9 +102,9 @@
= }

plugin->type =3D get= _env("remote_1", args->envp) ? CLIENT : SERVER;
- plugin->log =3D args->cal= lbacks->plugin_log;

- plugin->mas= k =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL);
+ plugin->mask =3D OPENVPN_PLUGIN_MA= SK(OPENVPN_PLUGIN_TLS_FINAL);
plugin->mask |=3D OPE= NVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY);

ovpn_note("vpn endpoint type=3D%s", plugin->type =3D= =3D CLIENT ? "client" : "server");
@@ -= 165,8 +167,8 @@
static int
tls_verify(str= uct openvpn_plugin_args_func_in const *args)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- struct plugin *plugin =3D (st= ruct plugin *)args->handle;
- struct session *sess =3D (struct session *)args->per_clie= nt_context;
+ stru= ct plugin *plugin =3D (struct plugin *)args->handle;
+ struct session *sess =3D (struct se= ssion *)args->per_client_context;

= /* we store cert subject for the server end point only */
= if (plugin->type !=3D SERVER)
@@ -201,8 +203,8 @@
static void
server_store(struct openvpn_pl= ugin_args_func_in const *args)
{
- struct plugin *plugin =3D (struct plugin *= )args->handle;
- = struct session *sess =3D (struct session *)args->per_client_context;

+ struct plugin *plu= gin =3D (struct plugin *)args->handle;
+ struct session *sess =3D (struct session *)args-&= gt;per_client_context;

char file[MAX= PATH];
snprintf(file, sizeof(file) - 1, "/tmp/ope= nvpn_sso_%s", sess->key);
@@ -213,8 +215,8 @@
static void
client_store(struct openvpn_plugin= _args_func_in const *args)
{
- struct plugin *plugin =3D (struct plugin *)arg= s->handle;
- stru= ct session *sess =3D (struct session *)args->per_client_context;=
+ struct plugin *plugin = =3D (struct plugin *)args->handle;
+ struct session *sess =3D (struct session *)args->p= er_client_context;

char *file =3D &q= uot;/tmp/openvpn_sso_user";
ovpn_note("app s= ession file: %s", file);
@@ -225,8 +227,8 @@ tls_final(struct openvpn_plugin_args_func_in const *args, struct openvpn_plugin_args_func_return *rv)
{

- struct plugi= n *plugin =3D (struct plugin *)args->handle;
- struct session *sess =3D (struct session *)= args->per_client_context;
+ struct plugin *plugin =3D (struct plugin *)args->handle;
+ struct session *se= ss =3D (struct session *)args->per_client_context;

const char *key;
if (!(key =3D get_e= nv("exported_keying_material", args->envp)))
@= @ -253,8 +255,7 @@
}

OP= ENVPN_EXPORT int
-openv= pn_plugin_func_v3(const int version,
- struct openvpn_plugin_args_func_in co= nst *args,
+openvpn_p= lugin_func_v3(const int version, struct openvpn_plugin_args_func_in const *= args,
struct openvpn_plugin_args_fu= nc_return *rv)
{
switch (args->typ= e)
@@ -272,7 +273,7 @@
openvpn_plugin_clie= nt_constructor_v1(openvpn_plugin_handle_t handle)
{=
struct plugin *plugin =3D (struct plugin *)handle;- struct session *sess =3D c= alloc(1, sizeof(*sess));
+ struct session *sess =3D calloc(1, sizeof(*sess));

ovpn_note("app session created");<= br>
@@ -283,7 +284,7 @@
openvpn_plu= gin_client_destructor_v1(openvpn_plugin_handle_t handle, void *ctx)<= br> {
struct plugin *plugin =3D (struct plugin *= )handle;
- struct se= ssion *sess =3D (struct session *)ctx;
+ struct session *sess =3D (struct session *)ctx;

ovpn_note("app session key: %s&quo= t;, sess->key);
ovpn_note("app session destroy= ed");
diff --git a/sample/sample-plugins/log/log.c b/s= ample/sample-plugins/log/log.c
index 82595cf..0a96c63 10064= 4
--- a/sample/sample-plugins/log/log.c
+++= b/sample/sample-plugins/log/log.c
@@ -37,7 +37,8 @@=
/*
* Our context, where we keep our state.
*/
-stru= ct plugin_context {
+= struct plugin_context
+{
const char *username;
const c= har *password;
};
@@ -77,7 +78,7 @@=
/*
* Allocate our context
*/

- conte= xt =3D (struct plugin_context *) calloc(1, sizeof(struct plugin_context));<= /span>
+ context =3D (str= uct plugin_context *)calloc(1, sizeof(struct plugin_context));
if (context =3D=3D NULL)

{
= printf("PLUGIN: allocating memory for context failed\n");<= /span>
@@ -93,19 +94,17 @@
/*
* Which callbacks to intercept.

*/
<= span style=3D"color: hsl(0, 100%, 40%);">- *type_mask =3D

- OPENVPN_PLUGIN_MASK(OPENVPN_= PLUGIN_UP)
- |OP= ENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_ROUTE_UP)

- |OPENVPN_PLUGIN_MA= SK(OPENVPN_PLUGIN_IPCHANGE)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY)
- |OPENVPN_PLUGIN_MASK(OPENVP= N_PLUGIN_AUTH_USER_PASS_VERIFY)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2)
- |OPENVPN_PLUGIN_= MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS)=
- |OPENVPN_PLUG= IN_MASK(OPENVPN_PLUGIN_TLS_FINAL);
+ *type_mask =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_UP) | = OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN)
+ | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_= ROUTE_UP)
+ = | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_IPCHANGE)
+ | OPENVPN_PLUGIN_MASK(OP= ENVPN_PLUGIN_TLS_VERIFY)
+ | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_V= ERIFY)
+ = | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2)
+ | OPENVPN_PLUGIN_M= ASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT)

+ | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEA= RN_ADDRESS)
+ = | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL);
=
- return (openvpn_p= lugin_handle_t) context;
+ return (openvpn_plugin_handle_t)context;
}=

void
@@ -173,9 +172,10 @@

}

OPENVPN_EXPORT int=
-openvpn_plugin_func_v1(openv= pn_plugin_handle_t handle, const int type, const char *argv[], const char *= envp[])
+openvpn_plug= in_func_v1(openvpn_plugin_handle_t handle, const int type, const char *argv= [],
+ = const char *envp[])
{
- struct plugin_context *context =3D (struct plug= in_context *) handle;
+ struct plugin_context *context =3D (struct plugin_context *)handle;

show(type, argv, envp);

@@ -186,8 +186,8 @@
const cha= r *username =3D get_env("username", envp);
= const char *password =3D get_env("password", envp);
=
- if (us= ername && !strcmp(username, context->username)
- && password &&a= mp; !strcmp(password, context->password))
+ if (username && !strcmp(username, = context->username) && password
+ && !strcmp(password, context->= password))
{
return O= PENVPN_PLUGIN_FUNC_SUCCESS;
}
@@ -= 205,6 +205,6 @@
OPENVPN_EXPORT void
openv= pn_plugin_close_v1(openvpn_plugin_handle_t handle)
{
- struct plugin_context *= context =3D (struct plugin_context *) handle;
+ struct plugin_context *context =3D (struct pl= ugin_context *)handle;
free(context);
= }
diff --git a/sample/sample-plugins/log/log_v3.c b/sample= /sample-plugins/log/log_v3.c
index c90cc3d..7da49c7 100644<= /span>
--- a/sample/sample-plugins/log/log_v3.c
++= + b/sample/sample-plugins/log/log_v3.c
@@ -40,7 +40,8 @@
/*
* Our context, where we keep our state.=
*/
-= struct plugin_context {
+struct plugin_context
+{
const char *username;
con= st char *password;
};
@@ -73,8 +74,7 @@
}

OPENVPN_EXPORT int

-openvpn_plugin_open_v3(con= st int v3structver,
- = struct openvpn_plugin_args_open_in const *args,=
+openvpn_plugin_open_v3(con= st int v3structver, struct openvpn_plugin_args_open_in const *args,<= br> struct openvpn_plugin_args_open_return *re= t)
{
struct plugin_context *context = =3D NULL;
@@ -82,7 +82,8 @@
/* Check t= hat we are API compatible */
if (v3structver !=3D OPEN= VPN_PLUGINv3_STRUCTVER)
{
- printf("log_v3: ** ERROR ** Incompati= ble plug-in interface between this plug-in and OpenVPN\n");
= + printf(
+ "log_v3: ** ERROR= ** Incompatible plug-in interface between this plug-in and OpenVPN\n"= );
return OPENVPN_PLUGIN_FUNC_ERROR;
}

@@ -93,26 +94,24 @@
<= span> }

/* Print some version in= formation about the OpenVPN process using this plug-in */
- printf("log_v3: OpenVPN %s (M= ajor: %i, Minor: %i, Patch: %s)\n",
- args->ovpn_version, args->ovpn_version_= major,
- args= ->ovpn_version_minor, args->ovpn_version_patch);
+ printf("log_v3: OpenVPN %s (Ma= jor: %i, Minor: %i, Patch: %s)\n", args->ovpn_version,
+ args->ovpn_version= _major, args->ovpn_version_minor, args->ovpn_version_patch);
/* Which callbacks to intercept. */=
- ret->type_mask =3D

- OPENVPN_PLUGIN_M= ASK(OPENVPN_PLUGIN_UP)
= - |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_RO= UTE_UP)
- |OPENV= PN_PLUGIN_MASK(OPENVPN_PLUGIN_IPCHANGE)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY)
- |OPENVPN_PLUGIN= _MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CO= NNECT_V2)
- |OPE= NVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LE= ARN_ADDRESS)
- |= OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_FINAL);
+ ret->type_mask =3D OPENVPN_PLUGIN_MASK(OP= ENVPN_PLUGIN_UP)
+ = | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_DOWN)
+ | OPENVPN_PLU= GIN_MASK(OPENVPN_PLUGIN_ROUTE_UP)

+ | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_IPC= HANGE)
+ = | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY)
+ | OPENVPN_PLUGIN_= MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY)
+ | OPENVPN_PLUGIN_MASK(OPENVPN_P= LUGIN_CLIENT_CONNECT_V2)
+ | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCO= NNECT)
+ = | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_LEARN_ADDRESS)
+ | OPENVPN_PLUG= IN_MASK(OPENVPN_PLUGIN_TLS_FINAL);


/* Allocate our context */
- context =3D (struct plugin_context *) calloc(1, s= izeof(struct plugin_context));
+ context =3D (struct plugin_context *)calloc(1, sizeof(struct= plugin_context));
if (context =3D=3D NULL)
= {
printf("PLUGIN: allocating memor= y for context failed\n");
@@ -124,7 +123,7 @@ context->password =3D "bar";

/* Point the global context handle to our newly created = context */
- ret->= ;handle =3D (void *) context;
+ ret->handle =3D (void *)context;
<= br> return OPENVPN_PLUGIN_FUNC_SUCCESS;
}=
@@ -245,13 +244,11 @@
}
=

- OPENVPN_EXPORT int
-openvpn_plugin_func_v3(const int version,
- struct openvpn_plugin_args_= func_in const *args,
= +openvpn_plugin_func_v3(const int version, struct openvpn_plugin_args_func_= in const *args,
struct openvpn_plug= in_args_func_return *retptr)
{
- struct plugin_context *context =3D (struct pl= ugin_context *) args->handle;
+ struct plugin_context *context =3D (struct plugin_context = *)args->handle;

printf("\nop= envpn_plugin_func_v3() :::::>> ");
show(arg= s->type, args->argv, args->envp);
@@ -272,8 +269,8= @@
const char *username =3D get_env("usernam= e", args->envp);
const char *password =3D = get_env("password", args->envp);

<= span style=3D"color: hsl(0, 100%, 40%);">- if (username && != strcmp(username, context->username)

- && password && !strcmp(passwor= d, context->password))
+ if (username && !strcmp(username, context->usernam= e) && password
- struct plugin_context *context =3D (struct= plugin_context *) handle;
+ struct plugin_context *context =3D (struct plugin_context *)hand= le;
free(context);
}
= diff --git a/sample/sample-plugins/simple/base64.c b/sample/sample-plugins/= simple/base64.c
index 6855966..5b2cff5 100644
--- a/sample/sample-plugins/simple/base64.c
+++ b/sample= /sample-plugins/simple/base64.c
@@ -100,21 +100,20 @@
*
*/
OPENVPN_EXPORT int

-openvpn_plugin_open_v3(co= nst int v3structver,
- = struct openvpn_plugin_args_open_in const *args,
+openvpn_plugin_open_v3(co= nst int v3structver, struct openvpn_plugin_args_open_in const *args,=
struct openvpn_plugin_args_open_return *r= et)
{
/* Check that we are API compat= ible */
if (v3structver !=3D OPENVPN_PLUGINv3_STRUCTVE= R)
{
- printf("base64.c: ** ERROR ** Incompatible plug-in interfa= ce between this plug-in and OpenVPN\n");
+ printf(
+ "base64.c: ** ERROR ** Incompatible = plug-in interface between this plug-in and OpenVPN\n");
return OPENVPN_PLUGIN_FUNC_ERROR;

}<= br>
/* Which callbacks to intercept. */
- ret->type_mask =3D
- OPENVPN_PLUGIN_= MASK(OPENVPN_PLUGIN_TLS_VERIFY)
- |OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT_V2);
+ ret->type_mask= =3D OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_TLS_VERIFY)
+ | OPENVPN_PLUGIN_MAS= K(OPENVPN_PLUGIN_CLIENT_CONNECT_V2);

= /* we don't need a plug-in context in this example, but OpenVPN expect= s "something" */
ret->handle =3D calloc(1= , 1);
@@ -127,8 +126,8 @@

/* Print some version information about the OpenVPN process using thi= s plug-in */

ovpn_log(PLOG_NOTE, PLUGIN_NAME, "Op= enVPN %s (Major: %i, Minor: %i, Patch: %s)\n",
- args->ovpn_version, args-&g= t;ovpn_version_major,
-= args->ovpn_version_minor, args->ovpn_version_patch);
+ args->o= vpn_version, args->ovpn_version_major, args->ovpn_version_minor,

+ args->ov= pn_version_patch);

return OPENVPN_PL= UGIN_FUNC_SUCCESS;
}
@@ -156,10 +155,10 @@=
*/

OPENVPN_EXPORT int=
-openvpn_plugin_func_v= 1(openvpn_plugin_handle_t handle, const int type, const char *argv[], const= char *envp[])
+openv= pn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, const cha= r *argv[],
+ = const char *envp[])
{
- if (type !=3D OPENVPN_PLUGIN_TLS_VERIFY=
- && ty= pe !=3D OPENVPN_PLUGIN_CLIENT_CONNECT_V2)
+ if (type !=3D OPENVPN_PLUGIN_TLS_VERIFY &&= ; type !=3D OPENVPN_PLUGIN_CLIENT_CONNECT_V2)
{=
ovpn_log(PLOG_ERR, PLUGIN_NAME, "Unsupported plug-i= n hook call attempted");
return OPENVPN_PLUGI= N_FUNC_ERROR;
@@ -176,14 +175,13 @@
/*= test the BASE64 encode function */
char *buf =3D NULL= ;
int r =3D ovpn_base64_encode(clcert_cn, strlen(clcer= t_cn), &buf);
- = ovpn_log(PLOG_NOTE, PLUGIN_NAME, "BASE64 encoded '%s' (return = value %i): '%s'",
- clcert_cn, r, buf);
+ ovpn_log(PLOG_NOTE, PLUGIN_NAME, "BASE64 en= coded '%s' (return value %i): '%s'", clcert_cn, r,
+ buf);

/* test the BASE64 decode function */
- char buf2[256] =3D = {0};
+ char buf2[2= 56] =3D { 0 };
r =3D ovpn_base64_decode(buf, &buf2= , 255);
- ovpn_log(P= LOG_NOTE, PLUGIN_NAME, "BASE64 decoded '%s' (return value %i):= '%s'",
-= buf, r, buf2);
+ ovpn_log(PLOG_NOTE, PLUGIN_NAME, "BASE64 decoded '%s&#= 39; (return value %i): '%s'", buf, r, buf2);
=
/* Verify the result, and free the buffer allocated = by ovpn_base64_encode() */
r =3D strcmp(clcert_cn, buf= 2);
@@ -203,6 +201,6 @@
OPENVPN_EXPORT voi= d
openvpn_plugin_close_v1(openvpn_plugin_handle_t handle)<= /span>
{
- = struct plugin_context *context =3D (struct plugin_context *) handle;
+ struct plugin_context= *context =3D (struct plugin_context *)handle;
free(co= ntext);
}
diff --git a/sample/sample-plugi= ns/simple/simple.c b/sample/sample-plugins/simple/simple.c
= index e17f3fa..2666e2f 100644
--- a/sample/sample-plugins/s= imple/simple.c
+++ b/sample/sample-plugins/simple/simple.c<= /span>
@@ -39,7 +39,8 @@
/*
* O= ur context, where we keep our state.
*/
-struct plugin_context {
+struct plugin_context

+{

const char= *username;
const char *password;
};<= /span>
@@ -79,7 +80,7 @@
/*
= * Allocate our context
*/
- context =3D (struct plugin_context *) c= alloc(1, sizeof(struct plugin_context));
+ context =3D (struct plugin_context *)calloc(1, siz= eof(struct plugin_context));
if (context =3D=3D NULL)<= /span>
{
printf("PLUGIN: alloca= ting memory for context failed\n");
@@ -98,21 +99,22 @= @
*/
*type_mask =3D OPENVPN_PLUG= IN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY);

= - return (openvpn_plugin_handl= e_t) context;
+ re= turn (openvpn_plugin_handle_t)context;
}
=
OPENVPN_EXPORT int
-openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const= int type, const char *argv[], const char *envp[])
+openvpn_plugin_func_v1(openvpn_plugin_handle= _t handle, const int type, const char *argv[],
+ const char *envp[])
{
- stru= ct plugin_context *context =3D (struct plugin_context *) handle;
= + struct plugin_context *con= text =3D (struct plugin_context *)handle;

/* get username/password from envp string array */

= const char *username =3D get_env("username", envp);
= const char *password =3D get_env("password", envp);

/* check entered username/password aga= inst what we require */
- if (username && !strcmp(username, context->username)
- && password= && !strcmp(password, context->password))
+ if (username && !strcmp(usern= ame, context->username) && password
+ && !strcmp(password, context->= ;password))
{
return OPENVPN_= PLUGIN_FUNC_SUCCESS;
}
@@ -125,6 +127,= 6 @@
OPENVPN_EXPORT void
openvpn_plugin_c= lose_v1(openvpn_plugin_handle_t handle)
{
- struct plugin_context *context =3D= (struct plugin_context *) handle;
+ struct plugin_context *context =3D (struct plugin_contex= t *)handle;
free(context);
}diff --git a/src/compat/compat-basename.c b/src/compat/compat-basen= ame.c
index abb4f49..ea8bfbb 100644
--- a/s= rc/compat/compat-basename.c
+++ b/src/compat/compat-basenam= e.c
@@ -42,7 +42,7 @@
/* If NULL, = check for \ instead ... might be Windows a path */
= p =3D strrchr(filename, '\\');
}
- return p ? p + 1 : (char *) fi= lename;

+ return p= ? p + 1 : (char *)filename;
}
#endif /* HAVE_BASENAME */
diff --git a/src/compat/= compat-dirname.c b/src/compat/compat-dirname.c
index c131de= e..527f252 100644
--- a/src/compat/compat-dirname.c<= br>+++ b/src/compat/compat-dirname.c
@@ -90,7 +90,7 @= @
/* The '/' is the last character, we hav= e to look further. */
if (runp !=3D path)<= br> {
- = last_slash =3D (char *) __memrchr(path, separator, runp - path);<= /span>
+ last_sla= sh =3D (char *)__memrchr(path, separator, runp - path);
= }
}

@@ -135,7 = +135,7 @@
/* This assignment is ill-designed but t= he XPG specs require to
* return a string contain= ing "." in any case no directory part is
= * found and so a static and constant string is required. */
- path =3D (char *) dot;
+ path =3D (char = *)dot;
}

return= path;
diff --git a/src/compat/compat-gettimeofday.c b/src/= compat/compat-gettimeofday.c
index 997f360..23b5734 100644<= /span>
--- a/src/compat/compat-gettimeofday.c
+++ = b/src/compat/compat-gettimeofday.c
@@ -49,7 +49,7 @@=
{
const time_t t =3D time(NULL);
= const DWORD gtc =3D GetTickCount();
- gtc_base =3D t - gtc/1000;
+ gtc_base =3D t - gtc / 1000;=
gtc_last =3D gtc;
}

@@ -113,7 +113,7 @@
return 0;
}


-#else /* ifdef _WIN32 */
+#else /* ifdef _WIN32 */

#includ= e <time.h>

diff --git a/src/openvpn= /argv.c b/src/openvpn/argv.c
index 95215c0..78d37c7 100644<= /span>
--- a/src/openvpn/argv.c
+++ b/src/openvpn/= argv.c
@@ -285,8 +285,7 @@
* fr= ee()d to avoid memory leaks.
*/
static c= har *
-argv_prep_format= (const char *format, const char delim, size_t *count,
- struct gc_arena *gc)
+argv_prep_format(const ch= ar *format, const char delim, size_t *count, struct gc_arena *gc) {
if (format =3D=3D NULL)
= {
@@ -312,7 +311,7 @@
* the = string is empty; the resulting format string
= * will never start with a delimiter.
*/
- if (j > 0) = /* Has anything been written to the output string? */
+ if (j > 0) /* Has anything= been written to the output string? */
{
f[j++] =3D delim;
= }
@@ -348,7 +347,7 @@
static bool argv_printf_arglist(struct argv *argres, const char *format, va_li= st arglist)
{
- const char delim =3D 0x1D; /* ASCII Group Separator (GS) */
+ const char delim = =3D 0x1D; /* ASCII Group Separator (GS) */
bool res = =3D false;

/*
@@ -48= 5,8 +484,8 @@
argv_reset(argres);

char *parms[MAX_PARMS + 1] =3D { 0 };
- int nparms =3D parse_line(cmdstr, pa= rms, MAX_PARMS, "SCRIPT-ARGV", 0,
- D_ARGV_PARSE_CMD, &ar= gres->gc);
+ in= t nparms =3D
+ = parse_line(cmdstr, parms, MAX_PARMS, "SCRIPT-ARGV", 0, D_ARGV_PA= RSE_CMD, &argres->gc);
if (nparms)
{

int i;
diff --git a/src= /openvpn/argv.h b/src/openvpn/argv.h
index 098a1cb..9aaa55b= 100644
--- a/src/openvpn/argv.h
+++ b/src/= openvpn/argv.h
@@ -32,7 +32,8 @@
#include "buffer.h"

-struct argv {
+struct argv
+{
struct gc_arena gc;
<= span> size_t capacity;

size_t argc;
@@ -56,21 +57,21 @@

bool argv_printf(struct argv *a, con= st char *format, ...)
#ifdef __GNUC__
#if= __USE_MINGW_ANSI_STDIO
-__attribute__ ((format(gnu_printf, 2, 3)))
+ __attribute__((format(gnu_printf, 2, 3)))
#else
-__a= ttribute__ ((format(__printf__, 2, 3)))
+ __attribute__((format(__printf__, 2, 3))) #endif
#endif
-;
+ = ;

bool argv_printf_cat(struct argv *a= , const char *format, ...)
#ifdef __GNUC__
#if __USE_MINGW_ANSI_STDIO

-__attribute__ ((format(gnu_printf, 2, 3)))
+ __attribute__((format(gnu_printf, 2, 3)))=
#else
-__attribute__ ((format(__printf__, 2, 3)))
+ __attribute__((format(__printf__, 2, 3)))
#endif
#endif
-;
+ ;

#endif /* ifndef ARGV_H */
diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token= .c
index 3cf55e8..a694e81 100644
--- a/src/= openvpn/auth_token.c
+++ b/src/openvpn/auth_token.c<= br>@@ -18,7 +18,7 @@

const char *a= uth_token_pem_name =3D "OpenVPN auth-token server key";
-#define AUTH_= TOKEN_SESSION_ID_LEN 12
+#define AUTH_TOKEN_SESSION_ID_LEN 12
#define AU= TH_TOKEN_SESSION_ID_BASE64_LEN (AUTH_TOKEN_SESSION_ID_LEN * 8 / 6)
#if AUTH_TOKEN_SESSION_ID_LEN % 3
@@ -53,7 +53,7 @@

}
else if (au= th_token_state_flags & AUTH_TOKEN_HMAC_OK)
{
- switch (auth_token_= state_flags & (AUTH_TOKEN_VALID_EMPTYUSER|AUTH_TOKEN_EXPIRED))+ switch (auth_token_s= tate_flags & (AUTH_TOKEN_VALID_EMPTYUSER | AUTH_TOKEN_EXPIRED))<= br> {
case 0:
= state =3D "Authenticated";
@@ -107= ,9 +107,9 @@
* in the encoding
= */

- = char session_id[AUTH_TOKEN_SESSION_ID_LEN*2] =3D {0};
+ char session_id[AUTH_TOKEN_SESSION= _ID_LEN * 2] =3D { 0 };
memcpy(session_id, session_id_= source + strlen(SESSION_ID_PREFIX),
- AUTH_TOKEN_SESSION_ID_LEN*8/6);
+ AUTH_TOKEN_SESSION_ID_LEN *= 8 / 6);

setenv_str(session->opt-= >es, "session_id", session_id);
}
<= span>@@ -121,8 +121,7 @@

}

void

-auth_token_in= it_secret(struct key_ctx *key_ctx, const char *key_file,
- bool key_inline)<= /span>
+auth_token_init_secr= et(struct key_ctx *key_ctx, const char *key_file, bool key_inline) {
struct key_type kt =3D auth_token_kt();

@@ -131,14 +130,12 @@
b= ool key_loaded =3D false;
if (key_file)
{

- key_l= oaded =3D read_pem_key_file(&server_secret_key,
- auth= _token_pem_name,
- = key_file, key_inline);
+ key_loaded =3D
+ read_pem_key_file(&= server_secret_key, auth_token_pem_name, key_file, key_inline);

}

else
{
- key_loaded =3D generate_ephem= eral_key(&server_secret_key,

- auth_token_pem_name)= ;
+ key_loaded= =3D generate_ephemeral_key(&server_secret_key, auth_token_pem_name);
}

if (!key_loade= d)
@@ -169,7 +166,7 @@
int64_t initial= _timestamp =3D timestamp;

hmac_ctx_t= *ctx =3D multi->opt.auth_token_key.hmac;
- ASSERT(hmac_ctx_size(ctx) =3D=3D 256/8);<= br>+ ASSERT(hmac_ctx_size(ct= x) =3D=3D 256 / 8);

uint8_t sessid[A= UTH_TOKEN_SESSION_ID_LEN];

@@ -185,7 +182= ,7 @@
char *initial_token_copy =3D string_alloc(mu= lti->auth_token_initial, &gc);

= char *old_sessid =3D initial_token_copy + strlen(SESSION_ID_PREFIX);<= /span>
- char *old_tsta= mp_initial =3D old_sessid + AUTH_TOKEN_SESSION_ID_LEN*8/6;
+ char *old_tstamp_initial =3D= old_sessid + AUTH_TOKEN_SESSION_ID_LEN * 8 / 6;
/*
* We null terminate the old t= oken just after the session ID to let
@@ -197,12 +194,13 @@=
memcpy(&initial_timestamp, &old_tstamp_de= code, sizeof(initial_timestamp));

= old_tstamp_initial[0] =3D '\0';
- ASSERT(openvpn_base64_decode(old_sessid, sessid= , AUTH_TOKEN_SESSION_ID_LEN) =3D=3D AUTH_TOKEN_SESSION_ID_LEN);
<= span style=3D"color: hsl(120, 100%, 40%);">+ ASSERT(openvpn_base64_d= ecode(old_sessid, sessid, AUTH_TOKEN_SESSION_ID_LEN)

+ =3D=3D AUTH_TOKEN_SESSION_= ID_LEN);
}
else if (!rand_bytes(s= essid, AUTH_TOKEN_SESSION_ID_LEN))
{
- msg( M_FATAL, "Failed to g= et enough randomness for "
- "authentication token");
+ msg(M_FATAL, "Failed to = get enough randomness for "
+ "authentication token");=
}

/* Calculate the HM= AC */
@@ -210,7 +208,7 @@
* with \0 i= n them is asking for troubles in so many ways anyway that we
* ignore that corner case here

*/
<= span style=3D"color: hsl(0, 100%, 40%);">- uint8_t hmac_output[256/8];
+ uint8_t hmac_outp= ut[256 / 8];

hmac_ctx_reset(ctx);

@@ -222,20 +220,20 @@
= struct key_state *ks =3D &multi->session[TM_ACTIVE].key[KS_PRIMARY];=
if (ks->auth_token_state_flags & AUTH_TOKEN_VA= LID_EMPTYUSER)
{
- hmac_ctx_update(ctx, (const uint8_t *) ""= , 0);
+ hmac_c= tx_update(ctx, (const uint8_t *)"", 0);
}
else
{
- hmac_ctx_update(ctx, (uint8_t *) up->us= ername, (int) strlen(up->username));
+ hmac_ctx_update(ctx, (uint8_t *)up->username= , (int)strlen(up->username));
}
= hmac_ctx_update(ctx, sessid, AUTH_TOKEN_SESSION_ID_LEN);
- hmac_ctx_update(ctx, (uint8_t *) &= amp;initial_timestamp, sizeof(initial_timestamp));
- hmac_ctx_update(ctx, (uint8_t *) &time= stamp, sizeof(timestamp));
+ hmac_ctx_update(ctx, (uint8_t *)&initial_timestamp, sizeof(i= nitial_timestamp));
+= hmac_ctx_update(ctx, (uint8_t *)&timestamp, sizeof(timestamp));
hmac_ctx_final(ctx, hmac_output);

/* Construct the unencoded session token */
- struct buffer token =3D alloc_buf= _gc(

- 2*sizeof(= uint64_t) + AUTH_TOKEN_SESSION_ID_LEN + 256/8, &gc);
+ struct buffer token =3D
= + alloc_buf_gc(2 * sizeo= f(uint64_t) + AUTH_TOKEN_SESSION_ID_LEN + 256 / 8, &gc);

ASSERT(buf_write(&token, sessid, sizeof(sessid= )));
ASSERT(buf_write(&token, &initial_timesta= mp, sizeof(initial_timestamp)));
@@ -245,8 +243,8 @@=
char *b64output =3D NULL;
openvpn_base6= 4_encode(BPTR(&token), BLEN(&token), &b64output);

- struct buffer= session_token =3D alloc_buf_gc(
- strlen(SESSION_ID_PREFIX) + strlen(b64output) + 1, &= gc);
+ struct buff= er session_token =3D
= + alloc_buf_gc(strlen(SESSION_ID_PREFIX) + strlen(b64output) + 1, &a= mp;gc);

ASSERT(buf_write(&sessio= n_token, SESSION_ID_PREFIX, strlen(SESSION_ID_PREFIX)));
= ASSERT(buf_write(&session_token, b64output, (int)strlen(b64output)))= ;
@@ -258,8 +256,7 @@
free(multi->a= uth_token);
multi->auth_token =3D strdup((char *)BP= TR(&session_token));

- dmsg(D_SHOW_KEYS, "Generated token for client= : %s (%s)",
- = multi->auth_token, up->username);
+ dmsg(D_SHOW_KEYS, "Generated token for cli= ent: %s (%s)", multi->auth_token, up->username);

if (!multi->auth_token_initial)
= {
@@ -277,22 +274,21 @@
static bool
check_hmac_token(hmac_ctx_t *ctx, const uint8_t *b64decoded= , const char *username)
{
- ASSERT(hmac_ctx_size(ctx) =3D=3D 256/8);+ ASSERT(hmac_ctx_size(ctx)= =3D=3D 256 / 8);

- uint8_t hmac_output[256/8];
+ uint8_t hmac_output[256 / 8];

hmac_ctx_reset(ctx);
- hmac_ctx_update(ctx, (uint8_t *) username, (int)= strlen(username));
- = hmac_ctx_update(ctx, b64decoded, TOKEN_DATA_LEN - 256/8);
+ hmac_ctx_update(ctx, (uint8_t *)= username, (int)strlen(username));
+ hmac_ctx_update(ctx, b64decoded, TOKEN_DATA_LEN - 256 / 8= );
hmac_ctx_final(ctx, hmac_output);
=
- const uint8_t *hm= ac =3D b64decoded + TOKEN_DATA_LEN - 256/8;
+ const uint8_t *hmac =3D b64decoded + TOKEN_DATA= _LEN - 256 / 8;
return memcmp_constant_time(&hmac_= output, hmac, 32) =3D=3D 0;
}

= unsigned int
-ve= rify_auth_token(struct user_pass *up, struct tls_multi *multi,
- struct tls_sessi= on *session)

+verify_= auth_token(struct user_pass *up, struct tls_multi *multi, struct tls_sessio= n *session)
{
/*
= * Base64 is <=3D input and input is < USER_PASS_LEN, so using USER_= PASS_LEN
@@ -300,8 +296,8 @@
*/
ASSERT(up && !up->protected);
= uint8_t b64decoded[USER_PASS_LEN];
- int decoded_len =3D openvpn_base64_decode(up->passwo= rd + strlen(SESSION_ID_PREFIX),
- b64decoded, USER_PASS= _LEN);
+ int decod= ed_len =3D
+ o= penvpn_base64_decode(up->password + strlen(SESSION_ID_PREFIX), b64decode= d, USER_PASS_LEN);

/*
* Ensure that the decoded data is the size of the

@= @ -309,8 +305,7 @@
*/
if (decode= d_len !=3D TOKEN_DATA_LEN)
{
- msg(M_WARN, "ERROR: --auth-token w= rong size (%d!=3D%d)",
- decoded_len, (int) TOKEN_DATA_LEN);
+ msg(M_WARN, "ERROR: --auth-t= oken wrong size (%d!=3D%d)", decoded_len, (int)TOKEN_DATA_LEN);=
return 0;
}

@@ -343,15 +338,14 @@
}
= else
{
- msg(M_WARN, "--auth-gen-token: HMAC on token from clie= nt failed (%s)",
-= up->username);
+ msg(M_WARN, "--auth-gen-token: HMAC on token from cl= ient failed (%s)", up->username);
return 0= ;
}

/* Accept s= ession tokens only if their timestamp is in the acceptable range
= * for renegotiations */
- bool in_renegotiation_time =3D now >=3D timestamp
- = && now < timestamp + 2 * session->opt->auth_token_r= enewal;
+ bool in_= renegotiation_time =3D
- msg(M_WA= RN, "Initial timestamp (%" PRIu64 ") in token from client ea= rlier than "
+ = msg(M_WARN,
+ = "Initial timestamp (%" PRIu64 ") in token from cli= ent earlier than "
"current timestam= p %" PRIu64 ". Broken/unsynchronised clock?",
timestamp_initial, timestamp);

ret = |=3D AUTH_TOKEN_EXPIRED;
}
- if (multi->opt.auth_toke= n_lifetime
- &am= p;& now > timestamp_initial + multi->opt.auth_token_lifetime)
+ if (multi->opt.a= uth_token_lifetime && now > timestamp_initial + multi->opt.au= th_token_lifetime)
{
ret |=3D= AUTH_TOKEN_EXPIRED;
}
@@ -391,7 +385,= 7 @@
strlen(SESSION_ID_PRE= FIX) + AUTH_TOKEN_SESSION_ID_BASE64_LEN))
{
= msg(M_WARN, "--auth-gen-token: session id in token chan= ged (Rejecting "
-= "token.");
+ "token.");
= ret =3D 0;
}
return ret;
@@ -409,8 +403,7 @@
}
= if (multi->auth_token_initial)
{
- secure_memzero(= multi->auth_token_initial,
- strlen(multi->auth_token_initial));
+ secure_me= mzero(multi->auth_token_initial, strlen(multi->auth_token_initial));<= /span>
free(multi->auth_token_initial);
= }
multi->auth_token =3D NULL;
@@ -438,7 +431,7 @@
if (!multi->auth_= token_initial)
{
msg(D_SHOW_K= EYS, "initial auth-token not generated yet, skipping "
= - "auth-token ren= ewal.");
+ = "auth-token renewal.");
= return;
}

diff --= git a/src/openvpn/auth_token.h b/src/openvpn/auth_token.h
i= ndex 5859905..f127127 100644
--- a/src/openvpn/auth_token.h=
+++ b/src/openvpn/auth_token.h
@@ -59,27 += 59,22 @@
* This function will free() an existing multi-&g= t;auth_token and keep the
* existing initial timestamp an= d session id contained in that token.
*/
-void
-generate_auth_token(const struct user_pass *up, struct = tls_multi *multi);
+v= oid generate_auth_token(const struct user_pass *up, struct tls_multi *multi= );

/**
* Verifies the = auth token to be in the format that generate_auth_token
*= create and checks if the token is valid.
*
*/

-unsigned
-verify_auth_token(struct us= er_pass *up, struct tls_multi *multi,
- struct tls_session *session);
<= span style=3D"color: hsl(0, 100%, 40%);">-

+unsigned verify_auth_token(struct user_pass *up, str= uct tls_multi *multi,
+ struct tls_session *session);
=

/**
* Loads an HMAC = secret from a file or if no file is present generates a
*= epheremal secret for the run time of the server and stores it into ctx
*/
-void=
-auth_token_init_secre= t(struct key_ctx *key_ctx, const char *key_file,
- bool key_inline);<= br>+void auth_token_init_secret= (struct key_ctx *key_ctx, const char *key_file, bool key_inline);

/**
@@ -126,8 += 121,7 @@
static inline bool
is_auth_token= (const char *password)
{
- return (memcmp_constant_time(SESSION_ID_PREFIX, pas= sword,
- = strlen(SESSION_ID_PREFIX)) =3D=3D 0);
+ return (memcmp_constant_time(SESSIO= N_ID_PREFIX, password, strlen(SESSION_ID_PREFIX)) =3D=3D 0);
}

/**
* Checks if a client should be = sent a new auth token to update its
@@ -135,15 +129,13 @@
* @param multi Pointer the multi object of the TLS ses= sion
* @param session Pointer to the TLS session itself=
*/
-= void
-resend_auth_token= _renegotiation(struct tls_multi *multi, struct tls_session *session);
+void resend_auth_token_re= negotiation(struct tls_multi *multi, struct tls_session *session);

/**
* Checks= if the timer to resend the auth-token has expired and if a new
<= span> * auth-token should be send to the client and triggers the resending=

*/
-= void
-check_send_auth_t= oken(struct context *c);
+void check_send_auth_token(struct context *c);

#endif /* AUTH_TOKEN_H */
diff --git a/src/open= vpn/base64.c b/src/openvpn/base64.c
index a9c2f4c..54d5b79 = 100644
--- a/src/openvpn/base64.c
+++ b/src= /openvpn/base64.c
@@ -41,8 +41,7 @@

#include "memdbg.h"

-static char base64_chars[] =3D
=
- "ABCDEFGHIJKLMNOPQR= STUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static char base64_chars[] =3D "ABCD= EFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";<= br> /*
* base64 encode input data of length size to= malloced
* buffer which is returned as *str. Returns st= ring
@@ -60,14 +59,14 @@
{
<= span> return -1;

}
- p =3D s =3D (char *) malloc(size * 4 / 3 + 4)= ;
+ p =3D s =3D (c= har *)malloc(size * 4 / 3 + 4);
if (p =3D=3D NULL)
{
return -1;
= }
- q =3D (const u= nsigned char *) data;
+ q =3D (const unsigned char *)data;
i =3D 0;
- for (i =3D 0; i < s= ize; )
+ for (i = =3D 0; i < size;)
{
c =3D = q[i++];
c *=3D 256;
@@ -196,5 +195= ,5 @@
*q++ =3D val & 0xff;
}

}
- return q - (unsigned char *) data;
+ return q - (unsigned char *)data;
}
diff --git a/src/openvpn/base64.h b/src/ope= nvpn/base64.h
index 7b4224a..be7aa64 100644
--- a/src/openvpn/base64.h

+++ b/src/openvpn/base64.h
@@ -35,12 +35,10 @@
#define _BASE64_H_<= br>
/** Compute resulting base64 length. 6 bits pe= r byte, padded to 4 bytes. */
-#define OPENVPN_BASE64_LENGTH(binary_length) \
- ((((8 * binary_length) / 6) + 3) &= ~3)
+#define OPENVPN= _BASE64_LENGTH(binary_length) ((((8 * binary_length) / 6) + 3) & ~3)

/** Compute the maximal number of bytes en= coded in a base64 string. */
-#define OPENVPN_BASE64_DECODED_LENGTH(base64_length) \
- ((base64_length / 4) * 3)
+#define OPENVPN_BASE64_DE= CODED_LENGTH(base64_length) ((base64_length / 4) * 3)

int openvpn_base64_encode(const void *data, int size, char **= str);

diff --git a/src/openvpn/basic.h b/= src/openvpn/basic.h
index f603ecc..0360803 100644--- a/src/openvpn/basic.h
+++ b/src/openvpn/basic.h<= /span>
@@ -27,7 +27,7 @@
#define BOOL_CAST(x) ((x= ) ? (true) : (false))

/* size of an arra= y */
-#define SIZE(x) (= sizeof(x)/sizeof(x[0]))
+#define SIZE(x) (sizeof(x) / sizeof(x[0]))

= /* clear an object (may be optimized away, use secure_memzero() to e= rase secrets) */
#define CLEAR(x) memset(&(x), 0, size= of(x))
diff --git a/src/openvpn/buffer.c b/src/openvpn/buff= er.c
index dd6044b..1a7e305 100644
--- a/sr= c/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -41,12 +41,14 @@

array_mult_safe(const size_t m1, co= nst size_t m2, const size_t extra)
{
= const size_t limit =3D 0xFFFFFFFF;
- unsigned long long res =3D (unsigned long long)m1 * (unsig= ned long long)m2 + (unsigned long long)extra;
- if (unlikely(m1 > limit) || unlikely(m2 >= limit) || unlikely(extra > limit) || unlikely(res > (unsigned long l= ong)limit))
+ unsi= gned long long res =3D
+ if = (unlikely(m1 > limit) || unlikely(m2 > limit) || unlikely(extra > = limit)
+ || un= likely(res > (unsigned long long)limit))
{ msg(M_FATAL, "attempted allocation of excessively lar= ge array");
}
- return (size_t) res;
+ return (size_t)res;
}
void
@@ -97,9 +99,9 @@
= buf.offset =3D 0;
buf.len =3D 0;
= #ifdef DMALLOC
-= buf.data =3D (uint8_t *) gc_malloc_debug(size, false, gc, file, line);<= /span>
+ buf.data =3D (ui= nt8_t *)gc_malloc_debug(size, false, gc, file, line);
#els= e
- buf.data =3D (ui= nt8_t *) gc_malloc(size, false, gc);
+ buf.data =3D (uint8_t *)gc_malloc(size, false, gc);
#endif
if (size)
{=
@@ -120,9 +122,9 @@
ret.offset =3D bu= f->offset;
ret.len =3D buf->len;
#ifdef DMALLOC

- r= et.data =3D (uint8_t *) openvpn_dmalloc(file, line, buf->capacity);
+ ret.data =3D (uint8_= t *)openvpn_dmalloc(file, line, buf->capacity);
#else
- ret.data =3D (uint8= _t *) malloc(buf->capacity);
+ ret.data =3D (uint8_t *)malloc(buf->capacity); #endif
check_malloc_return(ret.data); memcpy(BPTR(&ret), BPTR(buf), BLEN(buf));
= @@ -151,7 +153,7 @@
return buf->debug_file;<= br> }

-#else /* ifdef BUF_INIT_TRACKING */
+#else /* ifdef BUF_INIT_TRACKING */

#define buf_debug_line(buf) 0
#define= buf_debug_file(buf) "[UNDEF]"
@@ -253,7 +255,7 @= @
stat =3D vsnprintf((char *)ptr, cap, format,= arglist);
va_end(arglist);
= *(buf->data + buf->capacity - 1) =3D 0; /* windows vsnprin= tf needs this */
- = buf->len +=3D (int) strlen((char *)ptr);
+ buf->len +=3D (int)strlen((ch= ar *)ptr);
if (stat >=3D 0 && stat = < cap)
{
r= et =3D true;
@@ -273,7 +275,7 @@
{
strncpynt((char *)ptr, str, cap);
= *(buf->data + buf->capacity - 1) =3D 0; /* windows vsnprintf ne= eds this */
- bu= f->len +=3D (int) strlen((char *)ptr);
+ buf->len +=3D (int)strlen((char *)ptr);
ret =3D true;
}
return ret;

@@ -300,8 +302,7 @@
buff= er_write_file(const char *filename, const struct buffer *buf)
{

bool ret =3D false;
- int fd =3D platform_open(filename, O_CREAT | O= _TRUNC | O_WRONLY,
- = S_IRUSR | S_IWUSR);
+ int fd =3D platform_open(filename, O_CREAT | O_= TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
if (fd =3D=3D -1= )
{
msg(M_ERRNO, "Cannot= open file '%s' for write", filename);
@@ -341= ,12 +342,12 @@
{
struct gc_en= try *e;
#ifdef DMALLOC
- e =3D (struct gc_entry *) openvpn_dmalloc(file, l= ine, size + sizeof(struct gc_entry));
+ e =3D (struct gc_entry *)openvpn_dmalloc(file, li= ne, size + sizeof(struct gc_entry));
#else
- e =3D (struct gc_entry *) mal= loc(size + sizeof(struct gc_entry));

+ e =3D (struct gc_entry *)malloc(size + sizeof(stru= ct gc_entry));
#endif
check_mallo= c_return(e);
- r= et =3D (char *) e + sizeof(struct gc_entry);
+ ret =3D (char *)e + sizeof(struct gc_entry= );
e->next =3D a->list;
= a->list =3D e;
}
@@ -362,7 +36= 3,7 @@
#ifndef ZERO_BUFFER_ON_ALLOC
i= f (clear)
#endif
- memset(ret, 0, size);
+ memset(ret, 0, size);
return= ret;
}

@@ -440,9 +441,9= @@
ASSERT(a);
struct gc_entry_sp= ecial *e;
#ifdef DMALLOC
- e =3D (struct gc_entry_special *) openvpn_dmalloc(f= ile, line, sizeof(struct gc_entry_special));
+ e =3D (struct gc_entry_special *)openvpn_dmall= oc(file, line, sizeof(struct gc_entry_special));
#else
- e =3D (struct gc_entr= y_special *) malloc(sizeof(struct gc_entry_special));
+ e =3D (struct gc_entry_special *)mall= oc(sizeof(struct gc_entry_special));
#endif
check_malloc_return(e);

e->free_fnc =3D free= _function;
@@ -480,15 +481,15 @@
*/

char *
-format_hex_ex(const uint8_t *data, int size, int maxoutput,<= /span>
- unsigned= int space_break_flags, const char *separator,
- struct gc_arena *gc)
+format_hex_ex(const uint8_t *data, = int size, int maxoutput, unsigned int space_break_flags,

+ const char *separator, s= truct gc_arena *gc)
{
const size_t by= tes_per_hexblock =3D space_break_flags & FHE_SPACE_BREAK_MASK; const size_t separator_len =3D separator ? strlen(separator) := 0;
static_assert(INT_MAX <=3D SIZE_MAX, "Code= assumes INT_MAX <=3D SIZE_MAX");
- const size_t out_len =3D maxoutput > 0 ? maxoutp= ut :
- = ((size * 2) + ((size / bytes_per_hexblock) * separator_len) + 2);=
+ const size_t ou= t_len =3D maxoutput > 0
+ ? maxoutput
+ : ((size * 2) = + ((size / bytes_per_hexblock) * separator_len) + 2);

struct buffer out =3D alloc_buf_gc(out_len, gc); for (int i =3D 0; i < size; ++i)
@@ -532,13= +533,13 @@
void
buf_null_terminate(struc= t buffer *buf)
{
- char *last =3D (char *) BLAST(buf);
+ char *last =3D (char *)BLAST(buf);
if (last && *last =3D=3D '\0') /* alread= y terminated? */
{
return;
}

- if (!buf_safe(buf, 1)) /* make space for trailing nu= ll */
+ if (!buf_s= afe(buf, 1)) /* make space for trailing null */
{
buf_inc_len(buf, -1);
}@@ -555,12 +556,12 @@
{
while = (true)
{
- char *last =3D (char *) BLAST(buf);
+ char *last =3D (char *)BLAST(buf)= ;
if (!last)
{
= break;
}
- if (char_class(*last, CC_CRLF|CC_NU= LL))
+ if (cha= r_class(*last, CC_CRLF | CC_NULL))
{
if (!buf_inc_len(buf, -1))

{
@@ -657,9 +658,9 @@
if (gc)<= br> {
#ifdef DMALLOC
- ret =3D (char *) gc_malloc_debu= g(n, false, gc, file, line);
+ ret =3D (char *)gc_malloc_debug(n, false, gc, file, li= ne);
#else
- ret =3D (char *) gc_malloc(n, false, gc);
+ ret =3D (char *)gc_mall= oc(n, false, gc);

#endif
}=
else
@@ -718,7 +719,7 @@
{

struct buffer out =3D alloc_buf_gc(256, gc);
int i =3D 0;
- for (;; )
= + for (;;)
{
const char *c= p =3D *p++;
if (!cp)
@@ -757,9 +75= 8,9 @@
ASSERT(str);

= #ifdef DMALLOC
- bu= f_set_read(&buf, (uint8_t *) string_alloc_debug(str, gc, file, line), s= trlen(str) + 1);
+ = buf_set_read(&buf, (uint8_t *)string_alloc_debug(str, gc, file, line),= strlen(str) + 1);
#else
- buf_set_read(&buf, (uint8_t *) string_alloc(str= , gc), strlen(str) + 1);
+ buf_set_read(&buf, (uint8_t *)string_alloc(str, gc), strlen(st= r) + 1);
#endif

if = (buf.len > 0) /* Don't count trailing '\0' as part of length= */
@@ -846,10 +847,9 @@
break= ;
}
line[n++] =3D (char)c= ;
- }
- while (c);

+ } while (c);
=
- line[size-1] =3D '\0= ';
+ line[size= - 1] =3D '\0';
return !(eol && !strle= n(line));
}

@@ -1039,7 += 1039,8 @@
* Guaranteed to not increase string length.
*/
bool
-string_mod(char *str, const unsigned int inclusive, const= unsigned int exclusive, const char replace)
+string_mod(char *str, const unsigned int inclusive= , const unsigned int exclusive,
+ const char replace)
{
const char *in =3D str;

bool ret =3D true;
@@ -1088,11 +1089,8 @@
}

const char *
-string_mod_const(const char *str,
- const unsigned int inclusive,
= - const unsigned = int exclusive,
- = const char replace,
- struct gc_arena *gc)
+string_mod_const(const char *str, const unsigned = int inclusive, const unsigned int exclusive,
+ const char replace, struct gc_are= na *gc)
{
if (str)
= {
@@ -1131,23 +1129,16 @@
if (buf &= amp;& buf->len)
{
int = msglevel =3D D_ALIGN_DEBUG;
- const unsigned int u =3D (unsigned int) BPTR(buf);
= + const unsigned int u = =3D (unsigned int)BPTR(buf);

- if (u & (PAYLOAD_ALIGN-1))
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (u & (PAYLOAD_AL= IGN - 1))

{
msglevel = =3D D_ALIGN_ERRORS;
}

= msg(msglevel, "%sAlignment at %s/%d ptr=3D" ptr_fo= rmat " OLC=3D%d/%d/%d I=3D%s/%d",
- (msglevel =3D=3D D_ALIGN_ERRORS) ? "= ERROR: " : "",
- file,
- line,
-= (ptr_type)buf->data,
- buf->offset,
- buf->len,
- buf->capacity,
- buf_debug_file(buf),
= - buf_debug_line(buf))= ;
+ (msgle= vel =3D=3D D_ALIGN_ERRORS) ? "ERROR: " : "", file, line= , (ptr_type)buf->data,
+ buf->offset, buf->len, buf->capacity, buf_debug_= file(buf), buf_debug_line(buf));
}
}<= /span>
#endif /* ifdef VERIFY_ALIGNMENT */
@@ -12= 01,7 +1192,7 @@
if (str)
{=
const size_t len =3D strlen((const char *)str);- struct buffer_entry *e= =3D buffer_list_push_data(ol, str, len+1);
+ struct buffer_entry *e =3D buffer_list_push= _data(ol, str, len + 1);
if (e)
= {
e->buf.len =3D (int)len; /* Don= 9;t count trailing '\0' as part of length */
@@ -12= 50,8 +1241,7 @@
}

void<= /span>
-buffer_list_aggregate_= separator(struct buffer_list *bl, const size_t max_len,
- const cha= r *sep)
+buffer_list_= aggregate_separator(struct buffer_list *bl, const size_t max_len, const cha= r *sep)
{
const size_t sep_len =3D st= rlen(sep);
struct buffer_entry *more =3D bl->head;<= /span>
@@ -1340,7 +1330,7 @@

= if (fp)
{
- char *line =3D (char *) malloc(max_line_len);
= + char *line =3D (char *= )malloc(max_line_len);
if (line)
= {
bl =3D buffer_list_new();
= diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h
index 5f2ad5d..e512992 100644

--- a/src/openvpn/buffer.= h
+++ b/src/openvpn/buffer.h
@@ -59,13 +59,= 13 @@
*/
struct buffer
= {
- int capacity; = /**< Size in bytes of memory allocated by
- * \c = malloc(). */
- int o= ffset; /**< Offset in bytes of the actual content=
- = * within the allocated memory. */
- int len; /**< Length in bytes = of the actual content
-= * within the allocated memory. */=
- uint8_t *data; = /**< Pointer to the allocated memory. */
+ int capacity; /**< Size in bytes of mem= ory allocated by
+ = * \c malloc(). */
+ int offset; /**< Offset in bytes of the actual c= ontent
+ = * within the allocated memory. */
+ int len; /**< Length in bytes of the ac= tual content
+ = * within the allocated memory. */
+ uint8_t *data; /**< Pointer to the allo= cated memory. */

#ifdef BUF_INIT_TRACKIN= G
const char *debug_file;
@@ -86,8 +86= ,8 @@
*/
struct gc_entry
{

- struct gc_entr= y *next; /**< Pointer to the next item in the
- * linked= list. */
+ struct= gc_entry *next; /**< Pointer to the next item in the
+ * linked= list. */
};

/**=
@@ -115,8 +115,8 @@
*/
struct = gc_arena
{
- struct gc_entry *list; /**< First element of the linked l= ist of
- = * \c gc_entry structures. */
+ struct gc_entry *list; /**< First eleme= nt of the linked list of
+ * \c gc_entry structures. */
<= span> struct gc_entry_special *list_special;

};=

@@ -141,7 +141,7 @@
size_t array_mult_safe(const size_t m1, const size_t m2, const size= _t extra);

-#define PA_BRACKET (1<<0)
+#define PA_BRACKET (1 << 0)
char = *print_argv(const char **p, struct gc_arena *gc, const unsigned int flags);=

void buf_size_error(const size_t size);=
@@ -167,13 +167,15 @@

c= har *string_alloc_debug(const char *str, struct gc_arena *gc, const char *f= ile, int line);

-struct buffer string_alloc_buf_debug(const char *str, struct gc= _arena *gc, const char *file, int line);
+struct buffer string_alloc_buf_debug(const char *str, = struct gc_arena *gc, const char *file,
+ int line);
#else /* ifdef DMALLOC */

struct buffer alloc_buf(size_t size);

-struct buffer alloc_buf_gc(= size_t size, struct gc_arena *gc); /* allocate buffer with garbage collect= ion */
+struct buffer= alloc_buf_gc(size_t size,
+ struct gc_arena *gc); /* allocate buffer = with garbage collection */

struct buffer= clone_buf(const struct buffer *buf);

@@ = -198,8 +200,7 @@
* @param a gc_arena to use * @return new pointer
*/
-void *
-gc_realloc(void *ptr, size_t size, struct gc_arena *a);=
+void *gc_realloc(vo= id *ptr, size_t size, struct gc_arena *a);

#ifdef BUF_INIT_TRACKING

#define buf_init(buf, offset) = buf_init_debug(buf, offset, __FILE__, __LINE__)
@@ -214,14 = +215,14 @@
static inline void
gc_freeaddr= info_callback(void *addr)
{
- freeaddrinfo((struct addrinfo *) addr);+ freeaddrinfo((struct add= rinfo *)addr);
}

/** Re= turn an empty struct buffer */
static inline struct buffer=
clear_buf(void)
{
- return (struct buffer) { 0 };+ return (struct buffer){ 0= };
}

static inline boo= l
@@ -362,7 +363,7 @@
{
= if (maxlen > 0)
{
- strncpy(dest, src, maxlen-1);
+ strncpy(dest, src, maxlen = - 1);

dest[maxlen - 1] =3D 0;
= }
}
@@ -417,9 +418,9 @@
= SecureZeroMemory(data, len);
#elif defined(__GNUC__) |= | defined(__clang__)
memset(data, 0, len);
<= span style=3D"color: hsl(0, 100%, 40%);">- __asm__ __volatile__ ("&= quot; : : "r" (data) : "memory");

+ __asm__ __volatile__("" : := "r"(data) : "memory");
#else- volatile char *p =3D (vola= tile char *) data;
+ = volatile char *p =3D (volatile char *)data;
while (= len--)
{
*p++ =3D 0;@@ -436,12 +437,12 @@
bool buf_printf(struct buffe= r *buf, const char *format, ...)
#ifdef __GNUC__ #if __USE_MINGW_ANSI_STDIO
-__attribute__ ((format(gnu_printf, 2, 3)))
+ __attribute__((format(gnu_printf, 2= , 3)))
#else
-__attribute__ ((format(__printf__, 2, 3)))
+ __attribute__((format(__printf__, 2, 3))= )
#endif
#endif
-;
+ ;

/*
* p= uts append to a buffer with overflow check
@@ -494,12 +495,= 10 @@
/*
* Hex dump -- Output a binary b= uffer to a hex string and return it.
*/
-#define FHE_SPACE_BREAK_MASK 0xFF /* sp= ace_break parameter in lower 8 bits */
-#define FHE_CAPS 0x100 /* output hex in caps */=
-char *
-format_hex_ex(const uint8_t *data, i= nt size, int maxoutput,

- unsigned int space_break_flags, const char *separator,
- struct gc_ar= ena *gc);
+#define FH= E_SPACE_BREAK_MASK 0xFF /* space_break parameter in lower 8 bits */=
+#define FHE_CAPS = 0x100 /* output hex in caps */
+char *format_hex_ex(const uint8_t *data, int size, int maxout= put, unsigned int space_break_flags,
+ const char *separator, struct gc_arena= *gc);

static inline char *
format_hex(const uint8_t *data, int size, int maxoutput, struct gc_are= na *gc)

@@ -726,16 +725,10 @@
}
=
static inline bool
-buf_copy_range(struct buffer *dest,
- int dest_index,- const struct bu= ffer *src,
- = int src_index,
+b= uf_copy_range(struct buffer *dest, int dest_index, const struct buffer *src= , int src_index,
int src_len)
{

- if (src_inde= x < 0
- || sr= c_len < 0
- |= | src_index + src_len > src->len
- || dest_index < 0
+ if (src_index < 0 || src_len < 0 || src= _index + src_len > src->len || dest_index < 0
= || dest->offset + dest_index + src_len > dest->capacity)
{
return false;
@= @ -750,9 +743,7 @@

/* truncate src to le= n, copy excess data beyond len to dest */
static inline bo= ol
-buf_copy_excess(str= uct buffer *dest,
- = struct buffer *src,
- int len)
+buf_copy_excess(struct buffer *dest, struct buffer *src, int= len)
{
if (len < 0)
{

@@ -880,44 +871,44 @@
/* character classes */

-#define CC_ANY (1<<0) /**&= lt; any character */
-#= define CC_NULL (1<<1) /**< null character \0 */
+#define CC_ANY (1 <&= lt; 0) /**< any character */
+#define CC_NULL (1 << 1) /**< null= character \0 */

-#define CC_ALNUM (1<<2) /**< alphanumeri= c isalnum() */
-#define= CC_ALPHA (1<<3) /**< alphabetic isalpha() */<= br>-#define CC_ASCII = (1<<4) /**< ASCII character */
-#define CC_CNTRL (1<<5) /**< contr= ol character iscntrl() */
-#define CC_DIGIT (1<<6) /**< digit isdigit() */
-#define CC_PRINT = (1<<7) /**< printable (>=3D 32, !=3D 127) */
<= span style=3D"color: hsl(0, 100%, 40%);">-#define CC_PUNCT (1&= lt;<8) /**< punctuation ispunct() */

-#define CC_SPACE (1<<9) /**< whi= tespace isspace() */
-#= define CC_XDIGIT (1<<10) /**< hex digit isxdigit() */<= /span>
+#define CC_ALNUM (1= << 2) /**< alphanumeric isalnum() */
+#define CC_ALPHA (1 << 3) = /**< alphabetic isalpha() */
+#define CC_ASCII (1 << 4) /**< ASCII charact= er */
+#define CC_CNT= RL (1 << 5) /**< control character iscntrl() */+#define CC_DIGIT (1 <<= 6) /**< digit isdigit() */
+#define CC_PRINT (1 << 7) /**< printab= le (>=3D 32, !=3D 127) */
+#define CC_PUNCT (1 << 8) /**< punctuation ispun= ct() */
+#define CC_S= PACE (1 << 9) /**< whitespace isspace() */
+#define CC_XDIGIT (1 << 10) = /**< hex digit isxdigit() */


-#define CC_BLANK (1<<= 11) /**< space or tab */
-#define CC_NEWLINE (1<<12) /**< newline */=
-#define CC_CR = (1<<13) /**< carriage return */
+#define CC_BLANK (1 << 11) /**< spa= ce or tab */
+#define= CC_NEWLINE (1 << 12) /**< newline */
+#define CC_CR (1 << 13) = /**< carriage return */

-#define CC_BACKSLASH (1<<14) /**< = backslash */
-#define C= C_UNDERBAR (1<<15) /**< underscore */
-#define CC_DASH (1<<= 16) /**< dash */
-#d= efine CC_DOT (1<<17) /**< dot */
-#define CC_COMMA (1<<= 18) /**< comma */
-#= define CC_COLON (1<<19) /**< colon */
-#define CC_SLASH (1<&= lt;20) /**< slash */

-#define CC_SINGLE_QUOTE (1<<21) /**< single quote */
-#define CC_DOUBLE_QUOTE = (1<<22) /**< double quote */
-#define CC_REVERSE_QUOTE (1<<23) /**< reve= rse quote */
-#define C= C_AT (1<<24) /**< at sign */
-#define CC_EQUAL (1<<25)= /**< equal sign */
= -#define CC_LESS_THAN (1<<26) /**< less than sign */
-#define CC_GREATER_THAN = (1<<27) /**< greater than sign */
-#define CC_PIPE (1<<28) /**<= ; pipe */
-#define CC_Q= UESTION_MARK (1<<29) /**< question mark */
-#define CC_ASTERISK (1<<= 30) /**< asterisk */
+#define CC_BACKSLASH (1 << 14) /**< backslash */+#define CC_UNDERBAR (1 &= lt;< 15) /**< underscore */
+#define CC_DASH (1 << 16) /**< dash */
+#define CC_DOT = (1 << 17) /**< dot */
+#define CC_COMMA (1 << 18) /**< comma */
+#define CC_COLON = (1 << 19) /**< colon */
+#define CC_SLASH (1 << 20) /**< slash */
+#define CC_SINGLE_QUOTE = (1 << 21) /**< single quote */
+#define CC_DOUBLE_QUOTE (1 << 22) /**< doubl= e quote */
+#define C= C_REVERSE_QUOTE (1 << 23) /**< reverse quote */
+#define CC_AT (1 << 2= 4) /**< at sign */
+#define CC_EQUAL (1 << 25) /**< equal sign */
= +#define CC_LESS_THAN (1 &l= t;< 26) /**< less than sign */
+#define CC_GREATER_THAN (1 << 27) /**< greater t= han sign */
+#define = CC_PIPE (1 << 28) /**< pipe */
+#define CC_QUESTION_MARK (1 << 29) /**&l= t; question mark */
+= #define CC_ASTERISK (1 << 30) /**< asterisk */

/* macro classes */
-#define CC_NAME (CC_ALNUM|CC_UNDERBAR) /**= < alphanumeric plus underscore */
-#define CC_CRLF (CC_CR|CC_NEWLINE) /**< car= riage return or newline */
+#define CC_NAME (CC_ALNUM | CC_UNDERBAR) /**< alphanumeric plus u= nderscore */
+#define= CC_CRLF (CC_CR | CC_NEWLINE) /**< carriage return or newline */

bool char_class(const unsigned char c, cons= t unsigned int flags);

@@ -936,7 +927,8 @= @
* @param replace The character to replace the specified= character classes with.
* @return True if the string was= not modified, false otherwise.
*/
-bool string_mod(char *str, const unsigned i= nt inclusive, const unsigned int exclusive, const char replace);
= +bool string_mod(char *str, con= st unsigned int inclusive, const unsigned int exclusive,
+ const char replace);


/**
@@ = -947,8 +939,8 @@
* @param exclusive Character classes tha= t are not allowed even if they are also in inclusive.
* @= return True if the string consists only of allowed characters, false otherw= ise.
*/
-bool
-string_check_= buf(struct buffer *buf, const unsigned int inclusive, const unsigned int ex= clusive);
+bool strin= g_check_buf(struct buffer *buf, const unsigned int inclusive,
+ const unsig= ned int exclusive);


/**
= * Returns a copy of a string with certain classes of characters of it rep= laced with a specified
@@ -964,11 +956,8 @@
*

* @return The modified string with characters replac= ed within the specified range.
*/
-const char *string_mod_const(const char *st= r,
- = const unsigned int inclusive,
- const unsigned int exclusive= ,
- = const char replace,
- struct gc_arena *gc);
+const char *string_mod_const(const ch= ar *str, const unsigned int inclusive,
+ const unsigned int exclusiv= e, const char replace, struct gc_arena *gc);

void string_replace_leading(char *str, const char match, const char re= place);


@@ -1052,51 +1041,51 @@ * Allocate memory to hold a structure
*/<= br>
-#define ALL= OC_OBJ(dptr, type) \
- = { \
- check_m= alloc_return((dptr) =3D (type *) malloc(sizeof(type))); \
+#define ALLOC_OBJ(dptr, type) = \
+ { = \
+ chec= k_malloc_return((dptr) =3D (type *)malloc(sizeof(type))); \
}


-#define ALLOC_OBJ_CLEAR(dptr, type) \
- { \
- ALLOC_OBJ(dptr, type); \
+#define ALLOC_OBJ_CLEAR(dptr, type) \
+ { = \

+ AL= LOC_OBJ(dptr, type); \
memset((dptr), 0,= sizeof(type)); \
}

-#define ALLOC_ARRAY(dptr, type, n) \
- { \
- check_malloc_return((dptr) = =3D (type *) malloc(array_mult_safe(sizeof(type), (n), 0))); \

+#define ALLOC_ARRAY(dptr, type, = n) \

+ { = \

+ check_malloc_return((dpt= r) =3D (type *)malloc(array_mult_safe(sizeof(type), (n), 0))); \

= }

-#define ALLOC_ARRAY_GC(dptr, type, n, gc) \
- { \
- (dptr) =3D (type *) gc_malloc(array_mult_safe(siz= eof(type), (n), 0), false, (gc)); \
+#define ALLOC_ARRAY_GC(dptr, type, n, gc) = \
+ { = \
+ (dptr) =3D (type *)gc_malloc(array_mult_safe(sizeof(type), (n= ), 0), false, (gc)); \
}

<= span style=3D"color: hsl(0, 100%, 40%);">-#define ALLOC_ARRAY_CLEAR(dptr, t= ype, n) \

- { \
- ALLOC_ARRAY(dptr, = type, n); \
+#define = ALLOC_ARRAY_CLEAR(dptr, type, n) \
+ { = \

+ ALLOC_ARRAY(dptr, type, n); = \
memset((dptr), 0, (array_mult_safe(siz= eof(type), (n), 0))); \
}

= -#define ALLOC_ARRAY_CLEAR_GC(dpt= r, type, n, gc) \
- = { \
- (dptr) =3D= (type *) gc_malloc(array_mult_safe(sizeof(type), (n), 0), true, (gc)); \
+#define ALLOC_ARRAY_C= LEAR_GC(dptr, type, n, gc) \<= br>+ { = \
+ (dptr) =3D (type *)gc_mal= loc(array_mult_safe(sizeof(type), (n), 0), true, (gc)); \

= }

-#define ALLOC_VAR_ARRAY_CLEAR_GC(dptr, type, atype, n, gc) \<= br>- { \
- (dptr) =3D (type *) gc_malloc(array= _mult_safe(sizeof(atype), (n), sizeof(type)), true, (gc)); \
+#define ALLOC_VAR_ARRAY_CLEAR_GC(d= ptr, type, atype, n, gc) \
+ { = \
+ (dptr) =3D (ty= pe *)gc_malloc(array_mult_safe(sizeof(atype), (n), sizeof(type)), true, (gc= )); \
}

-#define ALLOC_OBJ_GC(dptr, type, gc) \
<= span style=3D"color: hsl(0, 100%, 40%);">- { \

- (dptr) =3D (type *) gc_malloc(sizeof(ty= pe), false, (gc)); \
= +#define ALLOC_OBJ_GC(dptr, type, gc) \+ { = \
+ (dptr) =3D (type *)gc_malloc(sizeof(type), false, (= gc)); \
}

-#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc) \
- { \
- (dptr) =3D (type *) gc_malloc(s= izeof(type), true, (gc)); \
+#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc) \
+ { = \
+ (dptr) =3D (type *)gc_malloc(sizeof(type), tru= e, (gc)); \
}

stati= c inline void
@@ -1121,8 +1110,8 @@
{
struct buffer_entry *head; /* next item to pop/peek */
struct buffer_entry *tail; /* last item pushed */<= br>- int size; = /* current number of entries */
- int max_size; /* maximum size list should grow to = */
+ int size; = /* current number of entries */
+ int max_size; /* maximum size li= st should grow to */
};

= /**
@@ -1210,8 +1199,7 @@
* @param max_l= en the maximum length of the aggregated buffer
* @param= sep the separator to put between buffers during aggregation */
-void buff= er_list_aggregate_separator(struct buffer_list *bl,
- const = size_t max_len, const char *sep);
+void buffer_list_aggregate_separator(struct buffer_list *bl, = const size_t max_len, const char *sep);

= struct buffer_list *buffer_list_file(const char *fn, int max_line_len);

diff --git a/src/openvpn/circ_list.h b/src/o= penvpn/circ_list.h
index 0189c8b..9b9a478 100644
= --- a/src/openvpn/circ_list.h
+++ b/src/openvpn/circ_= list.h
@@ -29,49 +29,46 @@
#include "= error.h"

#define CIRC_LIST(name, ty= pe) \
- struct name = { \
- int x_head= ; \
- int x_size= ; \
- int x_cap;= \
- int x_sizeo= f; \
- type x_li= st[]; \
+ struct n= ame \
+= { \
+ int x_head; \
+ int x_size; \
+ int x_cap; \<= br>+ int x_sizeof; = \
+ type x_= list[]; \
}

-#define CIRC_LIST_PUSH(obj, item) \
- { \
+#define CIRC_LIST_PUSH(obj, item) = \
+ { = \
(obj)->x_head =3D modulo_add((obj)-&g= t;x_head, -1, (obj)->x_cap); \
- (obj)->x_list[(obj)->x_head] =3D (item); \=
- (obj)->x_size =3D= min_int((obj)->x_size + 1, (obj)->x_cap); \
+ (obj)->x_list[(obj)->x_head] = =3D (item); \
+ (obj)->x_size =3D min_int((obj)->x_size + 1, = (obj)->x_cap); \
}

<= span style=3D"color: hsl(0, 100%, 40%);">-#define CIRC_LIST_SIZE(obj) \
- ((obj)->x_size)
+#define CIRC_LIST_SIZE= (obj) ((obj)->x_size)

-#define CIRC_LIST_INDEX(obj, index) \
- modulo_add((obj)->x_head, \
- index_veri= fy((index), (obj)->x_size, __FILE__, __LINE__), \
+#define CIRC_LIST_INDEX(obj, index) = \
+ modulo_add((obj)->x_head, index_verify(= (index), (obj)->x_size, __FILE__, __LINE__), \
= (obj)->x_cap)

-#define CIRC_LIST_ITEM(obj, index) \
- ((obj)->x_list[CIRC_LIST_INDEX((o= bj), (index))])
+#def= ine CIRC_LIST_ITEM(obj, index) ((obj)->x_list[CIRC_LIST_INDEX((obj), (in= dex))])

#define CIRC_LIST_RESET(obj) \
- { \
- (obj)->x_head =3D 0; \
- (obj)->x_size = =3D 0; \
+ { = \
+= (obj)->x_head =3D 0; \
+ (obj)->x_size =3D 0; \
}<= /span>

-#def= ine CIRC_LIST_ALLOC(dest, list_type, size) \
- { \
+#define CIRC_LIST_ALLOC(dest, list_type, size) = \
+ = { = \
const int so =3D sizeof(list_type) + sizeof((de= st)->x_list[0]) * (size); \
- (dest) =3D (list_type *) malloc(so); \
- check_malloc_return(dest); \
- memset((dest), 0, = so); \
- (dest)-= >x_cap =3D size; \
-= (dest)->x_sizeof =3D so; \
+ (dest) =3D (list_type *)malloc(so); = \
+ check_malloc_return(dest); = \
+ = memset((dest), 0, so); \
+ (dest)->x_c= ap =3D size; \
<= span style=3D"color: hsl(120, 100%, 40%);">+ (dest)->x_sizeof =3D= so; \

= }

-#= define CIRC_LIST_FREE(dest) \
- free(dest)
-add_entry(struct client_nat_o= ption_list *dest,
- = const struct client_nat_entry *e)
+add_entry(struct client_nat_option_list *dest, const st= ruct client_nat_entry *e)
{
if (dest-= >n >=3D MAX_CLIENT_NAT)
{
@@ -60= ,9 +59,7 @@
for (i =3D 0; i < list->n; ++i)<= /span>
{
const struct client= _nat_entry *e =3D &list->entries[i];
- msg(msglevel, " CNAT[%d] t=3D%d %s/= %s/%s",
- = i,
- = e->type,
+ = msg(msglevel, " CNAT[%d] t=3D%d %s/%s/%s", i, e->type= ,
print_in_addr_t(e->network, IA_NET_OR= DER, &gc),
print_in_addr_t(e->netma= sk, IA_NET_ORDER, &gc),
print_in_addr_= t(e->foreign_network, IA_NET_ORDER, &gc));
@@ -103,1= 1 +100,8 @@
}

void
-add_client_nat_to_option_l= ist(struct client_nat_option_list *dest,
- const char *type,- = const char *network,
- = const char *netmask,
- const char *forei= gn_network,
+add_clie= nt_nat_to_option_list(struct client_nat_option_list *dest, const char *type= ,
+ = const char *network, const char *netmask, const char *foreign_n= etwork,
int msglevel)=
{
struct client_nat_entry e;
@@ -180,9 +174,7 @@

dirstr =3D "IN";
}

- msg(msglevel, "** CNAT %s %s %s -> %s",<= /span>
- dirstr,=
- prefix,
+ msg(msglevel, "** CNAT = %s %s %s -> %s", dirstr, prefix,

print_in_= addr_t(iph->saddr, IA_NET_ORDER, &gc),
prin= t_in_addr_t(iph->daddr, IA_NET_ORDER, &gc));

@@ -190,11 +182,10 @@
}

void
-clien= t_nat_transform(const struct client_nat_option_list *list,
- struct buffer *ip= buf,
+client_nat_tran= sform(const struct client_nat_option_list *list, struct buffer *ipbuf,
const int direction)
{
- struct ip_tcp_udp_h= dr *h =3D (struct ip_tcp_udp_hdr *) BPTR(ipbuf);
+ struct ip_tcp_udp_hdr *h =3D (struct ip_tc= p_udp_hdr *)BPTR(ipbuf);
int i;
u= int32_t addr, *addr_ptr;
const uint32_t *from, *to;
diff --git a/src/openvpn/clinat.h b/src/openvpn/clinat.h
index 334b3f2..a9b42dd 100644
--- a/src/openvpn= /clinat.h
+++ b/src/openvpn/clinat.h
@@ -31= ,7 +31,8 @@
#define CN_OUTGOING 0
#define= CN_INCOMING 1

-struct client_nat_entry {
+struct client_nat_entry
+{
#define CN_SNAT 0
= #define CN_DNAT 1
int type;
@@ -40,28 = +41,27 @@
in_addr_t foreign_network;
= };

-s= truct client_nat_option_list {
+struct client_nat_option_list
+{
int n;
str= uct client_nat_entry entries[MAX_CLIENT_NAT];
};
struct client_nat_option_list *new_client_nat_lis= t(struct gc_arena *gc);

-struct client_nat_option_list *clone_client_nat_option_= list(const struct client_nat_option_list *src, struct gc_arena *gc);=
+struct client_nat_option_l= ist *clone_client_nat_option_list(
+ const struct client_nat_option_list *src, struct gc_aren= a *gc);

-void copy_client_nat_option_list(struct client_nat_option_list *dest, c= onst struct client_nat_option_list *src);
+void copy_client_nat_option_list(struct client_nat_op= tion_list *dest,
+ = const struct client_nat_option_list *src);

void print_client_nat_list(const struct cl= ient_nat_option_list *list, int msglevel);

-void add_client_nat_to_option_list(s= truct client_nat_option_list *dest,

- const char *type,- = const char *network,
- const char *netmask,
- co= nst char *foreign_network,

- int msglevel);
+void add_client_nat_to_option_list(struc= t client_nat_option_list *dest, const char *type,
+ const char= *network, const char *netmask,
+ const char *foreign_network,= int msglevel);

-void client_nat_transform(const struct client_nat_option_list *= list,
- = struct buffer *ipbuf,
+void client_nat_transform(const struct client_nat_option_list *= list, struct buffer *ipbuf,
cons= t int direction);

#endif /* if !defined(= CLINAT_H) */
diff --git a/src/openvpn/common.h b/src/openvp= n/common.h
index 5d4cf2e..645ebb9 100644
--= - a/src/openvpn/common.h
+++ b/src/openvpn/common.h<= br>@@ -28,7 +28,7 @@
* Statistics counters and asso= ciated printf format.
*/
typedef uint64_= t counter_type;
-#defin= e counter_format "%" PRIu64
+#define counter_format "%" PRIu64

/*
* Time intervals
@@ -38,17 +38,17 @@

/*
* Used as an up= per bound for timeouts.
*/
-#define BIG_TIMEOUT (60*60*24*7) /* one week (in s= econds) */
+#define B= IG_TIMEOUT (60 * 60 * 24 * 7) /* one week (in seconds) */
=
/*
* Printf formats for special types
*/
#ifdef _WIN64
-#define ptr_format "0x%016&q= uot; PRIx64
+#define = ptr_format "0x%016" PRIx64
#else
-#define ptr_format "= ;0x%08lx"

+#defi= ne ptr_format "0x%08lx"
#endif
-#define fragment_header_format "0= x%08x"
+#define = fragment_header_format "0x%08x"

/* these are used to cast the arguments

* and MUST matc= h the formats above */
@@ -95,6 +95,7 @@
/= *
* Script security warning
*/-#define SCRIPT_SECURITY_WARNIN= G "WARNING: External program may not be called unless '--script-se= curity 2' or higher is enabled. See --help text or man page for detaile= d info."
+#defin= e SCRIPT_SECURITY_WARNING \
+ "WARNING: External program may not be called unless '-= -script-security 2' or higher is enabled. See --help text or man page f= or detailed info."

#endif /* ifndef= COMMON_H */
diff --git a/src/openvpn/comp-lz4.c b/src/open= vpn/comp-lz4.c
index ab37164..57eb85a 100644
--- a/src/openvpn/comp-lz4.c

+++ b/src/openvpn/comp-lz4.c=
@@ -57,8 +57,7 @@

/* Do= esn't do any actual compression anymore */
static void=
-lz4_compress(struct b= uffer *buf, struct buffer work,
- struct compress_context *compctx,
+lz4_compress(struct buffer *buf, struc= t buffer work, struct compress_context *compctx,
= const struct frame *frame)
{
if (= buf->len <=3D 0)
@@ -79,8 +78,7 @@
<= /span>
/* Doesn't do any actual compression anymore */=
static void
= -lz4v2_compress(struct buffer *buf, struct buffer work,
- struct compress_context *c= ompctx,
+lz4v2_compre= ss(struct buffer *buf, struct buffer work, struct compress_context *compctx= ,
const struct frame *frame)
{

if (buf->len <=3D 0)
@@ -92= ,14 +90,13 @@
}

static = void
-do_lz4_decompress= (size_t zlen_max,
- = struct buffer *work,
- struct buffer *buf,
+do_lz4_decompress(size_t zlen_max, struct bu= ffer *work, struct buffer *buf,
struct c= ompress_context *compctx)
{
int uncom= p_len;
ASSERT(buf_safe(work, zlen_max));
- uncomp_len =3D LZ4_decompress_s= afe((const char *)BPTR(buf), (char *)BPTR(work), (size_t)BLEN(buf), zlen_ma= x);

+ uncomp_len = =3D LZ4_decompress_safe((const char *)BPTR(buf), (char *)BPTR(work), (size_= t)BLEN(buf),
+ = zlen_max);
if (uncomp_le= n <=3D 0)
{
dmsg(D_COMP_ER= RORS, "LZ4 decompression error: %d", uncomp_len);
@@ -118,12 +115,11 @@

}

static void

-lz4_deco= mpress(struct buffer *buf, struct buffer work,
- struct compress_context *compctx,
+lz4_decompress(struct= buffer *buf, struct buffer work, struct compress_context *compctx,<= br> const struct frame *frame)
{
size_t zlen_max =3D frame->buf.payload_size;
= - uint8_t c; /* flag = indicating whether or not our peer compressed */
+ uint8_t c; /* flag indicating whether or n= ot our peer compressed */

if (buf-&g= t;len <=3D 0)
{
@@ -156,12 +152,11 = @@
}

static void=
-lz4v2_decompress(struct buff= er *buf, struct buffer work,
- struct compress_context *compctx,
+lz4v2_decompress(struct buffer *buf, = struct buffer work, struct compress_context *compctx,
= const struct frame *frame)
{
= size_t zlen_max =3D frame->buf.payload_size;
- uint8_t c; /* flag indicating = whether or not our peer compressed */
+ uint8_t c; /* flag indicating whether or not our peer= compressed */

if (buf->len <= =3D 0)
{
@@ -204,19 +199,9 @@ }
}

-const struct compress_alg lz4_alg =3D {
- "lz4",
- lz4_compress_init,
- lz4_compress_uninit,<= /span>
- lz4_compress,
- lz4_decompress<= br>-};
+const struct compress_alg lz4_alg =3D { "= lz4", lz4_compress_init, lz4_compress_uninit, lz4_compress,
= + = lz4_decompress };

-const struct compress_alg lz4v2_alg =3D {
<= span style=3D"color: hsl(0, 100%, 40%);">- "lz4v2",

= - lz4v2_compress_init,<= br>- lz4_compress_uninit,
- lz4v2_compress,=
- lz4v2_decompress<= br>-};
+const struct compress_alg lz4v2_alg =3D { &quo= t;lz4v2", lz4v2_compress_init, lz4_compress_uninit,
+ = lz4v2_compress, lz4v2_decompress };
#endif /* ENABLE_LZ4= */
diff --git a/src/openvpn/comp.c b/src/openvpn/comp.c
index b2aa07e..82979a8 100644
--- a/src/openv= pn/comp.c
+++ b/src/openvpn/comp.c
@@ -172,= 10 +172,10 @@
{
#ifdef USE_COMP
msg(msglevel, "Compression or compression stub fra= ming is not allowed "
- "since data-channel offloading is enabled.");
+ = "since data-channel offloading is enabled.");
#e= lse
msg(msglevel, "Compression or compression= stub framing is not allowed "
- "since OpenVPN was built without compression= support.");
+ = "since OpenVPN was built without compression suppo= rt.");
#endif
return false;<= /span>
}
@@ -183,14 +183,14 @@
if ((info->flags & COMP_F_ALLOW_STUB_ONLY) && comp_no= n_stub_enabled(info))

{
msg(m= sglevel, "Compression is not allowed since allow-compression is "=
- "set= to 'stub-only'");
+ "set to 'stub-only'");<= /span>
return false;
}
#ifndef ENABLE_LZ4

if (info->alg =3D=3D COMP_AL= GV2_LZ4 || info->alg =3D=3D COMP_ALG_LZ4)
{<= br> msg(msglevel, "OpenVPN is compiled without LZ4 suppo= rt. Requested "
- = "compression cannot be enabled.");
+ "compression= cannot be enabled.");
return false; }
#endif
@@ -198,7 +198,7 @@<= /span>
if (info->alg =3D=3D COMP_ALG_LZO)
= {
msg(msglevel, "OpenVPN is compiled wit= hout LZO support. Requested "
- "compression cannot be enabled.");
+ &qu= ot;compression cannot be enabled.");
return f= alse;
}
#endif
diff -= -git a/src/openvpn/comp.h b/src/openvpn/comp.h
index 0bb0d3= 2..3ac2a3d 100644
--- a/src/openvpn/comp.h
= +++ b/src/openvpn/comp.h
@@ -34,21 +34,22 @@
/* Compression flags */

/* Removed
#d= efine COMP_F_ADAPTIVE (1<<0) / * COMP_ALG_LZO only * /
- #define COMP_F_ALLOW_CO= MPRESS (1<<1) / * not only incoming is compressed but also outg= oing * /
+ #define CO= MP_F_ALLOW_COMPRESS (1<<1) / * not only incoming is compressed = but also outgoing *
+= /
*/
/** initial command byte is swappe= d with last byte in buffer to preserve payload alignment */
-#define COMP_F_SWAP (= 1<<2)

+#define = COMP_F_SWAP (1 << 2)
/** tell server= that we only support compression stubs */
-#define COMP_F_ADVERTISE_STUBS_ONLY (1<<3)
+#define COMP_F_ADVERTISE_= STUBS_ONLY (1 << 3)
/** Only accept stub compression= , even with COMP_F_ADVERTISE_STUBS_ONLY
* we still accept= other compressions to be pushed */
-#define COMP_F_ALLOW_STUB_ONLY (1<<4)
+#define COMP_F_ALLOW_STUB_ONLY = (1 << 4)

/** push stub-v2 or comp-lzo no when we= see a client with comp-lzo in occ */
-#define COMP_F_MIGRATE (1<<5)
= +#define COMP_F_MIGRATE = (1 << 5)
/** Compression was explicitly set to= allow asymetric compression */
-#define COMP_F_ALLOW_ASYM (1<<6)
+#define COMP_F_ALLOW_ASYM = (1 << 6)
/** Do not allow compression framing (break= s DCO) */
-#define COMP= _F_ALLOW_NOCOMP_ONLY (1<<7)
+#define COMP_F_ALLOW_NOCOMP_ONLY (1 << 7)<= br>
/* algorithms */
#define COMP_= ALG_UNDEF 0
@@ -61,7 +62,7 @@

= /* algorithm v2 */
#define COMP_ALGV2_UNCOMPRESSED = 10
-#define COMP_ALGV2_= LZ4 11
+#define = COMP_ALGV2_LZ4 11
/*
#define CO= MP_ALGV2_LZO 12
#define COMP_ALGV2_SNAPPY 13=
@@ -80,8 +81,7 @@
static inline bool
<= span> comp_non_stub_enabled(const struct compress_options *info)

= {
- return in= fo->alg !=3D COMP_ALGV2_UNCOMPRESSED
- && info->alg !=3D COMP_ALG_STUB
+ return info->alg= !=3D COMP_ALGV2_UNCOMPRESSED && info->alg !=3D COMP_ALG_STUB
&& info->alg !=3D COMP_ALG_UNDEF;
}

@@ -90,8 +90,7 @@ * flags of allow-compression and also the whether algorithms are = compiled
* in
*/
-bool
-check_compression_settings_valid(struct compress_options *in= fo, int msglevel);
+b= ool check_compression_settings_valid(struct compress_options *info, int msg= level);

#ifdef USE_COMP
= #include "buffer.h"
@@ -110,18 +109,18 @@=

/* V1 on wire codes */
/* Ini= tial command byte to tell our peer if we compressed */
-#define LZO_COMPRESS_BYTE 0x66
<= span style=3D"color: hsl(0, 100%, 40%);">-#define LZ4_COMPRESS_BYTE 0x69
+#define LZO_COMPRESS_B= YTE 0x66
+#define= LZ4_COMPRESS_BYTE 0x69
#define NO_COMPRESS_BYTE = 0xFA
/** to maintain payload alignment, replace this byte = with last byte of packet */
#define NO_COMPRESS_BYTE_SWAP = 0xFB

/* V2 on wire code */
-#define COMP_ALGV2_INDICATOR_BYTE = 0x50

-#define COMP= _ALGV2_UNCOMPRESSED_BYTE 0
-#define COMP_ALGV2_LZ4_BYTE 1
-#define COMP_ALGV2_LZO_BYTE 2
-#define COMP_ALGV2_SNAPPY_B= YTE 3
+#defi= ne COMP_ALGV2_INDICATOR_BYTE 0x50
+#define COMP_ALGV2_UNCOMPRESSED_BYTE 0
+#define COMP_ALGV2_LZ4_BYTE 1<= /span>
+#define COMP_ALGV2_L= ZO_BYTE 2
+#= define COMP_ALGV2_SNAPPY_BYTE 3

/*=
* Compress worst case size expansion (for any algorithm)=
@@ -130,7 +129,7 @@
* Snappy: len + len/= 6 + 32
* LZ4: len + len/255 + 16 (LZ4_COMPRESSBOUND(l= en))
*/
-#define COMP_EXTRA_BUFFER(len) ((len)/6 + 128 + 3 + COMP_PREFIX_LEN)
+#define COMP_EXTRA_BUF= FER(len) ((len) / 6 + 128 + 3 + COMP_PREFIX_LEN)
/*
* Don't try to compress any packet smalle= r than this.
@@ -148,12 +147,10 @@
con= st char *name;
void (*compress_init)(struct compress_c= ontext *compctx);
void (*compress_uninit)(struct compr= ess_context *compctx);
= - void (*compress)(struct buffer *buf, struct buffer work,
- struct compres= s_context *compctx,

+= void (*compress)(struct buffer *buf, struct buffer work, struct compres= s_context *compctx,
const struct fram= e *frame);

- void (*decompress)(struct buffer *buf, struct buffer work,
- stru= ct compress_context *compctx,
+ void (*decompress)(struct buffer *buf, struct buffer work, st= ruct compress_context *compctx,
con= st struct frame *frame);
};

diff --git a/src/openvpn/compstub.c b/src/openvpn/compstub.c

= index 109d691..0d6e0e0 100644
--- a/src/openvpn/comps= tub.c
+++ b/src/openvpn/compstub.c
@@ -46,8= +46,7 @@
}

static void=
-stub_compress(struct = buffer *buf, struct buffer work,
- struct compress_context *compctx,
+stub_compress(struct buffer *buf, st= ruct buffer work, struct compress_context *compctx,
= const struct frame *frame)
{
= if (buf->len <=3D 0)
@@ -57,7 +56,7 @@
if (compctx->flags & COMP_F_SWAP)

{
uint8_t *head =3D BPTR(buf);
- uint8_t *tail =3D BEND(buf);+ uint8_t *tail =3D BEN= D(buf);
ASSERT(buf_safe(buf, 1));
= ++buf->len;

@@ -73,8 +72,7 @@=
}

static void-stub_decompress(struct buffer = *buf, struct buffer work,
- struct compress_context *compctx,
+stub_decompress(struct buffer *buf, struc= t buffer work, struct compress_context *compctx,
= const struct frame *frame)
{
u= int8_t c;
@@ -108,8 +106,7 @@

<= span>

static void
-stubv2_compress(struct buffer *buf, struct buffer work,
- struct comp= ress_context *compctx,
-= stubv2_decompress(struct buffer *buf, struct buffer work,
- struct compress_conte= xt *compctx,
+stubv2_= decompress(struct buffer *buf, struct buffer work, struct compress_context = *compctx,
const struct frame *frame)
{
if (buf->len <=3D 0)
<= span>@@ -158,19 +154,9 @@

}
}<= br>
-const struc= t compress_alg compv2_stub_alg =3D {
- "stubv2",
- stub_compress_init,
- stub_compress_uninit,
- stubv2_compress,
- stubv2_decompress
-};
+const struct compress_alg compv2_stub_alg =3D { "stubv2", st= ub_compress_init, stub_compress_uninit,
+ stubv2_co= mpress, stubv2_decompress };

-const struct compress_alg comp_stub_alg =3D {
- "stub",
- stub_compress_init,
- stub_compress_uninit= ,
- stub_compress,
- stub_decompress
-};
+const struct compress_alg comp_stub_alg = =3D { "stub", stub_compress_init, stub_compress_uninit,+ = stub_compress, stub_decompress };
#endif /*= USE_STUB */
diff --git a/src/openvpn/console.c b/src/openv= pn/console.c
index 617e146..deb280e 100644
= --- a/src/openvpn/console.c
+++ b/src/openvpn/console.c
@@ -38,7 +38,7 @@
#endif


-struct= _query_user query_user[QUERY_USER_NUMSLOTS]; /* GLOBAL */
+struct _query_user query_user[QUERY= _USER_NUMSLOTS]; /* GLOBAL */


void
@@ -54,16 +54,14 @@

void
-query_user_add(char *prompt, size_t prompt_len,
- char *resp, size_t resp_= len,
- bo= ol echo)
+query_user_= add(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo= )
{
int i;
/* Ensure input is sane. All these must be present otherwise = it is
* a programming error.
*/=
- ASSERT( prompt_le= n > 0 && prompt !=3D NULL && resp_len > 0 && = resp !=3D NULL );
+ = ASSERT(prompt_len > 0 && prompt !=3D NULL && resp_len = > 0 && resp !=3D NULL);

/= * Seek to the last unused slot */
for (i =3D 0; i <= QUERY_USER_NUMSLOTS; i++)
@@ -73,7 +71,7 @@
break;

}
}
- ASSERT( i < QUERY_= USER_NUMSLOTS ); /* Unlikely, but we want to panic if it happens */=
+ ASSERT(i < QUERY_US= ER_NUMSLOTS); /* Unlikely, but we want to panic if it happens */
=
/* Save the information needed for the user in= teraction */
query_user[i].prompt =3D prompt;diff --git a/src/openvpn/console.h b/src/openvpn/console.hindex 589f778..e2dddec 100644
--- a/src/openvpn/con= sole.h
+++ b/src/openvpn/console.h
@@ -31,1= 6 +31,17 @@
/**
* Configuration setup f= or declaring what kind of information to ask a user for
*= /
-struct _query_user {=
- char *prompt; = /**< Prompt to present to the user */
- size_t prompt_len; /**< Length of= the prompt string */
-= char *response; /**< The user's response */
= - size_t response_len; /*= *< Length the of the user response */
- bool echo; /**< True: The user sho= uld see what is being typed, otherwise mask it */
+struct _query_user
+{
+ char *prompt; /**< Prompt to present to the user *= /
+ size_t prompt_= len; /**< Length of the prompt string */
+ char *response; /**< The user's r= esponse */
+ size_= t response_len; /**< Length the of the user response */
+ bool echo; /**< Tru= e: The user should see what is being typed, otherwise mask it */
= };

#define QUERY_USER_NUMSLOTS 10=
-extern struct _query_= user query_user[]; /**< Global variable, declared in console.c */
+extern struct _query_user= query_user[]; /**< Global variable, declared in console.c */
=
/**
* Wipes all data put into al= l of the query_user structs
@@ -59,9 +60,7 @@
* @param echo Should the user input be echoed to the user? If F= alse, input will be masked

*
*/<= br>-void query_user_add(char *pro= mpt, size_t prompt_len,
- char *resp, size_t resp_len,
- bool echo);
+void query_user_add(char *prompt, = size_t prompt_len, char *resp, size_t resp_len, bool echo);



/**
@@ -108,7 +107,7 = @@
{
return query_user_exec_builtin()= ;
}
-#= endif /* defined(ENABLE_SYSTEMD) */
+#endif /* defined(ENABLE_SYSTEMD) */


/**
@@ -119,9 +118,7 @@
*
*/
static inline bool
-query_user_SINGLE(char = *prompt, size_t prompt_len,
- char *resp, size_t resp_len,
- bool echo)
+query_user_SINGLE(char *prompt, si= ze_t prompt_len, char *resp, size_t resp_len, bool echo)

{=
query_user_clear();
query_user_a= dd(prompt, prompt_len, resp, resp_len, echo);
diff --git a/= src/openvpn/console_builtin.c b/src/openvpn/console_builtin.c
index ba61d3f..a0984bf 100644

--- a/src/openvpn/console_= builtin.c
+++ b/src/openvpn/console_builtin.c
@@ -68,11 +68,10 @@


HANDLE in =3D= GetStdHandle(STD_INPUT_HANDLE);
int orig_stderr =3D g= et_orig_stderr(); /* guaranteed to be always valid */
- if ((in =3D=3D INVALID_HANDLE_VALUE)
- || win32_service= _interrupt(&win32_signal)
+ if ((in =3D=3D INVALID_HANDLE_VALUE) || win32_service_interru= pt(&win32_signal)
|| (_write(orig_stderr, prom= pt, strlen(prompt)) =3D=3D -1))
{
- msg(M_WARN|M_ERRNO, "get_cons= ole_input_win32(): unexpected error");
+ msg(M_WARN | M_ERRNO, "get_console_inp= ut_win32(): unexpected error");
return false;=
}

@@ -136,7 +135,7 = @@
return false;
}
<= /span>
-#endif /* _WIN32 */<= /span>
+#endif /* _WIN32 */<= /span>


#ifdef HAVE_TERMIOS_H<= /span>
@@ -178,7 +177,7 @@
}
= }

-#= endif /* HAVE_TERMIOS_H */
+#endif /* HAVE_TERMIOS_H */


/**
@@ -210,15 +209,17 @@
= * (in which case neither stdin or stderr are connected to a tty and
* /dev/tty can not be open()ed anymore)
= */
- if (!isat= ty(0) && !isatty(2) )
+ if (!isatty(0) && !isatty(2))
{<= /span>
- int fd =3D ope= n( "/dev/tty", O_RDWR );
+ int fd =3D open("/dev/tty", O_RDWR);
if (fd < 0)
{
- msg(M_FATAL, "neit= her stdin nor stderr are a tty device and you have neither a "
<= br>+ msg(M_FATAL,
+ "= neither stdin nor stderr are a tty device and you have neither a "
"controlling tty nor systemd - can't= ask for '%s'. If you used --daemon, "
= "you need to use --askpass to make passphrase-protected key= s work, and you "
= - "can not use --auth-nocache.", prompt );<= br>+ "can n= ot use --auth-nocache.",
+ prompt);
}
close(fd);

}
@@ -286,8 +28= 7,8 @@
/* Loop through configured query_user slots */<= /span>
for (i =3D 0; i < QUERY_USER_NUMSLOTS && qu= ery_user[i].response !=3D NULL; i++)
{
- if (!get_console_input(query_= user[i].prompt, query_user[i].echo,

- query_user[i].response, query_= user[i].response_len) )
+ if (!get_console_input(query_user[i].prompt, query_user[i].echo= , query_user[i].response,
+ query_user[i].response_len)) {
/* Force the final result st= ate to failed on failure */
ret =3D false;
diff --git a/src/openvpn/console_systemd.c b/src/openvpn/conso= le_systemd.c
index 91ebb35..af67b15 100644
= --- a/src/openvpn/console_systemd.c
+++ b/src/openvpn/conso= le_systemd.c
@@ -51,9 +51,7 @@
* moun= ted, as well as the systemd-ask-password executable
*= being available */

- return (sd_booted() > 0)
- && (stat(SYSTEMD_ASK_PASSWORD_= PATH, &c) =3D=3D 0);
+ return (sd_b= ooted() > 0) && (stat(SYSTEMD_ASK_PASSWORD_PATH, &c) =3D=3D = 0);
}

static bool
@@ -80,7 +78,7 @@
return false;<= br> }
memset(input, 0, capacity);
= - if (read(std_out, input, cap= acity-1) !=3D 0)
+ = if (read(std_out, input, capacity - 1) !=3D 0)
{
chomp(input);
ret =3D true;
@@ -100,7 +98,7 @@
bool
qu= ery_user_exec_systemd(void)
{
- bool ret =3D true; /* Presume everything goes= okay */
+ bool re= t =3D true; /* Presume everything goes okay */
int i;<= /span>

/* If systemd is not available, use = the default built-in mechanism */
@@ -113,7 +111,7 @@
for (i =3D 0; i < QUERY_USER_NUMSLOTS && query_u= ser[i].response !=3D NULL; i++)
{
= if (!get_console_input_systemd(query_user[i].prompt, query_user[i].ech= o,
- = query_user[i].response, query_user[i].response_len) )
+ = query_user[i].response, query_user[i].response_len))
{
/* Force the final resu= lt state to failed on failure */
ret =3D false= ;
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c<= /span>
index 7564f82..3bac0d1 100644
--- a/src/ope= nvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@= -64,8 +64,7 @@
*/

sta= tic void
-openvpn_encry= pt_aead(struct buffer *buf, struct buffer work,
- struct crypto_options *opt)<= /span>
+openvpn_encrypt_aead= (struct buffer *buf, struct buffer work, struct crypto_options *opt)=
{
struct gc_arena gc;
= int outlen =3D 0;
@@ -89,7 +88,7 @@
/*= Prepare IV */
{
struct buffe= r iv_buffer;
- u= int8_t iv[OPENVPN_MAX_IV_LENGTH] =3D {0};
+ uint8_t iv[OPENVPN_MAX_IV_LENGTH] =3D { 0 };<= /span>
const int iv_len =3D cipher_ctx_iv_length(ctx->= cipher);

ASSERT(iv_len >=3D O= PENVPN_AEAD_MIN_IV_LEN && iv_len <=3D OPENVPN_MAX_IV_LENGTH);
@@ -134,17 +133,14 @@
/* Buffer overflow= check */
if (!buf_safe(&work, buf->len + mac_l= en + cipher_ctx_block_size(ctx->cipher)))
{<= br>- msg(D_CRYPT_ERRORS,
- "ENCRY= PT: buffer size error, bc=3D%d bo=3D%d bl=3D%d wc=3D%d wo=3D%d wl=3D%d"= ;,
- buf->= ;capacity, buf->offset, buf->len, work.capacity, work.offset,<= br>- work.len);=
+ msg(D_CRYPT_ERRORS= , "ENCRYPT: buffer size error, bc=3D%d bo=3D%d bl=3D%d wc=3D%d wo=3D%d= wl=3D%d",
+ = buf->capacity, buf->offset, buf->len, work.capacity, work.= offset, work.len);
goto err;
= }

/* For AEAD ciphers, authenticate = Additional Data, including opcode */
ASSERT(cipher_ctx= _update_ad(ctx->cipher, BPTR(&work), BLEN(&work)));
- dmsg(D_PACKET_CONTENT, "E= NCRYPT AD: %s",

- = format_hex(BPTR(&work), BLEN(&work), 0, &gc));+ dmsg(D_PACKET_CONTENT, &= quot;ENCRYPT AD: %s", format_hex(BPTR(&work), BLEN(&work), 0, = &gc));

if (!use_epoch_data_forma= t)
{
@@ -160,7 +156,7 @@
/* update number of plaintext blocks encrypted. Use the (x + (n-1))= /n trick

* to round up the result to the number of bl= ocks used */
const int blocksize =3D AEAD_LIMIT_BLOCKS= IZE;
- opt->key_c= tx_bi.encrypt.plaintext_blocks +=3D (outlen + (blocksize - 1))/blocksize;
+ opt->key_ctx_b= i.encrypt.plaintext_blocks +=3D (outlen + (blocksize - 1)) / blocksize;

/* Flush the encryption buffer */
ASSERT(cipher_ctx_final(ctx->cipher, BEND(&work), &a= mp;outlen));
@@ -192,8 +188,7 @@
}<= br>
static void
-openvpn_encrypt_v1(struct buffer *buf, struct buffer work= ,
- s= truct crypto_options *opt)
+openvpn_encrypt_v1(struct buffer *buf, struct buffer work, struct cr= ypto_options *opt)
{
struct gc_arena = gc;
gc_init(&gc);
@@ -207,7 +202,7= @@
/* Do Encrypt from buf -> work */ if (ctx->cipher)
{
- uint8_t iv_buf[OPENVPN= _MAX_IV_LENGTH] =3D {0};

+ uint8_t iv_buf[OPENVPN_MAX_IV_LENGTH] =3D { 0 }; const int iv_size =3D cipher_ctx_iv_length(ctx->ciph= er);
int outlen;

<= span>@@ -227,8 +222,7 @@

/* Put packet ID = in plaintext buffer */
if (packet_id_initi= alized(&opt->packet_id)
&&a= mp; !packet_id_write(&opt->packet_id.send, buf,
- op= t->flags & CO_PACKET_ID_LONG_FORM,
- true))+ = opt->flags & CO_PACKET_ID_LONG_FORM, true))
{

msg(D_CRYPT_ERR= ORS, "ENCRYPT ERROR: packet ID roll over");
= goto err;
@@ -253,8 +247,7 @@
ASSERT(buf_write(&work, iv_buf, iv_size));

dmsg(D_PACKET_CONTENT, "ENCRYPT IV: %s", format_= hex(iv_buf, iv_size, 0, &gc));


- dmsg(D_PACKET_CONTENT, "EN= CRYPT FROM: %s",
-= format_hex(BPTR(buf), BLEN(buf), 80, &gc));
= + dmsg(D_PACKET_CONT= ENT, "ENCRYPT FROM: %s", format_hex(BPTR(buf), BLEN(buf), 80, &am= p;gc));

/* cipher_ctx was al= ready initialized with key & keylen */
ASS= ERT(cipher_ctx_reset(ctx->cipher, iv_buf));
@@ -262,13 += 255,9 @@
/* Buffer overflow check */ if (!buf_safe(&work, buf->len + cipher_ctx_block= _size(ctx->cipher)))
{
- msg(D_CRYPT_ERRORS, "= ENCRYPT: buffer size error, bc=3D%d bo=3D%d bl=3D%d wc=3D%d wo=3D%d wl=3D%d= cbs=3D%d",
- = buf->capacity,
- buf->offset,
- buf->len,
- work.capacity,
- work.o= ffset,
- = work.len,
+ = msg(D_CRYPT_ERRORS,
+ "ENCRYPT: buffer size error, bc=3D%d bo= =3D%d bl=3D%d wc=3D%d wo=3D%d wl=3D%d cbs=3D%d",
+ buf->capacity, buf= ->offset, buf->len, work.capacity, work.offset, work.len,
<= span> cipher_ctx_block_size(ctx->cipher));
goto err;
}
= @@ -282,14 +271,13 @@
ASSERT(buf_inc_len= (&work, outlen));

/* For= all CBC mode ciphers, check the last block is complete */
- ASSERT(cipher_ctx_mode(ctx= ->cipher) !=3D OPENVPN_MODE_CBC
- || outlen =3D=3D iv_size);
+ ASSERT(cipher_ctx_mode(c= tx->cipher) !=3D OPENVPN_MODE_CBC || outlen =3D=3D iv_size);
<= span> }

- = else /* No Encryption */
+ else /* No Encryption */ {
if (packet_id_initialized(&= amp;opt->packet_id)
= - && !packet_id_write(&opt->packet_id.send, b= uf,
- = opt->flags & CO_PACKET_ID_LONG_FORM, true))=
+ &&= !packet_id_write(&opt->packet_id.send, buf, opt->flags & CO_= PACKET_ID_LONG_FORM,
= + true))
{<= /span>
msg(D_CRYPT_ERRORS, "ENCRYPT ERROR: p= acket ID roll over");
goto err;
@@ -318,8 +306,7 @@

*= buf =3D work;

- dmsg(D_PACKET_CONTENT, "ENCRYPT TO: %s",=
- format_hex(BPTR= (&work), BLEN(&work), 80, &gc));
+ dmsg(D_PACKET_CONTENT, "ENCRYPT TO: %= s", format_hex(BPTR(&work), BLEN(&work), 80, &gc));=
}

gc_free(&gc);
@@ -333,8 +320,7 @@
}

void
-ope= nvpn_encrypt(struct buffer *buf, struct buffer work,
- struct crypto_options *opt)=
+openvpn_encrypt(str= uct buffer *buf, struct buffer work, struct crypto_options *opt)
= {
if (buf->len > 0 && opt)=
{
@@ -381,10 +367,8 @@
}

bool
-crypto_check_replay(struct crypto_options *opt,
<= span style=3D"color: hsl(0, 100%, 40%);">- const struct = packet_id_net *pin, uint16_t epoch,

- const char *error_prefix,
- struct gc_arena *= gc)

+crypto_check_rep= lay(struct crypto_options *opt, const struct packet_id_net *pin, uint16_t e= poch,
+ = const char *error_prefix, struct gc_arena *gc)
{
bool ret =3D false;
struct packet_id= _rec *recv;
@@ -401,8 +385,10 @@
{
/* We have an epoch that is neither current or old re= cv key but
* is authenticated, ie we need to move= to a new current recv key */
- msg(D_GENKEY, "Received data packet with new epoch %d.= Updating "
- = "receive key", epoch);
+ msg(D_GENKEY,
+ "Received data packet with new epoch= %d. Updating "
= + "receive key",
+ epoch);
epoch_replac= e_update_recv_key(opt, epoch);
recv =3D &opt-&= gt;packet_id.rec;
}
@@ -421,7 +407,8 @= @
{
if (!(opt->flags &= CO_MUTE_REPLAY_WARNINGS))
{
- msg(D_REPLAY_ERRORS, "%s: = bad packet ID (may be a replay): %s -- "
+ msg(D_REPLAY_ERRORS,
+ "%s: bad packet= ID (may be a replay): %s -- "
"= see the man page entry for --replay-window for "
= "more info or silence this warning with --mute-replay-warn= ings",
error_prefix, packet_id_net_pr= int(pin, true, gc));
@@ -439,9 +426,8 @@
= * On success, buf is set to point to plaintext, true is returned. */
static bool
-openvpn_decrypt_aead(struct buffer *buf, struct buffer w= ork,
- = struct crypto_options *opt, const struct frame *frame,
- const uint8_t *ad= _start)
+openvpn_decr= ypt_aead(struct buffer *buf, struct buffer work, struct crypto_options *opt= ,
+ = const struct frame *frame, const uint8_t *ad_start)
{
static const char error_prefix[] =3D "AEAD Decrypt= error";
struct packet_id_net pin =3D { 0 };
@@ -463,8 +449,7 @@
ASSERT(buf->len >= ; 0);
ASSERT(ctx->cipher);
=
- dmsg(D_PACKET_CONTENT, &= quot;DECRYPT FROM: %s",
- format_hex(BPTR(buf), BLEN(buf), 80, &gc));
<= span style=3D"color: hsl(120, 100%, 40%);">+ dmsg(D_PACKET_CONTENT, &quo= t;DECRYPT FROM: %s", format_hex(BPTR(buf), BLEN(buf), 80, &gc));

ASSERT(ad_start >=3D buf->data = && ad_start <=3D BPTR(buf));

@= @ -572,28 +557,24 @@

/* feed in tag = and the authenticated data */
ASSERT(cipher_ctx_update= _ad(ctx->cipher, ad_start, ad_size));
- dmsg(D_PACKET_CONTENT, "DECRYPT AD: %s",
- format_hex(ad_= start, ad_size, 0, &gc));
+ dmsg(D_PACKET_CONTENT, "DECRYPT AD: %s", format_hex= (ad_start, ad_size, 0, &gc));

/*= Decrypt and authenticate packet */
int outlen;=
- if (!cipher_ctx_update(c= tx->cipher, BPTR(&work), &outlen, BPTR(buf),
- data_len))
+ if (!cipher_ctx_upd= ate(ctx->cipher, BPTR(&work), &outlen, BPTR(buf), data_len))
{
CRYPT_ERROR("packet decry= ption failed");
}

ASSERT(buf_inc_len(&work, outlen));

- if (!cipher_ctx_final_check_tag(ctx->ciphe= r, BPTR(&work) + outlen,
- &outlen, tag_ptr, tag_size))=
+ if (!cipher_ctx= _final_check_tag(ctx->cipher, BPTR(&work) + outlen, &outlen, tag= _ptr, tag_size))
{
ctx->fa= iled_verifications++;
CRYPT_DROP("packet tag = authentication failed");
}
A= SSERT(buf_inc_len(&work, outlen));

- dmsg(D_PACKET_CONTENT, "DECRYPT= TO: %s",
- = format_hex(BPTR(&work), BLEN(&work), 80, &gc));
+ dmsg(D_PACKET_CONTENT, "= DECRYPT TO: %s", format_hex(BPTR(&work), BLEN(&work), 80, &= ;gc));


if (!crypto_check_replay(opt,= &pin, epoch, error_prefix, &gc))
{
= @@ -604,7 +585,7 @@
/* update number of plaintex= t blocks decrypted. Use the (x + (n-1))/n trick
* to = round up the result to the number of blocks used. */
c= onst int blocksize =3D AEAD_LIMIT_BLOCKSIZE;
- opt->key_ctx_bi.decrypt.plaintext_blocks +=3D= (outlen + (blocksize - 1))/blocksize;
+ opt->key_ctx_bi.decrypt.plaintext_blocks +=3D (ou= tlen + (blocksize - 1)) / blocksize;

= *buf =3D work;

@@ -627,8 +608,8 @@
* On success, buf is set to point to plaintext, true is return= ed.
*/
static bool
-openvpn_decrypt_v1(struct buffer *buf, stru= ct buffer work,
- = struct crypto_options *opt, const struct frame *frame)<= br>+openvpn_decrypt_v1(struct b= uffer *buf, struct buffer work, struct crypto_options *opt,
+ const struct fra= me *frame)

{
static const char error_= prefix[] =3D "Authenticate/Decrypt packet error";
struct gc_arena gc;

@@ -640,8 +621,7 @@
struct packet_id_net pin;

bool have_pi= n =3D false;

- dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s",
- format_hex(BPT= R(buf), BLEN(buf), 80, &gc));
+ dmsg(D_PACKET_CONTENT, "DECRYPT FROM: %s", = format_hex(BPTR(buf), BLEN(buf), 80, &gc));
/* Verify the HMAC */
if (ctx->= hmac)
@@ -723,8 +703,7 @@
}
ASSERT(buf_inc_len(&work, outlen));
- = dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s",
- format_hex(BPTR(&work), B= LEN(&work), 80, &gc));
+ dmsg(D_PACKET_CONTENT, "DECRYPT TO: %s", f= ormat_hex(BPTR(&work), BLEN(&work), 80, &gc));
=
/* Get packet ID from plaintext buffer or IV= , depending on cipher mode */
{
@@ -732,7 +711,8 @@

{
= if (packet_id_initialized(&opt->packet_id))
{
- if (!packet_id_read(&pin, &work= , BOOL_CAST(opt->flags & CO_PACKET_ID_LONG_FORM)))
+ if (!packet_i= d_read(&pin, &work,
+ BOOL_CAST(opt->flags= & CO_PACKET_ID_LONG_FORM)))
{=
CRYPT_ERROR("error readi= ng CBC packet-id");
}<= br>@@ -791,9 +771,8 @@


= bool
-openvpn_de= crypt(struct buffer *buf, struct buffer work,
- struct crypto_options *opt, const s= truct frame *frame,
- = const uint8_t *ad_start)
+openvpn_decrypt(struct buffer *buf, struct buffer work, = struct crypto_options *opt,
+ const struct frame *frame, const uint8_t *ad_start)=
{
bool ret =3D false;

@@ -816,9 +795,7 @@
}
=
unsigned int
-calculate_crypto_overhead(const struct key_type *kt,
- unsigned= int pkt_id_size,

- = bool occ)
+calculate_crypto_overhead(const struct key_type *kt, unsigned i= nt pkt_id_size, bool occ)
{
unsigned = int crypto_overhead =3D 0;

@@ -867,9 +844= ,8 @@
unsigned int
crypto_max_overhead(vo= id)
{
= - return packet_id_size(true) + OPENVPN_MAX_IV_LENGTH
- +OPENVPN_MAX_CIPHER_BLOCK_SIZ= E
- +max_int(= OPENVPN_MAX_HMAC_SIZE, OPENVPN_AEAD_TAG_LENGTH);
+ return packet_id_size(true) + OPENVPN_MAX_= IV_LENGTH + OPENVPN_MAX_CIPHER_BLOCK_SIZE
+ + max_int(OPENVPN_MAX_HMAC_SIZE, OPENVPN_A= EAD_TAG_LENGTH);
}

stat= ic void
@@ -877,12 +853,13 @@
{
= if (cipher_kt_insecure(ciphername))
{
- msg(M_WARN, "W= ARNING: INSECURE cipher (%s) with block size less than 128"
= + msg(M_WARN,
= + "WARNING: INS= ECURE cipher (%s) with block size less than 128"
= " bit (%d bit). This allows attacks like SWEET32. Mitigate b= y "
"using a --cipher with a larger = block size (e.g. AES-256-CBC). "
"Su= pport for these insecure ciphers will be removed in "
= "OpenVPN 2.7.",
- ciphername, cipher_kt_block_size(ciphername)*8= );
+ ciphe= rname, cipher_kt_block_size(ciphername) * 8);
}=
}

@@ -890,8 +867,8 @@ * Build a struct key_type.
*/
= void
-init_key_type(str= uct key_type *kt, const char *ciphername,
- const char *authname, bool tls_mode, bool= warn)
+init_key_type= (struct key_type *kt, const char *ciphername, const char *authname, bool tl= s_mode,
+ = bool warn)
{
bool aead_cipher =3D f= alse;

@@ -909,12 +886,11 @@

/* check legal cipher mode */
aead_cipher =3D cipher_kt_mode_aead(kt->cipher);

- if (!(cipher_kt_mode_cbc(kt= ->cipher)

- = || (tls_mode && aead_cipher)
+ if (!(cipher_kt_mode_cbc(kt->cipher) || (t= ls_mode && aead_cipher)
#ifdef ENABLE_OFB_CFB_MODE=
|| (tls_mode && cipher_kt_mode_ofb_= cfb(kt->cipher))
#endif
- ))
+ ))
{ msg(M_FATAL, "Cipher '%s' mode not suppor= ted", ciphername);
}
@@ -933,= 9 +909,9 @@
if (warn)
{
msg(M_WARN, "******* WARNING *******: '= ;--cipher none' was specified. "
- "This means NO encryption will be = performed and tunnelled "
- "data WILL be transmitted in clear text over = the network! "
- = "PLEASE DO RECONSIDER THIS SETTING!");
+ "Th= is means NO encryption will be performed and tunnelled "

+ "dat= a WILL be transmitted in clear text over the network! "

+ "PLEA= SE DO RECONSIDER THIS SETTING!");

} }
kt->digest =3D authname;
@@ -960,10 +936,10 @@

if (warn)
{

msg(M_WARN, "******* WARNING= *******: '--auth none' was specified. "
- "This means no authent= ication will be performed on received "
- "packets, meaning you CANNOT tr= ust that the data received by "
- "the remote side have NOT been manipula= ted. "
- = "PLEASE DO RECONSIDER THIS SETTING!");
+ "This means= no authentication will be performed on received "
+ "packets, = meaning you CANNOT trust that the data received by "
+ "the rem= ote side have NOT been manipulated. "
+ "PLEASE DO RECONSIDER T= HIS SETTING!");
}
}
}
@@ -1012,9 +988,8 @@

/* given a key and key_type, build a key_ctx */
void

-init_key_ctx(st= ruct key_ctx *ctx, const struct key_parameters *key,
- const struct key_type *kt, int= enc,
- con= st char *prefix)
+ini= t_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, const stru= ct key_type *kt,
+ = int enc, const char *prefix)
{
= struct gc_arena gc =3D gc_new();
CLEAR(*ctx);
@@ -1025,14 +1000,13 @@
cipher_ctx_ini= t(ctx->cipher, key->cipher, kt->cipher, enc);

const char *ciphername =3D cipher_kt_name(kt->cip= her);
- msg(D_CI= PHER_INIT, "%s: Cipher '%s' initialized with %d bit key",=
- prefix, c= iphername, cipher_kt_key_size(kt->cipher) * 8);
+ msg(D_CIPHER_INIT, "%s: Cipher = '%s' initialized with %d bit key", prefix, ciphername,<= br>+ cipher_kt_key_s= ize(kt->cipher) * 8);

dmsg(D_= SHOW_KEYS, "%s: CIPHER KEY: %s", prefix,
= format_hex(key->cipher, cipher_kt_key_size(kt->cipher), 0, &= ;gc));
- dmsg(D_= CRYPTO_DEBUG, "%s: CIPHER block_size=3D%d iv_size=3D%d",- prefix, cipher_kt= _block_size(kt->cipher),
- cipher_kt_iv_size(kt->cipher));
+ dmsg(D_CRYPTO_DEBUG, "%s: CI= PHER block_size=3D%d iv_size=3D%d", prefix,
+ cipher_kt_block_size(kt->ciphe= r), cipher_kt_iv_size(kt->cipher));
warn_insecu= re_key_type(ciphername);
}
@@ -1042,18 +1016,14 @@
ctx->hmac =3D hm= ac_ctx_new();
hmac_ctx_init(ctx->hmac, key->= hmac, kt->digest);

- msg(D_CIPHER_INIT,
- "%s: Using %d bit message hash '= ;%s' for HMAC authentication",
- prefix, md_kt_size(kt->digest) * 8, md_kt_= name(kt->digest));
+ msg(D_CIPHER_INIT, "%s: Using %d bit message hash '%s= 9; for HMAC authentication", prefix,
+ md_kt_size(kt->digest) * 8, md_kt_name= (kt->digest));

dmsg(D_SHOW_KE= YS, "%s: HMAC KEY: %s", prefix,
for= mat_hex(key->hmac, md_kt_size(kt->digest), 0, &gc));

- dmsg(D_C= RYPTO_DEBUG, "%s: HMAC size=3D%d block_size=3D%d",
- prefix,

- md_kt_size(kt->digest= ),

+ dmsg(D_CR= YPTO_DEBUG, "%s: HMAC size=3D%d block_size=3D%d", prefix, md_kt_s= ize(kt->digest),
hmac_ctx_size(ctx->hma= c));
-
= }
ctx->epoch =3D key->epoch;
gc_free(&gc);

@@ -1084,8 +1054,8 @@
}


void
-init_key_ctx_bi(struct key_ctx_bi *ctx, const stru= ct key2 *key2,
- = int key_direction, const struct key_type *kt, const char *name)
+init_key_ctx_bi(struct= key_ctx_bi *ctx, const struct key2 *key2, int key_direction,
+ const struct key_= type *kt, const char *name)

{
struct = key_direction_state kds;

@@ -1175,39 +114= 5,34 @@
struct gc_arena gc =3D gc_new();

CLEAR(*key);
- if (!rand_bytes(key->cipher, cipher_len)
= - || !rand_bytes(key->h= mac, hmac_len))
+ = if (!rand_bytes(key->cipher, cipher_len) || !rand_bytes(key->hmac, hm= ac_len))
{
msg(M_FATAL, "= ;ERROR: Random number generator cannot obtain entropy for key generation&qu= ot;);
}

- dmsg(D_SHOW_KEY_SOURCE, "Cipher source en= tropy: %s", format_hex(key->cipher, cipher_len, 0, &gc));
+ dmsg(D_SHOW_KEY_SOURC= E, "Cipher source entropy: %s",
+ format_hex(key->cipher, cipher_len, 0, &a= mp;gc));
dmsg(D_SHOW_KEY_SOURCE, "HMAC source ent= ropy: %s", format_hex(key->hmac, hmac_len, 0, &gc));
=
gc_free(&gc);
}
static void
-key_print(const struct key *key,
- const struct key_type *kt,
<= span style=3D"color: hsl(0, 100%, 40%);">- const char *prefix)
+key_print(const struct = key *key, const struct key_type *kt, const char *prefix)
{=
struct gc_arena gc =3D gc_new();
- dmsg(D_SHOW_KEY_SOURCE, "%s (ciph= er, %s, %d bits): %s",
- prefix, cipher_kt_name(kt->cipher), cipher_kt_key_size(kt= ->cipher) * 8,
+ = dmsg(D_SHOW_KEY_SOURCE, "%s (cipher, %s, %d bits): %s", prefix,= cipher_kt_name(kt->cipher),
+ cipher_kt_key_size(kt->cipher) * 8,
format_hex(key->cipher, cipher_kt_key_size(kt->cipher), 0,= &gc));

- dmsg(D= _SHOW_KEY_SOURCE, "%s (hmac, %s, %d bits): %s",
- prefix, md_kt_name(kt->dige= st), md_kt_size(kt->digest) * 8,
- format_hex(key->hmac, md_kt_size(kt->digest), = 0, &gc));
+ dm= sg(D_SHOW_KEY_SOURCE, "%s (hmac, %s, %d bits): %s", prefix, md_kt= _name(kt->digest),
+ md_kt_size(kt->digest) * 8, format_hex(key->hmac, md_kt_si= ze(kt->digest), 0, &gc));
gc_free(&gc);
}
/**
* Prints the keys in= a key2 structure.
*/
void
-key2_print(const struct key2 *k,
- const struct = key_type *kt,
- = const char *prefix0,
+key2_print(const struct key2 *k, const struct key_type *kt, const char = *prefix0,
const char *prefix1)
= {
ASSERT(k->n =3D=3D 2);
@@ -1249,= 11 +1214,10 @@
ASSERT(cipher_ctx_iv_length(cip= her) >=3D OPENVPN_AEAD_MIN_IV_LEN);

= /* Generate dummy implicit IV */
- ASSERT(rand_bytes(co->key_ctx_bi.encry= pt.implicit_iv,
- = OPENVPN_MAX_IV_LENGTH));
+ ASSERT(rand_bytes(co->key_ctx_b= i.encrypt.implicit_iv, OPENVPN_MAX_IV_LENGTH));
- memcpy(co->key_c= tx_bi.decrypt.implicit_iv,
- co->key_ctx_bi.encrypt.implicit_iv, OPENVPN_MAX_= IV_LENGTH);
+ = memcpy(co->key_ctx_bi.decrypt.implicit_iv, co->key_ctx_bi.encrypt= .implicit_iv,
+ = OPENVPN_MAX_IV_LENGTH);
}
<= span> }


@@ -1318,11 +1282,9 @@=
}

void
-crypto_read_openvpn_key(const struct key_ty= pe *key_type,
- = struct key_ctx_bi *ctx, const char *key_file,
- bool key_in= line, const int key_direction,

- const char *key_name, const char *opt_name= ,
- = struct key2 *keydata)
+crypto_read_openvpn_key(const struct key_type *key_type, struct key_c= tx_bi *ctx,
+ = const char *key_file, bool key_inline, const int key_direct= ion,
+ = const char *key_name, const char *opt_name, struct key2 *keydata)<= /span>
{
struct key2 key2;
= struct key_direction_state kds;
@@ -1336,7 +1298,8 @@

if (key2.n !=3D 2)
= {
- msg(M_ERR= , "File '%s' does not have OpenVPN Static Key format. Using &= quot;
+ msg(M_= ERR,
+ &qu= ot;File '%s' does not have OpenVPN Static Key format. Using "=
"free-form passphrase file is not suppor= ted anymore.",
print_key_filename(key_fil= e, key_inline));
}
@@ -1375,7 +1338,7 = @@
struct gc_arena gc =3D gc_new();
= struct buffer in;
int size;
- uint8_t hex_byte[3] =3D {0, 0, 0};
+ uint8_t hex_byte[3] = =3D { 0, 0, 0 };

/* parse info */
const unsigned char *cp;
@@ -1385,17 +13= 48,17 @@
int match =3D 0;

= /* output */
- uint8_t *out =3D (uint8_t *) &key2->keys;
+ uint8_t *out =3D (uint8_t *)&key= 2->keys;
const int keylen =3D sizeof(key2->keys)= ;
int count =3D 0;

= /* parse states */
= -#define PARSE_INITIAL 0
-#define PARSE_HEAD 1
-#define PARSE_DATA 2
-#define PARSE_DATA_COMPLETE 3
-#define PARSE_FOOT 4<= br>-#define PARSE_FINISHED = 5
+#define PARSE_INIT= IAL 0
+#define = PARSE_HEAD 1
+#define PARSE_DATA 2
+#define PARSE_DATA_COMPLETE 3
+#define PARSE_FOOT 4
+#define PARSE_FINISHED 5
<= span> int state =3D PARSE_INITIAL;


= /* constants */
@@ -1507,11 +1470,9 @@
= }
else
= {
- = msg(M_FATAL,
- (isprint(c) ? printable_char_fmt : unprintable= _char_fmt),
- = c, line_num,
- print_key_filename(file, flags & RKF_INLIN= E), count,
- = onekeylen, keylen);
+ msg(M_FATAL, (isprint(c) ? printable_char_= fmt : unprintable_char_fmt), c,
+ line_num, print_key_filename(file, flag= s & RKF_INLINE), count, onekeylen,
+ keylen);
= }
}
++l= ine_index;
@@ -1525,22 +1486,21 @@
*/=
key2->n =3D count / onekeylen;

- ASSERT(key2->n &= gt;=3D 0 && key2->n <=3D (int) SIZE(key2->keys));+ ASSERT(key2->n >= =3D 0 && key2->n <=3D (int)SIZE(key2->keys));

if (flags & RKF_MUST_SUCCEED)
{

if (!key2->n)
= {
- msg(M_F= ATAL, "Insufficient key material or header text not found in file '= ;%s' (%d/%d/%d bytes found/min/max)",
- print_key_filename(file, flags &am= p; RKF_INLINE), count, onekeylen,
- keylen);
+ msg(M_FATAL,
+ "Insufficient key material or he= ader text not found in file '%s' (%d/%d/%d bytes found/min/max)&quo= t;,
+ = print_key_filename(file, flags & RKF_INLINE), count, onekeylen, keylen)= ;
}

if = (state !=3D PARSE_FINISHED)
{
= msg(M_FATAL, "Footer text not found in file '%s' (%d/= %d/%d bytes found/min/max)",
- print_key_filename(file, flags & RKF_INLINE= ), count, onekeylen,
- = keylen);
+ print_key_filename(file, flags & RKF_INLINE), count= , onekeylen, keylen);
}
}

@@ -1599,12 +1559,7 @@
= generate_key_random(&key);

= /* format key as ascii */
- fmt =3D format_hex_ex((const uint8_t *)&key,
<= span style=3D"color: hsl(0, 100%, 40%);">- sizeo= f(key),

- = 0,
- = bytes_per_line,
- "\n",
- &gc)= ;

+ fmt =3D fo= rmat_hex_ex((const uint8_t *)&key, sizeof(key), 0, bytes_per_line, &quo= t;\n", &gc);

/* write t= o holding buffer */
buf_printf(&out, "%s\= n", fmt);
@@ -1617,7 +1572,7 @@
b= uf_printf(&out, "%s\n", static_key_foot);

/* write key file to stdout if no filename given */
- if (!filename || strc= mp(filename, "")=3D=3D0)
+ if (!filename || strcmp(filename, "") =3D=3D 0= )
{
printf("%.*s\n"= , BLEN(&out), BPTR(&out));
}
@= @ -1642,9 +1597,14 @@
if (key2->n < n) {
#ifdef ENABLE_SMALL
- msg(M_FATAL, "Key file '%s= 9; used in --%s contains insufficient key material [keys found=3D%d require= d=3D%d]", filename, option, key2->n, n);
+ msg(M_FATAL,
+ "Key file '%s' used = in --%s contains insufficient key material [keys found=3D%d required=3D%d]&= quot;,
+ f= ilename, option, key2->n, n);
#else
- msg(M_FATAL, "Key file '= %s' used in --%s contains insufficient key material [keys found=3D%d re= quired=3D%d] -- try generating a new key file with '" PACKAGE &quo= t; --genkey secret [file]', or use the existing key file in bidirection= al mode by specifying --%s without a key direction parameter", filenam= e, option, key2->n, n, option);
+ msg(M_FATAL,
+ "Key file '%s' used in --%s contai= ns insufficient key material [keys found=3D%d required=3D%d] -- try generat= ing a new key file with '" PACKAGE
+ " --genkey secret [file]', or = use the existing key file in bidirectional mode by specifying --%s without = a key direction parameter",
+ filename, option, key2->n, n, option); #endif
}
}
@= @ -1740,8 +1700,8 @@
/* This should be a very impr= obable failure */
if (!check_key(&key2->key= s[i], kt))
{
- msg(M_FATAL, "Key #%d in '%s' is b= ad. Try making a new key with --genkey.",
- i+1, shared_secret_file);<= br>+ msg(M_FATAL, &q= uot;Key #%d in '%s' is bad. Try making a new key with --genkey.&qu= ot;, i + 1,
+ = shared_secret_file);
}
= }
}
@@ -1768,9 +1728,7 @@
void

print_cipher(const char *ciphername)
{

- printf("= ;%s (%d bit key, ",
- cipher_kt_name(ciphername),
- cipher_kt_key_size(ciphername) * 8);=
+ printf("%s (%d b= it key, ", cipher_kt_name(ciphername), cipher_kt_key_size(ciphername) = * 8);

if (cipher_kt_block_size(ciphe= rname) =3D=3D 1)
{
@@ -1856,14 +1814,1= 3 @@
goto cleanup;
} buf_set_read(&server_key_buf, (void *)&server_key, siz= eof(server_key));
- = if (!crypto_pem_encode(pem_name, &server_key_pem,
- &server_key_= buf, &gc))
+ i= f (!crypto_pem_encode(pem_name, &server_key_pem, &server_key_buf, &= amp;gc))
{
msg(M_WARN, "= ERROR: could not PEM-encode key");
goto clean= up;
}

- if (!filename || strcmp(filename, "")= =3D=3D0)
+ if (!fi= lename || strcmp(filename, "") =3D=3D 0)
{
printf("%.*s", BLEN(&server_key_pem),= BPTR(&server_key_pem));
}
@@ -189= 9,8 +1856,7 @@
}

bool
-read_pem_key_file(struc= t buffer *key, const char *pem_name,
- const char *key_file, bool key_inline)
+read_pem_key_file(struc= t buffer *key, const char *pem_name, const char *key_file, bool key_inline)=
{
bool ret =3D false;
struct buffer key_pem =3D { 0 };

@@ -1911,8 +1867,7 = @@
key_pem =3D buffer_read_from_file(key_file, &am= p;gc);
if (!buf_valid(&key_pem))
{

- = msg(M_WARN, "ERROR: failed to read %s file (%s)",
<= span style=3D"color: hsl(0, 100%, 40%);">- pem_name, key_fil= e);

+ msg(= M_WARN, "ERROR: failed to read %s file (%s)", pem_name, key_file)= ;
goto cleanup;
}
}
@@ -1949,9 +1904,8 @@
= uint8_t out[8];
uint8_t expected_out[] =3D { '= q', 'D', '\xfe', '%', '@', 's',= 'u', '\x95' };

- int ret =3D ssl_tls1_PRF((uint8_t *)seed, (= int) strlen(seed),
- = (uint8_t *)secret, (int) strlen(secret),
= - out, = sizeof(out));
+ in= t ret =3D ssl_tls1_PRF((uint8_t *)seed, (int)strlen(seed), (uint8_t *)secre= t,
+ = (int)strlen(secret), out, sizeof(out));
<= br> return (ret && memcmp(out, expected_out, sizeof(out))= =3D=3D 0);
}
diff --git a/src/openvpn/cry= pto.h b/src/openvpn/crypto.h
index 68ad901..216d798 100644<= /span>
--- a/src/openvpn/crypto.h
+++ b/src/openvp= n/crypto.h
@@ -130,7 +130,8 @@
#include &q= uot;mtu.h"

/** Wrapper struct to pa= ss around SHA256 digests */
-struct sha256_digest {
+struct sha256_digest
+{
uint8_t digest[SHA256_DIGEST_LENGTH];
};

@@ -139,8 +140,8 @@
*/
struct key_type
{<= br>- const char *cipher; = /**< const name of the cipher */
- const char *digest; /**< Message digest sta= tic parameters */
+ = const char *cipher; /**< const name of the cipher */
+ const char *digest; /**< Messa= ge digest static parameters */
};
=
/**
@@ -159,7 +160,8 @@
/** int= ernal structure similar to struct key that holds key information
= * but is not represented on wire and can be changed/extended=
*/
-struct = key_parameters {
+str= uct key_parameters
+{=
/** %Key material for cipher operations. */ uint8_t cipher[MAX_CIPHER_KEY_LENGTH];
=
@@ -185,10 +187,10 @@
* @param key_params de= stination for the converted struct
* @param key = source of the conversion
*/
-void
-key_parameters_from_key(struct key_parameters *key_params, const st= ruct key *key);
+void= key_parameters_from_key(struct key_parameters *key_params, const struct ke= y *key);

-struct epoch_key {
+struct epoch_key
= +{
uint8_t epoch_key[SHA256_DIGEST_LENGTH];
= uint16_t epoch;
};
@@ -199,8 +2= 01,8 @@
*/
struct key_ctx
{

- cipher_ctx_t = *cipher; /**< Generic cipher %context. */
- hmac_ctx_t *hmac; /**< Generi= c HMAC %context. */
+= cipher_ctx_t *cipher; /**< Generic cipher %context. */
+ hmac_ctx_t *hmac; /**<= Generic HMAC %context. */

/**
*= This implicit IV will be always XORed with the packet id that is sent on
* the wire to get the IV. For the common AEAD ciphers = of AES-GCM and
@@ -214,7 +216,7 @@
*/=
uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH]; /**< The implicit part of the IV */
- size_t implicit_iv_len; /**< The le= ngth of implicit_iv */
- int n; /**< The number of \c key objects stor= ed
- = * in the \c key2.keys array. */
- struct key keys[2]; /**< Two unidi= rectional sets of %key
= - * material. The first key is the client=
- = * (encrypts) to server (decrypts), the
- * second= the server to client key. */
+ int n; /**< The number of \c key objects stor= ed
+ = * in the \c key2.keys array. */
+ struct key keys[2]; /**< Two unidirectional se= ts of %key
+ = * material. The first key is the client
+ * (encrypt= s) to server (decrypts), the
+ * second the server to client key. */
};

/**
@= @ -256,18 +258,18 @@
*/
struct key_direc= tion_state
{
- int out_key; /**< Index into the \c key2.keys= array for
- = * the sending direction. */
- int in_key; /**< Ind= ex into the \c key2.keys array for
- * the receiving direction. = */
- int need_keys; = /**< The number of key objects necessary
- * to = support both sending and
- *
<= span style=3D"color: hsl(0, 100%, 40%);">- = * This will be 1 if the same keys are

- * used in both directi= ons, or 2 if
- = * there are two sets of unidirectional
= - = * keys. */
+ in= t out_key; /**< Index into the \c key2.keys array for
+ * the sending = direction. */
+ in= t in_key; /**< Index into the \c key2.keys array for
+ * the receivin= g direction. */
+ = int need_keys; /**< The number of key objects necessary
+ * to support b= oth sending and
+ = * receiving.
+ *
+ * This will be 1 if the same keys are
+ * = used in both directions, or 2 if
+ * there are two sets of unidirectional=
+ = * keys. */
};

/**
@@ -277,10 +279,10 @@
*/
s= truct key_ctx_bi
{
- struct key_ctx encrypt; /**< Cipher and/or HMAC co= ntexts for sending
- = * direction. */
- struct key_ctx decrypt; /**< cipher an= d/or HMAC contexts for
= - * receiving direction. */
+ struct key_ctx encrypt; /**&l= t; Cipher and/or HMAC contexts for sending

+ * direction. */
+ struct key_ctx decryp= t; /**< cipher and/or HMAC contexts for
+ * receiving direction= . */
bool initialized;
};
<= span>

@@ -341,54 +343,58 @@
* keep= ing state between successive
* OpenVPN process star= tups. */

-#define CO_PACKET_ID_LONG_FORM (1<<0)
+#define CO_PACKET_ID_LONG_FORM (1 <= ;< 0)
/**< Bit-flag indicating whether to use
- * OpenVPN's lo= ng packet ID format. */
-#define CO_IGNORE_PACKET_ID (1<<1)
+ * OpenVPN's long packet ID format. */=
+#define CO_IGNORE_P= ACKET_ID (1 << 1)
/**< Bit-flag in= dicating whether to ignore
* the packet ID of a rec= eived packet.
* This flag is used during processing=
* of the first packet received from a
* client. */

+#define CO_MUTE_REPLAY_WARNINGS (1 <&= lt; 2)
/**< Bit-flag indicating not to display
* replay warnings. */
-#define CO_USE_TLS_KEY_MATERIAL_EXPORT (1<<3)
+#define CO_USE_TLS_KEY= _MATERIAL_EXPORT (1 << 3)
/**< Bit-flag indic= ating that data channel key derivation
* is done usin= g TLS keying material export [RFC5705]
*/
<= span style=3D"color: hsl(0, 100%, 40%);">-#define CO_RESEND_WKC (1<<4= )

+#define CO_RESEND_= WKC (1 << 4)
/**< Bit-flag i= ndicating that the client is expected to
* resend the= wrapped client key with the 2nd packet (packet-id 1)
= * like with the HARD_RESET_CLIENT_V3 packet */
-#define CO_FORCE_TLSCRYPTV2_COOKIE (1<<5)<= /span>
+#define CO_FORCE_TLS= CRYPTV2_COOKIE (1 << 5)
/**< Bit-flag ind= icating that we do not allow clients that do
* not su= pport resending the wrapped client key (WKc) with the
= * third packet of the three-way handshake */
-#define CO_USE_CC_EXIT_NOTIFY (1<<6)
+#define CO_USE_CC_EXIT= _NOTIFY (1 << 6)
/**< Bit-flag indic= ating that explicit exit notifies should be
* sent vi= a the control channel instead of using an OCC message
= */
-#define CO_USE_DYN= AMIC_TLS_CRYPT (1<<7)
+#define CO_USE_DYNAMIC_TLS_CRYPT (1 << 7)
<= span> /**< Bit-flag indicating that renegotiations are using tls-cry= pt

* with a TLS-EKM derived key.
= */
-#define CO_EPOC= H_DATA_KEY_FORMAT (1<<8)
+#define CO_EPOCH_DATA_KEY_FORMAT (1 << 8) /**< Bit-flag indicating the epoch the data format. This for= mat
* has the AEAD tag at the end of the packet and i= s using a longer
* 64-bit packet id that is split int= o a 16 bit epoch and 48 bit
* epoch counter */

- unsigned int flags; /**< Bit-flags determining b= ehavior of
- = * security operation functions. */
+ unsigned int flags; /**< Bit-= flags determining behavior of
+ * security operation functions. */
};

-#define CRYPT_ERROR_EXIT(flags, format) \
- do { msg(flags, "%s: " forma= t, error_prefix); goto error_exit; } while (false)
+#define CRYPT_ERROR_EXIT(flags, format) = \
+ do = \
+ { \=
+ msg(flags, "%= s: " format, error_prefix); \
+ goto error_exit; \+ } while (false)
#define CRYPT_ERROR(format) CRYPT_ERROR_EXIT(D_CR= YPT_ERRORS, format)
-#d= efine CRYPT_DROP(format) CRYPT_ERROR_EXIT(D_MULTI_DROPPED, format)+#define CRYPT_DROP(format) = CRYPT_ERROR_EXIT(D_MULTI_DROPPED, format)

/**

* Minimal IV length for AEAD mode ciphers (in bytes= ):
@@ -396,8 +402,8 @@
*/
#define OPENVPN_AEAD_MIN_IV_LEN (sizeof(packet_id_type) + 8)


-#define RKF_MUST= _SUCCEED (1<<0)
-= #define RKF_INLINE (1<<1)
+#define RKF_MUST_SUCCEED (1 << 0)
+#define RKF_INLINE (1 << = 1)
void read_key_file(struct key2 *key2, const char *file,= const unsigned int flags);

/**@@ -419,30 +425,26 @@
* more c= iphers than static key mode.
* @param warn Print w= arnings when null cipher / auth is used.
*/
-void init_key_type(struct key_type = *kt, const char *ciphername,

- const char *authname, bool tls_mode, bool warn);<= /span>
+void init_key_type(s= truct key_type *kt, const char *ciphername, const char *authname, bool tls_= mode,
+ = bool warn);

/*
* = Key context functions
*/

-void init_key_ctx(struct key_ctx *ct= x, const struct key_parameters *key,

- const struct key_type *kt, int enc,=
- const char= *prefix);
+void init= _key_ctx(struct key_ctx *ctx, const struct key_parameters *key, const struc= t key_type *kt,
+ = int enc, const char *prefix);

-void

-init_key_bi_ctx_send(struct key_ctx *ctx, const stru= ct key_parameters *key,
- const struct key_type *kt, const char *name);=
+void init_key_bi_ctx_send(= struct key_ctx *ctx, const struct key_parameters *key,
+ const struct k= ey_type *kt, const char *name);

-void
-init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key_param= eters *key,
- = const struct key_type *kt, const char *name);
+void init_key_bi_ctx_recv(struct key_c= tx *ctx, const struct key_parameters *key,
+ const struct key_type *kt,= const char *name);

void free_key_ctx(st= ruct key_ctx *ctx);

-void init_key_ctx_bi(struct key_ctx_bi *ctx, const struct k= ey2 *key2,
- = int key_direction, const struct key_type *kt,
- const char *name);
+void init_key_ctx_bi(= struct key_ctx_bi *ctx, const struct key2 *key2, int key_direction,<= br>+ const = struct key_type *kt, const char *name);

= void free_key_ctx_bi(struct key_ctx_bi *ctx);

<= span>@@ -477,8 +479,7 @@

* contain the processed pack= et ready for sending, or be empty if an
* error occur= red.
*/
-void openvpn_encrypt(struct buffer *buf, struct buffer work,
= - struct cryp= to_options *opt);
+vo= id openvpn_encrypt(struct buffer *buf, struct buffer work, struct crypto_op= tions *opt);


/**
@@ -514,9 +515,8 @@
* the plaintext packet= ready for further processing, or be empty if
* an er= ror occurred.
*/
-bool openvpn_decrypt(struct buffer *buf, struct buffer work,
- st= ruct crypto_options *opt, const struct frame *frame,
- const uint8_t *ad_star= t);
+bool openvpn_dec= rypt(struct buffer *buf, struct buffer work, struct crypto_options *opt,
+ c= onst struct frame *frame, const uint8_t *ad_start);

/** @} name Functions for performing security operations on dat= a channel packets */

@@ -531,11 +531,8 @@=
*
* @return true if packet ID is valid= ated to be not a replay, false otherwise.
*/
-bool crypto_check_replay(struct cr= ypto_options *opt,

- = const struct packet_id_net *pin,
- uint16_t epoch,
- = const char *error_prefix,
- struct gc_arena *gc);
+bool crypto_check_replay(struct crypto_op= tions *opt, const struct packet_id_net *pin,
+ uint16_t epoch, const cha= r *error_prefix, struct gc_arena *gc);

<= /span>
/** Calculate the maximum overhead that our encryption has=
@@ -551,10 +548,8 @@
* = incorrect way as all previous OpenVPN versions did, to
= * end up with identical numbers for OCC compatibilit= y
*/
= -unsigned int
-calculat= e_crypto_overhead(const struct key_type *kt,
- unsigned int pkt_id_size,<= /span>
- = bool occ);
+unsig= ned int calculate_crypto_overhead(const struct key_type *kt, unsigned int p= kt_id_size,
+ = bool occ);

/** Return the worst-case OpenVPN crypto overhead (in bytes) */
unsigned int crypto_max_overhead(void);
@@ -566,8 += 561,7 @@
* @param filename Filename of the serve= r key file to create.
* @param key_name The name= to use in the PEM header/footer.
*/
-void
-write_pem_key_file(const char *filename, const char *key_na= me);
+void write_pem_= key_file(const char *filename, const char *key_name);

/**
* Generate ephermal key material into t= he key structure
@@ -576,8 +570,7 @@
* @p= aram pem_name the name used for logging
* @return = true if key generation was successful
*/
-bool
-generate_ephemeral_key(struct buffer *key, = const char *pem_name);
-bool
-read_pem_key_file(struct = buffer *key, const char *pem_name,
- const char *key_file, bool key_inline);
+bool read_pem_key_file(s= truct buffer *key, const char *pem_name, const char *key_file,
+ bool key_= inline);


/*
* Message = digest-based pseudo random number generator.
@@ -632,16 +62= 4,12 @@
const char *keydirection2ascii(int kd, bool remote= , bool humanreadable);

/* print keys */<= /span>
-void key2_print(const = struct key2 *k,
- = const struct key_type *kt,
- const char *prefix0,
+void key2_print(const struct key2 *k, con= st struct key_type *kt, const char *prefix0,
= const char *prefix1);

-void crypto_read_openvpn_key(const struct key_type *ke= y_type,
- = struct key_ctx_bi *ctx, const char *key_file,
- bool ke= y_inline, const int key_direction,

- const char *key_name, const char = *opt_name,
- = struct key2 *keydata);
+void crypto_read_openvpn_key(const struct key_type *ke= y_type, struct key_ctx_bi *ctx,
+ const char *key_file, bool key_inl= ine, const int key_direction,
+ const char *key_name, const char *op= t_name, struct key2 *keydata);

/*=
* Inline functions
@@ -691,12 +679,12 @@=
if (cipher_defined(kt.cipher) && !cipher_valid(kt.ci= pher))
{
msg(M_WARN, "ER= ROR: --%s requires %s support.", optname, kt.cipher);
- return (struct key_type) { 0 }= ;
+ return (st= ruct key_type){ 0 };
}
if (md_def= ined(kt.digest) && !md_valid(kt.digest))
{
msg(M_WARN, "ERROR: --%s requires %s support.&qu= ot;, optname, kt.digest);
- return (struct key_type) { 0 };
+ return (struct key_type){ 0 };
}


return kt;
@@ -711,8 +699,7 @@

* For reference see the OpenVPN RFC= draft and
* https://www.ietf.org/archive/id/draft-irtf-c= frg-aead-limits-08.html
*/
-uint64_t
-cipher_get_aead_limits(const char *ciphername);
+uint64_t cipher_get_aead_limits(const= char *ciphername);

/**
= * Check if the number of failed decryption is over the acceptable limit.<= /span>
@@ -725,7 +712,7 @@
* but we accept s= lightly lower security bound for the edge
* of Chacha= 20-Poly1305 and packets over 16k as MTUs over 16k are
= * extremely rarely used */
- return ctx->failed_verifications > (1ull << 36);
+ return ctx->fail= ed_verifications > (1ull << 36);
}

/**
@@ -736,7 +723,7 @@
cipher_decrypt_verify_fail_warn(const struct key_ctx *ctx)

{

/* Use 2**35, half the amount after which we ref= use to decrypt */
- = return ctx->failed_verifications > (1ull << 35);
+ return ctx->failed_verific= ations > (1ull << 35);

}
=

@@ -745,7 +732,7 @@
*<= br> * Since cipher_ctx_block_size() is not reliable and will return = 1 in many
* cases use a hardcoded blocksize instead */
-#define AEAD_LIMIT_B= LOCKSIZE 16
+#defi= ne AEAD_LIMIT_BLOCKSIZE 16

/** * Checks if the current TLS library supports the TLS 1.0 PRF with = MD5+SHA1
@@ -762,13 +749,12 @@
* to read.=
*/
static inline bool
-aead_usage_limit_reached(const uint64_t= limit, const struct key_ctx *key_ctx,
- int64_t higest_pid)
+aead_usage_limit_reached(const ui= nt64_t limit, const struct key_ctx *key_ctx, int64_t higest_pid)

= {
/* This is the q + s <=3D p^(1/2) * 2^(1= 29/2) - 1 calculation where
* q is the number of prot= ected messages (highest_pid)
* s Total plaintext leng= th in all messages (in blocks) */
- return (limit > 0 && key_ctx->plaintext_block= s + (uint64_t) higest_pid > limit);
+ return (limit > 0 && key_ctx->plaintex= t_blocks + (uint64_t)higest_pid > limit);
}
<= span>

#endif /* CRYPTO_H */
diff --git a/= src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h
index 8bb7f47..239724c 100644

--- a/src/openvpn/crypto_bac= kend.h
+++ b/src/openvpn/crypto_backend.h
@= @ -46,18 +46,20 @@
#define OPENVPN_MAX_CIPHER_BLOCK_SIZE 3= 2

/* Maximum HMAC digest size (bytes) */=
-#define OPENVPN_MAX_H= MAC_SIZE 64
+#defin= e OPENVPN_MAX_HMAC_SIZE 64

/** Types ref= erencing specific message digest hashing algorithms */
-typedef enum {
+typedef enum
+{
MD_SHA1,
M= D_SHA256
} hash_algo_type;

/** Struct used in cipher name translation table */

-typedef struct {
- const char *openvpn_name; /**< Cipher= name used by OpenVPN */
+typedef struct=
+{
+ const char *openvpn_name; /**<= Cipher name used by OpenVPN */
+ const char *lib_name; /**< Cipher name used by crypt= o library */
} cipher_name_pair;
<= br> /** Cipher name translation table */
@@ -123,8 +1= 25,8 @@
*
* @return true iff PEM encode= succeeded.
*/
-bool crypto_pem_encode(const char *name, struct buffer *dst,
- co= nst struct buffer *src, struct gc_arena *gc);
+bool crypto_pem_encode(const char *name, struct b= uffer *dst, const struct buffer *src,
+ struct gc_arena *gc);

/**
* Decode a PEM buffer to binar= y data.
@@ -135,8 +137,7 @@
*
<= span> * @return true iff PEM decode succeeded.

*/=
-bool crypto_pem_decode(const= char *name, struct buffer *dst,
- const struct buffer *src);
+bool crypto_pem_decode(const char = *name, struct buffer *dst, const struct buffer *src);


/*
*
@@ -339,8 +340,8 @@
* @param enc Whether to encrypt or decrypt (eithe= r
* \c OPENVPN_OP_ENCRYPT or \c OPEN= VPN_OP_DECRYPT).
*/
-void cipher_ctx_init(cipher_ctx_t *ctx, const uint8_t *key,=
- = const char *ciphername, crypto_operation_t enc);
+void cipher_ctx_init(cipher_ctx_t *ctx, const = uint8_t *key, const char *ciphername,
+ crypto_operation_t enc);
<= span>

/**
* Returns the size of the IV = used by the cipher, in bytes, or 0 if no IV is
@@ -448,8 +4= 49,7 @@
*
* @return \c 0 o= n failure, \c 1 on success.
*/
-int cipher_ctx_update(cipher_ctx_t *ctx, uint8_t= *dst, int *dst_len,
- = uint8_t *src, int src_len);
+int cipher_ctx_update(cipher_ctx_t *ctx, uint8= _t *dst, int *dst_len, uint8_t *src, int src_len);
=
/**
* Pads the final cipher block using PKCS p= adding, and output to the destination
@@ -476,8 +476,8 @@
*
* @return \c 0 on failure= , \c 1 on success.
*/
-int cipher_ctx_final_check_tag(cipher_ctx_t *ctx, uint8_t= *dst, int *dst_len,
- = uint8_t *tag, size_t tag_len);
+int cipher_ctx_final_check_tag(cip= her_ctx_t *ctx, uint8_t *dst, int *dst_len, uint8_t *tag,

+ size_t= tag_len);


/*@@ -717,7 +717,7 @@
*
* @return= true if successful, false on any error
*/
-bool ssl_tls1_PRF(const= uint8_t *seed, int seed_len, const uint8_t *secret,
- int secret_len, uint8_t *= output, int output_len);
+bool ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *se= cret, int secret_len,
+ uint8_t *output, int output_len);

#endif /* CRYPTO_BACKEND_H_ */
diff --git a/s= rc/openvpn/crypto_epoch.c b/src/openvpn/crypto_epoch.c
inde= x 14727c7..9c00c50 100644
--- a/src/openvpn/crypto_epoch.c<= /span>
+++ b/src/openvpn/crypto_epoch.c
@@ -40,9 += 40,8 @@
#include "integer.h"

void
-o= vpn_hkdf_expand(const uint8_t *secret,
- const uint8_t *info, int info_len,=
- uint8_t *ou= t, int out_len)
+ovpn= _hkdf_expand(const uint8_t *secret, const uint8_t *info, int info_len, uint= 8_t *out,
+ = int out_len)
{
hmac_ctx_t *hma= c_ctx =3D hmac_ctx_new();
hmac_ctx_init(hmac_ctx, secr= et, "SHA256");
@@ -75,13 +74,10 @@
}


bool
-ovpn_expand_label(const uint8_t *secret, size_t secr= et_len,
- = const uint8_t *label, size_t label_len,
- const uint8_t *context, size_t cont= ext_len,
- = uint8_t *out, uint16_t out_len)
+ovpn_expand_label(const uint8_t *secret, size_t secret_len= , const uint8_t *label, size_t label_len,
+ const uint8_t *context, size_t cont= ext_len, uint8_t *out, uint16_t out_len)
{
- if (secret_len !=3D 32 || label_l= en > 250 || context_len > 255

- || label_len < 1)
+ if (secret_len !=3D 32 || label_len > 250 || = context_len > 255 || label_len < 1)
{
= /* Our current implementation is not a general purpose one
* and assumes that the secret size matches the siz= e of the
@@ -93,7 +89,7 @@
struct gc_a= rena gc =3D gc_new();
/* 2 byte for the outlen encoded= as uint16, 5 bytes for "ovpn ",
* 1 byte f= or context len byte and 1 byte for label len byte */
- const uint8_t *label_prefix =3D (const = uint8_t *) ("ovpn ");
+ const uint8_t *label_prefix =3D (const uint8_t *)("ovp= n ");
int prefix_len =3D 5;

int hkdf_label_len =3D 2 + prefix_len + 1 + label_len + 1= + context_len;
@@ -112,8 +108,7 @@

ASSERT(buf_len(&hkdf_label) =3D=3D hkdf_label_len);

- ovp= n_hkdf_expand(secret, buf_bptr(&hkdf_label),
- buf_len(&hkdf_label), o= ut, out_len);
+ ov= pn_hkdf_expand(secret, buf_bptr(&hkdf_label), buf_len(&hkdf_label),= out, out_len);

gc_free(&gc);
return true;
@@ -134,16 +129,14 @@
const size_t epoch_update_label_len =3D sizeof(epoch_update= _label) - 1;

/* E_N+1 =3D OVPN-Expan= d-Label(E_N, "datakey upd", "", 32) */
- ovpn_expand_label(epoch_key->ep= och_key, sizeof(epoch_key->epoch_key),
- epoch_update_label, epoch_update_= label_len,
- = NULL, 0,
- = new_epoch_key.epoch_key, sizeof(new_epoch_key.epoch_key= ));
+ ovpn_expand_= label(epoch_key->epoch_key, sizeof(epoch_key->epoch_key), epoch_updat= e_label,
+ = epoch_update_label_len, NULL, 0, new_epoch_key.epoch_key,=
+ size= of(new_epoch_key.epoch_key));
*epoch_key =3D new_epoch= _key;
}

void
= -epoch_data_key_derive(struct key= _parameters *key,
- = const struct epoch_key *epoch_key,
+epoch_data_key_derive(struct key_paramete= rs *key, const struct epoch_key *epoch_key,
= const struct key_type *kt)
{
= key->hmac_size =3D cipher_kt_iv_size(kt->cipher);
@@ = -158,19 +151,16 @@
/* length of the array without extr= a \0 byte from the string */
const size_t epoch_data_k= ey_label_len =3D sizeof(epoch_data_key_label) - 1;
=
- ovpn_expand_label(epoch_= key->epoch_key, sizeof(epoch_key->epoch_key),
- epoch_data_key_label,= epoch_data_key_label_len,
- NULL, 0,
- (uint8_t *)(&key->cipher), key-&= gt;cipher_size);
+ = ovpn_expand_label(epoch_key->epoch_key, sizeof(epoch_key->epoch_key)= , epoch_data_key_label,
+ epoch_data_key_label_len, NULL, 0, (uint8_t *)(&a= mp;key->cipher),
+= key->cipher_size);

const uint8_t epoch_data_iv_label[] =3D "data_iv";
=
/* length of the array without extra \0 byte from the string= */
const size_t epoch_data_iv_label_len =3D sizeof(ep= och_data_iv_label) - 1;

- ovpn_expand_label(epoch_key->epoch_key, sizeof(e= poch_key->epoch_key),
- NULL= , 0,
- = (uint8_t *)(&key->hmac), key->hmac_size);
+ ovpn_expand_label(epoch_key->ep= och_key, sizeof(epoch_key->epoch_key), epoch_data_iv_label,
+ epoch_data= _iv_label_len, NULL, 0, (uint8_t *)(&key->hmac), key->hmac_size);=

key->epoch =3D epoch_key->epoch;
}


@@ -188,8 +178,7 @@
=
epoch_data_key_derive(&send_key, &co->epo= ch_key_send, &co->epoch_key_type);

- init_key_bi_ctx_send(&co->= key_ctx_bi.encrypt, &send_key,

- &co->epoch_key_type, name);
+ init_key_bi_ctx_se= nd(&co->key_ctx_bi.encrypt, &send_key, &co->epoch_key_typ= e, name);
reset_packet_id_send(&co->packet_id.s= end);
CLEAR(send_key);
}
@@ -220,10 +209,10 @@

/* Either we have not genera= ted any future keys yet (first initialisation)
* or t= he last index is the same as our current epoch key
* = (last generated receive epoch key should match the epoch key) */
= - struct key_ctx *highest_futu= re_key =3D &co->epoch_data_keys_future[co->epoch_data_keys_future= _count - 1];
+ str= uct key_ctx *highest_future_key =3D
+ &co->epoch_data_keys_future[co->epoch_dat= a_keys_future_count - 1];

- ASSERT(co->epoch_key_recv.epoch =3D=3D 1
- || highest_futur= e_key->epoch =3D=3D co->epoch_key_recv.epoch);
+ ASSERT(co->epoch_key_recv.epoch = =3D=3D 1 || highest_future_key->epoch =3D=3D co->epoch_key_recv.epoch= );

/* free the keys that are not use= d anymore */
for (uint16_t i =3D 0; i < co->epoc= h_data_keys_future_count; i++)
@@ -251,12 +240,12 @@=
{
ASSERT(co->epoch_data_keys_fut= ure[i].epoch =3D=3D 0);
}
- memmove(co->epoch_data_keys_future,<= br>- co->epoch_data= _keys_future + num_keys_generate,
+ memmove(co->epoch_data_keys_future, co->epoch_data_= keys_future + num_keys_generate,
(co->epoch= _data_keys_future_count - num_keys_generate) * sizeof(struct key_ctx));

/* Clear and regenerate the array eleme= nts at the end */
- = for (uint16_t i =3D co->epoch_data_keys_future_count - num_keys_generate= ; i < co->epoch_data_keys_future_count; i++)
+ for (uint16_t i =3D co->epoch_data_ke= ys_future_count - num_keys_generate;
+ i < co->epoch_data_keys_future_count; i++)<= /span>
{
CLEAR(co->epoch_data_key= s_future[i]);
epoch_key_iterate(&co->epoch_= key_recv);
@@ -281,8 +270,7 @@
}
void
-epoch_replace_update_recv_key(struct crypto_options *co,- u= int16_t new_epoch)
+e= poch_replace_update_recv_key(struct crypto_options *co, uint16_t new_epoch)=
{
/* Find the key of the new epoch i= n future keys */
uint16_t fki;
@@ -351= ,8 +339,7 @@

void
epoch= _init_key_ctx(struct crypto_options *co, const struct key_type *key_type,
- cons= t struct epoch_key *e1_send,
- const struct epoch_key *e1_recv,
+ const struct epoc= h_key *e1_send, const struct epoch_key *e1_recv,
= uint16_t future_key_count)
{
= ASSERT(e1_send->epoch =3D=3D 1 && e1_recv->epoch =3D=3D 1);=
@@ -442,11 +429,9 @@
* decryptio= n fail warn limit.
* */
= else if (opt->key_ctx_bi.encrypt.epoch =3D=3D opt->key_ctx_bi.decrypt= .epoch
- = && (aead_usage_limit_reached(opt->aead_usage_limit,
= - = &opt->key_ctx_bi.decrypt,
+ && (aead_usage_limit_re= ached(opt->aead_usage_limit, &opt->key_ctx_bi.decrypt,
= opt->packet_id.rec.= id)
- = || cipher_decrypt_verify_fail_warn(&opt->key_ctx_bi.decrypt)
- ))
+ |= | cipher_decrypt_verify_fail_warn(&opt->key_ctx_bi.decrypt)))=
{
/* Receive key limit reac= hed. Increase our own send key to signal
* th= at we want to use a new epoch. Peer should then also move its
@@ -459,5 +444,4 @@

{
epoc= h_iterate_send_key(opt);
}
-
}
diff --git a/= src/openvpn/crypto_epoch.h b/src/openvpn/crypto_epoch.h
ind= ex c16f966..67a2240 100644
--- a/src/openvpn/crypto_epoch.h=
+++ b/src/openvpn/crypto_epoch.h
@@ -39,10= +39,8 @@
* @param out output keying material
* @param out_len length of output keying material
= */
-void=
-ovpn_hkdf_expand(const uint8= _t *secret,
- = const uint8_t *info, int info_len,
- uint8_t *out, int out_len);
= +void ovpn_hkdf_expand(const ui= nt8_t *secret, const uint8_t *info, int info_len, uint8_t *out,
<= span style=3D"color: hsl(120, 100%, 40%);">+ int out_l= en);


/**
* Variant of = the RFC 8446 TLS 1.3 HKDF-Expand-Label function with the
@= @ -61,11 +59,9 @@
* @param out_len length of output keyi= ng material
* @return
*/
-bool

-ovpn_expand_label(const uint8_t *secret, size_t secre= t_len,
- = const uint8_t *label, size_t label_len,
- const uint8_t *context, size_t conte= xt_len,
- = uint8_t *out, uint16_t out_len);
+bool ovpn_expand_label(const uint8_t *secret, size_t secre= t_len, const uint8_t *label,
+ size_t label_len, const uint8_t *context, s= ize_t context_len, uint8_t *out,
+ uint16_t out_len);

/**
* Generate a data channel key pair fro= m the epoch key
@@ -73,10 +69,8 @@
* @par= am epoch_key Epoch key to be used
* @param kt = Cipher information to generate the data channel key for
*/

-void
<= span style=3D"color: hsl(0, 100%, 40%);">-epoch_data_key_derive(struct key_= parameters *key,

- = const struct epoch_key *epoch_key,
- const struct key_type= *kt);
+void epoch_da= ta_key_derive(struct key_parameters *key, const struct epoch_key *epoch_key= ,
+ = const struct key_type *kt);

/**=
* Generates and fills the epoch_data_keys_future with ne= xt valid
@@ -91,8 +85,7 @@
* free the one= s that are older than the crypto_options.key_ctx_bi.decrypt and
<= span> * generate the keys from the newer epoch.

*/
-void
-epoch_generate_future_receive_keys(struct c= rypto_options *co);
+= void epoch_generate_future_receive_keys(struct crypto_options *co);<= br>

/** This is called when the p= eer uses a new send key that is not the default
@@ -103,21 = +96,17 @@
* @param co crypto_options to update
* @param new_epoch the new epoch to use for the receive key<= /span>
*/
-v= oid
-epoch_replace_upda= te_recv_key(struct crypto_options *co,
- uint16_t new_epoch);<= br>+void epoch_replace_update_r= ecv_key(struct crypto_options *co, uint16_t new_epoch);

/**
* Updates the send key and send_epoch= _key in cryptio_options->key_ctx_bi to
* use the next = epoch */
-void-epoch_iterate_send_key(struct = crypto_options *co);
= +void epoch_iterate_send_key(struct crypto_options *co);
<= /span>
/**
* Frees the extra data structures us= ed by epoch keys in \c crypto_options
*/
-void
-free_epoch_key_ctx(struct crypto_options *co);+void free_epoch_key_ctx(stru= ct crypto_options *co);

/**
* Initialises data channel keys and internal structures for epoch dat= a keys

@@ -132,10 +121,9 @@
* @param futu= re_key_count the number of future epoch keys that should be
* considered valid when receiving data from th= e peer

*/
-void
-epoch_init_= key_ctx(struct crypto_options *co, const struct key_type *key_type,<= br>- const stru= ct epoch_key *e1_send, const struct epoch_key *e1_recv,
- uint16_t future_key_co= unt);
+void epoch_ini= t_key_ctx(struct crypto_options *co, const struct key_type *key_type,
+ c= onst struct epoch_key *e1_send, const struct epoch_key *e1_recv,
= + uint16= _t future_key_count);

/**
* Using an epoch, this function will try to retrieve a decryption
@@ -144,8 +132,7 @@
* @param epoch epoch o= f the key to lookup
* @return the key context wi= th
*/
-struct key_ctx *
-epo= ch_lookup_decrypt_key(struct crypto_options *opt, uint16_t epoch);+struct key_ctx *epoch_lookup= _decrypt_key(struct crypto_options *opt, uint16_t epoch);
=
/**
* Checks if we need to iterate the = send epoch key. This needs to be in one
@@ -154,8 +141,7 @@=
* - send key aead usage limit reached (for AES-GCM and = similar ciphers)
* - recv key usage limit reached=
*/
-void
-epoch_check_send_iterate= (struct crypto_options *opt);
+void epoch_check_send_iterate(struct crypto_options *opt);=


#endif /* ifndef CRYPTO_EPOC= H_H */
diff --git a/src/openvpn/crypto_mbedtls.c b/src/open= vpn/crypto_mbedtls.c
index 1f3dcba..b13b662 100644--- a/src/openvpn/crypto_mbedtls.c
+++ b/src/openvp= n/crypto_mbedtls.c
@@ -66,7 +66,7 @@
crypt= o_init_lib_engine(const char *engine_name)
{
msg(M_WARN, "Note: mbed TLS hardware crypto engine functionali= ty is not "

- = "available");
+ "available");
}
provider_t *
@@ -124,8 +124,7 @@<= /span>
}

bool
-mbed_log_func_line(unsigned int flags,= int errval, const char *func,
- int line)
+mbed_log_func_line(unsigned int flags, int errval, const = char *func, int line)
{
char prefix[2= 56];

@@ -204,8 +203,8 @@
= const int *digests =3D mbedtls_md_list();

= #ifndef ENABLE_SMALL
- printf("The following message digests are available for use = with\n"
- = PACKAGE_NAME ". A message digest is used in conjunction with\n"= ;
+ printf("T= he following message digests are available for use with\n" PACKAGE_NAM= E
+ ".= A message digest is used in conjunction with\n"
= "the HMAC function, to authenticate received packets.\n"<= /span>
"You can specify a message digest as param= eter to\n"
"the --auth option.\n\n&qu= ot;);
@@ -233,12 +232,12 @@
}

bool
-crypto_pem_encode(const char *name, struct buffer *dst,
- const struct buff= er *src, struct gc_arena *gc)

+crypto_pem_encode(const char *name, struct buffer *dst, const str= uct buffer *src,
+ = struct gc_arena *gc)
{
= /* 1000 chars is the PEM line length limit (+1 for tailing NUL) */<= br>- char header[1000+1] =3D {= 0 };
- char footer[= 1000+1] =3D { 0 };
+ = char header[1000 + 1] =3D { 0 };
+ char footer[1000 + 1] =3D { 0 };

if (!snprintf(header, sizeof(header), "-----BEGIN %s-= ----\n", name))
{
@@ -250,9 +249,= 8 @@
}

size_t o= ut_len =3D 0;
- if (= MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL !=3D
- mbedtls_pem_write_buffer(header, footer, BPTR(sr= c), BLEN(src),
- = NULL, 0, &out_len))
+ if (MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL
+ !=3D mbedtls_= pem_write_buffer(header, footer, BPTR(src), BLEN(src), NULL, 0, &out_le= n))
{
return false; }
@@ -260,9 +258,9 @@
/* W= e set the size buf to out_len-1 to NOT include the 0 byte that
* mbedtls_pem_write_buffer in its length calculation */
*dst =3D alloc_buf_gc(out_len, gc);
- if (!mbed_ok(mbedtls_pem_write_buffer(header,= footer, BPTR(src), BLEN(src),
- BPTR(dst), BCAP(dst), &a= mp;out_len))
- |= | !buf_inc_len(dst, out_len-1))
+ if (!mbed_ok(mbedtls_pem_write_buffer(header, footer, BPTR(= src), BLEN(src), BPTR(dst),
+ BCAP(dst), &out_len))=
+ || !buf_inc= _len(dst, out_len - 1))
{
CLE= AR(*dst);
return false;
@@ -272,12= +270,11 @@
}

bool
-crypto_pem_decode(const ch= ar *name, struct buffer *dst,
- const struct buffer *src)
+crypto_pem_decode(const char *name, struc= t buffer *dst, const struct buffer *src)
{
/* 1000 chars is the PEM line length limit (+1 for tailing NUL) */
- char header[1000+1] = =3D { 0 };
- char fo= oter[1000+1] =3D { 0 };
+ char header[1000 + 1] =3D { 0 };
+ char footer[1000 + 1] =3D { 0 };
=
if (!snprintf(header, sizeof(header), "-----BEGI= N %s-----", name))
{
@@ -297,8 +2= 94,8 @@

size_t use_len =3D 0;=
mbedtls_pem_context ctx =3D { 0 };
- bool ret =3D mbed_ok(mbedtls_pem_read_buffe= r(&ctx, header, footer, BPTR(&input),
- NULL= , 0, &use_len));
= + bool ret =3D
+ = mbed_ok(mbedtls_pem_read_buffer(&ctx, header, footer, BPTR(&i= nput), NULL, 0, &use_len));
size_t buf_size =3D 0;=
const unsigned char *buf =3D mbedtls_pem_get_buffer(&= amp;ctx, &buf_size);
if (ret && !buf_write= (dst, buf, buf_size))
@@ -328,8 +325,8 @@
= mbedtls_ctr_drbg_context *
rand_ctx_get(void)
{

- static mbed= tls_entropy_context ec =3D {0};
- static mbedtls_ctr_drbg_context cd_ctx =3D {0};
+ static mbedtls_entropy_contex= t ec =3D { 0 };

+ = static mbedtls_ctr_drbg_context cd_ctx =3D { 0 };
stat= ic bool rand_initialised =3D false;

= if (!rand_initialised)
@@ -342,14 +339,15 @@
* 800-90 section 8.7.1). We have very little information at thi= s stage.

* Include Program Name, memory address o= f the context and PID.
*/
- buf_printf(&pers_string, "= OpenVPN %0u %p %s", platform_getpid(), &cd_ctx, time_string(0, 0, = 0, &gc));
+ = buf_printf(&pers_string, "OpenVPN %0u %p %s", platform_getp= id(), &cd_ctx,
+ = time_string(0, 0, 0, &gc));
<= br> /* Initialise mbed TLS RNG, and built-in entropy sources = */
mbedtls_entropy_init(&ec);
=
mbedtls_ctr_drbg_init(&cd_ctx);
- if (!mbed_ok(mbedtls_ctr_d= rbg_seed(&cd_ctx, mbedtls_entropy_func, &ec,

- = BPTR(&pers_string), BLEN(&pers_string))))
+ if (!mbed_ok(mbedtls_ctr_drbg_seed(&a= mp;cd_ctx, mbedtls_entropy_func, &ec, BPTR(&pers_string),+ = BLEN(&pers_string))))
{ msg(M_FATAL, "Failed to initialize random generat= or");
}
@@ -422,12 +420,14 @@=
return false;
}

- const size_t= key_bytelen =3D mbedtls_cipher_info_get_key_bitlen(cipher)/8;
+ const size_t key_bytelen =3D= mbedtls_cipher_info_get_key_bitlen(cipher) / 8;

if (k= ey_bytelen > MAX_CIPHER_KEY_LENGTH)
{
- msg(D_LOW, "Cipher alg= orithm '%s' uses a default key size (%zu bytes) "

+ msg(D_LOW,

+ "Cipher algorith= m '%s' uses a default key size (%zu bytes) "

= "which is larger than " PACKAGE_NAME "'s cur= rent maximum key size "
- "(%d bytes)", ciphername, key_bytelen, MAX_CIP= HER_KEY_LENGTH);
+ = "(%d bytes)",
+ ciphername, key_bytelen, MAX_CIPHER_KEY_LENGTH);
*reason =3D "disabled due to key size too larg= e";
return false;
}
@@ -458,7 +458,7 @@
return 0; }

- return (int)mbedtls_cipher_info_get_key_bitlen(cipher_kt)/8;=
+ return (int)mbe= dtls_cipher_info_get_key_bitlen(cipher_kt) / 8;
}
int
@@ -507,7 +507,7 @@ #ifdef MBEDTLS_CHACHAPOLY_C
|| mbedt= ls_cipher_info_get_type(cipher_kt) =3D=3D MBEDTLS_CIPHER_CHACHA20_POLY1305<= /span>
#endif
- );
+ = );
}

static mbedtls_c= ipher_mode_t
@@ -528,19 +528,21 @@
cipher_= kt_mode_ofb_cfb(const char *ciphername)
{
= const mbedtls_cipher_info_t *cipher =3D cipher_get(ciphername);=
- return cipher &&= (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_OFB
- || cipher_kt_mode(cipher) = =3D=3D OPENVPN_MODE_CFB);
+ return cipher
+ && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_OFB
+ || cip= her_kt_mode(cipher) =3D=3D OPENVPN_MODE_CFB);
}
=
bool
cipher_kt_mode_aead(const ch= ar *ciphername)
{
const mbedtls_ciphe= r_info_t *cipher =3D cipher_get(ciphername);
- return cipher && (cipher_kt_mode(cipher)= =3D=3D OPENVPN_MODE_GCM
+ return cipher
- || cipher_kt_mode(cipher) =3D=3D= MBEDTLS_MODE_CHACHAPOLY
+ || cipher_kt_mode(cipher) =3D=3D MBEDTLS_MODE_CHACHAPOL= Y
#endif
- );
+ );
}


@@ -566,8 +568,8 @@
}
=
void
= -cipher_ctx_init(mbedtls_cipher_context_t *ctx, const uint8_t *key,<= br>- const char *c= iphername, crypto_operation_t enc)
+cipher_ctx_init(mbedtls_cipher_context_t *ctx, const uint8_t= *key, const char *ciphername,
+ crypto_operation_t enc)
{
ASSERT(NULL !=3D ciphername && NULL !=3D ctx);
CLEAR(*ctx);
@@ -612,7 +614,7 @@ return 0;
}
- if (!mbed_ok(mbedtls_ciphe= r_write_tag(ctx, (unsigned char *) tag, tag_len)))
+ if (!mbed_ok(mbedtls_cipher_write_tag(ct= x, (unsigned char *)tag, tag_len)))
{
= return 0;
}
@@ -644,18 +646,2= 0 @@
bool
cipher_ctx_mode_ofb_cfb(const c= ipher_ctx_t *ctx)
{
- return ctx && (cipher_ctx_mode(ctx) =3D=3D OPENV= PN_MODE_OFB
- = || cipher_ctx_mode(ctx) =3D=3D OPENVPN_MODE_CFB);
+ return ctx
+ && (cipher_ctx_mode(ct= x) =3D=3D OPENVPN_MODE_OFB
+ || cipher_ctx_mode(ctx) =3D=3D OPENVPN_MODE_CFB);
}

bool
ci= pher_ctx_mode_aead(const cipher_ctx_t *ctx)
{
- return ctx && (cipher_= ctx_mode(ctx) =3D=3D OPENVPN_MODE_GCM

+ return ctx
+ && (cipher_ctx_mode(ctx) =3D=3D OPENVPN_MOD= E_GCM
#ifdef MBEDTLS_CHACHAPOLY_C
- || cipher_ctx_mode(ctx) =3D= =3D MBEDTLS_MODE_CHACHAPOLY
+ || cipher_ctx_mode(ctx) =3D=3D MBEDTLS_MODE_CHACHAPO= LY
#endif
- );
+ );
}

= int
@@ -691,13 +695,12 @@
}

int
- int *dst_len,= uint8_t *src, int src_len)
+cipher_ctx_update(mbedtls_cipher_context_t *ctx, uint8_t *dst, int = *dst_len, uint8_t *src,
+ int src_len)
{
= size_t s_dst_len =3D *dst_len;

- if (!mbed_ok(mbedtls_cipher_update(ctx, src,= (size_t) src_len, dst,
- &s_dst_len)))
+ if (!mbed_ok(mbedtls_cipher_upda= te(ctx, src, (size_t)src_len, dst, &s_dst_len)))
{=
return 0;
}
= @@ -723,8 +726,8 @@
}

i= nt
-cipher_ctx_final_ch= eck_tag(mbedtls_cipher_context_t *ctx, uint8_t *dst,
- int *dst_len, ui= nt8_t *tag, size_t tag_len)
+cipher_ctx_final_check_tag(mbedtls_cipher_context_t *ctx, uint8_t *= dst, int *dst_len, uint8_t *tag,
+ size_t tag_len)
{<= /span>
size_t olen =3D 0;

@= @ -750,8 +753,7 @@
}
*dst_len =3D= olen;

- = tag_len)))
+ if (!mbed_ok(mbedtls_cipher_check_tag(ctx, (const unsign= ed char *)tag, tag_len)))
{
r= eturn 0;
}
@@ -760,7 +762,6 @@<= br> }


-
/*
* * Generic message digest information functions
@@= -781,10 +782,10 @@
}
if (mbedtls= _md_get_size(md) > MAX_HMAC_KEY_LENGTH)
{- msg(M_FATAL, "Mess= age hash algorithm '%s' uses a default hash size (%d bytes) which i= s larger than " PACKAGE_NAME "'s current maximum hash size (%= d bytes)",
- = digest,
- = mbedtls_md_get_size(md),
- MAX_HMAC_KEY_LENGTH);
+ msg(M_FATAL,
+ "Message hash algorithm '%s'= uses a default hash size (%d bytes) which is larger than " PACKAGE_NA= ME
+ "= ;'s current maximum hash size (%d bytes)",
+ digest, mbedtls_md_get_size(m= d), MAX_HMAC_KEY_LENGTH);
}
retur= n md;
}
@@ -792,7 +793,7 @@
bool

md_valid(const char *digest)
{
- const mbedtls_md_inf= o_t *md =3D mbedtls_md_info_from_string(digest);
+ const mbedtls_md_info_t *md =3D mbedtls_m= d_info_from_string(digest);
return md !=3D NULL;
}

@@ -967,8 +968,8 @@<= br> * via its APIs like OpenSSL does with CRYPTO_memcmp * Adapt the function that mbedtls itself uses in
* mbedtls_safer_memcmp as it considers that to be safe */
<= br>- volatile const unsigned c= har *A =3D (volatile const unsigned char *) a;
- volatile const unsigned char *B =3D (volatile = const unsigned char *) b;
+ volatile const unsigned char *A =3D (volatile const unsigned char= *)a;
+ volatile c= onst unsigned char *B =3D (volatile const unsigned char *)b;
volatile unsigned char diff =3D 0;


for (size_t i =3D 0; i < size; i++)

@@ -983,12 +98= 4,11 @@
* from recent versions, so we use our own impleme= ntation if necessary. */
#if defined(HAVE_MBEDTLS_SSL_TLS_= PRF) && defined(MBEDTLS_SSL_TLS_PRF_TLS1)
bool
-ssl_tls1_PRF(const uint8_= t *seed, int seed_len, const uint8_t *secret,
- int secret_len, uint8_t *output, int o= utput_len)
+ssl_tls1_= PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int secret_le= n,
+ uint= 8_t *output, int output_len)
{
- return mbed_ok(mbedtls_ssl_tls_prf(MBEDTLS_SS= L_TLS_PRF_TLS1, secret,
- secret_len, "", seed, se= ed_len, output,
- = output_len));
+ return mbed_ok(mbedtls_ssl_tls_prf(MBEDTLS_S= SL_TLS_PRF_TLS1, secret, secret_len, "", seed,
+ = seed_len, output, output_len));
}
#else = /* defined(HAVE_MBEDTLS_SSL_TLS_PRF) && defined(MBEDTLS_SSL_TLS_PRF= _TLS1) */
/*
@@ -1003,8 +1003,8 @@<= br> * @param olen Length of the output buffer
*/

static void
-tls1_P_hash(const mbedtls_md_info_t *md_kt, const uint8_t *s= ec, int sec_len,
- = const uint8_t *seed, int seed_len, uint8_t *out, int olen)+tls1_P_hash(const mbedtls_md_= info_t *md_kt, const uint8_t *sec, int sec_len, const uint8_t *seed,=
+ int seed_len, = uint8_t *out, int olen)
{
struct gc_a= rena gc =3D gc_new();
uint8_t A1[MAX_HMAC_KEY_LENGTH];=
@@ -1038,7 +1038,7 @@
hmac_ctx_update= (ctx, seed, seed_len);
hmac_ctx_final(ctx, A1);=

- for (;= ; )
+ for (;;)
{
hmac_ctx_reset(ctx); hmac_ctx_reset(ctx_tmp);
@@ -1053,7 +1053,7= @@
olen -=3D chunk;
= hmac_ctx_final(ctx_tmp, A1); /* calc the next A1 value */
}

- = else /* last one */
-ssl_tls1_PRF(const uint8_t *label, int label_len, = const uint8_t *sec,
- = int slen, uint8_t *out1, int olen)
+ssl_tls1_PRF(const uint8_t *label, int label_len,= const uint8_t *sec, int slen, uint8_t *out1,
+ int olen)
{<= br> struct gc_arena gc =3D gc_new();
const m= d_kt_t *md5 =3D md_get("MD5");
@@ -1099,15 +1099,= 15 @@

uint8_t *out2 =3D (uint8_t *)g= c_malloc(olen, false, &gc);

- int len =3D slen/2;
+ int len =3D slen / 2;
const uint8_t *S1 =3D sec;

const uint8_t *S2 =3D= &(sec[len]);
- = len +=3D (slen&1); /* add for odd, make longer */
+ len +=3D (slen & 1); /* add for o= dd, make longer */

tls1_P_hash(md5, = S1, len, label, label_len, out1, olen);
tls1_P_hash(sh= a1, S2, len, label, label_len, out2, olen);

- for (int i =3D 0; i<olen; i+= +)

+ for (int i = =3D 0; i < olen; i++)
{
ou= t1[i] ^=3D out2[i];
}
diff --git a/src= /openvpn/crypto_mbedtls.h b/src/openvpn/crypto_mbedtls.h
in= dex 6575bad..fceae43 100644
--- a/src/openvpn/crypto_mbedtl= s.h
+++ b/src/openvpn/crypto_mbedtls.h
@@ -= 51,32 +51,32 @@
typedef void provider_t;
=
/** Maximum length of an IV */
-#define OPENVPN_MAX_IV_LENGTH MBEDTLS_MAX_IV_L= ENGTH
+#define OPENVP= N_MAX_IV_LENGTH MBEDTLS_MAX_IV_LENGTH

/*= * Cipher is in CBC mode */
-#define OPENVPN_MODE_CBC MBEDTLS_MODE_CBC
+#define OPENVPN_MODE_CBC MBEDTLS_MODE_CBC=

/** Cipher is in OFB mode */
= -#define OPENVPN_MODE_OFB = MBEDTLS_MODE_OFB
+#de= fine OPENVPN_MODE_OFB MBEDTLS_MODE_OFB

/= ** Cipher is in CFB mode */
-#define OPENVPN_MODE_CFB MBEDTLS_MODE_CFB
+#define OPENVPN_MODE_CFB MBEDTLS_MODE_CF= B

/** Cipher is in GCM mode */-#define OPENVPN_MODE_GCM = MBEDTLS_MODE_GCM
+#d= efine OPENVPN_MODE_GCM MBEDTLS_MODE_GCM

= typedef mbedtls_operation_t crypto_operation_t;
/** Cipher should encrypt */
-#define OPENVPN_OP_ENCRYPT MBEDTLS_ENCRYPT
+#define OPENVPN_OP_ENCRYPT MBEDT= LS_ENCRYPT


/** Cipher should decrypt */<= /span>
-#define OPENVPN_OP_DEC= RYPT MBEDTLS_DECRYPT
+#define OPENVPN_OP_DECRYPT MBEDTLS_DECRYPT
-#define MD4_DIGEST_LENGTH = 16
-#define MD5_DIGES= T_LENGTH 16
-#def= ine SHA_DIGEST_LENGTH 20
-#define SHA256_DIGEST_LENGTH 32
+#define MD4_DIGEST_LENGTH 16
+#define MD5_DIGEST_LENGTH 16<= br>+#define SHA_DIGEST_LENGTH = 20
+#define SHA256_= DIGEST_LENGTH 32

/**
*= Returns a singleton instance of the mbed TLS random number generator.
@@ -119,13 +119,11 @@
*
* @= returns true if no errors are detected, false otherwise.
= */
-bool mbed_log_func_= line(unsigned int flags, int errval, const char *func,
- int line);<= br>+bool mbed_log_func_line(uns= igned int flags, int errval, const char *func, int line);
=
/** Wraps mbed_log_func_line() to prevent function calls = for non-errors */
static inline bool
-mbed_log_func_line_lite(unsigned int flags,= int errval,
- = const char *func, int line)
+mbed_log_func_line_lite(unsigned int flags, int errv= al, const char *func, int line)
{
if = (errval)
{
@@ -146,7 +144,6 @@<= br> *
* @returns true if no errors are detected, f= alse otherwise.
*/
-#define mbed_ok(errval) \
- mbed_log_func_line_lite(D_CRYPT_ERRORS, errval, __fu= nc__, __LINE__)
+#def= ine mbed_ok(errval) mbed_log_func_line_lite(D_CRYPT_ERRORS, errval, __func_= _, __LINE__)

#endif /* CRYPTO_MBEDTLS_H_= */
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn= /crypto_openssl.c
index 88b3580..903c291 100644
<= span>--- a/src/openvpn/crypto_openssl.c

+++ b/src/openvpn/c= rypto_openssl.c
@@ -64,7 +64,7 @@
<= br> #ifdef _MSC_VER
/* mute ossl3 deprecation warnin= gs treated as errors in msvc */
-#pragma warning(disable: 4996)
+#pragma warning(disable : 4996)
#endi= f

/*
@@ -119,22 +119,17 = @@
ENGINE_register_all_complete();
<= span> return NULL;

}
- if ((e =3D ENGINE_by_id(engine)= ) =3D=3D NULL
- = && (e =3D try_load_engine(engine)) =3D=3D NULL)
+ if ((e =3D ENGINE_by_id(eng= ine)) =3D=3D NULL && (e =3D try_load_engine(engine)) =3D=3D NULL)
{
- crypto_msg(M_FATAL, "OpenSSL error: cannot load engine= '%s'",
- = engine);
+ crypto_msg(M_FATAL, "OpenSSL error: cannot load= engine '%s'", engine);
}
<= span>

if (!ENGINE_set_default(e, ENGINE_METHOD_AL= L))
{
- crypto_msg(M_FATAL,
- "OpenSSL error: ENGINE_set_d= efault failed on engine '%s'",
- engine);
+ crypto_msg(M_FATAL, "Ope= nSSL error: ENGINE_set_default failed on engine '%s'", engine)= ;
}

- msg(M_INFO, "Initializing OpenSSL sup= port for engine '%s'",
- ENGINE_get_id(e));
+ msg(M_INFO, "Initializing OpenSSL sup= port for engine '%s'", ENGINE_get_id(e));
= }
return e;
}
@@ -15= 2,7 +147,7 @@
engine_persist =3D setup_engine(engi= ne_name);
engine_initialized =3D true;
<= span> }

-#else /* = if HAVE_OPENSSL_ENGINE */
+#else /* if HAVE_OPENSSL_ENGINE */
msg(M_WARN, &= quot;Note: OpenSSL hardware crypto engine functionality is not available&qu= ot;);
#endif
}
@@ -168,7 = +163,7 @@
crypto_msg(M_FATAL, "failed to load= provider '%s'", provider);
}
<= span> return prov;

= -#else /* OPENSSL_VERSION_NUMBER >=3D 0x30000000L */
+#else /* OPENSSL_VERSION_NUMBER >= =3D 0x30000000L */
msg(M_WARN, "Note: OpenSSL pro= vider functionality is not available");
return NU= LL;
#endif
@@ -250,12 +245,13 @@ if (ERR_GET_REASON(err) =3D=3D SSL_R_NO_SHARED_CIPHER)
{
msg(D_CRYPT_ERRORS, &qu= ot;TLS error: The server has no TLS ciphersuites "
- "in common with the = client. Your --tls-cipher setting might be "
- "too restrictive.");<= /span>
+ = "in common with the client. Your --tls-cipher setting migh= t be "
+ = "too restrictive.");
= }
else if (ERR_GET_REASON(err) =3D=3D SSL_R_U= NSUPPORTED_PROTOCOL)
{
- msg(D_CRYPT_ERRORS, "TLS error: = Unsupported protocol. This typically "
+ msg(D_CRYPT_ERRORS,
+ "TLS error: Unsupp= orted protocol. This typically "
&quo= t;indicates that client and server have no common TLS version enabled. &quo= t;
"This can be caused by mismatched = tls-version-min and tls-version-max "
= "options on client and server. "
@@ -271,8 +267,= 8 @@
}
else
{

- = msg(flags, "OpenSSL: %s:%s:%s:%d:%s", ERR_error_string(err, N= ULL),
- = data, file, line, func);
+ msg(flags, "OpenSSL: %s:%s:%s:%d:%s", ERR_error_= string(err, NULL), data, file, line,
+ func);
} }
}
@@ -308,9 +304,7 @@
void
crypto_init_dmalloc(void)
{

- CRYPTO_set_mem= _ex_functions(crypto_malloc,
- crypto_realloc,
- crypto_fre= e);
+ CRYPTO_set_m= em_ex_functions(crypto_malloc, crypto_realloc, crypto_free);
}

#endif /* DMALLOC */

@@ -333,7 +327,8 @@

return strcmp(EVP_CIPHER_get0_na= me(*cipher_a), EVP_CIPHER_get0_name(*cipher_b));
}<= br>
-struct coll= ect_ciphers {
+struct= collect_ciphers
+{
/* If we ever exceed this, we must be more selective */=
const EVP_CIPHER *list[1000];
si= ze_t num;
@@ -355,12 +350,12 @@
const char *ciphername =3D EVP_CIPHER_get0_name(cipher);=

- if (ci= phername && (cipher_kt_mode_cbc(ciphername)
+ if (ciphername
+ && (cipher_kt_mode_cbc(ci= phername)
#ifdef ENABLE_OFB_CFB_MODE
- || cipher_kt_mode_of= b_cfb(ciphername)
+ = || cipher_kt_mode_ofb_cfb(ciphername)
#endif
- ||= cipher_kt_mode_aead(ciphername)
- ))
+ || cipher_kt_mode_aead(ciphername))) {
cipher_list->list[cipher_list->= ;num++] =3D cipher;
}
@@ -394,17 +389,= 18 @@
{
cipher =3D EV= P_get_cipherbyname(name);
}
-#else /* if defined(LIBRESSL_VERSION_NUMBE= R) */
+#else /* if de= fined(LIBRESSL_VERSION_NUMBER) */
const EVP_CIPHER= *cipher =3D EVP_get_cipherbynid(nid);
#endif
/* We cast the const away so we can keep the function prototyp= e

* compatible with EVP_CIPHER_do_all_provided */=
- collect_ciphe= rs((EVP_CIPHER *) cipher, &cipher_list);
+ collect_ciphers((EVP_CIPHER *)cipher, &= ;cipher_list);
}
#endif

/* cast to non-const to prevent warning */=
- qsort((EVP_CIPHER *)ciph= er_list.list, cipher_list.num, sizeof(*cipher_list.list), cipher_name_cmp);=
+ qsort((EVP_CIPH= ER *)cipher_list.list, cipher_list.num, sizeof(*cipher_list.list),+ cipher_name_cmp);<= /span>

for (size_t i =3D 0; i < cipher_l= ist.num; i++)
{
@@ -437,8 +433,8 @@
show_available_digests(void)
{
#ifndef ENABLE_SMALL

- printf("The following message digests are available for use wi= th\n"
- = PACKAGE_NAME ". A message digest is used in conjunction with\n"<= /span>
+ printf("The= following message digests are available for use with\n" PACKAGE_NAME<= /span>
+ ". = A message digest is used in conjunction with\n"
= "the HMAC function, to authenticate received packets.\n"
"You can specify a message digest as paramet= er to\n"
"the --auth option.\n")= ;
@@ -487,21 +483,19 @@
e =3D ENGINE_g= et_first();
while (e)
{- printf("%s [%s]\n&= quot;,
- = ENGINE_get_name(e),
- = ENGINE_get_id(e));
+ printf("%s [%s]\n", ENGINE_get_name(e), ENGIN= E_get_id(e));
e =3D ENGINE_get_next(e);
= }
ENGINE_cleanup();
-#else /* if HAVE_OPENSSL_ENGINE */<= br>+#else /* if HAVE_OPENSSL_EN= GINE */
printf("Sorry, OpenSSL hardware crypto en= gine functionality is not available.\n");
#endif
}


bool
-crypto_pem_encode(const = char *name, struct buffer *dst,
- const struct buffer *src, struct gc_arena *gc)<= /span>
+crypto_pem_encode(co= nst char *name, struct buffer *dst, const struct buffer *src,
+ struct gc_arena= *gc)

{
bool ret =3D false; BIO *bio =3D BIO_new(BIO_s_mem());
@@ -528,8 +5= 22,7 @@
}

bool-crypto_pem_decode(const char *= name, struct buffer *dst,
- const struct buffer *src)
+crypto_pem_decode(const char *name, struct buff= er *dst, const struct buffer *src)
{
= bool ret =3D false;

@@ -543,8 +536,7 @@
char *header_read =3D NULL;
uint8_= t *data_read =3D NULL;
long data_read_len =3D 0;
- if (!PEM_read_bio(bio, = &name_read, &header_read, &data_read,
- &data_read_len))
+ if (!PEM_read_bio(bi= o, &name_read, &header_read, &data_read, &data_read_len))
{
dmsg(D_CRYPT_ERRORS, "%= s: PEM decode failed", __func__);
goto cleanu= p;
@@ -552,17 +544,16 @@

= if (strcmp(name, name_read))
{
- dmsg(D_CRYPT_ERRORS,
<= span style=3D"color: hsl(0, 100%, 40%);">- "%s: unexpected= PEM name (got '%s', expected '%s')",

- __func__, name_read, name= );
+ dmsg(D_CR= YPT_ERRORS, "%s: unexpected PEM name (got '%s', expected '= %s')", __func__,
+ name_read, name);
goto cleanup;=
}

uint8_t *dst= _data =3D buf_write_alloc(dst, data_read_len);
if (!ds= t_data)
{
- dmsg(D_CRYPT_ERRORS, "%s: dst too small (%i, needs %l= i)", __func__,
- = BCAP(dst), data_read_len);
+ dmsg(D_CRYPT_ERRORS, "%s: dst too small (%i,= needs %li)", __func__, BCAP(dst),
+ data_read_len);
g= oto cleanup;
}
memcpy(dst_data, d= ata_read, data_read_len);
@@ -633,18 +624,21 @@
<= span>

if (FIPS_mode() && !(EVP_CIPHER_flags(c= ipher) & EVP_CIPH_FLAG_FIPS))
{
- msg(D_LOW, "Cipher algorith= m '%s' is known by OpenSSL library but "
- "currently disabled by run= ning in FIPS mode.", ciphername);
+ msg(D_LOW,
+ "Cipher algorithm '%s' is known = by OpenSSL library but "
+ "currently disabled by running in FIPS mode.&quo= t;,
+ ciph= ername);
*reason =3D "disabled by FIPS mode&q= uot;;
goto out;
}
<= span> #endif

if (EVP_CIPHER_key_length(cipher) > MA= X_CIPHER_KEY_LENGTH)
{
- msg(D_LOW, "Cipher algorithm '%s'= ; uses a default key size (%d bytes) "
+ msg(D_LOW,
+ "Cipher algorithm '%s' uses= a default key size (%d bytes) "
"wh= ich is larger than " PACKAGE_NAME "'s current maximum key siz= e "
- &= quot;(%d bytes)", ciphername, EVP_CIPHER_key_length(cipher),- MAX_CIPHER_KEY_LENG= TH);
+ &qu= ot;(%d bytes)",
= + ciphername, EVP_CIPHER_key_length(cipher), MAX_CIPHER_KEY_LENG= TH);
*reason =3D "disabled due to key size to= o large";
goto out;
}
@@ -759,7 +753,6 @@
bool
ci= pher_kt_insecure(const char *ciphername)
{
-

if (cipher_kt_b= lock_size(ciphername) >=3D 128 / 8)
{
return false;

@@ -791,12 +784,13 @@
<= span> {

evp_cipher_type *cipher =3D cipher_get(ciphern= ame);

- bool ret =3D cipher && (cipher_kt_mode(cipher) =3D=3D OPENVPN= _MODE_CBC
- = /* Exclude AEAD cipher modes, they require a different API */=
+ bool ret =3D ci= pher
+ = && (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_CBC
+ /* Exclude AEAD cipher modes, th= ey require a different API */
#ifdef EVP_CIPH_FLAG_CTS
- = && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CTS)
<= span style=3D"color: hsl(120, 100%, 40%);">+ && != (EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CTS)

#endif<= /span>
- = && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER))= ;
+ = && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER));
EVP_CIPHER_free(cipher);
return re= t;
}
@@ -805,8 +799,9 @@
= cipher_kt_mode_ofb_cfb(const char *ciphername)
{ evp_cipher_type *cipher =3D cipher_get(ciphername);
<= span style=3D"color: hsl(0, 100%, 40%);">- bool ofb_cfb =3D cipher &= & (cipher_kt_mode(cipher) =3D=3D OPENVPN_MODE_OFB

- || cipher_kt_= mode(cipher) =3D=3D OPENVPN_MODE_CFB)
+ bool ofb_cfb =3D cipher
+ && (cipher_kt_mode(cip= her) =3D=3D OPENVPN_MODE_OFB
+ || cipher_kt_mode(cipher) =3D=3D OPENVPN_MO= DE_CFB)
/* Exclude AEAD cipher modes, t= hey require a different API */
&&am= p; !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER);
<= span> EVP_CIPHER_free(cipher);

@@ -829,7 +824,7 @@
#ifdef NID_chacha20_poly1305
if (EVP_= CIPHER_nid(cipher) =3D=3D NID_chacha20_poly1305)
{=
- isaead = =3D true;
+ = isaead =3D true;
}
#endif
}
@@ -860,8 +855,8 @@
}

void
-cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *key,
- const c= har *ciphername, crypto_operation_t enc)
+cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *ke= y, const char *ciphername,
+ crypto_operation_t enc)
{ ASSERT(NULL !=3D ciphername && NULL !=3D ctx); evp_cipher_type *kt =3D cipher_get(ciphername);
@@ -914,7 +909,7 @@

int mode =3D EVP_CIPHER_CTX_mode= (ctx);

return mode =3D=3D EVP_CIPH_C= BC_MODE
- /* = Exclude AEAD cipher modes, they require a different API */
+ /* Exclude AEAD cipher modes, th= ey require a different API */
#ifdef EVP_CIPH_FLAG_CTS
&& !(flags & EVP_CIPH_FLAG_CTS)=
#endif
@@ -977,8 +972,7 @@
}

int
-cipher_ctx_update(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *ds= t_len,
- = uint8_t *src, int src_len)
+cipher_ctx_update(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len= , uint8_t *src, int src_len)
{
if (!E= VP_CipherUpdate(ctx, dst, dst_len, src, src_len))
{
@@ -994,8 +988,8 @@
}

int
-ciphe= r_ctx_final_check_tag(EVP_CIPHER_CTX *ctx, uint8_t *dst, int *dst_len,
- = uint8_t *tag, size_t tag_len)
+cipher_ctx_final_check_tag(EVP_CIPHER_CTX *ctx, uint8_t *dst, in= t *dst_len, uint8_t *tag,
+ size_t tag_len)
{<= br> ASSERT(tag_len < SIZE_MAX);
if (!EVP_= CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, tag_len, tag))
= @@ -1026,7 +1020,8 @@
}
if (EVP_M= D_size(md) > MAX_HMAC_KEY_LENGTH)
{
- crypto_msg(M_FATAL, "Mes= sage hash algorithm '%s' uses a default hash "

+ crypto_msg(M_FATAL,
<= br>+ "Me= ssage hash algorithm '%s' uses a default hash "
"size (%d bytes) which is larger than " PAC= KAGE_NAME "'s current "

&= quot;maximum hash size (%d bytes)",
= digest, EVP_MD_size(md), MAX_HMAC_KEY_LENGTH);
@@ -1052,1= 7 +1047,12 @@
* this translation table for forward lookup= , only for returning the name
* with md_kt_name() */
const cipher_name_pair digest_name_translation_table[] =3D {
- { "BLAKE2s256&= quot;, "BLAKE2S-256"},
- { "BLAKE2b512", "BLAKE2B-512"},- { "RIPEMD160", &= quot;RIPEMD-160" },
- { "SHA256", "SHA2-256&qu= ot;},
- { "SHA3= 84", "SHA2-384"},
- { "SHA512", "SHA2-512"},
- { "SHA512-224", "S= HA2-512/224"},

- = { "SHA512-256", "SHA2-512/256"},
- { "SHAKE128", "SHAKE-12= 8"},
- { "= SHAKE256", "SHAKE-256"},
+ { "BLAKE2s256", "BLAKE2S-256" }= , { "BLAKE2b512", "BLAKE2B-512" },
+ { "RIPEMD160", "RIPE= MD-160" }, { "SHA224", "SHA2-224" },
= + { "SHA256", &quo= t;SHA2-256" }, { "SHA384", "SHA2-384" },
+ { "SHA512&qu= ot;, "SHA2-512" }, { "SHA512-224", "SHA2-5= 12/224" },
+ = { "SHA512-256", "SHA2-512/256" }, { "SHAKE128"= ;, "SHAKE-128" },
+ { "SHAKE256", "SHAKE-256" },
};

const size_t digest_name_translation_table_count =3D=
sizeof(digest_name_translation_table) / sizeof(*diges= t_name_translation_table);
@@ -1099,7 +1089,7 @@
= return 0;
}
evp_md= _type *kt =3D md_get(mdname);
- unsigned char size =3D (unsigned char)EVP_MD_size(kt);<= br>+ unsigned char size =3D = (unsigned char)EVP_MD_size(kt);
EVP_MD_free(kt);
return size;
}
@@ -1287,10= +1277,8 @@
* only used for lookup so we cast (as Ope= nSSL also does internally)
* the constness away here.=
*/
- ctx->params[0] =3D OSSL_PARAM_construct_utf8_string("digest= ",
- = (char *) EVP_MD_get0_name(kt), 0);<= /span>
- ctx->params[1] = =3D OSSL_PARAM_construct_octet_string("key",
- = ctx->key, EVP_MD_size(kt));
+ ctx->params[0] =3D OSSL_PARAM_construct_utf8= _string("digest", (char *)EVP_MD_get0_name(kt), 0);
+ ctx->params[1] =3D OSSL_PA= RAM_construct_octet_string("key", ctx->key, EVP_MD_size(kt));<= /span>
ctx->params[2] =3D OSSL_PARAM_construct_end();

if (!EVP_MAC_init(ctx->ctx, NULL, 0, = ctx->params))
@@ -1349,8 +1337,8 @@
}
#if (OPENSSL_VERSION_NUMBER >=3D 0x30000000L) &&= !defined(LIBRESSL_VERSION_NUMBER)
bool
-ssl_tls1_PRF(const uint8_t *seed, int se= ed_len, const uint8_t *secret,
- int secret_len, uint8_t *output, int output_len)
+ssl_tls1_PRF(const uint8= _t *seed, int seed_len, const uint8_t *secret, int secret_len,
+ uint8_t *output, in= t output_len)

{
bool ret =3D true;
EVP_KDF_CTX *kctx =3D NULL;
@@ -1373,18 = +1361,18 @@

/* The OpenSSL APIs requ= ire us to cast the const aways even though the
* stri= ngs are never changed and only read */
- params[0] =3D OSSL_PARAM_construct_utf8_string(OSSL_KD= F_PARAM_DIGEST,
- = SN_md5_sha1, strlen(SN_md5_sha1)= );
- params[1] =3D O= SSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
- = (uint8_t *) secret, (size_t) secret_len);
- params[2] =3D OSSL_PARAM_construct_octet_s= tring(OSSL_KDF_PARAM_SEED,
- (uint8_t *) seed, (s= ize_t) seed_len);
+ = params[0] =3D
+ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, SN_md5_sha1, st= rlen(SN_md5_sha1));
+= params[1] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET, = (uint8_t *)secret,
+ = (size_t)secret_len);
+ params[2] =3D<= br>+ OSSL_PARAM_construc= t_octet_string(OSSL_KDF_PARAM_SEED, (uint8_t *)seed, (size_t)seed_len);

params[3] =3D OSSL_PARAM_construct_end();

if (EVP_KDF_derive(kctx, output, output_len, params= ) <=3D 0)
{
crypto_msg(D_T= LS_DEBUG_LOW, "Generating TLS 1.0 PRF using "
- "EVP_KDF_derive f= ailed");
+ = "EVP_KDF_derive failed"); goto err;
}
@@ -1400,15 +1388,15 @@
}
#elif d= efined(OPENSSL_IS_AWSLC)
bool
-ssl_tls1_PRF(const uint8_t *label, int label_len, = const uint8_t *sec,
- = int slen, uint8_t *out1, int olen)
+ssl_tls1_PRF(const uint8_t *label, int label_len,= const uint8_t *sec, int slen, uint8_t *out1,
+ int olen)
{<= br> CRYPTO_tls1_prf(EVP_md5_sha1(), out1, olen, sec, slen, label,= label_len, NULL, 0, NULL, 0);
}
#elif !d= efined(LIBRESSL_VERSION_NUMBER) && !defined(ENABLE_CRYPTO_WOLFSSL)<= /span>
bool
-= ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret,
- int secret_le= n, uint8_t *output, int output_len)
+ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8= _t *secret, int secret_len,
+ uint8_t *output, int output_len)
{
EVP_PKEY_CTX *pctx =3D EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1= _PRF, NULL);
if (!pctx)
@@ -1456,8 +14= 44,8 @@
* OpenSSL does. As result they will only be able = to support
* peers that support TLS EKM like when running= with OpenSSL 3.x FIPS */
bool
-ssl_tls1_PRF(const uint8_t *label, int label_len,= const uint8_t *sec,
- = int slen, uint8_t *out1, int olen)
+ssl_tls1_PRF(const uint8_t *label, int label_len= , const uint8_t *sec, int slen, uint8_t *out1,
+ int olen)
{=
return false;
}
diff --git = a/src/openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h
index 85f53f6..3e0067c 100644

--- a/src/openvpn/crypto_o= penssl.h
+++ b/src/openvpn/crypto_openssl.h
@@ -51,7 +51,8 @@

/* Use a dummy type for the provider */=
typedef void provider_t;
#else-typedef struct {
+typedef struct

+{
OSSL_PARAM param= s[3];
uint8_t key[EVP_MAX_KEY_LENGTH];
EVP_MAC_CTX *ctx;

@@ -72,29 +73,29 @@
#endif


/** Maximum length of an IV */<= /span>
-#define OPENVPN_MAX_IV= _LENGTH EVP_MAX_IV_LENGTH
+#define OPENVPN_MAX_IV_LENGTH EVP_MAX_IV_LENGTH

/** Cipher is in CBC mode */
-#define OPENVPN_MODE_CBC EVP_CIPH_CBC_MODE
+#define OPENVPN_MODE_C= BC EVP_CIPH_CBC_MODE

/** Cipher is in OF= B mode */
-#define OPEN= VPN_MODE_OFB EVP_CIPH_OFB_MODE
+#define OPENVPN_MODE_OFB EVP_CIPH_OFB_MODE

/** Cipher is in CFB mode */
-#define OPENVPN_MODE_CFB EVP_CIPH_CFB_MO= DE
+#define OPENVPN_M= ODE_CFB EVP_CIPH_CFB_MODE

/** Cipher is = in GCM mode */
-#define= OPENVPN_MODE_GCM EVP_CIPH_GCM_MODE
+#define OPENVPN_MODE_GCM EVP_CIPH_GCM_MODE
typedef int crypto_operation_t;
=
/** Cipher should encrypt */
-#define OPENVPN_OP_ENCRYPT 1
+#define OPENVPN_OP_ENCRYPT 1<= br>
/** Cipher should decrypt */
-#define OPENVPN_OP_DECRYPT 0=
+#define OPENVPN_OP_DECRYPT= 0

-#= define MD4_DIGEST_LENGTH 16
+#define MD4_DIGEST_LENGTH 16

/**

* Retrieve any occurred OpenSSL errors and print t= hose errors.
@@ -113,10 +114,11 @@
* @par= am flags Flags to indicate error type and priority.
* @param ... Format string and optional format arguments
*/
-#defin= e crypto_msg(flags, ...) \
- do { \
+#def= ine crypto_msg(flags, ...) \
+ do = \
+ {= \
= crypto_print_openssl_errors(nonfatal(flags)); \
- msg((flags), __VA_ARGS__); \
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg((flags), __VA_ARGS_= _); \

} while (false)

#endif /* CRYPTO_OPENSSL_H_ */
diff -= -git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c
in= dex 67dc382..d91d9a1 100644
--- a/src/openvpn/cryptoapi.c
+++ b/src/openvpn/cryptoapi.c
@@ -62,11 +62,= 12 @@
return 0;
}

-#else /* HAVE_XKEY_PROV= IDER */
+#else /* HA= VE_XKEY_PROVIDER */

static XKEY_EXTERNAL= _SIGN_fn xkey_cng_sign;

-typedef struct _CAPI_DATA {
+typedef struct _CAPI_DATA
+{
const CERT_CONTEXT= *cert_context;
HCRYPTPROV_OR_NCRYPT_KEY_HANDLE crypt_= prov;
EVP_PKEY *pubkey;
@@ -112,7 +113= ,7 @@
break;

default:

- = msg(M_WARN|M_INFO, "cryptoapicert: Unknown hash type NID=3D0x= %x", md_type);
+= msg(M_WARN | M_INFO, "cryptoapicert: Unknown hash type NID= =3D0x%x", md_type);
break;
}

return alg;
@@ -157,7 +158,7 = @@
parse_hexstring(const char *p, unsigned char *arr, size= _t capacity)
{
int i =3D 0;- for ( ; *p && i <= ; capacity; p +=3D 2)
+ for (; *p && i < capacity; p +=3D 2)
= {
/* skip spaces */
while= (*p =3D=3D ' ')
@@ -169,8 +170,7 @@
break;

}
- if (!isxdigit(p[0]) ||= !isxdigit(p[1])
- = || sscanf(p, "%2hhx", &arr[i++]) !=3D 1)
+ if (!isxdigit(p[0]) || !i= sxdigit(p[1]) || sscanf(p, "%2hhx", &arr[i++]) !=3D 1)
=
{
return 0;
}

@@ -179,21 +179,21 @@
}=

static void *
-decode_object(struct gc_arena *gc, LPCSTR struct_type,=
- const C= RYPT_OBJID_BLOB *val, DWORD flags, DWORD *cb)
+decode_object(struct gc_arena *gc, LPCSTR struct_= type, const CRYPT_OBJID_BLOB *val, DWORD flags,
+ DWORD *cb)
{
/* get byte count for decoding */
BY= TE *buf;
- if (!Cryp= tDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, struct_type,<= br>- va= l->pbData, val->cbData, flags, NULL, cb))
+ if (!CryptDecodeObject(X509_ASN_ENCODING | = PKCS_7_ASN_ENCODING, struct_type, val->pbData,
+ val->cbData, fl= ags, NULL, cb))
{
return NULL= ;
}

/* do the a= ctual decode */
buf =3D gc_malloc(*cb, false, gc);
- if (!CryptDecodeObjec= t(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, struct_type,
- val->pbData= , val->cbData, flags, buf, cb))
+ if (!CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_EN= CODING, struct_type, val->pbData,
+ val->cbData, flags, buf, cb)= )
{
return NULL;
}

@@ -243,8 +243,8 @@
= return true;
}
- const CRYPT_OID_IN= FO *tmpl_oid =3D find_oid(CRYPT_OID_INFO_NAME_KEY, tmpl_name,
- = CRYPT_TEMPLATE_OID_GROUP_ID);

+ const CRYPT_OID_INFO *tmpl_oid =3D=
+ fin= d_oid(CRYPT_OID_INFO_NAME_KEY, tmpl_name, CRYPT_TEMPLATE_OID_GROUP_ID);
if (tmpl_oid && !stricmp(tmpl_oid->psz= OID, cte->pszObjId))
{
= /* found OID match in extension against resolved key */=
@@ -274,7 +274,7 @@
DWORD find_type;<= br> const void *find_param;
unsigned char ha= sh[255];
- CRYPT_HAS= H_BLOB blob =3D {.cbData =3D 0, .pbData =3D hash};
+ CRYPT_HASH_BLOB blob =3D { .cbData =3D 0= , .pbData =3D hash };
struct gc_arena gc =3D gc_new();=

if (!strncmp(cert_prop, "SUBJ:= ", 5))
@@ -296,7 +296,7 @@
bl= ob.cbData =3D parse_hexstring(cert_prop + 6, hash, sizeof(hash)); if (blob.cbData =3D=3D 0)
{=
- msg(M_WARN|M_INF= O, "WARNING: cryptoapicert: error parsing <%s>.", cert_prop= );
+ msg(M= _WARN | M_INFO, "WARNING: cryptoapicert: error parsing <%s>.&quo= t;, cert_prop);
goto out;
= }
}
@@ -308,7 +308,8 @@ }
else
{
- msg(M_NONFATAL, "Erro= r in cryptoapicert: unsupported certificate specification <%s>",= cert_prop);

+ = msg(M_NONFATAL, "Error in cryptoapicert: unsupported certificate spec= ification <%s>",
+ cert_prop);
goto out; }

@@ -316,15 +317,14 @@
{
int validity =3D 1;
<= span> /* this frees previous rv, if not NULL */

- rv =3D CertFindCertificateInStore= (cert_store, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
- 0, = find_type, find_param, rv);
+ rv =3D CertFindCertificateInStore(cert_store, X509_ASN_ENCO= DING | PKCS_7_ASN_ENCODING, 0,
+ find_type, find_param, r= v);
if (!rv)
{
= break;
}
= /* if searching by template name, check now if it matches */
<= span style=3D"color: hsl(0, 100%, 40%);">- if (find_type =3D=3D CERT= _FIND_HAS_PRIVATE_KEY

-= && !test_certificate_template(cert_prop, rv))+ if (find_type =3D=3D = CERT_FIND_HAS_PRIVATE_KEY && !test_certificate_template(cert_prop, = rv))
{
continue;
}
@@ -333,7 +333,7 @@
= {
break;
}
- msg(M_WARN|M_IN= FO, "WARNING: cryptoapicert: ignoring certificate in store %s.",<= /span>
+ msg(M_WARN |= M_INFO, "WARNING: cryptoapicert: ignoring certificate in store %s.&qu= ot;,
validity < 0 ? "not yet valid&quo= t; : "that has expired");
}
=
@@ -356,12 +356,12 @@
if (status != =3D ERROR_SUCCESS)
{
SetLastE= rror(status);
- = msg(M_NONFATAL|M_ERRNO, "Error in cryptoapicert: ECDSA signature using= CNG failed.");
= + msg(M_NONFATAL | M_ERRNO, "Error in cryptoapicert: ECDSA sign= ature using CNG failed.");
return 0; }

/* NCryptSignHash ret= urns r|s -- convert to DER encoded buffer expected by OpenSSL */
= - int derlen =3D ecdsa_bin2der= (sig, (int) len, *siglen);
+ int derlen =3D ecdsa_bin2der(sig, (int)len, *siglen);
= if (derlen <=3D 0)
{
= return 0;
@@ -396,9 +396,9 @@
{<= /span>
msg(D_LOW, "Signing using NCryptSignHash with= PKCS1 padding: hashalg <%s>", sigalg.mdname);
=
- BCRYPT_PKCS1_= PADDING_INFO padinfo =3D {hashalg};
- status =3D NCryptSignHash(cd->crypt_prov, &pad= info, (BYTE *)tbs, (DWORD)tbslen,
- sig, (DWORD)*siglen, &len, = BCRYPT_PAD_PKCS1);
+ = BCRYPT_PKCS1_PADDING_INFO padinfo =3D { hashalg };
+ status =3D NCryptSignHash(cd-= >crypt_prov, &padinfo, (BYTE *)tbs, (DWORD)tbslen, sig,
+ = (DWORD)*siglen, &len, BCRYPT_PAD_PKCS1);

}<= br> else if (!strcmp(sigalg.padmode, "pss"))
= {
@@ -416,9 +416,10 @@
= msg(D_LOW, "Signing using NCryptSignHash with PSS padding: hashalg <= ;%s>, saltlen <%d>",
sigalg.mdna= me, saltlen);

- BCRYPT_PSS_PADDING_INFO padinfo =3D {hashalg, (DWORD) sal= tlen}; /* cast is safe as saltlen >=3D 0 */
- status =3D NCryptSignHash(cd->crypt_pro= v, &padinfo, (BYTE *)tbs, (DWORD) tbslen,
- sig, (DWORD)*siglen= , &len, BCRYPT_PAD_PSS);
+ BCRYPT_PSS_PADDING_INFO padinfo =3D { hashalg,
<= span style=3D"color: hsl(120, 100%, 40%);">+ = (DWORD)saltlen }; /* cast is safe as saltlen >=3D 0 */
+ status =3D NCryp= tSignHash(cd->crypt_prov, &padinfo, (BYTE *)tbs, (DWORD)tbslen, sig,=
+ = (DWORD)*siglen, &len, BCRYPT_PAD_PSS);
= }
else
{
@@ -42= 9,7 +430,7 @@
if (status !=3D ERROR_SUCCESS) {
SetLastError(status);
- msg(M_NONFATAL|M_ERRNO, &quo= t;Error in cryptoapicert: RSA signature using CNG failed.");
+ msg(M_NONFATAL | M_ER= RNO, "Error in cryptoapicert: RSA signature using CNG failed.");<= /span>
return 0;
}
=
@@ -484,7 +485,7 @@
char *name =3D NU= LL;
if (len)
{
- wchar_t *wname =3D gc_malloc(len= *sizeof(wchar_t), false, gc);
+ wchar_t *wname =3D gc_malloc(len * sizeof(wchar_t), false= , gc);
if (!wname
|| = CertGetNameStringW(cc, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, NULL, wname, len= ) =3D=3D 0)
{
@@ -504,7 +505,6 @@<= /span>
static int
Load_CryptoAPI_certificate(con= st char *cert_prop, X509 **cert, EVP_PKEY **privkey)
{
-
HCE= RTSTORE cs;
CAPI_DATA *cd =3D calloc(1, sizeof(*cd));<= /span>
struct gc_arena gc =3D gc_new();
@@ -5= 15,29 +515,35 @@
goto err;
}<= /span>
/* search CURRENT_USER first, then LOCAL_MACHINE */
- cs =3D CertOpenStore= ((LPCSTR) CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER
- |CE= RT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG, L"MY");
+ cs =3D CertOpenSt= ore((LPCSTR)CERT_STORE_PROV_SYSTEM, 0, 0,
+ CERT_SYSTEM_STORE_CURRENT_USER= | CERT_STORE_OPEN_EXISTING_FLAG
+ | CERT_STORE_READONLY_FLAG,<= br>+ L&qu= ot;MY");
if (cs =3D=3D NULL)
= {
- msg(M_NONFA= TAL|M_ERRNO, "Error in cryptoapicert: failed to open user certficate s= tore");
+ = msg(M_NONFATAL | M_ERRNO, "Error in cryptoapicert: failed to open use= r certficate store");
goto err;
}

cd->cert_context =3D find_certificate_in_= store(cert_prop, cs);
CertCloseStore(cs, 0); if (!cd->cert_context)
{
- cs =3D CertOpenStore((LPCSTR= ) CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_LOCAL_MACHINE

<= span style=3D"color: hsl(0, 100%, 40%);">- |CERT_= STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG, L"MY");
+ cs =3D CertOpenS= tore((LPCSTR)CERT_STORE_PROV_SYSTEM, 0, 0,
+ CERT_SYSTEM_STORE_LOCAL_M= ACHINE | CERT_STORE_OPEN_EXISTING_FLAG
+ | CERT_STORE_READONLY_FLA= G,
+ = L"MY");
if (cs =3D=3D NULL)
{
+ msg(M_NONFATAL | M_ERRNO,
+ "Error in cryp= toapicert: failed to open machine certficate store");

= goto err;
}
= cd->cert_context =3D find_certificate_in_store(cert_prop, cs); CertCloseStore(cs, 0);
if (cd->= cert_context =3D=3D NULL)
{
- msg(M_NONFATAL, "Error in = cryptoapicert: certificate matching <%s> not found", cert_prop);=
+ msg(M_N= ONFATAL, "Error in cryptoapicert: certificate matching <%s> not = found",
+ = cert_prop);
goto err;
}

}
@@ -550,7 +556,7 @@
}

/* cert_context-&= gt;pbCertEncoded is the cert X509 DER encoded. */
- *cert =3D d2i_X509(NULL, (const unsigned ch= ar **) &cd->cert_context->pbCertEncoded,
+ *cert =3D d2i_X509(NULL, (const unsigned= char **)&cd->cert_context->pbCertEncoded,
= cd->cert_context->cbCertEncoded);
= if (*cert =3D=3D NULL)
{
@@ -560,13 = +566,13 @@

/* set up stuff to use th= e private key */
/* We support NCRYPT key handles only= */
- DWORD flags = =3D CRYPT_ACQUIRE_COMPARE_KEY_FLAG
- | CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG;=
- if (!CryptAcquireCertifi= catePrivateKey(cd->cert_context, flags, NULL,
- &= cd->crypt_prov, &cd->key_spec, &cd->free_crypt_prov))
+ DWORD flags =3D CRYP= T_ACQUIRE_COMPARE_KEY_FLAG | CRYPT_ACQUIRE_ONLY_NCRYPT_KEY_FLAG;
= + if (!CryptAcquireCertifica= tePrivateKey(cd->cert_context, flags, NULL, &cd->crypt_prov,
+ = &cd->key_spec, &cd->free_crypt_prov))
{
/* private key may be in a toke= n not available, or incompatible with CNG */
- msg(M_NONFATAL|M_ERRNO, "Error in crypt= oapicert: failed to acquire key. Key not present or "
+ msg(M_NONFATAL | M_ERRNO,
+ "Erro= r in cryptoapicert: failed to acquire key. Key not present or "=
"is in a legacy token not supported by Windows = CNG API");
X509_free(*cert);
= goto err;
@@ -576,8 +582,8 @@
= EVP_PKEY *pkey =3D X509_get_pubkey(*cert);
cd->pub= key =3D pkey; /* will be freed with cd */

- *privkey =3D xkey_load_generic_ke= y(tls_libctx, cd, pkey,

- xkey_cng_sign, (XKEY_PRIVKEY_FREE_fn= *) CAPI_DATA_free);
= + *privkey =3D xkey_load_generic_key(tls_libctx, cd, pkey, xkey_cng_sign= ,
+ = (XKEY_PRIVKEY_FREE_fn *)CAPI_DATA_free);
gc_free(&gc);

return 1; /* do not free cd --= its kept by xkey provider */

@@ -598,8 += 604,7 @@
{
return ret;=
}
- i= f (SSL_CTX_use_certificate(ssl_ctx, cert)
- && SSL_CTX_use_PrivateKey(ssl_ctx, priv= key))
+ if (SSL_CT= X_use_certificate(ssl_ctx, cert) && SSL_CTX_use_PrivateKey(ssl_ctx,= privkey))
{
crypto_print_ope= nssl_errors(M_WARN);
ret =3D 1;
@@= -612,5 +617,5 @@
return ret;
}

-#endif /= * HAVE_XKEY_PROVIDER */
-#endif /* _WIN32 */
+#endif /* HAVE_XKEY_PROVIDER */
+#endif /* _WIN32 */
= diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c
index 98= cbb72..daa5553 100644
--- a/src/openvpn/dco.c
+++ b/src/openvpn/dco.c

@@ -52,14 +52,13 @@
#endif


static int
-dco_install_key(struct tls_multi *multi= , struct key_state *ks,
- const uint8_t *encrypt_key, const uint8_t *encrypt_iv,
- const ui= nt8_t *decrypt_key, const uint8_t *decrypt_iv,
+dco_install_key(struct tls_multi *multi, struct = key_state *ks, const uint8_t *encrypt_key,
+ const uint8_t *encrypt_iv, const uin= t8_t *decrypt_key, const uint8_t *decrypt_iv,
= const char *ciphername)

{
= - msg(D_DCO_DEBUG, "%s: p= eer_id=3D%d keyid=3D%d, currently %d keys installed",
- __func__, multi->dco_peer_i= d, ks->key_id, multi->dco_keys_installed);
+ msg(D_DCO_DEBUG, "%s: peer_id=3D%d ke= yid=3D%d, currently %d keys installed", __func__,
+ multi->dco_peer_id, ks->ke= y_id, multi->dco_keys_installed);

= /* Install a key in the PRIMARY slot only when no other key exist.<= br> * From that moment on, any new key will be installed in the = SECONDARY
@@ -72,33 +71,27 @@
slot= =3D OVPN_KEY_SLOT_SECONDARY;
}

- int ret =3D dco_new_ke= y(multi->dco, multi->dco_peer_id, ks->key_id, slot,
- encrypt_ke= y, encrypt_iv,

- = decrypt_key, decrypt_iv,
- ciphername);
+ int ret =3D dco_new_key(multi-= >dco, multi->dco_peer_id, ks->key_id, slot, encrypt_key, encrypt_i= v,

+ = decrypt_key, decrypt_iv, ciphername);
if ((re= t =3D=3D 0) && (multi->dco_keys_installed < 2))
{

multi->dco_keys_installed++;- ks->dco_status =3D = (slot =3D=3D OVPN_KEY_SLOT_PRIMARY) ? DCO_INSTALLED_PRIMARY :
- DCO_INSTAL= LED_SECONDARY;

+ = ks->dco_status =3D
+ (slot =3D=3D OVPN_KEY_SLOT_PRIMARY) ? DCO_INSTALLED_PRIMAR= Y : DCO_INSTALLED_SECONDARY;
}

return ret;
}

= int
-init_key_dc= o_bi(struct tls_multi *multi, struct key_state *ks,
- const struct key2 *key2, in= t key_direction,
- = const char *ciphername, bool server)
+init_key_dco_bi(struct tls_multi *multi, struct= key_state *ks, const struct key2 *key2,
+ int key_direction, const char *ciphern= ame, bool server)
{
struct key_direct= ion_state kds;
key_direction_state_init(&kds, key_= direction);

- return dco_install_key(multi, ks,
- key2->keys[kds.out_ke= y].cipher,
- = key2->keys[(int)server].hmac,
- key2->keys[kds.in_= key].cipher,
- = key2->keys[1 - (int)server].hmac,
+ return dco_install_key(multi, ks, ke= y2->keys[kds.out_key].cipher, key2->keys[(int)server].hmac,+ ke= y2->keys[kds.in_key].cipher, key2->keys[1 - (int)server].hmac,=
ciphername);
}

@@ -184,13 +177,15 @@
{
if (secondary)
{- msg(D_DCO_DEBUG, &q= uot;Swapping primary and secondary keys to "
+ msg(D_DCO_DEBUG,
+ "Swapping prima= ry and secondary keys to "
"prim= ary-id=3D%d secondary-id=3D%d",
prima= ry->key_id, secondary->key_id);
}
= else
{
- msg(D_DCO_DEBUG, "Swapping primar= y and secondary keys to "
+ msg(D_DCO_DEBUG,
+ "Swapping primary and secondary ke= ys to "
"primary-id=3D%d seconda= ry-id=3D(to be deleted)",
primary->= ;key_id);
}
@@ -276,13 +271,15 @@<= /span>
#if defined(_WIN32)
if (!proto_is_udp= (ce->proto) && mode =3D=3D MODE_SERVER)
{
- msg(msglevel, &= quot;NOTE: TCP transport disables data channel offload on Windows in server= mode.");
+ = msg(msglevel,
+ = "NOTE: TCP transport disables data channel offload on Windows= in server mode.");
return false;
<= span> }


if (!ce->remote &= & !dco_win_supports_multipeer())
{
- msg(msglevel, "NOTE: --r= emote is not defined. This DCO version doesn't support multipeer. Disab= ling Data Channel Offload");

+ msg(msglevel,
+ "NOTE: --remote is not defined. This DCO v= ersion doesn't support multipeer. Disabling Data Channel Offload")= ;
return false;
}
<= span>

@@ -311,7 +308,7 @@
if (!o->= tls_client && !o->tls_server)
{
<= span> msg(msglevel, "No tls-client or tls-server option in con= figuration "

- = "detected. Disabling data channel offload.");
<= span style=3D"color: hsl(120, 100%, 40%);">+ "det= ected. Disabling data channel offload.");

ret= urn false;
}

@@ -355= ,7 +352,8 @@
#if defined(_WIN32)
if (= (o->mode =3D=3D MODE_SERVER) && !dco_win_supports_multipeer())
{
-= msg(msglevel, "--mode server is set. This DCO version doesn= 9;t support multipeer. Disabling Data Channel Offload");
+ msg(msglevel,

<= span style=3D"color: hsl(120, 100%, 40%);">+ "--mode server= is set. This DCO version doesn't support multipeer. Disabling Data Cha= nnel Offload");

return false;
}


@@ -386,8 +384,8 @@
}

else if ((ret < 0) && (re= t !=3D -ENODEV))
{
- msg(msglevel, "Cannot retrieve type = of device %s: %s (%d)", o->dev,
- strerror(-ret), ret);
+ msg(msglevel, "Cannot = retrieve type of device %s: %s (%d)", o->dev, strerror(-ret),
+ ret);
}
}
#endif /* i= f defined(_WIN32) */
@@ -402,13 +400,13 @@
= if (!capng_have_capability(CAPNG_EFFECTIVE, CAP_SETPCAP)) {
msg(msglevel, "--user = specified but lacking CAP_SETPCAP. "
- "Cannot retain CAP_NET_ADMIN. Disa= bling data channel offload");
+ "Cannot retain CAP_NET_ADMIN.= Disabling data channel offload");
return= false;
}
if (!capng_have= _capability(CAPNG_PERMITTED, CAP_NET_ADMIN))
{
msg(msglevel, "--user specified but not perm= itted to retain CAP_NET_ADMIN. "
- "Disabling data channel offload")= ;
+ = "Disabling data channel offload");
= return false;
}
}
@@ -439,16 +437,18 @@
if (o->enable_ncp= _fallback
&& !tls_item_in_cipher_list(o-&g= t;ciphername, dco_get_supported_ciphers()))
{- msg(msglevel, "No= te: --data-ciphers-fallback with cipher '%s' "
- "disables data chann= el offload.", o->ciphername);

+ msg(msglevel,
+ "Note: --data-ciphers-fallback with ci= pher '%s' "
+ "disables data channel offload.",
+ o->ciphername);
return false;
}
=
#if defined(USE_COMP)
- if (o->comp.alg !=3D COMP_ALG_UNDEF
- || o->comp.flags & C= OMP_F_ALLOW_ASYM)

+ = if (o->comp.alg !=3D COMP_ALG_UNDEF || o->comp.flags & COMP_F_A= LLOW_ASYM)
{
- msg(msglevel, "Note: '--allow-compression'= is not set to 'no', disabling data channel offload.");=
+ msg(msglevel,
+ "Note: = '--allow-compression' is not set to 'no', disabling data ch= annel offload.");

if (o->= ;mode =3D=3D MODE_SERVER && !(o->comp.flags & COMP_F_MIGRATE= ))
{
@@ -467,8 +467,10 @@ {
if (!tls_item_in_cipher_list(token,= dco_get_supported_ciphers()))
{
- msg(msglevel, "Note: c= ipher '%s' in --data-ciphers is not supported "
- "by ovpn-dco, d= isabling data channel offload.", token);

+ msg(msglevel,
+ "Note: cipher '%= s' in --data-ciphers is not supported "
+ "by ovpn-dco, disabling d= ata channel offload.",
+ token);
gc_free(&g= c);
return false;
}
@@ -484,7 +486,7 @@
if (!o->use_peer= _id)
{
msg(msglevel, "OP= TIONS IMPORT: Server did not request DATA_V2 packet "
- "format required for = data channel offload");
+ "format required for data channel offlo= ad");
return false;
}
return true;
@@ -514,8 +516,7 @@<= br> }
#endif
int ret =3D dc= o_new_peer(&c->c1.tuntap->dco, multi->peer_id, sock->sd, NU= LL,
- = proto_is_dgram(sock->info.proto) ? remoteaddr : NULL,- NULL= , NULL);
+ = proto_is_dgram(sock->info.proto) ? remoteaddr : NULL, NU= LL, NULL);
if (ret < 0)
{
return ret;
@@ -548,7 +549,8 @@=
#if ENABLE_IP_PKTINFO
struct context *c =3D= &mi->context;

- if (!proto_is_udp(c->c2.link_sockets[0]->info.p= roto) || !(c->options.sockflags & SF_USE_IP_PKTINFO))
+ if (!proto_is_udp(c->c2.lin= k_sockets[0]->info.proto)

+ || !(c->options.sockflags & SF_USE_IP_PKTINFO))
{
return false;
= }
@@ -632,8 +634,8 @@
localad= dr =3D (struct sockaddr *)&local;
}

- int ret =3D dc= o_new_peer(&c->c1.tuntap->dco, peer_id, sd, localaddr,
= - remot= eaddr, vpn_addr4, vpn_addr6);
+ int ret =3D
+ dco_new_peer(&c->c1.tuntap->dco, peer_id, sd, local= addr, remoteaddr, vpn_addr4, vpn_addr6);
if (ret < = 0)
{
return ret;
@@ -645,8 +647,7 @@

}

void

-dco_install_ir= oute(struct multi_context *m, struct multi_instance *mi,
- struct mroute_addr *a= ddr)
+dco_install_iro= ute(struct multi_context *m, struct multi_instance *mi, struct mroute_addr = *addr)
{
#if defined(TARGET_LINUX) || def= ined(TARGET_FREEBSD) || defined(_WIN32)
if (!dco_enabl= ed(&m->top.options))
@@ -667,7 +668,8 @@
<= span> if (addrtype =3D=3D MR_ADDR_IPV6)

{ #if defined(_WIN32)
- dco_win_add_iroute_ipv6(&c->c1.tuntap->dco, addr-&= gt;v6.addr, addr->netbits, c->c2.tls_multi->peer_id);
+ dco_win_add_iroute_ipv6(= &c->c1.tuntap->dco, addr->v6.addr, addr->netbits,
+ = c->c2.tls_multi->peer_id);
#else
= net_route_v6_add(&m->top.net_ctx, &addr->v6.addr, ad= dr->netbits,
&mi->conte= xt.c2.push_ifconfig_ipv6_local, c->c1.tuntap->actual_name, 0,<= br>@@ -677,12 +679,12 @@
else if (addrtype =3D= =3D MR_ADDR_IPV4)
{
#if defined(_WIN3= 2)
- dco_win_add= _iroute_ipv4(&c->c1.tuntap->dco, addr->v4.addr, addr->netbi= ts, c->c2.tls_multi->peer_id);
+ dco_win_add_iroute_ipv4(&c->c1.tuntap->d= co, addr->v4.addr, addr->netbits,
+ c->c2.tls_multi->= peer_id);
#else
in_addr_t dest = =3D htonl(addr->v4.addr);
- net_route_v4_add(&m->top.net_ctx, &dest, addr->= ;netbits,
- = &mi->context.c2.push_ifconfig_local, c->c1.tuntap-&g= t;actual_name, 0,
- = DCO_IROUTE_METRIC);
+ net_route_v4_add(&m->top.net_ctx, &= dest, addr->netbits, &mi->context.c2.push_ifconfig_local,<= br>+ c-= >c1.tuntap->actual_name, 0, DCO_IROUTE_METRIC);
#end= if
}
#endif /* if defined(TARGET_LINU= X) || defined(TARGET_FREEBSD) || defined(_WIN32) */
@@ -702= ,32 +704,28 @@

if (mi->context.c2= .push_ifconfig_defined)
{
- for (const struct iroute *ir =3D c->opt= ions.iroutes;
- = ir;
- = ir =3D ir->next)
+= for (const struct iroute *ir =3D c->options.iroutes; ir; ir =3D = ir->next)
{
#if defined(_WIN32= )
dco_win_del_iroute_ipv4(&c->c1.tuntap= ->dco, htonl(ir->network), ir->netbits);
#else
net_route_v4_del(&m->top.net_ctx, &ir= ->network, ir->netbits,
- &mi->context.c2.push_ifconfig_l= ocal, c->c1.tuntap->actual_name,
- 0, DCO_IROUTE_METRIC);=
+ = &mi->context.c2.push_ifconfig_local, c->c1.tuntap->actual_n= ame, 0,
+ = DCO_IROUTE_METRIC);
#endif
}

}

= if (mi->context.c2.push_ifconfig_ipv6_defined)
{
- for (const struc= t iroute_ipv6 *ir6 =3D c->options.iroutes_ipv6;
- ir6;
- ir6 =3D ir6->next)
+ for (const struct iroute_ip= v6 *ir6 =3D c->options.iroutes_ipv6; ir6; ir6 =3D ir6->next)
{
#if defined(_WIN32)
= dco_win_del_iroute_ipv6(&c->c1.tuntap->dco, ir6->net= work, ir6->netbits);
#else
= net_route_v6_del(&m->top.net_ctx, &ir6->network, ir6->net= bits,
- = &mi->context.c2.push_ifconfig_ipv6_local, c->c1.tunt= ap->actual_name,
- = 0, DCO_IROUTE_METRIC);
+ &mi->cont= ext.c2.push_ifconfig_ipv6_local, c->c1.tuntap->actual_name, 0,=
+ = DCO_IROUTE_METRIC);
#endif
}
}
diff --git a/src/openvpn/dco.h b/src/= openvpn/dco.h
index f38316d..b1bd210 100644
--- a/src/openvpn/dco.h

+++ b/src/openvpn/dco.h
= @@ -44,8 +44,8 @@
struct tls_multi;
= struct tuntap;

-#define DCO_IROUTE_METRIC 100
-#define DCO_DEFAULT_METRIC 200
+#define DCO_IROUTE_METRIC 100
= +#define DCO_DEFAULT_METRIC 200=

#if defined(ENABLE_DCO)

@@ -156,9 +156,8 @@
*
= * @return 0 on success or a negative error code otherwise=
*/
-int ini= t_key_dco_bi(struct tls_multi *multi, struct key_state *ks,
- const struct key2= *key2, int key_direction,

- const char *ciphername, bool server);
+int init_key_dco_bi(struct tls_m= ulti *multi, struct key_state *ks, const struct key2 *key2,

+ int key_directi= on, const char *ciphername, bool server);


/**

* Possibly swap or wipe keys from DCO
@@ -190,8 +189,8 @@

*
* @return = 0 on success or a negative error code otherwise
*/

-int dco_set_pe= er(dco_context_t *dco, unsigned int peerid,
- int keepalive_interval, int keepaliv= e_timeout, int mss);
= +int dco_set_peer(dco_context_t *dco, unsigned int peerid, int keepalive_in= terval,
+ = int keepalive_timeout, int mss);

/*= *
* Remove a peer from DCO
@@ -262,7 +261= ,7 @@
{
return false;
}

-#else /* if define= d(ENABLE_DCO) */
+#el= se /* if defined(ENABLE_DCO) */

typedef= void *dco_context_t;

@@ -326,9 +325,8 @@=
}

static inline int
-init_key_dco_bi(struct t= ls_multi *multi, struct key_state *ks,
- const struct key2 *key2, int key_direction= ,
- cons= t char *ciphername, bool server)
+init_key_dco_bi(struct tls_multi *multi, struct key_state *ks,= const struct key2 *key2,
+ int key_direction, const char *ciphername, bool serve= r)
{
return 0;
}
@@ -347,8 +345,8 @@
}

static inline int
-dco_set_peer(dco_context_t *dco, unsigned int peerid,
- int keepalive_interval= , int keepalive_timeout, int mss)

+dco_set_peer(dco_context_t *dco, unsigned int peerid, int kee= palive_interval, int keepalive_timeout,
+ int mss)
{
return 0;

}
@@ -365,8 +363,7 @@
}

static inline void
-dco_install_iroute(struct m= ulti_context *m, struct multi_instance *mi,
- struct mroute_addr *addr)+dco_install_iroute(struct mu= lti_context *m, struct multi_instance *mi, struct mroute_addr *addr)=
{
}

diff --gi= t a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c
i= ndex b8816c6..7175d37 100644
--- a/src/openvpn/dco_freebsd.= c
+++ b/src/openvpn/dco_freebsd.c
@@ -73,9 = +73,8 @@
}

int-dco_new_peer(dco_context_t *dc= o, unsigned int peerid, int sd,
- struct sockaddr *localaddr, struct sockaddr *remotea= ddr,
- stru= ct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6)
+dco_new_peer(dco_context_t *dco, unsigned int = peerid, int sd, struct sockaddr *localaddr,
+ struct sockaddr *remoteaddr, struct in= _addr *vpn_ipv4, struct in6_addr *vpn_ipv6)
{
struct ifdrv drv;

nvlist_t *nvl, *local_nvl, = *remote_nvl;
@@ -99,8 +98,7 @@

= if (vpn_ipv4)
{
- nvlist_add_binary(nvl, "vpn_ipv4&quo= t;, &vpn_ipv4->s_addr,
- sizeof(vpn_ipv4->s_addr));
<= span style=3D"color: hsl(120, 100%, 40%);">+ nvlist_add_binary(nvl, = "vpn_ipv4", &vpn_ipv4->s_addr, sizeof(vpn_ipv4->s_addr)= );

}

if (vpn_ip= v6)
@@ -216,7 +214,7 @@
if (ret)
{
ret =3D -errno;
- msg(M_WARN|M_ERRNO, "Fail= ed to create interface %s (SIOCIFCREATE2)", ifr.ifr_name);
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(M_WARN | M_ERRNO, &= quot;Failed to create interface %s (SIOCIFCREATE2)", ifr.ifr_name);
return ret;
}
=
@@ -238,7 +236,7 @@
ret =3D -errn= o;
/* Delete the created interface again. */
(void)ioctl(tt->dco.fd, SIOCIFDESTROY, &ifr);
- msg(M_WARN|M_ERR= NO, "Failed to create interface %s (SIOCSIFNAME)", ifr.ifr_data);=
+ msg(M_WARN = | M_ERRNO, "Failed to create interface %s (SIOCSIFNAME)", ifr.ifr= _data);
return ret;
}<= br>
@@ -350,8 +348,7 @@
}
int
-dco_del_key(dco_context_t *dco, unsigned int peerid,
- dco_key_slot_t slot)
+dco_del_key(dco_context= _t *dco, unsigned int peerid, dco_key_slot_t slot)
{
struct ifdrv drv;
nvlist_t *nvl;
@@ -421,18 +418,16 @@
}

int
-dco_ne= w_key(dco_context_t *dco, unsigned int peerid, int keyid,
- dco_key_slot_t slot,=
- const uint8_t *e= ncrypt_key, const uint8_t *encrypt_iv,
- const uint8_t *decrypt_key, const uint8_t *dec= rypt_iv,
- c= onst char *ciphername)
+ = const uint8_t *encrypt_key, const uint8_t *encrypt_iv, const uint8_t *= decrypt_key,
+ = const uint8_t *decrypt_iv, const char *ciphername)
{<= /span>
struct ifdrv drv;
nvlist_t *nvl, = *encrypt_nvl, *decrypt_nvl;
int ret;
=
- msg(D_DCO_DEBUG, = "%s: slot %d, key-id %d, peer-id %d, cipher %s",
- __func__, slot, keyid, peerid,= ciphername);
+ ms= g(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", _= _func__, slot, keyid, peerid,
+ ciphername);

nvl = =3D nvlist_create(0);

@@ -470,16 +465,15 = @@
}

int
-dco_set_peer(dco_context_t *dco, uns= igned int peerid,

- = int keepalive_interval, int keepalive_timeout,
+dco_set_peer(dco_context_t *dco, unsign= ed int peerid, int keepalive_interval, int keepalive_timeout,
int mss)

{
struct if= drv drv;
nvlist_t *nvl;
int ret;<= /span>

- = msg(D_DCO_DEBUG, "%s: peer-id %d, ping interval %d, ping timeout %d&qu= ot;,
- __func__,= peerid, keepalive_interval, keepalive_timeout);
+ msg(D_DCO_DEBUG, "%s: peer-id %d, pin= g interval %d, ping timeout %d", __func__, peerid,
+ keepalive_interval, keepalive_t= imeout);

nvl =3D nvlist_create(0);
nvlist_add_number(nvl, "peerid", peerid);
@@ -699,7 +693,6 @@
static void
dco_update_peer_stat(struct multi_context *m, uint32_t peerid, const nv= list_t *nvl)

{
-
if (peerid >=3D m->max_clients || !m-= >instances[peerid])
{
msg(= M_WARN, "dco_update_peer_stat: invalid peer ID %d returned by kernel&q= uot;, peerid);
@@ -716,7 +709,6 @@
dco_get= _peer_stats_multi(dco_context_t *dco, struct multi_context *m,
const bool raise_sigusr1_on_err)

{

-
struct ifdrv drv;

uint8_t *buf =3D NULL;=
size_t buf_size =3D 4096;
diff --git a/src/o= penvpn/dco_freebsd.h b/src/openvpn/dco_freebsd.h
index e1a0= 54e..28d97bb 100644
--- a/src/openvpn/dco_freebsd.h<= br>+++ b/src/openvpn/dco_freebsd.h
@@ -27,25 +27,28 @= @

#include "ovpn_dco_freebsd.h"= ;

-#d= efine DCO_IROUTE_METRIC 100
+#define DCO_IROUTE_METRIC 100

= typedef enum ovpn_key_slot dco_key_slot_t;
typedef enum ov= pn_key_cipher dco_cipher_t;

-enum ovpn_message_type_t {
+enum ovpn_message_type_t
+{
OVPN_CMD_DEL_PEE= R,
OVPN_CMD_PACKET,
OVPN_CMD_SWAP= _KEYS,
};

-enum ovpn_del_reason_t {
+enum ovpn_del_reason_t
+{
OVPN_DEL_PEER_REASON_= EXPIRED,
OVPN_DEL_PEER_REASON_TRANSPORT_ERROR,<= br> OVPN_DEL_PEER_REASON_USERSPACE,
OVPN_DEL= _PEER_REASON_TRANSPORT_DISCONNECT,
};

-typedef struct dco_conte= xt {
+typedef struct = dco_context
+{=
bool open;
int fd;
= int pipefd[2];
diff --git a/src/openvpn/dco_internal.h b/s= rc/openvpn/dco_internal.h
index 27d03ef..866b364 100644
--- a/src/openvpn/dco_internal.h
+++ b/src/ope= nvpn/dco_internal.h
@@ -60,17 +60,14 @@
*= They are implemented by dco_linux.c
*/
=
-int dco_new_peer(dco_= context_t *dco, unsigned int peerid, int sd,
- struct sockaddr *localaddr, struct = sockaddr *remoteaddr,
-= struct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6);

+int dco_new_peer(dco_con= text_t *dco, unsigned int peerid, int sd, struct sockaddr *localaddr,
+ struct s= ockaddr *remoteaddr, struct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6);<= /span>

int dco_del_peer(dco_context_t *dco, uns= igned int peerid);

-int dco_new_key(dco_context_t *dco, unsigned int peerid, int= keyid,
- = dco_key_slot_t slot,
= - const uint8_t *encrypt_key, const uint8_t *encrypt_iv,
- const uin= t8_t *decrypt_key, const uint8_t *decrypt_iv,
- const char *ciphername);
= +int dco_new_key(dco_context_t = *dco, unsigned int peerid, int keyid, dco_key_slot_t slot,
+ const uint8_t *encry= pt_key, const uint8_t *encrypt_iv, const uint8_t *decrypt_key,
+ const uint8_t *d= ecrypt_iv, const char *ciphername);


int = dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot);<= /span>

diff --git a/src/openvpn/dco_linux.c b/sr= c/openvpn/dco_linux.c
index 22a445a..075efe8 100644<= br>--- a/src/openvpn/dco_linux.c
+++ b/src/openvpn/dc= o_linux.c
@@ -55,8 +55,7 @@
* have to exp= licitly do it to prevent the kernel from failing upon
* p= arsing of the message
*/
-#define nla_nest_start(_msg, _type) \
- nla_nest_start(_msg, (_type) | NLA= _F_NESTED)
+#define n= la_nest_start(_msg, _type) nla_nest_start(_msg, (_type) | NLA_F_NESTED)

static int ovpn_get_mcast_id(dco_context_t = *dco);

@@ -90,8 +89,7 @@
= ret =3D genl_connect(nl_sock);
if (ret) {
- = msg(msglevel, "Cannot connect to generic netlink: %s",
= - nl_geterror(ret));
+ msg(msglevel,= "Cannot connect to generic netlink: %s", nl_geterror(ret));
goto err_sock;
}
= set_cloexec(nl_socket_get_fd(nl_sock));
@@ -99,8 +97,7= @@
ret =3D genl_ctrl_resolve(nl_sock, OVPN_FAMILY_NAM= E);
if (ret < 0)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- msg(msglevel, "Canno= t find ovpn_dco netlink component: %s",

- nl_geterror(ret));
+ msg(msglevel, "Cannot find o= vpn_dco netlink component: %s", nl_geterror(ret));
= }

err_sock:
@@ -158,7 = +155,8 @@
default:
if= (ret)
{
- msg(M_NONFATAL, "%s: netlink reports e= rror (%d): %s", prefix, ret, nl_geterror(-ret));
+ msg(M_NONFATAL, "%s:= netlink reports error (%d): %s", prefix, ret,
+ nl_geterror(-ret));
}
break; }
@@ -178,8 +176,8 @@
* @retu= rn status of sending the message
*/
static int

-ovpn_n= l_msg_send(dco_context_t *dco, struct nl_msg *nl_msg, ovpn_nl_cb cb,=
- void *cb_ar= g, const char *prefix)
+ = const char *prefix)
{
d= co->status =3D 1;

@@ -193,8 +191,8 @@<= /span>

if (dco->status < 0) {
- = msg(M_INFO, "%s: failed to send netlink message: %s (%d)",=
- prefix, strerror= (-dco->status), dco->status);
+ msg(M_INFO, "%s: failed to send netlink messag= e: %s (%d)", prefix, strerror(-dco->status),
+ dco->status);
}


return dco->status;
@@ -206,7 +204,6 @@
struct sockaddr_in6 = *sock6 =3D (struct sockaddr_in6 *)sock;
if (sock->s= a_family =3D=3D AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sock6->sin= 6_addr))
{
-
struct sockaddr_in *sock4;
ALLOC_OBJ_CLEAR_GC(sock4, struct sockaddr_in, gc);

<= span> memcpy(&sock4->sin_addr, sock6->sin6_addr.s6_addr += 12, 4);

@@ -218,9 +215,8 @@
}
<= span>

int
-dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd,<= br>- struct sockaddr = *localaddr, struct sockaddr *remoteaddr,
- struct in_addr *vpn_ipv4, struct in6_addr *= vpn_ipv6)
+dco_new_pe= er(dco_context_t *dco, unsigned int peerid, int sd, struct sockaddr *locala= ddr,
+ st= ruct sockaddr *remoteaddr, struct in_addr *vpn_ipv4, struct in6_addr *vpn_i= pv6)
{
struct gc_arena gc =3D gc_new(= );
const char *remotestr =3D "[undefined]";<= /span>
@@ -228,8 +224,7 @@
{
= remotestr =3D print_sockaddr(remoteaddr, &gc);
}

- msg(D_DCO_= DEBUG, "%s: peer-id %d, fd %d, remote addr: %s", __func__,=
- peerid, sd, remotest= r);
+ msg(D_DCO_DE= BUG, "%s: peer-id %d, fd %d, remote addr: %s", __func__, peerid, = sd, remotestr);

struct nl_msg *nl_ms= g =3D ovpn_dco_nlmsg_create(dco, OVPN_CMD_PEER_NEW);
s= truct nlattr *attr =3D nla_nest_start(nl_msg, OVPN_A_PEER);
@@ -247,14 +242,17 @@

{
= NLA_PUT(nl_msg, OVPN_A_PEER_REMOTE_IPV4, sizeof(struct in_addr),=
&((struct sockaddr_in *)remoteaddr)->= sin_addr);
- = NLA_PUT_U16(nl_msg, OVPN_A_PEER_REMOTE_PORT, ((struct sockaddr_in *)remote= addr)->sin_port);
= + NLA_PUT_U16(nl_msg, OVPN_A_PEER_REMOTE_PORT,
+ ((struct sock= addr_in *)remoteaddr)->sin_port);
}
<= span> else if (remoteaddr->sa_family =3D=3D AF_INET6)

= {
NLA_PUT(nl_msg, OVPN_A_PEER_R= EMOTE_IPV6, sizeof(struct in6_addr),
&= amp;((struct sockaddr_in6 *)remoteaddr)->sin6_addr);
- NLA_PUT_U16(nl_msg, OVPN_A_PE= ER_REMOTE_PORT, ((struct sockaddr_in6 *)remoteaddr)->sin6_port);<= br>- NLA_PUT_U32(nl_ms= g, OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID, ((struct sockaddr_in6 *)remoteaddr)-&g= t;sin6_scope_id);
+ = NLA_PUT_U16(nl_msg, OVPN_A_PEER_REMOTE_PORT,
+ ((struct sockadd= r_in6 *)remoteaddr)->sin6_port);
+ NLA_PUT_U32(nl_msg, OVPN_A_PEER_REMOTE_IPV6_SCO= PE_ID,
+ = ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); }
}

@@ -280,8 +278,7 @@

}
if (vpn_ip= v6)
{
- NLA_PUT(nl_msg, OVPN_A_PEER_VPN_IPV6, sizeof(struct in6_addr),=
- vpn_i= pv6);
+ NLA_PU= T(nl_msg, OVPN_A_PEER_VPN_IPV6, sizeof(struct in6_addr), vpn_ipv6);<= br> }
nla_nest_end(nl_msg, attr);
=
@@ -294,7 +291,7 @@
}

static int
-ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused))= , void *arg)
+ovpn_nl= _cb_finish(struct nl_msg(*msg) __attribute__((unused)), void *arg) {
int *status =3D arg;

@@ -315,7 +312,8 @@
* missing at the message= level
* @NLMSGERR_ATTR_MISS_NEST: offset of the nest whe= re attribute was missing
*/
-enum ovpn_nlmsgerr_attrs {
+enum ovpn_nlmsgerr_attrs
+{
OVPN_NLMSGERR_AT= TR_MISS_TYPE =3D 5,
OVPN_NLMSGERR_ATTR_MISS_NEST =3D 6= ,
OVPN_NLMSGERR_ATTR_MAX =3D 6,
@@ -33= 0,8 +328,7 @@
* reply to see if it contains a human-reada= ble error. If found, it is printed.
*/
s= tatic int
-ovpn_nl_cb_e= rror(struct sockaddr_nl (*nla) __attribute__ ((unused)),
- struct nlmsgerr *err, v= oid *arg)
+ovpn_nl_cb= _error(struct sockaddr_nl(*nla) __attribute__((unused)), struct nlmsgerr *e= rr, void *arg)
{
struct nlmsghdr *nlh= =3D (struct nlmsghdr *)err - 1;
struct nlattr *tb_msg= [OVPN_NLMSGERR_ATTR_MAX + 1];
@@ -365,8 +362,7 @@ {
len =3D strnlen((char *)nla_data(tb_= msg[NLMSGERR_ATTR_MSG]),
nla_len(tb_= msg[NLMSGERR_ATTR_MSG]));
- msg(M_WARN, "kernel error: %*s", len,
- (char *)nla_data(tb_msg[N= LMSGERR_ATTR_MSG]));

= + msg(M_WARN, "kernel error: %*s", len, (char *)nla_data(t= b_msg[NLMSGERR_ATTR_MSG]));
}
=
if (tb_msg[OVPN_NLMSGERR_ATTR_MISS_NEST])
@@= -399,14 +395,12 @@
int ret =3D genl_connect(dco->n= l_sock);
if (ret)
{
- msg(M_ERR, "Cannot con= nect to generic netlink: %s",

- nl_geterror(ret));
+ msg(M_ERR, "Cannot connect to generic = netlink: %s", nl_geterror(ret));
}

/* enable Extended ACK for detailed error reportin= g */
ret =3D 1;
- setsockopt(nl_socket_get_fd(dco->nl_sock), SOL_NETLIN= K, NETLINK_EXT_ACK,
- = &ret, sizeof(ret));
+ setsockopt(nl_socket_get_fd(dco->nl_sock), SOL_NETL= INK, NETLINK_EXT_ACK, &ret, sizeof(ret));

<= span> /* set close on exec and non-block on the netlink socket */
set_cloexec(nl_socket_get_fd(dco->nl_sock));
<= span>@@ -421,10 +415,8 @@

nl_socket_set_cb(dco->nl_= sock, dco->nl_cb);

nl_cb_err(dco-= >nl_cb, NL_CB_CUSTOM, ovpn_nl_cb_error, &dco->status);
= - nl_cb_set(dco->nl_cb, NL_= CB_FINISH, NL_CB_CUSTOM, ovpn_nl_cb_finish,
- &dco->status);
- nl_cb_set(dco->nl_cb, NL_CB_ACK,= NL_CB_CUSTOM, ovpn_nl_cb_finish,
- &dco->status);
+ nl_cb_set(dco->nl_cb, NL_CB_FINISH, NL_C= B_CUSTOM, ovpn_nl_cb_finish, &dco->status);
+ nl_cb_set(dco->nl_cb, NL_CB_ACK, NL_C= B_CUSTOM, ovpn_nl_cb_finish, &dco->status);
=
/* The async PACKET messages confuse libnl and it will drop = them with
* wrong sequence numbers (NLE_SEQ_MISMATCH)= , so disable libnl's sequence
@@ -434,7 +426,7 @@
/* nl library sets the buffer size to 32k/32k by default wh= ich is sometimes
* overrun with very fast connecting/= disconnecting clients.
* TODO: fix this in a better a= nd more reliable way */
- ASSERT(!nl_socket_set_buffer_size(dco->nl_sock, 1024*1024, 1024*10= 24));
+ ASSERT(!nl= _socket_set_buffer_size(dco->nl_sock, 1024 * 1024, 1024 * 1024));=
}

bool
@@ -47= 8,7 +470,7 @@

if (dco->ovpn_dco_m= cast_id < 0)
{
- msg(M_ERR, "cannot get mcast group: %s",= nl_geterror(dco->ovpn_dco_mcast_id));
+ msg(M_ERR, "cannot get mcast group: %s&= quot;, nl_geterror(dco->ovpn_dco_mcast_id));
}

/* Register for ovpn-dco specific multic= ast messages that the kernel may
@@ -575,8 +567,7 @@=


int
-dco_del_key(dco_context_t *dco, unsigned int p= eerid,
- dco= _key_slot_t slot)
+dc= o_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot)
{
int ret =3D -EMSGSIZE;
msg(D_DCO_DEBUG, "%s: peer-id %d, slot %d", __func__, peeri= d, slot);

@@ -600,14 +591,12 @@
}
int
-dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid,
- dco_key_slot= _t slot,
- c= onst uint8_t *encrypt_key, const uint8_t *encrypt_iv,
- const uint8_t *decrypt_key, con= st uint8_t *decrypt_iv,
- const char *ciphername)
+dco_new_key(dco_context_t *dco, unsigned int peerid, int = keyid, dco_key_slot_t slot,
+ const uint8_t *encrypt_key, const uint8_t *encrypt_iv, = const uint8_t *decrypt_key,
+ const uint8_t *decrypt_iv, const char *ciphername)
{
- msg= (D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s",
- __func__, slot, = keyid, peerid, ciphername);
+ msg(D_DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, ciph= er %s", __func__, slot, keyid, peerid,
+ ciphername);

const size_t key_len =3D cipher_kt_key_size(ciphername);
const int nonce_tail_len =3D 8;
@@ -628,23 +617= ,19 @@
NLA_PUT_U32(nl_msg, OVPN_A_KEYCONF_KEY_ID, keyi= d);
NLA_PUT_U32(nl_msg, OVPN_A_KEYCONF_CIPHER_ALG, dco= _cipher);

- struct nlattr *key_enc =3D nla_nest_start(nl_msg,
- = OVPN_A_KEYCONF_ENCRYPT_DIR);

+ struct nlattr *key_enc =3D nla_nest_start(nl_msg, OVPN_= A_KEYCONF_ENCRYPT_DIR);
if (dco_cipher !=3D OVPN_CIPHE= R_ALG_NONE)
{
NLA_PUT(nl_msg,= OVPN_A_KEYDIR_CIPHER_KEY, key_len, encrypt_key);
- NLA_PUT(nl_msg, OVPN_A_KEYDIR_NONCE_TAI= L, nonce_tail_len,
- = encrypt_iv);
+ NLA_PUT(nl_msg, OVPN_A_KEYDIR_NONCE_TAIL, nonce_tail_len, enc= rypt_iv);
}
nla_nest_end(nl_msg, = key_enc);

- struct nlattr *key_dec =3D nla_nest_start(nl_msg,
- = OVPN_A_KEYCONF_DECRYPT_DIR);

+ struct nlattr *key_dec =3D nla_nest_start(nl_msg, OVPN_= A_KEYCONF_DECRYPT_DIR);
if (dco_cipher !=3D OVPN_CIPHE= R_ALG_NONE)
{
NLA_PUT(nl_msg,= OVPN_A_KEYDIR_CIPHER_KEY, key_len, decrypt_key);
- NLA_PUT(nl_msg, OVPN_A_KEYDIR_NONCE_TAI= L, nonce_tail_len,
- = decrypt_iv);
+ NLA_PUT(nl_msg, OVPN_A_KEYDIR_NONCE_TAIL, nonce_tail_len, dec= rypt_iv);
}
nla_nest_end(nl_msg, = key_dec);

@@ -659,11 +644,11 @@ }

int
-dco_set_peer(dco_context_t *dco, unsigned int pe= erid,
- int= keepalive_interval, int keepalive_timeout, int mss)
+dco_set_peer(dco_context_t *dco, unsigned= int peerid, int keepalive_interval, int keepalive_timeout,
+ int mss)

{

- msg(D_DCO_DE= BUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __func__,<= br>- peerid, keepalive_int= erval, keepalive_timeout, mss);
+ msg(D_DCO_DEBUG, "%s: peer-id %d, keepalive %d/%d, mss= %d", __func__, peerid,
+ keepalive_interval, keepalive_timeout, mss);

struct nl_msg *nl_msg =3D ovpn_dco_nlmsg_create(d= co, OVPN_CMD_PEER_SET);
if (!nl_msg)
@= @ -674,10 +659,8 @@
struct nlattr *attr =3D nla_nest_s= tart(nl_msg, OVPN_A_PEER);
int ret =3D -EMSGSIZE;
NLA_PUT_U32(nl_msg, OVPN_A_PEER_ID, peerid);
- NLA_PUT_U32(nl_msg, OVPN_A_PEER= _KEEPALIVE_INTERVAL,

- = keepalive_interval);
- NLA_PUT_U32(nl_msg, OVPN_A_PEER_KEEPALIVE_TIMEOUT,=
- keepalive_ti= meout);
+ NLA_PUT_= U32(nl_msg, OVPN_A_PEER_KEEPALIVE_INTERVAL, keepalive_interval);
= + NLA_PUT_U32(nl_msg, OVPN_A= _PEER_KEEPALIVE_TIMEOUT, keepalive_timeout);
nla_nest_= end(nl_msg, attr);

ret =3D ovpn_nl_m= sg_send(dco, nl_msg, NULL, NULL, __func__);
@@ -701,8 +684,= 7 @@
struct nlattr *tb[CTRL_ATTR_MAX + 1];
<= span> struct genlmsghdr *gnlh =3D nlmsg_data(nlmsg_hdr(msg));

- nla_parse= (tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
- genlmsg_attrlen(gnlh, 0), NULL);
+ nla_parse(tb, CTRL_= ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);

if (!tb[CTRL_ATTR_MCAST_GROUPS]) {
@@ -715,18 +697,16 @@
{=
struct nlattr *tb_mcgrp[CTRL_ATTR_MCAST_GRP_MAX += 1];

= - nla_parse(tb_mcgrp, CTRL_ATTR_MCAST_GRP_MAX,
- nla_data(mcgrp), nla_len(= mcgrp), NULL);
+ = nla_parse(tb_mcgrp, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), nla_len(mc= grp), NULL);

- if (!tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME]
- || !tb_mcgrp[CTRL_ATTR_MCAST= _GRP_ID])
+ if= (!tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME] || !tb_mcgrp[CTRL_ATTR_MCAST_GRP_ID])=
{
continue; }

- if (strncmp(nla_data(tb_mcgrp[CTRL_ATTR_MCAST_GRP_NA= ME]),
- = OVPN_MCGRP_PEERS,
-= nla_len(tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME])) !=3D 0)
+ if (strncmp(nl= a_data(tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME]), OVPN_MCGRP_PEERS,
+ nla_len(tb_mc= grp[CTRL_ATTR_MCAST_GRP_NAME]))

+ !=3D 0)
{
= continue;
}
@@ -784,8= +764,7 @@
return NL_STOP;
}<= /span>

- = if (nla_parse(attrs, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0),
- genlmsg_attrlen(gnl= h, 0), NULL))

+ if= (nla_parse(attrs, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(g= nlh, 0), NULL))
{
msg(D_DCO, = "received bogus data from ovpn-dco");
re= turn NL_STOP;
@@ -803,9 +782,8 @@
uint= 32_t ifindex =3D nla_get_u32(attrs[OVPN_A_IFINDEX]);
i= f (ifindex !=3D dco->ifindex)
{
- msg(D_DCO_DEBUG,
- "ovpn-dco: ignoring m= essage (type=3D%d) for foreign ifindex %d",
- gnlh->cmd, ifindex);
+ msg(D_DCO_DEBUG, "o= vpn-dco: ignoring message (type=3D%d) for foreign ifindex %d", gnlh-&g= t;cmd,

+ i= findex);
return NL_STOP;
}

@@ -827,8 +805,7 @@
= }

struct nlattr *dp_at= trs[OVPN_A_PEER_MAX + 1];
- if (nla_parse_nested(dp_attrs, OVPN_A_PEER_MAX, attrs[OVPN_= A_PEER],
- = NULL))
+ if (nla_parse_nested(dp_attrs, OVPN_A_PEER_MAX, attrs[OV= PN_A_PEER], NULL))
{
= msg(D_DCO, "ovpn-dco: can't parse peer in PEER_DEL_NTF mes= ssage");
return NL_STOP;
@@ -848,8 +825,9 @@

int reason =3D nla_get= _u32(dp_attrs[OVPN_A_PEER_DEL_REASON]);
unsign= ed int peerid =3D nla_get_u32(dp_attrs[OVPN_A_PEER_ID]);
<= /span>
- msg(D_DCO_= DEBUG, "ovpn-dco: received CMD_PEER_DEL_NTF, ifindex: %d, peer-id %u, = reason: %d",
- = ifindex, peerid, reason);
+ msg(D_DCO_DEBUG,
+ "ovpn-dco: received CMD_PEE= R_DEL_NTF, ifindex: %d, peer-id %u, reason: %d", ifindex,
+ peerid, reason);=

dco->dco_message_peer_id =3D peerid;
dco->dco_del_peer_reason =3D reason;
<= span> dco->dco_message_type =3D OVPN_CMD_PEER_DEL_NTF;
@@ -865,8 +843,7 @@
}

struct nlattr *dp_attrs[OVPN_A_KEYCONF_MA= X + 1];
- if= (nla_parse_nested(dp_attrs, OVPN_A_KEYCONF_MAX,
- attrs[OVPN_A_KE= YCONF], NULL))
+ = if (nla_parse_nested(dp_attrs, OVPN_A_KEYCONF_MAX, attrs[OVPN_A_KEYC= ONF], NULL))
{
= msg(D_DCO, "ovpn-dco: can't parse keyconf in KEY_SWAP_NTF messag= e");
return NL_STOP;
= @@ -885,8 +862,9 @@
int key_id =3D nla_get_u16= (dp_attrs[OVPN_A_KEYCONF_KEY_ID]);
unsigned in= t peer_id =3D nla_get_u32(dp_attrs[OVPN_A_KEYCONF_PEER_ID]);

- msg(D_= DCO_DEBUG, "ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex: %d, peer-id = %u, key-id: %d",
-= ifindex, peer_id, key_id);
+ msg(D_DCO_DEBUG,
+ "ovpn-dco: received = CMD_KEY_SWAP_NTF, ifindex: %d, peer-id %u, key-id: %d", ifindex,
+ peer_id, = key_id);
dco->dco_message_peer_id =3D peer_= id;
dco->dco_message_key_id =3D key_id;
dco->dco_message_type =3D OVPN_CMD_KEY_SWAP_NT= F;
@@ -931,49 +909,41 @@
if (tb[OVPN_A= _PEER_LINK_RX_BYTES])
{
c2-&g= t;dco_read_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_LINK_RX_BYTES]);
- msg(D_DCO_DEBUG, &= quot;%s / dco_read_bytes: " counter_format, __func__,
- c2->dco_read_bytes);
+ msg(D_DCO_DEBU= G, "%s / dco_read_bytes: " counter_format, __func__, c2->dco_r= ead_bytes);
}
else
{

- msg(M= _WARN, "%s: no link RX bytes provided in reply for peer %u",
- __func__, id);=
+ msg(M_WARN,= "%s: no link RX bytes provided in reply for peer %u", __func__, = id);
}

if (tb[O= VPN_A_PEER_LINK_TX_BYTES])
{
= c2->dco_write_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_LINK_TX_BYTES])= ;
- msg(D_DCO_DE= BUG, "%s / dco_write_bytes: " counter_format, __func__,- c2->dco_write_by= tes);
+ msg(D_= DCO_DEBUG, "%s / dco_write_bytes: " counter_format, __func__, c2-= >dco_write_bytes);
}
else
{
- = msg(M_WARN, "%s: no link TX bytes provided in reply for peer %u&q= uot;,
- __fu= nc__, id);
+ m= sg(M_WARN, "%s: no link TX bytes provided in reply for peer %u", = __func__, id);
}

= if (tb[OVPN_A_PEER_VPN_RX_BYTES])
{
= c2->tun_read_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_VPN_RX_= BYTES]);
- msg(D= _DCO_DEBUG, "%s / tun_read_bytes: " counter_format, __func__,
- c2->tun_re= ad_bytes);
+ m= sg(D_DCO_DEBUG, "%s / tun_read_bytes: " counter_format, __func__,= c2->tun_read_bytes);
}
else
{
-= msg(M_WARN, "%s: no VPN RX bytes provided in reply for peer %u= ",
- __= func__, id);
+ = msg(M_WARN, "%s: no VPN RX bytes provided in reply for peer %u",= __func__, id);
}

= if (tb[OVPN_A_PEER_VPN_TX_BYTES])
{
c2->tun_write_bytes =3D ovpn_nla_get_uint(tb[OVPN_A_PEER_VPN_T= X_BYTES]);

- msg= (D_DCO_DEBUG, "%s / tun_write_bytes: " counter_format, __func__,<= /span>
- c2->tun= _write_bytes);
+ = msg(D_DCO_DEBUG, "%s / tun_write_bytes: " counter_format, __fu= nc__, c2->tun_write_bytes);
}
= else
{
- msg(M_WARN, "%s: no VPN TX bytes provided in reply for p= eer %u",
- = __func__, id);
+ = msg(M_WARN, "%s: no VPN TX bytes provided in reply for peer %u&= quot;, __func__, id);
}
}
<= span>

@@ -985,8 +955,7 @@

msg(D_DCO_DEBUG, "%s: parsing message...", __func__);

- nla_= parse(tb, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0),
- genlmsg_attrlen(gnlh, 0), NULL);
+ nla_parse(tb, OVP= N_A_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);=

if (!tb[OVPN_A_PEER])
= {
@@ -1007,8 +976,7 @@

= if (peer_id >=3D m->max_clients || !m->instances[peer_id])
{
- = msg(M_WARN, "%s: cannot store DCO stats for peer %u", __fun= c__,
- peer_= id);
+ msg(M_W= ARN, "%s: cannot store DCO stats for peer %u", __func__, peer_id)= ;
return NL_SKIP;
}
@@ -1034,8 +1002,8 @@
if (rai= se_sigusr1_on_err && ret < 0)
{
<= span> msg(M_WARN, "Error retrieving DCO peer stats: the underl= ying DCO peer"

- = "may have been deleted from the kernel without notifying &qu= ot;
- "= userspace. Restarting the session");
+ "may have been deleted from = the kernel without notifying "
+ "userspace. Restarting the session= ");
register_signal(m->top.sig, SIGUSR1, &= quot;dco peer stats error");
}
= return ret;
@@ -1050,8 +1018,7 @@

msg(D_DCO_DEBUG, "%s: parsing message...", __fun= c__);

- nla_parse(tb, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0),
- genlmsg_attrlen(gnlh, 0)= , NULL);
+ nla_par= se(tb, OVPN_A_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NUL= L);

if (!tb[OVPN_A_PEER])
= {
@@ -1111,8 +1078,8 @@
if = (raise_sigusr1_on_err && ret < 0)
{<= br> msg(M_WARN, "Error retrieving DCO peer stats: the un= derlying DCO peer"
- "may have been deleted from the kernel without notifying= "
- &q= uot;userspace. Restarting the session");
+ "may have been deleted f= rom the kernel without notifying "
+ "userspace. Restarting the ses= sion");
register_signal(c->sig, SIGUSR1, &= quot;dco peer stats error");
}
= return ret;
@@ -1123,8 +1090,7 @@
{
if (resolve_ovpn_netlink_id(D_DCO_DEBUG) < 0) {
- = msg(msglevel,
- = "Note: Kernel support for ovpn-dco missing, disabling data channe= l offload.");
+ = msg(msglevel, "Note: Kernel support for ovpn-dco missing, disab= ling data channel offload.");
return false;
}

diff --git a/src/op= envpn/dco_linux.h b/src/openvpn/dco_linux.h
index 4e441ec..= 1800752 100644
--- a/src/openvpn/dco_linux.h
+++ b/src/openvpn/dco_linux.h

@@ -32,7 +32,7 @@ #include <netlink/netlink.h>

/* Defines to avoid mismatching with other platforms */

-#define OVPN_CMD_DEL_PEER OVPN_CMD_PEE= R_DEL_NTF
+#define OV= PN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF
#define OVPN_CMD_SW= AP_KEYS OVPN_CMD_KEY_SWAP_NTF

typedef en= um ovpn_key_slot dco_key_slot_t;
@@ -42,12 +42,14 @@=

#ifndef IFLA_OVPN_MAX
=
-enum ovpn_mode {
<= span style=3D"color: hsl(120, 100%, 40%);">+enum ovpn_mode

+{
OVPN_MODE_P2P= ,
OVPN_MODE_MP,
};
<= /span>
-enum ovpn_ifla_attrs {=
+enum ovpn_ifla_attr= s
+{
= IFLA_OVPN_UNSPEC =3D 0,
IFLA_OVPN_MODE,
diff --git a/src/openvpn/dco_win.c b/src/openvpn/d= co_win.c
index 2a13658..ff8205b 100644
--- = a/src/openvpn/dco_win.c
+++ b/src/openvpn/dco_win.c<= br>@@ -76,14 +76,12 @@

bool re= s =3D false;

- HANDLE h =3D CreateFile("\\\\.\\ovpn-dco-ver", GENER= IC_READ,
- = 0, NULL, OPEN_EXISTING, 0, NULL);
+ HANDLE h =3D CreateFile("\\\\.\\ovpn-dc= o-ver", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

if (h =3D=3D INVALID_HANDLE_VALUE)
{

/* fallback to a "normal" device= , this will fail if device is already in use */
- h =3D CreateFile("\\\\.\\ovpn-dco&qu= ot;, GENERIC_READ,
- = 0, NULL, OPEN_EXISTING, 0, NULL);
+ h =3D CreateFile("\\\\.\\ovp= n-dco", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
}


if (h =3D=3D INVALID_HANDLE= _VALUE)
@@ -92,8 +90,8 @@
}
=
DWORD bytes_returned =3D 0;
- if (!DeviceIoControl(h, OVPN_IOCTL_G= ET_VERSION, NULL, 0,
- = version, sizeof(*version), &bytes_returned, NUL= L))
+ if (!DeviceI= oControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0, version, sizeof(*version),
+ = &bytes_returned, NULL))
{
= goto done;
}
@@ -146,7 +144,8 @@
/* set mp mode */
OVPN_MODE m =3D O= VPN_MODE_MP;
DWORD bytes_returned =3D 0;
- if (!DeviceIoControl(dco->tt= ->hand, OVPN_IOCTL_SET_MODE, &m, sizeof(m), NULL, 0, &bytes_retu= rned, NULL))

+ if = (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_SET_MODE, &m, sizeof(= m), NULL, 0,
+ = &bytes_returned, NULL))
{=
msg(M_ERR, "DeviceIoControl(OVPN_IOCTL_SET_MODE) fa= iled");
}
@@ -220,7 +219,7 @@
{
volatile int *signal_received =3D &= ;sig_info->signal_received;
/* GetOverlappedResultE= x is available starting from Windows 8 */
- typedef BOOL (WINAPI *get_overlapped_result_ex_t)(H= ANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
+ typedef BOOL(WINAPI * get_overlapped_result_ex_= t)(HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
get_ov= erlapped_result_ex_t get_overlapped_result_ex =3D
= (get_overlapped_result_ex_t)GetProcAddress(GetModuleHandle("Kernel32.d= ll"),
= "GetOverlappedResultEx");
@@ -294,8 +293,8 @@=
}
if (!cur)
= {
- msg(M_FATAL= , "%s: Socket bind failed: Addr to bind has no %s record",=
- __func__, addr_f= amily_name(ai_family));
+ msg(M_FATAL, "%s: Socket bind failed: Addr to bind has no = %s record", __func__,
+ addr_family_name(ai_family));
}

OVPN_MP_START_VPN in, out;
@@ -321,7 +320,8 @@

}

void

-dco_p2p_new_pe= er(HANDLE handle, OVERLAPPED *ov, struct link_socket *sock, struct signal_i= nfo *sig_info)
+dco_p= 2p_new_peer(HANDLE handle, OVERLAPPED *ov, struct link_socket *sock,=
+ struct si= gnal_info *sig_info)
{
msg(D_DCO_DEBU= G, "%s", __func__);

@@ -332,8 += 332,7 @@
struct sockaddr *local =3D NULL;
struct sockaddr *remote =3D remoteaddr->ai_addr;


- if (remoteaddr= ->ai_protocol =3D=3D IPPROTO_TCP
- || remoteaddr->ai_socktype =3D=3D SOCK_STREAM)
+ if (remoteaddr->= ai_protocol =3D=3D IPPROTO_TCP || remoteaddr->ai_socktype =3D=3D SOCK_ST= REAM)
{
peer.Proto =3D OVPN_P= ROTO_TCP;
}
@@ -405,15 +404,15 @@
}
else
= {
- dco_c= onnect_wait(handle, ov, get_server_poll_remaining_time(sock->server_poll= _timeout), sig_info);
+ dco_connect_wait(handle, ov, get_server_poll_remaining_time(s= ock->server_poll_timeout),
+ sig_info);
= }
}
}

int

-dco_new_peer(d= co_context_t *dco, unsigned int peerid, int sd,
- struct sockaddr *localaddr, struct s= ockaddr *remoteaddr,
- = struct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6)
= +dco_new_peer(dco_context_t *dc= o, unsigned int peerid, int sd, struct sockaddr *localaddr,
+ struct sockaddr *remot= eaddr, struct in_addr *vpn_ipv4, struct in6_addr *vpn_ipv6)

{

msg(D_DCO_DEBUG, "%s: peer-id %d, fd %d"= , __func__, peerid, sd);

@@ -423,7 +422,7= @@
return 0;
}

- OVPN_MP_NEW_P= EER newPeer =3D {0};
= + OVPN_MP_NEW_PEER newPeer =3D { 0 };

= if (remoteaddr)
{
@@ -453,7 +452,= 8 @@
newPeer.PeerId =3D peerid;

DWORD bytesReturned;
- if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP= _NEW_PEER, &newPeer, sizeof(newPeer), NULL, 0, &bytesReturned, NULL= ))
+ if (!DeviceIo= Control(dco->tt->hand, OVPN_IOCTL_MP_NEW_PEER, &newPeer, sizeof(n= ewPeer), NULL, 0,
+ = &bytesReturned, NULL))
{
msg(M_ERR, "DeviceIoControl(OVPN_IOCTL_MP_NEW_P= EER) failed");
}
@@ -488,11 +488,= 11 @@
}

int
<= span style=3D"color: hsl(0, 100%, 40%);">-dco_set_peer(dco_context_t *dco, = unsigned int peerid,

- = int keepalive_interval, int keepalive_timeout, int mss)<= br>+dco_set_peer(dco_context_t = *dco, unsigned int peerid, int keepalive_interval, int keepalive_timeout,
+ int mss)=
{
- = msg(D_DCO_DEBUG, "%s: peer-id %d, keepalive %d/%d, mss %d", __f= unc__,
- peerid,= keepalive_interval, keepalive_timeout, mss);
+ msg(D_DCO_DEBUG, "%s: peer-id %d, keepal= ive %d/%d, mss %d", __func__, peerid,
+ keepalive_interval, keepalive_timeout, mss);=

OVPN_MP_SET_PEER mp_peer =3D { peer= id, keepalive_interval, keepalive_timeout, mss };
OVPN= _SET_PEER peer =3D { keepalive_interval, keepalive_timeout, mss };@@ -522,14 +522,12 @@
}
int
-dco_new_k= ey(dco_context_t *dco, unsigned int peerid, int keyid,
- dco_key_slot_t slot,- const uint8_t *encr= ypt_key, const uint8_t *encrypt_iv,
- const uint8_t *decrypt_key, const uint8_t *decryp= t_iv,
- cons= t char *ciphername)
+= dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_key_slo= t_t slot,
+ = const uint8_t *encrypt_key, const uint8_t *encrypt_iv, const uint8_t *dec= rypt_key,
+ = const uint8_t *decrypt_iv, const char *ciphername)
{
- msg(D_DCO_DEBUG, &quo= t;%s: slot %d, key-id %d, peer-id %d, cipher %s",
- __func__, slot, keyid, peerid, cip= hername);
+ msg(D_= DCO_DEBUG, "%s: slot %d, key-id %d, peer-id %d, cipher %s", __fun= c__, slot, keyid, peerid,
+ ciphername);

const int= nonce_len =3D 8;
size_t key_len =3D cipher_kt_key_siz= e(ciphername);
@@ -554,8 +552,8 @@
=
DWORD bytes_returned =3D 0;

- if (!DeviceIoControl(dco->tt-= >hand, OVPN_IOCTL_NEW_KEY, &crypto_data,

- sizeof(crypto_data), NUL= L, 0, &bytes_returned, NULL))
+ if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_NEW_= KEY, &crypto_data, sizeof(crypto_data), NULL,
+ 0, &bytes_return= ed, NULL))
{
msg(M_ERR, "= ;DeviceIoControl(OVPN_IOCTL_NEW_KEY) failed");
= return -1;
@@ -565,8 +563,7 @@
int
dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_sl= ot_t slot)
{
- msg(D_DCO, "%s: peer-id %d, slot %d called but ignored&quo= t;, __func__, peerid,
-= slot);
+ m= sg(D_DCO, "%s: peer-id %d, slot %d called but ignored", __func__,= peerid, slot);
/* FIXME: Implement in driver first */=
return 0;
}
@@ -576,= 7 +573,7 @@
{
msg(D_DCO_DEBUG, "= %s: peer-id %d", __func__, peer_id);

- OVPN_MP_SWAP_KEYS swap =3D {peer_= id};

+ OVPN_MP_SWA= P_KEYS swap =3D { peer_id };
DWORD ioctl =3D OVPN_IOCT= L_SWAP_KEYS;
VOID *buf =3D NULL;
= DWORD len =3D 0;
@@ -601,8 +598,8 @@
dco_a= vailable(int msglevel)
{
/* try to op= en device by symbolic name */
- HANDLE h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_RE= AD | GENERIC_WRITE,
- = 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FIL= E_FLAG_OVERLAPPED, NULL);
+ HANDLE h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ= | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
+ FILE_ATTRIBUTE_SYSTEM | FIL= E_FLAG_OVERLAPPED, NULL);

if (h !=3D= INVALID_HANDLE_VALUE)
{
@@ -627,7 +62= 4,7 @@
const char *
dco_version_string(st= ruct gc_arena *gc)
{
- OVPN_VERSION version =3D {0};
+ OVPN_VERSION version =3D { 0 }; if (dco_get_version(&version))
{
struct buffer out =3D alloc_buf_gc(256, gc);
= @@ -658,7 +655,8 @@
BOOL res =3D GetOverlappedRe= sult(dco->tt->hand, &dco->ov, &bytes_read, FALSE);<= br> if (res)
{
- msg(D_DCO_DEBUG, "%s: completion%s suc= cess [%ld]", __func__, queued ? "" : " non-queued"= , bytes_read);
+ = msg(D_DCO_DEBUG, "%s: completion%s success [%ld]", __func__, q= ueued ? "" : " non-queued",
+ bytes_read);

dco->dco_message_peer_id =3D dco->notif_buf.Peer= Id;
dco->dco_message_type =3D dco->notif_buf= .Cmd;
@@ -733,8 +731,8 @@
ZeroMemory(&= amp;stats, sizeof(OVPN_STATS));

DWOR= D bytes_returned =3D 0;
- if (!DeviceIoControl(tt->hand, OVPN_IOCTL_GET_STATS, NULL, 0,
- &= amp;stats, sizeof(stats), &bytes_returned, NULL))
+ if (!DeviceIoControl(tt->hand, OVP= N_IOCTL_GET_STATS, NULL, 0, &stats, sizeof(stats),
+ &bytes_retu= rned, NULL))
{
msg(M_WARN | M= _ERRNO, "DeviceIoControl(OVPN_IOCTL_GET_STATS) failed"); return -1;
@@ -764,7 +762,8 @@
<= span> /* the overlapped IOCTL will signal this event on I/O complet= ion */

ASSERT(ResetEvent(dco->ov.hEvent));

- = if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_NOTIFY_EVENT, NULL, 0,= &dco->notif_buf, sizeof(dco->notif_buf), NULL, &dco->ov))=
+ if (!Device= IoControl(dco->tt->hand, OVPN_IOCTL_NOTIFY_EVENT, NULL, 0, &dco-&= gt;notif_buf,
+ = sizeof(dco->notif_buf), NULL, &dco->ov))
{
DWORD err =3D GetLas= tError();
if (err =3D=3D ERROR_IO_PENDING) /* = operation queued? */
@@ -825,17 +824,21 @@
= }

void
-dco_win_add_iroute_ipv4(dco_context_t *dco, in_addr_t = dst, unsigned int netbits, unsigned int peer_id)
+dco_win_add_iroute_ipv4(dco_context_t *dco, in= _addr_t dst, unsigned int netbits,
+ unsigned int peer_id)
{

struct gc_arena gc =3D gc_new();
=
- OVPN_MP_IROUTE r= oute =3D {.Addr.Addr4.S_un.S_addr =3D dst, .Netbits =3D netbits, .PeerId = =3D peer_id, .IPv6 =3D 0};
+ OVPN_MP_IROUTE route =3D {
+ .Addr.Addr4.S_un.S_addr =3D dst, .Netbits =3D net= bits, .PeerId =3D peer_id, .IPv6 =3D 0
+ };

- msg(D_DCO_DEBUG, "%s: %s/%d -> peer %d&qu= ot;, __func__, print_in_addr_t(dst, IA_NET_ORDER, &gc), netbits, peer_i= d);
+ msg(D_DCO_DE= BUG, "%s: %s/%d -> peer %d", __func__, print_in_addr_t(dst, IA= _NET_ORDER, &gc),
+ netbits, peer_id);

DWORD b= ytes_returned =3D 0;
- = if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_MP_ADD_IROUTE, &= ;route,
- = sizeof(route), NULL, 0, &bytes_returned, NULL))
+ if (!DeviceIoControl(dco->= ;tt->hand, OVPN_IOCTL_MP_ADD_IROUTE, &route, sizeof(route), NULL, 0,=

+ = &bytes_returned, NULL))
{
= msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_MP_ADD_IROUTE= ) failed");
}
@@ -844,17 +847,19 = @@
}

void
-dco_win_add_iroute_ipv6(dco_context= _t *dco, struct in6_addr dst, unsigned int netbits, unsigned int peer_id)
+dco_win_add_iroute_ip= v6(dco_context_t *dco, struct in6_addr dst, unsigned int netbits,+ unsig= ned int peer_id)
{
struct gc_arena gc= =3D gc_new();

OVPN_MP_IROUTE route = =3D { .Addr.Addr6 =3D dst, .Netbits =3D netbits, .PeerId =3D peer_id, .IPv6= =3D 1 };

- msg(D_DCO_DEBUG, "%s: %s/%d -> peer %d", __func__, p= rint_in6_addr(dst, IA_NET_ORDER, &gc), netbits, peer_id);
+ msg(D_DCO_DEBUG, "%s: %s= /%d -> peer %d", __func__, print_in6_addr(dst, IA_NET_ORDER, &g= c),

+ netbits,= peer_id);

DWORD bytes_returned =3D = 0;
- if (!DeviceIoCo= ntrol(dco->tt->hand, OVPN_IOCTL_MP_ADD_IROUTE, &route,
= - sizeof(= route), NULL, 0, &bytes_returned, NULL))
+ if (!DeviceIoControl(dco->tt->hand, OVPN= _IOCTL_MP_ADD_IROUTE, &route, sizeof(route), NULL, 0,
+ &bytes_r= eturned, NULL))
{
msg(M_WARN = | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_MP_ADD_IROUTE) failed");
}
@@ -867,13 +872,15 @@
{

struct gc_arena gc =3D gc_new();
=
- OVPN_MP_IROUTE ro= ute =3D { .Addr.Addr4.S_un.S_addr =3D dst, .Netbits =3D netbits, .PeerId = =3D -1, .IPv6 =3D 0 };
+ .Addr.Addr4.S_un.S_addr =3D dst, .Netbits =3D netbits= , .PeerId =3D -1, .IPv6 =3D 0
+ };

msg(D_DCO_DEBUG, &q= uot;%s: %s/%d", __func__, print_in_addr_t(dst, IA_NET_ORDER, &gc),= netbits);

DWORD bytes_returned =3D = 0;
- if (!DeviceIoCo= ntrol(dco->tt->hand, OVPN_IOCTL_MP_DEL_IROUTE, &route,
= - sizeof(= route), NULL, 0, &bytes_returned, NULL))
+ if (!DeviceIoControl(dco->tt->hand, OVPN= _IOCTL_MP_DEL_IROUTE, &route, sizeof(route), NULL, 0,
+ &bytes_r= eturned, NULL))
{
msg(M_WARN = | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_MP_DEL_IROUTE) failed");
}
@@ -891,8 +898,8 @@
= msg(D_DCO_DEBUG, "%s: %s/%d", __func__, print_in6_addr(dst, I= A_NET_ORDER, &gc), netbits);

DWO= RD bytes_returned =3D 0;
- = sizeof(route), NULL, 0, &bytes_returned, NULL))+ if (!DeviceIoControl(dco= ->tt->hand, OVPN_IOCTL_MP_DEL_IROUTE, &route, sizeof(route), NULL= , 0,
+ = &bytes_returned, NULL))
{
msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_MP_DEL_IR= OUTE) failed");

}
diff --git a/sr= c/openvpn/dco_win.h b/src/openvpn/dco_win.h
index 4513f3f..= 5e489da 100644
--- a/src/openvpn/dco_win.h
= +++ b/src/openvpn/dco_win.h
@@ -33,21 +33,23 @@
<= span> typedef OVPN_KEY_SLOT dco_key_slot_t;

typedef OVPN_C= IPHER_ALG dco_cipher_t;

-typedef enum {
+typedef enum
+{
DCO_MODE_UNINIT,
DCO_MO= DE_P2P,
DCO_MODE_MP
} dco_mode_type;<= /span>

-stru= ct dco_context {
+str= uct dco_context
+{
struct tuntap *tt;
dco_mode_type if= mode;

OVPN_NOTIFY_EVENT notif_buf; /= **< Buffer for incoming notifications. */
- OVERLAPPED ov; /**< Used by overlapped I/O fo= r async IOCTL. */
- = int iostate; /**< State of overlapped I/O; see definitions in win32.h. *= /
- struct rw_handle= rwhandle; /**< Used to hook async I/O to the OpenVPN event loop. */
- int ov_ret; /**< W= in32 error code for overlapped operation, 0 for success */
+ OVERLAPPED ov; /**= < Used by overlapped I/O for async IOCTL. */
+ int iostate; /**< State = of overlapped I/O; see definitions in win32.h. */
+ struct rw_handle rwhandle; /**< Used= to hook async I/O to the OpenVPN event loop. */
+ int ov_ret; /**< Win32= error code for overlapped operation, 0 for success */

int dco_message_peer_id;
int dco_me= ssage_type;
@@ -59,31 +61,26 @@
typedef struct dco_context dco_context_t;
<= br>-void
-dco_mp_start_vpn(HANDLE handle, struct link_so= cket *sock);
+void dc= o_mp_start_vpn(HANDLE handle, struct link_socket *sock);
<= /span>
-void
-dco_p2p_new_peer(HANDLE handle, OVERLAP= PED *ov, struct link_socket *sock, struct signal_info *sig_info);+void dco_p2p_new_peer(HANDLE = handle, OVERLAPPED *ov, struct link_socket *sock,
+ struct signal_info *sig= _info);

-void
-dco_start_tun= (struct tuntap *tt);
= +void dco_start_tun(struct tuntap *tt);

-bool
-dco_win_supports_multipeer(void);
+bool dco_win_supports_multipeer(void);

-void
-dco_win_add_iroute_ipv4= (dco_context_t *dco, in_addr_t dst, unsigned int netbits, unsigned int peer= _id);
+void dco_win_a= dd_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned int netbits,
+ = unsigned int peer_id);

-void
-dco_win_add_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, un= signed int netbits, unsigned int peer_id);
+void dco_win_add_iroute_ipv6(dco_context_t *dco, str= uct in6_addr dst, unsigned int netbits,
+ unsigned int peer_id);

-void
-dco_win_del_iroute_ipv4(= dco_context_t *dco, in_addr_t dst, unsigned int netbits);
+void dco_win_del_iroute_ipv4(dco_cont= ext_t *dco, in_addr_t dst, unsigned int netbits);
<= br>-void
-dco_win_del_iroute_ipv6(dco_context_t *dco, st= ruct in6_addr dst, unsigned int netbits);
+void dco_win_del_iroute_ipv6(dco_context_t *dco, stru= ct in6_addr dst, unsigned int netbits);

-#else /* if defined(ENABLE_DCO) &&a= mp; defined(_WIN32) */
- const uint8= _t *p =3D (uint8_t *) (dhcp + 1);
+ const uint8_t *p =3D (uint8_t *)(dhcp + 1);
int i;


for (i =3D 0; i < = optlen; ++i)
{
const uint8_t = type =3D p[i];
const int room =3D optlen - i;
- if (type =3D=3D DH= CP_END) /* didn't find what we were looking for */
+ if (type =3D=3D DHCP_END= ) /* didn't find what we were looking for */

{=
return -1;
}<= br>- else if (type =3D=3D = DHCP_PAD) /* no-operation */
+ else if (type =3D=3D DHCP_PAD) /* no-operation */
{
}
e= lse if (type =3D=3D DHCP_MSG_TYPE) /* what we are looking for */
= {
if (room >=3D 3) {
-= if (p[i+1] =3D=3D 1) /* option length should be 1 */
+ if (p= [i + 1] =3D=3D 1) /* option length should be 1 */
= {
- = return p[i+2]; /* return message type */
+ return p[i + 2]; /* r= eturn message type */
}
= }
return -1;
= }
- else = /* some other option */
+ else /* some other option */
{

if (room >=3D 2)
{

- = const int len =3D p[i+1]; /* get option length */
- i +=3D (len + 1); = /* advance to next option */

+ const int len =3D p[i + 1]; /* get option le= ngth */
+ = i +=3D (len + 1); /* advance to next option */
}

}
}@@ -76,11 +76,11 @@
static in_addr_t
do_extract(struct dhcp *dhcp, int optlen)

{
= - uint8_t *p =3D (uint8_t *) (= dhcp + 1);
+ uint8= _t *p =3D (uint8_t *)(dhcp + 1);
int i;
in_addr_t ret =3D 0;


- for (i =3D 0; i < optlen; )
+ for (i =3D 0; i < optlen;)
{
const uint8_t type =3D p[i];<= /span>
const int room =3D optlen - i;
@@ = -96,25 +96,25 @@
{
if= (room >=3D 2)
{
- const int len =3D p[i+1]; /* get= option length */
- = if (len <=3D (room-2))
+ const int len =3D p[i + 1]; /* get option= length */
+ = if (len <=3D (room - 2))
{
/* get router IP address */
if (!ret && len >=3D 4 && (len &am= p; 3) =3D=3D 0)

{
- memcpy(&ret, p= +i+2, 4);
+ = memcpy(&ret, p + i + 2, 4);
= ret =3D ntohl(ret);
}
{
= /* delete the router option */
ui= nt8_t *dest =3D p + i;
= - const int owlen =3D len + 2; /* len of data= to overwrite */
+ = const int owlen =3D len + 2; /* len of data to overwri= te */
uint8_t *src =3D dest + owle= n;
uint8_t *end =3D p + optlen;
const int movlen =3D end - src;
if (movlen > 0)
= {
- memmove(dest, src, movlen); /* overwrite ro= uter option */
+ = memmove(dest, src, movlen); /* overwrite route= r option */
}
= memset(end - owlen, DHCP_PAD, owlen); /* pad tail */
}
@@ -129,12 +129,12 @@=
break;
}
}
- else /* some other option */+ else /* some other op= tion */
{
if (room &g= t;=3D 2)
{
- const int len =3D p[i+1]; /* get option l= ength */
- = i +=3D (len + 2); /* advance to next option */
+ const int len =3D p[i= + 1]; /* get option length */
+ i +=3D (len + 2); /* advance to next o= ption */
}
else
{
@@ -148,13 +148,13 @@<= br> in_addr_t
dhcp_extract_router_msg(struct buffer = *ipbuf)
{
- struct dhcp_full *df =3D (struct dhcp_full *) BPTR(ipbuf);<= br>- const int optlen =3D BLEN= (ipbuf) - (sizeof(struct openvpn_iphdr) + sizeof(struct openvpn_udphdr) + s= izeof(struct dhcp));
= + struct dhcp_full *df =3D (struct dhcp_full *)BPTR(ipbuf);
+ const int optlen =3D
<= br>+ BLEN(ipbuf)<= br>+ - (sizeof(struct op= envpn_iphdr) + sizeof(struct openvpn_udphdr) + sizeof(struct dhcp));=

- if (op= tlen >=3D 0
- = && df->ip.protocol =3D=3D OPENVPN_IPPROTO_UDP
- && df->udp.source = =3D=3D htons(BOOTPS_PORT)
- && df->udp.dest =3D=3D htons(BOOTPC_PORT)
= + if (optlen >=3D 0 &= & df->ip.protocol =3D=3D OPENVPN_IPPROTO_UDP
+ && df->udp.source =3D= =3D htons(BOOTPS_PORT) && df->udp.dest =3D=3D htons(BOOTPC_PORT)=
&& df->dhcp.op =3D=3D BOOTREPLY)
{
const int message_type =3D get_d= hcp_message_type(&df->dhcp, optlen);
@@ -165,10 +165= ,10 @@

/* recompute the UDP = checksum */
df->udp.check =3D 0;
= - df->udp.check =3D= htons(ip_checksum(AF_INET, (uint8_t *)&df->udp,
- = sizeof(struct openvpn_udphdr) + sizeof(struct dhcp) + optlen,- = (uint8_t *)&df->ip.saddr, (uint8_t *)&df->ip.= daddr,
- = OPENVPN_IPPROTO_UDP));
+ df->udp.check =3D htons(ip= _checksum(
+ = AF_INET, (uint8_t *)&df->udp,
+ sizeof(struct openvpn_udphdr) + siz= eof(struct dhcp) + optlen,
+ (uint8_t *)&df->ip.saddr, (uint8_t *)&df-= >ip.daddr, OPENVPN_IPPROTO_UDP));

= /* only return the extracted Router address if DHCPACK */ if (message_type =3D=3D DHCPACK)
diff = --git a/src/openvpn/dhcp.h b/src/openvpn/dhcp.h
index c578c= 6a..109d97c 100644
--- a/src/openvpn/dhcp.h
+++ b/src/openvpn/dhcp.h

@@ -31,10 +31,10 @@
#pragma pack(1)


/* DHCP Option types= */
-#define DHCP_PAD = 0
-#define DHCP= _ROUTER 3
-#defin= e DHCP_MSG_TYPE 53 /* message type (u8) */
-#define DHCP_END 255
+#define DHCP_PAD 0
+#define DHCP_ROUTER 3
+#define DHCP_MSG_TYPE 53 /* messa= ge type (u8) */

+#def= ine DHCP_END 255

/* DHCP Messages t= ypes */
#define DHCPDISCOVER 1
@@ -50,28 += 50,30 @@
#define BOOTPS_PORT 67
#define B= OOTPC_PORT 68

-struct dhcp {
+struct dhcp
+{
#define BOOTREQUEST 1
#define BOOTREPLY 2=
- uint8_t op; = /* message op */
+ = uint8_t op; /* message op */

- uint8_t htype; /* hardware addr= ess type (e.g. '1' =3D 10Mb Ethernet) */
- uint8_t hlen; /* hardware address lengt= h (e.g. '6' for 10Mb Ethernet) */
- uint8_t hops; /* client sets to 0, may be used= by relay agents */
- = uint32_t xid; /* transaction ID, chosen by client */
- uint16_t secs; /* seconds sin= ce request process began, set by client */

+ uint8_t htype; /* hardware address type (e.= g. '1' =3D 10Mb Ethernet) */
+ uint8_t hlen; /* hardware address length (e.g. &= #39;6' for 10Mb Ethernet) */
+ uint8_t hops; /* client sets to 0, may be used by re= lay agents */
+ ui= nt32_t xid; /* transaction ID, chosen by client */
+ uint16_t secs; /* seconds sin= ce request process began, set by client */
uint16_t fl= ags;
- uint32_t ciad= dr; /* client IP address, client sets if known */
- uint32_t yiaddr; /* 'your' IP= address -- server's response to client */
- uint32_t siaddr; /* server IP address */
- uint32_t giaddr; /*= relay agent IP address */
+ uint32_t ciaddr; /* client IP address, client sets if known *= /
+ uint32_t yiadd= r; /* 'your' IP address -- server's response to client */
+ uint32_t siaddr; = /* server IP address */
+ uint32_t giaddr; /* relay agent IP address */
= uint8_t chaddr[16]; /* client hardware address */
- uint8_t sname[64]; /* optional server = host name */
- uint8= _t file[128]; /* boot file name */
- uint32_t magic; /* must be 0x63825363 (network order) *= /
+ uint8_t sname[= 64]; /* optional server host name */
+ uint8_t file[128]; /* boot file name */
+ uint32_t magic; /* must = be 0x63825363 (network order) */

};

-struct dhcp_full {<= br>+struct dhcp_full
= +{
struct = openvpn_iphdr ip;
struct openvpn_udphdr udp; struct dhcp dhcp;
diff --git a/src/openvpn/dns.= c b/src/openvpn/dns.c
index ea3d91b..00d6ecb 100644<= br>--- a/src/openvpn/dns.c
+++ b/src/openvpn/dns.c
@@ -66,7 +66,7 @@
return false;
}

- char addrcopy[INET6_ADDRSTRLEN] =3D {0};
+ char addrcopy[INET6_ADDRSTRLEN]= =3D { 0 };

size_t copylen =3D 0;
= in_port_t port =3D 0;
sa_family_t af;
@@ -203,13 +203,13 @@

bool
dns_options_v= erify(int msglevel, const struct dns_options *o)
{<= br>- const struct dns_server *= server =3D
- o-&= gt;servers ? o->servers : o->servers_prepull;
+ const struct dns_server *server =3D o= ->servers ? o->servers : o->servers_prepull;
= while (server)
{
if (server-&= gt;addr_count =3D=3D 0)
{
- msg(msglevel, "ERROR: dns ser= ver %ld does not have an address assigned", server->priority);
+ msg(msglevel= , "ERROR: dns server %ld does not have an address assigned",
+ server-&= gt;priority);
return false;
= }
server =3D server->next;
@@ -353,8 +353,8 @@

#ifdef _WIN32

static void
-make_domain_list(const char *what, const struct dns_domain *src,=
- bool nrpt_d= omains, char *dst, size_t dst_size)
+make_domain_list(const char *what, const struct dns_domain = *src, bool nrpt_domains, char *dst,
+ size_t dst_size)
{=
/* NRPT domains need two \0 at the end for REG_MULTI_SZ
* and a leading '.' added in front of the domain = name */
@@ -430,11 +430,8 @@

ack_message_t ack;

nrpt_dns_cfg_message_t nrp= t =3D {
- .heade= r =3D {
- (a= dd ? msg_add_nrpt_cfg : msg_del_nrpt_cfg),
- sizeof(nrpt_dns_cfg_message_t),
= - 0
- },
+ .header =3D { (add ? msg_add_nrpt_cfg : m= sg_del_nrpt_cfg), sizeof(nrpt_dns_cfg_message_t),
+ 0 },
= .iface =3D { .index =3D tt->adapter_index, .name =3D "" }= ,
.flags =3D server->dnssec =3D=3D DNS_SECURITY= _NO ? 0 : nrpt_dnssec,
};
@@ -448,28 += 445,27 @@
break;
}

- = if (inet_ntop(server->addr[i].family, &server->addr[i].in,
- nrpt= .addresses[i], NRPT_ADDR_SIZE) =3D=3D NULL)
+ if (inet_ntop(server->addr[i].family, &a= mp;server->addr[i].in, nrpt.addresses[i],
+ NRPT_ADDR_SIZE)
+ =3D=3D NULL)
<= br> {
msg(M_WARN, "WARNING:= could not convert dns server address");
}
}

- make_domain_list("dns server resolve domains"= ;, server->domains, true,
- nrpt.resolve_domains, sizeof(nrpt.resolve_domai= ns));
+ make_domai= n_list("dns server resolve domains", server->domains, true, nr= pt.resolve_domains,
+= sizeof(nrpt.resolve_domains));

- make_domain_list("= dns search domains", search_domains, false,
- nrpt.search_domains, sizeof= (nrpt.search_domains));
+ make_domain_list("dns search domains", search_domains, fa= lse, nrpt.search_domains,
+ sizeof(nrpt.search_domains));
<= /span>
send_msg_iservice(o->msg_channel, &nrpt, sizeof= (nrpt), &ack, "DNS");
}

-#else /* ifdef _WIN32 */=
+#else /* ifdef _WI= N32 */

static void
-setenv_dns_option(struct env_set *es,
- const cha= r *format, int i, int j,
+setenv_dns_option(struct env_set *es, const char *forma= t, int i, int j, const char *value)
{
= char name[64];
bool name_ok =3D false;
@@ -535,14 +531,12 @@


if (s-&g= t;dnssec)
{
- setenv_dns_option(es, "dns_server_%d_dnssec= ", i, -1,
- = dnssec_value(s->dnssec));
+ setenv_dns_option(es, "d= ns_server_%d_dnssec", i, -1, dnssec_value(s->dnssec));
}


if (s->transpo= rt)
{
- setenv_dns_option(es, "dns_server_%d_transport&qu= ot;, i, -1,
- = transport_value(s->transport));
+ setenv_dns_option(es, "= dns_server_%d_transport", i, -1, transport_value(s->transport));
}
if (s->sni)
= {
@@ -562,7 +556,8 @@
}

static int
-do_run_up_down_command(bool up, const char *vars_file,= const struct dns_options *o, const struct tuntap *tt)
+do_run_up_down_command(bool up, const ch= ar *vars_file, const struct dns_options *o,
+ const struct tuntap *tt)
{
struct gc_arena gc =3D gc_new();
struct argv argv =3D argv_new();
@@ -594,12= +589,12 @@
}

static bo= ol
-run_updown_runner(b= ool up, struct options *o, const struct tuntap *tt, struct dns_updown_runne= r_info *updown_runner)
+ str= uct dns_updown_runner_info *updown_runner)
{
int dns_pipe_fd[2];

int ack_pipe_fd[2];=
- if (pipe(dns_pipe_fd) != =3D 0
- || pipe(= ack_pipe_fd) !=3D 0)
= + if (pipe(dns_pipe_fd) !=3D 0 || pipe(ack_pipe_fd) !=3D 0)
{

msg(M_ERR | M_ERRNO, "run_dns_up_d= own: unable to create pipes");
return false;<= /span>
@@ -627,8 +622,7 @@
/* Script runn= er process, close unused FDs */
for (int fd =3D 3;= fd < 100; ++fd)
{
- if (fd !=3D dns_pipe_fd[0]
<= span style=3D"color: hsl(0, 100%, 40%);">- && fd != =3D ack_pipe_fd[1])

+= if (fd !=3D dns_pipe_fd[0] && fd !=3D ack_pipe_fd[1])
{
close(fd);
}
@@ -689,7 +683,8 @@ }

static void
-run_up_down_command(bool up, struct opti= ons *o, const struct tuntap *tt, struct dns_updown_runner_info *updown_runn= er)
+run_up_down_comm= and(bool up, struct options *o, const struct tuntap *tt,
+ struct dns_updown_= runner_info *updown_runner)
{
struct = dns_options *dns =3D &o->dns_options;
if (!dns-= >updown || (o->up_script && !dns_updown_user_set(dns) &&a= mp; !dns_updown_forced(dns)))
@@ -847,7 +842,8 @@ }

void
-run_dns_up_down(bool up, struct options *o, con= st struct tuntap *tt, struct dns_updown_runner_info *duri)
+run_dns_up_down(bool up, struct opti= ons *o, const struct tuntap *tt,
+ struct dns_updown_runner_info *duri) {
if (!o->dns_options.servers)
{

@@ -877,14 +873,17 @@
}=
if (bad_count =3D=3D s->addr_count)
= {
- = msg(M_WARN, "DNS server %ld only has address(es) from a family = "
+ m= sg(M_WARN,
+ = "DNS server %ld only has address(es) from a family "
"the tunnel is not configured for - it wil= l not be reachable",
s->priority);=
}
else if (bad_count)
{
- = "the tunnel is not configured for", s->priority);+ msg(M_WARN,
+ "DN= S server %ld has address(es) from a family "
+ "the tunnel is not confi= gured for",
+ = s->priority);
}
= s =3D s->next;
}
diff --git = a/src/openvpn/dns.h b/src/openvpn/dns.h
index d33f64e..9610= 358 100644
--- a/src/openvpn/dns.h
+++ b/sr= c/openvpn/dns.h
@@ -28,33 +28,39 @@
#inclu= de "env_set.h"
#include "tun.h"=

-enum dns_s= ecurity {
+enum dns_s= ecurity
+{
= DNS_SECURITY_UNSET,
DNS_SECURITY_NO,=
DNS_SECURITY_YES,
DNS_SECURITY_OPTIONAL=
};

-enum dns_server_transport {
+enum dns_server_transport
+{
DNS_TRANSPORT_UNSET,<= /span>
DNS_TRANSPORT_PLAIN,
DNS_TRANSPOR= T_HTTPS,
DNS_TRANSPORT_TLS
};<= br>
-enum dns_up= down_flags {
+enum dn= s_updown_flags
+{
DNS_UPDOWN_NO_FLAGS,
DNS_UPDOWN_USER= _SET,
DNS_UPDOWN_FORCED
};
=
-struct dns_dom= ain {
+struct dns_dom= ain
+{
struct dns_domain *next;

const char *name;
};

-struct dns_server_addr {
- union {
+struct dns_server_addr
+{
+ unio= n
+ {
struct in_addr a4;

struct in6_addr a6= ;
} in;
@@ -62,7 +68,8 @@
in_port_t port;

};

-struct dns_server {

+struct dns_server

+{
struct dns_se= rver *next;
long priority;
size_t= addr_count;
@@ -73,7 +80,8 @@
const c= har *sni;
};

-struct dns_updown_runner_info {
+struct dns_updown_runner_info<= br>+{
bool= required;
int fds[2];
#if !defined(_= WIN32)
@@ -89,7 +97,8 @@
#define N_SEARCH_= LIST_LEN 10
#endif

-struct dhcp_options {
+struct dhcp_options
+{
in_addr_t dns[N_DH= CP_ADDR];
int dns_len;

@@ -101,7 +110,8 @@

int domain_search_list_len;
};

-struct dns_options {
+struct dns_options
+{
struct dhcp_options from_dhcp; struct dns_domain *search_domains;
struct= dns_server *servers_prepull;
@@ -166,8 +176,7 @@ * @param gc Pointer to the gc_arena to use for the clon= e
* @return The dns_options clone
= */
-struct dns_= options clone_dns_options(const struct dns_options *o,
- struc= t gc_arena *gc);
+str= uct dns_options clone_dns_options(const struct dns_options *o, struct gc_ar= ena *gc);

/**
* Saves = and resets the server options, so that pulled ones don't mix in.=
diff --git a/src/openvpn/env_set.c b/src/openvpn/env_set.c=
index f20ee8a..9a5681d 100644
--- a/src/openvpn/e= nv_set.c
+++ b/src/openvpn/env_set.c
@@ -24= 7,7 +247,7 @@

if (es)
{

- const= struct env_item *item =3D es->list;
+ const struct env_item *item =3D es->list;
while (item)
{
<= span> fputs(item->string, fp);

@@ -357,15 +3= 57,10 @@
}

void<= br>-setenv_str_ex(struct env_set = *es,
- con= st char *name,
- = const char *value,
- const unsigned int name_include,
- const unsigned int name_exclude,=
- const c= har name_replace,
- = const unsigned int value_include,
- const unsigned int value_exclude,
- const char va= lue_replace)
+setenv_= str_ex(struct env_set *es, const char *name, const char *value,
<= span style=3D"color: hsl(120, 100%, 40%);">+ const unsigned in= t name_include, const unsigned int name_exclude,

+ const char name_replace, const u= nsigned int value_include,
+ const unsigned int value_exclude, const char value_rep= lace)
{
struct gc_arena gc =3D gc_new= ();
const char *name_tmp;
@@ -443,9 +4= 38,7 @@
/* Make arrays of strings */

const char **
-make_env_array(const struct env_set *es,
- const bool check_allowed,- struct gc_arena = *gc)
+make_env_array(= const struct env_set *es, const bool check_allowed, struct gc_arena *gc)
{
char **ret =3D NULL;
= struct env_item *e =3D NULL;
@@ -461,7 +454,7 @@
}

/* alloc return ar= ray */
- ALLOC_ARRAY= _CLEAR_GC(ret, char *, n+1, gc);
+ ALLOC_ARRAY_CLEAR_GC(ret, char *, n + 1, gc);

/* fill return array */
if = (es)
diff --git a/src/openvpn/env_set.h b/src/openvpn/env_s= et.h
index 52c5312..5bbccbd 100644
--- a/sr= c/openvpn/env_set.h
+++ b/src/openvpn/env_set.h
<= span>@@ -34,26 +34,23 @@

* Handle environmental variable = lists
*/

-struct env_item {
+struct env_item
+{
char *string;
= struct env_item *next;
};

-struct env_set {

+struct env_set
+{
struct gc_arena *gc;<= /span>
struct env_item *list;
};
<= span>

/* set/delete environmental variable */
<= span style=3D"color: hsl(0, 100%, 40%);">-void setenv_str_ex(struct env_set= *es,

- = const char *name,
- = const char *value,
- const unsigned int name_include,- const unsig= ned int name_exclude,
-= const char name_replace,
- const unsigned int value_include,<= /span>
- con= st unsigned int value_exclude,
- const char value_replace);
+void setenv_str_ex(struct env_set *es, c= onst char *name, const char *value,
+ const unsigned int name_include, const u= nsigned int name_exclude,
+ const char name_replace, const unsigned int value_= include,
+ = const unsigned int value_exclude, const char value_replace);=

void setenv_counter(struct env_set *es, const = char *name, counter_type value);

@@ -124,= 8 +121,7 @@
/* returns true if environmental variable may = be passed to an external program */
bool env_allowed(const= char *str);

-const char **make_env_array(const struct env_set *es,
- const = bool check_allowed,

+= const char **make_env_array(const struct env_set *es, const bool check_allo= wed,
struct gc_arena *gc);

#endif /* ifndef ENV_SET_H */
diff --git a/src/openvpn/errlevel.h b/src/openvpn/errlevel.h

<= span>index fc3e64a..dce09c2 100644

--- a/src/openvpn/errlev= el.h
+++ b/src/openvpn/errlevel.h
@@ -50,13= 4 +50,134 @@
* of output.
*/
=
-#define M_VERB= 0 LOGLEV(0, 0, 0) /* Messages displayed even at --verb= 0 (fatal errors only) */
+#define M_VERB0 LOGLEV(0, 0, 0) /* Messages displayed even at --verb = 0 (fatal errors only) */

-#define M_INFO LOGLEV(1, 0, 0) /= * default informational messages */
+#define M_INFO LOGLEV(1, 0, 0) /* default informational me= ssages */

-#define D_LINK_ERRORS LOGLEV(1, 1, M_NONFATAL) /* show link = errors from main event loop */
-#define D_CRYPT_ERRORS LOGLEV(1, 2, M_NONFATAL) /* show er= rors from encrypt/decrypt */
-#define D_TLS_ERRORS LOGLEV(1, 3, M_NONFATAL) /* show TLS = control channel errors */
-#define D_RESOLVE_ERRORS LOGLEV(1, 4, M_NONFATAL) /* show hostnam= e resolve errors */
-#d= efine D_COMP_ERRORS LOGLEV(1, 5, M_NONFATAL) /* show compression e= rrors */
-#define D_REP= LAY_ERRORS LOGLEV(1, 6, M_NONFATAL) /* show packet replay errors */<= /span>
-#define D_STREAM_ERROR= S LOGLEV(1, 7, M_NONFATAL) /* TCP stream error requiring restart */=
-#define D_IMPORT_ERRO= RS LOGLEV(1, 8, M_NONFATAL) /* show server import option errors */<= /span>
-#define D_MULTI_ERRORS= LOGLEV(1, 9, M_NONFATAL) /* show multi-client server errors */
-#define D_EVENT_ERRORS = LOGLEV(1, 10, M_NONFATAL) /* show event.[ch] errors */
-#define D_PUSH_ERRORS LOGLEV= (1, 11, M_NONFATAL) /* show push/pull errors */

-#define D_PID_PERSIST LOGLEV(1, 12, M_NO= NFATAL) /* show packet_id persist errors */
-#define D_FRAG_ERRORS LOGLEV(1, 13, M_NONFAT= AL) /* show fragmentation errors */
-#define D_ALIGN_ERRORS LOGLEV(1, 14, M_NONFATAL) /*= show bad struct alignments */
+#define D_LINK_ERRORS LOGLEV(1, 1, M_NONFATAL) /* show link = errors from main event loop */
+#define D_CRYPT_ERRORS LOGLEV(1, 2, M_NONFATAL) /* show error= s from encrypt/decrypt */
+#define D_TLS_ERRORS LOGLEV(1, 3, M_NONFATAL) /* show TLS contro= l channel errors */
+= #define D_RESOLVE_ERRORS LOGLEV(1, 4, M_NONFATAL) /* show hostname resolve= errors */
+#define D= _COMP_ERRORS LOGLEV(1, 5, M_NONFATAL) /* show compression errors */
+#define D_REPLAY_ERRORS= LOGLEV(1, 6, M_NONFATAL) /* show packet replay errors */
+#define D_STREAM_ERRORS LOGLEV(1, = 7, M_NONFATAL) /* TCP stream error requiring restart */

+#define D_IMPORT_ERRORS LOGLEV(1, 8, = M_NONFATAL) /* show server import option errors */
+#define D_MULTI_ERRORS LOGLEV(1, 9, M_N= ONFATAL) /* show multi-client server errors */
+#define D_EVENT_ERRORS LOGLEV(1, 10, M_NONFAT= AL) /* show event.[ch] errors */
+#define D_PUSH_ERRORS LOGLEV(1, 11, M_NONFATAL) /* show pus= h/pull errors */
+#de= fine D_PID_PERSIST LOGLEV(1, 12, M_NONFATAL) /* show packet_id persist e= rrors */
+#define D_F= RAG_ERRORS LOGLEV(1, 13, M_NONFATAL) /* show fragmentation errors */
+#define D_ALIGN_ERRORS = LOGLEV(1, 14, M_NONFATAL) /* show bad struct alignments */

-#define D_HANDSHAK= E LOGLEV(2, 20, 0) /* show data & control channel hands= hakes */
-#define D_CLO= SE LOGLEV(2, 22, 0) /* show socket and TUN/TAP close */=
-#define D_PROXY = LOGLEV(2, 24, 0) /* show http proxy control packets */
-#define D_ARGV = LOGLEV(2, 25, 0) /* show struct argv errors */
+#define D_HANDSHAKE LOGLEV(2, 20, 0) = /* show data & control channel handshakes */
+#define D_CLOSE LOGLEV(2, 22, = 0) /* show socket and TUN/TAP close */

+#define D_PROXY LOGLEV(2, 24, 0) = /* show http proxy control packets */
+#define D_ARGV LOGLEV(2, 25, 0) = /* show struct argv errors */

-#define D_TLS_DEBUG_LOW LOGLEV(3, 20, = 0) /* low frequency info from tls_session routines */
-#define D_GREMLIN LOGLEV(= 3, 30, 0) /* show simulated outage info from gremlin module */
-#define D_GENKEY = LOGLEV(3, 31, 0) /* print message after key generation */-#define D_ROUTE L= OGLEV(3, 0, 0) /* show routes added and deleted (don't mute) */=
-#define D_TUNTAP_INFO= LOGLEV(3, 32, 0) /* show debugging info from TUN/TAP driver = */
-#define D_RESTART = LOGLEV(3, 33, 0) /* show certain restart messages */
-#define D_PUSH = LOGLEV(3, 34, 0) /* show push/pull info */
-#define D_IFCONFIG_POOL LOGLEV(3, 35, = 0) /* show ifconfig pool info */
-#define D_AUTH LOGLEV(3, 37, 0) /* s= how user/pass auth info */
-#define D_MULTI_LOW LOGLEV(3, 38, 0) /* show point-to-= multipoint low-freq debug info */
-#define D_PLUGIN LOGLEV(3, 39, 0) /* show pl= ugin calls */
-#define = D_MANAGEMENT LOGLEV(3, 40, 0) /* show --management info */
-#define D_SCHED_EXIT = LOGLEV(3, 41, 0) /* show arming of scheduled exit */-#define D_ROUTE_QUOTA LO= GLEV(3, 42, 0) /* show route quota exceeded messages */
-#define D_OSBUF LOGLE= V(3, 43, 0) /* show socket/tun/tap buffer sizes */

-#define D_PS_PROXY LOGLEV(3, = 44, 0) /* messages related to --port-share option */
-#define D_IFCONFIG LOGLEV(3= , 0, 0) /* show ifconfig info (don't mute) */

-#define D_DCO LOGLEV(3, = 0, 0) /* show DCO related messages */
+#define D_TLS_DEBUG_LOW LOGLEV(3, 20, 0) /*= low frequency info from tls_session routines */
+#define D_GREMLIN LOGLEV(3, 30, 0) = /* show simulated outage info from gremlin module */
+#define D_GENKEY LOGLEV(3, 31, 0) = /* print message after key generation */
+#define D_ROUTE LOGLEV(3, 0, 0) /= * show routes added and deleted (don't mute) */
+#define D_TUNTAP_INFO LOGLEV(3, 32, 0) = /* show debugging info from TUN/TAP driver */
+#define D_RESTART LOGLEV(3, 33, 0) = /* show certain restart messages */
+#define D_PUSH LOGLEV(3, 34, 0) /* sho= w push/pull info */
+= #define D_IFCONFIG_POOL LOGLEV(3, 35, 0) /* show ifconfig pool info *= /
+#define D_AUTH = LOGLEV(3, 37, 0) /* show user/pass auth info */
+#define D_MULTI_LOW LOGLEV(3, 3= 8, 0) /* show point-to-multipoint low-freq debug info */

+#define D_PLUGIN LOGLEV(3= , 39, 0) /* show plugin calls */

+#define D_MANAGEMENT LOGLEV(3, 40, 0) /* show -= -management info */
+= #define D_SCHED_EXIT LOGLEV(3, 41, 0) /* show arming of scheduled = exit */
+#define D_RO= UTE_QUOTA LOGLEV(3, 42, 0) /* show route quota exceeded messages */=
+#define D_OSBUF = LOGLEV(3, 43, 0) /* show socket/tun/tap buffer sizes */+#define D_PS_PROXY LOGL= EV(3, 44, 0) /* messages related to --port-share option */
= +#define D_IFCONFIG LOGLEV= (3, 0, 0) /* show ifconfig info (don't mute) */
+#define D_DCO LOGLEV(3, 0,= 0) /* show DCO related messages */

-#define D_SHOW_PARMS LOGLEV(= 4, 50, 0) /* show all parameters on program initiation */

= -#define D_LOW LOG= LEV(4, 52, 0) /* miscellaneous low-frequency debug info */-#define D_DHCP_OPT LO= GLEV(4, 53, 0) /* show DHCP options binary string */
-#define D_MBUF LOGLEV(4= , 54, 0) /* mbuf.[ch] routines */

-#define D_PACKET_TRUNC_ERR LOGLEV(4, 55, 0) /* = PACKET_TRUNCATION_CHECK */
-#define D_MULTI_DROPPED LOGLEV(4, 57, 0) /* show point-to-= multipoint packet drops */
-#define D_MULTI_MEDIUM LOGLEV(4, 58, 0) /* show medium fr= equency multi messages */
-#define D_X509_ATTR LOGLEV(4, 59, 0) /* show x509-track= attributes on connection */
-#define D_INIT_MEDIUM LOGLEV(4, 60, 0) /* show medium = frequency init messages */
-#define D_MTU_INFO LOGLEV(4, 61, 0) /* show terse MTU= info */
-#define D_PID= _DEBUG_LOW LOGLEV(4, 63, 0) /* show low-freq packet-id debuggin= g info */
-#define D_PI= D_DEBUG_MEDIUM LOGLEV(4, 64, 0) /* show medium-freq packet-id debu= gging info */
-#define = D_CIPHER_INIT LOGLEV(4, 65, 0) /* show messages about cipher = init */
+#define D_SH= OW_PARMS LOGLEV(4, 50, 0) /* show all parameters on program initia= tion */
+#define D_LO= W LOGLEV(4, 52, 0) /* miscellaneous low-frequency debug inf= o */
+#define D_DHCP_= OPT LOGLEV(4, 53, 0) /* show DHCP options binary string */
+#define D_MBUF = LOGLEV(4, 54, 0) /* mbuf.[ch] routines */
+#define D_PACKET_TRUNC_ERR LOGLEV(4, 55, 0) /= * PACKET_TRUNCATION_CHECK */
+#define D_MULTI_DROPPED LOGLEV(4, 57, 0) /* show point-to-mu= ltipoint packet drops */
+#define D_MULTI_MEDIUM LOGLEV(4, 58, 0) /* show medium frequenc= y multi messages */
+= #define D_X509_ATTR LOGLEV(4, 59, 0) /* show x509-track attribute= s on connection */
+#= define D_INIT_MEDIUM LOGLEV(4, 60, 0) /* show medium frequency init= messages */
+#define= D_MTU_INFO LOGLEV(4, 61, 0) /* show terse MTU info */+#define D_PID_DEBUG_LOW LO= GLEV(4, 63, 0) /* show low-freq packet-id debugging info */
+#define D_PID_DEBUG_MEDIUM LOGLE= V(4, 64, 0) /* show medium-freq packet-id debugging info */

+#define D_CIPHER_INIT LOGLE= V(4, 65, 0) /* show messages about cipher init */


-#define D_LOG_RW = LOGLEV(5, 0, 0) /* Print 'R' or 'W' to stdout fo= r read/write */
+#def= ine D_LOG_RW LOGLEV(5, 0, 0) /* Print 'R' or 'W&#= 39; to stdout for read/write */

-#define D_RTNL LOGLEV(6, 68, M_DE= BUG) /* show RTNL low level operations */
-#define D_LINK_RW LOGLEV(6, 69, M_DEBUG) /= * show TCP/UDP reads/writes (terse) */
-#define D_TUN_RW LOGLEV(6, 69, M_DEBUG) /* sh= ow TUN/TAP reads/writes */
-#define D_TAP_WIN_DEBUG LOGLEV(6, 69, M_DEBUG) /* show TAP-Windo= ws driver debug info */
-#define D_CLIENT_NAT LOGLEV(6, 69, M_DEBUG) /* show client NAT d= ebug info */
-#define D= _XKEY LOGLEV(6, 69, M_DEBUG) /* show xkey-provider debug inf= o */
-#define D_DCO_DEB= UG LOGLEV(6, 69, M_DEBUG) /* show DCO related lowlevel debug mess= ages */
-#define D_SIGN= AL_DEBUG LOGLEV(6, 69, M_DEBUG) /* show signal related debug message= s */
+#define D_RTNL = LOGLEV(6, 68, M_DEBUG) /* show RTNL low level operations */=
+#define D_LINK_RW LO= GLEV(6, 69, M_DEBUG) /* show TCP/UDP reads/writes (terse) */
+#define D_TUN_RW LOGLEV(6, = 69, M_DEBUG) /* show TUN/TAP reads/writes */

+#define D_TAP_WIN_DEBUG LOGLEV(6, 69, M_DEBUG) /* = show TAP-Windows driver debug info */
+#define D_CLIENT_NAT LOGLEV(6, 69, M_DEBUG) /* show cl= ient NAT debug info */
+#define D= _DCO_DEBUG LOGLEV(6, 69, M_DEBUG) /* show DCO related lowlevel debug me= ssages */
+#define D_= SIGNAL_DEBUG LOGLEV(6, 69, M_DEBUG) /* show signal related debug messages = */

-#= define D_SHOW_KEYS LOGLEV(7, 70, M_DEBUG) /* show data channel en= cryption keys */
-#defi= ne D_SHOW_KEY_SOURCE LOGLEV(7, 70, M_DEBUG) /* show data channel key so= urce entropy */
-#defin= e D_REL_LOW LOGLEV(7, 70, M_DEBUG) /* show low frequency info f= rom reliable layer */
-= #define D_FRAG_DEBUG LOGLEV(7, 70, M_DEBUG) /* show fragment debug= ging info */
-#define D= _WIN32_IO_LOW LOGLEV(7, 70, M_DEBUG) /* low freq win32 I/O debugging= info */
-#define D_MTU= _DEBUG LOGLEV(7, 70, M_DEBUG) /* show MTU debugging info */
-#define D_MULTI_DEBUG = LOGLEV(7, 70, M_DEBUG) /* show medium-freq multi debugging info */
-#define D_MSS = LOGLEV(7, 70, M_DEBUG) /* show MSS adjustments */
-#define D_COMP_LOW LOGLEV(7, 70, = M_DEBUG) /* show adaptive compression state changes */
-#define D_CONNECTION_LIST LOGLEV(7, 70= , M_DEBUG) /* show <connection> list info */
-#define D_SCRIPT LOGLEV(7, 70, = M_DEBUG) /* show parms & env vars passed to scripts */
-#define D_SHOW_NET LOGLEV(7= , 70, M_DEBUG) /* show routing table and adapter list */

-#define D_ROUTE_DEBUG LOGLEV(7, = 70, M_DEBUG) /* show verbose route.[ch] output */
-#define D_TLS_STATE_ERRORS LOGLEV(7, 70, M_D= EBUG) /* no TLS state for client */
-#define D_SEMAPHORE_LOW LOGLEV(7, 70, M_DEBUG) /* show= Win32 semaphore waits (low freq) */
-#define D_SEMAPHORE LOGLEV(7, 70, M_DEBUG) /* show= Win32 semaphore waits */
-#define D_TEST_FILE LOGLEV(7, 70, M_DEBUG) /* show test_file(= ) calls */
-#define D_M= ANAGEMENT_DEBUG LOGLEV(3, 70, M_DEBUG) /* show --management debug info *= /
-#define D_PLUGIN_DEB= UG LOGLEV(7, 70, M_DEBUG) /* show verbose plugin calls */
= -#define D_SOCKET_DEBUG LOG= LEV(7, 70, M_DEBUG) /* show socket.[ch] debugging info */
-#define D_SHOW_PKCS11 LOGLEV(7,= 70, M_DEBUG) /* show PKCS#11 actions */
-#define D_ALIGN_DEBUG LOGLEV(7, 70, M_DEBUG) /*= show verbose struct alignment info */
-#define D_PACKET_TRUNC_DEBUG LOGLEV(7, 70, M_DEBUG) /* PA= CKET_TRUNCATION_CHECK verbose */
-#define D_PING LOGLEV(7, 70, M_DEBUG) /* PING sen= d/receive messages */
-= #define D_PS_PROXY_DEBUG LOGLEV(7, 70, M_DEBUG) /* port share proxy de= bug */
-#define D_TLS_K= EYSELECT LOGLEV(7, 70, M_DEBUG) /* show key selection for data channe= l */
-#define D_ARGV_PA= RSE_CMD LOGLEV(7, 70, M_DEBUG) /* show parse_line() errors in argv_par= se_cmd */
-#define D_CR= YPTO_DEBUG LOGLEV(7, 70, M_DEBUG) /* show detailed info from crypto.= c routines */
-#define = D_PID_DEBUG LOGLEV(7, 70, M_DEBUG) /* show packet-id debugging in= fo */
-#define D_PUSH_D= EBUG LOGLEV(7, 73, M_DEBUG) /* show push/pull debugging info */
-#define D_SHOW_OCC = LOGLEV(7, 74, M_DEBUG) /* show options compatibility string */=
+#define D_SHOW_KEYS = LOGLEV(7, 70, M_DEBUG) /* show data channel encryption keys */+#define D_SHOW_KEY_SOURCE = LOGLEV(7, 70, M_DEBUG) /* show data channel key source entropy */+#define D_REL_LOW = LOGLEV(7, 70, M_DEBUG) /* show low frequency info from reliable layer */
+#define D_FRAG_DEBUG = LOGLEV(7, 70, M_DEBUG) /* show fragment debugging info */
= +#define D_WIN32_IO_LOW L= OGLEV(7, 70, M_DEBUG) /* low freq win32 I/O debugging info */
+#define D_MTU_DEBUG LOGL= EV(7, 70, M_DEBUG) /* show MTU debugging info */

+#define D_MULTI_DEBUG LOGLEV(7, 70, M_D= EBUG) /* show medium-freq multi debugging info */
+#define D_MSS LOGLEV(7, 70, M_= DEBUG) /* show MSS adjustments */
+#define D_COMP_LOW LOGLEV(7, 70, M_DEBUG) /* show a= daptive compression state changes */
+#define D_CONNECTION_LIST LOGLEV(7, 70, M_DEBUG) /* sho= w <connection> list info */
+#define D_SCRIPT LOGLEV(7, 70, M_DEBUG) /* show p= arms & env vars passed to scripts */
+#define D_SHOW_NET LOGLEV(7, 70, M_DEBUG) /*= show routing table and adapter list */
+#define D_ROUTE_DEBUG LOGLEV(7, 70, M_DEBUG) /* = show verbose route.[ch] output */
+#define D_TLS_STATE_ERRORS LOGLEV(7, 70, M_DEBUG) /* no TLS= state for client */
= +#define D_SEMAPHORE_LOW LOGLEV(7, 70, M_DEBUG) /* show Win32 semaphor= e waits (low freq) */
+#define D_SEMAPHORE LOGLEV(7, 70, M_DEBUG) /* show Win32 semapho= re waits */
+#define = D_TEST_FILE LOGLEV(7, 70, M_DEBUG) /* show test_file() calls */
+#define D_MANAGEMENT_D= EBUG LOGLEV(3, 70, M_DEBUG) /* show --management debug info */
= +#define D_PLUGIN_DEBUG L= OGLEV(7, 70, M_DEBUG) /* show verbose plugin calls */
+#define D_SOCKET_DEBUG LOGLEV(7, 70= , M_DEBUG) /* show socket.[ch] debugging info */
+#define D_SHOW_PKCS11 LOGLEV(7, 70, M_D= EBUG) /* show PKCS#11 actions */
+#define D_ALIGN_DEBUG LOGLEV(7, 70, M_DEBUG) /* show ve= rbose struct alignment info */
+#define D_PACKET_TRUNC_DEBUG LOGLEV(7, 70, M_DEBUG) /* PACKET_TR= UNCATION_CHECK verbose */
+#define D_PING LOGLEV(7, 70, M_DEBUG) /* PING send/rece= ive messages */
+#def= ine D_PS_PROXY_DEBUG LOGLEV(7, 70, M_DEBUG) /* port share proxy debug *= /
+#define D_TLS_KEYS= ELECT LOGLEV(7, 70, M_DEBUG) /* show key selection for data channel */=
+#define D_ARGV_PARS= E_CMD LOGLEV(7, 70, M_DEBUG) /* show parse_line() errors in argv_parse_= cmd */
+#define D_CRY= PTO_DEBUG LOGLEV(7, 70, M_DEBUG) /* show detailed info from crypto.c = routines */
+#define = D_PID_DEBUG LOGLEV(7, 70, M_DEBUG) /* show packet-id debugging inf= o */
+#define D_PUSH_= DEBUG LOGLEV(7, 73, M_DEBUG) /* show push/pull debugging info */
+#define D_SHOW_OCC = LOGLEV(7, 74, M_DEBUG) /* show options compatibility string */


-#define D_VLAN_DEBUG LOGLEV(7, 74, M_DEBUG) /* show VLAN = tagging/untagging debug info */
+#define D_VLAN_DEBUG LOGLEV(7, 74, M_DEBUG) /* show VLAN= tagging/untagging debug info */

-#define D_HANDSHAKE_VERBOSE LOGLEV(8, 70, M_D= EBUG) /* show detailed description of handshake */
-#define D_TLS_DEBUG_MED LOGLEV(8, 70, = M_DEBUG) /* limited info from tls_session routines */
-#define D_INTERVAL LOGLEV(8, 70,= M_DEBUG) /* show interval.h debugging info */
-#define D_SCHEDULER LOGLEV(8, 70, M_DEBU= G) /* show scheduler debugging info */
-#define D_GREMLIN_VERBOSE LOGLEV(8, 70, M_DEBUG) /* s= how verbose info from gremlin module */
-#define D_REL_DEBUG LOGLEV(8, 70, M_DEBUG) /* s= how detailed info from reliable routines */
-#define D_EVENT_WAIT LOGLEV(8, 70, M_DEBUG) = /* show detailed info from event waits */
-#define D_MULTI_TCP LOGLEV(8, 70, M_DEBUG) /*= show debug info from mtcp.c */
+#define D_HANDSHAKE_VERBOSE LOGLEV(8, 70, M_DEBUG) /* show deta= iled description of handshake */
+#define D_TLS_DEBUG_MED LOGLEV(8, 70, M_DEBUG) /* limited = info from tls_session routines */
+#define D_INTERVAL LOGLEV(8, 70, M_DEBUG) /* show in= terval.h debugging info */
+#define D_SCHEDULER LOGLEV(8, 70, M_DEBUG) /* show scheduler= debugging info */
+#= define D_GREMLIN_VERBOSE LOGLEV(8, 70, M_DEBUG) /* show verbose info from= gremlin module */
+#= define D_REL_DEBUG LOGLEV(8, 70, M_DEBUG) /* show detailed info fro= m reliable routines */
= +#define D_MULTI_TCP LOGLEV(8, 70, M_DEBUG) /* show debug info from= mtcp.c */

-#define D_TLS_DEBUG LOGLEV(9, 70, M_DEBUG) /* show detaile= d info from TLS routines */
-#define D_COMP LOGLEV(9, 70, M_DEBUG) /* show compress= ion info */
-#define D_= READ_WRITE LOGLEV(9, 70, M_DEBUG) /* show all tun/tcp/udp reads/wr= ites/opens */
-#define = D_PACKET_CONTENT LOGLEV(9, 70, M_DEBUG) /* show before/after encryptio= n packet content */
-#d= efine D_TLS_NO_SEND_KEY LOGLEV(9, 70, M_DEBUG) /* show when no data cha= nnel send-key exists */
-#define D_PID_PERSIST_DEBUG LOGLEV(9, 70, M_DEBUG) /* show packet-id pe= rsist debugging info */
-#define D_LINK_RW_VERBOSE LOGLEV(9, 70, M_DEBUG) /* increase link rea= ds/writes verbosity */
= -#define D_STREAM_DEBUG LOGLEV(9, 70, M_DEBUG) /* show TCP stream de= bug info */
-#define D_= WIN32_IO LOGLEV(9, 70, M_DEBUG) /* win32 I/O debugging info */
-#define D_PKCS11_DEBUG = LOGLEV(9, 70, M_DEBUG) /* show PKCS#11 debugging */
+#define D_TLS_DEBUG LOGLEV(9= , 70, M_DEBUG) /* show detailed info from TLS routines */
+#define D_COMP LOGLEV(9,= 70, M_DEBUG) /* show compression info */
+#define D_READ_WRITE LOGLEV(9, 70, M_DEBUG) /*= show all tun/tcp/udp reads/writes/opens */
+#define D_PACKET_CONTENT LOGLEV(9, 70, M_DEBUG) = /* show before/after encryption packet content */
+#define D_TLS_NO_SEND_KEY LOGLEV(9, 70, M_D= EBUG) /* show when no data channel send-key exists */
+#define D_PID_PERSIST_DEBUG LOGLEV(9, 70,= M_DEBUG) /* show packet-id persist debugging info */
+#define D_LINK_RW_VERBOSE LOGLEV(9, 70,= M_DEBUG) /* increase link reads/writes verbosity */
+#define D_STREAM_DEBUG LOGLEV(9, 70,= M_DEBUG) /* show TCP stream debug info */
+#define D_WIN32_IO LOGLEV(9, 70, M_DEBUG) /= * win32 I/O debugging info */
+#define D_PKCS11_DEBUG LOGLEV(9, 70, M_DEBUG) /* show PKCS#1= 1 debugging */

-#define D_SHAPER_DEBUG LOGLEV(10, 70, M_DEBUG) /* show tra= ffic shaper info */
+= #define D_SHAPER_DEBUG LOGLEV(10, 70, M_DEBUG) /* show traffic shaper i= nfo */

-#defi= ne D_OPENSSL_LOCK LOGLEV(11, 70, M_DEBUG) /* show OpenSSL locks */
+#define D_REGISTRY = LOGLEV(11, 70, M_DEBUG) /* win32 registry debugging info */
= +#define D_OPENSSL_LOCK LOGLEV(= 11, 70, M_DEBUG) /* show OpenSSL locks */

<= span style=3D"color: hsl(0, 100%, 40%);">-/*#define D_THREAD_DEBUG LO= GLEV(4, 70, M_DEBUG)*/ /* show pthread debug information */

+/*#define D_THREAD_DEBUG LOG= LEV(4, 70, M_DEBUG)*/ /* show pthread debug information */

=
-#endif /* ifndef ERR= LEVEL_H */
+#endif = /* ifndef ERRLEVEL_H */
diff --git a/src/openvpn/error.c b/src/openvpn/error.cindex 049cd92..d79d76a 100644
--- a/src/openvpn/err= or.c
+++ b/src/openvpn/error.c
@@ -52,9 +52= ,9 @@
unsigned int x_debug_level; /* GLOBAL */
<= span>

/* Mute state */
-static int mute_cutoff; /* GLOBAL */
-static int mute_count; /* GLOBAL= */

-static int mute_ca= tegory; /* GLOBAL */
+static int mute_count; /* GLOBAL */
+static int mute_category; /* GLOBA= L */


/*
* Output mode = priorities are as follows:
@@ -68,28 +68,28 @@

/* If true, indicates that stdin/stdout/stderr
* have been redirected due to --log */
-static bool std_redir; /* GLOBAL */
+static bool std_redir;= /* GLOBAL */

/* Should messages be writ= ten to the syslog? */
-= static bool use_syslog; /* GLOBAL */
+static bool use_syslog; /* GLOBAL */
=
/* Should stdout/stderr be be parsable and always be pref= ixed with time
* and message flags */
-static bool machine_readable_output; /*= GLOBAL */
+static bo= ol machine_readable_output; /* GLOBAL */

= /* Should timestamps be included on messages to stdout/stderr? */ static bool suppress_timestamps; /* GLOBAL */

/* The program name passed to syslog */
#if= SYSLOG_CAPABILITY
-sta= tic char *pgmname_syslog; /* GLOBAL */
+static char *pgmname_syslog; /* GLOBAL */
#endif


/* If non-null, messages shou= ld be written here (used for debugging only) */
-static FILE *msgfp; /* GLOBAL */+static FILE *msgfp; /* GLOBA= L */

/* If true, we forked from main Ope= nVPN process */
-static= bool forked; /* GLOBAL */
+static bool forked; /* GLOBAL */
/* our default output targets */
static FILE *defa= ult_out; /* GLOBAL */
@@ -176,7 +176,7 @@
= {
openvpn_exit(OPENVPN_EXIT_STATUS_CANNOT_OPEN= _DEBUG_FILE); /* exit point */
}
-#else /* ifdef OPENVPN_DEBUG_COMMAND_LINE = */
+#else /* ifdef OP= ENVPN_DEBUG_COMMAND_LINE */
msgfp =3D NULL;
= #endif
}
@@ -196,7 +196,7 @@=
FILE *fp =3D msgfp;
if (!fp)
= {
- f= p =3D (flags & (M_FATAL|M_USAGE_SMALL)) ? default_err : default_out;
+ fp =3D (flags = & (M_FATAL | M_USAGE_SMALL)) ? default_err : default_out;
}

if (!fp)
{
@@ -205,7 +205,12 @@

return fp;
}=

-#de= fine SWAP { tmp =3D m1; m1 =3D m2; m2 =3D tmp; }
+#define SWAP \
+ { \
+ tmp =3D m1; \
+ m1 =3D m2; \
+ m2 =3D tmp; \
+ }

int x_msg_line_num; /* GLOBAL */


@@ -26= 6,16 +271,15 @@

gc_init(&gc);

- m1= =3D (char *) gc_malloc(ERR_BUF_SIZE, false, &gc);
- m2 =3D (char *) gc_malloc(ERR_BUF_SIZE= , false, &gc);
+ = m1 =3D (char *)gc_malloc(ERR_BUF_SIZE, false, &gc);
+ m2 =3D (char *)gc_malloc(ERR_BUF= _SIZE, false, &gc);

vsnprintf(m1= , ERR_BUF_SIZE, format, arglist);
m1[ERR_BUF_SIZE - 1]= =3D 0; /* windows vsnprintf needs this */

if ((flags & M_ERRNO) && e)

{
- snprintf(m2, ERR_BU= F_SIZE, "%s: %s (errno=3D%d)",
- m1, openvpn_strerror(e, crt_error, &= ;gc), e);
+ sn= printf(m2, ERR_BUF_SIZE, "%s: %s (errno=3D%d)", m1, openvpn_strer= ror(e, crt_error, &gc), e);
SWAP;
}


@@ -286,7 +290,7 @@
= }

#if SYSLOG_CAPABILITY
- if (flags & (M_FATA= L|M_NONFATAL|M_USAGE_SMALL))
+ if (flags & (M_FATAL | M_NONFATAL | M_USAGE_SMALL))=
{
level =3D LOG_ERR;
}

@@ -321,10 +325,7 @@
cons= t struct virtual_output *vo =3D msg_get_virtual_output();
= if (vo)
{
- snprintf(m2, ERR_BUF_SIZE, "%s%s%s&qu= ot;,
- = prefix,
- = prefix_sep,
= - m1);
+ snprintf(m2, ERR_BUF_SIZE, "%s%s%s", prefix, p= refix_sep, m1);
virtual_output_print(vo, flags= , m2);
}
}
@@= -334,10 +335,7 @@
if (use_syslog && !std_= redir && !forked)
{
#if S= YSLOG_CAPABILITY
- = syslog(level, "%s%s%s",
- prefix,
- prefix_sep,
- m1);
+ syslog(level, "%s%s%s= ", prefix, prefix_sep, m1);
#endif
= }
else
@@ -350,32 +348,17 @= @
struct timeval tv;
= gettimeofday(&tv, NULL);

- fprintf(fp, "%&qu= ot; PRIi64 ".%06ld %x %s%s%s%s",
- (int64_t)tv.tv_sec,
= - (long)tv= .tv_usec,
- = flags,
- = prefix,
- prefix_sep,
- m1,
- "\n");<= br>-
+ fprintf(fp, "%" PRIi64= ".%06ld %x %s%s%s%s", (int64_t)tv.tv_sec, (long)tv.tv_usec,
+ = flags, prefix, prefix_sep, m1, "\n");
= }
else if ((flags & M_NOPREFIX) || suppr= ess_timestamps)
{
- fprintf(fp, "%s%s%s%s",<= /span>
- = prefix,
- = prefix_sep,
- m1,
- (flags&M_NOLF) ? "" : "\= n");
+ = fprintf(fp, "%s%s%s%s", prefix, prefix_sep, m1, (flags &= ; M_NOLF) ? "" : "\n");
}<= /span>
else
{
= - fprintf(fp, &quo= t;%s %s%s%s%s",
- = time_string(0, 0, show_usec, &gc),
- prefix,
- p= refix_sep,
- = m1,
- = (flags&M_NOLF) ? "" : "\n");
+ fprintf= (fp, "%s %s%s%s%s", time_string(0, 0, show_usec, &gc), prefix= , prefix_sep,
+ = m1, (flags & M_NOLF) ? "" : "\n")= ;
}
fflush(fp);
++x_msg_line_num;
@@ -390,7 +37= 3,6 @@
if (flags & M_FATAL)
{=
openvpn_exit(OPENVPN_EXIT_STATUS_ERROR); /* exit = point */
-
}

if (flags & M_USAGE_SMALL)
{

@@ -427,8 +409,7 @@
= if (suppressed > 0)
{
= msg(M_INFO | M_NOMUTE,
- "%d variation(s) on previous %d mess= age(s) suppressed by --mute",
- suppressed,
+ "%d variation(s) on previ= ous %d message(s) suppressed by --mute", suppressed,
= mute_cutoff);
}
= mute_count =3D 1;
@@ -482,8 +463,9 @@
}
}
= }
-#else /* if SYSLO= G_CAPABILITY */
- ms= g(M_WARN, "Warning on use of --daemon: this operating system lacks dae= mon logging features, therefore when I become a daemon, I won't be able= to log status or error messages");
+#else /* if SYSLOG_CAPABILITY */
+ msg(M_WARN,
+ "Warning on use of --daemon: thi= s operating system lacks daemon logging features, therefore when I become a= daemon, I won't be able to log status or error messages");=
#endif
}

@@ -= 526,19 +508,14 @@
saAttr.bInheritHandle =3D TRUE;<= /span>
saAttr.lpSecurityDescriptor =3D NULL;

- log_hand= le =3D CreateFileW(wide_string(file, &gc),
- GENERIC_WRITE,
- = FILE_SHARE_READ,
- &saAttr,
- append ? OPEN_= ALWAYS : CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- NULL);=
+ log_handle = =3D CreateFileW(wide_string(file, &gc), GENERIC_WRITE, FILE_SHARE_READ,= &saAttr,
+ = append ? OPEN_ALWAYS : CREATE_ALWAYS, FILE_ATTRI= BUTE_NORMAL, NULL);

gc_free(&= ;gc);

if (log_handle =3D=3D INVA= LID_HANDLE_VALUE)
{
- msg(M_WARN|M_ERRNO, "Warning: canno= t open --log file: %s", file);
+ msg(M_WARN | M_ERRNO, "Warning: cannot ope= n --log file: %s", file);
return;<= br> }

@@ -555,7 +532,8 @@
orig_stderr =3D _dup(_fileno(stderr));
if (orig_stderr =3D=3D -1)

{- msg(M_WARN | M_ERR= NO, "Warning: cannot duplicate stderr, password prompts will appear in= log file instead of console.");
+ msg(M_WARN | M_ERRNO,
+ "Warning: cannot dup= licate stderr, password prompts will appear in log file instead of console.= ");
orig_stderr =3D _fileno(stderr);
}

@@ -585,13 +563,12= @@
#elif defined(HAVE_DUP2)
if (!std= _redir)
{
- int out =3D open(file,
- O_CREAT | O_WRONLY | (append ? O_A= PPEND : O_TRUNC),
- = S_IRUSR | S_IWUSR);
+ int out =3D open(file, O_CREAT | O_WRONLY | (app= end ? O_APPEND : O_TRUNC), S_IRUSR | S_IWUSR);

= if (out < 0)
{
- msg(M_WARN|M_ERRNO, "W= arning: Error redirecting stdout/stderr to --log file: %s", file);
+ msg(M_WARN = | M_ERRNO, "Warning: Error redirecting stdout/stderr to --log file: %s= ",
+ = file);
return;
}<= /span>

@@ -613,7 +590,8 @@
= }

#else /* if defined(_WIN32) */=
- msg(M_WARN, "WARNIN= G: The --log option is not supported on this OS because it lacks the dup2 f= unction");
+ = msg(M_WARN,
+ = "WARNING: The --log option is not supported on this OS because it lack= s the dup2 function");
#endif /* if defined(_WIN32) *= /
}

@@ -649,10 +627,7 @@=
* from the OS.
*/
voi= d
-x_check_status(int s= tatus,
- = const char *description,
- struct tuntap *tt)
+x_check_status(int status, const char *= description, struct link_socket *sock, struct tuntap *tt)
= {
const char *extended_msg =3D NULL;
=
@@ -660,9 +635,7 @@
int my_errno =3D = openvpn_errno_maybe_crt(&crt_error);

= msg(x_cs_verbose_level, "%s %s returned %d",
- sock ? proto2ascii(sock->i= nfo.proto, sock->info.af, true) : "",

- description,
- status);
+ sock ? proto2ascii(sock->info.proto, so= ck->info.af, true) : "", description, status);

if (status < 0)
{@@ -694,16 +667,14 @@
if (extended_msg)=
{
msg(x_cs_i= nfo_level, "%s %s [%s]: %s (fd=3D" SOCKET_PRINTF ",code=3D%d= )", description,
-= sock ? proto2ascii(sock->info.proto, sock->info.a= f, true) : "",
- = sock ? sock->sd : -1, my_errno);
+ sock ? proto2ascii(sock->inf= o.proto, sock->info.af, true) : "", extended_msg,
+ openvpn_stre= rror(my_errno, crt_error, &gc), sock ? sock->sd : -1, my_errno);
}
else
{

msg(x_cs_info_level, &qu= ot;%s %s: %s (fd=3D" SOCKET_PRINTF ",code=3D%d)", descriptio= n,
sock ? proto2ascii(sock->info.pr= oto, sock->info.af, true) : "",
- openvpn_strerror(my_errno, crt_e= rror, &gc),
- = sock ? sock->sd : -1, my_errno);
+ openvpn_strerror(my_errno= , crt_error, &gc), sock ? sock->sd : -1, my_errno);
= }

if (x_cs_err_= delay_ms)
@@ -971,16 +942,10 @@
wc= har_t wmessage[256];
char *message =3D NULL;
struct buffer out =3D alloc_buf_gc(256, gc);
= - const DWORD status =3D = FormatMessageW(
- = FORMAT_MESSAGE_IGNORE_INSERTS
- | FORMAT_MESSAGE_FROM_SYSTEM
- | FORMAT_MESSAGE_ARGUMENT_ARRA= Y,
- NULL,
- errnum,
- 0,
= - wmessage,
= - SIZE(wmessage),
- NULL);<= br>+ const DWORD status = =3D
+ Form= atMessageW(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM
+ = | FORMAT_MESSAGE_ARGUMENT_ARRAY,
+ NULL, errnum, 0, wmessage, SI= ZE(wmessage), NULL);
if (status)
= {
message =3D utf16to8(wmessage, gc);<= /span>
diff --git a/src/openvpn/error.h b/src/openvpn/error.h
index e0a2730..1625df1 100644
--- a/src/openvpn= /error.h
+++ b/src/openvpn/error.h
@@ -50,1= 0 +50,10 @@
* Exit status codes
*/

-#define = OPENVPN_EXIT_STATUS_GOOD 0
-#define OPENVPN_EXIT_STATUS_ERROR = 1
-#define OPENVPN_EXI= T_STATUS_USAGE 1
-#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE 1+#define OPENVPN_EXIT_STATUS_= GOOD 0
+#define OPENVPN_EXIT_STATUS_ERROR 1
+#define OPENVPN_EXIT_STATUS_USAGE = 1
+#def= ine OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE 1
/*
* Special command line debugging mode.=
@@ -84,27 +84,27 @@

/* msg() f= lags */

-#define M_DEBUG_LEVEL (0x0F) /* debug level mask */<= br>+#define M_DEBUG_LEVEL (0x0F= ) /* debug level mask */

-#define M_FATAL (1<<4) /* exit= program */
-#define M_= NONFATAL (1<<5) /* non-fatal error */
-#define M_WARN (1<<6)= /* call syslog with LOG_WARNING */
-#define M_DEBUG (1<<7)
+#define M_FATAL (1 << 4) = /* exit program */

+= #define M_NONFATAL (1 << 5) /* non-fatal error */
+#define M_WARN (1 << 6) /* = call syslog with LOG_WARNING */
+#define M_DEBUG (1 << 7)

<= span style=3D"color: hsl(0, 100%, 40%);">-#define M_ERRNO (1<&= lt;8) /* show errno description */

+#define M_ERRNO (1 << 8) /* show errno= description */

-#define M_NOMUTE (1<<11) /* don't do = mute processing */
-#de= fine M_NOPREFIX (1<<12) /* don't show date/time pre= fix */
-#define M_USAGE= _SMALL (1<<13) /* fatal options error, call usage_small */=
-#define M_MSG_VIRT_OU= T (1<<14) /* output message through msg_status_output callb= ack */
-#define M_OPTER= R (1<<15) /* print "Options error:" prefix = */
-#define M_NOLF = (1<<16) /* don't print new line */
-#define M_NOIPREFIX (1<<17= ) /* don't print instance prefix */
+#define M_NOMUTE (1 << 11) /* don= 9;t do mute processing */
+#define M_NOPREFIX (1 << 12) /* don't show date/time pr= efix */
+#define M_US= AGE_SMALL (1 << 13) /* fatal options error, call usage_small */
+#define M_MSG_VIRT_OUT (= 1 << 14) /* output message through msg_status_output callback */
+#define M_OPTERR (= 1 << 15) /* print "Options error:" prefix */
+#define M_NOLF (1 <<= 16) /* don't print new line */

+#define M_NOIPREFIX (1 << 17) /* don't print i= nstance prefix */

/* flag combinations w= hich are frequently used */
-#define M_ERR (M_FATAL | M_ERRNO)
-#define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPT= ERR)
-#define M_CLIENT = (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX)
+#define M_ERR (M_FATAL | M_ERRNO)
+#define M_USAGE (M_USAGE_SMALL | M= _NOPREFIX | M_OPTERR)

+#define M_CLIENT (M_MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX)

/*
* Mute levels are designed to avo= id large numbers of
@@ -113,10 +113,10 @@
= * A mute level of 0 is always printed.
*/
#define MUTE_LEVEL_SHIFT 24

-#define MUTE_LEVEL_MASK 0xFF
+#define MUTE_LEVEL_MASK 0xFF
#define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEV= EL_MASK) << MUTE_LEVEL_SHIFT)
-#define DECODE_MUTE_LEVEL(flags) (((flags) >> MUTE_LEVE= L_SHIFT) & MUTE_LEVEL_MASK)
+#define DECODE_MUTE_LEVEL(flags) (((flags) >> MUTE_L= EVEL_SHIFT) & MUTE_LEVEL_MASK)

/*
* log_level: verbosity level n (--verb n) must be >=3D = log_level to print.
@@ -139,11 +139,34 @@
= bool dont_mute(unsigned int flags);

/* M= acro to ensure (and teach static analysis tools) we exit on fatal errors */=
-#define EXIT_FATAL(fl= ags) do { if ((flags) & M_FATAL) {_exit(1);}} while (false)
<= span style=3D"color: hsl(120, 100%, 40%);">+#define EXIT_FATAL(flags) = \

+ do = \
+ {= \
+ if ((flags) & M_FATAL) \
+ { \
+ _exit(1); \
+ } = \
+ } while= (false)

-#define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA= _ARGS__);} EXIT_FATAL(flags); } while (false)
+#define msg(flags, ...) \=
+ do = \
+ = { \
+ if (msg_test(flags)) \
+ { = \

+ = x_msg((flags), __VA_ARGS__); \
+ } \
+ EXIT_FATAL(flags); = \
+ } while (fa= lse)
#ifdef ENABLE_DEBUG
-#define dmsg(flags, ...) do { if (msg_test(flags)) {x_m= sg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
+#define dmsg(flags, ...) = \

+ do = \
+ { \
+ if (msg_test(flags)) = \
+ { = \
+ x_msg((flags), __VA_ARGS__); \
+ } \
+ EXIT_FATAL(fla= gs); \
= + } while (false)
#else
#define dmsg(f= lags, ...)
#endif
@@ -151,12 +174,12 @@
void x_msg(const unsigned int flags, const char *format, ...= )
#ifdef __GNUC__
#if __USE_MINGW_ANSI_ST= DIO
-__attribute__ ((fo= rmat(gnu_printf, 2, 3)))
+ __attribute__((format(gnu_printf, 2, 3)))
#else
-__attribute__ ((format(= __printf__, 2, 3)))
+= __attribute__((format(__printf__, 2, 3)))
#endif
#endif
-; = /* should be called via msg above */
+ ; /* should be called via msg above */

void x_msg_va(const unsigned int flags, const char *= format, va_list arglist);

@@ -174,7 +197,= 7 @@
void set_machine_readable_output(bool parsable);


-#define SDL_CONSTRAIN (1<<0)
+#define SDL_CONSTRAIN (1 << 0)
bool set_debug_level(const int level, const unsigned int flags);
=

bool set_mute_cutoff(const int cutoff);=
@@ -192,26 +215,41 @@

/* Fatal= logic errors */
#ifndef ENABLE_SMALL
-#define ASSERT(x) do { if (!(x)) {assert_f= ailed(__FILE__, __LINE__, #x);}} while (false)
+#define ASSERT(x) = \
+ do = \
+ { \
+ if (!(x)) = \
+ { \
+ assert_failed(__FILE_= _, __LINE__, #x); \

+= } \
+ } while (false)
#els= e
-#define ASSERT(x) do= { if (!(x)) {assert_failed(__FILE__, __LINE__, NULL);}} while (false)
+#define ASSERT(x) = \
+ do \+ { = \
+ if (!(x)) \
+ { = \

= + assert_failed(__FILE__, __LINE__, NULL); \
+ } = \
+ = } while (false)
#endif

= #ifdef _MSC_VER
__declspec(noreturn)
#end= if
-void assert_failed(= const char *filename, int line, const char *condition)
+void
+assert_failed(const char *filename, int line, const cha= r *condition)
#ifndef _MSC_VER
-__attribute__((__noreturn__))
+ __attribute__((__noreturn__))
#endif
-;
+ ;

/* Poor-man's static_assert() for when not supplied= by assert.h, taken from
* Linux's sys/cdefs.h under = GPLv2 */
#ifndef static_assert
-#define static_assert(expr, diagnostic) \<= br>- extern int (*__OpenVPN_st= atic_assert_function(void)) \
- [!!sizeof(struct { int __error_if_negative : (expr) ? 2 : -1; }= )]
+#define static_as= sert(expr, diagnostic) \
+ extern int (*__OpenVPN_static_assert_function( \=
+ void))[!!sizeof(st= ruct { int __error_if_negative : (expr) ? 2 : -1; })]
#end= if

/* Inline functions */
@@ -268,9 +306,7 @@


void set_check_sta= tus(unsigned int info_level, unsigned int verbose_level);
=
-void x_check_status(i= nt status,
- = const char *description,
- struct link_socket *sock,
+void x_check_status(int status, const= char *description, struct link_socket *sock,
= struct tuntap *tt);

static inlin= e void
@@ -384,7 +420,7 @@
*crt_er= ror =3D true;
err =3D errno;
= }
-#else /* ifdef _WIN= 32 */
+#else /* ifdef= _WIN32 */
*crt_error =3D true;
e= rr =3D errno;
#endif
diff --git a/src/open= vpn/event.c b/src/openvpn/event.c
index c3907b9..f3f992e 10= 0644
--- a/src/openvpn/event.c
+++ b/src/op= envpn/event.c
@@ -177,8 +177,8 @@
ASSE= RT(index >=3D 0 && index < wes->n_events);
for (i =3D index; i < wes->n_events - 1; ++i)

= {
- wes->= events[i] =3D wes->events[i+1];
- wes->esr[i] =3D wes->esr[i+1];
+ wes->events[i] =3D wes->= ;events[i + 1];
+ = wes->esr[i] =3D wes->esr[i + 1];
} --wes->n_events;
}
@@ -207,= 7 +207,7 @@
static void
we_free(struct ev= ent_set *es)
{
- struct we_set *wes =3D (struct we_set *) es;
+ struct we_set *wes =3D (struct w= e_set *)es;
free(wes->events);
= free(wes->esr);
free(wes);
@@ -216= ,7 +216,7 @@
static void
we_reset(struct = event_set *es)
{
- struct we_set *wes =3D (struct we_set *) es;
+ struct we_set *wes =3D (struct= we_set *)es;

ASSERT(wes->fast);
= wes->n_events =3D 0;
}
@@ -224,7 +22= 4,7 @@
static void
we_del(struct event_se= t *es, event_t event)
{
- struct we_set *wes =3D (struct we_set *) es;<= br>+ struct we_set *wes =3D = (struct we_set *)es;
ASSERT(!wes->fast);
= we_del_event(wes, event);
}
@@ = -232,13 +232,10 @@
static void
we_ctl(str= uct event_set *es, event_t event, unsigned int rwflags, void *arg) {
- struct = we_set *wes =3D (struct we_set *) es;
+ struct we_set *wes =3D (struct we_set *)es;
- dmsg(D_EV= ENT_WAIT, "WE_CTL n=3D%d ev=3D%p rwflags=3D0x%04x arg=3D" ptr_for= mat,
- wes->= n_events,
- eve= nt,
- rwflags,<= /span>
- (ptr_type)arg= );
+ dmsg(D_EVENT_= WAIT, "WE_CTL n=3D%d ev=3D%p rwflags=3D0x%04x arg=3D" ptr_format,= wes->n_events, event,
+ rwflags, (ptr_type)arg);

= if (wes->fast)
{
@@ -331,11 +32= 8,11 @@
}
= break;

- case EVENT_READ|EVENT_WRITE:
+ case EVENT_READ | EVENT_WRITE:<= br> switch (n)
{
case 0:
- if (!we_append_event(wes, event= , EVENT_READ|EVENT_WRITE, arg))
+ if (!we_append_event(wes, event, EVENT_= READ | EVENT_WRITE, arg))
{=
goto err;
= }
@@ -378,13 +375,15 @@
= return;

err:
- msg(D_EVENT_ERRORS, "Error: Windows res= ource limit WSA_MAXIMUM_WAIT_EVENTS (%d) has been exceeded", WSA_MAXIM= UM_WAIT_EVENTS);
+ = msg(D_EVENT_ERRORS,
= + "Error: Windows resource limit WSA_MAXIMUM_WAIT_EVENTS (%d) h= as been exceeded",
+ WSA_MAXIMUM_WAIT_EVENTS);
}
<= /span>
static int
we_wait(struct event_set *es, = const struct timeval *tv, struct event_set_return *out, int outlen)<= br> {
- struct= we_set *wes =3D (struct we_set *) es;
+ struct we_set *wes =3D (struct we_set *)es; const int timeout =3D tv_to_ms_timeout(tv);
= DWORD status;

@@ -396,11 +395,8 @@
int i;
for (i =3D 0; i < = wes->n_events; ++i)
{
- dmsg(D_EVENT_WAIT, "[%d] ev=3D= %p rwflags=3D0x%04x arg=3D" ptr_format,
- i,
- wes->events[i],
- wes->esr[i].rwflags,=
- (ptr= _type)wes->esr[i].arg);
+ dmsg(D_EVENT_WAIT, "[%d] ev=3D%p rwflags=3D0x%04x a= rg=3D" ptr_format, i, wes->events[i],
+ wes->esr[i].rwflags, (ptr_typ= e)wes->esr[i].arg);
}
}
#endif
@@ -408,18 +404,13 @@
/*

* First poll our event list with 0 timeout
*/
- status =3D WSAWaitForMultipleEvents(
- (DWORD) wes->n_events,
- wes->events,
- FALSE,
- (DWORD) 0,
- FALSE);
+ status =3D WSAWaitForMultipleEvents((DWORD)wes->= ;n_events, wes->events, FALSE, (DWORD)0, FALSE);

/*
* If at least one event is already= set, we must
* individually poll the whole list.
*/
-= if (status >=3D WSA_WAIT_EVENT_0 && status < WSA_WAIT_EVE= NT_0 + (DWORD) wes->n_events)
+ if (status >=3D WSA_WAIT_EVENT_0 && status <= WSA_WAIT_EVENT_0 + (DWORD)wes->n_events)
{<= br> int i;
int j =3D 0;
@@ -432,8 +423,8 @@

if (WaitForSingleObjec= t(wes->events[i], 0) =3D=3D WAIT_OBJECT_0)
= {
*out =3D wes->esr[i];
- dmsg(D_EVENT_WAIT, &q= uot;WE_WAIT leave [%d,%d] rwflags=3D0x%04x arg=3D" ptr_format,
<= br>- i, j, ou= t->rwflags, (ptr_type)out->arg);
+ dmsg(D_EVENT_WAIT, "WE_WAIT leave [= %d,%d] rwflags=3D0x%04x arg=3D" ptr_format, i, j,
+ out->rwflags, (p= tr_type)out->arg);
++j;
++out;

}
@@ = -453,19 +444,16 @@
*/
if= (timeout > 0)
{
- status =3D WSAWaitForMultipleEvents(
- (DWORD) w= es->n_events,
- = wes->events,
- FALSE,
- (DWORD) timeout,
- FALSE);
+ status =3D WSAWaitForMultipleEvents((DWORD= )wes->n_events, wes->events, FALSE,
+ (DWORD)= timeout, FALSE);
}

- if (outlen >=3D 1 &&= amp; status >=3D WSA_WAIT_EVENT_0 && status < WSA_WAIT_EVENT_= 0 + (DWORD) wes->n_events)

+ if (outlen >=3D 1 && status >=3D WSA_WAIT_E= VENT_0
+ &= amp;& status < WSA_WAIT_EVENT_0 + (DWORD)wes->n_events) {
*out =3D wes->esr[status = - WSA_WAIT_EVENT_0];
- = dmsg(D_EVENT_WAIT, "WE_WAIT leave rwflags=3D0x%04x arg=3D&q= uot; ptr_format,
- = out->rwflags, (ptr_type)out->arg);
+ dmsg(D_EVENT_WAIT, "WE_W= AIT leave rwflags=3D0x%04x arg=3D" ptr_format, out->rwflags,=
+ (ptr_type= )out->arg);
return 1;
= }
else if (status =3D=3D WSA_WAIT_TIMEOUT)
@@ -512,10 +500,9 @@
/* Allocate space fo= r event_set_return objects */
ALLOC_ARRAY_CLEAR(wes-&g= t;esr, struct event_set_return, wes->capacity);
=
- dmsg(D_EVENT_WAIT, "= ;WE_INIT maxevents=3D%d capacity=3D%d",
- *maxevents, wes->capacity);
+ dmsg(D_EVENT_WAIT, "WE_= INIT maxevents=3D%d capacity=3D%d", *maxevents, wes->capacity);

- ret= urn (struct event_set *) wes;
+ return (struct event_set *)wes;
}
=
#endif /* _WIN32 */
@@ -534,7 +521= ,7 @@
static void
ep_free(struct event_se= t *es)
{
- struct ep_set *eps =3D (struct ep_set *) es;
+ struct ep_set *eps =3D (struct ep_set= *)es;
close(eps->epfd);
free(= eps->events);
free(eps);
@@ -543,7 = +530,7 @@
static void
ep_reset(struct eve= nt_set *es)
{
- const struct ep_set *eps =3D (struct ep_set *) es;
<= span style=3D"color: hsl(120, 100%, 40%);">+ const struct ep_set *eps = =3D (struct ep_set *)es;

ASSERT(eps->fast);<= br> }

@@ -551,7 +538,7 @@ ep_del(struct event_set *es, event_t event)
{
struct epoll_event ev;
- struct ep_set *eps =3D (struct ep_set *) es;+ struct ep_set *eps =3D (= struct ep_set *)es;

dmsg(D_EVENT_WAI= T, "EP_DEL ev=3D%d", (int)event);

@@ -559,14 +546,14 @@

CLEAR(ev);
= if (epoll_ctl(eps->epfd, EPOLL_CTL_DEL, event, &ev) < 0)
{
- = msg(M_WARN|M_ERRNO, "EVENT: epoll_ctl EPOLL_CTL_DEL failed, sd=3D%= d", (int)event);
+ msg(M_WARN | M_ERRNO, "EVENT: epoll_ctl EPOLL_CTL_DEL failed= , sd=3D%d", (int)event);
}
}

static void
ep_ctl(struct = event_set *es, event_t event, unsigned int rwflags, void *arg)
{

- struct ep_s= et *eps =3D (struct ep_set *) es;
+ struct ep_set *eps =3D (struct ep_set *)es;
struct epoll_event ev;


CLEAR= (ev);
@@ -581,11 +568,8 @@
ev.even= ts |=3D EPOLLOUT;
}

- dmsg(D_EVENT_WAIT, "EP_CTL fd= =3D%d rwflags=3D0x%04x ev=3D0x%08x arg=3D" ptr_format,
- (int)event,

- rwflags,
- (unsigned int)ev.events,- (ptr_type)ev.data.ptr= );
+ dmsg(D_EVENT_= WAIT, "EP_CTL fd=3D%d rwflags=3D0x%04x ev=3D0x%08x arg=3D" ptr_fo= rmat, (int)event, rwflags,
+ (unsigned int)ev.events, (ptr_type)ev.data.ptr);
=
if (epoll_ctl(eps->epfd, EPOLL_CTL_MOD, eve= nt, &ev) < 0)
{
@@ -606,7 +590,= 7 @@
static int
ep_wait(struct event_set = *es, const struct timeval *tv, struct event_set_return *out, int outlen)
{
- s= truct ep_set *eps =3D (struct ep_set *) es;
+ struct ep_set *eps =3D (struct ep_set *)es;
int stat;

if (outl= en > eps->maxevents)
@@ -625,7 +609,7 @@
for (i =3D 0; i < stat; ++i)

{
esr->rwflags =3D 0;
- if (ev->events & (EPOLLIN|EPO= LLPRI|EPOLLERR|EPOLLHUP))
+ if (ev->events & (EPOLLIN | EPOLLPRI | EPOLLERR | = EPOLLHUP))
{
= esr->rwflags |=3D EVENT_READ;
}
<= span>@@ -634,8 +618,8 @@

esr->rwflags |= =3D EVENT_WRITE;
}
= esr->arg =3D ev->data.ptr;
- dmsg(D_EVENT_WAIT, "EP_WAIT[%d] rwflags=3D0x%= 04x ev=3D0x%08x arg=3D" ptr_format,
- i, esr->rwflags, ev->events, (ptr= _type)ev->data.ptr);
+ dmsg(D_EVENT_WAIT, "EP_WAIT[%d] rwflags=3D0x%04x ev=3D= 0x%08x arg=3D" ptr_format, i,
+ esr->rwflags, ev->events, (ptr_type)e= v->data.ptr);
++ev;
= ++esr;
}
@@ -683,7 +667,7 @@=
/* set epoll control fd */
eps-&= gt;epfd =3D fd;

- return (struct event_set *) eps;
+ return (struct event_set *)eps;
= }
#endif /* EPOLL */

@@ -702,7 +686,7 @@

static void
po_fr= ee(struct event_set *es)
{
- struct po_set *pos =3D (struct po_set *) es;
+ struct po_set *pos = =3D (struct po_set *)es;
free(pos->events);<= br> free(pos->args);
free(pos);@@ -711,7 +695,7 @@
static void
po= _reset(struct event_set *es)
{
- struct po_set *pos =3D (struct po_set *) es;<= /span>
+ struct po_set *p= os =3D (struct po_set *)es;
ASSERT(pos->fast);
pos->n_events =3D 0;
}
@@ -719,7 +703,7 @@

static void
po_del(s= truct event_set *es, event_t event)
{
- struct po_set *pos =3D (struct po_set = *) es;
+ struct po= _set *pos =3D (struct po_set *)es;
int i;

dmsg(D_EVENT_WAIT, "PO_DEL ev=3D%d", (= int)event);
@@ -732,8 +716,8 @@
= int j;
for (j =3D i; j < pos->n_events= - 1; ++j)
{
- pos->events[j] =3D pos->events[j+= 1];
- po= s->args[j] =3D pos->args[j+1];
+ pos->events[j] =3D pos->events[j + 1= ];
+ p= os->args[j] =3D pos->args[j + 1];
}
--pos->n_events;
b= reak;
@@ -751,7 +735,7 @@
}
= if (rwflags & EVENT_READ)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- pfdp->events |=3D (POL= LIN|POLLPRI);

+ = pfdp->events |=3D (POLLIN | POLLPRI);
} }

@@ -776,10 +760,10 @@ static void
po_ctl(struct event_set *es, event_t e= vent, unsigned int rwflags, void *arg)
{
- struct po_set *pos =3D (struct po_s= et *) es;
+ struct= po_set *pos =3D (struct po_set *)es;

- dmsg(D_EVENT_WAIT, "PO_CTL rwfla= gs=3D0x%04x ev=3D%d arg=3D" ptr_format,
- rwflags, (int)event, (ptr_type)arg);=
+ dmsg(D_EVENT_WAIT, &qu= ot;PO_CTL rwflags=3D0x%04x ev=3D%d arg=3D" ptr_format, rwflags, (int)e= vent,
+ (ptr_= type)arg);

if (pos->fast)<= br> {
@@ -817,7 +801,7 @@
static= int
po_wait(struct event_set *es, const struct timeval *t= v, struct event_set_return *out, int outlen)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- struct po_set *pos =3D (struc= t po_set *) es;

+ = struct po_set *pos =3D (struct po_set *)es;
int stat;<= /span>

stat =3D poll(pos->events, pos-&g= t;n_events, tv_to_ms_timeout(tv));
@@ -830,10 +814,10 @@
const struct pollfd *pfdp =3D pos->events;=
for (i =3D 0; i < pos->n_events && j < = outlen; ++i)
{
- if (pfdp->revents & (POLLIN|POLLPRI|PO= LLERR|POLLHUP|POLLOUT))
+ if (pfdp->revents & (POLLIN | POLLPRI | POLLERR | PO= LLHUP | POLLOUT))
{
= out->rwflags =3D 0;
- if (pfdp->revents & (POLLIN|POLLPRI|POLLERR|= POLLHUP))
+ = if (pfdp->revents & (POLLIN | POLLPRI | POLLERR | POLLHUP))
{
out-&= gt;rwflags |=3D EVENT_READ;
}
@@ -842,8 +826,10 @@

out->rwfla= gs |=3D EVENT_WRITE;
}
= out->arg =3D pos->args[i];
- dmsg(D_EVENT_WAIT, "PO_WAIT[%= d,%d] fd=3D%d rev=3D0x%08x rwflags=3D0x%04x arg=3D" ptr_format " = %s",
- = i, j, pfdp->fd, pfdp->revents, out->rwflags, (ptr_type)ou= t->arg, pos->fast ? "" : "[scalable]");+ dmsg(D_EVENT_= WAIT,
+ = "PO_WAIT[%d,%d] fd=3D%d rev=3D0x%08x rwflags=3D0x%04x arg=3D&qu= ot; ptr_format " %s", i, j,
+ pfdp->fd, pfdp->revents, out-&= gt;rwflags, (ptr_type)out->arg,
+ pos->fast ? "" : "[sc= alable]");
++out;
= ++j;
}
@@ -892,7= +878,7 @@
/* Allocate space for event_set_return obje= cts */
ALLOC_ARRAY_CLEAR(pos->args, void *, pos->= ;capacity);

- return (struct event_set *) pos;
+ return (struct event_set *)pos;
}

#endif /* POLL */

@= @ -904,15 +890,15 @@
bool fast;
f= d_set readfds;
fd_set writefds;
- void **args; /* allocated to capacity s= ize */
- int maxfd; = /* largest fd seen so far, always < capacity */
+ void **args; /* allocated to capacit= y size */
+ int ma= xfd; /* largest fd seen so far, always < capacity */
= int capacity; /* fixed largest fd + 1 */
};
static void
se_free(struct event= _set *es)
{
- struct se_set *ses =3D (struct se_set *) es;
+ struct se_set *ses =3D (struct se_s= et *)es;
free(ses->args);
free= (ses);
}
@@ -920,7 +906,7 @@
static void

se_reset(struct event_set *es)
<= span> {

- struct se_= set *ses =3D (struct se_set *) es;
+ struct se_set *ses =3D (struct se_set *)es;
int i;

ASSERT(ses->fast);
=
@@ -938,7 +924,7 @@
static void se_del(struct event_set *es, event_t event)
{
- struct se_set *ses = =3D (struct se_set *) es;
+ struct se_set *ses =3D (struct se_set *)es;
= ASSERT(!ses->fast);

dmsg(D_EVENT_= WAIT, "SE_DEL ev=3D%d", (int)event);
@@ -959,7 +9= 45,7 @@
static void
se_ctl(struct event_s= et *es, event_t event, unsigned int rwflags, void *arg)
{<= /span>
- struct se_set *ses= =3D (struct se_set *) es;
+ struct se_set *ses =3D (struct se_set *)es;

dmsg(D_EVENT_WAIT, "SE_CTL rwflags=3D0x%04x ev=3D%d= fast=3D%d cap=3D%d maxfd=3D%d arg=3D" ptr_format,
= rwflags, (int)event, (int)ses->fast, ses->capacity, ses->ma= xfd, (ptr_type)arg);
@@ -1001,17 +987,13 @@
}

else
{
- msg(D_EVENT_ERRORS, "Error:= select: too many I/O wait events, fd=3D%d cap=3D%d",
- (int) event,
+ msg(D_EVENT_ERRORS, "= ;Error: select: too many I/O wait events, fd=3D%d cap=3D%d", (int)even= t,

ses->capacity);
}
}

static int
<= span style=3D"color: hsl(0, 100%, 40%);">-se_wait_return(struct se_set *ses= ,

- fd_se= t *read,
- = fd_set *write,
- = struct event_set_return *out,
+se_wait_return(struct se_set *ses, fd_set *read, fd_set= *write, struct event_set_return *out,
int = outlen)
{
int i, j =3D 0;
<= span>@@ -1031,8 +1013,8 @@

out->rwflags= |=3D EVENT_WRITE;
}
= out->arg =3D ses->args[i];
- dmsg(D_EVENT_WAIT, "SE_WAIT[%d,%d] rwflags= =3D0x%04x arg=3D" ptr_format,
- i, j, out->rwflags, (ptr_type)out->arg)= ;
+ dmsg(D= _EVENT_WAIT, "SE_WAIT[%d,%d] rwflags=3D0x%04x arg=3D" ptr_format,= i, j, out->rwflags,
+ (ptr_type)out->arg);
+= +out;
++j;
}@@ -1041,16 +1023,15 @@
}
=
static int
-= se_wait_fast(struct event_set *es, const struct timeval *tv, struct event_s= et_return *out, int outlen)
+se_wait_fast(struct event_set *es, const struct timeval *tv, struct= event_set_return *out,
+ int outlen)
{
- struct se_set *ses =3D (struct se_set *) es;<= /span>
+ struct se_set *s= es =3D (struct se_set *)es;
struct timeval tv_tmp =3D = *tv;
int stat;

- dmsg(D_EVENT_WAIT, "SE_WAIT_FAST m= axfd=3D%d tv=3D%" PRIi64 "/%ld",
- ses->maxfd,
- (int64_t)tv_tmp.tv_sec,
- (long)tv_tmp.tv_usec);
+ dmsg(D_EVENT_WAIT, &= quot;SE_WAIT_FAST maxfd=3D%d tv=3D%" PRIi64 "/%ld", ses->= maxfd,
+ (int= 64_t)tv_tmp.tv_sec, (long)tv_tmp.tv_usec);

stat =3D select(ses->maxfd + 1, &ses->readfds, &ses-&g= t;writefds, NULL, &tv_tmp);


@@ -1063,= 16 +1044,17 @@
}

static= int
-se_wait_scalable(= struct event_set *es, const struct timeval *tv, struct event_set_return *ou= t, int outlen)
+se_wa= it_scalable(struct event_set *es, const struct timeval *tv, struct event_se= t_return *out,
+ = int outlen)
{
- struct se_set *ses =3D (struct se_set *) es;
+ struct se_set *ses = =3D (struct se_set *)es;
struct timeval tv_tmp =3D *tv= ;
fd_set read =3D ses->readfds;
= fd_set write =3D ses->writefds;
int stat;<= br>
- dmsg(D_= EVENT_WAIT, "SE_WAIT_SCALEABLE maxfd=3D%d tv=3D%" PRIi64 "/%= ld",
- ses= ->maxfd, (int64_t)tv_tmp.tv_sec, (long)tv_tmp.tv_usec);
+ dmsg(D_EVENT_WAIT, "SE_WAIT= _SCALEABLE maxfd=3D%d tv=3D%" PRIi64 "/%ld", ses->maxfd,<= /span>
+ (int64_t)tv= _tmp.tv_sec, (long)tv_tmp.tv_usec);

= stat =3D select(ses->maxfd + 1, &read, &write, NULL, &tv_tmp= );

@@ -1117,7 +1099,7 @@
= /* Allocate space for event_set_return void * args */
= ALLOC_ARRAY_CLEAR(ses->args, void *, ses->capacity);
<= span>

- return (str= uct event_set *) ses;
+ return (struct event_set *)ses;
}
#= endif /* SELECT */

@@ -1143,7 +1125,7 @@<= /span>
{
ret =3D po_init(maxevents, = flags);
}
-#else /* ifdef SELECT_PREFERRED_OVER_POLL */
+#else /* ifdef SELECT_PREFERRED_OVER_POL= L */
if (!ret)
{
= ret =3D po_init(maxevents, flags);
@@ -1175,7 +115= 7,7 @@
msg(M_WARN, "Note: sys_epoll API is un= available, falling back to poll/select API");
= ret =3D event_set_init_simple(maxevents, flags);
}
-#else /* if EPOLL */
+#else /* if EPOLL */
ret =3D event_set_init_simple(maxevents, flags);=
#endif
ASSERT(ret);
diff --= git a/src/openvpn/event.h b/src/openvpn/event.h
index 389f8= 0d..a5329e4 100644
--- a/src/openvpn/event.h
+++ b/src/openvpn/event.h

@@ -32,12 +32,12 @@
<= span> * rwflags passed to event_ctl and returned by

* st= ruct event_set_return.
*/
-#define READ_SHIFT 0
-#define WRITE_SHIFT 1
+#define READ_SHIFT 0
+#define WRITE_SHIFT 1
=
-#define EVENT_UNDEF = 4
-#define EVENT_REA= D (1 << READ_SHIFT)
-#define EVENT_WRITE (1 << WRITE_SHIFT)
+#define EVENT_UNDEF 4
+#define EVENT_READ (1 << REA= D_SHIFT)

+#define EVE= NT_WRITE (1 << WRITE_SHIFT)

/* eve= nt flags returned by io_wait.
*
@@ -58,35= +58,35 @@
* signals.
*/

-#define SOCKET_SHI= FT 0
-#define SO= CKET_READ (1 << (SOCKET_SHIFT + READ_SHIFT))
-#define SOCKET_WRITE (1 <<= ; (SOCKET_SHIFT + WRITE_SHIFT))
-#define TUN_SHIFT 2
-#define TUN_READ (1 << (TUN_SHIFT + READ= _SHIFT))
-#define TUN_W= RITE (1 << (TUN_SHIFT + WRITE_SHIFT))
-#define ERR_SHIFT 4
-#define ES_ERROR (1 <= < (ERR_SHIFT + READ_SHIFT))

-#define ES_TIMEOUT (1 << (ERR_SHIFT + WRITE_SHIFT))=
-#define MANAGEMENT_SH= IFT 6
-#define MANAG= EMENT_READ (1 << (MANAGEMENT_SHIFT + READ_SHIFT))
-#define MANAGEMENT_WRITE (1 <&l= t; (MANAGEMENT_SHIFT + WRITE_SHIFT))

-#define FILE_SHIFT 8
-#define FILE_CLOSED (1 << (FILE_SHIFT = + READ_SHIFT))
-#define= DCO_SHIFT 10
-#define DCO_READ (1 << (DCO_SHIFT + READ_SHIFT))<= br>-#define DCO_WRITE (= 1 << (DCO_SHIFT + WRITE_SHIFT))
+#define SOCKET_SHIFT 0
+#define SOCKET_READ (1 << (SOCKET_SHIFT= + READ_SHIFT))
+#def= ine SOCKET_WRITE (1 << (SOCKET_SHIFT + WRITE_SHIFT))
+#define TUN_SHIFT 2
+#define TUN_READ = (1 << (TUN_SHIFT + READ_SHIFT))
+#define TUN_WRITE (1 << (TUN_SHIFT + WRITE_S= HIFT))
+#define ERR_S= HIFT 4
+#defin= e ES_ERROR (1 << (ERR_SHIFT + READ_SHIFT))
+#define ES_TIMEOUT (1 << (= ERR_SHIFT + WRITE_SHIFT))
+#define MANAGEMENT_SHIFT 6
+#define MANAGEMENT_READ (1 << (MANAGEMENT_SHIFT + READ_= SHIFT))
+#define MANA= GEMENT_WRITE (1 << (MANAGEMENT_SHIFT + WRITE_SHIFT))
+#define FILE_SHIFT 8+#define FILE_CLOSED (1 &= lt;< (FILE_SHIFT + READ_SHIFT))
+#define DCO_SHIFT 10
+#define DCO_READ (1 << (DCO_SHIFT + RE= AD_SHIFT))
+#define D= CO_WRITE (1 << (DCO_SHIFT + WRITE_SHIFT))

/*
* Initialization flags passed to event_= set_init
*/
-#define EVENT_METHOD_US_TIMEOUT (1<<0)
-#define EVENT_METHOD_FAST (1<&l= t;1)
+#define EVENT_M= ETHOD_US_TIMEOUT (1 << 0)
+#define EVENT_METHOD_FAST (1 << 1)
=
/*
* The following constant is used as= boundary between integer value
* and real addresses when= passing arguments to event handlers as (void *)
*/
-#define MULTI_N (= (void *)16) /* upper bound on MTCP_x */
+#define MULTI_N ((void *)16) /* upper bound on MTCP_x *= /

#ifdef _WIN32
=
@@ -94,7 +94,7 @@

#define UNDE= FINED_EVENT (NULL)

-#else /* ifdef _WIN32 */
+#else /* ifdef _WIN32 */

<= span> typedef int event_t;


@@ -118,7 +118= ,8 @@
* 0 on timeout
* length o= f event_set_return if at least 1 event is returned
*/=
- int (*wait)(struc= t event_set *es, const struct timeval *tv, struct event_set_return *out, in= t outlen);
+ int (= *wait)(struct event_set *es, const struct timeval *tv, struct event_set_ret= urn *out,
+ = int outlen);
};

s= truct event_set_return
@@ -132,7 +133,8 @@
= struct event_set_functions func;
};
=
-typedef enum {=
+typedef enum
+{

EVENT_ARG_= MULTI_INSTANCE =3D 0,
EVENT_ARG_LINK_SOCKET, } event_arg_t;
@@ -141,9 +143,10 @@
struct event_arg

{
event_arg_t type= ;
- union {+ union
+ {
struct = multi_instance *mi; /* if type =3D EVENT_ARG_MULTI_INSTANCE */
- struct link_socket *sock; = /* if type =3D EVENT_ARG_LINK_SOCKET */

+ struct link_socket *sock; /* if type =3D EVENT= _ARG_LINK_SOCKET */
} u;
};
@@ -211,7 +214,7 @@
}<= br> }

-#else /* ifdef _WIN32 */
+#else /* ifdef _WIN32 */

s= tatic inline void
wait_signal(struct event_set *es, void *= arg)
diff --git a/src/openvpn/fdmisc.c b/src/openvpn/fdmisc= .c
index 3d8654c..f6be9fd 100644
--- a/src/= openvpn/fdmisc.c
+++ b/src/openvpn/fdmisc.c
@@ -42,7 +42,7 @@

{
return f= alse;
}
-#else /* ifdef _WIN32 */
+#else /* ifdef _WIN32 */
if (fcntl(fd, F_= SETFL, O_NONBLOCK) < 0)
{
= return false;
diff --git a/src/openvpn/fdmisc.h b/src/openv= pn/fdmisc.h
index 17b6994..1ff66aa 100644
-= -- a/src/openvpn/fdmisc.h
+++ b/src/openvpn/fdmisc.h=
@@ -46,4 +46,4 @@
}
#undef FD_S= ET /* prevent direct use of FD_SET() */

-#endif /* FD_MISC_H */
+#endif /* FD_MISC_H */=
diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c=
index a4f260a..f798c6e 100644
--- a/src/openvpn/f= orward.c
+++ b/src/openvpn/forward.c
@@ -59= ,14 +59,11 @@
{
struct buffer out =3D= alloc_buf_gc(64, gc);

- buf_printf(&out, "I/O WAIT %s|%s| %s",=
- tun_st= at(c->c1.tuntap, EVENT_READ, gc),
- tun_stat(c->c1.tuntap, EVENT_WRITE, gc),
- tv_strin= g(&c->c2.timeval, gc));
+ buf_printf(&out, "I/O WAIT %s|%s| %s", tun_sta= t(c->c1.tuntap, EVENT_READ, gc),
+ tun_stat(c->c1.tuntap, EVENT_WRITE, gc), = tv_string(&c->c2.timeval, gc));
for (int i =3D = 0; i < c->c1.link_sockets_num; i++)
{
= - buf_printf(&out, &qu= ot;\n %s|%s",
- = socket_stat(c->c2.link_sockets[i], EVENT_READ, gc),
+ buf_printf(&= out, "\n %s|%s", socket_stat(c->c2.link_sockets[i], EVENT_READ= , gc),
socket_stat(c->c2.link_socket= s[i], EVENT_WRITE, gc));
}
return= BSTR(&out);
@@ -128,7 +125,7 @@
stati= c inline void
context_immediate_reschedule(struct context = *c)
{
= - c->c2.timeval.tv_sec =3D 0; /* ZERO-TIMEOUT */
+ c->c2.timeval.tv_sec =3D 0; /* Z= ERO-TIMEOUT */
c->c2.timeval.tv_usec =3D 0;<= br> }

@@ -186,9 +183,8 @@
if (interval_test(&c->c2.tmp_int))
{
- = const int tmp_status =3D tls_multi_process
- (c->c2.tls= _multi, &c->c2.to_link, &c->c2.to_link_addr,
- get= _link_socket_info(c), &wakeup);
+ const int tmp_status =3D tls_multi_process(<= br>+ c->c2.tls_mu= lti, &c->c2.to_link, &c->c2.to_link_addr, get_link_socket_inf= o(c), &wakeup);

if (tmp_stat= us =3D=3D TLSMP_RECONNECT)
{
@@ -3= 46,12 +342,7 @@
#ifdef ENABLE_MANAGEMENT
= if (management)
{
- management_set_state(m= anagement,
- = OPENVPN_STATE_GET_CONFIG,
- NULL,<= /span>
- = NULL,
- = NULL,
- NULL,
+ management_set_s= tate(management, OPENVPN_STATE_GET_CONFIG, NULL, NULL, NULL, NULL,
NULL);
= }
#endif
@@ -378,8 +369,7 @@=
}

bool
-send_control_channel_string_dowork(struct t= ls_session *session,
- = const char *str, int msglevel)
= +send_control_channel_string_do= work(struct tls_session *session, const char *str, int msglevel)
= {
struct gc_arena gc =3D gc_new();
bool stat;

@@ -388,12 +378,11 @@
= struct key_state *ks =3D &session->key[KS_PRIMARY];

/* buffered cleartext write onto TLS control cha= nnel */
- stat =3D t= ls_send_payload(ks, (uint8_t *) str, strlen(str) + 1);
+ stat =3D tls_send_payload(ks, (uint8= _t *)str, strlen(str) + 1);

msg(msgl= evel, "SENT CONTROL [%s]: '%s' (status=3D%d)",
= - session->common_name = ? session->common_name : "UNDEF",
- sanitize_control_message(str, &gc),
- (int) stat);
+ session->com= mon_name ? session->common_name : "UNDEF", sanitize_control_me= ssage(str, &gc),
= + (int)stat);

gc_free(&gc= );
return stat;
@@ -426,8 +415,8 @@
static void
check_add_routes_action(struct = context *c, const bool errors)
{
- bool route_status =3D do_route(&c->o= ptions, c->c1.route_list, c->c1.route_ipv6_list,
- c->c1.= tuntap, c->plugins, c->c2.es, &c->net_ctx);
+ bool route_status =3D do_route(&am= p;c->options, c->c1.route_list, c->c1.route_ipv6_list, c->c1.tu= ntap,
+ = c->plugins, c->c2.es, &c->net_ctx);<= br>
int flags =3D (errors ? ISC_ERRORS : 0);
flags |=3D (!route_status ? ISC_ROUTE_ERRORS : 0);
@@ -459,8 +448,8 @@
register_si= gnal(c->sig, SIGHUP, "ip-fail");
= c->persist.restart_sleep_seconds =3D 10;
#ifdef _WI= N32
- sh= ow_routes(M_INFO|M_NOPREFIX);
- show_adapters(M_INFO|M_NOPREFIX);
+ show_routes(M_INFO | = M_NOPREFIX);
+ = show_adapters(M_INFO | M_NOPREFIX);
#endif=
}
}
@@ -603= ,7 +592,8 @@
* Buffer reallocation, for use with null enc= ryption.
*/
static inline void-buffer_turnover(const uint8_t *= orig_buf, struct buffer *dest_stub, struct buffer *src_stub, struct buffer = *storage)
+buffer_tur= nover(const uint8_t *orig_buf, struct buffer *dest_stub, struct buffer *src= _stub,
+ = struct buffer *storage)
{
if (orig= _buf =3D=3D src_stub->data && src_stub->data !=3D storage->= ;data)
{
@@ -631,7 +621,7 @@ if (dco_enabled(&c->options))
{
msg(M_WARN, "Attempting to send data packet whil= e data channel offload is in use. "
- "Dropping packet");
+ "Dropping= packet");

c->c2.buf.len =3D 0;
= }

@@ -651,7 +641,8 @@ /* Compress the packet. */
if (c-= >c2.comp_context)
{
- (*c->c2.comp_context->alg.compr= ess)(&c->c2.buf, b->compress_buf, c->c2.comp_context, &c-&= gt;c2.frame);
+ = (*c->c2.comp_context->alg.compress)(&c->c2.buf, b->co= mpress_buf, c->c2.comp_context,
+ &c->c= 2.frame);
}
#endif
#ifdef ENABLE_FRAGMENT

@@ -698,8 +689,7 @@
/*

* Get the address we will be sending the p= acket to.
*/
- link_socket_get_outgoing_addr(&c->c2.buf, get_link_= socket_info(c),
- = &c->c2.to_link_addr);
+ link_socket_get_outgoing_addr(&= ;c->c2.buf, get_link_socket_info(c), &c->c2.to_link_addr);=

/* if null encryption, copy result to read= _tun_buf */
buffer_turnover(orig_buf, &c->c2.to= _link, &c->c2.buf, &b->read_tun_buf);
@@ -712= ,8 +702,7 @@
check_session_timeout(struct context *c)
{
if (c->options.session_timeout
- && event_ti= meout_trigger(&c->c2.session_interval, &c->c2.timeval,=
- = ETT_DEFAULT))
+ = && event_timeout_trigger(&c->c2.session_interval, &am= p;c->c2.timeval, ETT_DEFAULT))
{
= msg(M_INFO, "Session timeout, exiting");
= register_signal(c->sig, SIGTERM, "session-timeout");
@@ -727,7 +716,7 @@
process_coarse_timers(s= truct context *c)
{
/* flush current = packet-id to file once per 60
- * seconds if --replay-persist was specified */
+ * seconds if --replay-persist w= as specified */
if (packet_id_persist_enabled(&c-&= gt;c1.pid_persist)
&& event_timeout_trigge= r(&c->c2.packet_id_persist_interval, &c->c2.timeval, ETT_DEFA= ULT))
{
@@ -850,7 +839,8 @@
= process_coarse_timers(c);
c->c2.coarse_t= imer_wakeup =3D now + c->c2.timeval.tv_sec;

= - dmsg(D_INTERVAL, "TIMER= : coarse timer wakeup %" PRIi64 " seconds", (int64_t)c->c= 2.timeval.tv_sec);
+ = dmsg(D_INTERVAL, "TIMER: coarse timer wakeup %" PRIi64 " = seconds",
+ = (int64_t)c->c2.timeval.tv_sec);

= /* Is the coarse timeout NOT the earliest one? */
i= f (c->c2.timeval.tv_sec > save.tv_sec)
@@ -864,10 +85= 4,10 @@
{
const int update_interval = =3D 10; /* seconds */
c->c2.update_timeout_random_c= omponent =3D now + update_interval;
- c->c2.timeout_random_component.tv_usec =3D (time_t) ge= t_random() & 0x0003FFFF;
+ c->c2.timeout_random_component.tv_usec =3D (time_t)get_rand= om() & 0x0003FFFF;
c->c2.timeout_random_compone= nt.tv_sec =3D 0;

- dmsg(D_INTERVAL, "RANDOM USEC=3D%ld", (long) c-&= gt;c2.timeout_random_component.tv_usec);
+ dmsg(D_INTERVAL, "RANDOM USEC=3D%ld", (l= ong)c->c2.timeout_random_component.tv_usec);
}
static inline void
@@ -898,10 +8= 88,8 @@
}

static inline= void
-socks_preprocess= _outgoing_link(struct context *c,
- struct link_socket *sock,=
- = struct link_socket_actual **to_addr,
- int *size_delta)+socks_preprocess_outgoing_lin= k(struct context *c, struct link_socket *sock,
+ struct link_socke= t_actual **to_addr, int *size_delta)
{
= if (sock->socks_proxy && sock->info.proto =3D=3D PROTO_UDP)=
{
@@ -912,9 +900,7 @@

/* undo effect of socks_preprocess_outgoing_link */
static inline void
-link_socket_write_post_size_adjust(int *size,
- int s= ize_delta,
- = struct buffer *buf)
+link_socket_write_post_size_adjust(int *size, int s= ize_delta, struct buffer *buf)
{
if (= size_delta > 0 && *size > size_delta)
{<= /span>
@@ -946,9 +932,7 @@
c->c2.buf =3D c= ->c2.buffers->read_link_buf;
ASSERT(buf_init(&am= p;c->c2.buf, c->c2.frame.buf.headroom));

= - status =3D link_socket_read(= sock,
- = &c->c2.buf,
- &c->c2.from);
+ status =3D link_socket_read(s= ock, &c->c2.buf, &c->c2.from);


if (socket_connection_reset(sock, status))

{<= /span>
@@ -966,12 +950,14 @@
/* recei= ved a disconnect from a connection-oriented protocol */
= if (event_timeout_defined(&c->c2.explicit_exit_notificatio= n_interval))
{
- msg(D_STREAM_ERRORS, "Connection= reset during exit notification period, ignoring [%d]", status);
+ msg(D_STR= EAM_ERRORS,
+ = "Connection reset during exit notification period, ignorin= g [%d]", status);
management_sleep(1)= ;
}
else {
= - register_signal(c->sig, SIGUSR1, "connection-reset= "); /* SOFT-SIGUSR1 -- TCP connection reset */
+ register_signal(c->sig= , SIGUSR1,
+ = "connection-reset"); /* SOFT-SIGUSR1 -- TC= P connection reset */
msg(D_STREAM_ERRORS,= "Connection reset, restarting [%d]", status);
= }
}
@@ -1017,7 +1003,8 = @@
if (management)
{
management_bytes_client(management, c->c2.buf.l= en, 0);
- ma= nagement_bytes_server(management, &c->c2.link_read_bytes, &c->= ;c2.link_write_bytes, &c->c2.mda_context);
+ management_bytes_server(managemen= t, &c->c2.link_read_bytes, &c->c2.link_write_bytes,+ = &c->c2.mda_context);
}
#endif

}
@@ -1045,11 +1032,8 @@
fprintf(stderr, "R");
= }
#endif
- msg(D_LINK_RW, "%s READ [%d] from %s: %s",
- proto2ascii(lsi->proto, = lsi->af, true),

- = BLEN(&c->c2.buf),
- print_link_socket_actual(&c->c2.from, &gc),
- PROTO_DUMP(&c-= >c2.buf, &gc));
+ BLEN(&c->c2.buf), print_link_socket_actual(&c= ->c2.from, &gc), PROTO_DUMP(&c->c2.buf, &gc));
=
/*
* Good, non-zero leng= th packet received.
@@ -1081,9 +1065,8 @@
= */
if ((opcode =3D=3D P_DATA_V1) = && dco_enabled(&c->options))
{<= /span>
- msg(D_= LINK_ERRORS,
- = "Data Channel Offload doesn't support DATA_V1 packets. = "
- = "Upgrade your server to 2.4.5 or newer.");
+ msg(D_LINK_ERRORS, &q= uot;Data Channel Offload doesn't support DATA_V1 packets. "=
+ = "Upgrade your server to 2.4.5 or newer.");
c->c2.buf.len =3D 0;

}<= /span>

@@ -1097,8 +1080,7 @@
= * will load crypto_options with the correct encryption key
* and return false.
= */
- if (tls= _pre_decrypt(c->c2.tls_multi, &c->c2.from, &c->c2.buf, &am= p;co,
- = floated, &ad_start))
+ if (tls_pre_decrypt(c->c2.tls_multi, &a= mp;c->c2.from, &c->c2.buf, &co, floated, &ad_start))
{
interval_action= (&c->c2.tmp_int);

@@ -1125,15 +110= 7,16 @@
}

= /* authenticate and decrypt the incoming packet */
- decrypt_status =3D openvpn_decrypt(= &c->c2.buf, c->c2.buffers->decrypt_buf,
- co= , &c->c2.frame, ad_start);
+ decrypt_status =3D
+ openvpn_decrypt(&c->c2.buf, c->c= 2.buffers->decrypt_buf, co, &c->c2.frame, ad_start);

if (!decrypt_status
= /* on the instance context we have only one socket, so just check the = first one */
&& link_socket_connection= _oriented(c->c2.link_sockets[0]))
{
<= span> /* decryption errors are fatal in TCP mode */

<= span style=3D"color: hsl(0, 100%, 40%);">- register_signal(c->= ;sig, SIGUSR1, "decryption-error"); /* SOFT-SIGUSR1 -- decryption= error in TCP mode */

+ register_signal(c->sig, SIGUSR1,
+ "decryption-= error"); /* SOFT-SIGUSR1 -- decryption error in TCP mode */
= msg(D_STREAM_ERRORS, "Fatal decryption error (proce= ss_incoming_link), restarting");
}
= }
@@ -1147,7 +1130,8 @@
}

void
-process_incoming_link_part2(struct context *c, struct link_soc= ket_info *lsi, const uint8_t *orig_buf)
+process_incoming_link_part2(struct context *c, struct l= ink_socket_info *lsi,
+ const uint8_t *orig_buf)
{
if (c->c2.buf.len > 0)
{
@@ -1162,17 +1146,15 @@
/* decompress= the incoming packet */
if (c->c2.comp_context)=
{
- (*c->c2.comp_context->alg.decompress)(&c->c2= .buf, c->c2.buffers->decompress_buf, c->c2.comp_context, &c-&g= t;c2.frame);
+ = (*c->c2.comp_context->alg.decompress)(&c->c2.buf, c->c= 2.buffers->decompress_buf,
+ c->c2.comp_c= ontext, &c->c2.frame);
}
#= endif

#ifdef PACKET_TRUNCATION_CHECK
/* if (c->c2.buf.len > 1) --c->c2.buf.len; *= /
- ipv4_packet_= size_verify(BPTR(&c->c2.buf),
- BLEN(&c->c2.buf),
- = TUNNEL_TYPE(c->c1.tuntap),
- "POST_DECRYPT",
- = &c->c2.n_trunc_post_decrypt);
+ ipv4_packet_size_verify(BPTR(&c->c2= .buf), BLEN(&c->c2.buf), TUNNEL_TYPE(c->c1.tuntap),
+ &= quot;POST_DECRYPT", &c->c2.n_trunc_post_decrypt);

#endif


/*
@@= -1199,7 +1181,8 @@
if (c->c2.buf.len > 0)
{
c->c2.link_read_b= ytes_auth +=3D c->c2.buf.len;
- c->c2.max_recv_size_local =3D max_int(c->c2.or= iginal_recv_size, c->c2.max_recv_size_local);
+ c->c2.max_recv_size_local =3D
+ max_i= nt(c->c2.original_recv_size, c->c2.max_recv_size_local);
}


/* Did we just re= ceive an openvpn ping packet? */
@@ -1262,9 +1245,10 @@
* ourselves in the foot and removing the just establishe= d session */
if (dco->dco_message_peer_id !=3D c-&g= t;c2.tls_multi->dco_peer_id)
{
- msg(D_DCO_DEBUG, "%s: receive= d message for mismatching peer-id %d, "
- "expected %d", __func__, dco-&= gt;dco_message_peer_id,
- c->c2.tls_multi->dco_peer_id);
+ msg(D_DCO_DEBUG,
+ "%s: received message = for mismatching peer-id %d, "
+ "expected %d",
+ __func__, dco->dco_message= _peer_id, c->c2.tls_multi->dco_peer_id);
ret= urn;
}

@@ -1275,16 += 1259,18 @@
c->c2.tls_multi->dco_peer_id = =3D -1;
if (dco->dco_del_peer_reason =3D=3D= OVPN_DEL_PEER_REASON_EXPIRED)
{
- msg(D_DCO_DEBUG, &q= uot;%s: received peer expired notification of for peer-id "

= - "%d&quo= t;, __func__, dco->dco_message_peer_id);
+ msg(D_DCO_DEBUG,
+ "%s: received= peer expired notification of for peer-id "
+ "%d",
= + __func__, = dco->dco_message_peer_id);
trigger_ping= _timeout_signal(c);
return;
}

break;

case OVPN_CMD_SWAP_KEYS:
- msg(D_DCO_DEBUG, "%s: received key= rotation notification for peer-id %d",
- __func__, dco->dco_message_peer_i= d);
+ msg(= D_DCO_DEBUG, "%s: received key rotation notification for peer-id %d&qu= ot;, __func__,
+ = dco->dco_message_peer_id);
tls_s= ession_soft_reset(c->c2.tls_multi);
break;<= /span>

@@ -1324,7 +1310,8 @@
= ASSERT(buf_safe(&c->c2.buf, c->c2.frame.buf.payload_size));
if (c->c1.tuntap->backend_driver =3D=3D DRIVER_AFUN= IX)
{
- c->c2.buf.len =3D read_tun_afunix(c->c1.tuntap, BPTR(&am= p;c->c2.buf), c->c2.frame.buf.payload_size);
+ c->c2.buf.len =3D
+ read_tun_afunix(c->c= 1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);
=
}
else
{@@ -1333,11 +1320,8 @@
#endif /* ifdef _WIN32 */

#ifdef PACKET_TRUNCATION_CHECK
<= span style=3D"color: hsl(0, 100%, 40%);">- ipv4_packet_size_verify(BPTR(= &c->c2.buf),

- = BLEN(&c->c2.buf),
- TUNNEL_TYPE(c->= c1.tuntap),
- = "READ_TUN",
- &c->c2.n_trunc_tun_rea= d);
+ ipv4_packet_= size_verify(BPTR(&c->c2.buf), BLEN(&c->c2.buf), TUNNEL_TYPE(c= ->c1.tuntap),
+ = "READ_TUN", &c->c2.n_trunc_tun_re= ad);
#endif

/* Was = TUN/TAP interface stopped? */
@@ -1392,7 +1376,7 @@<= br> if (proto_ver =3D=3D 4)
{
/* make sure we got whole IP header */

- if (BLEN(buf) < ((int) sizeof(struct= openvpn_iphdr) + ip_hdr_offset))
+ if (BLEN(buf) < ((int)sizeof(struct openvpn_iphdr)= + ip_hdr_offset))
{
= return;
}
@@ -1403,7 +1387,7 @@
return;
}

- struct op= envpn_iphdr *pip =3D (struct openvpn_iphdr *) (BPTR(buf) + ip_hdr_offset);<= /span>
+ struct openv= pn_iphdr *pip =3D (struct openvpn_iphdr *)(BPTR(buf) + ip_hdr_offset);

/* drop packets with same dest addr = as gateway */
if (memcmp(&tun_sa.addr.in4.sin_= addr.s_addr, &pip->daddr, sizeof(pip->daddr)) =3D=3D 0)@@ -1414,7 +1398,7 @@
else if (proto_ver =3D=3D= 6)
{
/* make sure we got who= le IPv6 header */
- = if (BLEN(buf) < ((int) sizeof(struct openvpn_ipv6hdr) + ip_hdr_offse= t))
+ if (BLEN= (buf) < ((int)sizeof(struct openvpn_ipv6hdr) + ip_hdr_offset)) {
return;
= }
@@ -1425,7 +1409,7 @@
r= eturn;
}

- struct openvpn_ipv6hdr *pip6 =3D (s= truct openvpn_ipv6hdr *) (BPTR(buf) + ip_hdr_offset);
+ struct openvpn_ipv6hdr *pip6 =3D = (struct openvpn_ipv6hdr *)(BPTR(buf) + ip_hdr_offset);

/* drop packets with same dest addr as gateway */
if (OPENVPN_IN6_ARE_ADDR_EQUAL(&tun_sa.addr.in6.= sin6_addr, &pip6->daddr))
@@ -1483,19 +1467,15 @@
* The --passtos and --mssfix options require=
* us to examine the IP header (IPv4 or IPv6). */
- = unsigned int flags =3D PIPV4_PASSTOS | PIP_MSSFIX | PIPV4_CLIENT_NAT<= /span>
- = | PIPV6_ICMP_NOHOST_CLIENT;
+ unsigned int flags =3D
+ PIPV4_PASSTOS | PIP_MSSFIX | PIPV4_CL= IENT_NAT | PIPV6_ICMP_NOHOST_CLIENT;
process_ip_he= ader(c, flags, &c->c2.buf, out_sock);

#ifdef PACKET_TRUNCATION_CHECK

/* if (c->c= 2.buf.len > 1) --c->c2.buf.len; */
- ipv4_packet_size_verify(BPTR(&c->c2.buf),=
- = BLEN(&c->c2.buf),
- TUNNEL_TYPE(c->c1.tuntap),=
- = "PRE_ENCRYPT",
- &c->c2.n_trunc_pre_enc= rypt);
+ ipv4_= packet_size_verify(BPTR(&c->c2.buf), BLEN(&c->c2.buf), TUNNEL= _TYPE(c->c1.tuntap),
+ "PRE_ENCRYPT", &c->c2.= n_trunc_pre_encrypt);
#endif
-
}
if (c-= >c2.buf.len > 0)
{
@@ -1571,8 +1= 551,7 @@
icmp6out.icmp6_type =3D OPENVPN_ICMP6_DESTINA= TION_UNREACHABLE;
icmp6out.icmp6_code =3D OPENVPN_ICMP= 6_DU_NOROUTE;

- int icmpheader_len =3D sizeof(struct openvpn_ipv6hdr)<= br>- + si= zeof(struct openvpn_icmp6hdr);
+ int icmpheader_len =3D sizeof(struct openvpn_ipv6hdr) + size= of(struct openvpn_icmp6hdr);
int totalheader_len =3D i= cmpheader_len;

if (TUNNEL_TYPE(c->= ;c1.tuntap) =3D=3D DEV_TYPE_TAP)
@@ -1585,8 +1564,7 @@
* frame should be <=3D 1280 and have as much as possib= le of the original
* packet
*/<= /span>
- int max_payload_si= ze =3D min_int(MAX_ICMPV6LEN,
- c->c2.frame.tun_mtu - icmphea= der_len);
+ int ma= x_payload_size =3D min_int(MAX_ICMPV6LEN, c->c2.frame.tun_mtu - icmphead= er_len);
int payload_len =3D min_int(max_payload_size,= BLEN(&inputipbuf));

pip6out.pay= load_len =3D htons(sizeof(struct openvpn_icmp6hdr) + payload_len);@@ -1614,10 +1592,10 @@

/* C= alculate checksum over the packet and write to header */
<= /span>
- uint16_t new_csum = =3D ip_checksum(AF_INET6, BPTR(outbuf), BLEN(outbuf),
- (const = uint8_t *)&pip6out.saddr,
- (uint8_t *)&pip6out.daddr, = OPENVPN_IPPROTO_ICMPV6);
+ uint= 16_t new_csum =3D
+ = ip_checksum(AF_INET6, BPTR(outbuf), BLEN(outbuf), (const uint8_t *)&a= mp;pip6out.saddr,
+ = (uint8_t *)&pip6out.daddr, OPENVPN_IPPROTO_ICMPV6);
+ ((struct openvpn_= icmp6hdr *)BPTR(outbuf))->icmp6_cksum =3D htons(new_csum);


/* IPv6 Header */
@@ -1633,7 +1611,7 @@

return;
}


- const struct openvpn_ethhdr *orig_ethhdr =3D (struct open= vpn_ethhdr *) BPTR(buf);
+ const struct openvpn_ethhdr *orig_ethhdr =3D (struct openvpn_e= thhdr *)BPTR(buf);

/* Copy frame= type and reverse source/destination for the response */
= struct openvpn_ethhdr ethhdr;
@@ -1714,15 +1692,13 @@=
{
mss_fixup_= ipv6(&ipbuf, c->c2.frame.mss_fix);
}
- if (!(flags = & PIP_OUTGOING) && (flags
- &(PIPV6_ICM= P_NOHOST_CLIENT | PIPV6_ICMP_NOHOST_SERVER)))
+ if (!(flags & PIP_OUTGOING)
+ &&= ; (flags & (PIPV6_ICMP_NOHOST_CLIENT | PIPV6_ICMP_NOHOST_SERVER)))
{
- ipv6_send_icmp_unreachable(c, buf,
- = (bool)(flags & PIPV6_ICMP_NOHOST_CLIENT));
+ ipv6_send_icmp_unreachable(c, = buf, (bool)(flags & PIPV6_ICMP_NOHOST_CLIENT));
= /* Drop the IPv6 packet */
buf-&= gt;len =3D 0;
}
-
}
}
}
@@ -1759,10 +1735,9 @@
= */
if (c->options.shaper)
{
- int overhead =3D datagram_overhead(c->c2.to_link_add= r->dest.addr.sa.sa_family,
- sock->info.prot= o);
- sh= aper_wrote_bytes(&c->c2.shaper,
- BLEN(&c->c2.to_l= ink) + overhead);
+ = int overhead =3D
+ datagram_overhead(c->c2.to_link_addr->= dest.addr.sa.sa_family, sock->info.proto);
+ shaper_wrote_bytes(&c->c2.= shaper, BLEN(&c->c2.to_link) + overhead);
= }

/*
@@ -= 1786,10 +1761,8 @@
}
#endif
msg(D_LINK_RW, "%s WRITE [%d] to %s: %s&qu= ot;,
- p= roto2ascii(sock->info.proto, sock->info.af, true),
- BLEN(&c->c2.to_li= nk),
- p= rint_link_socket_actual(c->c2.to_link_addr, &gc),
- PROTO_DUMP(&c->c2= .to_link, &gc));
= + proto2ascii(sock->info.proto, sock->info.af, true), = BLEN(&c->c2.to_link),
+ print_link_socket_actual(c->c2.to_link_addr, &a= mp;gc), PROTO_DUMP(&c->c2.to_link, &gc));

/* Packet send complexified by possible Socks5 usa= ge */
{
@@ -1800,9 +1773,7 @@<= /span>
socks_preprocess_outgoing_link(c, sock, &a= mp;to_addr, &size_delta);

= /* Send packet */
- size =3D (int)link_socket_write(sock,
- = &c->c2.to_link,
- to_addr);
+ size =3D (int)lin= k_socket_write(sock, &c->c2.to_link, to_addr);


/* Undo effect of prepend */
= link_socket_write_post_size_adjust(&size, size_delta, = &c->c2.to_link);
@@ -1823,7 +1794,8 @@
if (management)

{
management_bytes_client(management, 0, siz= e);
- = management_bytes_server(management, &c->c2.link_read_bytes, &c= ->c2.link_write_bytes, &c->c2.mda_context);
+ management_bytes_serv= er(management, &c->c2.link_read_bytes,
+ &= c->c2.link_write_bytes, &c->c2.mda_context);
= }
#endif
}
@@ -1840,9 +1812,7 @@
{
<= span> msg(D_LINK_ERRORS,

= "TCP/UDP packet was truncated/expanded on write to %s (tried=3D%d,a= ctual=3D%d)",
- = print_link_socket_actual(c->c2.to_link_addr, &gc),<= /span>
- BL= EN(&c->c2.to_link),
- size);
+ print_link_socket_actual(c->c2.to_link_a= ddr, &gc), BLEN(&c->c2.to_link), size);
= }
}

@@ -186= 1,7 +1831,8 @@
ENETUNREACH;
#endif
if (size < 0 && un= reachable && c->c2.tls_multi
- && !tls_initial_packet_received(c->= ;c2.tls_multi) && c->options.mode =3D=3D MODE_POINT_TO_POINT)
+ &&= !tls_initial_packet_received(c->c2.tls_multi)
+ && c->options.mode =3D= =3D MODE_POINT_TO_POINT)
{
= msg(M_INFO, "Network unreachable, restarting");
<= span> register_signal(c->sig, SIGUSR1, "network-unreach= able");

@@ -1872,8 +1843,7 @@
= if (c->c2.to_link.len > 0)
{
msg(D_LINK_ERRORS, "TCP/UDP packet too large on write t= o %s (tried=3D%d,max=3D%d)",

- print_link_socket_actual(c->c2.to_link_addr,= &gc),
- = c->c2.to_link.len,
+ print_link_socket_actual(c->c2.to_link_addr, &= ;gc), c->c2.to_link.len,
c->c2.frame= .buf.payload_size);
}
}
@@ -1906,8 +1876,8 @@
* The --mssfix optio= n requires
* us to examine the IP header (IPv4 or IPv= 6).
*/
- process_ip_header(c, PIP_MSSFIX|PIPV4_EXTRACT_DHCP_ROUTER|PIPV4_= CLIENT_NAT|PIP_OUTGOING, &c->c2.to_tun,
- in_sock);
+ process_ip_header(c, PIP_MSSFIX | = PIPV4_EXTRACT_DHCP_ROUTER | PIPV4_CLIENT_NAT | PIP_OUTGOING,
+ &c->c= 2.to_tun, in_sock);


if (c->c2.to_= tun.len <=3D c->c2.frame.buf.payload_size)
{
@@ -1925,11 +1895,8 @@
dmsg(D_TUN_RW,= "TUN WRITE [%d]", BLEN(&c->c2.to_tun));
=
#ifdef PACKET_TRUNCATION_CHECK
- ipv4_packet_size_verify(BPTR(&c->= c2.to_tun),
- = BLEN(&c->c2.to_tun),
- TUNNEL_TYPE(c-&= gt;c1.tuntap),
- = "WRITE_TUN",
- &c->c2.n_t= runc_tun_write);
+ = ipv4_packet_size_verify(BPTR(&c->c2.to_tun), BLEN(&c->c2= .to_tun), TUNNEL_TYPE(c->c1.tuntap),
+ "WRITE_TUN", = &c->c2.n_trunc_tun_write);
#endif
=
#ifdef _WIN32
@@ -1959,9 +1926,7 @@
{
msg(D_LINK_ERROR= S,
"TUN/TAP packet was destructiv= ely fragmented on write to %s (tried=3D%d,actual=3D%d)",
- c->c1.tuntap= ->actual_name,

- = BLEN(&c->c2.to_tun),
- size);
+ c->c1.tuntap->actual= _name, BLEN(&c->c2.to_tun), size);
}

/* indicate activity regarding= --inactive parameter */
@@ -1974,8 +1939,7 @@
* This should never happen, probably indicates some kind
* of MTU mismatch.
*/
- msg(D_LINK_ERRORS, = "tun packet too large on write (tried=3D%d,max=3D%d)",
= - c->c2.to_tun.len,=
+ msg(D_LINK_= ERRORS, "tun packet too large on write (tried=3D%d,max=3D%d)", c-= >c2.to_tun.len,
c->c2.frame.buf.payload_= size);
}

@@ -2051,9 = +2015,8 @@
}

static voi= d
-multi_io_process_fla= gs(struct context *c, struct event_set *es,
- const unsigned int flags, unsi= gned int *out_socket,
-= unsigned int *out_tuntap)
+multi_io_process_flags(struct context *c, stru= ct event_set *es, const unsigned int flags,
+ unsigned int *out_socket, un= signed int *out_tuntap)
{
unsigned in= t socket =3D 0;
unsigned int tuntap =3D 0;
<= span>@@ -2144,8 +2107,7 @@

*/
fo= r (int i =3D 0; i < c->c1.link_sockets_num; i++)
= {
- socket_set(= c->c2.link_sockets[i], es, socket,
- &c->c2.link_sockets[i]->ev_arg= , NULL);
+ soc= ket_set(c->c2.link_sockets[i], es, socket, &c->c2.link_sockets[i]= ->ev_arg, NULL);
}

tun_set(c->c1.tuntap, es, tuntap, (void *)tun_shift, NULL);
@@ -2159,7 +2121,6 @@
{
= *out_tuntap =3D tuntap;
}
-
}

/*
@@ -2210,15 +2171,16 @@
= struct event_set_return esr[4];

/* = These shifts all depend on EVENT_READ and EVENT_WRITE */
- static uintptr_t socket_shift =3D SO= CKET_SHIFT; /* depends on SOCKET_READ and SOCKET_WRITE */
+ static uintptr_t socket_shift = =3D SOCKET_SHIFT; /* depends on SOCKET_READ and SOCKET_WRITE */

<= span> #ifdef ENABLE_MANAGEMENT

- static uintptr_t management_shift =3D MANAGEMENT_SHIFT; /* dep= ends on MANAGEMENT_READ and MANAGEMENT_WRITE */
+ static uintptr_t management_shift =3D
+ MANAGEMENT_SHIFT;= /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */
#en= dif
#ifdef ENABLE_ASYNC_PUSH
static u= intptr_t file_shift =3D FILE_SHIFT;
#endif
#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)

- static uintptr_t dco_shift =3D DCO_SHI= FT; /* Event from DCO linux kernel module */
+ static uintptr_t dco_shift =3D DCO_SHIFT; /= * Event from DCO linux kernel module */
#endif
<= span>

/*
@@ -2297,8 +2259,7 @@=
if (ev_arg->type !=3D EVENT_ARG_LINK_= SOCKET)
{
= c->c2.event_set_status =3D ES_ERROR;
- msg(D_LI= NK_ERRORS,

- = "io_work: non socket event delivered");
+ = msg(D_LINK_ERRORS, "io_work: non socket event delivered");
return;
= }

@@ -2341,7 +2302,7 @@<= /span>
const unsigned int status =3D c->c2.event_set_statu= s;

#ifdef ENABLE_MANAGEMENT
- if (status & (MANAGEMENT_R= EAD|MANAGEMENT_WRITE))

-#define TUN_OUT(c) (BLEN(&(c)->c2.to_tun) >= 0)
-#define LINK_OUT(c= ) (BLEN(&(c)->c2.to_link) > 0)
-#define ANY_OUT(c) (TUN_OUT(c) || LINK_OUT(c))<= /span>
+#define TUN_OUT(c) = (BLEN(&(c)->c2.to_tun) > 0)
+#define LINK_OUT(c) (BLEN(&(c)->c2.to_link) > 0= )
+#define ANY_OUT(c)= (TUN_OUT(c) || LINK_OUT(c))

#ifdef ENA= BLE_FRAGMENT
#define TO_LINK_FRAG(c) ((c)->c2.fragment = && fragment_outgoing_defined((c)->c2.fragment))
= @@ -45,31 +45,32 @@
#define TO_LINK_FRAG(c) (false)=
#endif

-#define TO_LINK_DEF(c) (LINK_OUT(c) || TO_LINK_FRAG(c))
+#define TO_LINK_DEF(c) (= LINK_OUT(c) || TO_LINK_FRAG(c))

#include= "openvpn.h"
#include "occ.h" #include "ping.h"
#include "multi_= io.h"

-#define IOW_TO_TUN (1<<0)
-#define IOW_TO_LINK (1<<1)-#define IOW_READ_TUN (1= <<2)
-#define IOW= _READ_LINK (1<<3)
-#define IOW_SHAPER (1<<4)
-#define IOW_CHECK_RESIDUAL (1<<5)<= br>-#define IOW_FRAG (= 1<<6)
-#define IO= W_MBUF (1<<7)
-#define IOW_READ_TUN_FORCE (1<<8)
-#define IOW_WAIT_SIGNAL (1<<9)=
+#define IOW_TO_TUN = (1 << 0)
+#def= ine IOW_TO_LINK (1 << 1)
+#define IOW_READ_TUN (1 << 2)
+#define IOW_READ_LINK (1 <&= lt; 3)

+#define IOW_S= HAPER (1 << 4)
+#define IOW_CHECK_RESIDUAL (1 << 5)
+#define IOW_FRAG (1 << 6)
+#define IOW_MBUF = (1 << 7)
+= #define IOW_READ_TUN_FORCE (1 << 8)
+#define IOW_WAIT_SIGNAL (1 << 9)
<= span>

-#define IOW_REA= D (IOW_READ_TUN|IOW_READ_LINK)
+#define IOW_READ (IOW_READ_TUN | IOW_READ_LINK)

extern counter_type link_read_bytes_global;

extern counter_type link_write_bytes_glob= al;

-= void get_io_flags_dowork_udp(struct context *c, struct multi_io *multi_io, = const unsigned int flags);
+void get_io_flags_dowork_udp(struct context *c, struct multi_io *mul= ti_io,
+ = const unsigned int flags);

void get_io_flags_udp(struct context *c, struct multi_io *multi_io, cons= t unsigned int flags);


@@ -193,7 +194,8 @= @
* @param orig_buf - Pointer to a buffer data. *
*/
-void process_incoming_link_part2(struct context *c, struct link_s= ocket_info *lsi, const uint8_t *orig_buf);
+void process_incoming_link_part2(struct context *c, = struct link_socket_info *lsi,
+ const uint8_t *orig_buf);=

/**
* Write a packet to the = external network interface.
@@ -271,8 +273,7 @@
<= span> * @param str - The message to be sent

* @pa= ram msglevel - Message level to use for logging
*/
-bool
-send_control_channel_string(struct context = *c, const char *str, int msglevel);
+bool send_control_channel_string(struct context *c, const c= har *str, int msglevel);

/*
* Send a string to remote over the TLS control channel.

@@ -290,9 +291,7 @@

* @param msglevel - Message leve= l to use for logging
*/

-bool

-send_control_channel_string_dowork(struct tls_session = *session,
- = const char *str, int msglevel);
+bool send_control_channel_string_dowork(= struct tls_session *session, const char *str, int msglevel);


/**
@@ -303,13 +302,= 13 @@
*/
void reschedule_multi_process(s= truct context *c);

-#define PIPV4_PASSTOS (1<<0)<= br>-#define PIP_MSSFIX = (1<<1) /* v4 and v6 */
-#define PIP_OUTGOING (1<<= ;2)
-#define PIPV4_EXTR= ACT_DHCP_ROUTER (1<<3)
-#define PIPV4_CLIENT_NAT (1<<4)-#define PIPV6_ICMP_NOHOST_CLIEN= T (1<<5)
-= #define PIPV6_ICMP_NOHOST_SERVER (1<<6)
+#define PIPV4_PASSTOS (1 <= < 0)
+#define PIP_= MSSFIX (1 << 1) /* v4 and v6 */
+#define PIP_OUTGOING (1 <= < 2)
+#define PIPV= 4_EXTRACT_DHCP_ROUTER (1 << 3)
+#define PIPV4_CLIENT_NAT (1 << 4)+#define PIPV6_ICMP_NOHOST_CLI= ENT (1 << 5)
+= #define PIPV6_ICMP_NOHOST_SERVER (1 << 6)

void process_ip_header(struct context *c, unsign= ed int flags, struct buffer *buf,
@@ -351,7 +350,7 @@
static inline unsigned int
p2p_iow_flags(const= struct context *c)
{
- unsigned int flags =3D (IOW_SHAPER|IOW_CHECK_RESIDUAL|= IOW_FRAG|IOW_READ|IOW_WAIT_SIGNAL);
+ unsigned int flags =3D (IOW_SHAPER | IOW_CHECK_RESIDUAL= | IOW_FRAG | IOW_READ | IOW_WAIT_SIGNAL);
if (c->c= 2.to_link.len > 0)
{
flags= |=3D IOW_TO_LINK;
@@ -370,8 +369,8 @@
sta= tic inline void
io_wait(struct context *c, const unsigned = int flags)
{
- if (proto_is_dgram(c->c2.link_sockets[0]->info.proto)
- && c->= c2.fast_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF)))
+ if (proto_is_dgram(c= ->c2.link_sockets[0]->info.proto) && c->c2.fast_io<= br>+ && (flags &= amp; (IOW_TO_TUN | IOW_TO_LINK | IOW_MBUF)))
{<= br> /* fast path -- only for TUN/TAP/UDP writes */
= unsigned int ret =3D 0;
@@ -379,7 +378,7 @@<= /span>
{
ret |=3D TUN_WRITE;=
}
- if (flags & (IOW_TO_LINK|IOW_MBUF))
+ if (flags & (IOW_TO_LINK | IO= W_MBUF))
{
ret |=3D S= OCKET_WRITE;
}
diff --git a/src/op= envpn/fragment.c b/src/openvpn/fragment.c
index 287eb9b..c1= 21aae 100644
--- a/src/openvpn/fragment.c
+= ++ b/src/openvpn/fragment.c
@@ -35,7 +35,11 @@
#include "integer.h"

#include "memdbg.= h"

-#define FRAG_ERR(s) { errmsg =3D s; goto error; }
+#define FRAG_ERR(s) \
+ { \
+ errmsg =3D s; \
+ goto error; \

<= span style=3D"color: hsl(120, 100%, 40%);">+ }

<= br> static void
fragment_list_buf_init(struct fragme= nt_list *list, const struct frame *frame)
@@ -133,8 +137,7 = @@
* If a fragment fully completes the datagram, return t= he datagram.
*/
void
-fragment_incoming(struct fragment_master = *f, struct buffer *buf,
- const struct frame *frame)
+fragment_incoming(struct fragment_master *f, str= uct buffer *buf, const struct frame *frame)
{
const char *errmsg =3D NULL;

fragment_header_= type flags =3D 0;
@@ -165,11 +168,8 @@
= /* handle the fragment type */
if (frag_type = =3D=3D FRAG_WHOLE)
{
- dmsg(D_FRAG_DEBUG,
- "FRAG_IN buf->len= =3D%d type=3DFRAG_WHOLE flags=3D"
- fragment_header_format,
- buf->len,- flags);=
+ dmsg(D_FRAG_DE= BUG, "FRAG_IN buf->len=3D%d type=3DFRAG_WHOLE flags=3D" fragme= nt_header_format,
+ = buf->len, flags);

= if (flags & (FRAG_SEQ_ID_MASK | FRAG_ID_MASK))
= {
@@ -180,22 +180,18 @@
= {
const int seq_id =3D ((flags >> FRA= G_SEQ_ID_SHIFT) & FRAG_SEQ_ID_MASK);
const= int n =3D ((flags >> FRAG_ID_SHIFT) & FRAG_ID_MASK);
<= span style=3D"color: hsl(0, 100%, 40%);">- const int size =3D ((= frag_type =3D=3D FRAG_YES_LAST)

- ? (int)(((flags >> FRAG_SIZE_= SHIFT) & FRAG_SIZE_MASK) << FRAG_SIZE_ROUND_SHIFT)
- : buf-= >len);

+ = const int size =3D
= + ((frag_type =3D=3D FRAG_YES_LAST)
+ ? (int)(((flags >>= ; FRAG_SIZE_SHIFT) & FRAG_SIZE_MASK) << FRAG_SIZE_ROUND_SHIFT)
+ := buf->len);

/* get the ap= propriate fragment buffer based on received seq_id */
= struct fragment *frag =3D fragment_list_get_buf(&f->incoming= , seq_id);

- dmsg(D_FRAG_DEBUG,
- "FRAG_IN len=3D%d type=3D%d seq_id=3D= %d frag_id=3D%d size=3D%d flags=3D"
- fragment_header_format,
- buf->len,
<= br>- frag_type,
- seq_id= ,
- n,<= /span>
- size,=
- flag= s);
+ dmsg= (
+ D_= FRAG_DEBUG,
+ = "FRAG_IN len=3D%d type=3D%d seq_id=3D%d frag_id=3D%d size=3D%d= flags=3D" fragment_header_format,
+ buf->len, frag_type, seq_id, n, size= , flags);

/* make sure that = size is an even multiple of 1<<FRAG_SIZE_ROUND_SHIFT */
if (size & FRAG_SIZE_ROUND_MASK)

@@ -25= 8,11 +254,7 @@

/* pack fragment parms in= to a uint32_t and prepend to buffer */
static void<= br>-fragment_prepend_flags(struct= buffer *buf,
- = int type,
- int frag_id,
- int frag_size)
+fragment_prepend_flags(st= ruct buffer *buf, int type, int seq_id, int frag_id, int frag_size)<= br> {
fragment_header_type flags =3D ((type &= ; FRAG_TYPE_MASK) << FRAG_TYPE_SHIFT)
= | ((seq_id & FRAG_SEQ_ID_MASK) << FRAG_SEQ_ID_= SHIFT)
@@ -274,19 +266,19 @@
* If= you want to set FRAG_EXTRA_MASK/FRAG_EXTRA_SHIFT bits,
= * do it here.
*/
- dmsg(D_FRAG_DEBUG,
- "FRAG_OUT len=3D%d type= =3D%d seq_id=3D%d frag_id=3D%d frag_size=3D%d flags=3D"
- fragment_header_format,=

- buf->= len, type, seq_id, frag_id, frag_size, flags);
+ dmsg(
+ D_FRAG_DEBUG,
+ "FRAG_OUT len=3D%d type=3D%d se= q_id=3D%d frag_id=3D%d frag_size=3D%d flags=3D" fragment_header_format= ,
+ buf-&g= t;len, type, seq_id, frag_id, frag_size, flags);
}
else
{
flag= s |=3D (((frag_size >> FRAG_SIZE_ROUND_SHIFT) & FRAG_SIZE_MASK) &= lt;< FRAG_SIZE_SHIFT);

- dmsg(D_FRAG_DEBUG,
- "FRAG_OUT len=3D%d type=3D%d s= eq_id=3D%d frag_id=3D%d frag_size=3D%d flags=3D"
- fragment_header_format,=
- buf->len, ty= pe, seq_id, frag_id, frag_size, flags);
+ dmsg(
+ D_FRAG_DEBUG,
+ "FRAG_OUT len=3D%d type=3D%d seq_id=3D= %d frag_id=3D%d frag_size=3D%d flags=3D" fragment_header_format,
+ buf->len, = type, seq_id, frag_id, frag_size, flags);
}
=
flags =3D hton_fragment_header_type(flags);
@@ -307,8 +299,9 @@

if= (div > 0 && mod > 0 && mod < mfs_aligned * 3 / 4)=
{
- return min_int(mfs_aligned, (max_frag_size - ((max_frag_size - mo= d) / (div + 1))
- = + FRAG_SIZE_ROUND_MASK) & ~FRAG_SIZE_ROU= ND_MASK);
+ re= turn min_int(mfs_aligned,
+ (max_frag_size - ((max_frag_size - mod) / (div= + 1)) + FRAG_SIZE_ROUND_MASK)
+ & ~FRAG_SIZE_ROUND_MASK);<= br> }
else
{
= @@ -318,8 +311,7 @@

/* process an = outgoing datagram, possibly breaking it up into fragments */
void

-fragment_outgo= ing(struct fragment_master *f, struct buffer *buf,
- const struct frame *frame)
+fragment_outgoing(str= uct fragment_master *f, struct buffer *buf, const struct frame *frame)
{
const char *errmsg =3D NULL;
= if (buf->len > 0)
@@ -327,8 +319,8 @@
/* The outgoing buffer should be empty so we can put n= ew data in it */
if (f->outgoing.len) {
- = msg(D_FRAG_ERRORS, "FRAG: outgoing buffer is not empty, len=3D= [%d,%d]",
- = buf->len, f->outgoing.len);
+ msg(D_FRAG_ERRORS, "FRAG: outgoing = buffer is not empty, len=3D[%d,%d]", buf->len,
+ f->outgoing.len);
}
if (buf->len > frame= ->max_fragment_size) /* should we fragment? */
= {
@@ -352,11 +344,7 @@
/*
* Send the datagram whole.
= */
- = fragment_prepend_flags(buf,
- FRAG_WHOLE,
- 0,
- = 0,
- = 0);
+ fragment_prepend_flags(buf, FRAG_WHOLE, 0, 0, 0);
}
}
return;
@@ -364,8 +352,8 @@
error:
= if (errmsg)
{
- msg(D_FRAG_ERRORS, "FRAG_OUT error, len=3D%d= frag_size=3D%d MAX_FRAGS=3D%d: %s",
- buf->len, f->outgoing_frag_size, MAX_= FRAGS, errmsg);
+ = msg(D_FRAG_ERRORS, "FRAG_OUT error, len=3D%d frag_size=3D%d MAX_FR= AGS=3D%d: %s", buf->len,
+ f->outgoing_frag_size, MAX_FRAGS, errmsg);
}
buf->len =3D 0;
= return;
@@ -373,8 +361,7 @@
/* return true (and set buf) if we have an outgoing fragment which= is ready to send */
bool
-fragment_ready_to_send(struct fragment_master *f, stru= ct buffer *buf,
- = const struct frame *frame)
+fragment_ready_to_send(struct fragment_master *f, s= truct buffer *buf, const struct frame *frame)
{
= if (fragment_outgoing_defined(f))
{<= br>@@ -393,13 +380,12 @@
ASSERT(buf_copy_n(b= uf, &f->outgoing, size));

= /* fragment flags differ based on whether or not we are sending the last f= ragment */
- fra= gment_prepend_flags(buf,
- = f->outgoing_seq_id,
- f->outgoing_frag_id++,- = f->outgoing_frag_size);
+ fragment_prepend_flags(buf, last ? FRAG_YES_LAST : FRAG_YES= _NOTLAST, f->outgoing_seq_id,
+ f->outgoing_frag_id++, f->= ;outgoing_frag_size);

- ASSERT(!last || !f->outgoing.len); /* outgoing= buffer length should be zero after last fragment sent */
+ ASSERT(!last
+ || !f->outgoing
+ = .len); /* outgoing buffer length should be zero after last fragment sent *= /

return true;
= }
diff --git a/src/openvpn/fragment.h b/src/openvpn/fra= gment.h
index cc96057..c5c8108 100644
--- a= /src/openvpn/fragment.h
+++ b/src/openvpn/fragment.h=
@@ -46,15 +46,15 @@
#include "error.h"=


-#define N_FRAG_BUF 25
+#define N_FRAG_BUF 25
/= **< Number of packet buffers for
* reassembling inco= ming fragmented
* packets. */
<= br>-#define FRAG_TTL_SEC = 10
+#define F= RAG_TTL_SEC 10
/**< Time-to-live in seconds for a %frag= ment. */

-#define FRAG_WAKEUP_INTERVAL 5
+#define FRAG_WAKEUP_INTERVAL 5
/**= < Interval in seconds between calls to
* wakeup code= . */

@@ -62,15 +62,16 @@
= /**
* Structure for reassembling one incoming fragmented= packet.
*/
-struct fragment {
- bool defined; /**< Whether reassembly is currently=
- = * taking place in this structure. */
+struct fragment
+{
+ bool defined; /**< Whether reassembly is currently
+ = * taking place in this structure. */

- int max_frag_size; /**<= Maximum size of each %fragment. */
+ int max_frag_size; /**< Maximum size of each %fragme= nt. */

#define FRAG_MAP_MASK 0xFFFFFFFF<= /span>
/**< Mask for reassembly map. */
-#define MAX_FRAGS 32 /**< = Maximum number of fragments per packet. */
+#define MAX_FRAGS 32 /**< Maximum number of f= ragments per packet. */
unsigned int map;
/**< Reassembly map for recording which

*= fragments have been received.
@@ -81,10 +82,10 @@=
* n has been received. Needs to have
= * at least \c MAX_FRAGS bits. */

- time_t timestamp; /**< T= imestamp for time-to-live purposes. */
+ time_t timestamp; /**< Timestamp for time-to-liv= e purposes. */

- struct buffer buf; /**< Buffer in which received= datagrams
- = * are reassembled. */
+ struct buffer buf; /**< Buffer in which re= ceived datagrams
+ = * are reassembled. */
};
=

@@ -136,11 +137,12 @@
<= span> * fragment_incoming() function adds newly received parts into this a= rray

* and returns the whole packets once reassembly is c= omplete.
*/
-struct fragment_master {
+struct fragment_master
+{
struct event_timeout wakeup; /**<= Timeout structure used by the main
= * event loop to know when to do
= * fragmentation housekeeping. */
-#define N_SEQ_ID 256+#define N_SEQ_ID 256<= br> /**< One more than the maximum fragment
= * sequence ID, above which the IDs wrap
* to = zero. Should be a power of 2. */
@@ -196,24 +198,24 @@
#define ntoh_fragment_header_type(x) ntohl(x)
/**< Convert a \c fragment_header_type from network to host order. */<= /span>

-#def= ine FRAG_TYPE_MASK 0x00000003 /**< Bit mask for %fragment = type info. */
-#define = FRAG_TYPE_SHIFT 0 /**< Bit shift for %fragment typ= e info. */
+#define F= RAG_TYPE_MASK 0x00000003 /**< Bit mask for %fragment type info. */
+#define FRAG_TYPE_SHIFT = 0 /**< Bit shift for %fragment type info. */
<= /span>
-#define FRAG_WHOLE = 0 /**< Fragment type indicating packet is whole.= */
-#define FRAG_YES_N= OTLAST 1
= +#define FRAG_WHOLE 0 /**< Fragment type indicating packet= is whole. */
+#defin= e FRAG_YES_NOTLAST 1
/**< Fragment type indicating pack= et is part of a fragmented packet, but not
* the last p= art in the sequence. */
-#define FRAG_YES_LAST 2
+#define FRAG_YES_LAST 2
/**< Fr= agment type indicating packet is the last part in the sequence of parts. */=
-#define FRAG_TEST = 3
+#d= efine FRAG_TEST 3
/**< Fragment type not impleme= nted yet.
* In the future might be used as a control pack= et for establishing MTU size. */

-#define FRAG_SEQ_ID_MASK 0x000000f= f /**< Bit mask for %fragment sequence ID. */
-#define FRAG_SEQ_ID_SHIFT 2 = /**< Bit shift for %fragment sequence ID. */
+#define FRAG_SEQ_ID_MASK 0x000000ff /**< Bi= t mask for %fragment sequence ID. */
+#define FRAG_SEQ_ID_SHIFT 2 /**< Bit shift for= %fragment sequence ID. */

-#define FRAG_ID_MASK 0x0000001f /**&= lt; Bit mask for %fragment ID. */
-#define FRAG_ID_SHIFT 10 /**< Bit shi= ft for %fragment ID. */
+#define FRAG_ID_MASK 0x0000001f /**< Bit mask for %fragment ID.= */
+#define FRAG_ID_= SHIFT 10 /**< Bit shift for %fragment ID. */


/*
@@ -225,10 +227,10= @@
* max_frag_size is only sent over the wire if FRAG_= LAST is set. Otherwise it is assumed
* to be the actua= l %fragment size received.
*/
-#define FRAG_SIZE_MASK 0x00003fff /= **< Bit mask for %fragment size. */
-#define FRAG_SIZE_SHIFT 15 /**< Bi= t shift for %fragment size. */
-#define FRAG_SIZE_ROUND_SHIFT 2 /**< Bit shift = for %fragment size rounding. */
-#define FRAG_SIZE_ROUND_MASK ((1 << FRAG_SIZE_ROUND= _SHIFT) - 1)
+#define= FRAG_SIZE_MASK 0x00003fff /**< Bit mask for %fragment size. */
+#define FRAG_SIZE_SHI= FT 15 /**< Bit shift for %fragment size. */
+#define FRAG_SIZE_ROUND_SHIFT 2 = /**< Bit shift for %fragment size rounding. */

+#define FRAG_SIZE_ROUND_MASK ((1 <= < FRAG_SIZE_ROUND_SHIFT) - 1)
/**< Bit mask for %fra= gment size rounding. */

/*
@@ -236,14 +238,14 @@

*
* IF FRAG_WH= OLE or FRAG_YES_NOTLAST, these 16 bits are available (not currently used)
*/
-#d= efine FRAG_EXTRA_MASK 0x0000ffff /**< Bit mask for extra bi= ts. */
-#define FRAG_EX= TRA_SHIFT 15 /**< Bit shift for extra bits. */

+#define FRAG_EXTRA_MASK = 0x0000ffff /**< Bit mask for extra bits. */
+#define FRAG_EXTRA_SHIFT 15 /**< Bit = shift for extra bits. */

-/** @} name Fragment header *//***********************= *********************/
-/** @name Functions for initial= ization and cleanup *//** @{ *//************/
+/** @name Functions for initialization and cleanu= p */ /** @{ */ /************/

/**=
* Allocate and initialize a \c fragment_master structure.
@@ -279,7 +281,7 @@
*/
void f= ragment_free(struct fragment_master *f);

-/** @} name Functions for initializati= on and cleanup *//*******************/
+/** @} name Functions for initialization and cleanup */ = /*******************/


= /**************************************************************************= /
@@ -327,8 +329,7 @@
* complete. If= an error occurs during processing, the buffer length
* = is also set to zero.
*/
-void fragment_incoming(struct fragment_master *f, st= ruct buffer *buf,
- = const struct frame *frame);
+void fragment_incoming(struct fragment_master *f= , struct buffer *buf, const struct frame *frame);
<= br> /** @} name Functions for processing packets received from a VPN = tunnel */

@@ -379,8 +380,7 @@
<= span> * cases a fragmentation header will have been prepended to infor= m the

* remote peer how to handle the packet.<= br> */
-void fra= gment_outgoing(struct fragment_master *f, struct buffer *buf,
- const struct= frame *frame);

+void= fragment_outgoing(struct fragment_master *f, struct buffer *buf, const str= uct frame *frame);

/**
= * Check whether outgoing fragments are ready to be send, and if so make
@@ -436,7 +436,7 @@


/**************************************************************= ************/
-/** @nam= e Functions for regular housekeeping *//** @{ *//******************/=
+/** @name Functions for re= gular housekeeping */ /** @{ */ /******************/

/**
* Perform housekeeping of a \c fragment_= master structure.
@@ -460,10 +460,10 @@
= }
}

-/** @} name Functions for regular housekeeping *//******= *******************/
= +/** @} name Functions for regular housekeeping */ /***********************= **/


-/** @} addtogroup fragmentation *//**********************= ******************/
+= /** @} addtogroup fragmentation */ /***************************************= */


#endif /* ifdef ENA= BLE_FRAGMENT */
diff --git a/src/openvpn/gremlin.c b/src/op= envpn/gremlin.c
index b58defe..8bd68e5 100644
--- a/src/openvpn/gremlin.c

+++ b/src/openvpn/gremlin.c<= /span>
@@ -65,28 +65,29 @@
* When network goes u= p, it will be up for between
* UP_LOW and UP_HIGH seconds= .
*/
= -static const int up_low[] =3D { 60, 10, 5 };
+static const int up_low[] =3D { 60, 10, 5 };
static const int up_high[] =3D { 600, 60, 10 };
<= span>

/*
* When network goes down, it w= ill be down for between
* DOWN_LOW and DOWN_HIGH seconds.=
*/
-= static const int down_low[] =3D { 5, 10, 10 };
+static const int down_low[] =3D { 5, 10, 10 }= ;
static const int down_high[] =3D { 10, 60, 120 };=

/*
* Packet flood levels:
* { number of packets, packet size }
*/<= /span>
-static const struct pa= cket_flood_parms packet_flood_data[] =3D
-{{10, 100}, {10, 1500}, {100, 1500}};
+static const struct packet_flood_parms= packet_flood_data[] =3D { { 10, 100 },
+ = { 10, 1500 },
+ { 100, 150= 0 } };

struct packet_flood_parms<= br> get_packet_flood_parms(int level)
{
ASSERT(level > 0 && level < 4);

- return packet_flood_data [level - 1];<= /span>
+ return packet_fl= ood_data[level - 1];
}

= /*
@@ -148,18 +149,16 @@
int d= elta;
if (up)
{
- delta = =3D roll(down_low[up_down_level-1], down_high[up_down_level-1]);
= + delta =3D roll= (down_low[up_down_level - 1], down_high[up_down_level - 1]);
up =3D false;

}
<= span> else

{
- delta =3D roll(up_low[up_do= wn_level-1], up_high[up_down_level-1]);
+ delta =3D roll(up_low[up_down_level - 1= ], up_high[up_down_level - 1]);
up =3D tru= e;
}

- msg(D_GREMLIN,
- "GREMLIN: CONNECT= ION GOING %s FOR %d SECONDS",
- (up ? "UP" : "DOWN"),
+ msg(D_GREMLI= N, "GREMLIN: CONNECTION GOING %s FOR %d SECONDS", (up ? "UP&= quot; : "DOWN"),
delta);<= br> next =3D now + delta;
}
@@ -167,7 +166,7 @@

if (= drop_level)
{
- if (up && flip(drop_freq[drop_level-1]))
+ if (up &&= flip(drop_freq[drop_level - 1]))
{
dmsg(D_GREMLIN_VERBOSE, "GREMLIN: Random packet drop&qu= ot;);

return false;
@@ -186,7 = +185,7 @@
const int corrupt_level =3D GREMLIN_CORRUPT_= LEVEL(flags);
if (corrupt_level)
= {
- if (flip(cor= rupt_freq[corrupt_level-1]))
+ if (flip(corrupt_freq[corrupt_level - 1]))
{

do
{<= /span>
@@ -227,7 +226,7 @@
{
break;
}<= /span>
- } while (f= lip(2)); /* a 50% chance we will corrupt again */
+ } while (flip(2)); /* a 50% chan= ce we will corrupt again */
}
= }
}
diff --git a/src/openvpn/gremlin.h b/= src/openvpn/gremlin.h
index bf1cfea..a0491b4 100644<= br>--- a/src/openvpn/gremlin.h
+++ b/src/openvpn/grem= lin.h
@@ -30,30 +30,32 @@
* Gremlin optio= ns, presented as bitmask argument to --gremlin directive
= */

-#= define GREMLIN_CONNECTION_FLOOD_SHIFT (0)
-#define GREMLIN_CONNECTION_FLOOD_MASK (0x07)
+#define GREMLIN_CONNECTIO= N_FLOOD_SHIFT (0)
+#d= efine GREMLIN_CONNECTION_FLOOD_MASK (0x07)

-#define GREMLIN_PACKET_FLOOD_SHIFT = (3)

-#define GREM= LIN_PACKET_FLOOD_MASK (0x03)
+#define GREMLIN_PACKET_FLOOD_SHIFT (3)
+#define GREMLIN_PACKET_FLOOD_MASK (0x03= )

-#d= efine GREMLIN_CORRUPT_SHIFT (5)
-#define GREMLIN_CORRUPT_MASK (0x03)=
+#define GREMLIN_CORRUPT_SH= IFT (5)
+#define GREM= LIN_CORRUPT_MASK (0x03)

-#define GREMLIN_UP_DOWN_SHIFT (7)-#define GREMLIN_UP_DOWN_MASK = (0x03)
+#de= fine GREMLIN_UP_DOWN_SHIFT (7)
+#define GREMLIN_UP_DOWN_MASK (0x03)
/* 512:1/500 1024:1/100 1536:1/50 */

-#define GREMLIN_DROP_SHIFT = (9)

-#define GRE= MLIN_DROP_MASK (0x03)
+#define GREMLIN_DROP_SHIFT (9)
+#define GREMLIN_DROP_MASK (0x03)

/* extract gremlin parms */
<= br>-#define GREMLIN_CONNECTION_FL= OOD_LEVEL(x) (((x)>>GREMLIN_CONNECTION_FLOOD_SHIFT) & GREMLIN_CON= NECTION_FLOOD_MASK)
-#d= efine GREMLIN_PACKET_FLOOD_LEVEL(x) (((x)>>GREMLIN_PACKET_FLOOD_S= HIFT) & GREMLIN_PACKET_FLOOD_MASK)
-#define GREMLIN_CORRUPT_LEVEL(x) (((x)>>= ;GREMLIN_CORRUPT_SHIFT) & GREMLIN_CORRUPT_MASK)
-#define GREMLIN_UP_DOWN_LEVEL(x) = (((x)>>GREMLIN_UP_DOWN_SHIFT) & GREMLIN_UP_DOWN_MA= SK)

-#define GREMLIN_DR= OP_LEVEL(x) (((x)>>GREMLIN_DROP_SHIFT) & = GREMLIN_DROP_MASK)
+#= define GREMLIN_CONNECTION_FLOOD_LEVEL(x) \
+ (((x) >> GREMLIN_CONNECTION_FLOOD_SHIFT) &= amp; GREMLIN_CONNECTION_FLOOD_MASK)
+#define GREMLIN_PACKET_FLOOD_LEVEL(x) \
+ (((x) >> GREMLIN_PACKET_FLOOD= _SHIFT) & GREMLIN_PACKET_FLOOD_MASK)
+#define GREMLIN_CORRUPT_LEVEL(x) (((x) >> GREMLI= N_CORRUPT_SHIFT) & GREMLIN_CORRUPT_MASK)
+#define GREMLIN_UP_DOWN_LEVEL(x) (((x) >> GR= EMLIN_UP_DOWN_SHIFT) & GREMLIN_UP_DOWN_MASK)
+#define GREMLIN_DROP_LEVEL(x) (((x) >>= ; GREMLIN_DROP_SHIFT) & GREMLIN_DROP_MASK)

= #include "buffer.h"

diff= --git a/src/openvpn/helper.c b/src/openvpn/helper.c
index = 7cef9db..6ddffbe 100644
--- a/src/openvpn/helper.c+++ b/src/openvpn/helper.c
@@ -71,14 +71,12 @@

if (netmask)
{
- buf_printf(&ou= t, "route %s %s",
- print_in_addr_t(network, 0, gc),
+ buf_printf(&out, "ro= ute %s %s", print_in_addr_t(network, 0, gc),
= print_in_addr_t(netmask, 0, gc));
}<= br> else
{
- buf_printf(&out, "route %s",
- print_i= n_addr_t(network, 0, gc));
+ buf_printf(&out, "route %s", print_in_addr_t(n= etwork, 0, gc));
}

= return BSTR(&out);
@@ -114,11 +112,8 @@
<= span> helper_add_route(const in_addr_t network, const in_addr_t netmask, st= ruct options *o)

{
rol_check_alloc(o)= ;
- add_route_to_opt= ion_list(o->routes,
= - print_in_addr_t(network, 0, &o->gc),
- = print_in_addr_t(netmask, 0, &o->gc),
- NULL,
- NULL,=

+ add_route_to_op= tion_list(o->routes, print_in_addr_t(network, 0, &o->gc),<= br>+ = print_in_addr_t(netmask, 0, &o->gc), NULL, NULL,
= o->route_default_table_id);
}


@@ -128,10 +123,8 @@
= struct gc_arena gc =3D gc_new();
if ((a & sub= net) !=3D (b & subnet))
{
- msg(M_USAGE, "%s IP addresses %s = and %s are not in the same %s subnet",
- opt,
- print_in_addr_t(a, 0, &gc),
- print_in_addr_t(b, 0, &a= mp;gc),

+ msg(= M_USAGE, "%s IP addresses %s and %s are not in the same %s subnet"= ;, opt,
+ = print_in_addr_t(a, 0, &gc), print_in_addr_t(b, 0, &gc),
<= span> print_in_addr_t(subnet, 0, &gc));

= }
gc_free(&gc);
@@ -207,17 +200,= 17 @@
}
if (o->ifconfi= g_ipv6_pool_defined)
{
- msg(M_USAGE, "--server-ipv6 alre= ady defines an ifconfig-ipv6-pool, so you can't also specify --ifconfig= -pool explicitly");
+ msg(M_USAGE,
+ "--server-ipv6 already defines an ifconfig-i= pv6-pool, so you can't also specify --ifconfig-pool explicitly");<= /span>
}

o->= ;mode =3D MODE_SERVER;
o->tls_server =3D true;<= /span>

/* local ifconfig is "base = address + 1" and "+2" */
- o->ifconfig_ipv6_local =3D
- print_in6_addr( add_in6_addr(= o->server_network_ipv6, 1), 0, &o->gc );
+ o->ifconfig_ipv6_local =3D pri= nt_in6_addr(add_in6_addr(o->server_network_ipv6, 1), 0, &o->gc);<= /span>
o->ifconfig_ipv6_remote =3D
- print_in6_addr( add_in6_addr(= o->server_network_ipv6, 2), 0, &o->gc );
+ print_in6_addr(add_in6_addr(o= ->server_network_ipv6, 2), 0, &o->gc);
o= ->ifconfig_ipv6_netbits =3D o->server_netbits_ipv6;
=
/* basic sanity check */
@@ -229,= 8 +222,8 @@
*
* Smaller= pools can't get that far, therefore we just increase by 2
*/

- = o->ifconfig_ipv6_pool_base =3D add_in6_addr(o->server_network_ipv6= ,
- = o->server_netbits_ipv6 < 112 ? 0x1000 := 2);
+ o->i= fconfig_ipv6_pool_base =3D
+ add_in6_addr(o->server_network_ipv6, o->server_net= bits_ipv6 < 112 ? 0x1000 : 2);
o->ifconfig_i= pv6_pool_netbits =3D o->server_netbits_ipv6;
push_option(o, "tun-ipv6", M_USAGE);
@@ -284,12 +277,14 @@


if (o-= >shared_secret_file)
{
- msg(M_USAGE, "--server and --= secret cannot be used together (you must use SSL/TLS keys)");+ msg(M_USAGE,
+ "-= -server and --secret cannot be used together (you must use SSL/TLS keys)&qu= ot;);
}

= if (!(o->server_flags & SF_NOPOOL) && o->ifconfig_pool_d= efined)
{
- msg(M_USAGE, "--server already defines an ifc= onfig-pool, so you can't also specify --ifconfig-pool explicitly")= ;
+ msg(M_= USAGE,
+ = "--server already defines an ifconfig-pool, so you can't also s= pecify --ifconfig-pool explicitly");
}=

if (!(dev =3D=3D DEV_TYPE_TAP || dev = =3D=3D DEV_TYPE_TUN))
@@ -310,7 +305,8 @@
=
if (netbits < IFCONFIG_POOL_MIN_NETBITS)
{
-= msg(M_USAGE, "--server directive netmask allows for too ma= ny host addresses (subnet must be %s or higher)",
+ msg(M_USAGE,
+ "--server dire= ctive netmask allows for too many host addresses (subnet must be %s or high= er)",

print_netmask(IFCONFIG_POOL_MIN= _NETBITS, &gc));
}
@@ -320,7 +316,8 @@

i= f (netbits > 29)
{
- msg(M_USAGE, "--server di= rective when used with --dev tun must define a subnet of %s or lower",=
+ msg= (M_USAGE,
+ = "--server directive when used with --dev tun must define a s= ubnet of %s or lower",
print_netm= ask(29, &gc));
}
<= br>@@ -343,14 +340,17 @@
{ o->ifconfig_pool_defined =3D true; o->ifconfig_pool_start =3D o->server_netw= ork + 4;
- = o->ifconfig_pool_end =3D (o->server_network | ~o->server_ne= tmask) - pool_end_reserve;
- ifconfig_pool_verify_range(M_USAGE, o->ifconfig= _pool_start, o->ifconfig_pool_end);
+ o->ifconfig_pool_end =3D+ (o-&= gt;server_network | ~o->server_netmask) - pool_end_reserve;
+ ifconfig_poo= l_verify_range(M_USAGE, o->ifconfig_pool_start,

+ = o->ifconfig_pool_end);
}
<= span>

helper_add_route(o->server_netwo= rk, o->server_netmask, o);
if (o->en= able_c2c)
{
- push_option(o, print_opt_route(o= ->server_network, o->server_netmask, &o->gc), M_USAGE);=
+ push_o= ption(o, print_opt_route(o->server_network, o->server_netmask, &o= ->gc),
+ = M_USAGE);
} else if (o->topology =3D=3D TOP_NET30) {
@@ -367,7 +367,8 @@
o->ifconfig_pool_defined =3D true;

o->ifconfig_pool_start =3D o->server_network= + 2;

o->ifconfig_pool_end =3D (o-&= gt;server_network | ~o->server_netmask) - 1;
- ifconfig_pool_verify_range(M_= USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
+ ifconfig_pool_v= erify_range(M_USAGE, o->ifconfig_pool_start,

+ = o->ifconfig_pool_end);
}
o->ifconfig_pool_netmask =3D o->server_netmask;

@@ -387,16 +388,17 @@
= if (o->topology =3D=3D TOP_NET30 && !(o->server_flags= & SF_NOPOOL))
{
= msg(M_WARN, "WARNING: --topology net30 support for server &quo= t;
- = "configs with IPv4 pools will be removed in a future "- "relea= se. Please migrate to --topology subnet as soon "
- "as possible.&quo= t;);
+ = "configs with IPv4 pools will be removed in a future &quo= t;
+ = "release. Please migrate to --topology subnet as soon "= ;
+ = "as possible.");
}<= br> }
else if (dev =3D=3D DEV_TYPE_T= AP)
{
if (netbits >= ; 30)
{
- msg(M_USAGE, "--server directive when u= sed with --dev tap must define a subnet of %s or lower",
+ msg(M_USAGE,

+ &quo= t;--server directive when used with --dev tap must define a subnet of %s or= lower",
print_netmask(30, &g= c));
}

@@ -4= 64,12 +466,14 @@

if (!(o->ser= ver_flags & SF_NOPOOL) && o->ifconfig_pool_defined) {
- = msg(M_USAGE, "--server-bridge already defines an ifconfig-poo= l, so you can't also specify --ifconfig-pool explicitly");<= br>+ msg(M_USAGE,
+ "= --server-bridge already defines an ifconfig-pool, so you can't also spe= cify --ifconfig-pool explicitly");
}
if (o->shared_secret_file)
= {
- = msg(M_USAGE, "--server-bridge and --secret cannot be used toget= her (you must use SSL/TLS keys)");
+ msg(M_USAGE,
+ "--server-bridge and --secret= cannot be used together (you must use SSL/TLS keys)");
}


if (dev !=3D DEV_TY= PE_TAP)
@@ -479,9 +483,12 @@

if (o->server_bridge_defined)

{
- verify_commo= n_subnet("--server-bridge", o->server_bridge_ip, o->server_= bridge_pool_start, o->server_bridge_netmask);
- verify_common_subnet("--server-= bridge", o->server_bridge_pool_start, o->server_bridge_pool_end,= o->server_bridge_netmask);
- verify_common_subnet("--server-bridge", o-&g= t;server_bridge_ip, o->server_bridge_pool_end, o->server_bridge_netma= sk);
+ ver= ify_common_subnet("--server-bridge", o->server_bridge_ip,
+ = o->server_bridge_pool_start, o->server_bridge_netmask);
+ verify_commo= n_subnet("--server-bridge", o->server_bridge_pool_start,
+ = o->server_bridge_pool_end, o->server_bridge_netmask);<= br>+ verify_common_s= ubnet("--server-bridge", o->server_bridge_ip, o->server_bri= dge_pool_end,
+ = o->server_bridge_netmask);
= }

o->mode =3D MODE_SER= VER;
@@ -552,13 +559,14 @@
}
if (o->keepalive_ping * 2 > o->keepalive_timeo= ut)
{
- msg(M_USAGE, "the second parameter to --keepalive= (restart timeout=3D%d) must be at least twice the value of the first param= eter (ping interval=3D%d). A ratio of 1:5 or 1:6 would be even better. Re= commended setting is --keepalive 10 60.",
- o->keepalive_timeout,- o->keepalive= _ping);
+ = msg(M_USAGE,
+ = "the second parameter to --keepalive (restart timeout=3D%d) m= ust be at least twice the value of the first parameter (ping interval=3D%d)= . A ratio of 1:5 or 1:6 would be even better. Recommended setting is --ke= epalive 10 60.",
+ o->keepalive_timeout, o->keepalive_ping); }
if (o->ping_send_timeout || o= ->ping_rec_timeout)
{
- msg(M_USAGE, "--keepalive conf= licts with --ping, --ping-exit, or --ping-restart. If you use --keepalive,= you don't need any of the other --ping directives.");
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(M_USAGE,
=
+ "--ke= epalive conflicts with --ping, --ping-exit, or --ping-restart. If you use = --keepalive, you don't need any of the other --ping directives.");=
}

/*
diff --git a/src/openvpn/httpdigest.c b/src/openvpn/httpdige= st.c
index 8665402..a907d32 100644
--- a/sr= c/openvpn/httpdigest.c
+++ b/src/openvpn/httpdigest.c
@@ -33,10 +33,7 @@
#include "httpdigest.h&= quot;

static void
-CvtHex(
- IN HASH Bin,
- OUT HASHHEX Hex
- )
+Cvt= Hex(IN HASH Bin, OUT HASHHEX Hex)
{
u= nsigned short i;
unsigned char j;
@@ -= 46,20 +43,20 @@
j =3D (Bin[i] >> 4) & 0x= f;
if (j <=3D 9)
{
- Hex[i*2] =3D = (j + '0');
+ = Hex[i * 2] =3D (j + '0');
}
else
{
- Hex[i*2] =3D (j + 'a' -= 10);
+ He= x[i * 2] =3D (j + 'a' - 10);
}
<= span> j =3D Bin[i] & 0xf;

if (j <= =3D 9)
{
- Hex[i*2+1] =3D (j + '0');
+ Hex[i * 2 + 1] =3D (j + &= #39;0');
}
else
{
-= Hex[i*2+1] =3D (j + 'a' - 10);
+ Hex[i * 2 + 1] =3D (j + 'a&#= 39; - 10);
}
}
Hex[HASHHEXLEN] =3D '\0';

@@ -67,34 +64,27 @= @

/* calculate H(A1) as per spec */
void
-Dige= stCalcHA1(
- IN char= *pszAlg,
- IN char = *pszUserName,
- IN c= har *pszRealm,
- IN = char *pszPassword,
- = IN char *pszNonce,
- = IN char *pszCNonce,
-= OUT HASHHEX SessionKey
- )
+DigestCal= cHA1(IN char *pszAlg, IN char *pszUserName, IN char *pszRealm, IN char *psz= Password,
+ = IN char *pszNonce, IN char *pszCNonce, OUT HASHHEX SessionKey) {
HASH HA1;
md_ctx_t *md= 5_ctx =3D md_ctx_new();

md_ctx_init(= md5_ctx, "MD5");
- md_ctx_update(md5_ctx, (const uint8_t *) pszUserName, strlen(pszUs= erName));
- md_ctx_u= pdate(md5_ctx, (const uint8_t *) ":", 1);
- md_ctx_update(md5_ctx, (const uint8_t *= ) pszRealm, strlen(pszRealm));
- md_ctx_update(md5_ctx, (const uint8_t *) ":", 1);
- md_ctx_update(md5_ct= x, (const uint8_t *) pszPassword, strlen(pszPassword));
+ md_ctx_update(md5_ctx, (const uint8= _t *)pszUserName, strlen(pszUserName));
+ md_ctx_update(md5_ctx, (const uint8_t *)":&quo= t;, 1);
+ md_ctx_u= pdate(md5_ctx, (const uint8_t *)pszRealm, strlen(pszRealm));
+ md_ctx_update(md5_ctx, (const = uint8_t *)":", 1);

+ md_ctx_update(md5_ctx, (const uint8_t *)pszPassword, strlen(ps= zPassword));
md_ctx_final(md5_ctx, HA1);
if (pszAlg && strcasecmp(pszAlg, "md5-sess") =3D= =3D 0)

{
md_ctx_init(md5_ctx,= "MD5");
md_ctx_update(md5_ctx, HA1, HAS= HLEN);
- md_ctx_= update(md5_ctx, (const uint8_t *) ":", 1);
- md_ctx_update(md5_ctx, (const uint8= _t *) pszNonce, strlen(pszNonce));
- md_ctx_update(md5_ctx, (const uint8_t *) ":"= , 1);
- md_ctx_u= pdate(md5_ctx, (const uint8_t *) pszCNonce, strlen(pszCNonce));
<= span style=3D"color: hsl(120, 100%, 40%);">+ md_ctx_update(md5_ctx, = (const uint8_t *)":", 1);

+ md_ctx_update(md5_ctx, (const uint8_t *)pszNonce, s= trlen(pszNonce));
+ = md_ctx_update(md5_ctx, (const uint8_t *)":", 1);
= + md_ctx_update(md5_ctx,= (const uint8_t *)pszCNonce, strlen(pszCNonce));
m= d_ctx_final(md5_ctx, HA1);
}
md_c= tx_cleanup(md5_ctx);
@@ -104,17 +94,16 @@
=
/* calculate request-digest/response-digest as per HTTP D= igest spec */
void
-DigestCalcResponse(
- IN HASHHEX HA1, /* H(A1) */=
- IN char *pszNonce, = /* nonce from server */
- IN char *pszNonceCount, /* 8 hex di= gits */
- IN char *p= szCNonce, /* client nonce */
- IN char *pszQop, /*= qop-value: "", "auth", "auth-int" */<= br>- IN char *pszMethod, = /* method from the request */
- IN char *pszDigestUri, /* req= uested URL */
- IN H= ASHHEX HEntity, /* H(entity body) if qop=3D"auth-= int" */
- OUT H= ASHHEX Response /* request-digest or response-digest */=
- )
+DigestCalcResponse(IN HASHHEX HA1, = /* H(A1) */

+= IN char *pszNonce, /* nonce from server */+ IN char *= pszNonceCount, /* 8 hex digits */
+ IN char *pszCNonce, /* client nonce */=
+ = IN char *pszQop, /* qop-value: "", "auth", "= ;auth-int" */
+ = IN char *pszMethod, /* method from the request */
+ IN c= har *pszDigestUri, /* requested URL */
+ IN HASHHEX HEntity, /* H(entity = body) if qop=3D"auth-int" */
+ OUT HASHHEX Response /* request-di= gest or response-digest */
+)
{
HASH HA2;
= HASH RespHash;
@@ -124,12 +113,12 @@
=
/* calculate H(A2) */
md_ctx_ini= t(md5_ctx, "MD5");
- md_ctx_update(md5_ctx, (const uint8_t *) pszMethod, strlen(pszMe= thod));
- md_ctx_upd= ate(md5_ctx, (const uint8_t *) ":", 1);
- md_ctx_update(md5_ctx, (const uint8_t *) ps= zDigestUri, strlen(pszDigestUri));
+ md_ctx_update(md5_ctx, (const uint8_t *)pszMethod, strle= n(pszMethod));
+ m= d_ctx_update(md5_ctx, (const uint8_t *)":", 1);
+ md_ctx_update(md5_ctx, (const uin= t8_t *)pszDigestUri, strlen(pszDigestUri));
if (strcas= ecmp(pszQop, "auth-int") =3D=3D 0)
{<= br>- md_ctx_update(md5_ctx= , (const uint8_t *) ":", 1);
+ md_ctx_update(md5_ctx, (const uint8_t *)":&= quot;, 1);
md_ctx_update(md5_ctx, HEntity, HASHHEX= LEN);
}
md_ctx_final(md5_ctx, HA2= );
@@ -138,17 +127,17 @@
/* calculate = response */
md_ctx_init(md5_ctx, "MD5");
md_ctx_update(md5_ctx, HA1, HASHHEXLEN);
- md_ctx_update(md5_ctx, (const uint= 8_t *) ":", 1);
- md_ctx_update(md5_ctx, (const uint8_t *) pszNonce, strlen(pszNonce)= );
- md_ctx_update(m= d5_ctx, (const uint8_t *) ":", 1);
+ md_ctx_update(md5_ctx, (const uint8_t *)"= :", 1);
+ md_= ctx_update(md5_ctx, (const uint8_t *)pszNonce, strlen(pszNonce));+ md_ctx_update(md5_ctx, (c= onst uint8_t *)":", 1);
if (*pszQop)<= br> {
- = md_ctx_update(md5_ctx, (const uint8_t *) pszNonceCount, strlen(pszNonceCo= unt));
- md_ctx_= update(md5_ctx, (const uint8_t *) ":", 1);
- md_ctx_update(md5_ctx, (const uint8= _t *) pszCNonce, strlen(pszCNonce));
- md_ctx_update(md5_ctx, (const uint8_t *) ":&quo= t;, 1);
- md_ctx= _update(md5_ctx, (const uint8_t *) pszQop, strlen(pszQop));
- md_ctx_update(md5_ctx, (const= uint8_t *) ":", 1);

+ md_ctx_update(md5_ctx, (const uint8_t *)pszNonceCount, s= trlen(pszNonceCount));
+ md_ctx_update(md5= _ctx, (const uint8_t *)pszCNonce, strlen(pszCNonce));
+ md_ctx_update(md5_ctx, (const uin= t8_t *)":", 1);
+ md_ctx_update(md5_ctx, (const uint8_t *)pszQop, strlen(pszQop= ));
+ md_ctx_u= pdate(md5_ctx, (const uint8_t *)":", 1);
}
md_ctx_update(md5_ctx, HA2Hex, HASHHEXLEN);
<= span> md_ctx_final(md5_ctx, RespHash);

diff --git a/src= /openvpn/httpdigest.h b/src/openvpn/httpdigest.h
index 50cf= 451..1d1bc49 100644
--- a/src/openvpn/httpdigest.h+++ b/src/openvpn/httpdigest.h
@@ -26,34 +26,26 @@<= /span>
#define HASHLEN 16
typedef unsigned char = HASH[HASHLEN];
#define HASHHEXLEN 32
-typedef unsigned char HASHHEX[HASHHEXLEN+1]= ;
+typedef unsigned c= har HASHHEX[HASHHEXLEN + 1];
#undef IN
#u= ndef OUT
#define IN const
#define OUT

/* calculate H(A1) as per HTTP Digest spec = */
-void DigestCalcHA1(=
- IN char *pszAlg,<= /span>
- IN char *pszUserNa= me,
- IN char *pszRe= alm,
- IN char *pszP= assword,
- IN char *= pszNonce,
- IN char = *pszCNonce,
- OUT HA= SHHEX SessionKey
- )= ;
+void DigestCalcHA1= (IN char *pszAlg, IN char *pszUserName, IN char *pszRealm, IN char *pszPass= word,
+ = IN char *pszNonce, IN char *pszCNonce, OUT HASHHEX SessionKey);=

/* calculate request-digest/response-digest as= per HTTP Digest spec */
- IN HASHHEX HA1, /* H(A1) */
- IN char *pszNonce, /* nonce from serve= r */
- IN char *pszN= onceCount, /* 8 hex digits */
- IN char *pszCNonce, /* client nonce */
- IN char *pszQop, /* qop-v= alue: "", "auth", "auth-int" */
- IN char *pszMethod, /* me= thod from the request */

- IN HASHHEX HEntity, /* H(entity b= ody) if qop=3D"auth-int" */
- OUT HASHHEX Response /* request-digest or response= -digest */
- );
+void DigestCalcResponse(= IN HASHHEX HA1, /* H(A1) */
+ IN char *pszNonce, /* nonce fr= om server */
+ = IN char *pszNonceCount, /* 8 hex digits */
+ IN char *ps= zCNonce, /* client nonce */

+ IN char *pszQop, /* qop-value: &= quot;", "auth", "auth-int" */
+ IN char *pszMeth= od, /* method from the request */
+ IN char *pszDigestUri, /* reques= ted URL */
+ = IN HASHHEX HEntity, /* H(entity body) if qop=3D"aut= h-int" */
+ = OUT HASHHEX Response /* request-digest or response-di= gest */
+);
#endif /* if PROXY_DIGEST_AUTH */
diff --git a/src/openvpn/init.c b/src/openvpn/init.c

index= 77747a2..1085bce 100644
--- a/src/openvpn/init.c+++ b/src/openvpn/init.c
@@ -59,15 +59,15 @@<= br> #include "memdbg.h"

=
-static struct context= *static_context; /* GLOBAL */
+static struct context *static_context; /* GLOBAL */
<= span> static const char *saved_pid_file_name; /* GLOBAL */

=
/*
* Crypto initialization flags
*/
-#defin= e CF_LOAD_PERSISTED_PACKET_ID (1<<0)
-#define CF_INIT_TLS_MULTI (1<<1)
-#define CF_INIT_TLS_AUTH_ST= ANDALONE (1<<2)
+#define CF_LOAD_PERSISTED_PACKET_ID (1 << 0)
+#define CF_INIT_TLS_MULTI (1 &l= t;< 1)
+#define CF= _INIT_TLS_AUTH_STANDALONE (1 << 2)

= static void do_init_first_time(struct context *c);

@@ -106,21 +106,14 @@
* Used to execute the up= /down script/plugins.
*/
static void
-run_up_down(const char *c= ommand,
- co= nst struct plugin_list *plugins,
- int plugin_type,
+run_up_down(const char *command, const struct plugin_li= st *plugins, int plugin_type,
const char *arg,=
#ifdef _WIN32
DWORD adapter_= index,
#endif
- const char *dev_type,
- int tun_mtu,
- const char *ifconfig_local,
<= span style=3D"color: hsl(0, 100%, 40%);">- const char *ifconfig_= remote,

- co= nst char *context,
- = const char *signal_text,
- const char *script_type,
- struct env_set *es)
+ const char *dev_type, in= t tun_mtu, const char *ifconfig_local,
+ const char *ifconfig_remote, const char *con= text, const char *signal_text,
+ const char *script_type, struct env_set *es)<= br> {
struct gc_arena gc =3D gc_new();
@@ -156,9 +149,8 @@
{<= br> struct argv argv =3D argv_new();
= ASSERT(arg);
- = argv_printf(&argv,
= - "%s %d 0 %s %s %s",
- arg, tun_mtu, ifconfig_loc= al, ifconfig_remote, context);
+ argv_printf(&argv, "%s %d 0 %s %s %s", arg= , tun_mtu, ifconfig_local, ifconfig_remote,
+ context);

if (plugin_call(plugins, plugin_type, &argv, NULL= , es) !=3D OPENVPN_PLUGIN_FUNC_SUCCESS)
{@@ -174,8 +166,8 @@
ASSERT(arg); setenv_str(es, "script_type", script_type);
argv_parse_cmd(&argv, command);
- argv_printf_cat(&argv, "= %s %d 0 %s %s %s", arg, tun_mtu,
- ifconfig_local, ifconfig_remote, co= ntext);
+ argv= _printf_cat(&argv, "%s %d 0 %s %s %s", arg, tun_mtu, ifconfig= _local, ifconfig_remote,
+ context);
argv_msg(M_= INFO, &argv);
openvpn_run_script(&argv, es= , S_FATAL, "--up/--down");
argv_free(&am= p;argv);
@@ -197,8 +189,7 @@
* for th= e period of time before we pull the --ping-restart parameter
* from the server.

*/
- if (options->pull
- && options->ping_rec_= timeout_action =3D=3D PING_UNDEF
+ if (options->pull && options->ping_rec_timeo= ut_action =3D=3D PING_UNDEF
&& proto_is_dg= ram(options->ce.proto))
{
= options->ping_rec_timeout =3D PRE_PULL_INITIAL_PING_RESTART;
<= span>@@ -304,11 +295,9 @@

* @return if sendi= ng was successful
*/
static bool<= br>-management_callback_send_cc_m= essage(void *arg,
- = const char *command,
- const c= har *parameters)
+man= agement_callback_send_cc_message(void *arg, const char *command, const char= *parameters)
{
- struct context *c =3D (struct context *) arg;
+ struct context *c =3D (struct = context *)arg;

size_t len =3D strlen(command) + 1 + st= rlen(parameters) + 1;
if (len > PUSH_BUNDLE_SIZE)
{
@@ -332,7 +321,7 @@
= management_callback_remote_entry_count(void *arg)
{=
assert(arg);
- struct context *c =3D (struct context *) arg;
+ struct context *c =3D (struct conte= xt *)arg;
struct connection_list *l =3D c->options.= connection_list;

return l->len;
@@ -344,7 +333,7 @@
assert(arg);=
assert(remote);

- struct context *c =3D (struct context *) arg= ;
+ struct context= *c =3D (struct context *)arg;
struct connection_list = *l =3D c->options.connection_list;
bool ret =3D tru= e;

@@ -355,8 +344,8 @@
= const char *status =3D (ce->flags & CE_DISABLED) ? "disa= bled" : "enabled";

= /* space for output including 3 commas and a nul */
- int len =3D strlen(ce->remote) += strlen(ce->remote_port) + strlen(proto)
- + strlen(status) + 3 + 1;+ int len =3D+ strlen(ce->rem= ote) + strlen(ce->remote_port) + strlen(proto) + strlen(status) + 3 + 1;=
char *out =3D malloc(len);
= check_malloc_return(out);

@@ -375,10 += 364,12 @@
static bool
management_callback= _remote_cmd(void *arg, const char **p)
{
- struct context *c =3D (struct conte= xt *) arg;
+ struc= t context *c =3D (struct context *)arg;
struct connect= ion_entry *ce =3D &c->options.ce;
int ret =3D f= alse;
- if (p[1] &am= p;& ((ce->flags>>CE_MAN_QUERY_REMOTE_SHIFT)&CE_MAN_QUERY_R= EMOTE_MASK) =3D=3D CE_MAN_QUERY_REMOTE_QUERY)
+ if (p[1]
+ && ((ce->flags >> CE_MAN_QUERY_= REMOTE_SHIFT) & CE_MAN_QUERY_REMOTE_MASK)
+ =3D=3D CE_MAN_QUERY_REMOTE_QUERY)<= /span>
{
int flags =3D 0;
= if (!strcmp(p[1], "ACCEPT"))
@@ -4= 13,8 +404,8 @@
}
if (ret)=
{
- ce->flags &=3D ~(CE_MAN_QUERY_REMOTE_MASK<<C= E_MAN_QUERY_REMOTE_SHIFT);
- ce->flags |=3D ((flags&CE_MAN_QUERY_REMOTE_MASK)<= ;<CE_MAN_QUERY_REMOTE_SHIFT);
+ ce->flags &=3D ~(CE_MAN_QUERY_REMOTE_MASK &= lt;< CE_MAN_QUERY_REMOTE_SHIFT);
+ ce->flags |=3D ((flags & CE_MAN_QUERY_RE= MOTE_MASK) << CE_MAN_QUERY_REMOTE_SHIFT);
}<= /span>
}
return ret;
@@ = -439,8 +430,8 @@

ce->flags &a= mp;=3D ~(CE_MAN_QUERY_REMOTE_MASK << CE_MAN_QUERY_REMOTE_SHIFT);
ce->flags |=3D (CE_MAN_QUERY_REMOTE_QUERY << = CE_MAN_QUERY_REMOTE_SHIFT);
- while (((ce->flags >> CE_MAN_QUERY_REMOTE_SHIFT)
- & CE_= MAN_QUERY_REMOTE_MASK) =3D=3D CE_MAN_QUERY_REMOTE_QUERY)
+ while (((ce->flags >>= CE_MAN_QUERY_REMOTE_SHIFT) & CE_MAN_QUERY_REMOTE_MASK)
+ =3D=3D CE_MAN_QUERY_= REMOTE_QUERY)

{
manag= ement_event_loop_n_seconds(management, 1);
if = (IS_SIG(c))
@@ -458,8 +449,7 @@
/*= If it is likely a connection entry was modified,
= * check what changed in the flags and that it was not skipped
*/

- = const int flags =3D ((ce->flags >> CE_MAN_QUERY_REMOTE_SHIFT)
- = & CE_MAN_QUERY_REMOTE_MASK);
+ const int flags =3D ((ce->flags >> CE_MAN= _QUERY_REMOTE_SHIFT) & CE_MAN_QUERY_REMOTE_MASK);
= ce_changed =3D (flags !=3D CE_MAN_QUERY_REMOTE_SKIP);
= }
return ce_changed;
@@ -636,7 +62= 6,7 @@

/* Check if this connection a= ttempt would bring us over the limit */
if (c->opti= ons.connect_retry_max > 0
- && c->options.unsuccessful_attempts > (l->l= en * c->options.connect_retry_max))
+ && c->options.unsuccessful_attempts = > (l->len * c->options.connect_retry_max))
{<= /span>
msg(M_FATAL, "All connections have been conne= ct-retry-max (%d) times unsuccessful, exiting",
= c->options.connect_retry_max);
@@ -661,12 +651,11= @@
{
enable_auth_user_pass()= ;
#ifdef ENABLE_MANAGEMENT
- auth_user_pass_setup(c->options.auth_user_= pass_file,
- = c->options.auth_user_pass_file_inline,
+ auth_user_pass_setup(c->= options.auth_user_pass_file, c->options.auth_user_pass_file_inline,
&c->options.sc_info);
#else
- = auth_user_pass_setup(c->options.auth_user_pass_file,
- c->o= ptions.auth_user_pass_file_inline, NULL);

+ auth_user_pass_setup(c->options.auth_user_= pass_file, c->options.auth_user_pass_file_inline,
+ NULL);

#endif
}
}
@@ -714,9 +703,9 @@


if (!did_http = && c->options.ce.socks_proxy_server)
{
- c->c1.socks_pro= xy =3D socks_proxy_new(c->options.ce.socks_proxy_server,
- = c->options.ce.socks_proxy_port,

- c->optio= ns.ce.socks_proxy_authfile);
+ c->c1.socks_proxy =3D
+ socks_proxy_new(c->options.ce.socks_pr= oxy_server, c->options.ce.socks_proxy_port,
+ c->options.ce.soc= ks_proxy_authfile);
if (c->c1.socks_proxy)
{
c->c1.socks_proxy_ow= ned =3D true;
@@ -739,8 +728,8 @@
static v= oid
do_link_socket_addr_new(struct context *c)
<= span> {

- ALLOC_ARRA= Y_CLEAR_GC(c->c1.link_socket_addrs, struct link_socket_addr,
<= span style=3D"color: hsl(0, 100%, 40%);">- c->c1= .link_sockets_num, &c->gc);

+ ALLOC_ARRAY_CLEAR_GC(c->c1.link_socket_addrs, struct = link_socket_addr, c->c1.link_sockets_num,
+ &c->gc); }

void
@@ -761,1= 0 +750,11 @@
{
int i;<= br> pkcs11_initialize(true, c->options.pkcs11_pin_cache_pe= riod);
- for (i = =3D 0; i<MAX_PARMS && c->options.pkcs11_providers[i] !=3D NUL= L; i++)
+ for = (i =3D 0; i < MAX_PARMS && c->options.pkcs11_providers[i] != =3D NULL; i++)
{
- pkcs11_addProvider(c->options.pkcs11_pro= viders[i], c->options.pkcs11_protected_authentication[i],
- c->= ;options.pkcs11_private_mode[i], c->options.pkcs11_cert_private[i]);
+ pkcs11_addP= rovider(
+ = c->options.pkcs11_providers[i], c->options.pkcs11_protected_auth= entication[i],
+ = c->options.pkcs11_private_mode[i], c->options.pkcs11_cert_= private[i]);
}
}
#endif

@@ -789,9 +779,8 @@
* See= possibly_become_daemon() [init.c] for more details.
= */
sd_notifyf(0, "READY=3D1\nSTATUS=3DPre-connect= ion initialization successful\nMAINPID=3D%lu",
- (unsigned long) getpid());
+ (unsig= ned long)getpid());
#endif
-
}

void

@@ -819,10 +808,9 @@
{
if (!port_share && (c->options.port_share_host &&am= p; c->options.port_share_port))

{
- port_share =3D port_share_open(= c->options.port_share_host,
- c->options.port_share_port= ,
- = c->c2.frame.buf.payload_size,
- c->opti= ons.port_share_journal_dir);
+ port_share =3D
+ port_share_open(c->options.port_share_host, c-&g= t;options.port_share_port,
+ c->c2.frame.buf.payload_size, c->o= ptions.port_share_journal_dir);
if (port_share =3D= =3D NULL)
{
msg(M_FAT= AL, "Fatal error: Port sharing failed");
@@ -850,= 12 +838,12 @@
struct timeval tv;
= if (!gettimeofday(&tv, NULL))
{
- const unsigned int seed =3D (uns= igned int) tv.tv_sec ^ tv.tv_usec;
+ const unsigned int seed =3D (unsigned int)tv.tv_sec = ^ tv.tv_usec;
srandom(seed);
= }

- = error_reset(); /* initialize error.c */
- reset_check_status(); /* initial= ize status check code in socket.c */
+ error_reset(); /* initialize error.c */<= br>+ reset_check_status(); /= * initialize status check code in socket.c */

<= span> #ifdef _WIN32

init_win32();
@@ -= 893,9 +881,7 @@
#ifdef GEN_PATH_TEST
= {
struct gc_arena gc =3D gc_new();
- const char *fn =3D gen_path(&= quot;foo",

- = "bar",
- &gc);+ const char *fn =3D g= en_path("foo", "bar", &gc);
= printf("%s\n", fn);
gc_free(&gc);<= /span>
}
@@ -1012,8 +998,7 @@
}

if (options->show_tls_ciphers)
{
= - show_available_tls_ciphers(options->cipher_list,
= - = options->cipher_list_tls13,
+ show_available_tls_ciphers(options->cipher= _list, options->cipher_list_tls13,
= options->tls_cert_profile);
= }
if (options->show_curves)
@@ = -1041,11 +1026,10 @@
* We do not want user to use --g= enkey with --secret. In the transistion
* phase we fo= r secret.
*/
- if (options->genkey && options->genkey_type = !=3D GENKEY_SECRET
- = && options->shared_secret_file)
+ if (options->genkey && options-&= gt;genkey_type !=3D GENKEY_SECRET && options->shared_secret_file= )
{
msg(M_USAGE, "Using = --genkey type with --secret filename is "
- "not supported. Use --genkey typ= e filename instead.");
+ "not supported. Use --genkey type filena= me instead.");
}
if (options= ->genkey && options->genkey_type =3D=3D GENKEY_SECRET)=
{
@@ -1054,7 +1038,7 @@
= if (options->shared_secret_file && options->genkey_filen= ame)
{
msg(M_USAGE, &= quot;You must provide a filename to either --genkey "
- "or --secret, not= both");
+ = "or --secret, not both");
= }

/*
@@ -10= 64,7 +1048,7 @@
if (options->shared_secret_file= )
{
msg(M_WARN, "= ;WARNING: Using --genkey --secret filename is "
- "DEPRECATED. Use --ge= nkey secret filename instead.");
+ "DEPRECATED. Use --genkey s= ecret filename instead.");
genkey_filenam= e =3D options->shared_secret_file;
}
=
@@ -1074,8 +1058,7 @@
= msg(M_FATAL, "Failed to write key file");
= }

-= msg(D_GENKEY | M_NOPREFIX,
- "Randomly generated %d bit key written to %s&= quot;, nbits_written,
+ msg(D_GENKEY | M_NOPREFIX, "Randomly generated %d bit key wr= itten to %s", nbits_written,
options->= shared_secret_file);
return true;
= }
@@ -1092,8 +1075,8 @@
= "--genkey tls-crypt-v2-client requires a server key to be set via -= -tls-crypt-v2 to create a client key");
}

- = tls_crypt_v2_write_client_key_file(options->genkey_filename,
= - = options->genkey_extra_data, options->tls_crypt_v2_file,
+ tls_crypt_v2_w= rite_client_key_file(options->genkey_filename, options->genkey_extra_= data,
+ = options->tls_crypt_v2_file,
options->tls_crypt_v2_file_= inline);

return true;
}
@@ -1121,13 +1104,10 @@

/= * sanity check on options for --mktun or --rmtun */
no= tnull(options->dev, "TUN/TAP device (--dev)");
- if (options->ce.remote || opti= ons->ifconfig_local

= - || options->ifconfig_remote_netmask
- || options->shared_secret_file<= br>- || options->tls_se= rver || options->tls_client
- )
+ = if (options->ce.remote || options->ifconfig_local || options->i= fconfig_remote_netmask
- msg(M_FATAL|M_OPTERR,
+ msg(M_FATAL | M_OPTERR, "options --mktun or --rmtun should only be used to= gether with --dev");
}
@@ -1151,21 +1131,20 @@
#endif

#ifdef ENABLE_FEATURE_TUN_PERSIST
- tuncfg(options->dev, options->dev_typ= e, options->dev_node,
- options->username, options->groupname, &= amp;options->tuntap_options,
- ctx);
+ tuncfg(options->dev, options->dev_type, options->dev_no= de, options->persist_mode,
+ options->username, options->groupname, &opti= ons->tuntap_options, ctx);
if (options->persist_= mode && options->lladdr)
{
= set_lladdr(ctx, options->dev, options->lladdr, NULL);=
}
return true;
-#else /* ifdef ENABLE_FEATURE_TUN_PERSIST */<= /span>
- msg(M_FATAL|M_OPTE= RR,
+#else /* ifdef E= NABLE_FEATURE_TUN_PERSIST */
+ msg(M_FATAL | M_OPTERR,
"options= --mktun and --rmtun are not available on your operating "
<= span> "system. Please check 'man tun' (or 'tap= 9;), whether your system "

"supports usi= ng 'ifconfig %s create' / 'destroy' to create/remove "=
- "persist= ent tunnel interfaces.", options->dev );
+ "persistent tunnel interfaces.&qu= ot;,
+ options= ->dev);
#endif
return false;
}
@@ -1242,9 +1221,7 @@
= {
if (no_delay)
= {
- pla= tform_user_group_set(&c0->platform_state_user,
- &am= p;c0->platform_state_group,
- c);
+ platform_user_group_set(&= amp;c0->platform_state_user, &c0->platform_state_group, c);
}
else if (c->first= _time)
{
@@ -1272,7 +1249,8 @@=
{
if (-1 =3D= =3D setcon(c->options.selinux_context))
= {
- = msg(M_ERR, "setcon to '%s' failed; is /proc accessible?"= , c->options.selinux_context);
+ msg(M_ERR, "setcon to '%s' f= ailed; is /proc accessible?",
+ c->options.selinux_context);
}
else=
{
@@ -1317,17 +1295,12 @@=
#ifdef _WIN32
if (options->exit_event_na= me)
{
- win32_signal_open(&win32_signal,
- WSO_FORCE_SERVICE,
- = options->exit_event_name,
+ win32_signal_open(&win32_signal, WSO_FORCE_SERVICE, = options->exit_event_name,
opt= ions->exit_event_initial_state);
}
= else
{
- win32_signal_open(&win32_signal,
- WSO_FORCE_CONSO= LE,
- = NULL,
- = false);
+ win32_signal_open(&win32_signal, WSO_FORCE_CONSOLE, NULL,= false);

/* put a title on the t= op window bar */
if (win32_signal.mode =3D=3D WSO_= MODE_CONSOLE)
@@ -1378,8 +1351,7 @@
/*= initialize inactivity timeout */
if (c->options.se= ssion_timeout)
{
- event_timeout_init(&c->c2.session_interval, = c->options.session_timeout,
- now);
+ event_timeout_init(&c->c2.session_inte= rval, c->options.session_timeout, now);
}
/* initialize pings */
@@ -14= 10,8 +1382,7 @@
if (c->options.auth_token_generate<= /span>
&& c->options.auth_token_renewal < c= ->options.renegotiate_seconds)
{
- event_timeout_init(&c->c2= .auth_token_renewal_interval,
- c->options.auth_token_renewal, now);<= /span>
+ event_timeou= t_init(&c->c2.auth_token_renewal_interval, c->options.auth_token_= renewal, now);
}

= if (!deferred)
@@ -1421,16 +1392,16 @@
<= /span>
/* initialize occ timers */

- if (c->options.= occ
- &&= amp; !TLS_MODE(c)
- = && c->c2.options_string_local && c->c2.option= s_string_remote)
+ = if (c->options.occ && !TLS_MODE(c) && c->c2.opti= ons_string_local
+ = && c->c2.options_string_remote)
= {
event_timeout_init(&c->c2.occ_inter= val, OCC_INTERVAL_SECONDS, now);
}

if (c->options.mtu_test)
= {
- ev= ent_timeout_init(&c->c2.occ_mtu_load_test_interval, OCC_MTU_LOAD_INT= ERVAL_SECONDS, now);
= + event_timeout_init(&c->c2.occ_mtu_load_test_interval, O= CC_MTU_LOAD_INTERVAL_SECONDS,
+ now);
}

/* initialize packet_id persisten= ce timer */
@@ -1483,10 +1454,8 @@
* opti= ons and saving routes in the environment.
*/
static void

-do_in= it_route_list(const struct options *options,
- struct route_list *route_list,
- const= struct link_socket_info *link_socket_info,
- struct env_set *es,
+do_init_route_list(const struct op= tions *options, struct route_list *route_list,

+ const struct link_socket_info= *link_socket_info, struct env_set *es,
= openvpn_net_ctx_t *ctx)
{
const char= *gw =3D NULL;
@@ -1515,13 +1484,8 @@
= metric =3D options->route_default_metric;
}

- if = (init_route_list(route_list,
- options->routes,
- gw,
- metric,- link_s= ocket_current_remote(link_socket_info),
- es,
- ctx))
+ if (init_route_list(route_list, optio= ns->routes, gw, metric,
+ link_socket_current_remote(link_socket_info)= , es, ctx))
{
/* copy routes = to environment */
setenv_routes(es, route_list);
@@ -1529,14 +1493,12 @@
}
=
static void
-do_init_route_ipv6_list(const struct options *options,
- struct rou= te_ipv6_list *route_ipv6_list,

- const struct link_socket_info *link_socket= _info,
- = struct env_set *es,
+do_init_route_ipv6_list(const struct options *options, struct rout= e_ipv6_list *route_ipv6_list,
+ const struct link_socket_info *link_socke= t_info, struct env_set *es,
openvp= n_net_ctx_t *ctx)
{
const char *gw = =3D NULL;
- int metr= ic =3D -1; /* no metric set */
+ int metric =3D -1; /* no metric set */
=
/* see explanation in do_init_route_list() */<= /span>
if (dco_enabled(options))
@@ -1544,7 += 1506,7 @@
metric =3D DCO_DEFAULT_METRIC; }

- gw =3D options->ifconfig_ipv6_remote; /* default G= W =3D remote end */
+= gw =3D options->ifconfig_ipv6_remote; /* default GW =3D remote end *= /
if (options->route_ipv6_default_gateway) {
gw =3D options->route_ipv6_defau= lt_gateway;
@@ -1564,19 +1526,14 @@

for (i =3D 0; opt_list[i]; i++)
= {
- add_ro= ute_ipv6_to_option_list( options->routes_ipv6,
- stri= ng_alloc(opt_list[i], options->routes_ipv6->gc),
- = NULL, NULL, options->route_default_table_id);
+ add_route_ipv6_to_option_list(opt= ions->routes_ipv6,
+ string_alloc(opt_list[i], optio= ns->routes_ipv6->gc), NULL,
+ NULL, options->r= oute_default_table_id);
}
}

- i= f (init_route_ipv6_list(route_ipv6_list,
- options->routes_ipv6,
- = gw,
- = metric,
- link_socket_current_remote_ipv6(link_socket_= info),
- = es,
- = ctx))
+ if (init_route_ipv6_list(route_ipv6_list, options->routes= _ipv6, gw, metric,
+ = link_socket_current_remote_ipv6(link_socket_inf= o), es, ctx))
{
/* copy route= s to environment */
setenv_routes_ipv6(es, route_i= pv6_list);
@@ -1602,8 +1559,8 @@
if (f= lags & ISC_ERRORS)
{
#ifdef _WIN3= 2
- show_routes(= M_INFO|M_NOPREFIX);
- = show_adapters(M_INFO|M_NOPREFIX);
+ show_routes(M_INFO | M_NOPREFIX);
+ show_adapters(M_INFO | M_= NOPREFIX);

msg(M_INFO, "%s With Errors ( see = http://openvpn.net/faq.html#dhcpclientserv )", message);
#else

#ifdef ENABLE_SYSTEMD
@@ -1621,7= +1578,7 @@
}

/= * Flag that we initialized */
- if ((flags & (ISC_ERRORS|ISC_SERVER)) =3D=3D 0)
<= span style=3D"color: hsl(120, 100%, 40%);">+ if ((flags & (ISC_ERROR= S | ISC_SERVER)) =3D=3D 0)

{
= c->options.no_advance =3D true;
}
@= @ -1683,13 +1640,8 @@
tun_local =3D &c->= ;c1.tuntap->local;
tun_local6 =3D &c-&g= t;c1.tuntap->local_ipv6;
}
- management_set_state(management,
- = OPENVPN_STATE_CONNECTED,
- detail,
- tun_local,
<= span style=3D"color: hsl(0, 100%, 40%);">- tun_= local6,

- = &local,
- &remote);
+ management_set_state(management, OPENVP= N_STATE_CONNECTED, detail, tun_local, tun_local6,
+ &local, &= ;remote);
if (tun_local)
= {
management_post_tunnel_open(management, *tun= _local);
@@ -1705,8 +1657,7 @@
static bool=
route_noexec_enabled(const struct options *o, const struc= t tuntap *tt)
{
- return o->route_noexec
- || (tt && tt->backend_driver =3D= =3D DRIVER_AFUNIX)
+ = return o->route_noexec || (tt && tt->backend_driver =3D=3D= DRIVER_AFUNIX)
|| (tt && tt->backen= d_driver =3D=3D DRIVER_NULL);
}
@@ -1715,19 +1666,14 @@
* based on options.
*/
bool
-do_route(const struct options *options,
- struct route_list *route_list,
- struct route_i= pv6_list *route_ipv6_list,
- const struct tuntap *tt,
- const struct plugin_list *plugins,
- struct env_set *es,
<= br>- openvpn_net_ctx_t *c= tx)
+do_route(const s= truct options *options, struct route_list *route_list,
+ struct route_ipv6_list *route_i= pv6_list, const struct tuntap *tt,
+ const struct plugin_list *plugins, struct env_set *= es, openvpn_net_ctx_t *ctx)
{
bool re= t =3D true;
- if (!r= oute_noexec_enabled(options, tt) && ( route_list || route_ipv6_list= ) )
+ if (!route_= noexec_enabled(options, tt) && (route_list || route_ipv6_list))
{
- = ret =3D add_routes(route_list, route_ipv6_list, tt, ROUTE_OPTION_FLAG= S(options),
- = es, ctx);
+ ret =3D add_routes(route_list, route_ipv6_list, tt, ROUTE_OPTI= ON_FLAGS(options), es, ctx);
setenv_int(es, "= redirect_gateway", route_did_redirect_default_gateway(route_list));
}
#ifdef ENABLE_MANAGEMENT
@@ -1739,7 +1685,8 @@


if (plugin= _defined(plugins, OPENVPN_PLUGIN_ROUTE_UP))
{- if (plugin_call(plugin= s, OPENVPN_PLUGIN_ROUTE_UP, NULL, NULL, es) !=3D OPENVPN_PLUGIN_FUNC_SUCCES= S)
+ if (plugi= n_call(plugins, OPENVPN_PLUGIN_ROUTE_UP, NULL, NULL, es)
+ !=3D OPENVPN_PLUGIN_FUNC_S= UCCESS)
{
msg(M_WARN,= "WARNING: route-up plugin call failed");
= }
@@ -1757,13 +1704,13 @@
#ifdef _WIN32<= /span>
if (options->show_net_up)
{
- show_routes(M_IN= FO|M_NOPREFIX);
- = show_adapters(M_INFO|M_NOPREFIX);
+ show_routes(M_INFO | M_NOPREFIX);
+ show_adapters(M_INFO | M_NOPR= EFIX);
}
else if (check_debug_lev= el(D_SHOW_NET))
{
- show_routes(D_SHOW_NET|M_NOPREFIX);
- show_adapters(D_SHOW_NET|M_N= OPREFIX);

+ sh= ow_routes(D_SHOW_NET | M_NOPREFIX);
+ show_adapters(D_SHOW_NET | M_NOPREFIX);
<= span> }

#endif
return ret;=
@@ -1775,27 +1722,19 @@
static void
do_init_tun(struct context *c)

{
- c->c1.tuntap =3D init_tun(c->opt= ions.dev,
- = c->options.dev_type,
- c->options.topology,
- = c->options.ifconfig_local,
- c->options.ifconfig_remote_netmask,=
- = c->options.ifconfig_ipv6_local,
- c->options.ifconfig_ipv6= _netbits,
- = c->options.ifconfig_ipv6_remote,
- c->c1.link_s= ocket_addrs[0].bind_local,
- c->c1.link_socket_addrs[0].remote_list,=
- = !c->options.ifconfig_nowarn,
- c->c2.es,
- &c->= net_ctx,
- = c->c1.tuntap);
+ c->c1.tuntap =3D init_tun(c->options.dev, c->opti= ons.dev_type, c->options.topology,
+ c->options.ifconfig_local,= c->options.ifconfig_remote_netmask,
+ c->options.ifconfig_ipv6= _local, c->options.ifconfig_ipv6_netbits,
+ c->options.ifconfig= _ipv6_remote, c->c1.link_socket_addrs[0].bind_local,
+ c->c1.li= nk_socket_addrs[0].remote_list, !c->options.ifconfig_nowarn,
<= span style=3D"color: hsl(120, 100%, 40%);">+ c-&= gt;c2.es, &c->net_ctx, c->c1.tuntap);

if (is_tun_afunix(c->options.dev_node))
= {
/* Using AF_UNIX trumps using DCO */
= c->c1.tuntap->backend_driver =3D DRIVER_AFUNIX;=
}
- e= lse if (is_dev_type(c->options.dev, c->options.dev_type, "null&= quot;))
+ else if = (is_dev_type(c->options.dev, c->options.dev_type, "null"))<= /span>
{
c->c1.tuntap->backend= _driver =3D DRIVER_NULL;
}
@@ -1815,9 = +1754,7 @@
}
#endif
=
- init_tun_post(c-&= gt;c1.tuntap,
- = &c->c2.frame,
- &c->options.tuntap_options);
+ init_tun_post(c->c1.tunta= p, &c->c2.frame, &c->options.tuntap_options);


c->c1.tuntap_owned =3D true;
}<= /span>
@@ -1917,10 +1854,10 @@
}
else

{
- open_tun(c->options.dev, c->options.dev_type, = c->options.dev_node,
- tt, &c->net_ctx);
+ open_tun(c->options.dev, c->options.d= ev_type, c->options.dev_node, tt, &c->net_ctx);
= }
- msg(M_INFO, = "%s device [%s] opened", print_tun_backend_driver(tt->backend_= driver), tt->actual_name);
+ msg(M_INFO, "%s device [%s] opened", print_tun_back= end_driver(tt->backend_driver),
+ tt->actual_name);
}


@@ -1959,8 +1896,7 @@
#ifdef _WIN32

/* store (hide) interactive serv= ice handle in tuntap_options */
c->c1.tuntap-&g= t;options.msg_channel =3D c->options.msg_channel;
- msg(D_ROUTE, "interactive serv= ice msg_channel=3D%" PRIuPTR,
- (intptr_t) c->options.msg_channel);
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(D_ROUTE, "inte= ractive service msg_channel=3D%" PRIuPTR, (intptr_t)c->options.msg_= channel);

#endif

= /* allocate route list structure */
@@ -1970,8 +1906,8 @@=
ASSERT(c->c2.link_sockets[0]);
if (c->options.routes && c->c1.route_list)
{
- = do_init_route_list(&c->options, c->c1.route_list,=
- = &c->c2.link_sockets[0]->info, c->c2.es, &c->net_ctx)= ;
+ do_ini= t_route_list(&c->options, c->c1.route_list, &c->c2.link_so= ckets[0]->info,
+ = c->c2.es, &c->net_ctx);
<= span> }

if (c->options.routes_ipv6 &= ;& c->c1.route_ipv6_list)
{
@@ -1980,15 +1916,12 @@

}

/* do ifconfig */
- if (!ifconfig_noexec_enabled(c)
- && ifconfig_order(c-&= gt;c1.tuntap) =3D=3D IFCONFIG_BEFORE_TUN_OPEN)
+ if (!ifconfig_noexec_enabled(c) &&am= p; ifconfig_order(c->c1.tuntap) =3D=3D IFCONFIG_BEFORE_TUN_OPEN)<= br> {
/* guess actual tun/tap un= it number that will be returned
* by open_tun= */
- const = char *guess =3D guess_tuntap_dev(c->options.dev,
- = c->options.dev_type,
- c->options.dev_= node,
- = &gc);
+ const char *guess =3D
+ guess_tuntap_dev(c->= ;options.dev, c->options.dev_type, c->options.dev_node, &gc);
do_ifconfig(c->c1.tuntap, guess, c->c2.fram= e.tun_mtu, c->c2.es, &c->net_ctx);
}

@@ -2020,31 +1953,23 @@
= }

/* do ifconfig */<= br>- if (!ifconfig_noexec_= enabled(c)
- = && ifconfig_order(c->c1.tuntap) =3D=3D IFCONFIG_AFTER_TUN_OPEN)=
+ if (!ifconf= ig_noexec_enabled(c) && ifconfig_order(c->c1.tuntap) =3D=3D IFCO= NFIG_AFTER_TUN_OPEN)
{
- do_ifconfig(c->c1.tuntap, c->c1= .tuntap->actual_name,
+ = do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name, c->c2.fr= ame.tun_mtu, c->c2.es,
+ &c->net_ctx);
= }

run_dns_up_down(true, &c-= >options, c->c1.tuntap, &c->persist.duri);

/* run the up script */
- run_up_down(c->options.up_script,
- c->= plugins,
- = OPENVPN_PLUGIN_UP,
- c->c1.tuntap->actual_name,
+ run_up_down(c->options.up_s= cript, c->plugins, OPENVPN_PLUGIN_UP, c->c1.tuntap->actual_name,
#ifdef _WIN32
c->c1= .tuntap->adapter_index,
#endif
- dev_type_string(c->opti= ons.dev, c->options.dev_type),
- c->c2.frame.tun_mtu,
+ dev_type_string(c-&= gt;options.dev, c->options.dev_type), c->c2.frame.tun_mtu,
= print_in_addr_t(c->c1.tuntap->local, IA_EM= PTY_IF_UNDEF, &gc),
- print_in_addr_t(c->c1.tuntap->remote_netmask, I= A_EMPTY_IF_UNDEF, &gc),
- "init",
- NULL,
- "up",
- c->c2.es);
+ p= rint_in_addr_t(c->c1.tuntap->remote_netmask, IA_EMPTY_IF_UNDEF, &= gc), "init",
= - msg(M_INFO, "Preserving previous TUN/TAP instance: %s",<= /span>
- c->c1.t= untap->actual_name);
+ msg(M_INFO, "Preserving previous TUN/TAP instance: %s"= ;, c->c1.tuntap->actual_name);

= /* explicitly set the ifconfig_* env vars */
= do_ifconfig_setenv(c->c1.tuntap, c->c2.es);
@@ -2072,= 21 +1996,15 @@
/* run the up script if user specif= ied --up-restart */
if (c->options.up_restart)<= /span>
{
- run_up_down(c->options.up_script,
- c->plugins,
- OP= ENVPN_PLUGIN_UP,
+ = run_up_down(c->options.up_script, c->plugins, OPENVPN_PLUGIN= _UP,
c->c1.tuntap->actual_na= me,
#ifdef _WIN32
= c->c1.tuntap->adapter_index,
#endif
- dev_type_stri= ng(c->options.dev, c->options.dev_type),

- c->c2.frame.tun_mtu,
+ = dev_type_string(c->options.dev, c->options.dev_type), c->c2.fram= e.tun_mtu,
print_in_addr_t(c->c= 1.tuntap->local, IA_EMPTY_IF_UNDEF, &gc),
= print_in_addr_t(c->c1.tuntap->remote_netmask, IA_EMPTY= _IF_UNDEF, &gc),
- = "restart",
- NULL,
- "up",

- c= ->c2.es);
+ = "restart", NULL, "up", c->c2.es);
}

add_wf= p_block(c);
@@ -2102,8 +2020,7 @@
static v= oid
do_close_tun_simple(struct context *c)
{

- msg(D_CLOSE, &= quot;Closing %s interface",
- print_tun_backend_driver(c->c1.tuntap->backend_dri= ver));
+ msg(D_CLO= SE, "Closing %s interface", print_tun_backend_driver(c->c1.tun= tap->backend_driver));

if (c->= c1.tuntap)
{
@@ -2175,26 +2092,18 @@
/* delete any routes we added */
= if (c->c1.route_list || c->c1.route_ipv6_list)
{

- = run_up_down(c->options.route_predown_script,
- c->plugins,- OPENVP= N_PLUGIN_ROUTE_PREDOWN,
+ run_up_down(c->options.route_predown_script, c->plugi= ns, OPENVPN_PLUGIN_ROUTE_PREDOWN,
= tuntap_actual,
#ifdef _WIN32
= adapter_index,
#endif
- NULL,
- c->c2.frame= .tun_mtu,
- = print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
<= span style=3D"color: hsl(0, 100%, 40%);">- print_in_= addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc),

- "init",
- = signal_description(c->sig->signal_received,
- c-&= gt;sig->signal_text),
- c->c2.es);
+ = NULL, c->c2.frame.tun_mtu, print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &am= p;gc),
+ = print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc), &qu= ot;init",
+ = signal_description(c->sig->signal_received, c->= sig->signal_text),
+ "route-pre-down", c->c2.es);<= br>
- = delete_routes(c->c1.route_list, c->c1.route_ipv6_list,
- c->c1.= tuntap, ROUTE_OPTION_FLAGS(&c->options),

- c->c2.es, &c->= ;net_ctx);
+ = delete_routes(c->c1.route_list, c->c1.route_ipv6_list, c->c1.tu= ntap,
+ = ROUTE_OPTION_FLAGS(&c->options), c->c2.es, &c->= ;net_ctx);
}

= /* actually close tun/tap device based on --down-pre flag */@@ -2205,21 +2114,13 @@

= /* Run the down script -- note that it will run at reduced
= * privilege if, for example, "--user" was used. */
- run_up_down(c->= options.down_script,
- = c->plugins,
- OPENVPN_PLUGIN_DOWN,
- tuntap_actual,+ run_up_down(c->op= tions.down_script, c->plugins, OPENVPN_PLUGIN_DOWN, tuntap_actual,
#ifdef _WIN32
adapter_inde= x,
#endif
- NULL,
- c->c2.frame.tun_mtu,
- print_in_addr_t(local, = IA_EMPTY_IF_UNDEF, &gc),
- print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDE= F, &gc),
- = "init",
- signal_description(c->sig->signal_received= ,
- = c->sig->signal_text),
- "down",
+ NULL, c->= c2.frame.tun_mtu, print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
+ print= _in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc), "init",
+ s= ignal_description(c->sig->signal_received, c->sig->signal_text)= , "down",
c->c2.es);

del_wfp_block(c, adapter_index);
@@ -2235,21 +2136,13 @@
/* run the do= wn script on this restart if --up-restart was specified */
= if (c->options.up_restart)
{- run_up_down(c->o= ptions.down_script,
- = c->plugins,
- OPENVPN_PLUGIN_DOWN,
- tuntap_actual= ,

+ run_up= _down(c->options.down_script, c->plugins, OPENVPN_PLUGIN_DOWN, tuntap= _actual,
#ifdef _WIN32
= adapter_index,
#endif
- NULL,
- c->c2.frame.tun_= mtu,
- = print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
- print_in_addr_= t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc),
- "restart",
- sig= nal_description(c->sig->signal_received,
- c->s= ig->signal_text),
- = "down",
+ NULL, c->c2.frame.tun_mtu, = print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
+ print_in_addr_t(r= emote_netmask, IA_EMPTY_IF_UNDEF, &gc), "restart",
= + signal= _description(c->sig->signal_received, c->sig->signal_text), &qu= ot;down",
c->c2.es);
}

@@ -2278,10 +2171,9= @@
* equal, or either one is all-zeroes.
*/

static bool
-options_hash_changed_or_zero(const struct sha256_digest *a,

- = const struct sha256_digest *b)
+options_hash_changed_or_zero(const struct sha256_digest *a,= const struct sha256_digest *b)
{
- const struct sha256_digest zero =3D {{0}};=
+ const struct sh= a256_digest zero =3D { { 0 } };
return memcmp(a, b, si= zeof(struct sha256_digest))
|| !memcmp(a, &= zero, sizeof(struct sha256_digest));
}
@@ = -2317,13 +2209,12 @@

if (cipher_kt_m= ode_aead(o->ciphername))
{
- buf_printf(&out, "Data Channe= l: cipher '%s'",
- cipher_kt_name(o->ciphername));
+ buf_printf(&out, &quo= t;Data Channel: cipher '%s'", cipher_kt_name(o->ciphername)= );

}
else
{<= /span>
- buf_printf(&am= p;out, "Data Channel: cipher '%s', auth '%s'",
- ciphe= r_kt_name(o->ciphername), md_kt_name(o->authname));
+ buf_printf(&out, "Da= ta Channel: cipher '%s', auth '%s'", cipher_kt_name(o-= >ciphername),
+ = md_kt_name(o->authname));
}<= br>
if (o->use_peer_id)
@@ -= 2394,8 +2285,7 @@

if (c->options.= ce.explicit_exit_notification)
{
- buf_printf(&out, "explicit= -exit-notify %d",
= - c->options.ce.explicit_exit_notification);+ buf_printf(&out, = "explicit-exit-notify %d", c->options.ce.explicit_exit_notific= ation);
}
if (c->options.impor= ted_protocol_flags)
{
@@ -2447,10 +233= 7,8 @@
#endif

struc= t tls_session *session =3D &c->c2.tls_multi->session[TM_ACTIVE];<= /span>
- if (!tls_session_u= pdate_crypto_params(c->c2.tls_multi, session,
- &c= ->options, &c->c2.frame,
- frame_fragment,
- = get_link_socket_info(c),
+ if (!tls_session_update_crypto_params(c->c2.tls= _multi, session, &c->options, &c->c2.frame,
+ = frame_fragment, get_link_socket_info(c),
= &c->c1.tuntap->dco))
{

msg(D_TLS_ERRORS, "OPTIONS ERROR: fa= iled to import crypto options");
@@ -2487,14 +2375,13 = @@
* Was tun interface object persisted from = previous restart iteration,
* and if so did p= ulled options string change from previous iteration?
= */
- = if (!c->c2.did_open_tun
- && PULL_DEFINED(&c->options)- && c-&g= t;c1.tuntap
+ = if (!c->c2.did_open_tun && PULL_DEFINED(&c->options) = && c->c1.tuntap
&& opti= ons_hash_changed_or_zero(&c->c1.pulled_options_digest_save, &c->c2.pull= ed_options_digest))
{
= /* if so, close tun, delete routes, then reinitialize tun and add = routes */
- = msg(M_INFO, "NOTE: Pulled options changed on restart, will need to= close and reopen TUN/TAP device.");
+ msg(M_INFO,
+ "NOTE: Pulled option= s changed on restart, will need to close and reopen TUN/TAP device.");=

bool tt_dco_win =3D tun= tap_is_dco_win(c->c1.tuntap);
do_close_= tun(c, true);
@@ -2520,7 +2407,8 @@
*= reconnects to setup various things (like DCO and NCP cipher) that * might have changed from the previous connection.
= */
- if = (!c->c2.do_up_ran || (c->c2.tls_multi && c->c2.tls_multi-&= gt;multi_state =3D=3D CAS_RECONNECT_PENDING))
+ if (!c->c2.do_up_ran
+ || (c->c2.tls_multi &&= c->c2.tls_multi->multi_state =3D=3D CAS_RECONNECT_PENDING)) {
if (c->mode =3D=3D MODE_POINT_TO= _POINT)
{
@@ -2568,7 +2456,8 @@
if ((route_order(c->c1.tuntap) =3D=3D ROUTE_A= FTER_TUN) && c->options.route_delay_defined)
= {
event_timeout_init(&c->= c2.route_wakeup, c->options.route_delay, now);
- event_timeout_init(&c->c= 2.route_wakeup_expire, c->options.route_delay + c->options.route_dela= y_window, now);
+ = event_timeout_init(&c->c2.route_wakeup_expire,+ = c->options.route_delay + c->options.route_delay_window, now);
tun_standby_init(c->c1.tuntap); }
else
@@= -2600,23 +2489,10 @@
unsigned int
pull_p= ermission_mask(const struct context *c)
{
- unsigned int flags =3D
<= span style=3D"color: hsl(0, 100%, 40%);">- OPT_P_UP

- | OPT_P_ROUTE_EXTRAS- | OPT_P_SOCKBUF<= br>- | OPT_P_SOCKFLAGS
- | OPT_P_SETENV
- | OPT_P_SHAPER
- | OPT_P_TIMER
- | OPT_P_COMP
- | OPT_P_PERSIST<= /span>
- | OPT_P_MESSAG= ES
- | OPT_P_EXP= LICIT_NOTIFY
- |= OPT_P_ECHO
- | = OPT_P_PULL_MODE
- = | OPT_P_PEER_ID
- = | OPT_P_NCP
- = | OPT_P_PUSH_MTU;
+= unsigned int flags =3D OPT_P_UP | OPT_P_ROUTE_EXTRAS | OPT_P_SOCKBUF | = OPT_P_SOCKFLAGS
+ = | OPT_P_SETENV | OPT_P_SHAPER | OPT_P_TIMER | OPT_P_CO= MP | OPT_P_PERSIST
+ = | OPT_P_MESSAGES | OPT_P_EXPLICIT_NOTIFY | OPT_P_EC= HO | OPT_P_PULL_MODE
= + | OPT_P_PEER_ID | OPT_P_NCP | OPT_P_PUSH_MTU;

if (!c->options.route_nopull)=
{
@@ -2638,8 +2514,8 @@

struct tls_session *session =3D &c->c2.tls_multi-= >session[TM_ACTIVE];

- const char *ncp_cipher =3D get_p2p_ncp_cipher(sessi= on, c->c2.tls_multi->peer_info,
- &c->= options.gc);
+ con= st char *ncp_cipher =3D
+ get_p2p_ncp_cipher(session, c->c2.tls_multi->peer_info, &= amp;c->options.gc);

if (ncp_ciphe= r)
{
@@ -2648,8 +2524,8 @@
<= span> else if (!c->options.enable_ncp_fallback)

= {
msg(D_TLS_ERRORS, "ERROR: failed to negoti= ate cipher with peer and "
- "--data-ciphers-fallback not enabled. No usable = "
- &qu= ot;data channel cipher");
+ "--data-ciphers-fallback not enab= led. No usable "
+ "data channel cipher");
return false;

}
@@ -2661,9 +2537,8 @@
}
#endi= f

- = if (!tls_session_update_crypto_params(c->c2.tls_multi, session, &c= ->options,
- = &c->c2.frame, frame_fragment,
- = get_link_socket_info(c),
+ if (!tls_session_update_crypto_params(c->c2.tls= _multi, session, &c->options, &c->c2.frame,
+ = frame_fragment, get_link_socket_info(c),
= &c->c1.tuntap->dco))
{

msg(D_TLS_ERRORS, "ERROR: failed to = set crypto cipher");
@@ -2680,7 +2555,7 @@
<= span> {

if (found & OPT_P_MESSAGES)
{

- init_= verb_mute(c, IVM_LEVEL_1|IVM_LEVEL_2);
+ init_verb_mute(c, IVM_LEVEL_1 | IVM_LEVEL_2);
msg(D_PUSH, "OPTIONS IMPORT: --verb and/or --mu= te level changed");
}
if (fo= und & OPT_P_TIMER)
@@ -2709,9 +2584,9 @@
if (!check_compression_settings_valid(&c->options.comp, D= _PUSH_ERRORS))

{
msg(= D_PUSH_ERRORS, "OPTIONS ERROR: server pushed compression "=
- "settin= gs that are not allowed and will result "
- "in a non-working connection.= "
- = "See also allow-compression in the manual.");
+ "= settings that are not allowed and will result "
+ "in a= non-working connection. "
+ "See also allow-compression= in the manual.");
return false; }
#ifdef USE_COMP
@@ -273= 3,8 +2608,7 @@

for (int i =3D 0;= i < c->c1.link_sockets_num; i++)
{- link_socket_update= _buffer_sizes(c->c2.link_sockets[i],
- c->options= .rcvbuf,
+ = link_socket_update_buffer_sizes(c->c2.link_sockets[i], c->options.rc= vbuf,
c->op= tions.sndbuf);
}
}
= @@ -2744,8 +2618,7 @@
msg(D_PUSH, "OPTI= ONS IMPORT: --socket-flags option modified");
= for (int i =3D 0; i < c->c1.link_sockets_num; i++)
= {
- = link_socket_update_flags(c->c2.link_sockets[i],
- c->opt= ions.sockflags);
+ = link_socket_update_flags(c->c2.link_sockets[i], c->options.s= ockflags);
}
}

@@ -2790,12 +2663,11 @@
}

/* Check if pushed options are compa= tible with DCO, if enabled */
- if (dco_enabled(&c->options)
- && !dco_check_pull_opti= ons(D_PUSH_ERRORS, &c->options))
+ if (dco_enabled(&c->options) && = !dco_check_pull_options(D_PUSH_ERRORS, &c->options))
{

msg(D_PUSH_ERRORS, "OPTIONS E= RROR: pushed options are incompatible "
- "with data channel offload. Use= --disable-dco to connect to "
- "this server");
+ "wi= th data channel offload. Use --disable-dco to connect to "
<= span style=3D"color: hsl(120, 100%, 40%);">+ = "this server");

return false;=
}
}
@@ -2808,7 +268= 0,7 @@
if (epoch_data && !datav2_enabled)
{
msg(D_PUSH_ERRORS, "OPTION= S ERROR: Epoch key data format tag requires "
- "data v2 (peer-id) to be enab= led.");
+ = "data v2 (peer-id) to be enabled."); return false;
}

@@ -2823,7 +2695,8 @@

= if (c->options.ce.tun_mtu > frame->tun_max_mtu)
{

- = msg(D_PUSH_ERRORS, "Server-pushed tun-mtu is too large, please add &= quot;
+ ms= g(D_PUSH_ERRORS,
+ = "Server-pushed tun-mtu is too large, please add "
"tun-mtu-max %d in the client configura= tion",
c->options.ce.tun_mtu);
}
@@ -2887,8 +2760,7 @@
}


/* Slow down reconnection = after 5 retries per remote -- for TCP client or UDP tls-client only */
- if (c->mode =3D=3D = CM_CHILD_TCP
- |= | (c->options.ce.proto =3D=3D PROTO_UDP && c->options.tls_cli= ent))
+ if (c->= mode =3D=3D CM_CHILD_TCP || (c->options.ce.proto =3D=3D PROTO_UDP &&= amp; c->options.tls_client))
{
= backoff =3D (c->options.unsuccessful_attempts / c->options.conne= ction_list->len) - 4;
if (backoff > 0)
@@ -2957,10 +2829,8 @@
ASSERT(o->ce.= link_mtu_defined);
/* if we have a link mtu define= d we calculate what the old code
* would have com= e up with as tun-mtu */
- size_t overhead =3D frame_calculate_protocol_header_size(&c-&= gt;c1.ks.key_type,
- = o, true);
+ size_t overhead = =3D frame_calculate_protocol_header_size(&c->c1.ks.key_type, o, true= );
mtu =3D o->ce.link_mtu - overhead;-
}<= br> else
{
@@ -3045,7 +2915,= 8 @@
size_t tailroom =3D headroom;

#ifdef USE_COMP
- msg(D_MTU_DEBUG, "MTU: adding %zu buffer tailroom for co= mpression for %zu "
+ msg(D_MTU_DEBUG,
+ "MTU: adding %zu buffer tailroom for compression for %zu= "
"bytes of payload",
COMP_EXTRA_BUFFER(payload_size), payload_size);

tailroom +=3D COMP_EXTRA_BUFFER(payload_size);

@@ -3= 114,14 +2985,11 @@
}

/* Initialize packet ID tracking */

- packet_id_init(&c->c2.crypto_options.packet_= id,
- = options->replay_window,
- options->replay_time,
+ packet_id_init(&c->c2.crypto_optio= ns.packet_id, options->replay_window, options->replay_time, "STATIC", 0);
c-&= gt;c2.crypto_options.pid_persist =3D &c->c1.pid_persist;
<= span> c->c2.crypto_options.flags |=3D CO_PACKET_ID_LONG_FORM;
=
- packet_id_persist_load_o= bj(&c->c1.pid_persist,
- &c->c2.crypto_options.packet_= id);
+ packet_id_p= ersist_load_obj(&c->c1.pid_persist, &c->c2.crypto_options.pac= ket_id);

if (!key_ctx_bi_defined(&am= p;c->c1.ks.static_key))
{
@@ -3131,= 10 +2999,8 @@

/* Read cipher and= hmac keys from shared secret file */
crypto_read_= openvpn_key(&c->c1.ks.key_type, &c->c1.ks.static_key,<= br>- = options->shared_secret_file,
- options->shared_secret_file= _inline,
- = options->key_direction, "Static Key Encryption&q= uot;,
- = "secret", NULL);
+ options->shared_s= ecret_file, options->shared_secret_file_inline,
+ options->= key_direction, "Static Key Encryption", "secret", NULL)= ;
}
else
{
@@ -3162,26 +3028,23 @@
c->c1.ks= .tls_auth_key_type.digest =3D options->authname;
= if (!md_valid(options->authname))
{- msg(M_FATAL, "= ERROR: tls-auth enabled, but no valid --auth "
- "algorithm specified (= '%s')", options->authname);
+ msg(M_FATAL,
+ "ERROR: tls-auth enabled,= but no valid --auth "
+ "algorithm specified ('%s')",
+ options= ->authname);
}

- crypto_read_openvpn_key(&= ;c->c1.ks.tls_auth_key_type,

- &c->c1.ks.tls_wrap_key,
- = options->ce.tls_auth_file,
- options->ce.tls_auth_fil= e_inline,
- = options->ce.key_direction,
- "Control C= hannel Authentication", "tls-auth",
- &c->c1.= ks.original_wrap_keydata);
+ crypto_read_openvpn_key(&c->c1.ks.tls_auth_key_type, = &c->c1.ks.tls_wrap_key,
+ options->ce.tls_auth_file, op= tions->ce.tls_auth_file_inline,
+ options->ce.key_direction= , "Control Channel Authentication",
+ "tls-auth&qu= ot;, &c->c1.ks.original_wrap_keydata);
}=

/* TLS handshake encryption+authentication= (--tls-crypt) */
if (options->ce.tls_crypt_file)
{
-= tls_crypt_init_key(&c->c1.ks.tls_wrap_key,
- &c->c= 1.ks.original_wrap_keydata,
- options->ce.tls_crypt_file,
<= span style=3D"color: hsl(0, 100%, 40%);">- option= s->ce.tls_crypt_file_inline,

+ tls_crypt_init_key(&c->c1.ks.tls_wrap_key, &= c->c1.ks.original_wrap_keydata,
+ options->ce.tls_crypt_file, op= tions->ce.tls_crypt_file_inline,
= options->tls_server);
}

@@ -3190,16 +3053,14 @@
{
= if (options->tls_server)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- tls_crypt_v2_init_ser= ver_key(&c->c1.ks.tls_crypt_v2_server_key,

- true, = options->ce.tls_crypt_v2_file,
+ tls_crypt_v2_init_server_key(&c->c1.ks.tls= _crypt_v2_server_key, true,
+ options->ce.tls_crypt_v= 2_file,
options-&= gt;ce.tls_crypt_v2_file_inline);
}
else

{
- tls_crypt_v2_init_client_key(&c->c1.= ks.tls_wrap_key,
- = &c->c1.ks.original_wrap_keydata,=
- = &c->c1.ks.tls_crypt_v2_wkc,
- o= ptions->ce.tls_crypt_v2_file,
+ tls_crypt_v2_init_client_key(&c->c1.ks.tls_= wrap_key, &c->c1.ks.original_wrap_keydata,
+ &= ;c->c1.ks.tls_crypt_v2_wkc, options->ce.tls_crypt_v2_file,
= options->ce.tls_crypt_v2= _file_inline);
}
/* We ha= ve to ensure that the loaded tls-crypt key is small enough
= @@ -3211,15 +3072,14 @@

if (requ= ired_size > c->options.ce.tls_mtu)
{<= br>- msg(M_WARN, "= ;ERROR: tls-crypt-v2 client key too large to work with "
+ msg(M_WARN,
+ "ERROR: = tls-crypt-v2 client key too large to work with "
= "requested --max-packet-size %d, requires at least "<= /span>
"--max-packet-size %d. Packets will i= gnore requested "
= - "maximum packet size", c->options.ce.tls_mtu,=
- requi= red_size);
+ = "maximum packet size",
+ c->options.ce.tls_mtu, required_size= );
}
}
-
-
}

/*=
@@ -3248,7 +3108,7 @@

= case AR_INTERACT:
ssl_purge_au= th(false);
- = /* Intentional [[fallthrough]]; */
+ /* Intentional [[fallthrough]]; */<= /span>

case AR_NOINTERACT:
/* SOFT-SIGUSR1 -- Password failure error = */
@@ -3289,8 +3149,7 @@

= /* Do not warn if the cipher is used only in OCC */
bool warn =3D options->enable_ncp_fallback;

- init_key_type(&c->c1.ks.= key_type, ciphername, options->authname,
- true, warn);
+ init_key_type(&c->c1.ks= .key_type, ciphername, options->authname, true, warn);
=
/* initialize tls-auth/crypt/crypt-v2 key */
do_init_tls_wrap_key(c);
@@ -3298,8 +3= 157,7 @@
/* initialise auth-token crypto support *= /
if (c->options.auth_token_generate) {
- = auth_token_init_secret(&c->c1.ks.auth_token_key,
<= span style=3D"color: hsl(0, 100%, 40%);">- = c->options.auth_token_secret_file,

+ auth_token_init_secret(&c->c1.ks.aut= h_token_key, c->options.auth_token_secret_file,
= c->options.auth_token_secret_file_inline);
}

@@ -3377,25 +32= 35,27 @@
if (options->renegotiate_seconds_min < = 0)
{
/* Add 10% jitter to ren= eg-sec by default (server side only) */
- int auto_jitter =3D options->mode !=3D MODE_SE= RVER ? 0 :
- = get_random() % max_int(options->renegotiate_seconds / 10,= 1);
+ int aut= o_jitter =3D options->mode !=3D MODE_SERVER
+ ? 0
+ : ge= t_random() % max_int(options->renegotiate_seconds / 10, 1);

to.renegotiate_seconds =3D options->renegotiate_seconds - a= uto_jitter;

}
else
{

/* Add user-specified jitter to reneg-sec= */
- to.renegot= iate_seconds =3D options->renegotiate_seconds
- -(get_random() = % max_int(options->renegotiate_seconds
- = - options->renegotiate_seconds_min, 1));
+ to.renegotiate_seconds =3D
+ options->renegotia= te_seconds

+ = - (get_random()
+ = % max_int(options->renegotiate_seconds - options->reneg= otiate_seconds_min, 1));
}
to.sin= gle_session =3D options->single_session;
to.mode = =3D options->mode;
to.pull =3D options->pull;
- if (options->push= _peer_info) /* all there is */
+ if (options->push_peer_info) /* all there is */
{
to.push_peer_info_detail =3D = 3;
}
- else if (options->pull) /* pull clients send some de= tails */
+ else if= (options->pull) /* pull clients send some details */
= {
to.push_peer_info_detail =3D 2;
}

@@ -3403,7 +3263,7 @@
{
to.push_peer_info_detail =3D 0;
}=
- else = /* default: minimal info to allow NCP in P2P mode */
+ else /* default: minimal info to = allow NCP in P2P mode */
{
to= .push_peer_info_detail =3D 1;
}
@@ -35= 06,8 +3366,7 @@
}

= /* TLS handshake encryption (--tls-crypt) */
- if (options->ce.tls_crypt_file
<= span style=3D"color: hsl(0, 100%, 40%);">- || (options->ce.tls_cr= ypt_v2_file && options->tls_client))

+ if (options->ce.tls_crypt_file || (optio= ns->ce.tls_crypt_v2_file && options->tls_client))
<= span> {

to.tls_wrap.mode =3D TLS_WRAP_CRYPT;
}
@@ -3565,10 +3424,8 @@
if (c->c2.tls_multi)

{
= tls_multi_init_finalize(c->c2.tls_multi, c->options.ce.tls_mtu);<= /span>
- ASSERT(c->c= 2.tls_multi->opt.frame.buf.payload_size <=3D
- c->c2.frame.buf.payload_size= );
- frame_print= (&c->c2.tls_multi->opt.frame, D_MTU_INFO,
- "Control Channel M= TU parms");
+ = ASSERT(c->c2.tls_multi->opt.frame.buf.payload_size <=3D c->= ;c2.frame.buf.payload_size);
+ frame_print(&c->c2.tls_multi->opt.frame, D_MTU_I= NFO, "Control Channel MTU parms");

/* Keep the max mtu also in the frame of tls multi so it can a= ccess

* it in push_peer_info */
@= @ -3576,9 +3433,9 @@
}
if (c->= c2.tls_auth_standalone)
{
- tls_init_control_channel_frame_parameters(= &c->c2.tls_auth_standalone->frame, c->options.ce.tls_mtu);
- frame_print(&= c->c2.tls_auth_standalone->frame, D_MTU_INFO,
- "TLS-Auth MTU parm= s");
+ tl= s_init_control_channel_frame_parameters(&c->c2.tls_auth_standalone-&= gt;frame,
+ = c->options.ce.tls_mtu);+ frame_print(&c-&= gt;c2.tls_auth_standalone->frame, D_MTU_INFO, "TLS-Auth MTU parms&q= uot;);
c->c2.tls_auth_standalone->tls_wrap.w= ork =3D alloc_buf_gc(BUF_SIZE(&c->c2.frame), &c->c2.gc);
c->c2.tls_auth_standalone->workbuf =3D alloc_buf= _gc(BUF_SIZE(&c->c2.frame), &c->c2.gc);
= }
@@ -3594,14 +3451,12 @@

/* Initialise key_type with auth/cipher "none", so the key_= type struct is

* valid */
- init_key_type(&c->c1.ks.key_type, &quo= t;none", "none",
- c->options.test_crypto, true);
+ init_key_type(&c->c1.k= s.key_type, "none", "none", c->options.test_crypto, = true);


- = "******* WARNING *******: All encryption and authentication featu= res "
- &qu= ot;disabled -- All data will be tunnelled as clear text and will not be &qu= ot;
- "prot= ected against man-in-the-middle changes. "
- "PLEASE DO RECONSIDER THIS CONFIGURA= TION!");
+ ms= g(M_WARN, "******* WARNING *******: All encryption and authentication = features "
+ = "disabled -- All data will be tunnelled as clear text and = will not be "
+ = "protected against man-in-the-middle changes. "
+ "= PLEASE DO RECONSIDER THIS CONFIGURATION!");
}<= br>
static void
@@ -3615,7 +3470,7 = @@
{
do_init_crypto_tls(c, fl= ags);
}
- else /* no encryption or authentication. = */
+ else /* no en= cryption or authentication. */
{
= do_init_crypto_none(c);
}
@@ -3653= ,7 +3508,8 @@
#ifdef ENABLE_FRAGMENT
= if (c->options.ce.fragment > 0 && c->options.ce.mssfix >= ; c->options.ce.fragment)
{
- msg(M_WARN, "WARNING: if you u= se --mssfix and --fragment, you should "
+ msg(M_WARN,
+ "WARNING: if you use --mssfix an= d --fragment, you should "
"set --fr= agment (%d) larger or equal than --mssfix (%d)",
= c->options.ce.fragment, c->options.ce.mssfix);
}

@@ -3661,7 +3517,7 @@
&am= p;& c->options.ce.fragment_encap !=3D c->options.ce.mssfix_encap)=
{
msg(M_WARN, "WARNING:= if you use --mssfix and --fragment, you should "
- "use the \"mtu\"= ; flag for both or none of of them.");
+ "use the \"mtu\"= flag for both or none of of them.");
} #endif
}
@@ -3680,34 +3536,39 @@
#ifdef ENABLE_SELINUX
|| o->sel= inux_context
#endif
- )
+ )
{
if (!o->persi= st_tun)
{
- msg(M_WARN, "WARNING: you are using user/grou= p/chroot/setcon without persist-tun -- this may cause restarts to fail"= ;);
+ msg(= M_WARN,
+ = "WARNING: you are using user/group/chroot/setcon without persist-t= un -- this may cause restarts to fail");
}
}

if (o->chroo= t_dir && !(o->username && o->groupname))
{

- msg= (M_WARN, "WARNING: you are using chroot without specifying user and gr= oup -- this may cause the chroot jail to be insecure");
+ msg(M_WARN,

+ "WARNING: you are= using chroot without specifying user and group -- this may cause the chroo= t jail to be insecure");

}

if (o->pull && o->ifconfig_local && = c->first_time)
{
- msg(M_WARN, "WARNING: using --pull/--client= and --ifconfig together is probably not what you want");
+ msg(M_WARN,

+ "WARNING: using= --pull/--client and --ifconfig together is probably not what you want"= ;);

}

if (o->= ;server_bridge_defined || o->server_bridge_proxy_dhcp)
= {
- msg(M_WA= RN, "NOTE: when bridging your LAN adapter with the TAP adapter, note t= hat the new bridge adapter will often take on its own IP address that is di= fferent from what the LAN adapter was previously set to");
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(M_WARN,

<= span style=3D"color: hsl(120, 100%, 40%);">+ "NOTE: when br= idging your LAN adapter with the TAP adapter, note that the new bridge adap= ter will often take on its own IP address that is different from what the L= AN adapter was previously set to");

}
<= span>

if (o->mode =3D=3D MODE_SERVER)
{

if (o->duplicate_cn && o->= ;client_config_dir)
{
- msg(M_WARN, "WARNING: using --dup= licate-cn and --client-config-dir together is probably not what you want&qu= ot;);
+ ms= g(M_WARN,
+ = "WARNING: using --duplicate-cn and --client-config-dir together = is probably not what you want");
}
= if (o->duplicate_cn && o->ifconfig_pool_persis= t_filename)
{
@@ -3723,14 +3584,12= @@
{
warn_on_use_of_common_s= ubnets(&c->net_ctx);
}
- if (o->tls_client
- && !o->tls_verify=
- && o->ver= ify_x509_type =3D=3D VERIFY_X509_NONE
- && !(o->ns_cert_type & NS_CERT_CHECK= _SERVER)
- &= & !o->remote_cert_eku
+ if (o->tls_client && !o->tls_verify && o= ->verify_x509_type =3D=3D VERIFY_X509_NONE
+ && !(o->ns_cert_type & NS_= CERT_CHECK_SERVER) && !o->remote_cert_eku
= && !(o->verify_hash_depth =3D=3D 0 && o->verify_ha= sh))
{
- msg(M_WARN, "WARNING: No server certificate verification= method has been enabled. See http://openvpn.net/howto.html#mitm for more = info.");
+ = msg(M_WARN,
+ = "WARNING: No server certificate verification method has been ena= bled. See http://openvpn.net/howto.html#mitm for more info.");=
}
if (o->ns_cert_type)
{

@@ -3742,15 +3601,19 @@
{
if (script_security() >=3D SSEC_SCRIPTS) {
- = msg(M_WARN, "NOTE: the current --script-security setting may = allow this configuration to call user-defined scripts");
+ msg(M_WARN,
+ "NOTE: t= he current --script-security setting may allow this configuration to call u= ser-defined scripts");
}
= else if (script_security() >=3D SSEC_PW_ENV)
= {
- msg(M= _WARN, "WARNING: the current --script-security setting may allow passw= ords to be passed to scripts via environmental variables");
= + msg(M_WARN,=
+ "WARN= ING: the current --script-security setting may allow passwords to be passed= to scripts via environmental variables");
}<= /span>
else
{
- msg(M_WARN, "NOTE: star= ting with " PACKAGE_NAME " 2.1, '--script-security 2' or = higher is required to call user-defined scripts or executables");
+ msg(M_WARN,<= /span>
+ &quo= t;NOTE: starting with " PACKAGE_NAME
+ " 2.1, '--script-security 2&= #39; or higher is required to call user-defined scripts or executables"= ;);
}
}
}
@@ -3829,8 +3692,8 @@
*/
c->c2.frame_fragment =3D c->c2.frame;

=
- frame_calculate_dynamic(= &c->c2.frame_fragment, &c->c1.ks.key_type,
- &c->o= ptions, get_link_socket_info(c));
+ frame_calculate_dynamic(&c->c2.frame_fragment, &am= p;c->c1.ks.key_type, &c->options,
+ get_link_socket_info(c)= );
fragment_frame_init(c->c2.fragment, &c->c= 2.frame_fragment);
}
#endif
@@ -3843,8 +3706,7 @@

{
ASSERT(!c-= >c2.link_sockets);

- ALLOC_ARRAY_GC(c->c2.link_sockets, struct link_soc= ket *,
- = c->c1.link_sockets_num, &c->c2.gc);
+ ALLOC_ARRAY_GC(c->c2.link_sockets, str= uct link_socket *, c->c1.link_sockets_num, &c->c2.gc);
=
for (int i =3D 0; i < c->c1.link_sockets= _num; i++)
{
@@ -3907,8 +3769,7 @@
#ifdef ENABLE_FRAGMENT
if (c->c2.frag= ment)
{
- frame_print(&c->c2.frame_fragment, D_MTU_INFO,=
- "Fr= agmentation MTU parms");
+ frame_print(&c->c2.frame_fragment, D_MTU_INFO, &qu= ot;Fragmentation MTU parms");
}
= #endif
}
@@ -3922,23 +3783,18 @@ struct gc_arena gc =3D gc_new();

c->c2.options_string_local =3D

- options_string(&c->options, &c->= c2.frame, c->c1.tuntap, &c->net_ctx,
- false, &gc);
= + options_string(&c-= >options, &c->c2.frame, c->c1.tuntap, &c->net_ctx, fals= e, &gc);
c->c2.options_string_remote =3D=
- options_string(&= c->options, &c->c2.frame, c->c1.tuntap, &c->net_ctx,
- t= rue, &gc);
+ = options_string(&c->options, &c->c2.frame, c->c1.tuntap,= &c->net_ctx, true, &gc);

= msg(D_SHOW_OCC, "Local Options String (VER=3D%s): '%s'",=
- options_strin= g_version(c->c2.options_string_local, &gc),
- c->c2.options_string_local);=
+ options_string_ver= sion(c->c2.options_string_local, &gc), c->c2.options_string_local= );
msg(D_SHOW_OCC, "Expected Remote Options Strin= g (VER=3D%s): '%s'",
- options_string_version(c->c2.options_string_remote, = &gc),
- c-&g= t;c2.options_string_remote);
+ options_string_version(c->c2.options_string_remote, &am= p;gc), c->c2.options_string_remote);

= if (c->c2.tls_multi)
{
- tls_multi_init_set_options(c->c2.tl= s_multi,
- = c->c2.options_string_local,
+ tls_multi_init_set_options(c->= c2.tls_multi, c->c2.options_string_local,
= c->c2.options_string_remote);
= }

@@ -3962,10 +3818,8 @@

/* get user and/or group that we want to setuid= /setgid to,
* sets also platform_x_state */
- bool group_defined = =3D platform_group_get(c->options.groupname,
- = &c0->platform_state_group);
- bool user_defined =3D platform_user_get(c->options= .username,
- = &c0->platform_state_user);=
+ bool group_defined= =3D platform_group_get(c->options.groupname, &c0->platform_state= _group);
+ boo= l user_defined =3D platform_user_get(c->options.username, &c0->pl= atform_state_user);

c0->uid_g= id_specified =3D user_defined || group_defined;
@@ -4074,16 +3928,13 @@
* reconnect to the sam= e host again or there are still addresses that need
*= to be tried */
if (!(c->sig->signal_received = =3D=3D SIGUSR1
- = && ( (c->options.persist_remote_ip)
- ||
- ( c->sig->source !=3D SIG_SOUR= CE_HARD
- = && ((c->c1.link_socket_addrs[0].current_remote
- && c-&= gt;c1.link_socket_addrs[0].current_remote->ai_next)

- || c->options.no_a= dvance))
- = )))
+ &= ;& ((c->options.persist_remote_ip)
+ || (c->sig->source !=3D SIG_SOURC= E_HARD
+ = && ((c->c1.link_socket_addrs[0].current_remote
+ &&= ; c->c1.link_socket_addrs[0].current_remote->ai_next)

+ || c->opti= ons.no_advance)))))

{
- clear_remote_addrlist(&c->c1.link_socke= t_addrs[0],
- = !c->options.resolve_in_advance);
+ clear_remote_addrlist(&c-&g= t;c1.link_socket_addrs[0], !c->options.resolve_in_advance);
}


/* Clear the remote actua= l address when persist_remote_ip is not in use */
@@ -4099,= 8 +3950,7 @@
{
for (int i =3D= 0; i < c->c1.link_sockets_num; i++)
{
- if (c->c1.li= nk_socket_addrs[i].bind_local
- && !c->options.resolve_in_advance)
+ if (c->c1.= link_socket_addrs[i].bind_local && !c->options.resolve_in_advanc= e)
{
freeaddr= info(c->c1.link_socket_addrs[i].bind_local);
= }
@@ -4144,8 +3994,7 @@
*/

static void
-do_event_set_init(struct context *c,
- bool need_us_timeout)<= br>+do_event_set_init(struct co= ntext *c, bool need_us_timeout)
{
uns= igned int flags =3D 0;

@@ -4182,11 +4031,= 9 @@
{
if (!c->c1.status_output)
{
-= c->c1.status_output =3D status_open(c->options.status_file,
- = c->options.status_file_update_freq,
- = -1,
- = NULL,
- STATUS_OUTPUT_WRITE);<= /span>
+ c->c1.sta= tus_output =3D
+ = status_open(c->options.status_file, c->options.status_file_upd= ate_freq, -1, NULL,
+= STATUS_OUTPUT_WRITE);
c-&g= t;c1.status_output_owned =3D true;
}
= }
@@ -4213,8 +4060,9 @@
{
= if (!c->c1.ifconfig_pool_persist && c->options.ifconfig_= pool_persist_filename)
{
- c->c1.ifconfig_pool_persist =3D ifconfig= _pool_persist_init(c->options.ifconfig_pool_persist_filename,
= - = c->options.ifconfig_pool_persist_refres= h_freq);
+ c-&= gt;c1.ifconfig_pool_persist =3D
+ ifconfig_pool_persist_init(c->options.ifconfig_p= ool_persist_filename,
+ c->options.ifconfig_pool_persis= t_refresh_freq);
c->c1.ifconfig_pool_persist_ow= ned =3D true;
}
}
@@ = -4328,12 +4176,9 @@
unsigned int optio= n_types_found =3D 0;
if (config.list[i= ] && config.list[i]->value)
= {
- = options_string_import(&c->options,
- conf= ig.list[i]->value,
-= D_IMPORT_ERRORS|M_OPTERR,
- = OPT_P_DEFAULT & ~OPT_P_PLUGIN,
- = &option_types_found,
- c->es);
= + option= s_string_import(
+ = &c->options, config.list[i]->value, D_IM= PORT_ERRORS | M_OPTERR,
+ OPT_P_DEFAULT & ~OPT_P_PLUGIN, &opt= ion_types_found, c->es);
} }
}
@= @ -4374,7 +4219,7 @@
static void
manageme= nt_callback_status_p2p(void *arg, const int version, struct status_output *= so)
{
= - struct context *c =3D (struct context *) arg;
+ struct context *c =3D (struct context *)= arg;
print_status(c, so);
}
@@ -4407,7 +4252,7 @@
*/

int socketfd =3D -1;
- struct context *c =3D (struct contex= t *) arg;
+ struct= context *c =3D (struct context *)arg;
if (!c->c2.l= ink_sockets || !c->c2.link_sockets[0])
{
= return -1;
@@ -4488,24 +4333,14 @@ {
flags |=3D MF_SERVER= ;
}
- if (management_open(management,
- c->opti= ons.management_addr,
- = c->options.management_port,
- c-&= gt;options.management_user_pass,

- c->options.management_client_= user,
- = c->options.management_client_group,
- c->opti= ons.management_log_history_cache,
- c->options.management_echo_b= uffer_size,
- = c->options.management_state_buffer_size,- = c->options.remap_sigusr1,
- flags))
+ if (management_open(
+ management, c-= >options.management_addr, c->options.management_port,

+ c->options.m= anagement_user_pass, c->options.management_client_user,

+ c->options.ma= nagement_client_group, c->options.management_log_history_cache,+ c->op= tions.management_echo_buffer_size, c->options.management_state_buffer_si= ze,
+ = c->options.remap_sigusr1, flags))
{
- managemen= t_set_state(management,
- OPENVPN_STATE_CONNECTING,
= - = NULL,
- = NULL,
- NULL,
- NULL,<= /span>
+ mana= gement_set_state(management, OPENVPN_STATE_CONNECTING, NULL, NULL, NULL, NU= LL,
NULL);
= }

@@ -4884,9 +4719,7 @= @
/* close event objects */
do_cl= ose_event_set(c);

- if (c->mode =3D=3D CM_P2P
- || c->mode =3D=3D CM_CHILD_TCP- || c->mode =3D=3D C= M_CHILD_UDP
+ if (= c->mode =3D=3D CM_P2P || c->mode =3D=3D CM_CHILD_TCP || c->mode = =3D=3D CM_CHILD_UDP
|| c->mode =3D=3D CM_TOP)
{
#ifdef USE_COMP
@@ -= 4954,9 +4787,7 @@
}

voi= d
-inherit_context_chil= d(struct context *dest,
- const struct context *src,
- struct link_socket *sock= )
+inherit_context_ch= ild(struct context *dest, const struct context *src, struct link_socket *so= ck)
{
CLEAR(*dest);
=
@@ -5044,8 +4875,7 @@
}
=
void
= -inherit_context_top(struct context *dest,
- const struct context *src)<= br>+inherit_context_top(struct = context *dest, const struct context *src)
{
/* copy parent */

*dest =3D *src;
@@ -5173,7 +5003,7 @@

static void *
te= st_crypto_thread(void *arg)
{
- struct context *c =3D (struct context *) arg;<= /span>
+ struct context *= c =3D (struct context *)arg;
const struct options *opt= ions =3D &c->options;

ASSERT(= options->test_crypto);
@@ -5207,7 +5037,7 @@
<= span> c.options =3D *o;

options_detach(&am= p;c.options);
c.first_time =3D true;
- test_crypto_thread((void *)= &c);

+ te= st_crypto_thread((void *)&c);
return true;
}
return false;
diff= --git a/src/openvpn/init.h b/src/openvpn/init.h
index 5c6b= 9c1..a650de6 100644
--- a/src/openvpn/init.h
+++ b/src/openvpn/init.h

@@ -46,8 +46,8 @@

void uninit_static(void);

= -#define IVM_LEVEL_1 (1<<0)=
-#define IVM_LEVEL_2 (= 1<<1)
+#define = IVM_LEVEL_1 (1 << 0)
+#define IVM_LEVEL_2 (1 << 1)
void init_verb_m= ute(struct context *c, unsigned int flags);

void init_options_dev(struct options *options);

@@ -62,= 7 +62,8 @@

void pre_setup(const struct o= ptions *options);

-void init_instance_handle_signals(struct context *c, const st= ruct env_set *env, const unsigned int flags);
+void init_instance_handle_signals(struct context = *c, const struct env_set *env,
+ const unsigned int flags);

void init_instance(struct context *c, const= struct env_set *env, const unsigned int flags);
@@ -73,8 +74,7 @@

bool do_route(= const struct options *options, struct route_list *route_list,
struct route_ipv6_list *route_ipv6_list, const struct tun= tap *tt,

- = const struct plugin_list *plugins, struct env_set *es,
- openvpn_net_ctx_t *ctx);
+ const st= ruct plugin_list *plugins, struct env_set *es, openvpn_net_ctx_t *ctx);

void close_instance(struct context *c);

@@ -82,9 +82,7 @@
void context_gc_free(struct context *c);
<= br>-bool do_up(struct context *c,=
- bool pulle= d_options,
- = unsigned int option_types_found);
+bool do_up(struct context *c, bool pulled_options, unsigned i= nt option_types_found);

unsigned int pul= l_permission_mask(const struct context *c);

@@ -94,17 +92,15 @@


bool do_deferred_= options(struct context *c, const unsigned int found);

-void inherit_context_chil= d(struct context *dest,
- const struct context *src,
+void inherit_context_child(struct conte= xt *dest, const struct context *src,
= struct link_socket *sock);

-void inherit_context_top(struct context *dest,=
- = const struct context *src);
+void inherit_context_top(struct context *dest, const struct con= text *src);

-#define CC_GC_FREE (1<<0)
-#define CC_USR1_TO_HUP (1<<1)<= br>-#define CC_HARD_USR1_TO_HUP (= 1<<2)
-#define CC= _NO_CLOSE (1<<3)
+#define CC_GC_FREE (1 << 0)
+#define CC_USR1_TO_HUP (1 << 1= )
+#define CC_HARD_US= R1_TO_HUP (1 << 2)
+#define CC_NO_CLOSE (1 << 3)
void close_context(struct context *c, int sig, unsigned int flags);=

@@ -112,9 +108,9 @@

void free_context_buffers(struct context_buffers *b);=

-#define IS= C_ERRORS (1<<0)
-= #define ISC_SERVER (1<<1)
-#define ISC_ROUTE_ERRORS (1<<2)
+#define ISC_ERRORS (1 << 0)<= br>+#define ISC_SERVER (1= << 1)
+#define= ISC_ROUTE_ERRORS (1 << 2)
void initialization_seque= nce_completed(struct context *c, const unsigned int flags);

#ifdef ENABLE_MANAGEMENT
diff --git a/s= rc/openvpn/integer.h b/src/openvpn/integer.h
index c568036.= .e1f7950 100644
--- a/src/openvpn/integer.h
+++ b/src/openvpn/integer.h

@@ -27,13 +27,17 @@
= #include "error.h"

#ifn= def htonll
-#define hto= nll(x) ((1=3D=3Dhtonl(1)) ? (x) : \
- ((uint64_t)htonl((uint32_t)((x) & 0xFF= FFFFFF)) << 32) | htonl((uint32_t)((x) >> 32)))
+#define htonll(x) \

+ ((1 =3D=3D htonl(1)) \
+ ? (x) \

+ : ((uint64_t)= htonl((uint32_t)((x) & 0xFFFFFFFF)) << 32) | htonl((uint32_t)((x)= >> 32)))
#endif

= #ifndef ntohll
-#define= ntohll(x) ((1=3D=3Dntohl(1)) ? (x) : \
- ((uint64_t)ntohl((uint32_t)((x) & = 0xFFFFFFFF)) << 32) | ntohl((uint32_t)((x) >> 32)))
<= span style=3D"color: hsl(120, 100%, 40%);">+#define ntohll(x) \
+ ((1 =3D=3D ntohl(1)) \
+ ? (x) = \
+ : ((uint6= 4_t)ntohl((uint32_t)((x) & 0xFFFFFFFF)) << 32) | ntohl((uint32_t)= ((x) >> 32)))
#endif

static inline int

@@ -197,10 +201,7 @@
= if (index < 0 || index >=3D size)
{<= br> msg(M_FATAL, "Assertion Failed: Array index=3D%d out= of bounds for array size=3D%d in %s:%d",
- index,
- size,
- file,
- line);
+ index, size, file, line);
}
return index;
}
diff -= -git a/src/openvpn/interval.c b/src/openvpn/interval.c
inde= x f1abeee..35c1382 100644
--- a/src/openvpn/interval.c
+++ b/src/openvpn/interval.c
@@ -40,9 +40,7 @@<= /span>
}

bool
-event_timeout_trigger(struct event_tim= eout *et,
- = struct timeval *tv,
- const int et_const_retry)
+event_timeout_trigger(struct event_time= out *et, struct timeval *tv, const int et_const_retry)
{
if (!et->defined)
{
<= span>@@ -55,8 +53,7 @@

if (wakeup <=3D 0) {
#if INTERVAL_DEBUG
- dmsg(D_INTERVAL, "EVENT event_time= out_trigger (%d) etcr=3D%d", et->n,
- et_const_retry);
+ dmsg(D_INTERVAL, "EVENT even= t_timeout_trigger (%d) etcr=3D%d", et->n, et_const_retry); #endif
if (et_const_retry < 0)<= br> {
@@ -73,8 +70,8 @@
= if (tv && wakeup < tv->tv_sec)
{<= br> #if INTERVAL_DEBUG
- dmsg(D_INTERVAL, "EVENT event_timeout_wakeup (%d/%d) et= cr=3D%d",
- = (int) wakeup, et->n, et_const_retry);
+ dmsg(D_INTERVAL, "EVENT event_timeo= ut_wakeup (%d/%d) etcr=3D%d", (int)wakeup, et->n,
+ et_const_retry);<= br> #endif
tv->tv_sec =3D wakeup;<= br> tv->tv_usec =3D 0;
diff --git a/src/op= envpn/interval.h b/src/openvpn/interval.h
index 60030fd..d2= 473e4 100644
--- a/src/openvpn/interval.h
+= ++ b/src/openvpn/interval.h
@@ -75,8 +75,7 @@
}


if (top->last_action + = top->horizon > local_now
- || top->last_test_true + top->refresh <=3D local_= now
- || trigger= )
+ || top->= ;last_test_true + top->refresh <=3D local_now || trigger)
<= span> {

top->last_test_true =3D local_now;<= /span>
#if INTERVAL_DEBUG
@@ -135,9 +134,9 @@

struct event_timeout
{
- bool defined; /= **< This timeout is active */
- interval_t n; /**< periodic interval for periodic t= imeouts */
- time_t = last; /**< time of last event */
+ bool defined; /**< This timeout is active */<= /span>
+ interval_t n; /*= *< periodic interval for periodic timeouts */
+ time_t last; /**< time of last event *= /
};

static inline bool=
@@ -218,7 +217,7 @@
static inline interva= l_t
event_timeout_remaining(struct event_timeout *et)
{
- ret= urn (interval_t) ((et->last + et->n) - now);
+ return (interval_t)((et->last + et-&g= t;n) - now);
}

#define = ETT_DEFAULT (-1)
@@ -255,19 +254,18 @@
* = @param et_const_retry see above
* @return = if the timeout has triggered and event has been reset
= */
-bool event_timeou= t_trigger(struct event_timeout *et,
- struct timeval *tv,
- int et_co= nst_retry);

+bool eve= nt_timeout_trigger(struct event_timeout *et, struct timeval *tv, int et_con= st_retry);

/*
* Measur= e time intervals in microseconds
*/

-#define USEC_TIMER_MAX = 60 /* maximum interval size in seconds */
+#define USEC_TIMER_MAX 60 /* maximum interval size= in seconds */

#define USEC_TIMER_MAX_US= EC (USEC_TIMER_MAX * 1000000)

-struct usec_timer {
+struct usec_timer
+{
struct timeval start;=
struct timeval end;
};
diff= --git a/src/openvpn/list.c b/src/openvpn/list.c
index 1f33= b5f..3baaafd 100644
--- a/src/openvpn/list.c
+++ b/src/openvpn/list.c

@@ -35,8 +35,7 @@
#include "memdbg.h"


struct = hash *
-hash_init(const= int n_buckets,
- = const uint32_t iv,
= - h->n_buckets =3D (int) adjust_power_of_2(n_buckets);
+ h->n_buckets =3D (int)adjus= t_power_of_2(n_buckets);

h->mask =3D h->n_bucket= s - 1;
h->hash_function =3D hash_function; h->compare_function =3D compare_function;
@= @ -80,10 +79,7 @@
}

str= uct hash_element *
-has= h_lookup_fast(struct hash *hash,
- struct hash_bucket *bucket,
- const void *key,<= br>- uint32_t hv)=
+hash_lookup_fast(st= ruct hash *hash, struct hash_bucket *bucket, const void *key, uint32_t hv)<= /span>
{
struct hash_element *he;
= struct hash_element *prev =3D NULL;
@@ -111,10 += 107,7 @@
}

bool<= br>-hash_remove_fast(struct hash = *hash,
- = struct hash_bucket *bucket,
- const void *key,
- uint32_t hv)
+hash_remove_fast(struct hash *hash, struct ha= sh_bucket *bucket, const void *key, uint32_t hv)
{<= br> struct hash_element *he;
struct hash_ele= ment *prev =3D NULL;
@@ -220,9 +213,7 @@
}=

void
-hash_iterator_init_range(struct hash *hash,
- struct ha= sh_iterator *hi,

- = int start_bucket,
+hash_iterator_init_range(struct hash *hash, struct hash_i= terator *hi, int start_bucket,
in= t end_bucket)
{
if (end_bucket > h= ash->n_buckets)
@@ -243,8 +234,7 @@
}

void
-hash_iterator_init(struct hash *hash,
- struct hash_iterator *h= i)
+hash_iterator_ini= t(struct hash *hash, struct hash_iterator *hi)
{ hash_iterator_init_range(hash, hi, 0, hash->n_buckets);
}
@@ -391,17 +381,35 @@
* --= ------------------------------------------------------------------ */

-#define mix(a, b, c) \
- { \
- a -=3D b; a -=3D c; a ^=3D= (c>>13); \

- = b -=3D c; b -=3D a; b ^=3D (a<<8); \
- c -=3D a; c -=3D b; c ^=3D (b>>13= ); \
- a -=3D b= ; a -=3D c; a ^=3D (c>>12); \
- b -=3D c; b -=3D a; b ^=3D (a<<16); \<= br>- c -=3D a; c -=3D b; c= ^=3D (b>>5); \
- a -=3D b; a -=3D c; a ^=3D (c>>3); \
- b -=3D c; b -=3D a; b ^=3D (a<&= lt;10); \
- c -= =3D a; c -=3D b; c ^=3D (b>>15); \
+#define mix(a, b, c) \
+ { \
+ a -=3D b; \
+ a -=3D c; \
+ a ^=3D (c >>= ; 13); \
+ b -= =3D c; \
+ = b -=3D a; \
+ b ^=3D (a << 8); \
+ c -=3D a; \
+ c -=3D b; \
+ c ^=3D (b >> 13); \=
+ a -=3D b; = \
+ a -=3D c; = \
+ a = ^=3D (c >> 12); \
+ b -=3D c; \
+ b -=3D a; \
+ b ^=3D (a << 16); \
+ c -=3D a; \
+ c -=3D b; \
+ c ^=3D (b >>= ; 5); \
+ a -= =3D b; \
+ = a -=3D c; \
+ a ^=3D (c >> 3); \
+ b -=3D c; \
+ b -=3D a; \
+ b ^=3D (a << 10); \=
+ c -=3D a; = \
+ c -=3D b; = \
+ c = ^=3D (b >> 15); \
}

= uint32_t
@@ -411,21 +419,15 @@

/* Set up the internal state */
len = =3D length;
- a =3D = b =3D 0x9e3779b9; /* the golden ratio; an arbitrary value */- c =3D initval; = /* the previous hash value */
+ a =3D b =3D 0x9e3779b9; /* the golden ratio; an arbitrary val= ue */
+ c =3D init= val; /* the previous hash value */

/*---------------------------------------- handle most of the key */<= /span>
while (len >=3D 12)
{- a +=3D (k[0] + ((uint3= 2_t) k[1] << 8)
-= + ((uint32_t) k[2] << 16)
- + ((uint32_t) k[3] << 24));

- b +=3D (k[4] + ((= uint32_t) k[5] << 8)
- + ((uint32_t) k[6] << 16)
- + ((uint32_t) k[7] << 24))= ;
- c +=3D (k[8]= + ((uint32_t) k[9] << 8)
- + ((uint32_t) k[10] << 16)
- + ((uint32_t) k[11] <&l= t; 24));
+ a += =3D (k[0] + ((uint32_t)k[1] << 8) + ((uint32_t)k[2] << 16) + ((= uint32_t)k[3] << 24));
+ b +=3D (k[4] + ((uint32_t)k[5] << 8) + ((uint32_t)k[= 6] << 16) + ((uint32_t)k[7] << 24));
+ c +=3D (k[8] + ((uint32_t)k[9] <<= ; 8) + ((uint32_t)k[10] << 16) + ((uint32_t)k[11] << 24));
mix(a, b, c);
k +=3D 12;
len -=3D 12;
@@ -433,48 +435,48 @@

/*-------------------------------------= handle the last 11 bytes */
c +=3D length;
= - switch (len) /* a= ll the case statements fall through */
+ switch (len) /* all the case statements fall through= */
{
case 11:
- c +=3D ((uint32_t) k[10]= << 24);

- = /* Intentional [[fallthrough]]; */
+ c +=3D ((uint32_t)k[10] << 24);+ /* Intentional [[= fallthrough]]; */

case 10:
- c +=3D ((uint32= _t) k[9] << 16);
= - /* Intentional [[fallthrough]]; */
+ c +=3D ((uint32_t)k[9] << 16);
+ /* Intenti= onal [[fallthrough]]; */

case 9:=
- c +=3D ((= uint32_t) k[8] << 8);
+ c +=3D ((uint32_t)k[8] << 8);
= /* Intentional [[fallthrough]]; */

= /* the first byte of c is reserved for the length */
case 8:

- = b +=3D ((uint32_t) k[7] << 24);
- /* Intentional [[fallthrough]]; */=
+ b +=3D ((uint3= 2_t)k[7] << 24);
- b +=3D ((uint32_t) k[6] << 16);
- /* Intentional [[fallthrough]]; */<= /span>
+ b +=3D (= (uint32_t)k[6] << 16);
+ /* Intentional [[fallthrough]]; */

case 6:
- b +=3D ((uint32_t) k[5] << 8);
- /* Intentional [[fallthrough]]= ; */
+ b += =3D ((uint32_t)k[5] << 8);
+ /* Intentional [[fallthrough]]; */

case 5:
b +=3D k[4= ];
- /* Intentio= nal [[fallthrough]]; */
+ /* Intentional [[fallthrough]]; */
=
case 4:
- a +=3D ((uint32_t) k[3] << 24);
- /* Intentional [[fallthrough]]; */=
+ a +=3D = ((uint32_t)k[3] << 24);
+ /* Intentional [[fallthrough]]; */
<= /span>
case 3:
- a +=3D ((uint32_t) k[2] << 16);
- /* Intentional [[fallthrough= ]]; */

+ a= +=3D ((uint32_t)k[2] << 16);
+ /* Intentional [[fallthrough]]; */

case 2:
- a +=3D ((uint32_t) k[1] << 8);- /* Intentional [[fallth= rough]]; */
+ = a +=3D ((uint32_t)k[1] << 8);
+ /* Intentional [[fallthrough]]; */
case 1:
a += =3D k[0];
diff --git a/src/openvpn/list.h b/src/openvpn/lis= t.h
index 783570f..678e817 100644
--- a/src= /openvpn/list.h
+++ b/src/openvpn/list.h
@@= -37,8 +37,8 @@
#include "basic.h"
#include "buffer.h"


-#define hashsize(n) ((uint32_t)1<<(n)= )
-#define hashmask(n) = (hashsize(n)-1)
+#def= ine hashsize(n) ((uint32_t)1 << (n))
+#define hashmask(n) (hashsize(n) - 1)

struct hash_element
{
@@ -64,8 +64,7 @@

struct hash_bucket *buckets;=
};

-struct hash *hash_init(const int n_buckets,
- const uint32_t iv,
+struct hash *hash_ini= t(const int n_buckets, const uint32_t iv,
= uint32_t (*hash_function)(const void *key, uint32_t iv),
<= span> bool (*compare_function)(const void *key1, con= st void *key2));


@@ -73,15 +72,10 @@

bool hash_add(struct hash *hash, const void = *key, void *value, bool replace);

-struct hash_element *hash_lookup_fast(struc= t hash *hash,
- = struct hash_bucket *bucket,
- c= onst void *key,
- = uint32_t hv);
+struct hash_element *hash_lookup_fast(struct hash= *hash, struct hash_bucket *bucket,
+ const void *key, uint= 32_t hv);

-bool hash_remove_fast(struct hash *hash,
- struct hash_bucket *bucket,<= /span>
- = const void *key,
- = uint32_t hv);
+bool hash_remove_fast(struct hash *hash, struct hash_bucket *buc= ket, const void *key, uint32_t hv);

void= hash_remove_by_value(struct hash *hash, void *value);

@@ -97,9 +91,7 @@
int bucket_index_end;<= /span>
};

-void hash_iterator_init_range(struct hash *hash,
= - st= ruct hash_iterator *hi,
- int start_bucket,
+void hash_iterator_init_range(struct hash *ha= sh, struct hash_iterator *hi, int start_bucket,
= int end_bucket);

voi= d hash_iterator_init(struct hash *hash, struct hash_iterator *iter);=
@@ -155,10 +147,7 @@

/* NOTE: = assumes that key is not a duplicate */
static inline void<= /span>
-hash_add_fast(struct h= ash *hash,
- = struct hash_bucket *bucket,
- const void *key,
- uint32_t hv,
+hash_add_fast(struct hash *hash, struct hash_bucke= t *bucket, const void *key, uint32_t hv,
voi= d *value)
{
struct hash_element *he;<= /span>
diff --git a/src/openvpn/lladdr.c b/src/openvpn/lladdr.c
index cc677b4..d8bcad9 100644
--- a/src/openv= pn/lladdr.c
+++ b/src/openvpn/lladdr.c
@@ -= 14,8 +14,7 @@
#include "proto.h"

int
-set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr= ,
- const str= uct env_set *es)
+set= _lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr, con= st struct env_set *es)
{
int r;

@@ -32,27 +31,16 @@
#else /* = if defined(TARGET_LINUX) */
struct argv argv =3D argv_= new();
#if defined(TARGET_SOLARIS)
- argv_printf(&argv,
- "%s %s ether %s&q= uot;,
- = IFCONFIG_PATH,
- = ifname, lladdr);
+ argv_printf(&argv, "%s %s ether %s", IFCONFIG_PATH,= ifname, lladdr);
#elif defined(TARGET_OPENBSD)
= - argv_printf(&argv,
- "%s %s= lladdr %s",
- = IFCONFIG_PATH,
- ifname, lladdr);
+ argv_printf(&argv, "%s %s lladdr %s", I= FCONFIG_PATH, ifname, lladdr);
#elif defined(TARGET_DARWIN= )
- argv_printf(&= ;argv,
- = "%s %s lladdr %s",
- IFCONFIG_PATH,
- ifname, lladdr);
+ argv_printf(&argv, "%s %s lladdr= %s", IFCONFIG_PATH, ifname, lladdr);
#elif defined(T= ARGET_FREEBSD)
- arg= v_printf(&argv,
- = "%s %s ether %s",
- IFCONFIG_PATH,
- ifname, lladdr);
+ argv_printf(&argv, "= %s %s ether %s", IFCONFIG_PATH, ifname, lladdr);

#els= e /* if defined(TARGET_SOLARIS) */
- msg(M_WARN, "Sorry, but I don't know how to conf= igure link layer addresses on this operating system.");
+ msg(M_WARN,

+ "Sorry, but I don't k= now how to configure link layer addresses on this operating system.");=
return -1;
#endif /* if defined(TARG= ET_SOLARIS) */
argv_msg(M_INFO, &argv);
= diff --git a/src/openvpn/lzo.c b/src/openvpn/lzo.c
in= dex 01db221..a8649f8 100644
--- a/src/openvpn/lzo.c<= br>+++ b/src/openvpn/lzo.c
@@ -51,9 +51,10 @@<= br> int lzo_status =3D lzo_init();
if (lzo_s= tatus !=3D LZO_E_OK)
{
- msg(M_FATAL, "Cannot initialize LZO comp= ression library (lzo_init() returns %d)", lzo_status);
+ msg(M_FATAL, "Cannot i= nitialize LZO compression library (lzo_init() returns %d)",

= + lzo_status);
}
- = compctx->wu.lzo.wmem =3D (lzo_voidp) malloc(compctx->wu.lzo.wmem_size= );
+ compctx->w= u.lzo.wmem =3D (lzo_voidp)malloc(compctx->wu.lzo.wmem_size);
<= span> check_malloc_return(compctx->wu.lzo.wmem);

}<= /span>

@@ -65,8 +66,7 @@
}

static void
-lzo_compress(struct buffer *buf, struct buffer work,
- struct com= press_context *compctx,
+lzo_compress(struct buffer *buf, struct buffer work, struct compress_co= ntext *compctx,
const struct frame *frame)
{
uint8_t *header =3D buf_prepend(buf, = 1);
@@ -74,13 +74,12 @@
}
=
static void
-lzo_decompress(struct buffer *buf, struct buffer work,
<= span style=3D"color: hsl(0, 100%, 40%);">- struct compress_co= ntext *compctx,

+lzo_= decompress(struct buffer *buf, struct buffer work, struct compress_context = *compctx,
const struct frame *frame)=
{
lzo_uint zlen =3D frame->buf.payload_s= ize;
int err;
- uint8_t c; /* flag indicating whether or not our = peer compressed */
+ = uint8_t c; /* flag indicating whether or not our peer compressed */

if (buf->len <=3D 0)
{

@@ -95,8 +94,7 @@
if (c =3D= =3D LZO_COMPRESS_BYTE) /* packet was compressed */
{
ASSERT(buf_safe(&work, zlen));
- err =3D LZO_DECOMPRESS(BPTR(bu= f), BLEN(buf), BPTR(&work), &zlen,
- compctx->wu.lzo.wmem);=
+ err =3D LZO= _DECOMPRESS(BPTR(buf), BLEN(buf), BPTR(&work), &zlen, compctx->w= u.lzo.wmem);
if (err !=3D LZO_E_OK)
{

dmsg(D_COMP_ERRORS, "LZO dec= ompression error: %d", err);
@@ -113,7 +111,7 @@

*buf =3D work;
}=
- else if (c =3D=3D= NO_COMPRESS_BYTE) /* packet was not compressed */
+ else if (c =3D=3D NO_COMPRESS_BYTE) = /* packet was not compressed */
{
= /* nothing to do */
}
@@ -124,11 = +122,6 @@
}
}

-const struct compress_alg l= zo_alg =3D {
- "= ;lzo",
- lzo_co= mpress_init,
- lzo_c= ompress_uninit,
- lz= o_compress,
- lzo_de= compress
-};
= +const struct compress_alg lzo_= alg =3D { "lzo", lzo_compress_init, lzo_compress_uninit, lzo_comp= ress,
+ = lzo_decompress };
#endif /* ENABLE= _LZO */
diff --git a/src/openvpn/lzo.h b/src/openvpn/lzo.h<= /span>
index 03da2af..d5bab54 100644
--- a/src/ope= nvpn/lzo.h
+++ b/src/openvpn/lzo.h
@@ -57,1= 9 +57,19 @@
extern const struct compress_alg lzo_alg;

/*******************************************= *******************************/
-/** @name LZO library interface defines *//** @{ *//************= ***********/
-#define L= ZO_COMPRESS lzo1x_1_15_compress
+/** @name LZO library interface defines */ /** @{ */ /******= *****************/
+#= define LZO_COMPRESS lzo1x_1_15_compress
/**< LZO libr= ary compression function.
*
* Use \c = lzo1x_1_15_compress because it
* is described as faster= than the
* standard routine, although it does * need a bit more memory. */
-#define LZO_WORKSPACE LZO1X_1_15_MEM_COMPRESS+#define LZO_WORKSPACE LZO1X= _1_15_MEM_COMPRESS
/**< The size in bytes of the memory=
* %buffer required by the LZO library
= * compression algorithm. */
-#define LZO_DECOMPRESS lzo1x_decompress_safe
+#define LZO_DECOMPRESS lzo1x_decompress= _safe
/**< LZO library decompression function. *
* Use safe decompress because it
= @@ -79,26 +79,30 @@
* verify the integrity of inc= oming
* packets, you might want to consider
<= span> * using the non-safe version. */

-/** @} name LZO library interface *//******************= ********************/
+/** @} name LZO library interface */ /***********************************= ***/


/****************= **********************************************************/
-/** @name Adaptive compression define= s *//** @{ *//************************/

-#define AC_SAMP_SEC 2 /**< Number of seconds= in a sample period. */
-#define AC_MIN_BYTES 1000 /**< Minimum number of bytes a sample<= /span>
- = * period must contain for it to be
- * evaluated. *= /
-#define AC_SAVE_PCT = 5 /**< Minimum size reduction percentage
- * below = which compression will be
- * turned off. */
-#define AC_OFF_SEC 60 /**< S= econds to wait after compression has
- * been turned off before = retesting. */
-/** @} n= ame Adaptive compression defines *//*******************************/=
+/** @name Adaptive compres= sion defines */ /** @{ */ /************************/
+#define AC_SAMP_SEC 2 = /**< Number of seconds in a sample period. */
+#define AC_MIN_BYTES = \

+ 1000 = /**< Minimum number of bytes a sample \
+ = * period must contain for it to be \
+ = * evaluated. */
+#define AC_SAVE_PCT = \
+ 5 /**< Minimum= size reduction percentage \
+ * below whi= ch compression will be \
+ * turned off.= */
+#define AC_OFF_S= EC = \
+ 60 = /**< Seconds to wait after compres= sion has \
+ = * been turned off before rete= sting. */
+/** @} nam= e Adaptive compression defines */ /*******************************/=

/**
* Adaptive compre= ssion state.
*/
-struct lzo_adaptive_compress {
+struct lzo_adaptive_compress
+{
bool compress_stat= e;
time_t next;
int n_total;
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c=
index 8836e79..40dcd62 100644
--- a/src/openvpn/m= anage.c
+++ b/src/openvpn/manage.c
@@ -75,7= +75,8 @@
msg(M_CLIENT, "auth-retry t := Auth failure retry mode (none,interact,nointeract).");
msg(M_CLIENT, "bytecount n : Show bytes in/out, upda= te every n secs (0=3Doff).");

msg(M_CLIENT, "= ;echo [on|off] [N|all] : Like log, but only show messages in echo buffer.&= quot;);
- msg(M_CLIE= NT, "cr-response response : Send a challenge response answer via CR_= RESPONSE to server");
+ msg(M_CLIENT,
+ "cr-response response : Send a challenge response answe= r via CR_RESPONSE to server");
msg(M_CLIENT, &quo= t;exit|quit : Close management session.");
msg(M_CLIENT, "forget-passwords : Forget passwords entere= d so far.");

msg(M_CLIENT, "help = : Print this message.");
@@ -86,7 +87,8 @@
msg(M_CLIENT, "load-stats : Show global s= erver load stats.");
msg(M_CLIENT, "log [on|= off] [N|all] : Turn on/off realtime log display");
= msg(M_CLIENT, " + show last N lines or = 9;all' for entire history.");
- msg(M_CLIENT, "mute [n] : Set log m= ute level to n, or show level if n is absent.");
+ msg(M_CLIENT,
+ "mute [n] : Se= t log mute level to n, or show level if n is absent.");
msg(M_CLIENT, "needok type action : Enter confirmation for = NEED-OK request of 'type',");

msg(M_CLIEN= T, " where action =3D 'ok' or 'can= cel'.");
msg(M_CLIENT, "needstr type act= ion : Enter confirmation for NEED-STR request of 'type',");=
@@ -104,18 +106,25 @@
#endif
msg(M_CLIENT, "client-auth CID KID : Authenticate client-i= d/key-id CID/KID (MULTILINE)");

msg(M_CLIENT, &qu= ot;client-auth-nt CID KID : Authenticate client-id/key-id CID/KID");
- msg(M_CLIENT, "= ;client-deny CID KID R [CR] : Deny auth client-id/key-id CID/KID with log r= eason");
+ ms= g(M_CLIENT,
+ = "client-deny CID KID R [CR] : Deny auth client-id/key-id CID/KID with = log reason");
msg(M_CLIENT, " = text R and optional client reason text CR");
<= span style=3D"color: hsl(0, 100%, 40%);">- msg(M_CLIENT, "client-pe= nding-auth CID KID MSG timeout : Instruct OpenVPN to send AUTH_PENDING and = INFO_PRE msg");

- = msg(M_CLIENT, " to the client = and wait for a final client-auth/client-deny");
+ msg(M_CLIENT,
+ "client-pending-auth CID KID= MSG timeout : Instruct OpenVPN to send AUTH_PENDING and INFO_PRE msg"= );
+ msg(M_CLIENT,=
+ " = to the client and wait for a final client-= auth/client-deny");
msg(M_CLIENT, "client-ki= ll CID [M] : Kill client instance CID with message M (def=3DRESTART)&quo= t;);
msg(M_CLIENT, "env-filter [level] : Set = env-var filter level");
msg(M_CLIENT, "rsa-s= ig : Enter a signature in response to >RSA_SIGN challenge= ");
- msg(M_CLI= ENT, " Enter signature base64 on subsequent li= nes followed by END");
+ msg(M_CLIENT,
+ " Enter signature base64 on subs= equent lines followed by END");
msg(M_CLIENT, &qu= ot;pk-sig : Enter a signature in response to >PK_SIGN ch= allenge");
- ms= g(M_CLIENT, " Enter signature base64 on subseq= uent lines followed by END");
- msg(M_CLIENT, "certificate : Enter a clien= t certificate in response to >NEED-CERT challenge");
- msg(M_CLIENT, " = Enter certificate base64 on subsequent lines followed by END&q= uot;);

+ msg(M_CLI= ENT,
+ " = Enter signature base64 on subsequent lines followed= by END");
+ = msg(M_CLIENT,
+ = "certificate : Enter a client certificate in response to = >NEED-CERT challenge");
+ msg(M_CLIENT,
+ " Enter certificate base64 o= n subsequent lines followed by END");
msg(M_CLIEN= T, "signal s : Send signal s to daemon,"); msg(M_CLIENT, " s =3D SIGHUP|SIGT= ERM|SIGUSR1|SIGUSR2.");
msg(M_CLIENT, "state= [on|off] [N|all] : Like log, but show state history.");
@@ -123,7 +132,8 @@

msg(M_CLIENT, "test n = : Produce n lines of output for testing/debugging.");
msg(M_CLIENT, "username type u : Enter usernam= e u for a queried OpenVPN username.");
msg(M_CLIE= NT, "verb [n] : Set log verbosity level to n, or show if= n is absent.");
-= msg(M_CLIENT, "version [n] : Set client's version t= o n or show current version of daemon.");
+ msg(M_CLIENT,
+ "version [n] : Set client&= #39;s version to n or show current version of daemon.");
msg(M_CLIENT, "END");

}
=
@@ -306,7 +316,7 @@
man_delete_unix_sock= et(struct management *man)
{
#if UNIX_SOC= K_SUPPORT
- if ((man= ->settings.flags & (MF_UNIX_SOCK|MF_CONNECT_AS_CLIENT)) =3D=3D MF_UN= IX_SOCK)
+ if ((ma= n->settings.flags & (MF_UNIX_SOCK | MF_CONNECT_AS_CLIENT)) =3D=3D MF= _UNIX_SOCK)
{
socket_delete_u= nix(&man->settings.local_unix);
}
@@ -332,11 +342,11 @@

static void
virt= ual_output_callback_func(void *arg, const unsigned int flags, const char *s= tr)
{
= - struct management *man =3D (struct management *) arg;
+ struct management *man =3D (stru= ct management *)arg;
static int recursive_level =3D 0;= /* GLOBAL */

-#define AF_DID_PUSH (1<<0)
-#define AF_DID_RESET (1<<1)
+#define AF_DID_PUSH (1 << 0)
+#define AF_DID_RESET (1= << 1)
if (recursive_level < 5) /* limit recu= rsion */
{
struct gc_arena gc= =3D gc_new();
@@ -370,10 +380,10 @@
= }
else if (man->connection.log_realt= ime)
{
- out =3D log_entry_print(&e, LOG_PRINT_INT= _DATE
- = | LOG_PRINT_MSG_FLAGS
- | LOG_PRINT= _LOG_PREFIX
- = | LOG_PRINT_CRLF, &gc);
+ out =3D log_entry_pri= nt(&e,
+ = LOG_PRINT_INT_DATE | LOG_PRINT_MSG_FLAGS
+ = | LOG_PRINT_LOG_PREFIX | LOG_PRINT_CRLF,
+ = &gc);
}
if (= out)
{
@@ -382,11 +392,11 @@
}
if (flags & = M_FATAL)
{
- out =3D log_entry_print(&e, LOG_FATAL= _NOTIFY|LOG_PRINT_CRLF, &gc);
+ out =3D log_entry_print(&e, LOG_FATAL_NOT= IFY | LOG_PRINT_CRLF, &gc);
if (out)
{
man_= output_list_push_str(man, out);
- action_flags |=3D (AF_DID_PUSH|AF_DID_RESET);=
+ = action_flags |=3D (AF_DID_PUSH | AF_DID_RESET);
= }
}
}@@ -408,7 +418,8 @@
{
= /* cannot use msg here */
printf("virtual_ou= tput: message to management interface "
- "dropped due to recursion: <%= s>\n", str);
= + "dropped due to recursion: <%s>\n",<= br>+ str);=
}
}

@@ -4= 72,7 +483,8 @@
static void
man_command_un= supported(const char *command_name)
{
- msg(M_CLIENT, "ERROR: The '%s= ' command is not supported by the current daemon mode", command_na= me);
+ msg(M_CLIEN= T, "ERROR: The '%s' command is not supported by the current da= emon mode",
+ = command_name);
}

s= tatic void
@@ -495,8 +507,7 @@
{
man->connection.bytecount_update_seconds =3D update_= seconds;
event_timeout_init(&man->connectio= n.bytecount_update_interval,
- man->connection.bytecount_update_secon= ds,
- = now);
+ = man->connection.bytecount_update_seconds, now);
}
else
{
@@ -507,8 +518,7 @@
}
<= br> static void
-= man_bytecount_output_client(struct management *man,
- counter_type dc= o_read_bytes,
+man_by= tecount_output_client(struct management *man, counter_type dco_read_bytes,<= /span>
counter_type dco_write_bytes)<= /span>
{
char in[32];
@@ -52= 1,8 +531,7 @@
}

void
-man_bytecount_output_ser= ver(const counter_type *bytes_in_total,
- const counter_type *bytes_out= _total,
+man_bytecoun= t_output_server(const counter_type *bytes_in_total, const counter_type *byt= es_out_total,
struct man_def_a= uth_context *mdac)
{
char in[32];
@@ -547,7 +556,7 @@
char p3[128];
int n_killed;

- buf_set_read(&buf, (uint8_t *) = victim, strlen(victim) + 1);
+ buf_set_read(&buf, (uint8_t *)victim, strlen(victim) += 1);
buf_parse(&buf, ':', p1, sizeof(p= 1));
buf_parse(&buf, ':', p2, sizeof(p= 2));
buf_parse(&buf, ':', p3, sizeof(p= 3));
@@ -556,29 +565,29 @@
{
/* IP:port specified */
= bool status;
- = const in_addr_t addr =3D getaddr(GETADDR_HOST_ORDER|GETADDR_MSG_VIRT_O= UT, p2, 0, &status, NULL);
+ const in_addr_t addr =3D
+ getaddr(GETADDR_HOST_ORDER | GE= TADDR_MSG_VIRT_OUT, p2, 0, &status, NULL);
= if (status)
{
= const int port =3D atoi(p3);
- const int proto =3D (streq(p1, "tcp")) ?= PROTO_TCP_SERVER :
- = (streq(p1, "udp")) ? PROTO_UDP : = PROTO_NONE;
+ = const int proto =3D (streq(p1, "tcp")) ? PROTO_TCP_SERV= ER
+ = : (streq(p1, "udp")) ? PROTO_UDP
+ = : PROTO_NONE;


= if ((port > 0 && port < 65536) && (proto != =3D PROTO_NONE))
{
- n_killed =3D (*man->= persist.callback.kill_by_addr)(man->persist.callback.arg, addr, port, pr= oto);
+ = n_killed =3D (*man->persist.callback.kill_by_addr)(man->persist= .callback.arg,
+ = addr, port,= proto);
if (n_killed > 0) {
- msg(M_CLIENT, "SUCCESS: %d client(s) = at address %s:%s:%d killed",
- n_killed,
- proto2ascii(proto, = AF_UNSPEC, false),
- = print_in_addr_t(addr, 0, &gc),
+ msg(M_CLIEN= T, "SUCCESS: %d client(s) at address %s:%s:%d killed", n_killed,<= /span>
+ = proto2ascii(proto, AF_UNSPEC, false), print_in_addr_t(addr, 0, &= ;gc),
port);
= }
else
<= span> {

msg(M_= CLIENT, "ERROR: client at address %s:%s:%d not found",
= - prot= o2ascii(proto, AF_UNSPEC, false),
- print_in_addr_t(addr, 0, &gc),<= /span>
+ = proto2ascii(proto, AF_UNSPEC, false), print_in_addr_t(addr, 0, &= ;gc),
port);
= }
}
@@= -623,12 +632,8 @@
* for the log and echo commands.
*/
static void
-man_history(struct management *man,
- const char *parm,- const char *type,<= /span>
- struct log= _history *log,
- = bool *realtime,
- = const unsigned int lep_flags)
+man_history(struct management *man, const char *parm, = const char *type, struct log_history *log,
+ bool *realtime, const unsigned int lep_f= lags)
{
struct gc_arena gc =3D gc_new= ();
int n =3D 0;
@@ -671,35 +676,22 @@=
static void
man_log(struct management *m= an, const char *parm)
{
- man_history(man,
- parm,
- "log",
- man->persist.log,- &man->co= nnection.log_realtime,
= - LOG_PRINT_INT_DATE|LOG_PRINT_MSG_FLAGS);
+ man_history(man, parm, "log&= quot;, man->persist.log, &man->connection.log_realtime,+ LOG_PRINT_INT= _DATE | LOG_PRINT_MSG_FLAGS);
}
static void
man_echo(struct management *man, cons= t char *parm)
{
- man_history(man,
- parm,
- "echo",
- man->persist.echo,
- &man->connecti= on.echo_realtime,

- = LOG_PRINT_INT_DATE|MANAGEMENT_ECHO_FLAGS);
+ man_history(man, parm, "echo&qu= ot;, man->persist.echo, &man->connection.echo_realtime,+ LOG_PRINT_INT= _DATE | MANAGEMENT_ECHO_FLAGS);
}
=
static void
man_state(struct management *man, c= onst char *parm)
{
- man_history(man,
- parm,
- "state",
- man->persist.state,
= - &man->con= nection.state_realtime,
- LOG_PRINT_INT_DATE|LOG_PRINT_STATE
- |LOG_PRINT_LOCAL_IP|LOG_PRI= NT_REMOTE_IP);
+ m= an_history(man, parm, "state", man->persist.state, &man-&g= t;connection.state_realtime,
+ LOG_PRINT_INT_DATE | LOG_PRINT_STATE | LOG_PRINT_L= OCAL_IP | LOG_PRINT_REMOTE_IP);
}
=
static void
@@ -733,13 +725,8 @@
}


static void
-man_query_user_pass(struct management *man,
- cons= t char *type,
- = const char *string,
- const bool needed,
- const char *prompt,- char *dest= ,
- = int len)
+man_query_u= ser_pass(struct management *man, const char *type, const char *string, cons= t bool needed,
+ = const char *prompt, char *dest, int len)
{<= /span>
if (needed)
{
@@ = -748,16 +735,12 @@
{
= strncpynt(dest, string, len);
man_up_finalize(= man);
- msg(= M_CLIENT, "SUCCESS: '%s' %s entered, but not yet verified"= ;,
- typ= e,
- pro= mpt);
+ ms= g(M_CLIENT, "SUCCESS: '%s' %s entered, but not yet verified&qu= ot;, type, prompt);
}
els= e
{
- msg(M_CLIENT, "ERROR: %s of type '%s' enter= ed, but we need one of type '%s'",
- prompt,
- type,
- man->connection.up_query_typ= e);
+ msg(= M_CLIENT, "ERROR: %s of type '%s' entered, but we need one of = type '%s'", prompt,
+ type, man->connection.up_query_type);
}
}
else
@@ -769,36 +752,42 @@
static void
man_query_username(struct management *man, const char *type, const cha= r *string)

{
- const bool needed =3D ((man->connection.up_query_mode =3D=3D= UP_QUERY_USER_PASS
- = ) && man->connection.up_query_type);
- man_query_user_pass(m= an, type, string, needed, "username", man->connection.up_query= .username, USER_PASS_LEN);
+ const bool needed =3D
+ ((man->connection.up_query_mode =3D=3D UP_QUERY_USE= R_PASS) && man->connection.up_query_type);
+ man_query_user_pass(man, type, string= , needed, "username", man->connection.up_query.username,
+ U= SER_PASS_LEN);
}

static= void
man_query_password(struct management *man, const cha= r *type, const char *string)
{
const = bool needed =3D ((man->connection.up_query_mode =3D=3D UP_QUERY_PASS
- = || man->connection.up_query_mode =3D=3D UP_QUERY_USER_PASS
- ) &&= amp; man->connection.up_query_type);

+ || man->connection.up_quer= y_mode =3D=3D UP_QUERY_USER_PASS)
+ && man->connection.up_que= ry_type);
if (!string[0]) /* allow blank passwords to = be passed through using the blank_up tag */
{ string =3D blank_up;
}
- man_query_user_pass(man, type, s= tring, needed, "password", man->connection.up_query.password, = USER_PASS_LEN);

+ = man_query_user_pass(man, type, string, needed, "password", man-&g= t;connection.up_query.password,
+ USER_PASS_LEN);
}

static void
man_query_need_= ok(struct management *man, const char *type, const char *action)
= {
- const boo= l needed =3D ((man->connection.up_query_mode =3D=3D UP_QUERY_NEED_OK) &a= mp;& man->connection.up_query_type);
- man_query_user_pass(man, type, action, needed, &q= uot;needok-confirmation", man->connection.up_query.password, USER_P= ASS_LEN);
+ const = bool needed =3D
+ = ((man->connection.up_query_mode =3D=3D UP_QUERY_NEED_OK) && = man->connection.up_query_type);
+ man_query_user_pass(man, type, action, needed, "nee= dok-confirmation",
+ man->connection.up_query.password, USER_PASS= _LEN);
}

static void
man_query_need_str(struct management *man, const char *type,= const char *action)
{
- const bool needed =3D ((man->connection.up_query_m= ode =3D=3D UP_QUERY_NEED_STR) && man->connection.up_query_type);=
- man_query_user_pa= ss(man, type, action, needed, "needstr-string", man->connectio= n.up_query.password, USER_PASS_LEN);
+ const bool needed =3D
+ ((man->connection.up_query_mode =3D=3D UP= _QUERY_NEED_STR) && man->connection.up_query_type);
+ man_query_user_pass(man, typ= e, action, needed, "needstr-string",

+ man->connection.up_qu= ery.password, USER_PASS_LEN);
}
static void
@@ -827,8 +816,8 @@
{=
if (man->persist.callback.send_cc_message)<= br> {
- = const bool status =3D (*man->persist.callback.send_cc_message)<= br>- = (man->persist.callback.arg, message, parameters);
+ const bool status =3D (*man->= ;persist.callback.send_cc_message)(man->persist.callback.arg,
= + = message, parameters);
if (status)

{
= msg(M_CLIENT, "SUCCESS: command succeeded");
= @@ -893,13 +882,12 @@
{
ASSERT(p1);

- i= f (man->persist.callback.remote_entry_get
- && man->persist.callback.remote_e= ntry_count)
+ if (= man->persist.callback.remote_entry_get && man->persist.callba= ck.remote_entry_count)
{
unsi= gned int count =3D (*man->persist.callback.remote_entry_count)(man->p= ersist.callback.arg);

- unsigned int from =3D (unsigned int) atoi(p1);
- unsigned int to = =3D p2 ? (unsigned int) atoi(p2) : from + 1;
+ unsigned int from =3D (unsigned int)atoi(p= 1);
+ unsigned= int to =3D p2 ? (unsigned int)atoi(p2) : from + 1;

if (!strcmp(p1, "all"))
= {
@@ -910,7 +898,8 @@
for (uns= igned int i =3D from; i < min_uint(to, count); i++)
= {
char *remote =3D NULL;
- bool res =3D (*man->per= sist.callback.remote_entry_get)(man->persist.callback.arg, i, &remot= e);
+ bool= res =3D
+ = (*man->persist.callback.remote_entry_get)(man->persist.callback.= arg, i, &remote);
if (res && remot= e)
{
msg(M_CL= IENT, "%u,%s", i, remote);
@@ -956,8 +945,8 @@
}
}

-#define IER_RESET 0
-#define IER_NEW 1

<= span style=3D"color: hsl(120, 100%, 40%);">+#define IER_RESET 0

<= span style=3D"color: hsl(120, 100%, 40%);">+#define IER_NEW 1

<= span>

static void
in_extra_reset(struct = man_connection *mc, const int mode)
@@ -990,14 +979,9 @@
case IEC_CLIENT_AUTH:
i= f (man->persist.callback.client_auth)
{
- const boo= l status =3D (*man->persist.callback.client_auth)
- (ma= n->persist.callback.arg,
- man->connection.in_extra_c= id,
- = man->connection.in_extra_kid,
- tr= ue,
- = NULL,
- NULL,
- man= ->connection.in_extra);
+ const bool status =3D (*man->persist.callback.cli= ent_auth)(
+ = man->persist.callback.arg, man->connection.in_extra_cid,
+ m= an->connection.in_extra_kid, true, NULL, NULL, man->connection.in_ext= ra);
man->connection.in_extra =3D NULL;=
report_command_status(status, "clien= t-auth");
}
@@ -1064,9 +1= 048,8 @@
* @param timeout_str The timeout value in stri= ng form
*/
static void
-man_client_pending_auth(struct manageme= nt *man, const char *cid_str,
- const char *kid_str, const char *extra,
- c= onst char *timeout_str)
+man_client_pending_auth(struct management *man, const char *cid_str, co= nst char *kid_str,
+ = const char *extra, const char *timeout_str) {
unsigned long cid =3D 0;
= unsigned int kid =3D 0;
@@ -1076,8 +1059,8 @@
= {
if (man->persist.callback.client_p= ending_auth)
{
- bool ret =3D (*man->persist.callback.clien= t_pending_auth)
- = (man->persist.callback.arg, cid, kid, extra, timeou= t);
+ bool= ret =3D (*man->persist.callback.client_pending_auth)(man->persist.ca= llback.arg, cid,
+ = kid, extra= , timeout);

if (ret)<= br> {
@@ -1086,7 +1069,7 @@
else

{
= msg(M_CLIENT, "ERROR: client-pending-auth command failed.&qu= ot;
- = " Extra parameter might be too long");
+ " Extra p= arameter might be too long");
} }
else
@@ -1102,8 = +1085,7 @@
struct man_connection *mc =3D &man->= connection;
mc->in_extra_cid =3D 0;
mc->in_extra_kid =3D 0;

- if (parse_cid(cid_str, &mc->in_extra_cid)
<= span style=3D"color: hsl(0, 100%, 40%);">- && parse_uint(kid= _str, "KID", &mc->in_extra_kid))

+ if (parse_cid(cid_str, &mc->in_ext= ra_cid) && parse_uint(kid_str, "KID", &mc->in_extr= a_kid))
{
mc->in_extra_cmd= =3D IEC_CLIENT_AUTH;
in_extra_reset(mc, IER_NEW);=
@@ -1115,7 +1097,8 @@
}
=
static void
-man_client_deny(struct management *man, const char *cid_str, const = char *kid_str, const char *reason, const char *client_reason)
+man_client_deny(struct management= *man, const char *cid_str, const char *kid_str,

+ const char *reason, const char= *client_reason)
{
unsigned long cid = =3D 0;
unsigned int kid =3D 0;
@@ -112= 3,14 +1106,8 @@
{
if (man->= ;persist.callback.client_auth)
{
- const bool status =3D (*man= ->persist.callback.client_auth)
- (man->persist.callback.= arg,
- = cid,
- kid,
- false,
<= span style=3D"color: hsl(0, 100%, 40%);">- = reason,

- = client_reason,
- NULL);
+ const bool status =3D = (*man->persist.callback.client_auth)(

+ man->persist.callback.arg, cid, kid= , false, reason, client_reason, NULL);
if (sta= tus)
{
msg(M_= CLIENT, "SUCCESS: client-deny command succeeded");
@@ -1155,7 +1132,8 @@

{
if = (man->persist.callback.kill_by_cid)
{- const bool status = =3D (*man->persist.callback.kill_by_cid)(man->persist.callback.arg, c= id, kill_msg);
+ = const bool status =3D
+ (*man->persist.callback.kill_by_cid)(man->pe= rsist.callback.arg, cid, kill_msg);
if (status= )
{
msg(M_CLI= ENT, "SUCCESS: client-kill command succeeded");
@= @ -1238,12 +1216,10 @@
nclients =3D (*man->pers= ist.callback.n_clients)(man->persist.callback.arg);
= }
msg(M_CLIENT, "SUCCESS: nclients=3D%d,bytesin= =3D" counter_format ",bytesout=3D" counter_format,- nclients,
- link_read_bytes_global,
- link_write_bytes_= global);
+ ncl= ients, link_read_bytes_global, link_write_bytes_global);
}=

-#de= fine MN_AT_LEAST (1<<0)
+#define MN_AT_LEAST (1 << 0)
/** * Checks if the correct number of arguments to a management comman= d are present
* and otherwise prints an error and returns= false.
@@ -1263,11 +1239,8 @@
{
if (!p[i])
{
- msg(M_CLIENT, "ERROR: = the '%s' command requires %s%d parameter%s",
- p[0],
- (flags & MN_AT_LEAS= T) ? "at least " : "",
- n,
- n > 1 ? "s" : "");=
+ msg(M_C= LIENT, "ERROR: the '%s' command requires %s%d parameter%s"= ;, p[0],
+ = (flags & MN_AT_LEAST) ? "at least " : "", n, n= > 1 ? "s" : "");
retur= n false;
}
}
= @@ -1313,8 +1286,7 @@
*/
if (man= ->persist.callback.network_change)
{
- int fd =3D (*man->persist= .callback.network_change)

- (man->persist.callback.arg, samenetwork);
+ int fd =3D (*man-= >persist.callback.network_change)(man->persist.callback.arg, samenetw= ork);
man->connection.fdtosend =3D fd; msg(M_CLIENT, "PROTECTFD: fd '%d' sent to be = protected", fd);
if (fd =3D=3D -2)
= @@ -1335,7 +1307,8 @@
}

= static void
-man= _dispatch_command(struct management *man, struct status_output *so, const c= har **p, const int nparms)
+man_dispatch_command(struct management *man, struct status_output *s= o, const char **p,
+ = const int nparms)
{
= struct gc_arena gc =3D gc_new();

@@ -1= 665,7 +1638,8 @@
const int n =3D atoi(p[1]);
for (i =3D 0; i < n; ++i)
= {
- = msg(M_CLIENT, "[%d] The purpose of this command is to generate = large amounts of output.", i);
+ msg(M_CLIENT,
+ "[%d] The purpose of thi= s command is to generate large amounts of output.", i);
}

}
}@@ -1692,7 +1666,8 @@

ca= se MS_CC_WAIT_READ:
case MS_CC_WAIT_WRITE:<= br>- net_event_win32_s= tart(&man->connection.ne32, FD_READ|FD_WRITE|FD_CLOSE, man->conne= ction.sd_cli);
+ = net_event_win32_start(&man->connection.ne32, FD_READ | FD_WRI= TE | FD_CLOSE,
+ = man->connection.sd_cli);
= break;

default:
@@ -1737,27 +1712,24 @@
#if UNIX_SOCK_SUPPORT
if (man->settings.flags & MF_UNIX_SOCK) {
- = msg(D_MANAGEMENT, "MANAGEMENT: %s %s",
- description,
+ msg(D_MANAGEMENT, "MANAGEMEN= T: %s %s", description,
sockaddr_unix_nam= e(&man->settings.local_unix, "NULL"));
= }
else
#endif
- if (man->settings.flags & MF_CON= NECT_AS_CLIENT)
+ = if (man->settings.flags & MF_CONNECT_AS_CLIENT)
= {
- msg(D_M= ANAGEMENT, "MANAGEMENT: %s %s",
- description,
+ msg(D_MANAGEMENT, "MANAGEMENT: %s %s&= quot;, description,
print_sockaddr(man->set= tings.local->ai_addr, &gc));
}
= else
{
struct sockaddr_s= torage addr;
socklen_t addrlen =3D sizeof(addr);
- if (!getpeernam= e(man->connection.sd_cli, (struct sockaddr *) &addr,
- &addrlen= ))

+ if (!getp= eername(man->connection.sd_cli, (struct sockaddr *)&addr, &addrl= en))
{
msg(D_MANAGEME= NT, "MANAGEMENT: %s %s", description,
- print_sockaddr((struct sockaddr *= ) &addr, &gc));
+ print_sockaddr((struct sockaddr *)&addr, &gc));=
}
else
= {
@@ -1783,19 +1755,22 @@
{=
if (socket_defined(sd) && (man->settings.client_u= id !=3D -1 || man->settings.client_gid !=3D -1))
{<= /span>
- static const c= har err_prefix[] =3D "MANAGEMENT: unix domain socket client connection= rejected --";
+= static const char err_prefix[] =3D
+ "MANAGEMENT: unix domain socket cli= ent connection rejected --";
int uid, gid;
if (unix_socket_get_peer_uid_gid(man->connection.= sd_cli, &uid, &gid))
{
= if (man->settings.client_uid !=3D -1 && man->settin= gs.client_uid !=3D uid)
{
- msg(D_MANAGEMENT, "%s= UID of socket peer (%d) doesn't match required value (%d) as given by = --management-client-user",
+ msg(D_MANAGEMENT,
+ "%s UID of socket peer (= %d) doesn't match required value (%d) as given by --management-client-u= ser",
err_prefix, uid, man->se= ttings.client_uid);
return false; }
if (man->settings.cl= ient_gid !=3D -1 && man->settings.client_gid !=3D gid) {
-= msg(D_MANAGEMENT, "%s GID of socket peer (%d) doesn= 9;t match required value (%d) as given by --management-client-group",<= /span>
+ msg(= D_MANAGEMENT,
+ = "%s GID of socket peer (%d) doesn't match required v= alue (%d) as given by --management-client-group",
= err_prefix, gid, man->settings.client_gid);
<= span> return false;

}@@ -1877,8 +1852,8 @@
#endif
= {
man->connection.sd_top =3D create_soc= ket_tcp(man->settings.local);
- socket_bind(man->connection.sd_top, man->setti= ngs.local,
- = man->settings.local->ai_family, "MANAGEMENT", = false);
+ = socket_bind(man->connection.sd_top, man->settings.local, man->sett= ings.local->ai_family,
+ "MANAGEMENT", false);
}


/*
@@ -1906,14 +1881,13 @@

const struct sockaddr= *man_addr =3D man->settings.local->ai_addr;
= struct sockaddr_storage addr;
socklen_t a= ddrlen =3D sizeof(addr);
+ if (!getsockname(man->connection.sd_top, (struct s= ockaddr *)&addr, &addrlen))
{- man_addr =3D (= struct sockaddr *) &addr;
+ man_addr =3D (struct sockaddr *)&addr;=
}
else
= {
- = msg(M_WARN|M_ERRNO,
- "Failed to get the management socket addres= s");
+ = msg(M_WARN | M_ERRNO, "Failed to get the management socket addre= ss");
}
msg(= D_MANAGEMENT, "MANAGEMENT: TCP Socket listening on %s", print_sockaddr(man_addr, &gc));
@@ -1959,9 +1933,7 @@

#endif
{
man->connection.sd_cli =3D create_socket_tcp(man->= ;settings.local);
- = status =3D openvpn_connect(man->connection.sd_cli,
- man-&g= t;settings.local->ai_addr,
- 5,
+ status =3D openvpn_connect(man->connecti= on.sd_cli, man->settings.local->ai_addr, 5,
= &signal_received);
}

@@ -1976,15 +1948,13 @@
#if = UNIX_SOCK_SUPPORT
if (man->settings.flags &= MF_UNIX_SOCK)
{
- msg(D_LINK_ERRORS | M_ERRNO,
- "MANAGEMENT: co= nnect to unix socket %s failed",

+ msg(D_LINK_ERRORS | M_ERRNO, "MANAGEMENT= : connect to unix socket %s failed",
= sockaddr_unix_name(&man->settings.local_unix, "NULL"));
}
else
#en= dif
{
- msg(D_LINK_ERRORS | M_ERRNO,
- "MANAGEMENT: connect to %s= failed",
+ = msg(D_LINK_ERRORS | M_ERRNO, "MANAGEMENT: connect to %s failed&= quot;,
print_sockaddr(man->settings.loc= al->ai_addr, &gc));
}
= throw_signal_soft(SIGTERM, "management-connect-failed");
@@ -2049,7 +2019,7 @@
struct gc_arena gc = =3D gc_new();
struct status_output *so;
int nparms;

- = char *parms[MAX_PARMS+1];
+ char *parms[MAX_PARMS + 1];

= CLEAR(parms);
so =3D status_open(NULL, 0, -1, &= man->persist.vout, 0);
@@ -2102,8 +2072,7 @@
<= span> if (!ignore_sys_error(err, crt_error))

{
struct gc_arena gc =3D gc_new();
- msg(D_MANAGEMENT, "MANAGEMENT= : TCP %s error: %s", prefix,
- strerror(err));
+ msg(D_MANAGEMENT, "MANAGEMENT: TCP %s erro= r: %s", prefix, strerror(err));
gc_free(&= gc);
return true;
}@@ -2120,7 +2089,8 @@
struct msghdr msg =3D { 0= };
struct iovec iov[1];

<= span style=3D"color: hsl(0, 100%, 40%);">- union {

+ union
+ {
struct cmsghdr cm;
char control[CMSG_SPACE(sizeof(int))];
} control_un;

@@ -2133,7 +2103,7 @@
cmptr->cmsg_len =3D CMSG_LEN(sizeof(int));

c= mptr->cmsg_level =3D SOL_SOCKET;
cmptr->cmsg_typ= e =3D SCM_RIGHTS;
- = *((int *) CMSG_DATA(cmptr)) =3D sendfd;
+ *((int *)CMSG_DATA(cmptr)) =3D sendfd;

msg.msg_name =3D NULL;
msg.= msg_namelen =3D 0;
@@ -2153,13 +2123,14 @@
= struct iovec iov[1];
ssize_t n;
=
- union {+ union
+ {
struct c= msghdr cm;
char control[CMSG_SPACE(sizeof(int))];<= /span>
} control_un;
- struct cmsghdr *cmptr;
+ struct cmsghdr *cmptr;
- msghdr.msg_control =3D con= trol_un.control;
+ = msghdr.msg_control =3D control_un.control;
msghdr.msg= _controllen =3D sizeof(control_un.control);

msghdr.msg_name =3D NULL;

@@ -2170,13 +2141,12 @@
msghdr.msg_iov =3D iov;
msghdr.msg= _iovlen =3D 1;

- if ( (n =3D recvmsg(fd, &msghdr, flags)) <=3D 0)
+ if ((n =3D recvmsg(f= d, &msghdr, flags)) <=3D 0)
{
= return (n);
}

- if ( (cmptr =3D CMSG_FIRSTHDR(&a= mp;msghdr)) !=3D NULL

-= && cmptr->cmsg_len =3D=3D CMSG_LEN(sizeof(int)))=
+ if ((cmptr =3D CMSG_FI= RSTHDR(&msghdr)) !=3D NULL && cmptr->cmsg_len =3D=3D CMSG_LE= N(sizeof(int)))
{
if (cmptr-&= gt;cmsg_level !=3D SOL_SOCKET)
{
@= @ -2186,12 +2156,11 @@
{
= msg(M_ERR, "control type !=3D SCM_RIGHTS");
= }
- *rec= vfd =3D *((int *) CMSG_DATA(cmptr));
+ *recvfd =3D *((int *)CMSG_DATA(cmptr));
= }
else
{
- *recvfd =3D -1; /* de= scriptor was not passed */

-
+ *recvf= d =3D -1; /* descriptor was not passed */
}
= return (n);
}
@@ -2209,10 +2178= ,10 @@
}
struct user_pass up;
CLEAR(up);
- strncpy(up.username, msg, sizeof(up.username)-1);
+ strncpy(up.username, msg, size= of(up.username) - 1);


- management_query_user_pass(management, &up, comma= nd, GET_USER_PASS_NEED_OK, (void *) 0);
- return strcmp("ok", up.password)=3D=3D0;
+ management_query_u= ser_pass(management, &up, command, GET_USER_PASS_NEED_OK, (void *)0);
+ return strcmp(&qu= ot;ok", up.password) =3D=3D 0;
}

/*
@@ -2227,8 +2196,8 @@
= struct user_pass up;
CLEAR(up);
= strcpy(up.username, "tunmethod");
- management_query_user_pass(management, &up, = "PERSIST_TUN_ACTION",
- GET_USER_PASS_NEED_OK, (void *) 0)= ;
+ management_que= ry_user_pass(management, &up, "PERSIST_TUN_ACTION", GET_USER_= PASS_NEED_OK,
+ = (void *)0);
if (!strcmp("= ;NOACTION", up.password))
{
= return ANDROID_KEEP_OLD_TUN;
@@ -2239,7 +2208,8 @@
}
else
{<= br>- msg(M_ERR, "Got = unrecognised '%s' from management for PERSIST_TUN_ACTION query"= ;, up.password);
+ = msg(M_ERR, "Got unrecognised '%s' from management for PER= SIST_TUN_ACTION query",
+ up.password);
}
=
ASSERT(0);
@@ -2265,7 +2235,7 @@
{
man->connection.lastfdreceiv= ed =3D fd;
}
-#else /* ifdef TARGET_ANDROID */
+#else /* ifdef TARGET_ANDROID */
= len =3D recv(man->connection.sd_cli, (void *)buf, sizeof(buf), MSG_= NOSIGNAL);
#endif

@@ -22= 77,7 +2247,7 @@
{
bool proces= sed_command =3D false;

- ASSERT(len <=3D (int) sizeof(buf));+ ASSERT(len <=3D (i= nt)sizeof(buf));
command_line_add(man->connecti= on.in, buf, len);

/*
<= span>@@ -2305,7 +2275,7 @@

}
else

{
- man_process_comma= nd(man, (char *) line);

+ man_process_command(man, (char *)line);
<= span> }

if (man->connec= tion.halt)
{
@@ -2358,12 += 2328,13 @@
#ifdef TARGET_ANDROID
= if (man->connection.fdtosend > 0)
{- sent =3D man_send_= with_fd(man->connection.sd_cli, BPTR(buf), len, MSG_NOSIGNAL, man->co= nnection.fdtosend);
+= sent =3D man_send_with_fd(man->connection.sd_cli, BPTR(buf),= len, MSG_NOSIGNAL,
+= man->connection.fdtosend); man->connection.fdtosend =3D -1;
= }
else
#endif
- sent =3D send(man->conne= ction.sd_cli, (const void *)BPTR(buf), len, MSG_NOSIGNAL);

+ sent =3D send(man->co= nnection.sd_cli, (const void *)BPTR(buf), len, MSG_NOSIGNAL);
if (sent >=3D 0)

{
= buffer_list_advance(man->connection.out, sent);
<= span>@@ -2399,9 +2370,7 @@

}

<= span> static void

-man_= persist_init(struct management *man,
- const int log_history_cache,
- const int echo_buff= er_size,

+man_persist= _init(struct management *man, const int log_history_cache, const int echo_b= uffer_size,
const int state_buffer_size)<= /span>
{
struct man_persist *mp =3D &man= ->persist;
@@ -2459,17 +2428,10 @@
}

static void
-man_settings_init(struct man_settings *ms,- const char *a= ddr,
- = const char *port,
- = const char *pass_file,
- const char *client_user,
- const char *client_g= roup,
- = const int log_history_cache,
- const int echo_buffer_size,
- const int state_buffer_s= ize,
- = const int remap_sigusr1,
- const unsigned int flags)
+man_settings_init(struct man_settings *ms, cons= t char *addr, const char *port,
+ const char *pass_file, const char *client_use= r, const char *client_group,
+ const int log_history_cache, const int echo_buff= er_size,
+ = const int state_buffer_size, const int remap_sigusr1, const unsigned= int flags)
{
if (!ms->defined)
{
@@ -2515,7 +2477,6 @@
= else
#endif
{
= -
/*=
* Run management over tunnel, or
<= span> * separate channel?

@@ -2527,16 +2488,16= @@
else
{=
int status;
- int resolve_flags =3D GETADDR_RESOLVE|GETA= DDR_WARN_ON_SIGNAL|GETADDR_FATAL;
+ int resolve_flags =3D GETADDR_RESOLVE | GETAD= DR_WARN_ON_SIGNAL | GETADDR_FATAL;

= if (!(flags & MF_CONNECT_AS_CLIENT))
= {
resolve_flags |=3D GETADDR= _PASSIVE;
}

- status =3D openvpn= _getaddrinfo(resolve_flags, addr, port, 0,

- NULL, AF_= UNSPEC, &ms->local);
- ASSERT(status=3D=3D0);
+ status =3D
+ openvpn_getaddrinfo(r= esolve_flags, addr, port, 0, NULL, AF_UNSPEC, &ms->local);+ ASSERT(status= =3D=3D 0);
}
}

@@ -2654,9 +2615,7 @@
str= uct management *man;
ALLOC_OBJ_CLEAR(man, struct manag= ement);

- man_persist_init(man,
- MANAGEMENT_LOG_HISTORY_INITIAL_SIZE,- MANAGEMENT= _ECHO_BUFFER_SIZE,
+ = man_persist_init(man, MANAGEMENT_LOG_HISTORY_INITIAL_SIZE, MANAGEMENT_EC= HO_BUFFER_SIZE,
MANAGEMENT_STATE_BUFF= ER_SIZE);

man_connection_clear(&= man->connection);
@@ -2665,16 +2624,9 @@
}


bool
-management_open(struct management *man,
- const char *addr,
- const c= har *port,
- = const char *pass_file,
- const char *client_user,
- const char *client_group,- const int log_= history_cache,
- = const int echo_buffer_size,
- const int state_buffer_size,
- const int remap_sigus= r1,

+management_open(= struct management *man, const char *addr, const char *port, const char *pas= s_file,
+ = const char *client_user, const char *client_group, const int log_histor= y_cache,
+ = const int echo_buffer_size, const int state_buffer_size, const int rem= ap_sigusr1,
const unsigned int flags)
{
bool ret =3D false;
@@ = -2683,17 +2635,8 @@
* Save the settings only if they = have not
* been saved before.
*= /
- man_settings_ini= t(&man->settings,
- port,
- pass_file,
- client_user,
- client_group,<= /span>
- = log_history_cache,
- = echo_buffer_size,
- state_buffer_size,
- remap_sigusr1,

- flag= s);
+ man_settings= _init(&man->settings, addr, port, pass_file, client_user, client_gro= up,
+ = log_history_cache, echo_buffer_size, state_buffer_size, remap_sigusr1= , flags);

/*
*= The log is initially sized to MANAGEMENT_LOG_HISTORY_INITIAL_SIZE,<= br>@@ -2730,8 +2673,7 @@
}
<= br> void
-managem= ent_set_callback(struct management *man,
- const struct management_callback= *cb)
+management_set= _callback(struct management *man, const struct management_callback *cb)
{
man->persist.standalone_disabled = =3D true;
man->persist.callback =3D *cb;
= @@ -2747,15 +2689,12 @@
}
void
-manageme= nt_set_state(struct management *man,
- const int state,
- const char *detail,
- con= st in_addr_t *tun_local_ip,
- const struct in6_addr *tun_local_ip6,
= - const struc= t openvpn_sockaddr *local,
- const struct openvpn_sockaddr *remote)
= +management_set_state(struct ma= nagement *man, const int state, const char *detail,
+ const in_addr_t *tun= _local_ip, const struct in6_addr *tun_local_ip6,
+ const struct openvpn_sock= addr *local, const struct openvpn_sockaddr *remote)
{
- if (man->persist.st= ate && (!(man->settings.flags & MF_SERVER) || state < OPE= NVPN_STATE_CLIENT_BASE))
+ if (man->persist.state
+ && (!(man->settings.flags & MF_SERVER= ) || state < OPENVPN_STATE_CLIENT_BASE))
{ struct gc_arena gc =3D gc_new();
= struct log_entry e;
@@ -2787,13 +2726,11 @@

if (man->connection.state_realtime) {
- = out =3D log_entry_print(&e, LOG_PRINT_STATE_PREFIX
<= span style=3D"color: hsl(0, 100%, 40%);">- = | LOG_PRINT_INT_DATE

- | LOG_PRINT_STATE
- | LOG= _PRINT_LOCAL_IP
- = | LOG_PRINT_REMOTE_IP
- | LOG_P= RINT_CRLF
- = | LOG_ECHO_TO_LOG, &gc);
+ out =3D log_entry_print(&= e,
+ = LOG_PRINT_STATE_PREFIX | LOG_PRINT_INT_DATE | LOG_PRINT_ST= ATE
+ = | LOG_PRINT_LOCAL_IP | LOG_PRINT_REMOTE_IP | LOG_PRIN= T_CRLF
+ = | LOG_ECHO_TO_LOG,
+ &gc);<= br> }

if (out)
@@ -2808,25 +2745,23 @@
static bool env_filter_match(const char *env_str, const int env_filter_level)
{
- = static const char *env_names[] =3D {
- "username=3D",
- "password=3D",
- "X509_0_CN=3D",
- "tls_serial_&= quot;,
- "u= ntrusted_ip=3D",
-= "ifconfig_local=3D",
- "ifconfig_netmask=3D",
- "daemon_start_time=3D"= ;,
- "daemo= n_pid=3D",
- = "dev=3D",
-= "ifconfig_pool_remote_ip=3D",
- "ifconfig_pool_netmask=3D",
- "time_durati= on=3D",
- &= quot;bytes_sent=3D",
- "bytes_received=3D",
- "session_id=3D",
- "session_state=3D"
- };
+ static const char *env_names[] =3D = { "username=3D",
+ "password=3D",
+ = "X509_0_CN=3D",
+ "tls_seria= l_",
+ = "untrusted_ip=3D",
+ = "ifconfig_local=3D",
+ "ifconfig_netmask= =3D",
+ = "daemon_start_time=3D",
<= span style=3D"color: hsl(120, 100%, 40%);">+ = "daemon_pid=3D",

+ "dev=3D",
+ = "ifconfig_pool_remote_ip=3D",
+ = "ifconfig_pool_netmask=3D",
+ "time_durat= ion=3D",
+ = "bytes_sent=3D",
+ = "bytes_received=3D",

+ "session_id=3D&q= uot;,
+ = "session_state=3D" };
<= /span>
if (env_filter_level =3D=3D 0)
{<= /span>
@@ -2854,7 +2789,8 @@
}
<= /span>
static void
-man_output_env(const struct env_set *es, const bool tail, const int = env_filter_level, const char *prefix)
+man_output_env(const struct env_set *es, const bool tail,= const int env_filter_level,
+ const char *prefix)
{
if (es)

{
@@ -2915,11 +2851,1= 2 @@
char line[256];
if (man->= persist.callback.get_peer_info)
{
- const char *peer_info =3D (*man-&g= t;persist.callback.get_peer_info)(man->persist.callback.arg, mdac->ci= d);
+ const ch= ar *peer_info =3D
+ = (*man->persist.callback.get_peer_info)(man->persist.callbac= k.arg, mdac->cid);
if (peer_info)
{

struct buffer buf;
- buf_set_read(&buf, = (const uint8_t *) peer_info, strlen(peer_info));

+ buf_set_read(&buf, (const uint= 8_t *)peer_info, strlen(peer_info));
while (bu= f_parse(&buf, '\n', line, sizeof(line)))
= {
chomp(line);
@@ -= 2937,10 +2874,8 @@
}

vo= id
-management_notify_c= lient_needing_auth(struct management *management,
- const uns= igned int mda_key_id,
-= struct man_def_auth_context *mdac,
- = const struct env_set *es)
+management_notify_client_needing_auth(struct management= *management, const unsigned int mda_key_id,
+ struct man_d= ef_auth_context *mdac, const struct env_set *es)
{<= br> if (!(mdac->flags & DAF_CONNECTION_CLOSED))
= {
@@ -2951,7 +2886,7 @@
= }
msg(M_CLIENT, ">CLIENT:%s,%lu,%u",= mode, mdac->cid, mda_key_id);
man_output_extra= _env(management, "CLIENT");
- if (management->connection.env_filter_level>0= )
+ if (manage= ment->connection.env_filter_level > 0)
{
man_output_peer_info_env(management, mdac);
}
@@ -2961,18 +2896,15 @@
}


void
-management_notify_client_cr_response(unsigned mda_k= ey_id,
- = const struct man_def_auth_context *mdac,
- = const struct env_set *es,

- const char *response)+management_notify_client_cr_r= esponse(unsigned mda_key_id, const struct man_def_auth_context *mdac,
+ = const struct env_set *es, const char *response)
{

struct gc_arena gc;
if (manag= ement)
{
gc =3D gc_new();

- = msg(M_CLIENT, ">CLIENT:CR_RESPONSE,%lu,%u,%s",
- mdac->cid, mda_key_id= , response);

+ = msg(M_CLIENT, ">CLIENT:CR_RESPONSE,%lu,%u,%s", mdac->cid, = mda_key_id, response);
man_output_extra_env(manage= ment, "CLIENT");
if (management->conn= ection.env_filter_level > 0)
{
= @@ -2984,8 +2916,7 @@
}

= void
-management_conne= ction_established(struct management *management,
- struct man_def= _auth_context *mdac,
= +management_connection_established(struct management *management, struct ma= n_def_auth_context *mdac,
= const struct env_set *es)
{
mdac-&g= t;flags |=3D DAF_CONNECTION_ESTABLISHED;
@@ -2995,8 +2926,7= @@
}

void
-management_notify_client_close(str= uct management *management,

- struct man_def_auth_context *mdac,
+management_notify_clien= t_close(struct management *management, struct man_def_auth_context *mdac,
const struct env_set *es)
{
if ((mdac->flags & DAF_INITIAL= _AUTH) && !(mdac->flags & DAF_CONNECTION_CLOSED))
= @@ -3008,18 +2938,14 @@
}
void
-manageme= nt_learn_addr(struct management *management,
- struct man_def_auth_context *m= dac,
- = const struct mroute_addr *addr,
- const bool primary)
+management_learn_addr(struct managemen= t *management, struct man_def_auth_context *mdac,
+ const struct mroute_add= r *addr, const bool primary)
{
struct= gc_arena gc =3D gc_new();
if ((mdac->flags & D= AF_INITIAL_AUTH) && !(mdac->flags & DAF_CONNECTION_CLOSED))<= /span>
{
= - msg(M_CLIENT, ">CLIENT:ADDRESS,%lu,%s,%d",
= - mdac->cid,=
- mroute_addr_prin= t_ex(addr, MAPF_SUBNET, &gc),
- BOOL_CAST(primary));
+ msg(M_CLIENT, ">CLIENT:ADDRESS,%lu= ,%s,%d", mdac->cid,
+ mroute_addr_print_ex(addr, MAPF_SUBNET, &gc), BOOL_= CAST(primary));
}
gc_free(&gc= );
}
@@ -3043,7 +2969,10 @@

if (man->connection.echo_realtime) {
- = out =3D log_entry_print(&e, LOG_PRINT_INT_DATE|LOG_PRINT_ECHO_= PREFIX|LOG_PRINT_CRLF|MANAGEMENT_ECHO_FLAGS, &gc);
+ out =3D log_entry_print(&= ;e,
+ = LOG_PRINT_INT_DATE | LOG_PRINT_ECHO_PREFIX | LOG_PRINT_CR= LF
+ = | MANAGEMENT_ECHO_FLAGS,
+ &gc);
}

if (out)
@@ -3062,8 +2991,7 @@
* If we are runn= ing management over the tunnel,
* this is the place t= o initialize the connection.
*/
- if (man->settings.management_over_tu= nnel
- &&= ; man->connection.state =3D=3D MS_INITIAL)
+ if (man->settings.management_over_tunnel &= amp;& man->connection.state =3D=3D MS_INITIAL)
= {
/* listen on our local TUN/TAP IP address */
struct in_addr ia;
@@ -3072,12 +3000,= 11 @@

ia.s_addr =3D htonl(tun_lo= cal_ip);
inet_ntop(AF_INET, &ia, buf, sizeof(b= uf));
- ret =3D = openvpn_getaddrinfo(GETADDR_PASSIVE, buf, NULL, 0, NULL,
- AF_INE= T, &man->settings.local);
- ASSERT(ret=3D=3D0);
+ ret =3D
+ openvpn_getaddrinfo(GETADDR_PASSIVE, buf, NULL, = 0, NULL, AF_INET, &man->settings.local);
+ ASSERT(ret =3D=3D 0);
= man_connection_init(man);
}
-
}

void
@@ -3125,9 +3052,7 @@
= #ifdef _WIN32

void
-management_socket_set(struct management *ma= n,
- = struct event_set *es,
+management_socket_set(struct management *man, struct event_= set *es, void *arg,
unsigned int *pe= rsistent)
{
if (man->connection.st= ate !=3D MS_INITIAL)
@@ -3154,7 +3079,7 @@
= case MS_CC_WAIT_WRITE:
if (ma= n_persist_state(persistent, 3))
{- event_ctl(= es, ev, EVENT_READ|EVENT_WRITE, arg);
+ event_ctl(es, ev, EVENT_READ | EVENT_= WRITE, arg);
}
= break;

@@ -3187,7 +3112,8 @@=
net_event_win32_clear_selected_events(&m= an->connection.ne32, FD_ACCEPT);
}
}
- else if (man->connection.state =3D=3D MS_CC_WAIT_READ |= | man->connection.state =3D=3D MS_CC_WAIT_WRITE)
+ else if (man->connection.s= tate =3D=3D MS_CC_WAIT_READ
+ || man->connection.state =3D=3D MS_CC_WAIT_= WRITE)
{
if (= net_events & FD_READ)
{
@@ -3214,9 +3140,7 @@

#else /* ifdef _WIN32 */
void
-management_socket_set(struct management *man,
- struct event_set *e= s,
- = void *arg,
+manage= ment_socket_set(struct management *man, struct event_set *es, void *arg,
unsigned int *persistent)
{

switch (man->connection.state)
@@ -3383,7 +3307,8 @@

* Process management event loop = outside primary event loop
*/
static int=
-man_standalone_event_= loop(struct management *man, volatile int *signal_received, const time_t ex= pire)
+man_standalone= _event_loop(struct management *man, volatile int *signal_received,+ co= nst time_t expire)
{
int status =3D -= 1;
if (man_standalone_ok(man))
@@ -339= 7,18 +3322,16 @@
return status;
}

-#define= MWCC_PASSWORD_WAIT (1<<0)
-#define MWCC_HOLD_WAIT (1<<1)
-#define MWCC_OTHER_WAIT (1<<2)=
+#define MWCC_PASSWORD_WAIT= (1 << 0)
+#def= ine MWCC_HOLD_WAIT (1 << 1)
+#define MWCC_OTHER_WAIT (1 << 2)

/*
* Block until client connects
*/
static void
-man_wait_for_client_connection(struct management *m= an,
- = volatile int *signal_received,
- const time_t expire,
- = unsigned int flags)
+man_wait_for_client_connection(struct management *man, volatile int= *signal_received,
+ = const time_t expire, unsigned int flags)
{
ASSERT(man_standalone_ok(man));<= br> if (man->connection.state =3D=3D MS_LISTEN)
@@ -3493,11 +3416,8 @@

* Get a username/password from m= anagement channel in standalone mode.
*/
= bool
-management_query= _user_pass(struct management *man,
- struct user_pass *up,
- const ch= ar *type,

- = const unsigned int flags,
- const char *static_challenge)=
+management_query_us= er_pass(struct management *man, struct user_pass *up, const char *type,
+ = const unsigned int flags, const char *static_challenge)
{

struct gc_arena gc =3D gc_new();
= bool ret =3D false;
@@ -3546,10 +3466,7 @@
sc =3D static_challenge;

= }
}
- buf_printf(&alert_msg, ">%s:Need '%s' %s= ",
- = prefix,
- = type,
- = alert_type);
+ buf_printf(&alert_msg, ">%s:Need '%s' %s&= quot;, prefix, type, alert_type);

= if (flags & (GET_USER_PASS_NEED_OK | GET_USER_PASS_NEED_STR))<= br> {
@@ -3560,7 +3477,7 @@
= {
buf_printf(&alert_msg, " SC= :%d,%s",
BOOL_CAST(flags &= GET_USER_PASS_STATIC_CHALLENGE_ECHO)
- |(BOOL_CAST(flags & GET_USER_PAS= S_STATIC_CHALLENGE_CONCAT) << 1),
+ | (BOOL_CAST(flags & GET= _USER_PASS_STATIC_CHALLENGE_CONCAT) << 1),
= sc);
}

<= span>@@ -3625,8 +3542,8 @@

}

<= span> static int

-manag= ement_query_multiline(struct management *man,
- const char *b64_data, co= nst char *prompt, const char *cmd, int *state, struct buffer_list **input)<= /span>
+management_query_mul= tiline(struct management *man, const char *b64_data, const char *prompt,
+ = const char *cmd, int *state, struct buffer_list **input)
{

struct gc_arena gc =3D gc_new();
int ret =3D 0;

@@ -3645,12 +3562,12 @@

if (b64_data)
{
- alert_msg =3D a= lloc_buf_gc(strlen(b64_data)+strlen(prompt)+3, &gc);
+ alert_msg =3D alloc_buf_gc= (strlen(b64_data) + strlen(prompt) + 3, &gc);
= buf_printf(&alert_msg, ">%s:%s", prompt, b64_data);
}
else
= {
- ale= rt_msg =3D alloc_buf_gc(strlen(prompt)+3, &gc);
+ alert_msg =3D alloc_buf_gc(st= rlen(prompt) + 3, &gc);
buf_printf(&al= ert_msg, ">%s", prompt);
}
=
@@ -3703,8 +3620,9 @@

<= span> static char *

/* returns allocated base64 signature = */
-management_query_mu= ltiline_flatten_newline(struct management *man,
- const = char *b64_data, const char *prompt, const char *cmd, int *state, struct buf= fer_list **input)
+ma= nagement_query_multiline_flatten_newline(struct management *man, const char= *b64_data,
+ = const char *prompt, const char *cmd, int= *state,
+ = struct buffer_list **input)
{

int ok;
char *result =3D NULL= ;
@@ -3717,7 +3635,7 @@
buf =3D bu= ffer_list_peek(*input);
if (buf && BLEN(bu= f) > 0)
{
- result =3D (char *) malloc(BLEN(buf)+1);=
+ result =3D (ch= ar *)malloc(BLEN(buf) + 1);
check_malloc_retur= n(result);
memcpy(result, buf->data, BLEN(b= uf));
result[BLEN(buf)] =3D '\0';
@@ -3732,8 +3650,8 @@

static= char *
/* returns allocated base64 signature */-management_query_multiline_flat= ten(struct management *man,
- const char *b64_data, const char *= prompt, const char *cmd, int *state, struct buffer_list **input)
= +management_query_multiline_fla= tten(struct management *man, const char *b64_data, const char *prompt,
+ = const char *cmd, int *state, struct buffer_list **input)<= br> {
int ok;
char *result = =3D NULL;
@@ -3746,7 +3664,7 @@
bu= f =3D buffer_list_peek(*input);
if (buf &&= BLEN(buf) > 0)
{
- result =3D (char *) malloc(BLEN(buf)+1)= ;
+ result= =3D (char *)malloc(BLEN(buf) + 1);
check_mall= oc_return(result);
memcpy(result, buf->data= , BLEN(buf));
result[BLEN(buf)] =3D '\0= 9;;
@@ -3761,8 +3679,7 @@

char *

/* returns allocated base64 signature */-management_query_pk_sig(struct= management *man, const char *b64_data,
- const char *algorithm)
= +management_query_pk_sig(struct= management *man, const char *b64_data, const char *algorithm)
{

const char *prompt =3D "PK_SIGN";
const char *desc =3D "pk-sign";
@@ -3774,15 +3691,15 @@

desc =3D "rsa-sign&q= uot;;
}

- buf_write(&buf_data, b64_data, (int) strle= n(b64_data));
+ bu= f_write(&buf_data, b64_data, (int)strlen(b64_data));
= if (man->connection.client_version > 2)
{
- buf_write(&bu= f_data, ",", (int) strlen(","));
- buf_write(&buf_data, algorithm,= (int) strlen(algorithm));
+ buf_write(&buf_data, ",", (int)strlen(",&= quot;));
+ buf= _write(&buf_data, algorithm, (int)strlen(algorithm));
= }
- char *ret = =3D management_query_multiline_flatten(man,
- (c= har *)buf_bptr(&buf_data), prompt, desc,
- &= amp;man->connection.ext_key_state, &man->connection.ext_key_input= );
+ char *ret =3D= management_query_multiline_flatten(man, (char *)buf_bptr(&buf_data), p= rompt, desc,
+ = &man->connection.ext_key= _state,
+ = &man->connection.ext_key_inpu= t);
free_buf(&buf_data);
retu= rn ret;
}
@@ -3793,12 +3710,12 @@ const char prompt_1[] =3D "NEED-CERTIFICATE:";
struct buffer buf_prompt =3D alloc_buf(strlen(cert_name) + = 20);
buf_write(&buf_prompt, prompt_1, strlen(promp= t_1));
- buf_write(&= amp;buf_prompt, cert_name, strlen(cert_name)+1); /* +1 for \0 */
= + buf_write(&buf_prompt,= cert_name, strlen(cert_name) + 1); /* +1 for \0 */

char *result;
- result =3D management_query_multiline_flatten_newline(managemen= t,
- = NULL, (char *)buf_bptr(&buf_prompt= ), "certificate",
- &man->= connection.ext_cert_state, &man->connection.ext_cert_input);<= br>+ result =3D management_q= uery_multiline_flatten_newline(
+ management, NULL, (char *)buf_bptr(&buf_prompt), &q= uot;certificate",
- man->persist.standalone_disabled =3D false; /* Thi= s is so M_CLIENT messages will be correctly passed through msg() */<= br>+ man->persist.sta= ndalone_disabled =3D
= + false; /* This is so M_CLIENT messages will be correctly passe= d through msg() */
man->persist.special_state_m= sg =3D NULL;
man->settings.mansig |=3D MANSIG_I= GNORE_USR1_HUP;

@@ -3904,7 +3822,7 @@
int i;
for (i =3D 0; i < len; ++i= )
{
+ if (buf[i] = && char_class(buf[i], (CC_PRINT | CC_NEWLINE)))
= {
if (!buf_write_u8(&cl->buf, buf= [i]))
{
@@ -3988,10 +3906,16 @= @
}
if (flags & LOG_PRINT_REM= OTE_IP)
{
- buf_printf(&out, ",%s", (!addr_defined(&= e->remote_sock) ? "," :
- print_sockaddr_ex(&e-&g= t;remote_sock.addr.sa, ",", PS_DONT_SHOW_FAMILY|PS_SHOW_PORT, gc)= ));
- buf_printf= (&out, ",%s", (!addr_defined(&e->local_sock) ? ",= " :
- = print_sockaddr_ex(&e->local_sock.addr.sa, "= ,", PS_DONT_SHOW_FAMILY|PS_SHOW_PORT, gc)));
+ buf_printf(&out, ",%s",=
+ = (!addr_defined(&e->remote_sock)
+ ? ","
+ : print_sock= addr_ex(&e->remote_sock.addr.sa, ",",
+ = PS_DONT_SHOW_FAMILY | PS_SHOW_PORT, gc)));
+ buf_printf(&out, ",%s",
+ (!a= ddr_defined(&e->local_sock)
+ ? ","
+ : print_sockaddr= _ex(&e->local_sock.addr.sa, ",",
+ P= S_DONT_SHOW_FAMILY | PS_SHOW_PORT, gc)));
}
= if (flags & LOG_PRINT_LOCAL_IP && !IN6_IS_ADDR_UNSPE= CIFIED(&e->local_ip6))
{
@@ -41= 44,8 +4068,7 @@
void
management_check_byt= ecount(struct context *c, struct management *man, struct timeval *timeval)<= /span>
{
- = if (event_timeout_trigger(&man->connection.bytecount_update_interva= l,
- = timeval, ETT_DEFAULT))
+ if (event_timeout_trigger(&man->connection.bytecou= nt_update_interval, timeval, ETT_DEFAULT))
{ counter_type dco_read_bytes =3D 0;
= counter_type dco_write_bytes =3D 0;
@@ -4182,7 +4105,7 @@<= /span>
}
}

-#else /* ifdef ENABLE_MANAGEMENT */<= /span>
+#else /* ifdef ENABL= E_MANAGEMENT */

#include "win32.h&q= uot;
void
diff --git a/src/openvpn/manage.= h b/src/openvpn/manage.h
index eb19a4e..b541434 100644
--- a/src/openvpn/manage.h
+++ b/src/openvpn/ma= nage.h
@@ -25,24 +25,24 @@
#define MANAGE_= H

/* management_open flags */
= -#define MF_SERVER (1&= lt;<0)
-#define MF_Q= UERY_PASSWORDS (1<<1)
-#define MF_HOLD (1<<2)
-#define MF_SIGNAL (1<<3)

-#define MF_FORGET_DISCONNEC= T (1<<4)
-#define= MF_CONNECT_AS_CLIENT (1<<5)
-#define MF_CLIENT_AUTH (1<<6)
+#define MF_SERVER (1 <= ;< 0)
+#define MF_= QUERY_PASSWORDS (1 << 1)
+#define MF_HOLD (1 << 2)+#define MF_SIGNAL = (1 << 3)
= +#define MF_FORGET_DISCONNECT (1 << 4)
+#define MF_CONNECT_AS_CLIENT (1 <<= 5)
+#define MF_CLIEN= T_AUTH (1 << 6)
/* #define MF_CLIENT_PF = (1<<7) *REMOVED FEATURE* */
-#define MF_UNIX_SOCK (1<<8)<= br>-#define MF_EXTERNAL_KEY = (1<<9)
-#d= efine MF_EXTERNAL_KEY_NOPADDING (1<<10)
-#define MF_EXTERNAL_KEY_PKCS1PAD (1<<11)=
-#define MF_UP_DOWN = (1<<12)
-#define MF_QUERY_REMOTE (1<<13)
-#define MF_QUERY_PROXY (1&l= t;<14)
-#define MF_E= XTERNAL_CERT (1<<15)
-#define MF_EXTERNAL_KEY_PSSPAD (1<<16)-#define MF_EXTERNAL_KEY_DIGEST = (1<<17)
+#= define MF_UNIX_SOCK (1 << 8)
+#define MF_EXTERNAL_KEY (1 << 9= )
+#define MF_EXTERNA= L_KEY_NOPADDING (1 << 10)
+#define MF_EXTERNAL_KEY_PKCS1PAD (1 << 11)
+#define MF_UP_DOWN = (1 << 12)

+#de= fine MF_QUERY_REMOTE (1 << 13)
+#define MF_QUERY_PROXY (1 << 14= )
+#define MF_EXTERNA= L_CERT (1 << 15)
+#define MF_EXTERNAL_KEY_PSSPAD (1 << 16)
+#define MF_EXTERNAL_KEY_DIGEST = (1 << 17)



#ifde= f ENABLE_MANAGEMENT
@@ -52,21 +52,22 @@
#i= nclude "socket.h"
#include "mroute.h"<= /span>

-#def= ine MANAGEMENT_VERSION 5
-#define MANAGEMENT_N_PASSWORD_RETRIES 3
-#define MANAGEMENT_LOG_= HISTORY_INITIAL_SIZE 100
-#define MANAGEMENT_ECHO_BUFFER_SIZE 100
-#define MANAGEMENT_STATE_BUFFER_SIZE = 100
+#define MANA= GEMENT_VERSION 5
+#define MANAGEMENT_N_PASSWORD_RETRIES 3
+#define MANAGEMENT_LOG_HISTORY_INIT= IAL_SIZE 100

+#define= MANAGEMENT_ECHO_BUFFER_SIZE 100
+#define MANAGEMENT_STATE_BUFFER_SIZE 100=

/*
* Management-interface-ba= sed deferred authentication
*/
-struct man_def_auth_context {
+struct man_def_auth_context
= +{
unsigne= d long cid;

-#define DAF_CONNECTION_ESTABLISHED (1<<0)
-#define DAF_CONNECTION_CLOSED (1<= <1)
-#define DAF_INI= TIAL_AUTH (1<<2)
+#define DAF_CONNECTION_ESTABLISHED (1 << 0)
+#define DAF_CONNECTION_CLOSED = (1 << 1)

+#d= efine DAF_INITIAL_AUTH (1 << 2)
unsign= ed int flags;

unsigned int mda_key_i= d_counter;
@@ -99,7 +100,8 @@
* Manage lo= g file history
*/

-union log_entry_union {
+union log_entry_union
+{
unsigned int m= sg_flags;
int state;
int intval;<= /span>
@@ -116,23 +118,23 @@
union log_entry_= union u;
};

-#define LOG_PRINT_LOG_PREFIX (1<<0)=
-#define LOG_PRINT_ECHO_PREFI= X (1<<1)
-#defin= e LOG_PRINT_STATE_PREFIX (1<<2)
+#define LOG_PRINT_LOG_PREFIX (1 << 0)
<= span style=3D"color: hsl(120, 100%, 40%);">+#define LOG_PRINT_ECHO_PREFIX = (1 << 1)

+#defi= ne LOG_PRINT_STATE_PREFIX (1 << 2)

-#define LOG_PRINT_INT_DATE (1<&= lt;3)
-#define LOG_PRIN= T_MSG_FLAGS (1<<4)
-#define LOG_PRINT_STATE (1<<5)
-#define LOG_PRINT_LOCAL_IP (1<<6)
+#define LOG_PRINT_INT_D= ATE (1 << 3)
+= #define LOG_PRINT_MSG_FLAGS (1 << 4)
+#define LOG_PRINT_STATE (1 << 5)+#define LOG_PRINT_LOCAL_IP (= 1 << 6)

-#define LOG_PRINT_CRLF (1<<7)
-#define LOG_FATAL_NOTIFY (1<<8)=
+#define LOG_PRINT_C= RLF (1 << 7)
= +#define LOG_FATAL_NOTIFY (1 << 8)

-#define LOG_PRINT_INTVAL (1<&= lt;9)
+#define LOG_PR= INT_INTVAL (1 << 9)

-#define LOG_PRINT_REMOTE_IP (1<<10)+#define LOG_PRINT_REMOTE_IP = (1 << 10)

-#define LOG_ECHO_TO_LOG (1<<11)
+#define LOG_ECHO_TO_LOG (1 << 11= )

const char *log_entry_print(const stru= ct log_entry *e, unsigned int flags, struct gc_arena *gc);
=
@@ -174,32 +176,25 @@
{
= void *arg;

-#define MCF_SERVER (1<<0) /* is OpenVPN being run as a s= erver? */
+#define MC= F_SERVER (1 << 0) /* is OpenVPN being run as a server? */
<= span> unsigned int flags;


- void (*status) (void *arg, const int version,= struct status_output *so);
- void (*show_net) (void *arg, const int msglevel);
- int (*kill_by_cn) (void *arg, con= st char *common_name);

= - int (*kill_by_addr) (void *arg, const in_addr_t addr, const int port, = const int proto);
- = void (*delete_event) (void *arg, event_t event);
- int (*n_clients) (void *arg);
- bool (*send_cc_message) (void *a= rg, const char *message, const char *parameter);

+ void (*status)(void *arg, const int versio= n, struct status_output *so);
+ void (*show_net)(void *arg, const int msglevel);
+ int (*kill_by_cn)(void *arg,= const char *common_name);

+ int (*kill_by_addr)(void *arg, const in_addr_t addr, const int p= ort, const int proto);
+ int (*n_clients)(void *arg);<= br>+ bool (*send_cc_message)= (void *arg, const char *message, const char *parameter);
= bool (*kill_by_cid)(void *arg, const unsigned long cid, const char *kill= _msg);
- bool (*clie= nt_auth) (void *arg,
- = const unsigned long cid,
- const unsigned int mda_= key_id,
- = const bool auth,
- const char *reason,
- const char *client_re= ason,
- = struct buffer_list *cc_config); /* ownership transferred */=
- bool (*client_pending_au= th) (void *arg,
- = const unsigned long cid,
- const unsi= gned int kid,
- = const char *extra,
- unsigned int timeout= );
- char *(*get_pee= r_info) (void *arg, const unsigned long cid);
+ bool (*client_auth)(void *arg, const unsigned= long cid, const unsigned int mda_key_id,
+ const bool auth, const char *= reason, const char *client_reason,
+ struct buffer_list *cc_config); /* o= wnership transferred */
+ bool (*client_pending_auth)(void *arg, const unsigned long cid, con= st unsigned int kid,
= + const char *extra, unsigned int timeout);<= /span>
+ char *(*get_peer= _info)(void *arg, const unsigned long cid);
bool (*pro= xy_cmd)(void *arg, const char **p);
- bool (*remote_cmd) (void *arg, const char **p);+ bool (*remote_cmd)(void *= arg, const char **p);
#ifdef TARGET_ANDROID
int (*network_change)(void *arg, bool samenetwork);

= #endif
@@ -221,7 +216,8 @@
* = connections.
*/

= -struct man_persist {
<= span style=3D"color: hsl(120, 100%, 40%);">+struct man_persist

+{

bool defi= ned;

struct log_history *log;=
@@ -241,7 +237,8 @@
counter_type bytes_out;<= /span>
};

-struct man_settings {
+struct man_settings
+{
bool defined;
= unsigned int flags; /* MF_x flags */
struct addrinfo = *local;
@@ -257,9 +254,9 @@
int client= _gid;

/* flags for handling the manageme= nt interface "signal" command */
-#define MANSIG_IGNORE_USR1_HUP (1<<0)-#define MANSIG_MAP_USR1_TO_HUP = (1<<1)
-#define = MANSIG_MAP_USR1_TO_TERM (1<<2)
+#define MANSIG_IGNORE_USR1_HUP (1 << 0)
<= span style=3D"color: hsl(120, 100%, 40%);">+#define MANSIG_MAP_USR1_TO_HUP = (1 << 1)

+#def= ine MANSIG_MAP_USR1_TO_TERM (1 << 2)
unsigned in= t mansig;
};

@@ -271,12 = +268,13 @@
#define UP_QUERY_NEED_STR 4
<= /span>
/* states */
-#define MS_INITIAL 0 /* all sockets are closed */<= br>-#define MS_LISTEN 1= /* no client is connected */
-#define MS_CC_WAIT_READ 2 /* client is connected, waiting for= read on socket */
-#de= fine MS_CC_WAIT_WRITE 3 /* client is connected, waiting for ability to = write to socket */
+#= define MS_INITIAL 0 /* all sockets are closed */
+#define MS_LISTEN 1 /* no client = is connected */
+#def= ine MS_CC_WAIT_READ 2 /* client is connected, waiting for read on socket *= /
+#define MS_CC_WAIT= _WRITE 3 /* client is connected, waiting for ability to write to socket */<= /span>

-stru= ct man_connection {
+= struct man_connection
+{
int state;

= socket_descriptor_t sd_top;
@@ -345,16 +343,10 @@
struct management *management_init(void);<= br>
-bool manage= ment_open(struct management *man,
- const char *addr,
- const char *port,<= br>- const ch= ar *pass_file,
- = const char *client_user,
- const char *client_group,
<= span style=3D"color: hsl(0, 100%, 40%);">- const int lo= g_history_cache,

- = const int echo_buffer_size,
- const int state_buffer_size,
- cons= t int remap_sigusr1,
= +bool management_open(struct management *man, const char *addr, const char = *port,
+ = const char *pass_file, const char *client_user, const char *client_= group,
+ = const int log_history_cache, const int echo_buffer_size,
= + const int= state_buffer_size, const int remap_sigusr1,
= const unsigned int flags);

void = management_close(struct management *man);
@@ -363,28 +355,2= 2 @@

void management_pre_tunnel_close(st= ruct management *man);

-void management_socket_set(struct management *man,
- = struct event_set *es,
-= void *arg,
+void management_socket_set(struct management *man, struct= event_set *es, void *arg,
unsi= gned int *persistent);

void management_i= o(struct management *man);

-void management_set_callback(struct management *man,=
- = const struct management_callback *cb);
+void management_set_callback(struct management *= man, const struct management_callback *cb);

void management_clear_callback(struct management *man);


-bool management_que= ry_user_pass(struct management *man,
- struct user_pass *up,=
- = const char *type,
-= const unsigned int flags,
- const c= har *static_challenge);
+bool management_query_user_pass(struct management *man, struct user_pas= s *up, const char *type,
+ const unsigned int flags, const char *= static_challenge);

#ifdef TARGET_ANDROID=
bool management_android_control(struct management *man, c= onst char *command, const char *msg);

-#define ANDROID_KEEP_OLD_TUN 1
= +#define ANDROID_KEEP_OLD_TUN = 1
#define ANDROID_OPEN_BEFORE_CLOSE 2
= int managment_android_persisttun_action(struct management *man);
@@ -398,7 +384,8 @@

void management_up_down(struct management *man, const char *updown, co= nst struct env_set *es);


-void management_notify(struct management *man, const c= har *severity, const char *type, const char *text);
+void management_notify(struct management = *man, const char *severity, const char *type,
+ const char *text);<= br>
void management_notify_generic(struct managemen= t *man, const char *str);

@@ -408,25 +395= ,19 @@
const st= ruct env_set *es);

void management_conne= ction_established(struct management *management,
- struct ma= n_def_auth_context *mdac,
- const struct env_set *es);
+ = struct man_def_auth_context *mdac, const struct env_set *es);=

void management_notify_client_close(str= uct management *management,
- struct man_def_auth_context *mdac= ,
- = const struct env_set *es);
+ struct man_def_a= uth_context *mdac, const struct env_set *es);

<= span style=3D"color: hsl(0, 100%, 40%);">-void management_learn_addr(struct= management *management,

- const= struct mroute_addr *addr,
- const bool primary);
+void management_learn_addr(struct managem= ent *management, struct man_def_auth_context *mdac,
+ const struct m= route_addr *addr, const bool primary);

v= oid management_notify_client_cr_response(unsigned mda_key_id,
const struct man_def_auth_con= text *mdac,

- = const struct env_set *es,
- = const char *response);
+ const struct env_set *es, c= onst char *response);

-char *management_query_pk_sig(struct management *man, con= st char *b64_data,
- = const char *algorithm);
+char *management_query_pk_sig(struct managem= ent *man, const char *b64_data, const char *algorithm);

char *management_query_cert(struct management *man, const c= har *cert_name);

@@ -466,30 +447,28 @@
*/

/* client/server stat= es */
-#define OPENVPN_= STATE_INITIAL 0 /* Initial, undefined state */
-#define OPENVPN_STATE_CONNECTING 1 /* M= anagement interface has been initialized */
-#define OPENVPN_STATE_ASSIGN_IP 2 /* Assigning I= P address to virtual network interface */
-#define OPENVPN_STATE_ADD_ROUTES 3 /* Adding routes= to system */
-#define = OPENVPN_STATE_CONNECTED 4 /* Initialization sequence completed */
-#define OPENVPN_STATE_RECO= NNECTING 5 /* Restart */
-#define OPENVPN_STATE_EXITING 6 /* Exit */
+#define OPENVPN_STATE_INITIAL 0 /* = Initial, undefined state */
+#define OPENVPN_STATE_CONNECTING 1 /* Management interface has be= en initialized */
+#d= efine OPENVPN_STATE_ASSIGN_IP 2 /* Assigning IP address to virtual netwo= rk interface */
+#def= ine OPENVPN_STATE_ADD_ROUTES 3 /* Adding routes to system */
+#define OPENVPN_STATE_CONNECTED = 4 /* Initialization sequence completed */

+#define OPENVPN_STATE_RECONNECTING 5 /* Restart */=
+#define OPENVPN_STA= TE_EXITING 6 /* Exit */

/* client-o= nly states */
-#define = OPENVPN_STATE_WAIT 7 /* Waiting for initial response from server = */
-#define OPENVPN_STA= TE_AUTH 8 /* Authenticating with server */
-#define OPENVPN_STATE_GET_CONFIG 9 /* D= ownloading configuration from server */
-#define OPENVPN_STATE_RESOLVE 10 /* DNS lookup */
-#define OPENVPN_STATE_T= CP_CONNECT 11 /* Connecting to TCP server */
-#define OPENVPN_STATE_AUTH_PENDING 12 /* Waiting = in auth-pending mode
- = * technically variant of GET_CONFIG = */
+#define OPENVPN_S= TATE_WAIT 7 /* Waiting for initial response from server */+#define OPENVPN_STATE_AUTH = 8 /* Authenticating with server */
+#define OPENVPN_STATE_GET_CONFIG 9 /* Downloading c= onfiguration from server */
+#define OPENVPN_STATE_RESOLVE 10 /* DNS lookup */
+#define OPENVPN_STATE_TCP_CONNECT= 11 /* Connecting to TCP server */

+#define OPENVPN_STATE_AUTH_PENDING = \
+ 12 = /* Waiting in auth-pending mode \
+ = * technically variant of GET_CONFIG */


-#define OPENVPN_STATE_CLIENT_BASE = 7 /* Base index of client-only states */

+#define OPENVPN_STATE_CLIENT_BASE 7 /* Base index o= f client-only states */

-void management_set_state(struct management *man,
- c= onst int state,
- = const char *detail,
- const in_addr_t *tun_local_ip,<= /span>
- = const struct in6_addr *tun_local_ip6,
+void management_set_state(struct management *man, con= st int state, const char *detail,
+ const in_addr_t *tun_local_ip, cons= t struct in6_addr *tun_local_ip6,
= const struct openvpn_sockaddr *local_addr,
= const struct openvpn_sockaddr *remote_addr);
=
@@ -514,15 +493,10 @@
* These functions = drive the bytecount in/out counters.
*/
=
-void
-management_check_bytecount(struct cont= ext *c,
- = struct management *man,
- struct timeval *timeval);<= br>+void management_check_bytec= ount(struct context *c, struct management *man, struct timeval *timeval);

static inline void
-management_bytes_client(struct management *= man,
- = const int size_in,
- const int size_out)
+management_bytes_client(struct management *man,= const int size_in, const int size_out)
{
= if (!(man->persist.callback.flags & MCF_SERVER))
{

@@ -531,27 +505,24 @@
}
}

-void
-man_byt= ecount_output_server(const counter_type *bytes_in_total,
- const counte= r_type *bytes_out_total,
+void man_bytecount_output_se= rver(const counter_type *bytes_in_total,
+ const counter_type *b= ytes_out_total,
+ = struct man_def_auth_context *mdac);
=
static inline void
-management_bytes_server(struct management *man,
- con= st counter_type *bytes_in_total,
- const counter_type *bytes_out_total,
- s= truct man_def_auth_context *mdac)
+management_bytes_server(struct management *man, const counter= _type *bytes_in_total,
- = && (mdac->flags & (DAF_CONNECTION_ESTABLISHED | DAF_CON= NECTION_CLOSED)) =3D=3D DAF_CONNECTION_ESTABLISHED)
+ && (mdac->flags & = (DAF_CONNECTION_ESTABLISHED | DAF_CONNECTION_CLOSED))
+ =3D=3D DAF_CONNECTION_ESTA= BLISHED)
{
man_bytecount_outp= ut_server(bytes_in_total, bytes_out_total, mdac);
}
}

-void
-man_= persist_client_stats(struct management *man, struct context *c);
= +void man_persist_client_stats(= struct management *man, struct context *c);

#endif /* ifdef ENABLE_MANAGEMENT */


= diff --git a/src/openvpn/mbedtls_compat.h b/src/openvpn/mbedtls_compat.h
index aeb0c5f..94d56f9 100644
--- a/src/openv= pn/mbedtls_compat.h
+++ b/src/openvpn/mbedtls_compat.h
@@ -49,7 +49,7 @@
#include <mbedtls/x509_cr= t.h>

#ifdef HAVE_PSA_CRYPTO_H<= br>- #include <psa/crypto.h= >
+#include <ps= a/crypto.h>
#endif

#= if MBEDTLS_VERSION_NUMBER >=3D 0x03000000
@@ -90,8 +90,7= @@
* an error code.
*/
static inline int

-mb= edtls_compat_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx,
- const = unsigned char *additional,

+mbedtls_compat_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx, const = unsigned char *additional,
= size_t add_len)
{
#if MBEDTLS_VERSION_NUM= BER > 0x03000000
@@ -116,8 +115,7 @@
}<= /span>

static inline int
-mbedtls_compat_pk_parse_key(mbedtls_pk_cont= ext *ctx,
- = const unsigned char *key, size_t keylen,
+mbedtls_compat_pk_parse_key(mbedtls_pk= _context *ctx, const unsigned char *key, size_t keylen,
= const unsigned char *pwd, size_t pwdlen, int (*f_rng)(void *, unsigned char *, = size_t), void *p_rng)
{
@@ -129,8 +127,7 @= @
}

static inline int
-mbedtls_compat_pk_parse= _keyfile(mbedtls_pk_context *ctx,
- const char *path, const char *p= assword,
+mbedtls_com= pat_pk_parse_keyfile(mbedtls_pk_context *ctx, const char *path, const char = *password,
int (*f_rng)(vo= id *, unsigned char *, size_t), void *p_rng)
{
<= span> #if MBEDTLS_VERSION_NUMBER < 0x03020100

@@ -141,8 = +138,9 @@
}

#if MBEDTLS= _VERSION_NUMBER < 0x03020100
-typedef enum {
+typedef enum
+{
+ MBEDTLS_SSL_VERSION= _UNKNOWN, /*!< Context not in use or version not yet negotiated.= */
MBEDTLS_SSL_VERSION_TLS1_2 =3D 0x0303, /*!< (D)= TLS 1.2 */
MBEDTLS_SSL_VERSION_TLS1_3 =3D 0x0304, /*!&= lt; (D)TLS 1.3 */
} mbedtls_ssl_protocol_version;diff --git a/src/openvpn/mbuf.c b/src/openvpn/mbuf.c
index 3346a11..0585395 100644

--- a/src/openvpn/mbuf.c
+++ b/src/openvpn/mbuf.c
@@ -51,7 +51,7 @@
if (ms)
{
= int i;
- for (i = =3D 0; i < (int) ms->len; ++i)
+ for (i =3D 0; i < (int)ms->len; ++i)<= br> {
struct mbuf_item *item =3D= &ms->array[MBUF_INDEX(ms->head, i, ms->capacity)];
= mbuf_free_buf(item->buffer);
@@ -135,= 7 +135,7 @@
if (ms)
{
<= span> int i;

- = for (i =3D 0; i < (int) ms->len; ++i)
+ for (i =3D 0; i < (int)ms->len= ; ++i)
{
struct mbuf_= item *item =3D &ms->array[MBUF_INDEX(ms->head, i, ms->capacity= )];
if (item->instance)
@@ = -154,7 +154,7 @@
if (ms)
{=
int i;
- for (i =3D 0; i < (int) ms->len; ++i)
+ for (i =3D 0; i < (int)ms-&g= t;len; ++i)
{
struct = mbuf_item *item =3D &ms->array[MBUF_INDEX(ms->head, i, ms->cap= acity)];
if (item->instance =3D=3D mi)
diff --git a/src/openvpn/mbuf.h b/src/openvpn/mbuf.h
= index b9c1645..9c41a58 100644
--- a/src/openvpn/mbuf.= h
+++ b/src/openvpn/mbuf.h
@@ -36,14 +36,14= @@

struct multi_instance;

-#define MBUF_INDE= X(head, offset, size) (((head) + (offset)) & ((size)-1))
+#define MBUF_INDEX(head, offset, s= ize) (((head) + (offset)) & ((size) - 1))


<= span> struct mbuf_buffer

{
struct buf= fer buf;
int refcount;

-#define MF_UNICAST (1<<0)
+#define MF_UNICAST (1 &= lt;< 0)
unsigned int flags;
};

@@ -91,7 +91,7 @@
static in= line int
mbuf_maximum_queued(const struct mbuf_set *ms)
{
- r= eturn (int) ms->max_queued;
+ return (int)ms->max_queued;
}
=
struct multi_instance *mbuf_peek_dowork(struct mbu= f_set *ms);
diff --git a/src/openvpn/memdbg.h b/src/openvpn= /memdbg.h
index 6947275..743a853 100644
---= a/src/openvpn/memdbg.h
+++ b/src/openvpn/memdbg.h@@ -39,7 +39,8 @@
* from uninitialized data, we n= eed to untaint it before use --
* otherwise we will get a= lot of useless warnings.
*
- * valgrind --tool=3Dmemcheck --error-limit=3Dno = --suppressions=3Ddebug/valgrind-suppress --gen-suppressions=3Dyes ./openvpn= ...
+ * valgrind -= -tool=3Dmemcheck --error-limit=3Dno --suppressions=3Ddebug/valgrind-suppres= s
+ * --gen-suppressi= ons=3Dyes ./openvpn ...
*/

#ifdef USE_VALGRIND

@@ -48,7 +49,7 @@
=
#define VALGRIND_MAKE_READABLE(addr, len)

-#else /* ifdef US= E_VALGRIND */
+#else = /* ifdef USE_VALGRIND */

#define VALGRIN= D_MAKE_READABLE(addr, len)

@@ -86,7 +87,8= @@

#include <dmalloc.h>
-#define openv= pn_dmalloc(file, line, size) dmalloc_malloc((file), (line), (size), DMALLOC= _FUNC_MALLOC, 0, 0)
+= #define openvpn_dmalloc(file, line, size) \
+ dmalloc_malloc((file), (line), (size), DMALLOC_= FUNC_MALLOC, 0, 0)

/*
= * This #define will put the line number of the log
diff --g= it a/src/openvpn/misc.c b/src/openvpn/misc.c
index 4695700.= .6cb0e96 100644
--- a/src/openvpn/misc.c
++= + b/src/openvpn/misc.c
@@ -85,7 +85,7 @@
<= /span>
uint8_t rnd_bytes[n_rnd_bytes];
c= onst char *rnd_str;
- = struct buffer hname =3D alloc_buf_gc(strlen(hostname)+sizeof(rnd_bytes)*2= +4, gc);
+ struct = buffer hname =3D alloc_buf_gc(strlen(hostname) + sizeof(rnd_bytes) * 2 + 4,= gc);

prng_bytes(rnd_bytes, sizeof(r= nd_bytes));
rnd_str =3D format_hex_ex(rnd_bytes, sizeo= f(rnd_bytes), 40, 0, NULL, gc);
@@ -119,7 +119,9 @@<= br> }
else
= {
- msg(M_FA= TAL, "ERROR: could not read %s username/password/ok/string from manage= ment interface", prefix);
+ msg(M_FATAL,
+ "ERROR: could not read %s username/pas= sword/ok/string from management interface",
+ prefix);
= }
}
return true;
@@ -135,7 +137,8 @@

* @param auth_challenge The authe= ntication challenge string to parse. Can't be NULL.
*= @param gc The gc_arena structure for memory allocation.=
*
- * @retu= rn A pointer to the parsed auth_challenge_info structure, or = NULL if parsing fails.
+ * fails.
*/
static struct auth_c= hallenge_info *
parse_auth_challenge(const char *auth_chal= lenge, struct gc_arena *gc)
@@ -144,7 +147,7 @@
<= span>

struct auth_challenge_info *ac;
const int len =3D strlen(auth_challenge);

- char *work =3D (char *) gc_malloc(len+1, fals= e, gc);
+ char *wo= rk =3D (char *)gc_malloc(len + 1, false, gc);
char *cp= ;

struct buffer b;
@= @ -192,7 +195,7 @@
{
return N= ULL;
}
- ac->user =3D (char *) gc_malloc(strlen(work)+1, true, gc);
+ ac->user =3D (ch= ar *)gc_malloc(strlen(work) + 1, true, gc);
openvpn_ba= se64_decode(work, (void *)ac->user, -1);

/* parse challenge text */

@@ -208,11 +211,8 @@
*/

bool
-get_user_pass_cr(struct user_pass *up,<= /span>
- const= char *auth_file,
- = const char *prefix,
- const unsigned int flags,
- const char *auth_challenge= )
+get_user_pass_cr(s= truct user_pass *up, const char *auth_file, const char *prefix,
<= span style=3D"color: hsl(120, 100%, 40%);">+ const unsigned= int flags, const char *auth_challenge)

{
= struct gc_arena gc =3D gc_new();

@@ = -233,8 +233,7 @@
/*
* Ge= t username/password from management interface?
*/=
- if (managemen= t
- &&am= p; (!from_authfile && (flags & GET_USER_PASS_MANAGEMENT))
+ if (management &a= mp;& (!from_authfile && (flags & GET_USER_PASS_MANAGEMENT))=
&& management_query_user_pass_enabled= (management))
{
respo= nse_from_stdin =3D false;
@@ -245,118 +244,119 @@ }
else
#endif /* = ifdef ENABLE_MANAGEMENT */
- /*
- = * Get NEED_OK confirmation from the console
- */
- if (flags & GET_USER_PASS_NEED_OK)
- {

- struct buffer user_prompt =3D alloc= _buf_gc(128, &gc);
= -
- buf_prin= tf(&user_prompt, "NEED-OK|%s|%s:", prefix, up->username);<= /span>
- if (!query= _user_SINGLE(BSTR(&user_prompt), BLEN(&user_prompt),
- u= p->password, USER_PASS_LEN, false))

- {
- msg(M_FATAL, "ERROR: could not read %s ok-con= firmation from stdin", prefix);
- }
-
- if= (!strlen(up->password))
- {
- = strcpy(up->password, "ok");
- }
- }
- else if (flags & GET_USER_PASS_INLINE_CREDS)
- {
- struct buffer buf;- buf_set_read(&= buf, (uint8_t *) auth_file, strlen(auth_file) + 1);
- if (!(flags & GET_USER_PASS= _PASSWORD_ONLY))
- = {
- = buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
- }
- buf_parse(&buf, = 9;\n', up->password, USER_PASS_LEN);

-
= - if (strlen(up->password) =3D=3D 0)
- {
- password_from_stdin =3D 1;
<= span style=3D"color: hsl(0, 100%, 40%);">- }

- }
- /*
- * Read from auth file unless this is a dynamic challeng= e request.
- */=
- else if (from= _authfile && !(flags & GET_USER_PASS_DYNAMIC_CHALLENGE))=
- {
= /*
- = * Try to get username/password from a file.
+ * Get NEED_OK confirmation from t= he console
*/
- FILE *fp;
- char password_buf[USER_PASS_LEN] =3D { &#= 39;\0' };
-<= br>- fp =3D platform_f= open(auth_file, "r");
- if (!fp)
+ if (flags & GET_USER_PASS_NEED_OK)
{

- = msg(M_ERR, "Error opening '%s' auth file: %s"= , prefix, auth_file);
-= }
+ = struct buffer user_prompt =3D alloc_buf_gc(128, &gc);<= br>
- = if ((flags & GET_USER_PASS_PASSWORD_ONLY) =3D=3D 0)
- {
- /* Read username first */=
- if (fgets(up= ->username, USER_PASS_LEN, fp) =3D=3D NULL)
+ buf_printf(&user_prompt, &qu= ot;NEED-OK|%s|%s:", prefix, up->username);
+ if (!query_user_SINGLE(BSTR(= &user_prompt), BLEN(&user_prompt), up->password,
+ = USER_PASS_LEN, false))

{
- msg(M_FATAL, &q= uot;Error reading username from %s authfile: %s",

- prefix,
= + msg(M_FATA= L, "ERROR: could not read %s ok-confirmation from stdin", prefix)= ;
+ }<= /span>
+
+ if (!strlen(up->pass= word))
+ = {
+ = strcpy(up->password, "ok");
+ }
+ }
+ else if (flags & GET_USER_PASS_INLINE_CRE= DS)
+ {
+ struct= buffer buf;
+ = buf_set_read(&buf, (uint8_t *)auth_file, strlen(auth_file) + 1= );
+ i= f (!(flags & GET_USER_PASS_PASSWORD_ONLY))
+ {
+ buf_parse(&buf, '\n= 9;, up->username, USER_PASS_LEN);
+ }
+ buf_parse(&buf, '\n', up->pas= sword, USER_PASS_LEN);
+ = if (strlen(up->password) =3D=3D 0)
+ {
+ password_from_stdin =3D 1;
+ }

+ }

+ /*
+ * Read from auth file unless thi= s is a dynamic challenge request.
+ */
+ else if (from_authfile && !(flags & GET_U= SER_PASS_DYNAMIC_CHALLENGE))
+ {
+ * Try to get username/password from a file.
+ */

+ FILE *fp;
=
+ char passw= ord_buf[USER_PASS_LEN] =3D { '\0' };
+
+ fp =3D platform_fopen(auth_file, "r");
+ if (!fp)=
+ {
+ m= sg(M_ERR, "Error opening '%s' auth file: %s", prefix, aut= h_file);
+ = }
+
+ if ((flags &= GET_USER_PASS_PASSWORD_ONLY) =3D=3D 0)

+ {
+ /* Read username first */
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (fgets(u= p->username, USER_PASS_LEN, fp) =3D=3D NULL)

+ {
+ msg(M_FATAL, "Er= ror reading username from %s authfile: %s", prefix,
+ auth_file)= ;
+ = }
+ = }
+ ch= omp(up->username);
+
+ i= f (fgets(password_buf, USER_PASS_LEN, fp) !=3D NULL)
+ {
+ chomp(password_buf);<= /span>
+ }
+
+ if (flags & GET_USER_= PASS_PASSWORD_ONLY && !password_buf[0])
+ {
+ msg(M_FATAL, "Error read= ing password from %s authfile: %s", prefix, auth_file);
+ }

+
+ if (password_buf[0])
+ {
+ strncpy(up->passw= ord, password_buf, USER_PASS_LEN);
+ }
+ /* The auth-file does not have the password: g= et both username
+ = * and password from the management interface if possible.
+ * Othe= rwise set to read password from console.
+ */
+#if defined(ENABLE_MANAGEMENT)
+ else if (management &= & (flags & GET_USER_PASS_MANAGEMENT)
+ && management_que= ry_user_pass_enabled(management))
+ {
+ msg(D_LOW,
+ "No password found in %= s authfile '%s'. Querying the management interface",+ prefi= x, auth_file);
+ = if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))=
+ = {
+ = fclose(fp);
+ = return false;
+ }
+ }
+#endif
+ else
+ {
+ }
+
+ fclose(fp);
+
+ = if (!(flags & GET_USER_PASS_PASSWORD_ONLY) && str= len(up->username) =3D=3D 0)
+ {
+ msg(M_FATAL, "ERROR: username from %s aut= hfile '%s' is empty", prefix,
= auth_file);
}
= }
- = chomp(up->username);
-
- if (f= gets(password_buf, USER_PASS_LEN, fp) !=3D NULL)
- {
- chomp(password_buf);
- }
-
- if (flags & GET_USER_PASS_PASSWORD_ONLY && !pa= ssword_buf[0])
- = {
- = msg(M_FATAL, "Error reading password from %s authfile: %s", pref= ix, auth_file);
- = }
-
- if (password_buf[0])
- {
= - strncpy(up->p= assword, password_buf, USER_PASS_LEN);
- }
- /* The auth-file does not have the password: get both = username
- = * and password from the management interface if possible.
- * Otherwise set to read pa= ssword from console.
- = */
-#if def= ined(ENABLE_MANAGEMENT)
- else if (management
- && (flags & GET_USER_PASS_MANA= GEMENT)
- = && management_query_user_pass_enabled(management))- {
- msg(D_LOW, "No pas= sword found in %s authfile '%s'. Querying the management interface&= quot;, prefix, auth_file);
- if (!auth_user_pass_mgmt(up, prefix, flags, auth_chall= enge))
- = {
- = fclose(fp);
- = return false;
- = }
-#endif
else
{
- password_from_stdi= n =3D 1;

+ = username_from_stdin =3D true;
+ password_from_stdin =3D true;
}


- fclose(fp);
-
- = if (!(flags & GET_USER_PASS_PASSWORD_ONLY) && strlen(up-&= gt;username) =3D=3D 0)
= - {
- = msg(M_FATAL, "ERROR: username from %s authfile '%s' i= s empty", prefix, auth_file);
- }
- }
- = else
- {=
- username_from_st= din =3D true;
- = password_from_stdin =3D true;
- }
-=
/*
* Get username/passw= ord from standard input?
*/
@@ -3= 68,15 +368,15 @@
struct auth_challenge_inf= o *ac =3D parse_auth_challenge(auth_challenge, &gc);
= if (ac)
{
- char *response =3D = (char *) gc_malloc(USER_PASS_LEN, false, &gc);
+ char *response =3D (char= *)gc_malloc(USER_PASS_LEN, false, &gc);
= struct buffer packed_resp, challenge;

- challenge =3D = alloc_buf_gc(14+strlen(ac->challenge_text), &gc);

+ challenge =3D allo= c_buf_gc(14 + strlen(ac->challenge_text), &gc);
= buf_printf(&challenge, "CHALLENGE: %s", ac-&= gt;challenge_text);
buf_set_write(&= ;packed_resp, (uint8_t *)up->password, USER_PASS_LEN);
=
- i= f (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge),- = response, USER_PASS_LEN, BOOL_CAST(ac->flags&CR_ECHO)))<= /span>
+ = if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge), response= ,
+ = USER_PASS_LEN, BOOL_CAST(ac->flags & CR_ECH= O)))
{
= msg(M_FATAL, "ERROR: could not read challenge response from = stdin");
}
@@ -40= 0,17 +400,17 @@

if (user= name_from_stdin && !(flags & GET_USER_PASS_PASSWORD_ONLY))
{
- query_user_add(BSTR(&user_prompt), BLEN(&a= mp;user_prompt),
- = up->username, USER_PASS_LEN, true);=
+ query_= user_add(BSTR(&user_prompt), BLEN(&user_prompt), up->username,
+ = USER_PASS_LEN, true);
}

if (password_from_stdin)
{
- query_user_add(BSTR(&pass_prompt), BLEN(&= amp;pass_prompt),
- = up->password, USER_PASS_LEN, false);
+ quer= y_user_add(BSTR(&pass_prompt), BLEN(&pass_prompt), up->password,=
+ = USER_PASS_LEN, false);
}

- = if (!query_user_exec() )
+ if (!query_user_exec())
= {
msg(M_FATAL, "ERR= OR: Failed retrieving username or password");
= }
@@ -424,17 +424,18 @@
= }

#ifdef ENABLE_MANAGEMENT=
- if (auth_cha= llenge && (flags & GET_USER_PASS_STATIC_CHALLENGE) && r= esponse_from_stdin)
+= if (auth_challenge && (flags & GET_USER_PASS_ST= ATIC_CHALLENGE)
+ = && response_from_stdin)
= {
- = char *response =3D (char *) gc_malloc(USER_PASS_LEN, false, &gc);=
+ = char *response =3D (char *)gc_malloc(USER_PASS_LEN, false, &gc);
struct buffer packed_resp, challenge;
char *pw64 =3D NULL, *resp64 =3D NULL;

- = challenge =3D alloc_buf_gc(14+strlen(auth_challenge), &gc);=
+ = challenge =3D alloc_buf_gc(14 + strlen(auth_challenge), &gc); buf_printf(&challenge, "CHALLENGE: %s= ", auth_challenge);

- if (!query_user_SINGLE(BSTR(&c= hallenge), BLEN(&challenge),
- response, USER_PASS_L= EN,
+ = if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge), resp= onse,
+ = USER_PASS_LEN,
= BOOL_CAST(flags & GET_USER_PASS_STATIC_CHA= LLENGE_ECHO)))
{
= msg(M_FATAL, "ERROR: could not retrieve static cha= llenge response");
@@ -457,7 +458,8 @@
{

if (strlen= (up->password) + strlen(response) >=3D USER_PASS_LEN)
{

- msg(M_FATAL, "ERROR: could not conca= tenate password/static_response: string too long");
+ msg(M_FATA= L,
+ = "ERROR: could not concatenate password/static_response:= string too long");
}<= br> strncat(up->password, response, USER_P= ASS_LEN - strlen(up->password) - 1);
= }
@@ -500,7 +502,8 @@
*/=
if (!warn_shown)
{
- msg(M_WARN, "WARN= ING: this configuration may cache passwords in memory -- use the auth-nocac= he option to prevent this");

+ msg(M_WARN,
+ "WARNING: this configuration may cac= he passwords in memory -- use the auth-nocache option to prevent this"= );
warn_shown =3D true;
= }
}
@@ -595,7 +598,7 @@
<= span> char **ret =3D NULL;

int i =3D 0;
=
- buf_set_re= ad(&buf, (const uint8_t *) str, strlen(str));
+ buf_set_read(&buf, (const uint8_t *)s= tr, strlen(str));
while (buf_parse(&buf, '\n&#= 39;, line, sizeof(line)))
{
+= +len;
@@ -604,7 +607,7 @@
/* alloc ret= urn array */
ALLOC_ARRAY_CLEAR_GC(ret, char *, len + 1= , gc);

+ buf_set_read(&buf, (= const uint8_t *)str, strlen(str));
while (buf_parse(&a= mp;buf, '\n', line, sizeof(line)))
{ chomp(line);
@@ -669,12 +672,12 @@ const char *
sanitize_control_message(const char = *src, struct gc_arena *gc)
{
- char *ret =3D gc_malloc(strlen(src)+1, false, g= c);
+ char *ret = =3D gc_malloc(strlen(src) + 1, false, gc);
char *dest = =3D ret;
bool redact =3D false;
i= nt skip =3D 0;

- for (;; )
+ for (;;)
{
const cha= r c =3D *src;
if (c =3D=3D '\0')@@ -691,8 +694,7 @@
skip =3D 4;<= br> redact =3D true;
}- else if (!check_debug_l= evel(D_SHOW_KEYS)
- = && (c =3D=3D 'a' && !strncmp(src, &quo= t;auth-token ", 11)))
+ else if (!check_debug_level(D_SHOW_KEYS) && (c =3D= =3D 'a' && !strncmp(src, "auth-token ", 11)))
{
/* Unless --verb is 7 = or higher (D_SHOW_KEYS), hide
* the auth-toke= n value coming in the src string
@@ -756,8 +758,7 @@=

case 2:
= /* after the '=3D', replace non-printable or shell meta with= '_' */
- = if (!isprint(c) || isspace(c)
- || c =3D=3D '$' || c =3D=3D &= #39;(' || c =3D=3D '`')
+ if (!isprint(c) || isspace(c) || c =3D=3D &= #39;$' || c =3D=3D '(' || c =3D=3D '`')
{

*line =3D '_&#= 39;;
}
@@ -772,12 +773,12 = @@
{
char line[256];
= struct buffer buf;
- buf_set_read(&buf, (const uint8_t *) peer_info, strlen(peer_info)= );
+ buf_set_read(= &buf, (const uint8_t *)peer_info, strlen(peer_info));
= while (buf_parse(&buf, '\n', line, sizeof(line))) {
chomp(line);
= if (validate_peer_info_line(line)
- && (strncmp(line, "IV_", 3) =3D= =3D 0 || strncmp(line, "UV_", 3) =3D=3D 0) )
+ && (strncmp(line, &q= uot;IV_", 3) =3D=3D 0 || strncmp(line, "UV_", 3) =3D=3D 0))<= /span>
{
msg(M_INFO, "p= eer info: %s", line);
env_set_add(es, lin= e);
diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h
index c6e2fa51..07ac92d 100644
--- a/src/open= vpn/misc.h
+++ b/src/openvpn/misc.h
@@ -43,= 8 +43,7 @@

const char **make_arg_array(c= onst char *first, const char *parms, struct gc_arena *gc);
=
-const char **make_ex= tended_arg_array(char **p, bool is_inline,
- struct gc_arena *= gc);
+const char **ma= ke_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc);

/* prepend a random prefix to hostname */
const char *hostname_randomize(const char *hostname, struct g= c_arena *gc);
@@ -77,9 +76,10 @@
/*=
* Challenge response info on client as pushed by server.=
*/
-struct = auth_challenge_info {
-= #define CR_ECHO (1<<0) /* echo response when typed by user */
-#define CR_RESPONSE (1&l= t;<1) /* response needed */
+struct auth_challenge_info
+{
= +#define CR_ECHO (1 << 0) /* echo response when typed by user */<= /span>
+#define CR_RESPONSE = (1 << 1) /* response needed */
unsigned int flag= s;

const char *user;
@@ -90,38 +90,43 @@

/*
* Challenge resp= onse info on client as pushed by server.
*/
-struct static_challenge_info {
-#define SC_ECHO (1<= <0) /* echo response when typed by user */
-#define SC_CONCAT (1<<1) /* concatenate p= assword and response and do not base64 encode */
+struct static_challenge_info
+{
+#define SC_ECHO (1 << 0) /* echo response when = typed by user */
+#de= fine SC_CONCAT (1 << 1) /* concatenate password and response and do n= ot base64 encode */
unsigned int flags;

const char *challenge_text;
};

#else /* ifdef ENABLE_MANAGEMENT */
-struct auth_challenge_info = {};
-struct static_chal= lenge_info {};
+struc= t auth_challenge_info
+{
+};
+struct static_challenge_info
+{
+};
#endif /* ifdef ENABL= E_MANAGEMENT */

/*
* F= lags for get_user_pass and management_query_user_pass
*/<= /span>
-#define GET_USER_PASS_= MANAGEMENT (1<<0)
+#define GET_USER_PASS_MANAGEMENT (1 << 0) /* GET_USER_PASS_SENSITIVE (1<<1) not used anymore */
-#define GET_USER_PASS_PA= SSWORD_ONLY (1<<2)
-#define GET_USER_PASS_NOFATAL (1<&= lt;4)
-#define GET_USER= _PASS_NEED_STR (1<<5)
-#define GET_USER_PASS_PREVIOUS_CREDS_FAILED (1<<6)<= br>+#define GET_USER_PASS_PASSW= ORD_ONLY (1 << 2)
+#define GET_USER_PASS_NEED_OK (1 << 3)
+#define GET_USER_PASS_NO= FATAL (1 << 4)
+#define GET_USER_PASS_NEED_STR (1 << 5)
+#define GET_USER_PASS= _PREVIOUS_CREDS_FAILED (1 << 6)

-#define GET_USER_PASS_DYNAMIC_CHALLENGE = (1<<7) /**< CRV1 protocol -- dynamic challenge */
<= span style=3D"color: hsl(0, 100%, 40%);">-#define GET_USER_PASS_STATIC_CHAL= LENGE (1<<8) /**< SCRV1 protocol -- static challenge */
-#define GET_USER_PASS_STAT= IC_CHALLENGE_ECHO (1<<9) /**< SCRV1 protocol -- echo response */<= /span>
+#define GET_USER_PAS= S_DYNAMIC_CHALLENGE (1 << 7) /**< CRV1 protocol -- dynamic ch= allenge */
+#define G= ET_USER_PASS_STATIC_CHALLENGE (1 << 8) /**< SCRV1 protocol --= static challenge */
= +#define GET_USER_PASS_STATIC_CHALLENGE_ECHO (1 << 9) /**< SCRV1 p= rotocol -- echo response */

/** indicate= s that auth_file is actually inline creds */
-#define GET_USER_PASS_INLINE_CREDS (1<<10)

+#define GET_USER_PASS_I= NLINE_CREDS (1 << 10)
/** indicates passw= ord and response should be concatenated */
-#define GET_USER_PASS_STATIC_CHALLENGE_CONCAT (1<&l= t;11)
+#define GET_US= ER_PASS_STATIC_CHALLENGE_CONCAT (1 << 11)
/**
* Retrieves the user credentials from various= sources depending on the flags.
@@ -133,11 +138,8 @@
* @param auth_challenge The authentication challenge string.
* @return true if the user credentials were successfully r= etrieved, false otherwise.
*/
-bool get_user_pass_cr(struct user_pass *up,
- const= char *auth_file,
- = const char *prefix,
- const unsigned int flags,
<= span style=3D"color: hsl(0, 100%, 40%);">- const char = *auth_challenge);

+bo= ol get_user_pass_cr(struct user_pass *up, const char *auth_file, const char= *prefix,
+ = const unsigned int flags, const char *auth_challenge);
/**
* Retrieves the user crede= ntials from various sources depending on the flags.
@@ -149= ,9 +151,7 @@
* @return true if the user credentials were = successfully retrieved, false otherwise.
*/
static inline bool

= -get_user_pass(struct user_pass *up,
- const char *auth_file,
- const char *prefix,+get_user_pass(struct user_pas= s *up, const char *auth_file, const char *prefix,
= const unsigned int flags)
{
ret= urn get_user_pass_cr(up, auth_file, prefix, flags, NULL);
@= @ -206,29 +206,24 @@
/**
* Prepend a dir= ectory to a path.
*/
-struct buffer
-prepend_dir(const char *dir, const char *path, struct gc_arena *gc= );
+struct buffer pre= pend_dir(const char *dir, const char *path, struct gc_arena *gc);
/**
* Encrypt username and pass= word buffers in user_pass
*/
-void
-protect_user_pass(struct user_pass *up);
+void protect_user_pass(struct user_pass *up);<= /span>

/**
* Decrypt username= and password buffers in user_pass
*/
-void
-unprotect_user_pass(struct user_pass *up);
+void unprotect_user_pass(struct use= r_pass *up);



-#define _STRINGIFY(S) #S
+#define _STRINGIFY(S) #S
= /* *INDENT-OFF* - uncrustify need to ignore this macro */
= -#define MAC_FMT _STRINGIFY(%02hh= x:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx)
+#define MAC_FMT _STRINGIFY(%02hhx:%02hhx:%02h= hx:%02hhx:%02hhx:%02hhx)
/* *INDENT-ON* */
-#define MAC_PRINT_ARG(_mac) _mac[0], = _mac[1], _mac[2], \

- = _mac[3], _mac[4], _mac[5]
-#define MAC_SCAN_ARG(_mac) &_mac[0], &_mac[1], &_mac[2],= \
- &_mac[3], &= amp;_mac[4], &_mac[5]
+#define MAC_PRINT_ARG(_mac) _mac[0], _mac[1], _mac[2], _mac[3], _mac[= 4], _mac[5]
+#define = MAC_SCAN_ARG(_mac) &_mac[0], &_mac[1], &_mac[2], &_mac[3],= &_mac[4], &_mac[5]

#endif /* if= ndef MISC_H */
diff --git a/src/openvpn/mroute.c b/src/open= vpn/mroute.c
index a617b33..4692cbf 100644
= --- a/src/openvpn/mroute.c
+++ b/src/openvpn/mroute.c
@@ -48,14 +48,13 @@
static inline bool is_mac_mcast_addr(const uint8_t *mac)
{- return (bool) (mac[0] &= 1);
+ return (boo= l)(mac[0] & 1);
}

s= tatic inline bool
is_mac_mcast_maddr(const struct mroute_a= ddr *addr)
{
- return (addr->type & MR_ADDR_MASK) =3D=3D MR_ADDR_ETHER<= /span>
- && = is_mac_mcast_addr(addr->ether.addr);
+ return (addr->type & MR_ADDR_MASK) =3D=3D MR= _ADDR_ETHER && is_mac_mcast_addr(addr->ether.addr);
}


/*
@@ -82,8 +81,7= @@
}

/* only n= etworkss shorter than 8 bits are allowed to be all 0s. */
- if (all_zeros
- && !((addr->type & M= R_WITH_NETBITS) && (addr->netbits < 8)))
+ if (all_zeros && !((addr->= ;type & MR_WITH_NETBITS) && (addr->netbits < 8)))<= br> {
msg(D_MULTI_LOW, "Can't l= earn %s: network is all 0s, but netbits >=3D 8",
= mroute_addr_print(addr, gc));
@@ -92,8 +90,7 @@<= /span>

if (all_ones)
{=
- msg(D_MULTI_L= OW, "Can't learn %s: network is all 1s",
- mroute_addr_print(addr, gc));<= /span>
+ msg(D_MULTI_= LOW, "Can't learn %s: network is all 1s", mroute_addr_print(a= ddr, gc));
return false;
}

@@ -148,8 +145,7 @@


unsigned int
-mroute_extract_addr_ip(struct mroute_addr *src, struct= mroute_addr *dest,
- = const struct buffer *buf)
+mroute_extract_addr_ip(struct mroute_addr *src, = struct mroute_addr *dest, const struct buffer *buf)
{
unsigned int ret =3D 0;
if (BLEN(buf)= >=3D 1)
@@ -157,9 +153,9 @@
sw= itch (OPENVPN_IPH_GET_VER(*BPTR(buf)))
{ case 4:
- if (BLEN(buf) >=3D (int) sizeof(struct openvpn_iph= dr))
+ = if (BLEN(buf) >=3D (int)sizeof(struct openvpn_iphdr))
= {
- = const struct openvpn_iphdr *ip =3D (const struct openvpn_ip= hdr *) BPTR(buf);
+ = const struct openvpn_iphdr *ip =3D (const struct openvpn_= iphdr *)BPTR(buf);

m= route_get_in_addr_t(src, ip->saddr, 0);
= mroute_get_in_addr_t(dest, ip->daddr, 0);
@@ -181,1= 0 +177,10 @@
break;

case 6:
- if (BLEN(buf) >=3D (int) sizeof(struct openvp= n_ipv6hdr))
+ = if (BLEN(buf) >=3D (int)sizeof(struct openvpn_ipv6hdr)) {
- const struct openvpn_ipv6hdr *ipv6 =3D (const stru= ct openvpn_ipv6hdr *) BPTR(buf);
-#if 0 /* very basic debug */+ const str= uct openvpn_ipv6hdr *ipv6 =3D (const struct openvpn_ipv6hdr *)BPTR(buf);
+#if 0 /* very basic de= bug */
struct gc_arena gc =3D gc_new()= ;
msg( M_INFO, "IPv6 packet! src= =3D%s, dst=3D%s",
print_in6_= addr( ipv6->saddr, 0, &gc ),
@@ -213,9 +209,7 @@
}

static void
-mroute_copy_ether_to_addr(struct m= route_addr *maddr,

- = const uint8_t *ether_addr,
- uint16_t vid)<= br>+mroute_copy_ether_to_addr(s= truct mroute_addr *maddr, const uint8_t *ether_addr, uint16_t vid) {
maddr->type =3D MR_ADDR_ETHER; maddr->netbits =3D 0;
@@ -226,15 +220,13 @@<= /span>
}

unsigned int-mroute_extract_addr_ether(stru= ct mroute_addr *src,
- = struct mroute_addr *dest,
- uint16_t vid,=
+mroute_extract_addr_ether(= struct mroute_addr *src, struct mroute_addr *dest, uint16_t vid,
= const struct buffer *buf)
= {
unsigned int ret =3D 0;
- if (BLEN(buf) >=3D (int) sizeof(struct ope= nvpn_ethhdr))
+ if= (BLEN(buf) >=3D (int)sizeof(struct openvpn_ethhdr))
= {
- const stru= ct openvpn_ethhdr *eth =3D (const struct openvpn_ethhdr *) BPTR(buf);
+ const struct open= vpn_ethhdr *eth =3D (const struct openvpn_ethhdr *)BPTR(buf);
if (src)

{
= mroute_copy_ether_to_addr(src, eth->source, vid);
@@ -= 251,7 +243,6 @@
}

ret |=3D MROUTE_EXTRACT_SUCCEEDED;

-
}
return= ret;
}
@@ -261,8 +252,7 @@
* to a struct mroute_addr (addr).

*/
= bool
-mroute_extract_o= penvpn_sockaddr(struct mroute_addr *addr,
- const struct openvpn_so= ckaddr *osaddr,
+mrou= te_extract_openvpn_sockaddr(struct mroute_addr *addr, const struct openvpn_= sockaddr *osaddr,
bool use= _port)
{
switch (osaddr->addr.sa.s= a_family)
@@ -336,7 +326,7 @@
}=
else if ((ma->type & MR_ADDR_MASK) =3D=3D MR_ADDR_IPV= 6)
{
- int byte =3D sizeof(ma->v6.addr) - 1; /* rightmost byte = in address */
+ = int byte =3D sizeof(ma->v6.addr) - 1; /* rightmost byte in address */<= /span>
int bits_to_clear =3D 128 - ma->netbits;=

while (byte >=3D 0 && bits_= to_clear > 0)
@@ -352,7 +342,7 @@
= bits_to_clear =3D 0;
}
}

- = ASSERT( bits_to_clear =3D=3D 0 );
+ ASSERT(bits_to_clear =3D=3D 0);
= }
else
{
@@ -368= ,29 +358,24 @@
uint32_t
mroute_addr_hash_= function(const void *key, uint32_t iv)
{
- return hash_func(mroute_addr_hash_p= tr((const struct mroute_addr *) key),
- mroute_addr_hash_len((const struct mro= ute_addr *) key),
- = iv);
+ return hash_func(mroute_addr_hash_ptr((const struct mroute_addr *)key= ),
+ = mroute_addr_hash_len((const struct mroute_addr *)key), iv);
<= span> }


bool
mroute_add= r_compare_function(const void *key1, const void *key2)
{
- return mroute_addr_= equal((const struct mroute_addr *) key1,
- (const struct mroute_addr *= ) key2);
+ return = mroute_addr_equal((const struct mroute_addr *)key1, (const struct mroute_ad= dr *)key2);
}

const cha= r *
-mroute_addr_print(= const struct mroute_addr *ma,
- struct gc_arena *gc)
+mroute_addr_print(const struct mroute_addr *ma, = struct gc_arena *gc)
{
return mroute_= addr_print_ex(ma, MAPF_IA_EMPTY_IF_UNDEF, gc);
}
const char *
-mroute_addr_print_ex(const struct mroute_addr *ma,<= br>- const un= signed int flags,
- = struct gc_arena *gc)
+mroute_addr_print_ex(const struct mroute_addr *ma, const = unsigned int flags, struct gc_arena *gc)
{
struct buffer out =3D alloc_buf_gc(64, gc);

if (= ma)
@@ -400,8 +385,8 @@
switch (ma= ddr.type & MR_ADDR_MASK)
{
= case MR_ADDR_ETHER:
- buf_printf(&out, "%s", format_hex_ex(= ma->ether.addr,
- = sizeof(ma->ether.addr)= , 0, 1, ":", gc));
+ buf_printf(&out, "%s",
+ format= _hex_ex(ma->ether.addr, sizeof(ma->ether.addr), 0, 1, ":", = gc));

buf_printf(&out, "@%hu"= ;, ma->ether.vid);
break;

@@ -415,8 +400,10 @@
= {
buf_printf(&out, "%s:"= , proto2ascii(maddr.proto, AF_INET, false));
= }
- b= uf_printf(&out, "%s", print_in_addr_t(ntohl(maddr.v4.addr),
- = (flags & MAPF_IA_EMPTY_IF_UNDEF) ? IA_E= MPTY_IF_UNDEF : 0, gc));
+ buf_printf(&out, "%s",
+ print_in_a= ddr_t(ntohl(maddr.v4.addr),
+ (flags & MAPF_IA_EMP= TY_IF_UNDEF) ? IA_EMPTY_IF_UNDEF : 0,
+ gc)); if (maddr.type & MR_WITH_NETBITS)
{

if (flags &= MAPF_SUBNET)
@@ -442,10 +429,10 @@
= {
buf_printf(&out, "= ;%s:", proto2ascii(maddr.proto, AF_INET6, false));
= }
- = if (IN6_IS_ADDR_V4MAPPED( &maddr.v6.addr ) )
+ if (IN6_IS_ADDR_V4MA= PPED(&maddr.v6.addr))
{
- buf_printf(&= out, "%s", print_in_addr_t(maddr.v4mappedv6.addr,

- = IA_NET_ORDER, gc));

+ buf_printf(&out, "%s&quo= t;,
+ = print_in_addr_t(maddr.v4mappedv6.addr, IA_NET_ORDER, gc));
}
else if = (maddr.type & MR_WITH_PORT)
{@@ -501,7 +488,7 @@
{
= if (mh->net_len_refcount[i] > 0)
{- mh->net_len[j++= ] =3D (uint8_t) i;
+ = mh->net_len[j++] =3D (uint8_t)i;
}
}
mh->n_net_len =3D j;diff --git a/src/openvpn/mroute.h b/src/openvpn/mroute.h
= index c359fd2..08e8f6e 100644
--- a/src/openvpn/mrout= e.h
+++ b/src/openvpn/mroute.h
@@ -30,22 +3= 0,22 @@

#include <stddef.h>=

-#define IP= _MCAST_SUBNET_MASK ((in_addr_t)240<<24)
-#define IP_MCAST_NETWORK ((in_addr_t)224<&= lt;24)
+#define IP_MC= AST_SUBNET_MASK ((in_addr_t)240 << 24)
+#define IP_MCAST_NETWORK ((in_addr_t)224 <&= lt; 24)

/* Return status values for mrou= te_extract_addr_from_packet */

-#define MROUTE_EXTRACT_SUCCEEDED (1<<0)
-#define MROUTE_EXTRACT_B= CAST (1<<1)
-= #define MROUTE_EXTRACT_MCAST (1<<2)
-#define MROUTE_EXTRACT_IGMP (1<<3)
+#define MROUTE_EXTRACT_SU= CCEEDED (1 << 0)
+#define MROUTE_EXTRACT_MCAST (1 <<= 2)
+#define MROUTE_E= XTRACT_IGMP (1 << 3)

-#define MROUTE_SEC_EXTRACT_SUCCEEDED (1<<= (0+MROUTE_SEC_SHIFT))
-= #define MROUTE_SEC_EXTRACT_BCAST (1<<(1+MROUTE_SEC_SHIFT))=
-#define MROUTE_SEC_EXTRACT_M= CAST (1<<(2+MROUTE_SEC_SHIFT))
-#define MROUTE_SEC_EXTRACT_IGMP (1<<(3+MROUTE= _SEC_SHIFT))
+#define= MROUTE_SEC_EXTRACT_SUCCEEDED (1 << (0 + MROUTE_SEC_SHIFT))+#define MROUTE_SEC_EXTRACT_BC= AST (1 << (1 + MROUTE_SEC_SHIFT))
+#define MROUTE_SEC_EXTRACT_MCAST (1 << (2= + MROUTE_SEC_SHIFT))
+#define MROUTE_SEC_EXTRACT_IGMP (1 << (3 + MROUTE_SEC_SHIFT))<= /span>

-#def= ine MROUTE_SEC_SHIFT 4
+#define MROUTE_SEC_SHIFT 4

/*=
* Choose the largest address possible with
@@ -57,60 +57,64 @@

/*
* Address Type= s
*/
= -#define MR_ADDR_NONE 0
-#define MR_ADDR_ETHER 1
-#define MR_ADDR_IPV4 2
-#define MR_ADDR_IPV6 3<= /span>
-#define MR_ADDR_MASK = 3
+#define= MR_ADDR_NONE 0
+#de= fine MR_ADDR_ETHER 1
= +#define MR_ADDR_IPV4 2
+#define MR_ADDR_IPV6 3
+#define MR_ADDR_MASK 3

/* Addr= ess type mask indicating that port # is part of address */
-#define MR_WITH_PORT 4

+#define MR_WITH_PORT 4<= /span>

/* Address type mask indicating that net= bits is part of address */
-#define MR_WITH_NETBITS 8
+#define MR_WITH_NETBITS 8

<= span> /* Indicates than IPv4 addr was extracted from ARP packet */
-#define MR_ARP = 16
+#define MR_ARP= 16

/* Address type mask indicating that= proto # is part of address */
-#define MR_WITH_PROTO 32
+#define MR_WITH_PROTO 32
<= br>-struct mroute_addr {- uint8_t len; /* length = of address */
+struct= mroute_addr
+{
+ uint8_t len; /* l= ength of address */
uint8_t proto;
- uint8_t type; /* MR_ADDR/MR_WITH fl= ags */
+ uint8_t t= ype; /* MR_ADDR/MR_WITH flags */
uint8_t netbits; /= * number of bits in network part of address,
= * valid if MR_WITH_NETBITS is set */
- union {
+ union
+ {
uint8_t raw_addr[MR_MAX_ADDR_LEN]; /* = actual address */
- = struct {
+ = struct
+ {
uint8_t addr[OPENVPN_ETH_ALEN];
= uint16_t vid;
} ether;
- struct {

- in_addr_t addr; /* _netwo= rk order_ IPv4 address */
- in_port_t port; /* _network order_ TCP/UDP port */
+ struct+ {
+ in_addr_t addr; /* _network= order_ IPv4 address */
+ in_port_t port; /* _network order_ TCP/UDP port */ } v4;
= - struct {
+ = struct
+ = {
struct in6_addr addr;
- in_port_t port; /* _network= order_ TCP/UDP port */
+ in_port_t port; /* _network order_ TCP/UDP port */ } v6;
= - struct {
+ = struct
+ = {
uint8_t prefix[12];
- in_addr_t addr; /* _network= order_ IPv4 address */
+ in_addr_t addr; /* _network order_ IPv4 address */ } v4mappedv6;
};
};<= /span>

/* Double-check that struct packing work= s as expected */
-stati= c_assert(offsetof(struct mroute_addr, v4.port) =3D=3D
- offsetof(struct mroute_addr, = v4) + 4,
+static_asse= rt(offsetof(struct mroute_addr, v4.port) =3D=3D offsetof(struct mroute_addr= , v4) + 4,
"Unexpected struct packing o= f v4");
-static_as= sert(offsetof(struct mroute_addr, v6.port) =3D=3D
- offsetof(struct mroute_addr, v6) = + 16,
+static_assert(= offsetof(struct mroute_addr, v6.port) =3D=3D offsetof(struct mroute_addr, v= 6) + 16,
"Unexpected struct packing of = v6");
-static_asse= rt(offsetof(struct mroute_addr, v4mappedv6.addr) =3D=3D
- offsetof(struct mroute_addr= , v4mappedv6) + 12,
+= static_assert(offsetof(struct mroute_addr, v4mappedv6.addr)
+ =3D=3D offsetof(s= truct mroute_addr, v4mappedv6) + 12,

"U= nexpected struct packing of v4mappedv6");

= /*
@@ -121,22 +125,21 @@
/*<= br> * Used to help maintain CIDR routing table.
*/=
-struct mroute_helper = {
- unsigned int cac= he_generation; /* incremented when route added */
- int ageable_ttl_secs; /* host route = cache entry time-to-live*/
- int n_net_len; /* length of net_len array */<= br>- uint8_t net_len[MR_HELPER= _NET_LEN]; /* CIDR netlengths in descending order */
+struct mroute_helper
+{
+ unsigned int cache_generation; /* incremen= ted when route added */
+ int ageable_ttl_secs; /* host route cache entry = time-to-live*/
+ i= nt n_net_len; /* length of net_len array */
+ uint8_t net_len[MR_HE= LPER_NET_LEN]; /* CIDR netlengths in descending order */
int net_len_refcount[MR_HELPER_NET_LEN]; /* refcount of each netlen= gth */

};

struct openvp= n_sockaddr;

bool mroute_extract_openvpn_= sockaddr(struct mroute_addr *addr,
- const struct openvpn_sock= addr *osaddr,
- = bool use_port);
+ const struct = openvpn_sockaddr *osaddr, bool use_port);

-bool mroute_learnable_address(const s= truct mroute_addr *addr,

+bool mroute_learnable_address(const stru= ct mroute_addr *addr, struct gc_arena *gc);

uint32_t mroute_addr_hash_function(const void *key, uint32_t iv);

@@ -144,14 +147,12 @@
=
void mroute_addr_init(struct mroute_addr *addr);

-const char *mroute_= addr_print(const struct mroute_addr *ma,
- struct gc_arena *gc);
+const char *mroute_addr_= print(const struct mroute_addr *ma, struct gc_arena *gc);
=
-#define MAPF_SUBNET = (1<<0)
= -#define MAPF_IA_EMPTY_IF_UNDEF (1<<1)
-#define MAPF_SHOW_ARP (1<<2)-const char *mroute_addr_print_= ex(const struct mroute_addr *ma,
- const unsigned int flags,
+#define MAPF_SUBNET = (1 << 0)
= +#define MAPF_IA_EMPTY_IF_UNDEF (1 << 1)
+#define MAPF_SHOW_ARP (1 << 2)
+const char *mroute_add= r_print_ex(const struct mroute_addr *ma, const unsigned int flags, struct gc_arena *gc);
<= span>

void mroute_addr_mask_host_bits(struct mroute_addr = *ma);
@@ -164,25 +165,19 @@

void mroute_helper_del_iroute46(struct mroute_helper *mh, int netbits);=


-uns= igned int mroute_extract_addr_ip(struct mroute_addr *src,
- str= uct mroute_addr *dest,
-unsigned int mroute_extract_addr_ether(struct mroute_addr *= src,
- = struct mroute_addr *dest,
- uint16_t v= id,
- = const struct buffer *buf);
+unsigned int mroute_extract_addr_ether(struct m= route_addr *src, struct mroute_addr *dest,
+ uint16_t vid,= const struct buffer *buf);

/* * Given a raw packet in buf, return the src and dest
* addresses of the packet.

*/
stati= c inline unsigned int
-= mroute_extract_addr_from_packet(struct mroute_addr *src,
- struct m= route_addr *dest,
- = uint16_t vid,
- const struct buffer *bu= f,
- = int tunnel_type)
+mroute_extract_addr_from_packet(struct mroute_addr *src, struct m= route_addr *dest, uint16_t vid,
+ const struct buffer *buf, int t= unnel_type)
{
unsigned int ret =3D 0;=
verify_align_4(buf);
@@ -232,13 +227,= 13 @@
mroute_addr_hash_ptr(const struct mroute_addr *a)
{
/* NOTE: depends on ordering of struc= t mroute_addr */
- r= eturn (uint8_t *) &a->proto;
+ return (uint8_t *)&a->proto;
}<= /span>

static inline uint32_t
= mroute_addr_hash_len(const struct mroute_addr *a)
{=
- return (uint32_t) a->= len + 3;
+ return = (uint32_t)a->len + 3;
}

static inline void

diff --git a/src/openvpn/mss.c b/src= /openvpn/mss.c
index 01ccdeb..2ab839c 100644
--- a/src/openvpn/mss.c

+++ b/src/openvpn/mss.c@@ -49,27 +49,24 @@
const struct openvpn_iphdr = *pip;
int hlen;

- if (BLEN(buf) < (int) sizeof(struct= openvpn_iphdr))
+ = if (BLEN(buf) < (int)sizeof(struct openvpn_iphdr))
= {
return;
}
=
verify_align_4(buf);
- pip =3D (struct openvpn_iphdr *) BPTR(buf);
+ pip =3D (struct openv= pn_iphdr *)BPTR(buf);

hlen =3D OPENV= PN_IPH_GET_LEN(pip->version_len);

- if (pip->protocol =3D=3D OPENVPN_IP= PROTO_TCP
- &= ;& ntohs(pip->tot_len) =3D=3D BLEN(buf)
- && (ntohs(pip->frag_off) & = OPENVPN_IP_OFFMASK) =3D=3D 0
- && hlen <=3D BLEN(buf)
- && BLEN(buf) - hlen
- >=3D (int) sizeof(struc= t openvpn_tcphdr))

+ = if (pip->protocol =3D=3D OPENVPN_IPPROTO_TCP && ntohs(pip->= ;tot_len) =3D=3D BLEN(buf)
+ && (ntohs(pip->frag_off) & OPENVPN_IP_OFFMASK= ) =3D=3D 0 && hlen <=3D BLEN(buf)
+ && BLEN(buf) - hlen >=3D (int)s= izeof(struct openvpn_tcphdr))
{
= struct buffer newbuf =3D *buf;
if (buf_advance(= &newbuf, hlen))
{
- struct openvpn_tcphdr *tc =3D (struct = openvpn_tcphdr *) BPTR(&newbuf);
+ struct openvpn_tcphdr *tc =3D (struct openvpn_= tcphdr *)BPTR(&newbuf);
if (tc->flags &= amp; OPENVPN_TCPH_SYN_MASK)
{
= mss_fixup_dowork(&newbuf, maxmss);
@@ = -89,18 +86,18 @@
const struct openvpn_ipv6hdr *pip6;
struct buffer newbuf;

- if (BLEN(buf) < (int) sizeof(s= truct openvpn_ipv6hdr))

+ if (BLEN(buf) < (int)sizeof(struct openvpn_ipv6hdr))
<= span> {

return;
}<= br>
verify_align_4(buf);
- pip6 =3D (struct openvpn_ipv6hdr *) BPT= R(buf);
+ pip6 =3D= (struct openvpn_ipv6hdr *)BPTR(buf);

= /* do we have the full IPv6 packet?
* "payload= _len" does not include IPv6 header (+40 bytes)
*= /
- if (BLEN(buf) != =3D (int) ntohs(pip6->payload_len)+40)
+ if (BLEN(buf) !=3D (int)ntohs(pip6->payload_le= n) + 40)
{
return;
= }
@@ -124,13 +121,12 @@
* = verify remainder is large enough to contain a full TCP header
*/

newbuf =3D *buf;
- if (buf_advance( &newbuf, 40 )- && BLEN(&n= ewbuf) >=3D (int) sizeof(struct openvpn_tcphdr))
+ if (buf_advance(&newbuf, 40) &= ;& BLEN(&newbuf) >=3D (int)sizeof(struct openvpn_tcphdr))=
{
- = struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *) BPTR(&newbuf= );
+ struct op= envpn_tcphdr *tc =3D (struct openvpn_tcphdr *)BPTR(&newbuf);
= if (tc->flags & OPENVPN_TCPH_SYN_MASK)
{

- = mss_fixup_dowork(&newbuf, maxmss-20);
+ mss_fixup_dowork(&newbuf, maxmss -= 20);
}
}
}<= /span>
@@ -149,25 +145,22 @@
int accumulate;<= /span>
struct openvpn_tcphdr *tc;
- if (BLEN(buf) < (int) si= zeof(struct openvpn_tcphdr))
+ if (BLEN(buf) < (int)sizeof(struct openvpn_tcphdr))<= br> {
return;
}

verify_align_4(buf);
- tc =3D (struct openvpn_tcphdr *) BPT= R(buf);
+ tc =3D (= struct openvpn_tcphdr *)BPTR(buf);
hlen =3D OPENVPN_TC= PH_GET_DOFF(tc->doff_res);

/* Inv= alid header length or header without options. */
- if (hlen <=3D (int) sizeof(struct openvpn= _tcphdr)
- || hl= en > BLEN(buf))
+ = if (hlen <=3D (int)sizeof(struct openvpn_tcphdr) || hlen > BLEN(bu= f))
{
return;
}


- for (olen =3D hlen - (int) sizeof(struct openvpn_tcphdr),- opt =3D (uint8_t *)(tc= + 1);
- olen &= gt; 1;
+ for (olen= =3D hlen - (int)sizeof(struct openvpn_tcphdr), opt =3D (uint8_t *)(tc + 1)= ; olen > 1;
olen -=3D optlen, opt +=3D optlen)=
{
if (*opt =3D=3D OPENVPN_TC= POPT_EOL)
@@ -197,8 +190,8 @@
= {
dmsg(D_MSS, "MSS: %" P= RIu16 " -> %" PRIu16, mssval, maxmss);
= accumulate =3D htons(mssval);
- opt[2] =3D (uint8_t)((maxmss>&= gt;8)&0xff);
- = opt[3] =3D (uint8_t)(maxmss&0xff);
+ opt[2] =3D (uint8_t)(= (maxmss >> 8) & 0xff);
+ opt[3] =3D (uint8_t)(maxmss & 0xff);
accumulate -=3D htons(maxmss); ADJUST_CHECKSUM(accumulate, tc->check);
}
@@ -228,8 +221,7 @@<= br> }

static size_t
-get_ip_encap_overhead(const struct o= ptions *options,

- = const struct link_socket_info *lsi)
+get_ip_encap_overhead(const struct option= s *options, const struct link_socket_info *lsi)
{ /* Add the overhead of the encapsulating IP packets */<= br> sa_family_t af;
@@ -253,8 +245,7 @@ }

static void
-frame_calculate_fragment(struct frame *f= rame, struct key_type *kt,
- const struct options *options,
+frame_calculate_fragment(struct fr= ame *frame, struct key_type *kt, const struct options *options,

<= span> struct link_socket_info *lsi)

{

#if defined(ENABLE_FRAGMENT)
@@ -284,= 8 +275,7 @@
}

static vo= id
-frame_calculate_mss= fix(struct frame *frame, struct key_type *kt,
- const struct options *option= s,
+frame_calculate_m= ssfix(struct frame *frame, struct key_type *kt, const struct options *optio= ns,
struct link_socket_info *lsi)
{
if (options->ce.mssfix_fixed)
@@ -327,13 +317,10 @@
/* This is the targ= et value our payload needs to be smaller */
size_t tar= get =3D options->ce.mssfix - overhead;
frame->ms= s_fix =3D (uint16_t)(adjust_payload_max_cbc(kt, target) - payload_overhead)= ;
-
-
}

void
-fra= me_calculate_dynamic(struct frame *frame, struct key_type *kt,
- const stru= ct options *options,

= +frame_calculate_dynamic(struct frame *frame, struct key_type *kt, const st= ruct options *options,
struct link= _socket_info *lsi)
{
if (options->= ce.fragment > 0)
@@ -364,30 +351,29 @@
= int encap_overhead =3D datagram_overhead(af, proto);
<= /span>
/* check if mssfix and fragment need to be adjusted */=
- if (pmtu < o-&= gt;ce.mssfix
- |= | (o->ce.mssfix_encap && pmtu < o->ce.mssfix + encap_overh= ead))
+ if (pmtu &= lt; o->ce.mssfix || (o->ce.mssfix_encap && pmtu < o->ce= .mssfix + encap_overhead))
{
= const char *mtustr =3D o->ce.mssfix_encap ? " mtu" : "&qu= ot;;
- msg(D_MTU= _INFO, "Note adjusting 'mssfix %d%s' to 'mssfix %d mtu'= ; "
- &= quot;according to path MTU discovery", o->ce.mssfix,
- mtustr, pmtu);
+ msg(D_MTU_INFO,
+ "Note ad= justing 'mssfix %d%s' to 'mssfix %d mtu' "
<= span style=3D"color: hsl(120, 100%, 40%);">+ "according to = path MTU discovery",

+ o->ce.mssfix, mtustr, pmtu);
= o->ce.mssfix =3D pmtu;
o->ce.mssfix_encap = =3D true;
frame_calculate_dynamic(&c->c2.fr= ame, &c->c1.ks.key_type, o, lsi);
}
<= span>

#if defined(ENABLE_FRAGMENT)
- if (pmtu < o->ce.fragment<= br>- || (o->ce.fragment= _encap && pmtu < o->ce.fragment + encap_overhead))
= + if (pmtu < o->ce.fra= gment || (o->ce.fragment_encap && pmtu < o->ce.fragment + = encap_overhead))
{
const char= *mtustr =3D o->ce.fragment_encap ? " mtu" : "";
- msg(D_MTU_INFO, &= quot;Note adjusting 'fragment %d%s' to 'fragment %d mtu' &q= uot;
- "= ;according to path MTU discovery", o->ce.fragment,
- mtustr, pmtu);
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(D_MTU_INFO,
<= br>+ "Note adju= sting 'fragment %d%s' to 'fragment %d mtu' "+ "according t= o path MTU discovery",
+ o->ce.fragment, mtustr, pmtu);
= o->ce.fragment =3D pmtu;
o->ce.fragment_= encap =3D true;
- = frame_calculate_dynamic(&c->c2.frame_fragment, &c->c1.ks.ke= y_type,
- = o, lsi);
+ frame_calculate_dynamic(&c->c2.frame_fragment, &c= ->c1.ks.key_type, o, lsi);
}
#endi= f
}
diff --git a/src/openvpn/mss.h b/src/o= penvpn/mss.h
index 426af5e..46a956e 100644
= --- a/src/openvpn/mss.h
+++ b/src/openvpn/mss.h
<= span>@@ -37,8 +37,7 @@


/** Set the --mss= fix option. */
void frame_calculate_dynamic(struct frame *= frame, struct key_type *kt,
- const struct options *options,- st= ruct link_socket_info *lsi);
+ const struct options *options, struct= link_socket_info *lsi);

/**
<= span> * Checks and adjusts the fragment and mssfix value according to the<= /span>
diff --git a/src/openvpn/mstats.c b/src/openvpn/mstats.c
index cbef26a..b9c6741 100644
--- a/src/openv= pn/mstats.c
+++ b/src/openvpn/mstats.c
@@ -= 84,7 +84,7 @@
}

= /* mmap the file */
- = data =3D mmap(NULL, sizeof(struct mmap_stats), PROT_READ|PROT_WRITE, MAP= _SHARED, fd, 0);
+ = data =3D mmap(NULL, sizeof(struct mmap_stats), PROT_READ | PROT_WRITE, MAP= _SHARED, fd, 0);
if (data =3D=3D MAP_FAILED) {
msg(M_ERR, "mstats_open: write = error: %s", fn);
diff --git a/src/openvpn/mstats.h b/s= rc/openvpn/mstats.h
index ea0237f..8d63457 100644--- a/src/openvpn/mstats.h
+++ b/src/openvpn/mstats.= h
@@ -31,7 +31,8 @@
#include "basic.h= "

/* this struct is mapped to the f= ile */
-struct mmap_sta= ts {
+struct mmap_sta= ts
+{
counter_type link_read_bytes; /* counter_type can be assumed to be a = uint64_t */

counter_type link_write_bytes;
<= span> int n_clients;

diff --git a/src/openvpn/mtcp.c b/= src/openvpn/mtcp.c
index 71991dd..5bc2578 100644
= --- a/src/openvpn/mtcp.c
+++ b/src/openvpn/mtcp.c
@@ -67,8 +67,9 @@

i= f (he)
{
- struct multi_instance *oldmi =3D (struct multi_inst= ance *) he->value;
-= msg(D_MULTI_LOW, "MULTI TCP: new incoming client address m= atches existing client address -- new client takes precedence");
+ struct multi_= instance *oldmi =3D (struct multi_instance *)he->value;
+ msg(D_MULTI_LOW,<= br>+ "MULTI= TCP: new incoming client address matches existing client address -- new cl= ient takes precedence");
oldmi->did_re= al_hash =3D false;
multi_close_instance(m, old= mi, false);
he->key =3D &mi->real;
@@ -109,12 +110,10 @@
ASSERT(mi->con= text.c2.link_sockets[0]->info.lsa);
ASSERT(mi->c= ontext.c2.link_sockets[0]->mode =3D=3D LS_MODE_TCP_ACCEPT_FROM);<= br> ASSERT(mi->context.c2.link_sockets[0]->info.lsa->act= ual.dest.addr.sa.sa_family =3D=3D AF_INET
- || mi->context.c2.link_sockets[0]->inf= o.lsa->actual.dest.addr.sa.sa_family =3D=3D AF_INET6
- );
+ || mi->context.c2.link_sockets[0]= ->info.lsa->actual.dest.addr.sa.sa_family =3D=3D AF_INET6); mi->real.proto =3D mi->context.c2.link_sockets[0]->inf= o.proto;
- if (!mrou= te_extract_openvpn_sockaddr(&mi->real,
- &mi-&g= t;context.c2.link_sockets[0]->info.lsa->actual.dest,
- = true))
+ if (!m= route_extract_openvpn_sockaddr(
+ &mi->real, &mi->context.c2.link_socke= ts[0]->info.lsa->actual.dest, true))
{ msg(D_MULTI_ERRORS, "MULTI TCP: TCP client address is = undefined");
return false;
@@= -150,7 +149,8 @@
}

boo= l
-multi_tcp_process_ou= tgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const= unsigned int mpp_flags)
+multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct = multi_instance *mi,
+= const unsigned int mpp_flags)<= br> {
struct mbuf_item item;
= bool ret =3D true;
diff --git a/src/openvpn/mtcp.h b/src/= openvpn/mtcp.h
index 334d6eb..500aec2 100644
--- a/src/openvpn/mtcp.h

+++ b/src/openvpn/mtcp.h<= br>@@ -40,9 +40,11 @@

void multi_t= cp_instance_specific_free(struct multi_instance *mi);

-bool multi_tcp_process_ou= tgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_fla= gs);
+bool multi_tcp_= process_outgoing_link(struct multi_context *m, bool defer,
+ = const unsigned int mpp_flags);

-bool multi_tcp_process_outgoing_link_ready(stru= ct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flag= s);
+bool multi_tcp_p= rocess_outgoing_link_ready(struct multi_context *m, struct multi_instance *= mi,
+ = const unsigned int mpp_flags);
=
struct multi_instance *multi_create_instance_tcp(struct m= ulti_context *m, struct link_socket *sock);

diff --git a/src/openvpn/mtu.c b/src/openvpn/mtu.c

index= 78f1309..2b76387 100644
--- a/src/openvpn/mtu.c
= +++ b/src/openvpn/mtu.c
@@ -39,8 +39,7 @@
<= span>

/* allocate a buffer for socket or tun layer */
void
-all= oc_buf_sock_tun(struct buffer *buf,
- const struct frame *frame)
+alloc_buf_sock_tun(struct buffer *b= uf, const struct frame *frame)

{
/* a= llocate buffer for overlapped I/O */
*buf =3D alloc_bu= f(BUF_SIZE(frame));
@@ -60,8 +59,7 @@
}

size_t
-frame_calculate_protocol_header_size(const struct key_typ= e *kt,
- = const struct options *options,
+frame_calculate_protocol_header_size(cons= t struct key_type *kt, const struct options *options,
= bool occ)
{
/* Sum of all the overhead that reduces the usable packet size */
@@ -98,8 +96,7 @@

=
size_t
-fram= e_calculate_payload_overhead(size_t extra_tun,
- const struct opti= ons *options,
+frame_= calculate_payload_overhead(size_t extra_tun, const struct options *options,=
const struct key_type *k= t)
{
size_t overhead =3D 0;@@ -139,8 +136,7 @@
}

<= span> size_t

-frame_cal= culate_payload_size(const struct frame *frame,
- const struct options = *options,
+frame_calc= ulate_payload_size(const struct frame *frame, const struct options *options= ,
const struct key_type *kt)<= /span>
{
size_t payload_size =3D options->= ;ce.tun_mtu;
@@ -175,7 +171,7 @@
= * overhead */

/* overhead of BF-= CBC: 64 bit block size, 64 bit IV size */
- overhead +=3D 64/8 + 64/8;
+ overhead +=3D 64 / 8 + 64 / 8;
/* set ciphername to none, so its size does get add= ed in the
* fake_kt and the cipher is not tried t= o be resolved */
ciphername =3D "none";<= /span>
@@ -192,9 +188,7 @@
}

void
-fr= ame_print(const struct frame *frame,
- int level,
- const char *prefix)
+frame_print(const struct frame *frame, int leve= l, const char *prefix)
{
struct gc_ar= ena gc =3D gc_new();
struct buffer out =3D alloc_buf_g= c(256, &gc);
@@ -230,19 +224,18 @@
= {
#if defined(IP_MTU_DISCOVER)
= case AF_INET:
- = if (setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER,
- (vo= id *) &mtu_type, sizeof(mtu_type)))

+ if (setsockopt(sd, IPPROTO_IP, IP_MTU_D= ISCOVER, (void *)&mtu_type,
+ sizeof(mtu_type)))
{

-= msg(M_ERR, "Error setting IP_MTU_DISCOVER type=3D%= d on TCP/UDP socket",
- mtu_type);
+ msg(M_ERR, "Error setting IP_M= TU_DISCOVER type=3D%d on TCP/UDP socket", mtu_type);
= }
break;
=
#endif
#if defined(IPV6_MTU_DISCOVER)
case AF_INET6:
- if (setsockopt(sd, IPPROTO_IPV6, IPV6_M= TU_DISCOVER,
- = (void *) &mtu_type, sizeof(mtu_type)))
= + if (setsockopt= (sd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, (void *)&mtu_type,
+ siz= eof(mtu_type)))

{
= msg(M_ERR, "Error setting IPV6_MTU_DISCOVER type=3D%d on = TCP6/UDP6 socket",
mtu_type);=
@@ -273,13 +266,11 @@
{
return IP_PMTUDISC_DONT;

}
- msg(M_FATAL,

- "invalid --mtu-disc type: = 9;%s' -- valid types are 'yes', 'maybe', or 'no'= ;",
- name)= ;
-#else /* if defined= (IP_PMTUDISC_DONT) && defined(IP_PMTUDISC_WANT) && defined(= IP_PMTUDISC_DO) */
+ = msg(M_FATAL, "invalid --mtu-disc type: '%s' -- valid types = are 'yes', 'maybe', or 'no'", name);+#else /* if defined(IP_PMTUDI= SC_DONT) && defined(IP_PMTUDISC_WANT) && defined(IP_PMTUDIS= C_DO) */
msg(M_FATAL, MTUDISC_NOT_SUPPORTED_MSG);
#endif
- = return -1; /* NOTREACHED */
+ return -1; /* NOTREACHED */
= }

#if EXTENDED_SOCKET_ERROR_CAPABILITY<= /span>
@@ -301,7 +292,7 @@
struct sock_extend= ed_err *e;
struct sockaddr_storage addr;
struct buffer out =3D alloc_buf_gc(256, gc);

- char *cbuf =3D (char *) gc_malloc(256, = false, gc);
+ char= *cbuf =3D (char *)gc_malloc(256, false, gc);

<= span> *mtu =3D 0;


@@ -310,7 +301,7 @@=
memset(&rcvbuf, -1, sizeof(rcvbuf)); iov.iov_base =3D &rcvbuf;
iov= .iov_len =3D sizeof(rcvbuf);
- msg.msg_name =3D (uint8_t *) &addr;
+ msg.msg_name =3D (uint8_t *)&= ;addr;
msg.msg_namelen =3D sizeof(addr); msg.msg_iov =3D &iov;
msg.msg_= iovlen =3D 1;
@@ -332,7 +323,7 @@
= {
if (cmsg->cmsg_type =3D=3D IP_REC= VERR)
{
- e =3D (struct sock_extended_err *) C= MSG_DATA(cmsg);
+ = e =3D (struct sock_extended_err *)CMSG_DATA(cmsg); }
else
= {
@@ -343,7 +334,7 @@
{

if (cmsg->cmsg_type = =3D=3D IPV6_RECVERR)
{
- e =3D (struct sock_ex= tended_err *) CMSG_DATA(cmsg);
+ e =3D (struct sock_extended_err *)CMSG_DATA(= cmsg);
}
= else
{
@@ -406,7 +397,7 @@=
/* see "man 7 ip" (on Linux)
* this works on IPv4 and IPv6(-dual-stack) sockets (v4-mapped)
*/
- = if (setsockopt(sd, SOL_IP, IP_RECVERR, (void *) &on, sizeof(on)) != =3D 0)
+ if (setso= ckopt(sd, SOL_IP, IP_RECVERR, (void *)&on, sizeof(on)) !=3D 0) {
msg(M_WARN | M_ERRNO,
"Note: enable extended error passing on TCP/UDP socket= failed (IP_RECVERR)");

@@ -415,7 +406,7 @@
= * this only works on IPv6 sockets
*/
if (proto_af =3D=3D AF_INET6
- && setsockopt(sd, IPPROTO_IPV6, IPV= 6_RECVERR, (void *) &on, sizeof(on)) !=3D 0)
+ && setsockopt(sd, IPPROTO_IPV6= , IPV6_RECVERR, (void *)&on, sizeof(on)) !=3D 0)
{=
msg(M_WARN | M_ERRNO,
= "Note: enable extended error passing on TCP/UDP socket failed (IPV6_= RECVERR)");
diff --git a/src/openvpn/mtu.h b/src/openv= pn/mtu.h
index dca402a..b4ec11b 100644
--- = a/src/openvpn/mtu.h
+++ b/src/openvpn/mtu.h
@@ -51,38 +51,38 @@

/*
* Standard ether= net MTU
*/
-#define ETHERNET_MTU 1500
+#define ETHERNET_MTU 1500

/*

* It is a fatal error if mtu is less than<= br> * this value for tun device.
*/
-#define TUN_MTU_MIN 100
+#define TUN_MTU_MIN 100

/*
* Default MTU of net= work over which tunnel data will pass by TCP/UDP.
*/

-#define LINK_MTU_DEFAULT = 1500
+#define LINK_M= TU_DEFAULT 1500

/*
* D= efault MTU of tunnel device.
*/
-#define TUN_MTU_DEFAULT 1500
+#define TUN_MTU_DEFAULT 1500
=

/*
* MTU Defaults for TAP de= vices
*/
-#define TAP_MTU_EXTRA_DEFAULT 32
+#define TAP_MTU_EXTRA_DEFAULT 32

/*
* Default MSSFIX value, used for reducing = TCP MTU size
*/
-#define MSSFIX_DEFAULT 1492
+#define MSSFIX_DEFAULT 1492

/*
* Default maximum size of control channel = packets
*/
-#define TLS_MTU_DEFAULT 1250
+#define TLS_MTU_DEFAULT 1250
/*
* Alignment of payload data such as IP packet = or
@@ -95,62 +95,64 @@
/**
* Packet geometry parameters.

*/
-struct frame {
- struct {
+struct frame
+{
+ str= uct
+ {
= /* This struct holds all the information about the buffers t= hat are
* allocated to match this frame */=
- int payload_size; = /**< the maximum size that a payload that our
- * buffer= s can hold from either tun device
- * or network link.- = */
+ int pay= load_size; /**< the maximum size that a payload that our
+ * buff= ers can hold from either tun device

+ * or network link.
<= span style=3D"color: hsl(120, 100%, 40%);">+ */


- int headroom; /**< the headroom in the bu= ffer, this is choosen
-= * to allow all potential header to be ad= ded
- = * before the packet */
+ int headroom; /**< the headroom in the buffe= r, this is choosen
+ = * to allow all potential header to be added<= br>+ * = before the packet */

- int tailroom; /**< the tailroom in t= he buffer. Chosen large
- * enough to also accompany any extrea = header
- = * or work space required by
- * decryption/e= ncryption or compression. */
+ int tailroom; /**< the tailroom in the buffer. Chosen l= arge
+ = * enough to also accompany any extrea header
+ * or work space r= equired by
+ = * decryption/encryption or compression. */
= } buf;

- uint16_t mss_fix; /**< The actual MSS value that sh= ould be
- = * written to the payload packets. This
- * = is the value for IPv4 TCP packets. For

- * IPv6 packets another = 20 bytes must
- = * be subtracted */
+ uint16_t mss_fix; /**< The actual MSS= value that should be
+ * written to the payload packets. This
+ = * is the value for IPv4 TCP packets. For
+ * IPv6 packets ano= ther 20 bytes must
+ = * be subtracted */
- int max_fragment_size; = /**< The maximum size of a fragment.
- * Fragmentation is done= on the unencrypted
- = * payload after (potential) compression. So<= /span>
- = * this value specifies the maximum payload
- * size tha= t can be send in a single fragment
- */
+ int max_fragment_size; /**< The maximum= size of a fragment.
= + * Fragmentation is done on the unencrypted
+ = * payload after (potential) compression. So
+ * this value speci= fies the maximum payload
+ * size that can be send in a single fragme= nt
+ = */

- int tun_mtu; /**< the (user) configured tun= -mtu. This is used
- = * in configuring the tun interface or
- = * in calculations that use the desired size
- * of the= payload in the buffer.
- *
- * This variable is also u= sed in control
- = * frame context to set the desired maximum
- = * control frame payload (although most of
- * code igno= res it)
- = */
-= int tun_max_mtu; /**< the maximum tun-mtu size the buffer= s are
- = * are sized for. This is the upper bound that
= - = * a server can push as MTU */
+ int tun_mtu; /**< the (user) configured tun-m= tu. This is used
+ = * in configuring the tun interface or
= + * = in calculations that use the desired size
+ * of the payload in t= he buffer.
+ = *
= + * This variable is also used in control
+ = * frame context to set the desired maximum
+ * control frame = payload (although most of
+ * code ignores it)
+ */+ int tun_max_mtu; /*= *< the maximum tun-mtu size the buffers are
+ * are sized for. T= his is the upper bound that
+ * a server can push as MTU */<= br>
- int ext= ra_tun; /**< Maximum number of bytes in excess of- = * the tun/tap MTU that might be read
- * from or written to = the virtual
- = * tun/tap network interface.
- *- = * Only set with the option --tun-mtu-extra
- * which defaul= ts to 0 for tun and 32
= - * (\c TAP_MTU_EXTRA_DEFAULT) for tap.
- = * */
+ = int extra_tun; /**< Maximum number of bytes in excess of=
+ = * the tun/tap MTU that might be read
+ * from or written to the= virtual
+ = * tun/tap network interface.
+ *
+ * Only = set with the option --tun-mtu-extra
+ * which defaults to 0 for tun= and 32
+ = * (\c TAP_MTU_EXTRA_DEFAULT) for tap.
+ * */
};

/* Forward declarations,= to prevent includes */
@@ -175,9 +177,7 @@
* Function prototypes.

*/

= -void frame_print(const struct fr= ame *frame,
- = int level,
- = const char *prefix);
+void frame_print(const struct frame *frame, int level, const = char *prefix);

void set_mtu_discover_typ= e(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af);

@@ -195,10 +195,8 @@
*
* * [IP][UDP][OPENVPN PROTOCOL HEADER][ **PAYLOAD incl compression h= eader** ]

*/
-size_t
-frame_= calculate_payload_size(const struct frame *frame,
- const struct optio= ns *options,
- = const struct key_type *kt);
+size_t frame_calculate_payload_size(const struc= t frame *frame, const struct options *options,
+ const struct= key_type *kt);

/**
* = Calculates the size of the payload overhead according to tun-mtu and=
@@ -216,10 +214,8 @@
*
* * [= IP][UDP][OPENVPN PROTOCOL HEADER][ **PAYLOAD incl compression header** ]
*/
-siz= e_t
-frame_calculate_pa= yload_overhead(size_t extra_tun,
- const struct options *options,<= /span>
- = const struct key_type *kt);
+size_t frame_calculate_payload_overhead(size_t extra_tun= , const struct options *options,
+ const struct key_type = *kt);


/**
@@ -237,10 +233,8 @@

* @param occ Use the c= alculation for the OCC link-mtu
* @return si= ze of the overhead in bytes
*/
-size_t
-frame_calculate_protocol_header_size(const struct key_type *kt,=
- = const struct options *options,
- bool occ);
+size_t frame_calculate= _protocol_header_size(const struct key_type *kt,
+ co= nst struct options *options, bool occ);

= /**
* Calculate the link-mtu to advertise to our peer. T= he actual value is not
@@ -249,23 +243,18 @@
* value they expect. This assumes that the traditional cipher/auth dir= ectives

* in the config match the config of the peer.
*/
-size= _t
-calc_options_string= _link_mtu(const struct options *options,
- const struct frame *frame);=
+size_t calc_options= _string_link_mtu(const struct options *options, const struct frame *frame);=

/**
* Return the size= of the packet ID size that is currently in use by cipher and
* options for the data channel.

*/
-unsigned int
-calc_packet_id_size_dc(const struct options *opt= ions,
- = const struct key_type *kt);
+unsigned int calc_packet_id_size_dc(const struct options *op= tions, const struct key_type *kt);

/*
* allocate a buffer for socket or tun layer
*/

-void alloc_buf_s= ock_tun(struct buffer *buf,
- const struct frame *frame);
+void alloc_buf_sock_tun(struct buffer= *buf, const struct frame *frame);

/*
* EXTENDED_SOCKET_ERROR_CAPABILITY functions -- print extra= error info
diff --git a/src/openvpn/mudp.c b/src/openvpn/m= udp.c
index 93e65e0..3fb015d 100644
--- a/s= rc/openvpn/mudp.c
+++ b/src/openvpn/mudp.c
= @@ -39,18 +39,15 @@
#endif

static void

-send_h= mac_reset_packet(struct multi_context *m,
- struct tls_pre_decrypt_state *st= ate,
- = struct tls_auth_standalone *tas,
- struct session_id *sid,
<= span style=3D"color: hsl(120, 100%, 40%);">+send_hmac_reset_packet(struct m= ulti_context *m, struct tls_pre_decrypt_state *state,

+ struct tls_auth_st= andalone *tas, struct session_id *sid,
= bool request_resend_wkc)
{
reset_= packet_id_send(&state->tls_wrap_tmp.opt.packet_id.send);
<= span> state->tls_wrap_tmp.opt.packet_id.rec.initialized =3D true;
uint8_t header =3D 0 | (P_CONTROL_HARD_RESET_SERVER_V2 &= lt;< P_OPCODE_SHIFT);
struct buffer buf =3D tls_res= et_standalone(&state->tls_wrap_tmp, tas, sid,
- = &state->peer_session_id, header,
- request_re= send_wkc);
+ = &state->peer_session_id, header,= request_resend_wkc);

struct context= *c =3D &m->top;

@@ -66,8 +63,7 @@=

/* Returns true if this packet should c= reate a new session */
static bool
-do_pre_decrypt_check(struct multi_context *= m,
- = struct tls_pre_decrypt_state *state,
+do_pre_decrypt_check(struct multi_context *m, struct tls= _pre_decrypt_state *state,
struct mro= ute_addr addr)
{
ASSERT(m->top.c2.= tls_auth_standalone);
@@ -109,8 +105,8 @@
= if (early_neg_support)
{
= /* Calculate the session ID HMAC for our reply and create reset= packet */
- = struct session_id sid =3D calculate_session_id_hmac(state->peer_session= _id,
- = from, hmac, handwindow, 0);
+ struct ses= sion_id sid =3D
+ = calculate_session_id_hmac(state->peer_session_id, from, hmac= , handwindow, 0);
send_hmac_reset_packet(m, st= ate, tas, &sid, true);

r= eturn false;
@@ -125,8 +121,10 @@
= {
struct gc_arena gc =3D gc_new();
const char *peer =3D print_link_socket_actual= (&m->top.c2.from, &gc);
- msg(D_MULTI_DEBUG, "tls-crypt-v2 force-co= okie is enabled, "
- "ignoring connection attempt from old client (%s= )", peer);
+ = msg(D_MULTI_DEBUG,
+ "tls-crypt-v2 force-cookie is enabled, = "
+ = "ignoring connection attempt from old client (%s)",=
+ peer);=
gc_free(&gc);
= return false;
}
@@ -= 139,14 +137,13 @@
else if (verdict =3D=3D VERDICT_VALI= D_RESET_V2)
{
/* Calculate th= e session ID HMAC for our reply and create reset packet */
- struct session_id sid =3D calc= ulate_session_id_hmac(state->peer_session_id,
- = from, hmac, handwindow, 0);
+ struct session_id sid =3D
+ calculate_session_id_hmac(sta= te->peer_session_id, from, hmac, handwindow, 0);

send_hmac_reset_packet(m, state, tas, &sid, false);=

/* We have a reply do not creat= e a new session */
return false;
-
}
else if (verdict =3D=3D VERDICT_VALID_CONTROL_V1 || verdict =3D=3D VE= RDICT_VALID_ACK_V1

|| verdict =3D=3D VERDICT_= VALID_WKC_V1)
@@ -158,7 +155,7 @@
= bool ret =3D check_session_id_hmac(state, from, hmac, handwindow);
const char *peer =3D print_link_socket_a= ctual(&m->top.c2.from, &gc);
- uint8_t pkt_firstbyte =3D *BPTR( &m->top.c= 2.buf);
+ uint= 8_t pkt_firstbyte =3D *BPTR(&m->top.c2.buf);
= int op =3D pkt_firstbyte >> P_OPCODE_SHIFT;

if (!ret)
@@ -168,8 +165,10 @@ }
else
{=
- msg(D_MUL= TI_DEBUG, "Valid packet (%s) with HMAC challenge from peer (%s), "= ;
- &quo= t;accepting new connection.", packet_opcode_name(op), peer);+ msg(D_MULTI_DEBUG= ,
+ &q= uot;Valid packet (%s) with HMAC challenge from peer (%s), "
= + "acceptin= g new connection.",
+ packet_opcode_name(op), peer);
= }
gc_free(&gc);

= @@ -187,18 +186,16 @@
*/
struct multi_instance *
-multi_get_create_instance_udp(struct multi_context *m, bool *flo= ated,
- = struct link_socket *sock)
+multi_get_create_instance_udp(struct multi_context *m, = bool *floated, struct link_socket *sock)
{
struct gc_arena gc =3D gc_new();

- struct mroute_addr real =3D {0};
+ struct mroute_addr real =3D { 0 };
struct multi_instance *mi =3D NULL;
= struct hash *hash =3D m->hash;
real.proto =3D sock= ->info.proto;
m->hmac_reply_ls =3D sock;<= br>
- if (mro= ute_extract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true)<= /span>
- && m-&= gt;top.c2.buf.len > 0)
+ if (mroute_extract_openvpn_sockaddr(&real, &m->top.c2.= from.dest, true) && m->top.c2.buf.len > 0)
= {
struct hash_element *he;
= const uint32_t hv =3D hash_value(hash, &real);
@@ = -234,19 +231,20 @@
he =3D hash_lookup_fast(has= h, bucket, &real, hv);
if (he)
<= span> {

- = mi =3D (struct multi_instance *) he->value;
+ mi =3D (struct mul= ti_instance *)he->value;

}
= }

/* we have no existin= g multi instance for this connection */
if (!mi)
{
- struct tls_pre_decrypt_state state =3D {0};
+ struct tls_pre_decrypt_= state state =3D { 0 };

if (m->deferred_shut= down_signal.signal_received)
{
msg(D_MULTI_ERRORS,

= "MULTI: Connection attempt from %s ignored while server is "
- "= shutting down", mroute_addr_print(&real, &gc));
+ "shutting= down",

+ = mroute_addr_print(&real, &gc));
= }
else if (do_pre_decrypt_check(m, &= ;state, real))
{
@@ -274,7 +27= 2,8 @@
&& session_id_d= efined((&state.peer_session_id)))
= {
mi->context.c2.tls_mu= lti->n_sessions++;
-= struct tls_session *session =3D &mi->con= text.c2.tls_multi->session[TM_INITIAL];
+ struct tls_session *sess= ion =3D
+ = &mi->context.c2.tls_multi->session[TM_INITIAL= ];
session_skip_to_pre_start(s= ession, &state, &m->top.c2.from);
= }
}
@@ -294= ,9 +293,7 @@
{
const = char *status =3D mi ? "[ok]" : "[failed]";

- dmsg= (D_MULTI_DEBUG, "GET INST BY REAL: %s %s",
- mroute_addr_print(&rea= l, &gc),
- = status);
+ = dmsg(D_MULTI_DEBUG, "GET INST BY REAL: %s %s", mroute_ad= dr_print(&real, &gc), status);
} #endif
}
@@ -336,8 +333,8 @@
{
const unsigned int status =3D m->= multi_io->udp_flags;
const unsigned int mpp_flags = =3D m->top.c2.fast_io
- = : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);
+ = ? (MPP_CONDITIONAL_PRE_SELECT | MPP_CLOSE_ON_SIGNAL)<= br>+ = : (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);

#ifdef MULTI_DEBUG_EVENT_LOOP
char buf[1= 6];
@@ -366,7 +363,7 @@
#endif /* ifdef MU= LTI_DEBUG_EVENT_LOOP */

#ifdef ENABLE_MA= NAGEMENT
- if (statu= s & (MANAGEMENT_READ|MANAGEMENT_WRITE))
+ if (status & (MANAGEMENT_READ | MANAGEMENT_= WRITE))
{
ASSERT(management);=
management_io(management);
diff -= -git a/src/openvpn/multi.c b/src/openvpn/multi.c
index a760= e07..a65f8c2 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c

@@ -92,9 +92,7 @@
}


static bool
-learn_address_script(const struct multi_con= text *m,
- = const struct multi_instance *mi,
- const char *op,
+learn_address_script(const struct multi= _context *m, const struct multi_instance *mi, const char *op,
const struct mroute_addr *addr)

{=
struct gc_arena gc =3D gc_new();
@@ -= 125,14 +123,13 @@
if (plugin_defined(plugins, OPENVPN_= PLUGIN_LEARN_ADDRESS))
{
stru= ct argv argv =3D argv_new();
- argv_printf(&argv, "%s %s",
- op,
- mroute_addr_print(= addr, &gc));
+ = argv_printf(&argv, "%s %s", op, mroute_addr_print(addr, = &gc));
if (mi)
{
argv_printf_cat(&argv, "%s", tls_com= mon_name(mi->context.c2.tls_multi, false));
}
- if (plugin_call= (plugins, OPENVPN_PLUGIN_LEARN_ADDRESS, &argv, NULL, es) !=3D OPENVPN_P= LUGIN_FUNC_SUCCESS)
+= if (plugin_call(plugins, OPENVPN_PLUGIN_LEARN_ADDRESS, &argv, N= ULL, es)
+ = !=3D OPENVPN_PLUGIN_FUNC_SUCCESS)
{
msg(M_WARN, "WARNING: learn-address plugin call failed= ");

ret =3D false;
@@ -16= 5,8 +162,7 @@
multi_ifconfig_pool_persist(struct multi_con= text *m, bool force)
{
/* write pool = data to file */
- if= (m->ifconfig_pool
-= && m->top.c1.ifconfig_pool_persist
+ if (m->ifconfig_pool && m-= >top.c1.ifconfig_pool_persist
&& (force= || ifconfig_pool_write_trigger(m->top.c1.ifconfig_pool_persist)))
{
ifconfig_pool_write(m->top.c1= .ifconfig_pool_persist, m->ifconfig_pool);
@@ -174,9 +17= 0,7 @@
}

static void
-multi_reap_range(const s= truct multi_context *m,
- int start_bucket,
- int end_bucket)
+multi_reap_range(const struct multi_context *m,= int start_bucket, int end_bucket)
{
= struct gc_arena gc =3D gc_new();
struct hash_iterator = hi;
@@ -192,11 +186,10 @@
hash_iterato= r_init_range(m->vhash, &hi, start_bucket, end_bucket);
while ((he =3D hash_iterator_next(&hi)) !=3D NULL)

{

- str= uct multi_route *r =3D (struct multi_route *) he->value;
+ struct multi_route *r =3D (= struct multi_route *)he->value;

if (!multi_rout= e_defined(m, r))
{
- dmsg(D_MULTI_DEBUG, "MULTI: REAP DEL= %s",
- = mroute_addr_print(&r->addr, &gc));
+ dmsg(D_MULTI_DEBUG, "MUL= TI: REAP DEL %s", mroute_addr_print(&r->addr, &gc));=
learn_address_script(m, NULL, "delete", &a= mp;r->addr);
multi_route_del(r);
= hash_iterator_delete_element(&hi);
@= @ -257,7 +250,7 @@
cid_hash_function(const void *key, uint= 32_t iv)
{
const unsigned long *k =3D= (const unsigned long *)key;
- return (uint32_t) *k;
+ return (uint32_t)*k;
}
<= /span>
static bool
@@ -295,8 +288,7 @@
= {
int dev =3D DEV_TYPE_UNDEF;
=
- msg(D_MULTI_LOW, = "MULTI: multi_init called, r=3D%d v=3D%d",
- t->options.real_hash_size,
+ msg(D_MULTI_LOW, &quo= t;MULTI: multi_init called, r=3D%d v=3D%d", t->options.real_hash_si= ze,
t->options.virtual_hash_size);

/*
@@ -315,18 +307,14 @@<= br> * to determine which client sent an incoming packet * which is seen on the TCP/UDP socket.
= */
- m->hash =3D = hash_init(t->options.real_hash_size,
- get_random(),
- mroute_addr_hash_= function,
+ m->= hash =3D hash_init(t->options.real_hash_size, get_random(), mroute_addr_= hash_function,
mroute_addr_compare= _function);

/*
= * Virtual address hash table. Used to determine
* w= hich client to route a packet to.
*/
- m->vhash =3D hash_init(t->op= tions.virtual_hash_size,
- mroute_addr_hash_function,
+ m->vhash =3D has= h_init(t->options.virtual_hash_size, get_random(), mroute_addr_hash_func= tion,
mroute_addr_compare_functio= n);

/*
@@ -334,16 +3= 22,10 @@
* bucket size of one so that it can be used<= /span>
* for fast iteration through the list.
*/

- m->i= ter =3D hash_init(1,
- = get_random(),
- mroute_addr_hash_function,- mroute_= addr_compare_function);
+ m->iter =3D hash_init(1, get_random(), mroute_addr_hash_function= , mroute_addr_compare_function);

#ifdef = ENABLE_MANAGEMENT
- = m->cid_hash =3D hash_init(t->options.real_hash_size,
- 0,<= br>- c= id_hash_function,
- = cid_compare_function);
+ m->cid_hash =3D hash_init(t->options.r= eal_hash_size, 0, cid_hash_function, cid_compare_function);
#endif


#ifdef ENABLE_ASYNC_PUSH=
@@ -351,10 +333,8 @@
* Mapping between inot= ify watch descriptors and
* multi_instances. */
- m= ->inotify_watchers =3D hash_init(t->options.real_hash_size,- = get_random(),
- = int_hash_function,
- int_com= pare_function);
+ = m->inotify_watchers =3D
+ hash_init(t->options.real_hash_size, get_random(), int_ha= sh_function, int_compare_function);
#endif

/*
@@ -367,10 +347,9 @@
<= span> * Limit frequency of incoming connections to control

<= span> * DoS.

*/
- m->new_connection_limiter =3D frequency_limit_i= nit(t->options.cf_max,
- t->options.cf_p= er);
- m->initial= _rate_limiter =3D initial_rate_limit_init(t->options.cf_initial_max,
- = t->options.cf_initial_per);
+ m->new_connection_limiter = =3D frequency_limit_init(t->options.cf_max, t->options.cf_per);
+ m->initial_rate_li= miter =3D
+ in= itial_rate_limit_init(t->options.cf_initial_max, t->options.cf_initia= l_per);

/*
* A= llocate broadcast/multicast buffer list
@@ -387,8 +366,7 @@=
* differently based on whether a tun or tap style
* tunnel.
*/
- if (t->options.ifconfig_pool_define= d
- || t->opt= ions.ifconfig_ipv6_pool_defined)
+ if (t->options.ifconfig_pool_defined || t->options.i= fconfig_ipv6_pool_defined)
{
= int pool_type =3D IFCONFIG_POOL_INDIV;

@@= -397,14 +375,11 @@
pool_type =3D IFCONFIG_POO= L_30NET;
}

- m->ifconfig_pool =3D ifconfig_po= ol_init(t->options.ifconfig_pool_defined,
- pool_t= ype,
- = t->options.ifconfig_pool_start,
<= span style=3D"color: hsl(0, 100%, 40%);">- = t->options.ifconfig_pool_end,

- t->= ;options.duplicate_cn,
= - t->options.ifconfig_ipv6_= pool_defined,
- = t->options.ifconfig_ipv6_pool_base= ,
- = t->options.ifconfig_ipv6_pool_netbits );
+ m->ifconfig_po= ol =3D ifconfig_pool_init(
+ t->options.ifconfig_pool_defined, pool_type, t->op= tions.ifconfig_pool_start,
+ t->options.ifconfig_pool_end, t->options.duplicate= _cn,
+ t-&= gt;options.ifconfig_ipv6_pool_defined, t->options.ifconfig_ipv6_pool_bas= e,
+ t->= ;options.ifconfig_ipv6_pool_netbits);

= /* reload pool data from file */
if (t->c= 1.ifconfig_pool_persist)
@@ -454,7 +429,8 @@
/* initialize stale routes check timer */

if (t= ->options.stale_routes_check_interval > 0)
{
- msg(M_INFO, "= ;Initializing stale route check timer to run every %i seconds and to removi= ng routes with activity timeout older than %i seconds",
+ msg(M_INFO,

+ "Initializing sta= le route check timer to run every %i seconds and to removing routes with ac= tivity timeout older than %i seconds",

t-= >options.stale_routes_check_interval, t->options.stale_routes_ageing_= time);
event_timeout_init(&m->stale_routes_= check_et, t->options.stale_routes_check_interval, 0);
= }
@@ -475,8 +451,7 @@
buf_p= rintf(&out, "%s/", cn);
}
= buf_printf(&out, "%s", mroute_addr_print(&= mi->real, gc));
- = if (mi->context.c2.tls_multi
- && check_debug_level(D_DCO_DEBUG)=
+ if (mi->context= .c2.tls_multi && check_debug_level(D_DCO_DEBUG)
= && dco_enabled(&mi->context.options))
{

buf_printf(&out, " pee= r-id=3D%d", mi->context.c2.tls_multi->peer_id);
= @@ -523,8 +498,7 @@
* CIDR netlengths.
= */
static void
-multi_del_iroutes(struct multi_context *m,
- struct multi_instance *mi= )
+multi_del_iroutes(= struct multi_context *m, struct multi_instance *mi)
{
const struct iroute *ir;
const struct= iroute_ipv6 *ir6;
@@ -580,7 +554,9 @@

if (plugin_defined(mi->context.plugins, OPENVPN_PLUGI= N_CLIENT_DISCONNECT))
{
- if (plugin_call(mi->context.plugins, OPEN= VPN_PLUGIN_CLIENT_DISCONNECT, NULL, NULL, mi->context.c2.es) !=3D OPENVP= N_PLUGIN_FUNC_SUCCESS)
+ mi->context.c2.es)
+ !=3D OPENVPN_PLUGIN_FUNC_SUCCESS)
{
msg(M_WARN, "WA= RNING: client-disconnect plugin call failed");
= }
@@ -603,9 +579,7 @@
}
=
void
-multi_close_instance(struct multi_context *m,
- struct multi_instance *mi,
- bo= ol shutdown)
+multi_c= lose_instance(struct multi_context *m, struct multi_instance *mi, bool shut= down)
{
perf_push(PERF_MULTI_CLOSE_IN= STANCE);

@@ -650,7 +624,7 @@
#ifdef ENABLE_ASYNC_PUSH

if (mi->inotify_w= atch !=3D -1)
{
- hash_remove(m->inotify_watchers, (void *)= (unsigned long)mi->inotify_watch);
+ hash_remove(m->inotify_watchers, (void *)= (unsigned long)mi->inotify_watch);
mi->i= notify_watch =3D -1;
}
#endif
@@ -660,7 +634,7 @@
m->instanc= es[mi->context.c2.tls_multi->peer_id] =3D NULL;
= }

- schedule_remove_entry(m->schedule, (struct schedule_entry *) m= i);
+ schedule= _remove_entry(m->schedule, (struct schedule_entry *)mi);

ifconfig_pool_release(m->ifconfig_pool, mi-&= gt;vaddr_handle, false);

@@ -717,7 +691,7= @@
hash_iterator_init(m->iter, &hi);
while ((he =3D hash_iterator_next(&hi)))
= {
- = struct multi_instance *mi =3D (struct multi_instance *) he->value= ;
+ struct= multi_instance *mi =3D (struct multi_instance *)he->value;
mi->did_iter =3D false;

mu= lti_close_instance(m, mi, true);
}
@@ -789,7 +763,9 @@


if (hash_n_elem= ents(m->hash) >=3D m->max_clients)
{- msg(D_MULTI_ERRORS, &q= uot;MULTI: new incoming connection would exceed maximum number of clients (= %d)", m->max_clients);
+ msg(D_MULTI_ERRORS,
+ "MULTI: new incoming connection would e= xceed maximum number of clients (%d)",
+ m->max_clients);
= goto err;
}

@@= -879,7 +855,7 @@
while ((he =3D hash_iterator= _next(&hi)))
{
= struct gc_arena gc =3D gc_new();
- const struct multi_instance *mi =3D (struc= t multi_instance *) he->value;
+ const struct multi_instance *mi =3D (struct m= ulti_instance *)he->value;

= if (!mi->halt)
{
= @@ -900,21 +876,19 @@
while ((he =3D hash_iter= ator_next(&hi)))
{
= struct gc_arena gc =3D gc_new();
- const struct multi_route *route =3D (s= truct multi_route *) he->value;
+ const struct multi_route *route =3D (struct = multi_route *)he->value;

= if (multi_route_defined(m, route))
{
const struct multi_instance *mi =3D rou= te->instance;
const struct mroute_a= ddr *ma =3D &route->addr;
- char flags[2] =3D {0, 0};
+ char flags[2] =3D = { 0, 0 };

if (route-= >flags & MULTI_ROUTE_CACHE)
{
flags[0] =3D 'C'; }
- status_printf(so, "%s%s,%s,%s,%s",
- = mroute_addr_print(ma, &gc),
- flags,
+ status_printf(= so, "%s%s,%s,%s,%s", mroute_addr_print(ma, &gc), flags,
tls_common_name(mi->contex= t.c2.tls_multi, false),
= mroute_addr_print(&mi->real, &gc),
= time_string(route->last_reference, 0, false, &= gc));
@@ -926,8 +900,7 @@
stat= us_printf(so, "GLOBAL STATS");
if (m= ->mbuf)
{
- status_printf(so, "Max bcast/mcast= queue length,%d",
- mbuf_maximum_queued(m->mbuf));+ status_printf= (so, "Max bcast/mcast queue length,%d", mbuf_maximum_queued(m->= ;mbuf));
}

= status_printf(so, "END");
@@ -940,69 = +913,77 @@
* Status file version 2 and 3

*/
status_printf(so,= "TITLE%c%s", sep, title_string);
- status_printf(so, "TIME%c%s%c%u"= ;, sep, time_string(now, 0, false, &gc_top), sep, (unsigned int)now);
- status_prin= tf(so, "HEADER%cCLIENT_LIST%cCommon Name%cReal Address%cVirtual Addres= s%cVirtual IPv6 Address%cBytes Received%cBytes Sent%cConnected Since%cConne= cted Since (time_t)%cUsername%cClient ID%cPeer ID%cData Channel Cipher"= ;,
- = sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep, sep);
+ status_pri= ntf(so, "TIME%c%s%c%u", sep, time_string(now, 0, false, &gc_t= op), sep,
+ = (unsigned int)now);
+ status_printf(
+ so,
+ "HEADER%cCLIENT_LIST%cCommon Na= me%cReal Address%cVirtual Address%cVirtual IPv6 Address%cBytes Received%cBy= tes Sent%cConnected Since%cConnected Since (time_t)%cUsername%cClient ID%cP= eer ID%cData Channel Cipher",
+ sep, sep, sep, sep, sep, sep, sep, sep, sep,= sep, sep, sep, sep);
hash_iterator_init(m->= ;hash, &hi);
while ((he =3D hash_iterator_= next(&hi)))
{
= struct gc_arena gc =3D gc_new();
- const struct multi_instance *mi =3D (struct= multi_instance *) he->value;
+ const struct multi_instance *mi =3D (struct mu= lti_instance *)he->value;

= if (!mi->halt)
{
- status_printf(so, &= quot;CLIENT_LIST%c%s%c%s%c%s%c%s%c" counter_format "%c" coun= ter_format "%c%s%c%u%c%s%c"
+ status_printf(
+ so,
+ "CLI= ENT_LIST%c%s%c%s%c%s%c%s%c" counter_format "%c" counter_form= at

+ = "%c%s%c%u%c%s%c"
#ifdef ENABLE_MANAGEMENT=
- = "%lu"
+ "%lu"
#else
- = ""
+ ""
#endif
- = "%c%" PRIu32 "%c%s",

- sep, tls_common_name(m= i->context.c2.tls_multi, false),
- sep, mroute_addr_print(&= ;mi->real, &gc),
- sep, print_in_addr_t(mi->reporting_a= ddr, IA_EMPTY_IF_UNDEF, &gc),
- sep, print_in6_addr(mi->re= porting_addr_ipv6, IA_EMPTY_IF_UNDEF, &gc),
- sep, mi->con= text.c2.link_read_bytes + mi->context.c2.dco_read_bytes,
- sep= , mi->context.c2.link_write_bytes + mi->context.c2.dco_write_bytes,
- = sep, time_string(mi->created, 0, false, &gc),
<= span style=3D"color: hsl(0, 100%, 40%);">- = sep, (unsigned int)mi->created,

- sep, tls_username(mi->co= ntext.c2.tls_multi, false),
+ "%c%" PRIu32 "%c%s",
+ = sep, tls_common_name(mi->context.c2.tls_multi, false), sep,
= + mroute= _addr_print(&mi->real, &gc), sep,
+ print_in_addr_t(mi->rep= orting_addr, IA_EMPTY_IF_UNDEF, &gc), sep,
+ print_in6_addr(mi->re= porting_addr_ipv6, IA_EMPTY_IF_UNDEF, &gc), sep,
+ mi->context.c2= .link_read_bytes + mi->context.c2.dco_read_bytes, sep,
+ mi->contex= t.c2.link_write_bytes + mi->context.c2.dco_write_bytes, sep,
<= span style=3D"color: hsl(120, 100%, 40%);">+ time_st= ring(mi->created, 0, false, &gc), sep, (unsigned int)mi->created,=

+ = sep, tls_username(mi->context.c2.tls_multi, false),
#ifdef ENABLE_MANAGEMENT

- sep, mi->context.c2.mda_context.c= id,
+ = sep, mi->context.c2.mda_context.cid,
#else
- = sep,
+ = sep,
#endif
- sep, mi->conte= xt.c2.tls_multi ? mi->context.c2.tls_multi->peer_id : UINT32_MAX,
- = sep, translate_cipher_name_to_openvpn(mi->context.options.ciphe= rname));
+ = sep,
+ = mi->context.c2.tls_multi ? mi->context.c2.tls_m= ulti->peer_id : UINT32_MAX,
+ sep, translate_cipher_name_to_openvpn(mi= ->context.options.ciphername));
}
gc_free(&gc);
= }
hash_iterator_free(&hi);

- status_= printf(so, "HEADER%cROUTING_TABLE%cVirtual Address%cCommon Name%cReal = Address%cLast Ref%cLast Ref (time_t)",
- sep, sep, sep, sep, sep, se= p);
+ stat= us_printf(
+ = so,
+ = "HEADER%cROUTING_TABLE%cVirtual Address%cCommon Name%cReal Addr= ess%cLast Ref%cLast Ref (time_t)",
+ sep, sep, sep, sep, sep, sep); hash_iterator_init(m->vhash, &hi);
while ((he =3D hash_iterator_next(&hi)))

{

struct gc_arena gc =3D g= c_new();
- = const struct multi_route *route =3D (struct multi_route *) he->value;=
+ con= st struct multi_route *route =3D (struct multi_route *)he->value;=

if (multi_route_defined(m, rou= te))
{
= const struct multi_instance *mi =3D route->instance;
= const struct mroute_addr *ma =3D &route->addr;
- cha= r flags[2] =3D {0, 0};
- status= _printf(so, "ROUTING_TABLE%c%s%s%c%s%c%s%c%s%c%u",
- se= p, mroute_addr_print(ma, &gc), flags,

- sep, tls_common_name(= mi->context.c2.tls_multi, false),
- sep, mroute_addr_print(&am= p;mi->real, &gc),
+ = status_printf(so, "ROUTING_TABLE%c%s%s%c%s%c%s%c%s%c%u", = sep,
+ = mroute_addr_print(ma, &gc), flags, sep,
+ = tls_common_name(mi->context.c2.tls_multi, false), sep,

+ m= route_addr_print(&mi->real, &gc), sep,

+ time_string= (route->last_reference, 0, false, &gc), sep,
+ (unsign= ed int)route->last_reference);
}=
gc_free(&gc);
}=
@@ -1010,11 +991,12 @@

= if (m->mbuf)
{
- status_printf(so, &quo= t;GLOBAL_STATS%cMax bcast/mcast queue length%c%d",
- sep, sep, m= buf_maximum_queued(m->mbuf));
+ status_printf(so, "GLOBAL_STATS%cMax bcas= t/mcast queue length%c%d", sep, sep,
+ mbuf_maximum_queued(m-&= gt;mbuf));
}

- status_printf(so, "G= LOBAL_STATS%cdco_enabled%c%d", sep, sep, dco_enabled(&m->top.op= tions));

+ = status_printf(so, "GLOBAL_STATS%cdco_enabled%c%d", sep, sep,
+ = dco_enabled(&m->top.options));
statu= s_printf(so, "END");
}
= else
@@ -1024,19 +1006,22 @@

#ifdef PACKET_TRUNCATION_CHECK
{
- status_printf(= so, "HEADER,ERRORS,Common Name,TUN Read Trunc,TUN Write Trunc,Pre-encr= ypt Trunc,Post-decrypt Trunc");
+ status_printf(
+ so,
+ "HEADER,ERRORS,Common Name,TUN= Read Trunc,TUN Write Trunc,Pre-encrypt Trunc,Post-decrypt Trunc");
hash_iterator_init(m->hash, &hi);<= br> while ((he =3D hash_iterator_next(&hi))) {
struct gc_arena gc = =3D gc_new();
- = const struct multi_instance *mi =3D (struct multi_instance *) he-&g= t;value;
+ = const struct multi_instance *mi =3D (struct multi_instance *)he->va= lue;

if (!mi->halt)
{
- status_printf(so, "ERRORS,%s," co= unter_format "," counter_format "," counter_format &quo= t;," counter_format,
+ status_printf(so,
+ "ERRORS,%s,&= quot; counter_format "," counter_format "," counter_for= mat
+ = "," counter_format,
= tls_common_name(mi->context.c2.tls_multi, false)= ,
- = m->top.c2.n_trunc_tun_read,
- mi->context.c2.= n_trunc_tun_write,
+ = m->top.c2.n_trunc_tun_read, mi->cont= ext.c2.n_trunc_tun_write,
= mi->context.c2.n_trunc_pre_encrypt,
= mi->context.c2.n_trunc_post_decrypt);
= }
@@ -1067,9 +1052,7 @@
*= or NULL if none.
*/
static struct multi= _instance *
-multi_lear= n_addr(struct multi_context *m,
- struct multi_instance *mi,
- const struct mroute_addr *= addr,
+multi_learn_ad= dr(struct multi_context *m, struct multi_instance *mi, const struct mroute_= addr *addr,
const unsigned int flags)
{
struct hash_element *he;
@@ -1083,7 +1066,7 @@

he =3D hash_lookup_fast(m->= ;vhash, bucket, addr, hv);
if (he)
= {
- oldroute = =3D (struct multi_route *) he->value;
+ oldroute =3D (struct multi_route *)he->valu= e;
}
if (oldroute && mult= i_route_defined(m, oldroute))
{
@@ -11= 41,10 +1124,8 @@
}
}<= /span>

- = msg(D_MULTI_LOW, "MULTI: Learn%s: %s -> %s",
- learn_succeeded ? "= ;" : " FAILED",

- mroute_addr_print(&newroute->addr, &gc),
- multi_instan= ce_string(mi, false, &gc));
+ msg(D_MULTI_LOW, "MULTI: Learn%s: %s -> %s"= ;, learn_succeeded ? "" : " FAILED",
+ mroute_addr_print(&new= route->addr, &gc), multi_instance_string(mi, false, &gc));

if (!learn_succeeded)
{

@@ -1160,8 +1141,7 @@
* Get c= lient instance based on virtual address.
*/
static struct multi_instance *

-multi_get_instance_by_virtual_addr(struct multi_context *m,
- = const struct mroute_addr *addr,
+multi_get_instance_by_virtual_addr(struct multi_cont= ext *m, const struct mroute_addr *addr,
= bool cidr_routing)
{
= struct multi_route *route;
@@ -1173,7 +1153,7 @@ return NULL;
}

- route =3D (struct multi= _route *) hash_lookup(m->vhash, addr);
+ route =3D (struct multi_route *)hash_lookup(m->= ;vhash, addr);

/* does host route (p= ossible cached) exist? */
if (route && multi_r= oute_defined(m, route))
@@ -1197,13 +1177,13 @@
<= span> mroute_addr_mask_host_bits(&tryaddr);


/* look up a possible route with netbits ne= tmask */
- r= oute =3D (struct multi_route *) hash_lookup(m->vhash, &tryaddr);
+ route =3D (= struct multi_route *)hash_lookup(m->vhash, &tryaddr);

if (route && multi_route_defined(m= , route))
{
/= * found an applicable route, cache host route */
= struct multi_instance *mi =3D route->instance;
- multi_learn_addr(m, mi, = addr, MULTI_ROUTE_CACHE|MULTI_ROUTE_AGEABLE);
+ multi_learn_addr(m, mi, addr, MUL= TI_ROUTE_CACHE | MULTI_ROUTE_AGEABLE);
ret= =3D mi;
break;
= }
@@ -1217,15 +1197,12 @@
const= char *addr_text =3D mroute_addr_print(addr, &gc);
= if (ret)
{
- dmsg(D_MULTI_DEBUG, "GET INST BY VIRT: = %s -> %s via %s",
- addr_text,
- multi_instance_string(ret, false, &gc),
- mroute_ad= dr_print(&route->addr, &gc));
+ dmsg(D_MULTI_DEBUG, "GET INST BY VIRT= : %s -> %s via %s", addr_text,
+ multi_instance_string(ret, false, &= gc), mroute_addr_print(&route->addr, &gc));
= }
else
{
<= span style=3D"color: hsl(0, 100%, 40%);">- dmsg(D_MULTI_DEBUG, &= quot;GET INST BY VIRT: %s [failed]",

- addr_text);
+ dmsg(D_MULTI_DEBUG, "GET INST= BY VIRT: %s [failed]", addr_text);
}<= br> gc_free(&gc);
}
= @@ -1239,14 +1216,12 @@
* Helper function to multi_learn_= addr().
*/
static struct multi_instance = *
-multi_learn_in_addr_= t(struct multi_context *m,
- struct multi_instance *mi,
- in_addr_t a,- int netb= its, /* -1 if host route, otherwise # of network bits in address */=
+multi_learn_in_addr_t(stru= ct multi_context *m, struct multi_instance *mi, in_addr_t a,
+ int netbits,= /* -1 if host route, otherwise # of network bits in address */

<= span> bool primary)

{
struct openvpn_sockaddr remote_si;

- struct mroute_addr addr =3D {0};
+ struct mroute_addr addr =3D { 0 };=

CLEAR(remote_si);
= remote_si.addr.in4.sin_family =3D AF_INET;
@@ -1257,7 += 1232,7 @@
if (netbits >=3D 0)
= {
addr.type |=3D MR_WITH_NETBITS;
- addr.netbits =3D (uint8_t) net= bits;
+ addr.n= etbits =3D (uint8_t)netbits;
}

struct multi_instance *owner =3D multi_learn_addr(m, mi, &a= mp;addr, 0);
@@ -1272,7 +1247,7 @@
= /* "primary" is the VPN ifconfig address of the peer and already=
* known to DCO, so only install "extra"= ; iroutes (primary =3D false)
*/
- ASSERT(netbits >=3D 0); = /* DCO requires populated netbits */
+ ASSERT(netbits >=3D 0); /* DCO requires = populated netbits */
dco_install_iroute(m, mi, &am= p;addr);
}

@@ -1280,= 13 +1255,11 @@
}

static= struct multi_instance *
- struct multi_instance *mi,<= /span>
- s= truct in6_addr a6,
- = int netbits, /* -1 if host route, otherwise # of networ= k bits in address */
= +multi_learn_in6_addr(struct multi_context *m, struct multi_instance *mi, s= truct in6_addr a6,
+ = int netbits, /* -1 if host route, otherwise # of networ= k bits in address */
bool primary)
{
- s= truct mroute_addr addr =3D {0};
+ struct mroute_addr addr =3D { 0 };
=
addr.len =3D 16;
addr.type =3D MR_ADDR_= IPV6;
@@ -1296,8 +1269,8 @@
if (netbit= s >=3D 0)
{
addr.type |=3D= MR_WITH_NETBITS;
- = addr.netbits =3D (uint8_t) netbits;
- mroute_addr_mask_host_bits( &addr );+ addr.netbits =3D (ui= nt8_t)netbits;
+ = mroute_addr_mask_host_bits(&addr);
}
=
struct multi_instance *owner =3D multi_learn_a= ddr(m, mi, &addr, 0);
@@ -1312,7 +1285,7 @@
<= span> /* "primary" is the VPN ifconfig address of the pee= r and already

* known to DCO, so only install &qu= ot;extra" iroutes (primary =3D false)
*/
- ASSERT(netbits &g= t;=3D 0); /* DCO requires populated netbits */
+ ASSERT(netbits >=3D 0); /* = DCO requires populated netbits */
dco_install_irou= te(m, mi, &addr);
}

@@ -1324,8 +1297,7 @@

* to internal routing table.
*/
static void
-multi_add_iroutes(struct multi_context *m,=
- struct mul= ti_instance *mi)
+mul= ti_add_iroutes(struct multi_context *m, struct multi_instance *mi) {
struct gc_arena gc =3D gc_new();
= const struct iroute *ir;
@@ -1338,15 +1310,13 @@=
if (ir->netbits >=3D 0)
{

msg(D_MULTI_LOW, "MUL= TI: internal route %s/%d -> %s",
- print_in_addr_t(ir->network, 0, &= amp;gc),
- = ir->netbits,
- print_in_addr_t(ir-= >network, 0, &gc),
- multi_instance_string(mi, false, &gc));<= br>+ print_i= n_addr_t(ir->network, 0, &gc), multi_instance_string(mi, false, &= ;gc));
}

= mroute_helper_add_iroute46(m->route_helper, ir->netbits);
@@ -1356,8 +1326,7 @@
for (ir6 =3D = mi->context.options.iroutes_ipv6; ir6 !=3D NULL; ir6 =3D ir6->next)
{
msg(D_MULTI_LOW, &qu= ot;MULTI: internal route %s/%d -> %s",
- print_in6_addr(ir6->network, 0,= &gc),
- = ir6->netbits,
+ print_in6_addr(ir6->network, 0, &gc), ir6->netb= its,
multi_instance_string(mi, false, &= ;gc));

mroute_helper_add_iro= ute46(m->route_helper, ir6->netbits);
@@ -1387,7 +135= 6,7 @@
hash_iterator_init(m->iter, &hi)= ;
while ((he =3D hash_iterator_next(&hi)))=
{
- struct multi_instance *mi =3D (struct multi_insta= nce *) he->value;
= + struct multi_instance *mi =3D (struct multi_instance *)he-= >value;
if (mi !=3D new_mi && != mi->halt)
{
= const char *cn =3D tls_common_name(mi->context.c2.tls_multi, t= rue);
@@ -1404,7 +1373,9 @@

if (count)

{
- msg(D_MULTI_LOW, "= MULTI: new connection by client '%s' will cause previous active ses= sions by this client to be dropped. Remember to use the --duplicate-cn opt= ion if you want multiple clients using the same certificate or username to = concurrently connect.", new_cn);
+ msg(D_MULTI_LOW,
+ "MULTI: new connect= ion by client '%s' will cause previous active sessions by this clie= nt to be dropped. Remember to use the --duplicate-cn option if you want mu= ltiple clients using the same certificate or username to concurrently conne= ct.",
+ = new_cn);
}
= }
}
@@ -1413,7 +1384,6 @@
<= span> static void

check_stale_routes(struct multi_context = *m)
{
= -
struct gc_arena gc =3D gc_new();
= struct hash_iterator hi;
struct hash_element *he;
@@ -1422,8 +1392,9 @@
hash_iterator_init= _range(m->vhash, &hi, 0, hash_n_buckets(m->vhash));
while ((he =3D hash_iterator_next(&hi)) !=3D NULL)

{

- str= uct multi_route *r =3D (struct multi_route *) he->value;
- if (multi_route_defined(m, r)= && difftime(now, r->last_reference) >=3D m->top.options.s= tale_routes_ageing_time)

+ struct multi_route *r =3D (struct multi_route *)he->value;<= /span>
+ if (multi_ro= ute_defined(m, r)
+ = && difftime(now, r->last_reference) >=3D m->top.= options.stale_routes_ageing_time)
{
dmsg(D_MULTI_DEBUG, "MULTI: Deleting stale route for ad= dress '%s'",

mroute_addr_pri= nt(&r->addr, &gc));
@@ -1446,7 +1417,8 @@=
const struct options *o =3D &c->options;
if (o->push_ifconfig_constraint_defined && c->c2.pus= h_ifconfig_defined)

{
- return (o->push_ifconfig_constraint_netmask= & c->c2.push_ifconfig_local) =3D=3D o->push_ifconfig_constraint_= network;
+ ret= urn (o->push_ifconfig_constraint_netmask & c->c2.push_ifconfig_lo= cal)
+ = =3D=3D o->push_ifconfig_constraint_network;
}
else
{
@@ -1480,7 +145= 2,8 @@

mi->context.c2.push_if= config_defined =3D true;
mi->context.c2.push_if= config_local =3D mi->context.options.push_ifconfig_local;
- mi->context.c2.push_ifcon= fig_remote_netmask =3D mi->context.options.push_ifconfig_remote_netmask;=

+ mi->cont= ext.c2.push_ifconfig_remote_netmask =3D
+ mi->context.options.push_ifconfig_remote= _netmask;
mi->context.c2.push_ifconfig_local_al= ias =3D mi->context.options.push_ifconfig_local_alias;
=
/* the current implementation does not allow &quo= t;static IPv4, pool IPv6",
@@ -1490,7 +1463,8 @@
if (mi->context.options.ifconfig_ipv6_pool_defined
&& !mi->context.options.push_ifconfi= g_ipv6_defined)
{
- msg( M_INFO, "MULTI_sva: WARNING: if = --ifconfig-push is used for IPv4, automatic IPv6 assignment from --ifconfig= -ipv6-pool does not work. Use --ifconfig-ipv6-push for IPv6 then." );=
+ msg(M_I= NFO,
+ = "MULTI_sva: WARNING: if --ifconfig-push is used for IPv4, automatic I= Pv6 assignment from --ifconfig-ipv6-pool does not work. Use --ifconfig-ipv= 6-push for IPv6 then.");
}
= }
else if (m->ifconfig_pool && mi->va= ddr_handle < 0) /* otherwise, choose a pool address */
@= @ -1505,30 +1479,33 @@
}
<= br> CLEAR(remote_ipv6);
- mi->vaddr_handle =3D ifconfig_pool_acquire(m->= ;ifconfig_pool, &local, &remote, &remote_ipv6, cn);
<= span style=3D"color: hsl(120, 100%, 40%);">+ mi->vaddr_handle =3D=

+ ifconfi= g_pool_acquire(m->ifconfig_pool, &local, &remote, &remote_ip= v6, cn);
if (mi->vaddr_handle >=3D 0)=
{
const int tunnel_type =3D= TUNNEL_TYPE(mi->context.c1.tuntap);
const = int tunnel_topology =3D TUNNEL_TOPOLOGY(mi->context.c1.tuntap);
- = msg( M_INFO, "MULTI_sva: pool returned IPv4=3D%s, IPv6=3D%s",
- (mi->= context.options.ifconfig_pool_defined
- ? print_in_addr_t(remote, 0, &gc)
- : "= ;(Not enabled)"),
= - (mi->context.options.ifconfig_ipv6_pool_defined=
- ? print_in= 6_addr( remote_ipv6, 0, &gc )
- : "(Not enabled)") );
+ msg(M_INFO, "MUL= TI_sva: pool returned IPv4=3D%s, IPv6=3D%s",

+ (mi->context.options.ifcon= fig_pool_defined ? print_in_addr_t(remote, 0, &gc)
+ = : "(Not enabled)"),
+ (mi->context.options.ifconf= ig_ipv6_pool_defined
= + ? print_in6_addr(remote_ipv6, 0, &gc)
<= span style=3D"color: hsl(120, 100%, 40%);">+ : "(N= ot enabled)"));


if (mi-= >context.options.ifconfig_pool_defined)
{
/* set push_ifconfig_remote_netmask from po= ol ifconfig address(es) */
mi->context.= c2.push_ifconfig_local =3D remote;
- if (tunnel_type =3D=3D DEV_TYPE_TAP || (tunnel= _type =3D=3D DEV_TYPE_TUN && tunnel_topology =3D=3D TOP_SUBNET))
+ if (tu= nnel_type =3D=3D DEV_TYPE_TAP
+ || (tunnel_type =3D=3D DEV_TYPE_TUN &&= ; tunnel_topology =3D=3D TOP_SUBNET))
{
- mi-&= gt;context.c2.push_ifconfig_remote_netmask =3D mi->context.options.ifcon= fig_pool_netmask;
+ = mi->context.c2.push_ifconfig_remote_netmask =3D=
+ mi= ->context.options.ifconfig_pool_netmask;
= if (!mi->context.c2.push_ifconfig_remote_netmask)
= {
= - mi->context.c2.push_ifconfig_remote_netmask =3D= mi->context.c1.tuntap->remote_netmask;
+ mi->context.c2.push_if= config_remote_netmask =3D
+ mi->context.c1.tuntap->remote_netma= sk;
}
= }
else if (tunnel_type =3D=3D DEV_TYPE_TU= N)
@@ -1558,8 +1535,7 @@
if (m= i->context.options.ifconfig_ipv6_pool_defined)
= {
mi->context.c2.push_ifconfig_ipv6= _local =3D remote_ipv6;
- mi->context.c2.push_ifconfig_ipv6_remote =3D- mi->cont= ext.c1.tuntap->local_ipv6;
+ mi->context.c2.push_ifconfig_ipv6_remote =3D m= i->context.c1.tuntap->local_ipv6;
mi= ->context.c2.push_ifconfig_ipv6_netbits =3D
= mi->context.options.ifconfig_ipv6_netbits;
= mi->context.c2.push_ifconfig_ipv6_defined =3D true;<= br>@@ -1580,17 +1556,14 @@
*/
= if (mi->context.options.push_ifconfig_ipv6_defined)
= {
- mi->= context.c2.push_ifconfig_ipv6_local =3D
- mi->context.options.push_ifconfig_ipv6_loc= al;
- mi->con= text.c2.push_ifconfig_ipv6_remote =3D
- mi->context.options.push_ifconfig_ipv6_remot= e;
- mi->cont= ext.c2.push_ifconfig_ipv6_netbits =3D
- mi->context.options.push_ifconfig_ipv6_netbi= ts;
+ mi->c= ontext.c2.push_ifconfig_ipv6_local =3D mi->context.options.push_ifconfig= _ipv6_local;
+ = mi->context.c2.push_ifconfig_ipv6_remote =3D mi->context.options.pus= h_ifconfig_ipv6_remote;
+ mi->context.c2.push_ifconfig_ipv6_netbits =3D mi->context= .options.push_ifconfig_ipv6_netbits;
mi->contex= t.c2.push_ifconfig_ipv6_defined =3D true;

- msg( M_INFO, "MULTI_sva:= push_ifconfig_ipv6 %s/%d",

- print_in6_addr( mi->context.c2.push_ifconfig_ipv= 6_local, 0, &gc ),
= - mi->context.c2.push_ifconfig_ipv6_netbits );
+ msg(M_INFO, "MULTI_s= va: push_ifconfig_ipv6 %s/%d",

+ print_in6_addr(mi->context.c2.push_ifconfig_= ipv6_local, 0, &gc),
+ mi->context.c2.push_ifconfig_ipv6_netbits);
<= span> }


gc_free(&gc);=
@@ -1611,24 +1584,19 @@
const int tunnel= _type =3D TUNNEL_TYPE(mi->context.c1.tuntap);
c= onst int tunnel_topology =3D TUNNEL_TOPOLOGY(mi->context.c1.tuntap);

- = setenv_in_addr_t(mi->context.c2.es,
- "ifconfig_pool_remote_ip&qu= ot;,
- = mi->context.c2.push_ifconfig_local,
- SA_SET_IF_NONZERO);
+ setenv_in_addr_t(= mi->context.c2.es, "ifconfig_pool_remote_ip",
+ mi->cont= ext.c2.push_ifconfig_local, SA_SET_IF_NONZERO);
- if (tunnel_type =3D=3D = DEV_TYPE_TAP || (tunnel_type =3D=3D DEV_TYPE_TUN && tunnel_topology= =3D=3D TOP_SUBNET))
= + if (tunnel_type =3D=3D DEV_TYPE_TAP
+ || (tunnel_type =3D=3D DEV_TYPE_TUN &a= mp;& tunnel_topology =3D=3D TOP_SUBNET))
{
- setenv_in_add= r_t(mi->context.c2.es,
- "ifconfig_pool_netmask",<= br>- = mi->context.c2.push_ifconfig_remote_netmask,
- SA_SET_IF_NONZERO);<= /span>
+ setenv_i= n_addr_t(mi->context.c2.es, "ifconfig_pool_netmask",+ = mi->context.c2.push_ifconfig_remote_netmask, SA_SET_IF_NONZERO);<= br> }
else if (tunnel_type =3D=3D DE= V_TYPE_TUN)
{
- setenv_in_addr_t(mi->context.c2.es,<= br>- = "ifconfig_pool_local_ip",
- mi->context.c2.push_ifconfig_= remote_netmask,
- = SA_SET_IF_NONZERO);
+ setenv_in_addr_t(mi->context.c2.es, &= quot;ifconfig_pool_local_ip",
+ mi->context.c2.push_ifconfig= _remote_netmask, SA_SET_IF_NONZERO);
}
<= span> }


@@ -1638,16 +1606,11 @@

if (mi->context.c2.push_ifconfig_ipv6_= defined)
{
- setenv_in6_addr(mi->context.c2.es,
- "ifconfig_po= ol_remote",
- = &mi->context.c2.push_ifconfig_ipv6_local,<= br>- SA_SE= T_IF_NONZERO);
- = setenv_in6_addr(mi->context.c2.es,
- "ifconfig_pool_local",
- = &mi->context.c2.push_ifconfig_ipv6_remote,
- SA_SET_IF_NONZERO);
- setenv_int(mi-&g= t;context.c2.es,
- = "ifconfig_pool_ip6_netbits",
+ setenv_in6_addr(mi->context.c2= .es, "ifconfig_pool_remote",
+ &mi->context.c2.push_ifco= nfig_ipv6_local, SA_SET_IF_NONZERO);
+ setenv_in6_addr(mi->context.c2.es, "ifconf= ig_pool_local",
= + &mi->context.c2.push_ifconfig_ipv6_remote, = SA_SET_IF_NONZERO);
+= setenv_int(mi->context.c2.es, "ifconfig_pool_ip6_netbits&qu= ot;,
mi->context.c2.push_ifconfig_ip= v6_netbits);
}
}
@@ -= 1656,20 +1619,14 @@
* Called after client-connect script = is called
*/
static void
-multi_client_connect_post(struct mult= i_context *m,

- = struct multi_instance *mi,
- const char *dc_file,
+multi_client_connect_post= (struct multi_context *m, struct multi_instance *mi, const char *dc_file,
unsigned int *option_types_found)=
{
/* Did script generate a dynamic c= onfig file? */
if (platform_test_file(dc_file))=
{
- = options_server_import(&mi->context.options,
- dc_file,
- = D_IMPORT_ERRORS|M_OPTERR,
- CLIENT_CONNECT_OPT_MASK,
- opti= on_types_found,

- = mi->context.c2.es);
+ options_server_import(&mi->contex= t.options, dc_file, D_IMPORT_ERRORS | M_OPTERR,
+ CLIENT_CONNECT_OP= T_MASK, option_types_found, mi->context.c2.es);
=
/*
* If the --client-connect s= cript generates a config file
@@ -1688,10 +1645,8 @@=
* Called after client-connect plug-in is called
*/

static void
-multi_client_connect_post_plugin(struct multi_context *m,
- = struct multi_instance *mi,
- const struct plugin_return *pr= ,
- = unsigned int *option_types_found)
+multi_client_connect_post_plugin(struct multi_co= ntext *m, struct multi_instance *mi,
+ const struct plugin_retur= n *pr, unsigned int *option_types_found)
{
struct plugin_return config;


@@ -17= 05,12 +1660,9 @@
{
if= (config.list[i] && config.list[i]->value)
= {
- = options_string_import(&mi->context.options,
- conf= ig.list[i]->value,
-= D_IMPORT_ERRORS|M_OPTERR,
<= span style=3D"color: hsl(0, 100%, 40%);">- = CLIENT_CONNECT_OPT_MASK,

- option_types_found,- = mi->context.c2.es);
+ options_string_import(&mi->context.options= , config.list[i]->value,
+ D_IMPORT_ERRORS | M_OPTERR, C= LIENT_CONNECT_OPT_MASK,
+ option_types_found, mi->contex= t.c2.es);
}
}<= br>
@@ -1732,9 +1684,7 @@
* Called= to load management-derived client-connect config
*/
enum client_connect_return
-multi_client_connect_mda(struct multi_context *m,<= br>- stru= ct multi_instance *mi,
= - bool deferred,
+multi_client_connect_mda(struct multi_context *m, stru= ct multi_instance *mi, bool deferred,
= unsigned int *option_types_found)
{
= /* We never return CC_RET_DEFERRED */
@@ -1747,12 +1697= ,8 @@
for (be =3D mi->cc_config->head; be != =3D NULL; be =3D be->next)
{
= const char *opt =3D BSTR(&be->buf);
- options_string_import(&mi-&= gt;context.options,
- = opt,
- D_IMPORT_ERRORS|M_OPTERR,<= /span>
- = CLIENT_CONNECT_OPT_MASK,
- option_types_found,=
- = mi->context.c2.es);
+ options_string_import(&mi->context.options, opt= , D_IMPORT_ERRORS | M_OPTERR,
+ CLIENT_CONNECT_OPT_MASK, option= _types_found, mi->context.c2.es);
}
<= span>

/*
@@ -1817,9 +1763,9 @@
else if (dco_enabled(o))
{ msg(M_INFO, "Client does not support DATA_V2. Data ch= annel offloading "
- "requires DATA_V2. Dropping client.");
+ "requir= es DATA_V2. Dropping client.");

auth_set_clie= nt_reason(tls_multi, "Data channel negotiation "
- "f= ailed (missing DATA_V2)");
+ "failed (missing= DATA_V2)");
return false;
= }

@@ -1828,8 +1774,8 @@
if (proto & IV_PROTO_NCP_P2P)

{
<= span> msg(M_WARN, "Note: peer reports running in P2P mode (no = --pull/--client "

= - "option). It will not negotiate ciphers with this server.= "
- &q= uot;Expect this connection to fail.");
+ "option). It will not nego= tiate ciphers with this server. "
+ "Expect this connection to fail= .");
}

if = (proto & IV_PROTO_REQUEST_PUSH)
@@ -1844,11 +1790,11 @@=
else if (o->force_key_material_export)
<= span> {

msg(M_INFO, "PUSH: client does no= t support TLS Keying Material "
- "Exporters but --force-tls-key-material-exp= ort is enabled.");
+ "Exporters but --force-tls-key-material-export= is enabled.");
auth_set_client_reason(tls_mu= lti, "Client incompatible with this "
- "server. Keyi= ng Material Exporters (RFC 5705) "
- "support missing. Upg= rade to a client that "
- "supports this feature (OpenVPN = 2.6.0+).");
+ = "server. Keying Material Export= ers (RFC 5705) "
+ "support missing. Upgrade = to a client that "
+ "supports this feature (= OpenVPN 2.6.0+).");
return false;
<= span> }

if (proto & IV_PROTO_DYN_TLS_CRYPT)
@@ -1869,10 +1815,11 @@
*/
if (get_primary_key(tls_multi)->crypto_options.key_ctx_bi.initi= alized)

{
- msg(M_INFO, "PUSH: client wants to negotiate cipher (= NCP), but "
+ = msg(M_INFO,
+ = "PUSH: client wants to negotiate cipher (NCP), but "
"server has already generated data channel k= eys, "
"re-sending previously negoti= ated cipher '%s'",
- o->ciphername );
+ o->ciphername);
= return true;
}

@@= -1880,14 +1827,13 @@
* Push the first cipher from --= data-ciphers to the client that
* the client announce= s to be supporting.
*/
- char *push_cipher =3D ncp_get_best_cipher(o->= ncp_ciphers, peer_info,
- tls_multi->remote_cipherna= me,
- = &o->gc);
+ char *push_cipher =3D
+ ncp_get_best_cipher(o->ncp_ciphers, = peer_info, tls_multi->remote_ciphername, &o->gc);
if (push_cipher)

{
/* E= nable epoch data key format if supported and AEAD cipher in use */- if (tls_multi->sess= ion[TM_ACTIVE].opt->data_epoch_supported
- && (proto & IV_PROTO_DATA_EPO= CH) && cipher_kt_mode_aead(push_cipher))
+ if (tls_multi->session[TM_ACTIVE].o= pt->data_epoch_supported && (proto & IV_PROTO_DATA_EPOCH)
+ &&= cipher_kt_mode_aead(push_cipher))
{
o->imported_protocol_flags |=3D CO_EPOCH_DATA_KEY_FORMAT= ;

}
@@ -1908,16 +1854,17 @@=
* side, in this situation we fail the auth*/
if (strlen(peer_ciphers) > 0)

{
- msg(M_INFO, "PUSH: No= common cipher between server and client. "

+ msg(M_INFO,
+ "PUSH: No common cipher betwe= en server and client. "
"Server data= -ciphers: '%s'%s, client supported ciphers '%s'",
o->ncp_ciphers_conf, ncp_expanded_ciphers(o, &a= mp;gc), peer_ciphers);
}
else if = (tls_multi->remote_ciphername)
{
- msg(M_INFO, "PUSH: No commo= n cipher between server and client. "
+ msg(M_INFO,
+ "PUSH: No common cipher between ser= ver and client. "
"Server data-ciphe= rs: '%s'%s, client supports cipher '%s'",
- o->ncp_ciphers_conf= , ncp_expanded_ciphers(o, &gc),

- tls_multi->remote_ciphername);
+ o->ncp_ciphers_conf,= ncp_expanded_ciphers(o, &gc), tls_multi->remote_ciphername);
=
}
else
{@@ -1925,20 +1872,22 @@

i= f (o->enable_ncp_fallback && !tls_multi->remote_ciphername)
{
- msg(M_INFO, "Using data channel cipher '%s' si= nce "
- = "--data-ciphers-fallback is set.", o->ciphername);=
+ msg(M_INFO,
+ "= Using data channel cipher '%s' since "
+ "--data-ciphers-fall= back is set.",
+= o->ciphername);
ret =3D tru= e;
}
else
{

msg(M_INFO, "Use --data-ciphe= rs-fallback with the cipher the "
- "client is using if you want to allow= the client to connect");
+ "client is using if you want to all= ow the client to connect");
}
}

if (!ret)
{
auth_set_client_reason(tls_multi, "Data channel cipher neg= otiation "

- = "failed (no shared cipher)");
= + = "failed (no shared cipher)");
}<= /span>

gc_free(&gc);
@@= -1961,8 +1910,7 @@
setenv_del(mi->context.c2.es, &= quot;client_connect_deferred_file");
if (!platfor= m_unlink(ccs->deferred_ret_file))
{
- msg(D_MULTI_ERRORS, "MUL= TI: problem deleting temporary file: %s",

- ccs->deferred_ret_file);
= + msg(D_MULTI_ERRORS, &q= uot;MULTI: problem deleting temporary file: %s", ccs->deferred_ret_= file);
}
free(ccs->deferred_re= t_file);
ccs->deferred_ret_file =3D NULL;@@ -1993,8 +1941,7 @@
}
cc= s->deferred_ret_file =3D string_alloc(fn, NULL);

- setenv_str(mi->conte= xt.c2.es, "client_connect_deferred_file",
- ccs->deferred_ret_file);<= /span>
+ setenv_str(mi-&g= t;context.c2.es, "client_connect_deferred_file", ccs->deferred= _ret_file);

gc_free(&gc);=
return true;
@@ -2045,7 +1992,7 @@ default:
/* We received an unk= nown/unexpected value. Assume failure. */
msg= (M_WARN, "WARNING: Unknown/unexpected value in deferred "<= br>- "client-= connect resultfile");
+ "client-connect resultfile");
ret =3D CC_RET_FAILED;
}
fclose(fp);
@@ -2067,8 +2014,7 @@ setenv_del(mi->context.c2.es, "client_connect_conf= ig_file");
if (!platform_unlink(ccs->confi= g_file))
{
- msg(D_MULTI_ERRORS, "MULTI: problem deleting= temporary file: %s",
- ccs->config_file);
+ msg(D_MULTI_ERRORS, "MULTI: problem= deleting temporary file: %s", ccs->config_file);
= }
free(ccs->config_file);
ccs->config_file =3D NULL;

@@ -2102,18 +2048= ,15 @@
}
ccs->config_file =3D = string_alloc(fn, NULL);

- setenv_str(mi->context.c2.es, "client_conne= ct_config_file",
-= ccs->config_file);
+ setenv_str(mi->context.c2.es, "client_connect_= config_file", ccs->config_file);

= gc_free(&gc);
return true;
}=

static enum client_connect_return
-multi_client_connect_call_p= lugin_v1(struct multi_context *m,
- struct multi_instance *mi,<= /span>
- = bool deferred,
- unsigned int *option_types_found= )
+multi_client_conne= ct_call_plugin_v1(struct multi_context *m, struct multi_instance *mi,
+ = bool deferred, unsigned int *option_types_found)
{

enum client_connect_return ret =3D CC_RET_SKIPPED;=
#ifdef ENABLE_PLUGIN
@@ -2131,8 +2074,7 @= @
if (!deferred)
{=
call =3D OPENVPN_PLUGIN_CLIENT_CONNECT;
- if (!ccs_gen_config_fi= le(mi)

- = || !ccs_gen_deferred_ret_file(mi))
+ if (!ccs_gen_config_file(mi) || !ccs_gen_deferr= ed_ret_file(mi))
{
= ret =3D CC_RET_FAILED;
goto cleanup;=
@@ -2147,8 +2089,7 @@
}
argv_printf(&argv, "%s", cc= s->config_file);
- = int plug_ret =3D plugin_call(mi->context.plugins, call,
= - = &argv, NULL, mi->context.c2.es);
+ int plug_ret =3D plugin_call(mi->context.= plugins, call, &argv, NULL, mi->context.c2.es);
= if (plug_ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS)
= {
ret =3D CC_RET_SUCCEEDED;
@@ -2188,8 +2129,7 @@

/* if we still think we ha= ve succeeded, do postprocessing */
if (ret =3D=3D = CC_RET_SUCCEEDED)
{
- multi_client_connect_post(m, mi, ccs->= ;config_file,
- = option_types_found);
+ multi_client_connect_post(m, mi,= ccs->config_file, option_types_found);
}
cleanup:
argv_free(&argv);<= br>@@ -2205,10 +2145,8 @@
}
=
static enum client_connect_return
-multi_client_connect_call_plugin_v2(struct multi_con= text *m,
- = struct multi_instance *mi,
- bool deferr= ed,
- = unsigned int *option_types_found)
+multi_client_connect_call_plugin_v2(struc= t multi_context *m, struct multi_instance *mi,
+ bool deferre= d, unsigned int *option_types_found)
{
= enum client_connect_return ret =3D CC_RET_SKIPPED;
#ifde= f ENABLE_PLUGIN
@@ -2216,8 +2154,7 @@
= ASSERT(mi);
ASSERT(option_types_found);

- int call =3D d= eferred ? OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 :
- OPENVPN_PLUGIN_CLIENT_CONNECT_V= 2;
+ int call =3D = deferred ? OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 : OPENVPN_PLUGIN_CLIENT_C= ONNECT_V2;
/* V2 callback, use a plugin_return struct = for passing back return info */
if (plugin_defined(mi-= >context.plugins, call))
{
@@ -2225= ,8 +2162,7 @@

plugin_return_init= (&pr);

- int plug_ret =3D plugin_call(mi->context.plugins, call,
- = NULL, &pr, mi->context.c2.es);
+ int plug_ret =3D plugin_call(mi->c= ontext.plugins, call, NULL, &pr, mi->context.c2.es);
if (plug_ret =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS)

= {
multi_client_connect_post_plugin(m,= mi, &pr, option_types_found);
@@ -2235,13 +2171,12 @@<= /span>
else if (plug_ret =3D=3D OPENVPN_PLUGIN_FUNC_DEFER= RED)
{
ret =3D CC_RET= _DEFERRED;
- = if (!(plugin_defined(mi->context.plugins,
- OPENVPN_PLUGIN_CLI= ENT_CONNECT_DEFER_V2)))
+ if (!(plugin_defined(mi->context.plugins, OPENVPN_PLUGIN= _CLIENT_CONNECT_DEFER_V2)))
{
= msg(M_WARN, "A plugin that defers from the "
- "= ;OPENVPN_PLUGIN_CLIENT_CONNECT_V2 call must also "
- "declare support= for "
- = "OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2");
+ &quo= t;OPENVPN_PLUGIN_CLIENT_CONNECT_V2 call must also "

+ "decl= are support for "
-multi_client_connect_script_deferred(struct multi_context *m,
<= span style=3D"color: hsl(0, 100%, 40%);">- = struct multi_instance *mi,

+multi_client_connect_script_deferred(struct multi_context *m, st= ruct multi_instance *mi,
= unsigned int *option_types_found)
{
= ASSERT(mi);
@@ -2285,8 +2219,7 @@
i= f (ret =3D=3D CC_RET_SUCCEEDED)
{
= ccs_delete_deferred_ret_file(mi);
- multi_client_connect_post(m, mi, ccs->config_fi= le,
- = option_types_found);
+ multi_client_connect_post(m, mi, ccs->config_fi= le, option_types_found);
ccs_delete_config_file(mi= );
}
if (ret =3D=3D CC_RET_FAILED= )
@@ -2302,9 +2235,7 @@
* Runs the --clie= nt-connect script if one is defined.
*/
= static enum client_connect_return
-multi_client_connect_call_script(struct multi_context *m,
- = struct multi_instance *mi,
- bool deferred,
+multi_client_connect_call_script(str= uct multi_context *m, struct multi_instance *mi, bool deferred,
<= span> unsigned int *option_types_found)
{
if (deferred)
@@ -232= 4,8 +2255,7 @@

setenv_str(mi->= ;context.c2.es, "script_type", "client-connect");

- i= f (!ccs_gen_config_file(mi)
- || !ccs_gen_deferred_ret_file(mi))
+ if (!ccs_gen_config_file(mi) || != ccs_gen_deferred_ret_file(mi))
{
= ret =3D CC_RET_FAILED;
goto cleanu= p;
@@ -2342,8 +2272,7 @@
}
else
{
- multi_client_connec= t_post(m, mi, ccs->config_file,

- option_types_found);=
+ mul= ti_client_connect_post(m, mi, ccs->config_file, option_types_found);
ret =3D CC_RET_SUCCEEDED;
= }
}
@@ -2364,8 +2293,7 @= @
}

static bool<= br>-multi_client_setup_dco_initia= l(struct multi_context *m,
- struct multi_instance *mi,
+multi_client_setup_dco_initial(s= truct multi_context *m, struct multi_instance *mi,

= struct gc_arena *gc)
{
<= span> if (!dco_enabled(&mi->context.options))

@@= -2376,8 +2304,8 @@
int ret =3D dco_multi_add_new_peer= (m, mi);
if (ret < 0)
{=
- msg(D_DCO, "Can= not add peer to DCO for %s: %s (%d)",
- multi_instance_string(mi, false, gc), stre= rror(-ret), ret);
+ = msg(D_DCO, "Cannot add peer to DCO for %s: %s (%d)", multi_= instance_string(mi, false, gc),
+ strerror(-ret), ret);
retu= rn false;
}

@@ -2398= ,9 +2326,8 @@
}
#endif
struct tls_session *session =3D &c->c2.tls_multi->session[= TM_ACTIVE];

- if (!t= ls_session_update_crypto_params(c->c2.tls_multi, session, &c->opt= ions,
- = &c->c2.frame, frame_fragment,
- = get_link_socket_info(c),

+ if (!tls_session_update_crypto_params(c->c2.tls_multi, = session, &c->options, &c->c2.frame,
+ fra= me_fragment, get_link_socket_info(c),
= &c->c1.tuntap->dco))
{=
msg(D_TLS_ERRORS, "TLS Error: initializing d= ata channel failed");
@@ -2412,8 +2339,7 @@
= }

static void
-multi_client_connect_late_setup(struct mu= lti_context *m,
- = struct multi_instance *mi,
+multi_client_connect_late_setup(struct mu= lti_context *m, struct multi_instance *mi,
= const unsigned int option_types_found)
{<= /span>
ASSERT(m);
@@ -2430,7 +2356,8 @@
*/
if (!mi->context.c2.push_ifconf= ig_defined)
{
- msg(D_MULTI_ERRORS, "MULTI: no dynamic or static = remote "
+ = msg(D_MULTI_ERRORS,
+ "MULTI: no dynamic or static remote "
"--ifconfig address is available for %s",
<= br> multi_instance_string(mi, false, &gc)); }
@@ -2446,7 +2373,8 @@
= print_in_addr_t(mi->context.options.push_ifconfig_constraint_netma= sk, 0, &gc);

/* JYFIXME -- t= his should cause the connection to fail */
- msg(D_MULTI_ERRORS, "MULTI ERROR: primary= virtual IP for %s (%s) "
+ msg(D_MULTI_ERRORS,
+ "MULTI ERROR: primary virtual IP for %s= (%s) "
"violates tunnel network/net= mask constraint (%s/%s)",
multi_instance_= string(mi, false, &gc),
print_in_addr_t(mi= ->context.c2.push_ifconfig_local, 0, &gc),
@@ -2490,= 9 +2418,7 @@
{
if (mi->con= text.c2.push_ifconfig_defined)
{
- multi_learn_in_addr_t(m, mi= ,
- = mi->context.c2.push_ifconfig_local,
- -1, true)= ;
+ multi_= learn_in_addr_t(m, mi, mi->context.c2.push_ifconfig_local, -1, true);
msg(D_MULTI_LOW, "MULTI: primary virtual IP= for %s: %s",
multi_instance_string(m= i, false, &gc),
print_in_addr_t(mi->= ;context.c2.push_ifconfig_local, 0, &gc));
@@ -2500,15 = +2426,12 @@

if (mi->context.c= 2.push_ifconfig_ipv6_defined)
{
- multi_learn_in6_addr(m, mi,<= /span>
- = mi->context.c2.push_ifconfig_ipv6_local,
- -1, true)= ;
+ multi_= learn_in6_addr(m, mi, mi->context.c2.push_ifconfig_ipv6_local, -1, true)= ;
/* TODO: find out where addresses are "= unlearned"!! */
const char *ifconfig_loca= l_ipv6 =3D
print_in6_addr(mi->context.c= 2.push_ifconfig_ipv6_local, 0, &gc);
msg(D= _MULTI_LOW, "MULTI: primary virtual IPv6 for %s: %s",
<= span style=3D"color: hsl(0, 100%, 40%);">- multi_instance_st= ring(mi, false, &gc),

- ifconfig_local_ipv6);
+ multi_instance_string(mi, false, &= ;gc), ifconfig_local_ipv6);
}

/* add routes locally, pointing to new client, if
@@ -2524,7 +2447,8 @@
}
= else if (mi->context.options.iroutes)
{=
- msg(D_MULTI_ERRORS, = "MULTI: --iroute options rejected for %s -- iroute "
+ msg(D_MULTI_ERRORS,
+ "MULTI:= --iroute options rejected for %s -- iroute "
= "only works with tun-style tunnels",
= multi_instance_string(mi, false, &gc));
}

@@ -2538,8 +2462,7 @@
}

static void
-multi_client_connect_early_setup(struct multi_context *m,
- s= truct multi_instance *mi)

+multi_client_connect_early_setup(struct multi_context *m, struct mult= i_instance *mi)
{
ASSERT(mi->conte= xt.c1.tuntap);
/*
@@ -2574,10 +2497,8 = @@
* ccd/script to do compression on a special client.
*/
static enum client_connect_return
-multi_client_connect_compr= ess_migrate(struct multi_context *m,
- struct multi_instance = *mi,
- = bool deferred,
- unsigned int *option_ty= pes_found)
+multi_cli= ent_connect_compress_migrate(struct multi_context *m, struct multi_instance= *mi,
+ = bool deferred, unsigned int *option_types_found)
{
#ifdef USE_COMP
stru= ct options *o =3D &mi->context.options;
@@ -2608,9 += 2529,7 @@
* --client-config-dir directory.
*/

static enum client_connect_return
-multi_client_connect_source_ccd(struct = multi_context *m,
- = struct multi_instance *mi,
- bool defer= red,
+multi_client_co= nnect_source_ccd(struct multi_context *m, struct multi_instance *mi, bool d= eferred,
unsigned int *opt= ion_types_found)
{
/* Since we never = return a CC_RET_DEFERRED, this indicates a serious
@@ -2624= ,12 +2543,10 @@

const char *ccd_= client =3D
platform_gen_path(mi->context.op= tions.client_config_dir,
- = &gc);
+ tls_common_name(mi->context.c2.tl= s_multi, false), &gc);

const= char *ccd_default =3D
= - platform_gen_path(mi->context.options.client_config_dir,
- = CCD_DEFAULT, &gc);
+ platform_gen_path(mi->context.options.client_config= _dir, CCD_DEFAULT, &gc);


= /* try common-name file */
@@ -2645,12 +2562= ,8 @@

if (ccd_file)
{

- = options_server_import(&mi->context.options,
- ccd_fil= e,
- = D_IMPORT_ERRORS|M_OPTERR,
- CLIENT_CONNECT_OPT_MAS= K,
- = option_types_found,
- mi->context.c2.es);
+ options_serve= r_import(&mi->context.options, ccd_file, D_IMPORT_ERRORS | M_OPTERR,=
+ = CLIENT_CONNECT_OPT_MASK, option_types_found, mi->context.= c2.es);
/*
* Sel= ect a virtual address from either --ifconfig-push in
= * --client-config-dir file or --ifconfig-pool.
@@ -= 2666,9 +2579,9 @@
return ret;
}

-typedef e= num client_connect_return (*multi_client_connect_handler)
- (struct multi_context *m, struct mu= lti_instance *mi,
- = bool from_deferred, unsigned int *option_types_found);
+typedef enum client_connect_return (*mul= ti_client_connect_handler)(
+ struct multi_context *m, struct multi_instance *mi, bool from_d= eferred,
+ unsigne= d int *option_types_found);

static const= multi_client_connect_handler client_connect_handlers[] =3D {
multi_client_connect_compress_migrate,

@@ -2694,9 += 2607,9 @@
if (!multi->locked_username)
{

msg(D_MULTI_ERRORS, "MULTI: Ignori= ng override-username as no "
- "user/password method is enabled. Enable "= ;
- "--= management-client-auth, --auth-user-pass-verify, or a "
- "plugin with user/p= assword verify capability.");

+ "user/password method is en= abled. Enable "
= + "--management-client-auth, --auth-user-pa= ss-verify, or a "
- strncpynt(up.username, multi->locked_username,- sizeof(u= p.username));
+ = strncpynt(up.username, multi->locked_username, sizeof(up.username)= );

generate_auth_token(&= up, multi);
}

- msg(D_MULTI_LOW, "MULTI: No= te, override-username changes username "
+ msg(D_MULTI_LOW,
+ "MULTI: Note, override-user= name changes username "
"from '%= s' to '%s'",
- multi->locked_original_username,
- multi->locked_username);
+ multi->= ;locked_original_username, multi->locked_username);
= }
return true;
}
@@ = -2767,8 +2679,7 @@
bool from_deferred =3D (mi->cont= ext.c2.tls_multi->multi_state !=3D CAS_PENDING);

int *cur_handler_index =3D &mi->client_connect_defer= _state.cur_handler_index;
- unsigned int *option_types_found =3D
- &mi->client_connect_defer_state.optio= n_types_found;
+ u= nsigned int *option_types_found =3D &mi->client_connect_defer_state.= option_types_found;

/* We are called= for the first time */
if (!from_deferred)
<= span>@@ -2783,12 +2694,10 @@


bool cc= _succeeded =3D true;

- while (cc_succeeded
- && client_connect_handlers[*cur_handl= er_index] !=3D NULL)
= + while (cc_succeeded && client_connect_handlers[*cur_handler_in= dex] !=3D NULL)
{
enum client= _connect_return ret;
- = ret =3D client_connect_handlers[*cur_handler_index](m, mi, from_defe= rred,
- = option_types_found);
+ ret =3D client_connect_h= andlers[*cur_handler_index](m, mi, from_deferred, option_types_found);

from_deferred =3D false;
<= span>

@@ -2836,7 +2745,7 @@
if (m= i->context.options.disable)
{
= msg(D_MULTI_ERRORS, "MULTI: client has been rejected due t= o "
- = "'disable' directive");
+ "'disable= ' directive");
cc_succeeded =3D false= ;
}

@@ -2889,8 += 2798,8 @@
#ifdef ENABLE_MANAGEMENT
if= (management)
{
- management_connection_established(management,=
- = &mi->context.c2.mda_context, mi->context.c2.es);
+ management_con= nection_established(management, &mi->context.c2.mda_context,<= br>+ = mi->context.c2.es);
}
#endif

}
@@ -2912,13 +2821,14 @@=
while (buffer_i < r)
{
/* parse inotify events */

- struct inotify_event *pevent =3D (struct inotify_e= vent *) &buffer[buffer_i];
+ struct inotify_event *pevent =3D (struct inotify_event *= )&buffer[buffer_i];
size_t event_size =3D size= of(struct inotify_event) + pevent->len;
buffer_= i +=3D event_size;

msg(D_MULTI_D= EBUG, "MULTI: modified fd %d, mask %d", pevent->wd, pevent->= ;mask);

- struct multi_instance *mi =3D hash_lookup(m->inotify_watcher= s, (void *) (unsigned long) pevent->wd);
+ struct multi_instance *mi =3D
+ hash_lookup(m->ino= tify_watchers, (void *)(unsigned long)pevent->wd);


if (pevent->mask & IN_CLOSE_WRITE)
<= span> {

@@ -2937,7 +2847,7 @@
= /* this event is _always_ fired when watch is removed or file is de= leted */
if (mi)
= {
- hash= _remove(m->inotify_watchers, (void *) (unsigned long) pevent->wd);
+ hash_r= emove(m->inotify_watchers, (void *)(unsigned long)pevent->wd);=
mi->inotify_watch =3D -1;
= }
}
@@ -2954,9 +2864,7 @= @
* instance.
*/
void<= /span>
-multi_add_mbuf(struct = multi_context *m,
- = struct multi_instance *mi,
- struct mbuf_buffer *mb)
+multi_add_mbuf(struct multi_context *m, = struct multi_instance *mi, struct mbuf_buffer *mb)
{
if (multi_output_queue_ready(m, mi))
{=
@@ -2975,9 +2883,7 @@
* Add a packet to = a client instance output queue.
*/
stati= c inline void
-multi_un= icast(struct multi_context *m,
- const struct buffer *buf,
- struct multi_instance *mi)<= br>+multi_unicast(struct multi_= context *m, const struct buffer *buf, struct multi_instance *mi)
= {
struct mbuf_buffer *mb;

@@ -2994,10 +2900,8 @@
* Broadcast a packet = to all clients.
*/
static void-multi_bcast(struct multi_contex= t *m,
- cons= t struct buffer *buf,
-= const struct multi_instance *sender_instance,
- uint16_t vid)
+multi_bcast(struct multi_context = *m, const struct buffer *buf,

+ const struct multi_instance *sender_instance, uint16_= t vid)
{
struct hash_iterator hi;
struct hash_element *he;
@@ -3015,7 +2919= ,7 @@

while ((he =3D hash_iterat= or_next(&hi)))
{
- mi =3D (struct multi_instance *) he->= ;value;
+ = mi =3D (struct multi_instance *)he->value;
= if (mi !=3D sender_instance && !mi->halt)
= {
if (vid !=3D 0 && vid != =3D mi->context.options.vlan_pvid)
@@ -3073,29 +2977,24 = @@
tv_add(&mi->wakeup, &mi->context.c2.t= imeval);

/* tell scheduler to wake u= s up at some point in the future */
- schedule_add_entry(m->schedule,
- (struct schedule_ent= ry *) mi,
- = &mi->wakeup,
+ schedule_add_entry(m->schedule, (struct schedule_entry *)= mi, &mi->wakeup,
compute_wak= eup_sigma(&mi->context.c2.timeval));
}

#if defined(ENABLE_ASYNC_PUSH)
stat= ic void
-add_inotify_fi= le_watch(struct multi_context *m, struct multi_instance *mi,
- int inotify_f= d, const char *file)

= +add_inotify_file_watch(struct multi_context *m, struct multi_instance *mi,= int inotify_fd,
+ = const char *file)
{
= /* watch acf file */
- long watch_descriptor =3D inotify_add_watch(inotify_fd, file,<= br>- = IN_CLOSE_WRITE | IN_ONESHOT);
+ long watch_descriptor =3D inotify_add_watch(= inotify_fd, file, IN_CLOSE_WRITE | IN_ONESHOT);
if (wa= tch_descriptor >=3D 0)
{
i= f (mi->inotify_watch !=3D -1)
{
- hash_remove(m->inotify= _watchers,

- = (void *) (unsigned long)mi->inotify_watch);
+ hash_remove(m->inoti= fy_watchers, (void *)(unsigned long)mi->inotify_watch);

= }
- has= h_add(m->inotify_watchers, (const uintptr_t *)watch_descriptor,- mi, true);
+ hash_add(m->= ;inotify_watchers, (const uintptr_t *)watch_descriptor, mi, true); mi->inotify_watch =3D watch_descriptor;
}

else
@@ -3117,7 +3016,9 @@
{
bool ret =3D true;

- if (!IS_SIG(&mi= ->context) && ((flags & MPP_PRE_SELECT) || ((flags & MPP= _CONDITIONAL_PRE_SELECT) && !ANY_OUT(&mi->context))))=
+ if (!IS_SIG(&mi-&g= t;context)
+ &= amp;& ((flags & MPP_PRE_SELECT)
+ || ((flags & MPP_CONDITIONAL_PRE_SELECT= ) && !ANY_OUT(&mi->context))))
{=
#if defined(ENABLE_ASYNC_PUSH)
bool was= _unauthenticated =3D true;
@@ -3142,14 +3043,12 @@ if (ks && ks->plugin_auth.auth_control_file &am= p;& was_unauthenticated
&& (ks->= ;authenticated =3D=3D KS_AUTH_DEFERRED))
{<= br>- add_inotify_file_= watch(m, mi, m->top.c2.inotify_fd,
- ks->plugin_auth.auth_= control_file);
+ = add_inotify_file_watch(m, mi, m->top.c2.inotify_fd, ks->plugin= _auth.auth_control_file);
}
= if (ks && ks->script_auth.auth_control_file && was_un= authenticated
&& (ks->authenticated= =3D=3D KS_AUTH_DEFERRED))
{
- add_inotify_file_watch(m, mi, m= ->top.c2.inotify_fd,
- ks->script_auth.auth_control_file);=
+ add_ino= tify_file_watch(m, mi, m->top.c2.inotify_fd, ks->script_auth.auth_con= trol_file);
}
#endif

@@ -3167,8 +3066,7 @@
= && mi->client_connect_defer_state.deferred_ret_file) {
add_inotify_file_wat= ch(m, mi, m->top.c2.inotify_fd,
- mi->client_connect_d= efer_state.
- = deferred_ret_file);
+ mi->= client_connect_defer_state.deferred_ret_file);
= }
#endif
/* tell scheduler t= o wake us up at some point in the future */
@@ -3190,14 +30= 88,10 @@
multi_set_pending(m, ANY_OUT(&mi->= context) ? mi : NULL);

#ifdef MULTI_DEBU= G_EVENT_LOOP
- p= rintf("POST %s[%d] to=3D%d lo=3D%d/%d w=3D%" PRIi64 "/%ld\n&= quot;,
- = id(mi),
- = (int) (mi =3D=3D m->pending),
- mi ? mi->context.c2.to_tun.len : -1,- mi ? mi->con= text.c2.to_link.len : -1,
+ printf("POST %s[%d] to=3D%d lo=3D%d/%d w=3D%" PRIi6= 4 "/%ld\n", id(mi), (int)(mi =3D=3D m->pending),
+ mi ? mi->contex= t.c2.to_tun.len : -1, mi ? mi->context.c2.to_link.len : -1,

(mi && mi->context.c2.fragment) ? mi->con= text.c2.fragment->outgoing.len : -1,

- (int64_t)mi->context.c2.timeval.tv_sec,=
- (long)= mi->context.c2.timeval.tv_usec);
+ (int64_t)mi->context.c2.timeval.tv_sec, (= long)mi->context.c2.timeval.tv_usec);
#endif
= }

@@ -3210,10 +3104,9 @@
}

void
-multi_process_float(struct multi_context *m= , struct multi_instance *mi,
- struct link_socket *sock)
+multi_process_float(struct multi_context = *m, struct multi_instance *mi, struct link_socket *sock)
{=
- struct mroute_add= r real =3D {0};
+ = struct mroute_addr real =3D { 0 };
struct hash *hash = =3D m->hash;
struct gc_arena gc =3D gc_new();

@@ -3235,7 +3128,7 @@
str= uct hash_element *he =3D hash_lookup_fast(hash, bucket, &real, hv);
if (he)
{
- struct multi_instance *ex_mi =3D (struct= multi_instance *) he->value;
+ struct multi_instance *ex_mi =3D (struct multi_instanc= e *)he->value;

struct tls_mul= ti *m1 =3D mi->context.c2.tls_multi;
struct tls= _multi *m2 =3D ex_mi->context.c2.tls_multi;
@@ -3256,10 = +3149,8 @@
}

ms= g(D_MULTI_MEDIUM, "peer %" PRIu32 " (%s) floated from %s to = %s",
- mi-&= gt;context.c2.tls_multi->peer_id,
- tls_common_name(mi->context.c2.tls_multi, false),=
- mroute_addr_p= rint(&mi->real, &gc),
- print_link_socket_actual(&m->top.c2.from, &gc= ));
+ mi->c= ontext.c2.tls_multi->peer_id, tls_common_name(mi->context.c2.tls_mult= i, false),
+ m= route_addr_print(&mi->real, &gc), print_link_socket_actual(&= m->top.c2.from, &gc));

/* rem= ove old address from hash table before changing address */
= ASSERT(hash_remove(m->hash, &mi->real));
@@ = -3303,7 +3194,8 @@
multi_close_instance(m, mi, false);=
}

-#if (defined(ENABLE_DCO) && (defined(TARGET_LINUX) = || defined(TARGET_FREEBSD))) || defined(ENABLE_MANAGEMENT)
+#if (defined(ENABLE_DCO) && = (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))) \
+ || defined(ENABLE_MANAGEMENT)<= br> static void
multi_signal_instance(struct multi_c= ontext *m, struct multi_instance *mi, const int sig)
{
@@ -3315,8 +3207,7 @@
#if defined(ENABLE_DCO)= \
&& (defined(TARGET_LINUX) || defined(TARGET= _FREEBSD) || defined(TARGET_WIN32))
static void
= -process_incoming_del_peer(struct= multi_context *m, struct multi_instance *mi,
- dco_context_t *dco)
+process_incoming_del_peer= (struct multi_context *m, struct multi_instance *mi, dco_context_t *dco)
{
const char *reason =3D "ovpn-dco= : unknown reason";
switch (dco->dco_del_peer_r= eason)
@@ -3404,9 +3295,10 @@
= */
msglevel =3D D_DCO_DEBUG;
= }
- msg= (msglevel, "Received DCO message for unknown peer-id: %d, "
- "type %d, = del_peer_reason %d", peer_id, dco->dco_message_type,
- dco->dco_del_peer_rea= son);

+ msg(ms= glevel,
+ = "Received DCO message for unknown peer-id: %d, "
+ "type %d, del_peer_= reason %d",
+ = peer_id, dco->dco_message_type, dco->dco_del_peer_reason);
}

dco->dco_me= ssage_type =3D 0;
@@ -3496,11 +3388,8 @@
= if (TUNNEL_TYPE(m->top.c1.tuntap) =3D=3D DEV_TYPE_TUN)=
{
/* extract packet= source and dest addresses */
- mroute_flags =3D mroute_extract_addr_from_packet(&a= mp;src,
- = &dest,
- = 0,

- &= c->c2.to_tun,
- = DEV_TYPE_TUN);
+ mroute= _flags =3D
+ = mroute_extract_addr_from_packet(&src, &dest, 0, &c-&= gt;c2.to_tun, DEV_TYPE_TUN);

= /* drop packet if extract failed */
i= f (!(mroute_flags & MROUTE_EXTRACT_SUCCEEDED))
@@ -3511= ,14 +3400,15 @@
else if (multi_get_instanc= e_by_virtual_addr(m, &src, true) !=3D m->pending)
= {
/* IPv6 link-local ad= dress (fe80::xxx)? */
-= if ( (src.type & MR_ADDR_MASK) =3D=3D MR_ADDR_IPV6<= /span>
- = && IN6_IS_ADDR_LINKLOCAL(&src.v6.addr) )
+ if ((src.type &= MR_ADDR_MASK) =3D=3D MR_ADDR_IPV6
+ && IN6_IS_ADDR_LINKLOCAL(&am= p;src.v6.addr))
{
= /* do nothing, for now. TODO: add address learning */=
}
= else
{
- msg(D_MULTI_DROPPED, "= MULTI: bad source address from client [%s], packet dropped",+ msg(D= _MULTI_DROPPED,
+ = "MULTI: bad source address from client [%s], p= acket dropped",
mroute_ad= dr_print(&src, &gc));
}=
c->c2.to_tun.len =3D 0;
@= @ -3567,11 +3457,8 @@
}
}

/* extract packet sou= rce and dest addresses */
- mroute_flags =3D mroute_extract_addr_from_packet(&s= rc,
- = &dest,
- = vid,
- &c-= >c2.to_tun,
- = DEV_TYPE_TAP);
+ mroute_f= lags =3D
+ = mroute_extract_addr_from_packet(&src, &dest, vid, &c-&= gt;c2.to_tun, DEV_TYPE_TAP);

= if (mroute_flags & MROUTE_EXTRACT_SUCCEEDED)
= {
@@ -3580,7 +3467,7 @@
= /* check for broadcast */
= if (m->enable_c2c)
{<= /span>
- = if (mroute_flags & (MROUTE_EXTRACT_BCAST|MROUTE_EXTRACT_MCAST))
+ = if (mroute_flags & (MROUTE_EXTRACT_BCAST | MROUTE_EXTRACT_MCAST)= )
{
= multi_bcast(m, &c->c2.to_tun, m->pending, = vid);
}
@@ -36= 00,7 +3487,8 @@
}
= else
{
- msg(D_MULTI_= DROPPED, "MULTI: bad source address from client [%s], packet dropped&q= uot;,

+ = msg(D_MULTI_DROPPED,
+ "MULTI: bad source address from= client [%s], packet dropped",
= mroute_addr_print(&src, &gc));
= c->c2.to_tun.len =3D 0;
= }
@@ -3634,7 +3522,7 @@
if (BLEN(&= m->top.c2.buf) > 0)
{
u= nsigned int mroute_flags;
- struct mroute_addr src =3D {0}, dest =3D {0};
+ struct mroute_addr src =3D { = 0 }, dest =3D { 0 };
const int dev_type =3D TUNNEL= _TYPE(m->top.c1.tuntap);
int16_t vid =3D 0;

@@ -3661,25 +3549,22 @@
= * the appropriate multi_instance object.
*/=

- = mroute_flags =3D mroute_extract_addr_from_packet(&src,
<= span style=3D"color: hsl(0, 100%, 40%);">- = &dest,

- vid,
- = &m->top.c2.buf,
- = dev_type);
- if (mroute_= flags & (MROUTE_EXTRACT_BCAST|MROUTE_EXTRACT_MCAST))
+ if (mroute_flags & (MR= OUTE_EXTRACT_BCAST | MROUTE_EXTRACT_MCAST))
{<= /span>
/* for now, treat multicast as broadcast *= /
multi_bcast(m, &m->top.c2.buf, NU= LL, vid);
}
else<= /span>
{
- multi_set_pending(m, multi_get_instance_by_virtual= _addr(m, &dest, dev_type =3D=3D DEV_TYPE_TUN));
+ multi_set_pending(=
+ m, mul= ti_get_instance_by_virtual_addr(m, &dest, dev_type =3D=3D DEV_TYPE_TUN)= );

if (m->pending)
{
@@ -3697,7 +3582,8 @@
else
= {
/* drop packet */
- = msg(D_MULTI_DROPPED, "MULTI: packet dropped due to output saturati= on (multi_process_incoming_tun)");
+ msg(D_MULTI_DROPPED,=
+ = "MULTI: packet dropped due to output saturation (multi_process_i= ncoming_tun)");
buf_reset= _len(&c->c2.buf);
}<= br> }
@@ -3731,7 +3617,8 @@

set_prefix(item.instance);
= item.instance->context.c2.buf =3D item.buffer->buf;
- if (item.buffer-= >flags & MF_UNICAST) /* --mssfix doesn't make sense for broadcas= t or multicast */
+ = if (item.buffer->flags
+ & MF_UNICAST) /* --mssfix doesn't make sens= e for broadcast or multicast */
{
= pip_flags |=3D PIP_MSSFIX;
}@@ -3769,7 +3656,8 @@
{
= if (m->earliest_wakeup =3D=3D (struct multi_instance *)&m->def= erred_shutdown_signal)
{
- schedule_remove_entry(m->schedul= e, (struct schedule_entry *) &m->deferred_shutdown_signal);+ schedule_remove_= entry(m->schedule,
+ (struct schedule_entry *)&m->def= erred_shutdown_signal);
throw_signal(m->def= erred_shutdown_signal.signal_received);
} else
@@ -3812,9 +3700,9 @@
route_quota_exceeded(const struct multi_instance *mi)

{<= /span>
struct gc_arena gc =3D gc_new();
- msg(D_ROUTE_QUOTA, "MULTI ROUTE: r= oute quota (%d) exceeded for %s (see --max-routes-per-client option)",=
- mi->contex= t.options.max_routes_per_client,
- multi_instance_string(mi, false, &gc));
+ msg(D_ROUTE_QUOTA,
+ "MULTI ROUTE: ro= ute quota (%d) exceeded for %s (see --max-routes-per-client option)",<= /span>
+ mi->conte= xt.options.max_routes_per_client, multi_instance_string(mi, false, &gc)= );
gc_free(&gc);
}

@@ -3837,8 +3725,7 @@
parm.pac= ket_size =3D min_int(parm.packet_size, m->top.c2.frame.buf.payload_size)= ;

msg(D_GREMLIN, "GREMLIN_F= LOOD_CLIENTS: flooding clients with %d packets of size %d",
= - parm.n_packets,
- parm.packet_si= ze);
+ par= m.n_packets, parm.packet_size);

= for (i =3D 0; i < parm.packet_size; ++i)
{
@@ -3926,10 +3813,11 @@
hash_iterator_init= (m->iter, &hi);
while ((he =3D hash_iterator_ne= xt(&hi)))
{
- struct multi_instance *mi =3D (struct multi_instance= *) he->value;
+ = struct multi_instance *mi =3D (struct multi_instance *)he->value;<= /span>
if (!mi->halt && proto_is_dgram(mi->= context.c2.link_sockets[0]->info.proto))
{
- send_control_c= hannel_string(&mi->context, next_server ? "RESTART,[N]" : = "RESTART", D_PUSH);
+ send_control_channel_string(&mi->context, next= _server ? "RESTART,[N]" : "RESTART",
+ = D_PUSH);
multi_schedule_context_wakeup(m, mi= );
}
}
@@ -39= 43,8 +3831,7 @@

m->deferred_shutd= own_signal.signal_received =3D m->top.sig->signal_received;
- schedule_= add_entry(m->schedule,
- (struct schedule_entry *) &m->deferred_sh= utdown_signal,
+ s= chedule_add_entry(m->schedule, (struct schedule_entry *)&m->defer= red_shutdown_signal,
&m->def= erred_shutdown_signal.wakeup,
compu= te_wakeup_sigma(&m->deferred_shutdown_signal.wakeup));

@@ -3965,8 +3852,7 @@
status_= close(so);
return false;
}
- else if (has_udp_in_= local_list(&m->top.options)
- && is_exit_restart(m->top.sig->sign= al_received)
+ els= e if (has_udp_in_local_list(&m->top.options) && is_exit_rest= art(m->top.sig->signal_received)
&&= amp; (m->deferred_shutdown_signal.signal_received =3D=3D 0)
&& m->top.options.ce.explicit_exit_notificatio= n !=3D 0)

{
@@ -3984,7 +3870,7 @@
static void
management_callback_status(void *= arg, const int version, struct status_output *so)
{=
- struct multi_context *m = =3D (struct multi_context *) arg;
+ struct multi_context *m =3D (struct multi_context *)arg;<= /span>

if (!version)
{=
@@ -3999,14 +3885,14 @@
static int=
management_callback_n_clients(void *arg)
{
- struct multi_context *= m =3D (struct multi_context *) arg;
+ struct multi_context *m =3D (struct multi_context *)arg= ;
return m->n_clients;
}
static int
management_callback_k= ill_by_cn(void *arg, const char *del_cn)
{
- struct multi_context *m =3D (stru= ct multi_context *) arg;

+ struct multi_context *m =3D (struct multi_context *)arg; struct hash_iterator hi;
struct hash_eleme= nt *he;
int count =3D 0;
@@ -4014,7 +3= 900,7 @@
hash_iterator_init(m->iter, &hi);
while ((he =3D hash_iterator_next(&hi)))
{

- stru= ct multi_instance *mi =3D (struct multi_instance *) he->value;+ struct multi_instance= *mi =3D (struct multi_instance *)he->value;
if= (!mi->halt)
{
con= st char *cn =3D tls_common_name(mi->context.c2.tls_multi, false);=
@@ -4030,10 +3916,9 @@
}

static int
= -management_callback_kill_by_addr(void *arg, const in_addr_t addr,- = const int port, const int proto)
+management_callback_kill_by_addr(void *arg, const in_addr_t= addr, const int port, const int proto)
{
- struct multi_context *m =3D (struc= t multi_context *) arg;
+ struct multi_context *m =3D (struct multi_context *)arg;
= struct hash_iterator hi;
struct hash_elemen= t *he;
struct openvpn_sockaddr saddr;
= @@ -4050,7 +3935,7 @@
hash_iterator_init(m->ite= r, &hi);
while ((he =3D hash_iterator_next(&am= p;hi)))
{
- struct multi_instance *mi =3D (struct multi_instan= ce *) he->value;
+= struct multi_instance *mi =3D (struct multi_instance *)he->v= alue;
if (!mi->halt && mroute_addr_= equal(&maddr, &mi->real))
{<= br> multi_signal_instance(m, mi, SIGTERM);
= @@ -4065,7 +3950,7 @@
static void
m= anagement_delete_event(void *arg, event_t event)
{<= br>- struct multi_context *m = =3D (struct multi_context *) arg;
+ struct multi_context *m =3D (struct multi_context *)arg;<= /span>
if (m->multi_io)
{
<= span> multi_tcp_delete_event(m->multi_io, event);

@@ -4077,7 +3962,7 @@

{
if (m)
{
- = struct multi_instance *mi =3D (struct multi_instance *) hash_lookup(m-= >cid_hash, &cid);
+ struct multi_instance *mi =3D (struct multi_instance *)hash_lo= okup(m->cid_hash, &cid);
if (mi && = !mi->halt)
{
retur= n mi;
@@ -4089,7 +3974,7 @@
static bool
management_kill_by_cid(void *arg, const unsigned long cid, c= onst char *kill_msg)
{
- struct multi_context *m =3D (struct multi_context *) = arg;
+ struct mult= i_context *m =3D (struct multi_context *)arg;
struct m= ulti_instance *mi =3D lookup_by_cid(m, cid);
if (mi)
{
@@ -4104,13 +3989,10 @@
}


static bool
-management_client_pending_auth(void *arg,
- = const unsigned long cid,
- const unsigned int mda_key_id,
- = const char *extra,
- unsigned int timeout)
+management_client_pending_auth(void *a= rg, const unsigned long cid, const unsigned int mda_key_id,
+ cons= t char *extra, unsigned int timeout)

{
- struct multi_context *m =3D (struct m= ulti_context *) arg;
= + struct multi_context *m =3D (struct multi_context *)arg;
struct multi_instance *mi =3D lookup_by_cid(m, cid);


if (mi)
@@ -4132,8 +4014,7 @@
}

/* sends = INFO_PRE and AUTH_PENDING messages to client */
- bool ret =3D send_auth_pending_messages(m= ulti, session, extra,
-= timeout);
+ bool ret =3D send_auth_pending_= messages(multi, session, extra, timeout);
reschedu= le_multi_process(&mi->context);
multi_sched= ule_context_wakeup(m, mi);
return ret;
<= span>@@ -4143,15 +4024,11 @@



= static bool
-man= agement_client_auth(void *arg,
- const unsigned long cid,
- const unsigned in= t mda_key_id,
- = const bool auth,
- const char *reason,
- const char *client_r= eason,
- = struct buffer_list *cc_config) /* ownership transferred */<= br>+management_client_auth(void= *arg, const unsigned long cid, const unsigned int mda_key_id,
+ const boo= l auth, const char *reason, const char *client_reason,

+ struct buffer_lis= t *cc_config) /* ownership transferred */
{
- struct multi_context *m =3D (str= uct multi_context *) arg;

+ struct multi_context *m =3D (struct multi_context *)arg; struct multi_instance *mi =3D lookup_by_cid(m, cid); bool cc_config_owned =3D true;
bool ret = =3D false;
@@ -4171,7 +4048,8 @@
= }
else if (reason)
= {
- = msg(D_MULTI_LOW, "MULTI: connection rejected: %s, CLI:%s", reaso= n, np(client_reason));
= + np(client_reason));
}
}
}
@@ -4185,7 += 4063,7 @@
static char *
management_get_pe= er_info(void *arg, const unsigned long cid)
{
- struct multi_context *m =3D (s= truct multi_context *) arg;

+ struct multi_context *m =3D (struct multi_context *)arg;=
struct multi_instance *mi =3D lookup_by_cid(m, cid);<= br> char *ret =3D NULL;

@@ -432= 8,7 +4206,7 @@

tunnel_server_loop(&a= mp;multi);

- #ifdef ENABLE_ASYNC_PUSH
+#ifdef ENABLE_ASYNC_PUSH
close(top->= ;c2.inotify_fd);
#endif

= @@ -4342,5 +4220,4 @@
multi_uninit(&multi);=
multi_top_free(&multi);
close_insta= nce(top);
-
<= span> }

diff --git a/src/openvpn/multi.h b/src/openvpn/mult= i.h
index 40f7519..184432e 100644
--- a/src= /openvpn/multi.h
+++ b/src/openvpn/multi.h
= @@ -100,27 +100,28 @@
* page describes the role the struc= ture plays when OpenVPN is running in
* server-mode.
*/
-struc= t multi_instance {
- = struct schedule_entry se; /* this must be the first element of the struct= ure,
- = * We cast between this and schedule_entry so the
<= span style=3D"color: hsl(0, 100%, 40%);">- *= beginning of the struct must be identical */

+struct multi_instance
+{
+ struct schedule_entry se; /* this must be the first element o= f the structure,
+ = * We cast between this and schedule_entry so th= e
+ = * beginning of the struct must be identical */

- struct event_ar= g ev_arg; /**< this struct will store a pointer to either mi or=
- = * link_socket, depending on the event type, to keep
- * it acce= ssible it's placed within the same struct
- * it points to. */<= /span>
+ struct event_arg= ev_arg; /**< this struct will store a pointer to either mi or+ = * link_socket, depending on the event type, to keep
+ * it acce= ssible it's placed within the same struct
+ * it points to. */=

struct gc_arena gc;
bool halt;

int refcount;
- int route_count; /* number of= routes (including cached routes) owned by this instance */
- time_t created; /**&l= t; Time at which a VPN tunnel instance

- * was created. This pa= rameter is set
- = * by the \c multi_create_instance()
<= span style=3D"color: hsl(0, 100%, 40%);">- = * function. */

- s= truct timeval wakeup; /* absolute time */
- struct mroute_addr real; /**< External ne= twork address of the
- = * remote peer. */
+ int route_count; /* number of= routes (including cached routes) owned by this instance */
+ time_t created; /**<= ; Time at which a VPN tunnel instance

+ * was created. This para= meter is set
+ = * by the \c multi_create_instance()
+ * = function. */

+ str= uct timeval wakeup; /* absolute time */
+ struct mroute_addr real; /**< External network= address of the
+ = * remote peer. */
ifconfig= _pool_handle vaddr_handle;
char msg_prefix[MULTI_PREFI= X_MAX_LENGTH];

@@ -129,7 +130,7 @@=
struct mbuf_set *tcp_link_out_deferred;
= bool socket_set_called;

- in_addr_t reporting_addr; /* IP address shown = in status listing */
= + in_addr_t reporting_addr; /* IP address shown in status lis= ting */
struct in6_addr reporting_addr_ipv6; /* IPv6 a= ddress in status listing */

bool did= _real_hash;
@@ -139,10 +140,10 @@
stru= ct buffer_list *cc_config;
#endif
boo= l did_iroutes;
- int= n_clients_delta; /* added to multi_context.n_clients when instance is clos= ed */
+ int n_clie= nts_delta; /* added to multi_context.n_clients when instance is closed *= /

- = struct context context; /**< The context structure storing state
- = * for this VPN tunnel. */
+ struct context context; /**< The context structure= storing state
+ = * for this VPN tunnel. */
st= ruct client_connect_defer_state client_connect_defer_state;
#ifdef ENABLE_ASYNC_PUSH

int inotify_watch; /* watch= descriptor for acf */
@@ -160,22 +161,23 @@
* page describes the role the structure plays when OpenVPN is running i= n

* server-mode.
*/
-struct multi_context {
- struct multi_instance **instances; = /**< Array of multi_instances. An instance can be
- * = accessed using peer-id as an index. */
+struct multi_context
+{
+ struct multi_instance **instances; /**< Array of multi_instances. = An instance can be
+ = * accessed using peer-id as an index= . */

= - struct hash *hash; /**< VPN tunnel instances indexed by re= al
- = * address of the remote peer. */
- struct hash *vhash; /**< VPN tunn= el instances indexed by
- * virtual address of remote hosts. */<= /span>
- struct hash *iter;= /**< VPN tunnel instances indexed by real
- * addre= ss of the remote peer, optimized
- * for iteration. */+ struct hash *hash; = /**< VPN tunnel instances indexed by real
+ = * address of the remote peer. */
+ struct hash *vhash; /**< VPN tunnel in= stances indexed by
+ = * virtual address of remote hosts.= */
+ struct hash = *iter; /**< VPN tunnel instances indexed by real<= br>+ = * address of the remote peer, optimized
+ = * for iteration. */
struct schedule *schedule;
- struct mbuf_set *mbuf; = /**< Set of buffers for passing data
- * channel packets= between VPN tunnel
- = * instances. */
- struct multi_io *multi_io; /**< I/O s= tate and events tracker */
+ struct mbuf_set *mbuf; /**< Set of buffers for pa= ssing data
+ = * channel packets between VPN tunnel
+ = * instances. */
+ struct multi_io *multi_io; /**< I/O state and e= vents tracker */
struct ifconfig_pool *ifconfig_pool;<= /span>
struct frequency_limit *new_connection_limiter;=
struct initial_packet_rate_limit *initial_rate_limiter;
@@ -199,8 +201,8 @@
struct context_buffers= *context_buffers;
time_t per_second_trigger;
- struct c= ontext top; /**< Storage structure for process-wide
- *= configuration. */

= + struct context top; /**< Storage structure for process-wide<= br>+ * = configuration. */

struct buffer hm= ac_reply;
struct link_socket_actual *hmac_reply_dest;<= /span>
@@ -238,8 +240,8 @@
struct mroute_addr= addr;
struct multi_instance *instance;

-#define MULTI_ROUT= E_CACHE (1<<0)
= -#define MULTI_ROUTE_AGEABLE (1<<1)
+#define MULTI_ROUTE_CACHE (1 << 0)
= +#define MULTI_ROUTE_AGEABLE (1= << 1)
unsigned int flags;

unsigned int cache_generation;
@@ -271,7 = +273,8 @@

void multi_top_free(struct mul= ti_context *m);

-struct multi_instance *multi_create_instance(struct multi_conte= xt *m, const struct mroute_addr *real,
+struct multi_instance *multi_create_instance(struct mult= i_context *m,
+ = const struct mroute_addr *real,
struct link_socke= t *sock);

void multi_close_instance(stru= ct multi_context *m, struct multi_instance *mi, bool shutdown);
<= span>@@ -289,10 +292,10 @@

void multi_process_float(struct= multi_context *m, struct multi_instance *mi,
= struct link_socket *sock);

-#define MPP_PRE_SELECT (1&l= t;<0)
-#define MPP_C= ONDITIONAL_PRE_SELECT (1<<1)
-#define MPP_CLOSE_ON_SIGNAL (1<<2)
-#define MPP_RECORD_TOUCH (= 1<<3)

+#define = MPP_PRE_SELECT (1 << 0)
+#define MPP_CONDITIONAL_PRE_SELECT (1 << 1)
+#define MPP_CLOSE_ON_SI= GNAL (1 << 2)
+#define MPP_RECORD_TOUCH (1 << 3)
<= /span>

/***************************************= ***********************************/
@@ -317,7 +320,8 @@
* signal during processing.
* - False= , if the VPN tunnel instance \a mi was closed.
*/<= br>-bool multi_process_post(struc= t multi_context *m, struct multi_instance *mi, const unsigned int flags);
+bool multi_process_po= st(struct multi_context *m, struct multi_instance *mi,
+ const unsigned i= nt flags);

/**
* Proce= ss an incoming DCO message (from kernel space).
@@ -354,8 += 358,8 @@
* @param mpp_flags - Fast I/O optimization fl= ags.
* @param sock - Socket where the packet was = received.
*/
-bool multi_process_incoming_link(struct multi_context *m, struct m= ulti_instance *instance, const unsigned int mpp_flags,
- struct li= nk_socket *sock);
+bo= ol multi_process_incoming_link(struct multi_context *m, struct multi_instan= ce *instance,
+ = const unsigned int mpp_flags, struct link_socket= *sock);


/**@@ -382,9 +386,7 @@

struct multi_= instance *multi_get_queue(struct mbuf_set *ms);
-void multi_add_mbuf(struct mult= i_context *m,
- = struct multi_instance *mi,
- struct mbuf_buffer *mb);
+void multi_add_mbuf(struct multi_= context *m, struct multi_instance *mi, struct mbuf_buffer *mb);

<= span>

void multi_ifconfig_pool_persist(struct multi_conte= xt *m, bool force);

@@ -410,8 +412,7 @@
* Return true if our output queue is not full
*/

static inline bool
-multi_output_queue_ready(const struct multi_context = *m,
- = const struct multi_instance *mi)
+multi_output_queue_ready(const struct multi_context *m,= const struct multi_instance *mi)
{
i= f (mi->tcp_link_out_deferred)
{
@@ = -507,8 +508,7 @@
}

stat= ic inline bool
-multi_r= oute_defined(const struct multi_context *m,
- const struct multi_route *r)
+multi_route_defined(cons= t struct multi_context *m, const struct multi_route *r)
{<= /span>
if (r->instance->halt)
{
@@ -533,8 +533,7 @@
/*
* T= akes prefix away from multi_instance.
*/
-void
-ungenerate_prefix(struct multi_instance *mi);+void ungenerate_prefix(struct= multi_instance *mi);

/*
* Set a msg() function prefix with our current client instance ID.
@@ -570,10 +569,10 @@
* don't want to reap= in a single pass.
*/

-#define REAP_MAX_WAKEUP 10 /* Do rea= p pass at least once per n seconds */
-#define REAP_DIVISOR 256 /* How many passes to cover w= hole hash table */
-#de= fine REAP_MIN 16 /* Minimum number of buckets per pass */<= br>-#define REAP_MAX 1024 = /* Maximum number of buckets per pass */
+#define REAP_MAX_WAKEUP 10 /* Do reap pass at least= once per n seconds */
+#define REAP_MI= N 16 /* Minimum number of buckets per pass */
+#define REAP_MAX 1024 /* Maximum = number of buckets per pass */

/*<= br> * Mark a cached host route for deletion after this
@@ -618,7 +617,7 @@

struct timeval tv, current;

CLEAR(tv);
- m->earliest_wakeup =3D (struct multi_instan= ce *) schedule_get_earliest_wakeup(m->schedule, &tv);
+ m->earliest_wakeup =3D (str= uct multi_instance *)schedule_get_earliest_wakeup(m->schedule, &tv);=

if (m->earliest_wakeup)
{
ASSERT(!openvpn_gettimeofday(&current, NULL));
@@ -663,9 +662,7 @@

AS= SERT(mi);
#ifdef MULTI_DEBUG_EVENT_LOOP
- printf("%s -> TUN len=3D%d\n= ",
- id(= mi),
- mi->= ;context.c2.to_tun.len);
+ printf("%s -> TUN len=3D%d\n", id(mi), mi->context= .c2.to_tun.len);
#endif
set_prefix(mi= );
vlan_process_outgoing_tun(m, mi);
@= @ -675,12 +672,13 @@
return ret;
}

-#defin= e CLIENT_CONNECT_OPT_MASK (OPT_P_INSTANCE | OPT_P_INHERIT \
- |O= PT_P_PUSH | OPT_P_TIMER | OPT_P_CONFIG \

- |OPT_P_ECHO | OPT_P_C= OMP | OPT_P_SOCKFLAGS)
= + (OPT_P_INSTANCE | OPT_P_INHERIT | OPT_P_PUSH | OPT_P_TIMER | OPT_P_CON= FIG | OPT_P_ECHO \
+ = | OPT_P_COMP | OPT_P_SOCKFLAGS)

stat= ic inline bool
-multi_p= rocess_outgoing_link_dowork(struct multi_context *m, struct multi_instance = *mi, const unsigned int mpp_flags)
+multi_process_outgoing_link_dowork(struct multi_context *m, = struct multi_instance *mi,
+ const unsigned int mpp_flags)
{
bool ret =3D true;
= set_prefix(mi);
diff --git a/src/openvpn/multi_io.c b/src= /openvpn/multi_io.c
index 4854f4b..8cd7bba 100644--- a/src/openvpn/multi_io.c
+++ b/src/openvpn/multi= _io.c
@@ -40,12 +40,12 @@
/*
* Special tags passed to event.[ch] functions

*/
-#define MULTI_IO_SOCKET = ((void *)1)
-#defin= e MULTI_IO_TUN ((void *)2)
-#define MULTI_IO_SIG ((void *)3) /* Only on Windows */=
-#define MULTI_IO_MANA= GEMENT ((void *)4)
+#= define MULTI_IO_SOCKET ((void *)1)
+#define MULTI_IO_TUN ((void *)2)
+#define MULTI_IO_SIG = ((void *)3) /* Only on Windows */
+#define MULTI_IO_MANAGEMENT ((void *)4)
#define MULTI_IO_FILE_CLOSE_WRITE ((void *)5)
-#define MULTI_IO_DCO ((void *)6)=
+#define MULTI_IO_DC= O ((void *)6)

struct ta_iow= _flags
{
@@ -128,7 +128,8 @@
wait_signal(multi_io->es, MULTI_IO_SIG);

AL= LOC_ARRAY(multi_io->esr, struct event_set_return, multi_io->maxevents= );
*maxclients =3D max_int(min_int(multi_io->maxeve= nts - extra_events, *maxclients), 1);
- msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclien= ts=3D%d maxevents=3D%d", *maxclients, multi_io->maxevents);<= br>+ msg(D_MULTI_LOW, "= MULTI IO: MULTI_IO INIT maxclients=3D%d maxevents=3D%d", *maxclients,<= /span>
+ multi_io->= ;maxevents);
return multi_io;
}

@@ -143,18 +144,13 @@
mi-= >socket_set_called =3D true;
if (proto_is_dgram(mi-= >context.c2.link_sockets[0]->info.proto))
{
- socket_set(mi->= context.c2.link_sockets[0],
- m->multi_io->es,
- EVENT_READ,
- &mi->context.c= 2.link_sockets[0]->ev_arg,
- NULL);
+ socket_set(mi->context.c2.link_sockets[0], m->m= ulti_io->es, EVENT_READ,
+ &mi->context.c2.link_sockets[0]->ev_ar= g, NULL);
}
else
= {
- socket_= set(mi->context.c2.link_sockets[0],
- m->multi_io->es,
- mbuf_defined(mi->= ;tcp_link_out_deferred) ? EVENT_WRITE : EVENT_READ,
- &mi->ev_arg,
+ socket_set(mi-&g= t;context.c2.link_sockets[0], m->multi_io->es,
+ mbuf_defined(mi->tc= p_link_out_deferred) ? EVENT_WRITE : EVENT_READ, &mi->ev_arg,=
&mi->tcp_rwflags);
= }
}
@@ -199,7 +195,8 @@
= #ifdef ENABLE_MANAGEMENT
if (management)
{

- man= agement_socket_set(management, m->multi_io->es, MULTI_IO_MANAGEMENT, = &m->multi_io->management_persist_flags);
+ management_socket_set(management, m-= >multi_io->es, MULTI_IO_MANAGEMENT,
+ &m->multi_io->= ;management_persist_flags);
}
#endif<= /span>

@@ -208,7 +205,8 @@
= event_ctl(m->multi_io->es, m->top.c2.inotify_fd, EVENT_READ, MULTI= _IO_FILE_CLOSE_WRITE);
#endif

= - status =3D event_wait(m->= multi_io->es, &m->top.c2.timeval, m->multi_io->esr, m->m= ulti_io->maxevents);
+ status =3D
+ = event_wait(m->multi_io->es, &m->top.c2.timeval, m->m= ulti_io->esr, m->multi_io->maxevents);
update= _time();
m->multi_io->n_esr =3D 0;
if (status > 0)

@@ -219,13 +217,13 @@
= }

static int
-multi_io_wait_lite(struct multi_context *m= , struct multi_instance *mi, const int action, bool *tun_input_pending)
+multi_io_wait_lite(stru= ct multi_context *m, struct multi_instance *mi, const int action,+ bool *tun_= input_pending)
{
struct context *c = =3D multi_get_context(m, mi);
unsigned int looking_for= =3D 0;

- dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_wait_lite a=3D%s mi=3D= " ptr_format,
- = pract(action),
= + dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_wait_lite a=3D%s mi=3D&qu= ot; ptr_format, pract(action),
(ptr_type)mi);

tv_clear(&c->c2.timeval); /* ZER= O-TIMEOUT */
@@ -256,7 +254,7 @@
case TA_SOCKET_WRITE:
looking= _for =3D SOCKET_WRITE;
= - io_wait(c, IOW_TO_LINK|IOW_READ_TUN_FORCE);
+ io_wait(c, IOW_TO_LINK | I= OW_READ_TUN_FORCE);
break;

default:
@@ -292,12 +290,11 @@
static struct multi_instance *
multi_io_dispa= tch(struct multi_context *m, struct multi_instance *mi, const int action)
{
- = const unsigned int mpp_flags =3D MPP_PRE_SELECT|MPP_RECORD_TOUCH;+ const unsigned int mpp_fl= ags =3D MPP_PRE_SELECT | MPP_RECORD_TOUCH;
struct mult= i_instance *touched =3D mi;
m->mpp_touched =3D &= ;touched;

- dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_dispatch a=3D%s mi= =3D" ptr_format,
-= pract(action),
+ dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_dispatch a=3D%s mi=3D&= quot; ptr_format, pract(action),
(ptr_type)mi);

switch (action)
@@ -3= 20,8 +317,7 @@
clear_prefix();
if (!IS_SIG(&mi->context))

= {
- mu= lti_process_incoming_link(m, mi, mpp_flags,
- mi->co= ntext.c2.link_sockets[0]);
+ multi_process_incoming_link(m, mi, mpp_flags, mi->= ;context.c2.link_sockets[0]);
if (!IS_SIG(= &mi->context))
{
= stream_buf_read_setup(mi->context.c2.link_sockets[0])= ;
@@ -374,9 +370,9 @@
struct context *= c =3D multi_get_context(m, mi);
int newaction =3D TA_U= NDEF;

-#define MTP_NONE 0
-#define MTP_TUN_OUT (1<<0)
-#define MTP_LINK_OUT (1<<1)
+#define MTP_NONE 0

<= span style=3D"color: hsl(120, 100%, 40%);">+#define MTP_TUN_OUT (1 <<= ; 0)

+#define MTP_LIN= K_OUT (1 << 1)
unsigned int flags =3D MTP_NONE;<= /span>

if (TUN_OUT(c))
@@ -= 390,7 +386,7 @@

switch (flags)
{
- = case MTP_TUN_OUT|MTP_LINK_OUT:
+ case MTP_TUN_OUT | MTP_LINK_OUT:
= case MTP_TUN_OUT:
newaction =3D TA_TUN_W= RITE;
break;
@@ -414,16 +410,1= 3 @@
{
struct gc_aren= a gc =3D gc_new();
msg(M_FATAL, "MULTI IO= : multi_io_post bad state, mi=3D%s flags=3D%d",
- multi_instance_string(mi, f= alse, &gc),
- = flags);
+ = multi_instance_string(mi, false, &gc), flags);
= gc_free(&gc);
break;
}
}
- dmsg(D_MULTI_DEBUG, "M= ULTI IO: multi_io_post %s -> %s",
- pract(action),
- pract(newaction));
+ dmsg(D_MULTI_DEBUG, "MULTI IO: multi= _io_post %s -> %s", pract(action), pract(newaction));

return newaction;
}
@@ -502,48 +495,48 @@

}
= else
#endif
- /* incoming data on TUN? */
- if (e->arg =3D=3D MULTI_= IO_TUN)
- {<= /span>
- if (e-= >rwflags & EVENT_WRITE)
+ /* incoming data on TUN? */
+ if (e->arg =3D=3D MUL= TI_IO_TUN)
{
- multi_io_action(m, NULL, TA_TUN= _WRITE, false);
+ = if (e->rwflags & EVENT_WRITE)
+ {
+ multi_io_action= (m, NULL, TA_TUN_WRITE, false);
+ }
+ else if (e->rwflags & EVENT_READ)<= /span>
+ = {
+ = multi_io_action(m, NULL, TA_TUN_READ, false);
+ }
= }
- = else if (e->rwflags & EVENT_READ)
+ /* new incoming TCP client a= ttempting to connect? */
+ else if (e->arg =3D=3D MULTI_IO_SOCKET)
<= span> {

- multi_io_action(m, NULL, TA_TUN_READ, false);<= br>+ struct = multi_instance *mi;
+= ASSERT(m->top.c2.link_sockets[0]);
+ socket_reset_list= en_persistent(m->top.c2.link_sockets[0]);
+ mi =3D multi_create_instance_t= cp(m, m->top.c2.link_sockets[0]);
+ if (mi)
+ {
+ multi_io_action(m, mi, T= A_INITIAL, false);
+ = }
}
- }
- /* new incoming TCP client attempting= to connect? */
- = else if (e->arg =3D=3D MULTI_IO_SOCKET)
- {
- struct multi_instance *mi;
- ASSERT(m->top.c2= .link_sockets[0]);

- = socket_reset_listen_persistent(m->top.c2.link_sockets[0]);<= /span>
- mi =3D= multi_create_instance_tcp(m, m->top.c2.link_sockets[0]);
- if (mi)

- {

- multi_io_action(m,= mi, TA_INITIAL, false);
- = }
#if defined(ENABLE_DCO) \
- && (defined(TARGET_LI= NUX) || defined(TARGET_FREEBSD) || defined(TARGET_WIN32))
- /* incoming data on DCO? */=
- else if (= e->arg =3D=3D MULTI_IO_DCO)
- {
= - multi_process_incoming_dco(m);
- }
+ && (defined(TARGET_LINUX) || defined(TARGET= _FREEBSD) || defined(TARGET_WIN32))
+ /* incoming data on DCO? */
+ else if (e->arg = =3D=3D MULTI_IO_DCO)

= + {
+ = multi_process_incoming_dco(m);
+ }
#endif
- /* signal rec= eived? */
- = else if (e->arg =3D=3D MULTI_IO_SIG)
- {
- get_signal(&m->top.sig->signal_received= );
- }
+ /* signal= received? */
+ = else if (e->arg =3D=3D MULTI_IO_SIG)
+ {
+ get_signal(&m->top.s= ig->signal_received);
+ }
#ifdef ENABLE_ASYNC_PUSH
= - else if (e->arg = =3D=3D MULTI_IO_FILE_CLOSE_WRITE)
- {
- multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECOR= D_TOUCH);
- = }
+ el= se if (e->arg =3D=3D MULTI_IO_FILE_CLOSE_WRITE)
+ {
+ multi_process_file_closed(= m, MPP_PRE_SELECT | MPP_RECORD_TOUCH);
+ }
#endif
}

if (IS_SIG(&m->top))@@ -572,9 +565,7 @@

do=
{
- = dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_action a=3D%s p=3D%d",=
- pract(ac= tion),
- po= ll);
+ dmsg(D_= MULTI_DEBUG, "MULTI IO: multi_io_action a=3D%s p=3D%d", pract(act= ion), poll);

/*
= * If TA_SOCKET_READ_RESIDUAL, it means we still have pending
@@ -593,7 +584,8 @@
action =3D mul= ti_io_wait_lite(m, mi, action, &tun_input_pending);
= if (action =3D=3D TA_UNDEF)
{=
- msg(M_FATAL,= "MULTI IO: I/O wait required blocking in multi_io_action, action=3D%d= ", orig_action);
+ msg(M_FATAL, "MULTI IO: I/O wait required blocking i= n multi_io_action, action=3D%d",
+ orig_action);
= }
}

diff -= -git a/src/openvpn/networking.h b/src/openvpn/networking.h
= index 0ba4963..93fa765 100644
--- a/src/openvpn/networking.= h
+++ b/src/openvpn/networking.h
@@ -102,8 = +102,8 @@
*
* @return 0 on suc= cess, negative error code on error
*/
-int net_iface_new(openvpn_net_ctx_t *ctx,= const openvpn_net_iface_t *iface,
- const char *type, void *arg);
+int net_iface_new(openvpn_net_ctx_= t *ctx, const openvpn_net_iface_t *iface, const char *type,

+ void *arg);

/**
* Retrieve the interfac= e type
@@ -114,8 +114,7 @@
*
* @return 0 on success, a negative error code otherwise
*/
-int n= et_iface_type(openvpn_net_ctx_t *ctx, const char *iface,
- char type[IFACE_TYPE_= LEN_MAX]);
+int net_i= face_type(openvpn_net_ctx_t *ctx, const char *iface, char type[IFACE_TYPE_L= EN_MAX]);

/**
* Remove= an interface
@@ -135,8 +134,7 @@
*
* @return 0 on success, a negative error code otherwi= se
*/
-int net_iface_up(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface= ,
- boo= l up);
+int net_iface= _up(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, bool up);

/**
* Set the MTU for an = interface
@@ -147,8 +145,7 @@
* * @return 0 on success, a negative error code otherwise
*/
-in= t net_iface_mtu_set(openvpn_net_ctx_t *ctx,
- const openvpn_net_iface_t *ifac= e, uint32_t mtu);
+in= t net_iface_mtu_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *ifac= e, uint32_t mtu);

/**
= * Set the Link Layer (Ethernet) address of the TAP interface
@@ -159,8 +156,7 @@

*
* @return = 0 on success, a negative error code otherwise
*/
-int net_addr_ll_set(openvp= n_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
- uint8_t *addr);<= br>+int net_addr_ll_set(openvpn= _net_ctx_t *ctx, const openvpn_net_iface_t *iface, uint8_t *addr);
/**
* Add an IPv4 address to a= n interface
@@ -172,8 +168,8 @@
*<= br> * @return 0 on success, a negative error code otherwise=
*/
-= int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *ifac= e,
- = const in_addr_t *addr, int prefixlen);
+int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openv= pn_net_iface_t *iface, const in_addr_t *addr,
+ int prefixlen);

/**
* Add an IPv6 address to an int= erface
@@ -198,8 +194,8 @@
*
* @return 0 on success, a negative error code otherwise
*/
-int n= et_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,

- cons= t in_addr_t *addr, int prefixlen);
+int net_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_ne= t_iface_t *iface, const in_addr_t *addr,
+ int prefixlen);
<= /span>
/**
* Remove an IPv6 from an interface
@@ -223,8 +219,7 @@
*
* = @return 0 on success, a negative error code otherwise
*/

-int net_addr_= ptp_v4_add(openvpn_net_ctx_t *ctx,
- const openvpn_net_iface_t *iface,
+int net_addr_ptp_v4_add(= openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
= const in_addr_t *local, const in_addr_t *remote);

/**
@@ -237,8 +232,7 @@
*
* @return 0 on success, a neg= ative error code otherwise
*/
-int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx,
- = const openvpn_net_iface_t *iface,
+int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const openvp= n_net_iface_t *iface,
const in_add= r_t *local, const in_addr_t *remote);

#e= ndif /* ENABLE_SITNL || ENABLE_IPROUTE */
@@ -258,9 +252,8 = @@
*
* @return 0 on success, a= negative error code otherwise
*/
-int net_route_v4_add(openvpn_net_ctx_t *ctx= , const in_addr_t *dst,
- int prefixlen, const in_addr_t *gw,
- const openvpn_net= _iface_t *iface, uint32_t table,
+int net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *= dst, int prefixlen,
+= const in_addr_t *gw, const openvpn_net_iface_t *iface,= uint32_t table,
int metric);<= br>
/**
@@ -277,10 +270,9 @@=
*
* @return 0 on success, a negative= error code otherwise
*/
-int net_route_v6_add(openvpn_net_ctx_t *ctx, const str= uct in6_addr *dst,
- = int prefixlen, const struct in6_addr *gw,
- const openvpn_ne= t_iface_t *iface,

- = uint32_t table, int metric);
+int net_route_v6_add(openvpn_net_ctx_t *ctx, cons= t struct in6_addr *dst, int prefixlen,
+ const struct in6_addr *gw, const op= envpn_net_iface_t *iface, uint32_t table,
+ int metric);

/**
* Delete a route for an IPv4 address/= network
@@ -296,9 +288,8 @@
*
<= span> * @return 0 on success, a negative error code otherwise
*/
-int = net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
- int prefixlen= , const in_addr_t *gw,

= - const openvpn_net_iface_t *iface, uint32_t table,
+int net_route_v4_del(op= envpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen,
+ const in_addr_t= *gw, const openvpn_net_iface_t *iface, uint32_t table,
= int metric);

/**
@@ -315,10 +306,9 @@
*
* @r= eturn 0 on success, a negative error code otherwise
*/

-int net_route_v= 6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
- int prefixlen, con= st struct in6_addr *gw,
- const openvpn_net_iface_t *iface,
- uint32_t table, int= metric);
+int net_ro= ute_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixle= n,
+ = const struct in6_addr *gw, const openvpn_net_iface_t *iface, uint32_t t= able,
+ = int metric);

#endif /* ENABLE_SIT= NL || ENABLE_IPROUTE || TARGET_FREEBSD */

@@ -335,8 +325,8 @@

*
* @return = 0 on success, a negative error code otherwise
*/
-int net_route_v4_best_g= w(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
- in_addr_t *best_gw, open= vpn_net_iface_t *best_iface);
+int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t = *dst, in_addr_t *best_gw,
+ openvpn_net_iface_t *best_iface);
=
/**
* Retrieve the gateway and o= utgoing interface for the specified IPv6
@@ -350,8 +340,7 @= @
* @return 0 on success, a negative error c= ode otherwise
*/
int net_route_v6_best_g= w(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
- struct in6_addr *b= est_gw,
- = openvpn_net_iface_t *best_iface);
+ struct in6_addr *best_gw,= openvpn_net_iface_t *best_iface);

#endi= f /* ENABLE_SITNL || ENABLE_IPROUTE */

di= ff --git a/src/openvpn/networking_freebsd.c b/src/openvpn/networking_freebs= d.c
index 1c94756..b47444c 100644
--- a/src= /openvpn/networking_freebsd.c
+++ b/src/openvpn/networking_= freebsd.c
@@ -9,9 +9,8 @@
#if defined(TARG= ET_FREEBSD)

static int
-net_route_v4(const char *op, const in_a= ddr_t *dst, int prefixlen,
- const in_addr_t *gw, const char *iface, uint32_t table,
- int metric= )
+net_route_v4(const= char *op, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,=
+ const char *i= face, uint32_t table, int metric)
{
c= har buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
in_a= ddr_t _dst, _gw;
@@ -21,16 +20,12 @@
_= dst =3D ntohl(*dst);
_gw =3D ntohl(*gw);

- argv_printf(&= amp;argv, "%s %s -net %s/%d %s -fib %d",
- ROUTE_PATH, op,
- inet_ntop(AF_INET, &= amp;_dst, buf1, sizeof(buf1)),

- prefixlen,
- inet_ntop(AF_INET, &_gw, buf2, sizeof(buf= 2)),
- t= able);
+ argv_prin= tf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+ inet_nto= p(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+ inet_ntop(AF_INET, &_= gw, buf2, sizeof(buf2)), table);

arg= v_msg(M_INFO, &argv);
- status =3D openvpn_execve_check(&argv, NULL, 0,
- &qu= ot;ERROR: FreeBSD route command failed");

+ status =3D openvpn_execve_check(&argv, N= ULL, 0, "ERROR: FreeBSD route command failed");
=
argv_free(&argv);

@@ -38,24 +33,19 @@

}

static int

-net_route= _v6(const char *op, const struct in6_addr *dst,
- int prefixlen, const struct in6_addr= *gw, const char *iface,
+net_route_v6(const char *op, const struct in6_addr = *dst, int prefixlen, const struct in6_addr *gw,
+ const char *iface, uint32_t table,= int metric)
{
char buf1[INET6_ADDRST= RLEN], buf2[INET6_ADDRSTRLEN];
struct argv argv =3D ar= gv_new();
bool status;

- argv_printf(&argv, "%s= -6 %s -net %s/%d %s -fib %d",

- ROUTE_PATH, op,
- inet_ntop(AF_INET6, dst, buf1, size= of(buf1)),
- = prefixlen,
- = inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)),
- table);
+ argv_printf(&argv, "%s -6= %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+ inet_ntop(AF_INET6, dst, buf1,= sizeof(buf1)), prefixlen,
+ inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);=

argv_msg(M_INFO, &argv);=
- status =3D openvpn_execv= e_check(&argv, NULL, 0,
- "ERROR: FreeBSD route command = failed");
+ s= tatus =3D openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD rou= te command failed");

argv_free(= &argv);

@@ -63,33 +53,29 @@ }

int
-net_route_v4_add(openvpn_net_ctx_t *ctx, const i= n_addr_t *dst, int prefixlen,
- const in_addr_t *gw, const char *iface, uint32_t t= able,
- = int metric)
+net_rou= te_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, cons= t in_addr_t *gw,
+ = const char *iface, uint32_t table, int metric)
{

return net_route_v4("add", dst, prefixl= en, gw, iface, table, metric);
}
<= br> int
-net_rout= e_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
- int prefixlen, cons= t struct in6_addr *gw, const char *iface,

- uint32_t table, int metric)
= +net_route_v6_add(openvpn_net_c= tx_t *ctx, const struct in6_addr *dst, int prefixlen,
+ const struct in6_addr *g= w, const char *iface, uint32_t table, int metric)
{=
return net_route_v6("add", dst, prefixlen, gw, ifa= ce, table, metric);
}

i= nt
-net_route_v4_del(op= envpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen,
- const in_addr_t *gw, = const char *iface, uint32_t table,
- int metric)
+net_route_v4_del(openvpn_net_ctx_t *ctx, const in_add= r_t *dst, int prefixlen, const in_addr_t *gw,
+ const char *iface, uint32_t tabl= e, int metric)
{
return net_route_v4(= "del", dst, prefixlen, gw, iface, table, metric);
}


int
-net_route_v6_del(openvpn_net_ctx_t *ctx, const struct = in6_addr *dst,
- = int prefixlen, const struct in6_addr *gw, const char *iface,
- uint32_t = table, int metric)
+n= et_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int pre= fixlen,
+ = const struct in6_addr *gw, const char *iface, uint32_t table, int metr= ic)
{
return net_route_v6("del&q= uot;, dst, prefixlen, gw, iface, table, metric);
}<= br>diff --git a/src/openvpn/networking_iproute2.c b/src/openvpn/netwo= rking_iproute2.c
index 28b5bfc..aac245a 100644
--- a/src/openvpn/networking_iproute2.c

+++ b/src/openv= pn/networking_iproute2.c
@@ -62,8 +62,7 @@
= }

int
-net_iface_new(openvpn_net_ctx_t *ctx, const char *iface= , const char *type,
- = void *arg)
-net_iface_type(openvpn_net_ctx_t *ctx, const char = *iface,
- = char type[IFACE_TYPE_LEN_MAX])
+net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, char = type[IFACE_TYPE_LEN_MAX])
{
/* not su= pported by iproute2 */
msg(M_WARN, "%s: operation= not supported by iproute2 backend", __func__);
@@ -10= 3,8 +101,7 @@
{
struct argv argv =3D = argv_new();

- argv_printf(&argv, "%s link set dev %s %s", iprou= te_path, iface,
- = up ? "up" : "down");
+ argv_printf(&argv, "%s link set= dev %s %s", iproute_path, iface, up ? "up" : "down&quo= t;);
argv_msg(M_INFO, &argv);
= openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip link s= et failed");

@@ -118,8 +115,7 @@
{
struct argv argv =3D argv_new();

- argv_= printf(&argv, "%s link set dev %s up mtu %d", iproute_path, i= face,
- = mtu);
+ argv_print= f(&argv, "%s link set dev %s up mtu %d", iproute_path, iface,= mtu);
argv_msg(M_INFO, &argv);
= openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip link= set failed");

@@ -129,19 +125,16 @@=
}

int
-net_addr_ll_set(openvpn_net_ctx_t *ctx= , const openvpn_net_iface_t *iface,
- uint8_t *addr)
+net_addr_ll_set(openvpn_net_ctx_t *ctx, const open= vpn_net_iface_t *iface, uint8_t *addr)
{
= struct argv argv =3D argv_new();
int ret =3D 0;


- ar= gv_printf(&argv,
- = "%s link set addr " MAC_FMT " dev %s",
- iproute= _path, MAC_PRINT_ARG(addr), iface);
+ argv_printf(&argv, "%s link set addr " MA= C_FMT " dev %s", iproute_path, MAC_PRINT_ARG(addr),
+ iface);

argv_msg(M_INFO, &argv);
- if (!openvpn_execve_check(&arg= v, ctx->es, 0,
- = "Linux ip link set addr failed"))
+ if (!openvpn_execve_c= heck(&argv, ctx->es, 0, "Linux ip link set addr failed"))<= /span>
{
ret =3D -1;
}

@@ -152,15 +145,13 @@
}
=
int
-net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface,- const in_addr_t= *addr, int prefixlen)
- argv_printf(&ar= gv, "%s addr add dev %s %s/%d", iproute_path, iface,
- addr_str, prefixle= n);

+ argv_printf(= &argv, "%s addr add dev %s %s/%d", iproute_path, iface, addr_= str, prefixlen);
argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, S_FATAL, "Lin= ux ip addr add failed");

@@ -170,17 = +161,15 @@
}

int=
-net_addr_v6_add(openvpn_net_= ctx_t *ctx, const char *iface,
- const struct in6_addr *addr, int prefixlen)=
+net_addr_v6_add(openvpn_ne= t_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
+ int prefixlen)
{
struct argv argv =3D argv_new();
char *addr_str =3D (char *)print_in6_addr(*addr, 0, &c= tx->gc);

- argv_printf(&argv, "%s -6 addr add %s/%d dev %s",= iproute_path, addr_str,
+ argv_printf(&argv, "%s -6 addr add %s/%d dev= %s", iproute_path, addr_str, prefixlen, iface);
= argv_msg(M_INFO, &argv);
- openvpn_execve_check(&argv, ctx->es, S_FATAL,
<= span style=3D"color: hsl(0, 100%, 40%);">- "Li= nux ip -6 addr add failed");

+ openvpn_execve_check(&argv, ctx->es, S_FATAL, &quo= t;Linux ip -6 addr add failed");

= argv_free(&argv);

@@ -188,14 +177,1= 2 @@
}

int
-net_addr_v4_del(openvpn_net_ctx_t = *ctx, const char *iface,

+net_addr_v4_del(openvpn_net_ctx_t *ctx= , const char *iface, const in_addr_t *addr, int prefixlen)
= {
struct argv argv =3D argv_new();
= const char *addr_str =3D print_in_addr_t(*addr, 0, &ctx->gc);

- arg= v_printf(&argv, "%s addr del dev %s %s/%d", iproute_path, ifa= ce,
- ad= dr_str, prefixlen);
+= argv_printf(&argv, "%s addr del dev %s %s/%d", iproute_pa= th, iface, addr_str, prefixlen);

arg= v_msg(M_INFO, &argv);
openvpn_execve_check(&ar= gv, ctx->es, 0, "Linux ip addr del failed");
@= @ -206,14 +193,13 @@
}

= int
-net_addr_v6_del(op= envpn_net_ctx_t *ctx, const char *iface,
- const struct in6_addr *addr, int prefixl= en)
+net_addr_v6_del(= openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
+ int pre= fixlen)
{
struct argv argv =3D argv_n= ew();
char *addr_str =3D (char *)print_in6_addr(*addr,= 0, &ctx->gc);

- argv_printf(&argv, "%s -6 addr del %s/%d dev= %s", iproute_path,
+ argv_printf(&argv, "%s -6 addr del= %s/%d dev %s", iproute_path, addr_str, prefixlen, iface);
<= span> argv_msg(M_INFO, &argv);

openvpn_execve_= check(&argv, ctx->es, 0, "Linux ip -6 addr del failed");

@@ -223,15 +209,15 @@
}

int
-net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char *ifa= ce,
- = const in_addr_t *local, const in_addr_t *remote)
+net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, = const char *iface, const in_addr_t *local,
+ const in_addr_t *remote)<= br> {
struct argv argv =3D argv_new(); const char *local_str =3D print_in_addr_t(*local, 0, &ctx-&= gt;gc);
const char *remote_str =3D print_in_addr_t(*re= mote, 0, &ctx->gc);

- argv_printf(&argv, "%s addr add dev %s = local %s peer %s", iproute_path,
- iface, local_str, remote_str);
+ argv_printf(&argv, "= ;%s addr add dev %s local %s peer %s", iproute_path, iface, local_str,=

+ rem= ote_str);
argv_msg(M_INFO, &argv);
openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip a= ddr add failed");


@@ -241,15 +227,15= @@
}

int
-net_addr_ptp_v4_del(openvpn_net_ctx= _t *ctx, const char *iface,

- const in_addr_t *local, const in_addr_t *remote)<= /span>
+net_addr_ptp_v4_del(= openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,+ const in= _addr_t *remote)
{
struct argv argv = =3D argv_new();
const char *local_str =3D print_in_add= r_t(*local, 0, &ctx->gc);
const char *remote_st= r =3D print_in_addr_t(*remote, 0, &ctx->gc);

- argv_printf(&argv, = "%s addr del dev %s local %s peer %s", iproute_path,
- iface, local_str, = remote_str);

+ arg= v_printf(&argv, "%s addr del dev %s local %s peer %s", iprout= e_path, iface, local_str,
+ remote_str);
argv_msg(M_INFO, &a= mp;argv);
openvpn_execve_check(&argv, ctx->es, = 0, "Linux ip addr del failed");

@@ -259,9 +245,8 @@

}

= int
-net_route_v4_add(o= penvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen,
- const in_addr_t *gw,= const char *iface, uint32_t table,

- int metric)
+net_route_v4_add(openvpn_net_ctx_t *ctx, const in_ad= dr_t *dst, int prefixlen, const in_addr_t *gw,
+ const char *iface, uint32_t tab= le, int metric)
{
struct argv argv = =3D argv_new();
const char *dst_str =3D print_in_addr_= t(*dst, 0, &ctx->gc);
@@ -298,16 +283,14 @@ }

int
-net_route_v6_add(openvpn_net_ctx_t *ctx, const = struct in6_addr *dst,
-= int prefixlen, const struct in6_addr *gw, const char *ifac= e,
- ui= nt32_t table, int metric)
+net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, = int prefixlen,
+ = const struct in6_addr *gw, const char *iface, uint32_t table, i= nt metric)
{
struct argv argv =3D arg= v_new();
char *dst_str =3D (char *)print_in6_addr(*dst= , 0, &ctx->gc);
int ret =3D 0;
=
- argv_printf(&= ;argv, "%s -6 route add %s/%d dev %s", iproute_path, dst_str,
- prefixlen= , iface);
+ argv_p= rintf(&argv, "%s -6 route add %s/%d dev %s", iproute_path, ds= t_str, prefixlen, iface);

if (gw)
{
@@ -333,9 +316,8 @@
}=

int
-net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t = *dst, int prefixlen,
- = const in_addr_t *gw, const char *iface, uint32_t table,
- int metr= ic)
+net_route_v4_del= (openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr= _t *gw,
+ = const char *iface, uint32_t table, int metric)
{
struct argv argv =3D argv_new();
cons= t char *dst_str =3D print_in_addr_t(*dst, 0, &ctx->gc);
@@ -360,16 +342,14 @@

}

int

-net_route_v6_= del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,
- int prefixlen, const str= uct in6_addr *gw, const char *iface,
- uint32_t table, int metric)
+net_route_v6_del(openvpn_net_ctx_t = *ctx, const struct in6_addr *dst, int prefixlen,

+ const struct in6_addr *gw, co= nst char *iface, uint32_t table, int metric)
{
<= span> struct argv argv =3D argv_new();

char *dst_s= tr =3D (char *)print_in6_addr(*dst, 0, &ctx->gc);
= int ret =3D 0;

- argv_printf(&argv, "%s -6 route del %s/%d dev %s= ", iproute_path, dst_str,
- prefixlen, iface);
+ argv_printf(&argv, "%s -6 route del %s= /%d dev %s", iproute_path, dst_str, prefixlen, iface);

if (gw)
{
diff= --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c
index 79aba8d..5b78971 100644
--- a/src/openv= pn/networking_sitnl.c
+++ b/src/openvpn/networking_sitnl.c<= /span>
@@ -44,12 +44,12 @@
#define SNDBUF_SIZE (1= 024 * 2)
#define RCVBUF_SIZE (1024 * 4)
<= /span>
-#define SITNL_ADDATTR(= _msg, _max_size, _attr, _data, _size) \
- { = \
= +#define SITNL_ADDATTR(_msg, _max_size, _attr, _data, _size) \
+ { = \
if= (sitnl_addattr(_msg, _max_size, _attr, _data, _size) < 0) \
<= span style=3D"color: hsl(0, 100%, 40%);">- { = \

- goto err; = \
- } = \
+ { = \
+ goto err; = \
+ } = \
}


#define SITNL_NEST(_msg, _max_s= ize, _attr) \
@@ -59,8 +59,8 @@
_nest; \

})


-#define SITNL_NEST_END(_msg, _nest) = \
- { = \
+#define SITNL_NEST_END(_msg, _nest) = \
+ { = \
_nest->rta_len =3D (void *)sit= nl_nlmsg_tail(_msg) - (void *)_nest; \
}

@@ -74,7 +74,7 @@
* The only way out= to avoid any warning/error is to force the function to
*= not be inline'd.
*/
-static __attribute__ ((noinline)) void *
+static __attribute__((noinline)) = void *

sitnl_nlmsg_tail(const struct nlmsghdr *nlh)=
{
return (unsigned char *)nlh + NLMSG_ALIGN= (nlh->nlmsg_len);
@@ -84,7 +84,8 @@
* = Generic address data structure used to pass addresses and prefixes as
* argument to AF family agnostic functions
*= /
-typedef union {
+typedef union
= +{
in_addr= _t ipv4;
struct in6_addr ipv6;
} inet= _address_t;
@@ -92,7 +93,8 @@
/** * Link state request message
*/
-struct sitnl_link_req {

+struct sitnl_link_req

<= span style=3D"color: hsl(120, 100%, 40%);">+{

struct n= lmsghdr n;
struct ifinfomsg i;
ch= ar buf[256];
@@ -101,7 +103,8 @@
/**
* Address request message
*/
-struct sitnl_addr_req {

+struct sitnl_addr_req

<= span style=3D"color: hsl(120, 100%, 40%);">+{

struct n= lmsghdr n;
struct ifaddrmsg i;
ch= ar buf[256];
@@ -110,7 +113,8 @@
/**
* Route request message
*/
-struct sitnl_route_req {
+struct sitnl_route_req

<= span style=3D"color: hsl(120, 100%, 40%);">+{

struct n= lmsghdr n;
struct rtmsg r;
char b= uf[256];
@@ -121,7 +125,8 @@
/** * Object returned by route request operation
*/<= /span>
-struct sitnl_route_dat= a_cb {
+struct sitnl_= route_data_cb
+{
unsigned int iface;
inet_address_t gw= ;
};
@@ -130,16 +135,14 @@
* Helper function used to easily add attributes to a rtnl message
=
*/
static int
-sitnl_addattr(struct nlmsghdr *n, int maxlen, int type= , const void *data,
- = int alen)
+sitnl_addattr(struct nlmsghdr *n, int maxlen, int type, const void *data,= int alen)
{
int len =3D RTA_LENGTH(a= len);
struct rtattr *rta;

= if ((int)(NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len)) > ma= xlen)
{
- msg(M_WARN, "%s: rtnl: message exceeded bound of %d&quo= t;, __func__,
- = maxlen);
+ = msg(M_WARN, "%s: rtnl: message exceeded bound of %d", __func__, = maxlen);
return -EMSGSIZE;
}<= /span>

@@ -241,8 +244,8 @@
* S= end Netlink message and run callback on reply (if specified)
*/

static int
-sitnl_send(struct nlmsghdr *payload, pid_t peer, unsigned int = groups,
- sit= nl_parse_reply_cb cb, void *arg_cb)
+sitnl_send(struct nlmsghdr *payload, pid_t peer, unsigned i= nt groups, sitnl_parse_reply_cb cb,
+ void *arg_cb)
{
int len, rem_len, fd, ret, rcv_len;

struct socka= ddr_nl nladdr;
@@ -250,13 +253,11 @@
s= truct nlmsghdr *h;
unsigned int seq;
= char buf[1024 * 16];
- {
+ stru= ct iovec iov =3D {
.iov_base =3D payload, .iov_len =3D payload->nlmsg_len,
}= ;
- struct msghdr nl= msg =3D
- {+ struct msghdr nlmsg =3D = {
.msg_name =3D &nladdr,
= .msg_namelen =3D sizeof(nladdr),
.msg_iov =3D = &iov,
@@ -335,8 +336,8 @@

<= span> if (nlmsg.msg_namelen !=3D sizeof(nladdr))

= {
- m= sg(M_WARN, "%s: sender address length: %u (expected %zu)",=
- __func__, nl= msg.msg_namelen, sizeof(nladdr));
+ msg(M_WARN, "%s: sender address length: %u (= expected %zu)", __func__, nlmsg.msg_namelen,
+ sizeof(nladdr));
ret =3D -EIO;

goto out;
}
@@ -360,17 +361,18 @@
goto out;

}
=
-/* if (((= int)nladdr.nl_pid !=3D peer) || (h->nlmsg_pid !=3D nladdr.nl_pid)=
- * || (h->n= lmsg_seq !=3D seq))
- *= {
- * = rcv_len -=3D NLMSG_ALIGN(len);
- * h =3D (struct nlmsghdr *)((char *)h + NLM= SG_ALIGN(len));
- * = msg(M_DEBUG, "%s: skipping unrelated message. nl_pid:%d (pe= er:%d) nl_msg_pid:%d nl_seq:%d seq:%d",
- * __func__, (int)nladdr.nl_pid, p= eer, h->nlmsg_pid,
-= * h->nlmsg_seq, seq);
- * continue;
- * }
- */
+ /* if (((int)nladdr.nl_pid !=3D peer) || (h->= nlmsg_pid !=3D nladdr.nl_pid)
+ * || (h->nlmsg_seq !=3D seq))
+ * = {
+ * = rcv_len -=3D NLMSG_ALIGN(len);
+ * h =3D (struct nlmsghdr *= )((char *)h + NLMSG_ALIGN(len));
+ * msg(M_DEBUG, "%s: skipping u= nrelated message. nl_pid:%d (peer:%d)
+ * nl_msg_pid:%d nl_seq:%d seq:%d",
+ * = __func__, (int)nladdr.nl_pid, peer, h->nlmsg_pid,
+ * = h->nlmsg_seq, seq);

+ * }
+ */

if (h->nlmsg_type =3D=3D NLMSG_DONE)

= {
@@ -402,8 +404,8 @@
= }
else
= {
- = msg(M_WARN, "%s: rtnl: generic error (%d): %s&quo= t;,
- = __func__, err->error, strerror(-err->error));
+ msg(M_WAR= N, "%s: rtnl: generic error (%d): %s", __func__, err->error,
+ = strerror(-err->error));
= ret =3D err->error;
}
}

@@ -447,7 +449,8 @@
= return ret;
}

-typedef struct {
+typedef struct
+{
int addr_size;
inet_address_t gw;

char iface[IFNAMSIZ];
@@ -509,8 +512,7 @@

if (!= if_indextoname(ifindex, res->iface))
{
- msg(M_WARN | M_ERRNO, &quo= t;%s: rtnl: can't get ifname for index %d",

- __func__, ifindex);
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(M_WARN | M_ERRNO, &= quot;%s: rtnl: can't get ifname for index %d", __func__, ifindex);=

return -1;
}

@@ -523,8 +525,8 @@
}
=
static int
-sitnl_route_best_gw(sa_family_t af_family, const inet_address_t *dst= ,
- = void *best_gw, char *best_iface)
+sitnl_route_best_gw(sa_family_t af_family, const inet_address_= t *dst, void *best_gw,
-
}=

/* used by iproute2 implementation too = */
int
-net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,<= /span>
- s= truct in6_addr *best_gw, char *best_iface)
+net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const s= truct in6_addr *dst, struct in6_addr *best_gw,
+ char *best_iface) {
- inet_add= ress_t dst_v6 =3D {0};
- msg(D_ROUTE, "%s query: dst %s", __func__,
- inet_ntop(AF_INET6= , &dst_v6.ipv6, buf, sizeof(buf)));
+ msg(D_ROUTE, "%s query: dst %s", __func__= , inet_ntop(AF_INET6, &dst_v6.ipv6, buf, sizeof(buf)));

ret =3D sitnl_route_best_gw(AF_INET6, &dst_v6, = best_gw, best_iface);
if (ret < 0)
= @@ -616,15 +616,14 @@
inet_ntop(AF_INET6, best_gw,= buf, sizeof(buf)), best_iface);

ret= urn ret;
-
}


/* used by iproute2 implementatio= n too */
int
-net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,<= /span>
- i= n_addr_t *best_gw, char *best_iface)
+net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr= _t *dst, in_addr_t *best_gw,
+ char *best_iface)
{- inet_address_t dst_v4 =3D = {0};
+ inet_addres= s_t dst_v4 =3D { 0 };
char buf[INET_ADDRSTRLEN];
int ret;

@@ -633,8 +632,7= @@
dst_v4.ipv4 =3D htonl(*dst);
= }

- msg(D_ROUTE, "%s query: dst %s", __func__,
- inet_ntop(AF_INET, &dst_v4= .ipv4, buf, sizeof(buf)));
+ msg(D_ROUTE, "%s query: dst %s", __func__, inet_ntop(A= F_INET, &dst_v4.ipv4, buf, sizeof(buf)));

<= span> ret =3D sitnl_route_best_gw(AF_INET, &dst_v4, best_gw, best_i= face);

if (ret < 0)
@@ -670,8 +668,= 7 @@
ifindex =3D if_nametoindex(iface);
if (ifindex =3D=3D 0)

{
- msg(M_WARN, "%s: rtnl: cannot = get ifindex for %s: %s", __func__, iface,
- strerror(errno));
+ msg(M_WARN, "%s: rtnl: cann= ot get ifindex for %s: %s", __func__, iface, strerror(errno));<= br> return -ENOENT;
}
<= /span>
@@ -697,8 +694,7 @@
}

int
-net= _iface_mtu_set(openvpn_net_ctx_t *ctx, const char *iface,
- uint32_t mtu)<= br>+net_iface_mtu_set(openvpn_n= et_ctx_t *ctx, const char *iface, uint32_t mtu)
{ struct sitnl_link_req req;
int ifindex, r= et =3D -1;
@@ -708,8 +704,7 @@
ifindex= =3D if_nametoindex(iface);
if (ifindex =3D=3D 0)
{
- = msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s",= __func__,
- = iface);
+ msg= (M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __func_= _, iface);
return -1;
}

@@ -730,8 +725,7 @@
}<= br>
int
-net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t= *iface,
- = uint8_t *addr)
+ne= t_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, uin= t8_t *addr)
{
struct sitnl_link_req r= eq;
int ifindex, ret =3D -1;
@@ -741,8= +735,7 @@
ifindex =3D if_nametoindex(iface); if (ifindex =3D=3D 0)
{
- msg(M_WARN | M_ERRNO, "%s:= rtnl: cannot get ifindex for %s", __func__,
- iface);
+ msg(M_WARN | M_ERRNO, "%s: rtnl: c= annot get ifindex for %s", __func__, iface);
= return -1;
}

@@ -755= ,8 +748,7 @@

SITNL_ADDATTR(&req.= n, sizeof(req), IFLA_ADDRESS, addr, OPENVPN_ETH_ALEN);

- msg(M_INFO, "%s= : lladdr " MAC_FMT " for %s", __func__, MAC_PRINT_ARG(addr),=
- iface);
+ msg(M_INFO, "%s:= lladdr " MAC_FMT " for %s", __func__, MAC_PRINT_ARG(addr), = iface);

ret =3D sitnl_send(&req.= n, 0, 0, NULL, NULL);
err:
@@ -765,8 +757,= 7 @@

static int
sitnl_a= ddr_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family,=
- const inet_ad= dress_t *local, const inet_address_t *remote,
- int prefixlen)
+ const inet_address_t *loca= l, const inet_address_t *remote, int prefixlen)
{ struct sitnl_addr_req req;
uint32_t size;=
@@ -792,8 +783,7 @@
break;

default:
- msg(M_WARN, "%s: rtnl: unknown= address family %d", __func__,
- af_family);
+ msg(M_WARN, "%s: rtnl: unknown addre= ss family %d", __func__, af_family);
retu= rn -EINVAL;
}

@@ -82= 4,8 +814,7 @@
}

static = int
-sitnl_addr_ptp_add= (sa_family_t af_family, const char *iface,
- const inet_address_t *local,=
+sitnl_addr_ptp_add(sa_fami= ly_t af_family, const char *iface, const inet_address_t *local,
<= span> const inet_address_t *remote)

{
int ifindex;
@@ -849,18 +838,16 @@
ifindex =3D if_nametoindex(iface);
if= (ifindex =3D=3D 0)
{
- msg(M_WARN, "%s: cannot get ifindex for %= s: %s", __func__, np(iface),
- strerror(errno));
+ msg(M_WARN, "%s: cannot get ifindex for = %s: %s", __func__, np(iface), strerror(errno));
= return -ENOENT;
}

- return sitnl_addr_set(RTM_NEWADDR= , NLM_F_CREATE | NLM_F_REPLACE, ifindex,

- af_family, local, remote, 0);<= /span>
+ return sitnl_add= r_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifindex, af_family, local,=
+ = remote, 0);
}

st= atic int
-sitnl_addr_pt= p_del(sa_family_t af_family, const char *iface,
- const inet_address_t *local)
+sitnl_addr_ptp_del(sa= _family_t af_family, const char *iface, const inet_address_t *local)=
{
int ifindex;

= @@ -891,9 +878,8 @@
}

static int

-sitnl_= route_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family,
- const void= *dst, int prefixlen,
-= const void *gw, enum rt_class_t table, int metric,+sitnl_route_set(int cmd, uin= t32_t flags, int ifindex, sa_family_t af_family, const void *dst,+ int prefixlen= , const void *gw, enum rt_class_t table, int metric,
= enum rt_scope_t scope, int protocol, int type)
= {
struct sitnl_route_req req;
@@ -961,= 8 +947,7 @@
}

static in= t
-sitnl_addr_add(sa_fa= mily_t af_family, const char *iface,
- const inet_address_t *addr, int prefixlen)
+sitnl_addr_add(sa_fami= ly_t af_family, const char *iface, const inet_address_t *addr, int prefixle= n)
{
int ifindex;

@@ -985,52 +970,47 @@
ifindex =3D if_na= metoindex(iface);
if (ifindex =3D=3D 0)
{

- msg(M= _WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __func__,=
- iface);
+ msg(M_WARN | = M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __func__, iface);=
return -ENOENT;
}
=
- return sit= nl_addr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifindex,
<= span style=3D"color: hsl(0, 100%, 40%);">- af_fami= ly, addr, NULL, prefixlen);

-}
-
-static int

-sitnl_addr_del(sa_family_t af_family, const ch= ar *iface, inet_address_t *addr,
- int prefixlen)
-{
- = int ifindex;
-
- switch (af_family)
- {
- case AF_INET:
- case AF_INET6:
- break;
-
- default:
- return -EINVAL;
- }
-
- if (!iface)- {
- msg(M_WARN, "%s: passed NULL inter= face", __func__);
= - return -EINVAL;
-
- ifindex =3D if_nametoindex(ifa= ce);

- if (ifindex = =3D=3D 0)
- {=
- msg(M_WARN | M_ERRNO= , "%s: rtnl: cannot get ifindex for %s", __func__,
- iface);

- return -ENOENT;
- }

-
- return sitnl_addr_set(RTM_DELADDR, 0, ifindex, af_family, addr, NULL,=
+ return sitnl_ad= dr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifindex, af_family, addr,= NULL,
prefixlen);
}


+static int
+sitnl= _addr_del(sa_family_t af_family, const char *iface, inet_address_t *addr, i= nt prefixlen)
+{
+ int ifindex;<= br>+
+ switch (af_family)
+ {
+ case AF_INET:
+ case AF_INET6:
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ if (!iface)<= br>+ {
+ msg(M_WARN, "%s: passed NULL= interface", __func__);
+ return -EINVAL;
+ }
+<= /span>
+ ifindex =3D if_n= ametoindex(iface);
+ = if (ifindex =3D=3D 0)
+ {
+ m= sg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __fun= c__, iface);
+ = return -ENOENT;
+ = }
+
+ return sitnl_addr_set(RTM_DELADD= R, 0, ifindex, af_family, addr, NULL, prefixlen);
+}
+
int
-net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface,
- const in_a= ddr_t *addr, int prefixlen)
+net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in= _addr_t *addr, int prefixlen)
{
inet_= address_t addr_v4 =3D { 0 };
char buf[INET_ADDRSTRLEN]= ;
@@ -1042,15 +1022,15 @@

addr_v4.ipv4 =3D htonl(*addr);


- msg(M_INFO, "%s: %s/%d dev %s&quo= t;, __func__,
- = inet_ntop(AF_INET, &addr_v4.ipv4, buf, sizeof(buf)), prefixlen, iface);=
+ msg(M_INFO, &qu= ot;%s: %s/%d dev %s", __func__, inet_ntop(AF_INET, &addr_v4.ipv4, = buf, sizeof(buf)),
+ = prefixlen, iface);

return sit= nl_addr_add(AF_INET, iface, &addr_v4, prefixlen);
}

int
-net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface,
- const s= truct in6_addr *addr, int prefixlen)
+net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface,= const struct in6_addr *addr,
+ int prefixlen)
{
inet_address_t addr_v6 =3D { 0 };

char buf[INET6= _ADDRSTRLEN];
@@ -1062,15 +1042,14 @@

addr_v6.ipv6 =3D *addr;

- msg(M_INFO, "%s: %s/%d dev %= s", __func__,

- = inet_ntop(AF_INET6, &addr_v6.ipv6, buf, sizeof(buf)), prefixlen, i= face);
+ msg(M_INF= O, "%s: %s/%d dev %s", __func__, inet_ntop(AF_INET6, &addr_v6= .ipv6, buf, sizeof(buf)),
+ prefixlen, iface);

ret= urn sitnl_addr_add(AF_INET6, iface, &addr_v6, prefixlen);
}


int
-net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *= iface,
- = const in_addr_t *addr, int prefixlen)
+net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *ifac= e, const in_addr_t *addr, int prefixlen)
{
inet_address_t addr_v4 =3D { 0 };

char buf[INET_= ADDRSTRLEN];
@@ -1082,15 +1061,15 @@

addr_v4.ipv4 =3D htonl(*addr);
- msg(M_INFO, "%s: %s de= v %s", __func__,
-= inet_ntop(AF_INET, &addr_v4.ipv4, buf, sizeof(buf)), iface);
+ msg(M_INFO, "= %s: %s dev %s", __func__, inet_ntop(AF_INET, &addr_v4.ipv4, buf, s= izeof(buf)),
+ = iface);

return sitnl_addr_del(AF_IN= ET, iface, &addr_v4, prefixlen);
}

int
-ne= t_addr_v6_del(openvpn_net_ctx_t *ctx, const char *iface,
- const struct in6_addr *a= ddr, int prefixlen)
+= net_addr_v6_del(openvpn_net_ctx_t *ctx, const char *iface, const struct in6= _addr *addr,
+ = int prefixlen)
{
inet_addres= s_t addr_v6 =3D { 0 };
char buf[INET6_ADDRSTRLEN];
@@ -1102,15 +1081,15 @@

= addr_v6.ipv6 =3D *addr;

- msg(M_INFO, "%s: %s/%d dev %s", __func__= ,
- inet_ntop(AF= _INET6, &addr_v6.ipv6, buf, sizeof(buf)), prefixlen, iface);
= + msg(M_INFO, "%s: %s/%= d dev %s", __func__, inet_ntop(AF_INET6, &addr_v6.ipv6, buf, sizeo= f(buf)),
+ pre= fixlen, iface);

return sitnl_addr_de= l(AF_INET6, iface, &addr_v6, prefixlen);
}
<= span>

int
-net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char *iface,=
- const in= _addr_t *local, const in_addr_t *remote)
+net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char= *iface, const in_addr_t *local,
+ const in_addr_t *remote)
= {
inet_address_t local_v4 =3D { 0 };
= inet_address_t remote_v4 =3D { 0 };
@@ -1137,8 +1116,8 = @@
}

int
-net_addr_ptp_v4_del(openvpn_net_ctx_= t *ctx, const char *iface,

- const in_addr_t *local, const in_addr_t *remote)
+net_addr_ptp_v4_del(o= penvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,+ const in_= addr_t *remote)
{
inet_address_t loca= l_v4 =3D { 0 };
char buf[INET6_ADDRSTRLEN];
= @@ -1151,15 +1130,15 @@

local_= v4.ipv4 =3D htonl(*local);

- msg(M_INFO, "%s: %s dev %s", __func__,=
- inet_ntop(AF_= INET, &local_v4.ipv4, buf, sizeof(buf)), iface);
+ msg(M_INFO, "%s: %s dev %s"= , __func__, inet_ntop(AF_INET, &local_v4.ipv4, buf, sizeof(buf)),
+ iface);
return sitnl_addr_ptp_del(AF_INET, iface, &am= p;local_v4);
}

static i= nt
-sitnl_route_add(con= st char *iface, sa_family_t af_family, const void *dst,
- int prefixlen, const void= *gw, uint32_t table, int metric)
+sitnl_route_add(const char *iface, sa_family_t af_family, con= st void *dst, int prefixlen,
+ const void *gw, uint32_t table, int metric)=
{
enum rt_scope_t scope =3D RT_SCOPE_UNIVER= SE;
int ifindex =3D 0;
@@ -1169,8 +114= 8,7 @@
ifindex =3D if_nametoindex(iface); if (ifindex =3D=3D 0)
{- msg(M_WARN | M_ERRN= O, "%s: rtnl: can't get ifindex for %s",
- __func__, iface);+ msg(M_WARN | M_E= RRNO, "%s: rtnl: can't get ifindex for %s", __func__, iface);=
return -ENOENT;
}
}
@@ -1185,15 +1163,13 @@
scope =3D RT_SCOPE_LINK;

}
=
- return sitnl_rou= te_set(RTM_NEWROUTE, NLM_F_CREATE, ifindex,
- af_family, dst, prefixlen,= gw, table, metric, scope,
- RTPROT_BOOT, RTN_UNICAST);
+ return sitnl_route_set(RTM_NEWRO= UTE, NLM_F_CREATE, ifindex, af_family, dst, prefixlen, gw,
+ table, me= tric, scope, RTPROT_BOOT, RTN_UNICAST);
}
=
int
= -net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixl= en,
- c= onst in_addr_t *gw, const char *iface,
- uint32_t table, int metric)
+net_route_v4_add(openvpn_net_ctx_= t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
+ const char *= iface, uint32_t table, int metric)
{
= in_addr_t *dst_ptr =3D NULL, *gw_ptr =3D NULL;
in_addr= _t dst_be =3D 0, gw_be =3D 0;
@@ -1213,18 +1189,15 @@
}

msg(D_ROUTE, "= ;%s: %s/%d via %s dev %s table %d metric %d", __func__,
- inet_ntop(AF_INET, &dst_= be, dst_str, sizeof(dst_str)),

- prefixlen, inet_ntop(AF_INET, &gw_be, gw_str, sizeof(g= w_str)),
- np(if= ace), table, metric);
+ inet_ntop(AF_INET, &dst_be, dst_str, sizeof(dst_str)), prefix= len,
+ inet_nt= op(AF_INET, &gw_be, gw_str, sizeof(gw_str)), np(iface), table, metric);=

- = return sitnl_route_add(iface, AF_INET, dst_ptr, prefixlen, gw_ptr, table,<= /span>
- = metric);
+ re= turn sitnl_route_add(iface, AF_INET, dst_ptr, prefixlen, gw_ptr, table, met= ric);
}

int
<= span style=3D"color: hsl(0, 100%, 40%);">-net_route_v6_add(openvpn_net_ctx_= t *ctx, const struct in6_addr *dst,

- int prefixlen, const struct in6_addr *gw,
- const c= har *iface, uint32_t table, int metric)
+net_route_v6_add(openvpn_net_ctx_t *ctx, const struct i= n6_addr *dst, int prefixlen,
+ const struct in6_addr *gw, const char *iface, uin= t32_t table, int metric)
{
inet_addre= ss_t dst_v6 =3D { 0 };
inet_address_t gw_v6 =3D { 0 };=
@@ -1242,18 +1215,15 @@
}
<= span>

msg(D_ROUTE, "%s: %s/%d via %s dev %s tabl= e %d metric %d", __func__,
- inet_ntop(AF_INET6, &dst_v6.ipv6, dst_str, sizeof(dst= _str)),
- prefix= len, inet_ntop(AF_INET6, &gw_v6.ipv6, gw_str, sizeof(gw_str)),- np(iface), table, metr= ic);
+ inet_nt= op(AF_INET6, &dst_v6.ipv6, dst_str, sizeof(dst_str)), prefixlen,=
+ inet_ntop(AF_INET6= , &gw_v6.ipv6, gw_str, sizeof(gw_str)), np(iface), table, metric);

- retu= rn sitnl_route_add(iface, AF_INET6, dst, prefixlen, gw, table,
- metric)= ;

+ return sitnl_r= oute_add(iface, AF_INET6, dst, prefixlen, gw, table, metric);
}


static int
-sitnl_route_del(const char *iface, sa_famil= y_t af_family, inet_address_t *dst,
- int prefixlen, inet_address_t *gw, uint32_t t= able,
- = int metric)
+sitnl_ro= ute_del(const char *iface, sa_family_t af_family, inet_address_t *dst, int = prefixlen,
+ = inet_address_t *gw, uint32_t table, int metric)
{
int ifindex =3D 0;

@@= -1262,8 +1232,7 @@
ifindex =3D if_nametoindex(ifa= ce);
if (ifindex =3D=3D 0)
= {
- msg(M_= WARN | M_ERRNO, "%s: rtnl: can't get ifindex for %s",<= br>- __func__, ifa= ce);
+ msg= (M_WARN | M_ERRNO, "%s: rtnl: can't get ifindex for %s", __fu= nc__, iface);
return -ENOENT;
= }
}
@@ -1273,14 +1242,13 @@
table =3D RT_TABLE_MAIN;
}

- ret= urn sitnl_route_set(RTM_DELROUTE, 0, ifindex, af_family, dst, prefixlen,
- = gw, table, metric, RT_SCOPE_NOWHERE, 0, 0);
+ return sitnl_route_set(RTM_DELROUTE, 0, ifin= dex, af_family, dst, prefixlen, gw, table, metric,
+ RT_SCOPE_NOWHERE,= 0, 0);
}

int-net_route_v4_del(openvpn_net_ct= x_t *ctx, const in_addr_t *dst, int prefixlen,
- const in_addr_t *gw, const char *= iface, uint32_t table,
= - int metric)
+net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, in= t prefixlen, const in_addr_t *gw,
+ const char *iface, uint32_t table, int metri= c)
{
inet_address_t dst_v4 =3D { 0 };=
inet_address_t gw_v4 =3D { 0 };
@@ -1= 298,18 +1266,15 @@
}

msg(D_ROUTE, "%s: %s/%d via %s dev %s table %d metric %d", = __func__,

- inet= _ntop(AF_INET, &dst_v4.ipv4, dst_str, sizeof(dst_str)),
- prefixlen, inet_ntop(AF_INET,= &gw_v4.ipv4, gw_str, sizeof(gw_str)),

- np(iface), table, metric);
+ inet_ntop(AF_INET, &dst_v4.= ipv4, dst_str, sizeof(dst_str)), prefixlen,
+ inet_ntop(AF_INET, &gw_v4.ipv4, gw_str,= sizeof(gw_str)), np(iface), table, metric);

- return sitnl_route_del(iface, = AF_INET, &dst_v4, prefixlen, &gw_v4, table,

- metric);<= br>+ return sitnl_route_del(= iface, AF_INET, &dst_v4, prefixlen, &gw_v4, table, metric);<= br> }

int
-net_route_v6_del(openvpn_net_ctx_t *ctx, const= struct in6_addr *dst,
= - int prefixlen, const struct in6_addr *gw,
- const char *iface, u= int32_t table, int metric)

+net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst,= int prefixlen,
+ = const struct in6_addr *gw, const char *iface, uint32_t table, = int metric)
{
inet_address_t dst_v6 = =3D { 0 };
inet_address_t gw_v6 =3D { 0 };
<= span>@@ -1327,20 +1292,17 @@

}

msg(D_ROUTE, "%s: %s/%d via %s dev %s table %d metric = %d", __func__,
- = inet_ntop(AF_INET6, &dst_v6.ipv6, dst_str, sizeof(dst_str)),
- prefixlen, inet_nt= op(AF_INET6, &gw_v6.ipv6, gw_str, sizeof(gw_str)),
- np(iface), table, metric);<= br>+ inet_ntop(AF_INET6,= &dst_v6.ipv6, dst_str, sizeof(dst_str)), prefixlen,
+ inet_ntop(AF_INET6, &gw_v6= .ipv6, gw_str, sizeof(gw_str)), np(iface), table, metric);
=
- return sitnl_rou= te_del(iface, AF_INET6, &dst_v6, prefixlen, &gw_v6,
- table, met= ric);

+ return sit= nl_route_del(iface, AF_INET6, &dst_v6, prefixlen, &gw_v6, table, me= tric);
}


int

-net_iface_new(= openvpn_net_ctx_t *ctx, const char *iface, const char *type,
- void *arg)

<= span style=3D"color: hsl(120, 100%, 40%);">+net_iface_new(openvpn_net_ctx_t= *ctx, const char *iface, const char *type, void *arg)

{
- struct sitnl_link_r= eq req =3D { };
+ = struct sitnl_link_req req =3D {};
int ret =3D -1;

ASSERT(iface);
@@ -1358,= 8 +1320,7 @@
{
dco_context_t = *dco =3D arg;
struct rtattr *data =3D SITNL_NEST(&= amp;req.n, sizeof(req), IFLA_INFO_DATA);
- SITNL_ADDATTR(&req.n, sizeof(req), IFLA_OVPN= _MODE, &dco->ifmode,
- sizeof(uint8_t));
+ SITNL_ADDATTR(&req.n, sizeof(req), IF= LA_OVPN_MODE, &dco->ifmode, sizeof(uint8_t));
= SITNL_NEST_END(&req.n, data);
}
#endif

@@ -1367,7 +1328,7 @@

= req.i.ifi_family =3D AF_PACKET;

- msg(D_ROUTE, "%s: add %s ty= pe %s", __func__, iface, type);

+ msg(D_ROUTE, "%s: add %s type %s", __func__= , iface, type);

ret =3D sitnl_send(&= amp;req.n, 0, 0, NULL, NULL);
err:
@@ -137= 5,8 +1336,8 @@
}

static= int
-sitnl_parse_rtatt= r_flags(struct rtattr *tb[], int max, struct rtattr *rta,
- int len, unsig= ned short flags)
+sit= nl_parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta, int= len,
+ = unsigned short flags)
{
un= signed short type;

@@ -1396,8 +1357,7 @@<= /span>

if (len)
{
- msg(D_ROUTE, "= ;%s: %d bytes not parsed! (rta_len=3D%d)", __func__, len,
- rta->rta_len);
+ msg(D_ROUTE, &qu= ot;%s: %d bytes not parsed! (rta_len=3D%d)", __func__, len, rta->rt= a_len);
}

retur= n 0;
@@ -1410,8 +1370,7 @@
}

#define sitnl_parse_rtattr_nested(tb, max, rta) \
- (sitnl_parse_rtattr_f= lags(tb, max, RTA_DATA(rta), RTA_PAYLOAD(rta), \
- NLA_F_NESTED))
+ (sitnl_parse_rtattr= _flags(tb, max, RTA_DATA(rta), RTA_PAYLOAD(rta), NLA_F_NESTED))
<= span>

static int
sitnl_type_save(struct = nlmsghdr *n, void *arg)
@@ -1431,8 +1390,7 @@
{

struct rtattr *tb_link[IFLA_INFO_MAX + 1= ];

- = ret =3D sitnl_parse_rtattr_nested(tb_link, IFLA_INFO_MAX,
= - = tb[IFLA_LINKINFO]);
+ ret =3D sitnl_parse_rtattr_nested(tb_link, IFLA_INFO_MAX, t= b[IFLA_LINKINFO]);
if (ret < 0)
{

return ret;
@@ -14= 50,10 +1408,9 @@
}

int<= /span>
-net_iface_type(openvpn= _net_ctx_t *ctx, const char *iface,
- char type[IFACE_TYPE_LEN_MAX])
+net_iface_type(openvpn_net_ctx_t *c= tx, const char *iface, char type[IFACE_TYPE_LEN_MAX])

{
- struct sitnl_link_re= q req =3D { };
+ s= truct sitnl_link_req req =3D {};
int ifindex =3D if_na= metoindex(iface);

if (!ifindex)
@@ -1473,8 +1430,7 @@
int ret =3D sitnl_se= nd(&req.n, 0, 0, sitnl_type_save, type);
if (ret &= lt; 0)
{
- msg(D_ROUTE, "%s: cannot retrieve iface %s: %s (%d)&qu= ot;, __func__, iface,
-= strerror(-ret), ret);
+ msg(D_ROUTE, "%s: cannot retrieve iface %s: %s (= %d)", __func__, iface, strerror(-ret), ret);
= return ret;
}

@@ -14= 86,7 +1442,7 @@
int
net_iface_del(openvpn= _net_ctx_t *ctx, const char *iface)
{
- struct sitnl_link_req req =3D { };
+ struct sitnl_link_r= eq req =3D {};
int ifindex =3D if_nametoindex(iface);<= /span>

if (!ifindex)
diff -= -git a/src/openvpn/ntlm.c b/src/openvpn/ntlm.c
index 2c6a69= d..52afdb7 100644
--- a/src/openvpn/ntlm.c
= +++ b/src/openvpn/ntlm.c
@@ -45,15 +45,14 @@
#ifdef _MSC_VER

/* MS compilers */
#de= fine UINTEGER64 __int64
-#define UINT64(c) c ## Ui64
+#define UINT64(c) c##Ui64
#else
/* Non MS compilers */

#define UINTEGER64 unsigned long = long
-#define UINT64(c)= c ## LL
+#define UIN= T64(c) c##LL
#endif


-
stati= c void
gen_md4_hash(const uint8_t *data, int data_len, uin= t8_t *result)
{
@@ -65,8 +64,7 @@ }

static void
-gen_hmac_md5(const uint8_t *data, int d= ata_len, const uint8_t *key,
- uint8_t *result)
+gen_hmac_md5(const uint8_t *data, int data_len, const uint= 8_t *key, uint8_t *result)
{
hmac_ctx= _t *hmac_ctx =3D hmac_ctx_new();

@@ -92,1= 3 +90,13 @@

/* store little endian v= alue */
timestamp[0] =3D timestamp_ull & UINT64(0x= FF);
- timestamp[1] = =3D (timestamp_ull >> 8) & UINT64(0xFF);
- timestamp[2] =3D (timestamp_ull >&g= t; 16) & UINT64(0xFF);
- timestamp[3] =3D (timestamp_ull >> 24) & UINT64(0xFF);<= /span>
- timestamp[4] =3D (= timestamp_ull >> 32) & UINT64(0xFF);
- timestamp[5] =3D (timestamp_ull >> 40)= & UINT64(0xFF);
- = timestamp[6] =3D (timestamp_ull >> 48) & UINT64(0xFF);=
- timestamp[7] =3D (timest= amp_ull >> 56) & UINT64(0xFF);
+ timestamp[1] =3D (timestamp_ull >> 8) &= UINT64(0xFF);
+ t= imestamp[2] =3D (timestamp_ull >> 16) & UINT64(0xFF);
<= span style=3D"color: hsl(120, 100%, 40%);">+ timestamp[3] =3D (timestamp= _ull >> 24) & UINT64(0xFF);

+ timestamp[4] =3D (timestamp_ull >> 32) & UI= NT64(0xFF);
+ time= stamp[5] =3D (timestamp_ull >> 40) & UINT64(0xFF);
+ timestamp[6] =3D (timestamp_ul= l >> 48) & UINT64(0xFF);

+ timestamp[7] =3D (timestamp_ull >> 56) & UINT6= 4(0xFF);
}

static void<= /span>
@@ -107,7 +105,7 @@
/* Generates 8 ran= dom bytes to be used as client nonce */
int i;<= br>
- for (i = =3D 0; i<8; i++)
+= for (i =3D 0; i < 8; i++)
{
= nonce[i] =3D (unsigned char)get_random();
}
@@ -153,8 +151,8 @@
}
=
static void
= -add_security_buffer(int sb_offset, void *data, int length,
- unsigned char *ms= g_buf, int *msg_bufpos, size_t msg_bufsize)

+add_security_buffer(int sb_offset, void *data, int = length, unsigned char *msg_buf, int *msg_bufpos,
+ size_t msg_bufsize)=
{
if (*msg_bufpos + length > msg_bufsize= )
{
@@ -189,8 +187,7 @@
}


const char *
-ntlm_phase_3(const struct http_proxy_info *= p, const char *phase_2,
- struct gc_arena *gc)
+ntlm_phase_3(const struct http_proxy_info *p, const char *p= hase_2, struct gc_arena *gc)
{
/* NTL= M handshake
*
@@ -206,13 +203,13 @@
int i, ret_val;

= uint8_t ntlmv2_response[256];
- char userdomain_u[256]; /* for uppercase unicode username a= nd domain */
- char = userdomain[128]; /* the same as previous but ascii */
+ char userdomain_u[256]; /* for = uppercase unicode username and domain */

+ char userdomain[128]; /* the same as previous bu= t ascii */
uint8_t ntlmv2_hash[MD5_DIGEST_LENGTH];
uint8_t ntlmv2_hmacmd5[16];
- uint8_t *ntlmv2_blob =3D ntlmv2_response + 16; = /* inside ntlmv2_response, length: 128 */
+ uint8_t *ntlmv2_blob =3D ntlmv2_response + 16= ; /* inside ntlmv2_response, length: 128 */
int ntlmv2= _blob_size =3D 0;
- = int phase3_bufpos =3D 0x40; /* offset to next security buffer data to b= e added */
+ int p= hase3_bufpos =3D 0x40; /* offset to next security buffer data to be added *= /
size_t len;

c= har domain[128];
@@ -226,20 +223,20 @@
= separator =3D strchr(p->up.username, '\\');
= if (separator =3D=3D NULL)
{
- strncpy(username, p->up.username= , sizeof(username)-1);
= - username[sizeof(username)-1] =3D 0;
+ strncpy(username, p->up.username, sizeo= f(username) - 1);
+ = username[sizeof(username) - 1] =3D 0;
domain= [0] =3D 0;
}
else
{

- strncp= y(username, separator+1, sizeof(username)-1);
- username[sizeof(username)-1] =3D 0;<= br>+ strncpy(username, s= eparator + 1, sizeof(username) - 1);
+ username[sizeof(username) - 1] =3D 0;
len =3D separator - p->up.username;

= if (len > sizeof(domain) - 1)
{
len =3D sizeof(domain) - 1;

}
- strncpy(domain, p-= >up.username, len);
+ strncpy(domain, p->up.username, len);
= domain[len] =3D 0;
}

@@ -265,9 +262,9 @@

}

= /* extract the challenge from bytes 24-31 */
- for (i =3D 0; i<8; i++)
= + for (i =3D 0; i < 8; i+= +)
{
- challenge[i] =3D buf2[i+24];
+ challenge[i] =3D buf2[i + 24];
}


/* Generate NTLMv2 response = */
@@ -285,17 +282,16 @@
msg(M_INF= O, "NTLM: Username or domain too long");
}
unicodize(userdomain_u, userdomain);
- gen_hmac_md5((uint8_t *)userdomain_u= , 2 * strlen(userdomain), md4_hash,
- ntlmv2_hash);
+ gen_hmac_md5((uint8_t *)userdomain_u, 2 * strl= en(userdomain), md4_hash, ntlmv2_hash);

= /* NTLMv2 Blob */
-= memset(ntlmv2_blob, 0, 128); /* Clear blob buffe= r */
- ntlmv2_blob[0= x00] =3D 1; /* Signature */
- ntlmv2_blob[0x01] =3D 1; = /* Signature */
- ntlmv2_blob[0x04] =3D 0; /* Re= served */
- gen_time= stamp(&ntlmv2_blob[0x08]); /* 64-bit Timestamp */
- gen_nonce(&ntlmv2_= blob[0x10]); /* 64-bit Client Nonce */
- ntlmv2_blob[0x18] =3D 0; = /* Unknown, zero should work */

+ memset(ntlmv2_blob, 0, 128); /*= Clear blob buffer */
+ ntlmv2_blob[0x00] =3D 1; /* Signature */
+ ntlmv2_blob[0x01] =3D 1; = /* Signature */
= + ntlmv2_blob[0x04] =3D 0; /* Reserved */
+ gen_timestamp(&ntlmv2_blob[0x0= 8]); /* 64-bit Timestamp */
+ gen_nonce(&ntlmv2_blob[0x10]); /* 64-bit Client Nonce *= /
+ ntlmv2_blob[0x= 18] =3D 0; /* Unknown, zero should work */

/* Add target information block to the blob */
@@ -312,11 +308,11 @@
* byte= order on the wire for the NTLM header is LE.
*/
const size_t hoff =3D 0x14;
- unsigned long flags =3D buf2[hoff] | (buf2[hoff = + 1] << 8)
- = |(buf2[hoff + 2] << 16) | (buf2[hoff + 3] <&l= t; 24);
+ unsigned= long flags =3D
+ = buf2[hoff] | (buf2[hoff + 1] << 8) | (buf2[hoff + 2] << 16)= | (buf2[hoff + 3] << 24);
if ((flags & 0x00= 800000) =3D=3D 0x00800000)
{
- tib_len =3D buf2[0x28]; /* G= et Target Information block size */
+ tib_len =3D buf2[0x28]; /* Get Target Information b= lock size */
if (tib_len + 0x1c + 16 > sizeof(n= tlmv2_response))
{
ms= g(M_WARN, "NTLM: target information buffer too long for response (len= =3D%d)", tib_len);
@@ -328,7 +324,9 @@
uint8_t tib_pos =3D buf2[0x2c];

= if (tib_pos + tib_len > sizeof(buf2))
{
- msg(M_ERR= , "NTLM: phase 2 response from server too long (need %d bytes at offse= t %u)", tib_len, tib_pos);
+ msg(M_ERR,
+ "NTLM: phase 2 response from se= rver too long (need %d bytes at offset %u)",
+ tib_len, tib_pos);=
return NULL;
}
/* Get Target Information block pointer */<= br>@@ -352,41 +350,38 @@
memcpy(&ntlmv2_resp= onse[8], challenge, 8);

/* hmac-md5 = */
- gen_hmac_md5(&a= mp;ntlmv2_response[8], ntlmv2_blob_size + 8, ntlmv2_hash,
- ntlmv2_hmacmd5);
+ gen_hmac_md5(&ntl= mv2_response[8], ntlmv2_blob_size + 8, ntlmv2_hash, ntlmv2_hmacmd5);=

/* Add hmac-md5 result to the blob.=
* Note: This overwrites challenge previously written at
* ntlmv2_response[8..15] */
memcpy(= ntlmv2_response, ntlmv2_hmacmd5, MD5_DIGEST_LENGTH);

- memset(phase3, 0, size= of(phase3)); /* clear reply */
+ memset(phase3, 0, sizeof(phase3)); /* clear reply */=

- = strcpy((char *)phase3, "NTLMSSP\0"); /* signature */=
- phase3[8] =3D 3; /* = type 3 */
+ strcpy= ((char *)phase3, "NTLMSSP\0"); /* signature */
+ phase3[8] =3D 3; = /* type 3 */

/* NTLMv2 response= */
- add_security_b= uffer(0x14, ntlmv2_response, ntlmv2_blob_size + 16,
- phase3, &phase3= _bufpos, sizeof(phase3));
+ add_security_buffer(0x14, ntlmv2_response, ntlmv2_blob_size + 16,= phase3, &phase3_bufpos,
+ sizeof(phase3));
<= br> /* username in ascii */
- add_security_buffer(0x24, username, strlen(username), p= hase3,
- = &phase3_bufpos, sizeof(phase3));
+ add_security_buffer(0x24, username, strlen(us= ername), phase3, &phase3_bufpos, sizeof(phase3));

/* Set domain. If <domain> is empty, default domain= will be used
* (i.e. proxy's domain) */ add_security_buffer(0x1c, domain, strlen(domain), phase3, &= ;phase3_bufpos, sizeof(phase3));

/* = other security buffers will be empty */
- phase3[0x10] =3D phase3_bufpos; /* lm not used */=
- phase3[0x30] =3D = phase3_bufpos; /* no workstation name supplied */
- phase3[0x38] =3D phase3_bufpos; /* = no session key */
+ = phase3[0x10] =3D phase3_bufpos; /* lm not used */
+ phase3[0x30] =3D phase3_bufpos; /* no= workstation name supplied */
+ phase3[0x38] =3D phase3_bufpos; /* no session key */
/* flags */
phase3[0x3c= ] =3D 0x02; /* negotiate oem */
phase3[0x3d] =3D 0x02;= /* negotiate ntlm */

- return ((const char *)make_base64_string2((unsigned c= har *)phase3,
- = phase3_bufpos, gc));
+ return ((const char *)make_base6= 4_string2((unsigned char *)phase3, phase3_bufpos, gc));
}<= /span>
#endif /* if NTLM */
diff --git a/src/open= vpn/occ.c b/src/openvpn/occ.c
index 773fcfd..5f5bc9e 100644=
--- a/src/openvpn/occ.c
+++ b/src/openvpn/= occ.c
@@ -52,95 +52,93 @@
* OCC_STRING_SI= ZE must be set to sizeof (occ_magic)
*/
=
-const uint8_t occ_mag= ic[] =3D {
- 0x28, 0= x7f, 0x34, 0x6b, 0xd4, 0xef, 0x7a, 0x81,
- 0x2d, 0x56, 0xb8, 0xd3, 0xaf, 0xc5, 0x45, 0x9c
-};
+const uint8_t occ_magic[] =3D { 0x28, 0x7f, = 0x34, 0x6b, 0xd4, 0xef, 0x7a, 0x81,
+ 0x2d, 0x56, 0xb8, 0xd3, 0xaf,= 0xc5, 0x45, 0x9c };

static const struct= mtu_load_test mtu_load_test_sequence[] =3D {

<= span style=3D"color: hsl(0, 100%, 40%);">- {OCC_MTU_LOAD_REQUEST, -1000}= ,

- {OCC_MTU_LOAD, -= 1000},
- {OCC_MTU_LO= AD_REQUEST, -1000},
- = {OCC_MTU_LOAD, -1000},
- {OCC_MTU_LOAD, -1000},
+ { OCC_MTU_LOAD_REQUEST, -1000 },
+ { OCC_MTU_LOAD, -1000 },
=
+ { OCC_MTU_LOAD_REQUEST= , -1000 },
+ { OCC= _MTU_LOAD, -1000 },
+= { OCC_MTU_LOAD_REQUEST, -1000 },
+ { OCC_MTU_LOAD, -1000 },

<= span style=3D"color: hsl(0, 100%, 40%);">- {OCC_MTU_LOAD_REQUEST, -750},=

- {OCC_MTU_LOAD, -7= 50},
- {OCC_MTU_LOAD= _REQUEST, -750},
- {= OCC_MTU_LOAD, -750},
- = {OCC_MTU_LOAD_REQUEST, -750},
- {OCC_MTU_LOAD, -750},
+ { OCC_MTU_LOAD_REQUEST, -750 },
+ { OCC_MTU_LOAD, -750 },
+ { OCC_MTU_LOAD_REQUEST, -750 = },

+ { OCC_MTU_LOA= D, -750 },
+ { OCC= _MTU_LOAD_REQUEST, -750 },
+ { OCC_MTU_LOAD, -750 },

- {OCC_MTU_LOAD_REQUEST, -500},- {OCC_MTU_LOAD, -500},
- {OCC_MTU_LOAD_REQUEST, = -500},
- {OCC_MTU_LO= AD, -500},
- {OCC_MT= U_LOAD_REQUEST, -500},
= - {OCC_MTU_LOAD, -500},
+ { OCC_MTU_LOAD_REQUEST, -500 },
+ { OCC_MTU_LOAD, -500 },
+ { OCC_MTU_LOAD_REQUEST, -500 },+ { OCC_MTU_LOAD, -500 },<= /span>
+ { OCC_MTU_LOAD_R= EQUEST, -500 },
+ = { OCC_MTU_LOAD, -500 },

- {OCC_MTU_LOAD_REQUEST, -400},
- {OCC_MTU_LOAD, -400},
- {OCC_MTU_LOAD_REQUEST, -400},
- {OCC_MTU_LOAD, -400},
- {OCC_MTU_LOAD_REQUE= ST, -400},
- {OCC_MT= U_LOAD, -400},
+ {= OCC_MTU_LOAD_REQUEST, -400 },
+ { OCC_MTU_LOAD, -400 },
+ { OCC_MTU_LOAD_REQUEST, -400 },
+ { OCC_MTU_LOAD, -400 },
+ { OCC_MTU_LOAD_REQUEST, -400= },

+ { OCC_MTU_LO= AD, -400 },

- {OCC_MTU_LOAD_REQUEST, -300},
- {OCC_MTU_LOAD, -300},
- {OCC_MTU_LOAD_REQUEST, -300},
- {OCC_MTU_LOAD, -300},
- {OCC_MTU_LOAD_REQUEST, -300},
- {OCC_MTU_LOAD, -300= },
+ { OCC_MTU_LOA= D_REQUEST, -300 },
+ = { OCC_MTU_LOAD, -300 },
+ { OCC_MTU_LOAD_REQUEST, -300 },
+ { OCC_MTU_LOAD, -300 },
+ { OCC_MTU_LOAD_REQUEST, -300 },+ { OCC_MTU_LOAD, -300 },<= /span>

- = {OCC_MTU_LOAD_REQUEST, -200},
- {OCC_MTU_LOAD, -200},
- {OCC_MTU_LOAD_REQUEST, -200},
- {OCC_MTU_LOAD, -200},
- {OCC_MTU_LOAD_REQUEST, -200},
- {OCC_MTU_LOAD, -200},
+ { OCC_MTU_LOAD_REQUEST, -= 200 },
+ { OCC_MTU= _LOAD, -200 },
+ {= OCC_MTU_LOAD_REQUEST, -200 },
+ { OCC_MTU_LOAD, -200 },
+ { OCC_MTU_LOAD_REQUEST, -200 },
+ { OCC_MTU_LOAD, -200 },

- {OCC_MTU_LOA= D_REQUEST, -150},
- = {OCC_MTU_LOAD, -150},
-= {OCC_MTU_LOAD_REQUEST, -150},
- {OCC_MTU_LOAD, -150},
- {OCC_MTU_LOAD_REQUEST, -150},
- {OCC_MTU_LOAD, -150},
+ { OCC_MTU_LOAD_REQUEST, -150 },
+ { OCC_MTU_LOAD, -150 = },
+ { OCC_MTU_LOA= D_REQUEST, -150 },
+ = { OCC_MTU_LOAD, -150 },
+ { OCC_MTU_LOAD_REQUEST, -150 },
+ { OCC_MTU_LOAD, -150 },
=
- {OCC_MTU_LOAD_REQUEST, -= 100},
- {OCC_MTU_LOA= D, -100},
- {OCC_MTU= _LOAD_REQUEST, -100},
-= {OCC_MTU_LOAD, -100},
- {OCC_MTU_LOAD_REQUEST, -100},
- {OCC_MTU_LOAD, -100},
+ { OCC_MTU_LOAD_REQUEST, -100 },
+ { OCC_MTU_LOAD, -100 },+ { OCC_MTU_LOAD_REQUEST, -= 100 },
+ { OCC_MTU= _LOAD, -100 },
+ {= OCC_MTU_LOAD_REQUEST, -100 },
+ { OCC_MTU_LOAD, -100 },

- {OCC_MTU_LOAD_REQUEST, -50},<= br>- {OCC_MTU_LOAD, -50},
- {OCC_MTU_LOAD_REQUEST,= -50},
- {OCC_MTU_LO= AD, -50},
- {OCC_MTU= _LOAD_REQUEST, -50},
- = {OCC_MTU_LOAD, -50},
+ { OCC_MTU_LOAD_REQUEST, -50 },
+ { OCC_MTU_LOAD, -50 },
+ { OCC_MTU_LOAD_REQUEST, -50 },
+ { OCC_MTU_LOAD, -50 },
<= br>+ { OCC_MTU_LOAD_REQUEST,= -50 },
+ { OCC_MT= U_LOAD, -50 },

- {OCC_MTU_LOAD_REQUEST, 0},
- {OCC_MTU_LOAD, 0},
- {OCC_MTU_LOAD_REQUEST, 0},
- {OCC_MTU_LOAD, 0},
- {OCC_MTU_LOAD_REQUEST, 0},
<= span style=3D"color: hsl(0, 100%, 40%);">- {OCC_MTU_LOAD, 0},

= + { OCC_MTU_LOAD_REQUEST, 0 = },
+ { OCC_MTU_LOA= D, 0 },
+ { OCC_MT= U_LOAD_REQUEST, 0 },
= + { OCC_MTU_LOAD, 0 },
+ { OCC_MTU_LOAD_REQUEST, 0 },
+ { OCC_MTU_LOAD, 0 },

- {OCC_MTU_REQUEST, 0},
- {OCC_MTU_REQUEST, 0},
- {OCC_MTU_REQUEST, 0},
- {OCC_MTU_REQUEST, 0= },
- {OCC_MTU_REQUES= T, 0},
- {OCC_MTU_RE= QUEST, 0},
- {OCC_MT= U_REQUEST, 0},
- {OC= C_MTU_REQUEST, 0},
- = {OCC_MTU_REQUEST, 0},
= - {OCC_MTU_REQUEST, 0},
+ { OCC_MTU_REQUEST, 0 },
+ { OCC_MTU_REQUEST, 0 },
+ { OCC_MTU_REQUEST, 0 },
+ { OCC_MTU_REQUEST, 0 },
+ { OCC_MTU_REQUEST, 0 },+ { OCC_MTU_REQUEST, 0 },<= /span>
+ { OCC_MTU_REQUES= T, 0 },
+ { OCC_MT= U_REQUEST, 0 },
+ = { OCC_MTU_REQUEST, 0 },
+ { OCC_MTU_REQUEST, 0 },

- {-1, 0}
+ { -1, 0 }
};

void
@@ -156,15 +154,12 @@
= */
msg(D_SHOW_OCC,
"NOTE: failed to obtain options consistency info fro= m peer -- "

- = "this could occur if the remote peer is running a version o= f "
- = PACKAGE_NAME
- = " before 1.5-beta8 or if there is a network connectivity pro= blem, and will not necessarily prevent "
- PACKAGE_NAME
+ "this could occur if= the remote peer is running a version of " PACKAGE_NAME
+ " before 1.5-= beta8 or if there is a network connectivity problem, and will not necessari= ly prevent " PACKAGE_NAME

" from= running (" counter_format " bytes received from peer, " cou= nter_format
" bytes authenticated dat= a channel traffic) -- you can disable the options consistency "=
"check with --disable-occ.",- c->c2.link_r= ead_bytes,
- = c->c2.link_read_bytes_auth);
+ c->c2.link_read_bytes, c->c2.link_re= ad_bytes_auth);
}
event_t= imeout_clear(&c->c2.occ_interval);
}
= @@ -197,16 +192,17 @@
if (entry->op >= =3D 0)
{
c->c2.occ= _op =3D entry->op;
-= size_t payload_size =3D frame_calculate_payload_size(&c->= ;c2.frame,
- = &c->options, &am= p;c->c1.ks.key_type);
+ size_t payload_size =3D
+ frame_ca= lculate_payload_size(&c->c2.frame, &c->options, &c->c1= .ks.key_type);
+ = size_t header_size =3D
+ frame_calculate_protocol_header_size(&c->c= 1.ks.key_type, &c->options, false);

c->c2.occ_mtu_load_size =3D payload_size + header_size;
}
else
= {
- ms= g(M_INFO,
- = "NOTE: failed to empirically measure MTU (requires " PACKAGE_= NAME " 1.5 or higher at other end of connection).");
+ msg(M_INFO, "NO= TE: failed to empirically measure MTU (requires " PACKAGE_NAME
<= br>+ &qu= ot; 1.5 or higher at other end of connection).");
= event_timeout_clear(&c->c2.occ_mtu_load_test_interval);
c->c2.occ_mtu_load_n_tries =3D 0;
}

@@ -309,10 +305,8 @@
= proto_hdr =3D frame_calculate_protocol_header_size(kt, &c->opt= ions, false);

need_to_add = =3D min_int(c->c2.occ_mtu_load_size, c->c2.frame.buf.payload_size)
- = - OCC_STRING_SIZE
- = - sizeof(uint8_t) /* occ opcode */
- - payloa= d_hdr

- = - proto_hdr;
+ = - payload_hdr - proto_hdr;

= while (need_to_add > 0)
{
@@ -326,13 +320,8 @@
--need_to_= add;
}
dmsg(D_PAC= KET_CONTENT, "SENT OCC_MTU_LOAD min_int(%d,%d)-%d-%d-%d-%d) size=3D%d&= quot;,
- = c->c2.occ_mtu_load_size,
- c->c2.frame.buf.payload_size,
- OCC_STRING_SIZE,
- (int) size= of(uint8_t),
- = (int) payload_hdr,
- (int) proto_hdr,
- BLEN(&c->c2.buf));
+ c->c2.occ_mtu_l= oad_size, c->c2.frame.buf.payload_size, OCC_STRING_SIZE,

+ (int)sizeof(uint8_= t), (int)payload_hdr, (int)proto_hdr, BLEN(&c->c2.buf));

<= span> doit =3D true;

}
break;

@@ -388,12 +377,10 @@
= dmsg(D_PACKET_CONTENT, "RECEIVED OCC_REPLY");
= if (c->options.occ && !TLS_MODE(c) &&= c->c2.options_string_remote)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- if (!options_cmp_= equal_safe((char *) BPTR(&c->c2.buf),

- c->c2= .options_string_remote,
+ if (!options_cmp_equal_safe((char *)BPTR(&c->c2.= buf), c->c2.options_string_remote,
= c->c2.buf.len))
= {
- = options_warning_safe((char *) BPTR(&c->c2.buf),
- = c->c2.options_string_remote,
+ options_warning_safe((char *)BPTR(&c-&g= t;c2.buf), c->c2.options_string_remote,
= c->c2.buf.len);
= }
}
@@ -404,22 +391,20 @@
dmsg(D_PACKET_CONTENT, "RECEIVED OCC_MTU_R= EPLY");
c->c2.max_recv_size_remote =3D= buf_read_u16(&c->c2.buf);
c->c2.max= _send_size_remote =3D buf_read_u16(&c->c2.buf);
- if (c->options.mtu_test
- &&= ; c->c2.max_recv_size_remote > 0
+ if (c->options.mtu_test && c->= c2.max_recv_size_remote > 0
&& = c->c2.max_send_size_remote > 0)
{=
- msg(M_INFO, = "NOTE: Empirical MTU test completed [Tried,Actual] local->remote=3D= [%d,%d] remote->local=3D[%d,%d]",
- c->c2.max_send_size_local,
- c->c= 2.max_recv_size_remote,
- c->c2.max_send_size_remote,
- c->c2.max_recv_size_= local);
- = if (!c->options.ce.fragment
- && (proto_is_dgram(c->options.ce.= proto))
+ = msg(M_INFO,
+ = "NOTE: Empirical MTU test completed [Tried,Actual] loc= al->remote=3D[%d,%d] remote->local=3D[%d,%d]",
+ c->c2.max_send= _size_local, c->c2.max_recv_size_remote,
+ c->c2.max_send_size_remote, = c->c2.max_recv_size_local);
+ if (!c->options.ce.fragment && (proto= _is_dgram(c->options.ce.proto))
&am= p;& c->c2.max_send_size_local > TUN_MTU_MIN
= && (c->c2.max_recv_size_remote < c->c2.max= _send_size_local
|| c->c2.max_r= ecv_size_local < c->c2.max_send_size_remote))
= {
- = msg(M_INFO, "NOTE: This connection is unable to accommodate = a UDP packet size of %d. Consider using --fragment or --mssfix options as a= workaround.",
+= msg(M_INFO,
+ "NOTE: This connection is unable t= o accommodate a UDP packet size of %d. Consider using --fragment or --mssfi= x options as a workaround.",
= c->c2.max_send_size_local);
} }
diff --git a/src/openvpn/occ.h b/src/= openvpn/occ.h
index 8631bce..1ac93b2 100644
--- a/src/openvpn/occ.h

+++ b/src/openvpn/occ.h
= @@ -33,8 +33,8 @@
* OCC (OpenVPN Configuration Cont= rol) protocol opcodes.
*/

-#define OCC_REQUEST 0 /* = request options string from peer */

-#define OCC_REPLY 1 /* deliver options string to = peer */
+#define OCC_= REQUEST 0 /* request options string from peer */
+#define OCC_REPLY 1 /* deliver options strin= g to peer */

/*
* Send= an OCC_REQUEST once every OCC_INTERVAL
@@ -49,11 +49,12 @@=
/*
* Other OCC protocol opcodes used to= estimate the MTU empirically.
*/
-#define OCC_MTU_LOAD_REQUEST 2 /* = Ask peer to send a big packet to us */
-#define OCC_MTU_LOAD 3 /* Send a big pack= et to peer */
-#define = OCC_MTU_REQUEST 4 /* Ask peer to tell us the largest- = * packet it has received from us so far */
-#define OCC_MTU_REPLY 5 /* = Send largest packet size to peer */
+#define OCC_MTU_LOAD_REQUEST 2 /* Ask peer to send a big pa= cket to us */
+#defin= e OCC_MTU_LOAD 3 /* Send a big packet to peer */
+#define OCC_MTU_REQUEST = \
+ 4 /* Ask peer to tell us the largest= \
+ = * packet it has received from us so far */
+#define OCC_MTU_REPLY 5 /* Sen= d largest packet size to peer */

/*
* Process one command from mtu_load_test_sequence
<= span>@@ -64,7 +65,7 @@

/*
* Send an exit= message to remote.
*/
-#define OCC_EXIT 6
+#define OCC_EXIT 6

/*
* Used to conduct a load test command seq= uence
@@ -72,10 +73,10 @@
*/
struct mtu_load_test

{
- int op; /* OCC opcode to sen= d to peer */
- int d= elta; /* determine packet size to send by using
= - = * this delta against currently
- * configured MTU */
+ int op; /* OCC opcode to = send to peer */

+ = int delta; /* determine packet size to send by using
+ * this delta against curr= ently
+ = * configured MTU */
};

extern const uint8_t occ_magic[];

@@ -111,8 +112,7 @@
check_send_occ_req(struct context *c)
{
if (event_timeout_defined(&c->c2.occ_interval)
- && event_t= imeout_trigger(&c->c2.occ_interval,
- &c->c2.timeval= ,
+ &&= event_timeout_trigger(&c->c2.occ_interval, &c->c2.timeval,
(!TO_LINK_DEF(c) &&= ; c->c2.occ_op < 0) ? ETT_DEFAULT : 0))
{=
check_send_occ_req_dowork(c);
@@ -126,8 = +126,7 @@
check_send_occ_load_test(struct context *c)
{
if (event_timeout_defined(&c->c2= .occ_mtu_load_test_interval)
- && event_timeout_trigger(&c->c2.occ_mtu_load_= test_interval,
- = &c->c2.timeval,
+ && event_timeout_trigger(&= c->c2.occ_mtu_load_test_interval, &c->c2.timeval,
(!TO_LINK_DEF(c) && c->c2.occ= _op < 0) ? ETT_DEFAULT : 0))

{
= check_send_occ_load_test_dowork(c);
diff --git a/src/o= penvpn/openssl_compat.h b/src/openvpn/openssl_compat.h
inde= x 6baaaea..f9e1460 100644
--- a/src/openvpn/openssl_compat.= h
+++ b/src/openvpn/openssl_compat.h
@@ -68= ,15 +68,16 @@
}
}

-#define EVP_CTRL_AEAD_S= ET_TAG EVP_CTRL_GCM_SET_TAG
-#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_= GCM_GET_TAG
+#define = EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG
+#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG
#endif

#if defined(LIBRE= SSL_VERSION_NUMBER)
-#d= efine RSA_F_RSA_OSSL_PRIVATE_ENCRYPT RSA_F_RSA_EAY_PRIVATE_ENCRYPT
+#define RSA_F_RSA_OSSL= _PRIVATE_ENCRYPT RSA_F_RSA_EAY_PRIVATE_ENCRYPT
#endif

-#if defi= ned(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x3050= 400fL || defined(OPENSSL_IS_AWSLC)
+#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VER= SION_NUMBER < 0x3050400fL \
+ || defined(OPENSSL_IS_AWSLC)
#define SSL_ge= t_peer_tmp_key SSL_get_server_tmp_key
#endif

@@ -86,10 +87,8 @@
/* Note that this = is not a perfect emulation of the new function but
* is g= ood enough for our case of printing certificate details during
* handshake */

-s= tatic inline
-int
-EVP_PKEY_get_group_name(EVP= _PKEY *pkey, char *gname, size_t gname_sz,
- size_t *gname_len)
<= span style=3D"color: hsl(120, 100%, 40%);">+static inline int

+EVP_PKEY_get_group_name(EVP_PKEY = *pkey, char *gname, size_t gname_sz, size_t *gname_len)

{<= /span>
const EC_KEY *ec =3D EVP_PKEY_get0_EC_KEY(pkey);
if (ec =3D=3D NULL)
@@ -118,13 +117,12 @@
#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L &&= amp; !defined(OPENSSL_NO_EC) */

#if OPEN= SSL_VERSION_NUMBER < 0x30000000L
-#define EVP_MD_get0_name EVP_MD_name
-#define EVP_CIPHER_get0_name EVP_CIPHER_name
+#define EVP_MD_get0_n= ame EVP_MD_name
-#define SSL_CTX_new_ex(li= bctx, propq, method) \
- SSL_CTX_new((method))
+#define SSL_CTX_new_ex(libctx, propq, method) SSL_CTX= _new((method))

/* Some safe typedefs to = avoid too many ifdefs */
typedef void OSSL_LIB_CTX;=
@@ -161,9 +159,7 @@
}
static inline unsigned long
-ERR_get_error_all(const char **file, int *line,
- const char **fun= c,

- c= onst char **data, int *flags)
+ERR_get_error_all(const char **file, int *line, const char **func= , const char **data, int *flags)
{
st= atic const char *empty =3D "";
*func =3D emp= ty;
@@ -173,13 +169,13 @@

#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */


-#if OPENSSL_VERSION_NUMB= ER < 0x30500000 && (!defined(LIBRESSL_VERSION_NUMBER) || LIBRESS= L_VERSION_NUMBER > 0x3050400fL)
+#if OPENSSL_VERSION_NUMBER < 0x30500000 \
+ && (!defined(LIBRESSL_V= ERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3050400fL)

static inline int

SSL_get0_peer_signature_name(SSL *ssl,= const char **sigalg)
{
int peer_sig_= nid;
- if (SSL_get_p= eer_signature_nid(ssl, &peer_sig_nid)
- && peer_sig_nid !=3D NID_undef)<= br>+ if (SSL_get_peer_signat= ure_nid(ssl, &peer_sig_nid) && peer_sig_nid !=3D NID_undef)
{
*sigalg =3D OBJ_nid2sn(peer_si= g_nid);
return 1;
@@ -195,7 +191,8= @@
*sigalg =3D NULL;
return 0;
}
-#end= if /* if OPENSSL_VERSION_NUMBER < 0x30500000 && (!defined(LIBRES= SL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3050400fL) */+#endif /* if OPENSSL_VERSION= _NUMBER < 0x30500000 && (!defined(LIBRESSL_VERSION_NUMBER) || \<= /span>
+ LIBRESSL_V= ERSION_NUMBER > 0x3050400fL) */

#if O= PENSSL_VERSION_NUMBER < 0x30200000L && OPENSSL_VERSION_NUMBER &g= t;=3D 0x30000000L
static inline const char *
diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c

index 54d5a06..51dcd92 100644

--- a/src/openvpn/openvpn.= c
+++ b/src/openvpn/openvpn.c
@@ -120,8 +12= 0,7 @@
* printing depends on it */
= for (int j =3D 1; j < MAX_PARMS && c->options.providers.na= mes[j]; j++)
{
- c->options.providers.providers[j] =3D
- crypto_load_provider(c= ->options.providers.names[j]);

+ c->options.providers.providers[j] =3D crypto_load_= provider(c->options.providers.names[j]);
} }

@@ -130,8 +129,7 @@
= {
for (int j =3D 1; j < MAX_PARMS &&= c->options.providers.providers[j]; j++)
{- crypto_unload_provider= (c->options.providers.names[j],
- c->options.providers.provide= rs[j]);
+ cryp= to_unload_provider(c->options.providers.names[j], c->options.provider= s.providers[j]);
}
net_ctx_free(&= amp;c->net_ctx);
}
@@ -157,14 +155,15 @= @
* @param argc - Commandline argument count.
<= span> * @param argv - Commandline argument values.

*/
-static
-int
+static int
openvpn_main(int argc, char= *argv[])
{
struct context c;<= br>
#if PEDANTIC
- fprintf(stderr, "Sorry, I was built with --enab= le-pedantic and I am incapable of doing any real work!\n");
= + fprintf(
+ stderr,
+ "Sorry, I was built with --e= nable-pedantic and I am incapable of doing any real work!\n");<= br> return 1;
#endif
@@ -333,15 +332,13 @@

= /* pass restart status to management subsystem */
= signal_restart_status(c.sig);
- }
- while (signal_reset(c.sig, SIGUSR1) =3D=3D SIGUSR1= );
+ } whi= le (signal_reset(c.sig, SIGUSR1) =3D=3D SIGUSR1);
<= br> env_set_destroy(c.es);
u= ninit_options(&c.options);
gc_reset(&c= .gc);
uninit_early(&c);
- }
- while (signal_reset(c.sig, SIGHUP) =3D=3D SI= GHUP);
+ } whi= le (signal_reset(c.sig, SIGHUP) =3D=3D SIGHUP);
}

context_gc_free(&c);
@@ -366,7 +363,7 @@

int ret;
int= i;

-= if ((argv =3D calloc(argc+1, sizeof(char *))) =3D=3D NULL)
+ if ((argv =3D calloc(argc + = 1, sizeof(char *))) =3D=3D NULL)

{
= return 1;
}
diff --git a/src/ope= nvpn/openvpn.h b/src/openvpn/openvpn.h
index 3c8ce39..c5f88= c8 100644
--- a/src/openvpn/openvpn.h
+++ b= /src/openvpn/openvpn.h
@@ -70,7 +70,7 @@
= * renegotiation key */
struct key2 original_wrap_k= eydata;
struct key_ctx tls_crypt_v2_server_key;=
- struct buffer tls_crypt_= v2_wkc; /**< Wrapped client key */
+ struct buffer tls_crypt_v2_wkc; /**< W= rapped client key */
struct key_ctx auth_token_key;
};

@@ -170,10 +170,10 @@
/* persist crypto sequence number to/from file */
struct packet_id_persist pid_persist;

- struct tuntap *tuntap= ; /**< Tun/tap virtual network interface. */
- bool tuntap_owned; /**< Whe= ther the tun/tap interface should
- * be cleaned up when this %c= ontext is
- = * cleaned up. */
+ struct tuntap *tuntap; /**< Tun/tap virtual netw= ork interface. */
+ = bool tuntap_owned; /**< Whether the tun/tap interface should
+ = * be cleaned up when this %context is
+ * cleaned up. */

struct route_list *route_list;
= /**< List of routing information. See the
@@ = -209,8 +209,7 @@
static inline bool
is_ca= s_pending(enum multi_status cas)
{
- return cas =3D=3D CAS_PENDING || cas = =3D=3D CAS_PENDING_DEFERRED
- || cas =3D=3D CAS_PENDING_DEFERRED_PARTIAL;
+ return cas =3D=3D CAS_PENDING = || cas =3D=3D CAS_PENDING_DEFERRED || cas =3D=3D CAS_PENDING_DEFERRED_PARTI= AL;

}

/**
@@ -224,9 +223,9 @@

*/
struct context= _2
{
-= struct gc_arena gc; /**< Garbage collection arena for=
- = * allocations done in the level 2 scope
- * of this conte= xt_2 structure. */
+ = struct gc_arena gc; /**< Garbage collection arena for
+ * alloca= tions done in the level 2 scope

+ * of this context_2 structure. */

/* our global wait events */ struct event_set *event_set;
@@ -241,13 +240,13= @@

bool link_socket_owned;
- const st= ruct link_socket *accept_from; /* possibly do accept() on a parent link_soc= ket */
+ const str= uct link_socket *accept_from; /* possibly do accept() on a parent link_so= cket */

- struct link_socket_actual *to_link_addr; /* IP address of remote= */
- struct link_so= cket_actual from; /* address of incoming datagram */
= + struct link_socket_actual = *to_link_addr; /* IP address of remote */
+ struct link_socket_actual from; /* addre= ss of incoming datagram */

/* MTU fr= ame parameters */
- = struct frame frame; /* Active frame parameters */
+ struct frame fram= e; /* Active frame parameters */

#ifdef = ENABLE_FRAGMENT
/* Object to handle advanced MTU negot= iation and datagram fragmentation */
@@ -298,7 +297,7 @@
char *options_string_local;
char *o= ptions_string_remote;

- int occ_op; /* INIT to -1 */+ int occ_op; /* INIT to -= 1 */
int occ_n_tries;
struct even= t_timeout occ_interval;

@@ -306,11 +305,1= 1 @@
* Keep track of maximum packet size received so = far
* (of authenticated packets).
= */
- int original= _recv_size; /* temporary */
- int max_recv_size_local; /* max packet size received */
- int max_recv_size_re= mote; /* max packet size received by remote */
- int max_send_size_local; /* max packet si= ze sent */
- int max= _send_size_remote; /* max packet size sent by remote */
+ int original_recv_size; /* temp= orary */
+ int max= _recv_size_local; /* max packet size received */
+ int max_recv_size_remote; /* max packet s= ize received by remote */
+ int max_send_size_local; /* max packet size sent */
+ int max_send_size_remote; /*= max packet size sent by remote */



/* remote wants us to send back a load test packet of this= size */
@@ -474,60 +473,64 @@
*/<= br> struct context
{
- struct options options; /**< Options loade= d from command line or
= - * configuration file. */
+ struct options options; /**<= ; Options loaded from command line or

+ * configuration file. */

- b= ool first_time; /**< True on the first iteration of- = * OpenVPN's main loop. */
+ bool first_time; /**< True on the first iterati= on of
+ = * OpenVPN's main loop. */

= /* context modes */
-#define CM_P2P 0 /* standalone point-to-point session = or client */
-#define C= M_TOP 1 /* top level of a multi-client or point-to-multipoint s= erver */
-#define CM_TO= P_CLONE 2 /* clone of a CM_TOP context for one thread */
-#define CM_CHILD_UDP 3 /* ch= ild context of a CM_TOP or CM_THREAD */

-#define CM_CHILD_TCP 4 /* child context of a CM_TOP= or CM_THREAD */
- i= nt mode; /**< Role of this context within the- = * OpenVPN process. Valid values are \c
- * CM_P2P, \c CM_T= OP, \c CM_TOP_CLONE,
- = * \c CM_CHILD_UDP, and \c CM_CHILD_TCP. *= /
+#define CM_P2P = 0 /* standalone point-to-point session or client */
= +#define CM_TOP 1 = /* top level of a multi-client or point-to-multipoint server */+#define CM_TOP_CLONE 2 = /* clone of a CM_TOP context for one thread */
+#define CM_CHILD_UDP 3 /* child= context of a CM_TOP or CM_THREAD */
+#define CM_CHILD_TCP 4 /* child context of a CM_= TOP or CM_THREAD */
+= int mode; /**< Role of this context within the
+ = * OpenVPN process. Valid values are \c
+ * CM_= P2P, \c CM_TOP, \c CM_TOP_CLONE,
+ * \c CM_CHILD_UDP, and \c = CM_CHILD_TCP. */

- struct gc_arena gc; /**< Garbage collection are= na for
- = * allocations done in the scope of this
- * = context structure. */

+ struct gc_arena gc; /**< Garbage collection arena for
+ = * allocations done in the scope of this
+ * con= text structure. */

- struct env_set *es; /**< Set of environment v= ariables. */
+ str= uct env_set *es; /**< Set of environment variables. */
- openvpn_= net_ctx_t net_ctx; /**< Networking API opaque context */
+ openvpn_net_ctx_t net_ctx; /= **< Networking API opaque context */


- struct signal_info *sig; /**<= Internal error signaling object. */
+ struct signal_info *sig; /**< Internal error si= gnaling object. */

struct plugin_lis= t *plugins; /**< List of plug-ins. */
- bool plugins_owned; /**< Whether the plug= -ins should be
- = * cleaned up when this %context is
- *= cleaned up. */

+ = bool plugins_owned; /**< Whether the plug-ins should be
+ = * cleaned up when this %context is
+ * cleaned up.= */

-= bool did_we_daemonize; /**< Whether demonization has already
- = * taken place. */
+ bool did_we_daemonize; /**< Whether demonization has = already
+ = * taken place. */

struct context_persist persist;

/**< Persiste= nt %context. */
- st= ruct context_0 *c0; /**< Level 0 %context. */
- struct context_1 c1; /**< Le= vel 1 %context. */
- = struct context_2 c2; /**< Level 2 %context. */
+ struct context_0 *c0; /**< Lev= el 0 %context. */
+ = struct context_1 c1; /**< Level 1 %context. */
+ struct context_2 c2; /**< Level 2= %context. */
};

/*
* Check for a signal when inside an event loop
*/

-#define EVENT_= LOOP_CHECK_SIGNAL(c, func, arg) \
- if (IS_SIG(c)) \
- { = \

- cons= t int brk =3D func(arg); \
- perf_pop(); \
- if (brk) { = \

- = break;} \
- else { \
- continue;} = \
+#define EVENT_LOOP_CHECK_SIGNAL(c, func, arg) \
+ if (IS_SIG(c)) = \
+ { = \
+ const int brk =3D func(arg); \
= + perf_pop(); = \
+ = if (brk) \
+ { \
+ break; = \
+ } \
+ else = \
+ { = \
+ continue; \
<= span style=3D"color: hsl(120, 100%, 40%);">+ } = \

}

= /*
@@ -535,14 +538,15 @@
* have been comp= iled in.
*/

-#define TLS_MODE(c) ((c)->c2.tls_multi !=3D NU= LL)
-#define PROTO_DUMP= _FLAGS (check_debug_level(D_LINK_RW_VERBOSE) ? (PD_SHOW_DATA|PD_VERBOSE) : = 0)
-#define PROTO_DUMP(= buf, gc) protocol_dump((buf), \
- PROTO_DUMP_FLAGS \
- = |(c->c2.tls_multi ? PD_TLS : 0) \
- = |(c->options.tls_auth_file ? md_kt_size(c->c1.ks.key_type.digest) := 0) \
- = |(c->options.tls_crypt_file || c->options.t= ls_crypt_v2_file ? PD_TLS_CRYPT : 0), \
- gc)
<= span style=3D"color: hsl(120, 100%, 40%);">+#define TLS_MODE(c) ((c)-&= gt;c2.tls_multi !=3D NULL)

+#define PROTO_DUMP_FLAGS (check_debug_level(D_LINK_RW_VERBOSE) ? (PD= _SHOW_DATA | PD_VERBOSE) : 0)
+#define PROTO_DUMP(buf, gc) = \
+ protocol_dump( = \
+ (buf), = \
+ PROTO_DUMP_FLAGS | (c->c2.tls_multi ? PD_TLS : 0) = \
+ | (c->options.tls_auth_file ? md_kt_size(c-= >c1.ks.key_type.digest) : 0) \
+ | (c->options.tls_crypt_file || c-&g= t;options.tls_crypt_v2_file ? PD_TLS_CRYPT : 0), \
+ gc)

/* this represents "disabled peer-id" */

#def= ine MAX_PEER_ID 0xFFFFFF
diff --git a/src/openvpn/options.c= b/src/openvpn/options.c
index 0662b49..742ff58 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/o= ptions.c
@@ -67,8 +67,7 @@

#include "memdbg.h"


-const char title_string[] =3D
- PACKAGE_STRING
+const char title_string[] =3D PACKAGE_S= TRING
#ifdef CONFIGURE_GIT_REVISION
&= quot; [git:" CONFIGURE_GIT_REVISION CONFIGURE_GIT_FLAGS "]"<= /span>
#endif
@@ -114,7 +113,7 @@
#ifdef CONFIGURE_GIT_REVISION

" built on "= __DATE__
#endif
-;
+ ;<= /span>

#ifndef ENABLE_SMALL

@@ -698,7 +697,7 @@
" = cache until token is removed.\n"
= "--pkcs11-id-management : Acquire identity from manageme= nt interface.\n"
"--pkcs11-id serialized-id = 'id' : Identity to use, get using standalone --show-pkcs11-ids\n&q= uot;
-#endif = /* ENABLE_PKCS11 */
+#endif /* ENABLE_PKCS11 */
"\n"
"SSL Library information:\n"
= "--show-ciphers : Show cipher algorithms to use with --cipher option= .\n"
@@ -787,13 +786,13 @@
"= --show-pkcs11-ids provider [cert_private] : Show PKCS#11 available ids.\n&q= uot;
#endif
" = --verb option can be added *BEFORE* this.\n"<= /span>
-#endif = /* ENABLE_PKCS11 */
+#endif /* ENABLE_PKCS11 */
"\n"
"General Standalone Options:\n"
#ifdef ENABLE_DEBUG

"--show-gateway [address]:= Show info about gateway [to v4/v6 address].\n"
#endi= f
-;
+ ;

#endif /* !ENABLE_SMALL */


@@ -894,7 += 893,7 @@
#endif
#ifdef ENABLE_PKCS11
o->pkcs11_pin_cache_period =3D -1;
-#endif /* ENABLE_PKCS11 *= /
+#endif /* ENABLE_P= KCS11 */

/* P2MP server context feat= ures */
o->auth_token_generate =3D false;@@ -909,7 +908,7 @@
/* Error out if we can&= #39;t find a valid temporary directory, which should
= * be very unlikely. */
msg(M_USAGE, "Coul= d not find a suitable temporary directory."
- " (GetTempPath() failed). Cons= ider using --tmp-dir");
+ " (GetTempPath() failed). Consider usin= g --tmp-dir");
}
#else /* ifdef= _WIN32 */
/* Non-windows platforms use $TMPDIR, and i= f not set, default to '/tmp' */
@@ -950,10 +949,10 = @@

struct pull_filter
{=
-#define PUF_TYPE_UNDE= F 0 /**< undefined filter type */
-#define PUF_TYPE_ACCEPT 1 /**< filter type to acce= pt a matching option */
-#define PUF_TYPE_IGNORE 2 /**< filter type to ignore a matching opt= ion */
-#define PUF_TYP= E_REJECT 3 /**< filter type to reject and trigger SIGUSR1 */+#define PUF_TYPE_UNDEF 0 /*= *< undefined filter type */
+#define PUF_TYPE_ACCEPT 1 /**< filter type to accept a matchi= ng option */
+#define= PUF_TYPE_IGNORE 2 /**< filter type to ignore a matching option */
+#define PUF_TYPE_REJECT 3= /**< filter type to reject and trigger SIGUSR1 */
= int type;
int size;
char *pattern= ;
@@ -990,23 +989,19 @@
}
=
#define SHOW_PARM(name, value, format) msg(D_SHOW_PARMS,= " " #name " =3D " format, (value))
-#define SHOW_STR(var) SHOW_PARM(va= r, (o->var ? o->var : "[UNDEF]"), "'%s'")=
-#define SHOW_STR_INLI= NE(var) SHOW_PARM(var, \
- o->var ## _inline ? &quo= t;[INLINE]" : \
- = (o->var ? o->var : "[UN= DEF]"), \
- = "'%s'")
-#define SHOW_INT(var) SHOW_PAR= M(var, o->var, "%d")

-#define SHOW_UINT(var) SHOW_PARM(var, o->var, "%u&= quot;)
-#define SHOW_IN= T64(var) SHOW_PARM(var, o->var, "%" PRIi64)
-#define SHOW_UNSIGNED(var) SHOW_PAR= M(var, o->var, "0x%08x")

-#define SHOW_BOOL(var) SHOW_PARM(var, (o->var ? &qu= ot;ENABLED" : "DISABLED"), "%s");
+#define SHOW_STR(var) = SHOW_PARM(var, (o->var ? o->var : "[UNDEF]"), "'= ;%s'")
+#def= ine SHOW_STR_INLINE(var) \
+ SHOW_PARM(var, o->var##_inline ? "[INLINE]" : (o-&g= t;var ? o->var : "[UNDEF]"), "'%s'")<= br>+#define SHOW_INT(var) = SHOW_PARM(var, o->var, "%d")
+#define SHOW_UINT(var) SHOW_PARM(var, o->var, = "%u")
+#def= ine SHOW_INT64(var) SHOW_PARM(var, o->var, "%" PRIi64)
+#define SHOW_UNSIGNED(va= r) SHOW_PARM(var, o->var, "0x%08x")
+#define SHOW_BOOL(var) SHOW_PARM(var, (o-&= gt;var ? "ENABLED" : "DISABLED"), "%s");

#endif /* ifndef ENABLE_SMALL */
<= span>

static void
-setenv_connection_entry(struct env_set *es,
- const struct co= nnection_entry *e,
- = const int i)
+setenv_connection_entry(struct env_set *es, const struct conn= ection_entry *e, const int i)
{
seten= v_str_i(es, "remote", e->remote, i);
sete= nv_str_i(es, "remote_port", e->remote_port, i);
@@ -1024,9 +1019,7 @@

}

static void

-setenv_= local_entry(struct env_set *es,
- const struct local_entry *e,
- const int i)<= br>+setenv_local_entry(struct e= nv_set *es, const struct local_entry *e, const int i)
{
setenv_str_i(es, "proto", proto2ascii(e->pr= oto, AF_UNSPEC, false), i);
setenv_str_i(es, "loc= al", e->local, i);
@@ -1048,7 +1041,7 @@
= int i;
for (i =3D 0; i < o->c= onnection_list->len; ++i)
{
- setenv_connection_entry(es, o= ->connection_list->array[i], i+1);
+ setenv_connection_entry(es, o->connecti= on_list->array[i], i + 1);
}
= }
else
@@ -1060,7 +1053,7 @@=
{
for (int i =3D 0; i < o->ce= .local_list->len; i++)
{
- setenv_local_entry(es, o->ce= .local_list->array[i], i+1);
+ setenv_local_entry(es, o->ce.local_list->arra= y[i], i + 1);
}
}
<= span> }

@@ -1149,18 +1142,18 @@
}
static bool
-ipv6_addr_safe_hexplusbits( const char *ipv6_prefix_spec )=
+ipv6_addr_safe_hexp= lusbits(const char *ipv6_prefix_spec)
{
= struct in6_addr t_addr;
unsigned int t_bits;=

- return= get_ipv6_addr( ipv6_prefix_spec, &t_addr, &t_bits, M_WARN );
+ return get_ipv6_addr(= ipv6_prefix_spec, &t_addr, &t_bits, M_WARN);
}

static char *
string_subst= itute(const char *src, int from, int to, struct gc_arena *gc)
{

- char *ret = =3D (char *) gc_malloc(strlen(src) + 1, true, gc);
+ char *ret =3D (char *)gc_malloc(strlen(s= rc) + 1, true, gc);
char *dest =3D ret;
char c;


@@ -1172,8 +1165,7 @@
c =3D to;
}
*dest++ =3D c;

- }
- while (= c);
+ } while (c);=
return ret;
}

@@ -1201,9 +1193,7 @@
while (*cp &&= ; i < nbytes)
{
/* valid s= egments consist of exactly two hex digits, then ':' or EOS */
- if (!isxdigit(cp[0]= )
- || !isxd= igit(cp[1])
- = || (cp[2] !=3D ':' && cp[2] !=3D '\0')
= + if (!isxdigit(cp[0]) |= | !isxdigit(cp[1]) || (cp[2] !=3D ':' && cp[2] !=3D '\0= ')
|| sscanf(cp, "%x", &byte= ) !=3D 1)
{
msg(msgle= vel, "format error in hash fingerprint: %s", str);
@@ -1221,7 +1211,8 @@

}
if (i &= lt; nbytes)
{
- msg(msglevel, "hash fingerprint is wrong length -= expected %d bytes, got %d: %s", nbytes, i, str);
+ msg(msglevel, "hash fingerp= rint is wrong length - expected %d bytes, got %d: %s", nbytes, i,
+ str);=
}
else if (term !=3D '\0')
{
@@ -1241,8 +1232,7 @@
= * @param gc The returned list items will be allocated in this gc=
*/
static struct verify_hash_list *
-parse_hash_fingerprint_mu= ltiline(const char *str, int nbytes, int msglevel,
- struct gc_are= na *gc)
+parse_hash_f= ingerprint_multiline(const char *str, int nbytes, int msglevel, struct gc_a= rena *gc)
{
struct gc_arena gc_temp = =3D gc_new();
char *lines =3D string_alloc(str, &g= c_temp);
@@ -1263,8 +1253,7 @@
= continue;
}

- struct verify_hash_list *hash =3D= parse_hash_fingerprint(line, nbytes,
- = msglevel, gc);
+ = struct verify_hash_list *hash =3D parse_hash_fingerprint(line, nbyte= s, msglevel, gc);

if (!hash)
{
@@ -1289,7 +1278,7 @@
int i;

for (i =3D 0; i < len; ++i) {
- = msg(D_SHOW_PARMS, " %s[%d] =3D %s", name, i, array[i] );=
+ msg(D_SHOW_PARMS, = " %s[%d] =3D %s", name, i, array[i]);
}
}

@@ -1300,10 +1289,7 @@
int i;
for (i =3D 0; i < len; ++= i)
{
- msg(D_SHOW_PARMS, " %s[%d] =3D %s",
- name,
- i,
- print_in_addr_t(array[i], 0, &gc)= );
+ msg(D_SHO= W_PARMS, " %s[%d] =3D %s", name, i, print_in_addr_t(array[i], 0,= &gc));
}
gc_free(&gc);
}
@@ -1349,14 +1335,13 @@
= }
}
static void
-dhcp_option_address_parse(const char *name,= const char *parm, in_addr_t *array, int *len, int msglevel)
+dhcp_option_address_parse(const ch= ar *name, const char *parm, in_addr_t *array, int *len,

+ int msglevel)=
{
if (*len >=3D N_DHCP_ADDR)
{
- = msg(msglevel, "--dhcp-option %s: maximum of %d %s servers can be = specified",
- = name,
- = N_DHCP_ADDR,
- = name);
+ = msg(msglevel, "--dhcp-option %s: maximum of %d %s servers can be spec= ified", name,
+ = N_DHCP_ADDR, name);
}
= else
{
@@ -1401,12 +1386,15 @@<= br>
msg(D_SHOW_PARMS, " server_network = =3D %s", print_in_addr_t(o->server_network, 0, &gc)); msg(D_SHOW_PARMS, " server_netmask =3D %s", print_in= _addr_t(o->server_netmask, 0, &gc));
- msg(D_SHOW_PARMS, " server_network_ipv6 =3D= %s", print_in6_addr(o->server_network_ipv6, 0, &gc) );<= br>+ msg(D_SHOW_PARMS, "= ; server_network_ipv6 =3D %s", print_in6_addr(o->server_network_ip= v6, 0, &gc));
SHOW_INT(server_netbits_ipv6);
msg(D_SHOW_PARMS, " server_bridge_ip =3D %s", pr= int_in_addr_t(o->server_bridge_ip, 0, &gc));
- msg(D_SHOW_PARMS, " server_bridge= _netmask =3D %s", print_in_addr_t(o->server_bridge_netmask, 0, &= ;gc));
- msg(D_SHOW_= PARMS, " server_bridge_pool_start =3D %s", print_in_addr_t(o->= ;server_bridge_pool_start, 0, &gc));
- msg(D_SHOW_PARMS, " server_bridge_pool_end =3D= %s", print_in_addr_t(o->server_bridge_pool_end, 0, &gc));
+ msg(D_SHOW_PARMS, &q= uot; server_bridge_netmask =3D %s",
+ print_in_addr_t(o->server_bridge_netmask, = 0, &gc));
+ ms= g(D_SHOW_PARMS, " server_bridge_pool_start =3D %s",
+ print_in_addr_t(o->se= rver_bridge_pool_start, 0, &gc));

+ msg(D_SHOW_PARMS, " server_bridge_pool_end =3D = %s",
+ pr= int_in_addr_t(o->server_bridge_pool_end, 0, &gc));
= if (o->push_list.head)
{
= const struct push_entry *e =3D o->push_list.head;
@@ = -1420,13 +1408,16 @@
}
}
SHOW_BOOL(ifconfig_pool_defined);
- msg(D_SHOW_PARMS, " ifconfig_pool_st= art =3D %s", print_in_addr_t(o->ifconfig_pool_start, 0, &gc));<= /span>
+ msg(D_SHOW_PARMS= , " ifconfig_pool_start =3D %s",
+ print_in_addr_t(o->ifconfig_pool_start, = 0, &gc));
msg(D_SHOW_PARMS, " ifconfig_pool_= end =3D %s", print_in_addr_t(o->ifconfig_pool_end, 0, &gc));
- msg(D_SHOW_PARMS, &q= uot; ifconfig_pool_netmask =3D %s", print_in_addr_t(o->ifconfig_po= ol_netmask, 0, &gc));
+ msg(D_SHOW_PARMS, " ifconfig_pool_netmask =3D %s",
+ print_in_addr_t= (o->ifconfig_pool_netmask, 0, &gc));
SHOW_STR(i= fconfig_pool_persist_filename);
SHOW_INT(ifconfig_pool= _persist_refresh_freq);
SHOW_BOOL(ifconfig_ipv6_pool_d= efined);
- msg(D_SHO= W_PARMS, " ifconfig_ipv6_pool_base =3D %s", print_in6_addr(o->= ;ifconfig_ipv6_pool_base, 0, &gc));
+ msg(D_SHOW_PARMS, " ifconfig_ipv6_pool_base = =3D %s",
+ = print_in6_addr(o->ifconfig_ipv6_pool_base, 0, &gc));
SHOW_INT(ifconfig_ipv6_pool_netbits);

SHOW_INT= (n_bcast_buf);
SHOW_INT(tcp_queue_limit);
@@ -1440,11 +1431,15 @@

SHOW_BOOL(ccd_exclusive);<= /span>
SHOW_STR(tmp_dir);
SHOW_BOOL(push= _ifconfig_defined);
- = msg(D_SHOW_PARMS, " push_ifconfig_local =3D %s", print_in_addr= _t(o->push_ifconfig_local, 0, &gc));
- msg(D_SHOW_PARMS, " push_ifconfig_remote_ne= tmask =3D %s", print_in_addr_t(o->push_ifconfig_remote_netmask, 0, = &gc));
+ msg(D= _SHOW_PARMS, " push_ifconfig_local =3D %s",
+ print_in_addr_t(o->push_ifcon= fig_local, 0, &gc));
+ msg(D_SHOW_PARMS, " push_ifconfig_remote_netmask =3D %s"= ;,
+ print_in_= addr_t(o->push_ifconfig_remote_netmask, 0, &gc));
= SHOW_BOOL(push_ifconfig_ipv6_defined);
- msg(D_SHOW_PARMS, " push_ifconfig_ipv6_local = =3D %s/%d", print_in6_addr(o->push_ifconfig_ipv6_local, 0, &gc)= , o->push_ifconfig_ipv6_netbits );
- msg(D_SHOW_PARMS, " push_ifconfig_ipv6_remote =3D= %s", print_in6_addr(o->push_ifconfig_ipv6_remote, 0, &gc));
+ msg(D_SHOW_PARMS, = " push_ifconfig_ipv6_local =3D %s/%d",
+ print_in6_addr(o->push_ifconfig_ip= v6_local, 0, &gc), o->push_ifconfig_ipv6_netbits);
+ msg(D_SHOW_PARMS, " push_if= config_ipv6_remote =3D %s",
+ print_in6_addr(o->push_ifconfig_ipv6_remote, 0, &am= p;gc));
SHOW_BOOL(enable_c2c);
SH= OW_BOOL(duplicate_cn);
SHOW_INT(cf_max);
@@ -1477,16 +1472,13 @@

#endif /* ! ENABLE_SMALL */

static void
-option_iroute(struct options *o,
- const char *network_str,
- const char = *netmask_str,
- = int msglevel)
+= option_iroute(struct options *o, const char *network_str, const char *netma= sk_str, int msglevel)
{
struct iroute= *ir;

ALLOC_OBJ_GC(ir, struct iroute= , &o->gc);
ir->network =3D getaddr(GETADDR_H= OST_ORDER, network_str, 0, NULL, NULL);
- ir->netbits =3D 32; /* host route if no = netmask given */
+ = ir->netbits =3D 32; /* host route if no netmask given */

if (netmask_str)
{
= @@ -1495,8 +1487,7 @@

if (= ir->netbits < 0)
{
- msg(msglevel, "in --iroute %s = %s : Bad network/subnet specification",
- network_str,
+ msg(msglevel, "in --irou= te %s %s : Bad network/subnet specification", network_str,
<= span> netmask_str);

return;
}
@@ -1507,18 +1498,15 @@
= }

static void
-option_iroute_ipv6(struct options *o,
- const = char *prefix_str,
- = int msglevel)
+option_iroute_ipv6(struct options *o, const char *prefix_str, int = msglevel)
{
struct iroute_ipv6 *ir;

ALLOC_OBJ_GC(ir, struct iroute_ipv6, = &o->gc);

- if (!get_ipv6_addr(prefix_str, &ir->network, &ir= ->netbits, msglevel ))
+ if (!get_ipv6_addr(prefix_str, &ir->network, &ir->n= etbits, msglevel))
{
- msg(msglevel, "in --iroute-ipv6 %s: Bad IP= v6 prefix specification",
- prefix_str);
+ msg(msglevel, "in --iroute-ipv6 %s: Bad IPv6 pre= fix specification", prefix_str);
return;
}

@@ -1541,17 +1529,16 @= @
SHOW_BOOL(nocache);
SHOW_STR(ht= tp_version);
SHOW_STR(user_agent);
- for (i =3D 0; i < MAX_CUSTOM_HTTP= _HEADER && o->custom_headers[i].name; i++)
+ for (i =3D 0; i < MAX_CUSTOM_HTTP_= HEADER && o->custom_headers[i].name; i++)
{=
if (o->custom_headers[i].content)
{

- = msg(D_SHOW_PARMS, " custom_header[%d] =3D %s: %s", i,
- o->custo= m_headers[i].name, o->custom_headers[i].content);
+ msg(D_SHOW_PARMS, " cus= tom_header[%d] =3D %s: %s", i, o->custom_headers[i].name,+ o->custom_= headers[i].content);
}
el= se
{
- msg(D_SHOW_PARMS, " custom_header[%d] =3D %s"= ;, i,
- = o->custom_headers[i].name);
+ msg(D_SHOW_PARMS, " custom_header[%d] =3D %s&q= uot;, i, o->custom_headers[i].name);
} }
msg(D_SHOW_PARMS, "END http_proxy&= quot;);
@@ -1608,7 +1595,8 @@
for (int= i =3D 0; i < o->local_list->len; i++)
{
msg(D_SHOW_PARMS, " [%s]:%s-%s", o->lo= cal_list->array[i]->local,
- o->local_list->array[i]->port, proto2ascii(= o->local_list->array[i]->proto, o->af, false));
+ o->local_list->ar= ray[i]->port,

+ = proto2ascii(o->local_list->array[i]->proto, o->af, fal= se));
}
SHOW_STR(remote);<= br> SHOW_STR(remote_port);
@@ -1645,8 +1633,7 @@<= /span>
SHOW_INT(explicit_exit_notification);
=
SHOW_STR_INLINE(tls_auth_file);
- SHOW_PARM(key_direction, keydirection2= ascii(o->key_direction, false, true),
- "%s");
+ SHOW_PARM(key_direction, keydirection2asc= ii(o->key_direction, false, true), "%s");
= SHOW_STR_INLINE(tls_crypt_file);
SHOW_STR_INLINE(tls_= crypt_v2_file);
}
@@ -1901,7 +1888,7 @@
SHOW_INT(ns_cert_type);
{ int i;
= - for (i =3D 0; i<MAX_PARMS; i++)
+ for (i =3D 0; i < MAX_PARMS; i++)=
{
SHOW_INT(remote_cert_ku[i= ]);
}
@@ -1913,12 +1900,11 @@
SHOW_INT(verify_hash_depth);
= struct gc_arena gc =3D gc_new();
struct verify_has= h_list *hl =3D o->verify_hash;
- int digest_len =3D (o->verify_hash_algo =3D=3D MD_SH= A1) ? SHA_DIGEST_LENGTH :
- SHA256_DIGEST_LENGTH;
+ int digest_len =3D
+ (o->verify_hash_algo = =3D=3D MD_SHA1) ? SHA_DIGEST_LENGTH : SHA256_DIGEST_LENGTH;
while (hl)

{
- char *s =3D format_hex_ex(hl->hash= , digest_len, 0,
- = 1, ":", &gc);
+ char *s =3D format_hex_e= x(hl->hash, digest_len, 0, 1, ":", &gc);
= SHOW_PARM(verify_hash, s, "%s");
= hl =3D hl->next;
}
@@ = -1944,36 +1930,38 @@
#ifdef ENABLE_PKCS11
= {
int i;
- for (i =3D 0; i<MAX_PARMS && o->pkcs= 11_providers[i] !=3D NULL; i++)
+ for (i =3D 0; i < MAX_PARMS && o->pkcs11_= providers[i] !=3D NULL; i++)
{
= SHOW_PARM(pkcs11_providers, o->pkcs11_providers[i], "%s&q= uot;);
}
}
= {
int i;
- for (i =3D 0; i<MAX_PARMS; i++)
+ for (i =3D 0; i < MAX_PARM= S; i++)
{
- SHOW_PARM(pkcs11_protected_authentication, o->p= kcs11_protected_authentication[i] ? "ENABLED" : "DISABLED&qu= ot;, "%s");
+ SHOW_PARM(pkcs11_protected_authentication,
+ o->pkcs11_pro= tected_authentication[i] ? "ENABLED" : "DISABLED", &quo= t;%s");
}
}
{

int i;
- for (i =3D 0; i<MAX_PARMS; i++)
<= span style=3D"color: hsl(120, 100%, 40%);">+ for (i =3D 0; i < MA= X_PARMS; i++)

{
SHOW_= PARM(pkcs11_private_mode, o->pkcs11_private_mode[i], "%08x");<= /span>
}
}
{
int i;
- for (i =3D 0; i<MAX_PARMS; i++)
+ for (i =3D 0; i < MAX_PARMS; i++)=
{
- SHOW_PARM(pkcs11_cert_private, o->pkcs11_cert_private[= i] ? "ENABLED" : "DISABLED", "%s");+ SHOW_PARM(pkcs11_= cert_private, o->pkcs11_cert_private[i] ? "ENABLED" : "DI= SABLED",
+ = "%s");
}
}

SHOW_INT(pkcs11_pin_cache_period);
<= span> SHOW_STR(pkcs11_id);

SHOW_BOOL(pkcs11_id_man= agement);
-#endif = /* ENABLE_PKCS11 */
+#endif /* ENABLE_PKCS11 */

= show_p2mp_parms(o);

@@ -1994,9 +1982,7= @@
#ifdef ENABLE_MANAGEMENT

<= span> static struct http_proxy_options *

-parse_http_proxy_override(const char *server,
= - const = char *port,
- = const char *flags,
+parse_http_proxy_override(const char *server, const char *po= rt, const char *flags,
struct gc= _arena *gc)
{
if (server && p= ort)
@@ -2051,7 +2037,8 @@
} else
{
- msg(M_WARN, "Note: option http-proxy-overrid= e ignored because no TCP-based connection profiles are defined");
+ msg(M_WARN,
+ "Note: = option http-proxy-override ignored because no TCP-based connection profiles= are defined");
}
}

@@ -2068,8 +2055,7 @@
}

static struct local_entry *
-alloc_local_entry(struct connection_entry *ce,= const int msglevel,
- = struct gc_arena *gc)
+alloc_local_entry(struct connection_entry *ce, const int = msglevel, struct gc_arena *gc)
{
stru= ct local_list *l =3D alloc_local_list_if_undef(ce, gc);
= struct local_entry *e;
@@ -2082,7 +2068,9 @@
struct local_entry **new_array =3D gc_realloc(l->array, new= _cap * elem_size, gc);

if (!new_array)
<= span> {

- = msg(msglevel, "Unable to process more local options: out of memo= ry. Number of entries =3D %d", l->len);
+ msg(msglevel,
+ "Unable to process m= ore local options: out of memory. Number of entries =3D %d",+ l->len);
return NULL;
}<= br>
@@ -2116,10 +2104,13 @@
if = (l->len =3D=3D l->capacity)
{
= int capacity =3D l->capacity + CONNECTION_LIST_SIZE;
- struct connection_entry **= ce =3D gc_realloc(l->array, capacity*sizeof(struct connection_entry *), = &options->gc);

+ struct connection_entry **ce =3D
+ gc_realloc(l->array, capacity * sizeo= f(struct connection_entry *), &options->gc);
= if (ce =3D=3D NULL)
{
- msg(msglevel, "Unable to proces= s more connection options: out of memory. Number of entries =3D %d", l= ->len);
+ = msg(msglevel,
+ = "Unable to process more connection options: out of memory= . Number of entries =3D %d",
+ l->len);
retu= rn NULL;
}
l->array = =3D ce;
@@ -2149,10 +2140,13 @@
if (l-= >len =3D=3D l->capacity)
{
= int capacity =3D l->capacity + CONNECTION_LIST_SIZE;
- struct remote_entry **re =3D = gc_realloc(l->array, capacity*sizeof(struct remote_entry *), &option= s->gc);

+ s= truct remote_entry **re =3D
+ gc_realloc(l->array, capacity * sizeof(struct remote= _entry *), &options->gc);
if (re =3D=3D NUL= L)
{
- msg(msglevel, "Unable to process more remote optio= ns: out of memory. Number of entries =3D %d", l->len);
+ msg(msglevel,
=
+ "Unab= le to process more remote options: out of memory. Number of entries =3D %d&= quot;,
+ = l->len);
return NULL;
= }
l->array =3D re;
@@ -2= 216,8 +2210,7 @@
}

stat= ic void
-connection_ent= ry_preload_key(const char **key_file, bool *key_inline,
- struct gc_ar= ena *gc)
+connection_= entry_preload_key(const char **key_file, bool *key_inline, struct gc_arena = *gc)
{
if (key_file && *key_f= ile && !(*key_inline))
{
@@ -2= 227,7 +2220,7 @@
msg(M_FATAL, "Cannot pre= -load keyfile (%s)", *key_file);
}
=
- *key_f= ile =3D (const char *) in.data;
+ *key_file =3D (const char *)in.data;
= *key_inline =3D true;
}
}
@@ -2242,13 +2235,11 @@
}
= #endif

- if (options->verify_hash_no_ca
- || options->pkcs12_file
- || options->ca_file
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (options->verify_hash= _no_ca || options->pkcs12_file || options->ca_file

#= ifndef ENABLE_CRYPTO_MBEDTLS
|| options->ca_pat= h
#endif
- )
+ )<= /span>
{
return;
= }
@@ -2261,14 +2252,19 @@
msg(M_USAG= E, "%s", str);
}

-#define MUST_BE_UNDEF(parm, parm_na= me) \

- if (options-= >parm !=3D defaults.parm) { msg(M_USAGE, use_err, parm_name); }+#define MUST_BE_UNDEF(parm, = parm_name) \
+ = if (options->parm !=3D defaults.parm) \
+ { \=
+ msg(M_USAGE, use_e= rr, parm_name); \
+ = }
#define MUST_BE_FALSE(condition, parm_name) \- if (condition) { msg(M_USA= GE, use_err, parm_name); }
+ if (condition) \
+ { = \
+ msg(M_U= SAGE, use_err, parm_name); \
+ }

static void
<= span style=3D"color: hsl(0, 100%, 40%);">-options_postprocess_verify_ce(con= st struct options *options,

- const struct connection_entry *ce)
+options_postprocess_veri= fy_ce(const struct options *options, const struct connection_entry *ce)
{
struct options defaults;
int dev =3D DEV_TYPE_UNDEF;

@@ -2296,9 +2292,8 @@
*/
if (ce->proto =3D=3D PROTO_= TCP)
{
- msg(M_USAGE,
- "--proto tcp is ambiguous in this context. Please spe= cify "
- = "--proto tcp-server or --proto tcp-client");
+ msg(M_USAGE, "--proto tcp= is ambiguous in this context. Please specify "
+ "--proto tcp-se= rver or --proto tcp-client");
}
=
/*
@@ -2338,16 +2333,13 @@
= if (string_defined_equal(ce->remote, options->ifconfig_loc= al)
|| string_defined_equal(ce->remote, options= ->ifconfig_remote_netmask))
{
- msg(M_USAGE,
- "--local and --remote addr= esses must be distinct from --ifconfig "
- "addresses");
+ msg(M_USAGE, "--local = and --remote addresses must be distinct from --ifconfig "

+ "addre= sses");

}

- if (string_defined_equal(options->if= config_local,
- = options->ifconfig_remote_netmask))
+ if (string_defined_equal(options= ->ifconfig_local, options->ifconfig_remote_netmask))
= {
- msg(M_U= SAGE,
- &quo= t;local and remote/netmask --ifconfig addresses must be different");
+ msg(M_USAGE, = "local and remote/netmask --ifconfig addresses must be different"= );
}

if (ce->= ;bind_defined && !ce->bind_local)
@@ -2357,8 +23= 49,7 @@

if (ce->local_port_define= d && !ce->bind_local)
{
- msg(M_USAGE,
- "--lport and --nobind don= 't make sense when used together");
+ msg(M_USAGE, "--lport and --nobind do= n't make sense when used together");
}=

if (!ce->remote && !ce->bind= _local)
@@ -2370,8 +2361,7 @@
{=
struct local_entry *le =3D ce->local_list->array[i= ];

- = if (proto_is_net(le->proto)
- && string_defined_equal(le->local, c= e->remote)
+ = if (proto_is_net(le->proto) && string_defined_equal(le->loc= al, ce->remote)
&& string_defined_e= qual(le->port, ce->remote_port))
{ msg(M_USAGE, "--remote and one of the --local addr= esses are the same");
@@ -2397,7 +2387,8 @@
= && (options->management_flags
= || options->management_log_history_cache !=3D defaults.managem= ent_log_history_cache))
{
- msg(M_USAGE, "--management is not spe= cified, however one or more options which modify the behavior of --manageme= nt were specified");
+ msg(M_USAGE,
+ "--management is not specified, however one or more= options which modify the behavior of --management were specified");
}

if ((options-&= gt;management_client_user || options->management_client_group)@@ -2406,24 +2397,21 @@
msg(M_USAGE, "= --management-client-(user|group) can only be used on unix domain sockets&qu= ot;);
}

- if (options->management_addr
- && !(options->man= agement_flags & MF_UNIX_SOCK)

+ if (options->management_addr && !(options->= management_flags & MF_UNIX_SOCK)
&& (!= options->management_user_pass))
{
= msg(M_WARN, "WARNING: Using --management on a TCP port WITHOUT= "
- &q= uot;passwords is STRONGLY discouraged and considered insecure");
+ "= ;passwords is STRONGLY discouraged and considered insecure"); }

#endif /* ifdef ENABLE_MA= NAGEMENT */

#if !defined(HAVE_XKEY_PROVI= DER)
- if ((tls_vers= ion_max() >=3D TLS_VER_1_3)
- && (options->management_flags & MF_EXTERNAL= _KEY)
- &&am= p; !(options->management_flags & (MF_EXTERNAL_KEY_NOPADDING))=
- )
+ if ((tls_version_max() >=3D TLS= _VER_1_3) && (options->management_flags & MF_EXTERNAL_KEY)
+ && !(= options->management_flags & (MF_EXTERNAL_KEY_NOPADDING)))
= {
msg(M_FATAL, "management-externa= l-key with TLS 1.3 or later requires "
- "nopadding argument/support");<= /span>
+ = "nopadding argument/support");
}
= #endif
/*
@@ -2431,7 +2419,8 @@=
*/

#ifdef _WIN32<= /span>
- if (dev =3D=3D DEV= _TYPE_TUN && !(pull || (options->ifconfig_local && optio= ns->ifconfig_remote_netmask)))
+ if (dev =3D=3D DEV_TYPE_TUN
+ && !(pull || (options->ifconfi= g_local && options->ifconfig_remote_netmask)))
= {
msg(M_USAGE, "On Windows, --ifconfig is= required when --dev tun is used");
}
<= span>@@ -2447,14 +2436,13 @@

const char *prefix = =3D "Some --dhcp-option or --dns options require DHCP server";
if (options->windows_driver !=3D WINDOWS_DRIVER_T= AP_WINDOWS6)
{
- msg(M_USAGE, "%s, which is not supported= by the selected %s driver",
- prefix, print_tun_backend_driver(options->wi= ndows_driver));
+ = msg(M_USAGE, "%s, which is not supported by the selected %s dr= iver", prefix,
+= print_tun_backend_driver(options->windows_driver));
}
else if (options->tuntap= _options.ip_win32_type !=3D IPW32_SET_DHCP_MASQ
= && options->tuntap_options.ip_win32_type !=3D IPW32_SET_A= DAPTIVE)
{
- msg(M_USAGE, "%s, which requires --ip-win32 = dynamic or adaptive",
- prefix);
+ msg(M_USAGE, "%s, which requires --ip-win32 dyna= mic or adaptive", prefix);
}
= }
#endif /* ifdef _WIN32 */
@@ -2477,= 21 +2465,18 @@

if ((ce->http_prox= y_options) && ce->proto !=3D PROTO_TCP_CLIENT)
= {
- msg(M_US= AGE,
- "= ;--http-proxy MUST be used in TCP Client mode (i.e. --proto "- "tcp-client)&= quot;);
+ msg(= M_USAGE, "--http-proxy MUST be used in TCP Client mode (i.e. --proto &= quot;
+ = "tcp-client)");
}

if ((ce->http_proxy_options) && !ce->http= _proxy_options->server)
{
- msg(M_USAGE,
- "--http-proxy not specified but= other http proxy options present");
+ msg(M_USAGE, "--http-proxy not specified= but other http proxy options present");
}=

if (ce->http_proxy_options && c= e->socks_proxy_server)
{
- msg(M_USAGE,
- "--http-proxy can not be used to= gether with --socks-proxy");
+ msg(M_USAGE, "--http-proxy can not be used toget= her with --socks-proxy");
}

if (ce->socks_proxy_server && ce->proto =3D= =3D PROTO_TCP_SERVER)
@@ -2511,7 +2496,8 @@
{

const char use_err[] =3D "--%s cannot= be used with --mode server.";

-#define USAGE_VALID_SERVER_PROTOS "--m= ode server currently only supports " \
+#define USAGE_VALID_SERVER_PROTOS \
+ "--mode server = currently only supports " \
"--proto values = of udp, tcp-server, tcp4-server, or tcp6-server"
#ifd= ef TARGET_ANDROID
msg(M_FATAL, "--mode server= not supported on Android");
@@ -2534,7 +2520,7 @@
&& (ce->proto !=3D PROTO_TCP_SERVER))<= /span>
{
msg(M_USAGE, "= --port-share only works in TCP server mode "
- "(--proto values of tcp-se= rver, tcp4-server, or tcp6-server)");
+ "(--proto values of tc= p-server, tcp4-server, or tcp6-server)");
}
#endif
if (!options->tls_server= )
@@ -2548,8 +2534,7 @@
/* <con= nection> blocks force to have a remote embedded, so we check
<= span> * for the --remote and bail out if it is present

<= span> */

- = if (options->connection_list->len >1
- || options->connection_list->= array[0]->remote)
= + if (options->connection_list->len > 1 || options->conn= ection_list->array[0]->remote)
{
<= span> msg(M_USAGE, "<connection> cannot be used with= --mode server");

}
@@ -2557,= 9 +2542,8 @@
MUST_BE_UNDEF(shaper, "shaper&qu= ot;);
if (options->ipchange)
= {
- m= sg(M_USAGE,
- = "--ipchange cannot be used with --mode server (use "=
- "--clie= nt-connect instead)");
+ msg(M_USAGE, "--ipchange cannot be used with --mod= e server (use "
= + "--client-connect instead)"); }
if (!(proto_is_dgram(ce->prot= o) || ce->proto =3D=3D PROTO_TCP_SERVER))
{
@@ -2567,20 +2551,23 @@
}
<= span> if (!proto_is_udp(ce->proto) && (options->cf_ma= x || options->cf_per))

{
- msg(M_USAGE, "--connect-fr= eq only works with --mode server --proto udp. Try --max-clients instead.&q= uot;);
+ m= sg(M_USAGE,
+ = "--connect-freq only works with --mode server --proto udp. Tr= y --max-clients instead.");
}
- if (!(dev =3D=3D DEV_TYPE_TAP= || (dev =3D=3D DEV_TYPE_TUN && options->topology =3D=3D TOP_SUB= NET)) && options->ifconfig_pool_netmask)

+ if (!(dev =3D=3D DEV_TYPE_TAP || = (dev =3D=3D DEV_TYPE_TUN && options->topology =3D=3D TOP_SUBNET)= )
+ &&= amp; options->ifconfig_pool_netmask)
{- msg(M_USAGE, "= ;The third parameter to --ifconfig-pool (netmask) is only valid in --dev ta= p mode");
+ = msg(M_USAGE,
+= "The third parameter to --ifconfig-pool (netmask) is o= nly valid in --dev tap mode");
}
if (options->routes && (options->routes->flag= s & RG_ENABLE))

{
- msg(M_USAGE, "--redirect-gateway = cannot be used with --mode server (however --push \"redirect-gateway\&= quot; is fine)");
+ "--redirect-gateway cannot be used with --mode= server (however --push \"redirect-gateway\" is fine)");
}
MUST_BE_UNDEF(route_delay_= defined, "route-delay");
MUST_BE_UNDEF(u= p_delay, "up-delay");
- if (!options->ifconfig_pool_defined
- && !options->ifco= nfig_ipv6_pool_defined
- msg(M_USAGE, "--auth-user-pass cannot be used w= ith --mode server (it should be used on the client side only)");
+ msg(M_USAGE,<= /span>
+ &quo= t;--auth-user-pass cannot be used with --mode server (it should be used on = the client side only)");
}
= if (options->ccd_exclusive && !options->client_config_= dir)
{
@@ -2602,24 +2590,24 @@
if (options->auth_token_generate && !optio= ns->renegotiate_seconds)
{
= msg(M_USAGE, "--auth-gen-token needs a non-infinite "
- "--= renegotiate_seconds setting");
+ "--renegotiate_seconds settin= g");
}
if (options-&= gt;auth_token_generate && options->auth_token_renewal
= && options->auth_token_renewal < 2 * optio= ns->handshake_window)
{
- msg(M_USAGE, "--auth-gen-t= oken renewal time needs to be at least "
+ msg(M_USAGE,
+ "--auth-gen-token renew= al time needs to be at least "
"= two times --hand-window (%d).",
opti= ons->handshake_window);
-
}
- if (!options->auth_user_pass_verify_script
= - && !PLUGIN_O= PTION_LIST(options)
+= if (!options->auth_user_pass_verify_script && !PLUGIN_OP= TION_LIST(options)
&& !MAN_CLIENT_AUTH= _ENABLED(options))
{
- const char *use_err =3D "--%s must= be used with --management-client-auth, an --auth-user-pass-verify script, = or plugin";
+ = const char *use_err =3D
+ "--%s must be used with --management-clie= nt-auth, an --auth-user-pass-verify script, or plugin";

MUST_BE_FALSE(options->ssl_flags=
- &a= mp; (SSLF_CLIENT_CERT_NOT_REQUIRED|SSLF_CLIENT_CERT_OPTIONAL),
+ &a= mp; (SSLF_CLIENT_CERT_NOT_REQUIRED | SSLF_CLIENT_CERT_OPTIONAL),

= "verify-client-cert none|optional&quo= t;);
MUST_BE_FALSE(options->ssl_flags &= SSLF_USERNAME_AS_COMMON_NAME,
&= quot;username-as-common-name");
@@ -2661,7 +2649,7 @@<= /span>
MUST_BE_UNDEF(cf_max, "connect-freq");
MUST_BE_UNDEF(cf_per, "connect-freq");
MUST_BE_FALSE(options->ssl_flags
- & (SSLF_CLIE= NT_CERT_NOT_REQUIRED|SSLF_CLIENT_CERT_OPTIONAL),
+ & (SSLF_CLIENT_C= ERT_NOT_REQUIRED | SSLF_CLIENT_CERT_OPTIONAL),
= "verify-client-cert");
MUST_B= E_FALSE(options->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME, "use= rname-as-common-name");
MUST_BE_FALSE(options= ->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL, "auth-user-pass-opt= ional");
@@ -2669,15 +2657,16 @@
= if (options->server_flags & SF_TCP_NODELAY_HELPER)
{

msg(M_WARN, "WARNING: setti= ng tcp-nodelay on the client side will not "
- "affect the server. To hav= e TCP_NODELAY in both direction use "
- "tcp-nodelay in the server config= uration instead.");
+ "affect the server. To have TCP_NODELAY i= n both direction use "
+ "tcp-nodelay in the server configurati= on instead.");
}
MUS= T_BE_UNDEF(auth_user_pass_verify_script, "auth-user-pass-verify")= ;
MUST_BE_UNDEF(auth_token_generate, "auth-ge= n-token");
#if PORT_SHARE
if= (options->port_share_host || options->port_share_port)
{

- = msg(M_USAGE, "--port-share requires TCP server mode (--mode server= --proto tcp-server)");
+ msg(M_USAGE,
+ "--port-share requires TCP server mode (= --mode server --proto tcp-server)");
}=
#endif
MUST_BE_UNDEF(stale_routes_check= _interval, "stale-routes-check");
@@ -2690,8 +267= 9,7 @@
/*
* SSL/TLS mode sanity = checks.
*/
- if (options->tls_server + options->tls_client- + (options->shared_= secret_file !=3D NULL) > 1)
+ if (options->tls_server + options->tls_client + (optio= ns->shared_secret_file !=3D NULL) > 1)
{<= br> msg(M_USAGE, "specify only one of --tls-server, --tl= s-client, or --secret");
}
@@ -27= 05,29 +2693,26 @@
}

msg(msglevel, "DEPRECATION: No tls-client or tls-server o= ption in "

- = "configuration detected. OpenVPN 2.8 will remove the "
- "function= ality to run a VPN without TLS. "
- "See the examples section in the manual p= age for "
- = "examples of a similar quick setup with peer-fingerprint. "<= /span>
- "Open= VPN 2.7 allows using this configuration when using "
- "--allow-deprecated-in= secure-static-crypto but you should move "
- "to a proper configuration using= TLS as soon as possible."
- );
+ "configuration detected. OpenVPN 2.8 will r= emove the "
+ = "functionality to run a VPN without TLS. "
+ &= quot;See the examples section in the manual page for "
+ "example= s of a similar quick setup with peer-fingerprint. "

+ "OpenVPN 2.= 7 allows using this configuration when using "
+ "--allow-depre= cated-insecure-static-crypto but you should move "
+ "to a proper= configuration using TLS as soon as possible.");
= }

- = if (options->ssl_flags & (SSLF_CLIENT_CERT_NOT_REQUIRED|SSLF_CLIEN= T_CERT_OPTIONAL))
+ = if (options->ssl_flags & (SSLF_CLIENT_CERT_NOT_REQUIRED | SSLF_CLI= ENT_CERT_OPTIONAL))
{
msg(M_W= ARN, "WARNING: POTENTIALLY DANGEROUS OPTION "
- "--verify-client-cert no= ne|optional "
- = "may accept clients which do not present a certificate")= ;
+ = "--verify-client-cert none|optional "
+ "may accept clients = which do not present a certificate");
}
const int tls_version_max =3D
- (options->ssl_flags >&g= t; SSLF_TLS_VERSION_MAX_SHIFT)

- & SSLF_TLS_VERSION_MAX_MASK;
+ (options->ssl_flags >> SSLF_= TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_MASK;
= const int tls_version_min =3D
- (options->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIF= T)
- & SSLF_= TLS_VERSION_MIN_MASK;
+ (options->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) &= SSLF_TLS_VERSION_MIN_MASK;

if (tls_= version_max > 0 && tls_version_max < tls_version_min)<= br> {
@@ -2744,20 +2729,24 @@
= }
else if (!options->pkcs11_providers[0] = && options->pkcs11_id_management)
{
- msg(M_WARN, &= quot;Option pkcs11-id-management is ignored as no pkcs11-providers are spec= ified");
+ = msg(M_WARN,
+ = "Option pkcs11-id-management is ignored as no pkcs11-pro= viders are specified");
}

if (options->pkcs11_providers[0])
{

if (options->pkcs11_id_managem= ent && options->pkcs11_id !=3D NULL)
= {
- ms= g(M_USAGE, "Parameter --pkcs11-id cannot be used when --pkcs11-id-mana= gement is also specified.");
+ msg(M_USAGE,
+ "Parameter --pkcs11-id cann= ot be used when --pkcs11-id-management is also specified."); }
if (!options->pkcs11_= id_management && options->pkcs11_id =3D=3D NULL)
{

- = msg(M_USAGE, "Parameter --pkcs11-id or --pkcs11-id-managemen= t should be specified.");
+ msg(M_USAGE,
+ "Parameter --pkcs11-id or --pk= cs11-id-management should be specified.");
= }
- const = char use_err[] =3D "Parameter --%s cannot be used when --pkcs11-provid= er is also specified.";
+ const char use_err[] =3D
+ "Parameter --%s cannot be us= ed when --pkcs11-provider is also specified.";
= MUST_BE_UNDEF(cert_file, "cert");
= MUST_BE_UNDEF(priv_key_file, "key");
= MUST_BE_UNDEF(pkcs12_file, "pkcs12");
@@ -27= 70,9 +2759,10 @@
else
#endif /* i= fdef ENABLE_PKCS11 */
#ifdef ENABLE_CRYPTOAPI
- if (options->cryptoapi_= cert)

+ if= (options->cryptoapi_cert)
{
- const char use_err[] =3D &qu= ot;Parameter --%s cannot be used when --cryptoapicert is also specified.&qu= ot;;
+ con= st char use_err[] =3D
+ "Parameter --%s cannot be used when --cryptoapicert = is also specified.";
MUST_BE_UNDEF(cert_f= ile, "cert");
MUST_BE_UNDEF(priv_key= _file, "key");
MUST_BE_UNDEF(pkcs12_= file, "pkcs12");
@@ -2781,7 +2771,7 @@
= }
else
#endif
- if (options->pk= cs12_file)
+ = if (options->pkcs12_file)
{
= #ifdef ENABLE_CRYPTO_MBEDTLS
msg(M_USAGE, &qu= ot;Parameter --pkcs12 cannot be used with the mbed TLS version of OpenVPN.&= quot;);
@@ -2792,7 +2782,7 @@
= MUST_BE_UNDEF(priv_key_file, "key");
= MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "ma= nagement-external-key");
MUST_BE_FALSE(op= tions->management_flags & MF_EXTERNAL_CERT, "management-externa= l-cert");
-#endif = /* ifdef ENABLE_CRYPTO_MBEDTLS */
+#endif /* ifdef ENABLE_CRYPTO_MBEDTLS */
}

else /* cert/key from none of pkcs11,= pkcs12, cryptoapi */
{
@@ -2808,2= 4 +2798,25 @@
}
= else if (!(options->management_flags & MF_EXTERNAL_KEY))
{
- msg(M_USAGE, "--management-external-cert = must be used with --management-external-key");
+ msg(M_USAGE,+ &quo= t;--management-external-cert must be used with --management-external-key&qu= ot;);
}
}
if (pull)
{-
= const int sum =3D
((options->ce= rt_file !=3D NULL) || (options->management_flags & MF_EXTERNAL_CERT)= )
- = + ((options->priv_key_file !=3D NULL) || (options->management_flags &= amp; MF_EXTERNAL_KEY));
+ + ((options->priv_key_file !=3D NULL)
= + || (opt= ions->management_flags & MF_EXTERNAL_KEY));
=
if (sum =3D=3D 0)
= {
if (!options->auth_user_pass_f= ile)
{
= msg(M_USAGE, "No client-side authentication method is "=
- = "specified. You must use either "
- "--cert/--= key, --pkcs12, or "
+ = "specified. You must use either "
+ "--c= ert/--key, --pkcs12, or "
+ "--auth-user-pass"= ;);
}
= }
else if (sum !=3D 2)
@@= -2837,11 +2828,13 @@
{
= if (!(options->management_flags & MF_EXTERNAL_CERT))
{
- notnull(options->cert_file, "certifica= te file (--cert) or PKCS#12 file (--pkcs12)");
+ notnull(options->c= ert_file,
+ = "certificate file (--cert) or PKCS#12 file (--pkcs12= )");
}
= if (!(options->management_flags & MF_EXTERNAL_KEY))
{

-= notnull(options->priv_key_file, "private key fi= le (--key) or PKCS#12 file (--pkcs12)");
+ notnull(options->priv_key_= file,
+ = "private key file (--key) or PKCS#12 file (--pkcs12)&quo= t;);
}
}
}
@@ -2852,7 +2845,8 @@
if (options->tls_client && ce->tls_crypt_v2_file
&& (ce->tls_auth_file || ce->tls_= crypt_file))
{
- msg(M_USAGE, "--tls-crypt-v2, --tls-auth= and --tls-crypt are mutually exclusive in client mode");
+ msg(M_USAGE,
<= br>+ "--tls= -crypt-v2, --tls-auth and --tls-crypt are mutually exclusive in client mode= ");
}
}
= else
@@ -2981,12 +2975,12 @@
= if (ce->af =3D=3D AF_INET6)
{
= msg(M_INFO, "WARNING: '--proto udp6' is not compat= ible with "
- = "'--socks-proxy' today. Forcing IPv4 mode." )= ;
+ = "'--socks-proxy' today. Forcing IPv4 mode.");
}
else
= {
msg(M_INFO, "NOTICE: dual-stack mode= for '--proto udp' does not "
- "work correctly with '--socks= -proxy' today. Forcing IPv4." );
+ "work correctly with &#= 39;--socks-proxy' today. Forcing IPv4.");
= }
ce->af =3D AF_INET;
}<= /span>
@@ -3020,7 +3014,7 @@
}
= else
#endif
- if (ce->tun_mtu_defined)
+ if (ce->tun_mtu_define= d)
{
if (o->ce.tun= _mtu =3D=3D TUN_MTU_DEFAULT)
{
@@ -3063,12 +3057,9 @@

/* Pre-cache tls-auth/crypt(-v= 2) key file if
* keys were not already embedded in th= e config file.
*/
- connection_entry_preload_key(&ce->tls_auth_fil= e,
- = &ce->tls_auth_file_inline, &o->gc);
<= span style=3D"color: hsl(0, 100%, 40%);">- connection_entry_preload_key(= &ce->tls_crypt_file,

- &ce->tls_crypt_file_inline, &= amp;o->gc);
- con= nection_entry_preload_key(&ce->tls_crypt_v2_file,
- &ce= ->tls_crypt_v2_file_inline, &o->gc);
+ connection_entry_preload_key(&ce->tls= _auth_file, &ce->tls_auth_file_inline, &o->gc);
+ connection_entry_preload_key(= &ce->tls_crypt_file, &ce->tls_crypt_file_inline, &o->g= c);

+ connection_e= ntry_preload_key(&ce->tls_crypt_v2_file, &ce->tls_crypt_v2_fi= le_inline, &o->gc);


if (!proto_is_udp(ce->proto) && ce->explicit_exit_no= tification)

@@ -3099,10 +3090,8 @@
static = void
remap_redirect_gateway_flags(struct options *opt)
{
- if= (opt->routes
- = && opt->route_method =3D=3D ROUTE_METHOD_SERVICE
- && opt->routes-= >flags & RG_REROUTE_GW

- && !(opt->routes->flags & RG_DEF1))
+ if (opt->routes &a= mp;& opt->route_method =3D=3D ROUTE_METHOD_SERVICE
+ && opt->routes->= ;flags & RG_REROUTE_GW && !(opt->routes->flags & RG_D= EF1))
{
msg(M_INFO, "Fla= g 'def1' added to --redirect-gateway (iservice is in use)");
opt->routes->flags |=3D RG_DEF1;
@@ -3281,8 +3270,7 @@

/* If p11-kit is present on = the system then load its p11-kit-proxy.so
* by defaul= t if the user asks for PKCS#11 without otherwise specifying
* the module to use. */

- if (!options->pkcs11_providers[0]
- && (options->pkcs11_id || op= tions->pkcs11_id_management))
+ if (!options->pkcs11_providers[0] && (options-&= gt;pkcs11_id || options->pkcs11_id_management))
{
options->pkcs11_providers[0] =3D DEFAULT_PKCS11_= MODULE;
}
@@ -3310,8 +3298,8 @@=
if (dco_enabled(o) && o->enable_c2c)
{

msg(M_WARN, "Note: --client-to-cli= ent has no effect when using data "
- "channel offload: packets are always se= nt to the VPN "
- = "interface and then routed based on the system routing tabl= e");
+ = "channel offload: packets are always sent to the VPN "<= /span>
+ = "interface and then routed based on the system routing table");
}
}

= @@ -3341,17 +3329,19 @@
* parts of OpenVPN assert= that the ciphername is set */
o->ciphername = =3D "BF-CBC";

- msg(M_INFO, "Note: --cipher is not set. Op= enVPN versions before 2.5 "
+ msg(M_INFO,
+ "Note: --cipher is not set. OpenVPN versions = before 2.5 "
"defaulted to BF-CBC as= fallback when cipher negotiation "
"= ;failed in this case. If you need this fallback please add " "'--data-ciphers-fallback BF-CBC' to your = configuration "
"and/or add BF-CBC t= o --data-ciphers. E.g. "
- "--data-ciphers %s:BF-CBC", o->ncp_ciphers= _conf);
+ = "--data-ciphers %s:BF-CBC",
+ o->ncp_ciphers_conf);
= }
- else if (!o->= ;enable_ncp_fallback
- = && !tls_item_in_cipher_list(o->ciphername, o->ncp= _ciphers))
+ else = if (!o->enable_ncp_fallback && !tls_item_in_cipher_list(o->ci= phername, o->ncp_ciphers))
{
- msg(M_WARN, "DEPRECATED OPTION= : --cipher set to '%s' but missing in "
+ msg(M_WARN,
+ "DEPRECATED OPTION: --ci= pher set to '%s' but missing in "
= "--data-ciphers (%s). OpenVPN ignores --cipher for cipher "
"negotiations. ",
= o->ciphername, o->ncp_ciphers_conf);
@@ -3387,= 12 +3377,10 @@
options_set_backwards_compatible_options(st= ruct options *o)
{
/* TLS min version= is not set */
- int= tls_ver_min =3D (o->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT)
- &= ; SSLF_TLS_VERSION_MIN_MASK;
+ int tls_ver_min =3D (o->ssl_flags >> SSLF_TLS_VERSION= _MIN_SHIFT) & SSLF_TLS_VERSION_MIN_MASK;
if (tls_v= er_min =3D=3D 0)
{
- int tls_ver_max =3D (o->ssl_flags >> SSL= F_TLS_VERSION_MAX_SHIFT)
+ int tls_ver_max =3D (o-&g= t;ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX= _MASK;
if (need_compatibility_before(o, 20307))
{
/* 2.3.6 and earlier = have TLS 1.0 only, set minimum to TLS 1.0 */
@@ -3448,7 +34= 36,7 @@
o->comp.flags =3D COMP_F_ALLOW_STUB= _ONLY | COMP_F_ADVERTISE_STUBS_ONLY;
}
<= span> }

-#else /* = ifdef USE_COMP */
+#e= lse /* ifdef USE_COMP */
o->comp.flags =3D COMP_F_A= LLOW_NOCOMP_ONLY;
#endif
}
@@ -3459,17 +3447,16 @@

if (!check_tls_prf_working()= )
{
msg(D_TLS_ERRORS, "W= arning: TLS 1.0 PRF with MD5+SHA1 PRF is not "
- "supported by the TLS libr= ary. Your system does not support this "
- "calculation anymore or your secur= ity policy (e.g. FIPS 140-2) "
- "forbids it. Connections will only work with= peers running "
-= "OpenVPN 2.6.0 or higher)");
+ "supported by= the TLS library. Your system does not support this "
+ "calc= ulation anymore or your security policy (e.g. FIPS 140-2) "
= + &quo= t;forbids it. Connections will only work with peers running "+ &q= uot;OpenVPN 2.6.0 or higher)");
if (o->mod= e =3D=3D MODE_SERVER)
{
= msg(M_WARN, "Automatically enabling option "
- "--force-tls-key-m= aterial-export");
-<= /span>
}
}

@@ -3514,9 +3501,9 @@

#if defined(_WIN32)
if (tt->ip_win32_type !=3D IPW32_SET_DHCP_MASQ && tt->i= p_win32_type !=3D IPW32_SET_ADAPTIVE)

{
- return; /* Not in DHCP m= ode */

+ retur= n; /* Not in DHCP mode */
}
-#endif /* if defined(_WIN32) */
+#endif /* if defined(_WIN32= ) */

/* Copy --dns options to tuntap= _options */
const struct dns_domain *d =3D dns->sea= rch_domains;
@@ -3543,8 +3530,7 @@
= }
}
if ((s->trans= port && s->transport !=3D DNS_TRANSPORT_PLAIN)
- || (s->dnssec &&= s->dnssec !=3D DNS_SECURITY_NO)
- || non_standard_server_port)
+ || (s->dnssec && = s->dnssec !=3D DNS_SECURITY_NO) || non_standard_server_port)
<= span> {

/* Skip servers requiring unsu= pported config to be set */
s =3D s->next;<= /span>
@@ -3576,7 +3562,7 @@
}
}


= -#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
+#else /* if defined(_WIN32) || defi= ned(TARGET_ANDROID) */

/**
* @brief Postprocess DNS related settings

@@ -3703,8 += 3689,7 @@
}
}=
if ((s->transport && s->transpo= rt !=3D DNS_TRANSPORT_PLAIN)
- || (s->dnssec && s->dnssec !=3D DNS_SE= CURITY_NO)
- = || non_standard_server_port)
+ || (s->dnssec && s->dnssec !=3D= DNS_SECURITY_NO) || non_standard_server_port)
= {
/* Skip servers requiring unsupported c= onfig to be set */
s =3D s->next;
@@ -3838,7 +3823,7 @@
{
= /* DH file is only meaningful in a tls-server context. */
<= span> msg(M_WARN, "WARNING: Ignoring option 'dh' in tl= s-client mode, please only "

- "include this in your server configuration&quo= t;);
+ = "include this in your server configuration");
o->dh_file =3D NULL;

}
= #if ENABLE_MANAGEMENT
@@ -3847,25 +3832,23 @@
options_postprocess_http_proxy_override(o);

= }
#endif
- if (!o->ca_file && !o->ca_path && o->ver= ify_hash
- &= & o->verify_hash_depth =3D=3D 0)
+ if (!o->ca_file && !o->ca_path &&= amp; o->verify_hash && o->verify_hash_depth =3D=3D 0)<= br> {
msg(M_INFO, "Using certificat= e fingerprint to verify peer (no CA "
- "option set). ");
+ "option s= et). ");

o->verify_hash_no_ca =3D true;
}

if (o->confi= g && streq(o->config, "stdin") && o->remap_= sigusr1 =3D=3D SIGHUP)
{
msg(= M_USAGE, "Options 'config stdin' and 'remap-usr1 SIGHUP= 9; are "
- = "incompatible with each other.");
+ "incompatible with ea= ch other.");
}

= if (dco_enabled(o))
{
/*= check if any option should force disabling DCO */
- o->disable_dco =3D !dco_check_optio= n(D_DCO, o)
- = || !dco_check_startup_option(D_DCO, o);
+ o->disable_dco =3D !dco_check= _option(D_DCO, o) || !dco_check_startup_option(D_DCO, o);
= }
#ifdef USE_COMP
if (dco_enabled= (o))
@@ -3883,7 +3866,8 @@
{ if (o->windows_driver =3D=3D DRIVER_DCO)
{

- = msg(M_WARN, "Option --windows-driver ovpn-dco is ignored because Dat= a Channel Offload is disabled");
+ msg(M_WARN,
+ "Option --windows-driver ovpn-dc= o is ignored because Data Channel Offload is disabled");
o->windows_driver =3D WINDOWS_DRIVER_TAP_WINDOWS6;
}
else if (o->windows_drive= r =3D=3D WINDOWS_DRIVER_UNSPECIFIED)
@@ -3895,7 +3879,7 @@<= /span>
if (dco_enabled(o) && o->dev_node) {
msg(M_WARN, "Note: ignoring --= dev-node as it has no effect when using "
- "data channel offload");

+ &qu= ot;data channel offload");
o->dev_node =3D= NULL;
}
#endif /* _WIN32 */@@ -3933,14 +3917,14 @@
* Check file/directory s= anity
*
*/
-#ifndef ENABLE_SMALL /* Expect people using the s= tripped down version to know what they do */
+#ifndef ENABLE_SMALL /* Expect people using the st= ripped down version to know what they do */

-#define CHKACC_FILE (1<<0) = /**< Check for a file/directory presence */

-#define CHKACC_DIRPATH (1<<1) /**<= Check for directory presence where a file should reside */
-#define CHKACC_FILEXSTWR (1<<2)= /**< If file exists, is it writable? */

-#define CHKACC_ACPTSTDIN (1<<3) /**< If fi= lename is stdin, it's allowed and "exists" */
-#define CHKACC_PRIVATE (1<<4) = /**< Warn if this (private) file is group/others accessible */
<= br>-#define CHKACC_ACCEPT_URI (1&= lt;<5) /**< Do not check URIs, unless they start with file: */=
+#define CHKACC_FILE = (1 << 0) /**< Check for a file/directory presence */
+#define CHKACC_DIRPATH (1 <= < 1) /**< Check for directory presence where a file should reside */<= /span>
+#define CHKACC_FILEX= STWR (1 << 2) /**< If file exists, is it writable? */
<= span style=3D"color: hsl(120, 100%, 40%);">+#define CHKACC_ACPTSTDIN (1 &l= t;< 3) /**< If filename is stdin, it's allowed and "exists&q= uot; */

+#define CHKA= CC_PRIVATE (1 << 4) /**< Warn if this (private) file is group/o= thers accessible */
+= #define CHKACC_ACCEPT_URI (1 << 5) /**< Do not check URIs, unless = they start with file: */

static bool
check_file_access(const int type, const char *file, const int= mode, const char *opt)
@@ -3956,7 +3940,7 @@
/* If stdin is allowed and the file name is 'stdin', then d= o no

* further checks as stdin is always available
*/
= - if ( (type & CHKACC_ACPTSTDIN) && streq(file, "stdin&= quot;) )
+ if ((ty= pe & CHKACC_ACPTSTDIN) && streq(file, "stdin"))
{
return false;
= }
@@ -3979,10 +3963,11 @@
/* Is the= directory path leading to the given file accessible? */
= if (type & CHKACC_DIRPATH)
{
- char *fullpath =3D string_alloc(= file, NULL); /* POSIX dirname() implementation may modify its arguments */<= /span>
+ char *fullpa= th =3D
+ s= tring_alloc(file, NULL); /* POSIX dirname() implementation may modify its a= rguments */
char *dirpath =3D dirname(fullpath);

- = if (platform_access(dirpath, mode|X_OK) !=3D 0)
+ if (platform_access(dirpath, mode | = X_OK) !=3D 0)
{
errco= de =3D errno;
}
@@ -3990,13 +3975,= 13 @@
}

/* Is t= he file itself accessible? */
- if (!errcode && (type & CHKACC_FILE) && (pl= atform_access(file, mode) !=3D 0) )
+ if (!errcode && (type & CHKACC_FILE) &&= amp; (platform_access(file, mode) !=3D 0))
{ errcode =3D errno;
}
=
/* If the file exists and is accessible, is it writab= le? */
- if (!errcod= e && (type & CHKACC_FILEXSTWR) && (platform_access(file= , F_OK) =3D=3D 0) )
+= if (!errcode && (type & CHKACC_FILEXSTWR) && (platf= orm_access(file, F_OK) =3D=3D 0))
{
= if (platform_access(file, W_OK) !=3D 0)
{
@@ -4015,7 +4000,7 @@
#ifndef _WIN32=
else
{
- if (st.st_mode & (S_IRWXG|S_IR= WXO))
+ if= (st.st_mode & (S_IRWXG | S_IRWXO))
{
msg(M_WARN, "WARNING: file '%s' i= s group or others accessible", file);
}
@@ -4038,7 +4023,8 @@
* otherwise it will = look for the file inside the given chroot directory instead.
*/

static bool
-check_file_access_chroot(const char *chroot, const int type, = const char *file, const int mode, const char *opt)
+check_file_access_chroot(const char *chroot,= const int type, const char *file, const int mode,
+ const char *opt)
{
bool ret =3D false;
=
@@ -4071,9 +4057,8 @@
* the file is inli= ne (and therefore there is no access to check)
*/<= br> static bool
-= check_file_access_chroot_inline(bool is_inline, const char *chroot,<= br>- = const int type, const char *file,
- const int mode, const char *= opt)
+check_file_acce= ss_chroot_inline(bool is_inline, const char *chroot, const int type,=
+ = const char *file, const int mode, const char *opt)
{=
if (is_inline)
{
@@ -4088,8 +4073,8 @@

* is inline (and therefore there i= s no access to check)
*/
static bool
-check_file_access_inline(= bool is_inline, const int type, const char *file,
- const int mode, const = char *opt)
+check_fil= e_access_inline(bool is_inline, const int type, const char *file, const int= mode,
+ = const char *opt)
{
if (is= _inline)
{
@@ -4142,8 +4127,7 @@
}
else
{- msg(M_NOPREFIX|M_OPTER= R, "%s fails with '%s': No path to executable.",- opt, command);
+ msg(M_NOPREFIX = | M_OPTERR, "%s fails with '%s': No path to executable.",= opt, command);
return_code =3D true;
}


@@ -4162,55 +4146,51 @@=
bool errs =3D false;

= /* ** SSL/TLS/crypto related files ** */
- errs |=3D check_file_access_inline(options->dh_fi= le_inline, CHKACC_FILE,
- options->dh_file, R_OK, "--d= h");
+ errs |= =3D check_file_access_inline(options->dh_file_inline, CHKACC_FILE, optio= ns->dh_file, R_OK,
+ "--dh");
=
if (!options->verify_hash_no_ca)
= {
- errs |= =3D check_file_access_inline(options->ca_file_inline, CHKACC_FILE,
- = options->ca_file, R_OK, "--ca");
+ errs |=3D check_file_access= _inline(options->ca_file_inline, CHKACC_FILE, options->ca_file,
+ = R_OK, "--ca");
}
<= span>

- errs |=3D c= heck_file_access_chroot(options->chroot_dir, CHKACC_FILE,
- = options->ca_path, R_OK, "--capath");

+ errs |=3D check_file_access_chroot(optio= ns->chroot_dir, CHKACC_FILE, options->ca_path, R_OK,
+ = "--capath");

- errs |=3D check_file_access_inline(options->cert= _file_inline, CHKACC_FILE|CHKACC_ACCEPT_URI,
+ errs |=3D check_file_access_inline(options->= ;cert_file_inline, CHKACC_FILE | CHKACC_ACCEPT_URI,
= options->cert_file, R_OK, "--cert&qu= ot;);

errs |=3D check_file_access_in= line(options->extra_certs_file, CHKACC_FILE,
- options->= extra_certs_file, R_OK,
- "--extra-certs");+ = options->extra_certs_file, R_OK, "--extra-certs");

if (!(options->management_flags &am= p; MF_EXTERNAL_KEY))
{
errs |= =3D check_file_access_inline(options->priv_key_file_inline,
- = CHKACC_FILE|CHKACC_PRIVATE|CHKACC_ACCEPT_URI,

+ = CHKACC_FILE | CHKACC_PRIVATE | CHKACC_ACCEPT_URI,
= options->priv_key_file, R_OK, "--k= ey");
}

- errs |=3D check_file_access_inline(opti= ons->pkcs12_file_inline,
- CHKACC_FILE|CHKACC_PRIVATE,
+ errs |=3D check_file= _access_inline(options->pkcs12_file_inline, CHKACC_FILE | CHKACC_PRIVATE= ,
options->pkcs12_= file, R_OK, "--pkcs12");

i= f (options->ssl_flags & SSLF_CRL_VERIFY_DIR)
{<= /span>
- errs |=3D chec= k_file_access_chroot(options->chroot_dir, CHKACC_FILE,
- = options->crl_file, R_OK|X_OK,
- "--crl-verify di= rectory");
+ = errs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FILE,= options->crl_file,
- = errs |=3D check_file_access_chroot_inline(options->crl_file_inline,
- = options->chroot_dir,
- C= HKACC_FILE, options->crl_file,
- R_OK, "--c= rl-verify");
+ = errs |=3D
+ = check_file_access_chroot_inline(options->crl_file_inline, option= s->chroot_dir,
+ = CHKACC_FILE, options->crl_file= , R_OK, "--crl-verify");
}
=
if (options->tls_export_peer_cert_dir)
<= span> {

- er= rs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FILE,
- = options->tls_export_peer_cert_dir,
- W_= OK, "--tls-export-cert");
+ errs |=3D
+ check_file_access_chroot(options->chroot_dir, = CHKACC_FILE,
+ = options->tls_export_peer_cert_dir, W_OK, &= quot;--tls-export-cert");
}

ASSERT(options->connection_list);
@@ -= 4218,55 +4198,46 @@
{
struct = connection_entry *ce =3D options->connection_list->array[i];
- errs= |=3D check_file_access_inline(ce->tls_auth_file_inline,
- = CHKACC_FILE|CHKACC_PRIVATE,

- ce->tls_auth_file, R_= OK,
- = "--tls-auth");
- errs |=3D check_file_access_inline(ce->= ;tls_crypt_file_inline,
- CHKACC_FILE|CHKACC_PRIVATE,
- = ce->tls_crypt_file, R_OK,
- "--tls-= crypt");
- = errs |=3D check_file_access_inline(ce->tls_crypt_v2_file_inline,<= br>- = CHKACC_FILE|CHKACC_PRIVATE,
- ce->tls_crypt= _v2_file, R_OK,
- = "--tls-crypt-v2");
<= span style=3D"color: hsl(120, 100%, 40%);">+ errs |=3D check_file_ac= cess_inline(ce->tls_auth_file_inline, CHKACC_FILE | CHKACC_PRIVATE,
+ = ce->tls_auth_file, R_OK, "--tls-auth");
+ errs |=3D check_f= ile_access_inline(ce->tls_crypt_file_inline, CHKACC_FILE | CHKACC_PRIVAT= E,
+ = ce->tls_crypt_file, R_OK, "--tls-crypt"= ;);
+ errs |= =3D check_file_access_inline(ce->tls_crypt_v2_file_inline, CHKACC_FILE |= CHKACC_PRIVATE,
+ = ce->tls_crypt_v2_file, R_OK, "= ;--tls-crypt-v2");
}

= - errs |=3D check_file_access_= inline(options->shared_secret_file_inline,
- CHKACC_FILE|CH= KACC_PRIVATE,
- = options->shared_secret_file, R_OK,- = "--secret");
+ errs |=3D
+ check_file_access_inline(options->shared_secret_file_inline,= CHKACC_FILE | CHKACC_PRIVATE,
+ options->shared_secret_file,= R_OK, "--secret");

- errs |=3D check_file_access(CHKACC_DIRPATH|CH= KACC_FILEXSTWR,
- = options->packet_id_file, R_OK|W_OK, "--repl= ay-persist");
+ = errs |=3D check_file_access(CHKACC_DIRPATH | CHKACC_FILEXSTWR, options-&= gt;packet_id_file,
+ = R_OK | W_OK, "--replay-persist");

/* ** Password files ** */
<= span style=3D"color: hsl(0, 100%, 40%);">- errs |=3D check_file_access(C= HKACC_FILE|CHKACC_ACPTSTDIN|CHKACC_PRIVATE,

+ errs |=3D check_file_access(CHKACC_FILE | CHKAC= C_ACPTSTDIN | CHKACC_PRIVATE,
= options->key_pass_file, R_OK, "--askpass");
= #ifdef ENABLE_MANAGEMENT
- errs |=3D check_file_access(CHKACC_FILE|CHKACC_ACPTSTDIN|CHKACC_PRI= VATE,
- = options->management_user_pass, R_OK,
- "--manag= ement user/password file");
+ errs |=3D
+ check_file_access(CHKACC_FILE | CHKACC_ACPTSTDIN | CHKACC_PR= IVATE,
+ = options->management_user_pass, R_OK, "--management use= r/password file");
#endif /* ENABLE_MANAGEMENT */
errs |=3D check_file_access_inline(options->auth_user_= pass_file_inline,
- = CHKACC_FILE|CHKACC_ACPTSTDIN|CHKACC_PRIVAT= E,
- = options->auth_user_pass_file, R_OK,
- &qu= ot;--auth-user-pass");
+ CHKACC_FILE | CHKACC_ACPTSTDIN= | CHKACC_PRIVATE,
+ = options->auth_user_pass_file, R_OK, = "--auth-user-pass");
/* ** System related **= */
- errs |=3D chec= k_file_access(CHKACC_FILE, options->chroot_dir,
- R_OK|X_OK, "= ;--chroot directory");
- errs |=3D check_file_access(CHKACC_DIRPATH|CHKACC_FILEXSTWR, opti= ons->writepid,
- = R_OK|W_OK, "--writepid");
+ errs |=3D check_file_access(C= HKACC_FILE, options->chroot_dir, R_OK | X_OK, "--chroot directory&q= uot;);

+ errs |=3D= check_file_access(CHKACC_DIRPATH | CHKACC_FILEXSTWR, options->writepid,= R_OK | W_OK,
+ = "--writepid");
/* ** Log related ** */
- errs |=3D check_file_access(CHKACC_DIRPATH|CHKACC_FILEXS= TWR, options->status_file,
- R_OK|W_OK, "--status");
+ errs |=3D check_fil= e_access(CHKACC_DIRPATH | CHKACC_FILEXSTWR, options->status_file, R_OK |= W_OK,
+ = "--status");

= /* ** Config related ** */
errs |=3D check_file_ac= cess_chroot(options->chroot_dir, CHKACC_FILE, options->client_config_= dir,
- = R_OK|X_OK, "--client-config-dir");
= + = R_OK | X_OK, "--client-config-dir");
= errs |=3D check_file_access_chroot(options->chroot_dir, CHKACC_FILE, opt= ions->tmp_dir,
- = R_OK|W_OK|X_OK, "Temporary directory = (--tmp-dir)");
+= R_OK | W_OK | X_OK, "Temporary di= rectory (--tmp-dir)");

if (errs= )
{
@@ -4352,12 +4323,8 @@
<= span> * the other end of the connection]

*= /
char *
-options_string(const struct options *o,
- const struct frame *frame,
<= span style=3D"color: hsl(0, 100%, 40%);">- struct tuntap *tt,=

- openvp= n_net_ctx_t *ctx,
- = bool remote,
- struct gc_arena *gc)
+options_string(const struct options *o, const struct fram= e *frame, struct tuntap *tt,
+ openvpn_net_ctx_t *ctx, bool remote, struct gc_aren= a *gc)
{
struct buffer out =3D alloc_= buf(OPTION_LINE_SIZE);
bool tt_local =3D false;=
@@ -4373,8 +4340,7 @@
* cipher (p2p) or hav= e a fallback cipher configured for older non
* ncp cl= ients. But not sending it will make even 2.4 complain
= * about it being missing. So still send it. */
- buf_printf(&out, ",link-mtu %u"= ,
- (unsi= gned int) calc_options_string_link_mtu(o, frame));
+ buf_printf(&out, ",link-mtu %u&= quot;, (unsigned int)calc_options_string_link_mtu(o, frame));

if (o->ce.occ_mtu !=3D 0)
= {
@@ -4385,7 +4351,7 @@
buf_print= f(&out, ",tun-mtu %d", frame->tun_mtu);
= }

= - buf_printf(&out, ",proto %s", proto_remote(o->ce.pro= to, remote));
+ bu= f_printf(&out, ",proto %s", proto_remote(o->ce.proto, remo= te));

bool p2p_nopull =3D o->mode= =3D=3D MODE_POINT_TO_POINT && !PULL_DEFINED(o);
= /* send tun_ipv6 only in peer2peer mode - in client/server mode, it
@@ -4402,20 +4368,9 @@
*/
if (!tt)

{
- tt =3D init_tun(o->dev,
- o->dev_type,- o->to= pology,
- = o->ifconfig_local,
- o->ifconfig_remote_netmask,
- o->ifconfig= _ipv6_local,

- = o->ifconfig_ipv6_netbits,
- o->ifconfig_ipv6_remote,
- NULL,=
- = NULL,
- = false,
- = NULL,
- = ctx,
+ tt =3D init_tun(o->dev, o->dev_type, o->topolo= gy, o->ifconfig_local,
+ o->ifconfig_remote_netmask, o->ifconfig_i= pv6_local, o->ifconfig_ipv6_netbits,
+ o->ifconfig_ipv6_remote, NULL,= NULL, false, NULL, ctx, NULL);
if (tt)
= {
tt_local =3D true;
= @@ -4439,7 +4394,8 @@
#ifdef USE_COMP
if (o->comp.alg !=3D COMP_ALG_UNDEF)

{
- buf_printf(&out= , ",comp-lzo"); /* for compatibility, this simply indicates that = compression context is active, not necessarily LZO per-se */
+ buf_printf(&out, "= ;,comp-lzo"); /* for compatibility, this simply indicates that compres= sion

+ = context is active, not necessarily LZO per-se */=
}
#endif
@@ -4471,10 +4427,7 @@
{
= struct key_type kt;

- ASSERT((o->shared_secret_file !=3D NULL)
- + (TLS_CLIE= NT =3D=3D true)
- = + (TLS_SERVER =3D=3D true)
- <=3D 1);
+ ASSERT((o->shared_secret_file !=3D NULL) + = (TLS_CLIENT =3D=3D true) + (TLS_SERVER =3D=3D true) <=3D 1);
<= span>

/* Skip resolving BF-CBC to allow SSL libra= ries without BF-CBC
* to work here in the default= configuration */
@@ -4583,8 +4536,7 @@
}<= /span>

static const char *
-options_warning_extract_parm1(const char *= option_string,
- = struct gc_arena *gc_ret)
+options_warning_extract_parm1(const char *optio= n_string, struct gc_arena *gc_ret)
{
= struct gc_arena gc =3D gc_new();
struct buffer b =3D s= tring_alloc_buf(option_string, &gc);
@@ -4598,24 +4550,= 16 @@
}

static void
-options_warning_safe_scan= 2(const int msglevel,
-= const int delim,
- const bool report_inconsis= tent,
- = const char *p1,
- const struct buffer *b2_src,
- const cha= r *b1_name,

+options_= warning_safe_scan2(const int msglevel, const int delim, const bool report_i= nconsistent,
+ = const char *p1, const struct buffer *b2_src, const char= *b1_name,
const char *b2_name)=
{
/* We will stop sending 'key-m= ethod', 'keydir', 'proto' and 'tls-auth' in
* OCC in a future version (because it's not useful).= To reduce questions
* when interoperating, we no lon= ger printing a warning about it.
*/
- if (strprefix(p1, "key-method = ")
- || str= prefix(p1, "keydir ")
- || strprefix(p1, "proto ")
- || streq(p1, "tls-auth")=
- || strprefix(= p1, "tun-ipv6")
- || strprefix(p1, "cipher "))
+ if (strprefix(p1, "key-method "= ;) || strprefix(p1, "keydir ") || strprefix(p1, "proto "= ;)
+ || streq(= p1, "tls-auth") || strprefix(p1, "tun-ipv6") || strpref= ix(p1, "cipher "))
{
= return;
}
@@ -4642,10 +4586,7 @@
if (report_inconsistent)
= {
msg(msgleve= l, "WARNING: '%s' is used inconsistently, %s=3D'%s', %= s=3D'%s'",
- safe_print(p1_prefix, &gc),
- b1_name= ,

- = safe_print(p1, &gc),
- b2_name,
+ safe_print(p1_prefi= x, &gc), b1_name, safe_print(p1, &gc), b2_name,
= safe_print(p2, &gc));
= }
goto done;
<= span>@@ -4654,11 +4595,7 @@

}

msg(msglevel, "WARNING: '%s' is present= in %s config but missing in %s config, %s=3D'%s'",
= - safe_print(p1_prefix= , &gc),
- = b1_name,
- = b2_name,
- = b1_name,
- s= afe_print(p1, &gc));
+ safe_print(p1_prefix, &gc), b1_name, b2_name, b1_name,= safe_print(p1, &gc));

done:<= br> gc_free(&gc);
@@ -4666,13 +4603,9 @@<= /span>
}

static void-options_warning_safe_scan1(cons= t int msglevel,
- = const int delim,
- const bool report_inconsistent,<= /span>
- = const struct buffer *b1_src,
- const struct buffer *b2_src,<= br>- co= nst char *b1_name,
- = const char *b2_name)
+options_warning_safe_scan1(const int msglevel, con= st int delim, const bool report_inconsistent,
+ const struct buffer *b= 1_src, const struct buffer *b2_src,
+ const char *b1_name, const char = *b2_name)
{
struct gc_arena gc =3D gc= _new();
struct buffer b =3D *b1_src;
@= @ -4680,7 +4613,8 @@

while (buf_pars= e(&b, delim, p, OPTION_PARM_SIZE))
{
- options_warning_safe_scan2(= msglevel, delim, report_inconsistent, p, b2_src, b1_name, b2_name);
<= br>+ options_warning_saf= e_scan2(msglevel, delim, report_inconsistent, p, b2_src, b1_name,+ = b2_name);
}

= gc_free(&gc);
@@ -4700,13 +4634,9 @@
buf_printf(&local, "version %s", expected);
<= br> buf_printf(&remote, "version %s", actual);<= /span>

- = options_warning_safe_scan1(msglevel, ',', true,
- &a= mp;local, &remote,

= - "local", "remote");=
+ options_war= ning_safe_scan1(msglevel, ',', true, &local, &remote, "= ;local", "remote");

- options_warning_safe_scan1(msglevel= , ',', false,
-= &remote, &local,
- &q= uot;remote", "local");

+ options_warning_safe_scan1(msglevel, ',',= false, &remote, &local, "remote", "local");
}

gc_free(&gc= );
@@ -4745,13 +4675,12 @@
options_string_= version(const char *s, struct gc_arena *gc)
{
struct buffer out =3D alloc_buf_gc(4, gc);

- strncpynt((char *) BPTR(&out), s, 3= );
+ strncpynt((ch= ar *)BPTR(&out), s, 3);
return BSTR(&out);
}

char *
-options_string_extract_option(const cha= r *options_string, const char *opt_name,
- struct gc_arena *gc)
+options_string_extract_op= tion(const char *options_string, const char *opt_name, struct gc_arena *gc)=
{
char *ret =3D NULL;
const size_t opt_name_len =3D strlen(opt_name);

@@ -= 4759,14 +4688,14 @@
const char *p =3D options_string;<= /span>
while (p)
{
- if (0 =3D=3D strncmp(p, opt_name, o= pt_name_len)
- = && strlen(p) > (opt_name_len+1) && p[opt_name_len] = =3D=3D ' ')
+= if (0 =3D=3D strncmp(p, opt_name, opt_name_len) && strlen(p= ) > (opt_name_len + 1)
+ && p[opt_name_len] =3D=3D ' ')
= {
/* option found, extract valu= e */
- const= char *start =3D &p[opt_name_len+1];
+ const char *start =3D &p[opt_name_len = + 1];
const char *end =3D strchr(p, ','= ;);
size_t val_len =3D end ? end - start : str= len(start);
- = ret =3D gc_malloc(val_len+1, true, gc);
+ ret =3D gc_malloc(val_len + 1, true, gc);=
memcpy(ret, start, val_len);
= break;
}
@@ -4898,20 = +4827,13 @@
struct options o;
ini= t_options(&o, true);

- fprintf(fp, usage_message,
- title_string,
- o.ce.connect_retry_seconds,=
- o.ce.conn= ect_retry_seconds_max,
= - o.ce.local_port, o.ce.remote_port,
- TUN_MTU_DEFAULT, TAP_MTU_EXTRA_DEFAUL= T,
- o.verbo= sity,
- o.au= thname,
- o.= replay_window, o.replay_time,
- o.tls_timeout, o.renegotiate_seconds,
- o.handshake_window, o.trans= ition_window);
+ f= printf(fp, usage_message, title_string, o.ce.connect_retry_seconds,<= br>+ o.ce.connect_re= try_seconds_max, o.ce.local_port, o.ce.remote_port, TUN_MTU_DEFAULT,=
+ TAP_MTU_EXTRA_= DEFAULT, o.verbosity, o.authname, o.replay_window, o.replay_time,+ o.tls_timeout, o.= renegotiate_seconds, o.handshake_window, o.transition_window);
fflush(fp);


-#endif /* ENABLE_SMALL */
+#endif /* ENAB= LE_SMALL */

openvpn_exit(OPENVPN_EXI= T_STATUS_USAGE); /* exit point */
}
@@ -49= 19,7 +4841,7 @@
void
usage_small(void)
{
- m= sg(M_WARN|M_NOPREFIX, "Use --help for more information.");=
+ msg(M_WARN | M_NOPREFI= X, "Use --help for more information.");
open= vpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */
}

@@ -4952,8 +4874,7 @@
#def= ine LZO_LIB_VER_STR "", ""
#endif

- msg(= flags, "library versions: %s%s%s", get_ssl_library_version(),
- LZO_LIB_VER_STR);=
+ msg(flags, &quo= t;library versions: %s%s%s", get_ssl_library_version(), LZO_LIB_VER_ST= R);

#undef LZO_LIB_VER_STR
}

@@ -4961,20 +4882,20 @@
static void<= /span>
usage_version(void)
{
- msg(M_INFO|M_NOPREFIX, "%s"= , title_string);
- s= how_library_versions( M_INFO|M_NOPREFIX );
+ msg(M_INFO | M_NOPREFIX, "%s", title_s= tring);
+ show_lib= rary_versions(M_INFO | M_NOPREFIX);
#ifdef _WIN32- show_windows_version( M_IN= FO|M_NOPREFIX );
+ = show_windows_version(M_INFO | M_NOPREFIX);
#endif<= br> show_dco_version(M_INFO | M_NOPREFIX);
- msg(M_INFO|M_NOPREFIX, "Originally= developed by James Yonan");
- msg(M_INFO|M_NOPREFIX, "Copyright (C) 2002-2025 OpenVP= N Inc <sales@...515...>");
+ msg(M_INFO | M_NOPREFIX, "Originally developed b= y James Yonan");
+ msg(M_INFO | M_NOPREFIX, "Copyright (C) 2002-2025 OpenVPN Inc &l= t;sales@...515...>");
#ifndef ENABLE_SMALL<= br> #ifdef CONFIGURE_DEFINES
- msg(M_INFO|M_NOPREFIX, "Compile time defines: %s"= ;, CONFIGURE_DEFINES);
- msg(M_= INFO|M_NOPREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD);
+ msg(M_INFO | M_NO= PREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD);
= #endif
#endif
openvpn_exit(OPE= NVPN_EXIT_STATUS_GOOD);
@@ -5010,7 +4931,7 @@
}

#endif

-#ifdef _WIN32 /* This function is only used when= compiling on Windows */
+#ifdef _WIN32 /* This function is only used when compiling on Windows = */
static unsigned int
atou(const char *s= tr)
{
@@ -5027,13 +4948,8 @@
}


int
-parse_line(const char *line,
- char *p[],
- const int n,
- const char *file,
- const int line_num,
- int msglevel,<= /span>
- struct gc_a= rena *gc)
+parse_line= (const char *line, char *p[], const int n, const char *file, const int line= _num,
+ int= msglevel, struct gc_arena *gc)
{
con= st int STATE_INITIAL =3D 0;
const int STATE_READING_QU= OTED_PARM =3D 1;
@@ -5142,9 +5058,13 @@
= if (!(out =3D=3D '\\' || out =3D=3D '\"'= || space(out)))
{
#ifdef= ENABLE_SMALL
- = msg(msglevel, "%sOptions warning: Bad backslash ('\\&#= 39;) usage in %s:%d", error_prefix, file, line_num);
+ msg(msglevel, &qu= ot;%sOptions warning: Bad backslash ('\\') usage in %s:%d",

+ = error_prefix, file, line_num);
#else
- msg(msglevel, "%= sOptions warning: Bad backslash ('\\') usage in %s:%d: remember tha= t backslashes are treated as shell-escapes and if you need to pass backslas= h characters as part of a Windows filename, you should use double backslash= es such as \"c:\\\\" PACKAGE "\\\\static.key\"", e= rror_prefix, file, line_num);
+ msg(msglevel,
+ "%sOptions warning: Ba= d backslash ('\\') usage in %s:%d: remember that backslashes are tr= eated as shell-escapes and if you need to pass backslash characters as part= of a Windows filename, you should use double backslashes such as \"c:= \\\\" PACKAGE
+ = "\\\\static.key\"",
+ error_prefix,= file, line_num);
#endif
= return 0;
}
@@ -5159,7= +5079,7 @@
{
= parm[SIZE(parm) - 1] =3D 0;
msg(msglevel,= "%sOptions error: Parameter at %s:%d is too long (%d chars max): %s&q= uot;,
- = error_prefix, file, line_num, (int) SIZE(parm), parm);
+ error_prefix, fi= le, line_num, (int)SIZE(parm), parm);
retu= rn 0;
}
parm[parm= _len++] =3D out;
@@ -5175,17 +5095,20 @@
<= /span>
if (state =3D=3D STATE_READING_QUOTED_PARM)
= {
- m= sg(msglevel, "%sOptions error: No closing quotation (\") in %s:%d= ", error_prefix, file, line_num);
+ msg(msglevel, "%sOptions error: No closing = quotation (\") in %s:%d", error_prefix, file,
+ line_num);
= return 0;
}
if (state = =3D=3D STATE_READING_SQUOTED_PARM)
{
- msg(msglevel, "%sOptions e= rror: No closing single quotation (\') in %s:%d", error_prefix, fi= le, line_num);
+ = msg(msglevel, "%sOptions error: No closing single quotation (\'= ) in %s:%d", error_prefix,
+ file, line_num);
return 0;=
}
if (state !=3D STATE_INITIAL)<= /span>
{
= - msg(msglevel, "%sOptions error: Residual parse state (%d) in = %s:%d", error_prefix, state, file, line_num);
+ msg(msglevel, "%sOptions error:= Residual parse state (%d) in %s:%d", error_prefix, state,
<= span style=3D"color: hsl(120, 100%, 40%);">+ file, line_num);
return 0;
}
#i= f 0
@@ -5209,11 +5132,13 @@
} }

-struct in_src {
= -#define IS_TYPE_FP 1
+struct in_src
+{
+#define IS_TYPE_FP 1<= /span>
#define IS_TYPE_BUF 2
int type;
- union {
+ union

+ {
FILE *fp;
struct buffer *multiline;
} u;
@@ -5229,7 +5154,7 @@
else if (is->ty= pe =3D=3D IS_TYPE_BUF)
{
bool= status =3D buf_parse(is->u.multiline, '\n', line, size);=
- if ((int) strlen(lin= e) + 1 < size)
+ = if ((int)strlen(line) + 1 < size)
{
strcat(line, "\n");
= }
@@ -5243,11 +5168,10 @@
}
=
static char *
-read_inline_file(struct in_src *is, const char *close_tag,=
- int = *num_lines, struct gc_arena *gc)
+read_inline_file(struct in_src *is, const char *close_tag, int= *num_lines, struct gc_arena *gc)
{
c= har line[OPTION_LINE_SIZE];
- struct buffer buf =3D alloc_buf(8*OPTION_LINE_SIZE);
+ struct buffer buf =3D alloc_= buf(8 * OPTION_LINE_SIZE);

char *ret;
= bool endtagfound =3D false;

@@ -5265= ,7 +5189,7 @@
endtagfound =3D true;
= break;
}
- if (!buf_safe(&buf, strlen(line= )+1))
+ if (!b= uf_safe(&buf, strlen(line) + 1))
{
<= span> /* Increase buffer size */

s= truct buffer buf2 =3D alloc_buf(buf.capacity * 2);
@@ -5295= ,7 +5219,7 @@
if (p[0] && !p[1])
{

char *arg =3D p[0];
- if (arg[0] =3D=3D '<' &= amp;& arg[strlen(arg)-1] =3D=3D '>')
+ if (arg[0] =3D=3D '<' = && arg[strlen(arg) - 1] =3D=3D '>')
= {
struct buffer close_tag;

@@ -5321,8 +5245,7 @@
}

static int
-check_inline_file_via_buf(struct buffer *multiline, char *p[],
- = struct gc_arena *gc)
-static void
-a= dd_option(struct options *options,
- char *p[],
- bool is_inline,
- const char *file,
- int line,
- const int level,
- const int msglevel,
- const unsigned int perm= ission_mask,

- = unsigned int *option_types_found,
- struct env_set *es);
+static void add_option(struct options *options, c= har *p[], bool is_inline, const char *file,
+ int line, const int level, c= onst int msglevel,
+ = const unsigned int permission_mask, unsigned int *opt= ion_types_found,
+ = struct env_set *es);

= static void
-read_conf= ig_file(struct options *options,
- const char *file,
- int level,
- const char *top_file,
- const int= top_line,
- = const int msglevel,
- const unsigned int permission_mask,
- unsigned int *option_ty= pes_found,
- = struct env_set *es)
+read_config_file(struct options *options, const char *file, int level= , const char *top_file,
+ const int top_line, const int msglevel, const unsigned= int permission_mask,
+ unsigned int *option_types_found, struct env_set *es)
{
const int max_recursive_levels =3D 10= ;
FILE *fp;
int line_num;<= br>- char line[OPTION_LINE_SIZ= E+1];
- char *p[MAX_= PARMS+1];
+ char l= ine[OPTION_LINE_SIZE + 1];
+ char *p[MAX_PARMS + 1];

+= +level;
if (level <=3D max_recursive_levels)=
@@ -5380,7 +5290,8 @@
++line_num= ;
if (strlen(line) =3D=3D OPTION_LINE_SIZE= )
{
- msg(msglevel, "In %s:%d: Maximum op= tion line length (%d) exceeded, line starts with %s",
+ msg(msglevel,
+ = "In %s:%d: Maximum option line length (%d) exceeded, line starts wit= h %s",
file, line_num, OPTION= _LINE_SIZE, line);
}

@@ -5389,13 +5300,13 @@
{
offset =3D 3;
= }
- = if (parse_line(line + offset, p, SIZE(p)-1, file, line_num, msglevel, &am= p;options->gc))
+ = if (parse_line(line + offset, p, SIZE(p) - 1, file, line_num= , msglevel,
+ = &options->gc))
= {
bypass_doubledash(&p[0]);
int lines_inline =3D check_inline_file_vi= a_fp(fp, p, &options->gc);
- add_option(options, p, lines_inline, file, = line_num, level,
- = msglevel, permission_mask, option_types_found,
- = es);
+ = add_option(options, p, lines_inline, file, line_num, level, msg= level,
+ = permission_mask, option_types_found, es);
line_num +=3D lines_inline;

= }
}
@@ -5406,25 +5317,= 24 @@
}
else
{

- = msg(msglevel, "In %s:%d: Error opening configuration file: %s&quo= t;, top_file, top_line, file);
+ msg(msglevel, "In %s:%d: Error opening configur= ation file: %s", top_file, top_line,
+ file);
}
}
else
{=
- msg(msglevel, "= In %s:%d: Maximum recursive include levels exceeded in include attempt of f= ile %s -- probably you have a configuration file that tries to include itse= lf.", top_file, top_line, file);
+ msg(msglevel,
+ "In %s:%d: Maximum recursive include l= evels exceeded in include attempt of file %s -- probably you have a configu= ration file that tries to include itself.",
+ top_file, top_line, file);<= br> }
secure_memzero(line, sizeof(line));
CLEAR(p);
}
static void
-re= ad_config_string(const char *prefix,
- struct options *options,
- const char *config,=
- co= nst int msglevel,
- = const unsigned int permission_mask,
- unsigned int *option_types_= found,
- = struct env_set *es)
+read_config_string(const char *prefix, struct options *options, const c= har *config,
+ = const int msglevel, const unsigned int permission_mask,<= br>+ unsigned= int *option_types_found, struct env_set *es)
{
= char line[OPTION_LINE_SIZE];
struct buffer = multiline;
@@ -5434,15 +5344,15 @@
=
while (buf_parse(&multiline, '\n', line, sizeof(= line)))
{
- char *p[MAX_PARMS+1];
+ char *p[MAX_PARMS + 1];
= CLEAR(p);
++line_num;
- if (parse_line(line, p, SIZE(p)-1, prefix= , line_num, msglevel, &options->gc))
+ if (parse_line(line, p, SIZE(p) - 1, prefix= , line_num, msglevel, &options->gc))
{
bypass_doubledash(&p[0]);
= int lines_inline =3D check_inline_file_via_buf(&multiline, p, = &options->gc);
-= add_option(options, p, lines_inline, prefix, line_num, 0, msgle= vel,
- = permission_mask, option_types_found, es);
+ add_option(options, p, lines_inline= , prefix, line_num, 0, msglevel, permission_mask,
+ option_types_found, es= );
line_num +=3D lines_inline;
}

CLEAR(p);
@@ -5451,13 = +5361,8 @@
}

void
-parse_argv(struct options *= options,
- co= nst int argc,
- = char *argv[],
- = const int msglevel,
- const unsigned int permission_mask,
- unsigned int *option_types_found,
- struct env_s= et *es)
+parse_argv(s= truct options *options, const int argc, char *argv[], const int msglevel,
+ const unsi= gned int permission_mask, unsigned int *option_types_found, struct env_set = *es)
{
/* usage message */
= if (argc <=3D 1)
@@ -5468,24 +5373,26 @@
/* config filename specified only? */
= if (argc =3D=3D 2 && strncmp(argv[1], "--", 2)) {
- = char *p[MAX_PARMS+1];
- = add_option(options, p, false, NULL, 0, 0, msglevel, permission_mask,
- option= _types_found, es);
+ = add_option(options, p, false, NULL, 0, 0, msglevel, permission_mask,= option_types_found,
= + es);
}
else
{
/* parse command line */
for (int i =3D 1; i < argc; ++i)
= {
- = char *p[MAX_PARMS+1];
+ char *p[MAX_PARMS + 1];
CLEAR(p)= ;
p[0] =3D argv[i];
= if (strncmp(p[0], "--", 2))
{
- msg(msgle= vel, "I'm trying to parse \"%s\" as an --option paramete= r but I don't see a leading '--'", p[0]);
+ msg(msglevel,=
+ "= I'm trying to parse \"%s\" as an --option parameter but I don= 't see a leading '--'",
+ p[0]);
= }
else
{=
@@ -5508,8 +5415,8 @@
}
}
}
- add_option(options, p, = false, NULL, 0, 0, msglevel, permission_mask,

- option_types_found, es);
+ add_option(= options, p, false, NULL, 0, 0, msglevel, permission_mask, option_types_foun= d,
+ = es);
i +=3D j - 1;
= }
}
@@ -5564,84 +5471,64 @@=
}

bool
-apply_push_options(struct options *options,=
- st= ruct buffer *buf,
- = unsigned int permission_mask,
- unsigned int *option_types_found,=
- st= ruct env_set *es)
+ap= ply_push_options(struct options *options, struct buffer *buf, unsigned int = permission_mask,
+ = unsigned int *option_types_found, struct env_set *es)
{
char line[OPTION_PARM_SIZE];
<= span> int line_num =3D 0;

const char *file =3D &qu= ot;[PUSH-OPTIONS]";
+ const int msglevel =3D D_PUSH_ERRORS = | M_OPTERR;

while (buf_parse(buf, &#= 39;,', line, sizeof(line)))
{
- char *p[MAX_PARMS+1];
+ char *p[MAX_PARMS + 1];<= /span>
CLEAR(p);
++line_num;
if (!apply_pull_filter(options, line))
{

return false; /* Cause push/pull = error and stop push processing */
}
- if (parse_line(line, p, SIZE= (p)-1, file, line_num, msglevel, &options->gc))

+ if (parse_line(line, p, SIZE(p) = - 1, file, line_num, msglevel, &options->gc))
= {
- add_o= ption(options, p, false, file, line_num, 0, msglevel,
- permission_mask, opt= ion_types_found, es);
+ add_option(options, p, false, file, line_num, 0, msglevel, pe= rmission_mask,
+ = option_types_found, es);
}
}
return true;
}

void
-options_server_import(struct options *o,
- const char *filename= ,
- = int msglevel,
- = unsigned int permission_mask,
- unsigned int *option_types_fo= und,
+options_server_= import(struct options *o, const char *filename, int msglevel,
+ unsigned in= t permission_mask, unsigned int *option_types_found,

= struct env_set *es)
{
= msg(D_PUSH, "OPTIONS IMPORT: reading client specific options from: %= s", filename);
- = read_config_file(o,
-= filename,
- 0,
- filename,
- 0,
- msglevel,
- permission_mask,
- option= _types_found,
+ re= ad_config_file(o, filename, 0, filename, 0, msglevel, permission_mask, opti= on_types_found,
es);
= }

void
-options_string_import(struct options *options,<= br>- const c= har *config,
- = const int msglevel,
- const unsigned int permission_mask,=
- unsign= ed int *option_types_found,
+options_string_import(struct options *options, const char *config, = const int msglevel,
+= const unsigned int permission_mask, unsigned int *opt= ion_types_found,
struct env_set *es)=
{
- = read_config_string("[CONFIG-STRING]", options, config, msglevel= , permission_mask, option_types_found, es);
+ read_config_string("[CONFIG-STRING]",= options, config, msglevel, permission_mask,
+ option_types_found, es);
}

-#define VERIFY_PERMISSION(mask) { = \
- = if (!verify_permission(p[0], file, line, (mask), permission_mask, = \
- = option_types_found, msglevel, options, is_inline)) \
= - { = \
- goto err; = \
- } = \
= -}
+#define VERIFY_PE= RMISSION(mask) = \
+ { = = \
+ if (!ve= rify_permission(p[0], file, line, (mask), permission_mask, option_types_fou= nd, \
+ = msglevel, options, is_inline)) = \
+ { = = \
+ = goto err; = \
+ } = = \
+ }

static bool
-verify_permission(const char *name,
- const char *file,
- int line= ,
- co= nst unsigned int type,
= - const unsigned int allowed,
- unsigned int *found,
<= span style=3D"color: hsl(0, 100%, 40%);">- const int msgle= vel,

- = struct options *options,
- bool is_inline)
+verify_permission(const char *name, const char *file, int= line, const unsigned int type,
+ const unsigned int allowed, unsigned int *fou= nd, const int msglevel,
+ struct options *options, bool is_inline)
{

if (!(type & allowed))
= {
@@ -5651,8 +5538,7 @@

= if (is_inline && !(type & OPT_P_INLINE))
= {
- msg(msgl= evel, "option '%s' is not expected to be inline (%s:%d)",= name,
- fil= e, line);
+ ms= g(msglevel, "option '%s' is not expected to be inline (%s:%d)&= quot;, name, file, line);
return false;
= }

@@ -5669,12 +5555,12 @@
* connection_list
*/

- if ((type &= ; OPT_P_CONNECTION) && options->connection_list
- && !(allowed & OPT= _P_PULL_MODE))
+ i= f ((type & OPT_P_CONNECTION) && options->connection_list &am= p;& !(allowed & OPT_P_PULL_MODE))
{
= if (file)
{
- msg(M_WARN, "Option '%= s' in %s:%d is ignored by previous <connection> blocks ", na= me, file, line);
+ = msg(M_WARN, "Option '%s' in %s:%d is ignored by previ= ous <connection> blocks ", name,
+ file, line);
= }
else
{
@@ -5690,13 +5576,10 @@

* many parameters.
<= span> */


-#define NM_QUOTE_HINT (1<<0)
+#define NM_QUOTE_HINT (1 << 0)
=
static bool
-no_more_than_n_args(const int msglevel,
- char *p[],
- const int max,
- const u= nsigned int flags)
+n= o_more_than_n_args(const int msglevel, char *p[], const int max, const unsi= gned int flags)
{
const int len =3D s= tring_array_len((const char **)p);

@@ -57= 07,11 +5590,11 @@

if (len > max)<= /span>
{
= - msg(msglevel, "the --%s directive should have at most %d para= meter%s.%s",
- = p[0],
- = max - 1,
+ = msg(msglevel, "the --%s directive should have at most %d parameter%s.= %s", p[0], max - 1,
max >=3D 3 ? "= ;s" : "",
+ (flags & NM_QUOTE_HINT)
+ ? " To pass a list = of arguments as one of the parameters, try enclosing them in double quotes = (\"\")."
+ : "");
return false;=
}
else
@@ -5727,= 16 +5610,15 @@
}

static= void
-set_user_script(= struct options *options,
- const char *new_script,
- const char *type,
- bool in_chr= oot)
+set_user_script= (struct options *options, const char **script, const char *new_script,
+ const ch= ar *type, bool in_chroot)
{
if (*scri= pt)
{
- msg(M_WARN, "Multiple --%s scripts defined. "
- "The previ= ously configured script is overridden.", type);
+ msg(M_WARN,
+ "Multiple --%s scripts d= efined. "
+ = "The previously configured script is overridden.",=
+ type);<= br> }
*script =3D new_script;
options->user_script_used =3D true;

@@ -5744,14 += 5626,12 @@
#ifndef ENABLE_SMALL
{
char script_name[100];
- snprintf(script_name, sizeof(script_name),
- "= --%s script", type);
+ snprintf(script_name, sizeof(script_name), "--%s script&= quot;, type);

if (check_cmd_acce= ss(*script, script_name, (in_chroot ? options->chroot_dir : NULL)))
{
msg(M_USAGE, "Plea= se correct this error.");
}
-
}
#endif

}
@@ -5762,9 +5642,9 @@ if (comp_non_stub_enabled(info))
{<= br> msg(M_WARN, "WARNING: Compression for receiving enab= led. "
- = "Compression has been used in the past to break encryption. "
- "Compr= ession support is deprecated and we recommend to disable "
<= span style=3D"color: hsl(0, 100%, 40%);">- "it completely.&= quot;);

+ = "Compression has been used in the past to break encryption. &q= uot;
+ = "Compression support is deprecated and we recommend to disable &q= uot;
+ = "it completely.");
}
}=

@@ -5784,16 +5664,9 @@
= }

static void
-add_option(struct options *options,
- char *p[],

- bool is_inline,
<= br>- const char *file,<= /span>
- int line,
- const int le= vel,
- const = int msglevel,
- = const unsigned int permission_mask,
- unsigned int *option_types_found,
- struct env_set *es)
+add_option(struct option= s *options, char *p[], bool is_inline, const char *file, int line,+ const int level, = const int msglevel, const unsigned int permission_mask,
+ unsigned int *option_types_f= ound, struct env_set *es)
{
struct gc= _arena gc =3D gc_new();
const bool pull_mode =3D BOOL_= CAST(permission_mask & OPT_P_PULL_MODE);
@@ -5845,7 +57= 18,8 @@
options->config =3D p[1]; }

- read_config_file(options, p[1], level, file, line, ms= glevel, permission_mask, option_types_found, es);
+ read_config_file(options, p[1], level= , file, line, msglevel, permission_mask,
+ option_types_found, es);
}
#if defined(ENABLE_DEBUG) && !d= efined(ENABLE_SMALL)
else if (streq(p[0], "show-g= ateway") && !p[2])
@@ -5898,9 +5772,7 @@
* can potentially include security-sensitive strin= gs */
if (p[1] && strncmp(p[1], "= msg", 3) =3D=3D 0)
{
- msg(M_INFO, "%s:%s&qu= ot;,
- = pull_mode ? "ECHO-PULL" : "ECHO",
- BSTR(&string));<= /span>
+ msg(= M_INFO, "%s:%s", pull_mode ? "ECHO-PULL" : "ECHO&q= uot;, BSTR(&string));
}
#= ifdef ENABLE_MANAGEMENT
if (management)=
@@ -6015,8 +5887,7 @@
* When no option = is present, assume that only PKCS1
* padding is s= upported
*/
- if (!(options->management_flags
- &(MF_EXTERNAL_KEY_NO= PADDING | MF_EXTERNAL_KEY_PKCS1PAD)))
+ if (!(options->management_flags & (MF_EXTE= RNAL_KEY_NOPADDING | MF_EXTERNAL_KEY_PKCS1PAD)))
{=
options->management_flags |=3D MF_EXTERNAL= _KEY_PKCS1PAD;
}
@@ -6093,7 +5964,= 8 @@
else if (streq(p[0], "windows-driver") = && p[1] && !p[2])
{
= VERIFY_PERMISSION(OPT_P_GENERAL);
- msg(M_WARN, "DEPRECATED OPTION: windows-dri= ver: In OpenVPN 2.7, the default Windows driver is ovpn-dco. "<= br>+ msg(M_WARN,<= br>+ "DEPRECATE= D OPTION: windows-driver: In OpenVPN 2.7, the default Windows driver is ovp= n-dco. "
"If incompatible options ar= e used, OpenVPN will fall back to tap-windows6. Wintun support has been rem= oved.");
}
#endif
@@ -6128,7 +6000,8 @@

{
if = (!pull_mode)
{
- msg(M_WARN, "Note: option tun-ipv6 is ig= nored because modern operating systems do not need special IPv6 tun handlin= g anymore.");
+ = msg(M_WARN,
- = if (ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) && ip_or= _dns_addr_safe(p[2], options->allow_pull_fqdn)) /* FQDN -- may be DNS na= me */
+ if (ip= _or_dns_addr_safe(p[1], options->allow_pull_fqdn)
+ && ip_or_dns_addr_saf= e(p[2], options->allow_pull_fqdn)) /* FQDN -- may be DNS name */<= br> {
options->ifconfig_local= =3D p[1];
options->ifconfig_remote_netmask= =3D p[2];
@@ -6157,12 +6031,12 @@
= unsigned int netbits;

VERIFY_PE= RMISSION(OPT_P_UP);
- = if (get_ipv6_addr( p[1], NULL, &netbits, msglevel )
- && ipv6_addr_sa= fe( p[2] ) )

+ = if (get_ipv6_addr(p[1], NULL, &netbits, msglevel) && ipv6_addr= _safe(p[2]))
{
if (ne= tbits < 64 || netbits > 124)
{- msg( msglevel, = "ifconfig-ipv6: /netbits must be between 64 and 124, not '/%d'= ", netbits );
+ = msg(msglevel, "ifconfig-ipv6: /netbits must be between = 64 and 124, not '/%d'",
+ netbits);
= goto err;
}

<= span>@@ -6190,7 +6064,7 @@

{
= struct local_entry *e;

- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION= );
+ VERIFY_PE= RMISSION(OPT_P_GENERAL | OPT_P_CONNECTION);

e =3D alloc_local_entry(&options->ce, M_USAGE, &opti= ons->gc);

ASSERT(e);
@@ -6220,7= +6094,7 @@
}
else if (streq(p[0]= , "connection") && p[1] && !p[3])
{

- VERIFY= _PERMISSION(OPT_P_GENERAL|OPT_P_INLINE);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE= );
if (is_inline)
{
struct options sub;
@@ -6228,11 +61= 02,12 @@

init_options(&s= ub, true);
sub.ce =3D options->ce;- read_config_string= ("[CONNECTION-OPTIONS]", &sub, p[1], msglevel,
- OPT_P= _CONNECTION, option_types_found, es);

+ read_config_string("[CONNECTION-OPTIONS]= ", &sub, p[1], msglevel, OPT_P_CONNECTION,
+ option_typ= es_found, es);
if (!sub.ce.remote)
<= span> {

- = msg(msglevel, "Each 'connection' block must cont= ain exactly one 'remote' directive");
+ msg(msglevel,
+ "Each = 9;connection' block must contain exactly one 'remote' directive= ");

uninit_options(&sub);<= br> goto err;
}@@ -6263,16 +6138,14 @@
}
=
/* add number of options already ignored */
- for (i =3D 0; opti= ons->ignore_unknown_option
- && options->ignore_unknown_option[i]; i++)<= /span>
+ for (i =3D 0= ; options->ignore_unknown_option && options->ignore_unknown_o= ption[i]; i++)
{
numi= gnored++;
}

= /* Allocate array */
- ALLOC_ARRAY_GC(ignore, const char *, numignored+1, &options= ->gc);
- for = (i =3D 0; options->ignore_unknown_option
- && options->ignore_unknown_op= tion[i]; i++)
+ = ALLOC_ARRAY_GC(ignore, const char *, numignored + 1, &options->gc)= ;
+ for (i =3D= 0; options->ignore_unknown_option && options->ignore_unknown= _option[i]; i++)
{
ig= nore[i] =3D options->ignore_unknown_option[i];
= }
@@ -6282,9 +6155,9 @@
for (j =3D= 1; p[j]; j++)
{
/* A= llow the user to specify ignore-unknown-option --opt too */
- if (p[j][0]=3D=3D'-&#= 39; && p[j][1]=3D=3D'-')

+ if (p[j][0] =3D=3D '-' && = p[j][1] =3D=3D '-')
{
- options->ignore_unk= nown_option[i] =3D (p[j]+2);
+ options->ignore_unknown_option[i] =3D (p[j] + 2= );
}
else<= br> {
@@ -6313,7 +6186,7 @@
re.proto =3D -1;

re.af =3D 0;
- VERI= FY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_= CONNECTION);
re.remote =3D p[1];
= if (p[2])
{
@@ -6324,9 +61= 97,7 @@
const sa_family_t af =3D ascii2af(= p[3]);
if (proto < 0)
= {
- = msg(msglevel,
- "remote: bad protocol associated with = host %s: '%s'",
- p[1], p[3]);
+ msg(msglevel, "remote: bad= protocol associated with host %s: '%s'", p[1], p[3]);<= br> goto err;
}<= /span>
re.proto =3D proto;
@@ -63= 72,7 +6243,7 @@
}
else if (streq(= p[0], "connect-retry") && p[1] && !p[3]) {
- = VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENERAL |= OPT_P_CONNECTION);
options->ce.connect_retry_s= econds =3D positive_atoi(p[1], msglevel);
/*
* Limit the base value of retry wait interval to 16 bi= ts to avoid
@@ -6391,15 +6262,15 @@
= max_int(positive_atoi(p[2], msglevel), options->ce.connect_ret= ry_seconds);
}
}
- else if ((streq(p[0], "co= nnect-timeout") || streq(p[0], "server-poll-timeout"))
- && p[1= ] && !p[2])
+= else if ((streq(p[0], "connect-timeout") || streq(p[0], "= ;server-poll-timeout")) && p[1]
+ && !p[2])
= {
- VERIFY_PER= MISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNEC= TION);
options->ce.connect_timeout =3D positive= _atoi(p[1], msglevel);
}
else if = (streq(p[0], "connect-retry-max") && p[1] && !p[2= ])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_= GENERAL | OPT_P_CONNECTION);

options->connect_r= etry_max =3D positive_atoi(p[1], msglevel);
} else if (streq(p[0], "ipchange") && p[1])
@@ -6409,14 +6280,12 @@
{
= goto err;
}
- set_user_script(options,- &o= ptions->ipchange,
- = string_substitute(p[1], ',', ' ', &a= mp;options->gc),
- = "ipchange", true);
+ set_user_script(options, &option= s->ipchange,
+ = string_substitute(p[1], ',', ' ', &= options->gc), "ipchange", true);
}=
else if (streq(p[0], "float") && !p[1])
{
- = VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENER= AL | OPT_P_CONNECTION);
options->ce.remote_floa= t =3D true;
}
#ifdef ENABLE_DEBUG
@@ -6504,7 +6373,9 @@
{
if (!didit)

{
- msg(M_WARN, "WARN= ING: Multiple --daemon directives specified, ignoring --daemon %s. (Note th= at initscripts sometimes add their own --daemon directive.)", p[1]);
+ msg(M= _WARN,
+ = "WARNING: Multiple --daemon directives specified, ignoring --da= emon %s. (Note that initscripts sometimes add their own --daemon directive.= )",
+ = p[1]);
goto err;
= }
}
@@ -6566,7 +6437,= 8 @@
/* Warn when a debug verbosity is supplied wh= en built without debug support */
if (options->= verbosity >=3D 7)
{
- msg(M_WARN, "NOTE: debug verbosi= ty (--verb %d) is enabled but this build lacks debug support.",=
+ msg(M_WARN,
+ "= NOTE: debug verbosity (--verb %d) is enabled but this build lacks debug sup= port.",
options->verbosity);
}
#endif
@@ -6622,13 += 6494,13 @@
}
else if ((streq(p[0]= , "link-mtu") || streq(p[0], "udp-mtu")) && p[1= ] && !p[2])
{
- VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION);=
+ VERIFY_PERM= ISSION(OPT_P_MTU | OPT_P_CONNECTION);
options->= ce.link_mtu =3D positive_atoi(p[1], msglevel);
opt= ions->ce.link_mtu_defined =3D true;
}
else if (streq(p[0], "tun-mtu") && p[1] &&= ; !p[3])

{
- VERIFY_PERMISSION(OPT_P_PUSH_MTU|OPT_P_CONNECTION);
+ VERIFY_PERMISSION= (OPT_P_PUSH_MTU | OPT_P_CONNECTION);
options->c= e.tun_mtu =3D positive_atoi(p[1], msglevel);
optio= ns->ce.tun_mtu_defined =3D true;
if (p[2])
@@ -6642,7 +6514,7 @@
}
= else if (streq(p[0], "tun-mtu-max") && p[1] &&= !p[3])
{
- VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION);
<= span style=3D"color: hsl(120, 100%, 40%);">+ VERIFY_PERMISSION(OPT_P= _MTU | OPT_P_CONNECTION);

int max_mtu =3D positive= _atoi(p[1], msglevel);
if (max_mtu < 68 || max_= mtu > 65536)
{
@@ -6655,22 +652= 7,23 @@
}
else if (streq(p[0], &q= uot;tun-mtu-extra") && p[1] && !p[2])
= {
- VERIFY_= PERMISSION(OPT_P_MTU|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION)= ;
options->ce.tun_mtu_extra =3D positive_atoi(p= [1], msglevel);
options->ce.tun_mtu_extra_defin= ed =3D true;
}
else if (streq(p[0= ], "max-packet-size") && p[1] && !p[2]) {
- = VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONN= ECTION);
int maxmtu =3D positive_atoi(p[1], msglev= el);
options->ce.tls_mtu =3D constrain_int(maxm= tu, TLS_CHANNEL_MTU_MIN, TLS_CHANNEL_BUF_SIZE);
if (maxmtu < TLS_CHANNEL_MTU_MIN || maxmtu > TLS_CHAN= NEL_BUF_SIZE)
{
- msg(M_WARN, "Note: max-packet-size valu= e outside of allowed "
+ msg(M_WARN,
+ "Note: max-packet-size value outside of al= lowed "
"control channel packet = size (%d to %d), will use %d "
- "instead.", TLS_CHANNEL_MTU_MIN, TL= S_CHANNEL_BUF_SIZE,
- = options->ce.tls_mtu);
+ "instead.",
+ TLS_CHANNEL_MTU_MIN, T= LS_CHANNEL_BUF_SIZE, options->ce.tls_mtu);
}

/* also set mssfix maxmtu mtu */
@@ -6681,13 +6554,13 @@
#ifdef ENABLE_FRAGM= ENT
else if (streq(p[0], "mtu-dynamic"))
{
- = VERIFY_PERMISSION(OPT_P_MTU|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_MTU | OPT= _P_CONNECTION);
msg(msglevel, "--mtu-dynamic = has been replaced by --fragment");
goto err;<= /span>
}
else if (streq(p[0], "frag= ment") && p[1] && !p[3])
{=
- VERIFY_PERMISSION(OP= T_P_MTU|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION);
<= span> options->ce.fragment =3D positive_atoi(p[1], msglevel);

if (options->ce.fragment < 6= 8)
@@ -6708,7 +6581,7 @@
#endif /* ifdef E= NABLE_FRAGMENT */
else if (streq(p[0], "mtu-disc&= quot;) && p[1] && !p[2])
{
<= span style=3D"color: hsl(0, 100%, 40%);">- VERIFY_PERMISSION(OPT_P_M= TU|OPT_P_CONNECTION);

+ VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION);
= options->ce.mtu_discover_type =3D translate_mtu_discover_type_n= ame(p[1]);
}
else if (streq(p[0],= "mtu-test") && !p[1])
@@ -6779,20 +6652,= 19 @@
shaper =3D atoi_warn(p[1], msglevel);=
if (shaper < SHAPER_MIN || shaper > SHAPER_MAX)
{
- = SHAPER_MIN, SHAPER_MAX);
+ msg(msglevel, "Bad shaper value, must be between= %d and %d", SHAPER_MIN, SHAPER_MAX);
got= o err;
}
options->shap= er =3D shaper;
}
else if (streq(p= [0], "port") && p[1] && !p[2])
= {
- VERIFY_PE= RMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNE= CTION);
options->ce.local_port =3D options->= ce.remote_port =3D p[1];
}
else i= f (streq(p[0], "lport") && p[1] && !p[2])<= br> {
- = VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENERAL |= OPT_P_CONNECTION);

/* only trig= ger bind() if port is not 0 (or --local is used) */
= if (!streq(p[1], "0"))
@@ -6803,22 +6675,21 @@<= /span>
}
else if (streq(p[0], "rpor= t") && p[1] && !p[2])
{- VERIFY_PERMISSION(OPT_P= _GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION);=
options->ce.remote_port =3D p[1];
= }
else if (streq(p[0], "bind") && = !p[2])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);+ VERIFY_PERMISSION(OP= T_P_GENERAL | OPT_P_CONNECTION);
options->ce.bi= nd_defined =3D true;
if (p[1] && streq(p[1= ], "ipv6only"))
{
= options->ce.bind_ipv6_only =3D true;
}
-
}=
else if (streq(p[0], "nobind") && != p[1])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);+ VERIFY_PERMISSION(OPT= _P_GENERAL | OPT_P_CONNECTION);
options->ce.bin= d_local =3D false;
}
else if (str= eq(p[0], "fast-io") && !p[1])
@@ -6836,11= +6707,12 @@
options->inactivity_minimum_by= tes =3D (val < 0) ? 0 : val;
if (options-&g= t;inactivity_minimum_bytes > INT_MAX)
{
- msg(M_WAR= N, "WARNING: '--inactive' with a 'bytes' value"
+ msg(M= _WARN,
+ = "WARNING: '--inactive' with a 'bytes' value&quo= t;
" >2 Gbyte was silently ign= ored in older versions. If "
&qu= ot; your VPN exits unexpectedly with 'Inactivity timeout'"
" in %d seconds, revisit this value.= ",
- = options->inactivity_timeout );
+ options->inactivity_timeout);
}
}
= }
@@ -6853,14 +6725,12 @@
{ int proto;
sa_family_t af;=
- VERIFY_PERMISSION(OP= T_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION);
proto =3D ascii2proto(p[1]);
= af =3D ascii2af(p[1]);
if (proto < 0) {
- = msg(msglevel,
= - "Bad protocol: '%s'. Allowed protocols with -= -proto option: %s",
+ msg(msglevel, "Bad protocol: '%s'. Allowed pr= otocols with --proto option: %s", p[1],
= proto2ascii_all(&gc));
goto err;=
}
@@ -6883,7 +6753,7 @@
= {
struct http_proxy_options *ho;

- VERIFY_P= ERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONN= ECTION);

{
= if (!p[2])
@@ -6929,29 +6799,30 @@
= else if (streq(p[0], "http-proxy-user-pass") && p[1]= )
{
struct http_proxy_options= *ho;
- VERIFY_P= ERMISSION(OPT_P_GENERAL|OPT_P_INLINE);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE);=
ho =3D init_http_proxy_options_once(&options-= >ce.http_proxy_options, &options->gc);
h= o->auth_file_up =3D p[1];
ho->inline_creds = =3D is_inline;
}
else if (streq(p= [0], "http-proxy-retry") || streq(p[0], "socks-proxy-retry&q= uot;))
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);+ VERIFY_PERMISSION(OP= T_P_GENERAL | OPT_P_CONNECTION);
msg(M_WARN, "= ;DEPRECATED OPTION: http-proxy-retry and socks-proxy-retry: "- "In OpenVPN 2= .4 proxy connection retries are handled like regular connections. "
- "Use co= nnect-retry-max 1 to get a similar behavior as before.");
+ "In Ope= nVPN 2.4 proxy connection retries are handled like regular connections. &qu= ot;

+ = "Use connect-retry-max 1 to get a similar behavior as before."= ;);
}
else if (streq(p[0], "= http-proxy-timeout") && p[1] && !p[2])
{

- VERIFY= _PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
- msg(M_WARN, "DEPRECATED OPTION: http-pr= oxy-timeout: In OpenVPN 2.4 the timeout until a connection to a "
+ VERIFY_PERMISSIO= N(OPT_P_GENERAL | OPT_P_CONNECTION);
+ msg(M_WARN,
+ "DEPRECATED OPTION: http-proxy-timeout: I= n OpenVPN 2.4 the timeout until a connection to a "
= "server is established is managed with a single timeout set= by connect-timeout");
}
els= e if (streq(p[0], "http-proxy-option") && p[1] &&= !p[4])
{
struct http_proxy_o= ptions *ho;

- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);+ VERIFY_PERMISSION(OP= T_P_GENERAL | OPT_P_CONNECTION);
ho =3D init_http_= proxy_options_once(&options->ce.http_proxy_options, &options->= ;gc);

if (streq(p[1], "VERS= ION") && p[2] && !p[3])
@@ -6981,7 +68= 52,8 @@
}
if (!cu= stom_header)
{
- msg(msglevel, "Cannot use more t= han %d http-proxy-option CUSTOM-HEADER : '%s'", MAX_CUSTOM_HTT= P_HEADER, p[1]);
+ = msg(msglevel, "Cannot use more than %d http-proxy-option = CUSTOM-HEADER : '%s'",
+ MAX_CUSTOM_HTTP_HEADER, p[1]); }
else
= {
@@ -6998,7 +6870,7 @@
}
else if (streq(p[0], "socks-proxy") &&= ; p[1] && !p[4])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CON= NECTION);
+ VE= RIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION);
=
if (p[2])
{
@@ = -7041,7 +6913,7 @@
}
else if (str= eq(p[0], "explicit-exit-notify") && !p[2])
{

- VERIF= Y_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION|OPT_P_EXPLICIT_NOTIFY);<= br>+ VERIFY_PERMISSION(O= PT_P_GENERAL | OPT_P_CONNECTION | OPT_P_EXPLICIT_NOTIFY);
= if (p[1])
{
o= ptions->ce.explicit_exit_notification =3D positive_atoi(p[1], msglevel);=
@@ -7060,7 +6932,7 @@
{
VERIFY_PERMISSION(OPT_P_PERSIST);

msg(= M_WARN, "DEPRECATED: --persist-key option ignored. "
- "Keys are now alw= ays persisted across restarts. ");

+ "Keys are now always persisted= across restarts. ");
}
else= if (streq(p[0], "persist-local-ip") && !p[1])
= {
@@ -7092,7 +6964,8 @@
= rol_check_alloc(options);
if (pull_mode) {
- = if (!ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) &&= amp; !is_special_addr(p[1])) /* FQDN -- may be DNS name */
+ if (!ip_or_dns_addr_safe= (p[1], options->allow_pull_fqdn)
+ && !is_special_addr(p[1])) /* FQDN = -- may be DNS name */
{
= msg(msglevel, "route parameter network/IP '%s' must= be a valid address", p[1]);
goto err= ;
@@ -7102,14 +6975,16 @@
= msg(msglevel, "route parameter netmask '%s' must be an IP addr= ess", p[2]);
goto err;
}

- = if (p[3] && !ip_or_dns_addr_safe(p[3], options->allow_pul= l_fqdn) && !is_special_addr(p[3])) /* FQDN -- may be DNS name */
+ if (p[3] &= amp;& !ip_or_dns_addr_safe(p[3], options->allow_pull_fqdn)+ && !i= s_special_addr(p[3])) /* FQDN -- may be DNS name */
= {
msg(msglevel, "route paramete= r gateway '%s' must be a valid address", p[3]);
goto err;

}
/* p[4] is metric, if specified */

}=
- add_route_to_= option_list(options->routes, p[1], p[2], p[3], p[4], options->route_d= efault_table_id);
+ = add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4],<= /span>
+ = options->route_default_table_id);
}
else if (streq(p[0], "route-ipv6") && = p[1] && !p[4])
{
@@ -7129,14 += 7004,15 @@
}
/* p= [3] is metric, if specified */
}
- add_route_ipv6_to_option_list(o= ptions->routes_ipv6, p[1], p[2], p[3], options->route_default_table_i= d);
+ add_rout= e_ipv6_to_option_list(options->routes_ipv6, p[1], p[2], p[3],
= + = options->route_default_table_id);
}<= br> else if (streq(p[0], "max-routes") && !p[2]= )
{
msg(M_WARN, "DEPRECA= TED OPTION: --max-routes option ignored. "
- "The number of routes is unlimit= ed as of OpenVPN 2.4. "
- "This option will be removed in a future version, &= quot;
- &quo= t;please remove it from your configuration.");
+ "The number of r= outes is unlimited as of OpenVPN 2.4. "
+ "This option will be remo= ved in a future version, "
+ "please remove it from your configurat= ion.");
}
else if (streq(p[0= ], "route-gateway") && p[1] && !p[2])
<= span> {

@@ -7147,7 +7023,8 @@
= }
else
{
- if (ip_or_dns_addr_safe(p[= 1], options->allow_pull_fqdn) || is_special_addr(p[1])) /* FQDN -- may b= e DNS name */
+ = if (ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn)
= + || is_special_= addr(p[1])) /* FQDN -- may be DNS name */
{
options->route_default_gateway =3D p[1];<= /span>
}
@@ -7208,10 +7085,7 @@
{
goto err;
}

- s= et_user_script(options,
- &options->route_predown_script,
= - p[1],
- = "route-pre-down", true);
+ set_user_script(options, &options->route_pred= own_script, p[1], "route-pre-down", true);
}=
else if (streq(p[0], "route-noexec") &&= amp; !p[1])
{
@@ -7262,11 +7136,10 @@<= /span>

if (options->routes->flags= & RG_ENABLE)
{
- msg(M_WARN,
- "WARNING: You have specified = redirect-gateway and "
- "redirect-private at the same time (or the same = option "
- = "multiple times). This is not well supported and may lead to &= quot;
- = "unexpected results");
+ msg(M_WARN, "WARNING: You have specified redi= rect-gateway and "
+ "redirect-private at the same time (or the= same option "
+= "multiple times). This is not well supported a= nd may lead to "
+ "unexpected results");
= }

options->routes-&g= t;flags |=3D RG_ENABLE;
@@ -7366,8 +7239,7 @@
unsigned int major, minor, patch;

if (= !(sscanf(p[1], "%u.%u.%u", &major, &minor, &patch) = =3D=3D 3))
{
- msg(msglevel, "cannot parse version number= for --compat-mode: %s",
- p[1]);
+ msg(msglevel, "cannot parse version number for = --compat-mode: %s", p[1]);
goto err;
}

@@ -7385,14 +7257,= 13 @@
}
else if (streq(p[0], &quo= t;mssfix") && !p[3])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|= OPT_P_CONNECTION);
+ = VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION);
if (p[1])

{
= int mssfix =3D positive_atoi(p[1], msglevel);
= /* can be 0, but otherwise it needs to be high enough so we can
= * substract room for headers. */
- if (mssfix !=3D 0
- && (mssfix = < TLS_CHANNEL_MTU_MIN || mssfix > UINT16_MAX))

+ if (mssfix !=3D 0 && = (mssfix < TLS_CHANNEL_MTU_MIN || mssfix > UINT16_MAX))
{

msg(msglevel, "--mss= fix value '%s' is invalid", p[1]);
= goto err;
@@ -7468,15 +7339,14 @@
= unsigned int netbits =3D 0;

= VERIFY_PERMISSION(OPT_P_GENERAL);
- if (!get_ipv6_addr(p[1], &network, &netbits, = lev) )
+ if (!= get_ipv6_addr(p[1], &network, &netbits, lev))
= {
msg(msglevel, "error parsing --serv= er-ipv6 parameter");
goto err;
= }
if (netbits < 64 || netbits &g= t; 124)
{
- msg(msglevel,
- "--server-ipv6 settings: network must= be between /64 and /124 (not /%d)",
+ msg(msglevel, "--server-ipv6 setting= s: network must be between /64 and /124 (not /%d)",
= netbits);

got= o err;
@@ -7581,7 +7451,7 @@
unsig= ned int netbits =3D 0;

VERIFY_PE= RMISSION(OPT_P_GENERAL);
+ if (!get_ipv6_a= ddr(p[1], &network, &netbits, lev))
{
msg(msglevel, "error parsing --ifconfig-ipv6-= pool parameters");
goto err;
@@ -7670,7 +7540,8 @@

else if (streq(p[0], "c= lient-cert-not-required") && !p[1])
{
VERIFY_PERMISSION(OPT_P_GENERAL);
- msg(M_FATAL, "REMOVED OPTION= : --client-cert-not-required, use '--verify-client-cert none' inste= ad");
+ m= sg(M_FATAL,
+ = "REMOVED OPTION: --client-cert-not-required, use '--verify-cli= ent-cert none' instead");
}
= else if (streq(p[0], "verify-client-cert") && !p[2])<= /span>
{
@@ -7691,7 +7562,8 @@
}

else if (!streq(p[1], "r= equire"))
{
- msg(msglevel, "parameter to --= verify-client-cert must be 'none', 'optional' or 'requi= re'");
+ = msg(msglevel,
+ "parameter to --verify-client-cert must be &= #39;none', 'optional' or 'require'");
goto err;

}
}

@@ -7710,7 +7582,7 @@
{<= /span>
VERIFY_PERMISSION(OPT_P_GENERAL);
= msg(M_INFO, "DEPRECATION: opt-verify is deprecated and will b= e removed "
- = "in OpenVPN 2.7");
+ "in OpenVPN 2.7");
= options->ssl_flags |=3D SSLF_OPT_VERIFY;
= }
else if (streq(p[0], "auth-user-pass-verif= y") && p[1])
@@ -7732,18 +7604,19 @@ }
else
= {
- = msg(msglevel, "second parm to --auth-user-pass-verify must be &#= 39;via-env' or 'via-file'");
+ msg(msglevel,
+ "second parm t= o --auth-user-pass-verify must be 'via-env' or 'via-file'&q= uot;);
goto err;
= }
}
else
{

- = msg(msglevel, "--auth-user-pass-verify requires a second paramete= r ('via-env' or 'via-file')");
+ msg(msglevel,
+ "--auth-user-p= ass-verify requires a second parameter ('via-env' or 'via-file&= #39;)");

goto err;
= }
- set_user_= script(options,
- = &options->auth_user_pass_verify_script,
= - p[1], &q= uot;auth-user-pass-verify", true);
+ set_user_script(options, &options->auth_= user_pass_verify_script, p[1],
+ "auth-user-pass-verify", true)= ;
}
else if (streq(p[0], "au= th-gen-token"))
{
@@ -7767,14 +76= 40,12 @@
msg(msglevel, "Invalid argum= ent to auth-gen-token: %s (%d)", p[i], i);
= }
}
-
}
else if (streq(p[0], = "auth-gen-token-secret") && p[1] && !p[2])=
{
- = VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT= _P_INLINE);
options->auth_token_secret_file =3D= p[1];
options->auth_token_secret_file_inline = =3D is_inline;
-=
}
else if (streq(p[0], "client-con= nect") && p[1])
{
@@ -778= 3,8 +7654,7 @@
{
goto= err;
}
- set_user_script(options, &options->client_connect= _script,
- = p[1], "client-connect", true);
+ set_user_script(options, &opt= ions->client_connect_script, p[1], "client-connect", true);
}
else if (streq(p[0], "client= -crresponse") && p[1])
{
= @@ -7793,8 +7663,8 @@
{
= goto err;
}
- set_user_script(options, &options->client_= crresponse_script,
- = p[1], "client-crresponse", true);
= + set_user_script(option= s, &options->client_crresponse_script, p[1], "client-crresponse= ",
+ = true);
}
else if (str= eq(p[0], "client-disconnect") && p[1])
= {
@@ -7803,8 +7673,8 @@
{
goto err;
}
- set_user_script(options, &am= p;options->client_disconnect_script,

- p[1], "client-disconnect&quo= t;, true);
+ s= et_user_script(options, &options->client_disconnect_script, p[1], &q= uot;client-disconnect",
+ true);
}
else if (streq(p[0], "learn-address") && p[1])
{
@@ -7813,8 +7683,7 @@
{

goto err;
= }
- set_user_sc= ript(options, &options->learn_address_script,
- p[1], "learn-a= ddress", true);
= + set_user_script(options, &options->learn_address_script, p[= 1], "learn-address", true);
}
else if (streq(p[0], "tmp-dir") && p[1] &&= !p[2])

{
@@ -7889,8 +7758,8 @@=
in_addr_t local, remote_netmask;

VERIFY_PERMISSION(OPT_P_INSTANCE);
- local =3D getaddr(GETADDR_HOST_ORD= ER|GETADDR_RESOLVE, p[1], 0, NULL, NULL);
- remote_netmask =3D getaddr(GETADDR_HOST_ORDER|G= ETADDR_RESOLVE, p[2], 0, NULL, NULL);
+ local =3D getaddr(GETADDR_HOST_ORDER | GETADDR_RE= SOLVE, p[1], 0, NULL, NULL);
+ remote_netmask =3D getaddr(GETADDR_HOST_ORDER | GETADDR_RE= SOLVE, p[2], 0, NULL, NULL);
if (local && = remote_netmask)
{
opt= ions->push_ifconfig_defined =3D true;
@@ -7898,7 +7767,8= @@
options->push_ifconfig_remote_netmask = =3D remote_netmask;
if (p[3])
= {
- = options->push_ifconfig_local_alias =3D getaddr(GETADDR_HOST_ORD= ER|GETADDR_RESOLVE, p[3], 0, NULL, NULL);
+ options->push_ifconfig_local_alias= =3D
+ = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[3], 0, NULL, NULL);
}
}
= else
@@ -7912,7 +7782,7 @@
i= n_addr_t network, netmask;

VERIF= Y_PERMISSION(OPT_P_GENERAL);
- network =3D getaddr(GETADDR_HOST_ORDER|GETADDR_RESOLVE, p[1]= , 0, NULL, NULL);
+ = network =3D getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, NU= LL, NULL);
netmask =3D getaddr(GETADDR_HOST_ORDER,= p[2], 0, NULL, NULL);
if (network && netm= ask)
{
@@ -7933,7 +7803,7 @@

VERIFY_PERMISSION(OPT_P_INSTANCE);

- = if (!get_ipv6_addr( p[1], &local, &netbits, msglevel ) )+ if (!get_ipv6_addr(p= [1], &local, &netbits, msglevel))
{=
msg(msglevel, "cannot parse --ifconfig-ipv6-pus= h addresses");
goto err;
= @@ -7941,19 +7811,19 @@

if (p[2]= )
{
- if (!get_ipv6_addr( p[2], &remote, NULL, msglevel ) = )
+ if (!g= et_ipv6_addr(p[2], &remote, NULL, msglevel))
= {
- m= sg( msglevel, "cannot parse --ifconfig-ipv6-push addresses");
+ msg(msg= level, "cannot parse --ifconfig-ipv6-push addresses");
= goto err;
}
<= span> }

else
{
if (!options->ifconfig_ipv6_local
<= span style=3D"color: hsl(0, 100%, 40%);">- || !get_ipv6_addr= ( options->ifconfig_ipv6_local, &remote,

- NULL, msglevel= ) )
+ = || !get_ipv6_addr(options->ifconfig_ipv6_local, &remote, NULL, msgl= evel))
{
- msg( msglevel, "second argument to --i= fconfig-ipv6-push missing and no global --ifconfig-ipv6 address set");=
+ msg= (msglevel,
+ = "second argument to --ifconfig-ipv6-push missing and no glo= bal --ifconfig-ipv6 address set");
go= to err;
}
}@@ -7974,8 +7844,10 @@
VERIFY_PERMISSION(OP= T_P_INSTANCE);
if (strlen(p[1]) > USER_PASS_LEN= )
{
- msg(msglevel, "override-username exceeds the maximu= m length of %d "
-= "characters", USER_PASS_LEN);
+ msg(msglevel,
+ "override-us= ername exceeds the maximum length of %d "

+ "characters",+ USER_PASS_LE= N);

/* disable the connectio= n since ignoring the request to
* set another= username might cause serious problems */
@@ -8011,7 +7883,= 7 @@
msg(msglevel, "--stale-routes-check = aging time and check interval must be >=3D 1");
= goto err;
}
- options->stale_routes_ageing_time =3D = ageing_time;
+ = options->stale_routes_ageing_time =3D ageing_time;
= options->stale_routes_check_interval =3D check_interval;
= }

@@ -8032,7 +7904,7 @@=
}
else if (streq(p[0], "auth-user-= pass") && !p[2])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT= _P_INLINE);
+ = VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE);
i= f (p[1])
{
options-&g= t;auth_user_pass_file =3D p[1];
@@ -8073,15 +7945,15 @@
#ifdef _WIN32
VERIFY_PERMISSION(OPT_= P_GENERAL);
HANDLE process =3D GetCurrentProcess()= ;
- HANDLE handl= e =3D (HANDLE) ((intptr_t) atoll(p[1]));
- if (!DuplicateHandle(process, handle, process, &= amp;options->msg_channel, 0,
- FALSE, DUPLICATE_CLOSE_SOURCE | DUPL= ICATE_SAME_ACCESS))
+= HANDLE handle =3D (HANDLE)((intptr_t)atoll(p[1]));
+ if (!DuplicateHandle(process= , handle, process, &options->msg_channel, 0, FALSE,
+ DUPLICA= TE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
{=
msg(msglevel, "could not duplicate service pipe= handle");
goto err;
= }
options->route_method =3D ROUTE_METHOD_S= ERVICE;
-#else /* ifde= f _WIN32 */
+#else /*= ifdef _WIN32 */
msg(msglevel, "--msg-channel= is only supported on Windows");
goto err;
#endif
@@ -8093,8 +7965,8 @@
if (streq(p[1], "env"))

{
msg(M_INFO, "NOTE: --win-sys env is default f= rom OpenVPN 2.3. "
- "Please rem= ove this entry from your configuration file.");
+ "This entry = will now be ignored. "
+ "Please remove this entry from your c= onfiguration file.");
}
= else
{
@@ -8131,9 +8003,7 @@

if (index < 0)
{

- = msg(msglevel,
- = "Bad --ip-win32 method: '%s'. Allowed methods: %s&q= uot;,
- = p[1],
+ ms= g(msglevel, "Bad --ip-win32 method: '%s'. Allowed methods: %s= ", p[1],
ipset2ascii_all(&gc));
goto err;
}
= @@ -8153,7 +8023,9 @@

= if (!(offset > -256 && offset < 256))
{

- msg(msglevel, "--ip-win32 dynamic [offset] [= lease-time]: offset (%d) must be > -256 and < 256", offset);
+ = msg(msglevel,
+ = "--ip-win32 dynamic [offset] [lease-time]: offs= et (%d) must be > -256 and < 256",
+ offset);
goto err;

= }

@@ -8168,7 +8040,9 @@
= lease_time =3D atoi_warn(p[3], msglevel);
if (lease_time < min_lease)

= {
- = msg(msglevel, "--ip-win32 dynamic [offset] [leas= e-time]: lease time parameter (%d) must be at least %d seconds", lease= _time, min_lease);
+ = msg(msglevel,
+ "--ip-win32 dynamic [offs= et] [lease-time]: lease time parameter (%d) must be at least %d seconds&quo= t;,
+ = lease_time, min_lease);
= goto err;
}
= to->dhcp_lease_time =3D lease_time;
@@ -821= 8,7 +8092,8 @@

if (streq(p[1], &= quot;search-domains") && p[2])
{
- dns_domain_lis= t_append(&options->dns_options.search_domains, &p[2], &optio= ns->dns_options.gc);
+ dns_domain_list_append(&options->dns_options.search_= domains, &p[2],
+= &options->dns_options.gc);=
}
else if (streq(p[1], "se= rver") && p[2] && p[3] && p[4])
{

@@ -8229,7 +8104,8 @@
= goto err;
}
<= br>- struct dns_server= *server =3D dns_server_get(&options->dns_options.servers, priority,= &options->dns_options.gc);
+ struct dns_server *server =3D
+ dns_server_get(&op= tions->dns_options.servers, priority, &options->dns_options.gc);<= /span>

if (streq(p[3], "addres= s") && p[4])
{
@@= -8237,7 +8113,9 @@
{
= if (!dns_server_addr_parse(server, p[i]))
= {
= - msg(msglevel, "--dns server %ld: malformed ad= dress or maximum exceeded '%s'", priority, p[i]);
+ msg(msgl= evel,

+ = "--dns server %ld: malformed address or maximum exceeded= '%s'",
= + priority, p[i]);
= goto err;
}
}

@@ -8282,7 +8160,8 @@
= }
else
= {
- = msg(msglevel, "--dns server %ld: malformed transport va= lue '%s'", priority, p[4]);
+ msg(msglevel, "--dns server %= ld: malformed transport value '%s'", priority,
+ p[4]);
goto err;
= }
}
@@ -8292,7 +8171,9 @@
}
else
{

- = msg(msglevel, "--dns server %ld: unknown option type '= %s' or missing or unknown parameter", priority, p[3]);
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(msglevel,
+ &= quot;--dns server %ld: unknown option type '%s' or missing or unkno= wn parameter",
+= priority, p[3]);
goto = err;
}
}
@@ -8384,10 +8265,11 @@

#endif
= else
{
- msg(msglevel, "--dhcp-option: unknown option t= ype '%s' or missing or unknown parameter", p[1]);
+ msg(msglevel, "= --dhcp-option: unknown option type '%s' or missing or unknown param= eter",

+ = p[1]);
goto err;
= }
-#else /* if defi= ned(_WIN32) || defined(TARGET_ANDROID) */
+#else /* if defined(_WIN32) || defined(TARGET_ANDROI= D) */
setenv_foreign_option(options, (const char *= *)p, 3, es);
#endif /* if defined(_WIN32) || defined(TARGE= T_ANDROID) */
}
@@ -8395,14 +8277,14 @= @
else if (streq(p[0], "show-adapters") &= ;& !p[1])
{
VERIFY_PERMIS= SION(OPT_P_GENERAL);
- = show_tap_win_adapters(M_INFO|M_NOPREFIX, M_WARN|M_NOPREFIX);<= br>+ show_tap_win_adapte= rs(M_INFO | M_NOPREFIX, M_WARN | M_NOPREFIX);
open= vpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
}=
else if (streq(p[0], "show-net") &&= !p[1])
{
VERIFY_PERMISSION(O= PT_P_GENERAL);
- = show_routes(M_INFO|M_NOPREFIX);
- show_adapters(M_INFO|M_NOPREFIX);
+ show_routes(M_INFO | M_NOPREFIX);=
+ show_adapte= rs(M_INFO | M_NOPREFIX);
openvpn_exit(OPENVPN_EXIT= _STATUS_GOOD); /* exit point */
}
= else if (streq(p[0], "show-net-up") && !p[1])
= @@ -8551,19 +8433,20 @@

if= (streq(p[1], "no"))
{
- options->comp.flags =3D<= /span>
- COMP_F= _ALLOW_STUB_ONLY|COMP_F_ADVERTISE_STUBS_ONLY;
+ options->comp.flags =3D COMP_F_ALL= OW_STUB_ONLY | COMP_F_ADVERTISE_STUBS_ONLY;
if= (comp_non_stub_enabled(&options->comp))
= {
msg(msglevel, "'--allow-compr= ession no' conflicts with "
- " enabling compression");
+ = " enabling compression");
}
}
else if (options->comp= .flags & COMP_F_ALLOW_STUB_ONLY)
{
<= span> /* Also printed on a push to hint at configuration proble= ms */

- msg(= msglevel, "Cannot set allow-compression to '%s' "<= br>- "after s= et to 'no'", p[1]);
+ msg(msglevel,
+ "Cannot set allow-compression to &#= 39;%s' "
+ = "after set to 'no'",
+ p[1]);
= goto err;
}
el= se if (streq(p[1], "asym"))
@@ -8572,15 +8455,18 = @@
}
else if (streq(p[1],= "yes"))
{
- msg(M_WARN, "DEPRECATED OPTION: \&= quot;--allow-compression yes\" has been removed. "
+ msg(M_WARN,

= + "DEPRECAT= ED OPTION: \"--allow-compression yes\" has been removed. "
"We will use \"asym\" mode i= nstead. See the manual page for more information.");
=
options->comp.flags |=3D COMP_F_ALLOW_ASYM= ;
}
else
= {
- = msg(msglevel, "bad allow-compression option: %s -- "
<= span style=3D"color: hsl(0, 100%, 40%);">- "must be = 9;yes', 'no', or 'asym'", p[1]);

+ msg(msglevel,
<= span style=3D"color: hsl(120, 100%, 40%);">+ "bad allow= -compression option: %s -- "

+ "must be 'yes', 'no', or= 'asym'",
+ msg(msglevel, &= quot;bad comp-lzo option: %s -- must be 'yes', 'no', or = 9;adaptive'",
- options->comp.flags |=3D (COMP_F_SWAP|COMP_F_ADVERTISE_STU= BS_ONLY);
+ = options->comp.flags |=3D (COMP_F_SWAP | COMP_F_ADVERTISE_STUBS_ONLY);<= /span>
}
else if (streq(alg, &qu= ot;stub-v2"))
{
@@ -8679,7 +8= 566,7 @@
{
int key_direction;=

- = VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ VERIFY_PERMISSION(OPT_P_GENERAL= | OPT_P_CONNECTION);

key_direct= ion =3D ascii2keydirection(msglevel, p[1]);
if (ke= y_direction >=3D 0)
@@ -8701,7 +8588,7 @@
else if (streq(p[0], "secret") && p[1] && = !p[3])

{
msg(M_WARN, "DE= PRECATED OPTION: The option --secret is deprecated.");
- VERIFY_PERMISSION(OPT_P_GENER= AL|OPT_P_INLINE);

+ = VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE);
= options->shared_secret_file =3D p[1];
opti= ons->shared_secret_file_inline =3D is_inline;
i= f (!is_inline && p[2])
@@ -8723,7 +8610,6 @@=
{
VERIFY_PERMISSION(OPT_P_GENERAL);=
options->allow_deprecated_insecure_static_cryp= to =3D true;
- }
else if (streq(p[0], "genkey"= ) && !p[4])
{
@@ -8735,8 +8621= ,7 @@
}
else
{

- = if (streq(p[1], "secret") || streq(p[1], "tls-auth"= ;)
- || = streq(p[1], "tls-crypt"))
+ if (streq(p[1], "secret") || streq(p[= 1], "tls-auth") || streq(p[1], "tls-crypt"))
= {
options->genkey_ty= pe =3D GENKEY_SECRET;
}
@@ -87= 60,7 +8645,6 @@
{
= msg(msglevel, "unknown --genkey type: %s", p[1]);
= }
-<= /span>
}
if (p[2])
{

@@ -8774,23 +8658,22 @@
= }
else if (streq(p[0], "cipher") && = p[1] && !p[2])
{
- VERIFY_PERMISSION(OPT_P_NCP|OPT_P_INSTANCE)= ;
+ VERIFY_PER= MISSION(OPT_P_NCP | OPT_P_INSTANCE);
options->c= iphername =3D p[1];
}
else if (st= req(p[0], "data-ciphers-fallback") && p[1] && !p[= 2])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INSTANCE);
+ VERIFY_PERMISSION(OPT_P_G= ENERAL | OPT_P_INSTANCE);

options->ciphername = =3D p[1];
options->enable_ncp_fallback =3D true= ;
}
- = && p[1] && !p[2])
+ else if ((streq(p[0], "data-ciphers"= ;) || streq(p[0], "ncp-ciphers")) && p[1] && !p[2= ])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INSTANCE);
+ VERIFY_PERMISSION(OPT_P_GE= NERAL | OPT_P_INSTANCE);

if (streq(p[0], "ncp= -ciphers"))
{
ms= g(M_INFO, "Note: Treating option '--ncp-ciphers' as "
- " &#= 39;--data-ciphers' (renamed in OpenVPN 2.5).");
+ " '--= data-ciphers' (renamed in OpenVPN 2.5).");
= }
options->ncp_ciphers =3D p[1];
}

@@ -8852,7 +8735,7 @@
V= ERIFY_PERMISSION(OPT_P_GENERAL);
/* always error o= ut, this breaks the connection */
msg(M_FATAL, &qu= ot;--no-replay was removed in OpenVPN 2.7. "
- "Update your configuration.&qu= ot;);
+ = "Update your configuration.");
}
else if (streq(p[0], "replay-window") &&= !p[3])
{
@@ -8865,9 +8748,7 @@=
if (!(MIN_SEQ_BACKTRACK <=3D replay_window &&= amp; replay_window <=3D MAX_SEQ_BACKTRACK))
= {
msg(msglevel, "replay-window windo= w size parameter (%d) must be between %d and %d",
- replay_window,<= br>- MIN_SEQ_B= ACKTRACK,
- = MAX_SEQ_BACKTRACK);
+ replay_window, MIN_SEQ_BACKTRACK, MAX_SEQ_BACKT= RACK);
goto err;
= }
options->replay_window =3D replay_win= dow;
@@ -8879,10 +8760,9 @@
= replay_time =3D atoi_warn(p[2], msglevel);
= if (!(MIN_TIME_BACKTRACK <=3D replay_time && replay_time <= =3D MAX_TIME_BACKTRACK))
{
- msg(msglevel, &qu= ot;replay-window time window parameter (%d) must be between %d and %d"= ,

- = replay_time,
- = MIN_TIME_BACKTRACK,
- MAX_TIME_BACKTRACK);
+ msg(msglevel,=

+ = "replay-window time window parameter (%d) must be between %d and = %d",
+ = replay_time, MIN_TIME_BACKTRACK, MAX_TIME_BACKTRACK);<= br> goto err;
}<= /span>
options->replay_time =3D replay_time;
@@ -8951,8 +8831,8 @@
{
VERIFY_PERMISSION(OPT_P_GENERAL);

msg(M_= WARN, "Consider setting groups/curves preference with "- "tls-groups in= stead of forcing a specific curve with "
- "ecdh-curve.");
+ "tls-gro= ups instead of forcing a specific curve with "

+ "ecdh-curve.&quo= t;);
options->ecdh_curve =3D p[1];
}

else if (streq(p[0], "tls-server"= ) && !p[1])
@@ -8967,7 +8847,7 @@
= }
else if (streq(p[0], "ca") && = p[1] && !p[2])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLIN= E);
+ VERIFY_P= ERMISSION(OPT_P_GENERAL | OPT_P_INLINE);
options-&= gt;ca_file =3D p[1];
options->ca_file_inline = =3D is_inline;
}
@@ -8980,33 +8860,33 = @@
#endif /* ENABLE_CRYPTO_MBEDTLS */
= else if (streq(p[0], "dh") && p[1] && !p[2])
{
- = VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE);
+ VERIFY_PERMISSION(OPT_P_GENERAL |= OPT_P_INLINE);
options->dh_file =3D p[1];
options->dh_file_inline =3D is_inline;
}

else if (streq(p[0], "cert") &= ;& p[1] && !p[2])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT= _P_INLINE);
+ = VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE);
o= ptions->cert_file =3D p[1];
options->cert_fi= le_inline =3D is_inline;
}
else i= f (streq(p[0], "extra-certs") && p[1] && !p[2])
{
-= VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE);
+ VERIFY_PERMISSION(OPT_P_GENERAL = | OPT_P_INLINE);
options->extra_certs_file =3D = p[1];
options->extra_certs_file_inline =3D is_i= nline;
}
else if ((streq(p[0], &q= uot;verify-hash") && p[1] && !p[3])
= || (streq(p[0], "peer-fingerprint") && p[1] &= amp;& !p[2]))
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INLINE);
+ VERIFY_PERMIS= SION(OPT_P_GENERAL | OPT_P_INLINE);

= int verify_hash_depth =3D 0;
if (streq(p[0], &= quot;verify-hash"))
{
= msg(M_WARN, "DEPRECATED OPTION: The option --verify-hash is depr= ecated. "
- = "You should switch to the either use the level 1 certificate = as "
- = "--ca option, use --tls-verify or use --peer-fingerprint");
+ = "You should switch to the either use the level 1 certificate as &qu= ot;
+ = "--ca option, use --tls-verify or use --peer-fingerprint"= );
/* verify level 1 cert, i.e. the CA that si= gned the leaf cert */
verify_hash_depth =3D 1;=
}
@@ -9017,8 +8897,10 @@
if (options->verify_hash && o= ptions->verify_hash_depth !=3D verify_hash_depth)
= {
- msg(m= sglevel, "ERROR: Setting %s not allowed. --verify-hash and"
- " --pe= er-fingerprint are mutually exclusive", p[0]);
+ msg(msglevel,
+ "ERROR: Settin= g %s not allowed. --verify-hash and"

+ " --peer-fingerprint are mutuall= y exclusive",
+ = p[0]);
goto err;
}


@@ -9031,15 +8913,16 @@
}
else if (p[2] &= & !streq(p[2], "SHA256"))
{
- msg(msglev= el, "invalid or unsupported hashing algorithm: %s "
- "(only SHA= 1 and SHA256 are supported)", p[2]);

+ msg(msglevel,
+ "invalid or unsu= pported hashing algorithm: %s "
+ "(only SHA1 and SHA256 are suppor= ted)",
+ = p[2]);
goto err;
}

}

struct verify_hash_list *newlist;

- newlist =3D parse_hash_fingerprint_multili= ne(p[1], digest_len,
- = msglevel, &options-&g= t;gc);
+ newli= st =3D parse_hash_fingerprint_multiline(p[1], digest_len, msglevel, &op= tions->gc);

/* Append the new= list to the end of our current list */
if (!optio= ns->verify_hash)
@@ -9068,7 +8951,7 @@
= #endif
else if (streq(p[0], "key") &&= ; p[1] && !p[2])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INL= INE);
+ VERIFY= _PERMISSION(OPT_P_GENERAL | OPT_P_INLINE);
options= ->priv_key_file =3D p[1];
options->priv_key_= file_inline =3D is_inline;
}
@@ -9091,= 8 +8974,7 @@
}
#endif
<= span>

- options= ->ssl_flags &=3D
- ~(SSLF_TLS_VERSION_MIN_MASK << SSLF_TLS_VERSION_MIN_SHI= FT);
+ options= ->ssl_flags &=3D ~(SSLF_TLS_VERSION_MIN_MASK << SSLF_TLS_VERSI= ON_MIN_SHIFT);
options->ssl_flags |=3D (ver <= ;< SSLF_TLS_VERSION_MIN_SHIFT);
}
= else if (streq(p[0], "tls-version-max") && p[1] &= & !p[2])
@@ -9105,14 +8987,13 @@
= msg(msglevel, "unknown tls-version-max parameter: %s", p[1= ]);
goto err;
}
- options->ssl_fla= gs &=3D
- = ~(SSLF_TLS_VERSION_MAX_MASK << SSLF_TLS_VERSION_MAX_SHIFT);<= br>+ options->ssl_fla= gs &=3D ~(SSLF_TLS_VERSION_MAX_MASK << SSLF_TLS_VERSION_MAX_SHIFT= );
options->ssl_flags |=3D (ver << SSLF_T= LS_VERSION_MAX_SHIFT);
}
#ifndef ENAB= LE_CRYPTO_MBEDTLS
else if (streq(p[0], "pkcs12&qu= ot;) && p[1] && !p[2])
{
- VERIFY_PERMISSION(OPT_P_GEN= ERAL|OPT_P_INLINE);

+= VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE);
= options->pkcs12_file =3D p[1];
options-&= gt;pkcs12_file_inline =3D is_inline;
}
@@ -9185,10 +9066,9 @@

VERIFY_PERMISSION(OPT_P_GE= NERAL);
options->tls_groups =3D p[1]; }
- else= if (streq(p[0], "crl-verify") && p[1] && ((p[2] = && streq(p[2], "dir"))
- || !p= [2]))
+ else if (s= treq(p[0], "crl-verify") && p[1] && ((p[2] &&= amp; streq(p[2], "dir")) || !p[2]))
{=
- VERIFY_PERMISSION(OP= T_P_GENERAL|OPT_P_INLINE);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INLINE);
<= span> if (p[2] && streq(p[2], "dir"))

<= span> {

options->ssl_flags |=3D SSL= F_CRL_VERIFY_DIR;
@@ -9204,8 +9084,7 @@
= goto err;
}
set= _user_script(options, &options->tls_verify,
- string_substitute(p[1]= , ',', ' ', &options->gc),
- "tls-verify",= true);
+ = string_substitute(p[1], ',', ' ', &options-= >gc), "tls-verify", true);
}
else if (streq(p[0], "tls-export-cert") && p[1] = && !p[2])

{
@@ -9216,14 +9095,= 14 @@
{
VERIFY_PERMISSION(OPT= _P_GENERAL);
msg(msglevel, "--compat-names wa= s removed in OpenVPN 2.5. "
- "Update your configuration.");
<= span style=3D"color: hsl(120, 100%, 40%);">+ "Upd= ate your configuration.");

goto err; }
else if (streq(p[0], "no-name-rema= pping") && !p[1])
{
= VERIFY_PERMISSION(OPT_P_GENERAL);
msg(msglevel= , "--no-name-remapping was removed in OpenVPN 2.5. "
- "Update your conf= iguration.");

+ = "Update your configuration.");
goto err;

}
else if (= streq(p[0], "verify-x509-name") && p[1] && strlen= (p[1]) && !p[3])
@@ -9282,7 +9161,7 @@
size_t j;

for (j =3D 1; j < MAX_PA= RMS && p[j] !=3D NULL; ++j)
{
- sscanf(p[j], "%x&= quot;, &(options->remote_cert_ku[j-1]));

+ sscanf(p[j], "%x", &(= options->remote_cert_ku[j - 1]));
}
<= span> if (j =3D=3D 1)

{
@@= -9367,7 +9246,7 @@
{
int key= _direction =3D -1;

- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION|OPT= _P_INLINE);
+ = VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION | OPT_P_INLINE);<= br>
if (permission_mask & OPT_P_GENERAL= )
{
@@ -9383,7 +9262,6 @@ }
options->key= _direction =3D key_direction;
}
-

} else if (permission_mask & OPT_P_CONNECTION) {
@@ -9404,7 +9282,7 @@
= }
else if (streq(p[0], "tls-crypt") &&= amp; p[1] && !p[3])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_= CONNECTION|OPT_P_INLINE);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION | OPT_P_IN= LINE);
if (permission_mask & OPT_P_GENERAL)
{
options->tls_crypt= _file =3D p[1];
@@ -9418,7 +9296,7 @@
= }
else if (streq(p[0], "tls-crypt-v2") &= & p[1] && !p[3])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT= _P_CONNECTION|OPT_P_INLINE);
+ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION | OPT_P= _INLINE);
if (permission_mask & OPT_P_GENERAL)=
{
options->tls_cr= ypt_v2_file =3D p[1];
@@ -9461,19 +9339,19 @@
{

char *s =3D p[j];

- if (st= rncmp("ext:", s, 4) =3D=3D 0 && !x509_username_field_ext_= supported(s+4))
+ = if (strncmp("ext:", s, 4) =3D=3D 0 && !x509_usern= ame_field_ext_supported(s + 4))
{
msg(msglevel, "Unsupported x509-username-field ex= tension: %s", s);

}
- options->x509_username_field= [j-1] =3D p[j];
+ = options->x509_username_field[j - 1] =3D p[j];
= }
}
#endif /* ENABLE_X509ALTUS= ERNAME */
#ifdef ENABLE_PKCS11
else i= f (streq(p[0], "show-pkcs11-ids") && !p[3])
{

- char= *provider =3D p[1];
-= bool cert_private =3D (p[2] =3D=3D NULL ? false : (atoi_warn(p[2], = msglevel) !=3D 0 ));
= + char *provider =3D p[1];
+ bool cert_private =3D (p[2] =3D=3D NULL ? false : (at= oi_warn(p[2], msglevel) !=3D 0));

#ifdef= DEFAULT_PKCS11_MODULE
if (!provider)
@@ -9514,7 +9392,7 @@


for (j= =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j)
= {
- o= ptions->pkcs11_providers[j-1] =3D p[j];
+ options->pkcs11_providers[j - 1] =3D = p[j];
}
}
= else if (streq(p[0], "pkcs11-protected-authentication"))=
@@ -9525,7 +9403,8 @@

= for (j =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j)
{

- = options->pkcs11_protected_authentication[j-1] =3D atoi_warn(p[j], m= sglevel) !=3D 0 ? 1 : 0;
+ options->pkcs11_protected_authentication[j - 1] =3D
+ atoi_wa= rn(p[j], msglevel) !=3D 0 ? 1 : 0;
}
}

else if (streq(p[0], "pkcs11-private-mo= de") && p[1])
@@ -9536,7 +9415,7 @@
=
for (j =3D 1; j < MAX_PARMS && = p[j] !=3D NULL; ++j)
{
- sscanf(p[j], "%x", &(op= tions->pkcs11_private_mode[j-1]));
+ sscanf(p[j], "%x", &(options-&g= t;pkcs11_private_mode[j - 1]));
}
= }
else if (streq(p[0], "pkcs11-cert-private&= quot;))
@@ -9547,7 +9426,7 @@

<= span> for (j =3D 1; j < MAX_PARMS && p[j] !=3D NULL; ++j= )

{
- options->pkcs11_cert_private[j-1] =3D (bool) (atoi_wa= rn(p[j], msglevel));
= + options->pkcs11_cert_private[j - 1] =3D (bool)(atoi_warn(p[= j], msglevel));
}
} else if (streq(p[0], "pkcs11-pin-cache") && p= [1] && !p[2])
@@ -9593,13 +9472,13 @@
if (strncmp(p[1], "EXPORTER", 8))

= {
msg(msglevel, "Keying material ex= porter label must begin with "
- "\"EXPORTER\"");+ &q= uot;\"EXPORTER\"");
goto err;
}
if (streq(p[1], EXPORT_K= EY_DATA_LABEL))
{
- msg(msglevel, "Keying material export= er label must not be '"
- EXPORT_KEY_DATA_LABEL "'.");
+ msg(msglevel,=
+ &qu= ot;Keying material exporter label must not be '" EXPORT_KEY_DATA_L= ABEL "'.");
}
= if (ekm_length < 16 || ekm_length > 4095)
= {
@@ -9643,13 +9522,12 @@
} else if (streq(p[0], "vlan-pvid") && p[1] &am= p;& !p[2])
{
- VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INSTANCE);
+ VERIFY_PERMISS= ION(OPT_P_GENERAL | OPT_P_INSTANCE);
options->v= lan_pvid =3D positive_atoi(p[1], msglevel);
if (op= tions->vlan_pvid < OPENVPN_8021Q_MIN_VID
= || options->vlan_pvid > OPENVPN_8021Q_MAX_VID)
= {
- msg(= msglevel,
- = "the parameter of --vlan-pvid parameters must be >=3D %u and &l= t;=3D %u",
+ = msg(msglevel, "the parameter of --vlan-pvid parameters must be= >=3D %u and <=3D %u",
OPENVPN_= 8021Q_MIN_VID, OPENVPN_8021Q_MAX_VID);
goto er= r;
}
@@ -9670,11 +9548,14 @@
}
if (file)
= {
- m= sg(msglevel_unknown, "Unrecognized option or missing or extra paramete= r(s) in %s:%d: %s (%s)", file, line, p[0], PACKAGE_VERSION);+ msg(msglevel_unkn= own,
+ = "Unrecognized option or missing or extra parameter(s) in %s:%d: %s (%= s)", file,
+ = line, p[0], PACKAGE_VERSION);
}=
else
{
- msg(msglevel_unknown, "Unreco= gnized option or missing or extra parameter(s): --%s (%s)", p[0], PACK= AGE_VERSION);
+ = msg(msglevel_unknown, "Unrecognized option or missing or extra p= arameter(s): --%s (%s)",
+ p[0], PACKAGE_VERSION);
= }
}
err:
diff --git a= /src/openvpn/options.h b/src/openvpn/options.h
index 56e85d= 7..0855ec8 100644
--- a/src/openvpn/options.h
+++ b/src/openvpn/options.h

@@ -122,33 +122,34 @@=
const char *socks_proxy_port;
const cha= r *socks_proxy_authfile;

- int tun_mtu; /* MTU of tun device */
- int occ_mtu; /*= if non-null, this is the MTU we announce to peers in OCC */
- int tun_mtu_max; /* maximum = MTU that can be pushed */

+ int tun_mtu; /* MTU of tun device */
+ int occ_mtu; /* if non-nul= l, this is the MTU we announce to peers in OCC */
+ int tun_mtu_max; /* maximum MTU that= can be pushed */

bool tun_mtu_defin= ed; /* true if user overriding parm with command line option */
<= span> int tun_mtu_extra;

bool tun_mtu_extra_define= d;
- int link_mtu; = /* MTU of device over which tunnel packets pass via TCP/UDP */=
+ int link_mtu; = /* MTU of device over which tunnel packets pass via TCP/UDP */
<= span> bool link_mtu_defined; /* true if user overriding parm with comma= nd line option */

- = int tls_mtu; /* Maximum MTU for the control channel messages */
+ int tls_mtu; = /* Maximum MTU for the control channel messages */

/* Advanced MTU negotiation and datagram fragmentation o= ptions */
int mtu_discover_type; /* used if OS support= s setting Path MTU discovery options on socket */
<= br>- int fragment; /* i= nternal fragmentation size */
- bool fragment_encap; /* true if --fragment had the "mtu&qu= ot; parameter to
- = * include overhead from IP and TCP/UDP encapsulation *= /
- int mssfix; = /* Upper bound on TCP MSS */
- bool mssfix_default; /* true if --mssfix should use the def= ault parameters */
- = bool mssfix_encap; /* true if --mssfix had the "mtu" parameter= to include
- = * overhead from IP and TCP/UDP encapsulation */
<= span style=3D"color: hsl(0, 100%, 40%);">- bool mssfix_fixed; /* use t= he mssfix value without any encapsulation adjustments */

+ int fragment; /* internal= fragmentation size */
+ = * include overhead from IP and TCP/UDP encapsulation = */
+ int mssfix; = /* Upper bound on TCP MSS */
+ bool mssfix_default; /* true if --mssfix should us= e the default parameters */
+ bool mssfix_encap; /* true if --mssfix had the "mtu&qu= ot; parameter to include
+ * overhead from IP and TCP/UDP encapsulati= on */
+ bool mssfi= x_fixed; /* use the mssfix value without any encapsulation adjustments = */

- = int explicit_exit_notification; /* Explicitly tell peer when we are exit= ing via OCC_EXIT or [RESTART] message */
+ int explicit_exit_notification; /* Explicitly tell= peer when we are exiting via OCC_EXIT or
+ [RESTART] mess= age */

-#define CE_MAN_QUERY_PROXY (1<<1)
+#define CE_DISABLED (1 <= ;< 0)
+#define CE_= MAN_QUERY_PROXY (1 << 1)
#define CE_MAN_QUER= Y_REMOTE_UNDEF 0
#define CE_MAN_QUERY_REMOTE_QUERY 1
#define CE_MAN_QUERY_REMOTE_ACCEPT 2
@@ -231,= 7 +232,8 @@
char port[RH_PORT_LEN];
}= ;

-en= um genkey_type {
+enu= m genkey_type
+{
GENKEY_SECRET,
GENKEY_TLS_CRYPTV2_CLI= ENT,
GENKEY_TLS_CRYPTV2_SERVER,
@@ -33= 8,32 +340,32 @@

bool mlock;
- int keep= alive_ping; /* a proxy for ping/ping-restart */
+ int keepalive_ping; /* a proxy for = ping/ping-restart */
int keepalive_timeout;
=
- int inacti= vity_timeout; /* --inactive */
+ int inactivity_timeout; /* --inactive */
int64_t inactivity_minimum_bytes;


- int session_timeout; /* Forc= e-kill session after n seconds */
+ int session_timeout; /* Force-kill session after n sec= onds */

- int ping_send_timeout; /* Send a TCP/UDP ping to remote every = n seconds */
- int p= ing_rec_timeout; /* Expect a TCP/UDP ping from remote at least once e= very n seconds */
- = bool ping_timer_remote; /* Run ping timer only if we have a remote addr= ess */
+ int ping_= send_timeout; /* Send a TCP/UDP ping to remote every n seconds */+ int ping_rec_timeout; = /* Expect a TCP/UDP ping from remote at least once every n seconds */
+ bool ping_timer_remot= e; /* Run ping timer only if we have a remote address */
<= /span>
#define PING_UNDEF 0
#define PING_EXIT = 1
#define PING_RESTART 2
int ping_= rec_timeout_action; /* What action to take on ping_rec_timeout (exit or res= tart)? */

- bool persist_tun; /* Don't close/reopen TUN/TAP dev= on SIGUSR1 or PING_RESTART */
- bool persist_local_ip; /* Don't re-resolve local addr= ess on SIGUSR1 or PING_RESTART */
- bool persist_remote_ip; /* Don't re-resolve remote = address on SIGUSR1 or PING_RESTART */
+ bool persist_tun; /* Don't close/reope= n TUN/TAP dev on SIGUSR1 or PING_RESTART */
+ bool persist_local_ip; /* Don't re-re= solve local address on SIGUSR1 or PING_RESTART */
+ bool persist_remote_ip; /* Don't= re-resolve remote address on SIGUSR1 or PING_RESTART */
<= /span>
#if PASSTOS_CAPABILITY
bool passtos;<= /span>
#endif

- int resolve_retry_seconds; /* If hostname resolve = fails, retry for n seconds */
+ int resolve_retry_seconds; /* If hostname resolve fails, retr= y for n seconds */
bool resolve_in_advance;
= const char *ip_remote_hint;

@@= -434,7 +436,7 @@
int route_delay_window;
bool route_delay_defined;

struct route_option= _list *routes;
- str= uct route_ipv6_option_list *routes_ipv6; /* IPv6 */<= br>+ struct route_ipv6_optio= n_list *routes_ipv6; /* IPv6 */
bool block_ipv6;
bool route_nopull;
bool route_gateway_= via_dhcp;
@@ -469,13 +471,13 @@
bool s= erver_defined;
in_addr_t server_network;
in_addr_t server_netmask;

- bool server_ipv6_defined; /* IPv6= */
- struct in6_add= r server_network_ipv6; /* IPv6 */
- unsigned int server_netbits_ipv6; = /* IPv6 */
+ = bool server_ipv6_defined; /* IPv6 */
+ struct in6_addr server_network_ipv6; /* = IPv6 */
+ unsigned= int server_netbits_ipv6; /* IPv6 */

-#define SF_NOPOOL (1<<0)-#define SF_TCP_NODELAY_HELPER = (1<<1)
-#define S= F_NO_PUSH_ROUTE_GATEWAY (1<<2)
+#define SF_NOPOOL (1 << 0)
= +#define SF_TCP_NODELAY_HELPER = (1 << 1)
+#d= efine SF_NO_PUSH_ROUTE_GATEWAY (1 << 2)
unsigned= int server_flags;

bool server_bridg= e_proxy_dhcp;
@@ -494,9 +496,9 @@
cons= t char *ifconfig_pool_persist_filename;
int ifconfig_p= ool_persist_refresh_freq;

- bool ifconfig_ipv6_pool_defined; = /* IPv6 */
- stru= ct in6_addr ifconfig_ipv6_pool_base; /* IPv6 */
- int ifconfig_ipv6_pool_netbits; = /* IPv6 */
+ bool ifconfig_ipv6_pool_defined; /* IPv6 */
= + struct in6_addr ifconfig_i= pv6_pool_base; /* IPv6 */
+ int ifconfig_ipv6_pool_netbits; /* IPv6 */

int real_hash_size;
int virt= ual_hash_size;
@@ -511,7 +513,7 @@
int= n_bcast_buf;
int tcp_queue_limit;
= struct iroute *iroutes;
- struct iroute_ipv6 *iroutes_ipv6; /* IPv6 */
+ struct iroute_ipv6 *= iroutes_ipv6; /* IPv6 */
bool push_ifconfig_defined;
in_addr_t push_ifconfig_local;
in_= addr_t push_ifconfig_remote_netmask;
@@ -519,12 +521,12 @@<= /span>
bool push_ifconfig_constraint_defined;
in_addr_t push_ifconfig_constraint_network;

in_a= ddr_t push_ifconfig_constraint_netmask;
- bool push_ifconfig_ipv4_blocked; /= * IPv4 */
- bool pus= h_ifconfig_ipv6_defined; /* IPv6 */
- struct in6_addr push_ifconfig_ipv6_loc= al; /* IPv6 */
- struct in6_addr push_if= config_ipv6_remote; /* IPv6 */
- bool push_ifconfig_ipv6_blocked; /= * IPv6 */
+ bool p= ush_ifconfig_ipv4_blocked; /* IPv4 */
+ bool push_ifconfig_ipv6_defined; = /* IPv6 */
+ struc= t in6_addr push_ifconfig_ipv6_local; /* IPv6 */
+ int push_ifconfig_ipv6_netbits; = /* IPv6 */
+ stru= ct in6_addr push_ifconfig_ipv6_remote; /* IPv6 */
+ bool push_ifconfig_ipv6_blocked; = /* IPv6 */
bool enable_c2c;
boo= l duplicate_cn;

@@ -573,8 +575,8 @@
bool allow_deprecated_insecure_static_crypto;
int key_direction;

const char *ciphername;
- bool enable_ncp_fallb= ack; /**< If defined fall back to
- * ciphername if NCP = fails */
+ bool en= able_ncp_fallback; /**< If defined fall back to
+ * ciphername = if NCP fails */
/** The original ncp_ciphers specified= by the user in the configuration*/
const char *ncp_ci= phers_conf;
const char *ncp_ciphers;
@= @ -728,40 +730,40 @@
/*
* Option classes= .
*/
= -#define OPT_P_GENERAL (1<<0)
-#define OPT_P_UP (1<<1)
= -#define OPT_P_ROUTE (1= <<2)
-#define OPT= _P_DHCPDNS (1<<3) /* includes ip windows options like */
-#define OPT_P_SCRIPT = (1<<4)
-#d= efine OPT_P_SETENV (1<<5)
-#define OPT_P_SHAPER (1<<6)
-#define OPT_P_TIMER (1<= ;<7)

-#define OPT_P_= PERSIST (1<<8)
-#define OPT_P_PERSIST_IP (1<<9)
-#define OPT_P_COMP (1<<10) /* = TODO */
-#define OPT_P_= MESSAGES (1<<11)
-#define OPT_P_NCP (1<<12) /**< Negotiable cryp= to parameters */
-#defi= ne OPT_P_TLS_PARMS (1<<13) /* TODO */
-#define OPT_P_MTU (1<<14) /* = TODO */
-#define OPT_P_= NICE (1<<15)
-#define OPT_P_PUSH (1<<16)
-#define OPT_P_INSTANCE (1<<17)= /**< allowed in ccd, client-connect etc*/
-#define OPT_P_CONFIG (1<<18)<= br>-#define OPT_P_EXPLICIT_NOTIFY= (1<<19)
-#define= OPT_P_ECHO (1<<20)
-#define OPT_P_INHERIT (1<<21)
-#define OPT_P_ROUTE_EXTRAS (1<&l= t;22)
-#define OPT_P_PU= LL_MODE (1<<23)
-#define OPT_P_PLUGIN (1<<24)
-#define OPT_P_SOCKBUF (1<<25)
-#define OPT_P_SOCKFLAGS = (1<<26)
-#de= fine OPT_P_CONNECTION (1<<27)
-#define OPT_P_PEER_ID (1<<28)
-#define OPT_P_INLINE (1&l= t;<29)

-#define OPT_= P_PUSH_MTU (1<<30)
-#define OPT_P_ROUTE_TABLE (1<<31)
+#define OPT_P_GENERAL (1 <<= 0)
+#define OPT_P_UP= (1 << 1)
+#define OPT_P_ROUTE (1 << 2)
+#define OPT_P_DHCPDNS (1 <<= 3) /* includes ip windows options like */
+#define OPT_P_SCRIPT (1 << 4)<= br>+#define OPT_P_SETENV = (1 << 5)
+#d= efine OPT_P_SHAPER (1 << 6)
+#define OPT_P_TIMER (1 << 7)<= br>+#define OPT_P_PERSIST = (1 << 8)
+#d= efine OPT_P_PERSIST_IP (1 << 9)
+#define OPT_P_COMP (1 << 10) /* TOD= O */
+#define OPT_P_M= ESSAGES (1 << 11)
+#define OPT_P_NCP (1 << 12) /**< Negotiable= crypto parameters */
+#define OPT_P_TLS_PARMS (1 << 13) /* TODO */
+#define OPT_P_MTU (1 <= ;< 14) /* TODO */
= +#define OPT_P_NICE (1 << 15)
+#define OPT_P_PUSH (1 << 16)
+#define OPT_P_INSTANCE= (1 << 17) /**< allowed in ccd, client-connect etc*/=
+#define OPT_P_CONFIG = (1 << 18)
+= #define OPT_P_EXPLICIT_NOTIFY (1 << 19)
+#define OPT_P_ECHO (1 << 20)
+#define OPT_P_INHERIT = (1 << 21)
+#define OPT_P_PULL_MODE (1 << 23)<= /span>
+#define OPT_P_PLUGIN= (1 << 24)
+#define OPT_P_SOCKBUF (1 << 25)
+#define OPT_P_SOCKFLAGS (1 <<= 26)
+#define OPT_P_C= ONNECTION (1 << 27)
+#define OPT_P_PEER_ID (1 << 28)
+#define OPT_P_INLINE (1 <&= lt; 29)
+#define OPT_= P_PUSH_MTU (1 << 30)
+#define OPT_P_ROUTE_TABLE (1 << 31)

-#define OPT_P_DEFAU= LT (~(OPT_P_INSTANCE|OPT_P_PULL_MODE))
+#define OPT_P_DEFAULT (~(OPT_P_INSTANCE | OPT_P_PULL_M= ODE))

#define PULL_DEFINED(opt) ((opt)-&= gt;pull)
#define PUSH_DEFINED(opt) ((opt)->push_list)
@@ -794,12 +796,8 @@
#define MAN_CLIENT_AUT= H_ENABLED(opt) (false)
#endif

= -void parse_argv(struct options *= options,
- = const int argc,
- = char *argv[],
- const int msglevel,
- const unsigned int permission_mask,
- unsigned i= nt *option_types_found,
+void parse_argv(struct options *options, const int argc, char *argv[], = const int msglevel,
+= const unsigned int permission_mask, unsigned int *option_ty= pes_found,
struct env_set *es);
=
void notnull(const char *arg, const char *descript= ion);
@@ -827,12 +825,8 @@

const char *options_string_version(const char *s, struct gc_arena *gc);<= /span>

-char= *options_string(const struct options *o,
- const struct frame *frame,<= br>- struct t= untap *tt,
- = openvpn_net_ctx_t *ctx,
- bool remote,
- struct gc_arena *gc);+char *options_string(const s= truct options *o, const struct frame *frame, struct tuntap *tt,
<= span style=3D"color: hsl(120, 100%, 40%);">+ openvpn_ne= t_ctx_t *ctx, bool remote, struct gc_arena *gc);

bool options_cmp_equal_safe(char *actual, const char *expected, si= ze_t actual_n);

@@ -852,8 +846,8 @@
* @return gc-allocated value of option with name opt_name if o= ption was found,
* or NULL otherwise.
<= span> */

-char *option= s_string_extract_option(const char *options_string,
- const c= har *opt_name, struct gc_arena *gc);
+char *options_string_extract_option(const char *options_st= ring, const char *opt_name,
+ struct gc_arena *gc);

void options_postprocess(struct= options *options, struct env_set *es);
@@ -862,32 +856,21 = @@

void pre_connect_restore(struct optio= ns *o, struct gc_arena *gc);

-bool apply_push_options(struct options *options,
- = struct buffer *buf,
- = unsigned int permission_mask,
- unsigned int *optio= n_types_found,
- = struct env_set *es);
+bool apply_push_options(struct options *options, struct b= uffer *buf, unsigned int permission_mask,
+ unsigned int *option_types_fo= und, struct env_set *es);

void options_d= etach(struct options *o);

-void options_server_import(struct options *o,<= br>- co= nst char *filename,
- = int msglevel,
- unsigned int permission_mask,
- = unsigned int *option_types_found,
+void options_server_import(struct options *o, const char = *filename, int msglevel,
+ unsigned int permission_mask, unsigned int = *option_types_found,
struct env= _set *es);

void pre_pull_default(struct = options *o);

void rol_check_alloc(struct= options *options);

-int parse_line(const char *line,
- char *p[],
- const int n,
- const char *file,
- const int l= ine_num,
- = int msglevel,
- = struct gc_arena *gc);
+int parse_line(const char *line, char *p[], const int n, const c= har *file, const int line_num,
+ int msglevel, struct gc_arena *gc);

/*
* parse/print topology coding
@@ -911,11 +894,8 @@

const= char *auth_retry_print(void);

-void options_string_import(struct options *optio= ns,
- = const char *config,
- const int msglevel,
- const unsigned i= nt permission_mask,
- = unsigned int *option_types_found,
+void options_string_import(struct op= tions *options, const char *config, const int msglevel,
+ const unsign= ed int permission_mask, unsigned int *option_types_found,
= struct env_set *es);
bool key_is_external(const struct options *options);
diff --git a/src/openvpn/options_util.c b/src/openvpn/options_util.c
index 80d0c08..e2c445c 100644
--- a/src/openvpn= /options_util.c
+++ b/src/openvpn/options_util.c
= @@ -123,12 +123,11 @@

if (i &l= t; 0 || *endptr !=3D '\0' || i > INT_MAX)
{=
- msg(msglevel,= "Cannot parse argument '%s' as non-negative integer",
- str);=
+ msg(msglevel, &quo= t;Cannot parse argument '%s' as non-negative integer", str);
i =3D 0;
}

- return (int) i;
+ return (int)i;
}

int
@@ -1= 43,5 +142,5 @@
i =3D 0;
}

- ret= urn (int) i;
+ ret= urn (int)i;
}
diff --git a/src/openvpn/opt= ions_util.h b/src/openvpn/options_util.h
index 2474e7f..27a= 97a9 100644
--- a/src/openvpn/options_util.h
+++ b/src/openvpn/options_util.h

@@ -27,27 +27,23 @@

#include "options.h"

-const char *
-parse_auth_failed_temp(str= uct options *o, const char *reason);
+const char *parse_auth_failed_temp(struct options *o, cons= t char *reason);


/** C= hecks if the string is a valid integer by checking if it can be
<= span> * converted to an integer */

-bool
-va= lid_integer(const char *str, bool positive);
+bool valid_integer(const char *str, bool positive)= ;

/**
* Converts a str= to a positive number if the string represents a postive
= * integer number. Otherwise print a warning with msglevel and return 0
*/
-int
-positive_atoi(const cha= r *str, int msglevel);
-int
-atoi_warn(const char *str, int msglevel);+int atoi_warn(const char *st= r, int msglevel);

#endif /* ifndef OPTIO= NS_UTIL_H_ */
diff --git a/src/openvpn/otime.c b/src/openvp= n/otime.c
index d423067..196b175 100644
---= a/src/openvpn/otime.c
+++ b/src/openvpn/otime.c
= @@ -84,9 +84,7 @@
tv_string(const struct timeval *tv= , struct gc_arena *gc)
{
struct buffe= r out =3D alloc_buf_gc(64, gc);
- buf_printf(&out, "[%" PRIi64 "/%ld]",=
- (int64= _t)tv->tv_sec,
- = (long)tv->tv_usec);
+ buf_printf(&out, "[%" PRIi64 "/%ld]&qu= ot;, (int64_t)tv->tv_sec, (long)tv->tv_usec);
re= turn BSTR(&out);
}

@= @ -98,10 +96,7 @@
const char *
tv_string_= abs(const struct timeval *tv, struct gc_arena *gc)
{
- return time_string((tim= e_t) tv->tv_sec,
- = (long) tv->tv_usec,
- true,
- gc);
+ return time_string((time_t)tv->= tv_sec, (long)tv->tv_usec, true, gc);
}

/* format a time_t as ascii, or use current time if 0 *= /
@@ -125,9 +120,8 @@
t =3D tv.tv_sec;=
struct tm *tm =3D localtime(&t);
=
- buf_printf(&= out, "%04d-%02d-%02d %02d:%02d:%02d",
- tm->tm_year+1900, tm->tm_mon= +1, tm->tm_mday,
- = tm->tm_hour, tm->tm_min, tm->tm_sec);
+ buf_printf(&out, "%04d= -%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1,<= /span>
+ tm-&g= t;tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
=
if (show_usec && tv.tv_usec)
= {
@@ -197,9 +191,7 @@
t =3D t= ime(NULL);
gettimeofday(&tv, NULL);
= #if 1
- m= sg(M_INFO, "t=3D%" PRIi64 " s=3D%" PRIi64 " us=3D%= ld",
- = (int64_t)t,
- = (int64_t)tv.tv_sec,
+ msg(M_INFO, "t=3D%" PRIi64 " s=3D%" PRIi64 &q= uot; us=3D%ld", (int64_t)t, (int64_t)tv.tv_sec,
= (long)tv.tv_usec);
#endif
}
diff --git a/src/openvpn/otime.h b/src/openvpn/otime.h=
index 448389d..87f9a25 100644
--- a/src/openvpn/o= time.h
+++ b/src/openvpn/otime.h
@@ -237,7 = +237,7 @@
dest->tv_usec =3D usec;
= }

-#d= efine TV_WITHIN_SIGMA_MAX_SEC 600
+#define TV_WITHIN_SIGMA_MAX_SEC 600
#define= TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000)

/*
@@ -260,7 +260,7 @@
{

if (at > current)
{
- const interval_t de= lta =3D (interval_t) (at - current);
+ const interval_t delta =3D (interval_t)(at - curre= nt);
if (delta < *wakeup)
= {
*wakeup =3D delta;
diff = --git a/src/openvpn/ovpn_dco_freebsd.h b/src/openvpn/ovpn_dco_freebsd.h
index 53f94df..2d33475 100644
--- a/src/openvp= n/ovpn_dco_freebsd.h
+++ b/src/openvpn/ovpn_dco_freebsd.h
@@ -32,41 +32,45 @@
#include <netinet/in= .h>

/* Maximum size of an ioctl reque= st. */
-#define OVPN_MA= X_REQUEST_SIZE 4096
+#define OVPN_MAX_REQUEST_SIZE 4096

-enum ovpn_notif_type {
+enum ovpn_notif_type
+{
OVPN_NOTIF_DEL_= PEER,
OVPN_NOTIF_ROTATE_KEY,
};

-enum ovpn= _del_reason {
- OVPN= _DEL_REASON_REQUESTED =3D 0,
- OVPN_DEL_REASON_TIMEOUT =3D 1
+enum ovpn_del_reason
+{
+ OVPN_DEL_REASON_REQUESTED =3D 0,
+ OVPN_DEL_REASON_TIMEOUT =3D 1=
};

-enum ovpn_key_slot {
- OVPN_KEY_SLOT_PRIMARY =3D 0,
+enum ovpn_key_slot
+{
+ OVPN_KEY_SLOT_PRIMARY =3D 0,
OVPN_KEY_SLOT_SE= CONDARY =3D 1
};

-enum ovpn_key_cipher {
- OVPN_CIPHER_ALG_NONE = =3D 0,
- OVPN_CIPH= ER_ALG_AES_GCM =3D 1,
- OVPN_CIPHER_ALG_CHACHA20_POLY1305 =3D 2+enum ovpn_key_cipher+{
+ OVPN_CIPHER_ALG_NONE =3D 0,
+ OVPN_CIPHER_ALG_AES_GCM =3D 1,=

+ OVPN_CIPHER_ALG= _CHACHA20_POLY1305 =3D 2
};

-#define OVPN_NEW_PEER _I= O('D', 1)

-#def= ine OVPN_DEL_PEER _IO('D', 2)
-#define OVPN_GET_STATS _IO('D', = 3)
-#define OVPN_NEW_KE= Y _IO('D', 4)
-#define OVPN_SWAP_KEYS _IO('D', 5)
-#define OVPN_DEL_KEY _I= O('D', 6)

-#def= ine OVPN_SET_PEER _IO('D', 7)
-#define OVPN_START_VPN _IO('D', = 8)
-#define OVPN_SEND_P= KT _IO('D', 9)
-#define OVPN_POLL_PKT _IO('D', 10)
<= span style=3D"color: hsl(0, 100%, 40%);">-#define OVPN_GET_PKT _= IO('D', 11)

-#d= efine OVPN_SET_IFMODE _IO('D', 12)
-#define OVPN_GET_PEER_STATS _IO('D'= ;, 13)
+#define OVPN_= NEW_PEER _IO('D', 1)
+#define OVPN_DEL_PEER _IO('D', 2)
+#define OVPN_GET_STATS _IO(= 'D', 3)

+#def= ine OVPN_NEW_KEY _IO('D', 4)
+#define OVPN_SWAP_KEYS _IO('D', 5)
+#define OVPN_DEL_KEY = _IO('D', 6)
+#define OVPN_SET_PEER _IO('D', 7)
+#define OVPN_START_VPN _IO('D= 9;, 8)
+#define OVPN_= SEND_PKT _IO('D', 9)
+#define OVPN_POLL_PKT _IO('D', 10)
<= span style=3D"color: hsl(120, 100%, 40%);">+#define OVPN_GET_PKT _IO= ('D', 11)

+#d= efine OVPN_SET_IFMODE _IO('D', 12)
+#define OVPN_GET_PEER_STATS _IO('D', 13)=

#endif /* ifndef _NET_IF_OVPN_H_ */
diff --git a/src/openvpn/packet_id.c b/src/openvpn/packet_id.c=
index 76a81c6..9106e70 100644
--- a/src/op= envpn/packet_id.c
+++ b/src/openvpn/packet_id.c
<= span>@@ -54,20 +54,15 @@

#define SEQ_EXPIRED ((time_t)1)

#ifdef ENABLE_DEBUG
-static void packet_id_debug_print(int msgle= vel,
- = const struct packet_id_rec *p,
- const struct pa= cket_id_net *pin,
- = const char *message,
+static void packet_id_debug_print(int msglev= el, const struct packet_id_rec *p,
+ const struct packet_id_net= *pin, const char *message,
= packet_id_print_type value);

#endif = /* ENABLE_DEBUG */

static inline void
-packet_id_debug(int msgl= evel,
- = const struct packet_id_rec *p,
- const struct packet_id_net *pin,
- const char *message,
- uint64_t= value)
+packet_id_de= bug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net= *pin,
+ = const char *message, uint64_t value)
{
= #ifdef ENABLE_DEBUG
if (unlikely(check_debug_level(ms= glevel)))
@@ -78,7 +73,8 @@
}

static void
-packet_id_init_recv(struct packet_id_rec *rec, int seq_backtra= ck, int time_backtrack, const char *name, int unit)
+packet_id_init_recv(struct packet_id_rec = *rec, int seq_backtrack, int time_backtrack,
+ const char *name, int unit)
{
rec->name =3D name;
rec->unit =3D unit;

@@ -93,10 +89,10 @@ rec->initialized =3D true;
}
void

-packet_id_init= (struct packet_id *p, int seq_backtrack, int time_backtrack, const char *na= me, int unit)
+packet= _id_init(struct packet_id *p, int seq_backtrack, int time_backtrack, const = char *name,
+ = int unit)
{
- dmsg(D_PID_DEBUG, "PID packet_id_init seq_backtrack= =3D%d time_backtrack=3D%d",
- seq_backtrack,
+ dmsg(D_PID_DEBUG, "PID packet_id_init seq_backtrack= =3D%d time_backtrack=3D%d", seq_backtrack,
t= ime_backtrack);

ASSERT(p);@@ -119,8 +115,7 @@

/* Reinit= alise the source */
CLEAR(*src);
- packet_id_init_recv(src, dest->seq_b= acktrack, dest->time_backtrack,
- dest->name, dest->unit);<= br>+ packet_id_init_recv(src= , dest->seq_backtrack, dest->time_backtrack, dest->name, dest->= unit);
}

void@@ -146,10 +141,8 @@
* If time value incre= ases, start a new sequence list of number
* seque= nce for the new time point.
*/
- if (!CIRC_LIST_SIZE(p->seq_li= st)
- || pin= ->time > p->time
- || (pin->id >=3D p->seq_backtrack
- && pin->id = - p->seq_backtrack > p->id))
+ if (!CIRC_LIST_SIZE(p->seq_list) || pin->ti= me > p->time
+ = || (pin->id >=3D p->seq_backtrack && pin->id= - p->seq_backtrack > p->id))
{ p->time =3D pin->time;
= p->id =3D 0;
@@ -164,15 +157,14 @@
#= ifdef PID_SIMULATE_BACKTRACK
|| (get_random= () % 64) < 31
#endif
- )
+ )
{
= CIRC_LIST_PUSH(p->seq_list, SEQ_UNSEEN);
= ++p->id;
}

diff =3D p->id - pin->id;

- if (diff < CIRC_LIST_SIZE(p->seq_list)<= /span>
- &&= local_now > SEQ_EXPIRED)
+ if (diff < CIRC_LIST_SIZE(p->seq_list) && lo= cal_now > SEQ_EXPIRED)
{
= CIRC_LIST_ITEM(p->seq_list, diff) =3D local_now;
= }
@@ -221,8 +213,7 @@
* it is a = replay.
*/
bool
-packet_id_test(struct packet_id_rec *p,=
- const struct = packet_id_net *pin)
+= packet_id_test(struct packet_id_rec *p, const struct packet_id_net *pin)
{
uint64_t diff;

@@ -258,10 +249,11 @@
if (diff >= ; p->max_backtrack_stat)
{
= p->max_backtrack_stat =3D diff;
- packet_id_debug(D_PID_DEBUG= _LOW, p, pin, "PID_ERR replay-window backtrack occurred", p->m= ax_backtrack_stat);
+= packet_id_debug(D_PID_DEBUG_LOW, p, pin, "PID_ERR repl= ay-window backtrack occurred",
+ p->max_backtrack_stat);<= /span>
}

- if (diff >=3D (packet_id_type) CI= RC_LIST_SIZE(p->seq_list))
+ if (diff >=3D (packet_id_type)CIRC_LIST_SIZE(p->= ;seq_list))
{
= packet_id_debug(D_PID_DEBUG_LOW, p, pin, "PID_ERR large diff", d= iff);
return false;
@@ -28= 6,7 +278,7 @@
packet_id_debug(D_PID_DEBUG_LOW,= p, pin, "PID_ERR time backtrack", 0);
= return false;
}
- else /* time moved for= ward */
+ else= /* time moved forward */
{
= return true;
}
@@ -307,7 +2= 99,7 @@
{
return fals= e;
}
- else /* time moved forward */=
+ else /* time moved= forward */
{
return = pin->id =3D=3D 1;
}
@@ -383,8 += 375,7 @@
}

bool<= br>-packet_id_write(struct packet= _id_send *p, struct buffer *buf, bool long_form,
- bool prepend)
+packet_id_write(struct packet_id_send = *p, struct buffer *buf, bool long_form, bool prepend)
{
if (!packet_id_send_update(p, long_form))
{

@@ -432,8 +423,7 @@
buf_print= f(&out, "[ #" packet_id_format, (packet_id_print_type)pin->= ;id);
if (print_timestamp && pin->time)
{
- = buf_printf(&out, " / time =3D (" packet_id_format "= ;) %s",
- = (packet_id_print_type)pin->time,
+ buf_printf(&out, " / time =3D (&= quot; packet_id_format ") %s", (packet_id_print_type)pin->time= ,
time_string(pin->time, 0, false, g= c));
}

@@ -473,13 +4= 63,10 @@
if (!packet_id_persist_enabled(p))
= {
/* open packet-id persist file for bo= th read and write */
- = p->fd =3D platform_open(filename,
- O_CREAT | O_RDWR | O_BI= NARY,
- = S_IRUSR | S_IWUSR);
+ p->fd =3D platform_open(filename, O_CREAT | O_RDWR= | O_BINARY, S_IRUSR | S_IWUSR);
if (p->fd =3D= =3D -1)
{
- msg(D_PID_PERSIST | M_ERRNO,
- "Cannot open --replay-= persist file %s for read/write",
+ msg(D_PID_PERSIST | M_ERRNO, "Cannot ope= n --replay-persist file %s for read/write",
= filename);
}
else<= /span>
@@ -500,14 +487,12 @@
{=
p->time =3D p->time_last_written =3D image= .time;
p->id =3D p->id_last_written = =3D image.id;
- = dmsg(D_PID_PERSIST_DEBUG, "PID Persist Read from %s: %s",=
- = p->filename, packet_id_persist_print(p, &gc));
+ dmsg(D_PID_PERSIST_DEBUG,= "PID Persist Read from %s: %s", p->filename,
+ packet_id_persi= st_print(p, &gc));
}
= else if (n =3D=3D -1)
{
- msg(D_PID_PERSIST | = M_ERRNO,

- = "Read error on --replay-persist file %s",
- p->filename);
+ msg(D= _PID_PERSIST | M_ERRNO, "Read error on --replay-persist file %s",= p->filename);
}
}=
}
@@ -518,8 +503,8 @@
void

packet_id_persist_save(struct packet_id_persist *p)=
{
- = if (packet_id_persist_enabled(p) && p->time && (p->= time !=3D p->time_last_written
- || p->id= !=3D p->id_last_written))
+ if (packet_id_persist_enabled(p) && p->time=
+ && (p->= time !=3D p->time_last_written || p->id !=3D p->id_last_written))<= /span>
{
struct packet_id_persist_fi= le_image image;
ssize_t n;
@@ -536= ,20 +521,18 @@
{
= p->time_last_written =3D p->time;
= p->id_last_written =3D p->id;
- dmsg(D_PID_PERSIST_DEBUG, "PID Persist= Write to %s: %s",
- p->filename, packet_id_persist_print(p, &gc))= ;
+ dm= sg(D_PID_PERSIST_DEBUG, "PID Persist Write to %s: %s", p->file= name,
+ = packet_id_persist_print(p, &gc));
}=
else
{- msg(D_PID_PERSI= ST | M_ERRNO,
- = "Cannot write to --replay-persist file %s",+ msg(D_PID_PER= SIST | M_ERRNO, "Cannot write to --replay-persist file %s",
p->filename);
= }
}
else
{

- = msg(D_PID_PERSIST | M_ERRNO,
- "Cannot seek to beginning of --replay-persi= st file %s",
+ = msg(D_PID_PERSIST | M_ERRNO, "Cannot seek to beginning of --= replay-persist file %s",
p->filena= me);
}
gc_free(&gc);<= /span>
@@ -579,8 +562,7 @@
buf_printf(&am= p;out, " #" packet_id_format, (packet_id_print_type)p->id);
if (p->time)
{- buf_printf(&out= , " / time =3D (" packet_id_format ") %s",
- (packet_id_= print_type)p->time,

-packet_id_debug= _print(int msglevel,
- = const struct packet_id_rec *p,
- const struct packet_i= d_net *pin,
- = const char *message,
- packet_id_print_type value)
+packet_id_debug_print(int msglevel= , const struct packet_id_rec *p, const struct packet_id_net *pin,
+ const c= har *message, packet_id_print_type value)
{
struct gc_arena gc =3D gc_new();

struct buffer = out =3D alloc_buf_gc(256, &gc);
@@ -649,23 +628,13 @@
buf_printf(&out, " %" PRIi64 ":&= quot; packet_id_format, (int64_t)pin->time, pin->id);
}


- buf_printf(&out, " t=3D%" PRIi64 "[%d]",
- (int64_t)= prev_now,
- = (int)(prev_now - tv.tv_sec));
+ buf_printf(&out, " t=3D%" PRIi64 "[%d]&= quot;, (int64_t)prev_now, (int)(prev_now - tv.tv_sec));

- buf_printf(&out= , " r=3D[%d,%" PRIu64 ",%d,%" PRIu64 ",%d]",<= /span>
- (int)(p= ->last_reap - tv.tv_sec),
- p->seq_backtrack,
- p->time_backtrack,
- p->max_backtrack_stat= ,
- (int)= p->initialized);
+= buf_printf(&out, " r=3D[%d,%" PRIu64 ",%d,%" PR= Iu64 ",%d]", (int)(p->last_reap - tv.tv_sec),
+ p->seq_backtrack, = p->time_backtrack, p->max_backtrack_stat, (int)p->initialized);
if (sl !=3D NULL)
{
- buf_printf(&out, " s= l=3D[%d,%d,%d,%d]",

- sl->x_size,
- sl->x_cap,
- sl->x_sizeof);<= /span>
+ buf_printf(&= amp;out, " sl=3D[%d,%d,%d,%d]", sl->x_head, sl->x_size, sl-= >x_cap, sl->x_sizeof);
}


@@ -705,7 +674,7 @@
/* Hi= ghest 16 bits of packet id is the epoch.
*
= * The lower 48 bits are the per-epoch packet id counter. */
- uint64_t net_id =3D (= (uint64_t) epoch) << 48 | p->id;
+ uint64_t net_id =3D ((uint64_t)epoch) << 48= | p->id;

/* convert to network o= rder. This ensures that the highest bytes
* also beco= me the first ones on the wire*/
diff --git a/src/openvpn/pa= cket_id.h b/src/openvpn/packet_id.h
index 6db939f..8982729 = 100644
--- a/src/openvpn/packet_id.h
+++ b/= src/openvpn/packet_id.h
@@ -44,11 +44,11 @@
* These are ephemeral and are never saved to a file.

*= /
typedef uint32_t packet_id_type;
-#define PACKET_ID_MAX UINT32_MAX
-#define PACKET_ID_EPOCH_M= AX 0x0000ffffffffffffull
+#define PACKET_ID_MAX UINT32_MAX
+#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull<= /span>
/** Mask of the bits that contain the 48-bit of the per-ep= och packet
* counter in the packet id*/
-#define PACKET_ID_MASK 0x0000ffff= ffffffffull
+#define = PACKET_ID_MASK 0x0000ffffffffffffull
typedef uint32_t= net_time_t;

/*
@@ -82,8= +82,8 @@
* sequence number due to packets arriving
* out of order.
*/
-#define MIN_SEQ_BACKTRACK 0
-#define MAX_SEQ_BACKTRACK 65536+#define MIN_SEQ_BACKTRACK = 0
+#define MAX_SEQ_B= ACKTRACK 65536
#define DEFAULT_SEQ_BACKTRACK 64=

/*
@@ -91,8 +91,8 @@ * seconds due to packets arriving
* out of order= .
*/
= -#define MIN_TIME_BACKTRACK 0
-#define MAX_TIME_BACKTRACK 600
+#define MIN_TIME_BACKTRACK 0
+#define MAX_TIME_BACKTRACK 600=
#define DEFAULT_TIME_BACKTRACK 15

/*

@@ -113,14 +113,14 @@
*/ struct packet_id_rec
{
- time_t last_reap; /* last call of pa= cket_id_reap */
- ti= me_t time; /* highest time stamp received */
- uint64_t id; /* highes= t sequence number received */
- uint64_t seq_backtrack; /* set from --replay-window */=
- int time_backtrack; = /* set from --replay-window */
- uint64_t max_backtrack_stat; /* maximum backtrack seen so = far */
- bool initia= lized; /* true if packet_id_init was called */
- struct seq_list *seq_list; /* packet-i= d "memory" */
+ time_t last_reap; /* last call of packet_id_reap */
+ time_t time; = /* highest time stamp received */
+ uint64_t id; /* highest sequence= number received */
+= uint64_t seq_backtrack; /* set from --replay-window */
<= span style=3D"color: hsl(120, 100%, 40%);">+ int time_backtrack; = /* set from --replay-window */

+ uint64_t max_backtrack_stat; /* maximum backtrack seen so = far */
+ bool init= ialized; /* true if packet_id_init was called */
+ struct seq_list *seq_list; /*= packet-id "memory" */

const char *name;
int unit;
};
@@ -133,16 = +133,16 @@
{
const char *filename;
int fd;
- time_t time; /* time stamp */
- packet_id_type id; /* sequence number */=
+ time_t time; = /* time stamp */
= + packet_id_type id; /* sequence number */
time_t t= ime_last_written;
packet_id_type id_last_written;
};

struct packet_id_persist= _file_image
{
- time_t time; /* time stamp */
- packet_id_type id; /* sequence numb= er */
+ time_t tim= e; /* time stamp */
+ packet_id_type id; /* sequence number */
};

/*
@@ -202,7 +202,8 @@
struct packet_id_rec rec;
};

-void packet_id_in= it(struct packet_id *p, int seq_backtrack, int time_backtrack, const char *= name, int unit);
+voi= d packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack= , const char *name,
+= int unit);

void pack= et_id_free(struct packet_id *p);

@@ -210,= 16 +211,13 @@
* Move the packet id recv structure from \c= src to \c dest. \c src will
* be reinitialised. \c dest = will be freed before the move.
*/
-void
-packet_id_move_recv(struct packet_id_rec *dest, struct packe= t_id_rec *src);
+void= packet_id_move_recv(struct packet_id_rec *dest, struct packet_id_rec *src)= ;

/* should we accept an incoming packet= id ? */
-bool packet_i= d_test(struct packet_id_rec *p,
- const struct packet_id_net *pin);
<= span style=3D"color: hsl(120, 100%, 40%);">+bool packet_id_test(struct pack= et_id_rec *p, const struct packet_id_net *pin);

/* change our current state to reflect an accepted packet id */
-void packet_id_add(struct= packet_id_rec *p,
- = const struct packet_id_net *pin);
+void packet_id_add(struct packet_id_rec *p, c= onst struct packet_id_net *pin);

/* expi= re TIME_BACKTRACK sequence numbers */
void packet_id_reap(= struct packet_id_rec *p);
@@ -263,8 +261,7 @@
*

* @return true if successful, false otherwise.
*/
-bool= packet_id_write(struct packet_id_send *p, struct buffer *buf,
- bool long_for= m, bool prepend);

+bo= ol packet_id_write(struct packet_id_send *p, struct buffer *buf, bool long_= form, bool prepend);

/*
= * Inline functions.
@@ -310,7 +307,8 @@
= p->id =3D 0;
}

-const char *packet_id_net_print(const st= ruct packet_id_net *pin, bool print_timestamp, struct gc_arena *gc);=
+const char *packet_id_net_= print(const struct packet_id_net *pin, bool print_timestamp,
+ st= ruct gc_arena *gc);


static inline int
packet_id_size(bool long_form)
@@ -341,8 +33= 9,7 @@
* @param buf buffer to write the packet id/e= poch to
* @return false if the packet id space i= s exhausted and cannot be written
*/
-bool
-packet_id_write_epoch(struct packet_id_send *p, uint16_t ep= och, struct buffer *buf);
+bool packet_id_write_epoch(struct packet_id_send *p, uint16_t epoch, = struct buffer *buf);

/**
* Reads the packet ID containing both the epoch and the per-epoch counte= r

@@ -351,7 +348,6 @@
* @param buf bu= ffer to read the packet id from.
* @return 0 for a= n error/invalid id, epoch otherwise
*/
-uint16_t
-packet_id_read_epoch(struct packet_id_net *p, struct = buffer *buf);
+uint16= _t packet_id_read_epoch(struct packet_id_net *p, struct buffer *buf);

#endif /* PACKET_ID_H */
diff= --git a/src/openvpn/perf.c b/src/openvpn/perf.c
index 71c0= 0e5..78457e9 100644
--- a/src/openvpn/perf.c
+++ b/src/openvpn/perf.c

@@ -36,34 +36,32 @@

#include "memdbg.h"

-static const char *metric_= names[] =3D {
- &quo= t;PERF_BIO_READ_PLAINTEXT",
- "PERF_BIO_WRITE_PLAINTEXT",
- "PERF_BIO_READ_CIPHERTEXT",
- "PERF_BIO_WRIT= E_CIPHERTEXT",
- = "PERF_TLS_MULTI_PROCESS",
- "PERF_IO_WAIT",
- "PERF_EVENT_LOOP",
- "PERF_MULTI_CREATE_INSTANCE&quo= t;,
- "PERF_MUL= TI_CLOSE_INSTANCE",
- "PERF_MULTI_BCAST",
- "PERF_MULTI_MCAST",- "PERF_SCRIPT",
- "PERF_READ_IN_L= INK",
- "P= ERF_PROC_IN_LINK",
- "PERF_READ_IN_TUN",
- "PERF_PROC_IN_TUN",
- "PERF_PROC_OUT_LINK",
- "PERF_PROC_OUT_TUN",<= /span>
- "PERF_PROC_OU= T_TUN_MTCP"
-};
+static const char *met= ric_names[] =3D { "PERF_BIO_READ_PLAINTEXT",
+ &q= uot;PERF_BIO_WRITE_PLAINTEXT",
+ "PERF_BIO_READ_C= IPHERTEXT",
+ = "PERF_BIO_WRITE_CIPHERTEXT",
+ = "PERF_TLS_MULTI_PROCESS",
+ &qu= ot;PERF_IO_WAIT",
+ = "PERF_MULTI_CREATE_INSTANCE",
+ &qu= ot;PERF_MULTI_CLOSE_INSTANCE",
+ "PERF_MULTI_SHOW= _STATS",
+ = "PERF_MULTI_BCAST",
+ = "PERF_MULTI_MCAST",

+ "PERF_SCRIPT"= ;,
+ = "PERF_READ_IN_LINK",
+ &qu= ot;PERF_PROC_IN_LINK",
+ "PERF_READ_IN_TUN",=
+ = "PERF_PROC_IN_TUN",
+ "PE= RF_PROC_OUT_LINK",
+ "PERF_PROC_OUT_TUN",
+ = "PERF_PROC_OUT_TUN_MTCP" };

struct perf
{
-#define PS_INITIAL 0
-#define PS_METER_RUNNING 1
= -#define PS_METER_INTERRUPTED 2<= /span>
+#define PS_INITIAL = 0
+#define P= S_METER_RUNNING 1
+#define PS_METER_INTERRUPTED 2
int state;
=
struct timeval start;
@@ -139,= 8 +137,7 @@
{
const int sindex =3D ge= t_stack_index(0);
const int newlen =3D get_stack_index= (1);
- if (sindex &g= t;=3D 0 && newlen >=3D 0
- && pindex >=3D 0 && pindex < PE= RF_N)
+ if (sindex= >=3D 0 && newlen >=3D 0 && pindex >=3D 0 &&am= p; pindex < PERF_N)
{
int = i;
for (i =3D 0; i < sindex; ++i)
@@ -148,8 +145,7 @@

if (perf_set.stack[i] = =3D=3D pindex)
{
= perf_print_state(M_INFO);
- msg(M_FATAL, "PERF: push_perf_index %s failed&= quot;,
- = metric_names [pindex]);
+ msg(M_FATAL, "PERF: push_perf_index %s failed= ", metric_names[pindex]);
}
}


@@ -181,9 +177,7 @@<= br> {
if (p->state !=3D wanted)
{

- msg(= M_FATAL, "PERF: bad state actual=3D%d wanted=3D%d",
- p->state,

= - wanted);
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(M_FATAL, "PERF= : bad state actual=3D%d wanted=3D%d", p->state, wanted);

= }
}

@@ -192,7= +186,7 @@
{
struct timeval current;<= /span>
ASSERT(!gettimeofday(&current, NULL));
<= span style=3D"color: hsl(0, 100%, 40%);">- p->sofar +=3D (double) tv_= subtract(&current, &p->start, 600) / 1000000.0;

+ p->sofar +=3D (double)tv_subt= ract(&current, &p->start, 600) / 1000000.0;
= tv_clear(&p->start);
}
@@ -288,7 +282,8 @@
if (p->count > 0.= 0)
{
const double mea= n =3D p->sum / p->count;
- msg(M_INFO, "%s n=3D%.0f mean=3D%.3f max=3D%.3f&q= uot;, metric_names[i], p->count, mean*1000.0, p->max*1000.0);<= br>+ msg(M_INFO, &qu= ot;%s n=3D%.0f mean=3D%.3f max=3D%.3f", metric_names[i], p->count, = mean * 1000.0,
+ = p->max * 1000.0);
}
= }
}
@@ -304,15 +299,8 @@
{

const int j =3D perf_set.stack[i];
const struct perf *p =3D &perf_set.perf[j];=
- msg(lev, "[%d] = %s state=3D%d start=3D%s sofar=3D%f sum=3D%f max=3D%f count=3D%f",
- i,
= - metric_names[j],
- p->state,<= /span>
- tv_string(= &p->start, &gc),
- p->sofar,
- p->sum,
- p->max,
- p->count);
+ msg(lev, "[%d] %s state=3D%d start=3D%s sofar= =3D%f sum=3D%f max=3D%f count=3D%f", i, metric_names[j],
+ p->state, tv_strin= g(&p->start, &gc), p->sofar, p->sum, p->max, p->coun= t);

}
gc_free(&gc); }
diff --git a/src/openvpn/perf.h b/src/openvpn/per= f.h
index 5ddebeb..06d5093 100644
--- a/src= /openvpn/perf.h
+++ b/src/openvpn/perf.h
@@= -35,27 +35,27 @@
/*
* Metrics */
-#define PE= RF_BIO_READ_PLAINTEXT 0
-#define PERF_BIO_WRITE_PLAINTEXT 1
-#define PERF_BIO_READ_CIPHERTEXT 2
-#define PERF_BIO_WRITE_CIPHERTEXT 3=

-#define PERF_TLS_MULT= I_PROCESS 4
-#defi= ne PERF_IO_WAIT 5
-#define PERF_EVENT_LOOP 6
-#define PERF_MULTI_CREATE_INSTANCE 7
= -#define PERF_MULTI_CLOSE_INSTANC= E 8
-#define PERF_MUL= TI_SHOW_STATS 9
-= #define PERF_MULTI_BCAST 10
-#define PERF_MULTI_MCAST 11
-#define PERF_SCRIPT 12
-#define PERF_READ_IN_LIN= K 13
-#define= PERF_PROC_IN_LINK 14
-#define PERF_READ_IN_TUN 15
-#define PERF_PROC_IN_TUN 16-#define PERF_PROC_OUT_LINK = 17
-#define PERF_P= ROC_OUT_TUN 18
-#define PERF_N 20
+#define PERF_BIO_READ_PLAINTEXT 0=
+#define PERF_BIO_WR= ITE_PLAINTEXT 1
+#d= efine PERF_BIO_READ_CIPHERTEXT 2
+#define PERF_BIO_WRITE_CIPHERTEXT 3
+#define PERF_TLS_MULTI_PROCESS 4
+#define PERF_IO_WAIT = 5
+#define= PERF_EVENT_LOOP 6
+#define PERF_MULTI_CREATE_INSTANCE 7
+#define PERF_MULTI_CLOSE_INSTANCE 8
<= span style=3D"color: hsl(120, 100%, 40%);">+#define PERF_MULTI_SHOW_STATS = 9

+#define PERF_M= ULTI_BCAST 10
+#define PERF_MULTI_MCAST 11
+#define PERF_SCRIPT 12
+#define PERF_READ_IN_LINK = 13

+#define PERF_PROC= _IN_LINK 14
= +#define PERF_READ_IN_TUN 15
+#define PERF_PROC_IN_TUN 16
+#define PERF_PROC_OUT_LINK 17<= /span>
+#define PERF_PROC_OU= T_TUN 18
+#d= efine PERF_PROC_OUT_TUN_MTCP 19
+#define PERF_N 20

#ifdef ENABLE_PERFORMANCE_METRICS
@@ -64,7 +64,7 @@
/*
* Stack size=
*/
-= #define STACK_N 64
+#define STACK_N 64

void per= f_push(int type);

diff --git a/src/openvp= n/ping.c b/src/openvpn/ping.c
index f570d95..0fdca7b 100644=
--- a/src/openvpn/ping.c
+++ b/src/openvpn= /ping.c
@@ -39,10 +39,8 @@
*
* PING_STRING_SIZE must be sizeof (ping_string)

*/<= /span>
-const uint8_t ping_str= ing[] =3D {
- 0x2a, = 0x18, 0x7b, 0xf3, 0x64, 0x1e, 0xb4, 0xcb,
- 0x07, 0xed, 0x2d, 0x0a, 0x98, 0x1f, 0xc7, 0x48
-};
+const uint8_t ping_string[] =3D { 0x2a, 0= x18, 0x7b, 0xf3, 0x64, 0x1e, 0xb4, 0xcb,
+ 0x07, 0xed, 0x2d, 0x0a= , 0x98, 0x1f, 0xc7, 0x48 };

void<= br> trigger_ping_timeout_signal(struct context *c)
@@= -51,8 +49,7 @@
switch (c->options.ping_rec_timeout= _action)
{
case PING_EXIT:
- msg(M_INFO, = "%sInactivity timeout (--ping-exit), exiting",
- format_common_name(c, &a= mp;gc));
+ = msg(M_INFO, "%sInactivity timeout (--ping-exit), exiting", forma= t_common_name(c, &gc));
register_signal(c-= >sig, SIGTERM, "ping-exit");
brea= k;

diff --git a/src/openvpn/ping.h b/src/= openvpn/ping.h
index 4cb89b4..085b52f 100644
--- a/src/openvpn/ping.h

+++ b/src/openvpn/ping.h<= br>@@ -30,7 +30,7 @@
/*
* Initial = default --ping-restart before --pull
*/
-#define PRE_PULL_INITIAL_PING_RESTART 1= 20 /* in seconds */
= +#define PRE_PULL_INITIAL_PING_RESTART 120 /* in seconds */

extern const uint8_t ping_string[];

@@ -60,11 +60,11 @@
check_ping_restart(stru= ct context *c)
{
if (c->options.pi= ng_rec_timeout
- = && event_timeout_trigger(&c->c2.ping_rec_interval,- = &c->c2.timeval,
+ && event_timeout_trigger(&c->c2.ping_rec_inter= val, &c->c2.timeval,
= (!c->options.ping_timer_remote
= || link_socket_actual_defined(&c->c1.link_socket_addrs[= 0].actual))
- = ? ETT_DEFAULT : 15))
+ ? ETT_DEFAULT<= /span>
+ = : 15))
{
tri= gger_ping_timeout_signal(c);
}
@@ -77,= 8 +77,7 @@
check_ping_send(struct context *c)
{

if (c->options.ping_send_timeout
<= span style=3D"color: hsl(0, 100%, 40%);">- && event_timeout_= trigger(&c->c2.ping_send_interval,

- &c->c2.timeval,=
+ && = event_timeout_trigger(&c->c2.ping_send_interval, &c->c2.timev= al,
!TO_LINK_DEF(c) ? ETT= _DEFAULT : 1))
{
check_ping_s= end_dowork(c);
diff --git a/src/openvpn/pkcs11.c b/src/open= vpn/pkcs11.c
index 00428d8..c13903e 100644
= --- a/src/openvpn/pkcs11.c
+++ b/src/openvpn/pkcs11.c
@@ -40,51 +40,41 @@
#include "console.h&qu= ot;
#include "pkcs11_backend.h"
=
-static
-time_t

+static time_t
__mytime(void)
{
return openvpn_time(NULL);
= }

#if !defined(_WIN32)
= -static
-int
+static int
__mygettimeofday(struct timeval *tv= )
{
return gettimeofday(tv, NULL);
}
#endif

-static
-void
+static void
__mysleep(const unsigned long usec)
{
#if defined(_WIN32)
- Sleep(usec/1000);
+ Sleep(usec / 1000);
= #else
usleep(usec);
#endif
= }


-static pkcs11h_engine_system_t s_pkcs11h_sys_engine = =3D {
- malloc,
- free,
- __mytime,
- __mysleep,
+static pkcs11h_engine_system_t s_pkcs11h_sys_engine= =3D { malloc, free, __mytime, __mysleep,
#if defined(_WIN= 32)
- NULL+ = NULL
#else
- __mygettimeofday
+ = __mygettimeofday
#endif
};=

-sta= tic
-unsigned-_pkcs11_msg_pkcs112openvpn(
- const unsigned flags<= /span>
- )
+static unsigned
+_pkcs11_msg_pkcs112openvpn(const unsigne= d flags)
{
unsigned openvpn_flags;

@@ -122,11 +112,8 @@
r= eturn openvpn_flags;
}

-static
-unsigned
-_pkcs11_msg_openvpn2pkcs11(
- const unsigned flags
- )
+_= pkcs11_msg_openvpn2pkcs11(const unsigned flags)
{ unsigned pkcs11_flags;

@@ -1= 62,33 +149,23 @@
return pkcs11_flags;
= }

-s= tatic
-void
<= span style=3D"color: hsl(0, 100%, 40%);">-_pkcs11_openvpn_log(

- void *const global_data,
- unsigned flags,<= br>- const char *const szForma= t,
- va_list args

- )
+static void
+_pkcs11_openvpn_log(void *const global_data, u= nsigned flags, const char *const szFormat,
+ va_list args)
{=
- char Buffer[10*10= 24];
+ char Buffer= [10 * 1024];

(void)global_data;

vsnprintf(Buffer, sizeof(Buffer), szForm= at, args);
- Buffer[= sizeof(Buffer)-1] =3D 0;
+ Buffer[sizeof(Buffer) - 1] =3D 0;

msg(_pkcs11_msg_pkcs112openvpn(flags), "%s", Buffer);
}

-static
-PKCS= 11H_BOOL
-_pkcs11_openv= pn_token_prompt(
- v= oid *const global_data,
- void *const user_data,
- const pkcs11h_token_id_t token,
- const unsigned retry
- )
+static PKCS11H_BOOL
+_pkcs11_openvpn_token_prompt(void *const global_data, void *const= user_data,
+ = const pkcs11h_token_id_t token, const unsigned retry)<= /span>
{
struct user_pass token_resp;=

@@ -196,26 +173,16 @@
(voi= d)user_data;
(void)retry;

= - ASSERT(token!=3DNULL);
+ ASSERT(token !=3D NUL= L);

CLEAR(token_resp);
token_resp.defined =3D false;

token_resp.nocac= he =3D true;
- snpri= ntf(
- token_res= p.username,
- si= zeof(token_resp.username),
- "Please insert %s token",
- token->label
- );
+ snprintf(token_resp.username, sizeof(token_resp.use= rname), "Please insert %s token",
+ token->label);

- if (
- !get_user_pass(

- &token_resp,
=
- NULL,
= - "token-insertio= n-request",
- = GET_USER_PASS_MANAGEMENT|GET_USER_PASS_NEED_OK|GET_USER_PASS_NOFATAL=
- )<= br>- )
+ if (!get_user_pass(&token_resp,= NULL, "token-insertion-request",
+ GET_USER_PASS_MANAGEMENT | G= ET_USER_PASS_NEED_OK | GET_USER_PASS_NOFATAL))
{
return false;
}
@@= -225,16 +192,10 @@
}
}

-static
= -PKCS11H_BOOL
-_pkcs11_openvpn_pin_prompt(
- void *const global_data,
=
- void *const user_data,
- const pkcs11h_token= _id_t token,
- const= unsigned retry,
- c= har *const pin,
- co= nst size_t pin_max
- = )
+static PKCS11H_BO= OL
+_pkcs11_openvpn_p= in_prompt(void *const global_data, void *const user_data,
+ const pkcs= 11h_token_id_t token, const unsigned retry, char *const pin,
+ const s= ize_t pin_max)

{
struct user_pass tok= en_pass;
char prompt[1024];
@@ -244,21= +205,16 @@
(void)user_data;
(voi= d)retry;

- ASSERT(token!=3DNULL);
+ ASSERT(token !=3D NULL);

= snprintf(prompt, sizeof(prompt), "%s token", token->label= );

token_pass.defined =3D false;
token_pass.nocache =3D true;

= - if (
- !get_user_pass(
- &token_pass,
- NULL,

- prompt,
- GET_USER_PASS_MANAGEMENT|GET= _USER_PASS_PASSWORD_ONLY|GET_USER_PASS_NOFATAL
- )
- )
+ if (!get_user_pass(&token_pass, NULL, prompt,
+ GET_USER_PA= SS_MANAGEMENT | GET_USER_PASS_PASSWORD_ONLY

+ | GET_USER_PASS_NOFATAL)= )
{
return false;
<= span> }

@@ -279,21 +235,16 @@
}=

bool
-pkcs11_initialize(
- const bool protected_auth,
- const int nPINCachePeriod
- )
+pkcs11_initialize(const bool protected_auth, const int nPINCach= ePeriod)
{
CK_RV rv =3D CKR_FUNCTION_= FAILED;

- dmsg(
- = D_PKCS11_DEBUG,
- = "PKCS#11: pkcs11_initialize - entered"
- );
+ dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_initiali= ze - entered");

if ((rv =3D pkc= s11h_engine_setSystem(&s_pkcs11h_sys_engine)) !=3D CKR_OK)
{

- msg= (M_FATAL, "PKCS#11: Cannot initialize system engine %ld-'%s'&q= uot;, rv, pkcs11h_getMessage(rv));
+ msg(M_FATAL, "PKCS#11: Cannot initialize system= engine %ld-'%s'", rv,
+ pkcs11h_getMessage(rv));
= goto cleanup;
}

@= @ -331,7 +282,8 @@

if ((rv =3D pkcs1= 1h_setProtectedAuthentication(protected_auth)) !=3D CKR_OK)
{

- msg(M_= FATAL, "PKCS#11: Cannot set protected authentication mode %ld-'%s&= #39;", rv, pkcs11h_getMessage(rv));
+ msg(M_FATAL, "PKCS#11: Cannot set protect= ed authentication mode %ld-'%s'", rv,
+ pkcs11h_getMessage(rv));<= br> goto cleanup;
}

@@ -344,12 +296,8 @@
rv =3D CKR_OK;

cleanup:
- dmsg(
- D_PKCS11_DEBUG,
- "PKCS#11: pkcs11_initialize - return %ld-'%s'&= quot;,
- rv,
- pkcs11h_getMessag= e(rv)
- );
+ dmsg(D_PKCS11_DEBUG, = "PKCS#11: pkcs11_initialize - return %ld-'%s'", rv,
+ pkcs11h_getMessa= ge(rv));

return rv =3D=3D CKR_OK;
}
@@ -357,105 +305,85 @@
vo= id
pkcs11_terminate(void)
{
- dmsg(

- D_PKCS11_DEBUG,
- "PKCS#11: pkcs11_terminate - e= ntered"
- )= ;
+ dmsg(D_PKCS11_= DEBUG, "PKCS#11: pkcs11_terminate - entered");
<= /span>
pkcs11h_terminate();

- dmsg(

- D_PKCS11_DEBUG,
- "PKCS#11: pkcs11_terminate - retur= n"
- );
+ dmsg(D_PKCS11_DEBUG= , "PKCS#11: pkcs11_terminate - return");
}

bool
-pkcs11_addProvider(
- const char *const provider,
- const bool protected_auth,
- const unsigned private_mode,
= - const bool cert_private
- )
+pkcs11_addProvider(const char *const pro= vider, const bool protected_auth,
+ const unsigned private_mode, const bool ce= rt_private)
{
CK_RV rv =3D CKR_OK;

- AS= SERT(provider!=3DNULL);
+ ASSERT(provider !=3D NULL);

- dmsg(
- D_PKCS11_DEBUG,
- "PKCS#11: pkcs11_addProvider - entered -= provider=3D'%s', private_mode=3D%08x",
- provider,
- private_mode
- );
+ dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_addProvide= r - entered - provider=3D'%s', private_mode=3D%08x",+ provider, private_mo= de);

= - msg(
- M_IN= FO,
- "PKCS= #11: Adding PKCS#11 provider '%s'",
- provider
- );
+ msg(M_INFO, "PKCS#11: Adding PKCS#11 provider '%s= '", provider);

-#if PKCS11H_VERSION >=3D ((1<<16) | (28<<= ;8) | (0<<0))
+= #if PKCS11H_VERSION >=3D ((1 << 16) | (28 << 8) | (0 <<= ; 0))
if ((rv =3D pkcs11h_registerProvider(provider)) = !=3D CKR_OK)
{
- msg(M_WARN, "PKCS#11: Cannot register provider &= #39;%s' %ld-'%s'", provider, rv, pkcs11h_getMessage(rv));<= /span>
+ msg(M_WARN, = "PKCS#11: Cannot register provider '%s' %ld-'%s'"= , provider, rv,
+ = pkcs11h_getMessage(rv));
}
= else
{
PKCS11H_BOOL allow_p= rotected_auth =3D protected_auth;
PKCS11H_BOOL cer= t_is_private =3D cert_private;

- rv =3D pkcs11h_setProviderProperty(provi= der, PKCS11H_PROVIDER_PROPERTY_LOCATION, provider, strlen(provider) + 1);
+ rv =3D pkcs11= h_setProviderProperty(provider, PKCS11H_PROVIDER_PROPERTY_LOCATION, provide= r,
+ = strlen(provider) + 1);

= if (rv =3D=3D CKR_OK)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- rv =3D pkcs11h_setPro= viderProperty(provider, PKCS11H_PROVIDER_PROPERTY_ALLOW_PROTECTED_AUTH, &am= p;allow_protected_auth, sizeof(allow_protected_auth));

+ rv =3D pkcs11h_setProviderPr= operty(provider,
+ = PKCS11H_PROVIDER_PROPERTY_ALLOW_P= ROTECTED_AUTH,
+ = &allow_protected_auth, sizeof(a= llow_protected_auth));
}
= if (rv =3D=3D CKR_OK)
{
- rv =3D pkcs11h_setProviderProperty(p= rovider, PKCS11H_PROVIDER_PROPERTY_MASK_PRIVATE_MODE, &private_mode, si= zeof(private_mode));
= + rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER_= PROPERTY_MASK_PRIVATE_MODE,
+ &private_mode, siz= eof(private_mode));
}
if = (rv =3D=3D CKR_OK)
{
- rv =3D pkcs11h_setProviderProperty(prov= ider, PKCS11H_PROVIDER_PROPERTY_CERT_IS_PRIVATE, &cert_is_private, size= of(cert_is_private));
+ rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_PROVIDER= _PROPERTY_CERT_IS_PRIVATE,
+ &cert_is_private, s= izeof(cert_is_private));
}
#if de= fined(WIN32) && defined(PKCS11H_PROVIDER_PROPERTY_LOADER_FLAGS)
if (rv =3D=3D CKR_OK && platform_absolute_pat= hname(provider))
{
- unsigned loader_flags =3D LOAD_LIBRARY_SE= ARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
- rv =3D pkcs11h_setProviderPrope= rty(provider, PKCS11H_PROVIDER_PROPERTY_LOADER_FLAGS, &loader_flags, si= zeof(loader_flags));
= + unsigned loader_flags =3D
+ LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_= LIBRARY_SEARCH_DLL_LOAD_DIR;
+ rv =3D pkcs11h_setProviderProperty(provider, PKCS11H_P= ROVIDER_PROPERTY_LOADER_FLAGS,
+ &loader_flags, = sizeof(loader_flags));
}
#endif

if (rv !=3D CKR_OK || (rv =3D pkc= s11h_initializeProvider(provider)) !=3D CKR_OK)
{<= /span>
- msg(M_WARN= , "PKCS#11: Cannot initialize provider '%s' %ld-'%s'&q= uot;, provider, rv, pkcs11h_getMessage(rv));
+ msg(M_WARN, "PKCS#11: Cannot init= ialize provider '%s' %ld-'%s'", provider, rv,+ pkcs11h_getM= essage(rv));
pkcs11h_removeProvider(provider);=
}
}
#else = /* if PKCS11H_VERSION >=3D ((1<<16) | (28<<8) | (0<<0)= ) */
- if (- (rv =3D pkcs11h_addPro= vider(
- pr= ovider,
- p= rovider,
- = protected_auth,
- = private_mode,
- = PKCS11H_SLOTEVENT_METHOD_AUTO,
- 0,
- cert_private
- )) !=3D CKR_OK
- )
+ if ((rv =3D pkcs11h_addProvider(provider, provider, prot= ected_auth, private_mode,
+ PKCS11H_SLOTEVENT_METHOD_AUTO, 0, c= ert_private))
+ = !=3D CKR_OK)
{
- msg(M_WARN, "PKCS#11: Cannot initialize provid= er '%s' %ld-'%s'", provider, rv, pkcs11h_getMessage(rv= ));
+ msg(M_WA= RN, "PKCS#11: Cannot initialize provider '%s' %ld-'%s'= ", provider, rv,
+ pkcs11h_getMessage(rv));
}
#endif /* if PKCS11H_VERSION >=3D ((1<<16) | (28<<8) | (= 0<<0)) */


- dmsg(
-= D_PKCS11_DEBUG,
- "PKCS#11: pkcs11_addProvider - return rv=3D%ld-'%s'&= quot;,
- rv,
- pkcs11h_getMessag= e(rv)
- );
+ dmsg(D_PKCS11_DEBUG, = "PKCS#11: pkcs11_addProvider - return rv=3D%ld-'%s'", rv,=
+ pkcs11h_ge= tMessage(rv));

return rv =3D=3D CKR_= OK;
}
@@ -474,20 +402,11 @@
CK_RV rv =3D CKR_OK;

int count =3D 0;
- dmsg(
- D_PKCS11_DEBUG,
- "PKCS#11: = pkcs11_management_id_count - entered"
- );
+ dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_management_id_co= unt - entered");

- if (
- (rv =3D pkcs11h_certificate_enumCertificateIds(
- PKCS11H_ENUM_METHOD_CAC= HE_EXIST,

- = NULL,
- PK= CS11H_PROMPT_MASK_ALLOW_ALL,
- NULL,
- &id_list
- )) !=3D CKR_OK
- )
+ if ((rv =3D pkcs11h_certificate_enumCertificateIds(PKCS11H_ENUM_MET= HOD_CACHE_EXIST, NULL,
+ !=3D CKR_OK)
{
= msg(M_WARN, "PKCS#11: Cannot get certificate list %ld-'%s&#= 39;", rv, pkcs11h_getMessage(rv));
goto clean= up;
@@ -503,21 +422,13 @@
pkcs11h_cert= ificate_freeCertificateIdList(id_list);
id_list =3D NU= LL;

-= dmsg(
- D_PK= CS11_DEBUG,
- &q= uot;PKCS#11: pkcs11_management_id_count - return count=3D%d",- count
- );
+ dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_= management_id_count - return count=3D%d", count);

return count;
}

bool
-pkcs1= 1_management_id_get(
- = const int index,
- = char **id,
- char = **base64
- )<= br>+pkcs11_management_id_get(co= nst int index, char **id, char **base64)
{
pkcs11h_certificate_id_list_t id_list =3D NULL;

= pkcs11h_certificate_id_list_t entry =3D NULL;
@@ -534,27 +4= 45,17 @@
int count =3D 0;
bool su= ccess =3D false;

- ASSERT(id!=3DNULL);
- ASSERT(base64!=3DNULL);
+ ASSERT(id !=3D NULL);
+ ASSERT(base64 !=3D NULL);
=
- dmsg(
= - D_PKCS11_DEBUG,- "PKCS#11: pkcs11_= management_id_get - entered index=3D%d",
- index
- );
+ dmsg(D_PKCS11_DEBUG, "PKCS#11: pkcs11_management_id_get - e= ntered index=3D%d", index);

*id= =3D NULL;
*base64 =3D NULL;
<= br>- if (
- (rv =3D pkcs11h_certificate_enumCe= rtificateIds(
- = PKCS11H_ENUM_METHOD_CACHE_EXIST,
- NULL,
- PKCS11H_PROMPT_MASK_ALLOW_ALL,
- NULL,
- &id_list
- )) !=3D CKR_OK
<= span style=3D"color: hsl(0, 100%, 40%);">- )

+ if ((rv =3D pkcs11h_certificate_enumC= ertificateIds(PKCS11H_ENUM_METHOD_CACHE_EXIST, NULL,
+ = PKCS11H_PROMPT_MASK_ALLOW_ALL, NULL, &id_list))
<= span style=3D"color: hsl(120, 100%, 40%);">+ !=3D CKR_OK)

= {
msg(M_WARN, "PKCS#11: Cannot get= certificate list %ld-'%s'", rv, pkcs11h_getMessage(rv));
goto cleanup;
@@ -570,23 +471,16 @@

if (entry =3D=3D NULL)
{

- dmsg(<= /span>
- D_PKCS11_D= EBUG,
- &quo= t;PKCS#11: pkcs11_management_id_get - no certificate at index=3D%d",
- index
- );
+ dmsg(D_PKCS11_DEBUG, &qu= ot;PKCS#11: pkcs11_management_id_get - no certificate at index=3D%d",<= /span>
+ index);=
goto cleanup;
}

- if (<= br>- (rv =3D pkcs11h_certi= ficate_serializeCertificateId(
- NULL,
- &max,
- entry->certificate_id
- )) !=3D CKR_OK
- )
+ if ((rv =3D pkcs11h_certificate_serializeCertificate= Id(NULL, &max, entry->certificate_id))
+ !=3D CKR_OK)
{
- msg(M_WARN, "P= KCS#11: Cannot serialize certificate id %ld-'%s'", rv, pkcs11h= _getMessage(rv));
+ = msg(M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%= s'", rv,
+ = pkcs11h_getMessage(rv));
goto cleanup;
}

@@ -596,39 +490,24 = @@
goto cleanup;
}
=
- if (
- (rv =3D pkcs11h_cer= tificate_serializeCertificateId(
- internal_id,
- &max,
- entry->certificate_id
- )) !=3D CKR_OK
- )

+ if ((rv =3D pkcs11h_certificate_serializeCe= rtificateId(internal_id, &max, entry->certificate_id))
+ !=3D CKR_OK)

{

- msg= (M_WARN, "PKCS#11: Cannot serialize certificate id %ld-'%s'&qu= ot;, rv, pkcs11h_getMessage(rv));
+ msg(M_WARN, "PKCS#11: Cannot serialize certifica= te id %ld-'%s'", rv,
+ pkcs11h_getMessage(rv));
= goto cleanup;
}

- if (
- (rv =3D pkcs11h_certificate_create(
= - entry->certifica= te_id,
- NU= LL,
- PKCS1= 1H_PROMPT_MASK_ALLOW_ALL,
- PKCS11H_PIN_CACHE_INFINITE,
- &certificate
- )) !=3D CKR_OK
- )

+ if ((rv =3D pkcs11h_certificate_create(entr= y->certificate_id, NULL, PKCS11H_PROMPT_MASK_ALLOW_ALL,
+ = PKCS11H_PIN_CACHE_INFINITE, &certificate))
+ !=3D CKR_OK)
= {
msg(M_WARN, "PKCS#11: Cannot get certifica= te %ld-'%s'", rv, pkcs11h_getMessage(rv));
= goto cleanup;
}

- if (

- (rv =3D pkcs11h_certificate_getCertificat= eBlob(
- ce= rtificate,
- = NULL,
- &= amp;certificate_blob_size
- )) !=3D CKR_OK
- )
+= if ((rv =3D pkcs11h_certificate_getCertificateBlob(certificate, NULL, &= amp;certificate_blob_size))
+ !=3D CKR_OK)
{
= msg(M_WARN, "PKCS#11: Cannot get certificate blob %ld-'%s'&q= uot;, rv, pkcs11h_getMessage(rv));
goto cleanup;
@@ -640,13 +519,9 @@
goto cleanup;<= /span>
}

- if (
- (rv =3D pkcs11h_certificate_getCertificateBlob(
- certificate,
- certificate_blob,<= /span>
- &cert= ificate_blob_size
- = )) !=3D CKR_OK
- )
+ if (= (rv =3D pkcs11h_certificate_getCertificateBlob(certificate, certificate_blo= b,
+ = &certificate_blob_size))
= + !=3D CKR_OK) {
msg(M_WARN, "PKCS#11: Cannot ge= t certificate blob %ld-'%s'", rv, pkcs11h_getMessage(rv));
goto cleanup;
@@ -678,22 +553,15 @@
free(certificate_blob);
certificat= e_blob =3D NULL;

- dmsg(
= - D_PKCS11_DEBUG,
- success ? 1 : 0,
- *id
- = );
+ dmsg(D_PKC= S11_DEBUG, "PKCS#11: pkcs11_management_id_get - return success=3D%d, i= d=3D'%s'",
+ success ? 1 : 0, *id);

= return success;
}

int
-tls_ctx_use_pkcs11(
- struct tls_root_ctx *= const ssl_ctx,
- boo= l pkcs11_id_management,
- const char *const pkcs11_id
- )
+tl= s_ctx_use_pkcs11(struct tls_root_ctx *const ssl_ctx, bool pkcs11_id_managem= ent,
+ = const char *const pkcs11_id)
{
pk= cs11h_certificate_id_t certificate_id =3D NULL;
pkcs11= h_certificate_t certificate =3D NULL;
@@ -701,16 +569,13 @@=

bool ok =3D false;
=
- ASSERT(ssl_ctx!= =3DNULL);
- ASSERT(p= kcs11_id_management || pkcs11_id!=3DNULL);
+ ASSERT(ssl_ctx !=3D NULL);
+ ASSERT(pkcs11_id_management || pkcs11= _id !=3D NULL);

dmsg(
D_PKCS11_DEBUG,

"PKCS#11: tls_ctx_= use_pkcs11 - entered - ssl_ctx=3D%p, pkcs11_id_management=3D%d, pkcs11_id= =3D'%s'",
= - (void *)ssl_ctx,
- pkcs11_id_management ? 1 : 0,
- pkcs11_id
- );
+ (void *)ssl_ctx, pkcs11_id_management ? 1 : 0, pkcs11_id);

if (pkcs11_id_management)
<= span> {

@@ -720,30 +585,17 @@
<= br> id_resp.defined =3D false;
id_re= sp.nocache =3D true;
- = snprintf(
- = id_resp.username,
- "Please specify PKCS#11 id to use"=
- );=
+ snprintf(id_resp.u= sername, sizeof(id_resp.username), "Please specify PKCS#11 id to use&q= uot;);

- = !get_user_pass(
-= &id_resp,
- NULL,
- "pkcs11-id-request",
- GET_USER_PASS_MANAGEMENT|G= ET_USER_PASS_NEED_STR|GET_USER_PASS_NOFATAL
- )
- )
+ if (!get_user_pass(&id_resp, NULL, "pkcs11-id-= request",
+ = GET_USER_PASS_MANAGEMENT | GET_USER_PASS_NEED_STR
+ = | GET_USER_PASS_NOFATAL))
{
goto cleanup;

}

- if (
= - (rv =3D pkcs11h_cert= ificate_deserializeCertificateId(
- &certificate_id,
- id_resp.password
- )) !=3D CKR_OK
- )
<= span style=3D"color: hsl(120, 100%, 40%);">+ if ((rv =3D pkcs11h_cer= tificate_deserializeCertificateId(&certificate_id, id_resp.password))
+ !=3D CKR_= OK)
{
msg(M_WARN, &qu= ot;PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_getMe= ssage(rv));
goto cleanup;
@@ -= 751,38 +603,23 @@
}
else {
- = if (
- (rv = =3D pkcs11h_certificate_deserializeCertificateId(
- &certificate_id,- pkcs11_id
- )) !=3D C= KR_OK
- )
+ if ((rv =3D pk= cs11h_certificate_deserializeCertificateId(&certificate_id, pkcs11_id))=
+ !=3D CK= R_OK)
{
msg(M_WARN, &= quot;PKCS#11: Cannot deserialize id %ld-'%s'", rv, pkcs11h_get= Message(rv));
goto cleanup;
= }
}

- if (
- (rv =3D pkcs11h_certificate_create(
- certificate_id,- NULL,
- PKCS11H_PROMPT_MASK_A= LLOW_ALL,

- = PKCS11H_PIN_CACHE_INFINITE,
- &certificate
- )) !=3D CKR_OK
- )
+ if ((rv =3D pkcs11h_certificate_create(certificate_id, NULL,= PKCS11H_PROMPT_MASK_ALLOW_ALL,
+ PKCS11H_PIN_CACHE_INFI= NITE, &certificate))
+ !=3D CKR_OK)
{
m= sg(M_WARN, "PKCS#11: Cannot get certificate %ld-'%s'", rv= , pkcs11h_getMessage(rv));
goto cleanup; }

- if (
- = (pkcs11_init_tls_session(
- certificate,
- ssl_ctx
- ))
- )
+ = if ((pkcs11_init_tls_session(certificate, ssl_ctx)))
{=
/* Handled by SSL context free */
certificate =3D NULL;

@@ -806,26 +643,15 @@
certificate_id =3D NULL;
}<= br>
- dmsg(
- D_PKCS11_DEBUG,=
- "PKCS#11= : tls_ctx_use_pkcs11 - return ok=3D%d, rv=3D%ld",
- ok ? 1 : 0,
- rv
- );
+ dmsg(D_PKCS11_DEBUG, "PKCS#11: tls_ctx_use_pkcs11 - re= turn ok=3D%d, rv=3D%ld", ok ? 1 : 0, rv);

= return ok ? 1 : 0;
}
-static
-PKCS11H_BOOL
-_pkcs11_openvpn_show_pkcs11_ids_pin_prompt(- void *const global_data,
- void *const user_da= ta,
- const pkcs11h_= token_id_t token,
- = const unsigned retry,
-= char *const pin,
- = const size_t pin_max
- )
+static PKCS1= 1H_BOOL
+_pkcs11_open= vpn_show_pkcs11_ids_pin_prompt(void *const global_data, void *const user_da= ta,
+ = const pkcs11h_token_id_t token, const unsigned r= etry,
+ = char *const pin, const size_t pin_max)<= br> {
struct gc_arena gc =3D gc_new(); struct buffer pass_prompt =3D alloc_buf_gc(128, &gc);
@@ -834,11 +660,10 @@
(void)user_data;
(void)retry;

- ASSERT(token!=3DNULL);
+ ASSERT(token !=3D NULL);

buf_printf(&pass_prompt, "Please enter = '%s' token PIN or 'cancel': ", token->display);
- if (!query_user_SINGL= E(BSTR(&pass_prompt), BLEN(&pass_prompt),
- pin, pin_max, false)= )
+ if (!query_use= r_SINGLE(BSTR(&pass_prompt), BLEN(&pass_prompt), pin, pin_max, fals= e))
{
msg(M_FATAL, "Coul= d not retrieve the PIN");
}
@@ -8= 56,10 +681,7 @@
}

void<= /span>
-show_pkcs11_ids(
- const char *const provi= der,
- bool cert_pri= vate
- )
<= span style=3D"color: hsl(120, 100%, 40%);">+show_pkcs11_ids(const char *con= st provider, bool cert_private)

{
str= uct gc_arena gc =3D gc_new();
pkcs11h_certificate_id_l= ist_t user_certificates =3D NULL;
@@ -882,7 +704,8 @@

if ((rv =3D pkcs11h_setProtectedAuthentic= ation(TRUE)) !=3D CKR_OK)
{
- msg(M_FATAL, "PKCS#11: Cannot set p= rotected authentication %ld-'%s'", rv, pkcs11h_getMessage(rv))= ;
+ msg(M_FATA= L, "PKCS#11: Cannot set protected authentication %ld-'%s'"= ;, rv,
+ p= kcs11h_getMessage(rv));
goto cleanup;
}


@@ -898,118 +721,77 @@<= br> goto cleanup;
}

- if (
- (rv =3D pkcs11h_certificate_e= numCertificateIds(

- = PKCS11H_ENUM_METHOD_CACHE_EXIST,
- NULL,
- PKCS11H_PROMPT_MASK_ALLOW_ALL,
- NULL,

- &user_certificates
- )) !=3D CKR= _OK
- )+ if ((rv =3D pkcs11h_cert= ificate_enumCertificateIds(PKCS11H_ENUM_METHOD_CACHE_EXIST, NULL,+ = PKCS11H_PROMPT_MASK_ALLOW_ALL, NULL,
+ = &user_certificates))

+ !=3D CKR_OK)
{<= br> msg(M_FATAL, "PKCS#11: Cannot enumerate certificates= %ld-'%s'", rv, pkcs11h_getMessage(rv));
= goto cleanup;
}

- msg(
- M_INFO|M_NOPREFIX|M_NOLF,
- (
- "\n"
- "The following objects are av= ailable for use.\n"
- &quo= t;--pkcs11-id option please remember to use single quote mark.\n"
- )
- );
+ msg(M_INFO | M_NOPREFIX | M_NOLF,+ ("\n"
+ "The follow= ing objects are available for use.\n"
+ "Each object shown below may be used a= s parameter to\n"
- char serial[1024] =3D {0};
+ char serial[1024] =3D { 0 };
char *ser =3D NULL;

size_t ser_len =3D= 0;

-= if (
- = (rv =3D pkcs11h_certificate_serializeCertificateId(
- NULL,
- &ser_len,
= - current->cer= tificate_id
- = )) !=3D CKR_OK
-= )
+ = if ((rv =3D pkcs11h_certificate_serializeCertificateId(NULL, &ser_len= ,
+ = current->certificate_id))
+ !=3D CKR_OK= )
{
- msg(M_FATAL, "PKCS#11: Cannot serialize certificate= %ld-'%s'", rv, pkcs11h_getMessage(rv));
+ msg(M_FATAL, "PKCS#11: C= annot serialize certificate %ld-'%s'", rv,
+ pkcs11h_getMessage(rv))= ;
goto cleanup1;
}

- = if (
- rv = =3D=3D CKR_OK
- = && (ser =3D (char *)malloc(ser_len)) =3D=3D NULL
- )

+ if (rv =3D=3D CKR_OK && (= ser =3D (char *)malloc(ser_len)) =3D=3D NULL)
{
msg(M_FATAL, "PKCS#11: Cannot allocate memo= ry");
goto cleanup1;
= }

- = (rv =3D pkcs11h_certificate_serializeCertificateId(
- ser,
- &ser_len,- current->c= ertificate_id
- = )) !=3D CKR_OK
- )
+ = if ((rv =3D
+ = pkcs11h_certificate_serializeCertificateId(ser, &ser_len, = current->certificate_id))
+ !=3D CKR_OK)
{
- msg(M_FATAL, "PKCS#= 11: Cannot serialize certificate %ld-'%s'", rv, pkcs11h_getMes= sage(rv));

+ = msg(M_FATAL, "PKCS#11: Cannot serialize certificate %ld-'%s'= ;", rv,
+ = pkcs11h_getMessage(rv));
goto cleanup= 1;
}

- if (
- (rv =3D pkcs11h_certificate_create(
= - current->cer= tificate_id,
- = NULL,
- = PKCS11H_PROMPT_MASK_ALLOW_ALL,
- PKCS11H_PIN_CACHE_INFINITE,
- &certificate<= /span>
- ))

- )
= + if ((rv =3D pkcs11h_ce= rtificate_create(current->certificate_id, NULL,
+ = PKCS11H_PROMPT_MASK_ALLOW_ALL,
+ PKCS11H_PIN_CACHE_= INFINITE, &certificate)))
{
= msg(M_FATAL, "PKCS#11: Cannot create certificate %ld-'%= s'", rv, pkcs11h_getMessage(rv));
got= o cleanup1;
}

- if (
- (dn =3D pkcs11_certificate_dn(=
- certificate= ,
- &am= p;gc
- = )) =3D=3D NULL
- = )
+ if ((= dn =3D pkcs11_certificate_dn(certificate, &gc)) =3D=3D NULL)
= {
goto cleanup1;
}


- if (
-= (pkcs11_certificate_serial(
- certificate,
- serial,
- sizeof(serial)
- ))

- )
+ if ((pkcs11_certificate_serial(certi= ficate, serial, sizeof(serial))))
{
goto cleanup1;

}
<= /span>
- msg(- M_INFO|M_NOPREFIX|M= _NOLF,
- (
- "\= n"
- = "Certificate\n"
- " DN: %s\n"
- " Serial= : %s\n"

- = " Serialized id: %s\n"
- ),
- dn,
- serial,
- ser
- );
+ msg(M_INFO | M_NOPREFIX | M_NOLF,
+ ("\n"
+ "Certificate\n"=
+ "= DN: %s\n"
+ " Serial: %s\n"+ " Se= rialized id: %s\n"),
+ dn, serial, ser);

cle= anup1:

diff --git a/src/openvpn/pkcs11.h = b/src/openvpn/pkcs11.h
index 72913eb..e8f7df8 100644=
--- a/src/openvpn/pkcs11.h
+++ b/src/openvpn/pkcs= 11.h
@@ -28,49 +28,24 @@

= #include "ssl_common.h"

-bool
-pkcs11_initialize(
- const bool fProtectedAuthentication,
- const int nPINCachePeriod
- );

+bool pkcs11_initialize(const bool fProtectedAuth= entication, const int nPINCachePeriod);

-void
-pkcs11_terminate(void);
+void pkcs11_terminate(void);

-bool
-pkcs11_addProvider(
- const char *const provider,
<= span style=3D"color: hsl(0, 100%, 40%);">- const bool fProtectedAuthenti= cation,

- const unsi= gned private_mode,
- = const bool fCertIsPrivate
- );
+bool pkc= s11_addProvider(const char *const provider, const bool fProtectedAuthentica= tion,
+ = const unsigned private_mode, const bool fCertIsPrivate);
-int-pkcs11_logout(void);+int pkcs11_logout(void);

-int
-pkcs11_management_id_count= (void);
+int pkcs11_m= anagement_id_count(void);

-bool
-pkcs11_management_id_get(
- const int index,
- char **id,
= - char **base64
- = );
+bool pkcs11_mana= gement_id_get(const int index, char **id, char **base64);
=
-int
-tls_ctx_use_pkcs11(
- struct tls_root_ctx *const ssl_ctx,
- bool pkcs11_id_mana= gement,
- const char= *const pkcs11_id
- = );
+int tls_ctx_use_p= kcs11(struct tls_root_ctx *const ssl_ctx, bool pkcs11_id_management,=
+ con= st char *const pkcs11_id);

-void
-show_pkcs11_ids(
= - const char *const provider,
- bool cert_private
- );
+vo= id show_pkcs11_ids(const char *const provider, bool cert_private);
-#endif = /* ENABLE_PKCS11 */
+#endif /* ENABLE_PKCS11 */

-#endif /* OPENVPN_PKCS1= 1H_H */
+#endif /* OP= ENVPN_PKCS11H_H */
diff --git a/src/openvpn/pkcs11_backend.= h b/src/openvpn/pkcs11_backend.h
index dce6822..834456f 100= 644
--- a/src/openvpn/pkcs11_backend.h
+++ = b/src/openvpn/pkcs11_backend.h
@@ -57,8 +57,7 @@
= *
* @return 1 on failure, 0 on succe= ss
*/
-int pkcs11_certificate_serial(pkcs11h_certificate_t certificate, char *se= rial,
- = size_t serial_len);
+int pkcs11_certificate_serial(pkcs11h_certificate_t certifica= te, char *serial, size_t serial_len);

/*= *
* Load PKCS #11 Certificate's information into the = given TLS context
@@ -68,8 +67,7 @@
*
* @return 1 on failure, 0 on success
= */
-int pkcs11_= init_tls_session(pkcs11h_certificate_t certificate,
- struct tls_root= _ctx *const ssl_ctx);
+int pkcs11_init_tls_session(pkcs11h_certificate_t certificate, struct tls= _root_ctx *const ssl_ctx);

#endif /* def= ined(ENABLE_PKCS11) */
#endif /* PKCS11_BACKEND_H_ */
diff --git a/src/openvpn/pkcs11_mbedtls.c b/src/openvpn/pkcs11_= mbedtls.c
index 13b8a86..21c9d47 100644
---= a/src/openvpn/pkcs11_mbedtls.c
+++ b/src/openvpn/pkcs11_mb= edtls.c
@@ -47,16 +47,14 @@
size_t cer= t_blob_size =3D 0;
bool ret =3D false;

- if (pkcs11h_cer= tificate_getCertificateBlob(pkcs11_cert, NULL,
- &am= p;cert_blob_size) !=3D CKR_OK)
+ if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, NULL= , &cert_blob_size) !=3D CKR_OK)
{
= msg(M_WARN, "PKCS#11: Cannot retrieve certificate object size= ");
goto cleanup;
}

check_malloc_return((cert_blob =3D callo= c(1, cert_blob_size)));
- if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, cert_blob,
- = &cert_blob_size) !=3D CKR_OK)
+ if (pkcs11h_certificate_getCertifi= cateBlob(pkcs11_cert, cert_blob, &cert_blob_size) !=3D CKR_OK) {
msg(M_WARN, "PKCS#11: Cannot r= etrieve certificate object");
goto cleanup;
@@ -75,16 +73,14 @@
}

static bool
-pkcs11_sign(void *pkcs11_cert, const void *src, size_t src_len,<= br>- void *dst, size_t= dst_len)
+pkcs11_sig= n(void *pkcs11_cert, const void *src, size_t src_len, void *dst, size_t dst= _len)
{
- = src, src_len, dst, &dst_len);=
+ return CKR_OK+ =3D=3D pkcs11h_ce= rtificate_signAny(pkcs11_cert, CKM_RSA_PKCS, src, src_len, dst, &dst_le= n);
}

int
-pkcs11_init_tls_session(pkcs11h_cer= tificate_t certificate,

- struct tls_root_ctx *const ssl_ctx)
+pkcs11_init_tls_session(pkcs11h_c= ertificate_t certificate, struct tls_root_ctx *const ssl_ctx)

{

ASSERT(NULL !=3D ssl_ctx);

@@ -131,8 +127,7 @@
}

int
-pkcs11= _certificate_serial(pkcs11h_certificate_t cert, char *serial,
- size_t se= rial_len)

+pkcs11_cer= tificate_serial(pkcs11h_certificate_t cert, char *serial, size_t serial_len= )
{
int ret =3D 1;
= mbedtls_x509_crt mbed_crt =3D { 0 };
diff --git a/src/op= envpn/pkcs11_openssl.c b/src/openvpn/pkcs11_openssl.c
index= e6baa43..3fc15e8 100644
--- a/src/openvpn/pkcs11_openssl.c=
+++ b/src/openvpn/pkcs11_openssl.c
@@ -44,= 18 +44,21 @@
#ifdef HAVE_XKEY_PROVIDER
st= atic XKEY_EXTERNAL_SIGN_fn xkey_pkcs11h_sign;

<= span style=3D"color: hsl(0, 100%, 40%);">-#if PKCS11H_VERSION > ((1<&= lt;16) | (27<<8)) /* version > 1.27 */

+#if PKCS11H_VERSION > ((1 << 16) | (27= << 8)) /* version > 1.27 */

/*= Table linking OpenSSL digest NID with CKM and CKG constants in PKCS#11 */<= /span>
-#define MD_TYPE(n) {NI= D_sha ## n, CKM_SHA ## n, CKG_MGF1_SHA ## n}
+#define MD_TYPE(n) { NID_sha##n, CKM_SHA##n, CKG_M= GF1_SHA##n }
static const struct
{=
int nid;
unsigned long ckm_id; unsigned long mgf_id;
-} mdtypes[] =3D {MD_TYPE(224), MD_TYPE(256), MD_TYPE(384), MD_= TYPE(512),
- = {NID_sha1, CKM_SHA_1, CKG_MGF1_SHA1}, /* SHA_1 naming is an oddity */
- {NID_und= ef, 0, 0}};
+} mdtype= s[] =3D { MD_TYPE(224),
+ MD_TYPE(256),
+ MD_TYPE(384),
+ MD_TYPE(512),
+ { NID_sha1, CKM_SHA_1, CK= G_MGF1_SHA1 }, /* SHA_1 naming is an oddity */
+ { NID_undef, 0, 0 } };
/* From sigalg, derive parameters for pss signatu= re and fill in pss_params.
* Its of type CK_RSA_PKCS_PSS= _PARAMS struct with three fields to be filled in:
@@ -63,15= +66,13 @@
* where hashAlg is CKM_SHA256 etc., mgf is CKG= _MGF1_SHA256 etc.
*/
static int-set_pss_params(CK_RSA_PKCS_PSS= _PARAMS *pss_params, XKEY_SIGALG sigalg,
- pkcs11h_certificate_t cert)
+set_pss_params(CK_RSA_PKCS_PSS_PA= RAMS *pss_params, XKEY_SIGALG sigalg, pkcs11h_certificate_t cert)
{
int ret =3D 0;
X509 *x5= 09 =3D NULL;
EVP_PKEY *pubkey =3D NULL;

- if ((x509 =3D = pkcs11h_openssl_getX509(cert)) =3D=3D NULL
- || (pubkey =3D X509_get0_pubkey(x509)) =3D=3D = NULL)
+ if ((x509 = =3D pkcs11h_openssl_getX509(cert)) =3D=3D NULL || (pubkey =3D X509_get0_pub= key(x509)) =3D=3D NULL)
{
msg= (M_WARN, "PKCS#11: Unable get public key");
= goto cleanup;
@@ -91,8 +92,10 @@
c= onst EVP_MD *md =3D EVP_get_digestbyname(sigalg.mdname);
= if (!md)
{
- msg(M_WARN, "WARN: set_pss_params: EVP_get_digest= byname returned NULL "
- "for mdname =3D <%s>", sigalg.mdname);
+ msg(M_WARN,
+ "WARN= : set_pss_params: EVP_get_digestbyname returned NULL "
+ "for mdname =3D &l= t;%s>",

+ = sigalg.mdname);
goto cleanup;
}

int mdsize =3D EVP_MD_get_size(md);<= br>@@ -109,14 +112,16 @@

if (s= altlen < 0 || pss_params->hashAlg =3D=3D 0)
{
- msg(M_WARN, &quo= t;WARN: invalid RSA_PKCS1_PSS parameters: saltlen =3D <%s> "
- "mdname = =3D <%s>.", sigalg.saltlen, sigalg.mdname);
+ msg(M_WARN,
+ "WARN: invalid RSA_PKCS= 1_PSS parameters: saltlen =3D <%s> "
+ "mdname =3D <%s>.",=
+ sigalg.= saltlen, sigalg.mdname);
goto cleanup;
<= span> }

- pss_pa= rams->sLen =3D (unsigned long) saltlen; /* saltlen >=3D 0 at this poi= nt */
+ pss_params= ->sLen =3D (unsigned long)saltlen; /* saltlen >=3D 0 at this point */=

- = msg(D_XKEY, "set_pss_params: sLen =3D %lu, hashAlg =3D %lu, mgf =3D %= lu",
- pss_= params->sLen, pss_params->hashAlg, pss_params->mgf);
+ msg(D_XKEY, "set_pss_par= ams: sLen =3D %lu, hashAlg =3D %lu, mgf =3D %lu", pss_params->sLen,=

+ pss_params-= >hashAlg, pss_params->mgf);

re= t =3D 1;

@@ -139,14 +144,14 @@
= * is PSS in which case we return an error.
*/
static CK_RV
-pkcs11h_certificate_signAny_ex(const pkcs11h_certificate_t cert,
- = const CK_MECHANISM *mech, const unsigned char *tbs,
- size_t tbs= len, unsigned char *sig, size_t *siglen)
+pkcs11h_certificate_signAny_ex(const pkcs11h_certifica= te_t cert, const CK_MECHANISM *mech,
+ const unsigned char *tbs, s= ize_t tbslen, unsigned char *sig,
+ size_t *siglen)
{

if (mech->mechanism =3D=3D CKM_RSA_PKCS_PSS)
{
msg(M_NONFATAL, "PKCS#1= 1: Error: PSS padding is not supported by "
- "this version of pkcs11-helper = library.");
+ = "this version of pkcs11-helper library.");
return CKR_MECHANISM_INVALID;
= }
return pkcs11h_certificate_signAny(cert, mech->me= chanism, tbs, tbslen, sig, siglen);
@@ -159,12 +164,12 @@
* We support ECDSA, RSA_NO_PADDING, RSA_PKCS1_PADDING, RSA= _PKCS_PSS_PADDING
*/
static int-xkey_pkcs11h_sign(void *handle= , unsigned char *sig,
-= size_t *siglen, const unsigned char *tbs, size_t tbslen, = XKEY_SIGALG sigalg)
+= xkey_pkcs11h_sign(void *handle, unsigned char *sig, size_t *siglen, const u= nsigned char *tbs,
+ = size_t tbslen, XKEY_SIGALG sigalg)
{
pkcs11h_certificate_t cert =3D handle;
- CK_MECHANISM mech =3D {CKM_RSA_PKCS, = NULL, 0}; /* default value */
- CK_RSA_PKCS_PSS_PARAMS pss_params =3D {0};
+ CK_MECHANISM mech =3D { CKM_RSA_PKCS= , NULL, 0 }; /* default value */
+ CK_RSA_PKCS_PSS_PARAMS pss_params =3D { 0 };

unsigned char buf[EVP_MAX_MD_SIZE];
size_t buflen =3D 0;

@@ -179,7 +184,7 @@
= if (xkey_digest(tbs, tbslen, buf, &buflen, sigalg.mdname= ))
{
tbs =3D buf;
- tbslen =3D (s= ize_t) buflen;
+ = tbslen =3D (size_t)buflen;
sigalg.op = =3D "Sign";
}
e= lse
@@ -195,8 +200,7 @@
}
else if (!strcmp(sigalg.keytype, "RSA"))

{

- msg(D_= XKEY, "xkey_pkcs11h_sign: signing with RSA key: padmode =3D %s",<= /span>
- sigalg.pad= mode);
+ msg(D= _XKEY, "xkey_pkcs11h_sign: signing with RSA key: padmode =3D %s",= sigalg.padmode);
if (!strcmp(sigalg.padmode, &quo= t;none"))
{
mech= .mechanism =3D CKM_RSA_X_509;
@@ -231,11 +235,10 @@<= br> }
else
{
= - ASSERT(0); /* coding er= ror -- we couldnt have created any such key */
+ ASSERT(0); /* coding error -- we couldnt= have created any such key */
}

- if (CKR_OK !=3D pkcs11= h_certificate_signAny_ex(cert, &mech,
- tbs, t= bslen, sig, siglen))
= + if (CKR_OK !=3D pkcs11h_certificate_signAny_ex(cert, &mech, tbs, t= bslen, sig, siglen))
{
return= 0;
}
@@ -245,7 +248,7 @@
}


/* For EC keys, pkcs11 re= turns signature as r|s: convert to der encoded */
- int derlen =3D ecdsa_bin2der(sig, (int) *si= glen, siglen_max);
+ = int derlen =3D ecdsa_bin2der(sig, (int)*siglen, siglen_max);
<= span>

if (derlen <=3D 0)
{
@@ -275,8 +278,7 @@
* = other xkey_load_.. routines
*/
st= atic int
-xkey_load_fro= m_pkcs11h(pkcs11h_certificate_t certificate,
- struct tls_root_ctx *const ct= x)
+xkey_load_from_pk= cs11h(pkcs11h_certificate_t certificate, struct tls_root_ctx *const ctx)
{
int ret =3D 0;

@@ -327,10 +329,8 @@
#endif /* HAVE_XKEY_PROVI= DER */

int
-pkcs11_init_tls_session(pkcs11h_certificate_t certi= ficate,
- = struct tls_root_ctx *const ssl_ctx)
+pkcs11_init_tls_session(pkcs11h_certificate_t cer= tificate, struct tls_root_ctx *const ssl_ctx)
{
= -
#ifdef HAVE_XK= EY_PROVIDER
return (xkey_load_from_pkcs11h(certificate= , ssl_ctx) =3D=3D 0); /* inverts the return value */
#else=
@@ -404,7 +404,7 @@
openssl_sessi= on =3D NULL;
}
return ret;=
-#endif /* ifdef HAVE_XKEY_PR= OVIDER */
+#endif = /* ifdef HAVE_XKEY_PR= OVIDER */
}

char *
@@ -430,8 +430,7 @@
}
=
int
-pkcs11_= certificate_serial(pkcs11h_certificate_t certificate, char *serial,<= br>- siz= e_t serial_len)
+pkcs= 11_certificate_serial(pkcs11h_certificate_t certificate, char *serial, size= _t serial_len)
{
X509 *x509 =3D NULL;=
BIO *bio =3D NULL;
@@ -451,9 +450,9 @= @
}

i2a_ASN1_IN= TEGER(bio, X509_get_serialNumber(x509));
- n =3D BIO_read(bio, serial, serial_len-1);+ n =3D BIO_read(bio, seria= l, serial_len - 1);

- if (n<0)
+ if (n < 0)
{
= serial[0] =3D '\x0';
}
diff= --git a/src/openvpn/platform.c b/src/openvpn/platform.c
in= dex b690192..bfab104 100644
--- a/src/openvpn/platform.c
+++ b/src/openvpn/platform.c
@@ -67,8 +67,10 = @@
msg(M_ERR, "cd to '%s' failed&= quot;, top);
}
msg(M_INFO= , "chroot to '%s' and cd to '%s' succeeded", path= , top);
-#else /* ifde= f HAVE_CHROOT */
- = msg(M_FATAL, "Sorry but I can't chroot to '%s' because = this operating system doesn't appear to support the chroot() system cal= l", path);
+#els= e /* ifdef HAVE_CHROOT */
+ msg(M_FATAL,
+ "Sorry but I can't chroot to '%s' becau= se this operating system doesn't appear to support the chroot() system = call",
+ = path);
#endif
}
= }
@@ -95,8 +97,10 @@
}
<= span> state->username =3D username;

ret= =3D true;
-#else /* i= f defined(HAVE_GETPWNAM) && defined(HAVE_SETUID) */
- msg(M_FATAL, "cannot get= UID for user %s -- platform lacks getpwname() or setuid() system calls&quo= t;, username);

+#else= /* if defined(HAVE_GETPWNAM) && defined(HAVE_SETUID) */
= + msg(M_FATAL,+ "cannot get = UID for user %s -- platform lacks getpwname() or setuid() system calls"= ;,
+ usern= ame);
#endif
}
r= eturn ret;
@@ -139,8 +143,10 @@
}<= /span>
state->groupname =3D groupname;
ret =3D true;

-#else /* if defined(HAVE_GETGRNAM) && defined(HAVE_SETGID) */
- msg(M_FATAL, &qu= ot;cannot get GID for group %s -- platform lacks getgrnam() or setgid() sys= tem calls", groupname);
+#else /* if defined(HAVE_GETGRNAM) && defined(HAVE_SETGID)= */
+ msg(M_FA= TAL,
+ &qu= ot;cannot get GID for group %s -- platform lacks getgrnam() or setgid() sys= tem calls",
+ = groupname);
#endif
}<= br> return ret;
@@ -215,8 +221,7 @@
*/

void
platform_user_group_set(cons= t struct platform_state_user *user_state,
- const struct platform_state_gro= up *group_state,
- = struct context *c)
+ const struct platform_state_group= *group_state, struct context *c)
{
i= nt keep_caps =3D need_keep_caps(c);
unsigned int err_f= lags =3D (keep_caps > 0) ? M_FATAL : M_NONFATAL;
@@ -259= ,8 +264,8 @@
{
/* -4 and -6 m= ean failure of setuid/gid respectively.
* There i= s no point for us to continue if those failed. */
- msg(M_ERR, "capng_change_id('%= s','%s') failed: %d",
- user_state->username, group_state->group= name, res);
+ = msg(M_ERR, "capng_change_id('%s','%s') failed: %d"= ;, user_state->username,
+ group_state->groupname, res);
}=
else if (res =3D=3D -3)
{=
@@ -295,7 +300,7 @@
{
= msg(M_ERR, "Clearing KEEPCAPS flag failed");
= }
-#endif /* HAVE_= LIBCAPNG */
+#endif /= * HAVE_LIBCAPNG */

if (keep_caps)
{
@@ -322,7 +327,7 @@
= {
msg(M_INFO, "nice %d succeeded&q= uot;, niceval);
}
-#else /* ifdef HAVE_NICE */
+#else /* ifdef HAVE_NICE */
= msg(M_WARN, "WARNING: nice %d failed (function not implemented= )", niceval);
#endif
}@@ -333,9 +338,9 @@
platform_getpid(void) {
#ifdef _WIN32
- return (unsigned int) GetCurrentProcessId();<= br>+ return (unsigned int)Ge= tCurrentProcessId();
#else
- return (unsigned int) getpid();
+ return (unsigned int)getpid();
#endif
}

= @@ -355,12 +360,11 @@
else
{
msg(M_INFO, "mlock: MEMLOCK limit: soft=3D%ld KB,= hard=3D%ld KB",
-= ((long int) rl.rlim_cur) / 1024, ((long int) rl.rlim_max) / 102= 4);
- if (rl.rli= m_cur < MIN_LOCKED_MEM_MB*1024*1024)
+ ((long int)rl.rlim_cur) / 1024, ((long int)= rl.rlim_max) / 1024);
+ if (rl.rlim_cur < MIN_LOCKED_MEM_MB * 1024 * 1024)
<= span> {

- = msg(M_INFO, "mlock: RLIMIT_MEMLOCK < %d MB, increase limit&qu= ot;,
- M= IN_LOCKED_MEM_MB);
- = rl.rlim_cur =3D MIN_LOCKED_MEM_MB*1024*1024;
+ msg(M_INFO, "mlock: RLIM= IT_MEMLOCK < %d MB, increase limit", MIN_LOCKED_MEM_MB);
= + rl.rlim_cur =3D MI= N_LOCKED_MEM_MB * 1024 * 1024;
if (rl.rlim_max= < rl.rlim_cur)
{
= rl.rlim_max =3D rl.rlim_cur;
@@ -398,10 +402,10 @@<= /span>
res =3D _wchdir(wide_string(dir, &gc));
= gc_free(&gc);
return res;
-#else /* ifdef _WIN32 */
+#else /* ifdef _WIN32 */
#ifdef HAVE_CHDIR
return chdir(dir);
-#else /* ifdef HAVE_CHDIR= */
+#else /* ifdef H= AVE_CHDIR */
return -1;
#endif=
#endif
@@ -551,9 +555,8 @@
= {
++attempts;

- if (!snprintf(fname, sizeof(fnam= e), fname_fmt, max_prefix_len,
- prefix, (unsigned long) get_random(),=
- (unsig= ned long) get_random()))
+ if (!snprintf(fname, sizeof(fname), fname_fmt, max_prefix_len,= prefix,
+ = (unsigned long)get_random(), (unsigned long)get_random()))
{
msg(M_WARN, "ERROR:= temporary filename too long");
return NU= LL;
@@ -577,8 +580,7 @@
else if (f= d =3D=3D -1 && errno !=3D EEXIST)
{=
/* Something else went wrong, no need to retry. */<= /span>
- msg(M_WARN= | M_ERRNO, "Could not create temporary file '%s'",
- retfname);<= /span>
+ msg(M_WA= RN | M_ERRNO, "Could not create temporary file '%s'", ret= fname);
return NULL;
= }
}
@@ -591,12 +593,12 @@
* Put a directory and filename together.

*/<= br> const char *
= -platform_gen_path(const char *directory, const char *filename,
<= span style=3D"color: hsl(0, 100%, 40%);">- struct gc_arena= *gc)

+platform_gen_p= ath(const char *directory, const char *filename, struct gc_arena *gc)
{
#ifdef _WIN32
- const int CC_PATH_RESERVED =3D CC_LESS_THAN|CC_G= REATER_THAN|CC_COLON
- = |CC_DOUBLE_QUOTE|CC_SLASH|CC_BACKSLASH|CC_P= IPE|CC_QUESTION_MARK|CC_ASTERISK;
+ const int CC_PATH_RESERVED =3D CC_LESS_THAN | CC_GREATER_= THAN | CC_COLON | CC_DOUBLE_QUOTE
+ | CC_SLASH | CC_BACKSLASH | = CC_PIPE | CC_QUESTION_MARK
+ | CC_ASTERISK;
#el= se
const int CC_PATH_RESERVED =3D CC_SLASH;
= #endif
@@ -608,13 +610,11 @@

const char *safe_filename =3D string_mod_const(filename, CC= _PRINT, CC_PATH_RESERVED, '_', gc);

- if (safe_filename

- && strcmp(safe_file= name, ".")

- = && strcmp(safe_filename, "..")
+ if (safe_filename && strcmp= (safe_filename, ".") && strcmp(safe_filename, "..&qu= ot;)
#ifdef _WIN32
&& win= _safe_filename(safe_filename)
#endif
- )
+ )
{
= const size_t outsize =3D strlen(safe_filename) + (directory ? strlen(direc= tory) : 0) + 16;
struct buffer out =3D alloc_buf_g= c(outsize, gc);
@@ -672,14 +672,12 @@
= {
if (errno =3D=3D EACCES)
{

- = msg( M_WARN | M_ERRNO, "Could not access file '%s'&q= uot;, filename);
+ = msg(M_WARN | M_ERRNO, "Could not access file '%s'= ", filename);
}
= }
}

- dmsg(D_TEST_FILE, "TEST FILE '%s' [%d= ]",
- file= name ? filename : "UNDEF",
- ret);
+ dmsg(D_TEST_FILE, "TEST FILE '%s' [%d]", fi= lename ? filename : "UNDEF", ret);

return ret;

}
diff --git a/src/op= envpn/platform.h b/src/openvpn/platform.h
index 56f8909..b3= b13a7 100644
--- a/src/openvpn/platform.h
+= ++ b/src/openvpn/platform.h
@@ -60,7 +60,8 @@

/* Get/Set UID of process */
=
-struct platform_state_user {=
+struct platform_sta= te_user
+{
= #if defined(HAVE_GETPWNAM) && defined(HAVE_SETUID) const char *username;
uid_t uid;@@ -71,7 +72,8 @@

/* Get/Set GID = of process */

-struct platform_state_group {
+struct platform_state_group
+{
#if defined(HAVE_GETGRNAM) &= amp;& defined(HAVE_SETGID)
const char *groupname;<= /span>
gid_t gid;
@@ -85,8 +87,7 @@ bool platform_group_get(const char *groupname, struct platform_stat= e_group *state);

void platform_user_grou= p_set(const struct platform_state_user *user_state,
- const struct p= latform_state_group *group_state,
- struct context *c);
+ const= struct platform_state_group *group_state, struct context *c);



/*
@@ -117,7 +118,= 7 @@

unsigned int platform_getpid(void);=

-voi= d platform_mlockall(bool print_msg); /* Disable paging */
+void platform_mlockall(bool print_ms= g); /* Disable paging */

int platform_ch= dir(const char *dir);

@@ -153,8 +154,7 @@=
struct gc_arena *gc= );

/** Put a directory and filename toge= ther. */
-const char *p= latform_gen_path(const char *directory, const char *filename,
- struc= t gc_arena *gc);

+con= st char *platform_gen_path(const char *directory, const char *filename, str= uct gc_arena *gc);

/** Return true if pa= thname is absolute. */
bool platform_absolute_pathname(con= st char *pathname);
diff --git a/src/openvpn/plugin.c b/src= /openvpn/plugin.c
index bafa469..02de931 100644
<= span>--- a/src/openvpn/plugin.c

+++ b/src/openvpn/plugin.c<= /span>
@@ -45,7 +45,7 @@
#include "win32.h&q= uot;
#include "memdbg.h"

-#define PLUGIN_SYMBOL_REQUI= RED (1<<0)
+#de= fine PLUGIN_SYMBOL_REQUIRED (1 << 0)

/* used only for program aborts */

static struct plugin= _common *static_plugin_common =3D NULL; /* GLOBAL */
@@ -15= 3,7 +153,7 @@
static inline unsigned int
= plugin_supported_types(void)
{
- return ((1<<OPENVPN_PLUGIN_N)-1);
+ return ((1 << O= PENVPN_PLUGIN_N) - 1);
}

struct plugin_option_list *

@@ -165,8 +165,7 @@ }

bool
-plugin_option_list_add(struct plugin_option_lis= t *list, char **p,
- = struct gc_arena *gc)
+plugin_option_list_add(struct plugin_option_list *list= , char **p, struct gc_arena *gc)
{
if= (list->n < MAX_PLUGINS)
{
@@ -1= 94,7 +193,8 @@
for (i =3D 0; i < list->n; ++i)
{
const struct plugin_option *= o =3D &list->plugins[i];
- msg(msglevel, " plugin[%d] %s '%s'", i= , o->so_pathname, print_argv(o->argv, &gc, PA_BRACKET));+ msg(msglevel, "= plugin[%d] %s '%s'", i, o->so_pathname,
+ print_argv(o->argv, &a= mp;gc, PA_BRACKET));
}

gc_free(&gc);

@@ -204,24 +204,28 @@
<= span> #ifndef _WIN32


static void<= br>-libdl_resolve_symbol(void *ha= ndle, void **dest, const char *symbol, const char *plugin_name, const unsig= ned int flags)
+libdl= _resolve_symbol(void *handle, void **dest, const char *symbol, const char *= plugin_name,
+ = const unsigned int flags)
{
= *dest =3D dlsym(handle, symbol);
if ((flags &= PLUGIN_SYMBOL_REQUIRED) && !*dest)
{- msg(M_FATAL, "PLU= GIN: could not find required symbol '%s' in plugin shared object %s= : %s", symbol, plugin_name, dlerror());
+ msg(M_FATAL, "PLUGIN: could not find = required symbol '%s' in plugin shared object %s: %s",+ symbol, plugin_n= ame, dlerror());
}
}
=
#else /* ifndef _WIN32 */

<= span> static void

-dll_= resolve_symbol(HMODULE module, void **dest, const char *symbol, const char = *plugin_name, const unsigned int flags)
+dll_resolve_symbol(HMODULE module, void **dest, const c= har *symbol, const char *plugin_name,
+ const unsigned int flags)
{

*dest =3D GetProcAddress(module, symbol);
if ((flags & PLUGIN_SYMBOL_REQUIRED) && !*dest)=
{
- msg(M_FATAL, "PLUGIN: could not find required symbol '%s= ' in plugin DLL %s", symbol, plugin_name);
+ msg(M_FATAL, "PLUGIN: could = not find required symbol '%s' in plugin DLL %s", symbol,
+ plugin_name);=
}
}

@@ -255,8 +259,7 @@

* was parsed.
= *
*/
- if (!platform_absolute_pathname(p->so_pathname)
= - && p->so_path= name[0] !=3D '.')
+ if (!platform_absolute_pathname(p->so_pathname) && p-&= gt;so_pathname[0] !=3D '.')
{
= char full[PATH_MAX];

@@ -270,24 = +273,29 @@
}
if (!p->handle)
{
-= msg(M_ERR, "PLUGIN_INIT: could not load plugin shared object %= s: %s", p->so_pathname, dlerror());
+ msg(M_ERR, "PLUGIN_INIT: could not loa= d plugin shared object %s: %s", p->so_pathname,
+ dlerror());
}


-#define PLUGIN_SYM(var, name, flags) libdl_resolve_symbol(p->handle,= (void *)&p->var, name, p->so_pathname, flags)
+#define PLUGIN_SYM(var, name, flags) \=
+ libdl_resolve_s= ymbol(p->handle, (void *)&p->var, name, p->so_pathname, flags)=

-#el= se /* ifndef _WIN32 */
+#else /* ifndef _WIN32 */

WCHAR = *wpath =3D wide_string(p->so_pathname, &gc);
- WCHAR normalized_plugin_path[MAX_PATH] = =3D {0};
+ WCHAR n= ormalized_plugin_path[MAX_PATH] =3D { 0 };
/* Normaliz= e the plugin path, converting any relative paths to absolute paths. */
if (!GetFullPathNameW(wpath, MAX_PATH, normalized_plugin_p= ath, NULL))
{
- msg(M_ERR, "PLUGIN_INIT: could not load plugin DL= L: %ls. Failed to normalize plugin path.", wpath);
+ msg(M_ERR, "PLUGIN_INIT: c= ould not load plugin DLL: %ls. Failed to normalize plugin path.",
+ wpath);
}

if (!plugin_in_tr= usted_dir(normalized_plugin_path))
{
- msg(M_FATAL, "PLUGIN_INIT:= could not load plugin DLL: %ls. The DLL is not in a trusted directory.&quo= t;, normalized_plugin_path);
+ msg(M_FATAL,
+ "PLUGIN_INIT: could not load plugin DLL: %ls. Th= e DLL is not in a trusted directory.",
+ normalized_plugin_path);
}


p->module =3D LoadLibrar= yW(normalized_plugin_path);
@@ -296,7 +304,8 @@
<= span> msg(M_ERR, "PLUGIN_INIT: could not load plugin DLL: %ls&= quot;, normalized_plugin_path);

}

-#define PLUGIN_SYM(var, = name, flags) dll_resolve_symbol(p->module, (void *)&p->var, name,= p->so_pathname, flags)
+#define PLUGIN_SYM(var, name, flags) \
+ dll_resolve_symbol(p->module, (void *)&= ;p->var, name, p->so_pathname, flags)

#endif /* ifndef _WIN32 */


@@ -315,12= +324,14 @@

if (!p->open1 &&a= mp; !p->open2 && !p->open3)
{
= - msg(M_FATAL, "PLUGI= N: symbol openvpn_plugin_open_vX is undefined in plugin: %s", p->so= _pathname);
+ = msg(M_FATAL, "PLUGIN: symbol openvpn_plugin_open_vX is undefined in pl= ugin: %s",
+ = p->so_pathname);
}
=
if (!p->func1 && !p->func2 && !p->f= unc3)
{
- msg(M_FATAL, "PLUGIN: symbol openvpn_plugin_func_vX is = undefined in plugin: %s", p->so_pathname);
+ msg(M_FATAL, "PLUGIN: symbol op= envpn_plugin_func_vX is undefined in plugin: %s",
+ p->so_pathname); }

/*
@@= -331,10 +342,9 @@
const int plugin_needs_version = =3D (*p->min_version_required)();
if (plugin_ne= eds_version > OPENVPN_PLUGIN_VERSION)
{<= br>- msg(M_FATAL, &quo= t;PLUGIN_INIT: plugin needs interface version %d, but this version of OpenV= PN only supports version %d: %s",
- plugin_needs_version,
- OPENVPN_PLUGIN_VERSION,
- p->so= _pathname);
+ = msg(M_FATAL,
+ = "PLUGIN_INIT: plugin needs interface version %d, but this= version of OpenVPN only supports version %d: %s",
+ plugin_needs_version, O= PENVPN_PLUGIN_VERSION, p->so_pathname);
}
}

@@ -349,7 +359,9 @@

if (rel)
{<= br>- msg(M_WARN, "WAR= NING: plugin '%s' specified by a relative pathname -- using an abso= lute pathname would be more secure", p->so_pathname);
+ msg(M_WARN,

+ "WARNING: plugin= '%s' specified by a relative pathname -- using an absolute pathnam= e would be more secure",

+ p->so_pathname);
}
=
p->initialized =3D true;
@@= -428,9 +440,9 @@
static struct openvpn_plugin_callbacks c= allbacks =3D {
plugin_log,
plugin= _vlog,
- secure_memz= ero, /* plugin_secure_memzero */
- openvpn_base64_encode, /* plugin_base64_encode */
- openvpn_base64_deco= de, /* plugin_base64_decode */
+ secure_memzero, /* plugin_secure_memzero */+ openvpn_base64_encode, /= * plugin_base64_encode */
+ openvpn_base64_decode, /* plugin_base64_decode */
};



@@ -445,10 +457,8 = @@
#endif

static void
-plugin_open_item(struct= plugin *p,
- = const struct plugin_option *o,
- struct openvpn_plugin_string_list **retlis= t,
- co= nst char **envp,
+plu= gin_open_item(struct plugin *p, const struct plugin_option *o,
+ struct openvpn_= plugin_string_list **retlist, const char **envp,

= const int init_point)
{
ASSER= T(p->initialized);
@@ -472,19 +482,20 @@
if (p->open3)

{
= struct openvpn_plugin_args_open_in args =3D { p->plugin_type_mas= k,
- = (const char **const) o->argv,
- = (const char **const) envp,
+ = (const char **const)o->argv,
+ = (const char **const)envp,
= &callbacks,
= SSLAPI,
= PACKAGE_VERSION,
OPENVP= N_VERSION_MAJOR,
= OPENVPN_VERSION_MINOR,
- _OP= ENVPN_PATCH_LEVEL};
+= _OPENVPN_PATCH_LEVE= L };
struct openvpn_plugin_args_open_return re= targs;

CLEAR(retargs);
retargs.return_list =3D retlist;
- if ((*p->open3)(OPENVPN_P= LUGINv3_STRUCTVER, &args, &retargs) =3D=3D OPENVPN_PLUGIN_FUNC_SUCC= ESS)
+ if = ((*p->open3)(OPENVPN_PLUGINv3_STRUCTVER, &args, &retargs)=
+ =3D=3D OPE= NVPN_PLUGIN_FUNC_SUCCESS)
{
= p->plugin_type_mask =3D retargs.type_mask;
p->plugin_handle =3D retargs.handle;

= @@ -507,24 +518,20 @@
ASSERT(0);
}


- msg(D_PLUGIN, "PLUGIN_INIT: POST %s '%s' int= ercepted=3D%s %s",
- p->so_pathname,
- print_argv(o->argv, &gc, PA_BRACKET),<= br>- plugin_mask_strin= g(p->plugin_type_mask, &gc),
+ msg(D_PLUGIN, "PLUGIN_INIT: POST %s '%s= 9; intercepted=3D%s %s", p->so_pathname,
+ print_argv(o->argv, &gc, PA= _BRACKET), plugin_mask_string(p->plugin_type_mask, &gc),
<= span> (retlist && *retlist) ? "[RETLIST]" : &= quot;");


if ((p->plugin_= type_mask | plugin_supported_types()) !=3D plugin_supported_types())=
{
- = msg(M_FATAL, "PLUGIN_INIT: plugin %s expressed interest in = unsupported plugin types: [want=3D0x%08x, have=3D0x%08x]",
<= span style=3D"color: hsl(0, 100%, 40%);">- p->so_pathname= ,

- p-&g= t;plugin_type_mask,
- = plugin_supported_types());
+ msg(M_FATAL,
+ "PLUGIN_INIT: plugin %s expr= essed interest in unsupported plugin types: [want=3D0x%08x, have=3D0x%08x]&= quot;,
+ = p->so_pathname, p->plugin_type_mask, plugin_supported_types());
}

if (p-&= gt;plugin_handle =3D=3D NULL)
{
- msg(M_FATAL, "PLUGIN_IN= IT: plugin initialization function failed: %s",
- p->so_pathname);<= br>+ msg(M_FATAL, &q= uot;PLUGIN_INIT: plugin initialization function failed: %s", p->so_= pathname);
}

= gc_free(&gc);
@@ -532,15 +539,9 @@
}


static int
-plugin_call_item(const struct plugin *p,
- void *per_= client_context,
- = const int type,
- const struct argv *av,
- struct openvpn_plugin_string_list *= *retlist,
- = const char **envp,
- int certdepth,
- openvpn_x509_cert_t *current_cert
- )

+plugin_call_item(const struct plugi= n *p, void *per_client_context, const int type,

+ const struct argv *av, struct = openvpn_plugin_string_list **retlist,
+ const char **envp, int certdepth, openvp= n_x509_cert_t *current_cert)
{
int st= atus =3D OPENVPN_PLUGIN_FUNC_SUCCESS;

@@ = -564,8 +565,8 @@
if (p->func3)
= {
struct openvpn_plugin_args_func_in = args =3D { type,
- = (const char **const) a.a= rgv,
- = (const char **const) envp,+ = (const char **const)a.argv,
+ = (const char **const)envp,
= p->plugin_handle,
per_client_conte= xt,

= (current_cert ? certdepth : -1),
@@ -579,7 +580,8 @@
}
else if (p->func2)
{
-= status =3D (*p->func2)(p->plugin_handle, type, (const cha= r **)a.argv, envp, per_client_context, retlist);
+ status =3D (*p->func2)(p->pl= ugin_handle, type, (const char **)a.argv, envp,
+ per_client_con= text, retlist);
}
else if= (p->func1)
{
@@ -590,17 +592,1= 3 @@
ASSERT(0);
}

- = msg(D_PLUGIN, "PLUGIN_CALL: POST %s/%s status=3D%d",
<= span style=3D"color: hsl(0, 100%, 40%);">- p->so_pathname,
- plugin_type_= name(type),
+ = msg(D_PLUGIN, "PLUGIN_CALL: POST %s/%s status=3D%d", p->so_pat= hname, plugin_type_name(type),
status);=

if (status =3D=3D OPENVPN_PLUGIN_FUNC_= ERROR)
{
msg(M_WARN, = "PLUGIN_CALL: plugin function %s failed with status %d: %s",
- plugin_typ= e_name(type),
- = status,
- = p->so_pathname);
+ plugin_type_name(type), status, p->so_pathname= );
}

ar= gv_free(&a);
@@ -653,8 +651,7 @@
}

static void
-plugin_per_client_init(const struct plugin_common *pc= ,
- = struct plugin_per_client *cli,
+plugin_per_client_init(const struct plugin_common *pc, struct= plugin_per_client *cli,
const int = init_point)
{
const int n =3D pc->= n;
@@ -663,8 +660,7 @@
for (i =3D 0; i= < n; ++i)
{
const struct = plugin *p =3D &pc->plugins[i];
- if (p->plugin_handle
- && (init_point < 0 || init= _point =3D=3D p->requested_initialization_point)
+ if (p->plugin_handle &&= ; (init_point < 0 || init_point =3D=3D p->requested_initialization_po= int)
&& p->client_constructor)
{
cli->per_client_cont= ext[i] =3D (*p->client_constructor)(p->plugin_handle);
@@ -712,8 +708,7 @@


for (i =3D 0; = i < list->n; ++i)
{
- plugin_init_item(&pc->plugins[i],
- = &list->plugins[i]);
+ plugin_init_item(&pc->plugins[i], &list->plu= gins[i]);
pc->n =3D i + 1;
= }

@@ -722,11 +717,8 @@
= }

static void
-plugin_common_open(struct plugin_common *pc,
- const = struct plugin_option_list *list,
- struct plugin_return *pr,
- const struct env_set *= es,
- = const int init_point)
+ = struct plugin_return *pr, const struct env_set *es, const int in= it_point)
{
struct gc_arena gc =3D gc= _new();
int i;
@@ -741,10 +733,7 @@

for (i =3D 0; i < pc->n; ++i)
{
- = plugin_open_item(&pc->plugins[i],
- &list->plugins[i]= ,
- = pr ? &pr->list[i] : NULL,
- envp,
+ plugin_open_item(&pc->plugins[i],= &list->plugins[i], pr ? &pr->list[i] : NULL, envp, init_point);
}=

@@ -783,25 +772,17 @@
}=

void
-plugin_list_open(struct plugin_list *pl,
- const struct plugin_option= _list *list,
- = struct plugin_return *pr,
- const struct env_set *es,
- const int init_point)
+plugin_list_open(struct= plugin_list *pl, const struct plugin_option_list *list,
+ struct plugin_return = *pr, const struct env_set *es, const int init_point)
{
plugin_common_open(pl->common, list, pr, es, init_poin= t);
plugin_per_client_init(pl->common, &pl->= per_client, init_point);
}

int

-plugin_call_ss= l(const struct plugin_list *pl,
- const int type,
- const struct argv *av,
- struct plugin_return *= pr,
- st= ruct env_set *es,
- = int certdepth,
- openvpn_x509_cert_t *current_cert
- )
+plugin_call_ssl(const struct plugin_list *pl= , const int type, const struct argv *av,
+ struct plugin_return *pr, struct env_s= et *es, int certdepth,
- const int status =3D plugin_call_item(&pl-&g= t;common->plugins[i],
- = type,
- = av,
- = pr ? &pr->list[i] : NULL,
- = envp,

- = certdepth,
- = current_cert
- = );
+ const int status =3D
+ plugin_call_item= (&pl->common->plugins[i], pl->per_client.per_client_context[i]= ,

+ = type, av, pr ? &pr->list[i] : NULL, envp, certdepth, = current_cert);
switch (status)
{

case OPENVPN_PLUGIN_FUNC_S= UCCESS:
break;

case OPENVPN_PLUGIN_FUNC_DEFERRED:
- if ((type =3D= =3D OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY)

- && deferred_auth_done)<= /span>
+ = if ((type =3D=3D OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY) && deferred_= auth_done)
{
= /*
* Do not allow= deferred auth if a deferred auth has
@@ -855,13 +829,12 @@=
* error, we bail out and exit th= e OpenVPN process.
*/
<= span> error =3D true;

- msg(M_FATAL,
- "Ex= iting due to multiple authentication plug-ins "

- "performin= g deferred authentication. Only one "
- "authentication plug= -in doing deferred auth is "
- "allowed. Ignoring the result= and stopping now, "
- "the current authentication result is = not to be "
- = "trusted.");
+ msg(M_FATAL, "Exitin= g due to multiple authentication plug-ins "
+ "per= forming deferred authentication. Only one "
+ "au= thentication plug-in doing deferred auth is "
+ "a= llowed. Ignoring the result and stopping now, "
+ &quo= t;the current authentication result is not to be "
+ &q= uot;trusted.");
break;=
}
defer= red_auth_done =3D true;
@@ -997,8 +970,7 @@
}


void
-plugin_return_get_column(const struct plugin_return *= src,
- = struct plugin_return *dest,
+plugin_return_get_column(const struct plugin_return *src, s= truct plugin_return *dest,
const = char *colname)
{
int i;
@@ -1036,10 +1008,7 @@

msg(msglevel, "PLUG= IN #%d (%s)", i, prefix);
while (l) {
- = msg(msglevel, "[%d] '%s' -> '%s'\n",
- ++count= ,
- l-&g= t;name,
- = l->value);
+ = msg(msglevel, "[%d] '%s' -> '%s'\n", += +count, l->name, l->value);
l =3D l->= next;
}
}
dif= f --git a/src/openvpn/plugin.h b/src/openvpn/plugin.h
index= 5e91c60..9a7d9c6 100644
--- a/src/openvpn/plugin.h<= br>+++ b/src/openvpn/plugin.h
@@ -42,17 +42,20 @@

#define MAX_PLUGINS 16

-struct plugin_option {
+struct plugin_option<= /span>
+{
= const char *so_pathname;
const char **argv;<= br> };

-struct plugin_option_list {
+struct plugin_option_list
+{
int n;
s= truct plugin_option plugins[MAX_PLUGINS];
};

-struct plugin {
+struct plugin<= br>+{
bool= initialized;
const char *so_pathname;
unsigned int plugin_type_mask;

@@ -106,8 +109,7 @@

struct plugin_option_list *plugin_option_l= ist_new(struct gc_arena *gc);

-bool plugin_option_list_add(struct plugin_option_= list *list, char **p,
-= struct gc_arena *gc);
+bool plugin_option_list_add(struct plugin_opt= ion_list *list, char **p, struct gc_arena *gc);
#ifndef ENABLE_SMALL
void plugin_option_list_print= (const struct plugin_option_list *list, int msglevel);
@@ -= 116,29 +118,20 @@

struct plugin_list *pl= ugin_list_init(const struct plugin_option_list *list);

-void plugin_list_open(st= ruct plugin_list *pl,
-= const struct plugin_option_list *list,
- struct plugin_= return *pr,

- = const struct env_set *es,
- const int init_point);
+void plugin_list_open(struct plugi= n_list *pl, const struct plugin_option_list *list,

+ struct plugin_return *= pr, const struct env_set *es, const int init_point);

struct plugin_list *plugin_list_inherit(const struct plugin_li= st *src);

-int plugin_call_ssl(const struct plugin_list *pl,
- const int type,
- const s= truct argv *av,
- = struct plugin_return *pr,
- struct env_set *es,
- int current_cert_de= pth,
- = openvpn_x509_cert_t *current_cert
- );
+int plugin_call_ssl(const struct plugin_list *pl, const i= nt type, const struct argv *av,
+ struct plugin_return *pr, struct env_set *e= s, int current_cert_depth,
+ openvpn_x509_cert_t *current_cert);

void plugin_list_close(struct plugin_list *pl);

bool plugin_defined(const struct plugin_list= *pl, const int type);

-void plugin_return_get_column(const struct plugin_return= *src,
- = struct plugin_return *dest,
+void plugin_return_get_column(const struct plugin_re= turn *src, struct plugin_return *dest,
= const char *colname);

void pl= ugin_return_free(struct plugin_return *pr);
@@ -174,8 +167,= 14 @@
}

#else /* ifdef= ENABLE_PLUGIN */
-stru= ct plugin_list { int dummy; };
-struct plugin_return { int dummy; };
+struct plugin_list
+{
+ int dummy;
+};
+struct plugin_r= eturn
+{
+ int dummy;

+};

= static inline bool
plugin_defined(const struct plugin_lis= t *pl, const int type)
@@ -184,14 +183,9 @@
}


static inline int
-plugin_call_ssl(const struct plugin_list= *pl,
- = const int type,
- = const struct argv *av,
- struct plugin_return *pr,
- struct env_set *es,<= br>- int current_c= ert_depth,
- = openvpn_x509_cert_t *current_cert
- )
+plugin_call_ssl(const struct plugin_list *pl, const int type= , const struct argv *av,
+ struct plugin_return *pr, struct env_set *es, int curr= ent_cert_depth,
+ = openvpn_x509_cert_t *current_cert)
{ return 0;
}
@@ -199,11 +193,8 = @@
#endif /* ENABLE_PLUGIN */

= static inline int
- const int type,
- const struct argv *av,
<= span style=3D"color: hsl(0, 100%, 40%);">- struct plugin_return = *pr,

- struc= t env_set *es)
+plugi= n_call(const struct plugin_list *pl, const int type, const struct argv *av,=
+ struct = plugin_return *pr, struct env_set *es)
{
= return plugin_call_ssl(pl, type, av, pr, es, -1, NULL);
}

diff --git a/src/openvpn/pool.c b/src/openvpn/pool.c
index ced172c..6ccfcd3 100644
--- a/src/openv= pn/pool.c
+++ b/src/openvpn/pool.c
@@ -90,1= 4 +90,11 @@
* Keep track of a possible alloca= tion to us
* from an earlier session.<= br> */
- if (previous_usage < 0
- && common_name
- && ipe->com= mon_name
+ = if (previous_usage < 0 && common_name && ipe->common= _name
&& !strcmp(common_name, ipe-= >common_name))
{
= previous_usage =3D i;
}
-

} }

@@ -126,16 +123,14 @@
if (start > end)
{
= msg(msglevel, "--ifconfig-pool start IP [%s] is greater than = end IP [%s]",
- = print_in_addr_t(start, 0, &gc),
- print_in_addr_t(end, 0, &gc));
+ print_in_addr= _t(start, 0, &gc), print_in_addr_t(end, 0, &gc));
= ret =3D false;
}
if (end = - start >=3D IFCONFIG_POOL_MAX)
{
- msg(msglevel, "--ifconfig-= pool address range is too large [%s -> %s]. Current maximum is %d addre= sses, as defined by IFCONFIG_POOL_MAX variable.",
- print_in_addr_t(start, 0, &= ;gc),
- prin= t_in_addr_t(end, 0, &gc),
- IFCONFIG_POOL_MAX);
+ msg(msglevel,
+ "--ifconfig-pool address range is to= o large [%s -> %s]. Current maximum is %d addresses, as defined by IFCO= NFIG_POOL_MAX variable.",
+ print_in_addr_t(start, 0, &gc), print_in_addr_t(= end, 0, &gc), IFCONFIG_POOL_MAX);
ret =3D fals= e;
}
gc_free(&gc);
= @@ -143,10 +138,9 @@
}

<= span> struct ifconfig_pool *

-ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_add= r_t start,
- = in_addr_t end, const bool duplicate_cn,
- const bool ipv6_pool, const st= ruct in6_addr ipv6_base,
+ifconfig_pool_init(const bool ipv4_pool, enum po= ol_type type, in_addr_t start, in_addr_t end,
+ const bool duplicate_cn, const= bool ipv6_pool, const struct in6_addr ipv6_base,
+ const int ipv6_netbits)
{
struct gc_arena gc =3D gc_new();
struct ifconfig_pool *pool =3D NULL;
@@ -1= 80,8 +174,7 @@

if (pool_ipv4_siz= e < 2)
{
- msg(M_FATAL, "IPv4 pool size is too small (= %d), must be at least 2",
- pool_ipv4_size);
+ msg(M_FATAL, "IPv4 pool size is too = small (%d), must be at least 2", pool_ipv4_size);
= }

msg(D_IFCONFIG_POOL, &quo= t;IFCONFIG POOL IPv4: base=3D%s size=3D%d",
@@ -199,10= +192,8 @@
* 4 bytes, therefore we can just extra= ct that and use it as base in
* integer form
*/
- | (ipv6_= base.s6_addr[13] << 16)
- | (ipv6_base.s6_addr[14] << 8)=
- | ip= v6_base.s6_addr[15];
= + uint32_t base =3D (ipv6_base.s6_addr[12] << 24) | (ipv6_base= .s6_addr[13] << 16)
+ | (ipv6_base.s6_addr[14] << 8) | ipv6_b= ase.s6_addr[15];
/* some bits of the last 4 bytes = may still be part of the network
* portion of the= address, therefore we need to set them to 0
*/
@@ -215,7 +206,7 @@
* the foll= owing operation first computes mask=3D0x3fffff and then
= * uses mask to extract the wanted bits from base
*/

- = uint32_t mask =3D (1 << (128 - ipv6_netbits) ) - 1;+ uint32_t mask =3D= (1 << (128 - ipv6_netbits)) - 1;
base &= amp;=3D mask;
}

= @@ -233,24 +224,21 @@
if (base =3D=3D 0) {
msg(D_IFCONFIG_POOL, "I= FCONFIG POOL IPv6: incrementing pool start "
- "to avoid ::0 assignment&q= uot;);
+ = "to avoid ::0 assignment");
= base++;
pool->ipv6.base.s6_addr= [15]++;
}

- pool_ipv6_size =3D ipv6_netbits >= ;=3D 112
- = ? (1 << (128 - ipv6_netbits)) - base
- : IFCONFIG_POOL= _MAX;
+ pool_i= pv6_size =3D
+ = ipv6_netbits >=3D 112 ? (1 << (128 - ipv6_netbits)) - base : = IFCONFIG_POOL_MAX;

if (pool_ipv6= _size < 2)
{
- msg(M_FATAL, "IPv6 pool size is too sma= ll (%d), must be at least 2",
- pool_ipv6_size);
+ msg(M_FATAL, "IPv6 pool size is = too small (%d), must be at least 2", pool_ipv6_size);
= }

msg(D_IFCONFIG_POOL, = "IFCONFIG POOL IPv6: base=3D%s size=3D%d netbits=3D%d",- print_in6_addr(pool= ->ipv6.base, 0, &gc), pool_ipv6_size,
- ipv6_netbits);
+ print_in6_addr(pool->ipv6.base= , 0, &gc), pool_ipv6_size, ipv6_netbits);

<= span> /* if there is no v4 pool, or the v6 pool is smaller, use
* v6 pool size as "unified pool size"
@@ -265,16 +253,20 @@
{
= if (pool_ipv4_size < pool_ipv6_size)
{
- msg(M_INFO,= "NOTE: IPv4 pool size is %d, IPv6 pool size is %d. "
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(M_INFO,
<= br>+ "NOTE:= IPv4 pool size is %d, IPv6 pool size is %d. "
= "IPv4 pool size limits the number of clients that can be &qu= ot;
- &q= uot;served from the pool", pool_ipv4_size, pool_ipv6_size);
= + "served f= rom the pool",
+= pool_ipv4_size, pool_ipv6_size);
}=
else if (pool_ipv4_size > pool_ipv6_size)
{
= - msg(M_WARN, "WARNING: IPv4 pool size is %d, IPv6 pool siz= e is %d. "
+ = msg(M_WARN,
+= "WARNING: IPv4 pool size is %d, IPv6 pool size is %d. = "
"IPv6 pool size limits the num= ber of clients that can be "
"se= rved from the pool. This is likely a MISTAKE - please check "- "your con= figuration", pool_ipv4_size, pool_ipv6_size);
+ "your configuration&quo= t;,
+ = pool_ipv4_size, pool_ipv6_size);
}
}


@@ -303,7 +295,8 @@
}


ifconfig_pool_handle
-ifconfig_pool_acquire(struct ifconf= ig_pool *pool, in_addr_t *local, in_addr_t *remote, struct in6_addr *remote= _ipv6, const char *common_name)

+ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t *lo= cal, in_addr_t *remote,
+ struct in6_addr *remote_ipv6, const char *common_= name)
{
int i;

@@ -403,8 +396,7 @@
}
=
static ifconfig_pool_handle
-ifconfig_pool_ipv6_base_to_handle(const struct ifconfig_po= ol *pool,
- = const struct in6_addr *in_addr)
+ifconfig_pool_ipv6_base_to_handle(const s= truct ifconfig_pool *pool, const struct in6_addr *in_addr)
= {
ifconfig_pool_handle ret;
uint= 32_t base, addr;
@@ -423,14 +415,10 @@
= }
}

- base =3D (pool->ipv6.base.s6_addr[12] <= < 24)
- | = (pool->ipv6.base.s6_addr[13] << 16)
- | (pool->ipv6.base.s6_addr[14] <<= ; 8)
- | pool= ->ipv6.base.s6_addr[15];
+ base =3D (pool->ipv6.base.s6_addr[12] << 24) | (pool-&= gt;ipv6.base.s6_addr[13] << 16)
+ | (pool->ipv6.base.s6_addr[14] << 8) = | pool->ipv6.base.s6_addr[15];

- addr =3D (in_addr->s6_addr[12] <&= lt; 24)
- | (= in_addr->s6_addr[13] << 16)
- | (in_addr->s6_addr[14] << 8)
= + addr =3D (in_addr->s6_a= ddr[12] << 24) | (in_addr->s6_addr[13] << 16) | (in_addr->= ;s6_addr[14] << 8)
| in_addr->s6_addr[= 15];

ret =3D addr - base;
= @@ -479,14 +467,14 @@
/* IPv6 pools are always I= NDIV (--linear) */
if (pool->ipv6.enabled &&= ; hand >=3D 0 && hand < pool->size)
{=
- ret =3D add_i= n6_addr( pool->ipv6.base, hand );
+ ret =3D add_in6_addr(pool->ipv6.base, hand);
}
return ret;
}

static void
-ifconfig_pool_set(struct ifconfig_pool *pool, const = char *cn,
- = ifconfig_pool_handle h, const bool fixed)
+ifconfig_pool_set(struct ifconfig_pool *pool, c= onst char *cn, ifconfig_pool_handle h,
+ const bool fixed)
{
struct ifconfig_pool_entry *e =3D &pool->list[h]= ;
ifconfig_pool_entry_free(e, true);
@= @ -558,7 +546,8 @@
if (refresh_freq > 0)
= {
ret->fixed =3D false;
- ret->file =3D status_op= en(filename, refresh_freq, -1, NULL, STATUS_OUTPUT_READ|STATUS_OUTPUT_WRITE= );

+ ret->f= ile =3D
+ = status_open(filename, refresh_freq, -1, NULL, STATUS_OUTPUT_READ | STATUS_O= UTPUT_WRITE);
}
else
{

@@ -641,8 +630,7 @@
= * - CN,IP4
* - CN,,IP6
= */
- = if (!buf_parse(&in, ',', cn_buf, buf_size)
- || !buf_parse(&in, = ',', ip_buf, buf_size))
+ if (!buf_parse(&in, ',', cn_buf, buf_si= ze) || !buf_parse(&in, ',', ip_buf, buf_size))
= {
continue;
= }
@@ -652,22 +640,18 @@
= if (strlen(ip_buf) > 0)
{
<= span> bool v4_ok =3D true;

- in_addr_t addr =3D getaddr(GETADDR_HOS= T_ORDER, ip_buf, 0, &v4_ok,
- NULL);
+ in_addr_t addr =3D ge= taddr(GETADDR_HOST_ORDER, ip_buf, 0, &v4_ok, NULL);

if (!v4_ok)
= {
- = msg(M_WARN, "pool: invalid IPv4 (%s) for CN=3D%s", ip_buf,
- cn= _buf);
+ = msg(M_WARN, "pool: invalid IPv4 (%s) for CN=3D%s", ip_buf,= cn_buf);
}
= else
{
= h =3D ifconfig_pool_ip_base_to_handle(pool, addr);
= if (h < 0)
{
- ms= g(M_WARN,
- = "pool: IPv4 (%s) out of pool range for CN=3D%s",<= /span>
- = ip_buf, cn_buf);
- msg(M_WARN, "pool: invalid IPv6 (%s) for CN=3D%s= ", ip6_buf,
- = cn_buf);
+ msg(M_WARN, "pool: invalid IPv6 (%s) for C= N=3D%s", ip6_buf, cn_buf);
} else
{
= h6 =3D ifconfig_pool_ipv6_base_to_handle(pool, &= amp;addr6);
if (h6 < 0)
<= span> {

- msg(M_WARN,
- "pool: IPv6 (%s) out o= f pool range for CN=3D%s",
- ip6_buf, cn_buf);
+ msg(M_WARN, &qu= ot;pool: IPv6 (%s) out of pool range for CN=3D%s", ip6_buf, cn_buf);
}

= /* Rely on IPv6 if no IPv4 was provided or the one provid= ed
@@ -708,8 +689,7 @@
*/
if ((h6 >=3D 0) && (h !=3D h6))=
{
- "pool: IPv4 (%s) and IPv6 (%s) have diffe= rent offsets! Relying on IPv4",
+ msg(M_WARN, "pool: IPv4 (%s) and IPv6= (%s) have different offsets! Relying on IPv4",
= ip_buf, ip6_buf);
}
<= span>

@@ -760,7 +740,7 @@
CLEAR(array= );

msg(M_INFO | M_NOPREFIX, "**= ********** 1");
- = for (i =3D 0; i < (int) SIZE(array); ++i)
+ for (i =3D 0; i < (int)SIZE(array); ++i)=
{
char *cn;
= ifconfig_pool_handle h;
@@ -778,15 +758,12 @@
break;
}
= msg(M_INFO | M_NOPREFIX, "IFCONFIG_POOL TEST pass 1: l=3D%s r= =3D%s cn=3D%s",
- = print_in_addr_t(local, 0, &gc),
- print_in_addr_t(remote, 0, &gc),
- cn);=
+ print_in_addr_= t(local, 0, &gc), print_in_addr_t(remote, 0, &gc), cn);
<= span> array[i] =3D h;

-
}

msg(= M_INFO | M_NOPREFIX, "************* 2");
- for (i =3D (int) SIZE(array) / 16; i < = (int) SIZE(array) / 8; ++i)
+ for (i =3D (int)SIZE(array) / 16; i < (int)SIZE(array) / 8; = ++i)
{
msg(M_INFO, "Atte= mpt to release %d cn=3D%s", array[i], p->list[i].common_name);
if (!ifconfig_pool_release(p, array[i]))
@@ -799,13 +776,13 @@

CLEAR(array);

msg(M_INFO | M_NOPREFIX, "**************** 3&q= uot;);
- for (i =3D = 0; i < (int) SIZE(array); ++i)
+ for (i =3D 0; i < (int)SIZE(array); ++i)
{

char *cn;
ifcon= fig_pool_handle h;
in_addr_t local, remote;=
char buf[256];
- snprintf(buf, sizeof(buf), "common-name-%d", = i+24);
+ snpri= ntf(buf, sizeof(buf), "common-name-%d", i + 24);
= #ifdef DUP_CN
cn =3D NULL;
#else=
@@ -817,11 +794,8 @@
break;
}
msg(M_INFO | M_NOPREFIX,= "IFCONFIG_POOL TEST pass 3: l=3D%s r=3D%s cn=3D%s",
- print_in_addr_t(local,= 0, &gc),

- = print_in_addr_t(remote, 0, &gc),
- cn);
+ print_in_addr_t(local, 0, &gc), print_in_ad= dr_t(remote, 0, &gc), cn);
array[i] =3D h;
-
}

ifconfig_pool_free(p);
diff --git a/src/openvpn/pool.h b/src/openvpn/pool.h

inde= x 9c3905d..39f9d98 100644
--- a/src/openvpn/pool.h+++ b/src/openvpn/pool.h
@@ -30,7 +30,7 @@ #include "status.h"

#= define IFCONFIG_POOL_MAX 65536
-#define IFCONFIG_POOL_MIN_NETBITS 16
+#define IFCONFIG_POOL_MIN_NETBITS 16

enum pool_type
{<= br>@@ -49,12 +49,14 @@
struct ifconfig_pool {
bool duplicate_cn;
- struct {
+ struct
+ {
bool enabled;
= enum pool_type type;
in_addr_t base;
} ipv4;
- struct {
+ s= truct
+ { bool enabled;
struct in6_addr bas= e;
} ipv6;
@@ -70,18 +72,18 @@<= br>
typedef int ifconfig_pool_handle;

-struct ifconfig_p= ool *ifconfig_pool_init(const bool ipv4_pool,
- enum pool_= type type, in_addr_t start,
+struct ifconfig_pool *ifconfig_pool_init(const bool ipv4_pool, enum= pool_type type, in_addr_t start,
= in_addr_t end, const bool duplicate_cn,
- = const bool ipv6_pool,
= - const struct in6_addr ipv6_base,<= /span>
+ = const bool ipv6_pool, const struct in6_addr ipv6_base,=
const int ipv6_n= etbits);

void ifconfig_pool_free(struct = ifconfig_pool *pool);

bool ifconfig_pool= _verify_range(const int msglevel, const in_addr_t start, const in_addr_t en= d);

-= ifconfig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_a= ddr_t *local, in_addr_t *remote, struct in6_addr *remote_ipv6, const char *= common_name);
+ifconf= ig_pool_handle ifconfig_pool_acquire(struct ifconfig_pool *pool, in_addr_t = *local,
+ = in_addr_t *remote, struct in6_addr *remote_i= pv6,
+ = const char *common_name);

bool ifconfig_pool_release(struct ifconfig_pool *pool, ifconf= ig_pool_handle hand, const bool hard);

di= ff --git a/src/openvpn/proto.c b/src/openvpn/proto.c
index = 90930fe..6ab40a2 100644
--- a/src/openvpn/proto.c+++ b/src/openvpn/proto.c
@@ -55,8 +55,7 @@ else if (tunnel_type =3D=3D DEV_TYPE_TAP)
= {
const struct openvpn_ethhdr *eh;
- if (BLEN(buf) < (sizeof(s= truct openvpn_ethhdr)

-= + sizeof(struct openvpn_iphdr)))
+ if (BLEN(buf) < (sizeof(st= ruct openvpn_ethhdr) + sizeof(struct openvpn_iphdr)))
= {
return false;
}=
@@ -72,8 +71,7 @@
if (proto =3D= =3D htons(OPENVPN_ETH_P_8021Q))
{
= const struct openvpn_8021qhdr *evh;
- if (BLEN(buf) < (sizeof(struct op= envpn_ethhdr)
- = + sizeof(struct openvpn_iphdr)))
+ if (BLEN(buf) < (sizeof(st= ruct openvpn_ethhdr) + sizeof(struct openvpn_iphdr)))
= {
return false;
= }
@@ -110,12 +108,12 @@
bool
is_ipv4(int tunnel_type, struct buffer *buf)
{

- return is_ipv_= X( tunnel_type, buf, 4 );
+ return is_ipv_X(tunnel_type, buf, 4);
} bool
is_ipv6(int tunnel_type, struct buffer *buf)=
{
- = return is_ipv_X( tunnel_type, buf, 6 );
+ return is_ipv_X(tunnel_type, buf, 6);
<= span> }



@@ -132,9 +130,= 8 @@
*/
for (int i =3D 0; i <= len_payload; i +=3D 2)
{
- sum +=3D (uint16_t)(((payload[i] <<= 8) & 0xFF00)
- = +((i + 1 < len_payload) ? (payload[i + 1] & 0= xFF) : 0));
-+ sum +=3D (uint16_t)((= (payload[i] << 8) & 0xFF00)
+ + ((i + 1 < len_payload) ? (= payload[i + 1] & 0xFF) : 0));
}
<= /span>
/*
@@ -144,7 +141,6 @@
for (int i =3D 0; i < addr_len; i +=3D 2)

{
sum +=3D (uint16_t)((src_addr[i] << 8) & = 0xFF00) + (src_addr[i + 1] & 0xFF);
-
}
for (int i = =3D 0; i < addr_len; i +=3D 2)
{
@@= -167,17 +163,14 @@
}

/* Take the one's complement of sum */

- return ((uint16_t) ~sum);
+ return ((uint16_t)~sum); }

#ifdef PACKET_TRUNCATION_CHEC= K

void
-ipv4_packet_size_verify(const uint8_t *data,
= - const in= t size,
- = const int tunnel_type,
- const char *prefix,
- counter_type *erro= rs)
+ipv4_packet_size= _verify(const uint8_t *data, const int size, const int tunnel_type,<= br>+ con= st char *prefix, counter_type *errors)
{
= if (size > 0)
{
@@ -193,13 +186= ,13 @@
const char *msgstr =3D "PACKET SIZ= E INFO";
unsigned int msglevel =3D D_PACK= ET_TRUNC_DEBUG;

- if (BLEN(&buf) < (int) sizeof(struct openvpn= _iphdr))
+ = if (BLEN(&buf) < (int)sizeof(struct openvpn_iphdr))
{

return;
= }

verify_align_4(= &buf);
- = pip =3D (struct openvpn_iphdr *) BPTR(&buf);
+ pip =3D (struct openvpn_iphdr *)B= PTR(&buf);

hlen =3D OPEN= VPN_IPH_GET_LEN(pip->version_len);
totlen = =3D ntohs(pip->tot_len);
@@ -214,13 +207,8 @@
= }
}

- msg(msgleve= l, "%s %s: size=3D%d totlen=3D%d hlen=3D%d errcount=3D" counter_f= ormat,
- = msgstr,
- = prefix,
- = BLEN(&buf),
- = totlen,
= - hlen,
= - errors ? *errors : (counter_type)0);
+ msg(msglevel, "%s %s: si= ze=3D%d totlen=3D%d hlen=3D%d errcount=3D" counter_format, msgstr,
+ prefix,= BLEN(&buf), totlen, hlen, errors ? *errors : (counter_type)0);<= br> }
}
}
diff --git a/src/openvpn/proto.h b/src/openvpn/proto.h

i= ndex 11c2a49..f7f0060 100644
--- a/src/openvpn/proto.h
+++ b/src/openvpn/proto.h
@@ -33,15 +33,15 @@
* Tunnel types
*/
#defi= ne DEV_TYPE_UNDEF 0
-#d= efine DEV_TYPE_TUN 2 /* point-to-point IP tunnel */
-#define DEV_TYPE_TAP 3 /* ethernet = (802.3) tunnel */
+#d= efine DEV_TYPE_TUN 2 /* point-to-point IP tunnel */
+#define DEV_TYPE_TAP 3 /* ethernet (802= .3) tunnel */

/* TUN topologies */

-#define T= OP_UNDEF 0
-#define T= OP_NET30 1
-#define T= OP_P2P 2
-#define T= OP_SUBNET 3
+#define= TOP_UNDEF 0
+#defin= e TOP_NET30 1
+#defi= ne TOP_P2P 2
+#def= ine TOP_SUBNET 3

/*
* = IP and Ethernet protocol structs. For portability,
@@ -50,= 46 +50,45 @@
* native structs.
*/

-#define O= PENVPN_ETH_ALEN 6 /* ethernet address length */
+#define OPENVPN_ETH_ALEN 6 /* ethern= et address length */
struct openvpn_ethhdr
{

uint8_t dest[OPENVPN_ETH_ALEN]; /* destination e= thernet addr */
uint8_t source[OPENVPN_ETH_ALEN]; /* s= ource ethernet addr */

-#define OPENVPN_ETH_P_IPV4 0x0800 /* IPv4 protocol= */
-#define OPENVPN_ET= H_P_IPV6 0x86DD /* IPv6 protocol */
-#define OPENVPN_ETH_P_ARP 0x0806 /* ARP protocol */<= /span>
-#define OPENVPN_ETH_P_= 8021Q 0x8100 /* 802.1Q protocol */
+#define OPENVPN_ETH_P_IPV4 0x0800 /* IPv4 protocol */=
+#define OPENVPN_ETH= _P_IPV6 0x86DD /* IPv6 protocol */
+#define OPENVPN_ETH_P_ARP 0x0806 /* ARP protocol */=
+#define OPENVPN_ETH= _P_8021Q 0x8100 /* 802.1Q protocol */
uint16_t prot= o; /* packet type ID field */
};<= br>
struct openvpn_8021qhdr
{
- uint8_t dest[OPENVPN_E= TH_ALEN]; /* destination ethernet addr */
- uint8_t source[OPENVPN_ETH_ALEN]; /* source e= thernet addr */
+ = uint8_t dest[OPENVPN_ETH_ALEN]; /* destination ethernet addr */
+ uint8_t source[OPE= NVPN_ETH_ALEN]; /* source ethernet addr */
<= br>- uint16_t tpid; = /* 802.1Q Tag Protocol Identifier */
+ uint16_t tpid; /*= 802.1Q Tag Protocol Identifier */
#define OPENVPN_8021Q_M= ASK_PCP htons(0xE000) /* mask PCP out of pcp_cfi_vid */
#d= efine OPENVPN_8021Q_MASK_CFI htons(0x1000) /* mask CFI out of pcp_cfi_vid *= /
#define OPENVPN_8021Q_MASK_VID htons(0x0FFF) /* mask VID= out of pcp_cfi_vid */
= - uint16_t pcp_cfi_vid; /* bit fields, see IEEE 802.1Q */<= /span>
- uint16_t proto; = /* contained packet type ID field */
+ uint16_t pcp_cfi_vid; = /* bit fields, see IEEE 802.1Q */
+ uint16_t proto; /* containe= d packet type ID field */
};

<= span> /*

* Size difference between a regular Ethernet II = header and an Ethernet II
* header with additional IEEE 8= 02.1Q tagging.
*/
-#define SIZE_ETH_TO_8021Q_HDR (sizeof(struct openvpn_8021qhdr= ) \
- = - sizeof(struct openvpn_ethhdr))
+#define SIZE_ETH_TO_8021Q_HDR (sizeof(struct open= vpn_8021qhdr) - sizeof(struct openvpn_ethhdr))

= /** Version of IN6_ARE_ADDR_EQUAL that is guaranteed to work for
* unaligned access. E.g. Linux uses 32bit compares which ar= e
* not safe if the struct is unaligned. */
-#define OPENVPN_IN6_ARE_ADDR_EQUAL= (a, b) \

- (memcmp(a= , b, sizeof(struct in6_addr)) =3D=3D 0)
+#define OPENVPN_IN6_ARE_ADDR_EQUAL(a, b) (memcmp(a, b, = sizeof(struct in6_addr)) =3D=3D 0)

-struct openvpn_iphdr {
+struct openvpn_iphdr
+{
#define OPENVPN_IPH_= GET_VER(v) (((v) >> 4) & 0x0F)
#define OPENVPN_I= PH_GET_LEN(v) (((v) & 0x0F) << 2)
uint8_t ve= rsion_len;
@@ -103,9 +102,9 @@

= uint8_t ttl;

-#define OPENVPN_IPPROTO_IGMP 2 /* IGMP protocol */<= /span>
-#define OPENVPN_IPPROT= O_TCP 6 /* TCP protocol */
-#define OPENVPN_IPPROTO_UDP 17 /* UDP protocol */
<= span style=3D"color: hsl(120, 100%, 40%);">+#define OPENVPN_IPPROTO_IGMP = 2 /* IGMP protocol */

+#define OPENVPN_IPPROTO_UDP 17 /* UD= P protocol */
#define OPENVPN_IPPROTO_ICMPV6 58 /* ICMPV6 = protocol */
uint8_t protocol;
=
@@ -118,31 +117,33 @@
/*
* IPv= 6 header
*/
-struct openvpn_ipv6hdr {
+struct openvpn_ipv6hdr
+{
uint8_t version_prio;
uint8_t flow_lbl[3];

uint16_t payload_len;
uint8_t nexthdr;
uint8_t hop_limit;

- s= truct in6_addr saddr;
= - struct in6_addr daddr;
+ struct in6_addr saddr;
+ struct in6_addr daddr;
};

/*
* ICMPv6 header
*/

-struct openvpn_i= cmp6hdr {
-#define OPEN= VPN_ICMP6_DESTINATION_UNREACHABLE 1
-#define OPENVPN_ND_ROUTER_SOLICIT 133
-#define OPENVPN_ND_ROUT= ER_ADVERT 134
-#define OPENVPN_ND_NEIGHBOR_SOLICIT 135
-#define OPENVPN_ND_NEIGHBOR_ADVERT= 136

-#d= efine OPENVPN_ND_INVERSE_SOLICIT 141
-#define OPENVPN_ND_INVERSE_ADVERT = 142
+struct op= envpn_icmp6hdr
+{
+#define OPENVPN_ICMP6_D= ESTINATION_UNREACHABLE 1
+#define OPENVPN_ND_ROUTER_SOLICIT 133
+#define OPENVPN_ND_ROUTER_ADVERT = 134
+#define OP= ENVPN_ND_NEIGHBOR_SOLICIT 135
+#define OPENVPN_ND_NEIGHBOR_ADVERT 136
+#define OPENVPN_ND_INVERS= E_SOLICIT 141
+#define OPENVPN_ND_INVERSE_ADVERT 142
= uint8_t icmp6_type;
-#= define OPENVPN_ICMP6_DU_NOROUTE 0
-#define OPENVPN_ICMP6_DU_COMMUNICATION_PROH= IBTED 1
+#define O= PENVPN_ICMP6_DU_NOROUTE 0
+#define OPENVPN_ICMP6_DU_COMMUNICATION_PROHIBTED 1
uint8_t icmp6_code;
uint16_t icmp6_= cksum;
uint8_t icmp6_dataun[4];
@@ -15= 1,7 +152,8 @@
/*
* UDP header
= */
-struct open= vpn_udphdr {
+struct = openvpn_udphdr
+{
uint16_t source;
uint16_t dest;
uint16_t len;
@@ -161,23 +163,24 @@=
/*
* TCP header, per RFC 793.
= */
-struct openvpn_tc= phdr {
- uint16_t so= urce; /* source port */
- uint16_t dest; /* destination port */
- uint32_t seq; /* sequence = number */
- uint32_t= ack_seq; /* acknowledgement number */
+struct openvpn_tcphdr
+{
+ uint16_t source; /* source port */
+ uint16_t dest; /* destination port */
+ uint32_t seq; = /* sequence number */
+ uint32_t ack_seq; /* acknowledgement number */

#define OPENVPN_TCPH_GET_DOFF(d) (((d) & 0xF0) >> 2)=
uint8_t doff_res;

-#define OPENVPN_TCPH_FIN_MASK (1<<= ;0)
-#define OPENVPN_TC= PH_SYN_MASK (1<<1)
-#define OPENVPN_TCPH_PSH_MASK (1<<3)-#define OPENVPN_TCPH_ACK_MASK = (1<<4)
-#define O= PENVPN_TCPH_URG_MASK (1<<5)
-#define OPENVPN_TCPH_ECE_MASK (1<<6)
-#define OPENVPN_TCPH_CWR_MASK (1<<7)=
+#define OPENVPN_TCP= H_FIN_MASK (1 << 0)
+#define OPENVPN_TCPH_SYN_MASK (1 << 1)
+#define OPENVPN_TCPH_RST_MASK (1 << 2)=
+#define OPENVPN_TCP= H_PSH_MASK (1 << 3)
+#define OPENVPN_TCPH_ACK_MASK (1 << 4)
+#define OPENVPN_TCPH_URG_MASK (1 << 5)=
+#define OPENVPN_TCP= H_ECE_MASK (1 << 6)
+#define OPENVPN_TCPH_CWR_MASK (1 << 7)
uin= t8_t flags;

uint16_t window;<= br>@@ -190,9 +193,11 @@
#define OPENVPN_TCPOPT_MAXSE= G 2
#define OPENVPN_TCPOLEN_MAXSEG 4

-struct ip_tcp_udp_hdr {<= /span>
+struct ip_tcp_udp_hd= r
+{
= struct openvpn_iphdr ip;
- union {
+= union
+ {
struct openvpn_tcphdr tcp;
st= ruct openvpn_udphdr udp;
} u;
@@ -208,= 30 +213,36 @@
* subtracting out new words), and "cks= um"
* is the checksum value to be updated. */
-#define AD= JUST_CHECKSUM(acc, cksum) { \
- int _acc =3D acc; \
- _acc +=3D (cksum); \
- if (_acc < 0) { \
- _acc =3D -_acc; \
+#define ADJUST_CHECKSUM(acc, cksum) = \
+ = { \
+ int _acc =3D acc; = \
+ _ac= c +=3D (cksum); \
+ if (_acc < 0) = \
+ { = \
+ _acc =3D -_acc; \
_acc =3D (_acc >> 16) + (_acc & 0xffff= ); \
- _acc = +=3D _acc >> 16; \
- } else { \
+ _acc +=3D _acc >> 16; = \
+ = (cksum) =3D (uint16_t)~_acc; \
+ } = \
+ else = \
+ { \=
_acc =3D (_acc >> 16) + (_acc & 0xffff); \=
- _acc +=3D= _acc >> 16; \
- = (cksum) =3D (uint16_t) _acc; \
- } \
-}
+ = _acc +=3D _acc >> 16; \
+ (cksum) =3D (uint16_t)_acc; = \
+ = } \
+ }

-#define ADD_CHECKSUM_32(acc, u32) { \- acc +=3D (u32) & 0= xffff; \
- acc += =3D (u32) >> 16; \
-}
+#define ADD_= CHECKSUM_32(acc, u32) \
+ { \
+ acc +=3D (u32) & 0xffff; \
+ acc +=3D (u32) >> 1= 6; \

+ }

-#define= SUB_CHECKSUM_32(acc, u32) { \
- acc -=3D (u32) & 0xffff; \
- acc -=3D (u32) >> 16; \-}
+#define SUB_CHECKSUM_32(acc, u32) \
+ { = \

+ acc -=3D= (u32) & 0xffff; \
+ acc -=3D (u32) >> 16; \
+ }

/*
* This returns an ip protocol version of packet inside tun=
@@ -246,7 +257,7 @@
if (tunnel_type = =3D=3D DEV_TYPE_TUN)
{
*ip_hd= r_offset =3D 0;
- = if (likely(BLEN(buf) >=3D (int) sizeof(struct openvpn_iphdr)))<= br>+ if (likely(BLEN(buf= ) >=3D (int)sizeof(struct openvpn_iphdr)))
{
ip_ver =3D OPENVPN_IPH_GET_VER(*BPTR(buf));
}
@@ -257,7 +268,7 @@
= /* for tap get ip version from eth header */
= if (likely(BLEN(buf) >=3D *ip_hdr_offset))
= {
- const st= ruct openvpn_ethhdr *eh =3D (const struct openvpn_ethhdr *) BPTR(buf);
+ const struct= openvpn_ethhdr *eh =3D (const struct openvpn_ethhdr *)BPTR(buf); uint16_t proto =3D ntohs(eh->proto);
if (proto =3D=3D OPENVPN_ETH_P_IPV6)

= {
@@ -294,17 +305,12 @@
* @param pro= to next - header or IP protocol of the packet
* @retur= n The calculated checksum in host order
*/
-uint16_t

-ip_checksum(const sa_family_t af, const uint8_t *= payload, const int len_payload,
- const uint8_t *src_addr, const uint8_t *dest_addr, c= onst int proto);
+uin= t16_t ip_checksum(const sa_family_t af, const uint8_t *payload, const int l= en_payload,
+ = const uint8_t *src_addr, const uint8_t *dest_addr, const int p= roto);

#ifdef PACKET_TRUNCATION_CHECK
-void ipv4_packet_size_ve= rify(const uint8_t *data,
- const int size,
- const int tunnel_ty= pe,
- = const char
-= *prefix,
- counter_type *errors);<= br>+void ipv4_packet_size_verif= y(const uint8_t *data, const int size, const int tunnel_type,
+ cons= t char *prefix, counter_type *errors);


#= endif

diff --git a/src/openvpn/proxy.c b/= src/openvpn/proxy.c
index 0117a66..97ba650 100644--- a/src/openvpn/proxy.c
+++ b/src/openvpn/proxy.c<= /span>
@@ -40,11 +40,10 @@
#include "memdbg.= h"
#include "forward.h"

-#define UP_TYPE_PROXY = "HTTP Proxy"
+#define UP_TYPE_PROXY "HTTP Proxy"

struct http_proxy_options *
-init_http_proxy_options_once(struct http_proxy_options = **hpo,
- = struct gc_arena *gc)
+init_http_proxy_options_once(struct http_proxy_options **hpo= , struct gc_arena *gc)
{
if (!*hpo)
{
@@ -60,13 +59,8 @@
s= tatic struct user_pass static_proxy_user_pass;

= static bool
-rec= v_line(socket_descriptor_t sd,
- char *buf,
- int len,
- const int timeout_sec,
- const bool verbose,
- struct buffer *lookahead,
- volatile int *signal_receiv= ed)

+recv_line(socket= _descriptor_t sd, char *buf, int len, const int timeout_sec, const bool ver= bose,
+ stru= ct buffer *lookahead, volatile int *signal_received)
{
struct buffer la;
int lastc =3D 0;
@@ -162,7 +156,8 @@
{ if (verbose)
{
- msg(D= _LINK_ERRORS | M_ERRNO, "recv_line: Non-ASCII character (%d) read on r= ecv()", (int)c);
+ msg(D_LINK_ERRORS | M_ERRNO,
+ "recv_line: Non= -ASCII character (%d) read on recv()", (int)c);
= }
*lookahead =3D la;
= return false;
@@ -191,11 +186,10 @@<= /span>
}

static bool-send_line(socket_descriptor_t s= d,
- const cha= r *buf)
+send_line(so= cket_descriptor_t sd, const char *buf)
{
= const ssize_t size =3D send(sd, buf, strlen(buf), MSG_NOSIGNAL);=
- if (size !=3D (ssize_t) = strlen(buf))
+ if = (size !=3D (ssize_t)strlen(buf))
{
= msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed o= n send()");
return false;
@@ = -204,8 +198,7 @@
}

stat= ic bool
-send_line_crlf= (socket_descriptor_t sd,
+send_line_crlf(socket_descriptor_t sd, const char *src)
{
bool ret;

<= span>@@ -229,7 +222,7 @@

uint8_t *ret =3D NULL;=
char *b64out =3D NULL;
ASSERT(openvpn_b= ase64_encode((const void *)str, src_len, &b64out) >=3D 0);- ret =3D (uint8_t *) string_= alloc(b64out, gc);
+ = ret =3D (uint8_t *)string_alloc(b64out, gc);
free(b= 64out);
return ret;
}
@@ -241,8 +234,7 @@

}

= static const char *
-us= ername_password_as_base64(const struct http_proxy_info *p,
- struct gc_= arena *gc)
+username_= password_as_base64(const struct http_proxy_info *p, struct gc_arena *gc)
{
struct buffer out =3D alloc_buf_gc(st= rlen(p->up.username) + strlen(p->up.password) + 2, gc);
ASSERT(strlen(p->up.username) > 0);

@@ -286,1= 0 +278,7 @@
{
flags |= =3D GET_USER_PASS_INLINE_CREDS;
}
- get_user_pass(&static_prox= y_user_pass,
- = auth_file,
- UP_TYPE_PROXY,
- flags);
+ get_user_pass(&static_proxy_user_pas= s, auth_file, UP_TYPE_PROXY, flags);
static_proxy_= user_pass.nocache =3D p->options.nocache;
prote= ct_user_pass(&static_proxy_user_pass);
}@@ -326,9 +315,7 @@
* Consumes all headers.=
*/
static int
-get_proxy_authenticate(socket_descriptor_t sd,<= br>- int ti= meout,
- = char **data,
= +get_proxy_authenticate(socket_descriptor_t sd, int timeout, char **data,
volatile int *signal_received)
{
char buf[256];
@@ -348,2= 2 +335,22 @@
}
if (ret = =3D=3D HTTP_AUTH_NONE && !strncmp(buf, "Proxy-Authenticate: &q= uot;, 20))
{
- if (!strncmp(buf+20, "Basic ", 6))
+ if (!strnc= mp(buf + 20, "Basic ", 6))
{<= br> msg(D_PROXY, "PROXY AUTH BASIC: '%s'= ", buf);
- = *data =3D string_alloc(buf+26, NULL);
+ *data =3D string_alloc(buf + 26, = NULL);
ret =3D HTTP_AUTH_BASIC;
= }
#if PROXY_DIGEST_AUTH
- else if (!strncmp(buf+20,= "Digest ", 7))

+ else if (!strncmp(buf + 20, "Digest ", 7))
{
msg(D_PROXY, &q= uot;PROXY AUTH DIGEST: '%s'", buf);
- *data =3D string_alloc(buf+27, N= ULL);
+ = *data =3D string_alloc(buf + 27, NULL);
= ret =3D HTTP_AUTH_DIGEST;
}
#= endif
#if NTLM
- else if (!strncmp(buf+20, "NTLM", 4))
+ else if (!str= ncmp(buf + 20, "NTLM", 4))
{<= br> msg(D_PROXY, "PROXY AUTH NTLM: '%s'&= quot;, buf);
*data =3D NULL;
@@ -386,18 +373,16 @@

* Return true on success, or fal= se on parse failure.
*/
static bool
-get_key_value(const char *= str, /* source string */
- char *key, /* key stored here */<= br>- char *value, = /* value stored here */
- int max_key_len,
- int max_value_len,
- const char **endptr) /* nex= t search position */
= +get_key_value(const char *str, /* = source string */
+ = char *key, /* key = stored here */
+ = char *value, /* value = stored here */
+ = int max_key_len, int max_value_len, const char **endptr) /* next s= earch position */
{
int c;
= bool starts_with_quote =3D false;
bool esca= pe =3D false;

- for (c =3D max_key_len-1; (*str && (*str !=3D '= =3D') && c--); )
+ for (c =3D max_key_len - 1; (*str && (*str !=3D '= =3D') && c--);)
{
= *key++ =3D *str++;
}
@@ -416,7 +401,7= @@
starts_with_quote =3D true;
= }

= - for (c =3D max_value_len-1; *str && c--; str++)
+ for (c =3D max_value_len - 1; = *str && c--; str++)

{
= switch (*str)
{
@@ -530,7 +515,8 = @@
#if NTLM
else if (!strcmp(o-&g= t;auth_method_string, "ntlm"))
{<= br>- msg(M_WARN, "= ;NTLM v1 authentication has been removed in OpenVPN 2.7. Will try to use NT= LM v2 authentication.");
+ msg(M_WARN,
+ "NTLM v1 authentication has been removed= in OpenVPN 2.7. Will try to use NTLM v2 authentication.");
= p->auth_method =3D HTTP_AUTH_NTLM2;
= }
else if (!strcmp(o->auth_method_strin= g, "ntlm2"))
@@ -540,8 +526,7 @@
= #endif
else
{
= - msg(M_FATAL, "E= RROR: unknown HTTP authentication method: '%s'",
- o->auth_method_s= tring);

+ = msg(M_FATAL, "ERROR: unknown HTTP authentication method: '%s'&= quot;, o->auth_method_string);
}
}


@@ -556,7 +541,8 @@
#if !NTLM

if (p->auth_method =3D=3D HTTP_AUTH_= NTLM2)
{
- msg(M_FATAL, "Sorry, this version of " PACKAGE_NA= ME " was built without NTLM Proxy support.");
+ msg(M_FATAL,
+ "Sorry, this version = of " PACKAGE_NAME " was built without NTLM Proxy support.");=
}
#endif
@@ -571,10 +557,9 @@
}

= static bool
-add= _proxy_headers(struct http_proxy_info *p,
- socket_descriptor_t sd, /* already op= en to proxy */
- = const char *host /* openvpn server remote */
- )

+add_proxy_headers(struct http_prox= y_info *p, socket_descriptor_t sd, /* already open to proxy */

+ const char *ho= st /* openvpn server remote */

= +)
{ char buf[512];
int i;
@@ -= 585,12 +570,11 @@
* If content is NULL the whole head= er is in name
* Also remember if we already sent a Ho= st: header
*/
- for (i =3D 0; i < MAX_CUSTOM_HTTP_HEADER && p= ->options.custom_headers[i].name; i++)
+ for (i =3D 0; i < MAX_CUSTOM_HTTP_HEADER &= & p->options.custom_headers[i].name; i++)
{
if (p->options.custom_headers[i].content) {
- = snprintf(buf, sizeof(buf), "%s: %s",
- p->options.custom= _headers[i].name,
+ = snprintf(buf, sizeof(buf), "%s: %s", p->options.cust= om_headers[i].name,
p->options.cus= tom_headers[i].content);
if (!strcasecmp(p->= ;options.custom_headers[i].name, "Host"))
= {
@@ -599,8 +583,7 @@
}
else
{
- snprintf(buf, sizeof(buf), &quo= t;%s",
- = p->options.custom_headers[i].name);
+ snprintf(buf, sizeof(buf), "= %s", p->options.custom_headers[i].name);
= if (!strncasecmp(p->options.custom_headers[i].name, "Host:"= , 5))
{
host_= header_sent =3D true;
@@ -627,8 +610,7 @@
= /* send User-Agent string if provided */
if (p->= ;options.user_agent)
{
- snprintf(buf, sizeof(buf), "User-Agent: = %s",
- = p->options.user_agent);
+ snprintf(buf, sizeof(buf), "User-Agent: %s", = p->options.user_agent);
msg(D_PROXY, "Send= to HTTP proxy: '%s'", buf);
if (!sen= d_line_crlf(sd, buf))
{
@@ -642,11= +624,10 @@

bool
establ= ish_http_proxy_passthru(struct http_proxy_info *p,
- socket_descripto= r_t sd, /* already open to proxy */
- const char *host, /* op= envpn server remote */
= - const char *port, /* openvpn server= port */
- = struct event_timeout *server_poll_timeout,
- struct = buffer *lookahead,

+ = socket_descriptor_t sd, /* already open to pro= xy */
+ = const char *host, /* openvpn server remote */<= br>+ = const char *port, /* openvpn server port */
+ struct even= t_timeout *server_poll_timeout, struct buffer *lookahead,
= struct signal_info *sig_info)
{

struct gc_arena gc =3D gc_new();
@= @ -658,8 +639,7 @@
volatile int *signal_received =3D &= amp;sig_info->signal_received;

/*= get user/pass if not previously given */
- if (p->auth_method =3D=3D HTTP_AUTH_BASIC=
- || p->auth_method= =3D=3D HTTP_AUTH_DIGEST
+ if (p->auth_method =3D=3D HTTP_AUTH_BASIC || p->auth_method = =3D=3D HTTP_AUTH_DIGEST
|| p->auth_method =3D= =3D HTTP_AUTH_NTLM2)
{
get_us= er_pass_http(p, false);
@@ -671,7 +651,8 @@
unprotect_user_pass(&p->up);

}=

- /* are= we being called again after getting the digest server nonce in the previou= s transaction? */
+ = /* are we being called again after getting the digest server nonce in the= previous transaction?
-= snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
- host,
- port,
- p->op= tions.http_version);
= + snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s", host= , port, p->options.http_version);

= msg(D_PROXY, "Send to HTTP proxy: '%s'", buf);

@@ -724,8 +702,7 @@
= goto error;
}
=
- snpri= ntf(buf, sizeof(buf), "Proxy-Authorization: NTLM %s",
<= span style=3D"color: hsl(0, 100%, 40%);">- ntlm_pha= se_1(p, &gc));

+ = snprintf(buf, sizeof(buf), "Proxy-Authorization: NTLM %= s", ntlm_phase_1(p, &gc));
msg(D_= PROXY, "Attempting NTLM Proxy-Authorization phase 1");
= dmsg(D_SHOW_KEYS, "Send to HTTP proxy: '%s&= #39;", buf);
if (!send_line_crlf(sd, = buf))
@@ -749,7 +726,8 @@
}=

/* receive reply from proxy */<= br>- if (!recv_line(sd, bu= f, sizeof(buf), get_server_poll_remaining_time(server_poll_timeout), true, = NULL, signal_received))
+ if (!recv_line(sd, buf, sizeof(buf), get_server_poll_remaining_= time(server_poll_timeout),
+ true, NULL, signal_received))
{

goto error;
= }
@@ -761,7 +739,6 @@

= /* parse return string */
nparms =3D ssca= nf(buf, "%*s %d", &status);
-
}

/* check for a "407 Proxy Authentication Required" respon= se */

@@ -780,7 +757,9 @@
char= buf2[512];
while (true)
= {
- = if (!recv_line(sd, buf, sizeof(buf), get_server_poll_remaining_time(ser= ver_poll_timeout), true, NULL, signal_received))
+ if (!recv_line(sd, buf, sizeof= (buf),
+ = get_server_poll_remaining_time(server_poll_timeout), true= , NULL,
+ = signal_received))
{
goto error;
= }
@@ -811,9 +790,7 @@
/* n= ow send the phase 3 reply */

= /* format HTTP CONNECT message */
- snprintf(buf, sizeof(buf), "CONNECT %s:%s HTT= P/%s",
- = host,
- = port,
+ snprintf(buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",= host, port,
p->options.http_versi= on);

msg(D_PROXY, "Send= to HTTP proxy: '%s'", buf);
@@ -842,7 +819,8 = @@
const char *np3 =3D ntlm_phase_3(p, buf= 2, &gc);
if (!np3)
= {
- = msg(D_PROXY, "NTLM Proxy-Authorization phase 3 failed: r= eceived corrupted data from proxy server");
+ msg(D_PROXY,
+ "NTL= M Proxy-Authorization phase 3 failed: received corrupted data from proxy se= rver");

goto error;
}

snprintf(buf, sizeof= (buf), "Proxy-Authorization: NTLM %s", np3);
@@ -= 861,7 +839,9 @@
}

= /* receive reply from proxy */
- if (!recv_line(sd, buf, sizeof(buf)= , get_server_poll_remaining_time(server_poll_timeout), true, NULL, signal_r= eceived))
+ = if (!recv_line(sd, buf, sizeof(buf),
+ get_server_poll_remaining_tim= e(server_poll_timeout), true, NULL,
+ signal_received))
{

goto error;
}

@@ -905,7 +885,7 @@
= if (!realm || !nonce)
{=
msg(D_LINK_ERRORS, "HTTP proxy: digest = auth failed, malformed response "
- "from server: realm=3D or non= ce=3D missing" );
- snprintf(uri, sizeof(uri), "%s:%s&quo= t;,
- = host,
- = port);
- const int len =3D strlen(opaque)+16;
+ const int len = =3D strlen(opaque) + 16;

opaque_kv =3D= gc_malloc(len, false, &gc);
snpri= ntf(opaque_kv, len, ", opaque=3D\"%s\"", opaque);
}

- DigestCalcHA1(algor,
- user= name,

- = realm,
- = password,
- nonce,
- (char *)cnonc= e,
- = session_key);
- nonce,
- = nonce_count,
-= (char *)cnonce,
- qop,=
- = http_method,
- = uri,
- NULL,
- respo= nse);
+ = DigestCalcHA1(algor, username, realm, password, nonce, (char *)cnonce, se= ssion_key);
+ = DigestCalcResponse(session_key, nonce, nonce_count, (char *)cnonce,= qop,
+ = http_method, uri, NULL, response);

/* format HTTP CONNECT message */- snprintf(buf, s= izeof(buf), "%s %s HTTP/%s",
- http_method,
- uri,
+ snprintf(buf, si= zeof(buf), "%s %s HTTP/%s", http_method, uri,

= p->options.http_version);

msg(D_PROXY, "Send to HTTP proxy: '%s&= #39;", buf);
@@ -964,17 +927,10 @@
= }

/* send = digest response */
- = int sret =3D snprintf(buf, sizeof(buf), "Proxy-Authorizat= ion: Digest username=3D\"%s\", realm=3D\"%s\", nonce=3D= \"%s\", uri=3D\"%s\", qop=3D%s, nc=3D%s, cnonce=3D\&quo= t;%s\", response=3D\"%s\"%s",
- username,
- = realm,
- = nonce,
- uri,
- q= op,

- = nonce_count,
- cnonce,
- respons= e,
- = opaque_kv
- );
+ int sret =3D snprintf(
+ buf, sizeof(= buf),

+ = "Proxy-Authorization: Digest username=3D\"%s\", realm= =3D\"%s\", nonce=3D\"%s\", uri=3D\"%s\", qop= =3D%s, nc=3D%s, cnonce=3D\"%s\", response=3D\"%s\"%s&qu= ot;,
+ = username, realm, nonce, uri, qop, nonce_count, cnonce, response, opaqu= e_kv);
if (sret >=3D sizeof(buf))
{
goto err= or;
@@ -993,7 +949,9 @@
se= cure_memzero(buf, sizeof(buf));

= /* receive reply from proxy */
- if (!recv_line(sd, buf, sizeof(buf), get_s= erver_poll_remaining_time(server_poll_timeout), true, NULL, signal_received= ))
+ i= f (!recv_line(sd, buf, sizeof(buf),
+ get_server_poll_remaining_ti= me(server_poll_timeout), true, NULL,
+ signal_received)) {
goto error;<= /span>
}
@@ -1018,10 +976,8 @@
{
/* figure out what ki= nd of authentication the proxy needs */
char *= pa =3D NULL;
- = const int method =3D get_proxy_authenticate(sd,
- = get_server_poll_remaining_time(server_poll_timeout),
- = &pa,

- signal_received)= ;
+ const = int method =3D get_proxy_authenticate(
+ sd, get_server_poll_remaining_time(serve= r_poll_timeout), &pa, signal_received);
if= (method !=3D HTTP_AUTH_NONE)
{
if (pa)

@@ -1030,7 +986,8 @@
<= span> }

if (p->options.= auth_retry =3D=3D PAR_NCT && method =3D=3D HTTP_AUTH_BASIC)<= br> {
- msg(D_PROXY, "HTTP proxy: support for basic = auth and other cleartext proxy auth methods is disabled");
<= span style=3D"color: hsl(120, 100%, 40%);">+ msg(D_PROXY= ,

+ = "HTTP proxy: support for basic auth and other cleartext proxy au= th methods is disabled");
free(pa= );
goto error;
= }
@@ -1041,7 +998,8 @@
= }
else
{
- msg(D_PROXY= , "HTTP proxy: do not recognize the authentication method required by = proxy");
+ = msg(D_PROXY,
- if (!recv_= line(sd, NULL, 0, get_server_poll_remaining_time(server_poll_timeout), true= , NULL, signal_received))
+ if (!recv_line(sd, NULL, 0, get_server_poll_remaining_time(server= _poll_timeout), true, NULL,
+ signal_received))
{<= br> goto error;
}
@@ -10= 83,7 +1042,8 @@
{
}

- /* reset quer= ied_creds so that we don't think that the next creds request is due to = an auth error */
+ = /* reset queried_creds so that we don't think that the next creds requ= est is due to an auth
+ * error */
p->queried_creds =3D false;

#if 0
diff --git a/src/openvp= n/proxy.h b/src/openvpn/proxy.h
index cf1fbdb..054fe8c 1006= 44
--- a/src/openvpn/proxy.h
+++ b/src/open= vpn/proxy.h
@@ -35,19 +35,21 @@
#define HT= TP_AUTH_NTLM2 4
#define HTTP_AUTH_N 5 /* number of H= TTP_AUTH methods */

-struct http_custom_header {
+struct http_custom_header
+{
const char *name;
const char *content;
};
=
#define MAX_CUSTOM_HTTP_HEADER 10
-struct http_proxy_options {
+struct http_proxy_options
+{
const = char *server;
const char *port;

-#define PAR_NO 0 /* don= 't support any auth retries */
-#define PAR_ALL 1 /* allow all proxy auth protocols */
-#define PAR_NCT 2 /* disa= ble cleartext proxy auth protocols */
+#define PAR_NO 0 /* don't support any auth retries *= /
+#define PAR_ALL 1 = /* allow all proxy auth protocols */
+#define PAR_NCT 2 /* disable cleartext proxy auth protocol= s */
int auth_retry;

const char *auth_method_string;

@@ -57,11 +59,13 @@
const char *user_agent;
struct htt= p_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER];
= bool inline_creds; /* auth_file_up is inline credentials */
- bool first_time; /* indicates i= f we need to wipe user creds at the first iteration of the main loop */
+ bool first_time; = /* indicates if we need to wipe user creds at the first iteration of the ma= in
+ = loop */
bool nocache;
};

-struct = http_proxy_info {
+st= ruct http_proxy_info
= +{
bool defined;
int auth_method;=
struct http_proxy_options options;
@@= -78,12 +82,11 @@
void http_proxy_close(struct http_proxy_= info *hp);

bool establish_http_proxy_pas= sthru(struct http_proxy_info *p,
- socket_descriptor_t sd, /* a= lready open to proxy */
- const char *host, /* openvpn se= rver remote */
- = const char *port, /* openvpn server po= rt */
+ = socket_descriptor_t sd, /* already open to proxy */
+ = const char *host, /* openvpn server remote */
= + = const char *port, /* openvpn server port */
= struct event_timeout *server_poll_timeout,<= /span>
- = struct buffer *lookahead,
- struct signal_info *sig= _info);
+ = struct buffer *lookahead, struct signal_info *sig_in= fo);

uint8_t *make_base64_string2(const = uint8_t *str, int str_len, struct gc_arena *gc);
diff --git a/src/openvpn/ps.c b/src/openvpn/ps.c
in= dex 0f2b812..65d8d1d 100644
--- a/src/openvpn/ps.c+++ b/src/openvpn/ps.c
@@ -47,24 +47,25 @@ #define COMMAND_EXIT 11

/* = Response codes for background -> foreground communication */
<= span style=3D"color: hsl(0, 100%, 40%);">-#define RESPONSE_INIT_SUCCEEDED = 20

-#define RESPONSE_I= NIT_FAILED 21
+#= define RESPONSE_INIT_SUCCEEDED 20
+#define RESPONSE_INIT_FAILED 21
/*
* Return values for proxy_connection_io funct= ions
*/

-#define IOSTAT_EAGAIN_ON_READ 0 /* recv returned EA= GAIN */
-#define IOSTAT= _EAGAIN_ON_WRITE 1 /* send returned EAGAIN */
-#define IOSTAT_READ_ERROR 2 /* the other end= of our read socket (pc) was closed */
-#define IOSTAT_WRITE_ERROR 3 /* the other end of our = write socket (pc->counterpart) was closed */
-#define IOSTAT_GOOD 4 /* nothing to r= eport */
+#define IOS= TAT_EAGAIN_ON_READ 0 /* recv returned EAGAIN */
+#define IOSTAT_EAGAIN_ON_WRITE 1 /* send retur= ned EAGAIN */
+#defin= e IOSTAT_READ_ERROR 2 /* the other end of our read socket (pc) was clo= sed */
+#define IOSTA= T_WRITE_ERROR 3 /* the other end of our write socket (pc->counterpar= t) was closed */
+#de= fine IOSTAT_GOOD 4 /* nothing to report */

/*
* A foreign (non-OpenVPN) connection we = are proxying,
* usually HTTPS
*/=
-struct proxy_connection {
+struct proxy_connectio= n
+{
= bool defined;
struct proxy_connection *next;
struct proxy_connection *counterpart;
@@ -= 157,11 +158,11 @@
static int
send_control= (const socket_descriptor_t fd, int code)
{
- unsigned char c =3D (unsigned cha= r) code;

+ unsigne= d char c =3D (unsigned char)code;
const ssize_t size = =3D write(fd, &c, sizeof(c));
if (size =3D=3D size= of(c))
{
- return (int) size;
+ return (int)size;
}
<= span> else

{
@@ -183,9 +184,7 @@
* send commands, data, and file descriptors to the backgro= und process.
*/
static void
-port_share_sendmsg(const socket_de= scriptor_t sd,

- = const char command,
- const struct buffer *head,
+port_share_sendmsg(const socket_descrip= tor_t sd, const char command, const struct buffer *head,
= const socket_descriptor_t sd_send)
{
if (socket_defined(sd))
@@ -197,8 +196,7 = @@
char cmd;
ssize_t stat= us;

-= dmsg(D_PS_PROXY_DEBUG, "PORT SHARE: sendmsg sd=3D%d len=3D%d&q= uot;,
- (in= t)sd_send,
+ d= msg(D_PS_PROXY_DEBUG, "PORT SHARE: sendmsg sd=3D%d len=3D%d", (in= t)sd_send,
head ? BLEN(head) : -1);
CLEAR(mesg);
@@ -219,7 +2= 17,7 @@
mesg.msg_iov =3D iov;

mesg.msg_controllen =3D cmsg_size();
- mesg.msg_control =3D (char *)= malloc(mesg.msg_controllen);

+ mesg.msg_control =3D (char *)malloc(mesg.msg_controllen);=
check_malloc_return(mesg.msg_control);
= mesg.msg_flags =3D 0;

@@ -= 241,9 +239,9 @@
status =3D sendmsg(sd, &mesg, = MSG_NOSIGNAL);
if (status =3D=3D -1)
{

- = msg(M_WARN|M_ERRNO, "PORT SHARE: sendmsg failed -- unable to commu= nicate with background process (%d,%d,%d,%d)",
- sd, sd_send, sd_null[0], sd= _null[1]
- = );
+ ms= g(M_WARN | M_ERRNO,
+= "PORT SHARE: sendmsg failed -- unable to communicate w= ith background process (%d,%d,%d,%d)",
+ sd, sd_send, sd_null[0], sd_null[1]= );
}

cl= ose_socket_if_defined(sd_null[0]);
@@ -346,13 +344,13 @@

slen =3D sizeof(from.addr);
= dlen =3D sizeof(to.addr);
- if (!getpeername(pc->sd, (struct sockaddr *) &fro= m.addr.sa, &slen)
-= && !getsockname(cp->sd, (struct sockaddr *) &to.addr= .sa, &dlen))
+ = if (!getpeername(pc->sd, (struct sockaddr *)&from.addr.sa, &sle= n)
+ &&= ; !getsockname(cp->sd, (struct sockaddr *)&to.addr.sa, &dlen))
{
const char *f =3D print_open= vpn_sockaddr(&from, &gc);
const char *t = =3D print_openvpn_sockaddr(&to, &gc);
- fnlen =3D strlen(journal_dir) + strlen(t) = + 2;
- jfn =3D (= char *) malloc(fnlen);
+ jfn =3D (char *)malloc(fnlen)= ;
check_malloc_return(jfn);
= snprintf(jfn, fnlen, "%s/%s", journal_dir, t);
dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: client origin %s -= > %s", jfn, f);

@@ -368,7 +366,7 @@
}

else
{=
- msg(M_WARN|M_ERR= NO, "PORT SHARE: unable to write journal file in %s", jfn);
+ msg(M_WARN | = M_ERRNO, "PORT SHARE: unable to write journal file in %s", jfn);<= /span>
free(jfn);
} }
@@ -394,11 +392,13 @@
}

static inline void
-proxy_connection_io_requeue(struct proxy_conne= ction *pc, const int rwflags_new, struct event_set *es)
+proxy_connection_io_requeue(struct prox= y_connection *pc, const int rwflags_new,
+ struct event_set *es)
{
if (socket_defined(pc->sd) &&= ; pc->rwflags !=3D rwflags_new)
{
- /*dmsg (D_PS_PROXY_DEBUG, "= ;PORT SHARE PROXY: requeue[%d] rwflags=3D%d", (int)pc->sd, rwflags_= new);*/
+ /*dm= sg (D_PS_PROXY_DEBUG, "PORT SHARE PROXY: requeue[%d] rwflags=3D%d"= ;, (int)pc->sd,
+ = * rwflags_new);*/
event_ctl(es, pc->sd,= rwflags_new, (void *)pc);
pc->rwflags =3D rwfl= ags_new;
}
@@ -412,12 +412,9 @@=
* on success and false on failure to connect to server.<= br> */
static bool
-proxy_entry_new(struct proxy_connection **list,=
- struct event= _set *es,
- = const struct openvpn_sockaddr server_addr,
- const socket_descriptor_t sd_clien= t,
- str= uct buffer *initial_data,
- const char *journal_dir)
+proxy_entry_new(struct proxy_connection **list, st= ruct event_set *es,
+= const struct openvpn_sockaddr server_addr, const socket_des= criptor_t sd_client,
= + struct buffer *initial_data, const char *journal_dir)
{
socket_descriptor_t sd_server; int status;
@@ -427,7 +424,7 @@
/* connect to port share server */

if ((sd_serv= er =3D socket(server_addr.addr.sa.sa_family, SOCK_STREAM, IPPROTO_TCP)) <= ; 0)
{
- msg(M_WARN|M_ERRNO, "PORT SHARE PROXY: cannot create soc= ket");
+ = msg(M_WARN | M_ERRNO, "PORT SHARE PROXY: cannot create socket");<= /span>
return false;
}
status =3D openvpn_connect(sd_server, &server_addr.addr.sa, 5, = NULL);

@@ -473,11 +470,12 @@
journ= al_add(journal_dir, pc, cp);
}

- dmsg(D_PS_PROXY_DEBUG, = "PORT SHARE PROXY: NEW CONNECTION [c=3D%d s=3D%d]", (int)sd_clien= t, (int)sd_server);
+= dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: NEW CONNECTION [c=3D%d s= =3D%d]", (int)sd_client,
+ (int)sd_server);

= /* set initial i/o states */
proxy_connection_io_reque= ue(pc, EVENT_READ, es);
- proxy_connection_io_requeue(cp, EVENT_READ|EVENT_WRITE, es);+ proxy_connection_io_requ= eue(cp, EVENT_READ | EVENT_WRITE, es);

= return true;
}
@@ -489,12 +487,9 @@
* exit, true otherwise.
*/
static bool

-control_= message_from_parent(const socket_descriptor_t sd_control,
- struct prox= y_connection **list,
- = struct event_set *es,
- const struct openvpn= _sockaddr server_addr,
= - const int max_initial_buf,
- const char *j= ournal_dir)
+control_= message_from_parent(const socket_descriptor_t sd_control, struct proxy_conn= ection **list,
+ = struct event_set *es, const struct openvpn_sockaddr = server_addr,
+ = const int max_initial_buf, const char *journal_dir)
{
/* this buffer needs to be large enou= gh to handle the largest buffer
* that might be retur= ned by the link_socket_read call in read_incoming_link. */
= @@ -517,7 +512,7 @@
mesg.msg_iovlen =3D 2;
<= span>

mesg.msg_controllen =3D cmsg_size();
= - mesg.msg_control =3D (char *= ) malloc(mesg.msg_controllen);
+ mesg.msg_control =3D (char *)malloc(mesg.msg_controllen);
check_malloc_return(mesg.msg_control);
= mesg.msg_flags =3D 0;

@@ -531,10 +526= ,8 @@
status =3D recvmsg(sd_control, &mesg, MSG_NO= SIGNAL);
if (status !=3D -1)
{
- if (h =3D=3D NUL= L
- || h->= ;cmsg_len !=3D CMSG_LEN(sizeof(socket_descriptor_t))
- || h->cmsg_level !=3D SOL= _SOCKET
- ||= h->cmsg_type !=3D SCM_RIGHTS)
+ if (h =3D=3D NULL || h->cmsg_len !=3D CMSG_LEN(s= izeof(socket_descriptor_t))
+ || h->cmsg_level !=3D SOL_SOCKET || h->cmsg_type = !=3D SCM_RIGHTS)
{
ms= g(M_WARN, "PORT SHARE PROXY: received unknown message"); }
@@ -547,12 +540,7 @@
= if (status >=3D 2 && command =3D=3D COMMAND_REDIRECT)<= /span>
{
buf.len =3D= status - 1;
- = if (proxy_entry_new(list,
- es,
- server_add= r,
- = received_fd,
- &buf,
- journal= _dir))
+ = if (proxy_entry_new(list, es, server_addr, received_fd, &buf, journa= l_dir))
{
= CLEAR(buf); /* we gave the buffer to proxy_entry_new */
}

@@ -611,7 +599,8 @@
= *bytes_sent +=3D status;
if (status !=3D pc= ->buf.len)
{
- dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROX= Y: partial write[%d], tried=3D%d got=3D%d", (int)sd, pc->buf.len, s= tatus);
+ = dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: partial write[%d], tried=3D%= d got=3D%d", (int)sd,
+ pc->buf.len, status);
= buf_advance(&pc->buf, status);
retur= n IOSTAT_EAGAIN_ON_WRITE;
}
@@ -69= 9,9 +688,7 @@
* in the proxied connection.
*/

static int
-proxy_connection_io_dispatch(struct proxy_connection *pc,
- = const int rwflags,
-= struct event_set *es)
+proxy_connection_io_dispatch(struct proxy_co= nnection *pc, const int rwflags, struct event_set *es)
{
const int max_transfer_per_iteration =3D 10000;<= br> struct proxy_connection *cp =3D pc->counterpart;@@ -740,10 +727,8 @@
* This is the main function f= or the port share proxy background process.
*/
= static void
-por= t_share_proxy(const struct openvpn_sockaddr hostaddr,
- const socket_descriptor_t = sd_control,
- = const int max_initial_buf,
- const char *journal_dir)
+port_share_proxy(const struct openvpn_soc= kaddr hostaddr, const socket_descriptor_t sd_control,
+ const int max_initial_bu= f, const char *journal_dir)
{
if (sen= d_control(sd_control, RESPONSE_INIT_SUCCEEDED) >=3D 0)
= {
@@ -777,7 +762,8 @@
= const struct event_set_return *e =3D &esr[i];
= if (e->arg =3D=3D sd_control_marker)
= {
- = if (!control_message_from_parent(sd_control, &lis= t, es, hostaddr, max_initial_buf, journal_dir))
+ if (!control_message_fr= om_parent(sd_control, &list, es, hostaddr,
+ = max_initial_buf, journal_dir))
= {
goto done;
<= span> }

@@ -815,9 +801,7 @@<= br> * share proxy.
*/
struct port= _share *
-port_share_op= en(const char *host,
- = const char *port,
- const int max_initial_buf,
+port_share_open(const char *host, const c= har *port, const int max_initial_buf,
cons= t char *journal_dir)
{
pid_t pid;
@@ -835,9 +819,9 @@
* Get host's IP = address
*/

- status =3D openvpn_getaddrinfo(GETADDR_RES= OLVE|GETADDR_FATAL,
- = host, port, 0, NULL, AF_UNSPEC, &ai);
- ASSERT(status=3D=3D= 0);
+ status =3D
+ openvpn_getad= drinfo(GETADDR_RESOLVE | GETADDR_FATAL, host, port, 0, NULL, AF_UNSPEC, &am= p;ai);
+ ASSERT(st= atus =3D=3D 0);
ASSERT(sizeof(hostaddr.addr) >=3D a= i->ai_addrlen);
memcpy(&hostaddr.addr.sa, ai-&g= t;ai_addr, ai->ai_addrlen);
freeaddrinfo(ai);
@@ -983,7 +967,7 @@
bool
is_op= envpn_protocol(const struct buffer *buf)
{
- const unsigned char *p =3D (const= unsigned char *) BSTR(buf);

+ const unsigned char *p =3D (const unsigned char *)BSTR(buf);
const int len =3D BLEN(buf);
if (l= en >=3D 3)
{
@@ -1005,7 +989,7 @@
* We don't do the 2 byte check for tls-cry= pt-v2 because it is very
* unrealistic to hav= e only 2 bytes available.
*/
- return (plen >=3D 336 = && plen < (1024 + 255));
+ return (plen >=3D 336 && plen < (= 1024 + 255));
}
else
{
diff --git a/src/openvpn/ps.h b/src/= openvpn/ps.h
index 59aecbe..1309eae 100644
= --- a/src/openvpn/ps.h
+++ b/src/openvpn/ps.h
@@ -30,7 +30,8 @@

#include "buffer.h"<= br> #include "ssl.h"

-struct port_share {
+struct port_share
+{
/* Foreground'= s socket to background process */
socket_descriptor_t = foreground_fd;

@@ -40,9 +41,7 @@
extern struct port_share *port_share;
=
-struct port_sh= are *port_share_open(const char *host,
- const char *port,
- = const int max_initial_buf,
+struct port_share *port_share_open(const char *host, const c= har *port, const int max_initial_buf,
= const char *journal_dir);

= void port_share_close(struct port_share *ps);
diff --git a= /src/openvpn/push.c b/src/openvpn/push.c
index ad8fa3d7..92= 1b867 100644
--- a/src/openvpn/push.c
+++ b= /src/openvpn/push.c
@@ -98,7 +98,7 @@

case AR_INTERACT:
= ssl_purge_auth(false);
+ /* Intentional [[fallthrough]= ]; */

case AR_NOINTERACT:
/* SOFT-SIGTUSR1 -- Auth failure error */
@@ -117,20 +117,19 @@
/*
* Save the dynamic-challenge text even when management is defined
*/
= - if (authfail_extended
- && buf_string_match_head_str(&buf, "CRV1:&quo= t;) && BLEN(&buf))
+ if (authfail_extended && buf_string_match_head_str(&= amp;buf, "CRV1:") && BLEN(&buf))
= {
ssl_put_auth_challenge(BSTR(&buf));<= br> }
#endif /* ifdef ENABLE_MANAGEMENT */

-
}<= br>
/*
* Act on received restart = message from server
*/
void
-server_pushed_signal(struct contex= t *c, const struct buffer *buffer, const bool restart, const int adv)
+server_pushed_signal(stru= ct context *c, const struct buffer *buffer, const bool restart,
<= span style=3D"color: hsl(120, 100%, 40%);">+ const int = adv)

{
if (c->options.pull)=
{
@@ -253,7 +252,8 @@
= }
else
{
- msg(D_PUSH_ERRORS, &quo= t;WARNING: Received INFO command is too long, won't notify management c= lient.");

+ = msg(D_PUSH_ERRORS,
+ "WARNING: Received INFO command is too long, won= 't notify management client.");
}<= br>
gc_free(&gc);
@@ -2= 95,20 +295,18 @@
* if the se= rver does not push a timeout
*/
static v= oid
-parse_auth_pending= _keywords(const struct buffer *buffer,
- unsigned int *server_timeout)<= /span>
+parse_auth_pending_k= eywords(const struct buffer *buffer, unsigned int *server_timeout) {
struct buffer buf =3D *buffer;

/* does the buffer start with "AUTH_PENDING= ," ? */
- if (!= buf_advance(&buf, strlen("AUTH_PENDING"))
- || !(buf_read_u8(&buf) =3D=3D= ',') || !BLEN(&buf))
+ if (!buf_advance(&buf, strlen("AUTH_PENDING"= ;)) || !(buf_read_u8(&buf) =3D=3D ',') || !BLEN(&buf))
{
#ifdef ENABLE_MANAGEMENT
if (management)

{
- management_set_state(management= , OPENVPN_STATE_AUTH_PENDING,
- "", NULL, NULL, NULL, NU= LL);
+ man= agement_set_state(management, OPENVPN_STATE_AUTH_PENDING, "", NUL= L, NULL, NULL,
+ = NULL);
}
#endif


@@ -323,8 +321,8 @@
= * buf_parse is called, as it will insert \0 bytes into the buff= er */
if (management)
{- management_set_state(ma= nagement, OPENVPN_STATE_AUTH_PENDING,
- BSTR(&buf), NULL, NULL, NU= LL, NULL);
+ m= anagement_set_state(management, OPENVPN_STATE_AUTH_PENDING, BSTR(&buf),= NULL, NULL, NULL,
+ = NULL);
}
= #endif

@@ -347,17 +345,18 @@

/* Cap the increase at the maximum time we are w= illing stay in the
* pending authentication state */<= /span>
- unsigned int max_t= imeout =3D max_uint(c->options.renegotiate_seconds/2,
- = c->options.handshake_window);
+ unsigned int max_timeout =3D
+ max_uint(c->options.renegotiate_second= s / 2, c->options.handshake_window);

= /* try to parse parameter keywords, default to hand-winow timeout if th= e
* server does not supply a timeout */
unsigned int server_timeout =3D c->options.handshake_window;
parse_auth_pending_keywords(buffer, &server_timeout);=

- = msg(D_PUSH, "AUTH_PENDING received, extending handshake timeout from = %us "
- &qu= ot;to %us", c->options.handshake_window,
- min_uint(max_timeout, server_timeout));<= /span>
+ msg(D_PUSH,
+ "AUTH_PENDI= NG received, extending handshake timeout from %us "
+ "to %us",
= + c->options.handshak= e_window, min_uint(max_timeout, server_timeout));
<= br> const struct key_state *ks =3D get_primary_key(c->c2.tls_m= ulti);
c->c2.push_request_timeout =3D ks->establ= ished + min_uint(max_timeout, server_timeout);
@@ -377,16 += 376,16 @@
*
* @return true on success, = false on failure.
*/
-static bool push_option_fmt(struct gc_arena *gc, struct pu= sh_list *push_list,
- = int msglevel, const char *fmt, ...)
+static bool push_option_fmt(struc= t gc_arena *gc, struct push_list *push_list, int msglevel,

+ const ch= ar *fmt, ...)
#ifdef __GNUC__
#if __USE_M= INGW_ANSI_STDIO
-__attr= ibute__ ((format(gnu_printf, 4, 5)))
+ __attribute__((format(gnu_printf, 4, 5)))
#else

-__attribute= __ ((format(__printf__, 4, 5)))
+ __attribute__((format(__printf__, 4, 5)))
= #endif
#endif
-;
+ ;

/*
* Send auth failed mes= sage from server to client.
@@ -406,7 +405,7 @@
<= span> static const char auth_failed[] =3D "AUTH_FAILED";
size_t len;

- len =3D (client_reason ? strlen(client_reason)= +1 : 0) + sizeof(auth_failed);
+ len =3D (client_reason ? strlen(client_reason) + 1 : 0) + si= zeof(auth_failed);
if (len > PUSH_BUNDLE_SIZE)
{
len =3D PUSH_BUNDLE_SIZE;
@@ -422,13 +421,12 @@

= /* We kill the whole session, send the AUTH_FAILED to any TLS session
* that might be active */
- send_control_channel_string_dowork(&c= ->c2.tls_multi->session[TM_INITIAL],
- BSTR(&b= uf), D_PUSH);
- = send_control_channel_string_dowork(&c->c2.tls_multi->session[TM_A= CTIVE],
- = BSTR(&buf), D_PUSH);
+ send_control_channel_string_dowor= k(&c->c2.tls_multi->session[TM_INITIAL], BSTR(&buf),+ = D_PUSH);
+ send_control_channel_string_dowork(&c->c2.tls_multi->= session[TM_ACTIVE], BSTR(&buf),
+ D_PUSH);<= br>
reschedule_multi_process(c);
= -
}
gc_free(&gc);
@@ -436,8 = +434,7 @@


bool<= br>-send_auth_pending_messages(st= ruct tls_multi *tls_multi,
- struct tls_session *session,
+send_auth_pending_messages(struct = tls_multi *tls_multi, struct tls_session *session,

= const char *extra, unsigned int timeout)
{

struct key_state *ks =3D &session->key[KS_= PRIMARY];
@@ -449,8 +446,8 @@

<= span>

/* Calculate the maximum timeout and subtract t= he time we already waited */
- unsigned int max_timeout =3D max_uint(tls_multi->opt.renegoti= ate_seconds/2,
- = tls_multi->opt.handshake_window);
+ unsigned int max_time= out =3D
+ max_= uint(tls_multi->opt.renegotiate_seconds / 2, tls_multi->opt.handshake= _window);
max_timeout =3D max_timeout - (now - ks->= initial);
timeout =3D min_uint(max_timeout, timeout);<= /span>

@@ -509,15 +506,16 @@
= struct gc_arena gc =3D gc_new();
unsigned int option= _types_found =3D 0;

- msg(D_PUSH, "PUSH: Received control message: '= %s'", sanitize_control_message(BSTR(buffer), &gc));
= + msg(D_PUSH, "PUSH: Re= ceived control message: '%s'",
+ sanitize_control_message(BSTR(buffer), &= ;gc));

- = pull_permission_mask(c),
+ int status =3D process_incoming_push_msg(= c, buffer, c->options.pull, pull_permission_mask(c),
= &option_types_found);
if (status =3D=3D PUSH_MSG_ERROR)
= {
- m= sg(D_PUSH_ERRORS, "WARNING: Received bad push/pull message: %s", = sanitize_control_message(BSTR(buffer), &gc));
+ msg(D_PUSH_ERRORS, "WARNING: Rec= eived bad push/pull message: %s",
+ sanitize_control_message(BSTR(buffer), &= gc));
}
else if (status =3D=3D PU= SH_MSG_REPLY || status =3D=3D PUSH_MSG_CONTINUATION)
{=
@@ -593,17 +591,14 @@
*/
<= span> if (tls_multi->auth_token)

{
- push_option_fmt(gc, push_l= ist, M_USAGE, "auth-token %s",

- tls_multi->auth_token);
+ push_option_fmt(g= c, push_list, M_USAGE, "auth-token %s", tls_multi->auth_token)= ;

char *base64user =3D NULL;
int ret =3D openvpn_base64_encode(tls_multi->locke= d_username,
- = (int)strlen(tls_multi->locked_username),
- = &base64user);
+ (int)strlen(tls_mult= i->locked_username), &base64user);
if (ret = < USER_PASS_LEN && ret > 0)
{=
- push_option_fmt(= gc, push_list, M_USAGE, "auth-token-user %s",
- base64user);<= /span>
+ push_opt= ion_fmt(gc, push_list, M_USAGE, "auth-token-user %s", base64user)= ;
}
free(base64user);
}
@@ -619,8 +614,7 @@
*= @return true on success, false on failure.
*/
= bool
-prepare_pu= sh_reply(struct context *c, struct gc_arena *gc,
- struct push_list *push_list)<= /span>
+prepare_push_reply(s= truct context *c, struct gc_arena *gc, struct push_list *push_list)<= br> {
struct tls_multi *tls_multi =3D c->c2.t= ls_multi;
struct options *o =3D &c->options;
@@ -631,14 +625,12 @@
push_option_fm= t(gc, push_list, M_USAGE, "ifconfig-ipv6 %s/%d %s",
print_in6_addr(c->c2.push_ifconfig_ipv6_loca= l, 0, gc),

c->c2.push_ifconfig_= ipv6_netbits,
- = print_in6_addr(c->c2.push_ifconfig_ipv6_remote,- = 0, gc));
+ = print_in6_addr(c->c2.push_ifconfig_ipv6_remote, 0,= gc));
}

/* ipv= 4 */
if (c->c2.push_ifconfig_defined && c-&= gt;c2.push_ifconfig_local
- && c->c2.push_ifconfig_remote_netmask
- && !o->push_ifcon= fig_ipv4_blocked)

+ = && c->c2.push_ifconfig_remote_netmask && !o->pu= sh_ifconfig_ipv4_blocked)
{
i= n_addr_t ifconfig_local =3D c->c2.push_ifconfig_local;
= if (c->c2.push_ifconfig_local_alias)
@@ -647,14 = +639,12 @@
}
push_option_= fmt(gc, push_list, M_USAGE, "ifconfig %s %s",
= print_in_addr_t(ifconfig_local, 0, gc),
- print_in_ad= dr_t(c->c2.push_ifconfig_remote_netmask,

- 0, gc));
+ = print_in_addr_t(c->c2.push_ifconfig_remote_netmask, 0, gc));
<= span> }


if (tls_multi->use_pe= er_id)
{
- push_option_fmt(gc, push_list, M_USAGE, "peer-id %d&qu= ot;,
- = tls_multi->peer_id);
+ push_option_fmt(gc, push_list, M_USAGE, "peer-id %d= ", tls_multi->peer_id);
}
= /*
* If server uses --auth-gen-token and we have an = auth token
@@ -716,10 +706,11 @@
p= ush_option_fmt(gc, push_list, M_USAGE, "tun-mtu %d", o->ce.tun= _mtu);
if (client_max_mtu < o->ce.tun_mtu)
{
- msg(M_WARN, "Warning: reported maximum MTU from client= (%d) is lower "
+ msg(M_WARN,
+ "Warning: reported maximum MTU from client (%d) = is lower "
"than MTU used on the= server (%d). Add tun-max-mtu %d "
- "to client configuration.", cli= ent_max_mtu,
- = o->ce.tun_mtu, o->ce.tun_mtu);
+ "to client configuration."= ;,
+ c= lient_max_mtu, o->ce.tun_mtu, o->ce.tun_mtu);
= }
}

@@ -727,8 +718= ,7 @@
}

static bool
-send_push_options(struct = context *c, struct buffer *buf,
- struct push_list *push_list, int safe_cap,
+send_push_options(struct= context *c, struct buffer *buf, struct push_list *push_list, int safe_cap,=
bool *push_sent, bool *multi_push)
{
struct push_entry *e =3D push_list->= head;
@@ -798,15 +788,13 @@
buf_printf= (&buf, "%s", push_reply_cmd);

/* send options which are common to all clients */

- if (!send_push_options(c, &buf= , &c->options.push_list, safe_cap,
- &push_sent, &multi_p= ush))
+ if (!send_= push_options(c, &buf, &c->options.push_list, safe_cap, &push= _sent, &multi_push))
{
go= to fail;
}

/* s= end client-specific options */
- if (!send_push_options(c, &buf, per_client_push_list, safe= _cap,
- = &push_sent, &multi_push))
+ if (!send_push_options(c, &buf, per_client= _push_list, safe_cap, &push_sent, &multi_push))
= {
goto fail;
}
@@ -816,7 +804,7 @@

buf_printf(&buf, "= ;,push-continuation 1");
}

- if (BLEN(&buf) >= ; sizeof(push_reply_cmd)-1)
+ if (BLEN(&buf) > sizeof(push_reply_cmd) - 1)
<= span> {

const bool status =3D send_control_cha= nnel_string(c, BSTR(&buf), D_PUSH);
if (!statu= s)
@@ -851,8 +839,8 @@
}
=
static void
-push_option_ex(struct gc_arena *gc, struct push_list *push_list,
- const cha= r *opt, bool enable, int msglevel)
+push_option_ex(struct gc_arena *gc, struct push_list *push_l= ist, const char *opt, bool enable,
+ int msglevel)
{
if (!string_class(opt, CC_ANY, CC_COMMA))

{
@@ -894,8 +882,7 @@
push_reset(o);<= /span>
while (e)
{
- push_option_ex(&o-&= gt;gc, &o->push_list,

- string_alloc(e->option, &o->gc)= , true, M_FATAL);
+ = push_option_ex(&o->gc, &o->push_list, string_alloc(= e->option, &o->gc), true, M_FATAL);
= e =3D e->next;
}
}<= br>@@ -910,16 +897,16 @@
}
<= br> static bool
-= push_option_fmt(struct gc_arena *gc, struct push_list *push_list,- int msglevel, c= onst char *format, ...)
+push_option_fmt(struct gc_arena *gc, struct push_list *push_list, int m= sglevel, const char *format,
+ ...)
{
va_li= st arglist;
- char t= mp[256] =3D {0};
+ = char tmp[256] =3D { 0 };
int len;
= va_start(arglist, format);
len =3D vsnprintf(tmp, si= zeof(tmp), format, arglist);
va_end(arglist);- if (len > sizeof(tmp)-1= )
+ if (len > s= izeof(tmp) - 1)
{
return fals= e;
}
@@ -946,7 +933,7 @@
}


/* ifconfig-ipv6 is specia= l, as not part of the push list */
- if (streq( p, "ifconfig-ipv6" ))
+ if (streq(p, "ifconfig-ipv= 6"))

{
o->push_ifconf= ig_ipv6_blocked =3D true;
return;
= @@ -959,8 +946,7 @@
/* cycle through the push list= */
while (e)
{- if (e->enable
- &&am= p; strncmp( e->option, p, strlen(p) ) =3D=3D 0)
+ if (e->enable && strn= cmp(e->option, p, strlen(p)) =3D=3D 0)
{
msg(D_PUSH_DEBUG, "PUSH_REMOVE removing= : '%s'", e->option);
e->= ;enable =3D false;
@@ -1000,8 +986,7 @@
= struct push_list push_list =3D { 0 };
= struct gc_arena gc =3D gc_new();

- if (prepare_push_reply(c, &= gc, &push_list)
- = && send_push_reply(c, &push_list))
+ if (prepare_push_reply= (c, &gc, &push_list) && send_push_reply(c, &push_list))=

{
ret =3D PU= SH_MSG_REQUEST;
c->c2.sent_push_reply_e= xpiry =3D now + 30;
@@ -1023,9 +1008,9 @@
= char line[OPTION_PARM_SIZE];
while (buf_parse(buf,= ',', line, sizeof(line)))
{
- /* peer-id and auth-token might= change on restart and this should not trigger reopening tun */
<= span style=3D"color: hsl(0, 100%, 40%);">- if (strprefix(line, "= ;peer-id ")

- = || strprefix(line, "auth-token ")
+ /* peer-id and auth-token might chan= ge on restart and this should not trigger reopening tun
+ */
+ if (strprefix(line, "peer-id "= ;) || strprefix(line, "auth-token ")
= || strprefix(line, "auth-token-user "))
= {
continue;
@@ -1035,15 +1020= ,13 @@
{
continue;
}
+ md_ctx_update(ct= x, (const uint8_t *)line, strlen(line) + 1);
}<= br> }

static int
-process_incoming_push_reply(struct cont= ext *c,
- = unsigned int permission_mask,
- unsigned int *option_type= s_found,
- = struct buffer *buf)
+process_incoming_push_reply(struct context *c, unsigned int = permission_mask,
+ = unsigned int *option_types_found, struct buffer *b= uf)
{
int ret =3D PUSH_MSG_ERROR;
const uint8_t ch =3D buf_read_u8(buf);
@@= -1056,20 +1039,14 @@
md_ctx_init(c->c2.pul= led_options_state, "SHA256");
c->= c2.pulled_options_digest_init_done =3D true;
}
- if (apply_push_op= tions(&c->options,
- buf,
- permission_mask,- = option_types_found,
- = c->c2.es))
+ if (apply_push_options(&c->options, b= uf, permission_mask, option_types_found, c->c2.es))
= {
- pus= h_update_digest(c->c2.pulled_options_state, &buf_orig,
- &= ;c->options);

+ = push_update_digest(c->c2.pulled_options_state, &buf_orig, &= amp;c->options);
switch (c->options.push= _continuation)
{
= case 0:
case 1:
- md_ctx_final(c->c2.p= ulled_options_state,
- = c->c2.pulled_options_digest.digest);
+ md_= ctx_final(c->c2.pulled_options_state, c->c2.pulled_options_digest.dig= est);
md_ctx_cleanup(c->c2.pulled_o= ptions_state);
md_ctx_free(c->c2.pu= lled_options_state);
c->c2.pulled_o= ptions_state =3D NULL;
@@ -1092,10 +1069,8 @@
}


int
-process_incoming_push_msg(struct context *c,<= br>- con= st struct buffer *buffer,
- bool honor_received_options,
- unsigned int= permission_mask,
+pr= ocess_incoming_push_msg(struct context *c, const struct buffer *buffer,
+ = bool honor_received_options, unsigned int permission_mask,
unsigned int *option_types_found)

<= span> {

struct buffer buf =3D *buffer;
@@ -1105,11 +1080,9 @@

c->c2.push_request_rece= ived =3D true;
return process_incoming_push_reques= t(c);
}
- else if (honor_received_options
- && buf_string_compare_advance(&am= p;buf, push_reply_cmd))
+ else if (honor_received_options && buf_string_compare_advan= ce(&buf, push_reply_cmd))
{
- return process_incoming_push_reply(= c, permission_mask,
- = option_types_found, &buf);
+ return process_= incoming_push_reply(c, permission_mask, option_types_found, &buf);
}
else
{<= br>@@ -1132,13 +1105,14 @@
/* cycle through = the push list */
while (e)
= {
- char *= p[MAX_PARMS+1];
+ = char *p[MAX_PARMS + 1];
bool enable = =3D true;

/* parse the push = item */
CLEAR(p);
= if (e->enable
- = && parse_line(e->option, p, SIZE(p)-1, "[PUSH_R= OUTE_REMOVE]", 1, D_ROUTE_DEBUG, &gc))
+ && parse_line(e->opt= ion, p, SIZE(p) - 1, "[PUSH_ROUTE_REMOVE]", 1, D_ROUTE_DEBUG,
+ = &gc))
{
= /* is the push item a route directive? */
= if (p[0] && !strcmp(p[0], "route") && !p[3]= && o->iroutes)
@@ -1146,7 +1120,8 @@
= /* get route parameters */
= bool status1, status2;
= const in_addr_t network =3D getaddr(GETADDR_HOST_ORDER, p[1], 0, &stat= us1, NULL);
- = const in_addr_t netmask =3D getaddr(GETADDR_HOST_ORDER, p[2] ? p[= 2] : "255.255.255.255", 0, &status2, NULL);
+ const in_addr_t n= etmask =3D getaddr(
+= GETADDR_HOST_ORDER, p[2] ? p[2] : "255.255.255= .255", 0, &status2, NULL);

= /* did route parameters parse correctly? */
if (status1 && status2)

@@ -1= 156,7 +1131,9 @@
/* does route mat= ch an iroute? */
for (ir =3D o->= ;iroutes; ir !=3D NULL; ir =3D ir->next)
= {
- = if (network =3D=3D ir->network && netmask =3D= =3D netbits_to_netmask(ir->netbits >=3D 0 ? ir->netbits : 32))
+ = if (network =3D=3D ir->network
+ && netmask
+ = =3D=3D netbits_to_netmask(ir->netbits >=3D 0 ? ir->n= etbits : 32))
{
enable =3D false;

= break;
@@ -1164,8 +1141,7 @@
}
= }
}
- else if (p[0] && !strcmp(p[0], &qu= ot;route-ipv6") && !p[2]
- && o->iroutes_ipv6)
+ else if= (p[0] && !strcmp(p[0], "route-ipv6") && !p[2] &a= mp;& o->iroutes_ipv6)
{
<= span> /* get route parameters */

= struct in6_addr network;
diff --git a/src/op= envpn/push.h b/src/openvpn/push.h
index 048b4c4..84931fb 10= 0644
--- a/src/openvpn/push.h
+++ b/src/ope= nvpn/push.h
@@ -36,17 +36,16 @@
int process_incoming_push_request(struct context *c);

-int process_incom= ing_push_msg(struct context *c,
- const struct buffer *buffer,=
- = bool honor_received_options,
- unsigned int permission_mask,=
+int process_incoming_push_= msg(struct context *c, const struct buffer *buffer,
+ bool honor_= received_options, unsigned int permission_mask,
= unsigned int *option_types_found);

bool send_push_request(struct context *c);
=
void receive_auth_failed(struct context *c, const struct = buffer *buffer);

-void server_pushed_signal(struct context *c, const struct buff= er *buffer, const bool restart, const int adv);
+void server_pushed_signal(struct context *c, co= nst struct buffer *buffer, const bool restart,
+ const int adv);=

void receive_exit_message(struct context *c);<= /span>

@@ -60,8 +59,7 @@

void push_option(struct options *o, const char *opt, int msglev= el);

= -void push_options(struct options *o, char **p, int msglevel,
- struct gc_arena *= gc);

+void push_optio= ns(struct options *o, char **p, int msglevel, struct gc_arena *gc);<= br>
void push_reset(struct options *o);
<= span>

@@ -76,10 +74,8 @@
* doc/managemen= t-notes.txt under client-pending-auth for
* more details = on message format
*/
-bool
-= send_auth_pending_messages(struct tls_multi *tls_multi,
- struct tls_ses= sion *session, const char *extra,
- unsigned int timeout);
+bool send_auth_pending_messages(s= truct tls_multi *tls_multi, struct tls_session *session,

+ const = char *extra, unsigned int timeout);

void= send_restart(struct context *c, const char *kill_msg);

@@ -98,7 +94,6 @@
* @param c T= he context struct
* @param buffer Buffer containin= g the control message with AUTH_PENDING
*/
-void

-receive_auth_pending(struct context *c, const struct = buffer *buffer);
+voi= d receive_auth_pending(struct context *c, const struct buffer *buffer);

#endif /* ifndef PUSH_H */
= diff --git a/src/openvpn/pushlist.h b/src/openvpn/pushlist.h
index d946a5f..f4d4370 100644

--- a/src/openvpn/pushlist.= h
+++ b/src/openvpn/pushlist.h
@@ -26,13 +2= 6,15 @@

/* parameters to be pushed to pe= er */

-struct push_entry {
+struct push_entry
+= {
struct push_entry *next;
bool e= nable;
const char *option;
};<= br>
-struct push= _list {
+struct push_= list
+{
struct push_entry *head;

struct push_entry *ta= il;
};
diff --git a/src/openvpn/reflect_fi= lter.c b/src/openvpn/reflect_filter.c
index a5bcf94..8b4ff2= d 100644
--- a/src/openvpn/reflect_filter.c
+++ b/src/openvpn/reflect_filter.c

@@ -47,10 +47,10 @@
int64_t dropped =3D irl->curr_period_counter - irl= ->max_per_period;
if (dropped > 0) {
- = msg(D_TLS_DEBUG_LOW, "Dropped %" PRId64 " initial ha= ndshake packets"
-= " due to --connect-freq-initial %" PRId64 " = %d", dropped,
- = irl->max_per_period, irl->period_length);
-

+ msg(D_TLS_DEBUG_LOW,
+ "Dropped %" PRI= d64 " initial handshake packets"
+ " due to --connect-freq-initial= %" PRId64 " %d",
+ dropped, irl->max_per_period, irl->perio= d_length);
}
irl->last= _period_reset =3D now;
irl->curr_period_counter= =3D 0;
@@ -63,9 +63,11 @@

if (over_limit && !irl->warning_displayed)

{

- msg(M= _WARN, "Note: --connect-freq-initial %" PRId64 " %d rate lim= it "
+ ms= g(M_WARN,
+ = "Note: --connect-freq-initial %" PRId64 " %d rate limit &q= uot;
"exceeded, dropping initial handshak= e packets for the next %d "
- "seconds", irl->max_per_period, irl->= ;period_length,
+ = "seconds",
+ irl->max_per_period, irl->period_length,<= br> (int)(irl->last_period_reset + irl->period_leng= th - now));
irl->warning_displayed =3D true;
}
diff --git a/src/openvpn/reflect_filte= r.h b/src/openvpn/reflect_filter.h
index ae7be21..1981067 1= 00644
--- a/src/openvpn/reflect_filter.h
++= + b/src/openvpn/reflect_filter.h
@@ -27,7 +27,8 @@
/** struct that handles all the rate limiting lo= gic for initial
* responses */
-struct initial_packet_rate_limit {
+struct initial_packet_rate_limit<= /span>
+{
= /** This is a hard limit for packets per seconds. */
= int64_t max_per_period;

@@ -51,22 +52,1= 9 @@
* checks if the connection is still allowed to conne= ct under the rate
* limit. This also increases the intern= al counter at the same time
*/
-bool
-reflect_filter_rate_limit_check(struct initial_packet_rate_limit = *irl);
+bool reflect_= filter_rate_limit_check(struct initial_packet_rate_limit *irl);
<= span>

/**
* decreases the counter of in= itial packets seen, so connections that
* successfully co= mpleted the three-way handshake do not count against
* th= e counter of initial connection attempts
*/
-void

-reflect_filter_rate_limit_decrease(struct initial_pa= cket_rate_limit *irl);
-struct initial_pac= ket_rate_limit *
-initi= al_rate_limit_init(int max_per_period, int period_length);
+struct initial_packet_rate_limit *in= itial_rate_limit_init(int max_per_period, int period_length);

/**
* free the initial-packet rate = limiter structure
diff --git a/src/openvpn/reliable.c b/src= /openvpn/reliable.c
index 5505f56..0c3f08f 100644--- a/src/openvpn/reliable.c
+++ b/src/openvpn/relia= ble.c
@@ -51,8 +51,7 @@
* verify that tes= t - base < extent while allowing for base or test wraparound
<= span> */

static inline bool
-reliable_pid_in_range1(const packet_id_type test,
- = const packet_id_type base,
+reliable_pid_in_range1(const packet_id_type test, const packet_id_ty= pe base,
const unsigned int extent)=
{
return subtract_pid(test, base) &l= t; extent;
@@ -62,8 +61,7 @@
* verify tha= t test < base + extent while allowing for base or test wraparound=
*/
static inline bool
-reliable_pid_in_range2(const packet_id_type te= st,
- = const packet_id_type base,
+reliable_pid_in_range2(const packet_id_type test, const packet_= id_type base,
const unsigned int ex= tent)
{
if (base + extent >=3D bas= e)
@@ -75,7 +73,7 @@
}
else

{
- if ((test+0x80000000u) < (base+0x80000000u) + extent= )
+ if ((test = + 0x80000000u) < (base + 0x80000000u) + extent)
= {
return true;
}
@@ -88,8 +86,7 @@
* verify that p1 < p2 = while allowing for p1 or p2 wraparound
*/
static inline bool

-r= eliable_pid_min(const packet_id_type p1,
- const packet_id_type p2)
+reliable_pid_min(const packet_id_t= ype p1, const packet_id_type p2)

{
re= turn !reliable_pid_in_range1(p1, p2, 0x80000000u);
}
@@ -145,8 +142,7 @@

bool
-reliable= _ack_read(struct reliable_ack *ack,
- struct buffer *buf, const struct session_id= *sid)
+reliable_ack_= read(struct reliable_ack *ack, struct buffer *buf, const struct session_id = *sid)
{
struct session_id session_id_= remote;

@@ -155,12 +151,11 @@
<= span> return false;

}
=
- if (ack->len >=3D = 1 && (!session_id_defined(&session_id_remote)
- || !session_i= d_equal(&session_id_remote, sid)))
+ if (ack->len >=3D 1
+ && (!session_id_defined(&s= ession_id_remote) || !session_id_equal(&session_id_remote, sid)))
{
struct gc_arena gc =3D gc_new();=
- dmsg(D_REL_LO= W,
- "= ACK read BAD SESSION-ID FROM REMOTE, local=3D%s, remote=3D%s",<= br>+ dmsg(D_REL_LOW, &qu= ot;ACK read BAD SESSION-ID FROM REMOTE, local=3D%s, remote=3D%s",
session_id_print(sid, &gc), session_id_print(= &session_id_remote, &gc));
gc_free(&gc= );
return false;
@@ -211,7 +206,7 = @@
{
ASSERT(ack->len >=3D n);
/* This loop is backward to ensure the same order as in= ack */
- for (int i= =3D n-1; i >=3D 0; i--)
+ for (int i =3D n - 1; i >=3D 0; i--)
{<= /span>
packet_id_type id =3D ack->packet_id[i];=

@@ -251,9 +246,7 @@
/* write a= packet ID acknowledgement record to buf, */
/* removing a= ll acknowledged entries from ack */
bool
-reliable_ack_write(struct reliable_ack = *ack,
- = struct reliable_ack *ack_mru,
- struct buffer *buf,
+reliable_ack_write(struct reliable_ack *ack, = struct reliable_ack *ack_mru, struct buffer *buf,
= const struct session_id *sid, int max, bool prepend)
<= span> {

int i, j, n;
@@ -285,7 +278,8 = @@
packet_id_type pid =3D ack_mru->packet_id[i]= ;
packet_id_type net_pid =3D htonpid(pid);<= br> ASSERT(buf_write(&sub, &net_pid, sizeof(net_pid))= );
- dmsg(D_REL_= DEBUG, "ACK write ID " packet_id_format " (ack->len=3D%d,= n=3D%d)", (packet_id_print_type)pid, ack->len, n);
+ dmsg(D_REL_DEBUG, "ACK= write ID " packet_id_format " (ack->len=3D%d, n=3D%d)",<= /span>
+ (packet= _id_print_type)pid, ack->len, n);
}
if (total_acks)

{
@@ -294,7 +288= ,7 @@
}
if (n)
= {
- for (i = =3D 0, j =3D n; j < ack->len; )
+ for (i =3D 0, j =3D n; j < ack->len;)
{
ack->packet_id[i++] = =3D ack->packet_id[j++];
}
@@ -= 495,7 +489,8 @@
return true;
<= br> bad:
- dms= g(D_REL_DEBUG, "ACK " packet_id_format " is a replay: %s&quo= t;, (packet_id_print_type)id, reliable_print_ids(rel, &gc));
= + dmsg(D_REL_DEBUG, "AC= K " packet_id_format " is a replay: %s", (packet_id_print_ty= pe)id,
+ reli= able_print_ids(rel, &gc));
gc_free(&gc);
return false;
}
@@ -514,7 = +509,8 @@
gc_free(&gc);
}=

- = dmsg(D_REL_DEBUG, "ACK RWBS rel->size=3D%d rel->packet_id=3D%08= x id=3D%08x ret=3D%d", rel->size, rel->packet_id, id, ret);
+ dmsg(D_REL_DEBUG, &q= uot;ACK RWBS rel->size=3D%d rel->packet_id=3D%08x id=3D%08x ret=3D%d&= quot;, rel->size,
= + rel->packet_id, id, ret);
return ret;
}

@@ -631,9 +627,7 @@
}
}
(void)n_a= ctive; /* dmsg might not generate code */
- dmsg(D_REL_DEBUG, "ACK reliable_can_send activ= e=3D%d current=3D%d : %s",
- n_active,
- n_current,
+ dmsg(D_REL_DEBUG, "ACK reliable_can_send active=3D%d curren= t=3D%d : %s", n_active, n_current,
reliable_= print_ids(rel, &gc));

gc_free(&a= mp;gc);
@@ -654,8 +648,7 @@
/* If = N_ACK_RETRANSMIT later packets have received ACKs, we assume
* that the packet was lost and resend it even if the timeout ha= s

* not expired yet. */
- if (e->active
- && (e->n_acks >= =3D N_ACK_RETRANSMIT || local_now >=3D e->next_try))
+ if (e->active && = (e->n_acks >=3D N_ACK_RETRANSMIT || local_now >=3D e->next_try)= )
{
if (!best || reli= able_pid_min(e->packet_id, best->packet_id))
= {
@@ -721,9 +714,7 @@
}
}

- dmsg(D_REL_DEBUG, "ACK reliable_send_timeout %d %s&q= uot;,
- (int) r= et,
- reliable_= print_ids(rel, &gc));
+ dmsg(D_REL_DEBUG, "ACK reliable_send_timeout %d %s", (i= nt)ret, reliable_print_ids(rel, &gc));

gc_free(&gc);

return ret;
@= @ -734,8 +725,8 @@
*/

= void
-reliable_mark_act= ive_incoming(struct reliable *rel, struct buffer *buf,
- packet_id_ty= pe pid, int opcode)
+= reliable_mark_active_incoming(struct reliable *rel, struct buffer *buf, pac= ket_id_type pid,
+ = int opcode)
{
= for (int i =3D 0; i < rel->size; ++i)
{
@@ -754,11 +745,12 @@
e->next_t= ry =3D 0;
e->timeout =3D 0;
e->n_acks =3D 0;

- dmsg(D_REL_DEBUG, "ACK mark active incoming ID= " packet_id_format, (packet_id_print_type)e->packet_id);+ dmsg(D_REL_DEBUG,= "ACK mark active incoming ID " packet_id_format,
+ (packet_id_print_t= ype)e->packet_id);

return;
= }
}
- ASSERT(0); /* buf not found in rel */
+ ASSERT(0); /* buf no= t found in rel */
}

/*<= /span>
@@ -783,11 +775,12 @@
e->op= code =3D opcode;
e->next_try =3D 0;<= br> e->timeout =3D rel->initial_timeout;
= - dmsg(D_REL_DEBUG, &q= uot;ACK mark active outgoing ID " packet_id_format, (packet_id_print_t= ype)e->packet_id);
+ dmsg(D_REL_DEBUG, "ACK mark active outgoing ID " pa= cket_id_format,
+ = (packet_id_print_type)e->packet_id);
= return;
}
}
= - ASSERT(0); = /* buf not found in rel */
+ ASSERT(0); /* buf not found in rel */
}<= br>
/* delete a buffer previously activated by reli= able_mark_active() */
diff --git a/src/openvpn/reliable.h b= /src/openvpn/reliable.h
index 2cbff01..ecaec8d 100644
--- a/src/openvpn/reliable.h
+++ b/src/openvpn/r= eliable.h
@@ -41,18 +41,21 @@
* @{ */


-#define RELIABLE_ACK_SIZE 8 /**< The maximum number of p= acket IDs
- = * waiting to be acknowledged which can
- * = be stored in one \c reliable_ack

- * structure. */
<= span style=3D"color: hsl(120, 100%, 40%);">+#define RELIABLE_ACK_SIZE = \

+ = 8 /**< The maximum number of packet IDs \
+ * waiting to be acknowledged whi= ch can \
+ * = be stored in one \c reliable_ack \
+ * structure. */

-#define RELIABLE_CAPACITY 12 /**= < The maximum number of packets that

- * the reliability laye= r for one VPN
- = * tunnel in one direction can store. */+#define RELIABLE_CAPACITY = \
= + 12 /**< The maximum number of packets that \
+ * the reliability layer for one= VPN \
+ * = tunnel in one direction can store. */

-#define N_ACK_RETRANSMIT 3 /**< W= e retry sending a packet early if
- * this many later packets ha= ve been
- = * ACKed. */
+#define N_ACK_RETRANSMIT \
+ 3 /**< We retry sending a p= acket early if \

+ = * this many later packets have been \
+ * ACKed. */

<= span> /**

* The acknowledgment structure in which packet = IDs are stored for later
@@ -77,9 +80,9 @@
= interval_t timeout;
time_t next_try;
packet_id_type packet_id;

- size_t n_acks; /* Number of acks received for packets wit= h higher PID.
- = * Used for fast retransmission when there were at least=
- * N_ACK= _RETRANSMIT. */
+ = size_t n_acks; /* Number of acks received for packets with higher PID.
+ * Us= ed for fast retransmission when there were at least
+ * N_ACK_RETRANSMIT. *= /
int opcode;
struct buffer buf;<= /span>
};
@@ -94,7 +97,7 @@
= interval_t initial_timeout;
packet_id_type packet_id;<= /span>
int offset; /**< Offset of the bufs in the reliable= _entry array */
- bo= ol hold; /* don't xmit until reliable_schedule_now is called */<= br>+ bool hold; /* don'= t xmit until reliable_schedule_now is called */
struct= reliable_entry array[RELIABLE_CAPACITY];
};

@@ -121,8 +124,7 @@
* @li True, if p= rocessing was successful.
* @li False, if an error occurs= during processing.
*/
-bool reliable_ack_read(struct reliable_ack *ack,<= br>- struct= buffer *buf, const struct session_id *sid);
+bool reliable_ack_read(struct reliable_ack *ack, s= truct buffer *buf, const struct session_id *sid);
<= br>
/**
@@ -142,9 +144,8 @@<= br> * @li True, if processing was successful.
* @l= i False, if an error occurs during processing.
*/<= br>-bool
-reliable_ack_parse(struct buffer *buf, struct = reliable_ack *ack,
- = struct session_id *session_id_remote);
+bool reliable_ack_parse(struct buffer *b= uf, struct reliable_ack *ack,
+ struct session_id *session_id_remote);

/**
* Remove acknowledge= d packets from a reliable structure.
@@ -213,9 +214,7 @@
* @li True, if processing was successful.
= * @li False, if an error occurs during processing.
*/
-bool reliable_ack_write(= struct reliable_ack *ack,
- struct reliable_ack *ack_mru,
- struct buffer *= buf,
+bool reliable_a= ck_write(struct reliable_ack *ack, struct reliable_ack *ack_mru, struct buf= fer *buf,
const struct session_id = *sid, int max, bool prepend);

/** @} nam= e Functions for processing outgoing acknowledgments */
@@ -= 338,8 +337,8 @@
* @param pid The packet's packet ID.<= /span>
* @param opcode The packet's opcode.
= */
-void reliable_mar= k_active_incoming(struct reliable *rel, struct buffer *buf,
- pa= cket_id_type pid, int opcode);

+void reliable_mark_active_incoming(struct reliable *rel, struct = buffer *buf, packet_id_type pid,
+ int opcode);

/**
* Record a packet ID for later a= cknowledgment.
@@ -375,7 +374,6 @@
struct = reliable_entry *reliable_get_entry_sequenced(struct reliable *rel);<= br>

-
/**
* Copies the first n acks fr= om \c ack to \c ack_mru
*
@@ -383,8 +381,= 7 @@
* @param ack_mru The reliable structure to insert th= e acks into
* @param n The number of ACKS to copy<= br> */
-void
-copy_acks_to_mru(struct r= eliable_ack *ack, struct reliable_ack *ack_mru, int n);
+void copy_acks_to_mru(struct reliable_a= ck *ack, struct reliable_ack *ack_mru, int n);

=
/**
@@ -427,8 +424,7 @@
= * @return the number of buffer that are available for sending with= out
* breaking ack sequence
= * */
-int
-reliable_get_num_output_sequenced_= available(struct reliable *rel);

+int reliable_get_num_output_sequenced_available(struct reliabl= e *rel);

/**
* Mark th= e reliable entry associated with the given buffer as
diff -= -git a/src/openvpn/ring_buffer.h b/src/openvpn/ring_buffer.h
new file mode 100644

index 0000000..e554296
--- /dev/null

+++ b/src/openvpn/ring_buffer.h
= @@ -0,0 +1,124 @@
+/*
+ * OpenVPN -= - An application to securely tunnel IP networks
+ * over a single UDP port, with sup= port for SSL/TLS-based
+ * packet encryption, pa= cket authentication, and
+ * packet compression.
+ *
+ * 2019 Lev S= tipakov <lev@...515...>
+ *
+ * Thi= s program is free software; you can redistribute it and/or modify+ * it under the terms of the= GNU General Public License version 2
+ * as published by the Free Software Foundation.<= br>+ *
+ * This program is distributed in the hope = that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or F= ITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of th= e GNU General Public License along
+ * with this program; if not, write to the Free Software Fo= undation, Inc.,
+ * = 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */

+
+#ifdef _WIN32
+#= ifndef OPENVPN_RING_BUFFER_H
+#define OPENVPN_RING_BUFFER_H
+
+= #include <windows.h>
+#include <winioctl.h>
+
+#inc= lude <stdint.h>
+#include <stdbool.h>
+
+/*<= br>+ * Values below are taken f= rom Wireguard Windows client
+ * https://github.com/WireGuard/wireguard-go/blob/master/tun/wintu= n/ring_windows.go#L14
+ */
+#define WINTUN= _RING_CAPACITY 0x800000
+#define WINTUN_RING_TRAILING_BYTES 0x10000
+#define WINTUN_MAX_PACKET_SIZE 0xffff=
+#define WINTUN_PACK= ET_ALIGN 4
+
+#define TUN_IOCTL_REG= ISTER_RINGS \
+ CT= L_CODE(51820U, 0x970U, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
+
+/**
+ * Wintun ring buffer
+ * See https://github.com/WireGuard/wintun#ring-layout=
+ */
+struct tun_ring

+{
+ volatile ULONG head;
+ volatile ULONG tail;
+ volatile LONG alertable;
+ UCHAR data[WINTUN_RING_CAPACITY + = WINTUN_RING_TRAILING_BYTES];
+};
+<= br>+/**
+ * Struct for ring buffers registration
+ * See https://github= .com/WireGuard/wintun#registering-rings
+ */
+struct tun_register_rings
+{
+ stru= ct
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ ULONG ring_size;
=
+ struct tun_ring *r= ing;
+ HANDLE = tail_moved;
+ } se= nd, receive;
+};
+
+struct TUN_PACKET_HEADER
+{
+ uint32_t size;
+};
+struct TUN_PACKE= T
+{
+ uint32_t size;
+ UCHAR data[WINTUN_MAX_PACKET_SIZE= ];
+};
+

+/**
+ * Registers ring buffers used to exchange data between
+ * userspace openvpn process and = wintun kernel driver,

+ * see https://github.com/WireGuard/wintun#registering-rings
+ *

+ * @param device handle to opened wi= ntun device
+ * @para= m send_ring pointer to send ring
+ * @param receive_ring pointer to receive rin= g
+ * @param send_tai= l_moved event set by wintun to signal openvpn
+ * that data is av= ailable for reading in send ring
+ * @param receive_tail_moved event set by openvpn to signal w= intun
+ * = that data has been written to receive ring
+ * @return true i= f registration is successful, false otherwise - use
+ * GetLastError()
+ */
+static inline bool
+register_ring_buffers(HANDLE device, struct tun_ring *send= _ring, struct tun_ring *receive_ring,
+ HANDLE send_tail_moved, HANDLE rece= ive_tail_moved)
+{
+ struct tun_registe= r_rings rr;
+ BOOL= res;
+ DWORD byte= s_returned;
+<= br>+ ZeroMemory(&rr, siz= eof(rr));
++ rr.send.ring =3D send_rin= g;
+ rr.send.ring_= size =3D sizeof(struct tun_ring);
+ rr.send.tail_moved =3D send_tail_moved;
+
+ rr.receive.ring =3D receive_ring;
+ rr.receive.ring_size =3D sizeof(st= ruct tun_ring);
+ = rr.receive.tail_moved =3D receive_tail_moved;
+
+ res =3D DeviceIoControl(device, TUN_IOCTL_REGISTER_RINGS, &r= r, sizeof(rr), NULL, 0,
+ &bytes_returned, NULL);
+
+ return res !=3D FALSE;
+}
+
+#endif /* i= fndef OPENVPN_RING_BUFFER_H */
+#endif /* ifdef _WIN32 */
diff --git a/src/openv= pn/route.c b/src/openvpn/route.c
index 156262a..ff76ffe 100= 644
--- a/src/openvpn/route.c
+++ b/src/ope= nvpn/route.c
@@ -47,11 +47,11 @@
#include = "memdbg.h"

#if defined(TARGET_= LINUX) || defined(TARGET_ANDROID)
-#include <linux/rtnetlink.h> /* RTM_GETROUTE e= tc. */
+#include <= linux/rtnetlink.h> /* RTM_GETROUTE etc. */
#endif

#if defined(TARGET_NETBSD)
-#include <net/route.h> = /* RT_ROUNDUP(), RT_ADVANCE() */
+#include <net/route.h> /* RT_ROUNDUP(), RT_ADVANCE= () */
#endif

#ifdef _WI= N32
@@ -68,7 +68,8 @@

st= atic int route_ipv6_ipapi(bool add, const struct route_ipv6 *, const struct= tuntap *);

-static int add_route_ipapi(const struct route_ipv4 *r, const struct= tuntap *tt, DWORD adapter_index);
+static int add_route_ipapi(const struct route_ipv4 *r, const= struct tuntap *tt,
+= DWORD adapter_index);
static bool del_route_ipapi(const struct route_ipv4 *r, const stru= ct tuntap *tt);

@@ -90,9 +91,7 @@<= br> int i;
for (i =3D 0; i < rb->n_byp= ass; ++i)
{
- msg(D_ROUTE, "ROUTE: bypass_host_route[%d]=3D%s&quo= t;,
- i,
- print_in_addr= _t(rb->bypass[i], 0, &gc));
+ msg(D_ROUTE, "ROUTE: bypass_host_route[%d]=3D%s= ", i, print_in_addr_t(rb->bypass[i], 0, &gc));
= }
gc_free(&gc);
}
= @@ -100,9 +99,9 @@
#endif
/* Route addition return status codes */
-#define RTA_ERROR 0 /* route addition faile= d */
-#define RTA_SUCCE= SS 1 /* route addition succeeded */
-#define RTA_EEXIST 2 /* route not added as it already ex= ists */
+#define RTA_= ERROR 0 /* route addition failed */
+#define RTA_SUCCESS 1 /* route addition succeeded */
+#define RTA_EEXIST 2 /*= route not added as it already exists */

= static bool
add_bypass_address(struct route_bypass *rb, c= onst in_addr_t a)
@@ -170,7 +169,8 @@
}

void
-copy_route_option_list(struct route_option_list *dest, cons= t struct route_option_list *src, struct gc_arena *a)
+copy_route_option_list(struct route_optio= n_list *dest, const struct route_option_list *src,
+ struct gc_arena *a)
{
*dest =3D *src;
= dest->gc =3D a;
@@ -178,8 +178,7 @@

void
copy_route_ipv6_option_list(struct ro= ute_ipv6_option_list *dest,
- const struct route_ipv6_option_list *src,=
- = struct gc_arena *a)
+ const struct route_ipv6_option_list *src= , struct gc_arena *a)
{
*dest =3D *sr= c;
dest->gc =3D a;
@@ -189,11 +188,= 8 @@
route_string(const struct route_ipv4 *r, struct gc_ar= ena *gc)
{
struct buffer out =3D allo= c_buf_gc(256, gc);
- = buf_printf(&out, "ROUTE network %s netmask %s gateway %s",
- print_in= _addr_t(r->network, 0, gc),
- print_in_addr_t(r->netmask, 0, gc),
- print_in_addr_t(r-&= gt;gateway, 0, gc)

- = );
+ b= uf_printf(&out, "ROUTE network %s netmask %s gateway %s", pri= nt_in_addr_t(r->network, 0, gc),
+ print_in_addr_t(r->netmask, 0, gc), print= _in_addr_t(r->gateway, 0, gc));
if (r->flags &am= p; RT_METRIC_DEFINED)
{
buf_p= rintf(&out, " metric %d", r->metric);
@@ -= 233,10 +229,7 @@
}

stat= ic bool
-get_special_ad= dr(const struct route_list *rl,
- const char *string,
- in_addr_t *out,
- bool *status)+get_special_addr(const struc= t route_list *rl, const char *string, in_addr_t *out, bool *status)<= br> {
if (status)
{<= br>@@ -271,7 +264,8 @@
}
else

{
- msg(M_INFO, PACKAGE_NAME "= ROUTE: net_gateway undefined -- unable to get default gateway from system&= quot;);
+ = msg(M_INFO, PACKAGE_NAME
+ " ROUTE: net_gateway undefined -- unable = to get default gateway from system");
= if (status)
{
= *status =3D false;
@@ -316,15 +310,13 @@ }

static bool
-init_route(struct route_ipv4 *r,=
- struct addrinfo *= *network_list,
- = const struct route_option *ro,
+init_route(struct route_ipv4 *r, struct addrinfo **network_l= ist, const struct route_option *ro,
const struc= t route_list *rl)
{
const in_addr_t d= efault_netmask =3D IPV4_NETMASK_HOST;
bool status;
int ret;
- struct in_addr special =3D {0};
+ struct in_addr special =3D { 0 };
=
CLEAR(*r);
r->option =3D ro;=
@@ -338,7 +330,7 @@
/* get_special_ad= dr replaces specialaddr with a special ip addr
* like= gw. getaddrinfo is called to convert a a addrinfo struct */

- if (get_specia= l_addr(rl, ro->network, (in_addr_t *) &special.s_addr, &status))=
+ if (get_special= _addr(rl, ro->network, (in_addr_t *)&special.s_addr, &status))
{
if (!status)
{

@@ -347,13 +339,12 @@
= special.s_addr =3D htonl(special.s_addr);
char buf= [INET_ADDRSTRLEN];
inet_ntop(AF_INET, &special= , buf, sizeof(buf));
- = ret =3D openvpn_getaddrinfo(0, buf, NULL, 0, NULL,
- AF_IN= ET, network_list);
+ = ret =3D openvpn_getaddrinfo(0, buf, NULL, 0, NULL, AF_INET, network_= list);
}
else
= {
- ret =3D op= envpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL,
- ro-= >network, NULL, 0, NULL, AF_INET, network_list);

+ ret =3D openvpn_getaddrinfo(GETAD= DR_RESOLVE | GETADDR_WARN_ON_SIGNAL, ro->network, NULL, 0,
+ = NULL, AF_INET, network_list);

}

status =3D (ret =3D=3D 0);
@@ -367,13 +35= 8,8 @@

if (is_route_parm_defined(ro-= >netmask))
{
- r->netmask =3D getaddr(
- GETADDR_HOST_ORDER
- | GETADDR_WARN_ON_SIGNAL,<= /span>
- ro->net= mask,
- 0,
- &status= ,
- NULL);
+ r->netmask= =3D
+ get= addr(GETADDR_HOST_ORDER | GETADDR_WARN_ON_SIGNAL, ro->netmask, 0, &s= tatus, NULL);
if (!status)
= {
goto fail;
@@ -390,14 +376= ,8 @@
{
if (!get_special_addr= (rl, ro->gateway, &r->gateway, &status))
= {
- r-&= gt;gateway =3D getaddr(
- GETADDR_RESOLVE
- | GETADDR_HOST_ORDER
- | GETADDR_WARN_ON_SIGNAL,=
- ro->gatew= ay,
- 0,=
- &= status,
- = NULL);
+ = r->gateway =3D getaddr(GETADDR_RESOLVE | GETADDR_HOST_ORDER | GETADDR_W= ARN_ON_SIGNAL,
+ = ro->gateway, 0, &status, NULL); }
if (!status)
= {
@@ -412,7 +392,9 @@
}
else
{
- msg(M_WARN, PACKAGE_NAME "= ROUTE: " PACKAGE_NAME " needs a gateway parameter for a --route = option and no default was specified by either --route-gateway or --ifconfig= options");
+ = msg(M_WARN, PACKAGE_NAME
+ " ROUTE: " PACKAGE_NAME
<= span style=3D"color: hsl(120, 100%, 40%);">+ " needs a = gateway parameter for a --route option and no default was specified by eith= er --route-gateway or --ifconfig options");

= goto fail;
}
}
<= span>@@ -426,8 +408,7 @@

if (r->metric < 0)<= /span>
{
msg(M_WARN, PACKAGE= _NAME " ROUTE: route metric for network %s (%s) must be >=3D 0"= ;,
- ro-= >network,
- = ro->metric);
-init_route_ipv6(struct route_ipv6 *r6,<= /span>
- const = struct route_ipv6_option *r6o,
- const struct route_ipv6_list *rl6 )
+init_route_ipv6(struct route_ipv6 = *r6, const struct route_ipv6_option *r6o,

+ const struct route_ipv6_list *rl6)
{
CLEAR(*r6);
<= br>- if (!get_ipv6_addr( r6o-&= gt;prefix, &r6->network, &r6->netbits, M_WARN ))
+ if (!get_ipv6_addr(r6o->p= refix, &r6->network, &r6->netbits, M_WARN))

= {
goto fail;
}
= @@ -466,9 +446,9 @@
/* gateway */
if (is_route_parm_defined(r6o->gateway))

{
- if (inet_pton( = AF_INET6, r6o->gateway, &r6->gateway ) !=3D 1)
+ if (inet_pton(AF_INET6, r6o-&g= t;gateway, &r6->gateway) !=3D 1)
{- msg( M_WARN, PACKA= GE_NAME "ROUTE6: cannot parse gateway spec '%s'", r6o->= ;gateway );
+ = msg(M_WARN, PACKAGE_NAME "ROUTE6: cannot parse gateway spec '%= s'", r6o->gateway);
}
= }
else if (rl6->spec_flags & RTSA_REMOTE_E= NDPOINT)
@@ -485,8 +465,7 @@
if (r= 6->metric < 0)
{
= msg(M_WARN, PACKAGE_NAME " ROUTE: route metric for network %s (%s) m= ust be >=3D 0",
- r6o->prefix,
- r6o->metric);
+ r6o->prefix, r6o->metric);
goto fail;
} r6->flags |=3D RT_METRIC_DEFINED;
@@ -51= 1,12 +490,8 @@
}

void
-add_route_to_option_lis= t(struct route_option_list *l,
- const char *network,
- const char *netma= sk,
- = const char *gateway,
- const char *metric,
- int table_id)<= br>+add_route_to_option_list(st= ruct route_option_list *l, const char *network, const char *netmask,=
+ c= onst char *gateway, const char *metric, int table_id)
{
struct route_option *ro;
ALLOC_OBJ_= GC(ro, struct route_option, l->gc);
@@ -527,15 +502,11 @= @
ro->table_id =3D table_id;
r= o->next =3D l->routes;
l->routes =3D ro;
-
}=

void
-add_route_ipv6_to_option_list(struct route_ipv6_option_list *l,=
- = const char *prefix,
- const char *gateway,
- const cha= r *metric,
- = int table_id)
+add_route_ipv6_to_option_list(struct route_ipv6_option_list *l= , const char *prefix,
+ const char *gateway, const char *metric, in= t table_id)
{
struct route_ipv6_optio= n *ro;
ALLOC_OBJ_GC(ro, struct route_ipv6_option, l-&g= t;gc);
@@ -562,9 +533,7 @@
}

void
-route_list_add_vpn_gateway(struct route_list *rl,
- struct env_set = *es,
- = const in_addr_t addr)
+route_list_add_vpn_gateway(struct route_list *rl, struct env_se= t *es, const in_addr_t addr)
{
ASSERT= (rl);
rl->spec.remote_endpoint =3D addr;
= @@ -573,8 +542,7 @@
}

static void

-add_b= lock_local_item(struct route_list *rl,
- const struct route_gateway_address *g= ateway,
+add_block_lo= cal_item(struct route_list *rl, const struct route_gateway_address *gateway= ,
in_addr_t target)
= {
if (rl->rgi.gateway.netmask < 0xFFFFFFFF)
@@ -586,11 +554,11 @@
ALLOC_OBJ_GC(r2,= struct route_ipv4, &rl->gc);

= /* split a route into two smaller blocking routes, and direct them to = target */
- l2 = =3D ((~gateway->netmask)+1)>>1;
+ l2 =3D ((~gateway->netmask) + 1) >> 1= ;
r1->flags =3D RT_DEFINED;
= r1->gateway =3D target;
r1->network = =3D gateway->addr & gateway->netmask;
- r1->netmask =3D ~(l2-1);
+ r1->netmask =3D ~(l2 -= 1);

r1->next =3D rl->routes;
rl->routes =3D r1;


@@ -628,= 21 +596,15 @@
bool
block_local_needed(con= st struct route_list *rl)
{
- const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_N= ETMASK_DEFINED);
- r= eturn (rl->flags & RG_BLOCK_LOCAL)
- && (rl->rgi.flags & rgi_neede= d) =3D=3D rgi_needed
- = && (rl->spec.flags & RTSA_REMOTE_ENDPOINT)<= br>- && rl->= spec.remote_host_local !=3D TLA_LOCAL;
+ const int rgi_needed =3D (RGI_ADDR_DEFINED | RGI_NET= MASK_DEFINED);
+ r= eturn (rl->flags & RG_BLOCK_LOCAL) && (rl->rgi.flags &= ; rgi_needed) =3D=3D rgi_needed
+ && (rl->spec.flags & RTSA_REMOTE_ENDP= OINT) && rl->spec.remote_host_local !=3D TLA_LOCAL;
}


bool
-init_route_list(struct route_list *rl,
<= span style=3D"color: hsl(0, 100%, 40%);">- const struct rout= e_option_list *opt,

- = const char *remote_endpoint,
- int default_metric,
- in_addr_t remote_host,
- struct = env_set *es,
- = openvpn_net_ctx_t *ctx)
+init_route_list(struct route_list *rl, const struct route_option= _list *opt,
+ = const char *remote_endpoint, int default_metric, in_addr_t remote_h= ost,
+ = struct env_set *es, openvpn_net_ctx_t *ctx)
{
<= span> struct gc_arena gc =3D gc_new();

bool ret = =3D true;
@@ -684,14 +646,9 @@
if (is_= route_parm_defined(remote_endpoint))
{
bool defined =3D false;

- rl->spec.remote_endpoint =3D getaddr(
- GETADDR_RESOLVE
- | GETADDR_HOST_ORD= ER
- | GETAD= DR_WARN_ON_SIGNAL,
- = remote_endpoint,
- 0,
- = &defined,
= - NULL);
+= rl->spec.remote_endpoint =3D
+ getaddr(GETADDR_RESOLVE | GETADDR_HOST_ORDE= R | GETADDR_WARN_ON_SIGNAL, remote_endpoint,
+ 0, &defined, NULL);=

if (defined)
= {
@@ -759,14 +716,13 @@
* "good enou= gh")
*/
static bool
-route_ipv6_match_host( const struct r= oute_ipv6 *r6,

- = const struct in6_addr *host )
+route_ipv6_match_host(const struct route_ipv6 *r6= , const struct in6_addr *host)
{
unsi= gned int bits =3D r6->netbits;
int i;
unsigned int mask;


- if (bits>128)
+ if (bits > 128)
{
return false;
}
@@= -784,9 +740,9 @@
return true;
= }

-= mask =3D 0xff << (8-bits);
+ mask =3D 0xff << (8 - bits);

- if ( (r6->networ= k.s6_addr[i] & mask) =3D=3D (host->s6_addr[i] & mask ))+ if ((r6->network.s6_a= ddr[i] & mask) =3D=3D (host->s6_addr[i] & mask))
{

return true;
}=
@@ -795,12 +751,9 @@
}
<= br> bool
-init_ro= ute_ipv6_list(struct route_ipv6_list *rl6,
- const struct route_ipv6_option_li= st *opt6,
- = const char *remote_endpoint,
- int default_metric,
- const struct in6_ad= dr *remote_host_ipv6,
-= struct env_set *es,
+init_route_ipv6_list(struct route_ipv6_list *rl6, cons= t struct route_ipv6_option_list *opt6,
+ const char *remote_endpoint, int de= fault_metric,
+ = const struct in6_addr *remote_host_ipv6, struct env_set *es,=
openvpn_net_ctx_t *ctx)
{

struct gc_arena gc =3D gc_new();
@@ -824,7 +777,7 @@

}

msg(D_ROUTE, "GDG6: remote_host_ipv6=3D%s",

- remote_host_ipv6 ? print_= in6_addr(*remote_host_ipv6, 0, &gc) : "n/a" );

+ remote_host_ipv6 ? print_i= n6_addr(*remote_host_ipv6, 0, &gc) : "n/a");

=
get_default_gateway_ipv6(&rl6->rgi6, remote_h= ost_ipv6, ctx);
if (rl6->rgi6.flags & RGI_ADDR_= DEFINED)
@@ -839,16 +792,16 @@
dms= g(D_ROUTE, "ROUTE6: default_gateway=3DUNDEF");
= }

= - if (is_route_parm_defined( remote_endpoint ))
+ if (is_route_parm_defined(remote_endpoin= t))
{
- if (inet_pton( AF_INET6, remote_endpoint,
- &rl6->remote= _endpoint_ipv6) =3D=3D 1)
+ if (inet_pton(AF_INET6, remote_endpoint, &rl6->remote_= endpoint_ipv6) =3D=3D 1)
{
= rl6->spec_flags |=3D RTSA_REMOTE_ENDPOINT;
= }
else
{
- msg(M_WARN, PACKAGE_NAME= " ROUTE: failed to parse/resolve VPN endpoint: %s", remote_endpo= int);

+ ms= g(M_WARN, PACKAGE_NAME " ROUTE: failed to parse/resolve VPN endpoint: = %s",
+ = remote_endpoint);
ret =3D false;<= br> }
}
@@ -878,11 +831,= 11 @@
* avoiding routing loops, so ignore= this part and let
* need_remote_ipv6_rou= te always evaluate to false
*/
= - if (remote_host_= ipv6
- = && route_ipv6_match_host( r6, remote_host_ipv6 ) )
+ if (remote_host_i= pv6 && route_ipv6_match_host(r6, remote_host_ipv6))

{

need_remote_ipv6_r= oute =3D true;
- = msg(D_ROUTE, "ROUTE6: %s/%d overlaps IPv6 remote %s, addi= ng host route to VPN endpoint",
+ msg(D_ROUTE,
+ "ROUTE6: %s/%d o= verlaps IPv6 remote %s, adding host route to VPN endpoint",
= print_in6_addr(r6->network, 0, &gc), = r6->netbits,
print_in6_addr(*re= mote_host_ipv6, 0, &gc));
}
= @@ -894,15 +847,15 @@
/* add VPN server host rou= te if needed */
if (need_remote_ipv6_route)
= {
- i= f ( (rl6->rgi6.flags & (RGI_ADDR_DEFINED|RGI_IFACE_DEFINED) ) =3D=3D=
- (RGI_ADD= R_DEFINED|RGI_IFACE_DEFINED) )
+ if ((rl6->rgi6.flags & (RGI_ADDR_DEFINED | RGI_IF= ACE_DEFINED))
+ = =3D=3D (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED))
= {
struct route_ipv6 *r6;
= ALLOC_OBJ_CLEAR_GC(r6, struct route_ipv6, &rl6->gc);

r6->network =3D *remote_host_= ipv6;
r6->netbits =3D 128;
- if (!(rl6->rgi6.flags &= amp; RGI_ON_LINK) )
+= if (!(rl6->rgi6.flags & RGI_ON_LINK))
= {
r6->gateway =3D rl6->rg= i6.gateway.addr_ipv6;
}
@@ -91= 9,7 +872,8 @@
}
else
{
= - msg(M_WARN, "ROUTE6: IPv6 route overlaps with IPv6 remote= address, but could not determine IPv6 gateway address + interface, expect = failure\n" );
+ = msg(M_WARN,
-add_route3(in_addr_t network,
- in_addr_t netmask,
- in_addr_t gateway,
- const struct tuntap *tt,
- unsigned int fl= ags,
- const = struct route_gateway_info *rgi,
- const struct env_set *es,
+add_route3(in_addr_t network, in_addr_t netmask,= in_addr_t gateway, const struct tuntap *tt,
+ unsigned int flags, const struct route_= gateway_info *rgi, const struct env_set *es,
op= envpn_net_ctx_t *ctx)
{
struct route_= ipv4 r;
@@ -947,18 +896,13 @@
}
=
static void
-del_route3(in_addr_t network,
- in_addr_t netmask,
- in_addr_t gateway,
- const struct tuntap *tt,=

- unsigned i= nt flags,
- c= onst struct route_gateway_info *rgi,
- const struct env_set *es,
+del_route3(in_addr_t network, in_addr_t n= etmask, in_addr_t gateway, const struct tuntap *tt,
+ unsigned int flags, const stru= ct route_gateway_info *rgi, const struct env_set *es,
= openvpn_net_ctx_t *ctx)
{
stru= ct route_ipv4 r;
CLEAR(r);
- r.flags =3D RT_DEFINED|RT_ADDED;
+ r.flags =3D RT_DEFINED | RT_= ADDED;

r.network =3D network;
r.n= etmask =3D netmask;
r.gateway =3D gateway;
<= span>@@ -966,56 +910,42 @@

}

<= span> static bool

-add_= bypass_routes(struct route_bypass *rb,
- in_addr_t gateway,
- const struct tuntap *tt,<= /span>
- unsi= gned int flags,
- = const struct route_gateway_info *rgi,
- const struct env_set *es,
- openvpn= _net_ctx_t *ctx)
+add= _bypass_routes(struct route_bypass *rb, in_addr_t gateway, const struct tun= tap *tt,
+ = unsigned int flags, const struct route_gateway_info *rgi,
= + const struct= env_set *es, openvpn_net_ctx_t *ctx)
{
= int ret =3D true;
for (int i =3D 0; i < rb->n= _bypass; ++i)
{
if (rb->by= pass[i])
{
- ret =3D add_route3(rb->bypass[i], IPV4_NETMASK= _HOST, gateway, tt,
- = flags | ROUTE_REF_GW, rgi, es, ctx) && r= et;
+ ret = =3D add_route3(rb->bypass[i], IPV4_NETMASK_HOST, gateway, tt, flags | RO= UTE_REF_GW,
+ = rgi, es, ctx)
+ && ret;
}=
}
return ret;
}=

static void
-del_bypass_routes(struct route_bypass *rb,=
- in_addr_t = gateway,
- = const struct tuntap *tt,
- unsigned int flags,
- const struct route_gateway_info *= rgi,
- = const struct env_set *es,
- openvpn_net_ctx_t *ctx)
+del_bypass_routes(struct route_bypass *rb, in_ad= dr_t gateway, const struct tuntap *tt,
+ unsigned int flags, const struct route= _gateway_info *rgi,
+= const struct env_set *es, openvpn_net_ctx_t *ctx)<= br> {
int i;
for (i =3D 0; = i < rb->n_bypass; ++i)
{
= if (rb->bypass[i])
{
- del_route3(rb->bypass[i],
- IPV4= _NETMASK_HOST,
- = gateway,
- flags | ROUTE_REF_GW,
- rgi,
- es,

= + del_route3(rb->= bypass[i], IPV4_NETMASK_HOST, gateway, tt, flags | ROUTE_REF_GW, rgi, es,
ctx);
}
}
}

s= tatic bool
-redirect_de= fault_route_to_vpn(struct route_list *rl, const struct tuntap *tt,- = unsigned int flags, const struct env_set *es,
- openvpn_net_ctx_t *ct= x)
+redirect_default_= route_to_vpn(struct route_list *rl, const struct tuntap *tt, unsigned int f= lags,
+ = const struct env_set *es, openvpn_net_ctx_t *ctx) {
const char err[] =3D "NOTE: unable to r= edirect IPv4 default gateway --";
bool ret =3D tr= ue;
@@ -1065,9 +995,8 @@
i= f ((rl->spec.flags & RTSA_REMOTE_HOST)
= && rl->spec.remote_host !=3D IPV4_INVALID_ADDR) {
- ret =3D add_route3(rl->spec.remote_host, IPV4_N= ETMASK_HOST,
- = rl->rgi.gateway.addr, tt, flags | ROUTE_REF_= GW,
- = &rl->rgi, es, ctx);
+ ret =3D add_route3(rl->spe= c.remote_host, IPV4_NETMASK_HOST, rl->rgi.gateway.addr,
+ = tt, flags | ROUTE_REF_GW, &rl->rgi, es, ctx);
= if (ret)
{
<= span> rl->iflags |=3D RL_DID_LOCAL;

@@ -1081,20 +1010,23 @@

#endif /* ifndef TARGET_ANDROI= D */

/* route DHCP/DNS serve= r traffic through original default gateway */
- ret =3D add_bypass_routes(&rl->s= pec.bypass, rl->rgi.gateway.addr, tt, flags,
- &rl->r= gi, es, ctx) && ret;
+ ret =3D add_bypass_routes(&rl->spec.bypass, rl-= >rgi.gateway.addr, tt, flags, &rl->rgi, es,
+ ctx)<= /span>
+ &a= mp;& ret;

if (rl->fla= gs & RG_REROUTE_GW)
{
= if (rl->flags & RG_DEF1)
= {
/* add new default route (1st com= ponent) */
- = ret =3D add_route3(0x00000000, 0x80000000, rl->spec.remote_endp= oint,
- = tt, flags, &rl->rgi, es, ctx) && ret;
+ r= et =3D add_route3(0x00000000, 0x80000000, rl->spec.remote_endpoint, tt, = flags,
+ = &rl->rgi, es, ctx)
+ && ret;

/* add new default rout= e (2nd component) */
- = ret =3D add_route3(0x80000000, 0x80000000, rl->spec.r= emote_endpoint,
- = tt, flags, &rl->rgi, es, ctx) &&a= mp; ret;
+ = ret =3D add_route3(0x80000000, 0x80000000, rl->spec.remote_endp= oint, tt, flags,
+ = &rl->rgi, es, ctx)
+ &&= ; ret;

}
= else
{
@@ -1102,13 +1034,1= 3 @@
if (rl->rgi.flags & RGI_AD= DR_DEFINED)
{
= /* delete default route */
- del_route3(0, 0, rl->rgi.g= ateway.addr, tt,
- = flags | ROUTE_REF_GW, &rl->rgi, es, ct= x);
+ = del_route3(0, 0, rl->rgi.gateway.addr, tt, flags | ROUTE_REF_GW,= &rl->rgi,
+ = es, ctx);
= }

/* add new de= fault route */
- = ret =3D add_route3(0, 0, rl->spec.remote_endpoint, tt,
- = flags, &rl->rgi, es, ctx) && ret;
+ ret =3D add_rou= te3(0, 0, rl->spec.remote_endpoint, tt, flags, &rl->rgi, es, ctx)=

+ = && ret;
}
= }

@@ -1120,9 +1052,8 @@
}

static void
-undo_redirect_default_route_to_vpn(s= truct route_list *rl,

-= const struct tuntap *tt, unsigned int fl= ags,
- = const struct env_set *es,
+undo_redirect_default_route_to_vpn(struct route_lis= t *rl, const struct tuntap *tt,
+ unsigned int flags, const st= ruct env_set *es,
openv= pn_net_ctx_t *ctx)
{
if (rl &&= ; rl->iflags & RL_DID_REDIRECT_DEFAULT_GATEWAY)
@@ -= 1130,61 +1061,35 @@
/* delete remote host route */=
if (rl->iflags & RL_DID_LOCAL)
<= span> {

- = del_route3(rl->spec.remote_host,
- IPV4_NETMASK_HOST,
- rl->rgi.g= ateway.addr,

- = tt,
- = flags | ROUTE_REF_GW,
- &rl->rgi,
- es,
<= span style=3D"color: hsl(0, 100%, 40%);">- ctx);
+ del_route3(r= l->spec.remote_host, IPV4_NETMASK_HOST, rl->rgi.gateway.addr, tt,
+ = flags | ROUTE_REF_GW, &rl->rgi, es, ctx);
= rl->iflags &=3D ~RL_DID_LOCAL;
}<= br>
/* delete special DHCP/DNS bypass route= */
- del_bypass= _routes(&rl->spec.bypass, rl->rgi.gateway.addr, tt, flags,=
- &a= mp;rl->rgi, es, ctx);
+ del_bypass_routes(&rl->spec.bypass, rl->rgi.gateway.= addr, tt, flags, &rl->rgi, es, ctx);

if (rl->flags & RG_REROUTE_GW)

= {
if (rl->flags & RG_DEF1)
{

/* delete default route= (1st component) */
- = del_route3(0x00000000,
- 0x80000000,
- rl->spec.remo= te_endpoint,
- = tt,
-= flags,
- &rl->rgi,
- es,
= - ctx);=
+ del= _route3(0x00000000, 0x80000000, rl->spec.remote_endpoint, tt, flags, &am= p;rl->rgi,
+ = es, ctx);

= /* delete default route (2nd component) */
- del_route3(0x80000000,- 0x8= 0000000,
- = rl->spec.remote_endpoint,
- tt,
- flags,- &= ;rl->rgi,
- = es,
-= ctx);
+ del_route3(0x80000000, 0x80000000, rl->spec= .remote_endpoint, tt, flags, &rl->rgi,
+ es, ctx);
}

else
= {
/* delete default route */=
- del_route3(0= ,
- = 0,
- = rl->spec.remote_endpoint,
- tt,
- flags,- &= ;rl->rgi,
- = es,
-= ctx);
+ del_route3(0, 0, rl->spec.remote_endpoint, = tt, flags, &rl->rgi, es, ctx);
/* r= estore original default route if there was any */
= if (rl->rgi.flags & RGI_ADDR_DEFINED)
= {
- = add_route3(0, 0, rl->rgi.gateway.addr, tt,
- flags | R= OUTE_REF_GW, &rl->rgi, es, ctx);
+ add_route3(0, 0, rl->rgi.gateway= .addr, tt, flags | ROUTE_REF_GW, &rl->rgi, es,
+ ctx);
}
}
}

@@ -1194,32 +1099,28 @@
}

bool
-add_routes(struct route_list *rl, struct route_ipv6_list *r= l6,
- const s= truct tuntap *tt, unsigned int flags,
- const struct env_set *es, openvpn_net_ctx_t *ctx= )
+add_routes(struct = route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt,
+ unsigned int f= lags, const struct env_set *es, openvpn_net_ctx_t *ctx)
{<= /span>
bool ret =3D redirect_default_route_to_vpn(rl, tt, fla= gs, es, ctx);
- if (= rl && !(rl->iflags & RL_ROUTES_ADDED) )
+ if (rl && !(rl->iflags &a= mp; RL_ROUTES_ADDED))
{
struc= t route_ipv4 *r;

if (rl->rout= es && !tt->did_ifconfig_setup)
{=
- msg(M_INFO, &quo= t;WARNING: OpenVPN was configured to add an IPv4 "
+ msg(M_INFO,
+ "WARNING: Open= VPN was configured to add an IPv4 "

&= quot;route. However, no IPv4 has been configured for %s, "
<= span> "therefore the route installation may fail or ma= y not work "

- = "as expected.", tt->actual_name);
+ "as expected.&q= uot;,
+ = tt->actual_name);
}
<= br> #ifdef ENABLE_MANAGEMENT
if (management = && rl->routes)
{
- management_set_state(management= ,
- = OPENVPN_STATE_ADD_ROUTES,
- NULL,
- NULL,
- = NULL,
- = NULL,
+ management_set_state(management, OPENVPN_STATE_ADD_= ROUTES, NULL, NULL, NULL, NULL,
= NULL);
}
#endif
= @@ -1234,16 +1135,18 @@
}
= rl->iflags |=3D RL_ROUTES_ADDED;
}- if (rl6 && !(rl6-&g= t;iflags & RL_ROUTES_ADDED) )
+ if (rl6 && !(rl6->iflags & RL_ROUTES_ADDED= ))
{
struct route_ipv6 *r;

if (!tt->did_ifconfig_ipv6_setu= p)
{
- msg(M_INFO, "WARNING: OpenVPN was configured to ad= d an IPv6 "
+ = msg(M_INFO,
= + "WARNING: OpenVPN was configured to add an IPv6 "= ;
"route. However, no IPv6 has been c= onfigured for %s, "
"therefore t= he route installation may fail or may not work "
- "as expected.", t= t->actual_name);
+= "as expected.",
+ tt->actual_name);
= }

for (r =3D rl6->ro= utes_ipv6; r; r =3D r->next)
@@ -1261,9 +1164,8 @@
}

void
-delete_routes(struct route_list *rl, struct= route_ipv6_list *rl6,
= - const struct tuntap *tt, unsigned int flags,
- const struct env_set *e= s, openvpn_net_ctx_t *ctx)

+delete_routes(struct route_list *rl, struct route_ipv6_list *rl6, co= nst struct tuntap *tt,
- if (rl6 && (rl6->iflags & RL_ROUTES_ADDED) )
+ if (rl6 &&= (rl6->iflags & RL_ROUTES_ADDED))
{
<= span> struct route_ipv6 *r6;

for (r6 =3D r= l6->routes_ipv6; r6; r6 =3D r6->next)
@@ -1316,22 +12= 18,17 @@
static void
print_route_option(c= onst struct route_option *ro, int level)
{
- msg(level, " route %s/%s/%s= /%s",

- sho= w_opt(ro->network),
= - show_opt(ro->netmask),
- show_opt(ro->gateway),
- show_opt(ro->metric));
+ msg(level, " route %s/%s/%= s/%s", show_opt(ro->network), show_opt(ro->netmask),
<= span style=3D"color: hsl(120, 100%, 40%);">+ show_opt(ro->gateway= ), show_opt(ro->metric));

}
void
-print_rou= te_options(const struct route_option_list *rol,
- int level)
+print_route_options(const struct route= _option_list *rol, int level)
{
struc= t route_option *ro;
if (rol->flags & RG_ENABLE)=
{
- msg(level, " [redirect_default_gateway local=3D%d]",
- (rol->fl= ags & RG_LOCAL) !=3D 0);
+ msg(level, " [redirect_default_gateway local=3D%d]&q= uot;, (rol->flags & RG_LOCAL) !=3D 0);
}=
for (ro =3D rol->routes; ro; ro =3D ro->next) {
@@ -1340,8 +1237,7 @@
}

void
-print_default_gateway(const int msglevel,
- const struct route= _gateway_info *rgi,
+= print_default_gateway(const int msglevel, const struct route_gateway_info *= rgi,
const struct route_ipv6_gateway= _info *rgi6)
{
struct gc_arena gc =3D= gc_new();
@@ -1472,23 +1368,22 @@
str= uct gc_arena gc =3D gc_new();
if (r6->flags & R= T_DEFINED)
{
- struct buffer name1 =3D alloc_buf_gc( 256, &gc );
- struct buffer v= al =3D alloc_buf_gc( 256, &gc );
- struct buffer name2 =3D alloc_buf_gc( 256, &gc )= ;
+ struct buf= fer name1 =3D alloc_buf_gc(256, &gc);
+ struct buffer val =3D alloc_buf_gc(256, &= gc);
+ struct = buffer name2 =3D alloc_buf_gc(256, &gc);

- buf_printf( &name1, &q= uot;route_ipv6_network_%d", i );

- buf_printf( &val, "%s/%d", print_in6_= addr( r6->network, 0, &gc ),
- r6->netbits );
- setenv_str( es, BSTR(&name1), B= STR(&val) );
+ = buf_printf(&name1, "route_ipv6_network_%d", i);+ buf_printf(&val,= "%s/%d", print_in6_addr(r6->network, 0, &gc), r6->netb= its);
+ setenv= _str(es, BSTR(&name1), BSTR(&val));

- buf_printf( &name2, &qu= ot;route_ipv6_gateway_%d", i );

- setenv_str( es, BSTR(&name2), print_in6_addr( r6= ->gateway, 0, &gc ));
+ buf_printf(&name2, "route_ipv6_gateway_%d", = i);
+ setenv_s= tr(es, BSTR(&name2), print_in6_addr(r6->gateway, 0, &gc));

if (r6->flags & RT_METRIC_DEFI= NED)
{
- struct buffer name3 =3D alloc_buf_gc( 256, &gc );=
- buf_print= f( &name3, "route_ipv6_metric_%d", i);
- setenv_int( es, BSTR(&name3= ), r6->metric);
+ = struct buffer name3 =3D alloc_buf_gc(256, &gc);
+ buf_printf(&name= 3, "route_ipv6_metric_%d", i);

+ setenv_int(es, BSTR(&name3), r6->me= tric);
}
}
= gc_free(&gc);
@@ -1528,19 +1423,15 @@
#define LR_ERROR 2 /* caller should abort adding route */


static int
-local_route(in_addr_t network,
- in_addr_t netmask,
- in_addr_t gateway,
+local_route(in_addr_t network, i= n_addr_t netmask, in_addr_t gateway,

const str= uct route_gateway_info *rgi)
{
/* set= LR_MATCH on local host routes */
- const int rgi_needed =3D (RGI_ADDR_DEFINED|RGI_NETMASK_DEFI= NED|RGI_IFACE_DEFINED);
- if (rgi
- = && (rgi->flags & rgi_needed) =3D=3D rgi_needed
- && gateway =3D=3D r= gi->gateway.addr

+= const int rgi_needed =3D (RGI_ADDR_DEFINED | RGI_NETMASK_DEFINED | RGI_= IFACE_DEFINED);
+ = if (rgi && (rgi->flags & rgi_needed) =3D=3D rgi_needed &= & gateway =3D=3D rgi->gateway.addr
&&am= p; netmask =3D=3D 0xFFFFFFFF)
{
- if (((network ^ rgi->gateway.ad= dr) & rgi->gateway.netmask) =3D=3D 0)
+ if (((network ^ rgi->gateway.addr) &= ; rgi->gateway.netmask) =3D=3D 0)
{
<= span> return LR_MATCH;

}
@@ -1567,17 +1458,16 @@

static inline bool
is_on_link(const int is_local_route, const unsigned int flags, const s= truct route_gateway_info *rgi)

{
- return rgi && (is_local_route =3D= =3D LR_MATCH || ((flags & ROUTE_REF_GW) && (rgi->flags &= RGI_ON_LINK)));
+ = return rgi
+ = && (is_local_route =3D=3D LR_MATCH
+ || ((flags & ROUTE_REF_GW) &am= p;& (rgi->flags & RGI_ON_LINK)));
}
<= span> #endif


bool
-add_route(struct route_ipv4 *r,
<= span style=3D"color: hsl(0, 100%, 40%);">- const struct tuntap *tt= ,

- unsigned i= nt flags,
- co= nst struct route_gateway_info *rgi, /* may be NULL */
- const struct env_set *es,=
- openvpn_net_ctx_t = *ctx)
+add_route(stru= ct route_ipv4 *r, const struct tuntap *tt, unsigned int flags,
+ const struct route_gat= eway_info *rgi, /* may be NULL */

+ const struct env_set *es, openvpn_net_ctx_t *ctx)
{
int status =3D 0;
= int is_local_route;
@@ -1620,8 +1510,8 @@


status =3D RTA_SUCCESS;- int ret =3D net_route_v4_a= dd(ctx, &r->network, netmask_to_netbits2(r->netmask),
<= span style=3D"color: hsl(0, 100%, 40%);">- &a= mp;r->gateway, iface, r->table_id, metric);

+ int ret =3D net_route_v4_add(ctx, &r-= >network, netmask_to_netbits2(r->netmask), &r->gateway,=
+ = iface, r->table_id, metric);
if (ret =3D=3D -E= EXIST)
{
msg(D_ROUTE, "N= OTE: Linux route add command failed because route exists");
= @@ -1633,7 +1523,7 @@
status =3D RTA_ERROR;<= /span>
}

-#elif defined (TARGET_ANDROID)
+#elif defined(TARGET_ANDROID)
char out[128];


if (rgi)=
@@ -1647,15 +1537,11 @@
bool ret =3D managem= ent_android_control(management, "ROUTE", out);
= status =3D ret ? RTA_SUCCESS : RTA_ERROR;

-#elif defined (_WIN32)

<= span style=3D"color: hsl(120, 100%, 40%);">+#elif defined(_WIN32)
{
DWORD ai =3D TUN_ADAPTER_INDEX_INVAL= ID;
- argv_print= f(&argv, "%s%s ADD %s MASK %s %s",
- get_win_sys_path(),- WIN_ROUTE_= PATH_SUFFIX,
- = network,
- = netmask,
- gateway);
+ argv_printf(&argv, "%s%s ADD %s MASK %s %s&= quot;, get_win_sys_path(), WIN_ROUTE_PATH_SUFFIX,
+ network, netmask, gateway= );
if (r->flags & RT_METRIC_DEFINED)=
{
argv_printf_cat(&argv= , "METRIC %d", r->metric);
@@ -1681,8 +1567,8 = @@
else if ((flags & ROUTE_METHOD_MASK) =3D=3D= ROUTE_METHOD_EXE)
{
= netcmd_semaphore_lock();
- = "ERROR: Windows route add command failed");<= br>+ bool ret =3D
+ openvp= n_execve_check(&argv, es, 0, "ERROR: Windows route add command fai= led");
status =3D ret ? RTA_SUCCESS : RTA= _ERROR;
netcmd_semaphore_release();
= method =3D "route.exe";
@@ -16= 95,8 +1581,8 @@
{
= msg(D_ROUTE, "Route addition fallback to route.exe");=
netcmd_semaphore_lock();
- bool ret =3D openvpn_execve= _check(&argv, es, 0,
+ bool ret =3D openvpn_execve_check(
+ &am= p;argv, es, 0, "ERROR: Windows route add command failed [adaptive]&quo= t;);
status =3D ret ? RTA_SUCCESS : RTA_ER= ROR;
netcmd_semaphore_release(); method =3D "route.exe";
@= @ -1713,17 +1599,13 @@
}
}

-#elif = defined (TARGET_SOLARIS)
+#elif defined(TARGET_SOLARIS)

/= * example: route add 192.0.2.32 -netmask 255.255.255.224 somegateway */

- arg= v_printf(&argv, "%s add",
- ROUTE_PATH);
+ argv_printf(&argv, "%s add", R= OUTE_PATH);

- argv_printf_cat(&argv, "%s -netmask %s %s",
- network= ,
- = netmask,
- = gateway);
+ = argv_printf_cat(&argv, "%s -netmask %s %s", network, netmask= , gateway);

/* Solaris can only dist= inguish between "metric 0" =3D=3D "on-link on the
= * interface where the IP address given is configured" and = "metric > 0"
@@ -1738,14 +1620,12 @@ }

argv_msg(D_ROUTE, &= ;argv);
- bool ret = =3D openvpn_execve_check(&argv, es, 0,
- "ERROR: Solar= is route add command failed");
+ bool ret =3D openvpn_execve_check(&argv, es, 0, &qu= ot;ERROR: Solaris route add command failed");
sta= tus =3D ret ? RTA_SUCCESS : RTA_ERROR;

#= elif defined(TARGET_FREEBSD)

- argv_printf(&argv, "%s add",
- ROUTE_PAT= H);
+ argv_printf(= &argv, "%s add", ROUTE_PATH);

#if 0

if (r->flags & RT_METRIC_DEFINED)
@@ -1754,22 +1634,17 @@
}
#endif


- argv_printf_cat(&argv, "-net %s %s %s",
- network,
- gateway= ,
- = netmask);
+ argv_p= rintf_cat(&argv, "-net %s %s %s", network, gateway, netmask);=

/* FIXME -- add on-link support for= FreeBSD */

argv_msg(D_ROUTE, &a= rgv);
- bool ret =3D= openvpn_execve_check(&argv, es, 0,
- "ERROR: FreeBSD = route add command failed");
+ bool ret =3D openvpn_execve_check(&argv, es, 0, "= ERROR: FreeBSD route add command failed");
status= =3D ret ? RTA_SUCCESS : RTA_ERROR;

#eli= f defined(TARGET_DRAGONFLY)

- argv_printf(&argv, "%s add",
- ROUTE_PATH= );
+ argv_printf(&= amp;argv, "%s add", ROUTE_PATH);

#if 0

if (r->flags & RT_METRIC_DEFINED)
@@ -1778,22 +1653,17 @@
}
= #endif

- argv_printf_cat(&argv, "-net %s %s %s",
- network,
=
- gateway,=
- n= etmask);
+ argv_pr= intf_cat(&argv, "-net %s %s %s", network, gateway, netmask);<= /span>

/* FIXME -- add on-link support for = Dragonfly */

argv_msg(D_ROUTE, &= argv);
- bool ret = =3D openvpn_execve_check(&argv, es, 0,
- "ERROR: Drago= nFly route add command failed");
+ bool ret =3D openvpn_execve_check(&argv, es, 0, &= quot;ERROR: DragonFly route add command failed");
= status =3D ret ? RTA_SUCCESS : RTA_ERROR;

#elif defined(TARGET_DARWIN)


- argv_printf(&argv, "%s add",<= /span>
- ROUTE_= PATH);
+ argv_prin= tf(&argv, "%s add", ROUTE_PATH);

= #if 0
if (r->flags & RT_METRIC_DEFINED)<= /span>
@@ -1806,28 +1676,21 @@
{
/* Mac OS X route syntax for ON_LINK:

= * route add -cloning -net 10.10.0.1 -netmask 255.255.255.255 -interface e= n0 */
- argv_pri= ntf_cat(&argv, "-cloning -net %s -netmask %s -interface %s",<= /span>
- = network,
- = netmask,
+ argv_printf_cat(&argv, "-cloning -net %s -netmask %s -in= terface %s", network, netmask,
= rgi->iface);
}
else {
- = argv_printf_cat(&argv, "-net %s %s %s",
- network,- gateway= ,
- = netmask);
+ = argv_printf_cat(&argv, "-net %s %s %s", network, gateway, n= etmask);
}

argv= _msg(D_ROUTE, &argv);
- bool ret =3D openvpn_execve_check(&argv, es, 0,
- &= quot;ERROR: OS X route add command failed");

+ bool ret =3D openvpn_execve_check(&ar= gv, es, 0, "ERROR: OS X route add command failed");
status =3D ret ? RTA_SUCCESS : RTA_ERROR;

<= br> #elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)
- argv_prin= tf(&argv, "%s add",
- ROUTE_PATH);
+ argv_printf(&argv, "%s add", ROUTE_P= ATH);

#if 0
if (r-&= gt;flags & RT_METRIC_DEFINED)
@@ -1836,47 +1699,36 @@
}
#endif

<= span style=3D"color: hsl(0, 100%, 40%);">- argv_printf_cat(&argv, &q= uot;-net %s %s -netmask %s",

- network,
- gateway,
- netmask);
+ argv_printf_cat(&argv, "-n= et %s %s -netmask %s", network, gateway, netmask);

/* FIXME -- add on-link support for OpenBSD/NetBSD */

argv_msg(D_ROUTE, &argv);<= br>- bool ret =3D openvpn_exec= ve_check(&argv, es, 0,
- "ERROR: OpenBSD/NetBSD route = add command failed");
+ bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR:= OpenBSD/NetBSD route add command failed");
statu= s =3D ret ? RTA_SUCCESS : RTA_ERROR;

#el= if defined(TARGET_AIX)

{
<= span> int netbits =3D netmask_to_netbits2(r->netmask);
- argv_printf(&argv, = "%s add -net %s/%d %s",
- ROUTE_PATH,
- network, netbits, gateway);
+ argv_printf(&= argv, "%s add -net %s/%d %s", ROUTE_PATH, network, netbits, gatew= ay);
argv_msg(D_ROUTE, &argv);
- bool ret =3D openvpn_execve_c= heck(&argv, es, 0,

= - "ERROR: AIX route add command= failed");
+ = bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: AIX ro= ute add command failed");
status =3D ret ? RT= A_SUCCESS : RTA_ERROR;
}

<= span> #elif defined(TARGET_HAIKU)


/*= ex: route add /dev/net/ipro1000/0 0.0.0.0 gw 192.168.1.1 netmask 128.0.0.0= */
- argv_printf(&a= mp;argv, "%s add %s inet %s gw %s netmask %s",
- ROUTE_PATH,
- rgi->iface,
- network,<= /span>
- gatewa= y,
- net= mask);
+ argv_prin= tf(&argv, "%s add %s inet %s gw %s netmask %s", ROUTE_PATH, r= gi->iface, network,
- bool= ret =3D openvpn_execve_check(&argv, es, 0,
- "ERROR: = Haiku inet route add command failed");
+ bool ret =3D openvpn_execve_check(&argv, es= , 0, "ERROR: Haiku inet route add command failed");
status =3D ret ? RTA_SUCCESS : RTA_ERROR;

<= br>-#else /* if defined(TARGET_LI= NUX) */
- msg(M_FATA= L, "Sorry, but I don't know how to do 'route' commands on = this operating system. Try putting your routes in a --route-up script"= ;);
+#else /* if def= ined(TARGET_LINUX) */
+ msg(M_FATAL,
+ = "Sorry, but I don't know how to do 'route' commands= on this operating system. Try putting your routes in a --route-up script&= quot;);
#endif /* if defined(TARGET_LINUX) */

done:
@@ -1898,7 +1750,7 @@

void
-route_ipv6_clear_host_bits( struct route_ipv6 *= r6 )
+route_ipv6_clea= r_host_bits(struct route_ipv6 *r6)
{
= /* clear host bit parts of route
* (needed if routes = are specified improperly, or if we need to
@@ -1911,24 +176= 3,25 @@
{
if (bits_to_clear &= gt;=3D 8)
{
- r6->network.s6_addr[byte--] =3D 0; bits_to_cl= ear -=3D 8;
+ = r6->network.s6_addr[byte--] =3D 0;
+ bits_to_clear -=3D 8;
= }
else
{
= - r6->network.s6_ad= dr[byte--] &=3D (0xff << bits_to_clear); bits_to_clear =3D 0;
+ r6->netw= ork.s6_addr[byte--] &=3D (0xff << bits_to_clear);
+ bits_to_clear =3D 0;
}
}
}
bool
-add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt,
- unsigned = int flags, const struct env_set *es,
- openvpn_net_ctx_t *ctx)
+add_route_ipv6(struct route_ipv6 *r6, con= st struct tuntap *tt, unsigned int flags,
+ const struct env_set *es, openvpn_net_= ctx_t *ctx)
{
int status =3D 0;

bool gateway_needed =3D false;

= - if (!(r6->flags & RT_= DEFINED) )
+ if (!= (r6->flags & RT_DEFINED))
{
= return true; /* no error */
}
@@= -1938,10 +1791,10 @@

#ifndef _WIN32
const char *device =3D tt->actual_name;
- if (r6->iface !=3D NULL) = /* vpn server special route */

+ if (r6->iface !=3D NULL) /* vpn server special r= oute */
{
device =3D r6->i= face;
- if (!IN6= _IS_ADDR_UNSPECIFIED(&r6->gateway) )
+ if (!IN6_IS_ADDR_UNSPECIFIED(&r6->ga= teway))
{
gateway_nee= ded =3D true;
}
@@ -1949,11 +1802,= 10 @@
#endif

route_= ipv6_clear_host_bits(r6);
- const char *network =3D print_in6_addr( r6->network, 0, &gc)= ;
- const char *gate= way =3D print_in6_addr( r6->gateway, 0, &gc);
+ const char *network =3D print_in6_add= r(r6->network, 0, &gc);
+ const char *gateway =3D print_in6_addr(r6->gateway, 0, &a= mp;gc);

-#if defined(TARGET_DARWIN) \
- || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) = \
+#if defined(TARG= ET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \=
|| defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)<= br>
/* the BSD platforms cannot specify gateway= and interface independently,
@@ -1961,22 +1813,21 @@
* we build a combined "$gateway%$interface" gate= way string
*/
if (r6->iface != =3D NULL && gateway_needed
- && IN6_IS_ADDR_LINKLOCAL(&r6->gateway) = ) /* fe80::...%intf */
+ && IN6_IS_ADDR_LINKLOCAL(&r6->gateway)) /*= fe80::...%intf */
{
- int len =3D strlen(gateway) + 1 + strlen(r6->= ;iface)+1;
- cha= r *tmp =3D gc_malloc( len, true, &gc );
- snprintf( tmp, len, "%s%%%s", gatew= ay, r6->iface );
+= int len =3D strlen(gateway) + 1 + strlen(r6->iface) + 1;<= br>+ char *tmp =3D gc_ma= lloc(len, true, &gc);
+ snprintf(tmp, len, "%s%%%s", gateway, r6->iface)= ;
gateway =3D tmp;
} #endif

#ifndef _WIN32- msg(D_ROUTE, "add_rout= e_ipv6(%s/%d -> %s metric %d) dev %s",
- network, r6->netbits, gateway, r6->m= etric, device );
+ = msg(D_ROUTE, "add_route_ipv6(%s/%d -> %s metric %d) dev %s", = network, r6->netbits, gateway,
+ r6->metric, device);
#else=
- msg(D_ROUTE, "add_r= oute_ipv6(%s/%d -> %s metric %d) IF %lu",
- network, r6->netbits, gateway, r6-&g= t;metric,
- r6-&= gt;adapter_index ? r6->adapter_index : tt->adapter_index);
= + msg(D_ROUTE, "add_rou= te_ipv6(%s/%d -> %s metric %d) IF %lu", network, r6->netbits, ga= teway,
+ r6-&g= t;metric, r6->adapter_index ? r6->adapter_index : tt->adapter_inde= x);
#endif

/*
@@ -1990,18 +1841,19 @@
* interfaces. OT= OH, on "tap" interface, we must always set the
= * gateway unless the route is to be an on-link network
= */
- if (tt-&g= t;type =3D=3D DEV_TYPE_TAP
- && !( (r6->flags & RT_METRIC_DEFINED) &&= ; r6->metric =3D=3D 0 ) )
+ if (tt->type =3D=3D DEV_TYPE_TAP && !((r6->flags= & RT_METRIC_DEFINED) && r6->metric =3D=3D 0))
{

gateway_needed =3D true;
}


if (gateway_needed &&= ; IN6_IS_ADDR_UNSPECIFIED(&r6->gateway))
{
- msg(M_WARN, "= ROUTE6 WARNING: " PACKAGE_NAME " needs a gateway "+ msg(M_WARN,+ "ROUTE6 WARN= ING: " PACKAGE_NAME " needs a gateway "
= "parameter for a --route-ipv6 option and no default was set v= ia "
"--ifconfig-ipv6 or --route-ipv= 6-gateway option. Not installing "
- "IPv6 route to %s/%d.", network, r= 6->netbits);
+ = "IPv6 route to %s/%d.",
+ network, r6->netbits);
status =3D 0;

goto done;
}

@@ -2014,8 +1866,7 @@
}=

status =3D RTA_SUCCESS;
- int ret =3D net_route_v6_add(ctx, &a= mp;r6->network, r6->netbits,
- gateway_needed ? &r6->ga= teway : NULL,
+ in= t ret =3D net_route_v6_add(ctx, &r6->network, r6->netbits, gatewa= y_needed ? &r6->gateway : NULL,
= device, r6->table_id, metric);
if (ret = =3D=3D -EEXIST)
{
@@ -2028,14 +1879,14= @@
status =3D RTA_ERROR;
}

-#elif= defined (TARGET_ANDROID)
+#elif defined(TARGET_ANDROID)
char out[64];

snprintf(out, sizeof(out), "%s/%d %= s", network, r6->netbits, device);

status =3D management_android_control(management, "ROUTE6"= , out);


-#elif defined (_WIN32)
+#elif defined(_WIN32)

if (tt-= >options.msg_channel)
{
@@ -2045,7 = +1896,7 @@
{
status =3D route= _ipv6_ipapi(true, r6, tt);
}
-#elif defined (TARGET_SOLARIS)
+#elif defined(TARGET_SOLARIS)=

/* example: route add -inet6 2001:db8::/32= somegateway 0 */

@@ -2058,11 +1909,7 @@<= /span>
* use the GW addresses - it seems to still work for f= e80:: addresses,
* however this is done internally. = NUD maybe?)
*/
- argv_printf(&argv, "%s add -inet6 %s/%d %s"= ;,
- ROU= TE_PATH,
- = network,
- = r6->netbits,
-= gateway );
+ argv_printf(&argv, "%s add -inet6 %s/%d %s", ROUTE= _PATH, network, r6->netbits, gateway);

/* on tun (not tap), not "elsewhere"? -> metric 0 */
if (tt->type =3D=3D DEV_TYPE_TUN && !r6->if= ace)
@@ -2071,16 +1918,12 @@
}<= br>
argv_msg(D_ROUTE, &argv);
- bool ret =3D openvpn_execve_che= ck(&argv, es, 0,

- = "ERROR: Solaris route add -inet6 co= mmand failed");
= + bool ret =3D openvpn_execve_check(&argv, es, 0, "ERROR: Solar= is route add -inet6 command failed");
status =3D = ret ? RTA_SUCCESS : RTA_ERROR;

#elif def= ined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)
<= br>- argv_printf(&argv, &q= uot;%s add -inet6 %s/%d",
- ROUTE_PATH,
- network,
- r6->netbits);
+ argv_printf(&argv, "%s add -ine= t6 %s/%d", ROUTE_PATH, network, r6->netbits);

if (gateway_needed)
{
@@ -2092,15 +1935,12 @@

}
argv_msg(D_ROUTE, &argv);
- bool ret =3D openvpn_execve_check(&argv, es, 0= ,
- = "ERROR: *BSD route add -inet6 command failed");
+ bool ret =3D open= vpn_execve_check(&argv, es, 0, "ERROR: *BSD route add -inet6 comma= nd failed");
status =3D ret ? RTA_SUCCESS : RTA_E= RROR;

#elif defined(TARGET_DARWIN)

- argv_= printf(&argv, "%s add -inet6 %s -prefixlen %d",
- ROUTE_PATH,
<= br>- network, r6-&= gt;netbits );
+ ar= gv_printf(&argv, "%s add -inet6 %s -prefixlen %d", ROUTE_PATH= , network, r6->netbits);

if (gate= way_needed)
{
@@ -2112,58 +1952,45 @@<= /span>
}

argv_msg(D_RO= UTE, &argv);
- b= ool ret =3D openvpn_execve_check(&argv, es, 0,
- "ERRO= R: MacOS X route add -inet6 command failed");
+ bool ret =3D openvpn_execve_check(&a= rgv, es, 0, "ERROR: MacOS X route add -inet6 command failed");
status =3D ret ? RTA_SUCCESS : RTA_ERROR;

#elif defined(TARGET_OPENBSD)
=
- argv_printf(&argv, &= quot;%s add -inet6 %s -prefixlen %d %s",
- ROUTE_PATH,
- network, r6->netbits, ga= teway );
+ argv_pr= intf(&argv, "%s add -inet6 %s -prefixlen %d %s", ROUTE_PATH, = network, r6->netbits,
+ gateway);

argv_= msg(D_ROUTE, &argv);
- &q= uot;ERROR: OpenBSD route add -inet6 command failed");
+ bool ret =3D openvpn_execve_chec= k(&argv, es, 0, "ERROR: OpenBSD route add -inet6 command failed&qu= ot;);
status =3D ret ? RTA_SUCCESS : RTA_ERROR;=

#elif defined(TARGET_NETBSD)
=
- argv_printf(&= argv, "%s add -inet6 %s/%d %s",
- ROUTE_PATH,
- network, r6->netbits, gateway = );
+ argv_printf(&= amp;argv, "%s add -inet6 %s/%d %s", ROUTE_PATH, network, r6->n= etbits, gateway);

argv_msg(D_ROUTE, = &argv);
- bool r= et =3D openvpn_execve_check(&argv, es, 0,
- "ERROR: Ne= tBSD route add -inet6 command failed");
+ bool ret =3D openvpn_execve_check(&argv, e= s, 0, "ERROR: NetBSD route add -inet6 command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR;

#elif defined(TARGET_AIX)

- argv_printf(&argv, "%s add= -inet6 %s/%d %s",
- ROUTE_PATH,
- network, r6->netbits, gateway);
+ argv_printf(&argv, "%s = add -inet6 %s/%d %s", ROUTE_PATH, network, r6->netbits, gateway);
argv_msg(D_ROUTE, &argv);
- bool ret =3D openvpn_execve_check(&argv= , es, 0,
- = "ERROR: AIX route add command failed");
+ bool ret =3D openv= pn_execve_check(&argv, es, 0, "ERROR: AIX route add command failed= ");
status =3D ret ? RTA_SUCCESS : RTA_ERROR;

#elif defined(TARGET_HAIKU)

/* ex: route add /dev/net/ipro1000/0 inet6 :: gw be= ef::cafe prefixlen 64 */
- = ROUTE_PATH,
- = r6->iface,
- = network,
= - gateway,
- r6->netbits);
+ argv_printf(&argv, "%s add %s inet6 %s gw %s = prefixlen %d", ROUTE_PATH, r6->iface, network,
+ gateway, r6->netbits)= ;
argv_msg(D_ROUTE, &argv);
- bool ret =3D openvpn_execve_check(&= argv, es, 0,
- = "ERROR: Haiku inet6 route add command faile= d");
+ bool r= et =3D openvpn_execve_check(&argv, es, 0, "ERROR: Haiku inet6 rout= e add command failed");
status =3D ret ? RTA_SUCC= ESS : RTA_ERROR;

#else /* if defined(TA= RGET_LINUX) */
- msg= (M_FATAL, "Sorry, but I don't know how to do 'route ipv6' = commands on this operating system. Try putting your routes in a --route-up= script");
+ = msg(M_FATAL,
+ = "Sorry, but I don't know how to do 'route ipv6' commands = on this operating system. Try putting your routes in a --route-up script&q= uot;);
#endif /* if defined(TARGET_LINUX) */

done:
@@ -2184,12 +2011,8 @@ }

static void
-delete_route(struct route_ipv4 *r,
- const struct = tuntap *tt,
- = unsigned int flags,
= - const struct route_gateway_info *rgi,
- const struct env_set *es,
- openvpn_net_c= tx_t *ctx)
+delete_ro= ute(struct route_ipv4 *r, const struct tuntap *tt, unsigned int flags,
+ const struc= t route_gateway_info *rgi, const struct env_set *es, openvpn_net_ctx_t *ctx= )
{
#if !defined(TARGET_LINUX)
= const char *network;
@@ -2199,12 +2022,12 @@
#if !defined(TARGET_ANDROID)
const char = *gateway;
#endif
-#else /* if !defined(TARGET_LINUX) */
+#else /* if !defined(TARGET_LINUX) */=
int metric;
#endif
int= is_local_route;

- if ((r->flags & (RT_DEFINED|RT_ADDED)) !=3D (RT_DEF= INED|RT_ADDED))
+ = if ((r->flags & (RT_DEFINED | RT_ADDED)) !=3D (RT_DEFINED | RT_ADDED= ))
{
return;
= }
@@ -2235,19 +2058,16 @@
met= ric =3D r->metric;
}

- if (net_route_v4_del(ctx, &= ;r->network, netmask_to_netbits2(r->netmask),

- &r->gateway= , NULL, r->table_id, metric) < 0)
+ if (net_route_v4_del(ctx, &r->network, netma= sk_to_netbits2(r->netmask), &r->gateway, NULL,
+ r->table_i= d, metric)
+ &= lt; 0)
{
msg(M_WARN, "ER= ROR: Linux route delete command failed");
}
-#elif defined (_WIN32)
+#elif defined(_WIN32)

- ar= gv_printf(&argv, "%s%s DELETE %s MASK %s %s",
- get_win_sys_path(),
- WIN_ROU= TE_PATH_SUFFIX,
- = network,
- = netmask,
-= gateway);
+ argv_printf(&argv, "%s%s DELETE %s MASK %s %s", get= _win_sys_path(), WIN_ROUTE_PATH_SUFFIX,
+ network, netmask, gateway);
<= span>

argv_msg(D_ROUTE, &argv);
=
@@ -2275,7 +2095,8 @@
{ msg(D_ROUTE, "Route deletion fallback to route.exe= ");
netcmd_semaphore_lock();
- openvpn_execve_check(&= amp;argv, es, 0, "ERROR: Windows route delete command failed [adaptive= ]");

+ = openvpn_execve_check(&argv, es, 0,
+ "ERROR: Windows = route delete command failed [adaptive]");
= netcmd_semaphore_release();
}
= }
@@ -2284,35 +2105,23 @@
ASSERT= (0);
}

-#elif defined (TARGET_SOLARIS)
+#elif defined(TARGET_SOLARIS)
=
- argv_print= f(&argv, "%s delete %s -netmask %s %s",
- ROUTE_PATH,
- network,

- netmask,
- gateway);
+ argv_printf(&argv= , "%s delete %s -netmask %s %s", ROUTE_PATH, network, netmask, ga= teway);

argv_msg(D_ROUTE, &argv)= ;
openvpn_execve_check(&argv, es, 0, "ERROR: = Solaris route delete command failed");

#elif defined(TARGET_FREEBSD)


- argv_printf(&argv, "%s delete = -net %s %s %s",
- = ROUTE_PATH,
- network,
- gateway,
- netmask);
+ argv_printf(&argv, "%s delete -net %s %s %s&q= uot;, ROUTE_PATH, network, gateway, netmask);

<= span> argv_msg(D_ROUTE, &argv);

openvpn_execve= _check(&argv, es, 0, "ERROR: FreeBSD route delete command failed&q= uot;);

#elif defined(TARGET_DRAGONFLY)

- a= rgv_printf(&argv, "%s delete -net %s %s %s",
- ROUTE_PATH,
= - network,<= br>- gateway,
- netmask);<= /span>
+ argv_printf(&= ;argv, "%s delete -net %s %s %s", ROUTE_PATH, network, gateway, n= etmask);

argv_msg(D_ROUTE, &argv= );
openvpn_execve_check(&argv, es, 0, "ERROR:= DragonFly route delete command failed");
@@ -2321,19 = +2130,12 @@

if (is_on_link(is_local_= route, flags, rgi))
{
- argv_printf(&argv, "%s delete -clonin= g -net %s -netmask %s -interface %s",
- ROUTE_PATH,
- network,
- netmask,
<= br>- rgi->i= face);
+ argv_= printf(&argv, "%s delete -cloning -net %s -netmask %s -interface %= s", ROUTE_PATH,
= + network, netmask, rgi->iface);
= }
else
{
- argv_printf(&argv, "%s del= ete -net %s %s %s",
- network,
- gateway,
- netmask);
+ argv_printf(&argv, "%= s delete -net %s %s %s", ROUTE_PATH, network, gateway, netmask);
}

argv_msg(D_ROUTE, = &argv);
@@ -2341,26 +2143,20 @@

#elif defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)<= br>
- argv_pr= intf(&argv, "%s delete -net %s %s -netmask %s",
- ROUTE_PATH,
<= br>- network,
- gateway,
- netmask= );
+ argv_printf(&= amp;argv, "%s delete -net %s %s -netmask %s", ROUTE_PATH, network= , gateway, netmask);

argv_msg(D_ROUT= E, &argv);
openvpn_execve_check(&argv, es, 0, = "ERROR: OpenBSD/NetBSD route delete command failed");
<= span>

#elif defined(TARGET_ANDROID)
= msg(D_ROUTE_DEBUG, "Deleting routes on Android is not possible/not &qu= ot;
- "need= ed. The VpnService API allows routes to be set "
- "on connect only and will clea= n up automatically.");
+ "needed. The VpnService API allows rout= es to be set "
+= "on connect only and will clean up automaticall= y.");
#elif defined(TARGET_AIX)

{
int netbits =3D netmask_to_net= bits2(r->netmask);
-= argv_printf(&argv, "%s delete -net %s/%d %s",<= br>- ROUTE_PAT= H,
- = network, netbits, gateway);
+ argv_printf(&argv, "%s delete -net %s/%d %s"= , ROUTE_PATH, network, netbits, gateway);
argv_msg= (D_ROUTE, &argv);
openvpn_execve_check(&ar= gv, es, 0, "ERROR: AIX route delete command failed");
<= span> }

@@ -2368,17 +2164,14 @@
#elif = defined(TARGET_HAIKU)

/* ex: route d= elete /dev/net/ipro1000/0 inet 192.168.0.0 gw 192.168.1.1 netmask 255.255.0= .0 */
- argv_printf(= &argv, "%s delete %s inet %s gw %s netmask %s",
- ROUTE_PATH,
<= br>- rgi->iface= ,
- netw= ork,
- g= ateway,
- = netmask);
+ argv= _printf(&argv, "%s delete %s inet %s gw %s netmask %s", ROUTE= _PATH, rgi->iface, network,
+ gateway, netmask);
argv_msg= (D_ROUTE, &argv);
openvpn_execve_check(&argv, = es, 0, "ERROR: Haiku inet route delete command failed");
#else /* if defined(TARGET_LINUX) */
= - msg(M_FATAL, "Sorry, bu= t I don't know how to do 'route' commands on this operating sys= tem. Try putting your routes in a --route-up script");
+ msg(M_FATAL,

+ "Sorry, but I don't = know how to do 'route' commands on this operating system. Try putt= ing your routes in a --route-up script");
#endif /* i= f defined(TARGET_LINUX) */

done:<= br>@@ -2390,13 +2183,12 @@
}

void
-delet= e_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt,- const struct= env_set *es,
+delete= _route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, const str= uct env_set *es,
openvpn_net_ctx_t *ctx)=
{
const char *network;

- if ((r6->f= lags & (RT_DEFINED|RT_ADDED)) !=3D (RT_DEFINED|RT_ADDED))
+ if ((r6->flags & (RT_D= EFINED | RT_ADDED)) !=3D (RT_DEFINED | RT_ADDED))

{
return;
}
@@ -2= 408,7 +2200,7 @@
#if !defined(TARGET_SOLARIS)
bool gateway_needed =3D false;

const char *de= vice =3D tt->actual_name;
- if (r6->iface !=3D NULL) /* vpn server special r= oute */
+ if (r6-&= gt;iface !=3D NULL) /* vpn server special route */
{
device =3D r6->iface;
g= ateway_needed =3D true;
@@ -2417,8 +2209,7 @@
/* if we used a gateway on "add route", we also need to s= pecify it on

* delete, otherwise some OSes will refus= e to delete the route
*/
- if (tt->type =3D=3D DEV_TYPE_TAP
= - && !( (r6->fl= ags & RT_METRIC_DEFINED) && r6->metric =3D=3D 0 ) )+ if (tt->type =3D=3D D= EV_TYPE_TAP && !((r6->flags & RT_METRIC_DEFINED) && = r6->metric =3D=3D 0))
{
ga= teway_needed =3D true;
}
@@ -2428,13 += 2219,12 @@
struct gc_arena gc =3D gc_new();
= struct argv argv =3D argv_new();

- network =3D print_in6_addr( r6-= >network, 0, &gc);

+ network =3D print_in6_addr(r6->network, 0, &gc); #if !defined(TARGET_LINUX) && !defined(_WIN32)
- gateway =3D print_in6_addr( r6= ->gateway, 0, &gc);

+ gateway =3D print_in6_addr(r6->gateway, 0, &gc); #endif

-#if defined(TARGET_DARWIN) \
- || defined(TARGET_FREEBSD) || defined(TARGET_DRAG= ONFLY) \
+#if defi= ned(TARGET_DARWIN) || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) = \
|| defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)=

/* the BSD platforms cannot specify= gateway and interface independently,
@@ -2442,16 +2232,16 = @@
* we build a combined "$gateway%$interface&qu= ot; gateway string
*/
if (r6->= ;iface !=3D NULL && gateway_needed
- && IN6_IS_ADDR_LINKLOCAL(&r6->g= ateway) ) /* fe80::...%intf */
+ && IN6_IS_ADDR_LINKLOCAL(&r6->gate= way)) /* fe80::...%intf */
{
- int len =3D strlen(gateway) + 1 + strle= n(r6->iface)+1;
- = char *tmp =3D gc_malloc( len, true, &gc );
- snprintf( tmp, len, "%s%%%s&qu= ot;, gateway, r6->iface );
+ int len =3D strlen(gateway) + 1 + strlen(r6->iface) + = 1;
+ char *tmp= =3D gc_malloc(len, true, &gc);
+ snprintf(tmp, len, "%s%%%s", gateway, r6-= >iface);
gateway =3D tmp;
= }
#endif

- msg(D_ROUTE, "delete_route_ipv6(%s/%d)"= , network, r6->netbits );
+ msg(D_ROUTE, "delete_route_ipv6(%s/%d)", network, r6= ->netbits);

#if defined(TARGET_LINUX)=
int metric =3D -1;
@@ -2460,14 +2250,= 14 @@
metric =3D r6->metric;
= }

= - if (net_route_v6_del(ctx, &r6->network, r6->netbits,<= br>- gate= way_needed ? &r6->gateway : NULL, device, r6->table_id,- metric= ) < 0)
+ if (ne= t_route_v6_del(ctx, &r6->network, r6->netbits, gateway_needed ? &= amp;r6->gateway : NULL,
+ device, r6->table_id, metric)
= + < 0)
{

msg(M_WARN, "ERROR: Linux route v6 d= elete command failed");
}

-#elif defined (_WIN32)
+#elif defined(_WIN32)

if (tt->options.msg_channel)=
{
@@ -2477,25 +2267,18 @@
= {
route_ipv6_ipapi(false, r6, tt);
}

-#elif defin= ed (TARGET_SOLARIS)
+= #elif defined(TARGET_SOLARIS)

/* exa= mple: route delete -inet6 2001:db8::/32 somegateway */

- argv_printf(&arg= v, "%s delete -inet6 %s/%d %s",
- ROUTE_PATH,
- network,
- r6->netbits,
- gateway );
+ argv_printf(&argv, &q= uot;%s delete -inet6 %s/%d %s", ROUTE_PATH, network, r6->netbits, g= ateway);

argv_msg(D_ROUTE, &argv= );
openvpn_execve_check(&argv, es, 0, "ERROR:= Solaris route delete -inet6 command failed");

#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)

- argv= _printf(&argv, "%s delete -inet6 %s/%d",
- ROUTE_PATH,
- network,

<= span style=3D"color: hsl(0, 100%, 40%);">- r6->netbits );=

+ argv_printf(&am= p;argv, "%s delete -inet6 %s/%d", ROUTE_PATH, network, r6->net= bits);

if (gateway_needed) {
@@ -2511,9 +2294,7 @@

#elif defined(TARGET_DARWIN)

- argv_printf(&argv, "%s de= lete -inet6 %s -prefixlen %d",
- ROUTE_PATH,
- network, r6->netbits );
+ argv_printf(&argv, "= ;%s delete -inet6 %s -prefixlen %d", ROUTE_PATH, network, r6->netbi= ts);


if (gateway_needed)
<= span> {

@@ -2529,48 +2310,40 @@

#elif defined(TARGET_OPENBSD)

- argv_printf(&argv, "%s d= elete -inet6 %s -prefixlen %d %s",

- ROUTE_PATH,
- network, r6->netbits, gateway );=
+ argv_printf(&am= p;argv, "%s delete -inet6 %s -prefixlen %d %s", ROUTE_PATH, netwo= rk, r6->netbits,
+= gateway);

argv_msg(D= _ROUTE, &argv);
openvpn_execve_check(&argv, es= , 0, "ERROR: OpenBSD route delete -inet6 command failed");=

#elif defined(TARGET_NETBSD)
=
- argv_printf(&= argv, "%s delete -inet6 %s/%d %s",
- ROUTE_PATH,
- network, r6->netbits, gatew= ay );
+ argv_print= f(&argv, "%s delete -inet6 %s/%d %s", ROUTE_PATH, network, r6= ->netbits, gateway);

argv_msg(D_R= OUTE, &argv);
openvpn_execve_check(&argv, es, = 0, "ERROR: NetBSD route delete -inet6 command failed");
#elif defined(TARGET_AIX)

- argv_printf(&argv, = "%s delete -inet6 %s/%d %s",
- ROUTE_PATH,
- network, r6->netbits, gateway);
+ argv_printf(&= argv, "%s delete -inet6 %s/%d %s", ROUTE_PATH, network, r6->ne= tbits, gateway);
argv_msg(D_ROUTE, &argv);<= br> openvpn_execve_check(&argv, es, 0, "ERROR: AIX route= add command failed");

#elif define= d(TARGET_ANDROID)
msg(D_ROUTE_DEBUG, "Deleting ro= utes on Android is not possible/not "
- "needed. The VpnService API allows routes= to be set "
- = "on connect only and will clean up automatically.");+ "= ;needed. The VpnService API allows routes to be set "
+ "on conn= ect only and will clean up automatically.");
#elif de= fined(TARGET_HAIKU)

/* ex: route del= ete /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixlen 64 */
- argv_printf(&argv, "%= s delete %s inet6 %s gw %s prefixlen %d",

- ROUTE_PATH,
- r6->iface,
- network,

= - gateway,<= br>- r6->netbit= s);
+ argv_printf(= &argv, "%s delete %s inet6 %s gw %s prefixlen %d", ROUTE_PATH= , r6->iface, network,
+ gateway, r6->netbits);
argv_ms= g(D_ROUTE, &argv);
openvpn_execve_check(&argv,= es, 0, "ERROR: Haiku inet6 route delete command failed");=

#else /* if defined(TARGET_LINUX) */- msg(M_FATAL, "Sorry, = but I don't know how to do 'route ipv6' commands on this operat= ing system. Try putting your routes in a --route-down script");
+ msg(M_FATAL,+ "Sorry, but I d= on't know how to do 'route ipv6' commands on this operating sys= tem. Try putting your routes in a --route-down script");
#endif /* if defined(TARGET_LINUX) */


argv_free(&argv);

@@ -2596,13 +2369,12 @@=
status =3D GetIpForwardTable(NULL, &size, TRUE);<= br> if (status =3D=3D ERROR_INSUFFICIENT_BUFFER)
= {
- rt =3D = (PMIB_IPFORWARDTABLE) gc_malloc(size, false, gc);
+ rt =3D (PMIB_IPFORWARDTABLE)gc_malloc= (size, false, gc);
status =3D GetIpForwardTable(rt= , &size, TRUE);
if (status !=3D NO_ERROR)
{
msg(D_ROUTE, "NOTE= : GetIpForwardTable returned error: %s (code=3D%u)",
- strerror_win32(status, = gc),
- (= unsigned int)status);
+ strerror_win32(status, gc), (unsigned int)status);=
rt =3D NULL;
}
}

@@ -2610,9 +2382,7 @@
}<= br>
static int
-test_route(const IP_ADAPTER_INFO *adapters,
- const in_addr_t gateway,<= /span>
- DWORD *inde= x)
+test_route(const = IP_ADAPTER_INFO *adapters, const in_addr_t gateway, DWORD *index) {
int count =3D 0;
DWORD = i =3D adapter_index_of_ip(adapters, gateway, &count, NULL);
<= span>@@ -2624,11 +2394,7 @@

}

= static void
-tes= t_route_helper(bool *ret,
- int *count,
- int *good,
- int *ambig,
- const IP_ADAPTER_INFO *adapter= s,
+test_route_helper= (bool *ret, int *count, int *good, int *ambig, const IP_ADAPTER_INFO *adapt= ers,
const in_addr_t gateway)
= {
int c;
@@ -2688,13 +2454,8 @@=
}
}
=
- msg(D_ROUTE, "TEST = ROUTES: %d/%d succeeded len=3D%d ret=3D%d a=3D%d u/d=3D%s",
= - good,
- count,
- len,
- (int)ret,
- ambig,
- adapter_up ? "up" : "down");
= + msg(D_ROUTE, "TEST RO= UTES: %d/%d succeeded len=3D%d ret=3D%d a=3D%d u/d=3D%s", good, count,= len,
+ (int)r= et, ambig, adapter_up ? "up" : "down");

gc_free(&gc);
return ret;<= /span>
@@ -2718,12 +2479,9 @@
const D= WORD index =3D row->dwForwardIfIndex;
const= DWORD metric =3D row->dwForwardMetric1;

- dmsg(D_ROUTE_DEBUG, &qu= ot;GDGR: route[%lu] %s/%s i=3D%d m=3D%d",

- i,
- print_in_addr_t((in_addr_t) net, 0,= &gc),
- = print_in_addr_t((in_addr_t) mask, 0, &gc),
- (int)index,
- (int)metric);
+ dmsg(D_ROUTE_= DEBUG, "GDGR: route[%lu] %s/%s i=3D%d m=3D%d", i,
+ print_in_addr_t((i= n_addr_t)net, 0, &gc), print_in_addr_t((in_addr_t)mask, 0, &gc),
+ (int)= index, (int)metric);

if (!ne= t && !mask && metric < lowest_metric)
= {
@@ -2764,8 +2522,7 @@
if = (status !=3D NO_ERROR)
{
msg(= D_ROUTE, "NOTE: GetBestInterfaceEx returned error: %s (code=3D%u)"= ;,
- strerro= r_win32(status, gc),
- = (unsigned int)status);
+ strerror_win32(status, gc), (unsigned int)status)= ;
goto done;
}

@@ -2776,13 +2533,11 @@
CLEAR(luid= );
SOCKADDR_INET best_src;
CLEAR(= best_src);
- status = =3D GetBestRoute2(&luid, best_if_index, NULL,
- dest, 0, best_route,= &best_src);
+ = status =3D GetBestRoute2(&luid, best_if_index, NULL, dest, 0, best_rou= te, &best_src);
if (status !=3D NO_ERROR) {
msg(D_ROUTE, "NOTE: GetIpForwa= rdEntry2 returned error: %s (code=3D%u)",
- strerror_win32(status, gc),
= - (unsigned int)status= );
+ strer= ror_win32(status, gc), (unsigned int)status);
goto= done;
}

@@ -2873,13= +2628,10 @@
else if (count > 1)
= {
msg(M_WARN, "Warning: route gateway is a= mbiguous: %s (%d matches)",
- print_in_addr_t(r->gateway, 0, &gc),- count);
= + print_in_addr_t(r-= >gateway, 0, &gc), count);
}
<= /span>
- dmsg(D_ROUTE_DEBUG= , "DEBUG: route find if: on_tun=3D%d count=3D%d index=3D%d",
- on_tun,- count,
+ dmsg(D_ROUTE_DEBUG, "DEBUG= : route find if: on_tun=3D%d count=3D%d index=3D%d", on_tun, count,
(int)ret);

g= c_free(&gc);
@@ -2892,8 +2644,8 @@
* = https://msdn.microsoft.com/en-us/library/windows/desktop/aa814411(v=3Dvs.85= ).aspx
*/
void
-get_default_gateway_ipv6(struct route_ipv6_gate= way_info *rgi6,
- = const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
+get_default_gateway_ipv= 6(struct route_ipv6_gateway_info *rgi6, const struct in6_addr *dest,=
+ o= penvpn_net_ctx_t *ctx)
{
struct gc_ar= ena gc =3D gc_new();
CLEAR(*rgi6);
@@ = -2915,23 +2667,19 @@
goto done;
= }

= - msg( D_ROUTE, "GDG6: II=3D%lu DP=3D%s/%d NH=3D%s",- BestRoute.InterfaceInd= ex,
- print_in6= _addr( BestRoute.DestinationPrefix.Prefix.Ipv6.sin6_addr, 0, &gc),
- BestRoute.Destina= tionPrefix.PrefixLength,
- msg( D_ROUTE, &q= uot;GDG6: Metric=3D%d, Loopback=3D%d, AA=3D%d, I=3D%d",
- (int) BestRoute.Metric,
- (int) BestRoute.= Loopback,
- (in= t) BestRoute.AutoconfigureAddress,
- (int) BestRoute.Immortal );
+ msg(D_ROUTE, "GDG6: II=3D%lu DP=3D%s= /%d NH=3D%s", BestRoute.InterfaceIndex,
+ print_in6_addr(BestRoute.DestinationPrefix= .Prefix.Ipv6.sin6_addr, 0, &gc),
+ BestRoute.DestinationPrefix.PrefixLength,+ print_in6_addr(BestR= oute.NextHop.Ipv6.sin6_addr, 0, &gc));
+ msg(D_ROUTE, "GDG6: Metric=3D%d, Loopback= =3D%d, AA=3D%d, I=3D%d", (int)BestRoute.Metric,
+ (int)BestRoute.Loopback, (int)Bes= tRoute.AutoconfigureAddress, (int)BestRoute.Immortal);

rgi6->gateway.addr_ipv6 =3D BestRoute.NextHop.Ipv6.si= n6_addr;
- rgi6->= adapter_index =3D BestRoute.InterfaceIndex;
+ rgi6->adapter_index =3D BestRoute.Interf= aceIndex;
rgi6->flags |=3D RGI_ADDR_DEFINED | RGI_I= FACE_DEFINED;

/* on-link is signalle= d by receiving an empty (::) NextHop */
- if (IN6_IS_ADDR_UNSPECIFIED(&BestRoute.NextHop.Ip= v6.sin6_addr) )
+ = if (IN6_IS_ADDR_UNSPECIFIED(&BestRoute.NextHop.Ipv6.sin6_addr))<= br> {
rgi6->flags |=3D RGI_ON_LINK;
}
@@ -2947,7 +2695,9 @@
struct gc_arena gc =3D gc_new();

int ret =3D RTA= _ERROR;
DWORD status;
- const DWORD if_index =3D (adapter_index =3D=3D TUN= _ADAPTER_INDEX_INVALID) ? windows_route_find_if_index(r, tt) : adapter_inde= x;
+ const DWORD i= f_index =3D (adapter_index =3D=3D TUN_ADAPTER_INDEX_INVALID)
+ ? w= indows_route_find_if_index(r, tt)

+ : adapter_index;

if (if_index !=3D TUN_ADAPTER_INDEX_INVALID)
{
@@ -2958,7 +2708,7 @@
= fr.dwForwardPolicy =3D 0;
fr.dwForwardNextH= op =3D htonl(r->gateway);
fr.dwForwardIfIndex = =3D if_index;
- = fr.dwForwardType =3D 4; /* the next hop is not the final dest */
= + fr.dwForwardType =3D 4= ; /* the next hop is not the final dest */
fr.dwF= orwardProto =3D 3; /* PROTO_IP_NETMGMT */
fr.dwFor= wardAge =3D 0;
fr.dwForwardNextHopAS =3D 0;=
@@ -2971,8 +2721,7 @@
if ((r->network= & r->netmask) !=3D r->network)
{=
msg(M_WARN, "Warning: address %s is not a netwo= rk address in relation to netmask %s",
- print_in_addr_t(r->network, 0, &am= p;gc),
- = print_in_addr_t(r->netmask, 0, &gc));
+ print_in_addr_t(r->network, 0,= &gc), print_in_addr_t(r->netmask, 0, &gc));
= }

status =3D CreateIpForwa= rdEntry(&fr);
@@ -2988,20 +2737,22 @@
= else
{
/* fai= led, try increasing the metric to work around Vista issue */
- const unsigned int forwa= rd_metric_limit =3D 2048; /* iteratively retry higher metrics up to this li= mit */

+ c= onst unsigned int forward_metric_limit =3D
+ 2048; /* iteratively retry higher me= trics up to this limit */

fo= r (; fr.dwForwardMetric1 <=3D forward_metric_limit; ++fr.dwForwardMetric= 1)
{
- /* try a different forward type=3D3 ("the = next hop is the final dest") in addition to 4.
+ /* try a different forwar= d type=3D3 ("the next hop is the final dest") in addition<= br>+ * to 4.
* --redirect-gateway over RRAS seems to nee= d this. */
for (fr.dwForwardType =3D 4; fr= .dwForwardType >=3D 3; --fr.dwForwardType)
= {
status =3D CreateIpForwardEntry(= &fr);
if (status =3D=3D NO_ERROR)<= /span>
{
- msg(D_ROUTE, "ROUTE: CreateIp= ForwardEntry succeeded with dwForwardMetric1=3D%u and dwForwardType=3D%u&qu= ot;,
- = (unsigned int)fr.dwForwardMetric1,
- (unsigned int)fr.dwForw= ardType);
+ = msg(D_ROUTE,
+ "ROUTE: CreateIpForwardEntry succee= ded with dwForwardMetric1=3D%u and dwForwardType=3D%u",
+ (unsig= ned int)fr.dwForwardMetric1, (unsigned int)fr.dwForwardType);

ret =3D RTA_SUCCESS;

= goto doublebreak;
}
@@ -3021,9 +2772,10 @@
}
else
{=
- msg(M_WA= RN, "ERROR: route addition failed using CreateIpForwardEntry: "
- = "%s [status=3D%u if_index=3D%u]", strerror_win32(status, &gc= ),
- = (unsigned int)status, (unsigned int)if_index);
+ msg(M_WARN,+ "= ;ERROR: route addition failed using CreateIpForwardEntry: "
= + "= %s [status=3D%u if_index=3D%u]",
+ strerror_win32(status, &gc), = (unsigned int)status, (unsigned int)if_index);
= }
}
}
= @@ -3111,18 +2863,13 @@
return RTA_ERROR;
}

- route_message_t msg =3D {
- .header =3D {
- (add ? msg_add_route : msg_del_route),=
- sizeof(ro= ute_message_t),
- = 0
- },
- .family =3D AF_IN= ET,
- .prefix.ip= v4.s_addr =3D htonl(r->network),
- .gateway.ipv4.s_addr =3D htonl(r->gateway),=
- .iface =3D { .index = =3D if_index, .name =3D "" },
- .metric =3D (r->flags & RT_METRIC_DEFINED = ? r->metric : -1)
- = };
+ route_mess= age_t msg =3D { .header =3D { (add ? msg_add_route : msg_del_route),=
+ = sizeof(route_message_t), 0 },
+ .family =3D AF_INET,
+ = .prefix.ipv4.s_addr =3D htonl(r->network),
+ .gateway.ipv4= .s_addr =3D htonl(r->gateway),
+ .iface =3D { .index =3D if_index,= .name =3D "" },
+ .metric =3D (r->flags & RT_METRIC= _DEFINED ? r->metric : -1) };

net= mask_to_netbits(r->network, r->netmask, &msg.prefix_len);<= br> if (msg.prefix_len =3D=3D -1)
@@ -3152,7 +289= 9,7 @@
fwd_row->Metric =3D ((r->flags & RT_M= ETRIC_DEFINED) ? r->metric : -1);
fwd_row->Desti= nationPrefix.Prefix.si_family =3D AF_INET6;
fwd_row-&g= t;DestinationPrefix.Prefix.Ipv6.sin6_addr =3D r->network;
- fwd_row->DestinationPrefix.Pr= efixLength =3D (UINT8) r->netbits;

+ fwd_row->DestinationPrefix.PrefixLength =3D (UINT8= )r->netbits;
fwd_row->NextHop.si_family =3D AF_I= NET6;
fwd_row->NextHop.Ipv6.sin6_addr =3D r->gat= eway;
fwd_row->InterfaceIndex =3D r->adapter_ind= ex ? r->adapter_index : tt->adapter_index;
@@ -3217,2= 1 +2964,16 @@
do_route_ipv6_service(const bool add, const = struct route_ipv6 *r, const struct tuntap *tt)
{ int status;
- route_message_t msg =3D {
- .header =3D {
- (add ? msg_add_route : msg_del_route),
- sizeof(route_message_t),=

- 0<= br>- },
- .family =3D AF_INET6,
= - .prefix.ipv6 =3D r->n= etwork,
- .prefi= x_len =3D r->netbits,
- .iface =3D { .index =3D tt->adapter_index,= .name =3D "" },
- .metric =3D ( (r->flags & RT_METRIC_DEFINED) ? r->me= tric : -1)
- };
+ route_message_t msg = =3D { .header =3D { (add ? msg_add_route : msg_del_route),
+ = sizeof(route_message_t), 0 },
+ .family =3D AF_INET6,
<= span style=3D"color: hsl(120, 100%, 40%);">+ .pr= efix.ipv6 =3D r->network,

+ .prefix_len =3D r->netbits,<= br>+ = .gateway.ipv6 =3D r->gateway,
+ .iface =3D { .index =3D tt->ad= apter_index, .name =3D "" },
+ .metric =3D ((r->flags &a= mp; RT_METRIC_DEFINED) ? r->metric : -1) };

= - if (r->adapter_index) = /* vpn server special route */
+ if (r->adapter_index) /* vpn server special ro= ute */
{
msg.iface.index =3D = r->adapter_index;
}
@@ -3240,8 +298= 2,7 @@
* The tapdrvr knows about it and will answer n= eighbor discovery packets.
* (only do this for routes= actually using the tun/tap device)
*/
- if (tt->type =3D=3D DEV_TYPE_= TUN

- &&= msg.iface.index =3D=3D tt->adapter_index)
+ if (tt->type =3D=3D DEV_TYPE_TUN &&= ; msg.iface.index =3D=3D tt->adapter_index)
{

inet_pton(AF_INET6, "fe80::8", &msg.gatew= ay.ipv6);
}
@@ -3255,8 +2996,7 @@
status =3D do_route_service(add, &msg, sizeof(msg), tt= ->options.msg_channel);
if (status !=3D RTA_ERROR)<= /span>
{
= - msg(D_ROUTE, "IPv6 route %s via service %s",
<= span style=3D"color: hsl(0, 100%, 40%);">- add ? "addition&= quot; : "deletion",

+ msg(D_ROUTE, "IPv6 route %s via service %s", ad= d ? "addition" : "deletion",
= (status =3D=3D RTA_SUCCESS) ? "succeeded" : "failed becau= se route exists");
}
return = status;
@@ -3295,17 +3035,10 @@
buf_pr= intf(&out, "%s %s %s p=3D%d i=3D%d t=3D%d pr=3D%d a=3D%d h=3D%d m= =3D%d/%d/%d/%d/%d",
print_in_addr_t(r-= >dwForwardDest, IA_NET_ORDER, gc),
print= _in_addr_t(r->dwForwardMask, IA_NET_ORDER, gc),
- print_in_addr_t(r->dwForward= NextHop, IA_NET_ORDER, gc),
- (int)r->dwForwardPolicy,
- (int)r->dwForwardIfIndex,
- (int)r->= dwForwardType,
- = (int)r->dwForwardProto,
- (int)r->dwForwardAge,
- (int)r->dwForwardNextHopA= S,
- (int= )r->dwForwardMetric1,
- (int)r->dwForwardMetric3,=
- (int)r->dw= ForwardMetric4,
+ = print_in_addr_t(r->dwForwardNextHop, IA_NET_ORDER, gc), (int)= r->dwForwardPolicy,
+ (int)r->dwForwardAge, (int)r->dwForwardNextHopAS,= (int)r->dwForwardMetric1,
+ (int)r->dwForwardMetric2, (int)r->dwForwardM= etric3, (int)r->dwForwardMetric4,
(int)r= ->dwForwardMetric5);
return BSTR(&out);<= br> }
@@ -3354,12 +3087,11 @@
*= normally on Linux.
* It always fails and "ioctl= (SIOCGIFCONF) failed" confuses users
*/-
}
=
void
-get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6,
- c= onst struct in6_addr *dest, openvpn_net_ctx_t *ctx)
+get_default_gateway_ipv6(struct route_ipv= 6_gateway_info *rgi6, const struct in6_addr *dest,
+ openvpn_net_ctx_t *= ctx)
{
/* Same for ipv6 */
=
@@ -3423,7 +3155,7 @@
= if (ifr->ifr_addr.sa_family =3D=3D AF_INET)
= {
/* get interface addr */
- addr =3D ntohl(((str= uct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr);

<= span style=3D"color: hsl(120, 100%, 40%);">+ addr =3D ntohl(= ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr);
<= br>
/* get interface name */=
strncpynt(ifreq.ifr_name, ifr->ifr_name, size= of(ifreq.ifr_name));
@@ -3441,7 +3173,7 @@
= if (rgi->flags & RGI_ON_LINK)
= {
/* check that interface = name of current interface
- * matches interface name of best default route */
+ = * matches interface name of best default route */
= if (strcmp(ifreq.ifr_name, best_name))
= {
continue;@@ -3465,7 +3197,7 @@
{<= br> continue;
= }
- = netmask =3D ntohl(((struct sockaddr_in *) &ifreq.ifr_addr)->si= n_addr.s_addr);
+ = netmask =3D ntohl(((struct sockaddr_in *)&ifreq.ifr_add= r)->sin_addr.s_addr);

= /* check that interface matches default route */
= if (((rgi->gateway.addr ^ addr) & netmask) !=3D 0)
@@ -3510,22 +3242,22 @@
* netlink(3), netl= ink(7), rtnetlink(7)
* http://www.virtualbox.org/svn/vbox= /trunk/src/VBox/NetworkServices/NAT/rtmon_linux.c
*/
-struct rtreq {
<= span style=3D"color: hsl(120, 100%, 40%);">+struct rtreq

+{
struct nlmsghdr= nh;
struct rtmsg rtm;
char attrb= uf[512];
};

void=
-get_default_gateway_ipv6(str= uct route_ipv6_gateway_info *rgi6,
- const struct in6_addr *dest, openvpn_= net_ctx_t *ctx)
+get_= default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struct in6= _addr *dest,
+ = openvpn_net_ctx_t *ctx)
{
int flags;


CLEAR(*rgi6);

- if (= net_route_v6_best_gw(ctx, dest, &rgi6->gateway.addr_ipv6,
= - rgi= 6->iface) =3D=3D 0)
-#elif defined(TARGET_DARWIN) || defined(TARGET_SOLARIS) = \
- || defined(TARGE= T_FREEBSD) || defined(TARGET_DRAGONFLY) \
- || defined(TARGET_OPENBSD) || defined(TARGET_NET= BSD)
+#elif defined(T= ARGET_DARWIN) || defined(TARGET_SOLARIS) || defined(TARGET_FREEBSD) \
+ || defined(TARGET_DRA= GONFLY) || defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)

#include <sys/types.h>
#include= <sys/socket.h>
@@ -3563,7 +3294,8 @@
#include <ifaddrs.h>

#endif

-struct rtmsg {
<= span style=3D"color: hsl(120, 100%, 40%);">+struct rtmsg

+{
struct rt_msghd= r m_rtm;
char m_space[512];
};=
@@ -3585,26 +3317,30 @@
*/

#if defined(TARGET_DARWIN)
-#define ROUNDUP(a) \
- ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) - = 1))) : sizeof(uint32_t))
+#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(uint32_t) -= 1))) : sizeof(uint32_t))
#elif defined(TARGET_NETBSD)
#define ROUNDUP(a) RT_ROUNDUP(a)
#else
-#define ROUNDUP(a) \=
- ((a) > 0 ? (1 + (((a)= - 1) | (sizeof(long) - 1))) : sizeof(long))
+#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) |= (sizeof(long) - 1))) : sizeof(long))
#endif

#if defined(TARGET_SOLARIS)
-#define NEXTADDR(w, u) \
- if (rtm_addrs & (w)) { \
= - l =3D sizeof(u); memmove= (cp, &(u), l); cp +=3D ROUNDUP(l); \
+#define NEXTADDR(w, u) \
+ if (rtm_addrs & (w)) \
+ { = \
+ l =3D= sizeof(u); \
= + memmove(cp, &(u), l); \
+ cp +=3D ROUNDUP(l); \
}

#define ADVANCE(x, n) (x +=3D ROUNDUP(siz= eof(struct sockaddr_in)))
-#else /* if defined(TARGET_SOLARIS) */
-#define NEXTADDR(w, u) \
- if (rtm_addrs & (w)) { \
- l =3D ((struct sockaddr *)&= (u))->sa_len; memmove(cp, &(u), l); cp +=3D ROUNDUP(l); \
= +#else /* if defined(TARGET_SOL= ARIS) */
+#define NEX= TADDR(w, u) \
+ if (rtm_addrs & (w)) \
+ { = \
+ l =3D ((struct sockaddr *)&(u))->sa_len; \
+ memmove(cp, &(u), l)= ; \

= + cp +=3D ROUNDUP(l); \
}<= /span>

#define ADVANCE(x, n) (x +=3D ROUNDUP((n= )->sa_len))
@@ -3623,7 +3359,7 @@
s= truct sockaddr so_dst, so_mask;
char *cp =3D m_rtmsg.m= _space;
struct sockaddr *gate =3D NULL, *ifp =3D NULL,= *sa;
- struct rt_m= sghdr *rtm_aux;
+ = struct rt_msghdr *rtm_aux;

#define rtm m= _rtmsg.m_rtm

@@ -3633,7 +3369,7 @@=
pid =3D getpid();
seq =3D 0;
= #ifdef TARGET_OPENBSD
- rtm_addrs =3D RTA_DST | RTA_NETMASK; /* Kernel refuses = RTA_IFP */
+ rtm_a= ddrs =3D RTA_DST | RTA_NETMASK; /* Kernel refuses RTA_IFP */
#else

rtm_addrs =3D RTA_DST | RTA_NETMASK | RTA_IFP= ;
#endif
@@ -3674,7 +3410,7 @@
<= span> }

if (write(sockfd, (char *)&m_rtmsg, l)= < 0)
{
- msg(M_WARN|M_ERRNO, "GDG: problem writing to routing= socket");
+ = msg(M_WARN | M_ERRNO, "GDG: problem writing to routing socket"= ;);
goto done;
}
do

@@ -3724,7 +3460,7 @@
= if (ifp)
{
/* get int= erface name */
- = const struct sockaddr_dl *adl =3D (struct sockaddr_dl *) ifp;+ const struct soc= kaddr_dl *adl =3D (struct sockaddr_dl *)ifp;
i= f (adl->sdl_nlen && adl->sdl_nlen < sizeof(rgi->iface))=
{
memcpy(rgi= ->iface, adl->sdl_data, adl->sdl_nlen);
@@ -3792,1= 5 +3528,14 @@

if (getifaddrs(&am= p;ifap) !=3D 0)
{
- msg(M_WARN|M_ERRNO, "GDG: getifaddrs(= ) failed");
+ = msg(M_WARN | M_ERRNO, "GDG: getifaddrs() failed");
goto done;
}

for (ifa =3D ifap; ifa; ifa =3D ifa->ifa_n= ext)
{
- if (ifa->ifa_addr !=3D NULL
- && ifa->ifa_addr= ->sa_family =3D=3D AF_LINK
- && !strncmp(ifa->ifa_name, rgi->iface= , IFNAMSIZ) )
+ = if (ifa->ifa_addr !=3D NULL && ifa->ifa_addr->sa_fam= ily =3D=3D AF_LINK
+ = && !strncmp(ifa->ifa_name, rgi->iface, IFNAMSI= Z))
{
struct = sockaddr_dl *sdl =3D (struct sockaddr_dl *)ifa->ifa_addr;
memcpy(rgi->hwaddr, LLADDR(sdl), 6);

= @@ -3833,10 +3568,9 @@
#endif

= void
-get_defaul= t_gateway_ipv6(struct route_ipv6_gateway_info *rgi6,
- const struct in6_a= ddr *dest, openvpn_net_ctx_t *ctx)
+get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi= 6, const struct in6_addr *dest,
+ openvpn_net_ctx_t *ctx)
{

-
= struct rtmsg m_rtmsg;
int sockfd =3D -1; int seq, l, pid, rtm_addrs;
@@ -3852,7 +3586,7= @@
pid =3D getpid();
seq =3D 0;<= /span>
#ifdef TARGET_OPENBSD
- rtm_addrs =3D RTA_DST | RTA_NETMASK; /* Kerne= l refuses RTA_IFP */
= + rtm_addrs =3D RTA_DST | RTA_NETMASK; /* Kernel refuses RTA_IFP */
#else
rtm_addrs =3D RTA_DST | RTA_NETMASK= | RTA_IFP;
#endif
@@ -3873,8 +3607,8 @@
so_dst.sin6_family =3D AF_INET6;
s= o_mask.sin6_family =3D AF_INET6;

- if (dest !=3D NULL /* s= pecific host? */
- = && !IN6_IS_ADDR_UNSPECIFIED(dest) )
+ if (dest !=3D NULL /* specific host? */
+ && !IN6_= IS_ADDR_UNSPECIFIED(dest))
{
= so_dst.sin6_addr =3D *dest;
/* :: needs /0 "n= etmask", host route wants "no netmask */
@@ -3902= ,15 +3636,14 @@
}
if (write(sockf= d, (char *)&m_rtmsg, l) < 0)
{
- msg(M_WARN|M_ERRNO, "GDG6= : problem writing to routing socket");
+ msg(M_WARN | M_ERRNO, "GDG6: problem w= riting to routing socket");
goto done;=
}

do
= {
l =3D read(sockfd, (char *)&m_rtmsg, si= zeof(m_rtmsg));
- }<= /span>
- while (l > 0 &a= mp;& (rtm.rtm_seq !=3D seq || rtm.rtm_pid !=3D pid));
+ } while (l > 0 && (rtm= .rtm_seq !=3D seq || rtm.rtm_pid !=3D pid));

close(sockfd);

sockfd =3D -1;
@@ -3953,14 +3686,12 @@

* (KAME encodes the 16 b= it scope_id in s6_addr[2] + [3],
* but for a corr= ect link-local address these must be :0000: )
*/<= /span>
- if (gate->s= a_len =3D=3D sizeof(struct sockaddr_in6)
- && IN6_IS_ADDR_LINKLOCAL(&gw) )<= /span>
+ if (gate->= ;sa_len =3D=3D sizeof(struct sockaddr_in6) && IN6_IS_ADDR_LINKLOCAL= (&gw))
{
gw.s6_ad= dr[2] =3D gw.s6_addr[3] =3D 0;
}
=
- if (gate->= sa_len !=3D sizeof(struct sockaddr_in6)
- || IN6_IS_ADDR_UNSPECIFIED(&gw) )<= br>+ if (gate->sa_len= !=3D sizeof(struct sockaddr_in6) || IN6_IS_ADDR_UNSPECIFIED(&gw))
{
rgi6->flags |=3D RGI= _ON_LINK;
}
@@ -3974,7 +3705,7 @@<= /span>
if (ifp)
{
/* get interface name */

- const struct sockaddr_dl *adl =3D (struct soc= kaddr_dl *) ifp;
+ = const struct sockaddr_dl *adl =3D (struct sockaddr_dl *)ifp;
if (adl->sdl_nlen && adl->sdl_nlen &l= t; sizeof(rgi6->iface))
{
= memcpy(rgi6->iface, adl->sdl_data, adl->sdl_nlen);=
@@ -4058,15 +3789,15 @@
addre= ss_size +=3D route.gateway->sa_len;
}
- inter= face =3D (struct ifreq *)((addr_t)interface + IF_NAMESIZE
- + = sizeof(struct route_entry) + address_size);
+ interface =3D (struct ifreq *)((addr_t)inte= rface + IF_NAMESIZE + sizeof(struct route_entry)
+ + address= _size);
}
free(buffer); }

void
-get_default_gateway_ipv6(struct route_ipv6_gate= way_info *rgi6,
- = const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
+get_default_gateway_ipv= 6(struct route_ipv6_gateway_info *rgi6, const struct in6_addr *dest,=
+ o= penvpn_net_ctx_t *ctx)
{
/* TODO: Sam= e for ipv6 with AF_INET6 */
CLEAR(*rgi6);
@@ -4104,8 +3835,8 @@

CLEAR(*rgi);
}

void
-get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6,- const= struct in6_addr *dest, openvpn_net_ctx_t *ctx)
+get_default_gateway_ipv6(struct route_ipv6_gate= way_info *rgi6, const struct in6_addr *dest,
+ openvpn_net_ctx_t *ctx)
{
msg(D_ROUTE, "no support for ge= t_default_gateway_ipv6() on this system");
CLEAR(= *rgi6);
@@ -4185,7 +3916,8 @@
while (i= plist)
{
bool succeed =3D fal= se;
- const in_a= ddr_t ip =3D getaddr(GETADDR_HOST_ORDER, iplist->IpAddress.String, 0, &a= mp;succeed, NULL);
+ = const in_addr_t ip =3D
+ getaddr(GETADDR_HOST_ORDER, iplist->IpAddress.Stri= ng, 0, &succeed, NULL);
if (succeed) {
add_host_route_if_nonlocal(r= b, ip);
@@ -4233,7 +3965,7 @@
#else /* if= defined(_WIN32) */

static void-get_bypass_addresses(struct ro= ute_bypass *rb, const unsigned int flags) /* PLATFORM-SPECIFIC */<= br>+get_bypass_addresses(struct= route_bypass *rb, const unsigned int flags) /* PLATFORM-SPECIFIC */=
{
}

@@ -4254,= 7 +3986,8 @@
test_local_addr(const in_addr_t addr, const s= truct route_gateway_info *rgi)
{
stru= ct gc_arena gc =3D gc_new();
- const in_addr_t nonlocal_netmask =3D 0x80000000L; /* routes with= netmask <=3D to this are considered non-local */
+ const in_addr_t nonlocal_netmask =3D<= /span>
+ 0x80000000L;= /* routes with netmask <=3D to this are considered non-local */<= br> int ret =3D TLA_NONLOCAL;

= /* get full routing table */
@@ -4281,7 +4014,7 @@
#else /* if defined(_WIN32) */

int

-test_local_ad= dr(const in_addr_t addr, const struct route_gateway_info *rgi) /* PLATFORM= -SPECIFIC */
+test_lo= cal_addr(const in_addr_t addr, const struct route_gateway_info *rgi) /* PLA= TFORM-SPECIFIC */
{
if (rgi) {
diff --git a/src/openvpn/route.h b/src/openv= pn/route.h
index 237375c..a3aadb7 100644
--= - a/src/openvpn/route.h
+++ b/src/openvpn/route.h@@ -37,18 +37,18 @@
/*
* Windows = route methods
*/
-#define ROUTE_METHOD_ADAPTIVE 0 /* try IP helper first then = route.exe */
-#define R= OUTE_METHOD_IPAPI 1 /* use IP helper API */
-#define ROUTE_METHOD_EXE 2 /* use route.e= xe */
-#define ROUTE_ME= THOD_SERVICE 3 /* use the privileged Windows service */
-#define ROUTE_METHOD_MASK 3
+#define ROUTE_METHOD_ADAP= TIVE 0 /* try IP helper first then route.exe */
+#define ROUTE_METHOD_IPAPI 1 /* use IP helpe= r API */
+#define ROU= TE_METHOD_EXE 2 /* use route.exe */
+#define ROUTE_METHOD_SERVICE 3 /* use the privileged = Windows service */
+#= define ROUTE_METHOD_MASK 3
#endif

/*
* Route add/delete flags (must stay cle= ar of ROUTE_METHOD bits)
*/
-#define ROUTE_DELETE_FIRST (1<<2)
= -#define ROUTE_REF_GW (1&l= t;<3)
+#define ROU= TE_DELETE_FIRST (1 << 2)
+#define ROUTE_REF_GW (1 << 3)

struct route_bypass
{
@@ -60,= 9 +60,9 @@
struct route_special_addr
{
/* bits indicating which members below are defined */
-#define RTSA_REMOTE_ENDP= OINT (1<<0)
-#de= fine RTSA_REMOTE_HOST (1<<1)
-#define RTSA_DEFAULT_METRIC (1<<2)
+#define RTSA_REMOTE_ENDPOINT (1 &l= t;< 0)

+#define RT= SA_REMOTE_HOST (1 << 1)
+#define RTSA_DEFAULT_METRIC (1 << 2)
= unsigned int flags;

in_addr_t re= mote_endpoint;
@@ -73,7 +73,8 @@
int d= efault_metric;
};

-struct route_option {
+struct route_option
+{
struct route_optio= n *next;
const char *network;
con= st char *netmask;
@@ -83,39 +84,43 @@
};

/* redirect-gateway flags */
-#define RG_ENABLE (1<&l= t;0)

-#define RG_LOCAL = (1<<1)
-= #define RG_DEF1 (1<<2)
-#define RG_BYPASS_DHCP (1<<3)
-#define RG_BYPASS_DNS (1<<4)
-#define RG_REROUTE_GW = (1<<5)
-#define= RG_AUTO_LOCAL (1<<6)
-#define RG_BLOCK_LOCAL (1<<7)
+#define RG_ENABLE (1 << 0)+#define RG_LOCAL (1 &l= t;< 1)
+#define RG= _DEF1 (1 << 2)
+#define RG_BYPASS_DHCP (1 << 3)
+#define RG_BYPASS_DNS (1 << 4)
<= span style=3D"color: hsl(120, 100%, 40%);">+#define RG_REROUTE_GW (1 <&= lt; 5)

+#define RG_AU= TO_LOCAL (1 << 6)
+#define RG_BLOCK_LOCAL (1 << 7)

-struct route_option_list {
+struct route_option_list
+{
u= nsigned int flags; /* RG_x flags */
struct route_optio= n *routes;
struct gc_arena *gc;
};

-struct= route_ipv6_option {
= +struct route_ipv6_option
+{
struct route_ipv6_option *next;
- const char *prefix; /* e= .g. "2001:db8:1::/64" */

- const char *gateway; /* e.g. "2001:db8:0::2&qu= ot; */
- const char = *metric; /* e.g. "5" */
+ const char *prefix; /* e.g. "2001:db8:1::/6= 4" */
+ const= char *gateway; /* e.g. "2001:db8:0::2" */
+ const char *metric; /* e.g. "5&= quot; */
int table_id;
};
<= span>

-struct route_ip= v6_option_list {
- u= nsigned int flags; /* RG_x flags, see route_option-list */+struct route_ipv6_option_lis= t
+{
+ unsigned int flags; /* RG_x flag= s, see route_option-list */
struct route_ipv6_option *= routes_ipv6;
struct gc_arena *gc;
};<= /span>

-stru= ct route_ipv4 {
-#defin= e RT_DEFINED (1<<0)
-#define RT_ADDED (1<<1)
-#define RT_METRIC_DEFINED (1<<2)+struct route_ipv4
= +{
+#define RT_DEFINED (1 << 0)<= br>+#define RT_ADDED (= 1 << 1)
+#defin= e RT_METRIC_DEFINED (1 << 2)
struct route_ipv4 *= next;
unsigned int flags;
const s= truct route_option *option;
@@ -126,9 +131,10 @@
= int metric;
};

-struct route_ipv6 {

+struct route_ipv6
+{
struct route_ip= v6 *next;
- unsigned= int flags; /* RT_ flags, see route_ipv4 */<= br>+ unsigned int flags; /* = RT_ flags, see route_ipv4 */
struct in6_addr network;<= /span>
unsigned int netbits;
struct in6_= addr gateway;
@@ -136,25 +142,27 @@
in= t table_id;
/* gateway interface */
#= ifdef _WIN32
- DWORD= adapter_index; /* interface or ~0 if undefined */
+ DWORD adapter_index; /* interface= or ~0 if undefined */
#else
- char *iface; /* interface name (= null terminated) */
+= char *iface; /* interface name (null terminated) */
#e= ndif
};


-struct route_gateway_address {
+struct route_gateway_addr= ess
+{
in_addr_t addr;

in_addr_t netmask;
};


-struct route_gateway_info {
-#define RGI_ADDR_DEFINED (1<<0) /* set if gateway.addr= defined */
-#define RG= I_NETMASK_DEFINED (1<<1) /* set if gateway.netmask defined */
-#define RGI_HWADDR_DEFINED = (1<<2) /* set if hwaddr is defined */
-#define RGI_IFACE_DEFINED (1<<3) /* set = if iface is defined */
= -#define RGI_OVERFLOW (1<<4) /* set if more interface addres= ses than will fit in addrs */
-#define RGI_ON_LINK (1<<5)
+struct route_gateway_info
+{
+#define RGI_ADDR_DEFINED (1 << 0) /* set if gate= way.addr defined */
+= #define RGI_NETMASK_DEFINED (1 << 1) /* set if gateway.netmask define= d */
+#define RGI_HWA= DDR_DEFINED (1 << 2) /* set if hwaddr is defined */
+#define RGI_IFACE_DEFINED (1 <&= lt; 3) /* set if iface is defined */
+#define RGI_OVERFLOW (1 << 4) /* set if more = interface addresses than will fit in addrs */
+#define RGI_ON_LINK (1 << 5)=
unsigned int flags;

/= * gateway interface */
@@ -174,17 +182,19 @@

/* address/netmask pairs bound to interface */
#define RGI_N_ADDRESSES 8
- int n_addrs; /* len of addrs, may be 0 */
<= span style=3D"color: hsl(120, 100%, 40%);">+ int n_addrs; = /* len of addrs, may be 0 */

= struct route_gateway_address addrs[RGI_N_ADDRESSES]; /* local addresses at= tached to iface */
};

-struct route_ipv6_gateway_address {
+struct route_ipv6_gatewa= y_address
+{ struct in6_addr addr_ipv6;
int netbits_ip= v6;
};

-struct route_ipv6_gateway_info {
-/* RGI_ flags used as in route_gateway_info= */
+struct route_ipv= 6_gateway_info
+{
+ /* RGI_ flags used = as in route_gateway_info */
unsigned int flags;=

/* gateway interface */
@@= -211,45 +221,50 @@

/* address/netma= sk pairs bound to interface */
#define RGI_N_ADDRESSES 8
- int n_addrs; /* len= of addrs, may be 0 */
= - struct route_ipv6_gateway_address addrs[RGI_N_ADDRESSES]; /* local add= resses attached to iface */
+ int n_addrs; /* len of addrs, may be 0 */=
+ struct route_ipv6_gate= way_address
+ = addrs[RGI_N_ADDRESSES]; /* local addresses attached to iface */
<= span> };


-struct route_list {
-#define RL_DID_LOCAL (= 1<<1)
-#define RL= _ROUTES_ADDED (1<<2)
+struct route_list
+{
+#define RL_DID_LOCAL = (1 << 1)
+#d= efine RL_ROUTES_ADDED (1 << 2)
u= nsigned int iflags;

struct route_spe= cial_addr spec;
struct route_gateway_info rgi;<= br>- unsigned int flags; /* = RG_x flags */
+ un= signed int flags; /* RG_x flags */
struct route_ipv4 *= routes;
struct gc_arena gc;
};=

-struct rou= te_ipv6_list {
- uns= igned int iflags; /* RL_ flags, see route_list */
= +struct route_ipv6_list<= br>+{
+ unsigned int iflags; /* = RL_ flags, see route_list */

- unsigned int spec_flags; /* RTSA_ f= lags, route_special_addr */
+ unsigned int spec_flags; /* RTSA_ flags, route_spe= cial_addr */
struct in6_addr remote_endpoint_ipv6; /* = inside tun */
- stru= ct in6_addr remote_host_ipv6; /* --remote address */
+ struct in6_addr remote_host_ipv6; = /* --remote address */
int default_metric;
struct route_ipv6_gateway_info rgi6;- unsigned int flags; = /* RG_x flags, see route_option_list */
+ unsigned int flags; /* RG_x flags, see ro= ute_option_list */
struct route_ipv6 *routes_ipv6;
struct gc_arena gc;
};
=
/* internal OpenVPN route */
-struct iroute {
+struct iroute
+{
in_addr_t network;
= int netbits;
struct iroute *next;
= };

-s= truct iroute_ipv6 {
+= struct iroute_ipv6
+{=
struct in6_addr network;
unsigne= d int netbits;
struct iroute_ipv6 *next;
@@ -271,69 +286,52 @@


struct route_ip= v6_option_list *new_route_ipv6_option_list(struct gc_arena *a);
<= span>

-struct route_op= tion_list *clone_route_option_list(const struct route_option_list *src, str= uct gc_arena *a);
+st= ruct route_option_list *clone_route_option_list(const struct route_option_l= ist *src,
+ = struct gc_arena *a);

-struct route_ipv6_= option_list *clone_route_ipv6_option_list(const struct route_ipv6_option_li= st *src, struct gc_arena *a);
+struct route_ipv6_option_list *clone_route_ipv6_option_list(
+ const struct route_i= pv6_option_list *src, struct gc_arena *a);

-void copy_route_option_list(struct r= oute_option_list *dest, const struct route_option_list *src, struct gc_aren= a *a);

+void copy_rou= te_option_list(struct route_option_list *dest, const struct route_option_li= st *src,
+ = struct gc_arena *a);

vo= id copy_route_ipv6_option_list(struct route_ipv6_option_list *dest,<= br>- = const struct route_ipv6_option_list *src,
- struct gc_arena *a= );
+ = const struct route_ipv6_option_list *src, struct gc_arena *= a);

-= void route_ipv6_clear_host_bits( struct route_ipv6 *r6 );
+void route_ipv6_clear_host_bits(struc= t route_ipv6 *r6);

-bool add_route_ipv6(struct route_ipv6 *r, const struct tunta= p *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx= );
+bool add_route_ip= v6(struct route_ipv6 *r, const struct tuntap *tt, unsigned int flags,
+ const= struct env_set *es, openvpn_net_ctx_t *ctx);

<= span style=3D"color: hsl(0, 100%, 40%);">-void delete_route_ipv6(const stru= ct route_ipv6 *r, const struct tuntap *tt, const struct env_set *es, openvp= n_net_ctx_t *ctx);

+v= oid delete_route_ipv6(const struct route_ipv6 *r, const struct tuntap *tt,<= /span>
+ = const struct env_set *es, openvpn_net_ctx_t *ctx);

bool add_route(struct route_ipv4 *r, const struct tuntap *tt,= unsigned int flags,
const struct route_gat= eway_info *rgi, const struct env_set *es,
o= penvpn_net_ctx_t *ctx);

-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);+void add_route_to_option_lis= t(struct route_option_list *l, const char *network, const char *netmask,
+ = const char *gateway, const char *metric, int table_id);
<= span>

-void add_route_= ipv6_to_option_list(struct route_ipv6_option_list *l,
- const ch= ar *prefix,
- = const char *gateway,
- const char *metr= ic,
- = int table_id);
+void add_route_ipv6_to_option_list(struct route_ipv6_option_lis= t *l, const char *prefix,
+ const char *gateway, const char *m= etric, int table_id);

-bool init_route_list(struct route_list *rl,
- const struct r= oute_option_list *opt,

= - const char *remote_endpoint,
- int default_metric,
- in_add= r_t remote_host,
- = struct env_set *es,
- openvpn_net_ctx_t *ctx);
+bool init_route_list(struct route_l= ist *rl, const struct route_option_list *opt,

+ const char *remote_endpoint,= int default_metric, in_addr_t remote_host,
+ struct env_set *es, openvpn_ne= t_ctx_t *ctx);

-bool init_route_ipv6_list(struct route_ipv6_list *rl6,- const= struct route_ipv6_option_list *opt6,
- const char *remote_endpoint,
- = int default_metric,
- = const struct in6_addr *remote_host,
- struct env_= set *es,

+bool init_r= oute_ipv6_list(struct route_ipv6_list *rl6, const struct route_ipv6_option_= list *opt6,
+ = const char *remote_endpoint, int default_metric,+ co= nst struct in6_addr *remote_host, struct env_set *es,
= openvpn_net_ctx_t *ctx);

= -void route_list_add_vpn_gateway(= struct route_list *rl,
= - struct env_set *es,
- const in_ad= dr_t addr);
+void rou= te_list_add_vpn_gateway(struct route_list *rl, struct env_set *es, const in= _addr_t addr);

-bool add_routes(struct route_list *rl, struct route_ipv6_list *r= l6,
- co= nst struct tuntap *tt, unsigned int flags,
- const struct env_set *es, openvpn_net_= ctx_t *ctx);
+bool ad= d_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struct t= untap *tt,
+ = unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx= );

-v= oid delete_routes(struct route_list *rl,
- struct route_ipv6_list *rl6,- const struc= t tuntap *tt,
- = unsigned int flags,
- const struct env_set *es,
- openvpn_net_ctx_t *ctx);=
+void delete_routes(= struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt= ,
+ = unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx);

void setenv_routes(struct env_set *es, cons= t struct route_list *rl);

@@ -348,16 +346= ,12 @@
* @param dest Destination IP address in host byte = order.
* @param ctx Pointer to a platform-specific netwo= rk context struct.
*/
-void get_default_gateway(struct route_gateway_info *rgi,<= /span>
- = in_addr_t dest,
- = openvpn_net_ctx_t *ctx);
+void get_default_gateway(struct route_gateway_in= fo *rgi, in_addr_t dest, openvpn_net_ctx_t *ctx);
<= br>-void get_default_gateway_ipv6= (struct route_ipv6_gateway_info *rgi,
- const struct in6_addr *dest,<= /span>
+void get_default_gat= eway_ipv6(struct route_ipv6_gateway_info *rgi, const struct in6_addr *dest,=
openvpn_net_ctx_t *ctx);

-void p= rint_default_gateway(const int msglevel,
- const struct route_gateway_in= fo *rgi,
+void print_= default_gateway(const int msglevel, const struct route_gateway_info *rgi,
const struct route_ipv6_gateway_= info *rgi6);

/*
@@ -372,= 8 +366,7 @@
int test_local_addr(const in_addr_t addr, cons= t struct route_gateway_info *rgi);

#ifnd= ef ENABLE_SMALL
-void p= rint_route_options(const struct route_option_list *rol,
- int level);
+void print_route_options= (const struct route_option_list *rol, int level);
<= br> #endif

@@ -385,7 +378,7 @@

bool test_routes(const struct route_list *rl= , const struct tuntap *tt);

-#else /* ifdef _WIN32 */
+#else /* ifdef _WIN32 */
sta= tic inline bool
test_routes(const struct route_list *rl, c= onst struct tuntap *tt)
{
@@ -404,7 +397,7= @@
in_addr_t mask =3D 0;
if (net= bits > 0 && netbits <=3D addrlen)
{
- mask =3D IPV4_NETM= ASK_HOST << (addrlen-netbits);
+ mask =3D IPV4_NETMASK_HOST << (addrlen - net= bits);
}
return mask;
<= span> }

diff --git a/src/openvpn/run_command.c b/src/openvp= n/run_command.c
index 8b5fa4f..5fefb55 100644
--- a/src/openvpn/run_command.c

+++ b/src/openvpn/run_co= mmand.c
@@ -68,7 +68,7 @@
#ifdef _WIN32
case OPENVPN_EXECVE_ERROR:
= buf_printf(&out, "external program did not execute -- ");=
- /* fall throu= gh */
+ /*= fall through */

default:=
buf_printf(&out, "returned error code %d&qu= ot;, stat);
@@ -127,20 +127,16 @@
<= br> if (exitcode =3D=3D OPENVPN_EXECVE_FAILURE)
{

- = msg(msglevel, "%scould not execute external program (exit code 127= )",
- = msg_prefix);
+ = msg(msglevel, "%scould not execute external program (exit code= 127)", msg_prefix);
}
= else
{
- msg(msglevel, "%sexternal program exited with= error status: %d",
+ msg(msglevel, "%sexternal program ex= ited with error status: %d", msg_prefix, exitcode);
= }
-
}

else if (WIFSIGNALED(status))
{

- msg(= msglevel, "%sexternal program received signal %d",
- msg_prefix, WTERMSIG(sta= tus));

+ msg(m= sglevel, "%sexternal program received signal %d", msg_prefix, WTE= RMSIG(status));
}

= return false;
@@ -235,7 +231,8 @@
* Wr= apper around openvpn_execve
*/
int
-openvpn_execve_check(const = struct argv *a, const struct env_set *es, const unsigned int flags, const c= har *error_message)
+= openvpn_execve_check(const struct argv *a, const struct env_set *es, const = unsigned int flags,
+= const char *error_message)
{ struct gc_arena gc =3D gc_new();
const in= t stat =3D openvpn_execve(a, es, flags);
@@ -261,8 +258,7 @= @
}
if (error_message)
= {
- m= sg(((flags & S_FATAL) ? M_FATAL : M_WARN), "%s: %s",- error_message,
+ msg(((flags &am= p; S_FATAL) ? M_FATAL : M_WARN), "%s: %s", error_message,<= br> system_error_message(stat, &gc));
}

done:
@@ -277,7 +273,7 @@ * associated with formatting and parsing a command line. */
int
-openvpn_popen(const struct argv *a, const struct env_set *es)<= /span>
+openvpn_popen(const = struct argv *a, const struct env_set *es)
{
struct gc_arena gc =3D gc_new();

int ret =3D -1= ;
@@ -299,20 +295,20 @@
pi= d =3D fork();
if (pid =3D=3D (pid_t)0) = /* child side */
{
- close(pipe_stdout[0]);= /* Close read end */
+ close(pipe_stdout[0]); /* Close read end */
dup2(pipe_stdout[1], 1);
execve(cmd, argv, envp);

= exit(OPENVPN_EXECVE_FAILURE);
}<= /span>
- else i= f (pid > (pid_t)0) /* parent side */
+ else if (pid > (pid_t)0) /* pa= rent side */
{
= int status =3D 0;

- close(pipe_stdout[1]); /= * Close write end */
= + close(pipe_stdout[1]); /* Close write end */ waitpid(pid, &status, 0);
= ret =3D pipe_stdout[0];
= }
- el= se /* fork failed */
+ else /* fork failed */
= {
close(pipe_stdout[0]); close(pipe_stdout[1]);
diff --g= it a/src/openvpn/run_command.h b/src/openvpn/run_command.h
= index e9a6fe1..d398341 100644
--- a/src/openvpn/run_command= .h
+++ b/src/openvpn/run_command.h
@@ -28,3= 6 +28,38 @@
#include "env_set.h"

/* Script security */
-#define SSEC_NONE 0 /* strictly no calling of exte= rnal programs */
-#defi= ne SSEC_BUILT_IN 1 /* only call built-in programs such as ifconfig, route,= netsh, etc.*/
-#define= SSEC_SCRIPTS 2 /* allow calling of built-in programs and user-defined sc= ripts */
-#define SSEC_= PW_ENV 3 /* allow calling of built-in programs and user-defined scripts = that may receive a password as an environmental variable */
+#define SSEC_NONE 0 /* strictly= no calling of external programs */

+#define SSEC_BUILT_IN 1 /* only call built-in programs such= as ifconfig, route, netsh, etc.*/
+#define SSEC_SCRIPTS 2 /* allow calling of built-in program= s and user-defined scripts */
+#define SSEC_PW_ENV = \
+ 3 /* allow calling of built-in programs and user-defined = scripts that may receive a password \
+ as an environmental variable */
=
-#define OPENVPN_EXEC= VE_ERROR -1 /* generic error while forking to run an external program= */
-#define OPENVPN_EX= ECVE_NOT_ALLOWED -2 /* external program not run due to script security */
-#define OPENVPN_EXECVE_= FAILURE 127 /* exit code passed back from child when execve fails */
+#define OPENVPN_EXECVE_= ERROR -1 /* generic error while forking to run an external program *= /
+#define OPENVPN_EX= ECVE_NOT_ALLOWED -2 /* external program not run due to script security */<= /span>
+#define OPENVPN_EXEC= VE_FAILURE 127 /* exit code passed back from child when execve fails */=

int script_security(void);

void script_security_set(int level);

/* openvpn_execve flags */
-#define S_SCRIPT (1<<0)
-#define S_FATAL (1<<1)=
+#define S_SCRIPT (1 <= ;< 0)
+#define S_F= ATAL (1 << 1)
/** Instead of returning 1/0 for s= uccess/fail,
* return exit code when between 0 and 255 an= d -1 otherwise */
-#def= ine S_EXITCODE (1<<2)
+#define S_EXITCODE (1 << 2)
/** instead of= waiting for child process to exit and report the status,
= * return the pid of the child process */
-#define S_NOWAITPID (1<<3)
+#define S_NOWAITPID (1 << 3)=

/* wrapper around the execve() call */<= br>-int openvpn_popen(const struc= t argv *a, const struct env_set *es);
+int openvpn_popen(const struct argv *a, const struct env= _set *es);

bool openvpn_execve_allowed(c= onst unsigned int flags);

-int openvpn_execve_check(const struct argv *a, const = struct env_set *es,
- = const unsigned int flags, const char *error_message)= ;
+int openvpn_execve= _check(const struct argv *a, const struct env_set *es, const unsigned int f= lags,
+ = const char *error_message);

<= /span>
#ifndef WIN32
@@ -73,9 +75,7 @@
= * @return true if the process is still running, fa= lse if
* an error condition occu= rred
*/
-bool
-openvpn_waitp= id_check(pid_t pid, const char *msg_prefix,
- int msglevel);
+bool openvpn_waitpid_check(pid_t pid= , const char *msg_prefix, int msglevel);

= #endif

@@ -84,13 +84,12 @@
* 0 and 255, -1 otherwise

*/
static= inline int
-openvpn_ru= n_script(const struct argv *a, const struct env_set *es,
- const unsigned int fl= ags, const char *hook)
= + const char *hook)
{
= char msg[256];

- snprintf(msg, sizeof(msg),
- "WARNING: Failed running command (= %s)", hook);
+ = snprintf(msg, sizeof(msg), "WARNING: Failed running command (%s)&quo= t;, hook);
return openvpn_execve_check(a, es, flags | = S_SCRIPT, msg);
}

diff -= -git a/src/openvpn/schedule.c b/src/openvpn/schedule.c
inde= x aaa9885..0fa5838 100644
--- a/src/openvpn/schedule.c
+++ b/src/openvpn/schedule.c
@@ -55,15 +55,12 @= @
struct gc_arena gc =3D gc_new();
= if (e)
{
- dmsg(D_SCHEDULER, "SCHEDULE: %s wakeup=3D[%s] pri=3D= %u",
- = caller,
- = tv_string_abs(&e->tv, &gc),
+ dmsg(D_SCHEDULER, "SCHEDULE: %s wakeup=3D[%= s] pri=3D%u", caller, tv_string_abs(&e->tv, &gc), e->pri);
}
= else
{
- dmsg(D_SCHEDULER, "SCHEDULE: %s NULL",
= - caller);
= + dmsg(D_SCHEDULER, &quo= t;SCHEDULE: %s NULL", caller);
}
= gc_free(&gc);
}
@@ -85,8 +82,7 @@=
* that keys do not collide.
*/<= br> static inline int
-schedule_entry_compare(const struct schedule_entry *e1,
- const struct= schedule_entry *e2)

= +schedule_entry_compare(const struct schedule_entry *e1, const struct sched= ule_entry *e2)
{
if (e1->tv.tv_sec= < e2->tv.tv_sec)
{
@@ -361,12 += 357,11 @@

if (s->root)
= {
- s= chedule_insert(s, e); /* trivial insert into tree */
+ schedule_insert(s, e); /* trivia= l insert into tree */
}
else
{
s->root =3D e; /* tree was e= mpty, we are the first element */
-
}
/* This is the mag= ic of the randomized treap algorithm which
* keeps th= e tree balanced. Move the node up the tree until
@@ -447,1= 2 +442,8 @@
* internally consistent.
*/=
int
-= schedule_debug_entry(const struct schedule_entry *e,
- int depth,
<= span style=3D"color: hsl(0, 100%, 40%);">- int *count,<= /span>
- s= truct timeval *least,
-= const struct timeval *min,
- const struct timeval *max)
+schedule_debug_entry(= const struct schedule_entry *e, int depth, int *count, struct timeval *leas= t,
+ = const struct timeval *min, const struct timeval *max)
= {
struct gc_arena gc =3D gc_new();
= int maxdepth =3D depth;
@@ -494,13 +485,13 @@
<= span> *least =3D e->tv;

}
- d =3D= schedule_debug_entry(e->lt, depth+1, count, least, min, &e->tv);=
+ d =3D sched= ule_debug_entry(e->lt, depth + 1, count, least, min, &e->tv);
if (d > maxdepth)
{
maxdepth =3D d;
}
- d = =3D schedule_debug_entry(e->gt, depth+1, count, least, &e->tv, ma= x);
+ d =3D sc= hedule_debug_entry(e->gt, depth + 1, count, least, &e->tv, max);<= /span>
if (d > maxdepth)
{
maxdepth =3D d;
@@ -577,14 +568,= 8 @@

if (e)
{
- printf("Ve= rification Phase count=3D%d maxlev=3D%d sru=3D%d ins=3D%d coll=3D%d ls=3D%= d l=3D%s",
- = count,
- = maxlev,
- = zz.sru,
- = zz.ins,
- = zz.coll,
- = zz.lsteps,
+ printf("Verification Phase = count=3D%d maxlev=3D%d sru=3D%d ins=3D%d coll=3D%d ls=3D%d l=3D%s", co= unt,
+ = maxlev, zz.sru, zz.ins, zz.coll, zz.lsteps, tv_string(&e->tv, &g= c));

if (!tv_eq(&least, &= ;e->tv))
{
@@ -605,11 +590,11 @= @
for (i =3D 0; i < size; ++i)
= {
const int src =3D get_random() % size;- struct schedule_entry = *tmp =3D array [i];
+= struct schedule_entry *tmp =3D array[i];
i= f (i !=3D src)
{
- array [i] =3D array [src];
- array [src] =3D tmp;
+ array[i] =3D = array[src];
+ = array[src] =3D tmp;
}
}
}
@@ -626,14 +611,10 @@
= if (e)
{
printf("%s [%= u] e=3D" ptr_format ", p=3D" ptr_format " lt=3D" p= tr_format " gt=3D" ptr_format "\n",
- tv_string(&e->tv, &= amp;gc),
- = e->pri,
- = (ptr_type)e,
- = (ptr_type)e->parent,
- (ptr_type)e->lt,
+ tv_string(&e->tv, &g= c), e->pri, (ptr_type)e, (ptr_type)e->parent, (ptr_type)e->lt,
(ptr_type)e->gt);
- schedule_print_work(e->lt, indent+1)= ;
- schedule_pri= nt_work(e->gt, indent+1);
+ schedule_print_work(e->lt, indent + 1);
+ schedule_print_work(e->g= t, indent + 1);

}
else
= {
diff --git a/src/openvpn/schedule.h b/src/open= vpn/schedule.h
index 1608708..5a9db6f 100644
--- a/src/openvpn/schedule.h

+++ b/src/openvpn/schedule.h=
@@ -43,8 +43,8 @@

struc= t schedule_entry
{
- struct timeval tv; /* wakeup time */
= - unsigned int pri; = /* random treap priority */
+ struct timeval tv; /* wakeup time */
+ unsigned int pri; = /* random treap priority */

struct schedule_entry *p= arent; /* treap (btree) links */
struct schedule_entry= *lt;
struct schedule_entry *gt;
@@ -5= 3,7 +53,7 @@
struct schedule
{
= struct schedule_entry *earliest_wakeup; /* cached earliest wakeu= p */
- struct schedu= le_entry *root; /* the root of the treap (btree) */
+ struct schedule_entry *root; = /* the root of the treap (btree) */

};
/* Public functions */
@@ -95,9 += 95,7 @@
* an opaque object.
*/ static inline void
-schedule_add_entry(struct schedule *s,
- struct schedule_entry *e,<= br>- const stru= ct timeval *tv,
+sche= dule_add_entry(struct schedule *s, struct schedule_entry *e, const struct t= imeval *tv,
unsigned int sigma)<= br> {
if (!IN_TREE(e) || !sigma || !tv_within_si= gma(tv, &e->tv, sigma))
@@ -115,8 +113,7 @@ * is randomized every time an entry is re-added).
*/

static inline struct schedule_entry *
-schedule_get_earliest_wakeup(struct = schedule *s,

- = struct timeval *wakeup)
+schedule_get_earliest_wakeup(struct schedule *s, st= ruct timeval *wakeup)
{
struct schedu= le_entry *ret;

diff --git a/src/openvpn/s= ession_id.h b/src/openvpn/session_id.h
index 5ce9a96..7a752= 61 100644
--- a/src/openvpn/session_id.h
++= + b/src/openvpn/session_id.h
@@ -45,8 +45,7 @@
#define SID_SIZE (sizeof(x_session_id_zero.id))


static inline bool
-session_id_equal(const struct session_id *sid1,
- const struct session_i= d *sid2)
+session_id_= equal(const struct session_id *sid1, const struct session_id *sid2)<= br> {
return !memcmp(sid1->id, sid2->id, S= ID_SIZE);
}
diff --git a/src/openvpn/shape= r.c b/src/openvpn/shaper.c
index 1075954..005719e 100644
--- a/src/openvpn/shaper.c
+++ b/src/openvpn/= shaper.c
@@ -87,6 +87,5 @@
void
= shaper_msg(struct shaper *s)
{
- msg(M_INFO, "Output Traffic Shapi= ng initialized at %d bytes per second",
- s->bytes_per_second);
+ msg(M_INFO, "Output Traffic Sh= aping initialized at %d bytes per second", s->bytes_per_second);
}
diff --git a/src/openvpn/shaper.h b/src/op= envpn/shaper.h
index 2b3eeb9..b53d4ad 100644
--- a/src/openvpn/shaper.h

+++ b/src/openvpn/shaper.h
@@ -37,10 +37,10 @@
* the output direction.<= /span>
*/

-#define SHAPER_MIN 100 /* bytes per second */
+#define SHAPER_MIN 100 = /* bytes per second */
#define SHAPER_MAX 100000000=

-#define SH= APER_MAX_TIMEOUT 10 /* seconds */
+#define SHAPER_MAX_TIMEOUT 10 /* seconds */

#define SHAPER_USE_FP

@@ -126,11 +126,12 @@

/* compute delay in microsecond= s */
tv.tv_sec =3D 0;
#ifdef SHAPER_U= SE_FP
- tv.tv_usec = =3D min_int((int)((double)max_int(nbytes, 100) * s->factor), (SHAPER_MAX= _TIMEOUT*1000000));
+= tv.tv_usec =3D
+ = min_int((int)((double)max_int(nbytes, 100) * s->factor), (SHAPER_= MAX_TIMEOUT * 1000000));
#else
tv.tv_= usec =3D s->bytes_per_second
- ? min_int(max_int(nbytes, 100) * s->factor, (= SHAPER_MAX_TIMEOUT*1000000))
- : 0;
+ ? min_int(max_int(nbytes, 100) * s->factor= , (SHAPER_MAX_TIMEOUT * 1000000))
+ : 0;
#endif
<= span>

if (tv.tv_usec)
@@ -139,11 +140= ,9 @@
tv_add(&s->wakeup, &tv);
#ifdef SHAPER_DEBUG
- dmsg(D_SHAPER_DEBUG, "SHAPER shaper_w= rote_bytes bytes=3D%d delay=3D%ld sec=3D%" PRIi64 " usec=3D%ld&qu= ot;,
- nbyt= es,
- (long= )tv.tv_usec,
- = (int64_t)s->wakeup.tv_sec,
- (long)s->wakeup.tv_usec);
+ dmsg(D_SHAPER_DEBUG,
+ "SHAPER shaper= _wrote_bytes bytes=3D%d delay=3D%ld sec=3D%" PRIi64 " usec=3D%ld&= quot;, nbytes,

+ = (long)tv.tv_usec, (int64_t)s->wakeup.tv_sec, (long)s->wakeup.= tv_usec);
#endif
}
}=
diff --git a/src/openvpn/sig.c b/src/openvpn/sig.c<= br>index 9334b10..8adfeb2 100644
--- a/src/openvpn/si= g.c
+++ b/src/openvpn/sig.c
@@ -44,20 +44,1= 9 @@

struct signal_info siginfo_static; = /* GLOBAL */

-struct signame {
+struct signame
= +{
int value;
int priority;
const char *upper;
const char *lower;<= /span>
};

-static const struct signame signames[] =3D {
- { SIGINT, 5, "SIGINT",= "sigint"},

= - { SIGTERM, 4, "SIGTERM", "sigterm" },
- { SIGHUP, 3, "SIGHUP"= ;, "sighup" },

- { SIGUSR1, 2, "SIGUSR1", "sigusr1" },- { SIGUSR2, 1, "SIGUSR2= ", "sigusr2" }
-};
+static co= nst struct signame signames[] =3D { { SIGINT, 5, "SIGINT", "= sigint" },
+ = { SIGTERM, 4, "SIGTERM", &= quot;sigterm" },
+ { SIGHUP, 3, "SIGHUP"= ;, "sighup" },
+ { SIGUSR1, 2, "SIGUSR1= ", "sigusr1" },
+ { SIGUSR2, 1, "S= IGUSR2", "sigusr2" } };

/= * mask for hard signals from management or windows */
stat= ic unsigned long long ignored_hard_signals_mask;
@@ -210,8 = +209,7 @@
if (try_throw_signal(&siginfo_static, si= gnum, SIG_SOURCE_SOFT))
{
sig= info_static.signal_text =3D signal_text;
- msg(D_SIGNAL_DEBUG, "Throw signal (soft): %= s (%s)", signal_name(signum, true),
- signal_text);
+ msg(D_SIGNAL_DEBUG, "Throw signal (so= ft): %s (%s)", signal_name(signum, true), signal_text);
}

else
{
@= @ -242,8 +240,7 @@
{
= si->source =3D SIG_SOURCE_CONNECTION_FAILED;
}<= /span>
- msg(D_SIGNAL_D= EBUG, "register signal: %s (%s)", signal_name(signum, true),
- signal_text);<= /span>
+ msg(D_SIGNAL= _DEBUG, "register signal: %s (%s)", signal_name(signum, true), si= gnal_text);
}
else
{

@@ -331,7 +328,8 @@
= break;

default:- msg(msglevel, &= quot;Unknown signal %d [%s,%s] received by %s", si->signal_received= , hs, type, t);
+ = msg(msglevel, "Unknown signal %d [%s,%s] received by %s&qu= ot;, si->signal_received, hs,
+ type, t);
= break;
}
}
@= @ -366,13 +364,10 @@

if (state &= gt;=3D 0)
{
- management_set_state(management,
- stat= e,

- = si->signal_text ? si->signal_text : signal_name(si->= signal_received, true),
- NULL,
- NULL,
- NULL,<= /span>
- = NULL);
+ = management_set_state(management, state,
+ si->signa= l_text ? si->signal_text
+ : signal_name(si-&= gt;signal_received, true),
+ NULL, NULL, NULL, NULL);
= }
}
#endif /* ifdef EN= ABLE_MANAGEMENT */
@@ -402,7 +397,7 @@
= struct sigaction sa;
CLEAR(sa);

- sigfillset(&block= _mask); /* all signals */
+ sigfillset(&block_mask); /* all signals */
= sa.sa_handler =3D signal_handler;
sa.sa_mask =3D b= lock_mask; /* signals blocked inside the handler */
s= a.sa_flags =3D SA_RESTART; /* match with the behaviour of signal() on Linux= and BSD */
@@ -431,9 +426,9 @@
struct= sigaction sa;
CLEAR(sa);

= - sigfillset(&block_mask);= /* all signals */
+ = sigfillset(&block_mask); /* all signals */
sa.= sa_handler =3D signal_handler;
- sa.sa_mask =3D block_mask; /* signals blocked inside the handl= er */
+ sa.sa_mask= =3D block_mask; /* signals blocked inside the handler */
= sa.sa_flags =3D SA_RESTART; /* match with the behaviour of signal() on= Linux and BSD */

signal_mode =3D SM= _POST_INIT;
@@ -499,8 +494,10 @@
statu= s_printf(so, "Updated,%s", time_string(0, 0, false, &gc));
status_printf(so, "TUN/TAP read bytes," counte= r_format, c->c2.tun_read_bytes);
status_printf(so, = "TUN/TAP write bytes," counter_format, c->c2.tun_write_bytes);=
- status_printf(so,= "TCP/UDP read bytes," counter_format, c->c2.link_read_bytes += c->c2.dco_read_bytes);
- status_printf(so, "TCP/UDP write bytes," counter_format,= c->c2.link_write_bytes + c->c2.dco_write_bytes);
+ status_printf(so, "TCP/UDP rea= d bytes," counter_format,
+ c->c2.link_read_bytes + c->c2.dco_read_b= ytes);
+ status_pr= intf(so, "TCP/UDP write bytes," counter_format,
+ c->c2.link_write= _bytes + c->c2.dco_write_bytes);
status_printf(so, = "Auth read bytes," counter_format, c->c2.link_read_bytes_auth)= ;
#ifdef USE_COMP
if (c->c2.comp_c= ontext)
@@ -566,12 +563,13 @@
void<= br> process_explicit_exit_notification_timer_wakeup(struct context *c= )
{
- = if (event_timeout_trigger(&c->c2.explicit_exit_notification_inter= val,
- = &c->c2.timeval,
+ if (event_timeout_trigger(&c->c2.explicit_exit_n= otification_interval, &c->c2.timeval,
= ETT_DEFAULT))
{
- ASSERT(c->c2.explicit_exit_notif= ication_time_wait && c->options.ce.explicit_exit_notification);<= /span>
- if (now >= =3D c->c2.explicit_exit_notification_time_wait + c->options.ce.explic= it_exit_notification)
+ ASSERT(c->c2.explicit_exit_notification_time_wait
+ && c->= options.ce.explicit_exit_notification);

+ if (now >=3D c->c2.explicit_exit_notifica= tion_time_wait
+ = + c->options.ce.explicit_exit_notification)
= {
event_timeout_clear(&c-&g= t;c2.explicit_exit_notification_interval);
reg= ister_signal(c->sig, SIGTERM, "exit-with-notification");
@@ -609,8 +607,7 @@
process_sigterm(struct cont= ext *c)
{
bool ret =3D true;- if (c->options.ce.expli= cit_exit_notification
-= && !c->c2.explicit_exit_notification_time_wait)+ if (c->options.ce.exp= licit_exit_notification && !c->c2.explicit_exit_notification_tim= e_wait)
{
process_explicit_ex= it_notification_init(c);
ret =3D false;
= diff --git a/src/openvpn/sig.h b/src/openvpn/sig.h
in= dex fe81af9..bd1a895 100644
--- a/src/openvpn/sig.h<= br>+++ b/src/openvpn/sig.h
@@ -27,8 +27,8 @@ #include "status.h"
#include "win3= 2.h"

-#define SIG_SOURCE_SOFT 0
-#define SIG_SOURCE_HARD 1
+#define SIG_SOURCE_SOFT 0
+#define SIG_SOURCE_HARD 1
/* CONNECTION_FAILED is also a "soft" status,
* It is thrown if a connection attempt fails
*/

diff --git a/src/openvpn/socket.c b/src/openvpn/socke= t.c
index 980d8b4..62e7ae4 100644
--- a/src= /openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -61,8 +61,7 @@

* Convert sockflags/getaddr_flags int= o getaddr_flags
*/
static unsigned int
-sf2gaf(const unsigned i= nt getaddr_flags,
- = const unsigned int sockflags)
+sf2gaf(const unsigned int getaddr_flags, const unsigned int so= ckflags)
{
if (sockflags & SF_HOS= T_RANDOMIZE)
{
@@ -78,9 +77,8 @@
* Functions related to the translation of DNS names to IP addr= esses.
*/
static int
-get_addr_generic(sa_family_t af, unsigned= int flags, const char *hostname,
- void *network, unsigned int *netbits,- int resolve_r= etry_seconds, struct signal_info *sig_info,
+get_addr_generic(sa_family_t af, unsigned int flags= , const char *hostname, void *network,
+ unsigned int *netbits, int resolve_retr= y_seconds, struct signal_info *sig_info,
= int msglevel)
{
char *endp, *sep, *va= r_host =3D NULL;
@@ -109,9 +107,7 @@
= break;

default:- msg(M_WARN,<= br>- "Unsuppo= rted AF family passed to getaddrinfo for %s (%d)",
- hostname, af);
= + msg(M_WARN, "= Unsupported AF family passed to getaddrinfo for %s (%d)", hostname, af= );
goto out;
}
=
@@ -123,8 +119,7 @@
var_host = =3D strdup(hostname);
if (!var_host)
= {
- msg(M_NO= NFATAL | M_ERRNO,
- = "Can't allocate hostname buffer for getaddrinfo");
+ msg(M_NONFATAL= | M_ERRNO, "Can't allocate hostname buffer for getaddrinfo")= ;
goto out;
}

@@ -135,15 +130,14 @@
bits =3D = strtoul(sep + 1, &endp, 10);
if ((*endp !=3D &= #39;\0') || (bits > max_bits))
{
= - msg(msglevel, "= IP prefix '%s': invalid '/bits' spec (%s)", hostname,<= /span>
- sep + = 1);
+ msg(= msglevel, "IP prefix '%s': invalid '/bits' spec (%s)&q= uot;, hostname, sep + 1);
goto out;
= }
*sep =3D '\0';
= }

- ret =3D openvpn_getaddrinfo(flags & ~GETADDR_HOST_ORDER, v= ar_host, NULL,
- = resolve_retry_seconds, sig_info, af, &ai);
+ ret =3D openvpn_getad= drinfo(flags & ~GETADDR_HOST_ORDER, var_host, NULL, resolve_retry_secon= ds,
+ = sig_info, af, &ai);
if ((ret =3D=3D = 0) && network)
{
stru= ct in6_addr *ip6;
@@ -168,8 +162,7 @@

default:
/* can&= #39;t get here because 'af' was previously checked */
- msg(M_WARN,
<= br>- "Uns= upported AF family for %s (%d)", var_host, af);
+ msg(M_WARN, "Unsuppo= rted AF family for %s (%d)", var_host, af);
= goto out;
}
}@@ -192,19 +185,15 @@
}
in_addr_t
-get= addr(unsigned int flags,
- int resolve_retry_seconds,
- bool *succeeded,
+getaddr(unsigned int flags, const char *hostna= me, int resolve_retry_seconds, bool *succeeded,
st= ruct signal_info *sig_info)
{
in_addr= _t addr;
int status;

- status =3D get_addr_generic(AF_IN= ET, flags, hostname, &addr, NULL,

- resolve_retry_seconds, sig_in= fo,
- = M_WARN);
- = if (status=3D=3D0)
+ status =3D get_addr_generic(AF_INET, flags, hostname, &addr, NULL= , resolve_retry_seconds,
+ sig_info, M_WARN);
+ if (status =3D=3D 0)
= {
if (succeeded)
{
@@ -223,16 +212,15 @@
}

bool
-g= et_ipv6_addr(const char *hostname, struct in6_addr *network,
- unsigned int *netbits,= int msglevel)

+get_i= pv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netb= its, int msglevel)
{
- if (get_addr_generic(AF_INET6, GETADDR_RESOLVE, hostnam= e, network, netbits,
- = 0, NULL, msglevel) < 0)
+ if (get_addr_generic(AF_INET6, GETADDR_R= ESOLVE, hostname, network, netbits, 0, NULL, msglevel)
+ < 0)
{
return false;
}

- return true; = /* parsing OK, values set */
+ return true; /* parsing OK, values set */=
}

static inline bool@@ -257,12 +245,8 @@
* otherwise. (like getaddrin= fo)
*/
static int
-get_cached_dns_entry(struct cached_dns_entr= y *dns_cache,
- = const char *hostname,
- const char *servname,
- int ai_family,
- int re= solve_flags,
- = struct addrinfo **ai)
+get_cached_dns_entry(struct cached_dns_entry *dns_cache, cons= t char *hostname, const char *servname,
+ int ai_family, int resolve_flags, = struct addrinfo **ai)
{
struct cached= _dns_entry *ph;
int flags;
@@ -272,10 = +256,8 @@

for (ph =3D dns_cache; ph;= ph =3D ph->next)
{
- if (streqnull(ph->hostname, hostname)
- && str= eqnull(ph->servname, servname)
- && ph->ai_family =3D=3D ai_family=
- && ph-&g= t;flags =3D=3D flags)
+ if (streqnull(ph->hostname, hostname) && streqnull(ph-= >servname, servname)
+ && ph->ai_family =3D=3D ai_family && ph-= >flags =3D=3D flags)
{
= *ai =3D ph->ai;
return 0;
@@ -286,28 +268,19 @@



static int

-do_prer= esolve_host(struct context *c,
- const char *hostname,
- const char *servname,=
- const int= af,
+do_preresolve_h= ost(struct context *c, const char *hostname, const char *servname, const in= t af,
const int flags)
= {
struct addrinfo *ai;
int statu= s;

- = if (get_cached_dns_entry(c->c1.dns_cache,
- hostname,
= - ser= vname,
- = af,
- = flags,
- &ai) =3D=3D 0)
+ if (get_cached_dns_entry(c->c1= .dns_cache, hostname, servname, af, flags, &ai) =3D=3D 0)
{

/* entry already cached, return success = */
return 0;
}

- status =3D ope= nvpn_getaddrinfo(flags, hostname, servname,
- c->options.resolv= e_retry_seconds, NULL,
-
}
return status;
}
@@ -343,10 +315,8 @@
do_pre= resolve(struct context *c)
{
struct c= onnection_list *l =3D c->options.connection_list;
- const unsigned int preresolve_flags =3D= GETADDR_RESOLVE
- = |GETADDR_UPDATE_MANAGEMENT_STATE
- = |GETADDR_MENTION_RESOLVE_RETRY
- |GETADDR_= FATAL;
+ const uns= igned int preresolve_flags =3D GETADDR_RESOLVE | GETADDR_UPDATE_MANAGEMENT_= STATE
+ = | GETADDR_MENTION_RESOLVE_RETRY | GETADDR_FATAL= ;


for (int i =3D 0= ; i < l->len; ++i)
@@ -379,8 +349,7 @@
/* HTTP remote hostname does not need to be resolved */
if (!ce->http_proxy_options)
{=
- status = =3D do_preresolve_host(c, remote, ce->remote_port,
- ce-= >af, flags);
+ = status =3D do_preresolve_host(c, remote, ce->remote_port, ce->= ;af, flags);
if (status !=3D 0)
{

goto err;
@@ -390,11 +359,8 @@

/* Preresolve proxy */
if (ce->http_proxy_options)
= {
- status = =3D do_preresolve_host(c,
- ce->http_proxy_options->s= erver,
- = ce->http_proxy_options->port,
- = ce->af,

- = preresolve_flags);
+ status =3D do_preresolve_host= (c, ce->http_proxy_options->server,
+ ce->http_p= roxy_options->port, ce->af, preresolve_flags);

if (status !=3D 0)
{<= /span>
@@ -404,11 +370,8 @@

= if (ce->socks_proxy_server)
{
- status =3D do_preresol= ve_host(c,

- = ce->socks_proxy_server,
- c= e->socks_proxy_port,
- ce->af,
- fla= gs);
+ sta= tus =3D
+ = do_preresolve_host(c, ce->socks_proxy_server, ce->socks_proxy_por= t, ce->af, flags);
if (status !=3D 0)
{
goto err;=
@@ -434,10 +397,8 @@
{ goto err;
}
-
= }
}
-
}
return;
@@ -454,9 +415,11 @@
{
= switch (af)
{
- case AF_INET: return "[AF_INET]"= ;
+ case AF_IN= ET:
+ retu= rn "[AF_INET]";

- case AF_INET6: return "[AF_INET6]";=
+ case AF_INE= T6:
+ retu= rn "[AF_INET6]";
}
retu= rn "";
}
@@ -466,17 +429,13 @@
* If resolve error, try again for resolve_retry_seconds se= conds.
*/
int
-openvpn_getaddrinfo(unsigned int flags,- const char= *hostname,
- = const char *servname,
- int resolve_retry_seconds,
- struct signal_info *= sig_info,
- = int ai_family,
+ = int resolve_retry_seconds, struct signal_info *sig_info, int ai= _family,
struct addrinfo **res)=
{
struct addrinfo hints;
= int status;
- str= uct signal_info sigrec =3D {0};
+ struct signal_info sigrec =3D { 0 };
i= nt msglevel =3D (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
struct gc_arena gc =3D gc_new();
c= onst char *print_hostname;
@@ -501,8 +460,7 @@
msglevel |=3D M_MSG_VIRT_OUT;

}
- if ((flag= s & (GETADDR_FATAL_ON_SIGNAL|GETADDR_WARN_ON_SIGNAL))
- && !sig_info)+ if ((flags & (GETADDR= _FATAL_ON_SIGNAL | GETADDR_WARN_ON_SIGNAL)) && !sig_info) {
sig_info =3D &sigrec;
= }
@@ -534,12 +492,12 @@
=
status =3D getaddrinfo(hostname, servname, &hints, res);=

- = if (status !=3D 0) /* parse as numeric address failed? */
+ if (status !=3D 0) = /* parse as numeric address failed? */
{
const int fail_wait_interval =3D 5; /* seconds */
/* Add +4 to cause integer division rounding up (1 + 4)= =3D 5, (0+4)/5=3D0 */
= - int resolve_retries =3D (flags & GETADDR_TRY_ONCE) ? 1 :
- = ((resolve_retry_seconds + 4)/ fail_wait_interval);
+ int resolve_retries =3D+ (flags & GETA= DDR_TRY_ONCE) ? 1 : ((resolve_retry_seconds + 4) / fail_wait_interval);
const char *fmt;
int level = =3D 0;

@@ -562,8 +520,7 @@
}


fmt =3D "RESOL= VE: Cannot resolve host address: %s:%s%s (%s)";
- if ((flags & GETADDR_MENTION_RE= SOLVE_RETRY)
- = && !resolve_retry_seconds)
+ if ((flags & GETADDR_MENTION_RESOLVE_RETRY) &= amp;& !resolve_retry_seconds)
{
fmt =3D "RESOLVE: Cannot resolve host address: %s:%s%s = (%s)"

"(I would have retried t= his name query if you had "
@@ -572,8 +529,8 @@=

if (!(flags & GETADDR_RESOLVE) || = status =3D=3D EAI_FAIL)
{
- msg(msglevel, "RESOLVE: Canno= t parse IP address: %s:%s (%s)",
- print_hostname, print_servname, gai_strerro= r(status));
+ = msg(msglevel, "RESOLVE: Cannot parse IP address: %s:%s (%s)",= print_hostname,
+ = print_servname, gai_strerror(status));
= goto done;
}

@@ -582,12 +539,7 @@

{
= if (management)
{
- management_set_state(manage= ment,
- = OPENVPN_STATE_RESOLVE,
- NULL,
= - = NULL,
- = NULL,
- NULL,
+ management_set_state(mana= gement, OPENVPN_STATE_RESOLVE, NULL, NULL, NULL, NULL,
= NULL);
}
}
@@ -604,9 +556,8 @@
#endif

/* try hostname lookup */
<= span> hints.ai_flags &=3D ~AI_NUMERICHOST;

- dmsg(D_SOCKET_DEBUG,
- "GETA= DDRINFO flags=3D0x%04x ai_family=3D%d ai_socktype=3D%d",
- flags, hints.ai_fa= mily, hints.ai_socktype);

+ dmsg(D_SOCKET_DEBUG, "GETADDRINFO flags=3D0x%04x ai_= family=3D%d ai_socktype=3D%d", flags,
+ hints.ai_family, hints.ai_socktype)= ;
status =3D getaddrinfo(hostname, servname, &= amp;hints, res);

if (sig_inf= o)
@@ -617,9 +568,8 @@
= /* why are we overwriting SIGUSR1 ? */
= if (signal_reset(sig_info, SIGUSR1) =3D=3D SIGUSR1) /* ignore SIGUSR1 */<= /span>
{
- msg(level,
- "RESOLVE: = Ignored SIGUSR1 signal received during "
- "DNS resolution at= tempt");
+ = msg(level, "RESOLVE: Ignored SIGUSR1 signal received= during "
+ = "DNS resolution attempt"); }
else
{
@@ -651,11 +601,7 @@
level =3D D_RESOLVE_ERRORS;
}


- msg(level,
- fmt,
- print_hostname,
- print_servname,
- getaddrinfo_addr_family_nam= e(ai_family),
+ = msg(level, fmt, print_hostname, print_servname, getaddrinfo_addr_fami= ly_name(ai_family),
gai_strerror(status));=

if (--resolve_retries <= =3D 0)
@@ -680,9 +626,8 @@
/* IP a= ddress parse succeeded */
if (flags & GETADDR_= RANDOMIZE)
{
- msg(M_WARN,
- "WARNING: ignoring --remote-random-h= ostname because the "
- "hostname is an IP address");
+ msg(M_WARN, "WARN= ING: ignoring --remote-random-hostname because the "

+ "hostnam= e is an IP address");
}
= }

@@ -719,11 +664,11 @@
= {
if (a < 256 && b < 256 &&a= mp; c < 256 && d < 256)
{
= - addr->s_addr =3D = htonl(a<<24 | b<<16 | c<<8 | d);
+ addr->s_addr =3D htonl(a <= < 24 | b << 16 | c << 8 | d);
r= eturn OIA_IP; /* good dotted quad */
}
<= span> }

- if (st= ring_class(dotted_quad, CC_DIGIT|CC_DOT, 0))
+ if (string_class(dotted_quad, CC_DIGIT | CC_DO= T, 0))
{
return OIA_ERROR; /*= probably a badly formatted dotted quad */
}@@ -801,7 +746,7 @@
/* verify that string will = convert to IPv6 address */
{
= struct in6_addr a6;
- = return inet_pton( AF_INET6, ipv6_text_addr, &a6 ) =3D=3D 1;
+ return inet_pton(= AF_INET6, ipv6_text_addr, &a6) =3D=3D 1;
}<= br> }

@@ -811,7 +756,7 @@ if (addr)
{
const= size_t len =3D strlen(addr);
- return len > 0 && len <=3D 255 && str= ing_class(addr, CC_ALNUM|CC_DASH|CC_DOT, 0);
+ return len > 0 && len <=3D 2= 55 && string_class(addr, CC_ALNUM | CC_DASH | CC_DOT, 0); }
else
{
@@ -860,7 +805,7 @@


while ((= c =3D *p++))
{
- if ( (c >=3D '0' && c <= =3D '9') || (c >=3D 'a' && c <=3D 'f'= ) || (c >=3D 'A' && c <=3D 'F') )
<= span style=3D"color: hsl(120, 100%, 40%);">+ if ((c >=3D '= ;0' && c <=3D '9') || (c >=3D 'a' &&a= mp; c <=3D 'f') || (c >=3D 'A' && c <=3D &= #39;F'))

{
= ++nnum;
if (nnum > 2)
@@ -891,8 +836,7 @@

socklen_t len;
<= /span>
len =3D sizeof(val);
- if (getsockopt(sd, SOL_SOCKET, SO_SNDBUF, (void *) = &val, &len) =3D=3D 0
- && len =3D=3D sizeof(val))
+ if (getsockopt(sd, SOL_SOCKET, SO_SNDBUF,= (void *)&val, &len) =3D=3D 0 && len =3D=3D sizeof(val))
{
return val;
= }
@@ -904,7 +848,7 @@
socket_set_sndbu= f(socket_descriptor_t sd, int size)
{
#if= defined(SOL_SOCKET) && defined(SO_SNDBUF)
- if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, = (void *) &size, sizeof(size)) !=3D 0)
+ if (setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (void *= )&size, sizeof(size)) !=3D 0)
{
= msg(M_WARN, "NOTE: setsockopt SO_SNDBUF=3D%d failed", size= );
}
@@ -919,8 +863,7 @@
socklen_t len;


len =3D sizeo= f(val);
- if (getsoc= kopt(sd, SOL_SOCKET, SO_RCVBUF, (void *) &val, &len) =3D=3D 0
- && len =3D= =3D sizeof(val))
+ = if (getsockopt(sd, SOL_SOCKET, SO_RCVBUF, (void *)&val, &len) =3D= =3D 0 && len =3D=3D sizeof(val))
{
<= span> return val;

}
@@ -932,7 = +875,7 @@
socket_set_rcvbuf(socket_descriptor_t sd, int si= ze)
{
#if defined(SOL_SOCKET) && = defined(SO_RCVBUF)
- = if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (void *) &size, sizeof(size)= ) !=3D 0)
+ if (se= tsockopt(sd, SOL_SOCKET, SO_RCVBUF, (void *)&size, sizeof(size)) !=3D 0= )
{
msg(M_WARN, "NOTE: s= etsockopt SO_RCVBUF=3D%d failed", size);
retu= rn false;
@@ -942,31 +885,25 @@
}
void
-socket_set_buffers(socket_descriptor_t fd, const struct socket_bu= ffer_size *sbs,
- = bool reduce_size)
+socket_set_buffers(socket_descriptor_t fd, const struct socket_b= uffer_size *sbs, bool reduce_size)
{
= if (sbs)
{
const int sndbuf_o= ld =3D socket_get_sndbuf(fd);
const int rcvbuf_old= =3D socket_get_rcvbuf(fd);

- if (sbs->sndbuf
- && (reduce_size || sndbuf_= old < sbs->sndbuf))
+ if (sbs->sndbuf && (reduce_size || sndbuf_old <= sbs->sndbuf))
{
s= ocket_set_sndbuf(fd, sbs->sndbuf);
}
=
- if (sb= s->rcvbuf
- = && (reduce_size || rcvbuf_old < sbs->rcvbuf))
+ if (sbs->rcvbuf &= & (reduce_size || rcvbuf_old < sbs->rcvbuf))

= {
socket_set_rcvbuf(fd, sbs->rcvbuf);<= /span>
}

- msg(D_OSBUF, "Socket Buffers: R=3D[%d-&= gt;%d] S=3D[%d->%d]",
- rcvbuf_old,
- socket_get_rcvbuf(fd),
- sndbuf_old,
- socket_get_sndbuf(fd));
+ msg(D_OSBUF, "Socket = Buffers: R=3D[%d->%d] S=3D[%d->%d]", rcvbuf_old, socket_get_rcvb= uf(fd),

+ = sndbuf_old, socket_get_sndbuf(fd));
}
= }

@@ -978,7 +915,7 @@
s= ocket_set_tcp_nodelay(socket_descriptor_t sd, int state)
{=
#if defined(_WIN32) || (defined(IPPROTO_TCP) && d= efined(TCP_NODELAY))
- = if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (void *) &state, sizeof= (state)) !=3D 0)
+ = if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (void *)&state, sizeof(st= ate)) !=3D 0)
{
msg(M_WARN, &= quot;NOTE: setsockopt TCP_NODELAY=3D%d failed", state);
return false;

@@ -988,7 +925,7 @@
dmsg(D_OSBUF, "Socket flags: TCP_NODELAY=3D%d succeeded&quo= t;, state);

return true;
}
-#else /* if defined(_WI= N32) || (defined(IPPROTO_TCP) && defined(TCP_NODELAY)) */+#else /* if defined(_WIN32) |= | (defined(IPPROTO_TCP) && defined(TCP_NODELAY)) */
msg(M_WARN, "NOTE: setsockopt TCP_NODELAY=3D%d failed (No kernel= support)", state);

return false;
#endif

@@ -998,7 +935,7 @@
socket_set_ma= rk(socket_descriptor_t sd, int mark)
{
#i= f defined(TARGET_LINUX) && HAVE_DECL_SO_MARK
- if (mark && setsockopt(sd, SOL_= SOCKET, SO_MARK, (void *) &mark, sizeof(mark)) !=3D 0)
+ if (mark && setsockopt(s= d, SOL_SOCKET, SO_MARK, (void *)&mark, sizeof(mark)) !=3D 0)
= {
msg(M_WARN, "NOTE: setsockopt SO= _MARK=3D%d failed", mark);
}
@@ -= 1066,8 +1003,7 @@
/* set SO_REUSEADDR on socket */
{
int on =3D 1;
- if (setsockopt(sd, SOL_SOCKET,= SO_REUSEADDR,
- = (void *) &on, sizeof(on)) < 0)
+ if (setsockopt(sd, SOL_SOCKET, SO= _REUSEADDR, (void *)&on, sizeof(on)) < 0)
{=
msg(M_ERR, "TCP: Cannot setsockopt SO_RE= USEADDR on TCP socket");
}
@@= -1100,31 +1036,29 @@
if (addrinfo->ai_family = =3D=3D AF_INET)
{
#if defined(HAV= E_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
- if (setsockopt(sd, SOL_IP, IP_P= KTINFO,
- = (void *)&pad, sizeof(pad)) < 0)
+ if (setsockopt(sd, SOL_IP, IP= _PKTINFO, (void *)&pad, sizeof(pad)) < 0)
= {
msg(M_ERR, "UDP: failed setsocko= pt for IP_PKTINFO");
}
#= elif defined(IP_RECVDSTADDR)
- if (setsockopt(sd, IPPROTO_IP, IP_RECVDSTADDR,- (voi= d *)&pad, sizeof(pad)) < 0)
+ if (setsockopt(sd, IPPROTO_IP, IP_RECVDSTADDR, (= void *)&pad, sizeof(pad)) < 0)
{=
msg(M_ERR, "UDP: failed setsockopt for IP_R= ECVDSTADDR");
}
-#else /* if defined(HAVE_IN_PKTINFO) &&= ; defined(HAVE_IPI_SPEC_DST) */
+#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IP= I_SPEC_DST) */
#error ENABLE_IP_PKTINFO is set without IP_= PKTINFO xor IP_RECVDSTADDR (fix syshead.h)
#endif }
else if (addrinfo->ai_family= =3D=3D AF_INET6)
{
#ifndef IPV6_= RECVPKTINFO /* Some older Darwin platforms require this */
- if (setsockopt(sd, IPPROTO= _IPV6, IPV6_PKTINFO,
- = (void *)&pad, sizeof(pad)) < 0)
= + if (setsockopt(sd,= IPPROTO_IPV6, IPV6_PKTINFO, (void *)&pad, sizeof(pad)) < 0)<= br> #else
- = if (setsockopt(sd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
- (void *)&= pad, sizeof(pad)) < 0)
+ if (setsockopt(sd, IPPROTO_IPV6, IPV6_RECVPKTINFO, (void = *)&pad, sizeof(pad)) < 0)
#endif
- { msg(M_ERR, "UDP: fail= ed setsockopt for IPV6_RECVPKTINFO");}
+ {
+ msg(M_ERR, "UDP: failed setsockopt f= or IPV6_RECVPKTINFO");
+ }
}
}
#endif /* if ENABLE_IP_PKTINFO */
@@ -1144,14= +1078,12 @@
{
if (sock->s= ocks_proxy && sock->info.proto =3D=3D PROTO_UDP)
{

- = socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local,- ai_fami= ly, "SOCKS", false);
+ socket_bind(sock->ctrl_sd, sock->info.lsa->= bind_local, ai_family, "SOCKS", false);
= }
else
{
- socket_bind(sock->sd, s= ock->info.lsa->bind_local,
- ai_family,
- "TCP/UDP", sock-&= gt;info.bind_ipv6_only);
+ socket_bind(sock->sd, sock->info.lsa->bind_local,= ai_family, "TCP/UDP",
+ sock->info.bind_ipv6_only);<= br> }
}
}
@@ -1199,11 +1131,12 @@

if (sock->bind_dev)
{
msg(M_INFO, "Using bind-de= v %s", sock->bind_dev);
- if (setsockopt(sock->sd, SOL_SOCKET, SO_BINDTODEVICE, = sock->bind_dev, strlen(sock->bind_dev) + 1) !=3D 0)
+ if (setsockopt(sock->sd, S= OL_SOCKET, SO_BINDTODEVICE, sock->bind_dev,
+ strlen(sock->bind_dev)= + 1)
+ != =3D 0)
{
- msg(M_WARN|M_ERRNO, "WARN: setsockopt SO_BINDT= ODEVICE=3D%s failed", sock->bind_dev);
+ msg(M_WARN | M_ERRNO, "WARN: se= tsockopt SO_BINDTODEVICE=3D%s failed", sock->bind_dev);
<= span> }

-
}
#endif

@@ -1238,9 +1171,7 @@

* Functions used for establishing = a TCP stream connection.
*/
static void<= /span>
-socket_do_listen(socke= t_descriptor_t sd,
- = const struct addrinfo *local,
- bool do_listen,
+socket_do_listen(socket_descriptor_t sd,= const struct addrinfo *local, bool do_listen,
= bool do_set_nonblock)
{
struct = gc_arena gc =3D gc_new();
@@ -1265,9 +1196,7 @@
<= span> }


socket_descriptor_t
-socket_do_accept(socket_descriptor= _t sd,

- = struct link_socket_actual *act,
- const bool nowait)
+socket_do_accept(socket_descriptor_t sd, struct= link_socket_actual *act, const bool nowait)
{
<= span> /* af_addr_size WILL return 0 in this case if AFs other than AF_I= NET

* are compiled because act is empty here.<= br>@@ -1315,7 +1244,8 @@
/* only valid if we hav= e remote_len_af!=3D0 */
else if (remote_len_af &&a= mp; remote_len !=3D remote_len_af)
{
- msg(D_LINK_ERRORS, "TCP: R= eceived strange incoming connection with unknown address length=3D%d",= remote_len);
+ = msg(D_LINK_ERRORS,
= + "TCP: Received strange incoming connection with unknown a= ddress length=3D%d", remote_len);
openvpn_clo= se_socket(new_sd);
new_sd =3D SOCKET_UNDEFINED;
}
@@ -1332,19 +1262,14 @@
tcp_connection_established(const struct link_socket_actual *act)
<= br> {
struct gc_arena gc =3D gc_new();- msg(M_INFO, "TCP conne= ction established with %s",
- print_link_socket_actual(act, &gc));
+ msg(M_INFO, "TCP connectio= n established with %s", print_link_socket_actual(act, &gc));
gc_free(&gc);
}

static socket_descriptor_t
-socket_listen_accept(socket_descriptor_t sd,
- struct link_s= ocket_actual *act,

- = const char *remote_dynamic,
- const struct addrinfo *local,<= /span>
- b= ool do_listen,
- = bool nowait,
- volatile int *signal_received)
+socket_listen_accept(socket_descriptor= _t sd, struct link_socket_actual *act,
+ const char *remote_dynamic, const s= truct addrinfo *local, bool do_listen,
+ bool nowait, volatile int *signal_r= eceived)
{
struct gc_arena gc =3D gc_= new();
/* struct openvpn_sockaddr *remote =3D &act= ->dest; */
@@ -1398,8 +1323,7 @@

if (ai && !addrlist_match(&remote_verif= y, ai))
{
- msg(M_WARN,
- "TCP NOTE: Rejected connect= ion attempt from %s due to --remote setting",
+ msg(M_WARN, "TCP NOTE: = Rejected connection attempt from %s due to --remote setting", print_link_socket_actual(act, &gc));
if (openvpn_close_socket(new_sd))
{

@@ -1431,10 +1355,7 @@
}


void
-socket_bind(socket_descriptor_t sd,
- struct addrinfo *local,
- int ai_famil= y,
- const c= har *prefix,
+socket_= bind(socket_descriptor_t sd, struct addrinfo *local, int ai_family, const c= har *prefix,
bool ipv6only)
{=
struct gc_arena gc =3D gc_new();
@@ -= 1461,33 +1382,30 @@
}
if (!cur)
{
-= msg(M_FATAL, "%s: Socket bind failed: Addr to bind has no %s r= ecord",
- = prefix, addr_family_name(ai_family));
+ msg(M_FATAL, "%s: Socket bind failed: Add= r to bind has no %s record", prefix,
+ addr_family_name(ai_family));
<= span> }


if (ai_family =3D=3D AF_= INET6)
{
- int v6only =3D ipv6only ? 1 : 0; /* setsockopt must have a= n "int" */
= + int v6only =3D ipv6only ? 1 : 0; /* setsockopt must have an "= int" */

msg(M_INFO, "s= etsockopt(IPV6_V6ONLY=3D%d)", v6only);
- if (setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY,= (void *) &v6only, sizeof(v6only)))
+ if (setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, (= void *)&v6only, sizeof(v6only)))
{
<= span style=3D"color: hsl(0, 100%, 40%);">- msg(M_NONFATAL|M_ERRN= O, "Setting IPV6_V6ONLY=3D%d failed", v6only);

+ msg(M_NONFATAL | M_ERRNO, = "Setting IPV6_V6ONLY=3D%d failed", v6only);
= }
}
if (bind(sd, cur->ai_a= ddr, cur->ai_addrlen))
{
- msg(M_FATAL | M_ERRNO, "%s: Socket = bind failed on local address %s",
- prefix,
+ msg(M_FATAL | M_ERRNO, "%s: Socket bind faile= d on local address %s", prefix,
print_soc= kaddr_ex(local->ai_addr, ":", PS_SHOW_PORT, &gc));<= br> }
gc_free(&gc);
}

int
-openvpn_connect(socket_descriptor_t sd,
- const struct sockaddr *re= mote,
- = int connect_timeout,
= +openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int= connect_timeout,
volatile int *signal_rec= eived)
{
int status =3D 0;
= @@ -1507,7 +1425,7 @@
#else
= status =3D=3D EINPROGRESS
#endif
- )
+ )
{
wh= ile (true)
{
@@ -1562,7 +1480,7 @@=
socklen_t len;
len =3D sizeof(val);
- if (getsockopt(sd, SOL_SOCKET, SO_E= RROR, (void *) &val, &len) =3D=3D 0
+ if (getsockopt(sd, SOL_SOCKET, SO_E= RROR, (void *)&val, &len) =3D=3D 0
= && len =3D=3D sizeof(val))
{<= /span>
status =3D val;
@@ -15= 87,43 +1505,31 @@

if (ai->ai_fami= ly =3D=3D AF_INET)
{
- actual->dest.addr.in4 =3D
- *((struct sockaddr_in *) ai-= >ai_addr);
+ = actual->dest.addr.in4 =3D *((struct sockaddr_in *)ai->ai_addr);
}
else if (ai->ai_family =3D=3D A= F_INET6)
{
- actual->dest.addr.in6 =3D
- *((struct sockaddr_in6 *) ai->ai_ad= dr);
+ actual-= >dest.addr.in6 =3D *((struct sockaddr_in6 *)ai->ai_addr);
<= span> }

else
{
ASSERT(0);

}
-
}

static void

-socket_= connect(socket_descriptor_t *sd,
- const struct sockaddr *dest,
- const int connect_timeout,<= /span>
+socket_connect(socke= t_descriptor_t *sd, const struct sockaddr *dest, const int connect_timeout,=
struct signal_info *sig_info)
{

struct gc_arena gc =3D gc_new();
int status;


- msg(M_INFO, "Attempting to establish TCP connection= with %s",
- = print_sockaddr(dest, &gc));
+ msg(M_INFO, "Attempting to establish TCP connection = with %s", print_sockaddr(dest, &gc));

= #ifdef ENABLE_MANAGEMENT
if (management)=
{
- = management_set_state(management,
- OPENVPN_STATE_TCP_CONNECT,
- = NULL,
- = NULL,
- = NULL,
- NULL,
- NULL);
+ management_set_state(manag= ement, OPENVPN_STATE_TCP_CONNECT, NULL, NULL, NULL, NULL, NULL);

= }
#endif

@@ -= 1638,9 +1544,8 @@

if (status)=
{
-
- msg(D_LINK_ERRORS,= "TCP: connect to %s failed: %s",
- print_sockaddr(dest, &gc), strerror(s= tatus));
+ msg= (D_LINK_ERRORS, "TCP: connect to %s failed: %s", print_sockaddr(d= est, &gc),
+ = strerror(status));

openvp= n_close_socket(*sd);
*sd =3D SOCKET_UNDEFINED;
@@ -1648,8 +1553,7 @@
}
= else
{
- msg(M_INFO, "TCP connection established with %s"= ;,
- print_s= ockaddr(dest, &gc));
+ msg(M_INFO, "TCP connection established with %s", pr= int_sockaddr(dest, &gc));
}

done:
@@ -1662,15 +1566,12 @@
= * such as TCP.
*/

-static void
-stream_buf_init(struct stream_buf *sb, struct buffe= r *buf,
- = const unsigned int sockflags, const int proto);
+static void stream_buf_init(struct stream_buf= *sb, struct buffer *buf, const unsigned int sockflags,
+ const int p= roto);

-stream_= buf_close(struct stream_buf *sb);
+static void stream_buf_close(struct stream_buf *sb);
-static bool<= /span>
-stream_buf_added(struc= t stream_buf *sb, int length_added);
+static bool stream_buf_added(struct stream_buf *sb, int le= ngth_added);

/* For stream protocols, al= locate a buffer to build up packet.
* Called after frame = has been finalized. */
@@ -1688,16 +1589,12 @@
if (link_socket_connection_oriented(sock))

{<= /span>
#ifdef _WIN32
- stream_buf_init(&sock->stream_buf,
- &sock->= reads.buf_init,
- = sock->sockflags,
+ stream_buf_init(&sock->stream_buf, &so= ck->reads.buf_init, sock->sockflags,
= sock->info.proto);
#else
= alloc_buf_sock_tun(&sock->stream_buf_data, frame);

- stream_bu= f_init(&sock->stream_buf,
- &sock->stream_buf_data,- sock-&g= t;sockflags,
+ = stream_buf_init(&sock->stream_buf, &sock->stream_buf_data, s= ock->sockflags,
sock->info.p= roto);
#endif
}
@@ -1= 711,8 +1608,7 @@
/* resolve local address if undefined= */
if (!sock->info.lsa->bind_local)
<= span> {

- in= t flags =3D GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL
- |GETADDR_FATAL | GETADD= R_PASSIVE;
+ i= nt flags =3D GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL | GETADDR_FATAL | GET= ADDR_PASSIVE;
int status;
=
if (proto_is_dgram(sock->info.proto))
@@ -1721,24 +1617,19 @@

}

/* will return AF_{INET|INET6}from local_host */=
- status =3D get_cache= d_dns_entry(sock->dns_cache,
- sock->local_host,=
- = sock->local_port,
- af,
- flags,
- = &sock->info.lsa->bind_local);
+ status =3D get_cached_dns_entry(= sock->dns_cache, sock->local_host, sock->local_port, af,+ = flags, &sock->info.lsa->bind_local);

if (status)
{
- status =3D openvpn_get= addrinfo(flags, sock->local_host, sock->local_port, 0,

- = NULL, af, &sock->info.lsa->bind_local);

+ status =3D openvpn_getaddrin= fo(flags, sock->local_host, sock->local_port, 0, NULL, af,
= + = &sock->info.lsa->bind_local);
= }

- = if (status !=3D0)
+ if (status !=3D 0)
{
- msg(M_FATAL, "getaddr= info() failed for local \"%s:%s\": %s",
- sock->local_host, sock-= >local_port,
- = gai_strerror(status));
+ msg(M_FATAL, "getaddrinfo() failed for local = \"%s:%s\": %s", sock->local_host,
+ sock->local_port, gai_= strerror(status));
}

<= span> /* the address family returned by openvpn_getaddrinfo() shoul= d be

@@ -1760,9 +1651,7 @@
}

static void
-resolve_remote(struct link_socket *sock,
- int phase,
- const char **remote_dyna= mic,
+resolve_remote(= struct link_socket *sock, int phase, const char **remote_dynamic, struct signal_info *sig_info)
{
volatile int *signal_received =3D sig_info ? &sig_inf= o->signal_received : NULL;
@@ -1773,7 +1662,8 @@<= br> {
if (sock->remote_host) {
- = unsigned int flags =3D sf2gaf(GETADDR_RESOLVE|GETADDR_UPDATE_MANAG= EMENT_STATE, sock->sockflags);
+ unsigned int flags =3D
+ sf2gaf(GETADDR_RESOLVE | GETAD= DR_UPDATE_MANAGEMENT_STATE, sock->sockflags);
= int retry =3D 0;
int status =3D -1;<= br> struct addrinfo *ai;
@@ -1820,15 +171= 0,12 @@
}

<= /span>
- status =3D= get_cached_dns_entry(sock->dns_cache,
- sock->remo= te_host,
- = sock->remote_port,
- sock= ->info.af,
- = flags, &ai);
+ status =3D get_cached_dns_entry(= sock->dns_cache, sock->remote_host, sock->remote_port,
<= span style=3D"color: hsl(120, 100%, 40%);">+ = sock->info.af, flags, &ai);

= if (status)
{
- status =3D openvpn_getaddrinfo(flags, = sock->remote_host, sock->remote_port,
- retry, s= ig_info, sock->info.af, &ai);
+ status =3D openvpn_getaddrinfo(flags, sock= ->remote_host, sock->remote_port, retry,
+ sig= _info, sock->info.af, &ai);
}
if (status =3D=3D 0)
= @@ -1836,19 +1723,14 @@
sock->info.lsa-= >remote_list =3D ai;
sock->info.lsa-= >current_remote =3D ai;

- dmsg(D_SOCKET_DEBUG,
- "RESOLVE_RE= MOTE flags=3D0x%04x phase=3D%d rrs=3D%d sig=3D%d status=3D%d",
<= br>- flags,
- ph= ase,
- = retry,
- = signal_received ? *signal_received : -1,
- status);
+ dmsg(D_SOCKET_DEBUG,= "RESOLVE_REMOTE flags=3D0x%04x phase=3D%d rrs=3D%d sig=3D%d status=3D= %d",
+ = flags, phase, retry, signal_received ? *signal_received : -1, st= atus);
}
if (sign= al_received && *signal_received)
{
goto done;
}
- if (status!= =3D0)
+ if= (status !=3D 0)
{
= if (signal_received)
{
@@ -1875,8 +1757,7 @@

CLEAR(sock->info.lsa-&= gt;actual);
if (sock->info.lsa->current_remo= te)
{
- set_actual_address(&sock->info.lsa->actual,<= /span>
- = sock->info.lsa->current_remote);
+ set_actual_address(&sock->in= fo.lsa->actual, sock->info.lsa->current_remote);
= }
}

@@ -1885= ,7 +1766,6 @@
}

=
-
struct lin= k_socket *
link_socket_new(void)
{=
@@ -2078,8 +1958,7 @@
}
= ASSERT(cur);
msg(msglevel, "%s link = local (bound): %s",
- print_sockad= dr(cur->ai_addr, &gc));
+ proto2ascii(sock->info.proto, sock->info.af, t= rue), print_sockaddr(cur->ai_addr, &gc));
}
else
{
@@ -2088,12 += 1967,8 @@
}

/* = print active remote address */
- msg(msglevel, "%s link remote: %s",
- proto2ascii(sock->info.prot= o, sock->info.af, true),
- print_link_socket_actual_ex(&sock->info.lsa->actual= ,
- = ":",
- PS_SHOW_PORT_IF_DEFINED,
- = &gc));
+= msg(msglevel, "%s link remote: %s", proto2ascii(sock->info= .proto, sock->info.af, true),
+ print_link_socket_actual_ex(&sock->info.lsa->= ;actual, ":", PS_SHOW_PORT_IF_DEFINED, &gc));
gc_free(&gc);

}

@@ -2106,26 +1981,17 @@

switch (sock->mode)
{
case LS_MODE_DEFAULT:
= - sock->sd =3D sock= et_listen_accept(sock->sd,
- &sock->info.lsa-= >actual,
- = remote_dynamic,
- soc= k->info.lsa->bind_local,
- true,
- = false,
- = signal_received);
+ sock->sd =3D
+ socket_listen_acc= ept(sock->sd, &sock->info.lsa->actual, remote_dynamic,
<= br>+ = sock->info.lsa->bind_local, true, false, signal_received);<= /span>
break;

= case LS_MODE_TCP_LISTEN:
- socket_do_listen(sock->sd,
- sock->info.lsa-&= gt;bind_local,
- = true,
- false);
+ socket_do_listen(sock->sd, sock->i= nfo.lsa->bind_local, true, false);
break;

case LS_MODE_TCP_ACCEPT_FROM:
- sock->sd = =3D socket_do_accept(sock->sd,
- &sock->info.lsa-= >actual,
- = false);
+ sock->sd =3D socket_do_accept(sock->sd,= &sock->info.lsa->actual, false);
if= (!socket_defined(sock->sd))
{
register_signal(sig_info, SIGTERM, "socket-undefi= ned");

@@ -2146,10 +2012,8 @@
boo= l proxy_retry =3D false;
do
{
- socket_connect(&a= mp;sock->sd,
- = sock->info.lsa->current_remote->ai_addr,- get_ser= ver_poll_remaining_time(sock->server_poll_timeout),
- sig_info);+ socket_connect(&= sock->sd, sock->info.lsa->current_remote->ai_addr,
+ get_serve= r_poll_remaining_time(sock->server_poll_timeout), sig_info);

<= span>

if (sig_info->signal_received) {
@@ -2158,21 +2022,14 @@
=
if (sock->http_proxy)
= {
- proxy_r= etry =3D establish_http_proxy_passthru(sock->http_proxy,
- = sock->sd,

- sock->= proxy_dest_host,
- = sock->proxy_dest_port= ,
- = sock->server_poll_timeout,- = &sock->stream_buf.residual,
- = sig_info);

+ proxy_retry =3D establish_http_proxy_passthru(=
+ sock->h= ttp_proxy, sock->sd, sock->proxy_dest_host, sock->proxy_dest_port,=
+ soc= k->server_poll_timeout, &sock->stream_buf.residual, sig_info);
}
else if (sock->socks_p= roxy)
{
- establish_socks_proxy_passthru(sock->socks_proxy,=
- = sock->sd,
- sock->proxy_dest= _host,
- = sock->proxy_dest_port,
- = sock->server_poll_timeout,
+ establish_socks_proxy_passthru(sock->socks_proxy, = sock->sd, sock->proxy_dest_host,
+ sock->prox= y_dest_port, sock->server_poll_timeout,
= sig_info);
} if (proxy_retry)
@@ -2182,27 +2039,21 @@
}

} while (pr= oxy_retry);
- }

static void
p= hase2_socks_client(struct link_socket *sock, struct signal_info *sig_info)<= /span>
{
- = socket_connect(&sock->ctrl_sd,
- sock->info.lsa->current_remote-&g= t;ai_addr,
- = get_server_poll_remaining_time(sock->server_poll_timeout),
- sig_info= );
+ socket_connec= t(&sock->ctrl_sd, sock->info.lsa->current_remote->ai_addr,<= /span>
+ g= et_server_poll_remaining_time(sock->server_poll_timeout), sig_info);

if (sig_info->signal_received)
{
return;
}

- e= stablish_socks_proxy_udpassoc(sock->socks_proxy,
- sock->= ;ctrl_sd,
- = &sock->socks_relay.dest,
- sock-&g= t;server_poll_timeout,
= - sig_info);
+ establish_socks_proxy_udpassoc(sock->sock= s_proxy, sock->ctrl_sd, &sock->socks_relay.dest,
+ s= ock->server_poll_timeout, sig_info);

= if (sig_info->signal_received)
{
@@ -2225,8 +2076,7 @@


#if defined(_WIN= 32)
static void
-create_socket_dco_win(struct context *c, struct link_socket *soc= k,
- = struct signal_info *sig_info)
+create_socket_dco_win(struct context *c, struct link_socket *s= ock, struct signal_info *sig_info)
{
= /* in P2P mode we must have remote resolved at this point */
struct addrinfo *remoteaddr =3D sock->info.lsa->current_remote= ;

@@ -2274,14 +2124,13 @@

/* finalize socket initialization */

void
-link_socket_init_phase2(struct conte= xt *c,

- = struct link_socket *sock)
+link_socket_init_phase2(struct context *c, struct link_socke= t *sock)
{
const struct frame *frame = =3D &c->c2.frame;
struct signal_info *sig_info = =3D c->sig;

const char *remote_dy= namic =3D NULL;
- st= ruct signal_info sig_save =3D {0};
+ struct signal_info sig_save =3D { 0 };
=
ASSERT(sock);
ASSERT(sig_info);<= /span>
@@ -2306,7 +2155,7 @@
}

/* Second chance to resolv/create socket */=
- resolve_remote(sock, 2, = &remote_dynamic, sig_info);
+ resolve_remote(sock, 2, &remote_dynamic, sig_info);

/* If a valid remote has been found, c= reate the socket with its addrinfo */
#if defined(_WIN32)<= /span>
@@ -2327,7 +2176,7 @@
/* If we hav= e no --remote and have still not figured out the
= * protocol family to use we will use the first of the bind */

- if (sock-= >bind_local && !sock->remote_host && sock->info.l= sa->bind_local)
+ = if (sock->bind_local && !sock->remote_host && = sock->info.lsa->bind_local)
{
/* Warn if this is because neither v4 or v6 was specified
* and we should not connect a remote */<= br>@@ -2361,7 +2210,6 @@
else if (sock->info.= proto =3D=3D PROTO_TCP_CLIENT)
{
= phase2_tcp_client(sock, sig_info);
-
}
else if (sock= ->info.proto =3D=3D PROTO_UDP && sock->socks_proxy) {
@@ -2455,7 +2303,8 @@
}


static void
-ipchange_fmt(const bool include_cmd, struct argv *argv= , const struct link_socket_info *info, struct gc_arena *gc)
+ipchange_fmt(const bool include_cmd= , struct argv *argv, const struct link_socket_info *info,

+ struct gc_arena *gc)
{
const char *host =3D print_sockaddr_ex= (&info->lsa->actual.dest.addr.sa, " ", PS_SHOW_PORT, gc= );
if (include_cmd)
@@ -2467,13 +2316,= 11 @@
{
argv_printf(argv, &qu= ot;%s", host);
}
-
}

= void
link_socket_connection_initiated(struct link_socket_= info *info,
- = const struct link_socket_actual *act,
- con= st char *common_name,

+ const struct link_socket_actual *act, co= nst char *common_name,
st= ruct env_set *es)
{
struct gc_arena g= c =3D gc_new();
@@ -2489,7 +2336,8 @@
= {
buf_printf(&out, "[%s] ", = common_name);
}
- buf_printf(&out, "Peer Connection Initi= ated with %s", print_link_socket_actual(&info->lsa->actual, = &gc));
+ b= uf_printf(&out, "Peer Connection Initiated with %s",+ print_lin= k_socket_actual(&info->lsa->actual, &gc));
= msg(M_INFO, "%s", BSTR(&out));
}<= /span>

@@ -2501,7 +2349,8 @@
= {
struct argv argv =3D argv_new();
ipchange_fmt(false, &argv, info, &gc);

- if (plugin_call(info->plugi= ns, OPENVPN_PLUGIN_IPCHANGE, &argv, NULL, es) !=3D OPENVPN_PLUGIN_FUNC_= SUCCESS)
+ if = (plugin_call(info->plugins, OPENVPN_PLUGIN_IPCHANGE, &argv, NULL, es= )
+ !=3D O= PENVPN_PLUGIN_FUNC_SUCCESS)
{
= msg(M_WARN, "WARNING: ipchange plugin call failed");
}
@@ -2522,8 +2371,7 @@
}


void
-link_socket_bad_incoming_addr(struct buffer *buf,
- = const struct link_socket_info *info,
+link_socket_bad_incoming_addr(struct buffer *buf, c= onst struct link_socket_info *info,
= const struct link_socket_actual *from_addr)
{
struct gc_arena gc =3D gc_new();
@@ -2535,= 8 +2383,7 @@
case AF_INET6:
= msg(D_LINK_ERRORS,
"TCP/UDP: I= ncoming packet rejected from %s[%d], expected peer address: %s (allow this = incoming source address/port by removing --remote or adding --float)",=
- print= _link_socket_actual(from_addr, &gc),
- (int)from_addr->dest.addr.sa.sa_famil= y,
+ p= rint_link_socket_actual(from_addr, &gc), (int)from_addr->dest.addr.s= a.sa_family,
print_sockaddr_ex(info->ls= a->remote_list->ai_addr, ":", PS_SHOW_PORT, &gc));
/* print additional remote addresses */
= for (ai =3D info->lsa->remote_list->ai_next; ai= ; ai =3D ai->ai_next)
@@ -2561,16 +2408,16 @@
= {
const struct link_socket_addr *lsa =3D info-&= gt;lsa;

-/*
- * This logic s= upports "redirect-gateway" semantic, which
- * makes sense only for PF_INET routes over= PF_INET endpoints
- *<= /span>
- * Maybe in the future= consider PF_INET6 endpoints also ...
- * by now just ignore it
- *
-= * For --remote entries with multiple addresses this
- * only return the actual endpoint we have = successfully connected to
- */
+ /*
+ * This logic support= s "redirect-gateway" semantic, which
+ * makes sense only for PF_INET routes over = PF_INET endpoints
+ = *
+ * Maybe in= the future consider PF_INET6 endpoints also ...
+ * by now just ignore it
+ *
+ * For --remote entries with multiple addresse= s this
+ * only r= eturn the actual endpoint we have successfully connected to
+ */

if (ls= a->actual.dest.addr.sa.sa_family !=3D AF_INET)
{
return IPV4_INVALID_ADDR;
@@ -2582,8= +2429,7 @@
}
else if (lsa->cu= rrent_remote)
{
- return ntohl(((struct sockaddr_in *)lsa->current_= remote->ai_addr)
- = ->sin_addr.s_addr);
+ return ntohl(((struct sockaddr_in *)lsa->c= urrent_remote->ai_addr)->sin_addr.s_addr);
}
else
{
@@ -2596,12 += 2442,12 @@
{
const struct link_socket= _addr *lsa =3D info->lsa;

-/* This logic supports "redirect-gateway"= ; semantic,
- * for PF_= INET6 routes over PF_INET6 endpoints
- *
- * F= or --remote entries with multiple addresses this
- * only return the actual endpoint we have succe= ssfully connected to
- = */
+ /* This logic= supports "redirect-gateway" semantic,
+ * for PF_INET6 routes over PF_INET6 endpo= ints
+ *+ * For --remote entries = with multiple addresses this
+ * only return the actual endpoint we have successfully connec= ted to
+ */
if (lsa->actual.dest.addr.sa.sa_family !=3D AF_INET6)
{
return NULL;
= @@ -2632,20 +2478,16 @@
{
if = (rwflags & EVENT_READ)
{
- buf_printf(&out, "S%s&= quot;,
- = (s->rwflags_debug & EVENT_READ) ? "R" : "r&qu= ot;);
+ bu= f_printf(&out, "S%s", (s->rwflags_debug & EVENT_READ) = ? "R" : "r");
#ifdef _WIN32
= - buf_printf(&out,= "%s",
- = overlapped_io_state_ascii(&s->reads));
<= span style=3D"color: hsl(120, 100%, 40%);">+ buf_printf(&out= , "%s", overlapped_io_state_ascii(&s->reads));

<= span> #endif

}
if (rwflag= s & EVENT_WRITE)
{
- buf_printf(&out, "S%s",=
- = (s->rwflags_debug & EVENT_WRITE) ? "W" : "w");=
+ buf_pri= ntf(&out, "S%s", (s->rwflags_debug & EVENT_WRITE) ? &q= uot;W" : "w");
#ifdef _WIN32
- buf_printf(&out, &qu= ot;%s",

- = overlapped_io_state_ascii(&s->writes));
+ buf_printf(&out, &= quot;%s", overlapped_io_state_ascii(&s->writes));

#endif

}
}
@@ -2672,9 +2514,7 @@

}

static void

-stream_= buf_init(struct stream_buf *sb,
- struct buffer *buf,
- const unsigned int sockflags,
+stream_buf_init(struct st= ream_buf *sb, struct buffer *buf, const unsigned int sockflags,
<= span> const int proto)

{
= sb->buf_init =3D *buf;
@@ -2683,9 +2523,8 @@<= br> sb->residual =3D alloc_buf(sb->maxlen);
sb->error =3D false;

#if PORT_SHARE
- sb->port_share_state =3D ((s= ockflags & SF_PORT_SHARE) && (proto =3D=3D PROTO_TCP_SERVER))
- = ? PS_ENABLED
- = : PS_DISABLED;
+ sb->port_share_state =3D
+ ((sockflags & SF_PORT_SHARE) &= & (proto =3D=3D PROTO_TCP_SERVER)) ? PS_ENABLED : PS_DISABLED; #endif
stream_buf_reset(sb);
=
@@ -2700,9 +2539,7 @@
sb->next.of= fset =3D sb->buf.offset + sb->buf.len;
sb->ne= xt.len =3D (sb->len >=3D 0 ? sb->len : sb->maxlen) - sb->buf= .len;
dmsg(D_STREAM_DEBUG, "STREAM: SET NEXT, buf= =3D[%d,%d] next=3D[%d,%d] len=3D%d maxlen=3D%d",
- sb->buf.offset, sb->buf.len,=
- sb->next.= offset, sb->next.len,
+ sb->buf.offset, sb->buf.len, sb->next= .offset, sb->next.len, sb->len, sb->maxlen);
= ASSERT(sb->next.len > 0);
ASSERT(buf_safe(&s= b->buf, sb->next.len));
}
@@ -2710,8= +2547,7 @@
static inline void
stream_buf= _get_final(struct stream_buf *sb, struct buffer *buf)
{
- dmsg(D_STREAM_DEBUG,= "STREAM: GET FINAL len=3D%d",
- buf_defined(&sb->buf) ? sb->buf.len := -1);
+ dmsg(D_STR= EAM_DEBUG, "STREAM: GET FINAL len=3D%d", buf_defined(&sb->= buf) ? sb->buf.len : -1);
ASSERT(buf_defined(&s= b->buf));
*buf =3D sb->buf;
}
@@ -2719,8 +2555,7 @@
static inline void
stream_buf_get_next(struct stream_buf *sb, struct buffer *bu= f)
{
-= dmsg(D_STREAM_DEBUG, "STREAM: GET NEXT len=3D%d",
<= span style=3D"color: hsl(0, 100%, 40%);">- buf_defined(&sb->= next) ? sb->next.len : -1);

+ dmsg(D_STREAM_DEBUG, "STREAM: GET NEXT len=3D%d", = buf_defined(&sb->next) ? sb->next.len : -1);
= ASSERT(buf_defined(&sb->next));
*buf =3D sb-&g= t;next;
}
@@ -2734,8 +2569,7 @@
= ASSERT(buf_init(&sock->stream_buf.residual, 0));
sock->stream_buf.residual_fully_formed =3D stream_b= uf_added(&sock->stream_buf, 0);
dmsg(D_STRE= AM_DEBUG, "STREAM: RESIDUAL FULLY FORMED [%s], len=3D%d",<= br>- sock->stream_= buf.residual_fully_formed ? "YES" : "NO",
- sock->stream_buf.re= sidual.len);

+ = sock->stream_buf.residual_fully_formed ? "YES" : "N= O", sock->stream_buf.residual.len);
}
if (!sock->stream_buf.residual_fully_form= ed)
@@ -2746,8 +2580,7 @@
}

static bool
-stream_buf_added(struct stream_buf *sb,
- int length_added)
<= span style=3D"color: hsl(120, 100%, 40%);">+stream_buf_added(struct stream_= buf *sb, int length_added)

{
dmsg(D_S= TREAM_DEBUG, "STREAM: ADD length_added=3D%d", length_added);
if (length_added > 0)
@@ -2757,7 +2590,= 7 @@

/* if length unknown, see if we= can get the length prefix from
* the head of the buf= fer */
- if (sb->= len < 0 && sb->buf.len >=3D (int) sizeof(packet_size_type)= )
+ if (sb->len= < 0 && sb->buf.len >=3D (int)sizeof(packet_size_type))
{
packet_size_type net_size;

@@ -2783,7 +2616,9 @@

if (sb->len < 1 || sb->len > sb->maxle= n)
{
- msg(M_WARN, "WARNING: Bad encapsulated packet leng= th from peer (%d), which must be > 0 and <=3D %d -- please ensure tha= t --tun-mtu or --link-mtu is equal on both peers -- this condition could al= so indicate a possible active attack on the TCP link -- [Attempting restart= ...]", sb->len, sb->maxlen);
+ msg(M_WARN,
+ "WARNING: Bad encapsulated pac= ket length from peer (%d), which must be > 0 and <=3D %d -- please en= sure that --tun-mtu or --link-mtu is equal on both peers -- this condition = could also indicate a possible active attack on the TCP link -- [Attempting= restart...]",
+= sb->len, sb->maxlen);
st= ream_buf_reset(sb);
sb->error =3D true;
return false;
@@ -2800,8 +2635,7 = @@
ASSERT(buf_copy_excess(&sb->residual= , &sb->buf, sb->len));
}
dmsg(D_STREAM_DEBUG, "STREAM: ADD returned TRUE, buf_len=3D%= d, residual_len=3D%d",

- BLEN(&sb->buf),
- BLEN(&sb->residual));
+ BLEN(&sb->buf= ), BLEN(&sb->residual));

return true;
}
else
@@ -2832,7 +266= 6,7 @@
init_net_event_win32(&s->listen_hand= le, FD_ACCEPT, s->sd, 0);
}
re= turn &s->listen_handle;
-#else /* ifdef _WIN32 */
+#else /* ifdef _WIN32 */
return s->s= d;
#endif
}
@@ -2842,9 +2= 676,7 @@
*/

const char= *
-print_sockaddr_ex(c= onst struct sockaddr *sa,
- const char *separator,
- const unsigned int flags,+print_sockaddr_ex(const stru= ct sockaddr *sa, const char *separator, const unsigned int flags, struct gc_arena *gc)
{ struct buffer out =3D alloc_buf_gc(128, gc);
@@= -2862,7 +2694,7 @@
buf_puts(&out, &qu= ot;[AF_INET]");
}
= salen =3D sizeof(struct sockaddr_in);
- addr_is_defined =3D ((struct sockaddr_in = *) sa)->sin_addr.s_addr !=3D 0;
+ addr_is_defined =3D ((struct sockaddr_in *)sa)-&= gt;sin_addr.s_addr !=3D 0;
break;

case AF_INET6:
@@ -2871,7 +2= 703,7 @@
buf_puts(&out, "[AF_INET= 6]");
}
sale= n =3D sizeof(struct sockaddr_in6);
- addr_is_defined =3D !IN6_IS_ADDR_UNSPECIFIED(&= ((struct sockaddr_in6 *) sa)->sin6_addr);
+ addr_is_defined =3D !IN6_IS_ADDR_UNSPE= CIFIED(&((struct sockaddr_in6 *)sa)->sin6_addr);
= break;

case AF_UNSPEC:=
@@ -2888,10 +2720,10 @@
ASSER= T(0);
}

- status =3D getnameinfo(sa, salen, hostaddr, si= zeof(hostaddr),
- = servname, sizeof(servname), NI_NUMERICHOST | NI_NUMERICS= ERV);
+ status =3D= getnameinfo(sa, salen, hostaddr, sizeof(hostaddr), servname, sizeof(servna= me),
+ = NI_NUMERICHOST | NI_NUMERICSERV);

- if (status!=3D0)

+ if (status !=3D 0)

<= span> {

buf_printf(&out, "[nameinfo()= err: %s]", gai_strerror(status));
return BST= R(&out);
@@ -2925,7 +2757,7 @@
const c= har *
print_link_socket_actual(const struct link_socket_ac= tual *act, struct gc_arena *gc)
{
- return print_link_socket_actual_ex(act, &q= uot;:", PS_SHOW_PORT|PS_SHOW_PKTINFO, gc);
+ return print_link_socket_actual_ex(act, &qu= ot;:", PS_SHOW_PORT | PS_SHOW_PKTINFO, gc);
}<= br>
#ifndef IF_NAMESIZE
@@ -2933,10= +2765,8 @@
#endif

cons= t char *
-print_link_so= cket_actual_ex(const struct link_socket_actual *act,
- const char *sep= arator,
- = const unsigned int flags,
- struct gc_arena *gc)+print_link_socket_actual_ex(= const struct link_socket_actual *act, const char *separator,
+ const = unsigned int flags, struct gc_arena *gc)

{
if (act)

{
@@ -2960,12 +2790,11 = @@
#elif defined(IP_RECVDSTADDR)
= sa.addr.in4.sin_addr =3D act->pi.in4;
= ifname[0] =3D 0;
-#else /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI= _SPEC_DST) */
+#else = /* if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */
#error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_REC= VDSTADDR (fix syshead.h)
#endif
= buf_printf(&out, " (via %s%%%s)",
- print_s= ockaddr_ex(&sa.addr.sa, separator, 0, gc),
- ifname);
= + = print_sockaddr_ex(&sa.addr.sa, separator, 0, gc), ifname);
<= span> }

break;
<= span>

@@ -2977,8 +2806,9 @@
= sin6.sin6_family =3D AF_INET6;
= sin6.sin6_addr =3D act->pi.in6.ipi6_addr;
= if_indextoname(act->pi.in6.ipi6_ifindex, ifname);
- if (getnameinfo((= struct sockaddr *)&sin6, sizeof(struct sockaddr_in6),

- buf= , sizeof(buf), NULL, 0, NI_NUMERICHOST) =3D=3D 0)
+ if (getnameinfo((struct s= ockaddr *)&sin6, sizeof(struct sockaddr_in6), buf,
+ size= of(buf), NULL, 0, NI_NUMERICHOST)
+ =3D=3D 0)
= {
buf_printf(&out, &= quot; (via %s%%%s)", buf, ifname);
= }
@@ -3028,8 +2858,7 @@
{
char *out =3D gc_malloc(INET6_ADDRSTRLEN, true, gc);


- if (memcmp(&= ;a6, &in6addr_any, sizeof(a6)) !=3D 0
- || !(flags & IA_EMPTY_IF_UNDEF))
= + if (memcmp(&a6, &i= n6addr_any, sizeof(a6)) !=3D 0 || !(flags & IA_EMPTY_IF_UNDEF))<= br> {
inet_ntop(AF_INET6, &a6, out, = INET6_ADDRSTRLEN);
}
@@ -3051,30 +2880= ,31 @@
* (add in steps of 8 bits, taking overflow into ne= xt round)
*/
struct in6_addr
<= span style=3D"color: hsl(0, 100%, 40%);">-add_in6_addr( struct in6_addr bas= e, uint32_t add )

+ad= d_in6_addr(struct in6_addr base, uint32_t add)
{ int i;

- for (i =3D 15; i>=3D0 && add > 0; i--)
+ for (i =3D 15; i &g= t;=3D 0 && add > 0; i--)
{
= register int carry;
register uint32_t h;<= /span>

- = h =3D (unsigned char) base.s6_addr[i];
- base.s6_addr[i] =3D (h+add) & UINT8_MAX;
+ h =3D (unsign= ed char)base.s6_addr[i];
+ base.s6_addr[i] =3D (h + add) & UINT8_MAX;

/* using explicit carry for the 8-bit additions= will catch
* 8-bit and(!) 32-bit overruns nicely=
*/
- carry =3D ((h & 0xff) + (add & 0xff)) >> 8;<= /span>
- add =3D (add&g= t;>8) + carry;
+ = carry =3D ((h & 0xff) + (add & 0xff)) >> 8;
<= span style=3D"color: hsl(120, 100%, 40%);">+ add =3D (add >> 8= ) + carry;

}
return base;<= br> }

/* set environmental variabl= es for ip/port in *addr */
void
-setenv_sockaddr(struct env_set *es, const char *= name_prefix, const struct openvpn_sockaddr *addr, const unsigned int flags)=
+setenv_sockaddr(str= uct env_set *es, const char *name_prefix, const struct openvpn_sockaddr *ad= dr,
+ = const unsigned int flags)
{
char name= _buf[256];

@@ -3102,11 +2932,10 @@=
break;

ca= se AF_INET6:
- = if (IN6_IS_ADDR_V4MAPPED( &addr->addr.in6.sin6_addr ))
= + if (IN6_IS_ADDR_V4= MAPPED(&addr->addr.in6.sin6_addr))
{
struct in_addr ia;
- memcpy(&ia.s_addr, &add= r->addr.in6.sin6_addr.s6_addr[12],
- sizeof(ia.s_addr));
+ memcpy(&ia.s_add= r, &addr->addr.in6.sin6_addr.s6_addr[12], sizeof(ia.s_addr));=
snprintf(name_buf, sizeof(name_buf), "%s_ip= ", name_prefix);
inet_ntop(AF_INET, &= amp;ia, buf, sizeof(buf));
}
@= @ -3127,7 +2956,8 @@
}

= void
-setenv_in_addr_t(= struct env_set *es, const char *name_prefix, in_addr_t addr, const unsigned= int flags)
+setenv_i= n_addr_t(struct env_set *es, const char *name_prefix, in_addr_t addr,
+ const un= signed int flags)
{
if (addr || !(fla= gs & SA_SET_IF_NONZERO))
{
@@ -314= 0,9 +2970,7 @@
}

void
-setenv_in6_addr(struct = env_set *es,
- = const char *name_prefix,
- const struct in6_addr *addr,
+setenv_in6_addr(struct env_set *es, cons= t char *name_prefix, const struct in6_addr *addr,
= const unsigned int flags)
{
i= f (!IN6_IS_ADDR_UNSPECIFIED(addr) || !(flags & SA_SET_IF_NONZERO))
@@ -3156,10 +2984,8 @@
}

void
-set= env_link_socket_actual(struct env_set *es,
- const char *name_prefix,
- = const struct link_socket_actual *act,
- const unsigned int flags)=
+setenv_link_socket_actual(= struct env_set *es, const char *name_prefix,
+ const struct link_socket= _actual *act, const unsigned int flags)
{
= setenv_sockaddr(es, name_prefix, &act->dest, flags);
= }
@@ -3168,7 +2994,8 @@
* Convert = protocol names between index and ascii form.
*/
-struct proto_= names {
+struct proto= _names
+{
<= span> const char *short_form;

const char *display_= form;
sa_family_t proto_af;
@@ -3177,2= 2 +3004,22 @@

/* Indexed by PROTO_x */
static const struct proto_names proto_names[] =3D {<= br>- {"proto-uninitialize= d", "proto-NONE", AF_UNSPEC, PROTO_NONE},
+ { "proto-uninitialized",= "proto-NONE", AF_UNSPEC, PROTO_NONE },
/* t= ry IPv4 and IPv6 (client), bind dual-stack (server) */
- {"udp", "UDP&qu= ot;, AF_UNSPEC, PROTO_UDP},
- {"tcp-server", "TCP_SERVER", AF_UNSPEC, PROT= O_TCP_SERVER},
- {&q= uot;tcp-client", "TCP_CLIENT", AF_UNSPEC, PROTO_TCP_CLIENT}= ,
- {"tcp"= , "TCP", AF_UNSPEC, PROTO_TCP},
+ { "udp", "UDP", AF_UN= SPEC, PROTO_UDP },
+ = { "tcp-server", "TCP_SERVER", AF_UNSPEC, PROTO_TCP_S= ERVER },
+ { "= ;tcp-client", "TCP_CLIENT", AF_UNSPEC, PROTO_TCP_CLIENT },
+ { "tcp"= , "TCP", AF_UNSPEC, PROTO_TCP },
/* force IP= v4 */
- {"udp4&= quot;, "UDPv4", AF_INET, PROTO_UDP},
- {"tcp4-server", "TCPv4_S= ERVER", AF_INET, PROTO_TCP_SERVER},
- {"tcp4-client", "TCPv4_CLIENT", = AF_INET, PROTO_TCP_CLIENT},
- {"tcp4", "TCPv4", AF_INET, PROTO_TCP},=
+ { "udp4&qu= ot;, "UDPv4", AF_INET, PROTO_UDP },
+ { "tcp4-server", "TCPv4_SERVER= ", AF_INET, PROTO_TCP_SERVER },
+ { "tcp4-client", "TCPv4_CLIENT", A= F_INET, PROTO_TCP_CLIENT },
+ { "tcp4", "TCPv4", AF_INET, PROTO_TCP },
/* force IPv6 */
- {"udp6", "UDPv6", AF_INET6, PR= OTO_UDP},
- {"t= cp6-server", "TCPv6_SERVER", AF_INET6, PROTO_TCP_SERVER},
- {"tcp6-client&q= uot;, "TCPv6_CLIENT", AF_INET6, PROTO_TCP_CLIENT},
- {"tcp6", "= TCPv6", AF_INET6, PROTO_TCP},

+ { "udp6", "UDPv6", AF_INET6, PROTO_U= DP },
+ { "tc= p6-server", "TCPv6_SERVER", AF_INET6, PROTO_TCP_SERVER },
+ { "tcp6-clien= t", "TCPv6_CLIENT", AF_INET6, PROTO_TCP_CLIENT },
= + { "tcp6", "= TCPv6", AF_INET6, PROTO_TCP },
};

int
@@ -3263,9 +3090,11 @@
= {
switch (af)
{
- case AF_INET: return "AF= _INET";
+ = case AF_INET:
+ = return "AF_INET";

- case AF_INET6: return "AF_INET= 6";
+ cas= e AF_INET6:
+ = return "AF_INET6";
}
= return "AF_UNSPEC";
}
@@ -3291= ,13 +3120,11 @@
return "UDPv4"; }

- if ( (remote && proto =3D=3D PROTO_TCP_CLIENT)
- || (!remote &&= amp; proto =3D=3D PROTO_TCP_SERVER))
+ if ((remote && proto =3D=3D PROTO_TCP_CLIENT) = || (!remote && proto =3D=3D PROTO_TCP_SERVER))
= {
return "TCPv4_SERVER";
}

- if ( (rem= ote && proto =3D=3D PROTO_TCP_SERVER)
- || (!remote && proto =3D=3D PROTO_= TCP_CLIENT))
+ if = ((remote && proto =3D=3D PROTO_TCP_SERVER) || (!remote && p= roto =3D=3D PROTO_TCP_CLIENT))
{
= return "TCPv4_CLIENT";
}
@@ -3313,9 +3140,9 @@

void
bad_address_l= ength(int actual, int expected)
{
- msg(M_FATAL, "ERROR: received strange= incoming packet with an address length of %d -- we only accept address len= gths of %d.",
- = actual,
- e= xpected);
+ msg(M_= FATAL,
+ "= ;ERROR: received strange incoming packet with an address length of %d -- we= only accept address lengths of %d.",
+ actual, expected);
}=

/*
@@ -3323,8 +3150,7 @@
*/

int
-link_socket_read_tcp(struct link_socket *s= ock,
- = struct buffer *buf)
+link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)
{
int len =3D 0;
=
@@ -3337,9 +3163,9 @@
*/
if (sock->sd =3D=3D SOCKET_UNDEFINED)

= {
- msg(M_= INFO, "BUG: link_socket_read_tcp(): sock->sd=3D=3D-1, reset client = instance" );
- = sock->stream_reset =3D true; /* reset client instan= ce */
- retu= rn buf->len =3D 0; /* nothing to read */
+ msg(M_INFO, "BU= G: link_socket_read_tcp(): sock->sd=3D=3D-1, reset client instance"= );

+ sock-= >stream_reset =3D true; /* reset client instance */
+ return buf->len =3D 0; = /* nothing to read */
}

#ifdef _WIN32
@@ -3382,24 +3208,23 @@ * both IPv4 and IPv6 destination addresses, plus padding (see RFC= 2292)
*/
#if defined(HAVE_IN_PKTINFO) &= amp;& defined(HAVE_IPI_SPEC_DST)
-#define PKTINFO_BUF_SIZE max_int( CMSG_SPACE(sizeof(struct i= n6_pktinfo)), \
- = CMSG_SPACE(sizeof(struct in_pktinfo)) )<= br>+#define PKTINFO_BUF_SIZE \<= /span>
+ max_int(CMSG_SPA= CE(sizeof(struct in6_pktinfo)), CMSG_SPACE(sizeof(struct in_pktinfo)))
#else
-#de= fine PKTINFO_BUF_SIZE max_int( CMSG_SPACE(sizeof(struct in6_pktinfo)), \
- = CMSG_SPACE(sizeof(struct in_addr)) )
+#define PKTINFO_BUF_SIZE \
+ max_int(CMSG_SPACE(sizeof(struct in6_= pktinfo)), CMSG_SPACE(sizeof(struct in_addr)))
#endif

static socklen_t
-link_socket_read_udp_posix_recvmsg(struct link_so= cket *sock,
- = struct buffer *buf,
+link_socket_read_udp_posix_recvmsg(struct link_soc= ket *sock, struct buffer *buf,
= struct link_socket_actual *from)
{
struct iovec iov;

uint8_t pktinfo_buf[PKTINFO_BU= F_SIZE];
- struct ms= ghdr mesg =3D {0};
+ = struct msghdr mesg =3D { 0 };
socklen_t fromlen =3D= sizeof(from->dest.addr);

- ASSERT(sock->sd >=3D 0); = /* can't happen */
+ ASSERT(sock->sd >=3D 0); /* can't happen */
iov.iov_base =3D BPTR(buf);
= iov.iov_len =3D buf_forward_capacity_total(buf);
@@ -3= 415,43 +3240,40 @@
struct cmsghdr *cmsg; fromlen =3D mesg.msg_namelen;
cmsg= =3D CMSG_FIRSTHDR(&mesg);
- if (cmsg !=3D NULL
- && CMSG_NXTHDR(&mesg, cmsg) =3D=3D NU= LL
+ if (cmsg = !=3D NULL && CMSG_NXTHDR(&mesg, cmsg) =3D=3D NULL
#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
- && cms= g->cmsg_level =3D=3D SOL_IP
- && cmsg->cmsg_type =3D=3D IP_PKTINFO=
- && cmsg-= >cmsg_len >=3D CMSG_LEN(sizeof(struct in_pktinfo)) )
+ && cmsg->cmsg= _level =3D=3D SOL_IP && cmsg->cmsg_type =3D=3D IP_PKTINFO=
+ && cms= g->cmsg_len >=3D CMSG_LEN(sizeof(struct in_pktinfo)))
#elif defined(IP_RECVDSTADDR)

- && cmsg->cmsg_level =3D=3D IPPROTO_IP
- && cms= g->cmsg_type =3D=3D IP_RECVDSTADDR
- && cmsg->cmsg_len >=3D CMSG_LEN(s= izeof(struct in_addr)) )
+ &= amp;& cmsg->cmsg_level =3D=3D IPPROTO_IP && cmsg->cmsg_ty= pe =3D=3D IP_RECVDSTADDR
+ && cmsg->cmsg_len >=3D CMSG_LEN(sizeof(struc= t in_addr)))
+#else /= * if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */
#error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECV= DSTADDR (fix syshead.h)
#endif
{<= /span>
#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_S= PEC_DST)
- s= truct in_pktinfo *pkti =3D (struct in_pktinfo *) CMSG_DATA(cmsg);+ struct in_pktinfo= *pkti =3D (struct in_pktinfo *)CMSG_DATA(cmsg);
= from->pi.in4.ipi_ifindex =3D pkti->ipi_ifindex;
= from->pi.in4.ipi_spec_dst =3D pkti->ipi_spec_dst; #elif defined(IP_RECVDSTADDR)
- from->pi.in4 =3D *(struct in_addr *) CMSG_D= ATA(cmsg);
-#else /* i= f defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */<= br>+ from->pi.in4= =3D *(struct in_addr *)CMSG_DATA(cmsg);
+#else /* if defined(HAVE_IN_PKTINFO) && define= d(HAVE_IPI_SPEC_DST) */
#error ENABLE_IP_PKTINFO is set wi= thout IP_PKTINFO xor IP_RECVDSTADDR (fix syshead.h)
#endif=
}
- else if (cmsg !=3D NULL
- && CMSG_NXTHDR(&mesg, cmsg) = =3D=3D NULL
- = && cmsg->cmsg_level =3D=3D IPPROTO_IPV6
- && cmsg->cm= sg_type =3D=3D IPV6_PKTINFO
- && cmsg->cmsg_len >=3D CMSG_LEN(sizeof= (struct in6_pktinfo)) )
+ else if (cmsg !=3D NULL && CMSG_NXTHDR(&mesg, cmsg)= =3D=3D NULL
+ = && cmsg->cmsg_level =3D=3D IPPROTO_IPV6 && cms= g->cmsg_type =3D=3D IPV6_PKTINFO
+ && cmsg->cmsg_len >=3D CMSG_= LEN(sizeof(struct in6_pktinfo)))
{
- struct in6_pktinfo *pkti6= =3D (struct in6_pktinfo *) CMSG_DATA(cmsg);

+ struct in6_pktinfo *pkti6 =3D (struct = in6_pktinfo *)CMSG_DATA(cmsg);
from->pi.in6= .ipi6_ifindex =3D pkti6->ipi6_ifindex;
from= ->pi.in6.ipi6_addr =3D pkti6->ipi6_addr;
}
else if (cmsg !=3D NULL)
{=
- msg(M_WAR= N, "CMSG received that cannot be parsed (cmsg_level=3D%d, cmsg_type=3D= %d, cmsg=3Dlen=3D%d)", (int)cmsg->cmsg_level, (int)cmsg->cmsg_ty= pe, (int)cmsg->cmsg_len );
+ msg(M_WARN,
+ "CMSG received that cannot be parsed (cm= sg_level=3D%d, cmsg_type=3D%d, cmsg=3Dlen=3D%d)",
+ (int)cmsg->cmsg_level= , (int)cmsg->cmsg_type, (int)cmsg->cmsg_len);
= }
}

@@ -3460,15 +3= 282,14 @@
#endif /* if ENABLE_IP_PKTINFO */

int
- struct buffer = *buf,
+link_socket_re= ad_udp_posix(struct link_socket *sock, struct buffer *buf,
= struct link_socket_actual *from)
{

socklen_t fromlen =3D sizeof(from->dest.addr);=
socklen_t expectedlen =3D af_addr_size(sock->info.= af);
addr_zero_host(&from->dest);

- ASSERT(sock-&= gt;sd >=3D 0); /* can't happen */
+ ASSERT(sock->sd >=3D 0)= ; /* can't happen */


#if ENABLE_IP_P= KTINFO
/* Both PROTO_UDPv4 and PROTO_UDPv6 */@@ -3479,8 +3300,8 @@
else
#e= ndif
{
- buf->len =3D recvfrom(sock->sd, BPTR(buf), buf_forward_= capacity(buf), 0,
- = &from->dest.addr.sa, &fromlen);+ buf->len =3D recv= from(sock->sd, BPTR(buf), buf_forward_capacity(buf), 0, &from->de= st.addr.sa,
+ = &fromlen);
}
= /* FIXME: won't do anything when sock->info.af =3D=3D AF_UNSPEC = */
if (buf->len >=3D 0 && expectedlen &a= mp;& fromlen !=3D expectedlen)
@@ -3497,9 +3318,7 @@
*/

ssize_t
-link_socket_write_tcp(struct link_s= ocket *sock,

- = struct buffer *buf,
- struct link_socket_actual *to)
<= span style=3D"color: hsl(120, 100%, 40%);">+link_socket_write_tcp(struct li= nk_socket *sock, struct buffer *buf, struct link_socket_actual *to)
<= br> {
packet_size_type len =3D BLEN(buf);=
dmsg(D_STREAM_DEBUG, "STREAM: WRITE %d offset=3D%d"= ;, (int)len, buf->offset);
@@ -3516,8 +3335,7 @@<= br> #if ENABLE_IP_PKTINFO

ssize_t<= /span>
-link_socket_write_udp_= posix_sendmsg(struct link_socket *sock,
- struct buffer *buf,
+link_socket_write_udp= _posix_sendmsg(struct link_socket *sock, struct buffer *buf,
struct link_socket_actual *to)
{
struct iovec iov;
@@ -35= 45,19 +3363,19 @@
cmsg->cmsg_type =3D IP_PK= TINFO;
{
stru= ct in_pktinfo *pkti;
- = pkti =3D (struct in_pktinfo *) CMSG_DATA(cmsg);
+ pkti =3D (struct= in_pktinfo *)CMSG_DATA(cmsg);

pkti->ip= i_ifindex =3D to->pi.in4.ipi_ifindex;
p= kti->ipi_spec_dst =3D to->pi.in4.ipi_spec_dst;
= pkti->ipi_addr.s_addr =3D 0;
}
#elif defined(IP_RECVDSTADDR)
- ASSERT( CMSG_SPACE(sizeof(struct in_add= r)) <=3D sizeof(pktinfo_buf) );
+ ASSERT(CMSG_SPACE(sizeof(struct in_addr)) <= =3D sizeof(pktinfo_buf));
mesg.msg_controllen = =3D CMSG_SPACE(sizeof(struct in_addr));
cmsg = =3D CMSG_FIRSTHDR(&mesg);
cmsg->cmsg_le= n =3D CMSG_LEN(sizeof(struct in_addr));
cmsg-&= gt;cmsg_level =3D IPPROTO_IP;
cmsg->cmsg_ty= pe =3D IP_RECVDSTADDR;
= - *(struct in_addr *) CMSG_DATA(cmsg) =3D to->pi.in4;<= br>+ *(struct in_add= r *)CMSG_DATA(cmsg) =3D to->pi.in4;
#else /* if define= d(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) */
#error ENABLE_IP_PKTINFO is set without IP_PKTINFO xor IP_RECVDSTADDR (fi= x syshead.h)

#endif /* if defined(HAVE_IN_PKTINFO) &&a= mp; defined(HAVE_IPI_SPEC_DST) */
@@ -3570,7 +3388,7 @@
mesg.msg_name =3D &to->dest.addr.sa;
mesg.msg_namelen =3D sizeof(struct sockaddr_in6);

- = ASSERT( CMSG_SPACE(sizeof(struct in6_pktinfo)) <=3D sizeof(pktinf= o_buf) );
+ = ASSERT(CMSG_SPACE(sizeof(struct in6_pktinfo)) <=3D sizeof(pktinfo_buf)= );
mesg.msg_control =3D pktinfo_buf; mesg.msg_controllen =3D CMSG_SPACE(sizeof(struct in6_pk= tinfo));
mesg.msg_flags =3D 0;
@@ -3579,13 +3397,14 @@

cmsg->cmsg_level = =3D IPPROTO_IPV6;
cmsg->cmsg_type =3D IPV6_= PKTINFO;

- pkti6 =3D (struct in6_pktinfo *) CMSG_DATA(cmsg);+ pkti6 =3D (struc= t in6_pktinfo *)CMSG_DATA(cmsg);
pkti6->ipi= 6_ifindex =3D to->pi.in6.ipi6_ifindex;
pkti= 6->ipi6_addr =3D to->pi.in6.ipi6_addr;
b= reak;
}

- default: ASSERT(0);
+ default:
+ ASSERT(0);
= }
return sendmsg(sock->sd, &mesg, 0);=
}
@@ -3644,8 +3463,8 @@
=
if (socket_is_dco_win(sock))
{<= /span>
- status =3D= ReadFile((HANDLE)sock->sd, wsabuf[0].buf, wsabuf[0].len,
- &s= ock->reads.size, &sock->reads.overlapped);

+ status =3D ReadFile((HANDLE)s= ock->sd, wsabuf[0].buf, wsabuf[0].len, &sock->reads.size,<= br>+ = &sock->reads.overlapped);
/* Readfil= e status is inverted from WSARecv */
status = =3D !status;
}
@@ -3653,28 +3472,1= 5 @@
{
sock->reads= .addr_defined =3D true;
sock->reads.addrlen= =3D sizeof(sock->reads.addr6);
- status =3D WSARecvFrom(
- sock->sd,
- wsabuf,
- 1,
- &sock->reads.size,<= /span>
- &s= ock->reads.flags,
- = (struct sockaddr *) &sock->reads.addr,
- &sock->reads.= addrlen,

- = &sock->reads.overlapped,
- NULL);
+ status =3D WSARecvFrom(sock->sd, wsabuf, 1, = &sock->reads.size, &sock->reads.flags,
+ (struct = sockaddr *)&sock->reads.addr, &sock->reads.addrlen,+ = &sock->reads.overlapped, NULL);
}
else if (proto_is_tcp(sock->info.proto))
<= span> {

sock->reads.addr_defined = =3D false;
- = status =3D WSARecv(
- = sock->sd,
- wsabuf,
- 1,
- &sock->reads.size,
- &sock->reads.flags,<= br>- &sock->= ;reads.overlapped,
- = NULL);
+= status =3D WSARecv(sock->sd, wsabuf, 1, &sock->reads.= size, &sock->reads.flags,
+ &sock->reads.overlapped, N= ULL);
}
else
{

@@ -3697,8 +3503,7 @@
= sock->reads.status =3D 0;

= dmsg(D_WIN32_IO, "WIN32 I/O: Socket Receive immediate return [= %d,%d]",
- = (int) wsabuf[0].len,
- (int) sock->reads.size);
+ (int)wsabuf[0].len, (int= )sock->reads.size);
}
= else
{
@@ -3707,8 +3512,7 @@
{
sock->reads.i= ostate =3D IOSTATE_QUEUED;
sock->reads.= status =3D status;
- = dmsg(D_WIN32_IO, "WIN32 I/O: Socket Receive queued [%d]&q= uot;,
- = (int) wsabuf[0].len);
+ dmsg(D_WIN32_IO, "WIN32 I/O: Socket Receive que= ued [%d]", (int)wsabuf[0].len);
}<= br> else /* error occurred */
= {
@@ -3716,8 +3520,7 @@
= ASSERT(SetEvent(sock->reads.overlapped.hEvent));
= sock->reads.iostate =3D IOSTATE_IMMEDIATE_RETURN;
sock->reads.status =3D status;

- dmsg(D_WIN32_IO, "WIN= 32 I/O: Socket Receive error [%d]: %s",
- (int) wsabuf[0].len,
= + dmsg(D_WIN32_I= O, "WIN32 I/O: Socket Receive error [%d]: %s", (int)wsabuf[0].len= ,
strerror_win32(status, &gc));
gc_free(&gc);
= }
@@ -3749,12 +3552,11 @@

<= span> if (socket_is_dco_win(sock))

{
- status =3D Writ= eFile((HANDLE)sock->sd, wsabuf[0].buf, wsabuf[0].len,
- &sock= ->writes.size, &sock->writes.overlapped);
+ status =3D WriteFile((HANDLE)= sock->sd, wsabuf[0].buf, wsabuf[0].len, &sock->writes.size,
+ = &sock->writes.overlapped);

= /* WriteFile status is inverted from WSASendTo */
status =3D !status;

-
}
else if = (proto_is_udp(sock->info.proto))
{
@@ -3771,30 +3573,17 @@

sock->write= s.addrlen =3D sizeof(sock->writes.addr);
}<= /span>

- = status =3D WSASendTo(
- sock->sd,
- wsabuf,
- 1,
- &sock->writes.size,
- sock->writes.flags,
- (struct= sockaddr *) &sock->writes.addr,
- sock->writes.addrlen,
- &sock->writes.o= verlapped,
- = NULL);
+ = status =3D WSASendTo(sock->sd, wsabuf, 1, &sock->writes.size,= sock->writes.flags,
+ (struct sockaddr *)&sock->writes.= addr, sock->writes.addrlen,
+ &sock->writes.overlapped, = NULL);
}
else if (proto_i= s_tcp(sock->info.proto))
{
= /* destination address for TCP writes was established on connectio= n initiation */
sock->writes.addr_defined = =3D false;

- status =3D WSASend(
- sock->sd,
- wsabuf,
- 1,
- &sock->writes.size,- sock->writes= .flags,
- = &sock->writes.overlapped,
- NULL);
+ status =3D WSASend(sock->sd, wsabuf, 1, &= ;sock->writes.size, sock->writes.flags,
+ &sock->writes= .overlapped, NULL);
}
els= e
{
@@ -3811,9 +3600,8 @@
sock->writes.status =3D 0;=

- = dmsg(D_WIN32_IO, "WIN32 I/O: Socket Send immediate return [%d,%d]&qu= ot;,
- = (int) wsabuf[0].len,
- = (int) sock->writes.size);
+ dmsg(D_WIN32_IO, "WIN32 I/O: Sock= et Send immediate return [%d,%d]", (int)wsabuf[0].len,
+ (int)sock->writ= es.size);

}
else {
@@ -3823,8 +3611,7 @@
= {
sock->writes.iostate =3D I= OSTATE_QUEUED;
sock->writes.status =3D = status;
- = dmsg(D_WIN32_IO, "WIN32 I/O: Socket Send queued [%d]",- (int) wsa= buf[0].len);
+ = dmsg(D_WIN32_IO, "WIN32 I/O: Socket Send queued [%d]", (= int)wsabuf[0].len);
}
= else /* error occurred */
{
@@ -3833,8 +3620,7 @@

sock->writes.i= ostate =3D IOSTATE_IMMEDIATE_RETURN;
sock-= >writes.status =3D status;

- dmsg(D_WIN32_IO, "WIN32 I/O:= Socket Send error [%d]: %s",
- (int) wsabuf[0].len,
+ dmsg(D_WIN32_IO, "W= IN32 I/O: Socket Send error [%d]: %s", (int)wsabuf[0].len,
<= span> strerror_win32(status, &gc));


gc_free(&gc);
@@ -= 3906,7 +3692,9 @@
sa_len =3D sizeof(struct soc= kaddr_in);
if (buf_len(buf) < sa_len)
{
- msg(M_FATAL, "ERROR: received incoming packet with= too short length of %d -- must be at least %d.", buf_len(buf), sa_len= );
+ m= sg(M_FATAL,
+ = "ERROR: received incoming packet with too short length of = %d -- must be at least %d.",
+ buf_len(buf), sa_len);
= }
memcpy(dst, sa, sa_len); buf_advance(buf, sa_len);
@@ -3916,14 = +3704,17 @@
sa_len =3D sizeof(struct sockaddr_= in6);
if (buf_len(buf) < sa_len)
= {
- = msg(M_FATAL, "ERROR: received incoming packet with too = short length of %d -- must be at least %d.", buf_len(buf), sa_len);
+ msg(M_= FATAL,
+ = "ERROR: received incoming packet with too short length of %d --= must be at least %d.",
+ buf_len(buf), sa_len);
= }
memcpy(dst, sa, sa_len);
buf_advance(buf, sa_len);

brea= k;

default:
- msg(M_FATAL, "ERROR: rece= ived incoming packet with invalid address family %d.", sa->sa_famil= y);
+ msg(= M_FATAL, "ERROR: received incoming packet with invalid address family = %d.",
+ = sa->sa_family);
}
return sa_len;
@@ -3931,9 +3722,7 @@
/* Returns the number of bytes successfully read = */
int
-sockethandle_finalize(sockethandle_t sh,
- struct overlapped_io *io,=
- struct= buffer *buf,
+socket= handle_finalize(sockethandle_t sh, struct overlapped_io *io, struct buffer = *buf,
struct link_socket_actual *fro= m)
{
int ret =3D -1;
= @@ -4026,10 +3815,7 @@
*/

unsigned int

-socke= t_set(struct link_socket *s,
- struct event_set *es,
- unsigned int rwflags,
- void *arg,
+socket_set(struct link_socket *s, struct eve= nt_set *es, unsigned int rwflags, void *arg,
un= signed int *persistent)
{
if (s)
@@ -4109,20 +3895,15 @@
}

void
-so= cket_bind_unix(socket_descriptor_t sd,
- struct sockaddr_un *local,
- const char *prefix)=

+socket_bind_unix(so= cket_descriptor_t sd, struct sockaddr_un *local, const char *prefix)=
{
struct gc_arena gc =3D gc_new(); const mode_t orig_umask =3D umask(0);
=
- if (bind(sd, (struct soc= kaddr *) local, sizeof(struct sockaddr_un)))
+ if (bind(sd, (struct sockaddr *)local, sizeof(= struct sockaddr_un)))
{
- msg(M_FATAL | M_ERRNO,
- "%s: Socket bind[%d] faile= d on unix domain socket %s",
- prefix,
- (int)sd,
- sockaddr_unix_name(local, "NULL"));+ msg(M_FATAL | M_ERRN= O, "%s: Socket bind[%d] failed on unix domain socket %s", prefix,=
+ (int)sd= , sockaddr_unix_name(local, "NULL"));
}

umask(orig_umask);
@@ -4= 130,14 +3911,13 @@
}

so= cket_descriptor_t
-sock= et_accept_unix(socket_descriptor_t sd,
- struct sockaddr_un *remote)
<= span style=3D"color: hsl(120, 100%, 40%);">+socket_accept_unix(socket_descr= iptor_t sd, struct sockaddr_un *remote)

{
= socklen_t remote_len =3D sizeof(struct sockaddr_un);
= socket_descriptor_t ret;

CLEAR(*= remote);
- ret =3D a= ccept(sd, (struct sockaddr *) remote, &remote_len);
+ ret =3D accept(sd, (struct sockaddr= *)remote, &remote_len);
if (ret >=3D 0)=
{
/* set socket file descriptor to = not pass across execs, so that
@@ -4148,10 +3928,9 @@
}

int
-socket_connect_unix(socket_descriptor_t sd,=
- s= truct sockaddr_un *remote)
+socket_connect_unix(socket_descriptor_t sd, struct sockaddr_un *remo= te)
{
= - int status =3D connect(sd, (struct sockaddr *) remote, sizeof(struct s= ockaddr_un));
+ in= t status =3D connect(sd, (struct sockaddr *)remote, sizeof(struct sockaddr_= un));
if (status)
{
status =3D openvpn_errno();

diff --git a/src/op= envpn/socket.h b/src/openvpn/socket.h
index 6d71e83..f3f104= e 100644
--- a/src/openvpn/socket.h
+++ b/s= rc/openvpn/socket.h
@@ -65,7 +65,8 @@
stru= ct openvpn_sockaddr
{
/*int dummy;*/ = /* add offset to force a bug if sa not explicitly dereferenced */- union {
+ union
+ {
struct sockaddr sa= ;
struct sockaddr_in in4;
= struct sockaddr_in6 in6;
@@ -73,7 +74,8 @@
};


/* struct to hold preresolved host = names */
-struct cached= _dns_entry {
+struct = cached_dns_entry
+{
const char *hostname;
const char *= servname;
int ai_family;
@@ -89,7 +91,= 8 @@

struct openvpn_sockaddr dest;
#if ENABLE_IP_PKTINFO
- union {
+ union
+ = {
#if defined(HAVE_IN_PKTINFO) && defined(HAVE_I= PI_SPEC_DST)
struct in_pktinfo in4;
#elif defined(IP_RECVDSTADDR)

@@ -104,9 +107,9 @@=
struct link_socket_addr
{
= struct addrinfo *bind_local;
- struct addrinfo *remote_list; /* complete remote list */<= br>- struct addrinfo *current_= remote; /* remote used in the
- * current connection attempt = */
+ struct addrin= fo *remote_list; /* complete remote list */
+ struct addrinfo *current_remote; /* remote= used in the
+ = * current connection attempt */
<= span> struct link_socket_actual actual; /* reply to this address */
};

@@ -117,10 +120,10 @@
const char *ipchange_command;
const= struct plugin_list *plugins;
bool remote_float;
- int proto; = /* Protocol (PROTO_x defined below) */
- sa_family_t af; /* Address fa= mily like AF_INET, AF_INET6 or AF_UNSPEC*/
+ int proto; /* Protocol (PROTO_x defined be= low) */
+ sa_famil= y_t af; /* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/
= bool bind_ipv6_only;
- int mtu_changed; /* Set to true when mtu value is = changed */
+ int m= tu_changed; /* Set to true when mtu value is changed */
};=

/*
@@ -136,7 +139,7 @@<= /span>

struct buffer buf;
= struct buffer next;
- int len; /* -1 if not yet known */
+ int len; /* -1 if not yet known */
=
bool error; /* if true, fatal TCP error has oc= curred,
* requiring that connection be r= estarted */
@@ -164,10 +167,8 @@
* @param= sbs new sizes.
* @param reduce_size apply th= e new size even if smaller than current one
*/
= -void
-socket_set_buffers(socket_descriptor_t fd,=
- const str= uct socket_buffer_size *sbs,
- bool reduce_size);
+void socket_set_buffers(socket_descriptor_t fd, co= nst struct socket_buffer_size *sbs,
+ bool reduce_size);
=
/*
* This is the main socket structure= used by OpenVPN. The SOCKET_
@@ -178,10 +179,10 @@=
{
struct link_socket_info info;
<= span>

- struct even= t_arg ev_arg; /**< this struct will store a pointer to either mi or
- = * link_socket, depending on the event type, to keep
- * it = accessible it's placed within the same struct

- * it points to.= */
+ struct event= _arg ev_arg; /**< this struct will store a pointer to either mi or
+ = * link_socket, depending on the event type, to keep
+ * it acc= essible it's placed within the same struct
+ * it points to. */=

socket_descriptor_t sd;
<= span> socket_descriptor_t ctrl_sd; /* only used for UDP over Socks */
@@ -206,9 +207,9 @@
struct cached_dns_e= ntry *dns_cache;
bool bind_local;

-#define LS_MODE_DEFAULT = 0
-#define LS= _MODE_TCP_LISTEN 1
-#define LS_MODE_TCP_ACCEPT_FROM 2
+#define LS_MODE_DEFAULT 0
+#define LS_MODE_TCP_LISTEN 1<= br>+#define LS_MODE_TCP_ACCEPT_= FROM 2
int mode;

= int resolve_retry_seconds;
@@ -216,15 +217,15 @@
struct socket_buffer_size socket_buffer_size= s;

- = int mtu; /* OS discovered MTU, or 0 if unknown */
+ int mtu; /* OS disc= overed MTU, or 0 if unknown */

-#define SF_USE_IP_PKTINFO (1<<0)-#define SF_TCP_NODELAY (1<&l= t;1)
-#define SF_PORT_S= HARE (1<<2)
-#def= ine SF_HOST_RANDOMIZE (1<<3)
-#define SF_GETADDRINFO_DGRAM (1<<4)
-#define SF_DCO_WIN (1<<5)
= -#define SF_PREPEND_SA (1<<= 6)
+#define SF_USE_IP= _PKTINFO (1 << 0)
+#define SF_TCP_NODELAY (1 << 1)
+#define SF_PORT_SHARE (1 << 2)<= /span>
+#define SF_HOST_RAND= OMIZE (1 << 3)
+#define SF_GETADDRINFO_DGRAM (1 << 4)
+#define SF_DCO_WIN (1 << 5)
+#define SF_PREPEND_SA = (1 << 6)
unsigned int sockflags; int mark;
const char *bind_dev;
= @@ -278,12 +279,13 @@

int socket_r= ecv_queue(struct link_socket *sock, int maxsize);
<= br>-int socket_send_queue(struct = link_socket *sock,
- = struct buffer *buf,
+int socket_send_queue(struct link_socket *sock, struct b= uffer *buf,
const struct link_socket= _actual *to);

-typedef struct {
- union {
+typ= edef struct
+{=
+ union
+ {
SOCKE= T s;
HANDLE h;
};
<= span>@@ -291,17 +293,15 @@

bool prepend_sa; /* are inc= oming packets prepended with sockaddr? */
} sockethandle_t= ;

-in= t sockethandle_finalize(sockethandle_t sh,
- struct overlapped_io *io,
- = struct buffer *buf,
+int sockethandle_finalize(sockethandle_t sh, struct overlapped_io *io, st= ruct buffer *buf,
struct link_so= cket_actual *from);

static inline BOOL
SocketHandleGetOverlappedResult(sockethandle_t sh, struct o= verlapped_io *io)
{
- return sh.is_handle ?
- GetOverlappedResult(sh.h, &io->overlap= ped, &io->size, FALSE) :
- WSAGetOverlappedResult(sh.s, &io->overlapped, &= amp;io->size, FALSE, &io->flags);
+ return sh.is_handle
+ ? GetOverlappedResult(sh.h, &= ;io->overlapped, &io->size, FALSE)
+ : WSAGetOverlappedResult(sh.s, &= ;io->overlapped, &io->size, FALSE, &io->flags);
= }

static inline int
@@ -322,7 +322,7 @@

sh.is_handle ? SetLastError(ERR= OR_INVALID_FUNCTION) : WSASetLastError(WSAEINVAL);
}

-#else /*= ifdef _WIN32 */
+#el= se /* ifdef _WIN32 */

#define openvpn_cl= ose_socket(s) close(s)

@@ -330,29 +330,19= @@

struct link_socket *link_socket_new(= void);

- struct addrinfo *local,
- int af_family,
- const c= har *prefix,
+void so= cket_bind(socket_descriptor_t sd, struct addrinfo *local, int af_family, co= nst char *prefix,
bool ipv6only);<= br>
-int openvpn= _connect(socket_descriptor_t sd,
- const struct sockaddr *remote,
- int connect_tim= eout,

+int openvpn_co= nnect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_ti= meout,
volatile int *signal_received);=


-
/*
* Initialize link_soc= ket object.
*/
-void
-link_s= ocket_init_phase1(struct context *c,
- int sock_index,
- int mode);<= br>+void link_socket_init_phase= 1(struct context *c, int sock_index, int mode);
-void link_socket_init_phase2(st= ruct context *c,
- = struct link_socket *sock);
+void link_socket_init_phase2(struct context = *c, struct link_socket *sock);

void do_p= reresolve(struct context *c);

@@ -360,75 = +350,57 @@

void sd_close(socket_descript= or_t *sd);

-#define PS_SHOW_PORT_IF_DEFINED (1<<0)
-#define PS_SHOW_PORT (1<<1= )
-#define PS_SHOW_PKTI= NFO (1<<2)
-#define PS_DONT_SHOW_FAMILY (1<<4)
+#define PS_SHOW_PORT_IF_= DEFINED (1 << 0)
+#define PS_SHOW_PKTINFO (1 << 2= )
+#define PS_DONT_SH= OW_ADDR (1 << 3)
+#define PS_DONT_SHOW_FAMILY (1 << 4)

-const char *print_socka= ddr_ex(const struct sockaddr *addr,
- const char *separator,- = const unsigned int flags,
- struct gc_arena *gc);
+const char *print_sockaddr_ex(const str= uct sockaddr *addr, const char *separator,
+ const unsigned int fla= gs, struct gc_arena *gc);

-static inline
-const char *
-print_openvpn_sockaddr(const struct openvpn_sockaddr *addr,
= - struct gc= _arena *gc)
+static i= nline const char *
+p= rint_openvpn_sockaddr(const struct openvpn_sockaddr *addr, struct gc_arena = *gc)
{
return print_sockaddr_ex(&= addr->addr.sa, ":", PS_SHOW_PORT, gc);
}

-static i= nline
-const char *
-print_sockaddr(const stru= ct sockaddr *addr,
- = struct gc_arena *gc)
+static inline const char *
+print_sockaddr(const struct sockaddr *addr, struct gc_a= rena *gc)
{
return print_sockaddr_ex(= addr, ":", PS_SHOW_PORT, gc);
}
=

+= const char *print_link_socket_actual_ex(const struct link_socket_actual *ac= t, const char *separator,
+ const unsigned int flags, str= uct gc_arena *gc);

-const char *print_link_socket_actual_ex(const struct link_so= cket_actual *act,
- = const char *separator,
- = const unsigned int flags,
- struct gc_arena *gc);<= br>-
-const char *print_link_socket_actual(const struct = link_socket_actual *act,
+const char *print_link_socket_act= ual(const struct link_socket_actual *act, struct gc_arena *gc);
<= span>


-#define IA_NET_ORDER (1<<1)
+#define IA_EMPTY_IF_UNDEF (1 <<= ; 0)
+#define IA_NET_= ORDER (1 << 1)
const char *print_in_addr_t(in_a= ddr_t addr, unsigned int flags, struct gc_arena *gc);

const char *print_in6_addr(struct in6_addr addr6, unsigned in= t flags, struct gc_arena *gc);

const cha= r *print_in_port_t(in_port_t port, struct gc_arena *gc);
<= /span>
-struct in6_addr add_in= 6_addr( struct in6_addr base, uint32_t add );
+struct in6_addr add_in6_addr(struct in6_addr base= , uint32_t add);

-#define SA_IP_PORT (1<<0)
-#define SA_SET_IF_NONZERO (1<<1)
-void setenv_sockaddr(struc= t env_set *es,
- = const char *name_prefix,
- const struct openvpn_sockaddr *addr,<= /span>
- c= onst unsigned int flags);
+#define SA_IP_PORT (1 << 0)
+#define SA_SET_IF_NONZERO (1 << 1)<= br>+void setenv_sockaddr(struct= env_set *es, const char *name_prefix,
+ const struct openvpn_sockaddr *addr= , const unsigned int flags);

-void setenv_in_addr_t(struct env_set *es,- const ch= ar *name_prefix,
- = in_addr_t addr,
+void setenv_in_addr_t(struct env_set *es, const char *name_pre= fix, in_addr_t addr,
const unsigned = int flags);

-void setenv_in6_addr(struct env_set *es,
- const char *name_prefix,
- con= st struct in6_addr *addr,
+void setenv_in6_addr(struct env_set *es, const char *name_prefix, con= st struct in6_addr *addr,
const unsig= ned int flags);

-void setenv_link_socket_actual(struct env_set *es,
- con= st char *name_prefix,

-= const struct link_socket_actual *act,=
- = const unsigned int flags);
+void setenv_link_socket_actual(struct env_set *es, const char *na= me_prefix,
+ = const struct link_socket_actual *act, const unsigned = int flags);

void bad_address_length(int = actual, int expected);

@@ -438,20 +410,16= @@
#define IPV4_INVALID_ADDR 0xffffffff
= in_addr_t link_socket_current_remote(const struct link_socket_info *info);<= /span>

-cons= t struct in6_addr *link_socket_current_remote_ipv6
- (const struct link_socket_info *info);
+const struct in6_addr *= link_socket_current_remote_ipv6(const struct link_socket_info *info);

void link_socket_connection_initiated(struct = link_socket_info *info,
= const struct link_socket_actual *addr,
- const char *comm= on_name,
- = struct env_set *es);
+ const char = *common_name, struct env_set *es);

-void link_socket_bad_incoming_addr(struct b= uffer *buf,
- = const struct link_socket_info *info,
+void link_socket_bad_incoming_add= r(struct buffer *buf, const struct link_socket_info *info,

= const struct link_socket_actual *from_a= ddr);

-void set_actual_address(struct link_socket_actual *actual,
- struct addri= nfo *ai);

+void set_a= ctual_address(struct link_socket_actual *actual, struct addrinfo *ai);

void link_socket_bad_outgoing_addr(void);

@@ -466,9 +434,9 @@
*/

/* return values of openvpn_inet_aton */
-#define OIA_HOSTNAME = 0
-#define OIA_IP = 1
-#define OIA_ERROR= -1
+#define OIA_= HOSTNAME 0
+#define O= IA_IP 1
+#defin= e OIA_ERROR -1
int openvpn_inet_aton(const char *dotted= _quad, struct in_addr *addr);

/* integri= ty validation on pulled options */
@@ -482,23 +450,18 @@

socket_descriptor_t create_socket_tcp(stru= ct addrinfo *);

-socket_descriptor_t socket_do_accept(socket_descriptor_t sd,
- = struct link_socket_actual *act,
+socket_descriptor_t socket_do_accept(socket_descri= ptor_t sd, struct link_socket_actual *act,
= const bool nowait);

#if UNIX_SOCK_SUPPORT


socket_descripto= r_t create_socket_unix(void);

-void socket_bind_unix(socket_descriptor_t sd,
- str= uct sockaddr_un *local,
- const char *prefix);
+void socket_bind_unix(socket_descriptor_t sd, stru= ct sockaddr_un *local, const char *prefix);

-socket_descriptor_t socket_accept_u= nix(socket_descriptor_t sd,

- struct sockaddr_un *remote);
+socket_descriptor_t s= ocket_accept_unix(socket_descriptor_t sd, struct sockaddr_un *remote);

-int sock= et_connect_unix(socket_descriptor_t sd,
- struct sockaddr_un *remote);
+int socket_connect_unix(= socket_descriptor_t sd, struct sockaddr_un *remote);

void sockaddr_unix_init(struct sockaddr_un *local, const char = *path);

@@ -514,20 +477,20 @@
<= span> * DNS resolution

*/

-#define GETADDR_RESOLVE = (1<<0)

-#defi= ne GETADDR_FATAL (1<<1)
-#define GETADDR_HOST_ORDER (1<<2)<= /span>
-#define GETADDR_MENTIO= N_RESOLVE_RETRY (1<<3)
-#define GETADDR_FATAL_ON_SIGNAL (1<<4)
-#define GETADDR_WARN_ON_SIGNAL (= 1<<5)
-#define GE= TADDR_MSG_VIRT_OUT (1<<6)
-#define GETADDR_TRY_ONCE (1<<7)
-#define GETADDR_UPDATE_MANA= GEMENT_STATE (1<<8)
-#define GETADDR_RANDOMIZE (1<<9)
-#define GETADDR_PASSIVE (1&l= t;<10)
-#define GETA= DDR_DATAGRAM (1<<11)
+#define GETADDR_RESOLVE (1 << 0)<= /span>
+#define GETADDR_FATA= L (1 << 1)
+#define GETADDR_HOST_ORDER (1 << 2)
+#define GETADDR_MENTION_R= ESOLVE_RETRY (1 << 3)
+#define GETADDR_FATAL_ON_SIGNAL (1 << 4)
= +#define GETADDR_WARN_ON_SIGNAL= (1 << 5)
+#define GETADDR_MSG_VIRT_OUT (1 << 6)
+#define GETADDR_TRY_ONCE = (1 << 7)

+= #define GETADDR_UPDATE_MANAGEMENT_STATE (1 << 8)
+#define GETADDR_RANDOMIZE = (1 << 9)
+#defi= ne GETADDR_PASSIVE (1 << 10)
+#define GETADDR_DATAGRAM (1 &= lt;< 11)

-#define GETADDR_CACHE_MASK (GETADDR_DATAGRAM|GETADDR_P= ASSIVE)
+#define GETA= DDR_CACHE_MASK (GETADDR_DATAGRAM | GETADDR_PASSIVE)

/**
* Translate an IPv4 addr or hostname from= string form to in_addr_t
@@ -535,24 +498,17 @@
<= span> * In case of resolve error, it will try again for

= * resolve_retry_seconds seconds.
*/
-in_addr_t getaddr(unsigned int flags,
- const cha= r *hostname,
- = int resolve_retry_seconds,
- bool *succeeded,
- struct signal_info *sig_info);=
+in_addr_t getaddr(u= nsigned int flags, const char *hostname, int resolve_retry_seconds,<= br>+ bool *suc= ceeded, struct signal_info *sig_info);

/= **
* Translate an IPv6 addr or hostname from string form = to in6_addr
*/
-bool get_ipv6_addr(const char *hostname, struct in6_addr *networ= k,
- = unsigned int *netbits, int msglevel);
+bool get_ipv6_addr(const char *hostname, struct in6_addr = *network, unsigned int *netbits,
+ int msglevel);

= -int openvpn_getaddrinfo(unsigned= int flags,
- = const char *hostname,
- const char *servname,
- int resolve_r= etry_seconds,

- = struct signal_info *sig_info,
- int ai_family,
+int openvpn_getaddrinfo(unsigned= int flags, const char *hostname, const char *servname,

+ int resolve_ret= ry_seconds, struct signal_info *sig_info, int ai_family,
= struct addrinfo **res);

= /*
@@ -563,8 +519,9 @@
* Use enum&= #39;s instead of #define to allow for easier
* optional p= roto support
*/
-enum proto_num {
- PROTO_NONE, /* catch for uninitialized */
+enum proto_num
+{
+ PROTO_NONE, /* catch for uninitialized */
PROTO_UDP,

PROTO_TCP,
PRO= TO_TCP_SERVER,
@@ -666,11 +623,14 @@
}=
switch (addr->addr.sa.sa_family)
= {
- case AF_= INET: return addr->addr.in4.sin_addr.s_addr !=3D 0;
+ case AF_INET:
+ return addr->addr.in4.s= in_addr.s_addr !=3D 0;

- case AF_INET6: return !IN6_IS_ADDR_UNSPECIFIED(&= amp;addr->addr.in6.sin6_addr);
+ case AF_INET6:
+ return !IN6_IS_ADDR_UNSPECIFIED(&addr->= addr.in6.sin6_addr);

- default: return 0;
+ default:
+ return 0;
} }

@@ -706,17 +666,21 @@ switch (lsa->dest.addr.sa.sa_family)
{<= /span>
#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_S= PEC_DST)
- case = AF_INET: return lsa->pi.in4.ipi_spec_dst.s_addr !=3D 0;
+ case AF_INET:
+ return lsa->pi.in4.= ipi_spec_dst.s_addr !=3D 0;


#elif define= d(IP_RECVDSTADDR)
- = case AF_INET: return lsa->pi.in4.s_addr !=3D 0;
+ case AF_INET:
+ return lsa->pi.in4.s_ad= dr !=3D 0;

#endif
- case AF_INET6: return !IN6_IS_ADDR_= UNSPECIFIED(&lsa->pi.in6.ipi6_addr);
+ case AF_INET6:
+ return !IN6_IS_ADDR_UNSPECIFIED(&= ;lsa->pi.in6.ipi6_addr);

- default: return 0;
+ default:
+ return 0;
}
-#else /* if ENABLE_IP_P= KTINFO */
+#else /* i= f ENABLE_IP_PKTINFO */
ASSERT(0);
#en= dif
return false;
@@ -752,14 +716,16 @= @
switch (a1->addr.sa.sa_family)
{

case AF_INET:
- if (a1->addr.in4.sin_a= ddr.s_addr =3D=3D ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s= _addr)
+ = if (a1->addr.in4.sin_addr.s_addr
+ =3D=3D ((struct sockaddr_in *)curele= ->ai_addr)->sin_addr.s_addr)
{
return true;
= }
break;

case AF_INET6:

- if (IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_= addr, &((struct sockaddr_in6 *) curele->ai_addr)->sin6_addr))
+ if (IN6= _ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr,
+ &((s= truct sockaddr_in6 *)curele->ai_addr)->sin6_addr))
= {
return true; }
@@ -782,7 +748,8 @@
{

case AF_INET:
= if (curele->ai_family =3D=3D AF_INET
- && a1->add= r.in4.sin_addr.s_addr =3D=3D ((struct sockaddr_in *)curele->ai_addr)->= ;sin_addr.s_addr
+ = && a1->addr.in4.sin_addr.s_addr
+ =3D=3D (= (struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr

&& a1->addr.in4.sin_port =3D=3D ((struct= sockaddr_in *)curele->ai_addr)->sin_port)

= {
return true;
= @@ -791,8 +758,10 @@

case AF= _INET6:
if (curele->ai_family =3D=3D AF= _INET6
- = && IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr, &((s= truct sockaddr_in6 *) curele->ai_addr)->sin6_addr)
- && a1->ad= dr.in6.sin6_port =3D=3D ((struct sockaddr_in6 *) curele->ai_addr)->si= n6_port)
+ = && IN6_ARE_ADDR_EQUAL(&a1->addr.in6.sin6_addr,
+ = &((struct sockaddr_in6 *)curele->ai_addr)->sin6= _addr)
+ = && a1->addr.in6.sin6_port
+ =3D=3D ((struct sockaddr= _in6 *)curele->ai_addr)->sin6_port)
= {
return true;
= }
@@ -806,7 +775,6 @@
}

-
static inline bool
addr_port_match= (const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
{
@@ -825,24 +793,19 @@
}

static inline bool
-addr_match_proto(const struct openvpn_sockaddr= *a1,
- = const struct openvpn_sockaddr *a2,
+addr_match_proto(const struct openvpn_sockaddr *a1, const s= truct openvpn_sockaddr *a2,
const int pro= to)
{
= - return link_socket_proto_connection_oriented(proto)
- ? addr_match(a1, a2)- : addr_port_match(a= 1, a2);
+ return l= ink_socket_proto_connection_oriented(proto) ? addr_match(a1, a2)
= + = : addr_port_match(a1, a2);
}


static inline bool=
-addrlist_match_proto(const s= truct openvpn_sockaddr *a1,
- struct addrinfo *addr_list,
- const int proto)
+addrlist_match_proto(con= st struct openvpn_sockaddr *a1, struct addrinfo *addr_list, const int proto= )
{
- = return link_socket_proto_connection_oriented(proto)
- ? addrlist_match(a1, addr_list)=
- : addrlist= _port_match(a1, addr_list);
+ return link_socket_proto_connection_oriented(proto) ? addrlist_= match(a1, addr_list)
= + : addrlist_port_ma= tch(a1, addr_list);
}

s= tatic inline void
@@ -865,9 +828,11 @@
{
switch (af)
{
- case AF_INET: return sizeof(struct= sockaddr_in);
+ = case AF_INET:
+ = return sizeof(struct sockaddr_in);

- case AF_INET6: return sizeo= f(struct sockaddr_in6);

+ case AF_INET6:
+ return sizeof(struct sockaddr_in6);

default:
#if 0
@@ -= 890,8 +855,7 @@
static inline bool
socket= _foreign_protocol_detected(const struct link_socket *sock)
= {
- return link_soc= ket_connection_oriented(sock)
- && sock->stream_buf.port_share_state =3D=3D P= S_FOREIGN;
+ retur= n link_socket_connection_oriented(sock) && sock->stream_buf.port= _share_state =3D=3D PS_FOREIGN;
}
=
static inline const struct buffer *
@@ -932,8 +8= 96,7 @@
}

static inline= bool
-link_socket_veri= fy_incoming_addr(struct buffer *buf,
- const struct link_socket_in= fo *info,
+link_socke= t_verify_incoming_addr(struct buffer *buf, const struct link_socket_info *i= nfo,
const struct link_so= cket_actual *from_addr)
{
if (buf->= ;len > 0)
@@ -960,8 +923,7 @@
}<= br>
static inline void
-link_socket_get_outgoing_addr(struct buffer *buf,<= /span>
- = const struct link_socket_info *info,
+link_socket_get_outgoing_addr(struct buffer *buf, = const struct link_socket_info *info,
= struct link_socket_actual **act)
{
if (buf->len > 0)

@@ -981,23 +943,18 @@=
}

static inline void-link_socket_set_outgoing_addr(= struct link_socket_info *info,
- const struct link_socket_actual *act= ,
- = const char *common_name,
- struct env_set *es)
+link_socket_set_outgoing_addr(st= ruct link_socket_info *info, const struct link_socket_actual *act,
+ = const char *common_name, struct env_set *es)
{ struct link_socket_addr *lsa =3D info->lsa;
= if (
/* new or changed address? */
= (!info->connection_established
- || !addr_match_proto(&act->dest,= &lsa->actual.dest, info->proto)
- )
+ || !addr_match_proto(&act->dest, &lsa->ac= tual.dest, info->proto))
&&
<= span> /* address undef or address =3D=3D remote or --float */
(info->remote_float
- || (!lsa->remote_list || addrlist_match_pr= oto(&act->dest, lsa->remote_list, info->proto))
- )

- )
+ || (!lsa->remote_list || addrlist_match_proto(= &act->dest, lsa->remote_list, info->proto))))
= {
link_socket_connection_initiated(info, act,= common_name, es);
}
@@ -1033,14 +990,= 12 @@
* Socket Read Routines
*/<= br>
-int link_so= cket_read_tcp(struct link_socket *sock,
- struct buffer *buf);
<= span style=3D"color: hsl(120, 100%, 40%);">+int link_socket_read_tcp(struct= link_socket *sock, struct buffer *buf);


= #ifdef _WIN32

static inline int<= br>-link_socket_read_udp_win32(st= ruct link_socket *sock,
- struct buffer *buf,
+link_socket_read_udp_win32(struct link_socket = *sock, struct buffer *buf,
stru= ct link_socket_actual *from)
{
socket= handle_t sh =3D { .s =3D sock->sd };
@@ -1055,17 +1010,1= 4 @@

#else /* ifdef _WIN32 */
-int link_sock= et_read_udp_posix(struct link_socket *sock,
- struct buffer *buf,
+int link_socket_read_u= dp_posix(struct link_socket *sock, struct buffer *buf,
= struct link_socket_actual *from);

#endif /* ifdef _WIN32 */
/* read a TCP or UDP packet from link */
static in= line int
-link_socket_r= ead(struct link_socket *sock,
- struct buffer *buf,
- struct link_socket_actual *from)
+link_socket_read(struc= t link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
{
if (proto_is_udp(sock->info.proto= ) || socket_is_dco_win(sock))
/* unified UDPv4 and UDP= v6, for DCO-WIN the kernel
@@ -1097,16 +1049,13 @@ * Socket Write routines
*/

-ssize_t link_socket_writ= e_tcp(struct link_socket *sock,
- struct buffer *buf,
+ssize_t link_socket_write_tcp(struc= t link_socket *sock, struct buffer *buf,

= struct link_socket_actual *to);

#ifdef _WIN32


static inline int
-link_socket_write_win32(s= truct link_socket *sock,
- struct link_socket_actual = *to)
+link_socket_wri= te_win32(struct link_socket *sock, struct buffer *buf, struct link_socket_a= ctual *to)
{
int err =3D 0; int status =3D 0;
@@ -1145,16 +1094,14 @@
}
}

-#else /* ifdef _WIN32 */
+#else /* ifdef _WIN32 */
<= span>

-ssize_t link_so= cket_write_udp_posix_sendmsg(struct link_socket *sock,
- = struct buffer *buf,
+ssize_t link_socket_write_udp_posix_sendmsg(struct link_socket *sock, str= uct buffer *buf,
= struct link_socket_actual *to);


static inline ssize_t
-link_socket_write_udp_posix(struct link_socket *sock,- st= ruct buffer *buf,
+li= nk_socket_write_udp_posix(struct link_socket *sock, struct buffer *buf,
struct link_socket_actual *to)
{
#if ENABLE_IP_PKTINFO
@@ = -1165,14 +1112,12 @@
}
else
#endif
- = return sendto(sock->sd, BPTR(buf), BLEN(buf), 0,
- (struct sockaddr *) &= to->dest.addr.sa,
- = (socklen_t) af_addr_size(to->dest.addr.sa.sa_family));<= /span>
+ return sendt= o(sock->sd, BPTR(buf), BLEN(buf), 0, (struct sockaddr *)&to->dest= .addr.sa,
+ = (socklen_t)af_addr_size(to->dest.addr.sa.sa_family));=
}

static inline ssize_t
-link_socket_write_tcp_posix= (struct link_socket *sock,
- struct buffer *buf)
+link_socket_write_tcp_posix(struct link_s= ocket *sock, struct buffer *buf)
{
re= turn send(sock->sd, BPTR(buf), BLEN(buf), MSG_NOSIGNAL);
}

@@ -1180,9 +1125,7 @@
#endif /* ifdef = _WIN32 */

static inline ssize_t-link_socket_write_udp(struct l= ink_socket *sock,
- = struct buffer *buf,
- struct link_socket_actual *to)=
+link_socket_write_udp(stru= ct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
{
#ifdef _WIN32
return= link_socket_write_win32(sock, buf, to);
@@ -1193,9 +1136,7= @@

/* write a TCP or UDP packet to link= */
static inline ssize_t
-link_socket_write(struct link_socket *sock,
= - struct buffer = *buf,
- = struct link_socket_actual *to)
+link_socket_write(struct link_socket *sock, struct buffer *buf= , struct link_socket_actual *to)
{
if= (proto_is_udp(sock->info.proto) || socket_is_dco_win(sock))
<= span> {

@@ -1223,7 +1164,7 @@
{=
if (sock && ipbuf)
{
= - struct openvpn_iphdr *ip= h =3D (struct openvpn_iphdr *) BPTR(ipbuf);
+ struct openvpn_iphdr *iph =3D (struct openv= pn_iphdr *)BPTR(ipbuf);
sock->ptos =3D iph->= tos;
sock->ptos_defined =3D true;
}

@@ -1267,17 +1208,11 @@
<= br> event_t socket_listen_event_handle(struct link_socket *sock);

-unsigne= d int
-socket_set(struc= t link_socket *sock,
- = struct event_set *es,
- unsigned int rwflags,
- void *arg,
- unsigned int *persistent);
+unsigned int socket_set(struct link_= socket *sock, struct event_set *es, unsigned int rwflags,
+ void *arg, un= signed int *persistent);

static inline v= oid
-socket_set_listen_= persistent(struct link_socket *sock,
- struct event_set *es,- vo= id *arg)
+socket_set_= listen_persistent(struct link_socket *sock, struct event_set *es, void *arg= )
{
if (sock && !sock->lis= ten_persistent_queued)
{
diff --git a/= src/openvpn/socks.c b/src/openvpn/socks.c
index cc2dbdf..4a= d9622 100644
--- a/src/openvpn/socks.c
+++ = b/src/openvpn/socks.c
@@ -46,12 +46,10 @@
=
#include "memdbg.h"
-#define UP_TYPE_SOCKS = "SOCKS Proxy"
+#define UP_TYPE_SOCKS "SOCKS Proxy"
=
struct socks_proxy_info *
-socks_proxy_new(const char *server,
- const char *port,
- const char *authfi= le)

+socks_proxy_new(= const char *server, const char *port, const char *authfile)
{

struct socks_proxy_info *p;

@@ -84,8 +82,7 @@
}
static bool
-s= ocks_username_password_auth(struct socks_proxy_info *p,
- socket_descr= iptor_t sd,
+socks_us= ername_password_auth(struct socks_proxy_info *p, socket_descriptor_t sd,
struct event_timeout *server_po= ll_timeout,
volatile int *sig= nal_received)
{
@@ -103,24 +100,23 @@
goto cleanup;
}
=
- if ( (strlen(cred= s.username) > 255) || (strlen(creds.password) > 255) )
+ if ((strlen(creds.username) &g= t; 255) || (strlen(creds.password) > 255))

{=
- msg(M_NONFATAL,
- "SOCKS us= ername and/or password exceeds 255 characters. "
- "Authentication not possi= ble.");
+ = msg(M_NONFATAL, "SOCKS username and/or password exceeds 255 character= s. "
+ = "Authentication not possible.");
= goto cleanup;
}

- int sret =3D snprintf(to_send,= sizeof(to_send), "\x01%c%s%c%s",

- (int) strlen(creds.username),= creds.username,
- = (int) strlen(creds.password), creds.password);+ int sret =3D snprintf(to_= send, sizeof(to_send), "\x01%c%s%c%s", (int)strlen(creds.username= ),
+ = creds.username, (int)strlen(creds.password), creds.password);=
ASSERT(sret <=3D sizeof(to_send));

size =3D send(sd, to_send, strlen(to_send), MSG_NOSIGNAL);=

if (size !=3D strlen(to_send))
{
- = msg(D_LINK_ERRORS | M_ERRNO, "socks_username_password_auth: TCP p= ort write failed on send()");
+ msg(D_LINK_ERRORS | M_ERRNO,
+ "socks_username_password= _auth: TCP port write failed on send()");
got= o cleanup;
}

@@ -148= ,14 +144,16 @@
/* timeout? */
= if (status =3D=3D 0)
{
- msg(D_LINK_ERRORS | M_ERRNO, &q= uot;socks_username_password_auth: TCP port read timeout expired");
+ msg(D_LINK_= ERRORS | M_ERRNO,
+ = "socks_username_password_auth: TCP port read timeout exp= ired");
goto cleanup;
= }

/* error */
if (status < 0)

{
- msg(D_LINK_ERRORS | M_ERRN= O, "socks_username_password_auth: TCP port read failed on select()&quo= t;);
+ msg= (D_LINK_ERRORS | M_ERRNO,
+ "socks_username_password_auth: TCP port read fai= led on select()");
goto cleanup; }

@@ -165,7 +163,8 @@
/* error? */
if (size !=3D = 1)
{
- msg(D_LINK_ERRORS | M_ERRNO, "socks_username_passw= ord_auth: TCP port read failed on recv()");
+ msg(D_LINK_ERRORS | M_ERRNO,
+ "soc= ks_username_password_auth: TCP port read failed on recv()"); goto cleanup;
}

@@ -188,10 +187,8 @@
}

static bool
-socks_handshake(struct socks_proxy_info *p,
- socket_descriptor_t sd,
- struct ev= ent_timeout *server_poll_timeout,
- volatile int *signal_received)
+socks_handshake(struct socks_proxy_i= nfo *p, socket_descriptor_t sd,
+ struct event_timeout *server_poll_timeout, vola= tile int *signal_received)
{
char buf= [2];
int len =3D 0;
@@ -202,7 +199,6 @= @
if (p->authfile[0])
{=
method_sel[2] =3D 0x02; /* METHODS =3D [2 (plain login)]= */
-
= }
size =3D send(sd, method_sel, sizeof(method_sel)= , MSG_NOSIGNAL);
if (size !=3D sizeof(method_sel))
@@ -283,7 +279,8 @@
case 2: /* login/= password */
if (!p->authfile[0])
= {
- = msg(D_LINK_ERRORS, "socks_handshake: server asked for u= sername/login auth but we were "
+ msg(D_LINK_ERRORS,
+ "socks_handshake= : server asked for username/login auth but we were "
= "not provided any credentials");
return false;

}@@ -304,15 +301,13 @@
}
static bool
-re= cv_socks_reply(socket_descriptor_t sd,
- struct openvpn_sockaddr *addr,
= - struct event_ti= meout *server_poll_timeout,
- volatile int *signal_received)
+recv_socks_reply(socket_descriptor_t sd, = struct openvpn_sockaddr *addr,
+ struct event_timeout *server_poll_timeout, vola= tile int *signal_received)
{
char aty= p =3D '\0';
int alen =3D 0;
= int len =3D 0;
- = char buf[270]; /* 4 + alen(max 256) + 2 */
+ char buf[270]; /* 4 + alen(max 256)= + 2 */

if (addr !=3D NULL) {
@@ -380,18 +375,18 @@
= {
switch (atyp)
= {
- ca= se '\x01': /* IP V4 */
+ case '\x01': /* IP V4 */
alen =3D 4;

b= reak;

- case '\x03': /* DOMAINNAME */
+ case '\x03':= /* DOMAINNAME */
/* RFC 1928, section= 5: 1 byte length, <n> bytes name,
= * so the total "address length" is (length+1)
*/

- alen =3D (unsigned char) c + 1;
+ alen =3D (unsigned = char)c + 1;
break;

- case &#= 39;\x04': /* IP V6 */
+ case '\x04': /* IP V6 */
= alen =3D 16;
break= ;

@@ -422,8 +417,7 @@
= memcpy(&addr->addr.in4.sin_addr, buf + 4, sizeof(addr->addr= .in4.sin_addr));
memcpy(&addr->addr.in4.sin= _port, buf + 8, sizeof(addr->addr.in4.sin_port));
= struct gc_arena gc =3D gc_new();
- msg(M_INFO, "SOCKS proxy wants us to send UDP to= %s",
- = print_openvpn_sockaddr(addr, &gc));
+ msg(M_INFO, "SOCKS proxy wants us to send= UDP to %s", print_openvpn_sockaddr(addr, &gc));
= gc_free(&gc);
}
@@ -436,12 +430,12 @@
{
int p= ort =3D 0;
port =3D atoi(servname);
- if (port >0 && port < = 65536)
+ if (port = > 0 && port < 65536)
{
= return port;
}

- struct servent *service;
+ struct servent *servi= ce;
service =3D getservbyname(servname, NULL);<= br> if (service)
{
@@ -453,9= +447,9 @@

void
establi= sh_socks_proxy_passthru(struct socks_proxy_info *p,
- socket_descr= iptor_t sd, /* already open to proxy */
- const char *host, = /* openvpn server remote */
- const char *servname, /* openvpn se= rver port */
+ = socket_descriptor_t sd, /* already open to proxy */=
+ = const char *host, /* openvpn server remote */
<= span style=3D"color: hsl(120, 100%, 40%);">+ = const char *servname, /* openvpn server port */

= struct event_timeout *server_poll_timeout, struct signal_info *sig_info)=
{
@@ -468,32 +462,34 @@
}

/* format Socks CONNECT message */
- buf[0] =3D '\x05= '; /* VER =3D 5 */
- buf[1] =3D '\x01'; /* CMD =3D 1 (CONNECT= ) */
- buf[2] =3D &#= 39;\x00'; /* RSV */
- buf[3] =3D '\x03'; /* ATYP =3D 3 (DOMAI= NNAME) */
+ buf[0]= =3D '\x05'; /* VER =3D 5 */
+ buf[1] =3D '\x01'; /* CMD =3D 1 (CONNECT) */
+ buf[2] =3D '\= x00'; /* RSV */
+= buf[3] =3D '\x03'; /* ATYP =3D 3 (DOMAINNAME) */

len =3D strlen(host);
len =3D= (5 + len + 2 > sizeof(buf)) ? (sizeof(buf) - 5 - 2) : len;

- buf[4] =3D (= char) len;
+ buf[4= ] =3D (char)len;
memcpy(buf + 5, host, len);
int port =3D port_from_servname(servname);
- if (port =3D=3D0)
+ if (port =3D=3D 0)=
{
- msg(D_LINK_ERRORS, "establish_socks_proxy_passthrough: Canno= t convert %s to port number", servname);
+ msg(D_LINK_ERRORS, "establish_socks_= proxy_passthrough: Cannot convert %s to port number",
+ servname);
goto error;

}

= - buf[5 + len] =3D (char) (por= t >> 8);
- buf= [5 + len + 1] =3D (char) (port & 0xff);
+ buf[5 + len] =3D (char)(port >> 8);
+ buf[5 + len + 1] =3D = (char)(port & 0xff);

{ const ssize_t size =3D send(sd, buf, 5 + len + 2, MSG_NOSIG= NAL);
if ((int)size !=3D 5 + (int)len + 2)<= br> {
- = msg(D_LINK_ERRORS | M_ERRNO, "establish_socks_proxy_passthru= : TCP port write failed on send()");
+ msg(D_LINK_ERRORS | M_ERRNO,
+ "establish_= socks_proxy_passthru: TCP port write failed on send()");

goto error;

}
= }
@@ -515,7 +511,7 @@

v= oid
establish_socks_proxy_udpassoc(struct socks_proxy_info= *p,
- = socket_descriptor_t ctrl_sd, /* already open to proxy */
+ = socket_descriptor_t ctrl_sd, /* already open to proxy */
= struct openvpn_sockaddr *relay_addr,<= /span>
struct event_timeout *serve= r_poll_timeout,
struct sign= al_info *sig_info)
@@ -529,12 +525,12 @@
= /* send Socks UDP ASSOCIATE message */
/* V= ER =3D 5, CMD =3D 3 (UDP ASSOCIATE), RSV =3D 0, ATYP =3D 1 (IP V4),<= br> * BND.ADDR =3D 0, BND.PORT =3D 0 */
- const ssize_t size =3D send(ctrl_s= d,
- = "\x05\x03\x00\x01\x00\x00\x00\x00\x00\x00",=
- = 10, MSG_NOSIGNAL);
+ const ssize_t size =3D
+ send(ctrl_sd, "\x05\x03\x00\x01\x00\x00\x0= 0\x00\x00\x00", 10, MSG_NOSIGNAL);
if (size != =3D 10)
{
- msg(D_LINK_ERRORS | M_ERRNO, "establish_socks= _proxy_passthru: TCP port write failed on send()");
+ msg(D_LINK_ERRORS | M_ERRN= O,
+ &= quot;establish_socks_proxy_passthru: TCP port write failed on send()")= ;
goto error;
}
}
@@ -561,8 +557,7 @@
* R= un after UDP read.
*/
void
-socks_process_incoming_udp(struct b= uffer *buf,

- = struct link_socket_actual *from)
+socks_process_incoming_udp(struct buffer *buf= , struct link_socket_actual *from)
{
= int atyp;

@@ -578,7 +573,7 @@
<= span> }


atyp =3D buf_read_u8(buf= );
- if (atyp !=3D 1= ) /* ATYP =3D=3D 1 (IP V4) */
+ if (atyp !=3D 1) /* ATYP =3D=3D 1 (IP V4) */
{
goto error;
= }
@@ -600,8 +595,7 @@
* Returns the si= ze of the header.
*/
int
-socks_process_outgoing_udp(struct buf= fer *buf,

- = const struct link_socket_actual *to)
+socks_process_outgoing_udp(struct buffer = *buf, const struct link_socket_actual *to)
{
/*

* Get a 10 byte subset buffer prepended to= buf --
@@ -613,8 +607,8 @@
/* crash i= f not enough headroom in buf */
ASSERT(buf_defined(&am= p;head));

- buf_write_u16(&head, 0); /* RSV =3D 0 */
- buf_write_u8(&head, 0); /* = FRAG =3D 0 */
+ bu= f_write_u16(&head, 0); /* RSV =3D 0 */
+ buf_write_u8(&head, 0); /* FRAG =3D= 0 */
buf_write_u8(&head, '\x01'); /* ATYP= =3D 1 (IP V4) */
buf_write(&head, &to->des= t.addr.in4.sin_addr, sizeof(to->dest.addr.in4.sin_addr));
buf_write(&head, &to->dest.addr.in4.sin_port, sizeof(to-&= gt;dest.addr.in4.sin_port));

diff --git a/src/openvpn/socks= .h b/src/openvpn/socks.h
index 0eaa9da..03d74d9 100644
--- a/src/openvpn/socks.h
+++ b/src/openvpn/soc= ks.h
@@ -34,7 +34,8 @@
struct openvpn_sock= addr;
struct link_socket_actual;
<= br>-struct socks_proxy_info {
+struct socks_proxy_info=
+{
= bool defined;

char server[128];<= /span>
@@ -42,29 +43,26 @@
char authfile[256]= ;
};

-struct socks_proxy_info *socks_proxy_new(const char *serv= er,
- = const char *port,
+struct socks_proxy_info *socks_proxy_new(const char *s= erver, const char *port,
= const char *authfile);

void sock= s_proxy_close(struct socks_proxy_info *sp);

void establish_socks_proxy_passthru(struct socks_proxy_info *p,
<= br>- = socket_descriptor_t sd, /* already open to proxy */
- c= onst char *host, /* openvpn server remote */

- const c= har *servname, /* openvpn server port */
+ socket_de= scriptor_t sd, /* already open to proxy */
+ const char *host= , /* openvpn server remote */
+ const char *servname, = /* openvpn server port */
= struct event_timeout *server_poll_timeout,
= struct signal_info *sig_info);
<= /span>
void establish_socks_proxy_udpassoc(struct socks_proxy_inf= o *p,
- = socket_descriptor_t ctrl_sd, /* already open to proxy = */
+ = socket_descriptor_t ctrl_sd, /* already open to proxy */=
struct openvpn_sockad= dr *relay_addr,
struct= event_timeout *server_poll_timeout,
= struct signal_info *sig_info);

<= span style=3D"color: hsl(0, 100%, 40%);">-void socks_process_incoming_udp(s= truct buffer *buf,

- = struct link_socket_actual *from);
+void socks_process_incoming_udp(= struct buffer *buf, struct link_socket_actual *from);


-int socks_process_outgoin= g_udp(struct buffer *buf,
- const struct link_socket_actual *to);
+int socks_process_outg= oing_udp(struct buffer *buf, const struct link_socket_actual *to);
#endif /* ifndef SOCKS_H */
diff= --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index 9c6616= a..b72aa7f 100644
--- a/src/openvpn/ssl.c
+= ++ b/src/openvpn/ssl.c
@@ -75,20 +75,20 @@
= static int tls_packets_generated; /* GLOBAL */
static int= tls_packets_sent; /* GLOBAL */

-#define INCR_SENT ++tls_packets_sent=
-#define INCR_GENERATE= D ++tls_packets_generated
-#define INCR_SUCCESS ++tls_handshake_success
-#define INCR_ERROR ++tls_handshake_err= or
+#define INCR_SENT= ++tls_packets_sent
+#define INCR_GENERATED ++tls_packets_generated
+#define INCR_SUCCESS ++tls_handshake_su= ccess
+#define INCR_E= RROR ++tls_handshake_error

void
show_tls_performance_stats(void)
{
= msg(D_TLS_DEBUG_LOW, "TLS Handshakes, success=3D%f%% (good= =3D%d, bad=3D%d), retransmits=3D%f%%",
- (double) tls_handshake_success / (tls_handsha= ke_success + tls_handshake_error) * 100.0,
+ (double)tls_handshake_success / (tls_handsha= ke_success + tls_handshake_error) * 100.0,
tls_han= dshake_success, tls_handshake_error,
- (double) (tls_packets_sent - tls_packets_generated) = / tls_packets_generated * 100.0);
+ (double)(tls_packets_sent - tls_packets_generated) / = tls_packets_generated * 100.0);
}
-#else /* ifdef MEASURE_TLS_HANDSHAKE_STATS */=
+#else /* ifdef MEAS= URE_TLS_HANDSHAKE_STATS */

#define INCR_= SENT
#define INCR_GENERATED
@@ -112,7 +112= ,7 @@
if (*reneg_bytes =3D=3D -1) /* Not user-spec= ified */
{
msg(M_WARN= , "WARNING: cipher with small block size in use, "
- "reducing reneg= -bytes to 64MB to mitigate SWEET32 attacks.");

+ "reducing re= neg-bytes to 64MB to mitigate SWEET32 attacks.");
= *reneg_bytes =3D 64 * 1024 * 1024;
}
}
@@ -130,9 +130,10 @@

/* set limit to 7/8 of the limit so the renegotiation c= an succeed before
* we go over the limit */- limit =3D limit/8 * 7;
+ limit =3D limit / 8 = * 7;

= - msg(D_SHOW_KEYS, "Note: AEAD cipher %s will trigger a renegotiati= on"
+ msg(D_S= HOW_KEYS,
+ &q= uot;Note: AEAD cipher %s will trigger a renegotiation"
" at a sum of %" PRIi64 " blocks and packets."= ;,

ciphername, limit);
return= limit;
@@ -153,8 +154,7 @@
overhead += =3D 10;

/* tls-auth and tls-crypt */=
- overhead +=3D max= _int(tls_crypt_buf_overhead(),
- packet_id_size(true) + OPENVPN_MAX_HMAC_SI= ZE);
+ overhead += =3D max_int(tls_crypt_buf_overhead(), packet_id_size(true) + OPENVPN_MAX_HM= AC_SIZE);

/* TCP length field and op= code */
overhead +=3D 3;
@@ -218,8 +21= 8,7 @@
/* Add the typical UDP overhead for an IPv6 UDP= packet. TCP+IPv6 has a
* larger overhead but the ris= k of a TCP connection getting dropped because
* we tr= y to send a too large packet is basically zero */
- overhead +=3D datagram_overhead(session->= ;untrusted_addr.dest.addr.sa.sa_family,
- PROTO_UDP);
<= span style=3D"color: hsl(120, 100%, 40%);">+ overhead +=3D datagram_over= head(session->untrusted_addr.dest.addr.sa.sa_family, PROTO_UDP);
<= br>
return overhead;
}<= br>@@ -253,7 +252,8 @@
unprotect_user_pass(&= passbuf);
if (!strlen(passbuf.password))
{

- get_= user_pass(&passbuf, auth_file, UP_TYPE_PRIVATE_KEY, GET_USER_PASS_MANAG= EMENT|GET_USER_PASS_PASSWORD_ONLY);
+ get_user_pass(&passbuf, auth_file, UP_TYPE_PRIV= ATE_KEY,
+ = GET_USER_PASS_MANAGEMENT | GET_USER_PASS_PASSWORD_ONLY);<= br> }
}

@@ -29= 2,8 +292,7 @@
}

void
-auth_user_pass_setup(con= st char *auth_file, bool is_inline,
- const struct static_challenge_info *sci)=
+auth_user_pass_setu= p(const char *auth_file, bool is_inline, const struct static_challenge_info= *sci)
{
unsigned int flags =3D GET_U= SER_PASS_MANAGEMENT;

@@ -309,11 +308,7 @@=
if (auth_challenge) /* dynamic challenge/response= */
{
flags |=3D GET_= USER_PASS_DYNAMIC_CHALLENGE;
- get_user_pass_cr(&auth_user_pass,
- auth_file,<= /span>
- = UP_TYPE_AUTH,
- = flags,
- auth_challenge);
+ get_user_pass_cr(&au= th_user_pass, auth_file, UP_TYPE_AUTH, flags, auth_challenge);
}

else if (sci) /* static challenge r= esponse */
{
@@ -326,11 +321,7 @@<= /span>
{
flags |=3D = GET_USER_PASS_STATIC_CHALLENGE_CONCAT;
}
- get_user_pass_c= r(&auth_user_pass,
= - auth_file,
- UP_TYPE_AUTH,
- flags,=

- = sci->challenge_text);
+ get_user_pass_cr(&auth_user_pass, auth_file, U= P_TYPE_AUTH, flags, sci->challenge_text);
}
else
#endif /* ifdef ENABLE_MANAGEME= NT */
@@ -469,11 +460,10 @@
* @param crl_= file_inline True if crl_file is an inline CRL.
*/<= br> static void
-= tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file,
- bool cr= l_file_inline)
+tls_c= tx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, bool crl_= file_inline)
{
/* if something goes w= rong with stat(), we'll store 0 as mtime */
- platform_stat_t crl_stat =3D {0};
<= span style=3D"color: hsl(120, 100%, 40%);">+ platform_stat_t crl_stat = =3D { 0 };


/*
= * an inline CRL can't change at runtime, therefore there is no need to<= /span>
@@ -537,11 +527,10 @@

= if (options->dh_file)
{
- tls_ctx_load_dh_params(new_= ctx, options->dh_file,
- options->dh_file_inline);<= br>+ tls_ctx_load_dh= _params(new_ctx, options->dh_file, options->dh_file_inline); }
}
- else /* if client */<= br>+ else /* if client */
{
tls_ctx_client_new(new_ctx);<= /span>
}
@@ -568,8 +557,9 @@
=
if (options->pkcs12_file)
{<= /span>
- if (0 !=3D tls= _ctx_load_pkcs12(new_ctx, options->pkcs12_file,
- options-&= gt;pkcs12_file_inline, !options->ca_file))
+ if (0
+ !=3D tls_ctx_load_pkcs12(new_ctx, options-&= gt;pkcs12_file, options->pkcs12_file_inline,
+ !options->= ;ca_file))
{
goto err= ;
}
@@ -594,8 +584,7 @@
= #ifdef ENABLE_MANAGEMENT
else if (options->m= anagement_flags & MF_EXTERNAL_CERT)
{
- char *cert =3D management_= query_cert(management,

= - options->management_certific= ate);
+ char *= cert =3D management_query_cert(management, options->management_certifica= te);
tls_ctx_load_cert_file(new_ctx, cert, true);<= /span>
free(cert);
}
@@ -607,8 +596,9 @@


if (options->= ;priv_key_file)
{
- if (0 !=3D tls_ctx_load_priv_file(new_ctx, options= ->priv_key_file,
- = options->priv_key_file_inline))
+ if (0+ !=3D tls_ctx_loa= d_priv_file(new_ctx, options->priv_key_file,
+ options-&= gt;priv_key_file_inline))
{
= goto err;
}
@@ -626,15 +616= ,16 @@

if (options->ca_file || op= tions->ca_path)
{
- tls_ctx_load_ca(new_ctx, options->ca_file, o= ptions->ca_file_inline,
- options->ca_path, options->tls_server);<= /span>
+ tls_ctx_load= _ca(new_ctx, options->ca_file, options->ca_file_inline, options->c= a_path,
+ = options->tls_server);
}

/* Load extra certificates that are part of our own= certificate
* chain but shouldn't be included in= the verify chain */
if (options->extra_certs_file)=
{
- tls_ctx_load_extra_certs(new_ctx, options->extra_certs_file, o= ptions->extra_certs_file_inline);
+ tls_ctx_load_extra_certs(new_ctx, options->extr= a_certs_file,
+ = options->extra_certs_file_inline);
= }

/* Check certificate no= tBefore and notAfter */
@@ -778,9 +769,8 @@
for (int i =3D 0; i < KEY_SCAN_SIZE; ++i)

{
struct key_state *ks =3D get_key_scan(multi, i);
- buf_printf(&= out, " [key#%d state=3D%s auth=3D%s id=3D%d sid=3D%s]", i,=
- state_nam= e(ks->state), ks_auth_name(ks->authenticated),
- ks->key_id,+ buf_printf(&out, = " [key#%d state=3D%s auth=3D%s id=3D%d sid=3D%s]", i, state_name(= ks->state),
+ = ks_auth_name(ks->authenticated), ks->key_id,
= session_id_print(&ks->session_id_remote, g= c));
}

@@ -833,8 +82= 3,7 @@
* Build TLS object that reads/writes ciphertex= t
* to/from memory BIOs.
*/
- key_state_ssl_init(&a= mp;ks->ks_ssl, &session->opt->ssl_ctx, session->opt->ser= ver,
- = session);
+ = key_state_ssl_init(&ks->ks_ssl, &session->opt->ssl_ctx, se= ssion->opt->server, session);

= /* Set control-channel initiation mode */
ks->initi= al_opcode =3D session->initial_opcode;
@@ -870,14 +859,1= 2 @@
session->opt->frame.buf.headr= oom, TLS_RELIABLE_N_SEND_BUFFERS,
ks->= ;key_id ? false : session->opt->xmit_hold);
reli= able_init(ks->rec_reliable, BUF_SIZE(&session->opt->frame),
- sessio= n->opt->frame.buf.headroom, TLS_RELIABLE_N_REC_BUFFERS,
- false);
+ session->= ;opt->frame.buf.headroom, TLS_RELIABLE_N_REC_BUFFERS, false);
= reliable_set_timeout(ks->send_reliable, session->opt->p= acket_timeout);

/* init packet ID tr= acker */
- packet_id= _init(&ks->crypto_options.packet_id,
- session->opt->replay_window,= session->opt->replay_time, "SSL",
- ks->key_id);
<= span style=3D"color: hsl(120, 100%, 40%);">+ packet_id_init(&ks->= crypto_options.packet_id, session->opt->replay_window,

+ session->opt= ->replay_time, "SSL", ks->key_id);

=
ks->crypto_options.pid_persist =3D NULL;
=
@@ -889,11 +876,10 @@
* Attempt CRL= reload before TLS negotiation. Won't be performed if
= * the file was not modified since the last reload
= */
- if (session-&= gt;opt->crl_file
- = && !(session->opt->ssl_flags & SSLF_CRL_VERIFY_DIR)= )
+ if (session-&g= t;opt->crl_file && !(session->opt->ssl_flags & SSLF_CR= L_VERIFY_DIR))
{
- tls_ctx_reload_crl(&session->opt->ssl_ctx= ,
- = session->opt->crl_file, session->opt->crl_file_inline);<= /span>
+ tls_ctx_relo= ad_crl(&session->opt->ssl_ctx, session->opt->crl_file,
+ = session->opt->crl_file_inline);
}
<= span> }


@@ -964,7 +950,7 @@
#ifdef ENABLE_MANAGEMENT

|| management_ena= ble_def_auth(management)
#endif
- );
+ );
}

@@ -1013,8 +999,8 @@
}=
else
{
- session->initial_opcode =3D session->opt= ->tls_crypt_v2 ?
- = P_CONTROL_HARD_RESET_CLIENT_V3 : P_CONTROL_= HARD_RESET_CLIENT_V2;
+ session->initial_opcode =3D session->opt->tls_crypt_v2 ?= P_CONTROL_HARD_RESET_CLIENT_V3
+ : = P_CONTROL_HARD_RESET_CLIENT_V2;
}

/* Initialize control channel authentication parameters = */
@@ -1022,10 +1008,8 @@
session->= tls_wrap.work =3D alloc_buf(BUF_SIZE(&session->opt->frame));

/* initialize packet ID replay window fo= r --tls-auth */
- pa= cket_id_init(&session->tls_wrap.opt.packet_id,
- session->opt->repl= ay_window,
- = session->opt->replay_time,
- "TLS_WRAP", session->key= _id);
+ packet_id_= init(&session->tls_wrap.opt.packet_id, session->opt->replay_wi= ndow,
+ = session->opt->replay_time, "TLS_WRAP", session->key= _id);

/* If we are using tls-crypt-v= 2 we manipulate the packet id to be (ab)used
* to ind= icate early protocol negotiation */
@@ -1036,8 +1020,7 @@
}

/* load most r= ecent packet-id to replay protect on --tls-auth */
- packet_id_persist_load_obj(session->tls= _wrap.opt.pid_persist,
= - &session->tls_wrap.opt.packet_id);
+ packet_id_persist= _load_obj(session->tls_wrap.opt.pid_persist, &session->tls_wrap.o= pt.packet_id);

key_state_init(sessio= n, &session->key[KS_PRIMARY]);

@@ = -1095,9 +1078,7 @@
move_session(struct tls_multi *multi, i= nt dest, int src, bool reinit_src)
{
= msg(D_TLS_DEBUG_LOW, "TLS: move_session: dest=3D%s src=3D%s reinit_src= =3D%d",
- s= ession_index_name(dest),
- reinit_src);
+ session_index_name(dest), session_index_name(src), r= einit_src);
ASSERT(src !=3D dest);
= ASSERT(src >=3D 0 && src < TM_SIZE);
A= SSERT(dest >=3D 0 && dest < TM_SIZE);
@@ -120= 1,8 +1182,7 @@
*/

stru= ct tls_auth_standalone *
- struct gc_a= rena *gc)
+tls_auth_s= tandalone_init(struct tls_options *tls_options, struct gc_arena *gc)=
{
struct tls_auth_standalone *tas;
@@ -1243,9 +1223,7 @@
* sets.
*/
void
-tls_multi_init_set_options(struct tls_multi *multi,
- = const char *local,
- = const char *remote)
+tls_multi_init_set_options(struct tls_multi *mult= i, const char *local, const char *remote)
{
/* initialize options string */

multi->opt.l= ocal_options =3D local;
@@ -1291,8 +1269,7 @@
*/


static void
-key_source_print(const struct key_source *= k,
- co= nst char *prefix)
+ke= y_source_print(const struct key_source *k, const char *prefix)
{

struct gc_arena gc =3D gc_new();

@@ -1300,17 +1277,11 @@
VALGRIND_M= AKE_READABLE((void *)k->random1, sizeof(k->random1));
VALGRIND_MAKE_READABLE((void *)k->random2, sizeof(k->random2));=


- = dmsg(D_SHOW_KEY_SOURCE,
- prefix,
+ dmsg(D_SHOW_KEY_SOURCE, "%s pre_master: %s"= , prefix,
format_hex(k->pre_master, sizeof(k-&= gt;pre_master), 0, &gc));
- dmsg(D_SHOW_KEY_SOURCE,
- "%s random1: %s",
- prefix,
+ dmsg(D_SHOW_KEY_SOURCE, "%s random1: %s&= quot;, prefix,
format_hex(k->random1, sizeof(k= ->random1), 0, &gc));
- dmsg(D_SHOW_KEY_SOURCE,
- "%s random2: %s",
- prefix,
+ dmsg(D_SHOW_KEY_SOURCE, "%s random2: %s&q= uot;, prefix,
format_hex(k->random2, sizeof(k-= >random2), 0, &gc));

gc_free(= &gc);
@@ -1324,24 +1295,15 @@
}=

static bool
-openvpn_PRF(const uint8_t *secret,
- int secret_len,
- const char *label,
=
- const uint8_t *c= lient_seed,
- = int client_seed_len,
= - const uint8_t *server_seed,
- int server_seed_len,
- const struct session_id *client= _sid,
- cons= t struct session_id *server_sid,
- uint8_t *output,
- int output_len)
+openvpn_PRF(const uint8_t *secret, int secret_len= , const char *label, const uint8_t *client_seed,
+ int client_seed_len, const uint8_t= *server_seed, int server_seed_len,
+ const struct session_id *client_sid, const stru= ct session_id *server_sid,
+ uint8_t *output, int output_len)
{
/* concatenate seed components */
=
- struct buffer seed =3D a= lloc_buf(strlen(label)
= - + client_seed_len
- + server= _seed_len
- = + SID_SIZE * 2);
+ struct buffer seed =3D
+ alloc_buf(strlen(label) + client_seed_le= n + server_seed_len + SID_SIZE * 2);

= ASSERT(buf_write(&seed, label, strlen(label)));
A= SSERT(buf_write(&seed, client_seed, client_seed_len));
= @@ -1357,8 +1319,7 @@
}

/* compute PRF */

- bool ret =3D ssl_tls1_PRF(BPTR(&seed), BLEN(&seed), secret= , secret_len,
- = output, output_len);
+ bool ret =3D ssl_tls1_PRF(BPTR(&seed), BLEN(&a= mp;seed), secret, secret_len, output, output_len);
=
buf_clear(&seed);
free_buf(&see= d);
@@ -1368,11 +1329,8 @@
}

static void
-init_epoch_keys(struct key_state *ks,
- struct tls_multi *multi,=
- const struct= key_type *key_type,
- = bool server,
- struct key2 *key2)
+init_epoch_keys(struct key_state *ks, struct tls_multi= *multi, const struct key_type *key_type,
+ bool server, struct key2 *key2)
{
/* For now we hardcode this to be 16 for= the software based data channel
* DCO based implemen= tations/HW implementation might adjust this number
@@ -1403= ,19 +1361,15 @@
* b) They let userspace do the key de= rivation and pass all the individual
* keys to the DC= O layer.
* */
- epoch_init_key_ctx(co, key_type, &e1_send, &e1_re= cv, future_key_count);
+ epoch_init_key_ctx(co, key_type, &e1_send, &e1_recv, future= _key_count);

secure_memzero(&e1_= send, sizeof(e1_send));
secure_memzero(&e1_recv, s= izeof(e1_recv));
}

stat= ic void
-init_key_conte= xts(struct key_state *ks,
- struct tls_multi *multi,
- const struct key_type *key_type,=
- boo= l server,
- = struct key2 *key2,
+init_key_contexts(struct key_state *ks, struct tls_multi= *multi, const struct key_type *key_type,
+ bool server, struct key2 *key2, boo= l dco_enabled)
{
struct key_ctx_bi *k= ey =3D &ks->crypto_options.key_ctx_bi;

<= span>@@ -1429,12 +1383,10 @@

msg(M_FATAL, &quo= t;FATAL: DCO does not support --auth");
}

- = int ret =3D init_key_dco_bi(multi, ks, key2, key_direction,
- ke= y_type->cipher, server);

+ int ret =3D init_key_dco_bi(multi, ks, key2, key_direction,= key_type->cipher, server);
if (ret < 0)
{
- msg(M_FATAL, "Impossible to install key material in DCO:= %s",
- = strerror(-ret));
+ msg(M_FATAL, "Impossible to install key material in DCO:= %s", strerror(-ret));
}

/* encrypt/decrypt context are unused with DCO */
@@ -1446,7 +1398,8 @@
{
= if (!cipher_kt_mode_aead(key_type->cipher))
= {
- ms= g(M_FATAL, "AEAD cipher (currently %s) "
+ msg(M_FATAL,
+ "AEAD cipher (curr= ently %s) "
"required for epoch = data format.",
cipher_kt_name(key_typ= e->cipher));
}
@@ -1462,8 +1415= ,8 @@
generate_key_expansion_tls_export(struct tls_session= *session, struct key2 *key2)
{
if (!= key_state_export_keying_material(session, EXPORT_KEY_DATA_LABEL,
= - = strlen(EXPORT_KEY_DATA_LABEL),
- key2->keys,= sizeof(key2->keys)))
+ strlen(EXPORT_KEY_DATA_LABEL= ), key2->keys,
+ = sizeof(key2->keys)))
<= span> {

return false;
}
@@ -1480,42 +1433,28 @@
const struct ke= y_state *ks =3D &session->key[KS_PRIMARY];
cons= t struct key_source2 *key_src =3D ks->key_src;
<= br>- const struct session_id *= client_sid =3D session->opt->server ?
- &ks->= ;session_id_remote : &session->session_id;
- const struct session_id *server_sid =3D !se= ssion->opt->server ?
- &ks->session_id_remot= e : &session->session_id;
+ const struct session_id *client_sid =3D
+ session->opt->server ? &= amp;ks->session_id_remote : &session->session_id;
+ const struct session_id *server= _sid =3D

+ !se= ssion->opt->server ? &ks->session_id_remote : &session->= ;session_id;

/* debugging print of s= ource key material */
key_source2_print(key_src);

/* compute master secret */
- if (!openvpn_PRF(key_src->c= lient.pre_master,

- = sizeof(key_src->client.pre_master),
- KEY_EXPANSION_ID &qu= ot; master secret",
- sizeof(key_src->cli= ent.random1),
- = key_src->server.random1,
- sizeof(key_src->server.random1),=
- = NULL,
- = NULL,
- = master,
- = sizeof(master)))
+ if (!openvpn_PRF(key_src->client.pre_master, sizeof(ke= y_src->client.pre_master),
+ KEY_EXPANSION_ID " master secret",= key_src->client.random1,
+ sizeof(key_src->client.random1), key_src-&= gt;server.random1,
+ = sizeof(key_src->server.random1), NULL, NULL, master,= sizeof(master)))
{
return fa= lse;
}

/* compu= te key expansion */
- = if (!openvpn_PRF(master,
- sizeof(master),
- KEY_EXPANSION_ID " key expans= ion",
- = key_src->client.random2,
- sizeof(key_src->client.random2),
- key= _src->server.random2,
- client_sid,
- serve= r_sid,
- = (uint8_t *)key2->keys,
- sizeof(key2->keys)))
+ if (!openvpn_PRF(master, sizeof(mast= er), KEY_EXPANSION_ID " key expansion",
+ key_src->client.rando= m2, sizeof(key_src->client.random2),
+ key_src->server.random2, sizeof= (key_src->server.random2), client_sid,
+ server_sid, (uint8_t *)key2->= keys, sizeof(key2->keys)))
{
= return false;
}
@@ -1531,8 +1470,7 = @@
* master key.
*/
st= atic bool
-generate_key= _expansion(struct tls_multi *multi, struct key_state *ks,
- struct tls_sessi= on *session)
+generat= e_key_expansion(struct tls_multi *multi, struct key_state *ks, struct tls_s= ession *session)
{
struct key_ctx_bi = *key =3D &ks->crypto_options.key_ctx_bi;
bool r= et =3D false;
@@ -1559,17 +1497,16 @@
= if (!generate_key_expansion_openvpn_prf(session, &key2))
= {
msg(D_TLS_ERRORS, "TLS E= rror: PRF calculation failed. Your system "
- "might not support the old = TLS 1.0 PRF calculation anymore or "
- "the policy does not allow it (e.g= . running in FIPS mode). "
- "The peer did not announce support for the m= odern TLS Export "
- "feature that replaces the TLS 1.0 PRF (requires Ope= nVPN "
- = "2.6.x or higher)");
+ "might not support the = old TLS 1.0 PRF calculation anymore or "
+ "the policy do= es not allow it (e.g. running in FIPS mode). "
+ "The p= eer did not announce support for the modern TLS Export "
+ &qu= ot;feature that replaces the TLS 1.0 PRF (requires OpenVPN "
+ = "2.6.x or higher)");
goto exit;
}
}

= - key2_print(&key2, &s= ession->opt->key_type,
- "Master Encrypt", "Master Decrypt"= ;);
+ key2_print(&= amp;key2, &session->opt->key_type, "Master Encrypt", &q= uot;Master Decrypt");

/* check = for weak keys */
for (int i =3D 0; i < 2; ++i)
@@ -1581,8 +1518,7 @@
}
}


- init_key_contexts(ks, multi, &session->opt->key_type, se= rver, &key2,
- = session->opt->dco_enabled);
+ init_key_contexts(ks, multi, &sessio= n->opt->key_type, server, &key2, session->opt->dco_enabled)= ;
ret =3D true;

exi= t:
@@ -1598,11 +1534,10 @@
* can thus be = called only once per session.
*/
bool
-tls_session_generate_dat= a_channel_keys(struct tls_multi *multi,
- struct tls_session= *session)
+tls_sessi= on_generate_data_channel_keys(struct tls_multi *multi, struct tls_session *= session)
{
bool ret =3D false;=
- struct key_state *ks =3D= &session->key[KS_PRIMARY]; /* primary key */
+ struct key_state *ks =3D &sessio= n->key[KS_PRIMARY]; /* primary key */

= if (ks->authenticated <=3D KS_AUTH_FALSE)
{=
@@ -1617,8 +1552,7 @@
msg(D_TLS_E= RRORS, "TLS Error: generate_key_expansion failed");
goto cleanup;

}
- tls_limit_reneg_bytes(session->opt->ke= y_type.cipher,
- = &session->opt->renegotiate_bytes);
<= span style=3D"color: hsl(120, 100%, 40%);">+ tls_limit_reneg_bytes(sessi= on->opt->key_type.cipher, &session->opt->renegotiate_bytes)= ;


session->opt->aead_usage_lim= it =3D tls_get_limit_aead(session->opt->key_type.cipher);
<= span>

@@ -1632,23 +1566,18 @@
}
bool
-tls_session_update_crypto_params_do_work(struct tls_multi *multi,<= /span>
- = struct tls_session *session,
- struct o= ptions *options,
- = struct frame *frame,
- = struct frame *frame_fragment,
- struct link_socket_info *= lsi,
+tls_session_upd= ate_crypto_params_do_work(struct tls_multi *multi, struct tls_session *sess= ion,
+ = struct options *options, struct frame *frame,
+ = struct frame *frame_fragment, struct link_socket_info *ls= i,
dco_context_t = *dco)
{
if (session->key[KS_PRIMAR= Y].crypto_options.key_ctx_bi.initialized)
{
= /* keys already generated, nothing to do */
= return true;
-=
}

- init_key_type(&session->opt->key_type, op= tions->ciphername,
-= options->authname, true, true);
+ init_key_type(&session->opt-&g= t;key_type, options->ciphername, options->authname, true, true);

bool packet_id_long_form =3D cipher_kt_m= ode_ofb_cfb(session->opt->key_type.cipher);
sess= ion->opt->crypto_flags &=3D ~(CO_PACKET_ID_LONG_FORM);
= @@ -1692,10 +1621,8 @@
* mssfix are set to = update in-kernel config */
if (options->ping_se= nd_timeout || frame->mss_fix)
{
- int ret =3D dco_set_peer(= dco, multi->dco_peer_id,

- options->ping_send_timeout,
- = options->ping_rec_timeout,
- frame->mss_fix);
+ int ret = =3D dco_set_peer(dco, multi->dco_peer_id, options->ping_send_timeout,=
+ = options->ping_rec_timeout, frame->mss_fix); if (ret < 0)
{ msg(D_DCO, "Cannot set DCO peer parameters fo= r peer (id=3D%u): %s",
@@ -1708,11 +1635,9 @@ }

bool
-tls_session_update_crypto_params(struct tls_mu= lti *multi,
- = struct tls_session *session,
+tls_session_update_crypto_params(struct t= ls_multi *multi, struct tls_session *session,
= struct options *options, struct frame *frame,- = struct frame *frame_fragment,
- struct link_socket_info *lsi,
+ = struct frame *frame_fragment, struct link_socket_info *lsi,
dco_context_t *dco) {
if (!check_session_cipher(session, options)= )
@@ -1723,19 +1648,18 @@
/* Import cr= ypto settings that might be set by pull/push */
sessio= n->opt->crypto_flags |=3D options->imported_protocol_flags;=

- return= tls_session_update_crypto_params_do_work(multi, session, options,- = frame, frame_fragment, lsi, dco);
+ return tls_session_update_crypto_pa= rams_do_work(multi, session, options, frame, frame_fragment,
+ = lsi, dco);

}

static bool
-random_bytes_to_buf(struct buffer *buf,
- uint8_t *out,<= br>- int outle= n)
+random_bytes_to_b= uf(struct buffer *buf, uint8_t *out, int outlen)
{<= br> if (!rand_bytes(out, outlen))
{- msg(M_FATAL, "ERR= OR: Random number generator cannot obtain entropy for key generation [SSL]&= quot;);
+ msg(= M_FATAL,
+ = "ERROR: Random number generator cannot obtain entropy for key generat= ion [SSL]");
}
if (!buf_writ= e(buf, out, outlen))
{
@@ -1745,9 +166= 9,7 @@
}

static bool
-key_source2_randomize_wr= ite(struct key_source2 *k2,
- struct buffer *buf,
- bool server)
+key_source2_randomize_= write(struct key_source2 *k2, struct buffer *buf, bool server)
{

struct key_source *k =3D &k2->client;
if (server)
@@ -1778,9 +1700,7 @@=
}

static int
-key_source2_read(struct key_source2 *k= 2,
- st= ruct buffer *buf,
- = bool server)
+key_source2_read(struct key_source2 *k2, struct buffer *buf, bool ser= ver)
{
struct key_source *k =3D &= k2->client;

@@ -1830,10 +1750,10 @@
static void
key_state_soft_reset(struct tls= _session *session)
{
- struct key_state *ks =3D &session->key[KS_PRIMAR= Y]; /* primary key */
+ struct key_state *ks =3D &session->key[KS_PRIMARY]; = /* primary key */
struct key_state *ks_lame =3D &= ;session->key[KS_LAME_DUCK]; /* retiring key */
=
- ks->must_die =3D now = + session->opt->transition_window; /* remaining lifetime of old key *= /
+ ks->must_di= e =3D now + session->opt->transition_window; /* remaining lifetime= of old key */
key_state_free(ks_lame, false);<= br> *ks_lame =3D *ks;

@@ -1906,= 7 +1826,7 @@
{
return -len;
}
-= str[len-1] =3D '\0';
+ str[len - 1] =3D '\0';
return= len;
}

@@ -1920,14 +184= 0,14 @@
{
return NULL;=
}
- s= tr =3D (char *) malloc(len);
+ str =3D (char *)malloc(len);
check_malloc= _return(str);
if (!buf_read(buf, str, len))
= {
free(str);
r= eturn NULL;
}
- str[len-1] =3D '\0';
+ str[len - 1] =3D '\0';
return str;

}

@@ = -2017,7 +1937,6 @@
if (tls_item_in_cipher_list= ("AES-128-GCM", session->opt->config_ncp_ciphers) && tls_item_in_cipher_list("AES-256-GC= M", session->opt->config_ncp_ciphers))
= {
-
buf_printf(&out, "IV_NCP=3D2\n");
}
}
@@ -2056,7= +1975,7 @@
{
= buf_printf(&out, "IV_HWADDR=3D%s\n", format_hex_ex(rgi.hwadd= r, 6, 0, 1, ":", &gc));
}=
- buf_printf(&= out, "IV_SSL=3D%s\n", get_ssl_library_version() );
+ buf_printf(&out, &= quot;IV_SSL=3D%s\n", get_ssl_library_version());

#if = defined(_WIN32)
buf_printf(&out, "IV_= PLAT_VER=3D%s\n", win32_version_string(&gc));
#el= se
@@ -2078,8 +1997,7 @@
= || strncmp(e->string, "IV_PLAT_VER=3D", sizeof("= ;IV_PLAT_VER=3D") - 1) =3D=3D 0)
= && session->opt->push_peer_info_detail > 2) || (strncmp(e->string, "IV_GUI_VE= R=3D", sizeof("IV_GUI_VER=3D") - 1) =3D=3D 0)
- || (strncmp= (e->string, "IV_SSO=3D", sizeof("IV_SSO=3D") - 1) = =3D=3D 0)

- = )
+ = || (strncmp(e->string, "IV_SSO=3D", sizeof= ("IV_SSO=3D") - 1) =3D=3D 0))
= && buf_safe(&out, strlen(e->string) + 1))
{

buf_pri= ntf(&out, "%s\n", e->string);
@@ -2126,7 += 2044,7 @@
static bool
key_method_2_write(= struct buffer *buf, struct tls_multi *multi, struct tls_session *session)
{
- = struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary = key */
+ struct ke= y_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */<= br>
ASSERT(buf_init(buf, 0));
=
@@ -2161,7 +2079,7 @@
} else
#endif
- if (!write_string(buf, session->opt->l= ocal_options, TLS_OPTIONS_LEN))
+ if (!write_string(buf, session->opt->local_op= tions, TLS_OPTIONS_LEN))
{
= goto error;
}
@@ -2172,8 +20= 90,7 @@
{
#ifdef ENABLE_MANAGEMENT
auth_user_pass_setup(session->opt->auth_user_p= ass_file,
- = session->opt->auth_user_pass_file_inline,
= - ses= sion->opt->sci);
- if (session->opt->server &= ;& session->opt->mode !=3D MODE_SERVER
- && ks->key_id =3D=3D 0)
+ if (session->opt-&= gt;server && session->opt->mode !=3D MODE_SERVER && k= s->key_id =3D=3D 0)
{
/* t= ls-server option set and not P2MP server, so we
*= are a P2P client running in tls-server mode */
@@ -2251,18= +2167,16 @@
struct gc_arena gc =3D gc_new();

unsigned char *ekm =3D gc_malloc(ses= sion->opt->ekm_size, true, &gc);
- if (key_state_export_keying_material(session,<= /span>
- = session->opt->ekm_label,
- = session->opt->ekm_label_size,
- ekm, session-&= gt;opt->ekm_size))
+ if (key_state_export_keying_material(session, session->opt->= ;ekm_label,
+ = session->opt->ekm_label_size, ek= m,
+ = session->opt->ekm_size))
= {
unsigned int len =3D (size * 2) + 2= ;

const char *key =3D format= _hex_ex(ekm, size, len, 0, NULL, &gc);
set= env_str(session->opt->es, "exported_keying_material", key);=

- = dmsg(D_TLS_DEBUG_MED, "%s: exported keying material: %s"= ,
- __f= unc__, key);
+ = dmsg(D_TLS_DEBUG_MED, "%s: exported keying material: %s", __= func__, key);
secure_memzero(ekm, size);
}
else
@@ -228= 1,7 +2195,7 @@
static bool
key_method_2_r= ead(struct buffer *buf, struct tls_multi *multi, struct tls_session *sessio= n)
{
-= struct key_state *ks =3D &session->key[KS_PRIMARY]; /* prim= ary key */
+ struc= t key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */

struct gc_arena gc =3D gc_new();=
char *options;
@@ -2293,8 +2207,7 @@<= br> /* discard leading uint32 */
if (!buf_ad= vance(buf, 4))
{
- msg(D_TLS_ERRORS, "TLS ERROR: Plaintext buffer= too short (%d bytes).",
- buf->len);
+ msg(D_TLS_ERRORS, "TLS ERROR: Plaintext buffer t= oo short (%d bytes).", buf->len);
goto err= or;
}

@@ -2302,8 +22= 15,7 @@
int key_method_flags =3D buf_read_u8(buf);
if ((key_method_flags & KEY_METHOD_MASK) !=3D 2)
{
- = msg(D_TLS_ERRORS,
= - "TLS ERROR: Unknown key_method/flags=3D%d received from r= emote host",
+ = msg(D_TLS_ERRORS, "TLS ERROR: Unknown key_method/flags=3D%d rece= ived from remote host",
key_method_flags)= ;
goto error;
}
@@ -2311,7 +2223,8 @@

/* get key source material (n= ot actual keys yet) */
if (!key_source2_read(ks->ke= y_src, buf, session->opt->server))
{
<= span style=3D"color: hsl(0, 100%, 40%);">- msg(D_TLS_ERRORS, "T= LS Error: Error reading remote data channel key source entropy from plainte= xt buffer");

+ = msg(D_TLS_ERRORS,
+ "TLS Error: Error reading remote data channel key sour= ce entropy from plaintext buffer");
goto erro= r;
}

@@ -2341,13 +22= 54,11 @@
}

free= (multi->remote_ciphername);
- multi->remote_ciphername =3D
- options_string_extract_option(options, "= ;cipher", NULL);
+ multi->remote_ciphername =3D options_string_extract_option(options= , "cipher", NULL);
multi->remote_usescomp= =3D strstr(options, ",comp-lzo,");

<= span> /* In OCC we send '[null-cipher]' instead 'none' = */

- if (multi->r= emote_ciphername
- = && strcmp(multi->remote_ciphername, "[null-cipher]"= ) =3D=3D 0)
+ if (= multi->remote_ciphername && strcmp(multi->remote_ciphername, = "[null-cipher]") =3D=3D 0)
{
free(multi->remote_ciphername);

multi= ->remote_ciphername =3D string_alloc("none", NULL);
= @@ -2355,10 +2266,10 @@

if (us= ername_len < 0 || password_len < 0)
{
= - msg(D_TLS_ERRORS, "= TLS Error: Username (%d) or password (%d) too long",
- abs(username_len), abs(pass= word_len));
+ = msg(D_TLS_ERRORS, "TLS Error: Username (%d) or password (%d) too long&= quot;, abs(username_len),
+ abs(password_len));
auth_set_cli= ent_reason(multi, "Username or password is too long. "
= - &= quot;Maximum length is 128 bytes");
+ "Maximum le= ngth is 128 bytes");

/* tre= at the same as failed username/password and do not error
= * out (goto error) to sent an AUTH_FAILED back to the client */
@@ -2384,8 +2295,7 @@
/* Session veri= fication should have occurred during TLS negotiation*/
= if (!session->verified)
{
- msg(D_TLS_ERRORS,- "TLS Erro= r: Certificate verification failed (key-method 2)");
+ msg(D_TLS_ERRORS, "T= LS Error: Certificate verification failed (key-method 2)");
= goto error;
}
= ks->authenticated =3D KS_AUTH_TRUE;
@@ -2408,7 += 2318,7 @@
if (multi->opt.comp_options.flags &am= p; COMP_F_MIGRATE && multi->remote_usescomp)
= {
msg(D_PUSH, "Note: 'compress = migrate' detected remote peer "
- "with compression enabled.");<= /span>
+ = "with compression enabled.");
re= mote_options =3D options_string_compat_lzo(remote_options, &gc);=
}
#endif
@@ -2417,7 +23= 27,8 @@

if (session->opt->= ssl_flags & SSLF_OPT_VERIFY)
{
- msg(D_TLS_ERRORS, "O= ption inconsistency warnings triggering disconnect due to --opt-verify"= ;);

+ msg(= D_TLS_ERRORS,
+ = "Option inconsistency warnings triggering disconnect due to = --opt-verify");
ks->authenticated =3D = KS_AUTH_FALSE;
}
}
= @@ -2433,7 +2344,9 @@
{
= export_user_keying_material(session);

- if (plugin_call(session->opt-= >plugins, OPENVPN_PLUGIN_TLS_FINAL, NULL, NULL, session->opt->es) = !=3D OPENVPN_PLUGIN_FUNC_SUCCESS)
+ if (plugin_call(session->opt->plugins, OPENVPN_= PLUGIN_TLS_FINAL, NULL, NULL,
+ session->opt->es)
+ !=3D OPENVPN_PLUGIN_FUNC_= SUCCESS)
{
ks->aut= henticated =3D KS_AUTH_FALSE;
}
@@= -2483,8 +2396,8 @@
* @return if the state change was suc= cesful
*/
static bool
-session_move_pre_start(const struct tls_= session *session,
- = struct key_state *ks, bool skip_initial_send)
= +session_move_pre_start(const s= truct tls_session *session, struct key_state *ks,
+ bool skip_initial_send= )
{
struct buffer *buf =3D reliable_g= et_buf_output_sequenced(ks->send_reliable);
if (!bu= f)
@@ -2517,17 +2430,10 @@
#ifdef ENABLE_M= ANAGEMENT
if (management && ks->initial_opc= ode !=3D P_CONTROL_SOFT_RESET_V1)
{
- management_set_state(management,=
- = OPENVPN_STATE_WAIT,
- NULL,
- NULL,
- NULL,- N= ULL,
- = NULL);
+ = management_set_state(management, OPENVPN_STATE_WAIT, NULL, NULL, NUL= L, NULL, NULL);
}
#endif
return true;

-=
}

/**
= @@ -2536,8 +2442,7 @@
*/
static void
session_move_active(struct tls_multi *multi, struct tls_sessi= on *session,
- = struct link_socket_info *to_link_socket_info,
- struct key_state *ks= )
+ = struct link_socket_info *to_link_socket_info, struct key_state *ks)
{
dmsg(D_TLS_DEBUG_MED, "STATE S_ACTI= VE");

@@ -2552,8 +2457,8 @@ INCR_SUCCESS;

/* Set ou= tgoing address for data channel packets */
- link_socket_set_outgoing_addr(to_link_socket_info,= &ks->remote_addr,
- session->common_name, session->= opt->es);
+ lin= k_socket_set_outgoing_addr(to_link_socket_info, &ks->remote_addr, se= ssion->common_name,
-session_skip_to_pre_start(struct tls_session *session,- struc= t tls_pre_decrypt_state *state,
+session_skip_to_pre_start(struct tls_session *session, struct t= ls_pre_decrypt_state *state,
str= uct link_socket_actual *from)
{
struc= t key_state *ks =3D &session->key[KS_PRIMARY];
@@ -2= 654,8 +2558,7 @@
* Returns false if an error is encounter= ed that should abort the session.
*/
sta= tic bool
-read_incoming= _tls_ciphertext(struct buffer *buf, struct key_state *ks,
- bool *cont= inue_tls_process)
+re= ad_incoming_tls_ciphertext(struct buffer *buf, struct key_state *ks, bool *= continue_tls_process)
{
int status = =3D 0;
if (buf->len)
@@ -2663,8 +25= 66,7 @@
status =3D key_state_write_ciphertext(&= ;ks->ks_ssl, buf);
if (status =3D=3D -1)=
{
- = msg(D_TLS_ERRORS,
- "TLS Error: Incoming Ciphertext -> TLS objec= t write error");
+ msg(D_TLS_ERRORS, "TLS Error: Incoming Ciphertext -> = TLS object write error");
return false;
}
}
@@ -2684,1= 4 +2586,13 @@
static bool
control_packet_= needs_wkc(const struct key_state *ks)
{
- return (ks->crypto_options.flags = & CO_RESEND_WKC)
- = && (ks->send_reliable->packet_id =3D=3D 1);<= br>+ return (ks->crypto_o= ptions.flags & CO_RESEND_WKC) && (ks->send_reliable->pack= et_id =3D=3D 1);
}


static bool
-read_incoming_tls_plaintext(struct key_state *ks, struct buffer *buf,
- = interval_t *wakeup, bool *continue_tls_process)
+read_incoming_tls_plaintext(struct key_st= ate *ks, struct buffer *buf, interval_t *wakeup,
+ bool *continue_tls= _process)
{
ASSERT(buf_init(buf, 0));=

@@ -2746,7 +2647,8 @@
= * if we have a large wrapped client key. */
if (ma= xlen < 16)
{
- msg(D_TLS_ERRORS, "Warning: --max-packet-size (= %d) setting too low. "
+ msg(D_TLS_ERRORS,
+ "Warning: --max-packet-size (%d) setting too= low. "
"Sending minimum sized packe= t.",
session->opt->frame.tun_mtu);<= /span>
maxlen =3D 16;
@@ -2763,8 +2665,7 = @@

if (status =3D=3D -1)
<= span> {

- ms= g(D_TLS_ERRORS,
- = "TLS Error: Ciphertext -> reliable TCP/UDP transport read err= or");
+ m= sg(D_TLS_ERRORS, "TLS Error: Ciphertext -> reliable TCP/UDP transpo= rt read error");
gc_free(&gc);
= return false;
}
@@ -282= 0,12 +2721,9 @@
}

stati= c bool
-tls_process_sta= te(struct tls_multi *multi,
- struct tls_session *session,
- struct buffer *to_link,
+tls_process_state(str= uct tls_multi *multi, struct tls_session *session, struct buffer *to_link,<= /span>
struct link_socket_actual **to_link_addr= ,
- st= ruct link_socket_info *to_link_socket_info,
- interval_t *wakeup)
+ struct link_socke= t_info *to_link_socket_info, interval_t *wakeup)

{<= br> /* This variable indicates if we should call this method
* again to process more incoming/outgoing TLS state/data<= /span>
@@ -2834,7 +2732,7 @@
* should only b= e done after the outer loop (sending packets etc.)
* = has run once more */
bool continue_tls_process =3D fal= se;
- struct key_sta= te *ks =3D &session->key[KS_PRIMARY]; /* primary key */<= br>+ struct key_state *ks = =3D &session->key[KS_PRIMARY]; /* primary key */

/* Initial handshake */
if (ks->= ;state =3D=3D S_INITIAL)
@@ -2884,8 +2782,7 @@
struct buffer b =3D *buf;

INCR_SENT;<= /span>

- = write_control_auth(session, ks, &b, to_link_addr, opcode,- CONT= ROL_SEND_ACK_MAX, true);
+ write_control_auth(session, ks, &b, to_link_addr, opcode, = CONTROL_SEND_ACK_MAX, true);
*to_link =3D b;
dmsg(D_TLS_DEBUG, "Reliable -> TCP/UDP");<= /span>

@@ -2941,8 +2838,9 @@

/* Send Key */
buf =3D &ks->= ;plaintext_write_buf;
-= if (!buf->len && ((ks->state =3D=3D S_START && !s= ession->opt->server)
- || (ks->state =3D=3D S_GOT_KEY && ses= sion->opt->server)))
+ if (!buf->len
+ && ((ks->state =3D=3D S_START && !sessio= n->opt->server)
+ || (ks->state =3D=3D S_GOT_KEY && session->opt-= >server)))
{
if (!key_meth= od_2_write(buf, multi, session))
{
@@ -2977,8 +2875,7 @@

int status =3D key_state_wr= ite_plaintext(&ks->ks_ssl, buf);
if (status= =3D=3D -1)
{
- msg(D_TLS_ERRORS,
- "TLS ERROR: Outgoing Plaintex= t -> TLS object write error");
+ msg(D_TLS_ERRORS, "TLS ERROR: Outgoing = Plaintext -> TLS object write error");
= goto error;
}
if (status= =3D=3D 1)
@@ -3025,15 +2922,13 @@
}

/* Byte limit */
- if (session->opt->renegotiate_by= tes > 0
- &am= p;& ks->n_bytes >=3D session->opt->renegotiate_bytes)
+ if (session->opt-&= gt;renegotiate_bytes > 0 && ks->n_bytes >=3D session->o= pt->renegotiate_bytes)
{
r= eturn true;
}

/= * Packet limit */
- = if (session->opt->renegotiate_packets
- && ks->n_packets >=3D session-&= gt;opt->renegotiate_packets)
+ if (session->opt->renegotiate_packets && ks-&= gt;n_packets >=3D session->opt->renegotiate_packets)
{

return true;
}
@@ -3100,14 +2995,11 @@
* want to send to our= peer.
*/
static bool
-tls_process(struct tls_multi *multi,
- struct tls_se= ssion *session,
- = struct buffer *to_link,
- struct link_socket_actual **to_link_addr,
- struct link_socket_info= *to_link_socket_info,

+ = struct link_socket_actual **to_link_addr, struct link_socket_info= *to_link_socket_info,
interval_t *wakeup)
{
- st= ruct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary ke= y */
+ struct key_= state *ks =3D &session->key[KS_PRIMARY]; /* primary key */
struct key_state *ks_lame =3D &session->key[KS_LA= ME_DUCK]; /* retiring key */

/* Make= sure we were initialized and that we're not in an error state */
@@ -3116,21 +3008,18 @@
ASSERT(session_id_d= efined(&session->session_id));

= /* Should we trigger a soft reset? -- new key, keeps old key for a while = */
- if (ks->stat= e >=3D S_GENERATED_KEYS
- && should_trigger_renegotiation(session, ks))+ if (ks->state >=3D= S_GENERATED_KEYS && should_trigger_renegotiation(session, ks))
{
- = msg(D_TLS_DEBUG_LOW, "TLS: soft reset sec=3D%d/%d bytes=3D"= counter_format
- = "/%" PRIi64 " pkts=3D" counter_format "/%&qu= ot; PRIi64
- = " aead_limit_send=3D%" PRIu64 "/%" PRIu64
- " aead_limit_recv= =3D%" PRIu64 "/%" PRIu64,

- (int) (now - ks->established), session-&g= t;opt->renegotiate_seconds,
- ks->n_bytes, session->opt->renegotiate_bytes,=
- ks->n_= packets, session->opt->renegotiate_packets,
+ msg(D_TLS_DEBUG_LOW,
+ "TLS: soft reset se= c=3D%d/%d bytes=3D" counter_format "/%" PRIi64 " pkts= =3D" counter_format
+ "/%" PRIi64 " aead_limit_send=3D%" PRI= u64 "/%" PRIu64 " aead_limit_recv=3D%" PRIu64+ "/%" PR= Iu64,
+ (i= nt)(now - ks->established), session->opt->renegotiate_seconds, ks-= >n_bytes,
+ = session->opt->renegotiate_bytes, ks->n_packets, session->o= pt->renegotiate_packets,
ks->crypto_opti= ons.key_ctx_bi.encrypt.plaintext_blocks + ks->n_packets,
session->opt->aead_usage_limit,

= ks->crypto_options.key_ctx_bi.decrypt.plaintext_blocks + ks->n_= packets,
- s= ession->opt->aead_usage_limit
- );
+ session->opt->aead_usage_limit);
key_state_soft_reset(session);

}
<= span>

@@ -3147,19 +3036,15 @@
upd= ate_time();

dmsg(D_TLS_DEBUG, &q= uot;TLS: tls_process: chg=3D%d ks=3D%s lame=3D%s to_link->len=3D%d wakeu= p=3D%d",
- = continue_tls_process,
- state_name(ks->state),
- state_name(ks_lame->state),- to_link->len,
+ continue= _tls_process, state_name(ks->state), state_name(ks_lame->state), to_l= ink->len,
*wakeup);
- continue_tls_process =3D tls_proces= s_state(multi, session, to_link, to_link_addr,
- t= o_link_socket_info, wakeup);
+ continue_tls_process =3D
+ tls_process_state(multi, session, to_link= , to_link_addr, to_link_socket_info, wakeup);

<= span> if (ks->state =3D=3D S_ERROR)

{
return false;
}=
-
}

update_time();
@@ -3190,= 8 +3075,7 @@
{
struct= buffer buf =3D ks->ack_write_buf;
ASSERT(b= uf_init(&buf, multi->opt.frame.buf.headroom));
- write_control_auth(session, ks,= &buf, to_link_addr, P_ACK_V1,
- RELIABLE_ACK_SIZE, false);
+ write_contro= l_auth(session, ks, &buf, to_link_addr, P_ACK_V1, RELIABLE_ACK_SIZE, fa= lse);
*to_link =3D buf;
= dmsg(D_TLS_DEBUG, "Dedicated ACK -> TCP/UDP"); }
@@ -3200,8 +3084,7 @@
= /* When should we wake up again? */
if (ks->stat= e >=3D S_INITIAL || ks->state =3D=3D S_ERROR_PRE)
= {
- compute_ea= rliest_wakeup(wakeup,
-= reliable_send_timeout(ks->send_reliable)= );
+ compute_e= arliest_wakeup(wakeup, reliable_send_timeout(ks->send_reliable));=

if (ks->must_negotiate)
<= span> {

@@ -3211,8 +3094,7 @@

if (ks->established && session->opt->ren= egotiate_seconds)
{
- compute_earliest_wakeup(wakeup,
- ks->= ;established + session->opt->renegotiate_seconds - now);
+ compute_earliest_wakeup(= wakeup, ks->established + session->opt->renegotiate_seconds - now)= ;

}

dmsg(D_TLS_= DEBUG, "TLS: tls_process: timeout set to %d", *wakeup);@@ -3258,7 +3140,7 @@
if (session->tls_wrap.= work.data =3D=3D dataptr)
{
m= sg(M_INFO, "Warning buffer of freed TLS session is "
- "still in use (tl= s_wrap.work.data)");

+ "still in use (tls_wrap.work.data)");
goto used;
}
=
@@ -3276,7 +3158,8 @@
*/<= br> if (!ks->send_reliable)
{
- msg(M_FATAL, = "ERROR: session->key[%d]->send_reliable is NULL "+ msg(M_FATAL,
+ "ER= ROR: session->key[%d]->send_reliable is NULL "
= "while key state is %s. Exiting.",
i, state_name(ks->state));

}=
@@ -3285,7 +3168,8 @@
{ if (ks->send_reliable->array[j].buf.data =3D=3D d= ataptr)
{
- msg(M_INFO, "Warning buffer of freed = TLS session is still in"
+ msg(M_INFO,
+ "Warning buffer of freed TLS ses= sion is still in"
" use (ses= sion->key[%d].send_reliable->array[%d])",
= i, j);

@@ -3308,11 +3192,9= @@
*/

int
<= span style=3D"color: hsl(0, 100%, 40%);">-tls_multi_process(struct tls_mult= i *multi,

- = struct buffer *to_link,
+tls_multi_process(struct tls_multi *multi, struct buffer *to_link= ,
struct link_socket_actual **to_link_ad= dr,
- = struct link_socket_info *to_link_socket_info,
- interval_t *wakeup)
+ struct link_soc= ket_info *to_link_socket_info, interval_t *wakeup)

{
struct gc_arena gc =3D gc_new();
int a= ctive =3D TLSMP_INACTIVE;
@@ -3336,29 +3218,26 @@ /* set initial remote address. This triggers connecting wit= h that
* session. So we only do that if the TM_AC= TIVE session is not
* established */
- if (i =3D=3D TM_INITIAL &a= mp;& ks->state =3D=3D S_INITIAL

- && get_primary_key(multi)->state &l= t;=3D S_INITIAL
+ = if (i =3D=3D TM_INITIAL && ks->state =3D=3D S_INITIAL &&= amp; get_primary_key(multi)->state <=3D S_INITIAL
= && link_socket_actual_defined(&to_link_socket_info-&g= t;lsa->actual))
{
= ks->remote_addr =3D to_link_socket_info->lsa->actual;
}


dmsg(D_TLS_DEBUG,=
- "TL= S: tls_multi_process: i=3D%d state=3D%s, mysid=3D%s, stored-sid=3D%s, store= d-ip=3D%s",
- = i,
- = state_name(ks->state),
- session_id_print(&session->session_id, &gc),<= /span>
+ "T= LS: tls_multi_process: i=3D%d state=3D%s, mysid=3D%s, stored-sid=3D%s, stor= ed-ip=3D%s", i,
= + state_name(ks->state), session_id_print(&session->s= ession_id, &gc),
session_id_print(&ks= ->session_id_remote, &gc),
print_link_= socket_actual(&ks->remote_addr, &gc));
<= br>- if ((ks->state >= ;=3D S_INITIAL || ks->state =3D=3D S_ERROR_PRE) && link_socket_= actual_defined(&ks->remote_addr))
+ if ((ks->state >=3D S_INITIAL || ks->= state =3D=3D S_ERROR_PRE)
+ && link_socket_actual_defined(&ks->remote_= addr))
{
struct link_= socket_actual *tla =3D NULL;

= update_time();

- if (tls_process(multi, session, to_link, &tla,<= /span>
- = to_link_socket_info, wakeup))
+ if (tls_process(multi, session, to_link, &t= la, to_link_socket_info, wakeup))
{
= active =3D TLSMP_ACTIVE;
= }
@@ -3384,14 +3263,12 @@
{<= /span>
++multi->n_soft_errors;

- if = (i =3D=3D TM_ACTIVE
- = || (i =3D=3D TM_INITIAL && get_primary_key(multi)= ->state < S_ACTIVE))
+ if (i =3D=3D TM_ACTIVE || (i =3D=3D TM_INITIAL &= & get_primary_key(multi)->state < S_ACTIVE))
= {
error =3D true;<= br> }

- if (i =3D=3D TM_ACTIVE
- && ks_= lame->state >=3D S_GENERATED_KEYS

+ if (i =3D=3D TM_ACTIVE && ks_la= me->state >=3D S_GENERATED_KEYS
= && !multi->opt.single_session)
= {
move_session(multi, TM_LAME_DUCK, TM= _ACTIVE, true);
@@ -3423,8 +3300,8 @@
= if (ks->state =3D=3D S_ACTIVE && ks->authenticated =3D=3D= KS_AUTH_TRUE)
{
/* S= ession is now fully authenticated.
- * tls_session_generate_data_channel_keys will move= ks->state
- = * from S_ACTIVE to S_GENERATED_KEYS */
+ * tls_session_generate_data_channel_key= s will move ks->state
+ * from S_ACTIVE to S_GENERATED_KEYS */
= if (!tls_session_generate_data_channel_keys(multi, session))
{
msg(D_TLS_ERRO= RS, "TLS Error: generate_key_expansion failed");
= @@ -3469,7 +3346,8 @@
{
move_= session(multi, TM_ACTIVE, TM_INITIAL, true);
tas = =3D tls_authentication_status(multi);
- msg(D_TLS_DEBUG_LOW, "TLS: tls_multi_process: = initial untrusted "
+ msg(D_TLS_DEBUG_LOW,
+ "TLS: tls_multi_process: initial untrusted &= quot;
"session promoted to %strusted"= ;,
tas =3D=3D TLS_AUTHENTICATION_SUCCEEDED ? &= quot;" : "semi-");

@@ -352= 6,8 +3404,8 @@
* try to generate a sensible error message= and print it
*/
static void
<= span style=3D"color: hsl(0, 100%, 40%);">-print_key_id_not_found_reason(str= uct tls_multi *multi,

-= const struct link_socket_actual *from, int ke= y_id)
+print_key_id_n= ot_found_reason(struct tls_multi *multi, const struct link_socket_actual *f= rom,
+ = int key_id)
{
struct g= c_arena gc =3D gc_new();
const char *source =3D print_= link_socket_actual(from, &gc);
@@ -3545,17 +3423,14 @@<= /span>
* session but has not generated keys. */ if (ks->state >=3D S_INITIAL && ks->state= < S_GENERATED_KEYS)
{
- msg(D_MULTI_DROPPED,
- "Key %s [%d] n= ot initialized (yet), dropping packet.",

- source, key_id);
+ msg(D_MULTI_DROPPED, "= ;Key %s [%d] not initialized (yet), dropping packet.", source,<= br>+ key_id);
gc_free(&gc);
r= eturn;
}
if (ks->state= >=3D S_ACTIVE && ks->authenticated !=3D KS_AUTH_TRUE)=
{
- = msg(D_MULTI_DROPPED,
- "Key %s [%d] not authorized%s, dropping pack= et.",
- = source, key_id,
= + msg(D_MULTI_DROPPED, "Key %s [%d] not authorized%s, dropp= ing packet.", source, key_id,
(ks->= ;authenticated =3D=3D KS_AUTH_DEFERRED) ? " (deferred)" : "&= quot;);
gc_free(&gc);
= return;
@@ -3565,8 +3440,7 @@
= msg(D_TLS_ERRORS,
"TLS Error: local/remote T= LS keys are out of sync: %s "
"(received= key id: %d, known key ids: %s)",
- source, key_id,
- print_key_id(multi, &gc));
+ source, key_id, print_key_id(= multi, &gc));
gc_free(&gc);
}=

@@ -3578,11 +3452,8 @@
= * AEAD ciphers to the start of the authenticated data.
*= /
static inline void
-handle_data_channel_packet(struct tls_multi *multi,<= br>- co= nst struct link_socket_actual *from,
- struct buffer *buf,
- struct c= rypto_options **opt,

- = bool floated,
+handle_data_channel_packet(struct tls_multi *multi, con= st struct link_socket_actual *from,
+ struct buffer *buf, struct crypt= o_options **opt, bool floated,
= const uint8_t **ad_start)
{
struct gc= _arena gc =3D gc_new();
@@ -3628,7 +3499,8 @@
{

if (buf->len < 4)<= /span>
{
- msg(D_TLS_ERRORS, "Protocol error: re= ceived P_DATA_V2 from %s but length is < 4",
+ msg(D_TLS_ERRORS,
+ = "Protocol error: received P_DATA_V2 from %s but length is < 4"= ;,
print_link_socket_actual(from, = &gc));
++multi->n_soft_errors;<= /span>
goto done;
@@ -3638,9 = +3510,8 @@

++ks->n_packet= s;
ks->n_bytes +=3D buf->len;
= - dmsg(D_TLS_KEYSELECT= ,
- &qu= ot;TLS: tls_pre_decrypt, key_id=3D%d, IP=3D%s",
- key_id, print_link_socket_= actual(from, &gc));
+ dmsg(D_TLS_KEYSELECT, "TLS: tls_pre_decrypt, key_id=3D= %d, IP=3D%s", key_id,
+ print_link_socket_actual(from, &gc)); gc_free(&gc);
return;<= /span>
}
@@ -3681,14 +3552,9 @@ */

bool
-tls_pre_decrypt(struct tls_multi *multi,
- const st= ruct link_socket_actual *from,
- struct buffer *buf,
- struct crypto_options **opt,<= br>- bool floated,=
- const= uint8_t **ad_start)
= +tls_pre_decrypt(struct tls_multi *multi, const struct link_socket_actual *= from, struct buffer *buf,
+ struct crypto_options **opt, bool floated, const uint= 8_t **ad_start)
{
-
if (buf->len <=3D 0)
{

buf->len =3D 0;
@@ -3= 715,18 +3581,16 @@
/* control channel packet */=
bool do_burst =3D false;
bool new_link = =3D false;
- struct = session_id sid; /* remote session ID */
+ struct session_id sid; /* remote session ID= */

/* verify legal opcode */=
if (op < P_FIRST_OPCODE || op > P_LAST_OPCODE)<= br> {
- = if (op =3D=3D P_CONTROL_HARD_RESET_CLIENT_V1
- || op =3D=3D P_CONTROL_HARD_RESET_SERV= ER_V1)
+ if (o= p =3D=3D P_CONTROL_HARD_RESET_CLIENT_V1 || op =3D=3D P_CONTROL_HARD_RESET_S= ERVER_V1)
{
msg(D_TLS= _ERRORS, "Peer tried unsupported key-method 1");
= }
- msg= (D_TLS_ERRORS,
- = "TLS Error: unknown opcode received from %s op=3D%d",=
+ msg(D_TLS_ERRORS, = "TLS Error: unknown opcode received from %s op=3D%d",
<= span> print_link_socket_actual(from, &gc), op);

<= span> goto error;

}
@@ -3735,8= +3599,8 @@
if (is_hard_reset_method2(op))
<= span> {

/* verify client -> server or serve= r -> client connection */
- if (((op =3D=3D P_CONTROL_HARD_RESET_CLIENT_V2
- || op =3D=3D P_CONTRO= L_HARD_RESET_CLIENT_V3) && !multi->opt.server)

+ if (((op =3D=3D P_CONTROL_HAR= D_RESET_CLIENT_V2 || op =3D=3D P_CONTROL_HARD_RESET_CLIENT_V3)
+ && !multi-&= gt;opt.server)

|| ((op =3D=3D P_CONTROL_HARD_R= ESET_SERVER_V2) && multi->opt.server))
= {
msg(D_TLS_ERRORS,
@@ -3749,8= +3613,8 @@
/*
* Authenticate Pa= cket
*/
- dmsg(D_TLS_DEBUG, "TLS: control channel, op=3D%s, IP=3D%s&= quot;,
- packet= _opcode_name(op), print_link_socket_actual(from, &gc));
+ dmsg(D_TLS_DEBUG, "TLS: co= ntrol channel, op=3D%s, IP=3D%s", packet_opcode_name(op),

+ print_link_socket_actua= l(from, &gc));


/* get remote ses= sion-id */
{
@@ -3758,8 +3622,7 @@
buf_advance(&tmp, 1);
if= (!session_id_read(&sid, &tmp) || !session_id_defined(&sid))
{
- "TLS Error: session-id not found in packet = from %s",
+ = msg(D_TLS_ERRORS, "TLS Error: session-id not found in packet fr= om %s",
print_link_socket_actual(from= , &gc));
goto error;
= }
@@ -3772,29 +3635,25 @@
stru= ct tls_session *session =3D &multi->session[i];
= struct key_state *ks =3D &session->key[KS_PRIMARY];
<= span>

- dmsg(D_= TLS_DEBUG,
- = "TLS: initial packet test, i=3D%d state=3D%s, mysid=3D%s, rec-sid=3D= %s, rec-ip=3D%s, stored-sid=3D%s, stored-ip=3D%s",
- i,
- state_name(ks->state),- session_id_print(= &session->session_id, &gc),
- session_id_print(&sid, &gc),- print_link_socket= _actual(from, &gc),
- session_id_print(&ks->session_id_remote, &gc),
- print_link_= socket_actual(&ks->remote_addr, &gc));
+ dmsg(
+ D_TLS_DEBUG,
+ "TLS: initial packet test, i= =3D%d state=3D%s, mysid=3D%s, rec-sid=3D%s, rec-ip=3D%s, stored-sid=3D%s, s= tored-ip=3D%s",
= + i, state_name(ks->state), session_id_print(&session->= ;session_id, &gc),
+ = session_id_print(&ks->session_id_remote, &gc),<= br>+ print_link_sock= et_actual(&ks->remote_addr, &gc));

<= span> if (session_id_equal(&ks->session_id_remote, &sid)= )

/* found a match */
{
if (i =3D=3D TM_LAME_DUCK)
= {
- = msg(D_TLS_ERRORS,
= - "TLS ERROR: received control packet with stale se= ssion-id=3D%s",
= + msg(D_TLS_ERRORS, "TLS ERROR: received control packet= with stale session-id=3D%s",
ses= sion_id_print(&sid, &gc));
goto er= ror;
}
- dmsg(D_TLS_DEBUG,
- "TLS: found match, session[%d],= sid=3D%s",
- = i, session_id_print(&sid, &gc));
+ dmsg(D_TLS_DEBUG, "TLS: = found match, session[%d], sid=3D%s", i,
+ session_id_print(&sid, &g= c));
break;
}<= br> }
@@ -3825,8 +3684,8 @@
= goto error;
}

= - if (!read_control_auth(b= uf, tls_session_get_tls_wrap(session, key_id), from,
- session->= opt, true))
+ = if (!read_control_auth(buf, tls_session_get_tls_wrap(session, key_id), from= , session->opt,
+ = true))
{
<= span> goto error;

}
@@= -3834,13 +3693,7 @@
#ifdef ENABLE_MANAGEMENT
if (management)

{
- management_set_state(manageme= nt,
- = OPENVPN_STATE_AUTH,
- NULL,
- NULL,
- = NULL,
- = NULL,
- NULL);
+ management_set_state(management, OP= ENVPN_STATE_AUTH, NULL, NULL, NULL, NULL, NULL);
}=
#endif

@@ -3850,10 +370= 3,8 @@
*
* Without --tl= s-auth, we leave authentication entirely up to TLS.
= */
- msg(D_TL= S_DEBUG_LOW,
- = "TLS: Initial packet from %s, sid=3D%s",
- print_link_socket_actual(from, = &gc),
- = session_id_print(&sid, &gc));
+ msg(D_TLS_DEBUG_LOW, "TLS: Initial packet fr= om %s, sid=3D%s",
- msg(D_TLS_ERRO= RS,
- &q= uot;TLS Error: Unroutable control packet received from %s (si=3D%d op=3D%s)= ",
- = print_link_socket_actual(from, &gc),
- i,
- packet_opcode_name(op));
+ msg(D_TLS_ERRORS, "= TLS Error: Unroutable control packet received from %s (si=3D%d op=3D%s)&quo= t;,
+ = print_link_socket_actual(from, &gc), i, packet_opcode_name(op));=
goto error;
}

@@ -3895,17 +3743,16 @@
*/
if (op =3D=3D P_CONTROL_SOFT_RESET_V1 && ks= ->state >=3D S_GENERATED_KEYS)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- if (!read_control_aut= h(buf, tls_session_get_tls_wrap(session, key_id),

- from, sessio= n->opt, false))
+ = if (!read_control_auth(buf, tls_session_get_tls_wrap(session, ke= y_id), from,
+ = session->opt, false))
= {
goto error;
= }

key_state_soft_res= et(session);

- dmsg(D_TLS_DEBUG,
- "TLS: received P_CONTROL_SOFT_RESET_= V1 s=3D%d sid=3D%s",
- i, session_id_print(&sid, &gc));
+ dmsg(D_TLS_DEBUG, &qu= ot;TLS: received P_CONTROL_SOFT_RESET_V1 s=3D%d sid=3D%s", i,
+ session_id_= print(&sid, &gc));
}
= else
{
@@ -3926,8 +3773,8 @@
do_burst =3D true;
= }

- = from, session->opt, initial_packet))
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (!read_control_a= uth(buf, tls_session_get_tls_wrap(session, key_id), from,

+ se= ssion->opt, initial_packet))
{
/* if an initial packet in read_control_auth, we rathe= r

* error out than anything else */
@@ -3938,9 +3785,8 @@
goto erro= r;
}

- dmsg(D_TLS_DEBUG,
- "TLS: receive= d control channel packet s#=3D%d sid=3D%s",

- i, session_id_print(&sid, &= amp;gc));
+ = dmsg(D_TLS_DEBUG, "TLS: received control channel packet s#=3D%d sid= =3D%s", i,
+ = session_id_print(&sid, &gc));
= }
}

@@ -3992,9 +383= 8,8 @@
/* Check key_id */
if (ks-= >key_id !=3D key_id)
{
- msg(D_TLS_ERRORS,
- "TLS ERROR: local/remote key = IDs out of sync (%d/%d) ID: %s",
- ks->key_id, key_id, print_key_id(multi, &= ;gc));
+ msg(D= _TLS_ERRORS, "TLS ERROR: local/remote key IDs out of sync (%d/%d) ID: = %s", ks->key_id,
+ key_id, print_key_id(multi, &gc));
= goto error;
}

= @@ -4008,8 +3853,7 @@

if (!relia= ble_ack_read(&send_ack, buf, &session->session_id))
{

- = msg(D_TLS_ERRORS,
= - "TLS Error: reading acknowledgement record from packe= t");
+ = msg(D_TLS_ERRORS, "TLS Error: reading acknowledgement record from pa= cket");
goto error;
= }
reliable_send_purge(ks->send_reliable, &a= mp;send_ack);
@@ -4032,14 +3876,14 @@
= ASSERT(in);
if (!buf_c= opy(in, buf))
{
- msg(D_MULTI_DROPPED= ,
- = "Incoming control channel packet too big, dropping.");
+ = msg(D_MULTI_DROPPED, "Incoming control channel packet too big, dropp= ing.");
goto error; }
reliable= _mark_active_incoming(ks->rec_reliable, in, id, op);
= }

- /* Process outgoing acknowledgment for packet j= ust received, even if it's a replay */
+ /* Process outgoing acknowledgment f= or packet just received, even if it's a replay
+ */
= reliable_ack_acknowledge_packet_id(ks->rec_ack, id);
= }
}
@@ -4088,8 = +3932,7 @@

/* Choose the key with which = to encrypt a data packet */
void
-tls_pre_encrypt(struct tls_multi *multi,=
- struct buffe= r *buf, struct crypto_options **opt)
+tls_pre_encrypt(struct tls_multi *multi, struct buffer *bu= f, struct crypto_options **opt)
{
mul= ti->save_ks =3D NULL;
if (buf->len <=3D 0)
@@ -4144,8 +3987,7 @@

= ASSERT(ks);

- peer =3D htonl(((P_DATA_V2 << P_OPCODE_SHIFT) | ks->ke= y_id) << 24
- = | (multi->peer_id & 0xFFFFFF));
+ peer =3D htonl(((P_DATA_V2 << P= _OPCODE_SHIFT) | ks->key_id) << 24 | (multi->peer_id & 0xFF= FFFF));
ASSERT(buf_write_prepend(buf, &peer, 4));<= /span>
}

@@ -4170,9 +4012,7 @@<= /span>
*/

bool
-tls_send_payload(struct key_state *k= s,

- co= nst uint8_t *data,
- = int size)
+tls_send_payload(struct key_state *ks, const uint8_t *data, int size)
{
bool ret =3D false;
=
@@ -4204,8 +4044,7 @@
}
=
bool
-tls_rec_payload(struct tls_multi *multi,
- struct buffer *buf)
+tls_rec_payload(struct tls_multi *mult= i, struct buffer *buf)
{
bool ret =3D= false;

@@ -4258,8 +4097,7 @@
<= span> }


void
-show_available_tls_ciphers(const char *cipher_lis= t,
- = const char *cipher_list_tls13,
+show_available_tls_ciphers(const char *cipher_list, cons= t char *cipher_list_tls13,
cons= t char *tls_cert_profile)
{
printf(&q= uot;Available TLS Ciphers, listed in order of preference:\n");<= br>@@ -4276,8 +4114,7 @@
printf("\n"
"Be aware that that whether a cipher suite = in this list can actually work\n"
"de= pends on the specific setup of both peers. See the man page entries of\n&qu= ot;
- "-= -tls-cipher and --show-tls for more details.\n\n"
- );
+ "--tls-cipher and --show-tls for= more details.\n\n");
}

<= span> /*

@@ -4383,7 +4220,8 @@
}
if (flags & PD_VERBOSE)
= {
- buf_pr= intf(&out, " tls_crypt_hmac=3D%s", format_hex(tls_crypt_hmac,= TLS_CRYPT_TAG_SIZE, 0, gc));
+ buf_printf(&out, " tls_crypt_hmac=3D%s"= ,
+ = format_hex(tls_crypt_hmac, TLS_CRYPT_TAG_SIZE, 0, gc));
}

/*
* Remain= der is encrypted and optional wKc
diff --git a/src/openvpn/= ssl.h b/src/openvpn/ssl.h
index 000992d..db3e525 100644
--- a/src/openvpn/ssl.h
+++ b/src/openvpn/ssl.= h
@@ -58,9 +58,10 @@
/*
= * Various timeouts
*/
-#define TLS_MULTI_REFRESH 15 /* call tls_multi_process= once every n seconds */
- = * every packet sent/received action */+#define TLS_MULTI_REFRESH 15= /* call tls_multi_process once every n seconds */
+#define TLS_MULTI_HORIZON = \
+ 2 /* call tls_multi_proc= ess frequently for n seconds after \
+ * every packet sent/received= action */

/*
* Buffer= sizes (also see mtu.h).
@@ -78,46 +79,46 @@
* as reserved for this reason */


/**= Support P_DATA_V2 */
-= #define IV_PROTO_DATA_V2 (1<<1)
+#define IV_PROTO_DATA_V2 (1 << 1)
=
/** Assume client will send a push request and ser= ver does not need
* to wait for a push-request to send a = push-reply */
-#define = IV_PROTO_REQUEST_PUSH (1<<2)
+#define IV_PROTO_REQUEST_PUSH (1 << 2)

/** Supports key derivation via TLS key material expo= rter [RFC5705] */
-#def= ine IV_PROTO_TLS_KEY_EXPORT (1<<3)
+#define IV_PROTO_TLS_KEY_EXPORT (1 << 3)<= br>
/** Supports signaling keywords with AUTH_PENDI= NG, e.g. timeout=3Dxy */
+#define IV_PROTO_AUTH_PENDING_KW (1 << 4= )

/** Support doing NCP in P2P mode. Thi= s mode works by both peers looking at
* each other's = IV_ variables and deterministically deciding both on the same
* result. */

-#def= ine IV_PROTO_NCP_P2P (1<<5)
+#define IV_PROTO_NCP_P2P (1 << 5)

/** Supports the --dns option introduced in version 2= .6. Not sent anymore. */
+#define IV_PROTO_DNS_OPTION (1 << 6)

/** Support for explicit exit notify via co= ntrol channel
* This also includes support for the proto= col-flags pushed option */
-#define IV_PROTO_CC_EXIT_NOTIFY (1<<7)
+#define IV_PROTO_CC_EXIT_NOTIFY (1 << = 7)

/** Support for AUTH_FAIL,TEMP messag= es */
-#define IV_PROTO= _AUTH_FAIL_TEMP (1<<8)
+#define IV_PROTO_AUTH_FAIL_TEMP (1 << 8)
<= /span>
/** Support to dynamic tls-crypt (renegotiation with TLS-E= KM derived tls-crypt key) */
-#define IV_PROTO_DYN_TLS_CRYPT (1<<9)
+#define IV_PROTO_DYN_TLS_CRYPT (1 <<= ; 9)

/** Support the extended packet id = and epoch format for data channel packets */
-#define IV_PROTO_DATA_EPOCH (1<<10)
+#define IV_PROTO_DATA_EPO= CH (1 << 10)

/** Supports the --dn= s option after all the incompatible changes */
-#define IV_PROTO_DNS_OPTION_V2 (1<<11)
+#define IV_PROTO_DNS_OP= TION_V2 (1 << 11)

/* Default field= in X509 to be username */
#define X509_USERNAME_FIELD_DEF= AULT "CN"

-#define KEY_METHOD_2 2
+#define KEY_METHOD_2 2

/* key method taken from lower 4 bits */

#define KEY_ME= THOD_MASK 0x0F
@@ -204,9 +205,7 @@
* Used= to verify compatibility of local and remote option
* set= s.
*/
-void tls_multi_init_set_options(struct tls_multi *multi,
- const = char *local,
- = const char *remote);
+void tls_multi_init_set_options(struct tls_multi *m= ulti, const char *local, const char *remote);

<= span> /**

* Cleanup a \c tls_multi structure and free ass= ociated memory
@@ -226,9 +225,9 @@
=
/** @} addtogroup control_processor */
<= br>-#define TLSMP_INACTIVE 0
-#define TLSMP_ACTIVE 1
-#define TLSMP_KILL = 2
+#define TLSMP_INAC= TIVE 0
+#define TLSM= P_ACTIVE 1
+#defin= e TLSMP_KILL 2
#define TLSMP_RECONNECT 3

/*
@@ -237,11 +236,9 @@
* Basically decides if we should call tls_process for

* the active or untrusted sessions.

*/
-int tls_multi_process(struct tls_mult= i *multi,

- = struct buffer *to_link,
+int tls_multi_process(struct tls_multi *multi, struct buffer = *to_link,
struct link_socket_actual = **to_link_addr,
- = struct link_socket_info *to_link_socket_info,
- interval_t *w= akeup);

+ = struct link_socket_info *to_link_socket_info, interval_t *wakeup)= ;


/*******************= *******************************************************/
@@= -297,11 +294,8 @@
* @li False if the packet is a data ch= annel packet, or if an error
* occurred during proces= sing of a control channel packet.
*/
-bool tls_pre_decrypt(struct tls_multi *mul= ti,
- = const struct link_socket_actual *from,
- struct buffer *buf,
- struct crypto_o= ptions **opt,

- = bool floated,
+bool tls_pre_decrypt(struct tls_multi *multi, const struct link_sock= et_actual *from,
+ = struct buffer *buf, struct crypto_options **opt, bool flo= ated,
const uint8_t **ad_start);


@@ -323,8 +317,7 @@<= br> * @param buf - The buffer containing the outgoing packet.=
* @param opt - Returns a crypto options structure with the secu= rity parameters.
*/
-void tls_pre_encrypt(struct tls_multi *multi,
- struct buffer = *buf, struct crypto_options **opt);

+void tls_pre_encrypt(struct tls_multi *multi, struct buffer= *buf, struct crypto_options **opt);

/**=
* Selects the primary encryption that should be used to = encrypt data of an
@@ -349,8 +342,7 @@
*<= /span>
* @ingroup data_crypto
*/
-void

-tls_prepend_opcode_v1(const struct tls_multi *multi,= struct buffer *buf);
+void tls_prepend_opcode_v1(const struct tls_multi *multi, struct buffer *= buf);

/**
* Prepend an= OpenVPN data channel P_DATA_V2 header to the packet. The
= @@ -368,8 +360,7 @@
*
* @ingroup data_c= rypto
*/
-void
-tls_prepend_= opcode_v2(const struct tls_multi *multi, struct buffer *buf);
+void tls_prepend_opcode_v2(const = struct tls_multi *multi, struct buffer *buf);


<= span> /**

* Perform some accounting for the key state use= d.
@@ -433,15 +424,12 @@
/*
* Send a payload over the TLS control channel

*/
-bool tls_send_payload(stru= ct key_state *ks,
- = const uint8_t *data,
- int size);
+bool tls_send_payload(struct key_state *ks, c= onst uint8_t *data, int size);

/*=
* Receive a payload through the TLS control channel
<= span> */

-bool tls_rec= _payload(struct tls_multi *multi,
- struct buffer *buf);
+bool tls_rec_payload(struct tls_multi *mu= lti, struct buffer *buf);

/**
= * Updates remote address in TLS sessions.
@@ -449,8= +437,7 @@
* @param multi - Tunnel to update
* @param addr - new address

*/
-void tls_update_remote_addr(struct tls_mul= ti *multi,
- = const struct link_socket_actual *addr);
+void tls_update_remote_addr(struct tls= _multi *multi, const struct link_socket_actual *addr);

/**
* Update TLS session crypto parameters= (cipher and auth) and derive data
@@ -470,12 +457,9 @@
*
* @return true if updating succeeded or = keys are already generated, false otherwise.
*/-bool tls_session_update_crypto_= params(struct tls_multi *multi,
- struct tls_session *session= ,
- = struct options *options,
- struct frame *fr= ame,
- = struct frame *frame_fragment,
- struct l= ink_socket_info *lsi,
+bool tls_session_update_crypto_params(struct tls_multi *multi, struct tls= _session *session,
+ = struct options *options, struct frame = *frame,
+ = struct frame *frame_fragment, struct link_socket_= info *lsi,
dco_conte= xt_t *dco);

/*
@@ -534,1= 4 +518,12 @@
* protocol_dump() flags
*/=
#define PD_TLS_AUTH_HMAC_SIZE_MASK 0xFF
-#define PD_SHOW_DATA (1&l= t;<8)
-#define PD_TL= S (1<<9)
-#define PD_VERBOSE (1<<10)
-#define PD_TLS_CRYPT = (1<<11)

+#defin= e PD_SHOW_DATA (1 << 8)
+#define PD_TLS (1 << 9)
+#define PD_VERBOSE = (1 << 10)
+#define PD_TLS_CRYPT (1 << 11)

-const char *protoc= ol_dump(struct buffer *buffer,
- unsigned int flags,
- struct gc_arena = *gc);
+const char *pr= otocol_dump(struct buffer *buffer, unsigned int flags, struct gc_arena *gc)= ;

/*
* debugging code<= /span>
@@ -567,10 +549,8 @@
* @param cipher_list= _tls13 list of allowed TLS 1.3+ cipher, or NULL
* @param = tls_cert_profile TLS certificate crypto profile name.
*/=
-void
-show_available_tls_ciphers(const char = *cipher_list,
- = const char *cipher_list_tls13,
- const char *tls_cert= _profile);
+void show= _available_tls_ciphers(const char *cipher_list, const char *cipher_list_tls= 13,
+ = const char *tls_cert_profile);

=
/**
@@ -579,25 +559,19 @@ * This erases the source material used to generate the data chann= el keys, and
* can thus be called only once per session.<= /span>
*/
-b= ool
-tls_session_genera= te_data_channel_keys(struct tls_multi *multi,
- struct tls_s= ession *session);
+bo= ol tls_session_generate_data_channel_keys(struct tls_multi *multi, struct t= ls_session *session);

-void
= -tls_session_soft_reset(struct tls_multi *multi);
+void tls_session_soft_reset(struct tls_multi = *multi);

/**
* Load ov= pn.xkey provider used for external key signing
*/<= br>-void
-load_xkey_provider(void);
+void load_xkey_provider(void);
/* Special method to skip the three way handshake= RESET stages. This is
* used by the HMAC code when seein= g a packet that matches the previous
* HMAC based statele= ss server state */
-boo= l
-session_skip_to_pre_= start(struct tls_session *session,
- struct tls_pre_decrypt_state *state,=
- = struct link_socket_actual *from);
+bool session_skip_to_pre_start(struct tls_session *sessi= on, struct tls_pre_decrypt_state *state,
+ struct link_socket_actu= al *from);

#endif /* ifndef OPENVPN_SSL_= H */
diff --git a/src/openvpn/ssl_backend.h b/src/openvpn/s= sl_backend.h
index 1cf9e1d..56fc397 100644
= --- a/src/openvpn/ssl_backend.h
+++ b/src/openvpn/ssl_backe= nd.h
@@ -102,11 +102,11 @@
* = if a parse error should be flagged.
*/ #define TLS_VER_BAD -1
-#define TLS_VER_UNSPEC 0 /* default */
-#define TLS_VER_1_0 1
-#define TLS_VER_1_1 2
-#define TLS_VER_1_2 3
-#define TLS_VER_1_3 4
+#define TLS_VER_UNSPEC 0 = /* default */
+#defin= e TLS_VER_1_0 1
+#= define TLS_VER_1_1 2
+#define TLS_VER_1_2 3
+#define TLS_VER_1_3 4
int tls_version_parse(co= nst char *vstr, const char *extra);

/**<= /span>
@@ -219,8 +219,7 @@
* = of inline files.
* @param dh_file_inline = True if dh_file is an inline file.
*/
-void tls_ctx_load_dh_params(struct tls_r= oot_ctx *ctx, const char *dh_file,
- bool dh_file_inline);
+void tls_ctx_load_dh_params(stru= ct tls_root_ctx *ctx, const char *dh_file, bool dh_file_inline);

=
/**
* Load Elliptic Curve Parame= ters, and load them into the library-specific
@@ -229,8 +22= 8,7 @@
* @param ctx TLS context to use * @param curve_name The name of the elliptic curve to load.
*/
-void = tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name
- = );
+void tls_c= tx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name);

/**
* Load PKCS #12 file f= or key, cert and (optionally) CA certs, and add to
@@ -247,= 8 +245,8 @@
* @return 1 if an error = occurred, 0 if parsing was
* = successful.
*/
-int tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *p= kcs12_file,
- = bool pkcs12_file_inline, bool load_ca_file);
+int tls_ctx_load_pkcs12(struct tls_r= oot_ctx *ctx, const char *pkcs12_file, bool pkcs12_file_inline,
<= span style=3D"color: hsl(120, 100%, 40%);">+ bool lo= ad_ca_file);


/**
* Use= Windows cryptoapi for key and cert, and add to library-specific TLS=
@@ -272,8 +270,7 @@
* = of inline files.
* @param cert_file_inline True = if cert_file is an inline file.
*/
-void tls_ctx_load_cert_file(struct tls_root= _ctx *ctx, const char *cert_file,
- bool cert_file_inline);
<= span style=3D"color: hsl(120, 100%, 40%);">+void tls_ctx_load_cert_file(str= uct tls_root_ctx *ctx, const char *cert_file, bool cert_file_inline);

/**
* Load private key file= into the given TLS context.
@@ -319,8 +316,8 @@
= * connection and should use the CA for= verifying
* client certific= ates
*/
-void tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file,
- bool= ca_file_inline, const char *ca_path, bool tls_server);
+void tls_ctx_load_ca(struct tls_root_ct= x *ctx, const char *ca_file, bool ca_file_inline,
+ const char *ca_path, boo= l tls_server);

/**
* L= oad extra certificate authority certificates from the given file or path.
@@ -335,8 +332,7 @@
* @param extra_certs_f= ile_inline True if extra_certs_file is an inline
* = file.
*/
<= span style=3D"color: hsl(0, 100%, 40%);">-void tls_ctx_load_extra_certs(str= uct tls_root_ctx *ctx,

= - const char *extra_certs_file,
+void tls_ctx_load_extra_certs(stru= ct tls_root_ctx *ctx, const char *extra_certs_file,

= bool extra_certs_file_inline);

#ifdef ENABLE_CRYPTO_MBEDTLS
@@ -365,15 +361= ,14 @@
* @param is_server Initialise a server?=
* @param session The session associated with the given ke= y_state
*/
-void key_state_ssl_init(struct key_state_ssl *ks_ssl,
- const struct= tls_root_ctx *ssl_ctx, bool is_server, struct tls_session *session);
+void key_state_ssl_init(s= truct key_state_ssl *ks_ssl, const struct tls_root_ctx *ssl_ctx,
= + bool i= s_server, struct tls_session *session);

= /**
* Sets a TLS session to be shutdown state, so the TLS= library will generate
* a shutdown alert.
*/

-void
= -key_state_ssl_shutdown(struct ke= y_state_ssl *ks_ssl);
+void key_state_ssl_shutdown(struct key_state_ssl *ks_ssl);

/**
* Free the SSL channel part of t= he given key state.
@@ -390,12 +385,12 @@
= * an array containing the inline CRL.
* @param crl_inline True if crl_file is an inline CRL.

*/

-void backend_tl= s_ctx_reload_crl(struct tls_root_ctx *ssl_ctx,
- const char *crl_fi= le, bool crl_inline);
+void backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char = *crl_file,
+ = bool crl_inline);

-#define EXPORT_KEY_DATA_LABEL &q= uot;EXPORTER-OpenVPN-datakeys"
-#define EXPORT_P2P_PEERID_LABEL "EXPORTER-OpenVPN-p2= p-peerid"
-#define= EXPORT_DYNAMIC_TLS_CRYPT_LABEL "EXPORTER-OpenVPN-dynamic-tls-crypt&q= uot;
+#define EXPORT_= KEY_DATA_LABEL "EXPORTER-OpenVPN-datakeys"
+#define EXPORT_P2P_PEERID_LABEL = "EXPORTER-OpenVPN-p2p-peerid"

+#define EXPORT_DYNAMIC_TLS_CRYPT_LABEL "EXPO= RTER-OpenVPN-dynamic-tls-crypt"
/**
= * Keying Material Exporters [RFC 5705] allows additional keying material t= o be
* derived from existing TLS channel. This exported k= eying material can then be
@@ -408,10 +403,8 @@
<= span> * @param ekm_size The size of ekm, in bytes

* = @returns true if exporting succeeded, false otherwise
= */
-bool=
-key_state_export_keying_mate= rial(struct tls_session *session,
- const char *label, size_t labe= l_size,
- = void *ekm, size_t ekm_size);
+bool key_state_export_keying_material(struct tl= s_session *session, const char *label,
+ size_t label_size,= void *ekm, size_t ekm_size);

/*********= *****************************************************************/ /** @addtogroup control_tls
@@ -454,8 +447,7 @@
* again later to retry.
* - \c -1: An e= rror occurred.
*/
-int key_state_write_plaintext_const(struct key_state_ssl *ks_= ssl,
- = const uint8_t *data, int len);
+int key_state_write_plaintext_const(struct ke= y_state_ssl *ks_ssl, const uint8_t *data, int len);

/**
* Extract ciphertext data from the TLS mo= dule.
@@ -500,8 +492,7 @@
* again later= to retry.
* - \c -1: An error occurred.
= */
-int key_state_wri= te_ciphertext(struct key_state_ssl *ks_ssl,
- struct buffer *buf);
+int key_state_write_c= iphertext(struct key_state_ssl *ks_ssl, struct buffer *buf);

/**
* Extract plaintext data from th= e TLS module.
@@ -549,10 +540,8 @@
* @par= am tls13 Select if <=3DTLS1.2 or TLS1.3+ ciphers
<= span> * should be shown

*/
-void
-show_available_tls_ciphers_list(const char = *cipher_list,
- = const char *tls_cert_profile,
- bool tls13)= ;
+void show_availabl= e_tls_ciphers_list(const char *cipher_list, const char *tls_cert_profile,
+ = bool tls13);

/**<= br> * Show the available elliptic curves in the crypto library
diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h=
index e9dd5f2..e4814cd 100644
--- a/src/op= envpn/ssl_common.h
+++ b/src/openvpn/ssl_common.h@@ -118,15 +118,16 @@
* \ref key_generation "= data channel key generation".
* @ingroup control_pro= cessor
*/
-struct key_source {
- uint8_t pre_master[48]; /**< Random used for master secret
- = * generation, provided only by client
- * OpenVPN pe= er. */
- uint8_t ran= dom1[32]; /**< Seed used for master secret
- * genera= tion, provided by both client
- * and server. */
- uint8_t random2[32]; /**&l= t; Seed used for key expansion, provided

- * by both client and = server. */
+struct ke= y_source
+{+ uint8_t pre_master[48]; /= **< Random used for master secret
+ * generation, provided only= by client
+ = * OpenVPN peer. */
+ uint8_t random1[32]; /**< Seed used for mast= er secret
+ = * generation, provided by both client
+ * and= server. */
+ uint= 8_t random2[32]; /**< Seed used for key expansion, provided+ = * by both client and server. */
};


@@ -135,9 +136,10 @@
* 2 \= ref key_generation "data channel key generation".
* @ingroup control_processor

*/
-struct key_source2 {
- struct key_source client; /**< Ran= dom provided by client. */
- struct key_source server; /**< Random provided by server. */<= /span>
+struct key_source2
+{
+ struct key_source client; /**< R= andom provided by client. */
+ struct key_source server; /**< Random provided by server. *= /
};


@= @ -148,15 +150,16 @@
* being set to KS_AUTH_TRUE or KS_AU= TH_FALSE
* Only KS_AUTH_TRUE is fully authenticated
*/
-enum k= s_auth_state {
- KS_= AUTH_FALSE, /**< Key state is not authenticated */- KS_AUTH_DEFERRED, /= **< Key state authentication is being deferred,
- * by async auth= */
- KS_AUTH_TRUE = /**< Key state is authenticated. TLS and user/pass- = * succeeded. This includes AUTH_PENDING/OOB
- * authentication as th= ose hold the
- = * connection artificially in KS_AUTH_DEFERRED<= br>- = */
+enum ks_auth_st= ate
+{
+ KS_AUTH_FALSE, /**< Key = state is not authenticated */

+ KS_AUTH_DEFERRED, /**< Key state authentication is being = deferred,
+ = * by async auth */
+ KS_AUTH_TRUE /**< Key state is authenticated. TLS a= nd user/pass
+ = * succeeded. This includes AUTH_PENDING/OOB
+ * authentica= tion as those hold the

+ = */
};

struct auth_defer= red_status
@@ -169,14 +172,16 @@
/* key_state_test_auth_control_file return values, these specify t= he
* current status of a deferred authentication */
-enum auth_deferred_result {=
- ACF_PENDING, = /**< deferred auth still pending */
- ACF_SUCCEEDED, /**< deferred auth has suceeded = */
- ACF_DISABLED, = /**< deferred auth is not used */
- ACF_FAILED /**< deferred auth has failed */=
+enum auth_deferred_= result
+{
<= span style=3D"color: hsl(120, 100%, 40%);">+ ACF_PENDING, /**< defe= rred auth still pending */

+ ACF_SUCCEEDED, /**< deferred auth has suceeded */
<= span style=3D"color: hsl(120, 100%, 40%);">+ ACF_DISABLED, /**< defe= rred auth is not used */

+ ACF_FAILED /**< deferred auth has failed */
};


= -enum dco_key_status {
- t= ime_t initial; /* when we created this session */
- time_t established; /* = when our state went S_ACTIVE */

- time_t must_negotiate; /* key negotiation times out if n= ot finished before this time */
- time_t must_die; /* this object is destroyed at th= is time */
- time_t = peer_last_packet; /* Last time we received a packet in this control sess= ion */
+ time_t in= itial; /* when we created this session */
+ time_t established; /* when= our state went S_ACTIVE */
+ time_t must_negotiate; /* key negotiation times out if no= t finished before this time */
+ time_t must_die; /* this object is destroyed at = this time */
+ tim= e_t peer_last_packet; /* Last time we received a packet in this control= session */

- int initial_opcode; /* our initial P_ opcode */<= br>- struct session_id session= _id_remote; /* peer's random session ID */
+ int initial_opcode; /* our initial = P_ opcode */
+ str= uct session_id session_id_remote; /* peer's random session ID */
struct link_socket_actual remote_addr; /* peer's IP ad= dr */

- struct crypto_options crypto_options;/* data channel crypto options *= /
+ struct crypto_= options crypto_options; /* data channel crypto options */
=
- struct key_sourc= e2 *key_src; /* source entropy for key expansion */
+ struct key_source2 *key_src; = /* source entropy for key expansion */

struct buffer plaintext_read_buf;

struct buff= er plaintext_write_buf;
struct buffer ack_write_buf;

struct reliable *send_reliable; /* ho= lds a copy of outgoing packets until ACK received */
- struct reliable *rec_reliable; /* order= incoming ciphertext packets before we pass to TLS */
- struct reliable_ack *rec_ack; /* buffer= s all packet IDs we want to ACK back to sender */
- struct reliable_ack *lru_acks; /* keeps the= most recently acked packages*/
+ struct reliable *rec_reliable; /* order incoming ciphertex= t packets before we pass to TLS */
+ struct reliable_ack *rec_ack; /* buffers all packet ID= s we want to ACK back to sender */
+ struct reliable_ack *lru_acks; /* keeps the most recent= ly acked packages*/

/** Holds outgoi= ng message for the control channel until ks->state reaches
* S_ACTIVE */

struct buffer_list *paybuf;
- counter_type n_bytes;= /* how many bytes sent/recvd since last key exchange */
- counter_type n_packet= s; /* how many packets sent/recvd since last key exchange */
+ counter_type n_by= tes; /* how many bytes sent/recvd since last key exchange */
+ counter_type n_packets; /* h= ow many packets sent/recvd since last key exchange */


/*
* If bad username/password, TLS = connection will come up but 'authenticated' will be false.@@ -270,19 +275,20 @@
/** Control channel wrapping= (--tls-auth/--tls-crypt) context */
struct tls_wrap_ctx
{
- = enum {
- TLS_WRA= P_NONE =3D 0, /**< No control channel wrapping */
- TLS_WRAP_AUTH, /**< Control cha= nnel authentication */
= - TLS_WRAP_CRYPT, /**< Control channel encryption and authenticat= ion */
- } mode; = /**< Control channel wrapping mode */
- struct crypto_options opt; /**<= Crypto state */
- s= truct buffer work; /**< Work buffer (only for --tls-crypt) */
- struct key_ctx tls_c= rypt_v2_server_key; /**< Decrypts client keys */
- const struct buffer *tls_crypt_v2_wkc; = /**< Wrapped client key,
- * sent to server */=
- struct buffer tls= _crypt_v2_metadata; /**< Received from client */
- bool cleanup_key_ctx; = /**< opt.key_ctx_bi is owned by
- * this con= text */
+ enum
+ {
+ TLS_WRAP_NONE =3D 0, = /**< No control channel wrapping */
+ TLS_WRAP_AUTH, /**= < Control channel authentication */
+ TLS_WRAP_CRYPT, /**< Cont= rol channel encryption and authentication */
+ } mode; /**<= ; Control channel wrapping mode */
+ struct crypto_options opt; /**< Crypto s= tate */
+ struct b= uffer work; /**< Work buffer (only for --tls-crypt) = */
+ struct key_ct= x tls_crypt_v2_server_key; /**< Decrypts client keys */
+ const struct buffer *tls_crypt_v= 2_wkc; /**< Wrapped client key,
+ * sent to se= rver */
+ struct b= uffer tls_crypt_v2_metadata; /**< Received from client */
<= span style=3D"color: hsl(120, 100%, 40%);">+ bool cleanup_key_ctx; = /**< opt.key_ctx_bi is owned by

+ * = this context */
/** original key data to be xored in= to the key for dynamic tls-crypt.
*
= * We keep the original key data to ensure that the newly generated ke= y
@@ -364,8 +370,8 @@
/* struct crypto= _option flags */
unsigned int crypto_flags;
=
- int replay= _window; /* --replay-window parm */
- int replay_time; /* -= -replay-window parm */
+ int replay_time; /* --replay-window= parm */

const char *config_cipherna= me;
const char *config_ncp_ciphers;
@@= -393,9 +399,9 @@
const char *auth_user_pass_file;
bool auth_user_pass_file_inline;
=
- bool auth_token_generate= ; /**< Generate auth-tokens on successful
- * user/pass auth,= seet via
- = * options->auth_token_generate. */
+ bool auth_token_generate; /**<= ; Generate auth-tokens on successful
+ * user/pass auth,seet via<= /span>
+ = * options->auth_token_generate. */
bool= auth_token_call_auth; /**< always call normal authentication */<= br> unsigned int auth_token_lifetime;
unsign= ed int auth_token_renewal;
@@ -416,17 +422,17 @@
= #endif

/* configuration file = SSL-related boolean and low-permutation options */
-#define SSLF_CLIENT_CERT_NOT_REQUIRED (1<&l= t;0)
-#define SSLF_CLIE= NT_CERT_OPTIONAL (1<<1)
-#define SSLF_USERNAME_AS_COMMON_NAME (1<<2)
-#define SSLF_AUTH_USER_PASS_OPTION= AL (1<<3)

-#defi= ne SSLF_OPT_VERIFY (1<<4)
-#define SSLF_CRL_VERIFY_DIR (1<<5)<= /span>
+#define SSLF_CLIENT_= CERT_NOT_REQUIRED (1 << 0)
+#define SSLF_CLIENT_CERT_OPTIONAL (1 << 1)+#define SSLF_USERNAME_AS_COMM= ON_NAME (1 << 2)
+#define SSLF_AUTH_USER_PASS_OPTIONAL (1 << 3)
+#define SSLF_OPT_VERIFY = (1 << 4)
+#defi= ne SSLF_CRL_VERIFY_DIR (1 << 5)
#define SS= LF_TLS_VERSION_MIN_SHIFT 6
-#define SSLF_TLS_VERSION_MIN_MASK 0xF /* (uses bit positions 6= to 9) */
+#define SS= LF_TLS_VERSION_MIN_MASK 0xF /* (uses bit positions 6 to 9) */ #define SSLF_TLS_VERSION_MAX_SHIFT 10
-#define SSLF_TLS_VERSION_MAX_MASK 0xF /* (u= ses bit positions 10 to 13) */
-#define SSLF_TLS_DEBUG_ENABLED (1<<14)
+#define SSLF_TLS_VERSION_MAX_MASK = 0xF /* (uses bit positions 10 to 13) */

+#define SSLF_TLS_DEBUG_ENABLED (1 << 1= 4)
unsigned int ssl_flags;
#ifdef ENABLE_MANAGEMENT
@@ -457,10 +463,11 @@
* This is the index of \c tls_session.key
= *
* @{ */
-#define KS_PRIMARY 0 /**< Primary %key state index. */=
-#define KS_LAME_DUCK = 1 /**< %Key state index that will retire
- * soon. = */
-#define KS_SIZE = 2 /**< Size of the \c tls_session.key array. */
+#define KS_PRIMARY 0 /**< Prim= ary %key state index. */

+#define KS_LAME_DUCK \+ 1 /**<= %Key state index that will retire \
+ * soon. */
+#define KS_SIZE 2 /**< Size of the = \c tls_session.key array. */
/** @} name Index of key_stat= e objects within a tls_session structure */
/** @} addtogr= oup control_processor */

@@ -495,7 +502,7= @@
* tls_wrap_reneg.mode is TLS_WRAP_CRYPT, otherwis= e ignore it */
struct tls_wrap_ctx tls_wrap_reneg;

- int= initial_opcode; /* our initial P_ opcode */
+ int initial_opcode; /* our = initial P_ opcode */
struct session_id session_id; /* = our random session ID */

/**<= br>@@ -511,7 +518,7 @@

struct = cert_hash_set *cert_hash_set;

- bool verified; /* true if peer c= ertificate was verified against CA */
+ bool verified; /* true if peer certificate was verifi= ed against CA */

/* not-yet-authenti= cated incoming client */
struct link_socket_actual unt= rusted_addr;
@@ -536,12 +543,14 @@
* is = being negotiated.
*
* @{ */
= -#define TM_ACTIVE 0 = /**< Active \c tls_session. */
-#define TM_INITIAL 1 /**< As yet un-trusted \c tl= s_session
- = * being negotiated. */
-#define TM_LAME_DUCK 2 /**< Old \c tls_= session. */
-#define TM= _SIZE 3 /**< Size of the \c tls_multi.session
- *= array. */

+#define= TM_ACTIVE 0 /**< Active \c tls_session. */
+#define TM_INITIAL = \
+ = 1 /**< As yet un-trusted \c tls_session \
<= span style=3D"color: hsl(120, 100%, 40%);">+ * bei= ng negotiated. */

+#d= efine TM_LAME_DUCK 2 /**< Old \c tls_session. */
+#define TM_SIZE = \
+ 3 /**< Size of the \c tls_multi.session \<= br>+ * = array. */
/** @} name Index of tls_session objects within= a tls_multi structure */
/** @} addtogroup control_proces= sor */

@@ -613,7 +622,7 @@
* used by tls_pre_encrypt to communicate the encrypt key

= * to tls_post_encrypt()
*/
- struct key_state *save_ks; /* t= emporary pointer used between pre/post routines */

+ struct key_state *save_ks; /* temporary = pointer used between pre/post routines */

/*

* Used to return outgoing address from
@@ -621,8 +630,8 @@
*/
= struct link_socket_actual to_link_addr;

- int n_sessions; /**&l= t; Number of sessions negotiated thus

- * far. */
+ int n_sessions; /**< Number= of sessions negotiated thus

+ * far. */
enum multi_s= tatus multi_state;

/*
@@ -693,8 +702,8 @@

uint32_t peer_id;
bool use_peer_id;


- char *remote_ciphername; /**< cipher specifi= ed in peer's config file */
- bool remote_usescomp; /**< remote announced comp-lzo= in OCC string */
+ = char *remote_ciphername; /**< cipher specified in peer's config fi= le */
+ bool remot= e_usescomp; /**< remote announced comp-lzo in OCC string */
/*
* Our session object= s.
diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl= _mbedtls.c
index a4bb772..c619551 100644
--= - a/src/openvpn/ssl_mbedtls.c
+++ b/src/openvpn/ssl_mbedtls= .c
@@ -53,35 +53,28 @@
#include <mbedtl= s/version.h>

#if MBEDTLS_VERSION_NUMB= ER >=3D 0x02040000
-= #include <mbedtls/net_sockets.h>
+#include <mbedtls/net_sockets.h>
#else

- #include= <mbedtls/net.h>
-static const mbedtls_x509_crt_profile openvpn_x509_crt_pr= ofile_legacy =3D
-{
+static const mbedtls_x5= 09_crt_profile openvpn_x509_crt_profile_legacy =3D {
/= * Hashes from SHA-1 and above */
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 )
- |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_RIPE= MD160 )
- |MBEDTLS_X= 509_ID_FLAG( MBEDTLS_MD_SHA224 )
- |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 )
- |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_S= HA384 )
- |MBEDTLS_X= 509_ID_FLAG( MBEDTLS_MD_SHA512 ),
+ MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA1) | MBEDTLS_X509_ID_F= LAG(MBEDTLS_MD_RIPEMD160)
+ | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA224) | MBEDTLS_X509_ID_F= LAG(MBEDTLS_MD_SHA256)
-static const mbedtls_x509_= crt_profile openvpn_x509_crt_profile_preferred =3D
-{
+static const mbedtls_x509_crt_profile openvpn_x509_crt_profile_p= referred =3D {
/* SHA-2 and above */
- MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SH= A224 )
- |MBEDTLS_X5= 09_ID_FLAG( MBEDTLS_MD_SHA256 )
- |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA384 )
- |MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SH= A512 ),
+ MBEDTLS_= X509_ID_FLAG(MBEDTLS_MD_SHA224) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256)
+ | MBEDTLS_X50= 9_ID_FLAG(MBEDTLS_MD_SHA384) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512),
0xFFFFFFF, /* Any PK alg */
0xFFF= FFFF, /* Any curve */
2048, /* RSA-2048 and l= arger */
@@ -185,9 +178,8 @@
* Mbed TLS s= tores this callback in the mbedtls_ssl_config struct and it
* is used in the mbedtls_ssl_contexts set up from that config. */
=
int
-mbedtls= _ssl_export_keys_cb(void *p_expkey, const unsigned char *ms,
- const uns= igned char *kb, size_t maclen,

- size_t keylen, size_t ivlen,
= +mbedtls_ssl_export_keys_cb(voi= d *p_expkey, const unsigned char *ms, const unsigned char *kb,
+ size_= t maclen, size_t keylen, size_t ivlen,

= const unsigned char client_random[32],
= const unsigned char server_random[32],
= mbedtls_tls_prf_types tls_prf_type)
@@ -196,8 +188,8 @@

struct key_state_ssl *ks_ssl =3D = &session->key[KS_PRIMARY].ks_ssl;
struct tls_ke= y_cache *cache =3D &ks_ssl->tls_key_cache;
<= br>- static_assert(sizeof(ks_s= sl->ctx->session->master)
- =3D=3D sizeof(cache->master_secret), &quo= t;master size mismatch");
+ static_assert(sizeof(ks_ssl->ctx->session->master) = =3D=3D sizeof(cache->master_secret),
+ "master size mismatch");

memcpy(cache->client_server_random,= client_random, 32);
memcpy(cache->client_server_ra= ndom + 32, server_random, 32);
@@ -219,10 +211,8 @@<= br> * mbedtls_ssl_config. It is placed in the mbedtls_ssl_context af= ter it
* has been set up. */
void=
-mbedtls_ssl_export_keys_cb(v= oid *p_expkey,
- = mbedtls_ssl_key_export_type type,
- const unsigned c= har *secret,
- = size_t secret_len,
+mbedtls_ssl_export_keys_cb(void *p_expkey, mbedtls_ssl_key= _export_type type,
+ = const unsigned char *secret, size_t secret_len,
const unsigned char client_rando= m[32],
const unsigned char serv= er_random[32],
mbedtls_tls_prf_= types tls_prf_type)
@@ -242,8 +232,7 @@
= * a different value, something is wrong with mbed TLS. */
if (secret_len !=3D sizeof(cache->master_secret))

{

- msg(M_= FATAL,
- &qu= ot;ERROR: Incorrect TLS 1.2 master secret length: Got %zu, expected %zu&quo= t;,
+ msg(M_FA= TAL, "ERROR: Incorrect TLS 1.2 master secret length: Got %zu, expected= %zu",
secret_len, sizeof(cache->maste= r_secret));
}

@@ -25= 8,8 +247,7 @@


bool
-key_state_export_keying_m= aterial(struct tls_session *session,
- const char *label, size_t l= abel_size,
+key_state= _export_keying_material(struct tls_session *session, const char *label, siz= e_t label_size,
void *ekm= , size_t ekm_size)
{
ASSERT(strlen(la= bel) =3D=3D label_size);
@@ -268,7 +256,8 @@
/* Our version of mbed TLS has a built-in TLS-Exporter. */

mbedtls_ssl_context *ctx =3D session->key[= KS_PRIMARY].ks_ssl.ctx;
- if (mbed_ok(mbedtls_ssl_export_keying_material(ctx, ekm, ekm_size, la= bel, label_size, NULL, 0, 0)))
+ if (mbed_ok(
+ mbedtls_ssl_export_keying_material(ctx, ekm, ekm_size, = label, label_size, NULL, 0, 0)))
{
= return true;
}
@@ -288,10 +277,8= @@
}

int ret = =3D mbedtls_ssl_tls_prf(cache->tls_prf_type, cache->master_secret,
- = sizeof(cache->master_secret),
- label, cache->cli= ent_server_random,
- = sizeof(cache->client_server_random),
- = ekm, ekm_size);
+ sizeof(cache->master_secret), labe= l, cache->client_server_random,
+ sizeof(cache->client_se= rver_random), ekm, ekm_size);

if (mb= ed_ok(ret))
{
@@ -302,7 +289,7 @@
secure_memzero(ekm, session->opt->ekm_size);
return false;
}
-#endif /* defined(MBEDTLS_SSL_KEYING_= MATERIAL_EXPORT) */
+= #endif /* defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) */
}=

bool
@@ -325,7 +312,8 @= @
if (0 !=3D strcmp(cipher_name, pair->iana_name))<= /span>
{
/* Deprecated name found, n= otify user */
- = msg(M_WARN, "Deprecated cipher suite name '%s', please use IAN= A name '%s'", pair->openssl_name, pair->iana_name);
+ msg(M_WARN, &quo= t;Deprecated cipher suite name '%s', please use IANA name '%s&#= 39;",
+ = pair->openssl_name, pair->iana_name);
}

return pair->iana_name;
@@ -340,8 +328,10 @@

return;
= }

-= msg(M_WARN, "mbed TLS does not support setting tls-ciphersuites. &= quot;
- "Ig= noring TLS 1.3 cipher list: %s", ciphers);
+ msg(M_WARN,
+ "mbed TLS does not support setting tls= -ciphersuites. "
+ "Ignoring TLS 1.3 cipher list: %s",
+ ciphers);
}

void
@@ -360,7 +350,7 @@
int cipher_count =3D get_num_elements(ciphers, ':&#= 39;);

/* Allocate an array for them = */
- ALLOC_ARRAY_CLE= AR(ctx->allowed_ciphers, int, cipher_count+1)
+ ALLOC_ARRAY_CLEAR(ctx->allowed_ciphers,= int, cipher_count + 1)

/* Parse all= owed ciphers, getting IDs */
int i =3D 0;
@@ -369,8 +359,7 @@

token =3D strtok(tmp_ciphers, = ":");
while (token)
{
- ctx->allowed= _ciphers[i] =3D mbedtls_ssl_get_ciphersuite_id(
- tls_translate_cipher_name(token));
+ ctx->allowe= d_ciphers[i] =3D mbedtls_ssl_get_ciphersuite_id(tls_translate_cipher_name(t= oken));
if (0 !=3D ctx->allowed_ciphers[i])
{
i++;
@= @ -383,8 +372,7 @@
void
tls_ctx_set_cert_= profile(struct tls_root_ctx *ctx, const char *profile)
{
- if (!profile || 0 = =3D=3D strcmp(profile, "legacy")
- || 0 =3D=3D strcmp(profile, "insecure&quo= t;))
+ if (!profil= e || 0 =3D=3D strcmp(profile, "legacy") || 0 =3D=3D strcmp(profil= e, "insecure"))
{
c= tx->cert_profile =3D openvpn_x509_crt_profile_legacy;
= }
@@ -419,8 +407,7 @@
const char *t= oken;
while ((token =3D strsep(&tmp_groups, "= :")))
{
- const mbedtls_ecp_curve_info *ci =3D
- mbedtls_ecp_curve_info_from_= name(token);
+ = const mbedtls_ecp_curve_info *ci =3D mbedtls_ecp_curve_info_from_name(toke= n);
if (!ci)
{
= msg(M_WARN, "Warning unknown curve/group specified:= %s", token);
@@ -462,13 +449,11 @@
}=

void
-tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const c= har *dh_file,
- = bool dh_inline)
+tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_= file, bool dh_inline)
{
if (dh_inline= )
{
- = (const unsigned char *) dh_file,
+ if (!mbed_ok(mbedtls_dhm_parse_dhm(ctx->dh= m_ctx, (const unsigned char *)dh_file,
= strlen(dh_file) + 1)))
{
msg(M_FATAL, "Cannot read inline DH parame= ters");
@@ -483,24 +468,23 @@
}

msg(D_TLS_DEBUG_LOW, "Diffie-Hel= lman initialized with " counter_format " bit key",- (counter_type) mbedtls_= dhm_get_bitlen(ctx->dhm_ctx));
+ (counter_type)mbedtls_dhm_get_bitlen(ctx->dhm_ctx)= );
}

void
-tls_ctx_load_ecdh_params(struct tls= _root_ctx *ctx, const char *curve_name

- )
+tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, = const char *curve_name)
{
if (NULL != =3D curve_name)
{
msg(M_WARN,= "WARNING: mbed TLS builds do not support specifying an "<= br>- "ECDH curve = with --ecdh-curve, using default curves. Use "
- "--tls-groups to specify c= urves.");
+ = "ECDH curve with --ecdh-curve, using default curves. Us= e "
+ = "--tls-groups to specify curves.");
= }
}

int
-tls_ctx_load_pkcs12(struct tls_root_= ctx *ctx, const char *pkcs12_file,

- bool pkcs12_file_inline, bool load_ca_file= )
+tls_ctx_load_pkcs1= 2(struct tls_root_ctx *ctx, const char *pkcs12_file, bool pkcs12_file_inlin= e,
+ = bool load_ca_file)
{
msg(M_FATAL, = "PKCS #12 files not yet supported for mbed TLS.");
return 0;

@@ -515,8 +499,7 @@
#endi= f /* _WIN32 */

void
-tls_ctx_load_cert_file(struct tls_root_ctx= *ctx, const char *cert_file,
- bool cert_inline)
+tls_ctx_load_cert_file(struct tls_root_ctx *ct= x, const char *cert_file, bool cert_inline)
{
ASSERT(NULL !=3D ctx);


@@ -527,8= +510,7 @@

if (cert_inline) {
- = if (!mbed_ok(mbedtls_x509_crt_parse(ctx->crt_chain,
- = (const unsigned char *)cert_file,
+ if (!mbed_ok(mbedtls_x509_crt_parse(ctx->crt_ch= ain, (const unsigned char *)cert_file,
= strlen(cert_file) + 1)))
= {
msg(M_FATAL, "Cannot load inline certif= icate file");
@@ -544,8 +526,7 @@
}

int
-tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const char= *priv_key_file,
- = bool priv_key_inline)
+tls_ctx_load_priv_file(struct tls_root_ctx *ctx, const = char *priv_key_file, bool priv_key_inline)
{
int status;

ASSERT(NULL !=3D ctx);
<= span>@@ -557,40 +538,29 @@


if (priv_= key_inline)
{
- status =3D mbedtls_compat_pk_parse_key(ctx->priv_ke= y,
- = (const unsigned char *) priv_key_file,
= + status =3D mbedtls_com= pat_pk_parse_key(ctx->priv_key, (const unsigned char *)priv_key_file,
strlen(priv_key= _file) + 1, NULL, 0,
- = mbedtls_ctr_drbg_random,=
- = rand_ctx_get());
+ mbedtls_ctr_drbg= _random, rand_ctx_get());

if (MB= EDTLS_ERR_PK_PASSWORD_REQUIRED =3D=3D status)
{
- char passbuf= [512] =3D {0};
+ = char passbuf[512] =3D { 0 };
pem_passwo= rd_callback(passbuf, 512, 0, NULL);
- status =3D mbedtls_compat_pk_parse_key(ctx->pr= iv_key,
- = (const unsigned char *) priv_key_file,
- = strlen(priv_key_file) + 1,
- = (unsigned char *) passbuf,
- strlen(passbuf)= ,
- = mbedtls_ctr_drbg_random,
- = rand_ctx_get());
+ ctx->priv_key, (const= unsigned char *)priv_key_file, strlen(priv_key_file) + 1,
+ (unsigned char *)pas= sbuf, strlen(passbuf), mbedtls_ctr_drbg_random, rand_ctx_get());
= }
}
else {
- = status =3D mbedtls_compat_pk_parse_keyfile(ctx->priv_key,
- = priv_key_file,

- NULL,
- = mbedtls_ctr_drbg_random,

- rand_ctx_g= et());
+ statu= s =3D mbedtls_compat_pk_parse_keyfile(ctx->priv_key, priv_key_file, NULL= ,
+ = mbedtls_ctr_drbg_random, rand_ctx_get());
if (MBEDTLS_ERR_PK_PASSWORD_REQUIRED =3D=3D status)<= /span>
{
- char passbuf[512] =3D {0};
+ char passbuf[512] =3D { 0 };
= pem_password_callback(passbuf, 512, 0, NULL);
= - status =3D mbedtls_c= ompat_pk_parse_keyfile(ctx->priv_key,
- pri= v_key_file, passbuf,
- = mbedtls_ctr_drbg_random= ,
- = rand_ctx_get());
+ status =3D mbedtls_compat_pk_pars= e_keyfile(ctx->priv_key, priv_key_file, passbuf,
+ = mbedtls_ctr_drbg_random, rand_ctx_get());
= }
}
if (!mbed_ok(status))
@@ -606,10 +576,8 @@
return 1;=
}

- if (!mbed_ok(mbedtls_compat_pk_check_pair(&ctx->crt= _chain->pk,
- = ctx->priv_key,
- = mbedtls_ctr_drbg_random,
- rand_ctx_get())))
+ if (!mbed_ok(mbedt= ls_compat_pk_check_pair(&ctx->crt_chain->pk, ctx->priv_key,
+ = mbedtls_ctr_drbg_random, rand_ctx_get()))) {
msg(M_WARN, "Private key does = not match the certificate");
return 1;=
@@ -637,13 +605,12 @@
* @return 0 on success, n= on-zero mbed TLS error code on failure.
*/
static inline int

-e= xternal_pkcs1_sign( void *ctx_voidptr,
- int (*f_rng)(void *, unsigned char *,= size_t), void *p_rng,
- = int mode,
= + int mode,
#endif
- mbedtls_md_type_t md_= alg, unsigned int hashlen, const unsigned char *hash,
- unsigned char *sig )
+ m= bedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash,
+ u= nsigned char *sig)
{
struct external_= context *const ctx =3D ctx_voidptr;
int rv;
= @@ -671,23 +638,22 @@
*/
i= f (md_alg !=3D MBEDTLS_MD_NONE)
{
- const mbedtls_md_info_t *md_info = =3D mbedtls_md_info_from_type( md_alg );
+ const mbedtls_md_info_t *md_info =3D mbedtls_m= d_info_from_type(md_alg);
if (md_info =3D=3D NULL)=
{
- return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
+ return (MBEDTLS_ERR_RSA= _BAD_INPUT_DATA);

}

- if (!mbed_ok(mbedtls_oid_g= et_oid_by_md( md_alg, &oid, &oid_size )))

+ if (!mbed_ok(mbedtls_oid_get_oid_by_m= d(md_alg, &oid, &oid_size)))
{
<= span style=3D"color: hsl(0, 100%, 40%);">- return( MBEDTLS_ERR_R= SA_BAD_INPUT_DATA );

= + return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA);
= }

- hashlen =3D mbedtls_md_get_size( md_info );
+ hashlen =3D mbedtls_md_get_size(m= d_info);
asn_len =3D 10 + oid_size;
}


- if ((SIZE_MAX - hashlen) < asn_len
- || ctx->signature_length < (asn_len = + hashlen))
+ if (= (SIZE_MAX - hashlen) < asn_len || ctx->signature_length < (asn_len= + hashlen))
{
return MBEDTLS= _ERR_RSA_BAD_INPUT_DATA;
}
@@ -706,12 = +672,12 @@
* Digest ::=3D OCTET STRING
= */
*p++ =3D MBEDTLS_ASN1_SEQUENCE = | MBEDTLS_ASN1_CONSTRUCTED;
- *p++ =3D (unsigned char) ( 0x08 + oid_size + hashlen );
+ *p++ =3D (unsigne= d char)(0x08 + oid_size + hashlen);
*p++ =3D MBEDT= LS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED;
- *p++ =3D (unsigned char) ( 0x04 + oid_size )= ;
+ *p++ =3D (= unsigned char)(0x04 + oid_size);
*p++ =3D MBEDTLS_= ASN1_OID;
*p++ =3D oid_size & 0xFF;
= - memcpy( p, oid, oid_size= );
+ memcpy(p= , oid, oid_size);
p +=3D oid_size;
*p++ =3D MBEDTLS_ASN1_NULL;

*p++ =3D 0x0= 0;
@@ -726,8 +692,7 @@
memcpy(p, hash,= hashlen);

/* Call external signatur= e function */
- if (= !ctx->sign(ctx->sign_ctx, to_sign, asn_len + hashlen, sig,
= - ctx->signa= ture_length))
+ if= (!ctx->sign(ctx->sign_ctx, to_sign, asn_len + hashlen, sig, ctx->= signature_length))
{
rv =3D M= BEDTLS_ERR_RSA_PRIVATE_FAILED;
goto done;@@ -749,8 +714,8 @@
}

= int
-tls_ctx_use= _external_signing_func(struct tls_root_ctx *ctx,
- external_sign_= func sign_func, void *sign_ctx)
+tls_ctx_use_external_signing_func(struct tls_root_ctx *ctx, ext= ernal_sign_func sign_func,
+ void *sign_ctx)
{=
ASSERT(NULL !=3D ctx);

@@ -763,7 +728,7 @@

if (mbedtls_pk_get_type(&c= tx->crt_chain->pk) !=3D MBEDTLS_PK_RSA)
{=
msg(M_WARN, "ERROR: external key with mbed TLS requ= ires a "
- = "certificate with an RSA key.");
+ "certificate with an RS= A key.");
return 1;
}

@@ -772,8 +737,8 @@
ct= x->external_key.sign_ctx =3D sign_ctx;

ALLOC_OBJ_CLEAR(ctx->priv_key, mbedtls_pk_context);

- if (!mbed_ok(mbedtls_pk_setup_rs= a_alt(ctx->priv_key, &ctx->external_key,

- NULL= , external_pkcs1_sign, external_key_len)))
+ if (!mbed_ok(mbedtls_pk_setup_rsa_alt(ctx->pr= iv_key, &ctx->external_key, NULL,
+ external_pkc= s1_sign, external_key_len)))
{
= return 1;
}
@@ -784,8 +749,7 @@
#ifdef ENABLE_MANAGEMENT
/** Query the manage= ment interface for a signature, see external_sign_func. */
= static bool
-managemen= t_sign_func(void *sign_ctx, const void *src, size_t src_len,
- void *dst, size= _t dst_len)

+manageme= nt_sign_func(void *sign_ctx, const void *src, size_t src_len, void *dst, si= ze_t dst_len)
{
bool ret =3D false;
char *src_b64 =3D NULL;
@@ -800,8 +764,= 7 @@
* We only support RSA external keys and PKCS1 si= gnatures at the moment
* in mbed TLS, so the signatur= e parameter is hardcoded to this encoding
*/- if (!(dst_b64 =3D manageme= nt_query_pk_sig(management, src_b64,
- "RSA_PKCS1_= PADDING")))
+ = if (!(dst_b64 =3D management_query_pk_sig(management, src_b64, "RSA_P= KCS1_PADDING")))
{
goto = cleanup;
}
@@ -828,8 +791,8 @@<= br> #endif /* ifdef ENABLE_MANAGEMENT */

= void
-tls_ctx_lo= ad_ca(struct tls_root_ctx *ctx, const char *ca_file,
- bool ca_inline, const char = *ca_path, bool tls_server)
+tls_ctx_load_ca(struct tls_root_ctx *ctx, const char *ca_file, bool = ca_inline, const char *ca_path,
+ bool tls_server)
{
<= span> if (ca_path)

{
@@ -838,8 +80= 1,7 @@

if (ca_file && ca_inl= ine)
{
- if (!mbed_ok(mbedtls_x509_crt_parse(ctx->ca_chain,<= br>- = (const unsigned char *) ca_file,
+ if (!mbed_ok(mbedtls_x509_crt_parse(ctx= ->ca_chain, (const unsigned char *)ca_file,
= strlen(ca_file) + 1)))
= {
msg(M_FATAL, "Cannot load inline = CA certificates");
@@ -868,8 +830,7 @@

if (extra_certs_inline)
{
- if (!mbed_ok(mbedt= ls_x509_crt_parse(ctx->crt_chain,
- (const unsigned = char *) extra_certs_file,
+ if (!mbed_ok(mbedtls_x509_crt_parse(ctx->crt_chain, (const= unsigned char *)extra_certs_file,
= strlen(extra_certs_file) + 1)))
= {
msg(M_FATAL, "Cannot load inline ext= ra-certs file");
@@ -917,7 +878,7 @@
= }

static int
-endless_buf_read( endless_buffer *in, unsigned ch= ar *out, size_t out_len )
+endless_buf_read(endless_buffer *in, unsigned char *out, size_t out_l= en)
{
size_t read_len =3D 0;
@@ -932,8 +893,7 @@
if (= block_len <=3D out_len - read_len)
{
= buffer_entry *cur_entry =3D in->first_block;- memcpy(out + read_= len, cur_entry->data + in->data_start,
- block_len);
+ memcpy(out + read_len, cur_en= try->data + in->data_start, block_len);

<= span> read_len +=3D block_len;


@@ -949,8 +909,7 @@

}
e= lse
{
- memcpy(out + read_len, in->first_block->data + i= n->data_start,
- = out_len - read_len);
+ memcpy(out + read_len, in->first_block->d= ata + in->data_start, out_len - read_len);
= in->data_start +=3D out_len - read_len;
rea= d_len =3D out_len;
}
@@ -960,7 +91= 9,7 @@
}

static int
-endless_buf_write( endles= s_buffer *out, const unsigned char *in, size_t len )
+endless_buf_write(endless_buffer *out, co= nst unsigned char *in, size_t len)
{
= buffer_entry *new_block =3D malloc(sizeof(buffer_entry));
= if (NULL =3D=3D new_block)
@@ -996,22 +955,21 @@=
}

static int
-ssl_bio_read( void *ctx, unsigned char= *out, size_t out_len)
- bio_ctx *my= _ctx =3D (bio_ctx *) ctx;
+ bio_ctx *my_ctx =3D (bio_ctx *)ctx;
return e= ndless_buf_read(&my_ctx->in, out, out_len);
}

static int
-ssl_bio_write( void *ctx, const unsigned char *in, size_= t in_len)
+ssl_bio_wr= ite(void *ctx, const unsigned char *in, size_t in_len)
{
- bio_ctx *my_ctx =3D= (bio_ctx *) ctx;
+ = bio_ctx *my_ctx =3D (bio_ctx *)ctx;
return endless_b= uf_write(&my_ctx->out, in, in_len);
}

static void
-my_debug( void *ctx, int level, const char *file, int line,
- const char *str= )
+my_debug(void *ct= x, int level, const char *file, int line, const char *str)
= {
int my_loglevel =3D (level < 3) ? D_TLS_DEBUG_ME= D : D_TLS_DEBUG;
msg(my_loglevel, "mbed TLS msg (= %s:%d): %s", file, line, str);
@@ -1023,8 +981,8 @@
void
tls_ctx_personalise_random(struct tls_= root_ctx *ctx)
{
- static char old_sha256_hash[32] =3D {0};
- unsigned char sha256_hash[32] =3D {0= };
+ static char o= ld_sha256_hash[32] =3D { 0 };
+ unsigned char sha256_hash[32] =3D { 0 };
= mbedtls_ctr_drbg_context *cd_ctx =3D rand_ctx_get();

if (NULL !=3D ctx->crt_chain)
@@ -1056= ,7 +1014,7 @@
#elif defined(MBEDTLS_SSL_PROTO_TLS1_2)
return TLS_VER_1_2;
#else
- #error mbedtls is compiled withou= t support for TLS 1.2 or 1.3

+#error mbedtls is compiled without support for TLS 1.2 or 1.3
#endif
}

@@= -1089,8 +1047,7 @@
}

v= oid
-backend_tls_ctx_re= load_crl(struct tls_root_ctx *ctx, const char *crl_file,
- bool crl_inli= ne)
+backend_tls_ctx_= reload_crl(struct tls_root_ctx *ctx, const char *crl_file, bool crl_inline)=
{
ASSERT(crl_file);
=
@@ -1102,8 +1059,7 @@

= if (crl_inline)
{
- if (!mbed_ok(mbedtls_x509_crl_parse(ctx->cr= l,
- = (const unsigned char *)crl_file,
+ if (!mbed_ok(mbedtls_x509_crl= _parse(ctx->crl, (const unsigned char *)crl_file,
= strlen(crl_file) + 1)))
{

msg(M_WARN, "CRL: cannot p= arse inline CRL");
@@ -1125,8 +1081,7 @@
}


void
-key_state_ssl_init(struct key_state_ssl *ks_ssl,
- const= struct tls_root_ctx *ssl_ctx, bool is_server,
+key_state_ssl_init(struct key_state_ssl *ks_ssl,= const struct tls_root_ctx *ssl_ctx, bool is_server,
= struct tls_session *session)
{
ASSERT(NULL !=3D ssl_ctx);

@@ -1136,8 +1091,8 @@
/* Initialise SSL config */
ALLOC_O= BJ_CLEAR(ks_ssl->ssl_config, mbedtls_ssl_config);
m= bedtls_ssl_config_init(ks_ssl->ssl_config);
- mbedtls_ssl_config_defaults(ks_ssl->ssl_con= fig, ssl_ctx->endpoint,
- MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_= SSL_PRESET_DEFAULT);
= + mbedtls_ssl_config_defaults(ks_ssl->ssl_config, ssl_ctx->endpoin= t, MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT);
#ifdef MBEDTLS_DEBUG_C
/* We only want= to have mbed TLS generate debug level logging when we would
* also display it.

@@ -1153,8 +1108,7 @@
= }
#endif
mbedtls_ssl_conf_= dbg(ks_ssl->ssl_config, my_debug, NULL);
- mbedtls_ssl_conf_rng(ks_ssl->ssl_config, mbedt= ls_ctr_drbg_random,
- = rand_ctx_get());
+ mbedtls_ssl_conf_rng(ks_ssl->ssl_config, mbedtls= _ctr_drbg_random, rand_ctx_get());

m= bedtls_ssl_conf_cert_profile(ks_ssl->ssl_config, &ssl_ctx->cert_p= rofile);

@@ -1169,8 +1123,8 @@
= }

/* Disable TLS renegoti= ations if the mbedtls library supports that feature.
- * OpenVPN's renegotiation creates n= ew SSL sessions and does not depend on
- * this feature and TLS renegotiations have been proble= matic in the past. */
+ * OpenVPN's renegotiation creates new SSL sessions and does not = depend on
+ * thi= s feature and TLS renegotiations have been problematic in the past. */
#if defined(MBEDTLS_SSL_RENEGOTIATION)
mb= edtls_ssl_conf_renegotiation(ks_ssl->ssl_config, MBEDTLS_SSL_RENEGOTIATI= ON_DISABLED);
#endif /* MBEDTLS_SSL_RENEGOTIATION */
@@ -1187,12 +1141,10 @@
/* Initialise authe= ntication information */
if (is_server)
{

- mbed_= ok(mbedtls_ssl_conf_dh_param_ctx(ks_ssl->ssl_config,
- = ssl_ctx->dhm_ctx));
+ mbed_ok(mbedtls_ssl_conf_dh_param_ctx(ks_ssl->ssl_config= , ssl_ctx->dhm_ctx));
}
- mbed_ok(mbedtls_ssl_conf_ow= n_cert(ks_ssl->ssl_config, ssl_ctx->crt_chain,
- ssl_c= tx->priv_key));
+ = mbed_ok(mbedtls_ssl_conf_own_cert(ks_ssl->ssl_config, ssl_ctx->crt= _chain, ssl_ctx->priv_key));

/* I= nitialise SSL verification */
if (session->opt->= ssl_flags & SSLF_CLIENT_CERT_OPTIONAL)
@@ -1211,8 +1163= ,7 @@
/* Initialize minimum TLS version */
<= span> {

const int configured_tls_version_min = =3D
- (sessi= on->opt->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT)
- &SSLF_TLS_VERSION_M= IN_MASK;

+ = (session->opt->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & = SSLF_TLS_VERSION_MIN_MASK;

/* de= fault to TLS 1.2 */
mbedtls_ssl_protocol_version v= ersion =3D MBEDTLS_SSL_VERSION_TLS1_2;
@@ -1228,8 +1179,7 @= @
/* Initialize maximum TLS version */
{

const int configured_tls_version_max =3D
- (session-&g= t;opt->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT)
- &SSLF_TLS_VERSION_MAX_MA= SK;
+ (ses= sion->opt->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_= TLS_VERSION_MAX_MASK;

mbedtls_ss= l_protocol_version version =3D MBEDTLS_SSL_VERSION_UNKNOWN;

@@ -1246,10 +1196,10 @@
mbedtls= _ssl_conf_max_tls_version(ks_ssl->ssl_config, version);
= }

+#if defined(HAVE_MBEDTLS_SSL_CONF_EXPORT_KEYS_EXT_CB) \
+ && !defin= ed(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT)
/* Initialize k= eying material exporter, old style. */
- mbedtls_ssl_conf_export_keys_ext_cb(ks_ssl->ssl_con= fig,
- = mbedtls_ssl_export_keys_cb, session);
+ mbedtls_ssl_conf_export_keys_e= xt_cb(ks_ssl->ssl_config, mbedtls_ssl_export_keys_cb, session);
#endif

/* Initialise SSL co= ntext */
@@ -1268,8 +1218,7 @@

= /* Initialise BIOs */
ALLOC_OBJ_CLEAR(ks_ss= l->bio_ctx, bio_ctx);
- = ssl_bio_read, NULL);
+ mbedtls_ssl_set_bio(ks_ssl->ctx, ks_ssl->bio_ctx, ssl_bio_w= rite, ssl_bio_read, NULL);
}

<= span>

@@ -1318,7 +1267,7 @@

if (1 =3D=3D retval)

{
- memset(BPTR(buf), 0, BLEN(buf)); /= * erase data just written */
+ memset(BPTR(buf), 0, BLEN(buf)); /* erase data just writte= n */
buf->len =3D 0;
}

@@ -1351,16 +1300,14 @@
= {
return 0;
}
- mbed_log_err(D_T= LS_ERRORS, retval,
- = "TLS ERROR: write tls_write_plaintext_const error&qu= ot;);
+ mbed_l= og_err(D_TLS_ERRORS, retval, "TLS ERROR: write tls_write_plaintext_con= st error");
return -1;
}=

if (retval !=3D len)
{

- msg(D= _TLS_ERRORS,
- = "TLS ERROR: write tls_write_plaintext_const incomplete %d/%d",=
- retval, l= en);
+ msg(D_T= LS_ERRORS, "TLS ERROR: write tls_write_plaintext_const incomplete %d/%= d", retval,
+ = len);
perf_pop();
= return -1;
}
@@ -1447,15 +1394,14 @@=
{
return 0; }
- = mbed_log_err(D_TLS_ERRORS, retval,
- "TLS ERROR: write tls_write_cip= hertext error");
+ mbed_log_err(D_TLS_ERRORS, retval, "TLS ERROR: write tls_wri= te_ciphertext error");
return -1;
<= span> }


if (retval !=3D buf->= len)
{
- msg(D_TLS_ERRORS, "TLS ERROR: write tls_write_ciphertext= incomplete %d/%d",
+ msg(D_TLS_ERRORS, "TLS ERROR: write tls_write= _ciphertext incomplete %d/%d", retval,
+ buf->len);
= perf_pop();
return -1;
}
@@ -1463,7 +1409,7 @@
/* successful write = */
dmsg(D_HANDSHAKE_VERBOSE, "write tls_write_cip= hertext %d bytes", retval);

- memset(BPTR(buf), 0, BLEN(buf)); /* erase= data just written */
+ memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */=
buf->len =3D 0;

pe= rf_pop();
@@ -1535,25 +1481,20 @@
char= s2[256];

s1[0] =3D s2[0] =3D 0;
- snprintf(s1, sizeof(s= 1), "%s %s, cipher %s",
- prefix,
- mbedtls_ssl_get_version(ks_ssl->ctx),
= + snprintf(s1, sizeof(s1), &= quot;%s %s, cipher %s", prefix, mbedtls_ssl_get_version(ks_ssl->ctx= ),
mbedtls_ssl_get_ciphersuite(ks_ssl->ctx= ));

cert =3D mbedtls_ssl_get_peer_ce= rt(ks_ssl->ctx);
if (cert !=3D NULL)
{

- snpri= ntf(s2, sizeof(s2), ", %u bit key",
- (unsigned int) mbedtls_pk_get_bitl= en(&cert->pk));
-show_available_tls_ciphers_list(const c= har *cipher_list,
- = const char *tls_cert_profile,
- bool tl= s13)
+show_available_= tls_ciphers_list(const char *cipher_list, const char *tls_cert_profile, boo= l tls13)
{
if (tls13)
{

@@ -1604,8 +1545,8 @@
{
= static char mbedtls_version[30];
unsigned i= nt pv =3D mbedtls_version_get_number();
- snprintf(mbedtls_version, sizeof(mbedtls_version), &q= uot;mbed TLS %d.%d.%d",
- (pv>>24)&0xff, (pv>>16)&0xff, (pv&g= t;>8)&0xff );
= + snprintf(mbedtls_version, sizeof(mbedtls_version), "mbed TLS %d.%= d.%d", (pv >> 24) & 0xff,
+ (pv >> 16) & 0xff, (pv >>= 8) & 0xff);
return mbedtls_version;
}


diff --git a/src/openvpn/ssl_mbedtl= s.h b/src/openvpn/ssl_mbedtls.h
index 9f124cd..fcc5227 1006= 44
--- a/src/openvpn/ssl_mbedtls.h
+++ b/sr= c/openvpn/ssl_mbedtls.h
@@ -44,19 +44,22 @@

typedef struct _buffer_entry buffer_entry;

-struct _buffer_e= ntry {
+struct _buffe= r_entry
+{
= size_t length;
uint8_t *data;
buffer_entry *next_block;

};

-typedef struct {+typedef struct
+{

size_t dat= a_start;
buffer_entry *first_block;
= buffer_entry *last_block;
} endless_buffer;
<= span>

-typedef struct = {
+typedef struct
+{
= endless_buffer in;
endless_buffer out;
} bio_ctx;

@@ -74,12 +77,12 @@
*=
* @return true if signing succeeded, false otherwise. */
-typedef bo= ol (*external_sign_func)(
- void *sign_ctx, const void *src, size_t src_size,
- void *dst, size_t dst_size);=
+typedef bool (*external_si= gn_func)(void *sign_ctx, const void *src, size_t src_size, void *dst,
+ = size_t dst_size);

/** Context = used by external_pkcs1_sign() */
-struct external_context {
+struct external_context
+{
size_t signature_length;=
external_sign_func sign;
void *sign_ctx= ;
@@ -92,13 +95,16 @@
*
= * The constants 64 and 48 are inherent to TLS 1.2. For TLS 1.3, it is not<= /span>
* possible to obtain the exporter master secret from mbed= TLS. */
-struct tls_ke= y_cache {
+struct tls= _key_cache
+{<= br> unsigned char client_server_random[64];
= mbedtls_tls_prf_types tls_prf_type;
unsigned char mast= er_secret[48];
};
-#else /* !defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) */
-struct tls_key_cache { };<= /span>
+#else /* !defined(MB= EDTLS_SSL_KEYING_MATERIAL_EXPORT) */
+struct tls_key_cache
+{
+= };
#endif

/**@@ -107,30 +113,32 @@
*
* Either= \c priv_key_pkcs11 or \c priv_key must be filled in.
*/<= /span>
-struct tls_root_ctx {<= /span>
- bool initialised; = /**< True if the context has been initialised */
+struct tls_root_ctx

+{

+ bool initialised; /**< = True if the context has been initialised */

- int endpoint; /**= < Whether or not this is a server or a client */

+ int endpoint; = /**< Whether or not this is a server or a client */
<= /span>
- mbedtls_dhm_contex= t *dhm_ctx; /**< Diffie-Helmann-Merkle context */
- mbedtls_x509_crt *crt_chain; = /**< Local Certificate chain */
- mbedtls_x509_crt *ca_chain; /**< CA chain for= remote verification */
- mbedtls_pk_context *priv_key; /**< Local private key */
- mbedtls_x509_crl *crl;= /**< Certificate Revocation List */
- time_t crl_last_mtime; /**= < CRL last modification time */
- off_t crl_last_size; /**< size of last l= oaded CRL */
+ mbe= dtls_dhm_context *dhm_ctx; /**< Diffie-Helmann-Merkle context *= /
+ mbedtls_x509_c= rt *crt_chain; /**< Local Certificate chain */
+ mbedtls_x509_crt *ca_chain; = /**< CA chain for remote verification */

+ mbedtls_pk_context *priv_key; = /**< Local private key */
+ mbedtls_x509_crl *crl; /**< Certificate R= evocation List */
+ = time_t crl_last_mtime; /**< CRL last modification time= */
+ off_t crl_la= st_size; /**< size of last loaded CRL */
#ifdef ENABLE_PKCS11

+ pkcs11h_certificat= e_t pkcs11_cert; /**< PKCS11 certificate */
#endif<= /span>
- struct external_co= ntext external_key; /**< External key context */
- int *allowed_ciphers; /**< Lis= t of allowed ciphers for this connection */
- mbedtls_compat_group_id *groups; /**< List= of allowed groups for this connection */
+ struct external_context external_key; /**< Ex= ternal key context */
+ int *allowed_ciphers; /**< List of allowed cipher= s for this connection */
+ mbedtls_compat_group_id *groups; /**< List of allowed gro= ups for this connection */
mbedtls_x509_crt_profile ce= rt_profile; /**< Allowed certificate types */
};=

-struct key= _state_ssl {
- mbedt= ls_ssl_config *ssl_config; /**< mbedTLS global ssl config */<= br>- mbedtls_ssl_context *ctx;= /**< mbedTLS connection context */
+struct key_state_ssl
+{
+ mbedtls_ssl_config *ssl_config; /**< mbedTLS global ssl = config */
+ mbedtl= s_ssl_context *ctx; /**< mbedTLS connection context */
<= span> bio_ctx *bio_ctx;


struct t= ls_key_cache tls_key_cache;
@@ -146,8 +154,7 @@
<= span> *

* @return 0 if successful, = 1 if an error occurred.
*/
-int tls_ctx_use_external_signing_func(struct tls_roo= t_ctx *ctx,
- = external_sign_func sign_func,
+int tls_ctx_use_external_signing_func= (struct tls_root_ctx *ctx, external_sign_func sign_func,
= void *sign_ctx);

static inline void
diff --git a/src/openvpn/s= sl_ncp.c b/src/openvpn/ssl_ncp.c
index 74d7b43..08bd33a 100= 644
--- a/src/openvpn/ssl_ncp.c
+++ b/src/o= penvpn/ssl_ncp.c
@@ -83,8 +83,7 @@
{
return false;
}
- else if (tls_peer_info_ncp_ver(p= eer_info) >=3D 2

- = || strstr(peer_info, "IV_CIPHERS=3D"))
+ else if (tls_peer_info_ncp_ver(= peer_info) >=3D 2 || strstr(peer_info, "IV_CIPHERS=3D"))
{
return true;
= }
@@ -99,7 +98,7 @@
{
= bool error_found =3D false;

- struct buffer new_list =3D alloc_buf(MAX_NC= P_CIPHERS_LENGTH);
+ = struct buffer new_list =3D alloc_buf(MAX_NCP_CIPHERS_LENGTH);
=
char *const tmp_ciphers =3D string_alloc(list,= NULL);
const char *token =3D strtok(tmp_ciphers, &quo= t;:");
@@ -127,22 +126,23 @@
= if (nonecipher)
{
msg= (M_WARN, "WARNING: cipher 'none' specified for --data-ciphers.= "
- = "This allows negotiation of NO encryption and "
- "tunnelled data = WILL then be transmitted in clear text "

- "over the network! "
- "PLEA= SE DO RECONSIDER THIS SETTING!");
+ "This allows negotiation of= NO encryption and "
+ "tunnelled data WILL then be transmitted= in clear text "
+ "over the network! "
+ "PLEASE D= O RECONSIDER THIS SETTING!");
}
if (!nonecipher && !cipher_valid(token))

{

msg(M_WARN, "Unsupported %sc= ipher in --data-ciphers: %s", optstr, token);
= error_found =3D error_found || !optional;
}
- else if (!nonec= ipher && !cipher_kt_mode_aead(token)
- && !cipher_kt_mode_cbc(toke= n)
+ else if (= !nonecipher && !cipher_kt_mode_aead(token) && !cipher_kt_mo= de_cbc(token)
&& !cipher_kt_mode_= ofb_cfb(token))
{
- msg(M_WARN, "Unsupported %scipher alg= orithm '%s'. It does not use "
- "CFB, OFB, CBC, or a supported A= EAD mode", optstr, token);
+ msg(M_WARN,
+ "Unsupported %scipher algorithm '%= s'. It does not use "
+ "CFB, OFB, CBC, or a supported AEAD mode&qu= ot;,
+ = optstr, token);
error_found =3D error_found |= | !optional;
}
else
@@ -155,7 +155,7 @@
ovpn_cipher= _name =3D "none";
}
=
- if (buf_= len(&new_list)> 0)
+ if (buf_len(&new_list) > 0)
= {
/* The next if condition ensure t= here is always space for
* a :
= @@ -164,11 +164,10 @@
}
=
/* Ensure buffer has capacity for cipher nam= e + : + \0 */
- = if (!(buf_forward_capacity(&new_list) >
- strlen(ovpn_cipher_name) + 2= ))
+ if (!= (buf_forward_capacity(&new_list) > strlen(ovpn_cipher_name) + 2))
{
msg(M_WARN, &= quot;Length of --data-ciphers is over the "
- "limit of 127 chars&quo= t;);
+ = "limit of 127 chars");
= error_found =3D true;
}
= else
@@ -180,7 +179,6 @@
}<= /span>


-
char *ret =3D NULL;
= if (!error_found && buf_len(&new_list) > 0)
{

@@ -201,8 +199,7 @@
size_t ne= wlen =3D strlen(o->ncp_ciphers) + 1 + strlen(ciphername) + 1;
= char *ncp_ciphers =3D gc_malloc(newlen, false, &o->gc);

- A= SSERT(snprintf(ncp_ciphers, newlen, "%s:%s", o->ncp_ciphers,
- cip= hername));
+ ASSER= T(snprintf(ncp_ciphers, newlen, "%s:%s", o->ncp_ciphers, ciphe= rname));
o->ncp_ciphers =3D ncp_ciphers;
= }

@@ -234,7 +231,7 @@
{

return iv_ciphers;
= }
- else if (tls_pe= er_info_ncp_ver(peer_info)>=3D2)
+ else if (tls_peer_info_ncp_ver(peer_info) >=3D 2)
{
/* If the peer announces IV_N= CP=3D2 then it supports the AES GCM
* ciphers */<= /span>
@@ -247,8 +244,8 @@
}

char *
-= ncp_get_best_cipher(const char *server_list, const char *peer_info,<= br>- const cha= r *remote_cipher, struct gc_arena *gc)
+ncp_get_best_cipher(const char *server_list, const char = *peer_info, const char *remote_cipher,
+ struct gc_arena *gc)
{

/*
* The gc of the parameter= is tied to the VPN session, create a
@@ -263,8 +260,7 @@
/* non-NCP clients without OCC? "assume nothing&q= uot; */
/* For client doing the newer version of NCP (= that send IV_CIPHERS)
* we cannot assume that they wi= ll accept remote_cipher */
- if (remote_cipher =3D=3D NULL
- || (peer_info && strstr(peer_info, "I= V_CIPHERS=3D")))
+ if (remote_cipher =3D=3D NULL || (peer_info && strstr(peer_in= fo, "IV_CIPHERS=3D")))
{
= remote_cipher =3D "";
}
@@ -274,8 +270,7 @@

const char *token;
while ((token =3D strsep(&tmp_ciphers, ":")))
<= br> {
- = if (tls_item_in_cipher_list(token, peer_ncp_list)
- || streq(token, remote_cipher))=
+ if (tls_ite= m_in_cipher_list(token, peer_ncp_list) || streq(token, remote_cipher))
{
break;
= }
@@ -303,8 +298,7 @@
static bool=
tls_poor_mans_ncp(struct options *o, const char *remote_c= iphername)
{
- if (remote_ciphername
- && tls_item_in_cipher_list(remote_ciphername, o= ->ncp_ciphers))
+ = if (remote_ciphername && tls_item_in_cipher_list(remote_cipherna= me, o->ncp_ciphers))
{
o-&= gt;ciphername =3D string_alloc(remote_ciphername, &o->gc); msg(D_TLS_DEBUG_LOW, "Using peer cipher '%s'&q= uot;, o->ciphername);
@@ -339,29 +333,27 @@
/* We failed negotiation, give appropriate error message */
=
if (c->c2.tls_multi->remote_ciphername)
{

- msg(D= _TLS_ERRORS, "OPTIONS ERROR: failed to negotiate "
+ msg(D_TLS_ERRORS,
+ "OPTIONS ER= ROR: failed to negotiate "
"cipher w= ith server. Add the server's "
"= ;cipher ('%s') to --data-ciphers (currently '%s'), e.g.&quo= t;
"--data-ciphers %s:%s if you want to c= onnect to this server.",
- c->c2.tls_multi->remote_ciphername,
- c->options.ncp_ciphe= rs_conf, c->options.ncp_ciphers_conf,

- c->c2.tls_multi->remote_ciphername);
+ c->c2.= tls_multi->remote_ciphername, c->options.ncp_ciphers_conf,
= + c->options.ncp_= ciphers_conf, c->c2.tls_multi->remote_ciphername);
= return false;
-<= /span>
}
else
{
msg(D_TLS_ERRORS, "OPTIONS ERROR: failed to nego= tiate "
- = "cipher with server. Configure "
- "--data-ciphers-fallback if you wa= nt to connect "
- = "to this server.");
+ "cipher with server. Co= nfigure "
+ = "--data-ciphers-fallback if you want to connect &= quot;
+ = "to this server.");
return f= alse;
}
}
const char *
-g= et_p2p_ncp_cipher(struct tls_session *session, const char *peer_info,
- struct g= c_arena *gc)
+get_p2p= _ncp_cipher(struct tls_session *session, const char *peer_info, struct gc_a= rena *gc)
{
/* we use a local gc aren= a to keep the temporary strings needed by strsep */
st= ruct gc_arena gc_local =3D gc_new();
@@ -411,8 +403,7 @@
}

static void
<= span style=3D"color: hsl(0, 100%, 40%);">-p2p_ncp_set_options(struct tls_mu= lti *multi, struct tls_session *session,

- const char *common_cipher)+p2p_ncp_set_options(struct tl= s_multi *multi, struct tls_session *session, const char *common_cipher)
{
/* will return 0 if peer_info is null = */
const unsigned int iv_proto_peer =3D extract_iv_pro= to(multi->peer_info);
@@ -434,8 +425,8 @@
session->opt->crypto_flags |=3D CO_USE_CC_EXIT_NOTIFY;
}

- if (session->opt->data_epoch_supported &&= (iv_proto_peer & IV_PROTO_DATA_EPOCH)
- && common_cipher && cipher_kt_= mode_aead(common_cipher))
+ if (session->opt->data_epoch_supported && (iv_proto= _peer & IV_PROTO_DATA_EPOCH) && common_cipher
+ && cipher_kt_mode_aea= d(common_cipher))
{
session-&= gt;opt->crypto_flags |=3D CO_EPOCH_DATA_KEY_FORMAT;
= }
@@ -458,20 +449,18 @@

= uint8_t peerid[3];
if (!key_state= _export_keying_material(session, EXPORT_P2P_PEERID_LABEL,
- = strlen(EXPORT_P2P_PEERID_LABEL),
- &am= p;peerid, 3))
+ = strlen(EXPORT_P2P_PEERID_LABEL)= , &peerid, 3))
{
= /* Non DCO setup might still work but also this should never=
* happen or very likely the TLS encryption key = exporter will
* also fail */
msg(M_NONFATAL, "TLS key export for P2P peer id f= ailed. "

- = "Continuing anyway, expect problems");
+ &q= uot;Continuing anyway, expect problems");

= }
else
{<= br> multi->peer_id =3D (peerid[0] << 16) + (= peerid[1] << 8) + peerid[2];
}-
}
}
if (iv_proto_peer & IV_PROTO_D= YN_TLS_CRYPT)
@@ -512,12 +501,11 @@
= common_cipher =3D BSTR(&out);
}
=
- msg(D_TLS_DEBUG_= LOW, "P2P mode NCP negotiation result: "
+ msg(D_TLS_DEBUG_LOW,
+ "P2P mode NCP negotiation = result: "
"TLS_export=3D%d, DATA_v2=3D%d= , peer-id %d, epoch=3D%d, cipher=3D%s",
- (bool)(session->opt->crypto_flags &= ; CO_USE_TLS_KEY_MATERIAL_EXPORT),
- multi->use_peer_id,
- multi->peer_id,
- (bool)(session->opt->crypto_flags = & CO_EPOCH_DATA_KEY_FORMAT),
+ (bool)(session->opt->crypto_flags & CO_USE_T= LS_KEY_MATERIAL_EXPORT), multi->use_peer_id,
+ multi->peer_id, (bool)(session->o= pt->crypto_flags & CO_EPOCH_DATA_KEY_FORMAT),
= common_cipher);

gc_free(&gc);=
@@ -527,16 +515,15 @@
bool
check_session_cipher(struct tls_session *session, struct options *option= s)

{
-= bool cipher_allowed_as_fallback =3D options->enable_ncp_fallback
- = && streq(options->ciphername, session->opt->c= onfig_ciphername);
+ = bool cipher_allowed_as_fallback =3D
+ options->enable_ncp_fallback && streq= (options->ciphername, session->opt->config_ciphername);
=
if (!session->opt->server && !ci= pher_allowed_as_fallback
&& !tls_item_in_c= ipher_list(options->ciphername, options->ncp_ciphers))
{

struct gc_arena gc =3D gc_new(); msg(D_TLS_ERRORS, "Error: negotiated cipher not allow= ed - %s not in %s%s",
- options->ciphername, options->ncp_ciphers_conf,
- ncp_expanded_c= iphers(options, &gc));
+ options->ciphername, options->ncp_ciphers_conf, nc= p_expanded_ciphers(options, &gc));
/* undo cip= her push, abort connection setup */
options->ci= phername =3D session->opt->config_ciphername;
= gc_free(&gc);
@@ -577,7 +564,7 @@
= const char *after_default =3D def + strlen(search);
= buf_write(&ncp_ciphers_buf, after_default, strlen(after_default));

- o-&g= t;ncp_ciphers =3D (char *) ncp_ciphers;
+ o->ncp_ciphers =3D (char *)ncp_ciphers; }

/**
@@ -588,8= +575,8 @@
void
options_postprocess_setde= fault_ncpciphers(struct options *o)
{
- bool default_in_cipher_list =3D o->= ncp_ciphers
- = && tls_item_in_cipher_list("DEFAULT&qu= ot;, o->ncp_ciphers);
+ bool default_in_cipher_list =3D
+ o->ncp_ciphers && tls_item_in_ciphe= r_list("DEFAULT", o->ncp_ciphers);
/* preserve the values that the user put into the configuration= */
o->ncp_ciphers_conf =3D o->ncp_ciphers;
diff --git a/src/openvpn/ssl_ncp.h b/src/openvpn/ssl_ncp.h
index 6159264..51cd4f2 100644
--- a/src/openvpn= /ssl_ncp.h
+++ b/src/openvpn/ssl_ncp.h
@@ -= 39,8 +39,7 @@
* Returns whether the client supports NCP e= ither by
* announcing IV_NCP>=3D2 or the IV_CIPHERS li= st
*/
-bool
-tls_peer_suppor= ts_ncp(const char *peer_info);
+bool tls_peer_supports_ncp(const char *peer_info);

/* forward declaration to break include dependency lo= op */
struct context;
@@ -51,8 +50,7 @@
*
* @return Wether the client NCP proces= s suceeded or failed
*/
-bool
+bool check_pull_client_ncp(struct conte= xt *c, int found);

/**
= * Iterates through the ciphers in server_list and return the first<= br>@@ -74,9 +72,8 @@
* @returns NULL if no common c= ipher is available, otherwise the best common
* cipher
*/
-cha= r *
-ncp_get_best_ciphe= r(const char *server_list, const char *peer_info,
- const char *remote_cipher, = struct gc_arena *gc);
+char *ncp_get_best_cipher(const char *server_list, const char *peer_info,= const char *remote_cipher,
+ struct gc_arena *gc);


/**
@@ -87,8 +84,7 @@
* or allocated via gc. If no information is available an emp= ty string
* ("") is returned.
= */
-const char *
-tls_peer_ncp_list(const cha= r *peer_info, struct gc_arena *gc);
+const char *tls_peer_ncp_list(const char *peer_info, struct= gc_arena *gc);

/**
* = Check whether the ciphers in the supplied list are supported.
@@ -103,8 +99,7 @@

* is short tha= n MAX_NCP_CIPHERS_LENGTH. NULL
* oth= erwise.
*/
-char *
-mutate_n= cp_cipher_list(const char *list, struct gc_arena *gc);
+char *mutate_ncp_cipher_list(const char = *list, struct gc_arena *gc);

/**<= br> * Appends the cipher specified by the ciphernamer parameter to t= o
@@ -148,17 +143,15 @@
* @param gc = gc arena that will be used to allocate the returned cipher
= * @return common cipher if one exist.
= */
-const char *
-get_p2p_ncp_cipher(struct = tls_session *session, const char *peer_info,
- struct gc_arena *gc);
<= span style=3D"color: hsl(120, 100%, 40%);">+const char *get_p2p_ncp_cipher(= struct tls_session *session, const char *peer_info,

+ struct gc_= arena *gc);


/**=
* Checks if the cipher is allowed, otherwise returns false and = reset the
* cipher to the config cipher.
= */
-bool
-check_session_cipher(struct tls_se= ssion *session, struct options *options);

+bool check_session_cipher(struct tls_session *session= , struct options *options);

/** * Checks for availability of Chacha20-Poly1305 and sets@@ -168,8 +161,7 @@
* If DEFAULT is in the ncp_cip= her string, it will be replaced
* by the default cipher s= tring as defined above.
*/
-void
-options_postprocess_setdefault_ncpciphers(struct options *o);<= br>+void options_postprocess_se= tdefault_ncpciphers(struct options *o);

= /** returns the o->ncp_ciphers in brackets, e.g.
* (A= ES-256-GCM:CHACHA20-POLY1305) if o->ncp_ciphers_conf
@@ = -177,6 +169,5 @@
*
* The returned stri= ng will be allocated in the passed \c gc
*/
-const char *

-ncp_expanded_ciphers(struct options *o, str= uct gc_arena *gc);
+c= onst char *ncp_expanded_ciphers(struct options *o, struct gc_arena *gc);
#endif /* ifndef OPENVPN_SSL_NCP_H */
diff -= -git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
index 4c11cd4..2fe4b75 100644

--- a/src/openvpn/ssl_opens= sl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -11= 4,7 +114,7 @@
if (ERR_peek_error() !=3D 0)
<= span> {

crypto_msg(M_WARN, "Warning: TLS = server context initialisation "
- "has warnings.");
+ "= has warnings.");

}
}
<= span>

@@ -132,7 +132,7 @@
if (ERR_pee= k_error() !=3D 0)
{
crypto_ms= g(M_WARN, "Warning: TLS client context initialisation "- "has wa= rnings.");
+ = "has warnings.");
}
}

@@ -153,15 +153,13 @@
}

bool
-key_state_export_keying_material(struct= tls_session *session,
= - const char *label, size_t label_size,
+key_state_export_keying= _material(struct tls_session *session, const char *label, size_t label_size= ,
void *ekm, size_t ekm_s= ize)

{
SSL *ssl =3D= session->key[KS_PRIMARY].ks_ssl.ssl;

- if (SSL_export_keying_material(ssl= , ekm, ekm_size, label,
- label_size, NULL, 0, 0) =3D=3D 1)
+ if (SSL_export_keyin= g_material(ssl, ekm, ekm_size, label, label_size, NULL, 0, 0) =3D=3D 1)
{
return true;
= }
@@ -185,16 +183,15 @@
if (where = & SSL_CB_LOOP)
{
dmsg(D_H= ANDSHAKE_VERBOSE, "SSL state (%s): %s",
- where & SSL_ST_CONNECT ? "= ;connect" :
- = where &SSL_ST_ACCEPT ? "accept" :
- "undefined", SSL_s= tate_string_long(s));
+ where & SSL_ST_CONNECT ? "connect"
= + : where & SSL= _ST_ACCEPT ? "accept"
+ : "undefined",
+ SSL_stat= e_string_long(s));
}
else if (whe= re & SSL_CB_ALERT)
{
- dmsg(D_TLS_DEBUG_LOW, "%s %s SSL alert= : %s",
- = where & SSL_CB_READ ? "Received" : "Sent",
- SSL_alert_type= _string_long(ret),
- = SSL_alert_desc_string_long(ret));
+ dmsg(D_TLS_DEBUG_LOW, "%s %s SSL alert= : %s", where & SSL_CB_READ ? "Received" : "Sent&quo= t;,
+ SSL= _alert_type_string_long(ret), SSL_alert_desc_string_long(ret));
<= span> }

}

@@ -233,7 = +230,7 @@
return TLS_VER_1_2;
#elif d= efined(TLS1_1_VERSION) || defined(SSL_OP_NO_TLSv1_1)
r= eturn TLS_VER_1_1;
-#el= se /* if defined(TLS1_3_VERSION) */
+#else /* if defined(TLS1_3_VERSION) */
= return TLS_VER_1_0;
#endif
}
= @@ -279,10 +276,10 @@
static bool
t= ls_ctx_set_tls_versions(struct tls_root_ctx *ctx, unsigned int ssl_flags)
{
- = int tls_ver_min =3D openssl_tls_version(
- (ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) = & SSLF_TLS_VERSION_MIN_MASK);
- int tls_ver_max =3D openssl_tls_version(
- (ssl_flags >> SSLF_TLS_VER= SION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_MASK);
+ int tls_ver_min =3D
+ openssl_tls_version((ssl_flags &g= t;> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERSION_MIN_MASK);=
+ int tls_ver_max =3D
+ openssl_tls_ve= rsion((ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSIO= N_MAX_MASK);

if (!tls_ver_min)
{
@@ -373,7 +370,8 @@
= for (; begin_of_cipher < strlen(ciphers); begin_of_cipher =3D end_of_cip= her)
{
end_of_cipher +=3D str= cspn(&ciphers[begin_of_cipher], ":");
- cipher_pair =3D tls_get_cipher_name= _pair(&ciphers[begin_of_cipher], end_of_cipher - begin_of_cipher);
+ cipher_pair =3D<= /span>
+ tls_get_= cipher_name_pair(&ciphers[begin_of_cipher], end_of_cipher - begin_of_ci= pher);

if (NULL =3D=3D cipher_pa= ir)
{
@@ -394,11 +392,13 @@=
current_cipher_len =3D strlen(current_cipher);

if (end_of_cipher - begin_of_ciph= er =3D=3D current_cipher_len
- && 0 !=3D memcmp(&ciphers[begin_of_ciphe= r], cipher_pair->iana_name,
- end_of_cipher - begin_of_cipher))
+ &= & 0
+ = !=3D memcmp(&ciphers[begin_of_cipher], cipher_pair->iana_= name,
+ = end_of_cipher - begin_of_cipher))
= {
/* Non-IANA name used, show warni= ng */
- = msg(M_WARN, "Deprecated TLS cipher name '%s', please use IANA = name '%s'", cipher_pair->openssl_name, cipher_pair->iana= _name);
+ = msg(M_WARN, "Deprecated TLS cipher name '%s', please use I= ANA name '%s'",
+ cipher_pair->openssl_name, cipher_pair->= iana_name);
}
}

@@ -406,8 +406,7 @@
i= f ((SIZE_MAX - openssl_ciphers_len) < current_cipher_len
|| (len - 1) < (openssl_ciphers_len + current_cipher_len))=

{
- msg(M_FATAL,
- "Failed to set restricted TLS cipher list, to= o long (>%d).",
+ msg(M_FATAL, "Failed to set restricted TLS cipher list= , too long (>%d).",
(int)(len - 1)= );
}

@@ -422,7 += 421,7 @@

if (openssl_ciphers_len >= ; 0)
{
- openssl_ciphers[openssl_ciphers_len-1] =3D '\0';
+ openssl_ciphers[= openssl_ciphers_len - 1] =3D '\0';
} }

@@ -432,17 +431,18 @@ if (ciphers =3D=3D NULL)
{
/* Use sane default TLS cipher list */

- if (!SSL_CTX_set_cipher_list(ctx->ctx= ,
- = /* Use openssl's default list as a basis */
= - = "DEFAULT"
- "= ;:!EXP:!LOW:!MEDIUM"
- /* Disable static (EC)DH keys (no = forward secrecy) */
- = ":!kDH:!kECDH"
- = /* Disable DSA private keys */

- ":!DSS"
<= span style=3D"color: hsl(0, 100%, 40%);">- = /* Disable unsupported TLS modes */

- ":!PSK:!SRP:!kR= SA"))
+ i= f (!SSL_CTX_set_cipher_list(
+ ctx->ctx,
+ /* Use openssl's default list as a ba= sis */
+ = "DEFAULT"
+ ":!EXP:!LOW:!MEDIUM"
+ /* Disable static = (EC)DH keys (no forward secrecy) */

+ ":!kDH:!kECDH"
+ /* Disable DSA private= keys */
+ = ":!DSS"
+ ":!PSK:!SRP:!kRSA&q= uot;))
{
crypto_msg(M= _FATAL, "Failed to set default TLS cipher list.");
}

@@ -462,8 +462,7 @@
}<= br>
static void
-convert_tls13_list_to_openssl(char *openssl_ciphers, size= _t len,
- = const char *ciphers)
+convert_tls13_list_to_openssl(char *openssl_ciphers, size_= t len, const char *ciphers)
{
/*
* OpenSSL (and official IANA) cipher names have _ in them= . We
@@ -472,9 +471,8 @@
*/ if (strlen(ciphers) >=3D (len - 1))
{
- msg(M_FATAL,
- "Failed= to set restricted TLS 1.3 cipher list, too long (>%d).",- (int) (len - 1));
+ msg(M_FATAL, = "Failed to set restricted TLS 1.3 cipher list, too long (>%d)."= ;,
+ (int)= (len - 1));
}

s= trncpy(openssl_ciphers, ciphers, len);
@@ -499,20 +497,19 @= @
}

#if !defined(TL= S1_3_VERSION)
- cryp= to_msg(M_WARN, "Not compiled with OpenSSL 1.1.1 or higher. "
+ crypto_msg(M_WARN,
+ "= Not compiled with OpenSSL 1.1.1 or higher. "
= "Ignoring TLS 1.3 only tls-ciphersuites '%s' setting.&q= uot;,
ciphers);
#else
ASSERT(NULL !=3D ctx);

= char openssl_ciphers[4096];
- convert_tls13_list_to_openssl(openssl_ciphers, sizeof(openssl= _ciphers),
- = ciphers);
+ convert_tls13_list_to_openssl(openssl_ciphers, sizeof(open= ssl_ciphers), ciphers);

if (!SSL_CTX= _set_ciphersuites(ctx->ctx, openssl_ciphers))
{
- crypto_msg(M_FATA= L, "Failed to set restricted TLS 1.3 cipher list: %s",
= - openssl_ciphe= rs);
+ crypto_= msg(M_FATAL, "Failed to set restricted TLS 1.3 cipher list: %s", = openssl_ciphers);
}
#endif
= }
@@ -521,7 +518,7 @@
tls_ctx_set_c= ert_profile(struct tls_root_ctx *ctx, const char *profile)
= {
#if OPENSSL_VERSION_NUMBER > 0x10100000L \- && (!defined(LIBRES= SL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3060000fL)
= + && (!defined(LIBRE= SSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER > 0x3060000fL)
= /* OpenSSL does not have certificate profiles, but a complex set= of
* callbacks that we could try to implement to ach= ieve something similar.
* For now, use OpenSSL's = security levels to achieve similar (but not equal)
@@ -550,= 8 +547,10 @@
#else /* if OPENSSL_VERSION_NUMBER > 0x10= 100000L */
if (profile)
{<= br>- msg(M_WARN, "WAR= NING: OpenSSL 1.1.0 and LibreSSL do not support "
- "--tls-cert-profile, igno= ring user-set profile: '%s'", profile);
+ msg(M_WARN,
+ "WARNING: OpenSSL 1.1.0 = and LibreSSL do not support "
+ "--tls-cert-profile, ignoring user-set prof= ile: '%s'",
+ profile);
}
#endif /= * if OPENSSL_VERSION_NUMBER > 0x10100000L */
}@@ -603,15 +602,13 @@

if (!S= SL_CTX_set1_groups(ctx->ctx, glist, glistlen))
{
- crypto_msg(M_FAT= AL, "Failed to set allowed TLS group list: %s",
- groups);
<= span style=3D"color: hsl(120, 100%, 40%);">+ crypto_msg(M_FATAL, &qu= ot;Failed to set allowed TLS group list: %s", groups);

}

gc_free(&gc);
#else /* i= f OPENSSL_VERSION_NUMBER < 0x30000000L */
if (!SSL_= CTX_set1_groups_list(ctx->ctx, groups))
{- crypto_msg(M_FATAL, &qu= ot;Failed to set allowed TLS group list: %s",
- groups);
+ crypto_msg(M_FATAL, "Fail= ed to set allowed TLS group list: %s", groups);
}=
#endif /* if OPENSSL_VERSION_NUMBER < 0x30000000L */
}
@@ -653,8 +650,7 @@
}

void
-tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char= *dh_file,
- = bool dh_file_inline)
+tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *d= h_file, bool dh_file_inline)
{
BIO *b= io;

@@ -690,8 +686,7 @@
= crypto_msg(M_FATAL, "SSL_CTX_set0_tmp_dh_pkey"); }

- msg(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with %= d bit key",
- = 8 * EVP_PKEY_get_size(dh));
+ msg(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with %= d bit key", 8 * EVP_PKEY_get_size(dh));
#else /* if = OPENSSL_VERSION_NUMBER >=3D 0x30000000L */
DH *dh = =3D PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
BIO_= free(bio);
@@ -706,8 +701,7 @@
cry= pto_msg(M_FATAL, "SSL_CTX_set_tmp_dh");
}

- ms= g(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with %d bit key",<= /span>
- 8 * DH_size(dh= ));
+ msg(D_TLS_DE= BUG_LOW, "Diffie-Hellman initialized with %d bit key", 8 * DH_siz= e(dh));

DH_free(dh);
#endif /* if OPENSSL_VERSION_NUMBER >=3D 0x30000000L */

@@ -720,8 +714,8 @@

if (curve_name !=3D NULL)=
{
msg(M_WARN, "WARNING: OpenSS= L 3.0+ builds do not support specifying an "
- "ECDH curve with --ecdh-curve,= using default curves. Use "
- "--tls-groups to specify groups.");
+ "= ;ECDH curve with --ecdh-curve, using default curves. Use "
<= span style=3D"color: hsl(120, 100%, 40%);">+ "--tls= -groups to specify groups.");

}
= #elif !defined(OPENSSL_NO_EC)
int nid =3D NID_undef;
@@ -754,10 +748,9 @@
{
= /* Creating key failed, fall back on sane default */
ecdh =3D EC_KEY_new_by_curve_name(NID_secp384r1);

- const char *source =3D (NUL= L =3D=3D curve_name) ?

= - "extract curve from certificate" : = "use supplied curve";
- msg(D_TLS_DEBUG_LOW,
- "Failed to %s (%s), using secp384r1 inste= ad.", source, sname);
+ const char *source =3D
+ (NULL =3D=3D curve_name) ? "extract curv= e from certificate" : "use supplied curve";
+ msg(D_TLS_DEBUG_LOW, "F= ailed to %s (%s), using secp384r1 instead.", source, sname); sname =3D OBJ_nid2sn(NID_secp384r1);
}=

@@ -771,7 +764,7 @@
= EC_KEY_free(ecdh);
#else /* ifndef OPENSSL_NO_EC */
msg(D_LOW, "Your OpenSSL library was built without el= liptic curve support."
- " Skipping ECDH parameter loading.");
+ " Skipping EC= DH parameter loading.");

#endif /* OPENSSL_NO_EC */
}

@@ -795,7 +788,8 @@
{
struct user_pass up;
CLEAR(up);
- get_user_pass(&up, NULL, "PKCS#11 tok= en", GET_USER_PASS_MANAGEMENT|GET_USER_PASS_PASSWORD_ONLY);
= + get_user_pass(&= ;up, NULL, "PKCS#11 token",
+ GET_USER_PASS_MANAGEMENT | GET_= USER_PASS_PASSWORD_ONLY);
UI_set_result(ui, ui= s, up.password);
purge_user_pass(&up, true= );
}
@@ -846,12 +840,11 @@<= br> {
return NULL;
= }
- pkey =3D PEM_rea= d_bio_PrivateKey(in, NULL,
- SSL_CTX_get_default_passwd_cb(ssl_c= tx),
+ pkey =3D PE= M_read_bio_PrivateKey(in, NULL, SSL_CTX_get_default_passwd_cb(ssl_ctx),
SSL_CTX_get_default_passwd= _cb_userdata(ssl_ctx));
BIO_free(in);
=
-#else /* defined(HAV= E_OPENSSL_STORE_API) */
+#else /* defined(HAVE_OPENSSL_STORE_API) */
OSSL_STORE_CTX *store_ctx =3D NULL;
OSSL_= STORE_INFO *info =3D NULL;
@@ -864,8 +857,7 @@
}

UI_method_set_reader(ui_method, ui_reader);=

- = store_ctx =3D OSSL_STORE_open_ex(uri, tls_libctx, NULL, ui_method, ssl_ctx= ,
- = NULL, NULL, NULL);
+ store_ctx =3D OSSL_STORE_open_ex(uri, tls_libctx, NULL, u= i_method, ssl_ctx, NULL, NULL, NULL);
if (!store_ctx)<= /span>
{
goto end;
@= @ -905,8 +897,8 @@
}

in= t
-tls_ctx_load_pkcs12(= struct tls_root_ctx *ctx, const char *pkcs12_file,
- bool pkcs12_file_inline, b= ool load_ca_file)
+tl= s_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, bool p= kcs12_file_inline,
+ = bool load_ca_file)
{
= FILE *fp;
EVP_PKEY *pkey;
@@ -921,8= +913,7 @@
if (pkcs12_file_inline)
= {
BIO *b64 =3D BIO_new(BIO_f_base64());- BIO *bio =3D BIO_new_m= em_buf((void *) pkcs12_file,
- (int) strlen(pkcs12_file));
+ BIO *bio =3D BIO_= new_mem_buf((void *)pkcs12_file, (int)strlen(pkcs12_file));
ASSERT(b64 && bio);

BIO_push(b64= , bio);
p12 =3D d2i_PKCS12_bio(b64, NULL);<= br>@@ -957,7 +948,7 @@
if (!PKCS12_parse(p12= , password, &pkey, &cert, &ca))
{
crypto_msg(M_WARN, "Decoding PKCS12 failed. P= robably wrong password "
- "or unsupported/legacy encryption"= );
+ = "or unsupported/legacy encryption");
#ifdef ENABLE_MANAGEMENT

if (management &am= p;& (ERR_GET_REASON(ERR_peek_error()) =3D=3D PKCS12_R_MAC_VERIFY_FAILUR= E))
{
@@ -1003,11 +994,13 @@
X509_STORE *cert_store =3D SSL_CTX_get_cert= _store(ctx->ctx);
if (!X509_STORE_add_c= ert(cert_store, sk_X509_value(ca, i)))
{
- cry= pto_msg(M_FATAL, "Cannot add certificate to certificate chain (X509_ST= ORE_add_cert)");
+ crypto_msg(M_FATAL,
+ "Cannot add certi= ficate to certificate chain (X509_STORE_add_cert)");
= }
if (!SSL_CTX_add_client_= CA(ctx->ctx, sk_X509_value(ca, i)))
{
- cry= pto_msg(M_FATAL, "Cannot add certificate to client CA list (SSL_CTX_ad= d_client_CA)");
= + crypto_msg(M_FATAL,
+ "Cannot add certif= icate to client CA list (SSL_CTX_add_client_CA)");
= }
}
}
@@ -1025,7 +1018,9 @@
{<= br> if (!SSL_CTX_add_extra_chain_cert(ctx->ctx, sk= _X509_value(ca, i)))
{
- crypto_msg(M_FATAL, &= quot;Cannot add extra certificate to chain (SSL_CTX_add_extra_chain_cert)&q= uot;);
+ = crypto_msg(
+ = M_FATAL,
+ "Cannot add extra certificate to c= hain (SSL_CTX_add_extra_chain_cert)");
= }
}
}
@@ -1042,7 +1037,8 @@

/* Load Certificate and Priva= te Key */
if (!SSL_CTX_use_CryptoAPI_certificate(ctx-&= gt;ctx, cryptoapi_cert))
{
- crypto_msg(M_FATAL, "Cannot load cer= tificate \"%s\" from Microsoft Certificate Store", cryptoapi= _cert);
+ cryp= to_msg(M_FATAL, "Cannot load certificate \"%s\" from Microso= ft Certificate Store",
+ cryptoapi_cert);
} }
#endif /* ENABLE_CRYPTOAPI */
@= @ -1060,8 +1056,7 @@
* is found in the buffe= r. If loading more certificates is
* option= al, break without raising an error
*/<= br>- if (optional
- &&= ERR_GET_REASON(ERR_peek_error()) =3D=3D PEM_R_NO_START_LINE)
+ if (optional &&am= p; ERR_GET_REASON(ERR_peek_error()) =3D=3D PEM_R_NO_START_LINE)

<= span> {

/* remove that error f= rom error stack */
(void)ERR_get_error();<= /span>
@@ -1110,8 +1105,8 @@
}
UI_method_set_reader(ui_method, ui_reader);

=
- store_ctx =3D OSSL_STORE= _open_ex(uri, tls_libctx, NULL, ui_method, tls_ctx->ctx,
- NU= LL, NULL, NULL);

+ = store_ctx =3D
+ = OSSL_STORE_open_ex(uri, tls_libctx, NULL, ui_method, tls_ctx->ctx, NU= LL, NULL, NULL);
if (!store_ctx)
= {
goto end;
@@ -1188,14 +1183,13 @= @
UI_destroy_method(ui_method);
O= SSL_STORE_INFO_free(info);
OSSL_STORE_close(store_ctx)= ;
-#else /* defined(HAV= E_OPENSSL_STORE_API */
-tls_ctx_load_cert_pem_file(struct tls_roo= t_ctx *ctx, const char *cert_file,
- bool cert_file_inline)
+tls_ctx_load_cert_pem_file(struc= t tls_root_ctx *ctx, const char *cert_file, bool cert_file_inline)
{
BIO *in =3D NULL;
X509= *x =3D NULL;
@@ -1205,11 +1199,11 @@

if (cert_file_inline)
{
- in =3D BIO_new_mem_buf((ch= ar *) cert_file, -1);

+ in =3D BIO_new_mem_buf((char *)cert_file, -1);
= }
else
{
- in =3D BIO_new_file((char *) cert_f= ile, "r");
= + in =3D BIO_new_file((char *)cert_file, "r");
<= span> }


if (in =3D=3D NULL)
@@ -1218,8 +1212,7 @@
goto end;=
}

- x =3D PEM_read_bio_X509(in, NULL,
- SSL_CTX_get_default_= passwd_cb(ctx->ctx),
+ x =3D PEM_read_bio_X509(in, NULL, SSL_CTX_get_default_passwd_cb(ctx= ->ctx),
SSL_CTX_get_default_p= asswd_cb_userdata(ctx->ctx));
if (x =3D=3D NULL)
{
@@ -1256,8 +1249,7 @@
= }

void
-tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const= char *cert_file,
- = bool cert_file_inline)
+tls_ctx_load_cert_file(struct tls_root_ctx *ctx, cons= t char *cert_file, bool cert_file_inline)
{
if (cert_uri_supported() && !cert_file_inline)

{

@@ -1284,13 +1276,12 @@
<= br> if (priv_key_file_inline)
{
- in =3D BIO_new_mem_buf((ch= ar *) priv_key_file, -1);

+ in =3D BIO_new_mem_buf((char *)priv_key_file, -1);
= if (in =3D=3D NULL)
{
goto end;

}
- pkey =3D PEM_read_bio_PrivateKey(in= , NULL,
- = SSL_CTX_get_default_passwd_cb(ctx->ctx),=
+ pkey =3D PEM_read_= bio_PrivateKey(in, NULL, SSL_CTX_get_default_passwd_cb(ctx->ctx),=
SSL_CTX_get_default_passw= d_cb_userdata(ctx->ctx));
}
el= se
@@ -1325,8 +1316,7 @@
}

void
- = bool crl_inline)
+backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const cha= r *crl_file, bool crl_inline)
{
BIO *= in =3D NULL;

@@ -1355,7 +1345,7 @@=

if (crl_inline)
{
- in =3D BIO_new_me= m_buf((char *) crl_file, -1);
+ in =3D BIO_new_mem_buf((char *)crl_file, -1);
<= span> }

else
{
@@ -1364,8 +1354,7 @@


if (in =3D= =3D NULL)
{
- msg(M_WARN, "CRL: cannot read: %s",
= - print_key_filename(c= rl_file, crl_inline));
-get_sig_from_man(const unsigned char *dgst, unsigned int dgs= tlen,
- = unsigned char *sig, unsigned int siglen,
- const char *algorithm)
+get_sig_from_man(const unsigned cha= r *dgst, unsigned int dgstlen, unsigned char *sig,

+ unsigned int siglen, const = char *algorithm)
{
char *in_b64 =3D N= ULL;
char *out_b64 =3D NULL;
@@ -1491,= 7 +1479,6 @@
if (management && bencret > 0)=
{
out_b64 =3D management_que= ry_pk_sig(management, in_b64, algorithm);
-
}
if (out_b6= 4)
{
@@ -1505,8 +1492,7 @@
<= span>

/* sign arbitrary data */
static i= nt
-rsa_priv_enc(int fl= en, const unsigned char *from, unsigned char *to, RSA *rsa,
- int padding)

<= span style=3D"color: hsl(120, 100%, 40%);">+rsa_priv_enc(int flen, const un= signed char *from, unsigned char *to, RSA *rsa, int padding)

{

unsigned int len =3D RSA_size(rsa);
int ret =3D -1;

@@ -1534,8 +1520,7 @@
ASSERT(NULL !=3D pub_rsa);


/= * allocate custom RSA method object */
- rsa_meth =3D RSA_meth_new("OpenVPN external priva= te key RSA Method",
+ rsa_meth =3D RSA_meth_new("O= penVPN external private key RSA Method", RSA_METHOD_FLAG_NO_CHECK);
check_malloc_return(rsa_meth);
RSA_= meth_set_pub_enc(rsa_meth, rsa_pub_enc);
RSA_meth_set_= pub_dec(rsa_meth, rsa_pub_dec);
@@ -1595,7 +1580,7 @@
{
/* release the method structure */
const EC_KEY_METHOD *ec_meth =3D EC_KEY_get_method(ec);
- EC_KEY_METHOD_free((E= C_KEY_METHOD *) ec_meth);
+ EC_KEY_METHOD_free((EC_KEY_METHOD *)ec_meth);
}<= /span>

/* EC_KEY_METHOD callback: sign().
@@ -1634,8 +1619,8 @@
* struct or NULL on erro= r.
*/
static ECDSA_SIG *
-ecdsa_sign_sig(const unsigned char *d= gst, int dgstlen, const BIGNUM *in_kinv,

- const BIGNUM *in_r, EC_KEY *ec)+ecdsa_sign_sig(const unsigned= char *dgst, int dgstlen, const BIGNUM *in_kinv, const BIGNUM *in_r,=
+ EC_KEY *ec)=
{
ECDSA_SIG *ecsig =3D NULL;<= br> unsigned int len =3D ECDSA_size(ec);
@@ -1733= ,8 +1718,7 @@

#ifdef HAVE_XKEY_PROVIDER<= /span>
EVP_PKEY *privkey =3D xkey_load_management_key(tls_lib= ctx, pkey);
- if (!p= rivkey
- || !SSL= _CTX_use_PrivateKey(ctx->ctx, privkey))
+ if (!privkey || !SSL_CTX_use_PrivateKey(ctx->= ctx, privkey))
{
EVP_PKEY_fre= e(privkey);
goto cleanup;
@@ -1743= ,7 +1727,7 @@
#else /* ifdef HAVE_XKEY_PROVIDER */=
#if OPENSSL_VERSION_NUMBER < 0x30000000L
= if (EVP_PKEY_id(pkey) =3D=3D EVP_PKEY_RSA)
-#else /* OPENSSL_VERSION_NUMBER < 0x30000000L */
+#else /* OPENSSL_VER= SION_NUMBER < 0x30000000L */
if (EVP_PKEY_is_a(pkey= , "RSA"))
#endif /* OPENSSL_VERSION_NUMBER < = 0x30000000L */
{
@@ -1755,7 +1739,7 @@=
#if !defined(OPENSSL_NO_EC)
#if OPENSSL_= VERSION_NUMBER < 0x30000000L
else if (EVP_PKEY_id(p= key) =3D=3D EVP_PKEY_EC)
+#else /* OPENSSL_VERSION_NUMBER < 0x= 30000000L */
else if (EVP_PKEY_is_a(pkey, "EC&quo= t;))
#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */<= /span>
{
@@ -1797,8 +1781,8 @@
}


void
-tls_ctx_load_ca(struct tls_root_ctx *ctx, const char= *ca_file,
- = bool ca_file_inline, const char *ca_path, bool tls_server)
<= span style=3D"color: hsl(120, 100%, 40%);">+tls_ctx_load_ca(struct tls_root= _ctx *ctx, const char *ca_file, bool ca_file_inline,

+ const char *ca_path, bool= tls_server)
{
STACK_OF(X509_INFO) *i= nfo_stack =3D NULL;
STACK_OF(X509_NAME) *cert_names = =3D NULL;
@@ -1893,8 +1877,7 @@
= {
crypto_msg(M_WARN,
"Cannot load CA certi= ficate file %s (entry %d did not validate)",
- print_key_fi= lename(ca_file, ca_file_inline),
- added);
+ print_= key_filename(ca_file, ca_file_inline), added);
= }
prev =3D cnum;
}

@@ -1910,8 +1893,7 @@

if (!added)
{<= br>- crypto_msg(M_FATA= L,
- = "Cannot load CA certificate file %s (no entries were read)",<= /span>
+ crypto_m= sg(M_FATAL, "Cannot load CA certificate file %s (no entries were read)= ",
print_key_filename(ca_file,= ca_file_inline));
}

<= span>@@ -1919,10 +1901,10 @@

{
= if (cnum !=3D added)
{
- crypto_msg(M_FATAL,= "Cannot load CA certificate file %s (only %d "

+ crypto_msg(M_FATAL,
+ = "Cannot load CA certificate file %s (only %d "
"of %d entries were valid X509 names)&= quot;,

- = print_key_filename(ca_file, ca_file_inline), cnum,
- added);=

+ = print_key_filename(ca_file, ca_file_inline), cnum, added); }
}
<= br>@@ -1962,9 +1944,7 @@
if (in =3D=3D NULL)
{
crypto_msg(M_FATAL, "Cann= ot load extra-certs file: %s",
- print_key_filename(extra_certs_file,
- = extra_certs_file_inline));
-
+ = print_key_filename(extra_certs_file, extra_certs_file_inlin= e));
}
else
= {
@@ -1989,10 +1969,10 @@

#warning BIO_DEBUG defined


-static FILE *biofp; /* = GLOBAL */
-static bool = biofp_toggle; /* GLOBAL */
-static time_t biofp_last_open; /*= GLOBAL */
-static cons= t int biofp_reopen_interval =3D 600; /* GLOBAL */
+static FILE *biofp; = /* GLOBAL */
+stati= c bool biofp_toggle; /* GLOBAL */
+static time_t biofp_last_open; = /* GLOBAL */
+st= atic const int biofp_reopen_interval =3D 600; /* GLOBAL */
=
static void
close_biofp(void)@@ -2032,8 +2012,8 @@
if (len > 0) {
open_biofp();
- fprintf(biofp, "BIO_%s %s time= =3D%" PRIi64 " bio=3D" ptr_format " len=3D%d data=3D%s\= n",
- = mode, desc, (int64_t)time(NULL), (ptr_type)bio, len, format_hex(buf, len= , 0, &gc));
+ = fprintf(biofp, "BIO_%s %s time=3D%" PRIi64 " bio=3D"= ; ptr_format " len=3D%d data=3D%s\n", mode, desc,
+ (int64_t)time(NULL)= , (ptr_type)bio, len, format_hex(buf, len, 0, &gc));

= fflush(biofp);
}
gc_free(&= amp;gc);
@@ -2043,8 +2023,8 @@
bio_debug_o= c(const char *mode, BIO *bio)
{
open_= biofp();
- fprintf(b= iofp, "BIO %s time=3D%" PRIi64 " bio=3D" ptr_format &qu= ot;\n",
- = mode, (int64_t)time(NULL), (ptr_type)bio);
+ fprintf(biofp, "BIO %s time=3D%" PR= Ii64 " bio=3D" ptr_format "\n", mode, (int64_t)time(NUL= L),
+ (ptr= _type)bio);
fflush(biofp);
}
@@ -2083,13 +2063,12 @@
= }
else if (i !=3D size)
{=
- crypto_ms= g(D_TLS_ERRORS, "TLS ERROR: BIO write %s incomplete %d/%d",
- desc= , i, size);
+ = crypto_msg(D_TLS_ERRORS, "TLS ERROR: BIO write %s incomplete %d/%d= ", desc, i, size);
ret =3D -1;
= ERR_clear_error();
}
= else
- = { /* successful write */
+ { /* successful write */ dmsg(D_HANDSHAKE_VERBOSE, "BIO write %s %d bytes&= quot;, desc, i);
ret =3D 1;
= }
@@ -2105,9 +2084,9 @@
static void=
bio_write_post(const int status, struct buffer *buf)
{
- if = (status =3D=3D 1) /* success status return from bio_write? */
+ if (status =3D=3D 1) = /* success status return from bio_write? */

= {
- memset(BPT= R(buf), 0, BLEN(buf)); /* erase data just written */
+ memset(BPTR(buf), 0, BLEN(buf)); = /* erase data just written */
buf->len =3D 0;
}
}
@@ -2133,7 +2112,7= @@
*/
int i =3D BIO_read(bio, B= PTR(buf), len);

- VALGRIND_MAKE_READABLE((void *) &i, sizeof(i));<= br>+ VALGRIND_MAKE_READABLE(= (void *)&i, sizeof(i));

#ifdef BIO_D= EBUG
bio_debug_data("read", bio, BPTR(buf), = i, desc);
@@ -2155,17 +2134,18 @@
= buf->len =3D 0;
}
else<= br>- { /= * successful read */
= + { /* successful read */
dmsg(D_HANDSHAKE_VERB= OSE, "BIO read %s %d bytes", desc, i);
b= uf->len =3D i;
ret =3D 1;
- VALGRIND_MAKE_READABLE((void *) BPT= R(buf), BLEN(buf));
+= VALGRIND_MAKE_READABLE((void *)BPTR(buf), BLEN(buf));
}

return ret;
}

void
-key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_root= _ctx *ssl_ctx, bool is_server, struct tls_session *session)
+key_state_ssl_init(struct key_state= _ssl *ks_ssl, const struct tls_root_ctx *ssl_ctx, bool is_server,
+ struct tls= _session *session)
{
ASSERT(NULL !=3D= ssl_ctx);
ASSERT(ks_ssl);
@@ -2233,8 = +2213,7 @@

ASSERT(NULL !=3D ks_ssl);=

- = ret =3D bio_write(ks_ssl->ssl_bio, BPTR(buf), BLEN(buf),
- "tls_write_= plaintext");

+ = ret =3D bio_write(ks_ssl->ssl_bio, BPTR(buf), BLEN(buf), "tls_wri= te_plaintext");
bio_write_post(ret, buf);<= br>
perf_pop();
@@ -2338,7 +231= 7,7 @@
type =3D OBJ_nid2sn(typeid);

/* OpenSSL reports rsaEncryption, dsaEncryptio= n and
- * id-ecP= ublicKey, map these values to nicer ones */
+ * id-ecPublicKey, map these values to nice= r ones */
if (typeid =3D=3D EVP_PKEY_RSA) {
type =3D "RSA";
@@ -2356,7 +2335,7 @@
{
<= span> type =3D "unknown type";

= }
-#else /* OpenSSL = >=3D 3 */
+#else = /* OpenSSL >=3D 3 */
type =3D EVP_PKEY_get0_typ= e_name(pkey);
if (type =3D=3D NULL)
{

@@ -2365,8 +2344,7 @@
#endif = /* if OPENSSL_VERSION_NUMBER < 0x30000000L */
}

- snp= rintf(buf, buflen, "%d bits %s%s",
- EVP_PKEY_bits(pkey), type, curve);
+ snprintf(buf, buflen= , "%d bits %s%s", EVP_PKEY_bits(pkey), type, curve);
}


/**
@@ -2386,12 += 2364,10 @@
int signature_nid =3D X509_get_signature_ni= d(cert);
if (signature_nid !=3D 0)
= {
- snprintf(s= ig, sizeof(sig), ", signature: %s",
- OBJ_nid2sn(signature_nid));=
+ snprintf(sig, size= of(sig), ", signature: %s", OBJ_nid2sn(signature_nid)); }

- snprintf(buf, buflen, ", peer certificate: %s%s",
- pkeybuf, s= ig);
+ snprintf(bu= f, buflen, ", peer certificate: %s%s", pkeybuf, sig);
<= span>

EVP_PKEY_free(pkey);
}<= br>@@ -2409,8 +2385,7 @@
char pkeybuf[128] =3D {= 0 };
print_pkey_details(pkey, pkeybuf, sizeof(pkeybuf= ));

-= snprintf(buf, buflen, ", peer temporary key: %s",
<= span style=3D"color: hsl(0, 100%, 40%);">- pkeybuf);

= + snprintf(buf, buflen, &quo= t;, peer temporary key: %s", pkeybuf);

EVP_PKEY_free(pkey);

}
@@ -2472,8 = +2447,7 @@
|| (defined(LIBRESSL_VERSION_NUMBER) &&= amp; LIBRESSL_VERSION_NUMBER >=3D 0x3090000fL)
/* L= ibreSSL 3.7.x and 3.8.x implement this function but do not export it=
* and fail linking with an unresolved symbol */
<= span style=3D"color: hsl(0, 100%, 40%);">- if (SSL_get_peer_signature_ty= pe_nid(ssl, &peer_sig_type_nid)

- && peer_sig_type_nid !=3D NID_undef)+ if (SSL_get_peer_signatu= re_type_nid(ssl, &peer_sig_type_nid) && peer_sig_type_nid !=3D = NID_undef)
{
peer_sig_type = =3D get_sigtype(peer_sig_type_nid);
}
= @@ -2484,8 +2458,7 @@
return;
= }

- = snprintf(buf, buflen, ", peer signing digest/type: %s %s",
- peer_sig, pe= er_sig_type);
+ sn= printf(buf, buflen, ", peer signing digest/type: %s %s", peer_sig= , peer_sig_type);
}

#if= OPENSSL_VERSION_NUMBER >=3D 0x30000000L
@@ -2523,11 +24= 96,8 @@

s1[0] =3D s2[0] =3D s3[0] = =3D s4[0] =3D s5[0] =3D 0;
ciph =3D SSL_get_current_ci= pher(ks_ssl->ssl);
-= snprintf(s1, sizeof(s1), "%s %s, cipher %s %s",
- prefix,

- SSL_get_version(ks_ssl-= >ssl),

- = SSL_CIPHER_get_version(ciph),
- SSL_CIPHER_get_name(ciph));
+ snprintf(s1, sizeof(s1), "%s %s, cip= her %s %s", prefix, SSL_get_version(ks_ssl->ssl),
+ SSL_CIPHER_get_version(c= iph), SSL_CIPHER_get_name(ciph));
X509 *cert =3D SSL_g= et_peer_certificate(ks_ssl->ssl);

= if (cert)
@@ -2545,9 +2515,7 @@
}<= br>
void
-show_available_tls_ciphers_list(const char *cipher_list,<= br>- = const char *tls_cert_profile,
- bool tls13)
+show_available_tls_ciphers_list(const ch= ar *cipher_list, const char *tls_cert_profile, bool tls13)
= {
struct tls_root_ctx tls_ctx;

@@ -2560,8 +2528,7 @@
#if defined(TLS1_3_VERSI= ON)
if (tls13)
{
- SSL_CTX_set_min_proto_version(= tls_ctx.ctx,
- = openssl_tls_version(TLS_VER_1_3));
<= span style=3D"color: hsl(120, 100%, 40%);">+ SSL_CTX_set_min_proto_v= ersion(tls_ctx.ctx, openssl_tls_version(TLS_VER_1_3));

= tls_ctx_restrict_ciphers_tls13(&tls_ctx, cipher_list);
<= span> }

else
@@ -2600,8 +2567,7 @@=
else if (NULL =3D=3D pair)
= {
/* No translation found, print warning */=
- printf(&q= uot;%s (No IANA name known to OpenVPN, use OpenSSL name.)\n",- cipher_name= );
+ print= f("%s (No IANA name known to OpenVPN, use OpenSSL name.)\n", ciph= er_name);
}
else {
@@ -2639,7 +2605,7 @@
= for (n =3D 0; n < crv_len; n++)
{=
const char *sname;
- sname =3D OBJ_nid2sn(curves[n].nid);
+ sname =3D OB= J_nid2sn(curves[n].nid);
if (sname =3D=3D NULL= )
{
sname =3D= "";
@@ -2655,7 +2621,7 @@
f= ree(curves);
#else /* ifndef OPENSSL_NO_EC */
<= span> msg(M_WARN, "Your OpenSSL library was built without elliptic= curve support. "

= - "No curves available.");
+ "No curves available.");<= /span>
#endif /* ifndef OPENSSL_NO_EC */
}

@@ -2679,7 +2645,7 @@
static = int
provider_unload(OSSL_PROVIDER *prov, void *unused)
{
- (v= oid) unused;
+ (vo= id)unused;
OSSL_PROVIDER_unload(prov);
return 1;

}
@@ -2717,7 +2683,7 @@
if (!OSSL_PROVIDER_load(tls_libctx, "ovpn.xkey&= quot;))
{
msg(M_NONFA= TAL, "ERROR: failed loading external key provider: "
- "Signing with= external keys will not work.");

+ "Signing with external k= eys will not work.");
}
= }

diff --git a/src/openvpn/ssl_openssl.h = b/src/openvpn/ssl_openssl.h
index f26b44e..48c23f3 100644
--- a/src/openvpn/ssl_openssl.h
+++ b/src/op= envpn/ssl_openssl.h
@@ -37,17 +37,19 @@
*= Structure that wraps the TLS context. Contents differ depending on the
* SSL library used.
*/
-struct tls_root_ctx {
+struct tls_root_ctx
+{
SSL_CTX *ctx;
time_t crl_last_mtime;
off_t crl_la= st_size;
};

-struct key_state_ssl {
- SSL *ssl; /* SSL object -- = new obj created for each new key */
- BIO *ssl_bio; /* read/write plainte= xt from here */
- BI= O *ct_in; /* write ciphertext to here */
- BIO *ct_out; = /* read ciphertext from here */
+struct key_state_ssl
+{
+ S= SL *ssl; /* SSL object -- new obj created for each new key */+ BIO *ssl_bio; /* read/wri= te plaintext from here */
+ BIO *ct_in; /* write ciphertext to here */
+ BIO *ct_out; /* read ciphertext fro= m here */
};

/**=
diff --git a/src/openvpn/ssl_pkt.c b/src/openvpn/ssl_pkt.c=
index bfd405f..8143c88 100644
--- a/src/openvpn/s= sl_pkt.c
+++ b/src/openvpn/ssl_pkt.c
@@ -62= ,8 +62,7 @@
{
ASSERT(co);
<= span>

- const struc= t key_ctx *ctx =3D (incoming ? &co->key_ctx_bi.decrypt :
<= span style=3D"color: hsl(0, 100%, 40%);">- = &co->key_ctx_bi.encrypt);

+ const struct key_ctx *ctx =3D (incoming ? &co->key_= ctx_bi.decrypt : &co->key_ctx_bi.encrypt);
ASSE= RT(ctx->hmac);

{
= @@ -121,8 +120,7 @@
tls_wrap_control(struct tls_wrap_ctx *= ctx, uint8_t header, struct buffer *buf,
= struct session_id *session_id)
{
- if (ctx->mode =3D=3D TLS_WRAP_AUTH
- || ctx->mode =3D= =3D TLS_WRAP_NONE)
+ = if (ctx->mode =3D=3D TLS_WRAP_AUTH || ctx->mode =3D=3D TLS_WRAP_NO= NE)
{
ASSERT(session_id_write= _prepend(session_id, buf));
ASSERT(buf_write_prepe= nd(buf, &header, sizeof(header)));
@@ -149,8 +147,7 @@<= /span>
if ((header >> P_OPCODE_SHIFT) =3D=3D P_CONT= ROL_HARD_RESET_CLIENT_V3
|| (header >> P= _OPCODE_SHIFT) =3D=3D P_CONTROL_WKC_V1)
{- if (!buf_copy(&= ;ctx->work,
- = ctx->tls_crypt_v2_wkc))
+ if (!buf_copy(&ctx->work, ctx-= >tls_crypt_v2_wkc))
{
= msg(D_TLS_ERRORS, "Could not append tls-crypt-v2 client ke= y");
buf->len =3D 0;
@@ -165,12 +162,8 @@

}

void

-write_control_= auth(struct tls_session *session,
- struct key_state *ks,
- struct buffer *buf,
- struct = link_socket_actual **to_link_addr,
- int opcode,
- int max_ack,
+write_control_auth(struct tls_session *se= ssion, struct key_state *ks, struct buffer *buf,
+ struct link_socket_actual *= *to_link_addr, int opcode, int max_ack,
= bool prepend_ack)
{
uint8_t header = =3D ks->key_id | (opcode << P_OPCODE_SHIFT);
@@ -1= 85,34 +178,30 @@
}

= ASSERT(link_socket_actual_defined(&ks->remote_addr));
= - ASSERT(reliable_ack_write
- (ks->r= ec_ack, ks->lru_acks, buf, &ks->session_id_remote,
- max_ack, prepend_ack)= );

+ ASSERT(reliab= le_ack_write(ks->rec_ack, ks->lru_acks, buf, &ks->session_id_r= emote, max_ack,
+ = prepend_ack));

= msg(D_TLS_DEBUG, "%s(): %s", __func__, packet_opcode_name(op= code));

- tls_wrap_control(tls_session_get_tls_wrap(session, ks->key_id), = header, buf, &session->session_id);
+ tls_wrap_control(tls_session_get_tls_wrap(sessio= n, ks->key_id), header, buf,
+ &session->session_id);

*to_link_addr =3D &ks->remote_addr;
}

bool
-read_control_auth(struct buffer *buf,
- struct tl= s_wrap_ctx *ctx,
- = const struct link_socket_actual *from,
- const struct tls_options = *opt,
+read_control_a= uth(struct buffer *buf, struct tls_wrap_ctx *ctx,
+ const struct link_socket_ac= tual *from, const struct tls_options *opt,
= bool initial_packet)
{
struct gc_a= rena gc =3D gc_new();
bool ret =3D false;

const uint8_t opcode =3D *(BPTR(buf)) >> P= _OPCODE_SHIFT;
- if = ((opcode =3D=3D P_CONTROL_HARD_RESET_CLIENT_V3
- || opcode =3D=3D P_CONTROL_WKC_V1)=
+ if ((opcode =3D=3D P_C= ONTROL_HARD_RESET_CLIENT_V3 || opcode =3D=3D P_CONTROL_WKC_V1)
&& !tls_crypt_v2_extract_client_key(buf, ctx, opt, ini= tial_packet))

{
- msg(D_TLS_ERRORS,
- "TLS Error: can not extract tls-crypt-v= 2 client key from %s",
+ msg(D_TLS_ERRORS, "TLS Error: can not extract tls-cryp= t-v2 client key from %s",
print_link_sock= et_actual(from, &gc));
goto cleanup; }
@@ -224,8 +213,7 @@
= /* move the hmac record to the front of the packet */
= if (!swap_hmac(buf, &ctx->opt, true))
{=
- msg(D_TLS= _ERRORS,
- = "TLS Error: cannot locate HMAC in incoming packet from %s",
+ msg(D_TLS_= ERRORS, "TLS Error: cannot locate HMAC in incoming packet from %s"= ;,
print_link_socket_actual(from, &gc)= );
gc_free(&gc);
= return false;
@@ -236,12 +224,10 @@
= openvpn_decrypt(buf, null, &ctx->opt, NULL, BPTR(buf));=
if (!buf->len)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- msg(D_TLS_ERRORS,
- "TLS= Error: incoming packet authentication failed from %s",
+ msg(D_TLS_ERRORS, &quo= t;TLS Error: incoming packet authentication failed from %s",
print_link_socket_actual(from, &gc)); goto cleanup;
}
-

}
else if (ctx->mode =3D=3D TLS_WRAP_CRYPT)

= {
@@ -305,17 +291,14 @@
* on the UDP port= listener in --mode server mode.
*/
enum= first_packet_verdict
-= tls_pre_decrypt_lite(const struct tls_auth_standalone *tas,
- struct tls_pre_d= ecrypt_state *state,

- = const struct link_socket_actual *from,
- const struct buff= er *buf)
+tls_pre_dec= rypt_lite(const struct tls_auth_standalone *tas, struct tls_pre_decrypt_sta= te *state,
+ = const struct link_socket_actual *from, const struct buffer *buf= )
{
struct gc_arena gc =3D gc_new();<= /span>
/* A packet needs to have at least an opcode and sessi= on id */
if (buf->len < (1 + SID_SIZE)) {
- = dmsg(D_TLS_STATE_ERRORS,
- "TLS State Error: Too short packet (length %d) recei= ved from %s",
+ = dmsg(D_TLS_STATE_ERRORS, "TLS State Error: Too short packet (le= ngth %d) received from %s",
buf->len= , print_link_socket_actual(from, &gc));
goto e= rror;
}
@@ -329,27 +312,21 @@ * scrutinize carefully */

= /* Allow only the reset packet or the first packet of the actual handsh= ake. */
- if (op != =3D P_CONTROL_HARD_RESET_CLIENT_V2
- && op !=3D P_CONTROL_HARD_RESET_CLIENT_V3
- && op !=3D= P_CONTROL_V1
- = && op !=3D P_CONTROL_WKC_V1
- && op !=3D P_ACK_V1)
+ if (op !=3D P_CONTROL_HARD_RESET_CLIENT_= V2 && op !=3D P_CONTROL_HARD_RESET_CLIENT_V3
+ && op !=3D P_CONTROL_V1 &= amp;& op !=3D P_CONTROL_WKC_V1 && op !=3D P_ACK_V1)
<= span> {

/*
* This ca= n occur due to bogus data or DoS packets.
*/
- dmsg(D_TLS_STATE_E= RRORS,
- &q= uot;TLS State Error: No TLS state for client %s, opcode=3D%d",<= br>- print_link_socke= t_actual(from, &gc),
= + dmsg(D_TLS_STATE_ERRORS, "TLS State Error: No TLS state for c= lient %s, opcode=3D%d",
+ print_link_socket_actual(from, &gc), op);<= br> goto error;
}

if (key_id !=3D 0)
{
= dmsg(D_TLS_STATE_ERRORS,
- "TLS State Error: Unknown key ID (%d) receive= d from %s -- 0 was expected",
- key_id,
+ "TLS State Error: Unknown key ID (%d) recei= ved from %s -- 0 was expected", key_id,
= print_link_socket_actual(from, &gc));
goto err= or;
}
@@ -361,8 +338,7 @@
if (!session_id_read(&state->peer_session_id, &tmp)
|| !session_id_defined(&state->peer_session_id= ))
{
- msg(D_TLS_ERRORS,
- "TLS Error: session-id not found in packet from %s= ",
+ msg(= D_TLS_ERRORS, "TLS Error: session-id not found in packet from %s"= ,
print_link_socket_actual(from, &gc));

goto error;
}
@= @ -373,8 +349,7 @@
/* HMAC test and unwrapping the enc= rypted part of the control message
* into newbuf or j= ust setting newbuf to point to the start of control
*= message */
- bool s= tatus =3D read_control_auth(&state->newbuf, &state->tls_wrap_= tmp,
- = from, NULL, true);
+ bool status =3D read_control_auth(&state->newb= uf, &state->tls_wrap_tmp, from, NULL, true);

if (!status)
{
@@ -426= ,11 +401,8 @@


struct b= uffer
-tls_reset_standa= lone(struct tls_wrap_ctx *ctx,
- struct tls_auth_standalone *tas,
- struct sessio= n_id *own_sid,

- = struct session_id *remote_sid,
- uint8_t header,
+tls_reset_standalone(struct tls_wra= p_ctx *ctx, struct tls_auth_standalone *tas,

+ struct session_id *own_sid, s= truct session_id *remote_sid, uint8_t header,
= bool request_resend_wkc)
{
/= * Copy buffer here to point at the same data but allow tls_wrap_control
@@ -485,12 +457,11 @@
}

struct session_id
-calculate_session_id_hmac(struct session_id client_sid,- const= struct openvpn_sockaddr *from,
- hmac_ctx_t *hmac,
- int handwindow, i= nt offset)
+calculate= _session_id_hmac(struct session_id client_sid, const struct openvpn_sockadd= r *from,
+ = hmac_ctx_t *hmac, int handwindow, int offset)
{

- union {
+ union
+ {

uint= 8_t hmac_result[SHA256_DIGEST_LENGTH];
struct sess= ion_id sid;
} result;
@@ -498,23 +469,= 22 @@
/* Get the valid time quantisation for our hmac,=
* we divide time by handwindow/2 and allow the previ= ous
* and future session time if specified by offset = */
- uint32_t sessio= n_id_time =3D ntohl(now/((handwindow+1)/2) + offset);
+ uint32_t session_id_time =3D ntohl(no= w / ((handwindow + 1) / 2) + offset);

= hmac_ctx_reset(hmac);
/* We do not care about endian= here since it does not need to be
* portable */
- hmac_ctx_update(hmac, = (const uint8_t *) &session_id_time,
- sizeof(session_id_time));
<= span style=3D"color: hsl(120, 100%, 40%);">+ hmac_ctx_update(hmac, (cons= t uint8_t *)&session_id_time, sizeof(session_id_time));


/* add client IP and port */
s= witch (from->addr.sa.sa_family)
{
= case AF_INET:
-= hmac_ctx_update(hmac, (const uint8_t *) &from->addr.in4,= sizeof(struct sockaddr_in));
+ hmac_ctx_update(hmac, (const uint8_t *)&from->= addr.in4, sizeof(struct sockaddr_in));
break;<= /span>

case AF_INET6:
- hmac_ctx_update(hmac, (cons= t uint8_t *) &from->addr.in6, sizeof(struct sockaddr_in6));+ hmac_ctx_update(= hmac, (const uint8_t *)&from->addr.in6, sizeof(struct sockaddr_in6))= ;
break;
}

@@ -527,10 +497,8 @@
}

bool
- const struct = openvpn_sockaddr *from,
- hmac_ctx_t *hmac,
- int handwindow)
+check_session_id_hmac(struct tls_pre_= decrypt_state *state, const struct openvpn_sockaddr *from,
+ hmac_ctx_t *hm= ac, int handwindow)
{
if (!from)
{
@@ -575,7 +543,7 @@
= }

/* include the NUL byte and ensur= e NUL termination */
- = cmdlen +=3D 1;
+ = cmdlen +=3D 1;

/* Construct a buf= fer that only holds the current command and
* its clo= sing NUL byte */
diff --git a/src/openvpn/ssl_pkt.h b/src/o= penvpn/ssl_pkt.h
index 98a39d3..fd673f4 100644
--- a/src/openvpn/ssl_pkt.h

+++ b/src/openvpn/ssl_pkt.h=
@@ -36,40 +36,40 @@
#include "ssl_co= mmon.h"

/* packet opcode (high 5 bi= ts) and key-id (low 3 bits) are combined in one byte */
-#define P_KEY_ID_MASK 0x= 07
-#define P_OPCODE_SH= IFT 3
+#define P_KEY_ID_MASK 0x07
+#define P_OPCODE_SHIFT 3

/* pa= cket opcodes -- the V1 is intended to allow protocol changes in the future = */
-#define P_CONTROL_H= ARD_RESET_CLIENT_V1 1 /* initial key from client, forget previous state= */
-#define P_CONTROL_= HARD_RESET_SERVER_V1 2 /* initial key from server, forget previous stat= e */
-#define P_CONTROL= _SOFT_RESET_V1 3 /* new key, graceful transition from old to new= key */
-#define P_CONT= ROL_V1 4 /* control channel packet (usually TLS ciphe= rtext) */
-#define P_AC= K_V1 5 /* acknowledgement for packets received */=
-#define P_DATA_V1 = 6 /* data channel packet */
-#define P_DATA_V2 9 /*= data channel packet with peer-id */
+#define P_CONTROL_HARD_RESET_CLIENT_V1 1 /* initial key fr= om client, forget previous state */
+#define P_CONTROL_HARD_RESET_SERVER_V1 2 /* initial key fro= m server, forget previous state */
+#define P_CONTROL_SOFT_RESET_V1 3 /* new key, gracefu= l transition from old to new key */
+#define P_CONTROL_V1 4 /* control channel= packet (usually TLS ciphertext) */
+#define P_ACK_V1 5 /* acknowledgement= for packets received */
+#define P_DATA_V1 6 /* data channel packet */
+#define P_DATA_V2 = 9 /* data channel packet with peer-id */
<= /span>
/* indicates key_method >=3D 2 */
-#define P_CONTROL_HARD_RESET_CLIENT_V2 7 = /* initial key from client, forget previous state */
-#define P_CONTROL_HARD_RESET_SERVER_V2 8 = /* initial key from server, forget previous state */
+#define P_CONTROL_HARD_RESET_CLIENT_V2 = 7 /* initial key from client, forget previous state */
+#define P_CONTROL_HARD_RESET_SERVER_V2 8= /* initial key from server, forget previous state */

/* indicates key_method >=3D 2 and client-specific tls-cry= pt key */
-#define P_CO= NTROL_HARD_RESET_CLIENT_V3 10 /* initial key from client, forget previou= s state */
+#define P= _CONTROL_HARD_RESET_CLIENT_V3 10 /* initial key from client, forget previou= s state */

/* Variant of P_CONTROL_V1 bu= t with appended wrapped key
* like P_CONTROL_HARD_RESET_C= LIENT_V3 */
-#define P_= CONTROL_WKC_V1 11
+#define P_CONTROL_WKC_V1 11

= /* define the range of legal opcodes
* Since we do no lon= ger support key-method 1 we consider
* the v1 op codes in= valid */
-#define P_FIR= ST_OPCODE 3
-#define P_LAST_OPCODE 11
+#define P_FIRST_OPCODE 3
+#define P_LAST_OPCODE 11

/*
* Define number of buffers for sen= d and receive in the reliability layer.
*/
-#define TLS_RELIABLE_N_SEND_BUFFERS = 6 /* also window size for reliability layer */

-#define TLS_RELIABLE_N_REC_BUFFERS 12+#define TLS_RELIABLE_N_SEND_B= UFFERS 6 /* also window size for reliability layer */
+#define TLS_RELIABLE_N_REC_BUFFERS 12

/*
* Used in --mode serv= er mode to check tls-auth signature on initial
@@ -82,7 +82= ,8 @@
struct frame frame;
};
-enum first_p= acket_verdict {
+enum= first_packet_verdict
+{
/** This packet is a valid reset packet from the p= eer (all but tls-crypt-v2) */
VERDICT_VALID_RESET_V2,<= /span>
/** This is a valid v3 reset (tls-crypt-v2) */<= br>@@ -102,7 +103,8 @@
* struct that stores the tem= porary data for the tls lite decrypt
* functions */
-struct tl= s_pre_decrypt_state {
+struct tls_pre_decrypt_state
+{
struct tls_wrap_ctx tls_wrap_tmp;<= br> struct buffer newbuf;
struct session_id = peer_session_id;
@@ -145,11 +147,10 @@
* = @li False if the packet is not valid, did not pass the HMAC firewall=
* test, or some other error occurred.
*/<= /span>
-enum first_packet_verd= ict
-tls_pre_decrypt_li= te(const struct tls_auth_standalone *tas,
- struct tls_pre_decrypt_state *stat= e,
- = const struct link_socket_actual *from,
- const struct buffer *buf);+enum first_packet_verdict tl= s_pre_decrypt_lite(const struct tls_auth_standalone *tas,
+ = struct tls_pre_decrypt_state *state,
+ c= onst struct link_socket_actual *from,
+ const stru= ct buffer *buf);

/* Creates an SHA256 HM= AC context with a random key that is used for the
* sessi= on id.
@@ -171,11 +172,9 @@
* @param offs= et offset to 'now' to use
* @return = the expected server session id
*/
-struct session_id
-calculate_session_id_hmac(struct session_i= d client_sid,
- = const struct openvpn_sockaddr *from,
- hmac_ctx_t *hmac= ,
- = int handwindow, int offset);
+struct session_id calculate_session_id_hmac(struct session_i= d client_sid,
+ = const struct openvpn_sockaddr *from, = hmac_ctx_t *hmac,
+ = int handwindow, int offset);

/**
* Checks if a control = packet has a correct HMAC server session id
@@ -186,24 +185= ,15 @@
* @param handwindow the quantisation of the cur= rent time
* @return the expected server sess= ion id
*/
-bool
-check_sessi= on_id_hmac(struct tls_pre_decrypt_state *state,
- const struct openvpn_sockad= dr *from,
- = hmac_ctx_t *hmac,
- int handwindow);
+bool check_session_id_hmac(struct tls_pre_decrypt_= state *state, const struct openvpn_sockaddr *from,
+ hmac_ctx_t *hmac,= int handwindow);

/*
*= Write a control channel authentication record.
*/=
-void
-write_control_auth(struct tls_session *sess= ion,
- = struct key_state *ks,
- struct buffer *buf,
- struct link_socket_actual **to_link_a= ddr,
- = int opcode,
- = int max_ack,
- bool prepend_ack);
-
+v= oid write_control_auth(struct tls_session *session, struct key_state *ks, s= truct buffer *buf,
+ = struct link_socket_actual **to_link_addr, int opcode= , int max_ack,
+ = bool prepend_ack);


/**
@@ -215,12 +205,9 @@
= * @param initial_packet whether this is the initial packet for the conne= ction
* @return if the packet was succes= sfully processed
*/
-bool
-r= ead_control_auth(struct buffer *buf,
- struct tls_wrap_ctx *ctx,
- const struct link_so= cket_actual *from,
- = const struct tls_options *opt,
- bool initial_packet);
<= span style=3D"color: hsl(120, 100%, 40%);">+bool read_control_auth(struct b= uffer *buf, struct tls_wrap_ctx *ctx,

+ const struct link_socket_actual *f= rom, const struct tls_options *opt,
+ bool initial_packet);


/**
@@ -228,13 +215,= 9 @@
* from the tls pre decrypt state.
= *
*/
= -struct buffer
-tls_res= et_standalone(struct tls_wrap_ctx *ctx,
- struct tls_auth_standalone *tas,
- stru= ct session_id *own_sid,
- struct session_id *remote_sid,
- uint8_t header,=
- bool re= quest_resend_wkc);
+s= truct buffer tls_reset_standalone(struct tls_wrap_ctx *ctx, struct tls_auth= _standalone *tas,
+ = struct session_id *own_sid, struct session= _id *remote_sid,
+ = uint8_t header, bool request_resend_wkc);


/**
@@ = -247,8 +230,7 @@
* with length 0 if there is= no message or the message has
* invalid cha= racters.
*/
-struct buffer
-= extract_command_buffer(struct buffer *buf, struct gc_arena *gc);
= +struct buffer extract_command_= buffer(struct buffer *buf, struct gc_arena *gc);
static inline const char *
packet_opcode_name(int= op)
@@ -324,14 +306,14 @@
* but the netw= ork time part of the packet id takes care of that. And
* = this is also a rather theoretical scenario as it still needs more than
* 2^31 control channel packets to happen */
-#define EARLY_NEG_MASK 0xff000= 000
-#define EARLY_NEG_= START 0x0f000000
+#define EARLY_NEG_MASK 0xff000000
+#define EARLY_NEG_START 0x0f000000


/* Early negotiation that part of the serv= er response in the RESET_V2 packet.
* Since clients that = announce early negotiation support will treat the payload
= * of reset packets special and parse it as TLV messages.
= * as TLV (type, length, value) */
-#define TLV_TYPE_EARLY_NEG_FLAGS 0x0001
-#define EARLY_NEG_FLAG_RESEND_WKC = 0x0001

+#define TL= V_TYPE_EARLY_NEG_FLAGS 0x0001
+#define EARLY_NEG_FLAG_RESEND_WKC 0x0001
#endif= /* ifndef SSL_PKT_H */
diff --git a/src/openvpn/ssl_util.c= b/src/openvpn/ssl_util.c
index d3d7b2c..676a0e5 100644
--- a/src/openvpn/ssl_util.c
+++ b/src/openvpn= /ssl_util.c
@@ -29,8 +29,7 @@
#include &qu= ot;ssl_util.h"

char *
-extract_var_peer_info(const char *p= eer_info, const char *var,

- struct gc_arena *gc)
+extract_var_peer_info(const char *peer_info, co= nst char *var, struct gc_arena *gc)
{
= if (!peer_info)
{
@@ -78,8 +77,10 @@<= /span>
options_string_compat_lzo(const char *options, struct gc_a= rena *gc)
{
/* Example string without= and with comp-lzo, i.e. input/output of this function */
- /* w/o comp: 'V4,dev-type tun,l= ink-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tl= s-server' */
- /= * comp-lzo: 'V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,com= p-lzo,auth SHA1,keysize 128,key-method 2,tls-server' */
+ /* w/o comp: 'V4,dev-type t= un,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize

+ * 128,key-method 2,tls-server&= #39; */

+ /* comp-= lzo: 'V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,comp-lzo,a= uth SHA1,keysize
+ = * 128,key-method 2,tls-server' */

= /* Note: since this function is used only in a very limited scope it ma= kes
* assumptions how the string looks. Since we loca= lly generated the string
@@ -119,146 +120,156 @@
= * SSL/TLS Cipher suite name translation table
*/<= /span>
static const tls_cipher_name_pair tls_cipher_name_translat= ion_table[] =3D {
- = {"ADH-SEED-SHA", "TLS-DH-anon-WITH-SEED-CBC-SHA"},
- {"AES128-GCM-SHA2= 56", "TLS-RSA-WITH-AES-128-GCM-SHA256"},
- {"AES128-SHA256", "TLS= -RSA-WITH-AES-128-CBC-SHA256"},
- {"AES128-SHA", "TLS-RSA-WITH-AES-128-CBC-= SHA"},
- {"= ;AES256-GCM-SHA384", "TLS-RSA-WITH-AES-256-GCM-SHA384"},
- {"AES256-SHA256&= quot;, "TLS-RSA-WITH-AES-256-CBC-SHA256"},
- {"AES256-SHA", "TLS-RSA-= WITH-AES-256-CBC-SHA"},
- {"CAMELLIA128-SHA256", "TLS-RSA-WITH-CAMELLIA-128= -CBC-SHA256"},
- = {"CAMELLIA128-SHA", "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA&quo= t;},
- {"CAMELL= IA256-SHA256", "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA256"},
- {"CAMELLIA256-SHA= ", "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA"},
- {"DES-CBC3-SHA", "TLS-= RSA-WITH-3DES-EDE-CBC-SHA"},
- {"DES-CBC-SHA", "TLS-RSA-WITH-DES-CBC-SHA&qu= ot;},
- {"DH-DS= S-SEED-SHA", "TLS-DH-DSS-WITH-SEED-CBC-SHA"},
- {"DHE-DSS-AES128-GCM-SHA256= ", "TLS-DHE-DSS-WITH-AES-128-GCM-SHA256"},

- {"DHE-DSS-AES128-SHA256",= "TLS-DHE-DSS-WITH-AES-128-CBC-SHA256"},
- {"DHE-DSS-AES128-SHA", "TLS= -DHE-DSS-WITH-AES-128-CBC-SHA"},
- {"DHE-DSS-AES256-GCM-SHA384", "TLS-DHE-D= SS-WITH-AES-256-GCM-SHA384"},
- {"DHE-DSS-AES256-SHA256", "TLS-DHE-DSS-WITH= -AES-256-CBC-SHA256"},
- {"DHE-DSS-AES256-SHA", "TLS-DHE-DSS-WITH-AES-256-C= BC-SHA"},
- {&q= uot;DHE-DSS-CAMELLIA128-SHA256", "TLS-DHE-DSS-WITH-CAMELLIA-128-C= BC-SHA256"},
- = {"DHE-DSS-CAMELLIA128-SHA", "TLS-DHE-DSS-WITH-CAMELLIA-128-C= BC-SHA"},
- {&q= uot;DHE-DSS-CAMELLIA256-SHA256", "TLS-DHE-DSS-WITH-CAMELLIA-256-C= BC-SHA256"},
- = {"DHE-DSS-CAMELLIA256-SHA", "TLS-DHE-DSS-WITH-CAMELLIA-256-C= BC-SHA"},
- {&q= uot;DHE-DSS-SEED-SHA", "TLS-DHE-DSS-WITH-SEED-CBC-SHA"},
- {"DHE-RSA-AES128= -GCM-SHA256", "TLS-DHE-RSA-WITH-AES-128-GCM-SHA256"},=
- {"DHE-RSA-AES128-SH= A256", "TLS-DHE-RSA-WITH-AES-128-CBC-SHA256"},
- {"DHE-RSA-AES128-SHA"= , "TLS-DHE-RSA-WITH-AES-128-CBC-SHA"},

- {"DHE-RSA-AES256-GCM-SHA384", &quo= t;TLS-DHE-RSA-WITH-AES-256-GCM-SHA384"},
- {"DHE-RSA-AES256-SHA256", "TLS-D= HE-RSA-WITH-AES-256-CBC-SHA256"},
- {"DHE-RSA-AES256-SHA", "TLS-DHE-RSA-WIT= H-AES-256-CBC-SHA"},
- {"DHE-RSA-CAMELLIA128-SHA256", "TLS-DHE-RSA-WITH-CAM= ELLIA-128-CBC-SHA256"},
- {"DHE-RSA-CAMELLIA128-SHA", "TLS-DHE-RSA-WITH-CAM= ELLIA-128-CBC-SHA"},
- {"DHE-RSA-CAMELLIA256-SHA256", "TLS-DHE-RSA-WITH-CAM= ELLIA-256-CBC-SHA256"},
- {"DHE-RSA-CAMELLIA256-SHA", "TLS-DHE-RSA-WITH-CAM= ELLIA-256-CBC-SHA"},
- {"DHE-RSA-CHACHA20-POLY1305", "TLS-DHE-RSA-WITH-CHAC= HA20-POLY1305-SHA256"},
- {"DHE-RSA-SEED-SHA", "TLS-DHE-RSA-WITH-SEED-CBC-S= HA"},
- {"= DH-RSA-SEED-SHA", "TLS-DH-RSA-WITH-SEED-CBC-SHA"},- {"ECDH-ECDSA-AES128-GC= M-SHA256", "TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256"},=
- {"ECDH-ECDSA-AES128= -SHA256", "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256"},<= br>- {"ECDH-ECDSA-AES128-= SHA", "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA"},
- {"ECDH-ECDSA-AES256-GCM-SHA= 384", "TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA384"},

<= span style=3D"color: hsl(0, 100%, 40%);">- {"ECDH-ECDSA-AES256-SHA2= 56", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA256"},

- {"ECDH-ECDSA-AES256-SHA38= 4", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384"},

- {"ECDH-ECDSA-AES256-SHA&qu= ot;, "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA"},

- {"ECDH-ECDSA-CAMELLIA128-SHA256&q= uot;, "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-SHA256"},
<= span style=3D"color: hsl(0, 100%, 40%);">- {"ECDH-ECDSA-CAMELLIA128= -SHA", "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-SHA"},
- {"ECDH-ECDSA-CAMELLIA= 256-SHA256", "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA256"},=
- {"ECDH-ECDSA= -CAMELLIA256-SHA", "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA"= ;},
- {"ECDH-EC= DSA-DES-CBC3-SHA", "TLS-ECDH-ECDSA-WITH-3DES-EDE-CBC-SHA"},<= /span>
- {"ECDH-ECDSA-= DES-CBC-SHA", "TLS-ECDH-ECDSA-WITH-DES-CBC-SHA"},
= - {"ECDH-ECDSA-RC4-SHA&qu= ot;, "TLS-ECDH-ECDSA-WITH-RC4-128-SHA"},
- {"ECDHE-ECDSA-AES128-GCM-SHA256"= , "TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256"},
- {"ECDHE-ECDSA-AES128-SHA256"= ;, "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256"},
- {"ECDHE-ECDSA-AES128-SHA384&quo= t;, "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA384"},
- {"ECDHE-ECDSA-AES128-SHA"= , "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA"},
- {"ECDHE-ECDSA-AES256-GCM-SHA384&qu= ot;, "TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384"},
- {"ECDHE-ECDSA-AES256-SHA256&q= uot;, "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA256"},
- {"ECDHE-ECDSA-AES256-SHA384&= quot;, "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384"},

- {"ECDHE-ECDSA-AES256-SHA&qu= ot;, "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA"},

- {"ECDHE-ECDSA-CAMELLIA128-SHA256= ", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CBC-SHA256"},- {"ECDHE-ECDSA-CAMELLI= A128-SHA", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CBC-SHA"},
- {"ECDHE-ECDSA-CA= MELLIA256-SHA256", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-CBC-SHA256&= quot;},
- {"ECD= HE-ECDSA-CAMELLIA256-SHA", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-CBC= -SHA"},
- {&quo= t;ECDHE-ECDSA-CHACHA20-POLY1305", "TLS-ECDHE-ECDSA-WITH-CHACHA20-= POLY1305-SHA256"},
- {"ECDHE-ECDSA-DES-CBC3-SHA", "TLS-ECDHE-ECDSA-WITH-3DE= S-EDE-CBC-SHA"},
-= {"ECDHE-ECDSA-DES-CBC-SHA", "TLS-ECDHE-ECDSA-WITH-DES-CB= C-SHA"},
- {&qu= ot;ECDHE-ECDSA-RC4-SHA", "TLS-ECDHE-ECDSA-WITH-RC4-128-SHA"}= ,
- {"ECDHE-RSA= -AES128-GCM-SHA256", "TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256"= },
- {"ECDHE-RS= A-AES128-SHA256", "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256"},<= /span>
- {"ECDHE-RSA-A= ES128-SHA384", "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA384"},
- {"ECDHE-RSA-AES1= 28-SHA", "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA"},
- {"ECDHE-RSA-AES256-GCM-SH= A384", "TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384"},

<= span style=3D"color: hsl(0, 100%, 40%);">- {"ECDHE-RSA-AES256-SHA25= 6", "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA256"},

- {"ECDHE-RSA-AES256-SHA384&q= uot;, "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384"},

- {"ECDHE-RSA-AES256-SHA", = "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA"},
- {"ECDHE-RSA-CAMELLIA128-SHA256", &= quot;TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SHA256"},
- {"ECDHE-RSA-CAMELLIA128-SHA"= ;, "TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SHA"},
- {"ECDHE-RSA-CAMELLIA256-SHA256&= quot;, "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SHA256"},
<= span style=3D"color: hsl(0, 100%, 40%);">- {"ECDHE-RSA-CAMELLIA256-= SHA", "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SHA"},

= - {"ECDHE-RSA-CHACHA20-PO= LY1305", "TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256"},
- {"ECDHE-RSA-DES-= CBC3-SHA", "TLS-ECDHE-RSA-WITH-3DES-EDE-CBC-SHA"},- {"ECDHE-RSA-DES-CBC-SH= A", "TLS-ECDHE-RSA-WITH-DES-CBC-SHA"},
- {"ECDHE-RSA-RC4-SHA", "T= LS-ECDHE-RSA-WITH-RC4-128-SHA"},
- {"ECDH-RSA-AES128-GCM-SHA256", "TLS-ECDH= -RSA-WITH-AES-128-GCM-SHA256"},
- {"ECDH-RSA-AES128-SHA256", "TLS-ECDH-RSA-= WITH-AES-128-CBC-SHA256"},
- {"ECDH-RSA-AES128-SHA384", "TLS-ECDH-RSA-WITH-= AES-128-CBC-SHA384"},
- {"ECDH-RSA-AES128-SHA", "TLS-ECDH-RSA-WITH-AES-128-= CBC-SHA"},
- {&= quot;ECDH-RSA-AES256-GCM-SHA384", "TLS-ECDH-RSA-WITH-AES-256-GCM-= SHA384"},
- {&q= uot;ECDH-RSA-AES256-SHA256", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA25= 6"},
- {"E= CDH-RSA-AES256-SHA384", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA384&quo= t;},
- {"ECDH-R= SA-AES256-SHA", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA"},=
- {"ECDH-RSA-CAMELLIA= 128-SHA256", "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA256"},
- {"ECDH-RSA-CAM= ELLIA128-SHA", "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA"},
- {"ECDH-RSA-CAME= LLIA256-SHA256", "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SHA256"= },
- {"ECDH-RSA= -CAMELLIA256-SHA", "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SHA"}= ,
- {"ECDH-RSA-= DES-CBC3-SHA", "TLS-ECDH-RSA-WITH-3DES-EDE-CBC-SHA"},=
- {"ECDH-RSA-DES-CBC-= SHA", "TLS-ECDH-RSA-WITH-DES-CBC-SHA"},
- {"ECDH-RSA-RC4-SHA", "T= LS-ECDH-RSA-WITH-RC4-128-SHA"},
- {"EDH-DSS-DES-CBC3-SHA", "TLS-DHE-DSS-WIT= H-3DES-EDE-CBC-SHA"},
- {"EDH-DSS-DES-CBC-SHA", "TLS-DHE-DSS-WITH-DES-CBC-S= HA"},
- {"= EDH-RSA-DES-CBC3-SHA", "TLS-DHE-RSA-WITH-3DES-EDE-CBC-SHA"},=
- {"EDH-RSA-DE= S-CBC-SHA", "TLS-DHE-RSA-WITH-DES-CBC-SHA"},
- {"EXP-DES-CBC-SHA", &qu= ot;TLS-RSA-EXPORT-WITH-DES40-CBC-SHA"},

- {"EXP-EDH-DSS-DES-CBC-SHA", "TLS-= DH-DSS-EXPORT-WITH-DES40-CBC-SHA"},
- {"EXP-EDH-RSA-DES-CBC-SHA", "TLS-DH-R= SA-EXPORT-WITH-DES40-CBC-SHA"},
- {"EXP-RC2-CBC-MD5", "TLS-RSA-EXPORT-WITH-= RC2-CBC-40-MD5"},
= - {"EXP-RC4-MD5", "TLS-RSA-EXPORT-WITH-RC4-40-MD5"},=
- {"NULL-MD5&q= uot;, "TLS-RSA-WITH-NULL-MD5"},
- {"NULL-SHA256", "TLS-RSA-WITH-NULL-S= HA256"},
- {&qu= ot;NULL-SHA", "TLS-RSA-WITH-NULL-SHA"},
- {"PSK-3DES-EDE-CBC-SHA", &qu= ot;TLS-PSK-WITH-3DES-EDE-CBC-SHA"},
- {"PSK-AES128-CBC-SHA", "TLS-PSK-WITH-= AES-128-CBC-SHA"},
- {"PSK-AES256-CBC-SHA", "TLS-PSK-WITH-AES-256-CBC-SHA&q= uot;},
- {"PSK-= RC4-SHA", "TLS-PSK-WITH-RC4-128-SHA"},
- {"RC4-MD5", "TLS-RSA-WIT= H-RC4-128-MD5"},
-= {"RC4-SHA", "TLS-RSA-WITH-RC4-128-SHA"},
= - {"SEED-SHA", "= ;TLS-RSA-WITH-SEED-CBC-SHA"},
- {"SRP-DSS-3DES-EDE-CBC-SHA", "TLS-SRP-SHA-D= SS-WITH-3DES-EDE-CBC-SHA"},
- {"SRP-DSS-AES-128-CBC-SHA", "TLS-SRP-SHA-DSS-= WITH-AES-128-CBC-SHA"},
- {"SRP-DSS-AES-256-CBC-SHA", "TLS-SRP-SHA-DSS-WITH= -AES-256-CBC-SHA"},
= - {"SRP-RSA-AES-128-CBC-SHA", "TLS-SRP-SHA-RSA-WITH-AES-1= 28-CBC-SHA"},
- = {"SRP-RSA-AES-256-CBC-SHA", "TLS-SRP-SHA-RSA-WITH-AES-256-C= BC-SHA"},
+ {= "ADH-SEED-SHA", "TLS-DH-anon-WITH-SEED-CBC-SHA" },
+ { "AES128-GCM-= SHA256", "TLS-RSA-WITH-AES-128-GCM-SHA256" },
+ { "AES128-SHA256", &= quot;TLS-RSA-WITH-AES-128-CBC-SHA256" },

+ { "AES128-SHA", "TLS-RSA-WITH-= AES-128-CBC-SHA" },
+ { "AES256-GCM-SHA384", "TLS-RSA-WITH-AES-256-GCM-SH= A384" },
+ { = "AES256-SHA256", "TLS-RSA-WITH-AES-256-CBC-SHA256" },
+ { "AES256-SH= A", "TLS-RSA-WITH-AES-256-CBC-SHA" },
+ { "CAMELLIA128-SHA256", &qu= ot;TLS-RSA-WITH-CAMELLIA-128-CBC-SHA256" },
+ { "CAMELLIA128-SHA", "TLS-R= SA-WITH-CAMELLIA-128-CBC-SHA" },
+ { "CAMELLIA256-SHA256", "TLS-RSA-WITH-= CAMELLIA-256-CBC-SHA256" },
+ { "CAMELLIA256-SHA", "TLS-RSA-WITH-CAMELLIA= -256-CBC-SHA" },
+ { "DES-CBC3-SHA", "TLS-RSA-WITH-3DES-EDE-CBC-SHA"= },
+ { "DES-= CBC-SHA", "TLS-RSA-WITH-DES-CBC-SHA" },
+ { "DH-DSS-SEED-SHA", "= ;TLS-DH-DSS-WITH-SEED-CBC-SHA" },
+ { "DHE-DSS-AES128-GCM-SHA256", "TLS-D= HE-DSS-WITH-AES-128-GCM-SHA256" },
+ { "DHE-DSS-AES128-SHA256", "TLS-DHE-= DSS-WITH-AES-128-CBC-SHA256" },
+ { "DHE-DSS-AES128-SHA", "TLS-DHE-DSS-WI= TH-AES-128-CBC-SHA" },
+ { "DHE-DSS-AES256-GCM-SHA384", "TLS-DHE-DSS-WITH= -AES-256-GCM-SHA384" },
+ { "DHE-DSS-AES256-SHA256", "TLS-DHE-DSS-WITH-AE= S-256-CBC-SHA256" },
+ { "DHE-DSS-AES256-SHA", "TLS-DHE-DSS-WITH-AES-256-= CBC-SHA" },
+ = { "DHE-DSS-CAMELLIA128-SHA256", "TLS-DHE-DSS-WITH-CAMELLIA-= 128-CBC-SHA256" },
+ { "DHE-DSS-CAMELLIA128-SHA", "TLS-DHE-DSS-WITH-CAMEL= LIA-128-CBC-SHA" },
+ { "DHE-DSS-CAMELLIA256-SHA256", "TLS-DHE-DSS-WITH-C= AMELLIA-256-CBC-SHA256" },
+ { "DHE-DSS-CAMELLIA256-SHA", "TLS-DHE-DSS-WI= TH-CAMELLIA-256-CBC-SHA" },
+ { "DHE-DSS-SEED-SHA", "TLS-DHE-DSS-WITH-SEE= D-CBC-SHA" },
+ = { "DHE-RSA-AES128-GCM-SHA256", "TLS-DHE-RSA-WITH-AES-128-= GCM-SHA256" },
+= { "DHE-RSA-AES128-SHA256", "TLS-DHE-RSA-WITH-AES-128-CBC= -SHA256" },
+ = { "DHE-RSA-AES128-SHA", "TLS-DHE-RSA-WITH-AES-128-CBC-SHA&q= uot; },
+ { "= DHE-RSA-AES256-GCM-SHA384", "TLS-DHE-RSA-WITH-AES-256-GCM-SHA384&= quot; },
+ { "= ;DHE-RSA-AES256-SHA256", "TLS-DHE-RSA-WITH-AES-256-CBC-SHA256&quo= t; },
+ { "DH= E-RSA-AES256-SHA", "TLS-DHE-RSA-WITH-AES-256-CBC-SHA" },
+ { "DHE-RSA-CAM= ELLIA128-SHA256", "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA256"= },
+ { "DHE-= RSA-CAMELLIA128-SHA", "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA"= ; },
+ { "DHE= -RSA-CAMELLIA256-SHA256", "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA2= 56" },
+ { &q= uot;DHE-RSA-CAMELLIA256-SHA", "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-= SHA" },
+ { &= quot;DHE-RSA-CHACHA20-POLY1305", "TLS-DHE-RSA-WITH-CHACHA20-POLY1= 305-SHA256" },
+= { "DHE-RSA-SEED-SHA", "TLS-DHE-RSA-WITH-SEED-CBC-SHA&quo= t; },
+ { "DH= -RSA-SEED-SHA", "TLS-DH-RSA-WITH-SEED-CBC-SHA" },
= + { "ECDH-ECDSA-AES128-= GCM-SHA256", "TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256" },
+ { "ECDH-ECDSA-= AES128-SHA256", "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256" },<= /span>
+ { "ECDH-ECD= SA-AES128-SHA", "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA" },
+ { "ECDH-ECDSA-= AES256-GCM-SHA384", "TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA384"= },
+ { "ECDH= -ECDSA-AES256-SHA256", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA256&qu= ot; },
+ { "E= CDH-ECDSA-AES256-SHA384", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384= " },
+ { &quo= t;ECDH-ECDSA-AES256-SHA", "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA&qu= ot; },
+ { "E= CDH-ECDSA-CAMELLIA128-SHA256", "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-= CBC-SHA256" },
+= { "ECDH-ECDSA-CAMELLIA128-SHA", "TLS-ECDH-ECDSA-WITH-CAM= ELLIA-128-CBC-SHA" },
+ { "ECDH-ECDSA-CAMELLIA256-SHA256", "TLS-ECDH-ECDS= A-WITH-CAMELLIA-256-CBC-SHA256" },
+ { "ECDH-ECDSA-CAMELLIA256-SHA", "TLS= -ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA" },
+ { "ECDH-ECDSA-DES-CBC3-SHA", "= ;TLS-ECDH-ECDSA-WITH-3DES-EDE-CBC-SHA" },
+ { "ECDH-ECDSA-DES-CBC-SHA", "= TLS-ECDH-ECDSA-WITH-DES-CBC-SHA" },
+ { "ECDH-ECDSA-RC4-SHA", "TLS-ECDH-E= CDSA-WITH-RC4-128-SHA" },
+ { "ECDHE-ECDSA-AES128-GCM-SHA256", "TLS-ECDHE= -ECDSA-WITH-AES-128-GCM-SHA256" },
+ { "ECDHE-ECDSA-AES128-SHA256", "TLS-= ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" },
+ { "ECDHE-ECDSA-AES128-SHA384", "= ;TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA384" },
+ { "ECDHE-ECDSA-AES128-SHA", &qu= ot;TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA" },
+ { "ECDHE-ECDSA-AES256-GCM-SHA384"= ;, "TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384" },
+ { "ECDHE-ECDSA-AES256-SHA256= ", "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA256" },
+ { "ECDHE-ECDSA-AES256-S= HA384", "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384" },
<= br>+ { "ECDHE-ECDSA-AES= 256-SHA", "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA" },+ { "ECDHE-ECDSA-CAME= LLIA128-SHA256", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CBC-SHA256&qu= ot; },
+ { "E= CDHE-ECDSA-CAMELLIA128-SHA", "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-C= BC-SHA" },
+ = { "ECDHE-ECDSA-CAMELLIA256-SHA256", "TLS-ECDHE-ECDSA-WITH-CA= MELLIA-256-CBC-SHA256" },
+ { "ECDHE-ECDSA-CAMELLIA256-SHA", "TLS-ECDHE-E= CDSA-WITH-CAMELLIA-256-CBC-SHA" },
+ { "ECDHE-ECDSA-CHACHA20-POLY1305", "= TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256" },
+ { "ECDHE-ECDSA-DES-CBC3-SHA&quo= t;, "TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA" },
+ { "ECDHE-ECDSA-DES-CBC-SHA&qu= ot;, "TLS-ECDHE-ECDSA-WITH-DES-CBC-SHA" },
+ { "ECDHE-ECDSA-RC4-SHA", &q= uot;TLS-ECDHE-ECDSA-WITH-RC4-128-SHA" },
+ { "ECDHE-RSA-AES128-GCM-SHA256", &q= uot;TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256" },
+ { "ECDHE-RSA-AES128-SHA256", &= quot;TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256" },
+ { "ECDHE-RSA-AES128-SHA384"= , "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA384" },
+ { "ECDHE-RSA-AES128-SHA", = "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA" },
+ { "ECDHE-RSA-AES256-GCM-SHA384"= , "TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384" },
+ { "ECDHE-RSA-AES256-SHA256"= ;, "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA256" },
+ { "ECDHE-RSA-AES256-SHA384&quo= t;, "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384" },
+ { "ECDHE-RSA-AES256-SHA"= , "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA" },
+ { "ECDHE-RSA-CAMELLIA128-SHA256&= quot;, "TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SHA256" },
= + { "ECDHE-RSA-CAMELLIA= 128-SHA", "TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SHA" },
+ { "ECDHE-RSA-CAM= ELLIA256-SHA256", "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SHA256&quo= t; },
+ { "EC= DHE-RSA-CAMELLIA256-SHA", "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SH= A" },
+ { &qu= ot;ECDHE-RSA-CHACHA20-POLY1305", "TLS-ECDHE-RSA-WITH-CHACHA20-POL= Y1305-SHA256" },
+ { "ECDHE-RSA-DES-CBC3-SHA", "TLS-ECDHE-RSA-WITH-3DES-E= DE-CBC-SHA" },
+= { "ECDHE-RSA-DES-CBC-SHA", "TLS-ECDHE-RSA-WITH-DES-CBC-S= HA" },
+ { &q= uot;ECDHE-RSA-RC4-SHA", "TLS-ECDHE-RSA-WITH-RC4-128-SHA" },<= /span>
+ { "ECDH-RSA= -AES128-GCM-SHA256", "TLS-ECDH-RSA-WITH-AES-128-GCM-SHA256" = },
+ { "ECDH-= RSA-AES128-SHA256", "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA256" }= ,
+ { "ECDH-R= SA-AES128-SHA384", "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA384" },=
+ { "ECDH-RS= A-AES128-SHA", "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA" },=
+ { "ECDH-RSA-AES25= 6-GCM-SHA384", "TLS-ECDH-RSA-WITH-AES-256-GCM-SHA384" },
+ { "ECDH-RSA-AE= S256-SHA256", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA256" },
+ { "ECDH-RSA-AES= 256-SHA384", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA384" },
+ { "ECDH-RSA-AES2= 56-SHA", "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA" },
+ { "ECDH-RSA-CAMELLIA128= -SHA256", "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA256" },
+ { "ECDH-RSA-CA= MELLIA128-SHA", "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA" },<= /span>
+ { "ECDH-RSA= -CAMELLIA256-SHA256", "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SHA256&= quot; },
+ { "= ;ECDH-RSA-CAMELLIA256-SHA", "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-S= HA" },
+ { &q= uot;ECDH-RSA-DES-CBC3-SHA", "TLS-ECDH-RSA-WITH-3DES-EDE-CBC-SHA&q= uot; },
+ { "= ECDH-RSA-DES-CBC-SHA", "TLS-ECDH-RSA-WITH-DES-CBC-SHA" },

+ { "ECDH-RSA-R= C4-SHA", "TLS-ECDH-RSA-WITH-RC4-128-SHA" },
+ { "EDH-DSS-DES-CBC3-SHA&quo= t;, "TLS-DHE-DSS-WITH-3DES-EDE-CBC-SHA" },
+ { "EDH-DSS-DES-CBC-SHA", &q= uot;TLS-DHE-DSS-WITH-DES-CBC-SHA" },
+ { "EDH-RSA-DES-CBC3-SHA", "TLS-DHE= -RSA-WITH-3DES-EDE-CBC-SHA" },
+ { "EDH-RSA-DES-CBC-SHA", "TLS-DHE-RSA-WI= TH-DES-CBC-SHA" },
+ { "EXP-DES-CBC-SHA", "TLS-RSA-EXPORT-WITH-DES40-CBC-= SHA" },
+ { &= quot;EXP-EDH-DSS-DES-CBC-SHA", "TLS-DH-DSS-EXPORT-WITH-DES40-CBC-= SHA" },
+ { &= quot;EXP-EDH-RSA-DES-CBC-SHA", "TLS-DH-RSA-EXPORT-WITH-DES40-CBC-= SHA" },
+ { &= quot;EXP-RC2-CBC-MD5", "TLS-RSA-EXPORT-WITH-RC2-CBC-40-MD5" = },
+ { "EXP-R= C4-MD5", "TLS-RSA-EXPORT-WITH-RC4-40-MD5" },
+ { "NULL-MD5", "T= LS-RSA-WITH-NULL-MD5" },

+ { "NULL-SHA256", "TLS-RSA-WITH-NULL-SHA256&quo= t; },
+ { "NU= LL-SHA", "TLS-RSA-WITH-NULL-SHA" },
+ { "PSK-3DES-EDE-CBC-SHA", &quo= t;TLS-PSK-WITH-3DES-EDE-CBC-SHA" },
+ { "PSK-AES128-CBC-SHA", "TLS-PSK-WI= TH-AES-128-CBC-SHA" },
+ { "PSK-AES256-CBC-SHA", "TLS-PSK-WITH-AES-256-CB= C-SHA" },
+ {= "PSK-RC4-SHA", "TLS-PSK-WITH-RC4-128-SHA" },+ { "RC4-MD5", &q= uot;TLS-RSA-WITH-RC4-128-MD5" },
+ { "RC4-SHA", "TLS-RSA-WITH-RC4-128-SHA= " },
+ { &quo= t;SEED-SHA", "TLS-RSA-WITH-SEED-CBC-SHA" },
+ { "SRP-DSS-3DES-EDE-CBC-SHA= ", "TLS-SRP-SHA-DSS-WITH-3DES-EDE-CBC-SHA" },
+ { "SRP-DSS-AES-128-CBC-SH= A", "TLS-SRP-SHA-DSS-WITH-AES-128-CBC-SHA" },

+ { "SRP-DSS-AES-256-CBC-SH= A", "TLS-SRP-SHA-DSS-WITH-AES-256-CBC-SHA" },

+ { "SRP-RSA-3DES-EDE-CBC-S= HA", "TLS-SRP-SHA-RSA-WITH-3DES-EDE-CBC-SHA" },

+ { "SRP-RSA-AES-128-CBC-= SHA", "TLS-SRP-SHA-RSA-WITH-AES-128-CBC-SHA" },

+ { "SRP-RSA-AES-256-CBC-= SHA", "TLS-SRP-SHA-RSA-WITH-AES-256-CBC-SHA" },

#ifdef ENABLE_CRYPTO_OPENSSL

/* OpenSSL-specific = group names */
- {&q= uot;DEFAULT", "DEFAULT"},
- {"ALL", "ALL"},
- {"HIGH", "HIGH"= ;}, {"!HIGH", "!HIGH"},
- {"MEDIUM", "MEDIUM"}, {"= !MEDIUM", "!MEDIUM"},
- {"LOW", "LOW"}, {"!LOW", &= quot;!LOW"},
- = {"ECDH", "ECDH"}, {"!ECDH", "!ECDH"= },
- {"ECDSA&qu= ot;, "ECDSA"}, {"!ECDSA", "!ECDSA"},- {"EDH", "ED= H"}, {"!EDH", "!EDH"},
- {"EXP", "EXP"}, {"!E= XP", "!EXP"},
- {"RSA", "RSA"}, {"!RSA", "!RS= A"},
- {"k= RSA", "kRSA"}, {"!kRSA", "!kRSA"},
- {"SRP", "= ;SRP"}, {"!SRP", "!SRP"},
+ { "DEFAULT", "DEFAULT&quo= t; },
+ { "AL= L", "ALL" },
+ { "HIGH", "HIGH" },
+ { "!HIGH", "!HIGH"= ; },
+ { "MED= IUM", "MEDIUM" },
+ { "!MEDIUM", "!MEDIUM" },
+ { "LOW", "LOW= " },

+ { &quo= t;!LOW", "!LOW" },
+ { "ECDH", "ECDH" },
+ { "!ECDH", "!ECDH&= quot; },
+ { "= ;ECDSA", "ECDSA" },
+ { "!ECDSA", "!ECDSA" },
+ { "EDH", "EDH= " },

+ { &quo= t;!EDH", "!EDH" },
+ { "EXP", "EXP" },
+ { "!EXP", "!EXP"= ; },
+ { "RSA= ", "RSA" },
+ { "!RSA", "!RSA" },
+ { "kRSA", "kRSA" },<= /span>
+ { "!kRSA&qu= ot;, "!kRSA" },
+ { "SRP", "SRP" },
+ { "!SRP", "!SRP" },
#endif
- = {NULL, NULL}
+ = { NULL, NULL }
};

const= tls_cipher_name_pair *
diff --git a/src/openvpn/ssl_util.h= b/src/openvpn/ssl_util.h
index e50f899..6f48c23 100644
--- a/src/openvpn/ssl_util.h
+++ b/src/openvpn= /ssl_util.h
@@ -44,8 +44,7 @@
* @return = The content of the variable as NULL terminated string or NULL if the=
* variable cannot be found.
*/
-char *extract_var_peer_info= (const char *peer_info, const char *var,
- struct gc_arena *gc);=
+char *extract_var_peer_inf= o(const char *peer_info, const char *var, struct gc_arena *gc);
<= span>

/**
* Extracts the IV_PROTO varia= ble and returns its value or 0
@@ -75,7 +74,11 @@ * @param cipher_name Can be either OpenSSL or IANA cipher name
* @return tls_cipher_name_pair* if found, NUL= L otherwise
*/
-typedef struct { const char *openssl_name; const char *iana_name= ; } tls_cipher_name_pair;
+typedef struct
= +{
+ const char *o= penssl_name;
+ con= st char *iana_name;
+= } tls_cipher_name_pair;
const tls_cipher_name_pair *tls_ge= t_cipher_name_pair(const char *cipher_name, size_t len);
<= /span>
/**
@@ -89,7 +92,6 @@
* = @param delimiter the delimiter to count, typically ':' * @return occrrences of delimiter + 1
*/

-int
<= span style=3D"color: hsl(0, 100%, 40%);">-get_num_elements(const char *stri= ng, char delimiter);

= +int get_num_elements(const char *string, char delimiter);
=
#endif /* ifndef SSL_UTIL_H_ */
diff --g= it a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c
in= dex 41635c8..645fb86 100644
--- a/src/openvpn/ssl_verify.c<= /span>
+++ b/src/openvpn/ssl_verify.c
@@ -150,11 += 150,12 @@
/* If the username has been overridden, = we accept both the original
* username and the ch= anged username */
if (strcmp(username, multi->l= ocked_username) !=3D 0
= - && (!multi->locked_original_username || strcmp(use= rname, multi->locked_original_username) !=3D 0))
+ && (!multi->locked= _original_username
+ = || strcmp(username, multi->locked_original_username) !=3D= 0))
{
- msg(D_TLS_ERRORS, "TLS Auth Error: username atte= mpted to change from '%s' to '%s' -- tunnel disabled",=
- multi= ->locked_username,
-= username);
+ msg(D_TLS_ERRORS,
+ "TLS Auth Error: username attempted t= o change from '%s' to '%s' -- tunnel disabled",=
+ multi->= locked_username, username);

= /* disable the tunnel */
tls_deauthenticate(mu= lti);
@@ -240,8 +241,8 @@
{
continue;
}
- else if (ch1 = && ch2 && !memcmp(ch1->sha256_hash, ch2->sha256_hash,=
- = sizeof(ch1->sha256_hash)))
+ else if (ch1 && ch2
+ = && !memcmp(ch1->sha256_hash, ch2->sha256_hash, sizeof(ch1->= ;sha256_hash)))
{
= continue;
}
@@ -276,8 +27= 7,7 @@
if (ch)
{<= /span>
ALLOC_OBJ(dest->ch[i], struct cert_hash= );
- mem= cpy(dest->ch[i]->sha256_hash, ch->sha256_hash,
- sizeof(dest->ch= [i]->sha256_hash));
-verify_peer_cert(const struct tls= _options *opt, openvpn_x509_cert_t *peer_cert,
- const char *subject, const char *= common_name)
+verify_= peer_cert(const struct tls_options *opt, openvpn_x509_cert_t *peer_cert, co= nst char *subject,
+ = const char *common_name)
{
/* verify certificate nsCertType */

if (opt->= ns_cert_type !=3D NS_CERT_CHECK_NONE)
{
if (SUCCESS =3D=3D x509_verify_ns_cert_type(peer_cert, opt->n= s_cert_type))

{
- msg(D_HANDSHAKE, "VERIFY OK: nsCertType= =3D%s",
- = print_nsCertType(opt->ns_cert_type));
+ msg(D_HANDSHAKE, "VERIFY OK: n= sCertType=3D%s", print_nsCertType(opt->ns_cert_type));
}

else
{
- msg(D_HANDSHA= KE, "VERIFY nsCertType ERROR: %s, require nsCertType=3D%s",
- subject, pr= int_nsCertType(opt->ns_cert_type));
- return FAILURE; /* Reject connecti= on */
+ ms= g(D_HANDSHAKE, "VERIFY nsCertType ERROR: %s, require nsCertType=3D%s&q= uot;, subject,
+ = print_nsCertType(opt->ns_cert_type));
+ return FAILURE; /* Reject con= nection */
}
}

@@ -350,7 +349,7 @@
else
{
msg(D_HANDSHAKE, "V= ERIFY KU ERROR");
= - return FAILURE; /* Reject connection */
= + return FAILURE; /*= Reject connection */
}
}

@@ -364,28 +363,27 @@
= else
{
msg(D_HANDS= HAKE, "VERIFY EKU ERROR");
- return FAILURE; /* Reject connection= */
+ retu= rn FAILURE; /* Reject connection */
}
}


/* verify X509 name or us= ername against --verify-x509-[user]name */
if (opt->= ;verify_x509_type !=3D VERIFY_X509_NONE)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- if ( (opt->verify_x509= _type =3D=3D VERIFY_X509_SUBJECT_DN

- && strcmp(opt->verify_x509_name, sub= ject) =3D=3D 0)
- = || (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_RDN- && st= rcmp(opt->verify_x509_name, common_name) =3D=3D 0)
- || (opt->verify_x509_type = =3D=3D VERIFY_X509_SUBJECT_RDN_PREFIX
- && strncmp(opt->verify_x509_nam= e, common_name,
- = strlen(opt->verify_x509_name)) =3D=3D 0) )<= br>+ if ((opt->verify= _x509_type =3D=3D VERIFY_X509_SUBJECT_DN
+ && strcmp(opt->verify_x509_nam= e, subject) =3D=3D 0)
+ || (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_RDN
+ &= & strcmp(opt->verify_x509_name, common_name) =3D=3D 0)
+ || (opt->verify_x5= 09_type =3D=3D VERIFY_X509_SUBJECT_RDN_PREFIX

+ && strncmp(opt->verify= _x509_name, common_name, strlen(opt->verify_x509_name)) =3D=3D 0))
{
msg(D_HANDSHAKE, "V= ERIFY X509NAME OK: %s", subject);
} else
{
- msg(D_HANDSHAKE, "VERIFY X509NAM= E ERROR: %s, must be %s",
- subject, opt->verify_x509_name);
- return FAILURE; = /* Reject connection */

+ msg(D_HANDSHAKE, "VERIFY X509NAME ERROR: %s, must = be %s", subject,
+ opt->verify_x509_name);
+ return FAILURE; /* Reject connection *= /
}
}

@@ -398,8 +396,7 @@
*/
static= void
verify_cert_set_env(struct env_set *es, openvpn_x509= _cert_t *peer_cert, int cert_depth,
- const char *subject,
- const struct x509_trac= k *x509_track)
+ = const char *subject, const struct x509_track *x509_track)
{
char envname[64];
= char *serial =3D NULL;
@@ -425,13 +422,10 @@
struct buffer sha256 =3D x509_get_sha256_fingerprint(peer_cert= , &gc);


snprintf(envname, si= zeof(envname), "tls_digest_%d", cert_depth);
- setenv_str(es, envname,
= - format_hex_ex= (BPTR(&sha1), BLEN(&sha1), 0, 1, ":", &gc));+ setenv_str(es, envna= me, format_hex_ex(BPTR(&sha1), BLEN(&sha1), 0, 1, ":", &a= mp;gc));

- snprintf(envname, sizeof(envname), "tls_digest_sha256_%d&= quot;,
- = cert_depth);
- = setenv_str(es, envname,
+ snprintf(envname, sizeof(envname), "tls_digest_sha2= 56_%d", cert_depth);
+ setenv_str(es, envname, format_hex_ex(BPTR(&sha256), BLEN= (&sha256), 0, 1, ":", &gc));
}

/* export serial number as environmental = variable */
@@ -475,8 +469,8 @@
* call --= tls-verify plug-in(s)
*/
static result_t=
-verify_cert_call_plug= in(const struct plugin_list *plugins, struct env_set *es,
- int cert_depth,= openvpn_x509_cert_t *cert, char *subject)
+verify_cert_call_plugin(const struct plugin_list *pl= ugins, struct env_set *es, int cert_depth,
+ openvpn_x509_cert_t *cert, c= har *subject)
{
if (plugin_defined(pl= ugins, OPENVPN_PLUGIN_TLS_VERIFY))
{
@= @ -485,20 +479,19 @@

argv_printf= (&argv, "%d %s", cert_depth, subject);

- ret =3D plugin_cal= l_ssl(plugins, OPENVPN_PLUGIN_TLS_VERIFY, &argv, NULL, es, cert_depth, = cert);
+ ret = =3D
+ plug= in_call_ssl(plugins, OPENVPN_PLUGIN_TLS_VERIFY, &argv, NULL, es, cert_d= epth, cert);

argv_free(&argv= );

if (ret =3D=3D OPENVPN_PLUGIN= _FUNC_SUCCESS)
{
- msg(D_HANDSHAKE, "VERIFY PLUGIN OK: de= pth=3D%d, %s",
- = cert_depth, subject);
+ msg(D_HANDSHAKE, "VERIFY PLUGIN OK: depth= =3D%d, %s", cert_depth, subject);
} else
{
- msg(D_HANDSHAKE, "VERIFY PLUGIN = ERROR: depth=3D%d, %s",
- cert_depth, subject);
- return FAILURE; /* Reject co= nnection */
+ = msg(D_HANDSHAKE, "VERIFY PLUGIN ERROR: depth=3D%d, %s", cert_= depth, subject);
+ = return FAILURE; /* Reject connection */
}=
}
return SUCCESS;
@@ -508,8 +501,8 @@

* run --tls-verify script */
static result_t
-verify_cert_call_command(const char *verify_command,= struct env_set *es,
- = int cert_depth, char *subject)
+verify_cert_call_command(const char *ver= ify_command, struct env_set *es, int cert_depth,
+ char *subject)=
{
int ret;
struct gc_a= rena gc =3D gc_new();
@@ -528,22 +521,20 @@

if (ret)
{
- msg(D_HANDSHAKE, "VERIFY SCR= IPT OK: depth=3D%d, %s",
- cert_depth, subject);
+ msg(D_HANDSHAKE, "VERIFY SCRIPT OK: dept= h=3D%d, %s", cert_depth, subject);
return SUC= CESS;
}

- msg(D_HANDSHAKE, "VERIFY SCRIPT ERROR: de= pth=3D%d, %s",
- = cert_depth, subject);
- return FAILURE; /* Reject connection */
+ msg(D_HANDSHAKE, "VERIFY= SCRIPT ERROR: depth=3D%d, %s", cert_depth, subject);

+ return FAILURE; /* Reject connec= tion */
}

/*
= * check peer cert against CRL directory
*/=
static result_t
-verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_t *cert,
- co= nst char *subject, int cert_depth)
+verify_check_crl_dir(const char *crl_dir, openvpn_x509_cert_= t *cert, const char *subject,
+ int cert_depth)
{ result_t ret =3D FAILURE;
char fn[256];
@@ -553,8 +544,8 @@
char *serial =3D bac= kend_x509_get_serial(cert, &gc);
if (!serial)
{
- = msg(D_HANDSHAKE, "VERIFY CRL: depth=3D%d, %s, serial number is no= t available",
- = cert_depth, subject);
+ msg(D_HANDSHAKE, "VERIFY CRL: depth=3D%d, %s, seria= l number is not available", cert_depth,
+ subject);
got= o cleanup;
}

@@ -566= ,8 +557,8 @@
fd =3D platform_open(fn, O_RDONLY, 0);
if (fd >=3D 0)
{
- msg(D_HANDSHAKE, "VERIFY= CRL: depth=3D%d, %s, serial=3D%s is revoked",

- cert_depth, subject, serial);
+ msg(D_HANDSHA= KE, "VERIFY CRL: depth=3D%d, %s, serial=3D%s is revoked", cert_de= pth, subject,
+ = serial);
goto cleanup;
= }

@@ -601,8 +592,10 @@
= char *subject =3D x509_get_subject(cert, &gc);
= if (!subject)
{
- msg(D_TLS_ERRORS, "VERIFY ERROR: depth=3D%d, co= uld not extract X509 "
- "subject string from certificate", cert_depth);=
+ msg(D_TLS_E= RRORS,
+ &= quot;VERIFY ERROR: depth=3D%d, could not extract X509 "
+ "subject string f= rom certificate",

- char username[TLS_USERNAME_LEN+1] =3D {0}; /* null-terminated *= /
+ char usern= ame[TLS_USERNAME_LEN + 1] =3D { 0 }; /* null-terminated */
=
- if (SUCCESS = !=3D backend_x509_get_username(username, sizeof(username),
- = opt->x509_username_field[i], cert))
+ if (SUCCESS
+ !=3D backend_x509_get_username(us= ername, sizeof(username), opt->x509_username_field[i],
+ = cert))
{
if (!cer= t_depth)
{
- msg(D_TLS_ERRORS, "VERIFY ERROR: cou= ld not extract %s from X509 "
+ msg(D_TLS_ERRORS,
+ "VERIFY ERROR: could = not extract %s from X509 "
"= subject string ('%s') -- note that the field length is "
"limited to %d characters",
- opt->= ;x509_username_field[i],
- TLS_USERNAME_LEN);
+ opt->x509_username_fiel= d[i], subject, TLS_USERNAME_LEN);
goto cle= anup;
}
break;
@@ -635,11 +628,11 @@
{
if (!cert_depth)

{
= - msg(D_TLS_ERRORS= , "VERIFY ERROR: could not append %s from X509 "
+ msg(D_TLS_ERRORS,
+ &q= uot;VERIFY ERROR: could not append %s from X509 "
= "certificate -- note that the username length is &quo= t;
"limited to %d characters"= ;,
- = opt->x509_username_field[i],
- buf.capacity - 1);
+ opt->x509_username_fie= ld[i], buf.capacity - 1);
goto cleanup;
}
break;
= @@ -649,8 +642,10 @@
char *common_name =3D BSTR(= &buf);
if (!common_name)
{
- msg(D_TLS_ERRORS= , "VERIFY ERROR: depth=3D%d, could not extract X509 "
<= span style=3D"color: hsl(0, 100%, 40%);">- "username string= from certificate", cert_depth);

+ msg(D_TLS_ERRORS,
+ "VERIFY ERROR: depth=3D%d, could n= ot extract X509 "
+ cert_depth); goto cleanup;
}

@@ -660,13 +655,15 @@
/* warn if cert chai= n is too deep */
if (cert_depth >=3D MAX_CERT_DEPTH= )
{
- goto cleanup= ; /* Reject connection */
+ msg(D_TLS_ERRORS,
+ "TLS Error: Convoluted certi= ficate chain detected with depth [%d] greater than %d",
+ cert_depth, MAX_CERT_D= EPTH);

+ goto = cleanup; /* Reject connection */
}

if (cert_depth =3D=3D opt->verify_hash_depth &&a= mp; opt->verify_hash)
{
- struct buffer cert_fp =3D {0};
= + struct buffer cert_fp = =3D { 0 };

switch (opt->verif= y_hash_algo)
{
@@ -684,8 +681,10 @= @
* value in an enumerated type. So if t= his unlikely scenario
* happens, consider= this a failure
*/
- msg(M_WARN, "Unexpecte= d invalid algorithm used with "
- "--verify-hash (%i)", opt->= verify_hash_algo);
+ = msg(M_WARN,
+ "Unexpected invalid algorithm used with &qu= ot;
+ = "--verify-hash (%i)",
+ opt->verify_hash_algo);
ret =3D FAILURE;

goto= cleanup;
}
@@ -694,8 +693,7 @@

while (current_hash)
{

- = if (memcmp_constant_time(BPTR(&cert_fp), current_hash->hash,
- = BLEN(&cert_fp)) =3D=3D 0)
+ if (memcmp_constant_time(BPTR(&cert_f= p), current_hash->hash, BLEN(&cert_fp)) =3D=3D 0)
= {
break;
= }
@@ -704,11 +702,12 @@

= if (!current_hash)
{
- const char *hex_fp =3D f= ormat_hex_ex(BPTR(&cert_fp), BLEN(&cert_fp),

- = 0, 1, ":", &gc);
- msg(D_TLS_ERRORS, "TLS Error: --tls-verify/--= peer-fingerprint "
+ const char *hex_fp =3D format_hex_ex(BPTR(&cert_fp), BL= EN(&cert_fp), 0, 1, ":", &gc);
+ msg(D_TLS_ERRORS,
+ "TLS Error: --t= ls-verify/--peer-fingerprint "
"= certificate hash verification failed. (got certificate "
- "fingerprint: = %s)", hex_fp);

+= "fingerprint: %s)",
+ hex_fp);
= goto cleanup;
}
}=
@@ -723,14 +722,14 @@

if (= opt->export_peer_cert_dir)
{
- pem_export_fname =3D platform_creat= e_temp_file(opt->export_peer_cert_dir,
- &q= uot;pef", &gc);
+ pem_export_fname =3D platform_create_temp_file(opt->export_= peer_cert_dir, "pef", &gc);

- if (!pem_export_fname
<= br>- || !verify_cert_c= ert_export_env(opt->es, cert, pem_export_fname))
+ if (!pem_export_fname || !verify_= cert_cert_export_env(opt->es, cert, pem_export_fname))
= {
- = msg(D_TLS_ERRORS, "TLS Error: Failed to export certificate for "<= /span>
- "= --tls-export-cert in %s", opt->export_peer_cert_dir);
+ msg(D_TLS_ERRORS,
+ "T= LS Error: Failed to export certificate for "
+ "--tls-export-cert in %s= ",
+ = opt->export_peer_cert_dir);
goto cleanu= p;
}
}
@@ -75= 3,8 +752,8 @@
}

= /* run --tls-verify script */
- if (opt->verify_command && SUCCESS !=3D verify_cert= _call_command(opt->verify_command,
- = opt->es, cert_depth, subject))
+ if (opt->verify_command
+ && SUCCESS !=3D verify_ce= rt_call_command(opt->verify_command, opt->es, cert_depth, subject))
{
goto cleanup;
}

@@ -787,7 +786,7 @@
verify_ce= rt_cert_delete_env(opt->es, pem_export_fname);
if (= ret !=3D SUCCESS)
{
- tls_clear_error(); /* always? */
+ tls_clear_error(); = /* always? */

session->verified =3D false; /* d= ouble sure? */
}

@@ = -797,9 +796,9 @@
}

/* *= **************************************************************************<= /span>
-* Functions for the ma= nagement of deferred authentication when using
-* user/password authentication.
-****************************************= *********************************** */
+ * Functions for the management of deferred authenticati= on when using
+ * use= r/password authentication.
+ *******************************************************************= ******** */

void
auth_s= et_client_reason(struct tls_multi *multi, const char *client_reason)=
@@ -885,15 +884,13 @@
* @returns false The fi= le had an invlaid format or another error occured
*/
static bool
- = struct tls_multi *multi,
+key_state_check_auth_pending_file(struct auth_deferred_status = *ads, struct tls_multi *multi,
= struct tls_session *session)
{
= bool ret =3D true;
if (ads->auth_pending_file)
{
- = struct buffer_list *lines =3D buffer_list_file(ads->auth_pending_f= ile,
- = 1024);
+ struct buffer_list *lines =3D buffer_list_fi= le(ads->auth_pending_file, 1024);
if (lines &am= p;& lines->head)
{
= /* Must have at least three lines. further lines are ignored for
@@ -901,7 +898,7 @@
if (!lines->= head || !lines->head->next || !lines->head->next->next)
{
msg(M_WARN, &qu= ot;auth pending control file is not at least "
- "three lines long.= ");
+ = "three lines long.");
= buffer_list_free(lines);
return fal= se;
}
@@ -928,10 +925,13 @@
char buf[128];
= snprintf(buf, sizeof(buf),
&q= uot;Authentication failed, required pending auth "
- "method = 9;%s' not supported", pending_method);
+ "method '%s&#= 39; not supported",
+ pending_method);
= auth_set_client_reason(multi, buf);
- msg(M_INFO, "Client does not suppor= ted auth pending method "
- "'%s'", pending_method);
+ msg(M_I= NFO,
+ = "Client does not supported auth pending method "
<= span style=3D"color: hsl(120, 100%, 40%);">+ "'= %s'",

+ = pending_method);
ret =3D fa= lse;
}
else
@@ -976,8 +976,7 @@
* @return true if file cr= eation was successful
*/
static bool
-key_state_gen_auth_contro= l_files(struct auth_deferred_status *ads,
- const struct tls_optio= ns *opt)
+key_state_g= en_auth_control_files(struct auth_deferred_status *ads, const struct tls_op= tions *opt)
{
struct gc_arena gc =3D = gc_new();

@@ -1018,7 +1017,6 @@ {
ret =3D BSTR(&reason);
}
-
}
return ret;
}

@@ -1089,8 +1087,7 @@
#endif ASSERT(auth_plugin < 4 && auth_script < 4 &a= mp;& auth_man < 4);

- if (auth_plugin =3D=3D ACF_FAILED || auth_sc= ript =3D=3D ACF_FAILED
= - || auth_man =3D=3D ACF_FAILED)
+ if (auth_plugin =3D=3D ACF_FAILED || auth_s= cript =3D=3D ACF_FAILED || auth_man =3D=3D ACF_FAILED)
= {
ks->authenticated =3D KS_AUTH_FALSE;=
return;
@@ -1123,7 +1120,7 @@=
* with no caching (0) here as well to have the same supe= r quick initial
* reaction.
*/-static time_t cache_intervals[= ] =3D {0, 0, 0, 0, 0, 1, 1, 2, 2, 4, 8};
+static time_t cache_intervals[] =3D { 0, 0, 0, 0, 0, 1= , 1, 2, 2, 4, 8 };

/**
= * uses cache_intervals times to determine if we should update the@@ -1190,8 +1187,10 @@
{
= struct gc_arena gc =3D gc_new();
const struct = key_state *ks =3D get_primary_key(multi);
- const char *plugin_message =3D key_state_check_= auth_failed_message_file(&ks->plugin_auth, &gc);
- const char *script_message = =3D key_state_check_auth_failed_message_file(&ks->script_auth, &= gc);

+ const c= har *plugin_message =3D
+ key_state_check_auth_failed_message_file(&ks->plugin= _auth, &gc);
+ = const char *script_message =3D
+ key_state_check_auth_failed_message_file(&k= s->script_auth, &gc);

if = (plugin_message)
{
@@ -1235,7 +123= 4,8 @@
* to indicate auth failure/success.
*/

bool
-tls_authenticate_key(struct tls_multi *multi, const unsigned int mda= _key_id, const bool auth, const char *client_reason)
+tls_authenticate_key(struct tls_multi *mu= lti, const unsigned int mda_key_id, const bool auth,
+ const char *client_r= eason)
{
bool ret =3D false; if (multi)
@@ -1271,8 +1271,7 @@
* Check if the script/plugin left a message in the auth failed message=

* file and relay it to the user */
stat= ic void
-check_for_clie= nt_reason(struct tls_multi *multi,
- struct auth_deferred_status *status)
+check_for_client_reas= on(struct tls_multi *multi, struct auth_deferred_status *status)
= {
struct gc_arena gc =3D gc_new();
const char *msg =3D key_state_check_auth_failed_message_file(statu= s, &gc);

@@ -1293,7 +1292,7 @@
str= uct argv argv =3D argv_new();
const char *tmp_file =3D= "";
int retval =3D OPENVPN_PLUGIN_FUNC_ERRO= R;
- struct key_stat= e *ks =3D &session->key[KS_PRIMARY]; /* primary key */+ struct key_state *ks =3D= &session->key[KS_PRIMARY]; /* primary key */

/* Set environmental variables prior to calling script */<= /span>
setenv_str(session->opt->es, "script_type&q= uot;, "user-pass-verify");
@@ -1305,8 +1304,7 @@<= /span>
{
struct status_output *so;

- = tmp_file =3D platform_create_temp_file(session->opt->tmp_dir, &quo= t;up",
- = &gc);
+ tmp_file =3D platform_create_temp_file(ses= sion->opt->tmp_dir, "up", &gc);
= if (tmp_file)
{
so = =3D status_open(tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE);
@@ -1331,15 +1329,17 @@

/* pre-create files for defe= rred auth control */
if (!key_state_gen_auth_control_f= iles(&ks->script_auth, session->opt))
{
- msg(D_TLS_ERRORS, = "TLS Auth Error (%s): "
- "could not create deferred auth control file&q= uot;, __func__);
+ = msg(D_TLS_ERRORS,
+ "could not create deferred au= th control file",
- int script_ret =3D openvpn_run_scrip= t(&argv, session->opt->es, S_EXITCODE,
- "--= auth-user-pass-verify");
+ int script_ret =3D
+ openvpn_run_script(&argv, session->opt->es, = S_EXITCODE, "--auth-user-pass-verify");
swit= ch (script_ret)
{
case 0:
@@ -1359,13 +1359,11 @@
{
/* Check if we the plugin has written the pending auth control
* file and send the pending auth to the client */
- if (!key_state_= check_auth_pending_file(&ks->script_auth,
- m= ulti, session))
+ = if (!key_state_check_auth_pending_file(&ks->script_auth, multi, = session))
{
retval = =3D OPENVPN_PLUGIN_FUNC_ERROR;
key_state_rm_au= th_control_files(&ks->script_auth);
}

-
}
else
{
@@ -1396,8 +1= 394,8 @@
struct tls_session *session =3D &multi-&g= t;session[TM_ACTIVE];
setenv_str(session->opt->e= s, "crresponse", cr_response);

- plugin_call(session->opt->pl= ugins, OPENVPN_PLUGIN_CLIENT_CRRESPONSE, NULL,
- NULL, session->opt->es);
+ plugin_call(session= ->opt->plugins, OPENVPN_PLUGIN_CLIENT_CRRESPONSE, NULL, NULL,<= br>+ session->= ;opt->es);

setenv_del(session->= ;opt->es, "crresponse");
}
@@= -1406,7 +1404,6 @@
void
verify_crrespons= e_script(struct tls_multi *multi, const char *cr_response)
= {
-
= struct tls_session *session =3D &multi->session[TM_ACTIVE];

if (!session->opt->client_crrespons= e_script)
@@ -1426,8 +1423,7 @@
if (tmp_file)
{
- struct status_output *so =3D status_open= (tmp_file, 0, -1, NULL,
- STATUS_OUTPUT_WRITE);
+ struct status_ou= tput *so =3D status_open(tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE);
status_printf(so, "%s", cr_response);<= br> if (!status_close(so))
{<= br>@@ -1464,7 +1460,7 @@
con= st struct user_pass *up)
{
int retval= =3D OPENVPN_PLUGIN_FUNC_ERROR;
- struct key_state *ks =3D &session->key[KS_PRIMARY]; = /* primary key */
= + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primary = key */

/* set password in private en= v space */
setenv_str(session->opt->es, "pa= ssword", up->password);
@@ -1472,13 +1468,16 @@
/* generate filename for deferred auth control file */
if (!key_state_gen_auth_control_files(&ks->plugin= _auth, session->opt))
{
- msg(D_TLS_ERRORS, "TLS Auth Error (%= s): "
- = "could not create deferred auth control file", __func__);=
+ msg(D_TLS_ERRORS,<= /span>
+ "TL= S Auth Error (%s): "
+ "could not create deferred auth control file",<= /span>
+ __func__= );
return retval;
}
/* call command */
- retval =3D plugin_call(session->opt->p= lugins, OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY, NULL, NULL, session->opt-&= gt;es);
+ retval = =3D plugin_call(session->opt->plugins, OPENVPN_PLUGIN_AUTH_USER_PASS_= VERIFY, NULL, NULL,
+= session->opt->es);
<= br> if (retval =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED)
{

@@ -1517,18 +1516,18 @@
#define = KMDA_DEF 3

static int
-verify_user_pass_management(struct t= ls_session *session,

- = const struct user_pass *up)
+verify_user_pass_management(struct tls_s= ession *session, const struct user_pass *up)
{
<= span> int retval =3D KMDA_ERROR;

- struct key_state *ks =3D &session->key[KS_PRIMARY= ]; /* primary key */
+ struct key_state *ks =3D &session->key[KS_PRIMARY]; /* pri= mary key */

/* set username/password= in private env space */
setenv_str(session->opt-&g= t;es, "password", up->password);

<= span> if (management)

{
- management_notify_client_needing_auth(ma= nagement, ks->mda_key_id, session->opt->mda_context, session->o= pt->es);
+ = management_notify_client_needing_auth(management, ks->mda_key_id, sessio= n->opt->mda_context,
+ session->opt->es= );
}

setenv_del= (session->opt->es, "password");
@@ -1540,8 = +1539,7 @@
#endif /* ifdef ENABLE_MANAGEMENT */
=
static bool
-set_verify_user_pass_env(struct user_pass *up, struct tls_mu= lti *multi,
- = struct tls_session *session)
+set_verify_user_pass_env(struct user_pass *up, stru= ct tls_multi *multi, struct tls_session *session)
{=
/* Is username defined? */
if ((session= ->opt->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL) || strlen(up->= ;username))
@@ -1577,7 +1575,8 @@
= msg(D_TLS_ERRORS,
"TLS Auth Error: --user= name-as-common name specified and "
"= ;username is longer than the maximum permitted Common Name "- "length of %d = characters", TLS_USERNAME_LEN);
+ "length of %d characters",+ TLS_USERNAME_LEN)= ;
return false;
}
<= span> else

@@ -1593,10 +1592,9 @@
* r= esult of the username/password verification
*/
= void
-verify_use= r_pass(struct user_pass *up, struct tls_multi *multi,
- struct tls_session *sessio= n)
+verify_user_pass(= struct user_pass *up, struct tls_multi *multi, struct tls_session *session)=
{
- = struct key_state *ks =3D &session->key[KS_PRIMARY]; /* primar= y key */
+ struct = key_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */

ASSERT(up && !up->protected);<= /span>

@@ -1624,9 +1622,10 @@
= if (multi->locked_original_username
&&am= p; strncmp(up->username, multi->locked_original_username, sizeof(up-&= gt;username)) =3D=3D 0)
{
- msg(D_MULTI_LOW, "TLS: Replacing clie= nt provided username '%s' with "
- "username from override-user '= %s'", up->username,
- multi->locked_username);
+ msg(D_MULTI_LOW,
+ "TLS: Replacing client = provided username '%s' with "
+ "username from override-user '%= s'",
+ = up->username, multi->locked_username);
= strncpy(up->username, multi->locked_username, sizeof(up->username= ));
}

@@ -1662,7 +16= 61,8 @@
* We do not want the EXPIRED or EMPTY= USER flags here so check
* for equality with= AUTH_TOKEN_HMAC_OK
*/
- msg(M_WARN, "TLS: Username= /auth-token authentication "
+ msg(M_WARN,
+ "TLS: Username/auth-token authentica= tion "
"succeeded for username &= #39;%s'",
up->username);
skip_auth =3D true;
@@ -1671,8 +167= 1,10 @@
{
wipe_auth_t= oken(multi);
ks->authenticated =3D KS_AUTH_= FALSE;
- msg= (M_WARN, "TLS: Username/auth-token authentication "
- "failed for us= ername '%s'", up->username);

+ msg(M_WARN,
+ "TLS: Username/auth-token= authentication "
+ up->usernam= e);
return;
}<= br> }
@@ -1717,14 +1719,14 @@
= bool plugin_ok =3D plugin_status =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS
|| plugin_status =3D=3D OPENVPN_PLUGIN_FUN= C_DEFERRED;

- bool script_ok =3D script_status =3D=3D OPENVPN_PLUGIN_FUNC_SU= CCESS
- = || script_status =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED;
+ bool script_ok =3D script_statu= s =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS

+ || script_status =3D=3D OPENVPN_PLUGI= N_FUNC_DEFERRED;

if (script_ok &= & plugin_ok && tls_lock_username(multi, up->username)=
#ifdef ENABLE_MANAGEMENT
&& man= _def_auth !=3D KMDA_ERROR
#endif
- )
+ )
{
ks-= >authenticated =3D KS_AUTH_TRUE;
if (plugin_sta= tus =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED
@@ -1758,8 +1760,7 = @@
* to store the auth-token in multi->aut= h_token, so
* the initial timestamp and sessi= on id can be extracted from it
*/
<= span style=3D"color: hsl(0, 100%, 40%);">- if (!multi->auth_t= oken

- &= amp;& (ks->auth_token_state_flags & AUTH_TOKEN_HMAC_OK)+ if (!multi->a= uth_token && (ks->auth_token_state_flags & AUTH_TOKEN_HMAC_O= K)
&& !(ks->auth_token_state_fl= ags & AUTH_TOKEN_EXPIRED))
{
multi->auth_token =3D strdup(up->password);
@@ -1773,8 +1774,7 @@
}

msg(D_HANDSHAKE, "TLS: Username/Password a= uthentication %s for username '%s' %s",
- (ks->authenticated =3D=3D KS= _AUTH_DEFERRED) ? "deferred" : "succeeded",
<= span style=3D"color: hsl(0, 100%, 40%);">- up->username,
+ (ks->auth= enticated =3D=3D KS_AUTH_DEFERRED) ? "deferred" : "succeeded= ", up->username,
(session->opt->= ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : &quo= t;");
}
else
@@ -1787,7 +1787,7 @@

void
verify_final_= auth_checks(struct tls_multi *multi, struct tls_session *session) {
- struct k= ey_state *ks =3D &session->key[KS_PRIMARY]; /* primary key */
+ struct key_state = *ks =3D &session->key[KS_PRIMARY]; /* primary key */

/* While it shouldn't really happen, don't = allow the common name to be NULL */
if (!session->c= ommon_name)
@@ -1801,9 +1801,9 @@
= const char *cn =3D session->common_name;
if (cn= && strcmp(cn, multi->locked_cn))
{
- msg(D_TLS_ERR= ORS, "TLS Auth Error: TLS object CN attempted to change from '%s&#= 39; to '%s' -- tunnel disabled",
- multi->locked_cn,
- cn);

+ msg(D_TLS_ERRORS,
+ "TLS= Auth Error: TLS object CN attempted to change from '%s' to '%s= ' -- tunnel disabled",
+ multi->locked_cn, cn);

/* change the common name back to its original va= lue and disable the tunnel */
set_common_name(= session, multi->locked_cn);
@@ -1817,7 +1817,8 @@=
const struct cert_hash_set *chs =3D session->cert_has= h_set;
if (chs && !cert_hash_compare(chs, = multi->locked_cert_hash_set))
{
- msg(D_TLS_ERRORS, "T= LS Auth Error: TLS object CN=3D%s client-provided SSL certs unexpectedly ch= anged during mid-session reauth",

+ msg(D_TLS_ERRORS,
+ "TLS Auth Error: TLS obje= ct CN=3D%s client-provided SSL certs unexpectedly changed during mid-sessio= n reauth",
session->common_name);<= /span>

/* disable the tunnel */
@@ -1831,15 +1832,14 @@
struct gc_are= na gc =3D gc_new();

const char *= cn =3D session->common_name;
- const char *path =3D platform_gen_path(session->opt-&g= t;client_config_dir_exclusive,
- cn, &gc);<= br>+ const char *path = =3D platform_gen_path(session->opt->client_config_dir_exclusive, cn, = &gc);
if (!cn || !strcmp(cn, CCD_DEFAULT) || != platform_test_file(path))
{
= ks->authenticated =3D KS_AUTH_FALSE;
= wipe_auth_token(multi);
- ses= sion->common_name,
-= path ? path : "UNDEF");
+ msg(D_TLS_ERRORS,
+ "TLS Auth Erro= r: --client-config-dir authentication failed for common name '%s' f= ile=3D'%s'",

+ session->common_name, path ? path : "UNDEF&qu= ot;);
}

= gc_free(&gc);
@@ -1853,8 +1853,7 @@
= while (item)
{
struct env_= item *next =3D item->next;
- if (item->string
- && 0 =3D=3D strncmp("X509_", it= em->string, strlen("X509_")))
+ if (item->string && 0 =3D=3D strn= cmp("X509_", item->string, strlen("X509_")))<= br> {
env_set_del(es, item->s= tring);
}
diff --git a/src/openvpn= /ssl_verify.h b/src/openvpn/ssl_verify.h
index 9a30db0..92a= 760b 100644
--- a/src/openvpn/ssl_verify.h
= +++ b/src/openvpn/ssl_verify.h
@@ -55,25 +55,27 @@ #define TLS_USERNAME_LEN 64

/**= Structure containing the hash for a single certificate */
-struct cert_hash {
- unsigned char sha256_hash[256/8];
+struct cert_hash=
+{
+ unsigned char sha256_hash[256 / 8];
};

/** Structure containing= the hashes for a full certificate chain */
-struct cert_hash_set {
+struct cert_hash_set
+{
struct cert_hash *ch[MAX_C= ERT_DEPTH]; /**< Array of certificate hashes */
};

-#define = VERIFY_X509_NONE 0
-#define VERIFY_X509_SUBJECT_DN 1
-#define VERIFY_X509_SUBJECT_RDN 2
-#define VERIFY_X509_SUB= JECT_RDN_PREFIX 3
+#= define VERIFY_X509_NONE 0
+#define VERIFY_X509_SUBJECT_DN 1
+#define VERIFY_X509_SUBJECT_RDN = 2

+#define VERIF= Y_X509_SUBJECT_RDN_PREFIX 3

enum tls_aut= h_status
{
- TLS_AUTHENTICATION_SUCCEEDED=3D0,
- TLS_AUTHENTICATION_FAILED=3D1,
- TLS_AUTHENTICATION_DEFERRED=3D2
+ TLS_AUTHENTICATION_S= UCCEEDED =3D 0,
+ = TLS_AUTHENTICATION_FAILED =3D 1,
+ TLS_AUTHENTICATION_DEFERRED =3D 2
};

/**
@@ -92,8 +94,7 @@=
*
* @return Current authenticati= on status of the tls_multi
*/
-enum tls_auth_status
-tls_authentication_status(struct tls_multi *multi)= ;
+enum tls_auth_stat= us tls_authentication_status(struct tls_multi *multi);

/** Check whether the \a ks \c key_state has finished the ke= y exchange part
* of the OpenVPN hand shake. This is tha= t the key_method_2read/write
@@ -156,8 +157,7 @@
= * @param session The session to set the common name for
* @param common_name The name to set the common name to
*/
-void<= /span>
-set_common_name(struct= tls_session *session, const char *common_name);
+void set_common_name(struct tls_session *sessi= on, const char *common_name);

/**=
* Returns the username field for the given tunnel
@@ -188,8 +188,7 @@

* @param session The current= TLS session
*
*/
-void verify_user_pass(struct user_pass *up,= struct tls_multi *multi,
- struct tls_session *session);
+void verify_user_pass(struct user_pass = *up, struct tls_multi *multi, struct tls_session *session);


/**
@@ -204,8 +203,7 = @@
* @return true if name is under limit or = username-as-common-name
* is not act= ive
*/
- c= onst char *username);
+bool ssl_verify_username_length(struct tls_session *session, const char *= username);

/**
* Runs = the --client-crresponse script if one is defined.
@@ -215,8= +213,7 @@
* the files for the deferred auth like the man= agement commands.
*
*/
-void
-verify_crresponse_script(struct tls_multi *multi, const= char *cr_response);
= +void verify_crresponse_script(struct tls_multi *multi, const char *cr_resp= onse);

/**
* Call the = plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE.
@@ -225,8 +222,7 @= @
* that it does not directly participate in the authenti= cation but rather
* should set the files for the deferred= auth like the management commands.
*/
-void
-verify_crresponse_plugin(struct tls_multi *multi, const c= har *cr_response);
+v= oid verify_crresponse_plugin(struct tls_multi *multi, const char *cr_respon= se);

/**
* Perform fin= al authentication checks, including locking of the cn, the allowed@@ -243,7 +239,7 @@
{
const s= truct x509_track *next;
const char *name;
-#define XT_FULL_CHAIN (1<<0)=

+#define XT_FULL_CHA= IN (1 << 0)
unsigned int flags;
= int nid;
};
@@ -252,11 +248,11 @@
* Certificate checking for verify_nsCertType
*/

/** Do not perform Netscape certificate type verific= ation */
-#define NS_CE= RT_CHECK_NONE (0)
+#d= efine NS_CERT_CHECK_NONE (0)
/** Do not perform Netscape= certificate type verification */
-#define NS_CERT_CHECK_SERVER (1<<0)
+#define NS_CERT_CHECK_SERVER (1 << = 0)
/** Do not perform Netscape certificate type verificati= on */
-#define NS_CERT_= CHECK_CLIENT (1<<1)
+#define NS_CERT_CHECK_CLIENT (1 << 1)
<= br> /** Require keyUsage to be present in cert (0xFFFF is an invalid = KU value) */
#define OPENVPN_KU_REQUIRED (0xFFFF)@@ -265,7 +261,8 @@
* TODO: document
*/

#ifdef ENABLE_MANAGEMENT
-bool tls_authenticate_key(struct tls_multi *mu= lti, const unsigned int mda_key_id, const bool auth, const char *client_rea= son);
+bool tls_authe= nticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const b= ool auth,
+ = const char *client_reason);

#endif


diff --git a/src/openvpn/ssl_v= erify_backend.h b/src/openvpn/ssl_verify_backend.h
index eb= 80cc8..87e381b 100644
--- a/src/openvpn/ssl_verify_backend.= h
+++ b/src/openvpn/ssl_verify_backend.h
@@= -33,7 +33,11 @@
/**
* Result of verific= ation function
*/
-typedef enum { SUCCESS =3D 0, FAILURE =3D 1 } result_t;
+typedef enum
+{

+ SUCCESS =3D 0,
+ FAILURE =3D 1
+} result_t;

/*
* Backend support functions.
@@ -95,8 +99,7 = @@
*
* @return a string co= ntaining the certificate fingerprint
*/
-struct buffer x509_get_sha1_fingerprint= (openvpn_x509_cert_t *cert,
- struct gc_arena *gc);<= br>+struct buffer x509_get_sha1= _fingerprint(openvpn_x509_cert_t *cert, struct gc_arena *gc);

/**
* Retrieve the certificate'= s SHA256 fingerprint.
@@ -106,8 +109,7 @@
= *
* @return a string containing the certifi= cate fingerprint
*/
-struct buffer x509_get_sha256_fingerprint(openvpn_x509_cert= _t *cert,
- = struct gc_arena *gc);
+struct buffer x509_get_sha256_fingerprint= (openvpn_x509_cert_t *cert, struct gc_arena *gc);
<= br> /*
* Retrieve the certificate's username fr= om the specified field.
@@ -122,8 +124,8 @@
*

* @return \c FAILURE, \c or SUCCESS
*/
-resu= lt_t backend_x509_get_username(char *common_name, int cn_len,
- = char *x509_username_field, openvpn_x509_cert_t *peer_cert);

+result_t backend_x509_get_username(= char *common_name, int cn_len, char *x509_username_field,

+ op= envpn_x509_cert_t *peer_cert);

#ifdef EN= ABLE_X509ALTUSERNAME
/**
@@ -158,8 +160,7 = @@
* @return String representation of the ce= rtificate's serial number
* in h= ex notation, or NULL on error.
*/
-char *backend_x509_get_serial_hex(openvpn_x= 509_cert_t *cert,
- = struct gc_arena *gc);
+char *backend_x509_get_serial_hex(openvpn= _x509_cert_t *cert, struct gc_arena *gc);

/*

* Write the certificate to the file in PEM format.
@@ -169,8 +170,7 @@
*
* = @return \c FAILURE, \c or SUCCESS
*/<= br>-result_t backend_x509_write_p= em(openvpn_x509_cert_t *cert,
- const char *filename);
+result_t backend_x509_write_pem(= openvpn_x509_cert_t *cert, const char *filename);

<= br> /*
* Save X509 fields to environment, using the= naming convention:
@@ -194,8 +194,8 @@
*= @param gc Garbage collection arena for temp data
*

*/
-void x509_track_add(const struct x509_track **ll_head, const char *nam= e,
- = int msglevel, struct gc_arena *gc);
+void x509_track_add(const struct x509_track **ll_head, con= st char *name, int msglevel,
+ struct gc_arena *gc);
=
/*
* Save X509 fields to environment, using th= e naming convention:
@@ -217,8 +217,8 @@
= * @param cert_depth Depth of the certificate
* @param = cert Certificate to set the environment for
*/
-void x509_setenv_track(= const struct x509_track *xt, struct env_set *es,
- const int depth, openvpn_= x509_cert_t *x509);
+= void x509_setenv_track(const struct x509_track *xt, struct env_set *es, con= st int depth,
+ = openvpn_x509_cert_t *x509);

/*

* Check X.509 Netscape certificate type field, if= available.
diff --git a/src/openvpn/ssl_verify_mbedtls.c b= /src/openvpn/ssl_verify_mbedtls.c
index 25ad09c..032d07d 10= 0644
--- a/src/openvpn/ssl_verify_mbedtls.c
+++ b/src/openvpn/ssl_verify_mbedtls.c

@@ -47,10 +47,9 @@<= /span>
#define MAX_SUBJECT_LENGTH 256
int
-verify_cal= lback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth,
= - uint32_t *flags)=
+verify_callback(voi= d *session_obj, mbedtls_x509_crt *cert, int cert_depth, uint32_t *flags)
{
- s= truct tls_session *session =3D (struct tls_session *) session_obj;+ struct tls_session *sess= ion =3D (struct tls_session *)session_obj;
struct gc_a= rena gc =3D gc_new();

ASSERT(cert);<= /span>
@@ -72,8 +71,7 @@
* Clearing thes= e flags relies on verify_cert will later rejecting a
= * certificate that has no matching fingerprint.
= */
- uint32_t= flags_ignore =3D MBEDTLS_X509_BADCERT_NOT_TRUSTED
- | MBEDTLS_X509= _BADCERT_EXPIRED
+ = uint32_t flags_ignore =3D MBEDTLS_X509_BADCERT_NOT_TRUSTED | MBEDTLS_X= 509_BADCERT_EXPIRED
| MBED= TLS_X509_BADCERT_FUTURE;
*flags =3D *flags & ~= flags_ignore;
}
@@ -86,9 +84,10 @@
char *subject =3D x509_get_subject(cert, &gc);
char *serial =3D backend_x509_get_serial(cert, &= gc);

= - ret =3D mbedtls_x509_crt_verify_info(errstr, sizeof(errstr)-1, &qu= ot;", *flags);
- = if (ret <=3D 0 && !snprintf(errstr, sizeof(errstr),=
- = "Could not retrieve error string, flags=3D%" PRIx32, *flags= ))
+ ret =3D m= bedtls_x509_crt_verify_info(errstr, sizeof(errstr) - 1, "", *flag= s);
+ if (ret = <=3D 0
+ = && !snprintf(errstr, sizeof(errstr), "Could not retrieve err= or string, flags=3D%" PRIx32,
+ *flags))
{=
errstr[0] =3D '\0';
= }
@@ -99,13 +98,15 @@

<= span> if (subject)

{
- msg(D_TLS_ERRORS, "VERIFY = ERROR: depth=3D%d, subject=3D%s, serial=3D%s: %s",
- cert_depth, subject, seri= al ? serial : "<not available>", errstr);
+ msg(D_TLS_ERRORS, "V= ERIFY ERROR: depth=3D%d, subject=3D%s, serial=3D%s: %s", cert_depth,
+ subje= ct, serial ? serial : "<not available>", errstr); }
else
{<= /span>
- msg(D_TLS_= ERRORS, "VERIFY ERROR: depth=3D%d, (could not extract X509 "
- "subj= ect string from certificate): %s", cert_depth, errstr);
+ msg(D_TLS_ERRORS,
+ "VE= RIFY ERROR: depth=3D%d, (could not extract X509 "
+ "subject string fro= m certificate): %s",
+ cert_depth, errstr);
}

/* Leave flags set to non-zero to ind= icate that the cert is not ok */
@@ -128,20 +129,18 @@
#endif

result_t
<= span style=3D"color: hsl(0, 100%, 40%);">-backend_x509_get_username(char *c= n, int cn_len,

- = char *x509_username_field, mbedtls_x509_crt *cert)
+backend_x509_get_username= (char *cn, int cn_len, char *x509_username_field, mbedtls_x509_crt *cert)
{
mbedtls_x509_name *name;
<= span>

- ASSERT( cn = !=3D NULL );
+ ASS= ERT(cn !=3D NULL);

name =3D &cer= t->subject;

/* Find common name *= /
while (name !=3D NULL)
{=
- if (0 =3D=3D memcmp(= name->oid.p, MBEDTLS_OID_AT_CN,
- MBEDTLS_OID_SIZE(MBEDTLS_OID_AT_CN)))<= /span>
+ if (0 =3D=3D= memcmp(name->oid.p, MBEDTLS_OID_AT_CN, MBEDTLS_OID_SIZE(MBEDTLS_OID_AT_= CN)))
{
break;=
}
@@ -158,13 +157,13 @@
= /* Found, extract CN */
if (cn_len > name->= val.len)
{
- memcpy( cn, name->val.p, name->val.len );+ memcpy(cn, name->v= al.p, name->val.len);
cn[name->val.len] =3D = '\0';
}
else
{

- mem= cpy( cn, name->val.p, cn_len);
- cn[cn_len-1] =3D '\0';
+ memcpy(cn, name->val.p, cn_len);<= /span>
+ cn[cn_len - = 1] =3D '\0';
}

return SUCCESS;

@@ -179,8 +178,7 @@

/* Transform asn1 integer serial into mbed TLS MPI = */
mbedtls_mpi_init(&serial_mpi);
- if (!mbed_ok(mbedtls_mpi_read_bina= ry(&serial_mpi, cert->serial.p,
- cert->serial.l= en)))
+ if (!mbed_= ok(mbedtls_mpi_read_binary(&serial_mpi, cert->serial.p, cert->ser= ial.len)))
{
msg(M_WARN, &quo= t;Failed to retrieve serial from certificate.");
= goto end;
@@ -211,7 +209,7 @@
<= br> buf =3D gc_malloc(len, true, gc);
- if (mbedtls_x509_serial_get= s(buf, len-1, &cert->serial) < 0)
+ if (mbedtls_x509_serial_gets(buf, len - 1, &= ;cert->serial) < 0)
{
b= uf =3D NULL;
}
@@ -235,7 +233,7 @@
struct buffer der =3D {};
buf_set_re= ad(&der, cert->raw.p, cert->raw.len);
- if (!crypto_pem_encode(&quo= t;CERTIFICATE", &pem, &der, &gc))
+ if (!crypto_pem_encode("CERTIFIC= ATE", &pem, &der, &gc))
{
<= span> goto err;

}
@@ -248,15 += 246,13 @@
gc_free(&gc);
retur= n SUCCESS;
err:
- msg(D_TLS_DEBUG_LOW, "Error writing X509 certificate to= file %s",
- = filename);
+ msg= (D_TLS_DEBUG_LOW, "Error writing X509 certificate to file %s", fi= lename);
gc_free(&gc);
return= FAILURE;
}

static stru= ct buffer
-x509_get_fin= gerprint(const mbedtls_md_info_t *md_info, mbedtls_x509_crt *cert,- struct gc= _arena *gc)
+x509_get= _fingerprint(const mbedtls_md_info_t *md_info, mbedtls_x509_crt *cert, stru= ct gc_arena *gc)
{
const size_t md_si= ze =3D mbedtls_md_get_size(md_info);
struct buffer fin= gerprint =3D alloc_buf_gc(md_size, gc);
@@ -268,26 +264,24 = @@
struct buffer
x509_get_sha1_fingerprin= t(mbedtls_x509_crt *cert, struct gc_arena *gc)
{- return x509_get_fingerprint= (mbedtls_md_info_from_type(MBEDTLS_MD_SHA1),
- cert, gc);+ return x509_get_fingerpri= nt(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), cert, gc);
= }

struct buffer
x509_ge= t_sha256_fingerprint(mbedtls_x509_crt *cert, struct gc_arena *gc) {
- return x= 509_get_fingerprint(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256),- = cert, gc);
+ retu= rn x509_get_fingerprint(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), cert,= gc);
}

char * x509_get_subject(mbedtls_x509_crt *cert, struct gc_arena *gc)
{
- cha= r tmp_subject[MAX_SUBJECT_LENGTH] =3D {0};
+ char tmp_subject[MAX_SUBJECT_LENGTH] =3D { 0 };<= /span>
char *subject =3D NULL;

int ret =3D 0;


- ret =3D mbedtls_x509_dn_gets( tmp_subject, MAX_SUBJ= ECT_LENGTH-1, &cert->subject );
+ ret =3D mbedtls_x509_dn_gets(tmp_subject, MAX_SUBJEC= T_LENGTH - 1, &cert->subject);
if (ret > 0)<= /span>
{
/* Allocate the required sp= ace for the subject */
@@ -306,7 +300,7 @@
= string_mod(value, CC_ANY, CC_CRLF, '?');
= msg(D_X509_ATTR, "X509 ATTRIBUTE name=3D'%s' value=3D'%s&#= 39; depth=3D%d", name, value, depth);
name_expand= _size =3D 64 + strlen(name);
- name_expand =3D (char *) malloc(name_expand_size);
+ name_expand =3D (char *)mallo= c(name_expand_size);

check_malloc_return(name_expand);=
snprintf(name_expand, name_expand_size, "X509_%d= _%s", depth, name);
setenv_str(es, name_expand, v= alue);
@@ -319,8 +313,7 @@
size_t i;
char *val;

- if (!(orig->tag =3D=3D MBEDTLS_ASN1_UTF8_= STRING
- || or= ig->tag =3D=3D MBEDTLS_ASN1_PRINTABLE_STRING
+ if (!(orig->tag =3D=3D MBEDTLS_ASN1_UTF8= _STRING || orig->tag =3D=3D MBEDTLS_ASN1_PRINTABLE_STRING
|| orig->tag =3D=3D MBEDTLS_ASN1_IA5_STRING))

{

/* Only support C-string compatible type= s */
@@ -334,15 +327,15 @@
ret= urn string_alloc("ERROR: embedded null value", gc);
}

}
- val =3D gc_malloc(orig->len+1, false, gc);
= + val =3D gc_malloc(orig->= ;len + 1, false, gc);
memcpy(val, orig->p, orig->= ;len);
val[orig->len] =3D '\0';
<= span> return val;

}

= static void
-do_setenv= _name(struct env_set *es, const struct x509_track *xt,
- const mbedtls_x509_crt *cer= t, int depth, struct gc_arena *gc)
+do_setenv_name(struct env_set *es, const struct x509_track *= xt, const mbedtls_x509_crt *cert,
+ int depth, struct gc_arena *gc)
{

const mbedtls_x509_name *xn;
= for (xn =3D &cert->subject; xn !=3D NULL; xn =3D xn->next)
@@ -358,7 +351,8 @@
}
<= br> void
-x509_tr= ack_add(const struct x509_track **ll_head, const char *name, int msglevel, = struct gc_arena *gc)
= +x509_track_add(const struct x509_track **ll_head, const char *name, int ms= glevel,
+ = struct gc_arena *gc)
{
struct x509= _track *xt;
ALLOC_OBJ_CLEAR_GC(xt, struct x509_track, = gc);
@@ -373,8 +367,8 @@
}

void
- const int= depth, mbedtls_x509_crt *cert)
+x509_setenv_track(const struct x509_track *xt, struct env_set *= es, const int depth,
= + mbedtls_x509_crt *cert)
{
struct gc_arena gc =3D gc_new();

while (xt)
@@ -396,8 +390,8 @@
cert= _hash =3D x509_get_sha256_fingerprint(cert, &gc);
= }

- fingerprint =3D format_hex_ex(BPTR(&cert_hash= ),
- = BLEN(&cert_hash), 0, 1 | FHE_CAPS, ":&quo= t;, &gc);
+ = fingerprint =3D
+ format_hex_ex(BPTR(&cert_hash), BLEN(&cer= t_hash), 0, 1 | FHE_CAPS, ":", &gc);
= do_setenv_x509(es, xt->name, fingerprint, depth);
}

else
@@ -427= ,29 +421,27 @@

while (name !=3D NULL= )
{
+ char name_expand[64 + 8];
c= onst char *shortname;

- if (0 =3D=3D mbedtls_oid_get_attr_short_name(&= ;name->oid, &shortname) )
+ if (0 =3D=3D mbedtls_oid_get_attr_short_name(&name= ->oid, &shortname))
{
- snprintf(name_expand, sizeof(na= me_expand), "X509_%d_%s",
- cert_depth, shortname);
+ snprintf(name_expand, si= zeof(name_expand), "X509_%d_%s", cert_depth, shortname); }
else
{=
- snprintf(= name_expand, sizeof(name_expand), "X509_%d_\?\?",
- cert_depth);
+ snprintf(na= me_expand, sizeof(name_expand), "X509_%d_\?\?", cert_depth);
}

for (i = =3D 0; i < name->val.len; i++)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- if (i >=3D (int) s= izeof( s ) - 1)

+ = if (i >=3D (int)sizeof(s) - 1)
{
break;
}=

c =3D name->val.p[i];- if (c < 32 || c = =3D=3D 127 || ( c > 128 && c < 160 ) )
+ if (c < 32 || c =3D=3D 127= || (c > 128 && c < 160))
{
s[i] =3D '?';
= }
@@ -483,15 +475,13 @@
}
<= span>

result_t
-x509_verify_cert_ku(mbedtls_x509_crt *cert, const unsigned *cons= t expected_ku,
- = int expected_len)
+x509_verify_cert_ku(mbedtls_x509_crt *cert, const unsigned *cons= t expected_ku, int expected_len)
{
ms= g(D_HANDSHAKE, "Validating certificate key usage");

if (!mbedtls_x509_crt_has_ext_type(cert, MBEDTLS_= X509_EXT_KEY_USAGE))
{
- msg(D_TLS_ERRORS,
- "ERROR: Certificate does not hav= e key usage extension");
+ msg(D_TLS_ERRORS, "ERROR: Certificate does not have = key usage extension");
return FAILURE;=
}

@@ -502,10 +492,9 @@
}

result_t fFound = =3D FAILURE;
- for (= size_t i =3D 0; SUCCESS !=3D fFound && i<expected_len; i++)
+ for (size_t i =3D 0;= SUCCESS !=3D fFound && i < expected_len; i++)
= {
- if (expe= cted_ku[i] !=3D 0
- = && 0 =3D=3D mbedtls_x509_crt_check_key_usage(cert, expected= _ku[i]))
+ if = (expected_ku[i] !=3D 0 && 0 =3D=3D mbedtls_x509_crt_check_key_usage= (cert, expected_ku[i]))
{
= fFound =3D SUCCESS;
}
@@ -543= ,10 +532,10 @@
char oid_num_str[1024];<= br> const char *oid_str;

- if (0 =3D=3D mbedtls_oid= _get_extended_key_usage( oid, &oid_str ))

+ if (0 =3D=3D mbedtls_oid_get_extended= _key_usage(oid, &oid_str))
{
- msg(D_HANDSHAKE, &q= uot;++ Certificate has EKU (str) %s, expects %s",

- oid_str, expected_oid)= ;
+ ms= g(D_HANDSHAKE, "++ Certificate has EKU (str) %s, expects %s", oid= _str,
+ = expected_oid);
if (!strcmp(expected_= oid, oid_str))
{
= fFound =3D SUCCESS;
@@ -554,11 +543,10 @@

}
}

- if (0 = < mbedtls_oid_get_numeric_string( oid_num_str,
- = sizeof(oid_num_str), oid))
+ if (0 < mbedtls_oid_get_numeric_string(oid_num_s= tr, sizeof(oid_num_str), oid))
{
- msg(D_HANDSHAKE, &q= uot;++ Certificate has EKU (oid) %s, expects %s",

- oid_num_str, expected_= oid);
+ = msg(D_HANDSHAKE, "++ Certificate has EKU (oid) %s, expects %s",= oid_num_str,
+ = expected_oid);
if (!strcmp(e= xpected_oid, oid_num_str))
{
fFound =3D SUCCESS;

diff --git a/sr= c/openvpn/ssl_verify_mbedtls.h b/src/openvpn/ssl_verify_mbedtls.hindex ff21157..f5f34e4 100644
--- a/src/openvpn/ssl_= verify_mbedtls.h
+++ b/src/openvpn/ssl_verify_mbedtls.h
@@ -70,8 +70,7 @@
*
* @ret= urn The return value is 0 unless a fatal error occurred.
= */
-int verify_callback= (void *session_obj, mbedtls_x509_crt *cert, int cert_depth,
- uint32_t *flags);=

+int verify_callback= (void *session_obj, mbedtls_x509_crt *cert, int cert_depth, uint32_t *flags= );

/** @} name Function for authenticati= ng a new connection from a remote OpenVPN peer */
<= br>diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_ve= rify_openssl.c
index 1546815..9e7ab6c 100644
--- a/src/openvpn/ssl_verify_openssl.c

+++ b/src/openvpn/= ssl_verify_openssl.c
@@ -58,7 +58,7 @@
= /* get the tls_session pointer */
ssl =3D X509_STORE_= CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
ASSERT(ssl);

- = session =3D (struct tls_session *) SSL_get_ex_data(ssl, mydata_index);
+ session =3D (struct= tls_session *)SSL_get_ex_data(ssl, mydata_index);
ASS= ERT(session);

X509 *current_cert =3D= X509_STORE_CTX_get_current_cert(ctx);
@@ -82,8 +82,7 @@
{
msg(D_TLS_DEBUG_LOW, = "VERIFY WARNING: depth=3D%d, %s: %s",
= X509_STORE_CTX_get_error_depth(ctx),
- X509_verify_cert_error_string(X509_STO= RE_CTX_get_error(ctx)),
- subject);
+ X509_verify_cert_error_string(X509_STORE_CTX_get_er= ror(ctx)), subject);
ret =3D 1;
goto cleanup;

}
@@ = -91,8 +90,8 @@
/* Remote site specified a certific= ate, but it's not correct */
msg(D_TLS_ERRORS,= "VERIFY ERROR: depth=3D%d, error=3D%s: %s, serial=3D%s",<= br> X509_STORE_CTX_get_error_depth(ctx),
- X509_verify_cert_error_str= ing(X509_STORE_CTX_get_error(ctx)),
- subject, serial ? serial : "<not availabl= e>");
+ = X509_verify_cert_error_string(X509_STORE_CTX_get_error(ctx)), subject= ,
+ serial= ? serial : "<not available>");
ERR_clear_error();

@@ -12= 1,8 +120,7 @@
return nid =3D=3D NID_subject_alt_name |= | nid =3D=3D NID_issuer_alt_name;
}

-static
-bool
+static bool
extract_x509_extension(X509= *cert, char *fieldname, char *out, int size)
{
= bool retval =3D false;
@@ -130,8 +128,7 @@

if (!x509_username_field_ext_supported(fi= eldname))
{
- msg(D_TLS_ERRORS,
- "ERROR: --x509-username-field 'ext:%s&#= 39; not supported", fieldname);
+ msg(D_TLS_ERRORS, "ERROR: --x509-username-fie= ld 'ext:%s' not supported", fieldname);
= return false;
}

@= @ -149,10 +146,10 @@
numalts =3D sk_GENERAL_NAME_n= um(extensions);

/* loop through = all alternatives */
- = for (i =3D 0; i<numalts; i++)
+ for (i =3D 0; i < numalts; i++)
{

/* get a handle to alternative n= ame number i */
- = const GENERAL_NAME *name =3D sk_GENERAL_NAME_value(extensions, i );
+ const GEN= ERAL_NAME *name =3D sk_GENERAL_NAME_value(extensions, i);
=
switch (name->type)
= {
@@ -175,8 +172,8 @@
= break;

default:
- msg= (D_TLS_DEBUG, "%s: ignoring general name field type %i",- __func= __, name->type);
+= msg(D_TLS_DEBUG, "%s: ignoring general name field = type %i", __func__,
+ name->type);
= break;
}
}
@@ -199,8 +196,7 @@
* to contain result is g= rounds for error).
*/
static result_t
-extract_x509_field_ssl(X= 509_NAME *x509, const char *field_name, char *out,
- int size)
+extract_x509_field_ssl(X509_NAME = *x509, const char *field_name, char *out, int size)

{
int lastpos =3D -1;
int tmp =3D -1;
@@ -257,13 +253,12 @@
}

result_t
- char *x509_= username_field, X509 *peer_cert)
+backend_x509_get_username(char *common_name, int cn_len, char = *x509_username_field, X509 *peer_cert)
{
= #ifdef ENABLE_X509ALTUSERNAME
if (strncmp("ext:&q= uot;, x509_username_field, 4) =3D=3D 0)
{
- if (!extract_x509_extensio= n(peer_cert, x509_username_field+4, common_name, cn_len))

+ if (!extract_x509_extension(p= eer_cert, x509_username_field + 4, common_name, cn_len))
= {
return FAILURE;
= }
@@ -272,10 +267,9 @@
{ ASN1_INTEGER *asn1_i =3D X509_get_serialNumber(peer_cert);<= /span>
struct gc_arena gc =3D gc_new();
- char *serial =3D format_hex_ex(= asn1_i->data, asn1_i->length,
- 0, 1 | FHE_CAPS, NULL, &= amp;gc);
+ cha= r *serial =3D format_hex_ex(asn1_i->data, asn1_i->length, 0, 1 | FHE_= CAPS, NULL, &gc);

- if (!serial || cn_len <=3D strlen(serial)+2)
+ if (!serial |= | cn_len <=3D strlen(serial) + 2)
{
<= span> gc_free(&gc);

return FAI= LURE;
@@ -285,11 +279,12 @@
} else
#endif /* ifdef ENABLE_X509ALTUSERNAME *= /
- if (FAILURE =3D= =3D extract_x509_field_ssl(X509_get_subject_name(peer_cert),
- = x509_username_field, common_name, cn_len))

- {
- return FAILURE;
- }
+ = if (FAILURE
+ = =3D=3D extract_x509_field_ssl(X509_get_subject_name(peer_cert), = x509_username_field,
= + common_name, cn_len))
+ {

+ return FAILURE;
+ }
return SUCCESS;
}
@@ -339,8 += 334,7 @@
return SUCCESS;
err:<= br> BIO_free(out);
- crypto_msg(D_TLS_DEBUG_LOW, "Error writing X509 certificate= to file %s",
- = filename);
- X509_NAME_print_ex(subject_bio,= X509_get_subject_name(cert),
- 0, XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN
- |A= SN1_STRFLGS_UTF8_CONVERT | ASN1_STRFLGS_ESC_CTRL);
+ X509_NAME_print_ex(subject_bio, X509_get= _subject_name(cert), 0,
+ XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN | ASN1_STR= FLGS_UTF8_CONVERT
+ = | ASN1_STRFLGS_ESC_CTRL);
=
if (BIO_eof(subject_bio))
{
<= span>@@ -421,7 +415,8 @@

*/

<= span> void

-x509_track_= add(const struct x509_track **ll_head, const char *name, int msglevel, stru= ct gc_arena *gc)
+x50= 9_track_add(const struct x509_track **ll_head, const char *name, int msglev= el,
+ s= truct gc_arena *gc)
{
struct x509_tra= ck *xt;
ALLOC_OBJ_CLEAR_GC(xt, struct x509_track, gc);=
@@ -453,7 +448,7 @@
string_mod(value,= CC_ANY, CC_CRLF, '?');
msg(D_X509_ATTR, "= ;X509 ATTRIBUTE name=3D'%s' value=3D'%s' depth=3D%d", = name, value, depth);
name_expand_size =3D 64 + strlen(= name);
- name_expand= =3D (char *) malloc(name_expand_size);
+ name_expand =3D (char *)malloc(name_expand_size);
check_malloc_return(name_expand);
= snprintf(name_expand, name_expand_size, "X509_%d_%s", depth, name= );
setenv_str(es, name_expand, value);
@@ -488,8 +483,7 @@

fp_buf =3D x5= 09_get_sha256_fingerprint(x509, &gc);
= }

- fp_str =3D format_hex_ex(BPTR(&fp_buf), BLEN(&= ;fp_buf), 0,
- = 1 | FHE_CAPS, ":", &gc);
+ fp= _str =3D format_hex_ex(BPTR(&fp_buf), BLEN(&fp_buf), 0, 1 | FHE_CAP= S, ":", &gc);
do_setenv_= x509(es, xt->name, fp_str, depth);
}
break;
@@ -596,10 +590,9 @@<= /span>
continue;
} name_expand_size =3D 64 + strlen(objbuf);
- name_expand =3D (char *) malloc= (name_expand_size);
+= name_expand =3D (char *)malloc(name_expand_size);
= check_malloc_return(name_expand);
- snprintf(name_expand, name_expand_size, "X= 509_%d_%s", cert_depth,
- objbuf);
+ snprintf(name_expand, name_expand_size, "X509_%d_= %s", cert_depth, objbuf);
string_mod(name_exp= and, CC_PRINT, CC_CRLF, '_');
string_mod((= char *)buf, CC_PRINT, CC_CRLF, '_');
seten= v_str_incr(es, name_expand, (char *)buf);
@@ -621,8 +614,8 = @@
* Unfortunately, X509_check_purpose() does som= e weird thing that
* prevent it to take a const a= rgument
*/
- result_t result =3D X509_check_purpose(peer_cert, X5= 09_PURPOSE_SSL_CLIENT, 0) ?
- SUCCESS : FAILURE;
+ result_t result =3D
+ X509_check_purpose(peer_= cert, X509_PURPOSE_SSL_CLIENT, 0) ? SUCCESS : FAILURE;

/*
* old versions of OpenS= SL allow us to make the less strict check we used to
@@ -63= 7,7 +630,7 @@
if (result =3D=3D SUCCESS)
{
msg(M_WARN, &quo= t;X509: Certificate is a client certificate yet it's purpose "
- "= ;cannot be verified (check may fail in the future)");
+ "ca= nnot be verified (check may fail in the future)");
= }
ASN1_BIT_STRING_free(ns); }
@@ -649,8 +642,8 @@
= * Unfortunately, X509_check_purpose() does some weird thing that
* prevent it to take a const argument
*/

- = result_t result =3D X509_check_purpose(peer_cert, X509_PURPOSE_SSL_SERVER, = 0) ?
- = SUCCESS : FAILURE;
+ result_t result =3D
+ X509_check_purpose(peer_cert, X509_PURPOSE_SSL_= SERVER, 0) ? SUCCESS : FAILURE;

= /*
* old versions of OpenSSL allow us to make the= less strict check we used to
@@ -665,7 +658,7 @@ if (result =3D=3D SUCCESS)
= {
msg(M_WARN, "X509: Certificate is = a server certificate yet it's purpose "
- "cannot be verified (ch= eck may fail in the future)");
+ "cannot be verified (check= may fail in the future)");
}
<= span> ASN1_BIT_STRING_free(ns);

}
@@ -676,8 +669,7 @@
}
=
result_t
-x5= 09_verify_cert_ku(X509 *x509, const unsigned *const expected_ku,
= - int expected= _len)
+x509_verify_ce= rt_ku(X509 *x509, const unsigned *const expected_ku, int expected_len)
{
ASN1_BIT_STRING *ku =3D X509_get_ext_d2= i(x509, NID_key_usage, NULL, NULL);

@@ -7= 23,8 +715,7 @@

if (fFound !=3D SUCCE= SS)
{
- msg(D_TLS_ERRORS,
- "ERROR: Certificate has key usage %04x, expected = one of:", nku);
= + msg(D_TLS_ERRORS, "ERROR: Certificate has key usage %04x, exp= ected one of:", nku);
for (size_t i =3D 0; i = < expected_len && expected_ku[i]; i++)
= {
msg(D_TLS_ERRORS, " * %04x", expec= ted_ku[i]);
@@ -742,8 +733,7 @@
EXTEND= ED_KEY_USAGE *eku =3D NULL;
result_t fFound =3D FAILUR= E;

- = if ((eku =3D (EXTENDED_KEY_USAGE *) X509_get_ext_d2i(x509, NID_ext_key_u= sage,
- = NULL, NULL)) =3D=3D NULL)
= + if ((eku =3D (EXTENDED_KEY= _USAGE *)X509_get_ext_d2i(x509, NID_ext_key_usage, NULL, NULL)) =3D=3D NULL= )
{
msg(D_HANDSHAKE, "Ce= rtificate does not have extended key usage extension");
}

@@ -759,8 +749,8 @@

if (SUCCESS !=3D fFound && OBJ_obj2txt(szOid, size= of(szOid), oid, 0) !=3D -1)

{
- msg(D_HANDSHAKE, "= ;++ Certificate has EKU (str) %s, expects %s",
- szOid, expected_oid);
+ msg(D= _HANDSHAKE, "++ Certificate has EKU (str) %s, expects %s", szOid,=
+ = expected_oid);
if (!strcmp(expected_oid, = szOid))
{
= fFound =3D SUCCESS;
@@ -768,8 +758,8 @@
}

if (SUCCESS !=3D fFound &= & OBJ_obj2txt(szOid, sizeof(szOid), oid, 1) !=3D -1)
= {
- = msg(D_HANDSHAKE, "++ Certificate has EKU (oid) %s, expects %s&q= uot;,
- = szOid, expected_oid);
+ msg(D_HANDSHAKE, "++ Certificate has EKU (oid) %= s, expects %s", szOid,
+ expected_oid);
= if (!strcmp(expected_oid, szOid))
{
fFound =3D SUCCESS;
diff --= git a/src/openvpn/status.c b/src/openvpn/status.c
index 4b0= e516..83300ff 100644
--- a/src/openvpn/status.c
<= span>+++ b/src/openvpn/status.c

@@ -49,7 +49,7 @@ case STATUS_OUTPUT_READ:
retur= n "READ";

- case STATUS_OUTPUT_READ|STATUS_OUTPUT_WRITE:=
+ case STATUS_OUTPUT= _READ | STATUS_OUTPUT_WRITE:
return "READ= /WRITE";

default:@@ -58,11 +58,8 @@
}

struct status_output *

-status_open(const char *filename,
- const int refresh_freq,
- const int msglevel,
<= span style=3D"color: hsl(0, 100%, 40%);">- const struct virtual_= output *vout,

- = const unsigned int flags)
+status_open(const char *filename, const int refresh_freq, const i= nt msglevel,
+ = const struct virtual_output *vout, const unsigned int flags) {
struct status_output *so =3D NULL; if (filename || msglevel >=3D 0 || vout)
@@ = -79,21 +76,16 @@
switch (so->flags)<= br> {
case STATUS_OUTPUT= _WRITE:
- = so->fd =3D platform_open(filename,
- O_CREAT | = O_TRUNC | O_WRONLY,
- = S_IRUSR | S_IWUSR);
+ so->fd =3D<= /span>
+ = platform_open(filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR= );
break;

= case STATUS_OUTPUT_READ:
- so->fd =3D platform_open(f= ilename,
- = O_RDONLY,
- S_IRUSR | S_IW= USR);
+ = so->fd =3D platform_open(filename, O_RDONLY, S_IRUSR | S_IWUSR);
break;

- case STATUS_OUTPUT_R= EAD|STATUS_OUTPUT_WRITE:

- = O_CREAT | O_RDWR,
+ case STATUS_O= UTPUT_READ | STATUS_OUTPUT_WRITE:
+ so->fd =3D platform_open(filename, O_C= REAT | O_RDWR, S_IRUSR | S_IWUSR);
bre= ak;

default:
<= span>@@ -168,10 +160,10 @@

}
#eli= f defined(HAVE_CHSIZE)
{
- const long off =3D (long) lseek(so-= >fd, (off_t)0, SEEK_CUR);
+ const long off =3D (long)lseek(so->fd, (off_t)0, SE= EK_CUR);
chsize(so->fd, off);
}

-#else /= * if defined(HAVE_FTRUNCATE) */
+#else /* if defined(HAVE_FTRUNCATE) */
#warnin= g both ftruncate and chsize functions appear to be missing from this OS
#endif

@@ -223,7 +215,7 @@<= /span>
{
if (so && (so->flags &am= p; STATUS_OUTPUT_WRITE))
{
- char buf[STATUS_PRINTF_MAXLEN+2]; /* leav= e extra bytes for CR, LF */
+ char buf[STATUS_PRINTF_MAXLEN + 2]; /* leave extra bytes fo= r CR, LF */
va_list arglist;
= int stat;

diff --git a/src/openvpn/st= atus.h b/src/openvpn/status.h
index eaed22a..292e63a 100644=
--- a/src/openvpn/status.h
+++ b/src/openv= pn/status.h
@@ -29,10 +29,11 @@
/*<= br> * virtual function interface for status output
= */
-struct virtual_out= put {
+struct virtual= _output
+{
= void *arg;
unsigned int flags_default;
- void (*func) (void *ar= g, const unsigned int flags, const char *str);
+ void (*func)(void *arg, const unsigned int f= lags, const char *str);
};

static inline void

@@ -47,8 +48,8 @@
<= /span>
struct status_output
{
-#define STATUS_OUTPUT_READ (1<<0)=
-#define STATUS_OUTPUT= _WRITE (1<<1)
+= #define STATUS_OUTPUT_READ (1 << 0)
+#define STATUS_OUTPUT_WRITE (1 << 1) unsigned int flags;

char= *filename;
@@ -63,11 +64,8 @@
bool er= rors;
};

-struct status_output *status_open(const char *filenam= e,
- = const int refresh_freq,
- const int msglevel,
- = const struct virtual_output *vout,
- const unsigned int f= lags);
+struct status= _output *status_open(const char *filename, const int refresh_freq, const in= t msglevel,
+ = const struct virtual_output *vout, const unsigned= int flags);

bool status_trigger(struct = status_output *so);

@@ -80,12 +78,12 @@
void status_printf(struct status_output *so, const char *fo= rmat, ...)
#ifdef __GNUC__
#if __USE_MING= W_ANSI_STDIO
-__attribu= te__ ((format(gnu_printf, 2, 3)))
+ __attribute__((format(gnu_printf, 2, 3)))
#else

-__attribute__ = ((format(__printf__, 2, 3)))
+ __attribute__((format(__printf__, 2, 3)))
#en= dif
#endif
-;
+ ;=

bool status_read(struct status_output *so, str= uct buffer *buf);

diff --git a/src/openvp= n/syshead.h b/src/openvpn/syshead.h
index 00d7685..9b87214 = 100644
--- a/src/openvpn/syshead.h
+++ b/sr= c/openvpn/syshead.h
@@ -29,20 +29,20 @@

/* branch prediction hints */
#if defined(= __GNUC__)
-#define like= ly(x) __builtin_expect((x), 1)
-#define unlikely(x) __builtin_expect((x), 0)
<= span style=3D"color: hsl(120, 100%, 40%);">+#define likely(x) __builtin_e= xpect((x), 1)

+#defin= e unlikely(x) __builtin_expect((x), 0)
#else
-#define likely(x) (x)
-#define unlikely(x) (x)
+#define likely(x) (x)=
+#define unlikely(x)= (x)
#endif

#ifdef _WIN= 32
#include <windows.h>
#include &l= t;winsock2.h>
#include <tlhelp32.h>
-#define sleep(x) Sleep((x)*1000)
-#define random rand
-#define srandom srand
+#define sleep(x) Sleep((= x) * 1000)
+#define r= andom rand
+#define= srandom srand
#endif

= #ifdef _MSC_VER /* Visual Studio */
@@ -52,7 +52,7 @@

#if defined(__APPLE__)
#if _= _ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >=3D 1070
-#define __APPLE_USE_RFC_3542 1<= br>+#define __APPLE_USE_RFC_354= 2 1
#endif
#endif

@@ -167,10 +167,10 @@
#endif
<= /span>
#if defined(TARGET_HAIKU)
-#include <SupportDefs.h> /* uint32, etc */

-#include <net/if.h>= /* ifconf etc */
-#endif /* TARGET_HAIKU */
<= span style=3D"color: hsl(120, 100%, 40%);">+#include <SupportDefs.h> = /* uint32, etc */

+#i= nclude <net/if.h> /* ifconf etc */
+#include <sys/sockio.h> /* SIOCGRTTABLE, e= tc */
+#endif = /* TARGET_HAIKU */

#ifdef HAV= E_ARPA_INET_H
#include <arpa/inet.h>
@@ -184,7 +184,7 @@

#include <net/if_tap.h><= br> #endif

-#if defined(TARGET_LINUX) || defined (TARGET_ANDROID)+#if defined(TARGET_LINUX) ||= defined(TARGET_ANDROID)

#ifdef HAVE_LIN= UX_IF_TUN_H
#include <linux/if_tun.h>
@@ -374,7 +374,9 @@

* Does this platform support linux-= style IP_PKTINFO
* or bsd-style IP_RECVDSTADDR ? */
-#if ((def= ined(HAVE_IN_PKTINFO) && defined(IP_PKTINFO)) || defined(IP_RECVDST= ADDR)) && defined(HAVE_MSGHDR) && defined(HAVE_CMSGHDR) &am= p;& defined(CMSG_FIRSTHDR) && defined(CMSG_NXTHDR) && d= efined(HAVE_RECVMSG) && defined(HAVE_SENDMSG)
+#if ((defined(HAVE_IN_PKTINFO) &&= defined(IP_PKTINFO)) || defined(IP_RECVDSTADDR)) \
+ && defined(HAVE_MSGHDR) &= & defined(HAVE_CMSGHDR) && defined(CMSG_FIRSTHDR) \<= br>+ && defined(CMSG= _NXTHDR) && defined(HAVE_RECVMSG) && defined(HAVE_SENDMSG)<= /span>
#define ENABLE_IP_PKTINFO 1
#else<= br> #define ENABLE_IP_PKTINFO 0
@@ -423,10 +425,10 @@=
* Directory separation char
*/<= br> #ifdef _WIN32
-#define PATH_SEPARATOR '\\'
+#define PATH_SEPARATOR '\\'
= #define PATH_SEPARATOR_STR "\\"
#else
= -#define PATH_SEPARATOR '/= 9;
+#define PATH_SEPA= RATOR '/'
#define PATH_SEPARATOR_STR "/&q= uot;
#endif

@@ -435,11 += 437,11 @@
*/
#ifdef _WIN32
#define SOCKET_UNDEFINED (INVALID_SOCKET)

-#define SOCKET_PRINTF "%" PRIxPTR<= br>+#define SOCKET_PRINTF &q= uot;%" PRIxPTR
typedef SOCKET socket_descriptor_t;
#else
#define SOCKET_UNDEFINED (-1)<= br>-#define SOCKET_PRINTF "%= d"
+#define SOCK= ET_PRINTF "%d"
typedef int socket_descriptor_= t;
#endif

@@ -460,7 +462= ,9 @@
/*
* HTTPS port sharing capability=
*/
-= #if defined(ENABLE_PORT_SHARE) && defined(SCM_RIGHTS) && de= fined(HAVE_MSGHDR) && defined(HAVE_CMSGHDR) && defined(CMSG= _FIRSTHDR) && defined(CMSG_NXTHDR) && defined(HAVE_RECVMSG)= && defined(HAVE_SENDMSG)
+#if defined(ENABLE_PORT_SHARE) && defined(SCM_RIGHTS)= && defined(HAVE_MSGHDR) \
+ && defined(HAVE_CMSGHDR) && defined(CMS= G_FIRSTHDR) && defined(CMSG_NXTHDR) \
+ && defined(HAVE_RECVMSG) && d= efined(HAVE_SENDMSG)
#define PORT_SHARE 1
= #else
#define PORT_SHARE 0
@@ -494,8 +498= ,7 @@
/*
* Do we have CryptoAPI capabili= ty?
*/
- && !defined(ENA= BLE_CRYPTO_WOLFSSL)
+= #if defined(_WIN32) && defined(ENABLE_CRYPTO_OPENSSL) && !d= efined(ENABLE_CRYPTO_WOLFSSL)
#define ENABLE_CRYPTOAPI
#endif

@@ -522,8 +525,7 @@<= /span>
/*
* Compression support
*/

-#if defined(ENAB= LE_LZO) || defined(ENABLE_LZ4) \
- || defined(ENABLE_COMP_STUB)
+#if defined(ENABLE_LZO) || defined(ENABLE_LZ4) |= | defined(ENABLE_COMP_STUB)
#define USE_COMP
#endif


diff --git a/src/openvpn/tls_c= rypt.c b/src/openvpn/tls_crypt.c
index 67e19382..f7f530c 10= 0644
--- a/src/openvpn/tls_crypt.c
+++ b/sr= c/openvpn/tls_crypt.c
@@ -41,9 +41,9 @@
co= nst char *tls_crypt_v2_srv_pem_name =3D "OpenVPN tls-crypt-v2 server k= ey";

/** Metadata contains user-spe= cified data */
-static = const uint8_t TLS_CRYPT_METADATA_TYPE_USER =3D 0x00;
+static const uint8_t TLS_CRYPT_M= ETADATA_TYPE_USER =3D 0x00;

/** Metadata contains a 64-bit= unix timestamp in network byte order */
-static const uint8_t TLS_CRYPT_METADATA_TYPE_TIMESTAMP = =3D 0x01;
+static= const uint8_t TLS_CRYPT_METADATA_TYPE_TIMESTAMP =3D 0x01;
=
static struct key_type
tls_crypt_kt(voi= d)
@@ -58,11 +58,10 @@
}
=
void
= -tls_crypt_init_key(struct key_ctx_bi *key, struct key2 *keydata,- const char *= key_file, bool key_inline, bool tls_server)
+tls_crypt_init_key(struct key_ctx_bi *key, struct k= ey2 *keydata, const char *key_file,
+ bool key_inline, bool tls_server)=
{
- const= int key_direction =3D tls_server ?
- KEY_DIRECTION_NORMAL : KEY_DIRE= CTION_INVERSE;
+ c= onst int key_direction =3D tls_server ? KEY_DIRECTION_NORMAL : KEY_DIRECTIO= N_INVERSE;
struct key_type kt =3D tls_crypt_kt();
if (!kt.cipher || !kt.digest)
{
@@ -90,7 +89,6 @@
{
= key->keys[k].hmac[j] =3D key->keys[k].hmac[j] ^ other->k= eys[k].hmac[j];
}
-
}
}
<= span>

@@ -99,8 +97,8 @@
{
struct key2 rengokeys;

if (!key_state_export_key= ing_material(session, EXPORT_DYNAMIC_TLS_CRYPT_LABEL,
- s= trlen(EXPORT_DYNAMIC_TLS_CRYPT_LABEL),
- rengokeys.keys, = sizeof(rengokeys.keys)))
+ strlen(EXPORT_DYNAMIC_TLS_CR= YPT_LABEL), rengokeys.keys,
+ sizeof(rengokeys.keys)))<= /span>
{
return false;
}

@@ -112,27 +110,23 @@
sessio= n->tls_wrap_reneg.work =3D alloc_buf(BUF_SIZE(&session->opt->f= rame));
session->tls_wrap_reneg.opt.pid_persist =3D= NULL;

- session-&= gt;opt->replay_window,
- session->opt->replay_time,
- "TLS_WRAP_RENEG&q= uot;, session->key_id);
+ packet_id_init(&session->tls_wrap_reneg.opt.packet_id, se= ssion->opt->replay_window,
+ session->opt->replay_time, "TLS_= WRAP_RENEG", session->key_id);

- if (session->tls_wrap.mode =3D=3D= TLS_WRAP_CRYPT
- = || session->tls_wrap.mode =3D=3D TLS_WRAP_AUTH)
+ if (session->tls_wrap.mode =3D=3D = TLS_WRAP_CRYPT || session->tls_wrap.mode =3D=3D TLS_WRAP_AUTH) {
xor_key2(&rengokeys, &sessio= n->tls_wrap.original_wrap_keydata);
}

- const int key= _direction =3D session->opt->server ?
- KEY_DIRECTION_NORMAL : = KEY_DIRECTION_INVERSE;
- init_key_ctx_bi(&session->tls_wrap_re= neg.opt.key_ctx_bi, &rengokeys, key_direction,
- &kt, "dynamic tls= -crypt");
+ i= nit_key_ctx_bi(&session->tls_wrap_reneg.opt.key_ctx_bi, &rengoke= ys, key_direction, &kt,
+ "dynamic tls-crypt");
secure_memzero(&rengokeys, sizeof(rengokeys));

<= /span>
return true;
@@ -140,8 +134,7 @@


bool
-tls_crypt_wrap(const struct buffer *src, st= ruct buffer *dst,
- = struct crypto_options *opt)
+tls_crypt_wrap(const struct buffer *src, struct buffer *= dst, struct crypto_options *opt)
{
co= nst struct key_ctx *ctx =3D &opt->key_ctx_bi.encrypt;
struct gc_arena gc;

@@ -150,12 +143,11 @@
= ASSERT(ctx->cipher);
ASSERT(ctx->hmac= );
ASSERT(packet_id_initialized(&opt->packet_id= ));
- ASSERT(hmac_ct= x_size(ctx->hmac) =3D=3D 256/8);
+ ASSERT(hmac_ctx_size(ctx->hmac) =3D=3D 256 / 8);

gc_init(&gc);

- dmsg(D_PACKET_CONTENT= , "TLS-CRYPT WRAP FROM: %s",
- format_hex(BPTR(src), BLEN(src), 80, &gc));
+ dmsg(D_PACKET_CON= TENT, "TLS-CRYPT WRAP FROM: %s", format_hex(BPTR(src), BLEN(src),= 80, &gc));

/* Get packet ID */<= /span>
if (!packet_id_write(&opt->packet_id.send, dst,= true, false))
@@ -164,15 +156,15 @@
= goto err;
}

- dmsg(D_PACKET_CONTENT, "TLS-CRYPT = WRAP AD: %s",
- = format_hex(BPTR(dst), BLEN(dst), 0, &gc));
+ dmsg(D_PACKET_CONTENT, "TLS-CRYP= T WRAP AD: %s", format_hex(BPTR(dst), BLEN(dst), 0, &gc));<= br>
/* Buffer overflow check */
if (!buf_safe(dst, BLEN(src) + TLS_CRYPT_BLOCK_SIZE + TLS_CRYPT_TAG_S= IZE))

{
- msg(D_CRYPT_ERRORS, "TLS-CRYPT WRAP: buffer size error,= "
- &q= uot;sc=3D%d so=3D%d sl=3D%d dc=3D%d do=3D%d dl=3D%d", src->capacity= , src->offset,
- = src->len, dst->capacity, dst->offset, dst->len);=
+ msg(D_CRYPT_ERRORS= ,
+ "= TLS-CRYPT WRAP: buffer size error, "
+ "sc=3D%d so=3D%d sl=3D%d dc=3D%d do= =3D%d dl=3D%d",
= + src->capacity, src->offset, src->len, dst->capacit= y, dst->offset, dst->len);
goto err;<= br> }

@@ -196,15 +188,13 @@
/* Encrypt src */
{
= int outlen =3D 0;
- ASSERT(cipher_ctx_update(ctx->cipher, BEND(dst), &outle= n,
- = BPTR(src), BLEN(src)));
+ ASSERT(cipher_ctx_update(ctx->cipher, BEND(dst= ), &outlen, BPTR(src), BLEN(src)));
ASSERT(buf= _inc_len(dst, outlen));
ASSERT(cipher_ctx_final(ct= x->cipher, BPTR(dst), &outlen));
ASSERT(buf= _inc_len(dst, outlen));
}

= - dmsg(D_PACKET_CONTENT, "= ;TLS-CRYPT WRAP TO: %s",
- format_hex(BPTR(dst), BLEN(dst), 80, &gc));
= + dmsg(D_PACKET_CONTENT, &qu= ot;TLS-CRYPT WRAP TO: %s", format_hex(BPTR(dst), BLEN(dst), 80, &g= c));

gc_free(&gc);
return true;

@@ -217,8 +207,7 @@
}=

bool
-tls_crypt_unwrap(const struct buffer *src, struct buffer= *dst,
- = struct crypto_options *opt)
+tls_crypt_unwrap(const struct buffer *src, struct buffer *dst, st= ruct crypto_options *opt)
{
static co= nst char error_prefix[] =3D "tls-crypt unwrap error";
<= span> const struct key_ctx *ctx =3D &opt->key_ctx_bi.decrypt;
@@ -229,11 +218,9 @@
ASSERT(opt);=
ASSERT(src->len > 0);
ASSERT(ctx-= >cipher);
- ASSER= T(packet_id_initialized(&opt->packet_id)
- || (opt->flags & CO_IGNORE_PACK= ET_ID));
+ ASSERT(= packet_id_initialized(&opt->packet_id) || (opt->flags & CO_IG= NORE_PACKET_ID));

- dmsg(D_PACKET_CONTENT, "TLS-CRYPT UNWRAP FROM: %s&qu= ot;,
- format_h= ex(BPTR(src), BLEN(src), 80, &gc));
+ dmsg(D_PACKET_CONTENT, "TLS-CRYPT UNWRAP FROM:= %s", format_hex(BPTR(src), BLEN(src), 80, &gc));
=
if (buf_len(src) < TLS_CRYPT_OFF_CT)
{

@@ -254,8 +241,8 @@
{
CRYPT_ERROR("cipher reset failed");
}
- if (!cipher_ctx_update(ctx->cipher, BPTR(dst), &outlen,<= /span>
- = BPTR(src) + TLS_CRYPT_OFF_CT, BLEN(src) - TLS_CRYPT_OFF_CT))
+ if (!cipher_ctx_u= pdate(ctx->cipher, BPTR(dst), &outlen, BPTR(src) + TLS_CRYPT_OFF_CT,=
+ = BLEN(src) - TLS_CRYPT_OFF_CT))
{
CRYPT_ERROR("cipher update failed");
}
@@ -284,10 +271,8 @@

if (memcmp_constant_time(tag, tag_check, sizeof= (tag_check)))
{
- dmsg(D_CRYPTO_DEBUG, "tag : %s&quo= t;,
- f= ormat_hex(tag, sizeof(tag_check), 0, &gc));
- dmsg(D_CRYPTO_DEBUG, "tag_check:= %s",
- = format_hex(tag_check, sizeof(tag_check), 0, &gc));
+ dmsg(D_CRYPTO_DEBUG, &= quot;tag : %s", format_hex(tag, sizeof(tag_check), 0, &gc));<= /span>
+ dmsg(D_C= RYPTO_DEBUG, "tag_check: %s", format_hex(tag_check, sizeof(tag_ch= eck), 0, &gc));
CRYPT_ERROR("packet a= uthentication failed");
}
= }
@@ -316,30 +301,24 @@
}

static inline void
-tls_crypt_v2_load_client_key(struct key_ctx_bi *key, cons= t struct key2 *key2,
- = bool tls_server)
+tls_crypt_v2_load_client_key(struct key_ctx_bi *ke= y, const struct key2 *key2, bool tls_server)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- const int key_direction =3D t= ls_server ?

- = KEY_DIRECTION_NORMAL : KEY_DIRECTION_INVERSE;+ const int key_direction = =3D tls_server ? KEY_DIRECTION_NORMAL : KEY_DIRECTION_INVERSE;
struct key_type kt =3D tls_crypt_kt();

if (!k= t.cipher || !kt.digest)
{
msg= (M_FATAL, "ERROR: --tls-crypt-v2 not supported");
}

- init_key_c= tx_bi(key, key2, key_direction, &kt,
- "Control Channel Encryption&quo= t;);
+ init_key_ct= x_bi(key, key2, key_direction, &kt, "Control Channel Encryption&qu= ot;);
}

void
= tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *or= iginal_key,
- = struct buffer *wkc_buf, const char *key_file,
= - boo= l key_inline)
+ = struct buffer *wkc_buf, const char *key_file, bool k= ey_inline)
{
- struct buffer client_key =3D alloc_buf(TLS_CRYPT_V2_CLIENT_KEY_= LEN
- = + TLS_CRYPT_V2_MAX_WKC_LEN);
+ struct buffer client_key =3D alloc_bu= f(TLS_CRYPT_V2_CLIENT_KEY_LEN + TLS_CRYPT_V2_MAX_WKC_LEN);
=
- if (!read_pem_ke= y_file(&client_key, tls_crypt_v2_cli_pem_name,
- key_file, key_inlin= e))
+ if (!read_pe= m_key_file(&client_key, tls_crypt_v2_cli_pem_name, key_file, key_inline= ))
{
msg(M_FATAL, "ERROR= : invalid tls-crypt-v2 client key format");
}
@@ -357,15 +336,14 @@
}

void
-tls= _crypt_v2_init_server_key(struct key_ctx *key_ctx, bool encrypt,
= - con= st char *key_file, bool key_inline)
+tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, bool = encrypt, const char *key_file,
+ bool key_inline)
{=
struct key srv_key;
struct buffe= r srv_key_buf;

buf_set_write(&sr= v_key_buf, (void *)&srv_key, sizeof(srv_key));
- if (!read_pem_key_file(&srv_key_buf, t= ls_crypt_v2_srv_pem_name,
- key_file, key_inline))
+ if (!read_pem_key_file(&srv_key_b= uf, tls_crypt_v2_srv_pem_name, key_file, key_inline))
= {
msg(M_FATAL, "ERROR: invalid tls-crypt-v2 s= erver key format");
}
@@ -384,14 = +362,13 @@
}

static boo= l
-tls_crypt_v2_wrap_cl= ient_key(struct buffer *wkc,
- const struct key2 *src_key,
<= span style=3D"color: hsl(0, 100%, 40%);">- cons= t struct buffer *src_metadata,

- struct key_ctx *server_key, struct gc= _arena *gc)
+tls_cryp= t_v2_wrap_client_key(struct buffer *wkc, const struct key2 *src_key,=
+ = const struct buffer *src_metadata, struct key_ctx *server_key,+ = struct gc_arena *gc)
{
cipher_ctx_t *= cipher_ctx =3D server_key->cipher;
- struct buffer work =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_WK= C_LEN
- = + cipher_ctx_block_size(cipher_ctx), gc);
<= span style=3D"color: hsl(120, 100%, 40%);">+ struct buffer work =3D
+ alloc_buf_gc(TLS= _CRYPT_V2_MAX_WKC_LEN + cipher_ctx_block_size(cipher_ctx), gc);
<= span>

/* Calculate auth tag and synthetic IV */
uint8_t *tag =3D buf_write_alloc(&work, TLS_CRYPT_TAG_S= IZE);
@@ -400,8 +377,8 @@
msg(M_WA= RN, "ERROR: could not write tag");
retur= n false;
}
- uint16_t net_len =3D htons(sizeof(src_key->keys) + BLEN(sr= c_metadata)
- = + TLS_CRYPT_V2_TAG_SIZE + sizeof(uint16_t));
<= span style=3D"color: hsl(120, 100%, 40%);">+ uint16_t net_len =3D htons(= sizeof(src_key->keys) + BLEN(src_metadata) + TLS_CRYPT_V2_TAG_SIZE
+ = + sizeof(uint16_t));
hmac_ctx_t *hmac_ctx =3D serv= er_key->hmac;
hmac_ctx_reset(hmac_ctx);
<= span> hmac_ctx_update(hmac_ctx, (void *)&net_len, sizeof(net_len));=

@@ -409,16 +386,13 @@
hmac_ctx_update= (hmac_ctx, BPTR(src_metadata), BLEN(src_metadata));
hm= ac_ctx_final(hmac_ctx, tag);

- dmsg(D_CRYPTO_DEBUG, "TLS-CRYPT WRAP TAG:= %s",
- fo= rmat_hex(tag, TLS_CRYPT_TAG_SIZE, 0, gc));
+ dmsg(D_CRYPTO_DEBUG, "TLS-CRYPT WRAP TAG: %= s", format_hex(tag, TLS_CRYPT_TAG_SIZE, 0, gc));

/* Use the 128 most significant bits of the tag as IV */<= /span>
ASSERT(cipher_ctx_reset(cipher_ctx, tag));
<= span>

/* Overflow check (OpenSSL requires an extra bl= ock in the dst buffer) */
- if (buf_forward_capacity(&work) < (sizeof(src_key->keys)<= /span>
- = + BLEN(src_metadata)
- + sizeof(net_len)
+ if (buf_forward_ca= pacity(&work) < (sizeof(src_key->keys) + BLEN(src_metadata) + siz= eof(net_len)
+ ciph= er_ctx_block_size(cipher_ctx)))
{
= msg(M_WARN, "ERROR: could not crypt: insufficient space in dst&qu= ot;);
@@ -427,11 +401,11 @@

/* Encrypt */

int outlen =3D 0;
- ASSERT(cipher_ctx_update(cipher_= ctx, BEND(&work), &outlen,

- (void *)src_key->keys, sizeof(= src_key->keys)));
= + ASSERT(cipher_ctx_update(cipher_ctx, BEND(&work), &outlen, (vo= id *)src_key->keys,
- ASSERT(cipher_ctx_update(cipher_ctx, BEND(&= work), &outlen,
- = BPTR(src_metadata), BLEN(src_metadata)));=
+ ASSERT(cipher_ctx_upda= te(cipher_ctx, BEND(&work), &outlen, BPTR(src_metadata),
= + B= LEN(src_metadata)));
ASSERT(buf_inc_len(&work, out= len));
ASSERT(cipher_ctx_final(cipher_ctx, BEND(&w= ork), &outlen));
ASSERT(buf_inc_len(&work, out= len));
@@ -442,8 +416,7 @@

static bool

tls_crypt_v2_unwrap_client_key(struct key2 = *client_key, struct buffer *metadata,
- struct buffer wrapped_client= _key,
- = struct key_ctx *server_key)
+ struct buffer wrapped= _client_key, struct key_ctx *server_key)
{
const char *error_prefix =3D __func__;

bool ret = =3D false;
@@ -455,9 +428,8 @@
struct = buffer plaintext =3D { 0 };

dmsg(D_T= LS_DEBUG_MED, "%s: unwrapping client key (len=3D%d): %s", __func_= _,
- BLEN(&= wrapped_client_key), format_hex(BPTR(&wrapped_client_key),
- = BLEN(&wrapped_client_key),

- 0, &am= p;gc));
+ BLE= N(&wrapped_client_key),
+ format_hex(BPTR(&wrapped_client_key), BLEN(&wrappe= d_client_key), 0, &gc));

if (TLS= _CRYPT_V2_MAX_WKC_LEN < BLEN(&wrapped_client_key))
= {
@@ -472,13 +444,12 @@
{ CRYPT_ERROR("failed to read length");
= }
- memcp= y(&net_len, BEND(&wrapped_client_key) - sizeof(net_len),
= - sizeof(net_len));
+ memcpy(&net_len= , BEND(&wrapped_client_key) - sizeof(net_len), sizeof(net_len));=

if (ntohs(net_len) !=3D BLEN(&wrapped_= client_key))
{
- dmsg(D_TLS_DEBUG_LOW, "%s: net_len=3D%u, BLEN=3D= %i", __func__,
- = ntohs(net_len), BLEN(&wrapped_client_key));
+ dmsg(D_TLS_DEBUG_LOW, "= %s: net_len=3D%u, BLEN=3D%i", __func__, ntohs(net_len),
+ BLEN(&wrapped_cli= ent_key));

CRYPT_ERROR("invalid length")= ;
}

@@ -495,8 +466,7= @@
}
buf_set_write(&plaintex= t, plaintext_buf_data, sizeof(plaintext_buf_data));
in= t outlen =3D 0;
- if= (!cipher_ctx_update(server_key->cipher, BPTR(&plaintext), &outl= en,
- = BPTR(&wrapped_client_key),
+ if (!cipher_ctx_update(server_key->cipher, BPTR(= &plaintext), &outlen, BPTR(&wrapped_client_key),
BLEN(&wrapped_client_key)))

{

CRYPT_ERROR("could not decrypt clie= nt key");
@@ -513,19 +483,16 @@
u= int8_t tag_check[TLS_CRYPT_TAG_SIZE] =3D { 0 };
hmac_c= tx_reset(server_key->hmac);
hmac_ctx_update(server_= key->hmac, (void *)&net_len, sizeof(net_len));
- hmac_ctx_update(server_key->hmac, BP= TR(&plaintext),
- = BLEN(&plaintext));
+ hmac_ctx_update(server_key->hmac, BPTR(&pla= intext), BLEN(&plaintext));
hmac_ctx_final(server_= key->hmac, tag_check);

if (memcmp= _constant_time(tag, tag_check, sizeof(tag_check)))
{
- dmsg(D_CRYPTO_D= EBUG, "tag : %s",
- format_hex(tag, sizeof(tag_check), 0, &gc));
- dmsg(D_CRYPTO_DE= BUG, "tag_check: %s",
- format_hex(tag_check, sizeof(tag_check), 0, &gc)= );
+ dmsg(D_CR= YPTO_DEBUG, "tag : %s", format_hex(tag, sizeof(tag_check), 0= , &gc));
+ = dmsg(D_CRYPTO_DEBUG, "tag_check: %s", format_hex(tag_check, size= of(tag_check), 0, &gc));
CRYPT_ERROR("cli= ent key authentication error");
msg(D_TLS_DEB= UG_LOW, "This might be a client-key that was generated for "
- "a differ= ent tls-crypt-v2 server key)");
+ "a different tls-crypt-v= 2 server key)");
}

if (buf_len(&plaintext) < sizeof(client_key->keys))
@@ -553,8 +520,7 @@
}
=
static bool
= -tls_crypt_v2_verify_metadata(const struct tls_wrap_ctx *ctx,
- const = struct tls_options *opt)

+tls_crypt_v2_verify_metadata(const struct tls_wrap_ctx *ctx, const str= uct tls_options *opt)
{
bool ret =3D = false;
struct gc_arena gc =3D gc_new();
@@ -567,8 +533,7 @@

goto cleanup;
}


- tmp_file =3D platform_create_temp_file(opt->tmp_dir, "tls_= crypt_v2_metadata_",
- &gc);
+ tmp_file =3D platform_create_temp_fi= le(opt->tmp_dir, "tls_crypt_v2_metadata_", &gc); if (!tmp_file || !buffer_write_file(tmp_file, &metadata))
{
msg(M_WARN, "ERROR: cou= ld not write metadata to file");
@@ -576,8 +541,7 @@
}

char metadata_= type_str[4] =3D { 0 }; /* Max value: 255 */
- snprintf(metadata_type_str, sizeof(metadata_type_= str),
- &qu= ot;%i", (uint8_t) metadata_type);
+ snprintf(metadata_type_str, sizeof(metadata_type_str= ), "%i", (uint8_t)metadata_type);
struct env= _set *es =3D env_set_create(NULL);
setenv_str(es, &quo= t;script_type", "tls-crypt-v2-verify");
= setenv_str(es, "metadata_type", metadata_type_str);
@@ -612,15 +576,12 @@

}

bool

-tls_crypt_v2= _extract_client_key(struct buffer *buf,
- struct tls_wrap_ctx *ctx,=
- = const struct tls_options *opt,
- bool initial_packet)
+tls_crypt_v2_extract_c= lient_key(struct buffer *buf, struct tls_wrap_ctx *ctx,
+ const s= truct tls_options *opt, bool initial_packet)
{
<= span> if (!ctx->tls_crypt_v2_server_key.cipher)

= {
- msg(D_TLS_E= RRORS,
- &qu= ot;Client wants tls-crypt-v2, but no server key present.");
= + msg(D_TLS_ERRORS, &quo= t;Client wants tls-crypt-v2, but no server key present.");
<= span> return false;

}
=
@@ -634,8 +595,7 @@
msg(D_TLS_ERRORS, &q= uot;Can not read tls-crypt-v2 client key length");
= return false;
}
- memcpy(&net_len, BEND(&wrapped_client_key)= - sizeof(net_len),
- = sizeof(net_len));
+ memcpy(&net_len, BEND(&wrapped_client_key) - sizeof(net_= len), sizeof(net_len));

uint16_t wkc= _len =3D ntohs(net_len);
if (!buf_advance(&wrapped= _client_key, BLEN(&wrapped_client_key) - wkc_len))
@@ -= 658,7 +618,7 @@
* basically transforming the CONT= ROL_WKC_V1 into a normal CONTROL_V1
* packet*/
msg(D_TLS_ERRORS, "control channel security alr= eady setup ignoring "
- "wrapped key part of packet.");
+ "wrap= ped key part of packet.");

= /* Remove client key from buffer so tls-crypt code can unwrap message */
ASSERT(buf_inc_len(buf, -(BLEN(&wrapped_client_k= ey))));
@@ -666,10 +626,8 @@
}<= br>
ctx->tls_crypt_v2_metadata =3D alloc_buf= (TLS_CRYPT_V2_MAX_METADATA_LEN);
- if (!tls_crypt_v2_unwrap_client_key(&ctx->original_wr= ap_keydata,
- = &ctx->tls_crypt_v2_metadata,- = wrapped_client_key,
- &ctx->tls_crypt_v2_se= rver_key))
+ if (!= tls_crypt_v2_unwrap_client_key(&ctx->original_wrap_keydata, &ctx= ->tls_crypt_v2_metadata,
+ wrapped_client_key, &ct= x->tls_crypt_v2_server_key))
{
= msg(D_TLS_ERRORS, "Can not unwrap tls-crypt-v2 client key");=
secure_memzero(&ctx->original_wrap_keydata= , sizeof(ctx->original_wrap_keydata));
@@ -681,8 +639,7 = @@
ctx->cleanup_key_ctx =3D true;
= ctx->opt.flags |=3D CO_PACKET_ID_LONG_FORM;
mem= set(&ctx->opt.key_ctx_bi, 0, sizeof(ctx->opt.key_ctx_bi));=
- tls_crypt_v2_load_client= _key(&ctx->opt.key_ctx_bi,
- &ctx->original_wrap_key= data, true);
+ tls= _crypt_v2_load_client_key(&ctx->opt.key_ctx_bi, &ctx->origina= l_wrap_keydata, true);

/* Remove cli= ent key from buffer so tls-crypt code can unwrap message */
ASSERT(buf_inc_len(buf, -(BLEN(&wrapped_client_key))));
@@ -702,16 +659,13 @@
}
void
-tls_crypt= _v2_write_client_key_file(const char *filename,
- const char *b6= 4_metadata,
- = const char *server_key_file,
- bool ser= ver_key_inline)
+tls_= crypt_v2_write_client_key_file(const char *filename, const char *b64_metada= ta,
+ = const char *server_key_file, bool server_key_inline)
{
struct gc_arena gc =3D gc_new();
struct key_ctx server_key =3D { 0 };
s= truct buffer client_key_pem =3D { 0 };
- struct buffer dst =3D alloc_buf_gc(TLS_CRYPT_V2_CLIENT= _KEY_LEN
- = + TLS_CRYPT_V2_MAX_WKC_LEN, &gc);
+ struct buffer dst =3D alloc_b= uf_gc(TLS_CRYPT_V2_CLIENT_KEY_LEN + TLS_CRYPT_V2_MAX_WKC_LEN, &gc);
struct key2 client_key =3D { .n =3D 2 };
=
if (!rand_bytes((void *)client_key.keys, sizeof(clie= nt_key.keys)))
@@ -727,8 +681,7 @@
= size_t b64_length =3D strlen(b64_metadata);
metad= ata =3D alloc_buf_gc(OPENVPN_BASE64_DECODED_LENGTH(b64_length) + 1, &gc= );
ASSERT(buf_write(&metadata, &TLS_CRYPT_= METADATA_TYPE_USER, 1));
- = BCAP(&metadata));
+ int decoded_len =3D openvp= n_base64_decode(b64_metadata, BEND(&metadata), BCAP(&metadata));
if (decoded_len < 0)
{
msg(M_FATAL, "ERROR: failed to base64 deco= de provided metadata");
@@ -736,9 +689,8 @@
= }
if (decoded_len > TLS_CRYPT_V2= _MAX_METADATA_LEN - 1)
{
- msg(M_FATAL,
- "ERROR: metadata too l= ong (%d bytes, max %u bytes)",
- decoded_len, TLS_CRYPT_V2_MAX_METADATA_LEN - = 1);
+ msg(= M_FATAL, "ERROR: metadata too long (%d bytes, max %u bytes)", dec= oded_len,
+ = TLS_CRYPT_V2_MAX_METADATA_LEN - 1);
goto= cleanup;
}
ASSERT(buf_in= c_len(&metadata, decoded_len));
@@ -751,18 +703,15 @@
ASSERT(buf_write(&metadata, &timestamp, siz= eof(timestamp)));
}

- tls_crypt_v2_init_server_key(&= server_key, true, server_key_file,
- server_key_inline);- if (!tls_crypt_v2_wrap_clie= nt_key(&dst, &client_key, &metadata, &server_key,- = &gc))
+ = tls_crypt_v2_init_server_key(&server_key, true, server_key_file, serve= r_key_inline);
+ i= f (!tls_crypt_v2_wrap_client_key(&dst, &client_key, &metadata, = &server_key, &gc))
{
= msg(M_FATAL, "ERROR: could not wrap generated client key");
goto cleanup;
}
<= /span>
/* PEM-encode Kc || WKc */
- if (!crypto_pem_encode(tls_crypt_v2_cli_pem_n= ame, &client_key_pem, &dst,
- &gc))
+ if (!crypto_pem_encode(tls_crypt_v2_cli_= pem_name, &client_key_pem, &dst, &gc))
{
msg(M_FATAL, "ERROR: could not PEM-encode clie= nt key");
goto cleanup;
@@ -7= 88,17 +737,15 @@
struct buffer test_wrapped_client_key= ;
struct key2 keydata;
msg(D_GENK= EY, "Testing client-side key loading...");
- tls_crypt_v2_init_client_key(&test_= client_key, &keydata, &test_wrapped_client_key,
- client_f= ile, client_inline);
= + tls_crypt_v2_init_client_key(&test_client_key, &keydata, &= test_wrapped_client_key, client_file,
+ client_inline); free_key_ctx_bi(&test_client_key);

/* Sanity check: unwrap and load client key (as "serve= r") */
- struct= buffer test_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN,
- = &gc);
+ struct buffer test_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX= _METADATA_LEN, &gc);
struct key2 test_client_key2 = =3D { 0 };
free_key_ctx(&server_key);
- tls_crypt_v2_init_server_key(&= amp;server_key, false, server_key_file,

- server_key_inline);

+ tls_crypt_v2_init_se= rver_key(&server_key, false, server_key_file, server_key_inline);
msg(D_GENKEY, "Testing server-side key loading..."= ;);
ASSERT(tls_crypt_v2_unwrap_client_key(&test_cl= ient_key2, &test_metadata,
= test_wrapped_client_key, &server_key));
= diff --git a/src/openvpn/tls_crypt.h b/src/openvpn/tls_crypt.h
index 42545d1..55bb26f 100644

--- a/src/openvpn/tls_cry= pt.h
+++ b/src/openvpn/tls_crypt.h
@@ -86,2= 1 +86,21 @@
#include "session_id.h"
#include "ssl_common.h"


-#define TLS_CRYPT_TAG_SIZE (256/8)
-#define TLS_CRYPT_PID_SIZE = (sizeof(packet_id_type) + sizeof(net_time_t))
-#define TLS_CRYPT_BLOCK_SIZE (128/8)
+#define TLS_CRYPT_TAG_SIZE (256 = / 8)

+#define TLS_CRY= PT_PID_SIZE (sizeof(packet_id_type) + sizeof(net_time_t))
+#define TLS_CRYPT_BLOCK_SIZE (128 /= 8)


#define TLS_CRYPT_OFF_PID (1 + SID_S= IZE)
#define TLS_CRYPT_OFF_TAG (TLS_CRYPT_OFF_PID + TLS_CR= YPT_PID_SIZE)
-#define = TLS_CRYPT_OFF_CT (TLS_CRYPT_OFF_TAG + TLS_CRYPT_TAG_SIZE)
+#define TLS_CRYPT_OFF_CT (TLS_CRYPT_= OFF_TAG + TLS_CRYPT_TAG_SIZE)

-#define TLS_CRYPT_V2_MAX_WKC_LEN (1024)+#define TLS_CRYPT_V2_MAX_WKC_= LEN (1024)
#define TLS_CRYPT_V2_CLIENT_KEY_LEN (2048 / = 8)
#define TLS_CRYPT_V2_SERVER_KEY_LEN (sizeof(struct key)= )
-#define TLS_CRYPT_V2= _TAG_SIZE (TLS_CRYPT_TAG_SIZE)
-#define TLS_CRYPT_V2_MAX_METADATA_LEN (unsigned)(TLS_CRYPT_V2_MAX_= WKC_LEN \
- = - (TLS_CRYPT_V2_CLIENT_KEY_LEN + TLS_C= RYPT_V2_TAG_SIZE \
- = + sizeof(uint16_t)))
+#define TLS_CRYPT_V2_TAG_= SIZE (TLS_CRYPT_TAG_SIZE)
+#define TLS_CRYPT_V2_MAX_METADATA_LEN \
+ (unsigned)(TLS_CRYPT_V2_MAX_WKC_LEN \=
+ - (T= LS_CRYPT_V2_CLIENT_KEY_LEN + TLS_CRYPT_V2_TAG_SIZE + sizeof(uint16_t)))

/**
* Initialize a key_ct= x_bi structure for use with @c --tls-crypt.
@@ -113,8 +113,= 8 @@
* otherwise.
= * @param tls_server Must be set to true is this is a TLS server instance= .
*/
= -void tls_crypt_init_key(struct key_ctx_bi *key, struct key2 *keydata,
- co= nst char *key_file, bool key_inline, bool tls_server);
+void tls_crypt_init_key(struct key_ctx_b= i *key, struct key2 *keydata, const char *key_file,
+ bool key_inline, = bool tls_server);

/**
= * Generates a TLS-Crypt key to be used with dynamic tls-crypt using the
@@ -125,8 +125,7 @@
* @param session sessi= on that will be used for the TLS EKM exporter
* @return = true iff generating the key was successful
*/
-bool
-tls_session_generate_dynamic_tls_crypt_key= (struct tls_session *session);
+bool tls_session_generate_dynamic_tls_crypt_key(struct tls_sessi= on *session);

/**
* Re= turns the maximum overhead (in bytes) added to the destination buffer by
@@ -145,8 +144,7 @@
*
* @= returns true iff wrapping succeeded.
*/
-bool tls_crypt_wrap(const struct buffer= *src, struct buffer *dst,
- struct crypto_options *opt);
+bool tls_crypt_wrap(const struct buffer *= src, struct buffer *dst, struct crypto_options *opt);

/**
* Unwrap a control channel packet (decr= ypts, authenticates and performs
@@ -159,8 +157,7 @@=
* @returns true iff unwrapping succeeded (data authenticated co= rrectly and was
* no replay).
*/=
-bool tls_crypt_unwrap(const = struct buffer *src, struct buffer *dst,
- struct crypto_options *opt);=
+bool tls_crypt_unwrap(cons= t struct buffer *src, struct buffer *dst, struct crypto_options *opt);

/**
* Initialize a tls-cry= pt-v2 server key (used to encrypt/decrypt client keys).
@@ = -174,8 +171,8 @@
* otherwise.=
*
*/
-void tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, boo= l encrypt,
- = const char *key_file, bool key_inline);
+void tls_crypt_v2_init_server_ke= y(struct key_ctx *key_ctx, bool encrypt, const char *key_file,

+ = bool key_inline);


/**
= * Initialize a tls-crypt-v2 client key.
@@ -192,10 +189,9= @@
* @param key_inline True if key_file contains = an inline key, False
* otherwise= .
*/
= -void tls_crypt_v2_init_client_key(struct key_ctx_bi *key,
- stru= ct key2 *original_key,
= - struct buffer *wrapped_key_buf,- = const char *key_file, bool key_inline);
+void tls_crypt_v2_init_client_key(struct key_ctx_bi= *key, struct key2 *original_key,
+ struct buffer *wrapped_key_= buf, const char *key_file,
+ bool key_inline);
=
/**
* Extract a tls-crypt-v2 client ke= y from a P_CONTROL_HARD_RESET_CLIENT_V3
@@ -212,10 +208,8 @= @
*
* @returns true if a key was succes= sfully extracted.
*/
-bool tls_crypt_v2_extract_client_key(struct buffer *buf,
- = struct tls_wrap_ctx *ctx,
- const struct tls_opt= ions *opt,
- = bool initial_packet);
+bool tls_crypt_v2_extract_client_key(struct buf= fer *buf, struct tls_wrap_ctx *ctx,
+ const struct tls_optio= ns *opt, bool initial_packet);

/**
* Generate a tls-crypt-v2 server key, and write to file.
@@ -234,8 +228,7 @@
* @param key_inline = True if key_file contains an inline key, False
* = otherwise.
*/
-void tls_crypt_v2_write_client_key_file(const c= har *filename,
- = const char *b64_metadata,
+void tls_crypt_v2_write_client_key_f= ile(const char *filename, const char *b64_metadata,
= const char *key_file, bool key_inline);

/** @} */
diff --git a/sr= c/openvpn/tun.c b/src/openvpn/tun.c
index d15d9eb6..2703f7b= 100644
--- a/src/openvpn/tun.c
+++ b/src/o= penvpn/tun.c
@@ -85,27 +85,25 @@
#ifdef _WIN32

-const static GUID GUID_DEVCLASS_NET =3D { 0x4d36e972L, 0= xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };=
-const static GUID GUID_DEVIN= TERFACE_NET =3D { 0xcac88484, 0x7515, 0x4c03, { 0x82, 0xe6, 0x71, 0xa8, 0x7= a, 0xba, 0xc3, 0x61 } };
+const static GUID GUID_DEVCLASS_NET =3D {
+ 0x4d36e972L, 0xe325, 0x11ce, { 0xbf, 0xc1, 0= x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 }
+};
+c= onst static GUID GUID_DEVINTERFACE_NET =3D {
+ 0xcac88484, 0x7515, 0x4c03, { 0x82, 0xe6, 0x71= , 0xa8, 0x7a, 0xba, 0xc3, 0x61 }
+};

-/* #define SIMULATE_DHCP_FAILED */ /* simulate bad DHCP n= egotiation */
+/* #de= fine SIMULATE_DHCP_FAILED */ /* simulate bad DHCP negotiation */
=
-#define NI_TES= T_FIRST (1<<0)
-= #define NI_IP_NETMASK (1<<1)
-#define NI_OPTIONS (1<<2)
+#define NI_TEST_FIRST (1 << 0)+#define NI_IP_NETMASK (1 <= ;< 1)
+#define NI_= OPTIONS (1 << 2)

-static void netsh_ifconfig(const struct tuntap_option= s *to,
- = DWORD adapter_index,
- const in_addr_t ip,
- const in_add= r_t netmask,
- = const unsigned int flags);
+static void netsh_ifconfig(const struct tuntap_opt= ions *to, DWORD adapter_index, const in_addr_t ip,
+ const in_addr_t n= etmask, const unsigned int flags);

-static void windows_set_mtu(const int iface= _index,
- = const short family,
- const int mtu);
+static void windows_set_mtu(const int i= face_index, const short family, const int mtu);
-static void netsh_set_dns6_serv= ers(const struct in6_addr *addr_list,
- const int addr_len,
+static void netsh_set_dn= s6_servers(const struct in6_addr *addr_list, const int addr_len,
= DWORD adapter_index);
<= span>

static void netsh_command(const struct argv *a, int= n, int msglevel);
@@ -122,15 +120,10 @@
= struct gc_arena gc =3D gc_new();
HANDLE pipe =3D tt= ->options.msg_channel;

- address_message_t addr =3D {
- .header =3D {
- (add ? msg_add_address : msg_d= el_address),
- = sizeof(address_message_t),
- 0
-= },
- .fa= mily =3D family,
- = .iface =3D { .index =3D tt->adapter_index, .name =3D "" }
- };
+ address_message_t addr =3D { .he= ader =3D { (add ? msg_add_address : msg_del_address),
+ = sizeof(address_message_t), 0 },
+ .family =3D family,
= + = .iface =3D { .index =3D tt->adapter_index, .name =3D "" } };<= /span>

if (addr.iface.index =3D=3D TUN_ADAP= TER_INDEX_INVALID)
{
@@ -142,16 +135,1= 4 @@
{
addr.address.ipv4.s_ad= dr =3D htonl(tt->local);
addr.prefix_len =3D ne= tmask_to_netbits2(tt->adapter_netmask);
- msg(D_IFCONFIG, "INET address service: %s= %s/%d",
- = add ? "add" : "remove",
+ msg(D_IFCONFIG, "INET address serv= ice: %s %s/%d", add ? "add" : "remove",
= print_in_addr_t(tt->local, 0, &gc), addr.prefix_l= en);
}
else
= {
addr.address.ipv6 =3D tt->local_ipv6;<= br> addr.prefix_len =3D (tt->type =3D=3D DEV_TYPE_TUN) ? 1= 28 : tt->netbits_ipv6;
- msg(D_IFCONFIG, "INET6 address service: %s %s/%d",
- add ? "= add" : "remove",
+ msg(D_IFCONFIG, "INET6 address service: %s %s/%d&q= uot;, add ? "add" : "remove",
= print_in6_addr(tt->local_ipv6, 0, &gc), addr.prefix_len);=
}

@@ -163,8 +154,8 @@
if (ack.error_number !=3D NO_ERROR)
{=
msg(M_WARN, "TUN: %s address failed using se= rvice: %s [status=3D%u if_index=3D%d]",
- (add ? "adding" : "deleti= ng"), strerror_win32(ack.error_number, &gc),
- ack.error_number, addr.iface.in= dex);
+ (a= dd ? "adding" : "deleting"), strerror_win32(ack.error_n= umber, &gc), ack.error_number,
+ addr.iface.index);
goto= out;
}

@@ -190,15 += 181,11 @@

/* Use dns_cfg_msg with ad= dr_len =3D 0 for setting only the DOMAIN */
dns_cfg_me= ssage_t dns =3D {
- = .header =3D {
- = (add ? msg_add_dns_cfg : msg_del_dns_cfg),
- sizeof(dns_cfg_message_t),<= br>- 0
- },

+ .header =3D { (add ? msg_add_dns_cfg := msg_del_dns_cfg), sizeof(dns_cfg_message_t), 0 },
= .iface =3D { .index =3D tt->adapter_index, .name =3D "" },
- .domains =3D &qu= ot;", /* set below */
- .family =3D AF_INET, /* unused */
- .addr_len =3D 0 /* add/delete= only the domain, not DNS servers */
+ .domains =3D "", /* set below */
+ .family =3D AF_= INET, /* unused */
+ = .addr_len =3D 0 /* add/delete only the domain, not DNS servers = */
};

/* interf= ace name is required */
@@ -238,8 +225,8 @@
if (ack.error_number !=3D NO_ERROR)

{
= msg(M_WARN, "TUN: %s DNS domains failed using service: = %s [status=3D%u if_name=3D%s]",
- (add ? "adding" : "deleting"= ), strerror_win32(ack.error_number, &gc),
- ack.error_number, dns.iface.name);
+ (add ? "= ;adding" : "deleting"), strerror_win32(ack.error_number, &am= p;gc), ack.error_number,
+ dns.iface.name);
goto out;=
}

@@ -266,17 +253,12 @@
}

/* Use dns_cfg_= msg with domain =3D "" for setting only the DNS servers */=
- dns_cfg_message_t dns = =3D {
- .header = =3D {
- (add= ? msg_add_dns_cfg : msg_del_dns_cfg),
- sizeof(dns_cfg_message_t),
- 0
- },
- .iface =3D { .index =3D tt->adapter_index, .name = =3D "" },
- = .domains =3D "",
- .family =3D family,
- .addr_len =3D addr_len
- };
+ dns_cfg_message_t dns =3D { .header =3D { (add ? msg_add_d= ns_cfg : msg_del_dns_cfg),
+ sizeof(dns_cfg_message_t),= 0 },
+ = .iface =3D { .index =3D tt->adapter_index, .name =3D &qu= ot;" },
+ = .domains =3D "",
+ .family =3D fam= ily,
+ = .addr_len =3D addr_len };

= /* interface name is required */
strncpy(dns.ifac= e.name, tt->actual_name, sizeof(dns.iface.name));
@@ -28= 6,8 +268,8 @@
{
addr_len =3D = _countof(dns.addr);
dns.addr_len =3D addr_len;
- msg(M_WARN, "= ;Number of %s DNS addresses sent to service truncated to %d",- ip_proto_name, add= r_len);
+ msg(= M_WARN, "Number of %s DNS addresses sent to service truncated to %d&qu= ot;, ip_proto_name,
+= addr_len);
}

<= span> for (int i =3D 0; i < addr_len; ++i)

@@ -338,1= 5 +320,10 @@
goto out;
}

- wins= _cfg_message_t wins =3D {
- .header =3D {
- (add ? msg_add_wins_cfg : msg_del_wins_cfg),
- sizeof(wins_cfg_message_= t),

- 0
- },
- .iface =3D {.index =3D tt->= ;adapter_index, .name =3D "" },

- .addr_len =3D addr_len
- };
+ wins_cfg_message_t wins =3D { .header =3D { (add ? msg_= add_wins_cfg : msg_del_wins_cfg),
+ sizeof(wins_cfg_m= essage_t), 0 },
+ = .iface =3D { .index =3D tt->adapter_index, .= name =3D "" },
+ .addr_len =3D addr_len };

/* interface name is required */
strncpy(wins.iface.name, tt->actual_name, sizeof(wins.iface.name))= ;

@@ -356,8 +333,7 @@
{
addr_len =3D _countof(wins.addr);

wins.= addr_len =3D addr_len;
= - msg(M_WARN, "Number of WINS addresses sent to service truncat= ed to %d",
- = addr_len);
+ = msg(M_WARN, "Number of WINS addresses sent to service truncated t= o %d", addr_len);
}

<= span> for (int i =3D 0; i < addr_len; ++i)

@@ -376,8= +352,8 @@
if (ack.error_number !=3D NO_ERROR)<= br> {
msg(M_WARN, "TUN: %s WINS fai= led using service: %s [status=3D%u if_name=3D%s]",
- (add ? "adding" : &= quot;deleting"), strerror_win32(ack.error_number, &gc),
= - ack.error_number, wi= ns.iface.name);
+ = (add ? "adding" : "deleting"), strerror_win32(a= ck.error_number, &gc), ack.error_number,
+ wins.iface.name);
= goto out;
}

@@ = -395,20 +371,15 @@
struct gc_arena gc =3D gc_new();
HANDLE pipe =3D tt->options.msg_channel;
const char *family_name =3D (family =3D=3D AF_INET6) ? "IPv6&= quot; : "IPv4";

- set_mtu_message_t mtu_msg =3D {
- .header =3D {
- msg_set_mtu,
- sizeof(set_mtu_message_t),
- 0

- },
- .iface =3D {.index =3D tt->adapter_index},<= /span>
- .mtu =3D mtu,<= /span>
- .family =3D fa= mily
- };
= + set_mtu_message_t mtu_msg = =3D { .header =3D { msg_set_mtu, sizeof(set_mtu_message_t), 0 },
= + = .iface =3D { .index =3D tt->adapter_index },
+ .mtu = =3D mtu,
+ = .family =3D family };
strncpynt= (mtu_msg.iface.name, tt->actual_name, sizeof(mtu_msg.iface.name));
if (family =3D=3D AF_INET6 && mtu < 1280)=
{
- = msg(M_INFO, "NOTE: IPv6 interface MTU < 1280 conflicts with IETF= standards and might not work");
+ msg(M_INFO,
+ "NOTE: IPv6 interface MTU < 1280 conf= licts with IETF standards and might not work");
}=

if (!send_msg_iservice(pipe, &m= tu_msg, sizeof(mtu_msg), &ack, "Set_mtu"))
@@= -419,11 +390,13 @@
if (ack.error_number !=3D NO_ERROR= )
{
msg(M_NONFATAL, "TUN= : setting %s mtu using service failed: %s [status=3D%u if_index=3D%d]"= ,
- family_n= ame, strerror_win32(ack.error_number, &gc), ack.error_number, mtu_msg.i= face.index);
+ = family_name, strerror_win32(ack.error_number, &gc), ack.error_numb= er,
+ mtu_= msg.iface.index);
}
else {
- = msg(M_INFO, "%s MTU set to %d on interface %d using service", fa= mily_name, mtu, mtu_msg.iface.index);
+ msg(M_INFO, "%s MTU set to %d on interface %= d using service", family_name, mtu,
+ mtu_msg.iface.index);
= ret =3D true;
}

@@ -442,7 +415,8 @@


struct argv arg= v =3D argv_new();
argv_printf(&argv, "%s%s ni= cconfig where (InterfaceIndex=3D%ld) call SetDNSDomain '%s'",<= /span>
- get_wi= n_sys_path(), WMIC_PATH_SUFFIX, tt->adapter_index, add ? tt->options.= domain : "");
+ get_win_sys_path(), WMIC_PATH_SUFFIX, tt->adapter_in= dex,
+ = add ? tt->options.domain : "");
exec_com= mand("WMIC", &argv, 1, M_WARN);

<= span> argv_free(&argv);

@@ -480,12 +454,7 @@=
}

create_adapter_mess= age_t msg =3D {
- = .header =3D {
- = msg_create_adapter,
- sizeof(create_adapter_message_t),
- 0
- },
- .adapter_type =3D t
+ .header =3D { msg_create_adapter, sizeof(create_ad= apter_message_t), 0 }, .adapter_type =3D t
};
if (!send_msg_iservice(msg_channel, &msg= , sizeof(msg), &ack, "create_adapter"))
@@ -4= 96,7 +465,8 @@
if (ack.error_number !=3D NO_ERROR)
{
msg(M_NONFATAL, "TUN: cre= ating %s adapter using service failed: %s [status=3D%u]",
- print_tun_backend_driv= er(driver_type), strerror_win32(ack.error_number, &gc), ack.error_numbe= r);

+ prin= t_tun_backend_driver(driver_type), strerror_win32(ack.error_number, &gc= ),
+ ack.e= rror_number);
}
else
{

@@ -512,7 +482,8 @@
#endif /* i= fdef _WIN32 */

#ifdef TARGET_SOLARIS
-static void solaris_error= _close(struct tuntap *tt, const struct env_set *es, const char *actual, boo= l unplumb_inet6);
+st= atic void solaris_error_close(struct tuntap *tt, const struct env_set *es, = const char *actual,
+= bool unplumb_inet6);

#include <stropts.h>
#endif
<= span>@@ -583,10 +554,7 @@

* before the device is actually= opened.
*/
const char *
-guess_tuntap_dev(const char *dev,
- const ch= ar *dev_type,
- = const char *dev_node,
- struct gc_arena *gc)
+guess_tuntap_dev(const char *dev, const char *de= v_type, const char *dev_node, struct gc_arena *gc)
{

#ifdef _WIN32
const int dt =3D dev_type_en= um(dev, dev_type);
@@ -620,16 +588,17 @@
= {
if (looks_like_netmask)
= {
- msg(= M_WARN, "WARNING: Since you are using --dev tun with a point-to-point = topology, the second argument to --ifconfig must be an IP address. You are= using something (%s) that looks more like a netmask. %s",
<= span style=3D"color: hsl(0, 100%, 40%);">- print_in_addr_t(a= ddr, 0, &gc),

- = ifconfig_warn_how_to_silence);
+ msg(M_WARN,
+ "WARNING: Since you are usi= ng --dev tun with a point-to-point topology, the second argument to --ifcon= fig must be an IP address. You are using something (%s) that looks more li= ke a netmask. %s",
+ print_in_addr_t(addr, 0, &gc), ifconfig_warn_how_to= _silence);
}
}
else

{
if (!looks_like= _netmask)
{
- msg(M_WARN, "WARNING: Since you are using s= ubnet topology, the second argument to --ifconfig must be a netmask, for ex= ample something like 255.255.255.0. %s",
+ msg(M_WARN,
+ "WARNING: Since you are = using subnet topology, the second argument to --ifconfig must be a netmask,= for example something like 255.255.255.0. %s",
= ifconfig_warn_how_to_silence);
}=
}
@@ -641,10 +610,7 @@
* c= lash with ifconfig addresses or subnet.
*/
static void

-check_a= ddr_clash(const char *name,
- int type,
- in_addr_t public,
- in_addr_t local,
+check_addr_clash(const char *name, in= t type, in_addr_t public, in_addr_t local,
= in_addr_t remote_netmask)
{
struct = gc_arena gc =3D gc_new();
@@ -661,7 +627,7 @@
if (type =3D=3D DEV_TYPE_TUN)

{=
const in_addr_t test_netmask =3D 0xFFFFFF00;<= br>- const in_addr_t p= ublic_net =3D public &test_netmask;
+ const in_addr_t public_net =3D public &= test_netmask;
const in_addr_t local_net =3D l= ocal & test_netmask;
const in_addr_t remot= e_net =3D remote_netmask & test_netmask;

@@ -669,37 +635,28 @@

{
= msg(M_WARN,
"WARNI= NG: --%s address [%s] conflicts with --ifconfig address pair [%s, %s]. %s&q= uot;,
- = name,
- = print_in_addr_t(public, 0, &gc),
- print_in_addr_t(local, 0, &g= c),
- = print_in_addr_t(remote_netmask, 0, &gc),
- ifconfig_warn_how_to_silence);=
+ = name, print_in_addr_t(public, 0, &gc), print_in_addr_t(local, 0, &= gc),
+ = print_in_addr_t(remote_netmask, 0, &gc), ifconfig_warn_how_to_sile= nce);
}

= if (public_net =3D=3D local_net || public_net =3D=3D remote_net)
{
msg(M_WARN,<= /span>
"WARNING: potential conflict betw= een --%s address [%s] and --ifconfig address pair [%s, %s] -- this is a war= ning only that is triggered when local/remote addresses exist within the sa= me /24 subnet as --ifconfig endpoints. %s",
- name,
- print_in_addr_t(public,= 0, &gc),
- = print_in_addr_t(local, 0, &gc),
- print_in_addr_t(remote_netmas= k, 0, &gc),
- = ifconfig_warn_how_to_silence);
+ name, print_in_addr_t(public, = 0, &gc), print_in_addr_t(local, 0, &gc),
+ print_in_addr_t(remote_net= mask, 0, &gc), ifconfig_warn_how_to_silence);
= }
}
else if (type =3D= =3D DEV_TYPE_TAP)
{
- const in_addr_t public_network =3D publi= c &remote_netmask;
- name,
- print_= in_addr_t(public, 0, &gc),
- print_in_addr_t(local, 0, &gc),
= - print_in_add= r_t(remote_netmask, 0, &gc),
- ifconfig_warn_how_to_silence);
+ name, print_i= n_addr_t(public, 0, &gc), print_in_addr_t(local, 0, &gc),
+ print_in_= addr_t(remote_netmask, 0, &gc), ifconfig_warn_how_to_silence); }
}
}
@@ -711,7 +668,7 @@
{
s= truct gc_arena gc =3D gc_new();
struct route_gateway_i= nfo rgi;
- const uns= igned int needed =3D (RGI_ADDR_DEFINED|RGI_NETMASK_DEFINED);
+ const unsigned int needed =3D = (RGI_ADDR_DEFINED | RGI_NETMASK_DEFINED);


get_default_gateway(&rgi, 0, ctx);

if ((rgi.= flags & needed) =3D=3D needed)
@@ -719,7 +676,8 @@
const in_addr_t lan_network =3D rgi.gateway.addr &= rgi.gateway.netmask;
if (lan_network =3D=3D 0xC0A= 80000 || lan_network =3D=3D 0xC0A80100)
{- msg(M_WARN, "= NOTE: your local LAN uses the extremely common subnet address 192.168.0.x o= r 192.168.1.x. Be aware that this might create routing conflicts if you co= nnect to the VPN server from public locations such as internet cafes that u= se the same subnet.");
+ msg(M_WARN,
+ "NOTE: your local LAN uses the extremely c= ommon subnet address 192.168.0.x or 192.168.1.x. Be aware that this might = create routing conflicts if you connect to the VPN server from public locat= ions such as internet cafes that use the same subnet.");
}

}
gc_free(&gc);=
@@ -737,8 +695,7 @@
{
if (!is_tun_p2p(tt))

{
- buf_printf(&out, "= %s %s",
- = print_in_addr_t(tt->local & tt->remote_netmask, 0, = gc),
+ buf= _printf(&out, "%s %s", print_in_addr_t(tt->local & tt-= >remote_netmask, 0, gc),
print_i= n_addr_t(tt->remote_netmask, 0, gc));
}<= br> else if (tt->type =3D=3D DEV_TYPE_TUN) /* tun p2p topo= logy */
@@ -775,20 +732,16 @@
{=
if (rwflags & EVENT_READ)
{=
- buf_print= f(&out, "T%s",
- (tt->rwflags_debug & EVENT_READ) ? &qu= ot;R" : "r");
+ buf_printf(&out, "T%s", (tt->rwflags_= debug & EVENT_READ) ? "R" : "r");
= #ifdef _WIN32
- = buf_printf(&out, "%s",
- overlapped_io_state_ascii(&tt= ->reads));
+ = buf_printf(&out, "%s", overlapped_io_state_ascii(&t= t->reads));
#endif
} if (rwflags & EVENT_WRITE)
{
- buf_printf(= &out, "T%s",
- (tt->rwflags_debug & EVENT_WRITE) ? &quo= t;W" : "w");
+ buf_printf(&out, "T%s", (tt->rwflags_d= ebug & EVENT_WRITE) ? "W" : "w");
= #ifdef _WIN32
- = buf_printf(&out, "%s",
- overlapped_io_state_ascii(&tt= ->writes));
+ = buf_printf(&out, "%s", overlapped_io_state_ascii(&= tt->writes));
#endif
}<= br> }
@@ -807,8 +760,7 @@
{
bool tun_p2p =3D false;

- if (tt->type =3D=3D DEV_TYPE_TA= P
- || (tt->t= ype =3D=3D DEV_TYPE_TUN && tt->topology =3D=3D TOP_SUBNET))
+ if (tt->type =3D= =3D DEV_TYPE_TAP || (tt->type =3D=3D DEV_TYPE_TUN && tt->topo= logy =3D=3D TOP_SUBNET))
{
tu= n_p2p =3D false;
}
@@ -818,7 +770,8 @@=
}
else
{
- msg(M_FATAL, &qu= ot;Error: problem with tun vs. tap setting"); /* JYFIXME -- needs to b= e caught earlier, in init_tun? */
+ msg(M_FATAL, "Error: problem with tun vs. tap se= tting"); /* JYFIXME -- needs to be caught
+ = earlier, in init_tun? */
}<= br> return tun_p2p;
}
@@ -871,20= +824,16 @@
* but don't execute yet.
= */
struct tuntap *
-init_tun(const char *dev, /* --dev option */<= br>- const char *dev_type= , /* --dev-type option */
- int topology, /* one of the TOP_x values */=
- const char *ifconfi= g_local_parm, /* --ifconfig parm 1 */
- const char *ifconfig_remote_netmask_parm= , /* --ifconfig parm 2 */
- const char *ifconfig_ipv6_local_parm, /* --ifconfig parm= 1 IPv6 */
+init_tun(= const char *dev, /* --dev option */
+ const char *dev_type, = /* --dev-type option */

+ int topology, /* = one of the TOP_x values */
+ const char *ifconfig_local_parm, /* --ifconfig par= m 1 */
+ cons= t char *ifconfig_remote_netmask_parm, /* --ifconfig parm 2 */
+ const char *ifconfig_ipv= 6_local_parm, /* --ifconfig parm 1 IPv6 */

in= t ifconfig_ipv6_netbits_parm,
- const char *ifconfig_ipv6_remote_parm, /* --ifconfig p= arm 2 IPv6 */
- = struct addrinfo *local_public,
- struct addrinfo *remote_public,
- const bool strict_warn,
- struct env_set *es,
=
- openvpn_net_ctx_t *= ctx,
- struct t= untap *tt)
+ = const char *ifconfig_ipv6_remote_parm, /* --ifconfig parm 2 IPv6 */
+ struct addrinfo= *local_public, struct addrinfo *remote_public, const bool strict_warn,
+ struct env_set= *es, openvpn_net_ctx_t *ctx, struct tuntap *tt)
{<= br> if (!tt)
{
@@ -906,25 +8= 55,13 @@
* Convert arguments to binary IPv4 addre= sses.
*/

- tt->local =3D getaddr(- GETADDR_RESOLVE
- | GETADDR_HOS= T_ORDER
- | = GETADDR_FATAL_ON_SIGNAL
- | GETADDR_FATAL,
- ifconfig_local_parm,
- 0,
- NULL,
- NULL);
+ tt->local =3D
+ getaddr(GETADDR_RESOLVE | GETADDR_HOST_ORDER | GET= ADDR_FATAL_ON_SIGNAL | GETADDR_FATAL,
+ ifconfig_local_parm, 0, NULL, NULL);<= /span>

- = tt->remote_netmask =3D getaddr(
- (tun_p2p ? GETADDR_RESOLVE : 0)
- | GETADDR_HOST_ORDER
- | GETADDR_FAT= AL_ON_SIGNAL
- = | GETADDR_FATAL,
- = ifconfig_remote_netmask_parm,
- 0,
- NULL,
- NULL);
+ tt->remote_netmask =3D getaddr((tun_p2p ? GETADDR_RESOLVE = : 0) | GETADDR_HOST_ORDER
+ | GETADDR_FATAL_ON_SIGNAL | = GETADDR_FATAL,
+ = ifconfig_remote_netmask_parm, 0, NULL, NULL= );

/*
= * Look for common errors in --ifconfig parms
@@ -943,12 +88= 0,9 @@
{
if (= curele->ai_family =3D=3D AF_INET)
{
- const= in_addr_t local =3D ntohl(((struct sockaddr_in *)curele->ai_addr)->s= in_addr.s_addr);
- = check_addr_clash("local",
- tt->ty= pe,
- = local,
- tt->local,
- tt-&g= t;remote_netmask);
+ = const in_addr_t local =3D
+ ntohl(((struct sockaddr_in= *)curele->ai_addr)->sin_addr.s_addr);
+ check_addr_clash("local&q= uot;, tt->type, local, tt->local, tt->remote_netmask);
<= span> }

}

@@ -956,12 +890,9 @@
{ if (curele->ai_family =3D=3D AF_INET)
= {
- check_addr_clash("remote&q= uot;,
- = tt->type,
- remote,
- tt-= >local,
- = tt->remote_netmask);
+ const in_addr_t remote = =3D
+ = ntohl(((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_add= r);
+ = check_addr_clash("remote", tt->type, remote, tt->local,= tt->remote_netmask);
}
}

}
@@ -987,15 +918,= 15 @@

if (ifconfig_ipv6_local_parm &= amp;& ifconfig_ipv6_remote_parm)
{
-

/* * Convert arguments to binary IPv6 addresses.
<= span> */


- if (inet_pton( AF_INET6, ifconfig_ipv6_local_parm, &a= mp;tt->local_ipv6 ) !=3D 1
- || inet_pton( AF_INET6, ifconfig_ipv6_remote_parm, &= ;tt->remote_ipv6 ) !=3D 1)
+ if (inet_pton(AF_INET6, ifconfig_ipv6_local_parm, &tt= ->local_ipv6) !=3D 1
+ || inet_pton(AF_INET6, ifconfig_ipv6_remote_parm, &tt-&= gt;remote_ipv6) !=3D 1)
{
- msg( M_FATAL, "init_tun: prob= lem converting IPv6 ifconfig addresses %s and %s to binary", ifconfig_= ipv6_local_parm, ifconfig_ipv6_remote_parm );
+ msg(M_FATAL, "init_tun: problem = converting IPv6 ifconfig addresses %s and %s to binary",
+ ifconfig_ipv6_loc= al_parm, ifconfig_ipv6_remote_parm);

}
<= span> tt->netbits_ipv6 =3D ifconfig_ipv6_netbits_parm;

@@ -1017,9 +948,7 @@
* Platform = specific tun initializations
*/
void
-init_tun_post(struct tunt= ap *tt,
- = const struct frame *frame,
- const struct tuntap_options *options)
+init_tun_post(struct tuntap *tt, const= struct frame *frame, const struct tuntap_options *options)
{

tt->options =3D *options;
#ifd= ef _WIN32
@@ -1046,8 +975,7 @@
* -> he= lper function to simplify code below
*/
= static void
-add_route_= connected_v6_net(struct tuntap *tt,
- const struct env_set *es)+add_route_connected_v6_net(s= truct tuntap *tt, const struct env_set *es)
{
struct route_ipv6 r6;


@@ -1055,8= +983,8 @@
r6.network =3D tt->local_ipv6; r6.netbits =3D tt->netbits_ipv6;
r6.gat= eway =3D tt->local_ipv6;
- r6.metric =3D 0; /* connected route */
- r6.flags =3D RT_DEFIN= ED | RT_METRIC_DEFINED;
+ r6.metric =3D 0; /* connected route */
+ r6.flags =3D RT_DEFINED | RT_METRIC_DEFINED;=
add_route_ipv6(&r6, tt, 0, es, NULL);
<= span> }


@@ -1069,15 +997,16 @@
= r6.network =3D tt->local_ipv6;
r6.netbit= s =3D tt->netbits_ipv6;
r6.gateway =3D tt->local= _ipv6;
- r6.metric = =3D 0; /* connected route */
- r6.flags =3D RT_DEFINED | RT_ADDED | RT_ME= TRIC_DEFINED;
+ r6= .metric =3D 0; /* connected route */
+ r6.flags =3D RT_DEFINED | RT_ADDED | RT_METRIC_DEFINED= ;
route_ipv6_clear_host_bits(&r6);
delete_route_ipv6(&r6, tt, NULL, NULL);

}=
-#endif /* if defined(_WIN32)= || defined(TARGET_DARWIN) || defined(TARGET_NETBSD) || defined(TARGET_OPEN= BSD) */
+#endif /* if= defined(_WIN32) || defined(TARGET_DARWIN) || defined(TARGET_NETBSD) || \
+ defined(TAR= GET_OPENBSD) */

-#if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \
- || defined(TARGET_NET= BSD) || defined(TARGET_OPENBSD)
+#if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || def= ined(TARGET_NETBSD) \
+ || defined(TARGET_OPENBSD)
/* we can't use true = subnet mode on tun on all platforms, as that
* conflicts = with IPv6 (wants to use ND then, which we don't do),
= * but the OSes want "a remote address that is different from ours"= ;
@@ -1088,11 +1017,11 @@
*/

in_addr_t
-create_arbitrary_remote( struct tuntap *tt )
+create_arbitrary_remote(struct tuntap *= tt)
{
in_addr_t remote;

- remote =3D (t= t->local & tt->remote_netmask) +1;
+ remote =3D (tt->local & tt->remote_n= etmask) + 1;

if (remote =3D=3D tt-&g= t;local)
{
@@ -1113,8 +1042,8 @@
* @param ctx the networking API opaque context */
static void
-do_ifconfig_ipv6(struct tuntap *tt, const char *ifname, = int tun_mtu,
- = const struct env_set *es, openvpn_net_ctx_t *ctx)
+do_ifconfig_ipv6(struct tuntap *tt, c= onst char *ifname, int tun_mtu, const struct env_set *es,
+ openvpn_net_ctx_t *c= tx)
{
#if !defined(TARGET_LINUX) struct argv argv =3D argv_new();
@@ -1133,16 += 1062,14 @@
msg(M_FATAL, "Linux can't brin= g %s up", ifname);
}

= - if (net_addr_v6_add(ctx, ifn= ame, &tt->local_ipv6,
- tt->netbits_ipv6) < 0)
+ if (net_addr_v6_add(ctx, ifname= , &tt->local_ipv6, tt->netbits_ipv6) < 0)

= {
msg(M_FATAL, "Linux can't add IPv6 to = interface %s", ifname);
}
#elif = defined(TARGET_ANDROID)
char out6[64];

- snprintf(out6, = sizeof(out6), "%s/%d %d",
- ifconfig_ipv6_local, tt->netbits_ipv6, tun_mt= u);
+ snprintf(out= 6, sizeof(out6), "%s/%d %d", ifconfig_ipv6_local, tt->netbits_= ipv6, tun_mtu);
management_android_control(management,= "IFCONFIG6", out6);
#elif defined(TARGET_SOLARI= S)
argv_printf(&argv, "%s %s inet6 unplumb&qu= ot;, IFCONFIG_PATH, ifname);
@@ -1153,9 +1080,8 @@ {
const char *ifconfig_ipv6_remote = =3D print_in6_addr(tt->remote_ipv6, 0, &gc);

- argv_printf(&ar= gv, "%s %s inet6 plumb %s/%d %s mtu %d up",
- IFCONFIG_PATH, ifname, = ifconfig_ipv6_local,
- = tt->netbits_ipv6, ifconfig_ipv6_remote, tun_mtu);
+ argv_printf(&am= p;argv, "%s %s inet6 plumb %s/%d %s mtu %d up", IFCONFIG_PATH, if= name,
+ = ifconfig_ipv6_local, tt->netbits_ipv6, ifconfig_ipv6_remote, tun_m= tu);
}
else /* tap mode */=
{
@@ -1163,8 +1089,7 @@
= argv_printf(&argv, "%s %s inet6 plumb up", IFCONFIG_PATH= , ifname);
argv_msg(M_INFO, &argv);
=
- if (!o= penvpn_execve_check(&argv, es, 0,
- "Solaris ifconfig IP= v6 (prepare) failed"))
+ if (!openvpn_execve_check(&argv, es, 0, "Solaris i= fconfig IPv6 (prepare) failed"))
{
= solaris_error_close(tt, es, ifname, true);
}

@@ -1178,8 +1103,8 @@
= /* static IPv6 addresses need to go to a subinterface (tap0:1)
= * and we cannot set an mtu here (must go to the "paren= t")
*/
- argv_printf(&argv, "%s %s inet6 addif %s/%= d up", IFCONFIG_PATH,
- ifname, ifconfig_ipv6_local, tt->netbits_ipv6 )= ;
+ argv_print= f(&argv, "%s %s inet6 addif %s/%d up", IFCONFIG_PATH, ifname,= ifconfig_ipv6_local,
+ tt->netbits_ipv6);
} argv_msg(M_INFO, &argv);

@@ -1190,23 +1115,19 @@


if (tt->= type !=3D DEV_TYPE_TUN)
{
- argv_printf(&argv, "%s %s inet6 m= tu %d", IFCONFIG_PATH,
- ifname, tun_mtu);
+ argv_printf(&argv, "%s %s inet6 mt= u %d", IFCONFIG_PATH, ifname, tun_mtu);
argv_= msg(M_INFO, &argv);
openvpn_execve_check(&= argv, es, 0, "Solaris ifconfig IPv6 mtu failed");
}

-#elif defined(= TARGET_OPENBSD) || defined(TARGET_NETBSD) \
- || defined(TARGET_DARWIN) || defined(TARGET_FREEB= SD) \
- || defined(T= ARGET_DRAGONFLY)
- a= rgv_printf(&argv, "%s %s inet6 %s/%d mtu %d up", IFCONFIG_PAT= H, ifname,
- = ifconfig_ipv6_local, tt->netbits_ipv6, tun_mtu);
+#elif defined(TARGET_OPENBSD) || defin= ed(TARGET_NETBSD) || defined(TARGET_DARWIN) \
+ || defined(TARGET_FREEBSD) || defined(TARGET_= DRAGONFLY)
+ argv_= printf(&argv, "%s %s inet6 %s/%d mtu %d up", IFCONFIG_PATH, i= fname, ifconfig_ipv6_local,
+ tt->netbits_ipv6, tun_mtu);
= argv_msg(M_INFO, &argv);

- openvpn_execve_check(&argv, es, S_FATAL,<= /span>
- = "generic BSD ifconfig inet6 failed");
+ openvpn_execve_check(&argv, es, S_FA= TAL, "generic BSD ifconfig inet6 failed");

-#if defined(TARGET_FREEBSD= ) && __FreeBSD_version >=3D 1200000 \
- && __FreeBSD_version < 1300000
+#if defined(TARGET_FRE= EBSD) && __FreeBSD_version >=3D 1200000 && __FreeBSD_ver= sion < 1300000
/* On FreeBSD 12.0-12.4, there is ip= v6_activate_all_interfaces=3D"YES"
* in rc.= conf, which is not set by default. If it is *not* set,
= * "all new interfaces that are not already up" are configured = by
@@ -1225,27 +1146,26 @@
argv_printf= (&argv, "%s %s inet6 -ifdisabled", IFCONFIG_PATH, ifname);
argv_msg(M_INFO, &argv);
- openvpn_execve_check(&a= rgv, es, S_FATAL,
- = "FreeBSD BSD 'ifconfig inet6 -ifdisabled'= failed");
+ = openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD BSD 'ifconfi= g inet6 -ifdisabled' failed");
#endif
<= span>

#elif defined(TARGET_AIX)
- argv_printf(&argv, "%s %s inet6 %s= /%d mtu %d up", IFCONFIG_PATH, ifname,
- ifconfig_ipv6_local, tt->netbits_i= pv6, tun_mtu);
+ a= rgv_printf(&argv, "%s %s inet6 %s/%d mtu %d up", IFCONFIG_PAT= H, ifname, ifconfig_ipv6_local,
+ tt->netbits_ipv6, tun_mtu);
= argv_msg(M_INFO, &argv);

/*= AIX ifconfig will complain if it can't find ODM path in env */<= br> es =3D env_set_create(NULL);
env_set_add= (es, "ODMDIR=3D/etc/objrepos");

- openvpn_execve_check(&argv, e= s, S_FATAL,

- = "generic BSD ifconfig inet6 failed");
+ openvpn_execve_check(&ar= gv, es, S_FATAL, "generic BSD ifconfig inet6 failed");

=
env_set_destroy(es);
-#elif defined (_WIN32)
+#elif defined(_WIN32)
i= f (tt->options.ip_win32_type =3D=3D IPW32_SET_MANUAL)
= {
- msg(M_INF= O, "******** NOTE: Please manually set the v6 IP of '%s' to %= s (if it is not already set)",
+ msg(M_INFO,
+ "******** NOTE: Please manually set the v= 6 IP of '%s' to %s (if it is not already set)",
ifname, ifconfig_ipv6_local);

}<= br> else if (tt->options.msg_channel)
@@ -1276= ,8 +1196,8 @@
int netbits =3D (tt->type =3D=3D = DEV_TYPE_TUN) ? 128 : tt->netbits_ipv6;

argv_printf(&argv, "%s%s interface ipv6 set address %lu= %s/%d store=3Dactive",

- get_win_sys_path(), NETSH_PATH_SUFFIX, tt->ad= apter_index,
- = ifconfig_ipv6_local, netbits);
+ get_win_sys_path(), NETSH_PATH_SU= FFIX, tt->adapter_index, ifconfig_ipv6_local,
+ netbits);
= netsh_command(&argv, 4, M_FATAL);
if = (tt->type =3D=3D DEV_TYPE_TUN)
{
@@ -1292,8 +1212,9 @@

do_dns_domain_wmic(tru= e, tt);
}
}
-#else /* platforms we have no IPv6 code= for */
- msg(M_FATA= L, "Sorry, but I don't know how to do IPv6 'ifconfig' comm= ands on this operating system. You should ifconfig your TUN/TAP device man= ually or use an --up script.");
+#else /* platforms we have no IPv6 code for */
= + msg(M_FATAL,
+ "Sorry, but I don= 9;t know how to do IPv6 'ifconfig' commands on this operating syste= m. You should ifconfig your TUN/TAP device manually or use an --up script.= ");

#endif /* outer "if defined(TARGET_xxx)"= ; conditional */

#if !defined(TARGET_LIN= UX)
@@ -1312,8 +1233,8 @@
* @param ctx = the networking API opaque context
*/
= static void
-do_ifconf= ig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
- const struct env_set= *es, openvpn_net_ctx_t *ctx)

+do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_m= tu, const struct env_set *es,
+ openvpn_net_ctx_t *ctx)
{
#if !defined(_WIN32) && !defined(TARGET_ANDROID)=
/*
@@ -1348,16 +1269,14 @@
=
if (tun_p2p)
{
- if (net_addr_ptp_v4_add(ctx, if= name, &tt->local,
+ if (net_addr_ptp= _v4_add(ctx, ifname, &tt->local, &tt->remote_netmask) < 0)=
{
msg(M_FATAL, "= ;Linux can't add IP to interface %s", ifname);
= }
}
else
= {
- if (net_a= ddr_v4_add(ctx, ifname, &tt->local,
- netmask_to_netbits2(tt->= ;remote_netmask)) < 0)
+ if (net_addr_v4_add(ctx, ifname, &tt->local, netmask_t= o_netbits2(tt->remote_netmask)) < 0)
{
msg(M_FATAL, "Linux can't add IP to interf= ace %s", ifname);
}
@@ -1365,= 8 +1284,8 @@
#elif defined(TARGET_ANDROID)
char out[64];


- snprintf(out, sizeof(out), "%s %s %d %s", ifc= onfig_local,
- = ifconfig_remote_netmask, tun_mtu, print_topology(tt->topology));
+ snprintf(out, sizeo= f(out), "%s %s %d %s", ifconfig_local, ifconfig_remote_netmask, t= un_mtu,
+ = print_topology(tt->topology));
management_android_= control(management, "IFCONFIG", out);
#elif defined(TARGET_SOLARIS)
@@ -1377,8 +1296,8 @@=
*/
if (tun_p2p)
{

- argv_p= rintf(&argv, "%s %s %s %s mtu %d up", IFCONFIG_PATH, ifname,<= /span>
- if= config_local, ifconfig_remote_netmask, tun_mtu);
+ argv_printf(&argv, "%s %s %s = %s mtu %d up", IFCONFIG_PATH, ifname, ifconfig_local,
+ ifconfig_remote_= netmask, tun_mtu);

argv_msg(M_IN= FO, &argv);
if (!openvpn_execve_check(&arg= v, es, 0, "Solaris ifconfig phase-1 failed"))
@@ = -1386,19 +1305,16 @@
solaris_error_close(tt, e= s, ifname, false);
}

<= span style=3D"color: hsl(0, 100%, 40%);">- argv_printf(&argv, &q= uot;%s %s netmask 255.255.255.255", IFCONFIG_PATH,

- ifname);
+ argv_printf(&argv, &= quot;%s %s netmask 255.255.255.255", IFCONFIG_PATH, ifname);
}
else if (tt->type =3D=3D DEV_TYPE_TUN= )
{
- = ifname, ifconfig_local, ifconfig_local,
- ifconfig_remote_net= mask, tun_mtu);
+ = argv_printf(&argv, "%s %s %s %s netmask %s mtu %d up", IF= CONFIG_PATH, ifname,
= + ifconfig_local, ifconfig_local, ifconfig_remote_netmas= k, tun_mtu);
}
else /* tap */
{
- = argv_printf(&argv, "%s %s %s netmask %s up",
= - IFCONFIG_PAT= H, ifname, ifconfig_local,
+ argv_printf(&argv, "%s %s %s netmask %s up", I= FCONFIG_PATH, ifname, ifconfig_local,
= ifconfig_remote_netmask);
}
@@ -1423,7 +1339,7 @@

#elif defi= ned(TARGET_OPENBSD)

- in_addr_t remote_end; /* for "virtual&qu= ot; subnet topology */
- "%s %s %s %s mtu %d netmask 255.255.25= 5.255 up -link0",
= - IFCONFIG_PATH, ifname, ifconfig_local,
- ifconfig_remote_n= etmask, tun_mtu);

+ = argv_printf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.2= 55 up -link0", IFCONFIG_PATH,
+ ifname, ifconfig_local, ifconfig_remote_= netmask, tun_mtu);
}
else if (tt-= >type =3D=3D DEV_TYPE_TUN)
{
- remote_end =3D create_arbitrary_rem= ote( tt );
- arg= v_printf(&argv, "%s %s %s %s mtu %d netmask %s up -link0",
- IFCO= NFIG_PATH, ifname, ifconfig_local,
- print_in_addr_t(remote_end, 0, &gc), t= un_mtu,
+ remo= te_end =3D create_arbitrary_remote(tt);
+ argv_printf(&argv, "%s %s %s %s mtu %d= netmask %s up -link0", IFCONFIG_PATH, ifname,
+ ifconfig_local, print= _in_addr_t(remote_end, 0, &gc), tun_mtu,
= ifconfig_remote_netmask);
}
= else /* tap */
{
- argv_printf(&argv, "%s %s %s netmask %s = mtu %d link0",
- = IFCONFIG_PATH, ifname, ifconfig_local,
- ifconfig_remote_netm= ask, tun_mtu);
+ = argv_printf(&argv, "%s %s %s netmask %s mtu %d link0", IFC= ONFIG_PATH, ifname,
+= ifconfig_local, ifconfig_remote_netmask, tun_mtu);
}
argv_msg(M_INFO, &argv);=
openvpn_execve_check(&argv, es, S_FATAL, "OpenBSD i= fconfig failed");
@@ -1469,20 +1381,19 @@
}


#elif defined(TARGET_NETBSD)<= /span>
- in_addr_t remote_e= nd =3D INADDR_ANY; /* for "virtual" subnet topology */+ in_addr_t remote_end =3D = INADDR_ANY; /* for "virtual" subnet topology */
=
if (tun_p2p)
{
- argv_printf(&argv, "%s= %s %s %s mtu %d netmask 255.255.255.255 up",
- IFCONFIG_PATH, ifname, ifc= onfig_local,
- = ifconfig_remote_netmask, tun_mtu);
+ argv_printf(&argv, "%s %s %s %s = mtu %d netmask 255.255.255.255 up", IFCONFIG_PATH, ifname,
<= span style=3D"color: hsl(120, 100%, 40%);">+ ifconfig_lo= cal, ifconfig_remote_netmask, tun_mtu);

}
else if (tt->type =3D=3D DEV_TYPE_TUN)

{
remote_end =3D create_arbitrary_remote(tt);<= br>- argv_printf(&argv= , "%s %s %s %s mtu %d netmask %s up", IFCONFIG_PATH,
- ifname, ifconf= ig_local, print_in_addr_t(remote_end, 0, &gc),

- tun_mtu, ifconfig_remote_n= etmask);
+ arg= v_printf(&argv, "%s %s %s %s mtu %d netmask %s up", IFCONFIG_= PATH, ifname,
+ = ifconfig_local, print_in_addr_t(remote_end, 0, &gc), tun_= mtu,
+ = ifconfig_remote_netmask);
}
= else /* tap */
{
@@ -1491,8 +1402,7 @@=
* so we don't need the "link0" ext= ra parameter to specify we want to do
* tunneling= at the ethernet level
*/
- argv_printf(&argv, "%s %s = %s netmask %s mtu %d",
- IFCONFIG_PATH, ifname, ifconfig_local,
= + argv_printf(&argv,= "%s %s %s netmask %s mtu %d", IFCONFIG_PATH, ifname, ifconfig_lo= cal,
ifconfig_remote_netmask, tun_mtu)= ;
}
argv_msg(M_INFO, &argv);<= /span>
@@ -1518,28 +1428,24 @@
argv_printf(&a= mp;argv, "%s %s delete", IFCONFIG_PATH, ifname);
= argv_msg(M_INFO, &argv);
openvpn_execve_check= (&argv, es, 0, NULL);
- msg(M_INFO,
- = "NOTE: Tried to delete pre-existing tun/tap instance -- No Probl= em if failure");
+ msg(M_INFO, "NOTE: Tried to delete pre-existing tun/tap instance= -- No Problem if failure");


/* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmas= k 255.255.255.255 up */
if (tun_p2p)
= {
- argv_pri= ntf(&argv, "%s %s %s %s mtu %d netmask 255.255.255.255 up",
- IFC= ONFIG_PATH, ifname, ifconfig_local,
- ifconfig_remote_netmask, tun_mtu);=
+ argv_printf(&a= rgv, "%s %s %s %s mtu %d netmask 255.255.255.255 up", IFCONFIG_PA= TH, ifname,
+ = ifconfig_local, ifconfig_remote_netmask, tun_mtu);
}

else if (tt->type =3D=3D DEV_TYPE_TUN)
{
-= argv_printf(&argv, "%s %s %s %s netmask %s mtu %d up"= ,
- = IFCONFIG_PATH, ifname, ifconfig_local, ifconfig_local,
- ifconfig_remote_netmas= k, tun_mtu);
+ = argv_printf(&argv, "%s %s %s %s netmask %s mtu %d up", IFCON= FIG_PATH, ifname,
+ = ifconfig_local, ifconfig_local, ifconfig_remote_netmask, = tun_mtu);
}
else /* tap */=
{
- = argv_printf(&argv, "%s %s %s netmask %s mtu %d up", IFCONF= IG_PATH,
- = ifname, ifconfig_local, ifconfig_remote_netmask,
- tun_mtu);
<= span style=3D"color: hsl(120, 100%, 40%);">+ argv_printf(&argv, = "%s %s %s netmask %s mtu %d up", IFCONFIG_PATH, ifname, ifconfig_= local,

+ = ifconfig_remote_netmask, tun_mtu);
}
=
argv_msg(M_INFO, &argv);
@= @ -1560,17 +1466,16 @@
#elif defined(TARGET_FREEBSD) || de= fined(TARGET_DRAGONFLY)

/* example: = ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.255.255.255 up */
- if (tun_p2p) /* poi= nt-to-point tun */
+ = if (tun_p2p) /* point-to-point tun */
{
<= span style=3D"color: hsl(0, 100%, 40%);">- argv_printf(&argv, &q= uot;%s %s %s %s mtu %d netmask 255.255.255.255 up",

- IFCONFIG_PATH, ifnam= e, ifconfig_local,
- = ifconfig_remote_netmask, tun_mtu);
+ argv_printf(&argv, "%s %= s %s %s mtu %d netmask 255.255.255.255 up", IFCONFIG_PATH, ifname,
+ ifc= onfig_local, ifconfig_remote_netmask, tun_mtu);
}
- else /* tun= with topology subnet and tap mode (always subnet) */
+ else /* tun with topology subnet and = tap mode (always subnet) */
{
= int netbits =3D netmask_to_netbits2(tt->remote_netmask);
- argv_printf(&argv, "= ;%s %s %s/%d mtu %d up", IFCONFIG_PATH,

- ifname, ifconfig_local, netbits,= tun_mtu );
+ = argv_printf(&argv, "%s %s %s/%d mtu %d up", IFCONFIG_PATH, if= name, ifconfig_local, netbits,
+ tun_mtu);
}
<= span>

argv_msg(M_INFO, &argv);
@@= -1580,7 +1485,7 @@
{
/* AIX = ifconfig will complain if it can't find ODM path in env */
struct env_set *aix_es =3D env_set_create(NULL);

- env_set_add( aix_es, "= ODMDIR=3D/etc/objrepos" );

+ env_set_add(aix_es, "ODMDIR=3D/etc/objrepos")= ;

if (tt->type =3D=3D DEV_TYP= E_TUN)
{
@@ -1588,23 +1493,23 @@
}

/* exa= mple: ifconfig tap0 172.30.1.1 netmask 255.255.254.0 up */
- argv_printf(&argv, "%= s %s %s netmask %s mtu %d up", IFCONFIG_PATH,
- ifname, ifconfig_local, if= config_remote_netmask, tun_mtu);
+ argv_printf(&argv, "%s %s %s netmask %s mtu %= d up", IFCONFIG_PATH, ifname, ifconfig_local,
+ ifconfig_remote_netmask,= tun_mtu);

argv_msg(M_INFO, &= ;argv);
openvpn_execve_check(&argv, aix_es, S_= FATAL, "AIX ifconfig failed");

= env_set_destroy(aix_es);
}
-#elif defined (_WIN32)
+#elif defined(_WIN32)
if (tt->options.ip_win32_type =3D=3D IPW32_SET_MANUAL)

<= span> {

msg(M_INFO,
= "******** NOTE: Please manually set the IP/netmask of '%s'= to %s/%s (if it is not already set)",
- ifname, ifconfig_local,
- ifconfig_remote_netmask);
+ ifname, i= fconfig_local, ifconfig_remote_netmask);
}
<= span style=3D"color: hsl(0, 100%, 40%);">- else if (tt->options.ip_wi= n32_type =3D=3D IPW32_SET_DHCP_MASQ || tt->options.ip_win32_type =3D=3D = IPW32_SET_ADAPTIVE)

+= else if (tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ=
+ || tt->opt= ions.ip_win32_type =3D=3D IPW32_SET_ADAPTIVE)
{=
/* Let the DHCP configure the interface. */
}

@@ -1619,8 +1524,8 @@
{
if (tt->options.ip_win32_type =3D=3D IPW32_SET_NET= SH)
{
- netsh_ifconfig(&tt->options, tt->adapter_ind= ex, tt->local,
- = tt->adapter_netmask, NI_IP_NETMASK | NI_OPTIONS);=
+ netsh_i= fconfig(&tt->options, tt->adapter_index, tt->local, tt->ada= pter_netmask,
+ = NI_IP_NETMASK | NI_OPTIONS);
= }

do_dns_domain_wmic(true, tt);<= /span>
@@ -1637,13 +1542,14 @@
}
#elif defined(TARGET_HAIKU)

/* example: ifconfig = tun/0 inet 1.1.1.1 255.255.255.0 mtu 1450 up */
- argv_printf(&argv, "%s %s inet %s %s= mtu %d up", IFCONFIG_PATH,
- ifname, ifconfig_local, ifconfig_remote_netmask,= tun_mtu);
+ argv_= printf(&argv, "%s %s inet %s %s mtu %d up", IFCONFIG_PATH, if= name, ifconfig_local,
+ ifconfig_remote_netmask, tun_mtu);

argv_msg(M_INFO, &argv);
openvpn_= execve_check(&argv, es, S_FATAL, "Haiku ifconfig failed");
#else /* if defined(TARGET_LINUX) */
- msg(M_FATAL, "Sorry, but I don'= ;t know how to do 'ifconfig' commands on this operating system. Yo= u should ifconfig your TUN/TAP device manually or use an --up script."= );
+ msg(M_FATAL,<= /span>
+ "Sorry,= but I don't know how to do 'ifconfig' commands on this operati= ng system. You should ifconfig your TUN/TAP device manually or use an --up= script.");
#endif /* if defined(TARGET_LINUX) */

#if !defined(TARGET_LINUX)
= @@ -1654,8 +1560,8 @@

/* execute the ifc= onfig command through the shell */
void
-do_ifconfig(struct tuntap *tt, const cha= r *ifname, int tun_mtu,
- const struct env_set *es, openvpn_net_ctx_t *ctx)
<= span style=3D"color: hsl(120, 100%, 40%);">+do_ifconfig(struct tuntap *tt, = const char *ifname, int tun_mtu, const struct env_set *es,

+ openvpn_net_ctx_t *ctx)<= /span>
{
msg(D_LOW, "do_ifconfig, ipv4= =3D%d, ipv6=3D%d", tt->did_ifconfig_setup,
= tt->did_ifconfig_ipv6_setup);
@@ -1663,13 +1569,8 @@
#ifdef ENABLE_MANAGEMENT
if (management= )
{
- OPENVPN_STATE_ASSIGN_IP,=
- = NULL,
- = &tt->local,
- &tt->local_ipv6,
- = NULL,
- = NULL);
+ NULL, NULL);
= }
#endif

@@ -= 1695,19 +1596,16 @@

if (is_tun_p2p(t= t))
{
- if (net_addr_ptp_v4_del(ctx, tt->actual_name, &tt->l= ocal,
- = &tt->remote_netmask) < 0)
+ if (net_addr_ptp_v4_del(ctx, tt-&= gt;actual_name, &tt->local, &tt->remote_netmask) < 0)
{
= - msg(M_WARN, "Linux can't del IP from iface %s",<= /span>
- tt->= ;actual_name);
+ = msg(M_WARN, "Linux can't del IP from iface %s", tt->= ;actual_name);
}
}
= else
{
if (net_add= r_v4_del(ctx, tt->actual_name, &tt->local, netbits) < 0)
{
-= msg(M_WARN, "Linux can't del IP from iface %s",
- tt->= actual_name);
+ = msg(M_WARN, "Linux can't del IP from iface %s", tt->= actual_name);
}
}
<= span> #elif defined(TARGET_FREEBSD)

@@ -1715,8 +1613,7 @@
const char *ifconfig_local =3D print_in_addr_t(tt->l= ocal, 0, &gc);
struct argv argv =3D argv_new();

- ar= gv_printf(&argv, "%s %s %s -alias", IFCONFIG_PATH,
= - tt->actual_na= me, ifconfig_local);
= + argv_printf(&argv, "%s %s %s -alias", IFCONFIG_PATH, tt-= >actual_name, ifconfig_local);
argv_msg(M_INFO, &am= p;argv);
openvpn_execve_check(&argv, NULL, 0, &quo= t;FreeBSD ip addr del failed");

@@ -= 1730,8 +1627,7 @@
undo_ifconfig_ipv6(struct tuntap *tt, op= envpn_net_ctx_t *ctx)
{
#if defined(TARGE= T_LINUX)
- if (net_a= ddr_v6_del(ctx, tt->actual_name, &tt->local_ipv6,
- tt->netbit= s_ipv6) < 0)

+ = if (net_addr_v6_del(ctx, tt->actual_name, &tt->local_ipv6, tt->= ;netbits_ipv6) < 0)
{
msg(= M_WARN, "Linux can't del IPv6 from iface %s", tt->actual_n= ame);
}
@@ -1740,8 +1636,8 @@ const char *ifconfig_ipv6_local =3D print_in6_addr(tt->loca= l_ipv6, 0, &gc);
struct argv argv =3D argv_new();<= /span>

- = argv_printf(&argv, "%s %s inet6 %s/%d -alias", IFCONFIG_PATH,=
- tt-&g= t;actual_name, ifconfig_ipv6_local, tt->netbits_ipv6);
+ argv_printf(&argv, "%s %= s inet6 %s/%d -alias", IFCONFIG_PATH, tt->actual_name,
+ ifconfig_ipv6_lo= cal, tt->netbits_ipv6);


argv_msg(= M_INFO, &argv);
openvpn_execve_check(&argv, NU= LL, 0, "FreeBSD ip -6 addr del failed");
@@ -1831= ,7 +1727,7 @@
struct iovec iv[2];
= struct openvpn_iphdr *iph;

- iph =3D (struct openvpn_iphdr *) bu= f;
+ iph =3D (= struct openvpn_iphdr *)buf;

if (= OPENVPN_IPH_GET_VER(iph->version_len) =3D=3D 6)
= {
@@ -1894,8 +1790,7 @@

= #if !(defined(_WIN32) || defined(TARGET_LINUX) || defined(TARGET_SOLARIS))=
static void
-open_tun_generic(const char *dev, const char *dev_type, const char = *dev_node,
- = struct tuntap *tt)
+open_tun_generic(const char *dev, const char *dev_type, const char *de= v_node, struct tuntap *tt)
{
char tun= name[256];
char dynamic_name[256];
@@ = -1925,10 +1820,8 @@
#if defined(TARGET_HAIKU)
sep =3D "/";

#endif<= br>- snprintf(tunn= ame, sizeof(tunname),
-= "/dev/%s%s%d", dev, sep, i);
<= span style=3D"color: hsl(0, 100%, 40%);">- snprintf(dynamic_= name, sizeof(dynamic_name),

- "%s%s%d", dev, sep, i);
= + snprintf(tunna= me, sizeof(tunname), "/dev/%s%s%d", dev, sep, i);
+ snprintf(dynamic_na= me, sizeof(dynamic_name), "%s%s%d", dev, sep, i);

if ((tt->fd =3D open(tunname, O_RDWR)) > 0)
<= br> {
dynamic_op= ened =3D true;
@@ -1953,9 +1846,9 @@
i= f (!dynamic_opened)
{
/* has = named device existed before? if so, don't destroy at end */
<= span style=3D"color: hsl(0, 100%, 40%);">- if (if_nametoindex( dev )= > 0)

+ if = (if_nametoindex(dev) > 0)
{
- msg(M_INFO, "TUN/TAP dev= ice %s exists previously, keep at program end", dev );
+ msg(M_INFO, "TUN/T= AP device %s exists previously, keep at program end", dev);

= tt->persistent_if =3D true;
= }

@@ -1971,14 +1864,13 @@

/* tt->actual_name is passed to up and down scri= pts and used as the ifconfig dev name */
tt->actual= _name =3D string_alloc(dynamic_opened ? dynamic_name : dev, NULL);-
}
= #endif /* !_WIN32 && !TARGET_LINUX && !TARGET_FREEBS= D*/

#if defined(TARGET_LINUX) || defined= (TARGET_FREEBSD)
static void
-open_tun_dco_generic(const char *dev, const char *d= ev_type,
- = struct tuntap *tt, openvpn_net_ctx_t *ctx)
+open_tun_dco_generic(const char *dev, const = char *dev_type, struct tuntap *tt,
+ openvpn_net_ctx_t *ctx)
{

char dynamic_name[256];
bool = dynamic_opened =3D false;
@@ -1995,8 +1887,7 @@
<= span> {

for (int i =3D 0; i < 256; ++i)
{
- snprintf(dynamic_name, sizeof(dynamic_name),
- "%s%d",= dev, i);
+ = snprintf(dynamic_name, sizeof(dynamic_name), "%s%d", dev, i);
int ret =3D open_tun_dco(tt, ctx, dynamic_name)= ;
if (ret =3D=3D 0)
= {
@@ -2026,14 +1917,12 @@
int r= et =3D open_tun_dco(tt, ctx, dev);
if (ret =3D=3D = -EEXIST)
{
- msg(M_INFO, "DCO device %s already exists, w= on't be destroyed at shutdown",
- dev);
+ msg(M_INFO, "DCO device %s already ex= ists, won't be destroyed at shutdown", dev);
= tt->persistent_if =3D true;
} else if (ret < 0)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- msg(M_ERR, "Cann= ot open DCO device %s: %s (%d)", dev,

- strerror(-ret), ret);
+ msg(M_ERR, "Cannot = open DCO device %s: %s (%d)", dev, strerror(-ret), ret);
}

else
{
@@ -2060,7 +1949,7 @@
}
#endi= f /* !_WIN32 */

-#if defined (TARGET_ANDROID)
+#if defined(TARGET_ANDROID)
void
open_tun(const char *dev, const char *dev_type, const char *de= v_node, struct tuntap *tt,
openvpn_net_ctx_t *ctx= )
@@ -2100,7 +1989,7 @@

= int android_method =3D managment_android_persisttun_action(management);=

- = if (oldtunfd >=3D0 && android_method =3D=3D ANDROID_KEEP_OLD_T= UN)
+ if (oldtunfd= >=3D 0 && android_method =3D=3D ANDROID_KEEP_OLD_TUN) {
/* keep the old fd */
opentun =3D true;

@@ -2211,8 +2100,7 @@ }
else
{=
- msg(M_FAT= AL, "I don't recognize device %s as a tun or tap device",
- dev);
+ msg(M_FATAL= , "I don't recognize device %s as a tun or tap device", dev);=
}

/*
@@ -2227,7 +2115,7 @@
* Use specia= l ioctl that configures tun/tap device with the parms
= * we set in ifr
*/
- if (ioctl(tt->fd, TUNSETIFF, (void *= ) &ifr) < 0)
+= if (ioctl(tt->fd, TUNSETIFF, (void *)&ifr) < 0) {
msg(M_ERR, "ERROR: Cann= ot ioctl TUNSETIFF %s", dev);
}
@@ -2248,7 +2136,7 @@

CLEAR(netifr);
strncpynt(netifr.ifr_name, ifr.ifr_name, IFN= AMSIZ);
netifr.ifr_qlen =3D tt->options= .txqueuelen;
- = if (ioctl(ctl_fd, SIOCSIFTXQLEN, (void *) &netifr) >=3D 0)
+ if (io= ctl(ctl_fd, SIOCSIFTXQLEN, (void *)&netifr) >=3D 0)
= {
msg(D_OSBUF, "= TUN/TAP TX queue length set to %d", tt->options.txqueuelen);=
}
@@ -2287,13 +2175,13 @@=

/* TUNSETGROUP appeared in 2.6.23 */ #ifndef TUNSETGROUP
-#define TUNSETGROUP _IOW('T', 206, int)
+#define TUNSETGROUP _IOW('T', 2= 06, int)
#endif

void
-tuncfg(const char *dev, = const char *dev_type, const char *dev_node,
- int persist_mode, const char *username, const = char *groupname,
- = const struct tuntap_options *options, openvpn_net_ctx_t *ctx)
<= span style=3D"color: hsl(120, 100%, 40%);">+tuncfg(const char *dev, const c= har *dev_type, const char *dev_node, int persist_mode,

+ const char *username, const char = *groupname, const struct tuntap_options *options,
+ openvpn_net_ctx_t *ctx)
{

struct tuntap *tt;

@@ -2413,8 +2301,7 @@

}
else<= /span>
{
= - msg(M_FATAL, "I don't recognize device %s as a tun or tap= device",
- = dev);
+ m= sg(M_FATAL, "I don't recognize device %s as a tun or tap device&qu= ot;, dev);
}

if= ((tt->ip_fd =3D open(ip_node, O_RDWR, 0)) < 0)
@@ -2= 432,7 +2319,7 @@
/* get unit number */
if (*ptr)

{
- while (*ptr && !isdigit((int) *ptr))
+ while (*ptr &= & !isdigit((int)*ptr))
{
= ptr++;
}
@@ -2445,7 +2332,= 7 @@
strioc_ppa.ic_len =3D sizeof(ppa);
strioc_ppa.ic_dp =3D (char *)&ppa;


<= span style=3D"color: hsl(0, 100%, 40%);">- if (*ptr =3D=3D '\0')= /* no number given, try dynamic */

+ if (*ptr =3D=3D '\0') /* no number gi= ven, try dynamic */
{
bool fo= und_one =3D false;
while (!found_one && pp= a < 64)
@@ -2453,27 +2340,28 @@
= int new_ppa =3D ioctl(tt->fd, I_STR, &strioc_ppa);
if (new_ppa >=3D 0)

{
- msg( M_INF= O, "open_tun: got dynamic interface '%s%d'", dev_tuntap_t= ype, new_ppa );
+ = msg(M_INFO, "open_tun: got dynamic interface '%s%d'= ;", dev_tuntap_type, new_ppa);
ppa = =3D new_ppa;
found_one =3D true; break;
}
if (errno !=3D EEXIST)

{
- msg(M_ERR, = "open_tun: unexpected error trying to find free %s interface", de= v_tuntap_type );
+ = msg(M_ERR, "open_tun: unexpected error trying to find fre= e %s interface",
+ dev_tuntap_type);
}
ppa++;
}
= if (!found_one)
{
- msg(M_ERR, "open_tun: coul= d not find free %s interface, give up.", dev_tuntap_type );
= + msg(M_ERR, "o= pen_tun: could not find free %s interface, give up.", dev_tuntap_type)= ;
}
}
- else /* try this= particular one */
+ = else /* try this particular one */
{
if ((ppa =3D ioctl(tt->fd, I_STR, &strioc_ppa)) < 0)
{
- msg(M_ERR, "Can't assign PPA for new interface (%s= %d)", dev_tuntap_type, ppa );
+ msg(M_ERR, "Can't assign PPA for new in= terface (%s%d)", dev_tuntap_type, ppa);
}
}

@@ -2490,13 +2378,13 = @@
if (tt->type =3D=3D DEV_TYPE_TUN)
{

/* Assign ppa according to the unit numbe= r returned by tun device */
- if (ioctl(if_fd, IF_UNITSEL, (char *) &ppa) < 0)
+ if (ioctl(if_fd, = IF_UNITSEL, (char *)&ppa) < 0)
{
= msg(M_ERR, "Can't set PPA %d", ppa);
}
}

- tt->actual_name =3D (char *= ) malloc(32);

+ tt= ->actual_name =3D (char *)malloc(32);
check_malloc_= return(tt->actual_name);

snprintf= (tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa);@@ -2514,7 +2402,7 @@
{
= msg(M_ERR, "Can't set PPA %d", ppa);
}

- i= f (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0)
+ if (ioctl(if_fd, SIOCGLIFFLAGS, &if= r) < 0)
{
msg(M_ER= R, "Can't get flags\n");
}@@ -2576,7 +2464,7 @@

CLEAR(i= fr);
strncpynt(ifr.lifr_name, tt->actual_name, size= of(ifr.lifr_name));
- = ifr.lifr_ip_muxid =3D ip_muxid;
+ ifr.lifr_ip_muxid =3D ip_muxid;
if = (tt->type =3D=3D DEV_TYPE_TAP)
{
= ifr.lifr_arp_muxid =3D arp_muxid;
@@ -2606,8 +2494,7= @@
if (tt->did_ifconfig_ipv6_setup)
{

struct argv argv =3D argv_new();- argv_printf( &argv= , "%s %s inet6 unplumb",
- IFCONFIG_PATH, tt->actual_name );
+ argv_printf(&= ;argv, "%s %s inet6 unplumb", IFCONFIG_PATH, tt->actual_name);=
argv_msg(M_INFO, &argv);
= openvpn_execve_check(&argv, NULL, 0, "Solaris ifconfig inet6 = unplumb failed");
argv_free(&argv);
@@ -2670,23 +2557,19 @@
}

static void
-solaris_error_close(struct tuntap *tt, const struct env_set *es,=
- const ch= ar *actual, bool unplumb_inet6 )
+solaris_error_close(struct tuntap *tt, const struct env_set *e= s, const char *actual,
- argv_printf( &argv, "%s %s inet6 = unplumb",
- = IFCONFIG_PATH, actual );
+ argv_printf(&argv, "%s %s inet6 unplumb= ", IFCONFIG_PATH, actual);
argv_msg(M_INFO, &= amp;argv);
openvpn_execve_check(&argv, es, 0, = "Solaris ifconfig inet6 unplumb failed");
}<= /span>

- = argv_printf(&argv,
= - "%s %s unplumb",
- IFCONFIG_PATH,
- actual);
+ argv_printf(&argv, "%s %s= unplumb", IFCONFIG_PATH, actual);

= argv_msg(M_INFO, &argv);
openvpn_execve_check(= &argv, es, 0, "Solaris ifconfig unplumb failed");
<= span>@@ -2772,8 +2655,7 @@

/* setup command, close tun= dev (clears tt->actual_name!), run command
*/

- arg= v_printf(&argv, "%s %s destroy",
- IFCONFIG_PATH, tt->actual_name)= ;
+ argv_printf(&a= mp;argv, "%s %s destroy", IFCONFIG_PATH, tt->actual_name);

close_tun_generic(tt);
=
@@ -2823,11 +2705,11 @@
if (strcmp(d= ev, "tap") =3D=3D 0)
{
= struct ifreq ifr;
-= if ((tt->fd =3D open( "/dev/tap", O_RDWR)) < 0)
+ if ((tt->fd = =3D open("/dev/tap", O_RDWR)) < 0)
{<= /span>
msg(M_FATAL, "Cannot allocate NetBSD TAP = dev dynamically");
}
- if (ioctl( tt->fd, TAPGIFNAME, (voi= d *)&ifr ) < 0)
- int i =3D IFF_POINTOPOINT|IFF_MULTICAST;
- ioctl(tt->fd, TU= NSIFMODE, &i); /* multicast on */
+ int i =3D IFF_POINTOPOINT | IFF_MULTICAST;
+ ioctl(tt->fd,= TUNSIFMODE, &i); /* multicast on */
i =3D 0;<= /span>
- ioctl(tt->f= d, TUNSLMODE, &i); /* link layer mode off */
+ ioctl(tt->fd, TUNSLMODE, &= i); /* link layer mode off */

i= f (tt->type =3D=3D DEV_TYPE_TUN)
{
i =3D 1;

- if (ioctl(tt->fd, TUNSIFHEAD, &i) < 0) /* mu= lti-af mode on */
+ = if (ioctl(tt->fd, TUNSIFHEAD, &i) < 0) /* multi-af mode= on */
{
msg(= M_WARN | M_ERRNO, "ioctl(TUNSIFHEAD)");
= }
@@ -2886,8 +2768,7 @@
/* setup c= ommand, close tun dev (clears tt->actual_name!), run command
<= span> */


- argv_printf(&argv, "%s %s destroy",
<= span style=3D"color: hsl(0, 100%, 40%);">- IFCONFIG_PATH, tt= ->actual_name);

+ = argv_printf(&argv, "%s %s destroy", IFCONFIG_PATH, tt->= actual_name);

close_tun_generic(tt);=

@@ -2920,7 +2801,7 @@
= struct iovec iv[2];
struct openvpn_iphdr *i= ph;

-= iph =3D (struct openvpn_iphdr *) buf;
+ iph =3D (struct openvpn_iphdr *)buf;

if (OPENVPN_IPH_GET_VER(iph->vers= ion_len) =3D=3D 6)
{
@@ -3028,7 +2= 909,7 @@
{
ASSERT(tt);

- if (tt->per= sistent_if) /* keep pre-existing if around */
+ if (tt->persistent_if) /* keep pre= -existing if around */
{
clos= e_tun_generic(tt);
free(tt);
@@ -3= 041,14 +2922,12 @@
/* setup command, close tun dev (cl= ears tt->actual_name!), run command
*/
<= span>

- argv_printf= (&argv, "%s %s destroy",
- IFCONFIG_PATH, tt->actual_name);=
+ argv_printf(&argv,= "%s %s destroy", IFCONFIG_PATH, tt->actual_name);
<= span>

close_tun_generic(tt);
=
argv_msg(M_INFO, &argv);
- openvpn_execve_check(&argv, NULL, 0,- "= ;FreeBSD 'destroy tun interface' failed (non-critical)");
+ openvpn_execve_check= (&argv, NULL, 0, "FreeBSD 'destroy tun interface' failed (= non-critical)");

free(tt);
argv_free(&argv);
@@ -3063,7 +2942,7 @= @
struct iovec iv[2];
str= uct ip *iph;

- iph =3D (struct ip *) buf;
+ iph =3D (struct ip *)buf;
=
if (iph->ip_v =3D=3D 6)
= {
@@ -3158,7 +3037,7 @@
struct = iovec iv[2];
struct ip *iph;

- iph =3D (struct i= p *) buf;
+ ip= h =3D (struct ip *)buf;

if (iph-= >ip_v =3D=3D 6)
{
@@ -3234,16 += 3113,14 @@

if (fd < 0)
= {
- m= sg(M_INFO | M_ERRNO, "Opening utun%d failed (socket(SYSPROTO_CONTROL))= ",
- ut= unnum);
+ msg(= M_INFO | M_ERRNO, "Opening utun%d failed (socket(SYSPROTO_CONTROL))&qu= ot;, utunnum);
return -2;
}

if (ioctl(fd, CTLIOCGINFO, &ctlIn= fo) =3D=3D -1)
{
close(fd);
- msg(M_INFO | M_= ERRNO, "Opening utun%d failed (ioctl(CTLIOCGINFO))",
- utunnum);

+ msg(M_INFO | M_ERRNO, &q= uot;Opening utun%d failed (ioctl(CTLIOCGINFO))", utunnum);

<= span> return -2;

}
@@ -3253,7 +3130,7 @@
sc.sc_family =3D AF_SYSTE= M;
sc.ss_sysaddr =3D AF_SYS_CONTROL;
=
- sc.sc_unit =3D ut= unnum+1;
+ sc.sc_u= nit =3D utunnum + 1;


= /* If the connect is successful, a utun%d device will be created, where = "%d"
@@ -3261,8 +3138,7 @@

if (connect(fd, (struct sockaddr *)&sc, sizeof(sc)) &l= t; 0)
{
- msg(M_INFO | M_ERRNO, "Opening utun%d failed (connect(A= F_SYS_CONTROL))",
= - utunnum);
- if (dev_node && (strcmp("utun", dev_node) !=3D 0 ))=
+ if (dev_node &a= mp;& (strcmp("utun", dev_node) !=3D 0))
= {
if (sscanf(dev_node, "utun%d", &ut= unnum) !=3D 1)
{
- msg(M_FATAL, "Cannot parse 'dev-no= de %s' please use 'dev-node utunX'"
- "to use a utun device = number X", dev_node);
+ msg(M_FATAL,
+ "Cannot parse 'dev-node %s' please= use 'dev-node utunX'"
+ "to use a utun device number X",<= /span>
+ dev_= node);
}
}
<= /span>

-
CLEAR(ctlInfo);
- if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof(ctl= Info.ctl_name)) >=3D
- sizeof(ctlInfo.ctl_name))
+ if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof= (ctlInfo.ctl_name))
+= >=3D sizeof(ctlInfo.ctl_name))
{
= msg(M_ERR, "Opening utun: UTUN_CONTROL_NAME too long&qu= ot;);
}
@@ -3317,7 +3194,7 @@ fd =3D utun_open_helper(ctlInfo, utunnum);
<= span> /* Break if the fd is valid,

= * or if early initialization failed (-2) */
- if (fd !=3D-1)
+ if (fd !=3D -1)
= {
break;
= }
@@ -3353,13 +3230,11 @@
= openvpn_net_ctx_t *ctx)
{
/* If dev= _node does not start start with utun assume regular tun/tap */
- if ((!dev_node && tt-&= gt;type=3D=3DDEV_TYPE_TUN)

- || (dev_node && !strncmp(dev_node, "utun", 4= )))
+ if ((!dev_no= de && tt->type =3D=3D DEV_TYPE_TUN) || (dev_node && !str= ncmp(dev_node, "utun", 4)))
{
-

/* Check i= f user has specific dev_type tap and forced utun with
= * dev-node utun */
- if (tt->type!=3DDEV_TYPE_TUN)
+ if (tt->type !=3D DEV_TYPE_TUN) {
msg(M_FATAL, "Cannot us= e utun devices with --dev-type %s",
d= ev_type_string(dev, dev_type));
@@ -3387,12 +3262,11 @@
}
else
{=
-
/*= Use plain dev-node tun to select /dev/tun style
= * Unset dev_node variable prior to passing to open_tun_generic to * let open_tun_generic pick the first available tun device= */

-= if (dev_node && strcmp(dev_node, "tun")=3D=3D0)
+ if (dev_node = && strcmp(dev_node, "tun") =3D=3D 0)
= {
dev_node =3D NULL;
= }
@@ -3411,11 +3285,9 @@

<= span> if (tt->did_ifconfig_ipv6_setup)

{=
- const char *ifconfig= _ipv6_local =3D
- = print_in6_addr(tt->local_ipv6, 0, &gc);
+ const char *ifconfig_ipv6_local = =3D print_in6_addr(tt->local_ipv6, 0, &gc);
=
- argv_printf(&arg= v, "%s delete -inet6 %s",
- ROUTE_PATH, ifconfig_ipv6_local );=
+ argv_printf(&a= rgv, "%s delete -inet6 %s", ROUTE_PATH, ifconfig_ipv6_local);
argv_msg(M_INFO, &argv);
= openvpn_execve_check(&argv, NULL, 0, "MacOS X 'remove inet6 r= oute' failed (non-critical)");
}
@@ -3464,44 +3336,46 @@


if (tt-&= gt;type =3D=3D DEV_TYPE_TUN)
{
- msg(M_FATAL, "no support for &= #39;tun' devices on AIX" );
+ msg(M_FATAL, "no support for 'tun' de= vices on AIX");
}

- if (strncmp( dev, "tap&quo= t;, 3 ) !=3D 0 || dev_node)

+ if (strncmp(dev, "tap", 3) !=3D 0 || dev_node)=
{
- = msg(M_FATAL, "'--dev %s' and/or '--dev-node' not su= pported on AIX, use '--dev tap0', 'tap1', etc.", dev )= ;
+ msg(M_FATA= L,
+ "= ;'--dev %s' and/or '--dev-node' not supported on AIX, use &= #39;--dev tap0', 'tap1', etc.",
+ dev);
}

- if (s= trcmp( dev, "tap" ) =3D=3D 0) /* find first free tap= dev */
- { = /* (=3D no /dev/tapN node) */
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (strcmp(dev, "tap&q= uot;) =3D=3D 0) /* find first free tap dev */

+ { /* (=3D no /dev/= tapN node) */
int i;
- for (i =3D 0; i<99; i++)
+ for (i =3D 0; i < 99; i+= +)

{
snprintf(tunname= , sizeof(tunname), "/dev/tap%d", i);
- if (access( tunname, F_OK ) < 0 &am= p;& errno =3D=3D ENOENT)
+ if (access(tunname, F_OK) < 0 && errno =3D= =3D ENOENT)
{
= break;
}
} if (i >=3D 99)
{
- msg( M_FATAL, "cann= ot find unused tap device" );

+ msg(M_FATAL, "cannot find unused tap device= ");
}

- snprintf( dynamic_name, sizeof(dyna= mic_name), "tap%d", i );
+ snprintf(dynamic_name, sizeof(dynamic_name), "t= ap%d", i);
dev =3D dynamic_name;
}

- else = /* name given, sanity check */<= br>+ else /* name given, san= ity check */
{
/* ensure that= dev name is "tap+<digits>" *only* */
= p =3D &dev[3];
= - while (isdigit(*p) )
+ while (isdigit(*p))
{
= p++;
}
= if (*p !=3D '\0')
{
- msg( M_FATAL, "TAP device = name must be '--dev tapNNNN'" );
+ msg(M_FATAL, "TAP device name mu= st be '--dev tapNNNN'");
}
=
snprintf(tunname, sizeof(tunname), "/= dev/%s", dev);
@@ -3509,16 +3383,15 @@

/* pre-existing device?
*/
- if (access( tunname,= F_OK ) < 0 && errno =3D=3D ENOENT)
+ if (access(tunname, F_OK) < 0 && = errno =3D=3D ENOENT)
{
-
/* tunnel device must be cr= eated with 'ifconfig tapN create'
*/
struct argv argv =3D argv_new();
= struct env_set *es =3D env_set_create(NULL);
a= rgv_printf(&argv, "%s %s create", IFCONFIG_PATH, dev);=
argv_msg(M_INFO, &argv);
- env_set_add( es, "ODMDIR=3D/etc/objr= epos" );
+ = env_set_add(es, "ODMDIR=3D/etc/objrepos");
= openvpn_execve_check(&argv, es, S_FATAL, "AIX 'create tun= interface' failed");
env_set_destroy(es)= ;
argv_free(&argv);
@@ -3556,1= 8 +3429,16 @@
*/
if (tt->pers= istent_if)
{
- argv_printf(&argv, "%s %s 0.0.0.0 down",<= /span>
- IF= CONFIG_PATH, tt->actual_name);
+ argv_printf(&argv, "%s %s 0.0.0.0 down"= , IFCONFIG_PATH, tt->actual_name);
}
else

{
- argv_printf(&argv, "%s %s destroy",
- IFCONF= IG_PATH, tt->actual_name);
+ argv_printf(&argv, "%s %s destroy", IFCONFI= G_PATH, tt->actual_name);
}

close_tun_generic(tt);
argv_msg(M_INFO= , &argv);
- env_= set_add( es, "ODMDIR=3D/etc/objrepos" );
+ env_set_add(es, "ODMDIR=3D/etc/objr= epos");
openvpn_execve_check(&argv, es, 0, &q= uot;AIX 'destroy tap interface' failed (non-critical)");

free(tt);
@@ -3607,13 +34= 78,8 @@
/* the overlapped read will signal this ev= ent on I/O completion */
ASSERT(ResetEvent(tt->= reads.overlapped.hEvent));

- status =3D ReadFile(
- tt->hand,
- BPTR(&tt->reads.buf),=
- len,
- &tt->re= ads.size,
- = &tt->reads.overlapped
- );
+ status =3D
= + ReadFile(tt->hand, BPTR(&tt->reads.buf), len, &t= t->reads.size, &tt->reads.overlapped);
if (status) /* operation completed immediately? */<= br> {
@@ -3623,9 +3489,8 @@
= tt->reads.iostate =3D IOSTATE_IMMEDIATE_RETURN;
tt->reads.status =3D 0;


- dmsg(D_WIN32_IO, "= WIN32 I/O: TAP Read immediate return [%d,%d]",

- (int) len,
- (int) tt->reads.s= ize);

+ dm= sg(D_WIN32_IO, "WIN32 I/O: TAP Read immediate return [%d,%d]", (i= nt)len,
+ = (int)tt->reads.size);
}
= else
{
@@ -3634,8 +3499,7 @= @
{
tt->re= ads.iostate =3D IOSTATE_QUEUED;
tt->rea= ds.status =3D err;
- = dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read queued [%d]",<= /span>
- (= int) len);
+ = dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read queued [%d]", (int)l= en);
}
else /* er= ror occurred */
{
@@ -3643,8 += 3507,7 @@
ASSERT(SetEvent(tt->reads.ove= rlapped.hEvent));
tt->reads.iostate =3D= IOSTATE_IMMEDIATE_RETURN;
tt->reads.st= atus =3D err;
- = dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read error [%d] : %s",
- (i= nt) len,
+ = dmsg(D_WIN32_IO, "WIN32 I/O: TAP Read error [%d] : %s", (int= )len,
strerror_win32(status, &gc)= );
gc_free(&gc);
= }
@@ -3669,13 +3532,8 @@
/= * the overlapped write will signal this event on I/O completion */ ASSERT(ResetEvent(tt->writes.overlapped.hEvent));

- s= tatus =3D WriteFile(
- = tt->hand,
- BPTR(&tt->writes.buf),
- BLEN(&tt->writes.buf),
<= span style=3D"color: hsl(0, 100%, 40%);">- &tt->writes.si= ze,

- &t= t->writes.overlapped
- );
+ = status =3D WriteFile(tt->hand, BPTR(&tt->writes.buf), BLEN(&= amp;tt->writes.buf), &tt->writes.size,
+ &tt->writes.= overlapped);

if (status) /* oper= ation completed immediately? */
{
= @@ -3686,9 +3544,8 @@

tt->= ;writes.status =3D 0;

- dmsg(D_WIN32_IO, "WIN32 I/O: TAP Write i= mmediate return [%d,%d]",
- BLEN(&tt->writes.buf),
- (int) tt->writes.size= );
+ dmsg(= D_WIN32_IO, "WIN32 I/O: TAP Write immediate return [%d,%d]", BLEN= (&tt->writes.buf),
+ (int)tt->writes.size);
}=
else
{
@= @ -3697,8 +3554,7 @@
{
= tt->writes.iostate =3D IOSTATE_QUEUED;
= tt->writes.status =3D err;
- dmsg(D_WIN32_IO, "WIN32 I/O: TAP Wri= te queued [%d]",
-= BLEN(&tt->writes.buf));
+ dmsg(D_WIN32_IO, "WI= N32 I/O: TAP Write queued [%d]", BLEN(&tt->writes.buf));=
}
else /* error occurre= d */
{
@@ -3706,8 +3562,7 @@
ASSERT(SetEvent(tt->writes.overlapped.hE= vent));
tt->writes.iostate =3D IOSTATE_= IMMEDIATE_RETURN;
tt->writes.status =3D= err;
- = dmsg(D_WIN32_IO, "WIN32 I/O: TAP Write error [%d] : %s",- BLEN(&= ;tt->writes.buf),
= + dmsg(D_WIN32_IO, "WIN32 I/O: TAP Write error [%d] : %= s", BLEN(&tt->writes.buf),
= strerror_win32(err, &gc));
gc_free(&= amp;gc);
}
@@ -3750,11 +3605,1= 3 @@
struct device_instance_id_interface *first =3D NU= LL;
struct device_instance_id_interface *last =3D NULL= ;

- = dev_info_set =3D SetupDiGetClassDevsEx(&GUID_DEVCLASS_NET, NULL, NULL= , DIGCF_PRESENT, NULL, NULL, NULL);
+ dev_info_set =3D
+ SetupDiGetClassDevsEx(&GUID_DEVCLASS_NET, NULL= , NULL, DIGCF_PRESENT, NULL, NULL, NULL);
if (dev_info= _set =3D=3D INVALID_HANDLE_VALUE)
{
= err =3D GetLastError();
- msg(M_FATAL, "Error [%u] opening device information s= et key: %s", (unsigned int)err, strerror_win32(err, gc));
+ msg(M_FATAL, "Error= [%u] opening device information set key: %s", (unsigned int)err,
+ strerror_win= 32(err, gc));
}

= msg(D_TAP_WIN_DEBUG, "Enumerate device interface lists:");
@@ -3787,7 +3644,8 @@
}
<= span> }


- dev_key =3D SetupDiOpenDevRegKey(dev_info_set, &dev= ice_info_data, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE);
= + dev_key =3D SetupDiOpe= nDevRegKey(dev_info_set, &device_info_data, DICS_FLAG_GLOBAL, 0,=
+ = DIREG_DRV, KEY_QUERY_VALUE);
if (dev_= key =3D=3D INVALID_HANDLE_VALUE)
{
continue;

@@ -3795,27 +3653,23 @@
<= span>

len =3D sizeof(net_cfg_instance_id);=
data_type =3D REG_SZ;
- status =3D RegQueryValueEx(dev_key,
- n= et_cfg_instance_id_string,

- NULL,
- &data_type,
- = net_cfg_instance_id,
- &len);
+ status =3D RegQueryValueEx(dev_key, n= et_cfg_instance_id_string, NULL, &data_type,
+ net_cfg_insta= nce_id, &len);
if (status !=3D ERROR_SUCCESS)<= /span>
{
goto next; }

len =3D sizeo= f(device_instance_id);
= - res =3D SetupDiGetDeviceInstanceId(dev_info_set, &device_info_= data, device_instance_id, len, &len);
+ res =3D SetupDiGetDeviceInstanceId(dev_info_s= et, &device_info_data, device_instance_id, len,
+ = &len);
if (!res)
{
goto next;
}
=
cr =3D CM_Get_Device_Interface_List_Size(&= amp;dev_interface_list_size,
- (LPGUID)&GUID_DEV= INTERFACE_NET,
- = device_instance_id,
+ = (LPGUID)&GUID_DEVINTERFACE_NET, device_instance_id,
<= br> CM_GET_DEVICE_INTE= RFACE_LIST_PRESENT);

if (cr !=3D= CR_SUCCESS)
@@ -3825,8 +3679,7 @@
=
char *dev_interface_list =3D gc_malloc(dev_interface_lis= t_size, false, gc);
cr =3D CM_Get_Device_Interface= _List((LPGUID)&GUID_DEVINTERFACE_NET, device_instance_id,
- = dev_interface_list,

- dev_interface_list_size,
+ = dev_interface_list, dev_interface_list_size,
<= span> CM_GET_DEVICE_INTERFACE_LIS= T_PRESENT);

if (cr !=3D CR_SUCCESS)
{

@@ -3840,12 +3693,12 @@
= {
struct device_instance_id_interface *dev_= iif;
ALLOC_OBJ_CLEAR_GC(dev_iif, struct device= _instance_id_interface, gc);
- dev_iif->net_cfg_instance_id =3D (unsigned char *)str= ing_alloc((char *)net_cfg_instance_id, gc);
+ dev_iif->net_cfg_instance_id =3D
+ (unsign= ed char *)string_alloc((char *)net_cfg_instance_id, gc);
= dev_iif->device_interface =3D string_alloc(dev_if, gc);

msg(D_TAP_WIN_DEBUG, "NetCfg= InstanceId: %s, Device Interface: %s",
- dev_iif->net_cfg_instance_id,
- dev_iif-&g= t;device_interface);
= + dev_iif->net_cfg_instance_id, dev_iif->device_interf= ace);

/* link into return li= st */
if (!first)
@@ -3880,12 = +3733,7 @@
struct tap_reg *last =3D NULL;
int i =3D 0;


- status =3D RegOpenKeyEx(
- HKEY_LOCAL_MACHINE,
- ADAPTER_KEY,
- 0,
- KEY_READ,
- &adapter_key);
+ status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, ADA= PTER_KEY, 0, KEY_READ, &adapter_key);

if (status !=3D ERROR_SUCCESS)

{
@@ -3905,34 +3753,19 @@

DWORD data_type;
len =3D sizeof(enum_name);
- status =3D RegEnumKeyEx(
- adapter_key,=
- i,=
- enum_name,
- &len,
- NULL,- NULL,
- NULL,

- NULL);
+ status =3D RegEnumKeyEx(adapter_= key, i, enum_name, &len, NULL, NULL, NULL, NULL);
= if (status =3D=3D ERROR_NO_MORE_ITEMS)
{
break;
}
= else if (status !=3D ERROR_SUCCESS)
{
- msg(M_FATAL, &= quot;Error enumerating registry subkeys of key: %s",
- ADAPTER_KEY);+ msg(M_FATAL, &quo= t;Error enumerating registry subkeys of key: %s", ADAPTER_KEY);=
}

- snprintf(unit_string, sizeof(unit_string), "%= s\\%s",
- = ADAPTER_KEY, enum_name);
+ snprintf(unit_string, sizeof(unit_string), "%s\\%= s", ADAPTER_KEY, enum_name);

- status =3D RegOpenKeyEx(
= - HKEY_LOCAL_MACHINE,<= /span>
- unit_strin= g,
- 0,
- KEY_READ,
- &unit_key)= ;
+ status =3D= RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit_string, 0, KEY_READ, &unit_key);=

if (status !=3D ERROR_SUCCESS)<= /span>
{
@@ -3941,29 +3774,19 @@ else
{
= len =3D sizeof(component_id);
- status =3D RegQueryValueEx(
- unit_key,
- component_id_string,
- NULL,
- &data_t= ype,
- (= LPBYTE)component_id,
- = &len);
+ status =3D RegQueryValueEx(unit_key, component_id_string,= NULL, &data_type,
- dmsg(D_REGISTRY, "E= rror opening registry key: %s\\%s",
- unit_string, component_id_string);<= /span>
+ dmsg= (D_REGISTRY, "Error opening registry key: %s\\%s", unit_string,
+ = component_id_string);
}
= else
{
= len =3D sizeof(net_cfg_instance_id);
- status =3D RegQueryValueEx(
- unit_key,
<= br>- net_cfg_i= nstance_id_string,
- = NULL,
= - &data_type,
- net_cfg_instance_id,
- &len);
= + status =3D Reg= QueryValueEx(unit_key, net_cfg_instance_id_string, NULL, &data_type,
+ = net_cfg_instance_id, &len);
=
if (status =3D=3D ERROR_SUCCESS && data_= type =3D=3D REG_SZ)
{
@@ -= 3997,8 +3820,8 @@
}
last =3D reg;


- msg(D_TAP_WIN_= DEBUG, "NetCfgInstanceId: %s, Driver: %s",
- reg->guid, p= rint_tun_backend_driver(reg->windows_driver));
+ msg(D_TAP_WIN_DEBUG, = "NetCfgInstanceId: %s, Driver: %s", reg->guid,
+ print_t= un_backend_driver(reg->windows_driver));

= }
}
}
@@ -4021,12 +3844,8 @@
struct panel_reg= *last =3D NULL;
int i =3D 0;
=
- status =3D RegOpenKeyEx(=
- HKEY_LOCAL_MA= CHINE,
- NETWORK= _CONNECTIONS_KEY,
- = 0,
- KEY_REA= D,
- &networ= k_connections_key);
+= status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0,= KEY_READ,
+ = &network_connections_key);
if (status !=3D ERROR_SUCCESS)
{@@ -4043,35 +3862,20 @@
const WCHAR name_st= ring[] =3D L"Name";

le= n =3D sizeof(enum_name);
- network_connections_key,
- i,
- enum_name,
- &len,
- NULL,
- NULL,
- NULL,
- NULL);
+ status =3D RegEnumKeyEx(network_connections_key, i, enum_= name, &len, NULL, NULL, NULL, NULL);
if (statu= s =3D=3D ERROR_NO_MORE_ITEMS)
{
= break;
}
else = if (status !=3D ERROR_SUCCESS)
{
- msg(M_FATAL, "Error en= umerating registry subkeys of key: %s",
- NETWORK_CONNECTIONS_KEY);
= + msg(M_FATAL, "= ;Error enumerating registry subkeys of key: %s", NETWORK_CONNECTIONS_K= EY);
}

- snprintf(connection_string, sizeof(conn= ection_string),
- = "%s\\%s\\Connection",
+ snprintf(connection_string, sizeof(connectio= n_string), "%s\\%s\\Connection",
= NETWORK_CONNECTIONS_KEY, enum_name);

- status =3D RegOpenKeyEx(<= br>- HKEY_LOCAL_MACHIN= E,
- connect= ion_string,
- = 0,
- KEY_R= EAD,
- &= connection_key);
+ = status =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, connection_string, 0, KEY_= READ, &connection_key);

if (= status !=3D ERROR_SUCCESS)
{
@@ -4= 080,18 +3884,13 @@
else
{=
len =3D sizeof(name_data);
- status =3D RegQueryValueExW(=
- conne= ction_key,
- = name_string,
- = NULL,
- = &name_type,
- (LPBYTE) name_data,
- &len);
+ status =3D RegQueryValueExW(connecti= on_key, name_string, NULL, &name_type,
+ (LPBYTE)name_d= ata, &len);

if (status != =3D ERROR_SUCCESS || name_type !=3D REG_SZ)
{<= /span>
- dmsg(D= _REGISTRY, "Error opening registry key: %s\\%s\\%ls",
<= span style=3D"color: hsl(0, 100%, 40%);">- NETWORK_CONN= ECTIONS_KEY, connection_string, name_string);

+ dmsg(D_REGISTRY, "Error open= ing registry key: %s\\%s\\%ls", NETWORK_CONNECTIONS_KEY,
+ connection_s= tring, name_string);

}
= else
{
@@ -4144,15 +3943= ,14 @@
}
if ((local & (~mask)= ) !=3D (remote & (~mask)))
{
- err =3D "must exist within the= same 255.255.255.252 subnet. This is a limitation of --dev tun when used = with the TAP-WIN32 driver";
+ err =3D
+ "must exist within the same 255.255.255.252 subne= t. This is a limitation of --dev tun when used with the TAP-WIN32 driver&q= uot;;
goto error;
}- if ((local & mask) =3D= =3D 0
- || (loca= l & mask) =3D=3D 3
= - || (remote & mask) =3D=3D 0
- || (remote & mask) =3D=3D 3)
+ if ((local & mask) =3D=3D 0= || (local & mask) =3D=3D 3 || (remote & mask) =3D=3D 0 || (remote = & mask) =3D=3D 3)

{
- err =3D "cannot use the first or last a= ddress within a given 255.255.255.252 subnet. This is a limitation of --de= v tun when used with the TAP-WIN32 driver";
+ err =3D
+ "cannot use the first or last add= ress within a given 255.255.255.252 subnet. This is a limitation of --dev = tun when used with the TAP-WIN32 driver";
got= o error;
}

@@ -4160,= 10 +3958,10 @@
return;

error:

- msg(M_F= ATAL, "There is a problem in your selection of --ifconfig endpoints [l= ocal=3D%s, remote=3D%s]. The local and remote VPN endpoints %s. Try '= " PACKAGE " --show-valid-subnets' option for more info."= ,
- print_in_add= r_t(local, 0, &gc),
- print_in_addr_t(remote, 0, &gc),
- err);
+ msg(M_FATAL,
+ "There is a problem in your selection of --ifc= onfig endpoints [local=3D%s, remote=3D%s]. The local and remote VPN endpoi= nts %s. Try '" PACKAGE
+ " --show-valid-subnets' option for more info.= ",
+ prin= t_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc), err);<= /span>
gc_free(&gc);
}
=
@@ -4187,7 +3985,7 @@

= for (i =3D 0; i < 256; i +=3D 4)
{
- printf("[%3d,%3d] &quo= t;, i+1, i+2);

+ = printf("[%3d,%3d] ", i + 1, i + 2);
i= f (++col > 4)
{
co= l =3D 0;
@@ -4230,7 +4028,8 @@
{
if (!strcmp(tr->guid, pr->guid)) {
= - msg(msglev, "'%s' %s %s", pr->name, t= r->guid, print_tun_backend_driver(tr->windows_driver));
+ msg(msglev, "= ;'%s' %s %s", pr->name, tr->guid,

+ print_tun_backend_dri= ver(tr->windows_driver));
++links;
}
}
@@ -4= 268,12 +4067,14 @@

if (warn_panel_du= p)
{
- msg(warnlev, "WARNING: Some TAP-Windows adapters have dupl= icate links from the Network Connections control panel");
+ msg(warnlev,

<= span style=3D"color: hsl(120, 100%, 40%);">+ "WARNING: Some= TAP-Windows adapters have duplicate links from the Network Connections con= trol panel");

}

if (warn_panel_null)

{
- msg(warnlev, "WARNING: Some TAP-Wi= ndows adapters have no link from the Network Connections control panel"= ;);
+ msg(warn= lev,
+ &qu= ot;WARNING: Some TAP-Windows adapters have no link from the Network Connect= ions control panel");
}
<= br> gc_free(&gc);
@@ -4315,7 +4116,8 @@
}

static const struct tap_re= g *
-get_adapter_by_nam= e(const char *name, const struct tap_reg *tap_reg, const struct panel_reg *= panel_reg)
+get_adapt= er_by_name(const char *name, const struct tap_reg *tap_reg,
+ const struct pa= nel_reg *panel_reg)

{
const struct pa= nel_reg *pr;

@@ -4336,8 +4138,8 @@=
if (!tap_reg)
{
= msg(M_FATAL, "There are no TAP-Windows or ovpn-dco adapters "
- "on th= is system. You should be able to create an adapter "
- "by using tapctl.exe = utility.");
+ = "on this system. You should be able to create an ad= apter "
+ = "by using tapctl.exe utility.");
= }
}

@@ -4346,13 +4148= ,10 @@
* registry for the TAP device # =3D device_number.=
*/
static const char *
-get_unspecified_device_guid(const int = device_number,
- = uint8_t *actual_name,
- int actual_name_size,
+get_unspecified_device_g= uid(const int device_number, uint8_t *actual_name, int actual_name_size,
const struct tap_reg *tap_reg_sr= c,
const struct panel_reg *pan= el_reg_src,
- = enum tun_driver_type *windows_driver,
- struct gc_are= na *gc)
+ = enum tun_driver_type *windows_driver, struct gc_arena *gc)<= /span>
{
const struct tap_reg *tap_reg =3D t= ap_reg_src;
struct buffer actual =3D clear_buf();
@@ -4412,13 +4211,9 @@
* returning the GUID a= nd optional actual_name and device type
*/
static const char *

= -get_device_guid(const char *name,
- uint8_t *actual_name,
- int actual_name_size,- enum tun_drive= r_type *windows_driver,
- const struct tap_reg *tap_reg,
- const struct panel_reg *panel_re= g,
- str= uct gc_arena *gc)
+ge= t_device_guid(const char *name, uint8_t *actual_name, int actual_name_size,=
+ enu= m tun_driver_type *windows_driver, const struct tap_reg *tap_reg,+ const struct = panel_reg *panel_reg, struct gc_arena *gc)
{
struct buffer ret =3D alloc_buf_gc(256, gc);

s= truct buffer actual =3D clear_buf();
@@ -4488,17 +4283,15 @= @

if ((status =3D GetAdaptersInfo(NU= LL, &size)) !=3D ERROR_BUFFER_OVERFLOW)
{- msg(M_INFO, "GetA= daptersInfo #1 failed (status=3D%u) : %s",
- (unsigned int)status,
+ msg(M_INFO, "GetAdapte= rsInfo #1 failed (status=3D%u) : %s", (unsigned int)status,

= strerror_win32(status, gc));
}
else
{
- pi =3D (PIP_ADAPTER_INFO) gc_malloc(size, fa= lse, gc);
+ pi= =3D (PIP_ADAPTER_INFO)gc_malloc(size, false, gc);
= if ((status =3D GetAdaptersInfo(pi, &size)) !=3D NO_ERROR)
<= span> {

- = msg(M_INFO, "GetAdaptersInfo #2 failed (status=3D%u) : %s",=
- (unsi= gned int)status,
+ = msg(M_INFO, "GetAdaptersInfo #2 failed (status=3D%u) : %s&quo= t;, (unsigned int)status,
strerror_win32(s= tatus, gc));
pi =3D NULL;
= }
@@ -4517,21 +4310,19 @@
{
if ((status =3D GetPerAdapterInfo(index, NULL, &siz= e)) !=3D ERROR_BUFFER_OVERFLOW)
{
- msg(M_INFO, "GetPerAd= apterInfo #1 failed (status=3D%u) : %s",
- (unsigned int)status,
+ msg(M_INFO, "Get= PerAdapterInfo #1 failed (status=3D%u) : %s", (unsigned int)status,
strerror_win32(status, gc));
}

else
{=
- pi =3D (PIP_PER_= ADAPTER_INFO) gc_malloc(size, false, gc);
+ pi =3D (PIP_PER_ADAPTER_INFO)gc_malloc(si= ze, false, gc);
if ((status =3D GetPerAdapterI= nfo((ULONG)index, pi, &size)) =3D=3D ERROR_SUCCESS)
= {
return pi;
= }
else
= {
- msg(= M_INFO, "GetPerAdapterInfo #2 failed (status=3D%u) : %s",<= br>- (unsigned= int)status,
+ = msg(M_INFO, "GetPerAdapterInfo #2 failed (status=3D%u) : %s&q= uot;, (unsigned int)status,
strerror_w= in32(status, gc));
}
= }
@@ -4548,21 +4339,19 @@

if ((status =3D GetInterfaceInfo(NULL, &size)) !=3D ERROR_INSUFFI= CIENT_BUFFER)

{
- msg(M_INFO, "GetInterfaceInfo #1 failed (status= =3D%u) : %s",
- = (unsigned int)status,
+ msg(M_INFO, "GetInterfaceInfo #1 failed (status=3D%= u) : %s", (unsigned int)status,
strerror_= win32(status, gc));
}
else=
{
- = ii =3D (PIP_INTERFACE_INFO) gc_malloc(size, false, gc);
+ ii =3D (PIP_INTERFACE_INFO)g= c_malloc(size, false, gc);
if ((status =3D GetInte= rfaceInfo(ii, &size)) =3D=3D NO_ERROR)
{
return ii;
}
else

{
- msg(M_INFO, "GetInterfaceInfo #2 fai= led (status=3D%u) : %s",
- (unsigned int)status,
+ msg(M_INFO, "GetInterfaceInfo #2= failed (status=3D%u) : %s", (unsigned int)status,
= strerror_win32(status, gc));
}
}
@@ -4750,7 +4539,6 @@
= else
{
ret =3D true; /* thi= s can occur when TAP adapter is bridged */
-
}
return re= t;
}
@@ -4774,7 +4562,8 @@
in_addr_t adapter_ip, adapter_netmask;

= if (get_adapter_ip_netmask(ai, i, &adapter_ip, &adapter_netm= ask))
{
- if (adapter_ip && adapter_netmask &a= mp;& (ip & adapter_netmask) =3D=3D (adapter_ip & adapter_netmas= k))
+ = if (adapter_ip && adapter_netmask
+ && (ip & adapter_netm= ask) =3D=3D (adapter_ip & adapter_netmask))
= {
if (highest_netmask &&= adapter_netmask > *highest_netmask)
= {
@@ -4789,10 +4578,7 @@
}

DWORD
-adapter_index_of_ip(const IP_ADAPTER_INFO *list,
- const in_addr_t ip,
- int = *count,
- = in_addr_t *netmask)
+adapter_index_of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, = int *count, in_addr_t *netmask)
{
str= uct gc_arena gc =3D gc_new();
DWORD ret =3D TUN_ADAPTE= R_INDEX_INVALID;
@@ -4843,11 +4629,8 @@
= }

dmsg(D_ROUTE_DEBUG, "DEBUG:= IP Locate: ip=3D%s nm=3D%s index=3D%d count=3D%d metric=3D%d",=
- print_in_addr_t(ip,= 0, &gc),
- = print_in_addr_t(highest_netmask, 0, &gc),
- (int)ret,
- count ? *count : -1,
- lowest_metric);
+ print_in_addr_t(ip, 0, &g= c), print_in_addr_t(highest_netmask, 0, &gc), (int)ret,
+ count ? *count : -1, lowes= t_metric);


if (ret =3D=3D TUN_ADAPTE= R_INDEX_INVALID && count)
{
@@= -4868,9 +4651,9 @@
* is DHCP disabled.
= */

-= #define DHCP_STATUS_UNDEF 0
-#define DHCP_STATUS_ENABLED 1
-#define DHCP_STATUS_DISABLED 2
+#define DHCP_STATUS_UNDEF 0
= +#define DHCP_STATUS_ENABLED 1=
+#define DHCP_STATUS= _DISABLED 2

static int
= dhcp_status(DWORD index)
@@ -4915,22 +4698,19 @@
= DWORD status;
const DWORD c= ontext =3D ip->Context;

- if ((status =3D DeleteIPAddress((ULONG) = context)) =3D=3D NO_ERROR)
+ if ((status =3D DeleteIPAddress((ULONG)context)) =3D=3D = NO_ERROR)
{
m= sg(M_INFO, "Successfully deleted previously set dynamic IP/netmask: %s= /%s",
- = ip->IpAddress.String,
- ip->IpMask.String);
+ ip->IpAddress.Str= ing, ip->IpMask.String);
}
= else
{
= const char *empty =3D "0.0.0.0";
- if (strcmp(ip->IpAddress.Str= ing, empty)
- = || strcmp(ip->IpMask.String, empty))
+ if (strcmp(ip->IpAddress.S= tring, empty) || strcmp(ip->IpMask.String, empty))
= {
- = msg(M_INFO, "NOTE: could not delete previously set dynamic= IP/netmask: %s/%s (status=3D%u)",
- ip->IpAddress.String,- ip->= ;IpMask.String,
- = (unsigned int)status);
+ msg(M_INFO,
+ "NOTE: could= not delete previously set dynamic IP/netmask: %s/%s (status=3D%u)",
+ = ip->IpAddress.String, ip->IpMask.String, (unsigned int)status);
}
}
<= span> ip =3D ip->Next;

@@ -5100,7 +4880,7 @@=
}
else
{
- msg(M_INFO|M_NOP= REFIX, "TAP-Windows device: %s [Non-admin access allowed]", devic= e_path);
+ msg= (M_INFO | M_NOPREFIX, "TAP-Windows device: %s [Non-admin access allowe= d]", device_path);
}
}
@@ -5120,7 +4900,8 @@
if (dev= _node)
{
/* Get the device GU= ID for the device specified with --dev-node. */
- device_guid =3D get_device_guid(dev_node,= actual_buffer, sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);<= /span>
+ device_guid = =3D get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), NULL, t= ap_reg,
+ = panel_reg, &gc);

= if (!device_guid)
{
@@ -5128,20 +4909,11 @@

}

/* Open Windows TAP-Windows adapter */
- snprintf(device_path, sizeof(d= evice_path), "%s%s%s",
- USERMODEDEVICEDIR,
- device_guid,
+ snprintf(device_path, sizeof(dev= ice_path), "%s%s%s", USERMODEDEVICEDIR, device_guid,
TAP_WIN_SUFFIX);


- hand =3D CreateFile(
<= span style=3D"color: hsl(0, 100%, 40%);">- device_path,
- MAXIMUM_ALLOWED,
- 0, = /* was: FILE_SHARE_READ */
- 0,
- FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,- 0
- );
+ hand =3D CreateFile(device_path, MAX= IMUM_ALLOWED, 0, /* was: FILE_SHARE_READ */
+ 0, OPEN_EXISTING, FILE_AT= TRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);

if (hand =3D=3D INVALID_HANDLE_VALUE)

{=
@@ -5158,13 +4930,8 @@
/* Try ope= ning all TAP devices */
while (true)
{

- = device_guid =3D get_unspecified_device_guid(device_number,
- = actual_buffer,

- sizeof(a= ctual_buffer),
- = tap_reg,
- = panel_reg,
- NULL,
- = &gc);

+ device_guid =3D get_unspecified_device_guid(+ device_number= , actual_buffer, sizeof(actual_buffer), tap_reg, panel_reg, NULL, &gc);=

if (!device_guid) {
@@ -5172,20 +4939,11 @@
}


/* Open Wi= ndows TAP-Windows adapter */
- snprintf(device_path, sizeof(device_path), "%s%s%s&= quot;,
- = USERMODEDEVICEDIR,
+ snprintf(device_path, sizeof(device_path), &qu= ot;%s%s%s", USERMODEDEVICEDIR, device_guid,
= TAP_WIN_SUFFIX);

- hand =3D CreateFile(
- device_path,
= - MAXIMUM_ALLOWED,=
- 0, = /* was: FILE_SHARE_READ */
- 0,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVE= RLAPPED,
- = 0
- )= ;
+ hand = =3D CreateFile(device_path, MAXIMUM_ALLOWED, 0, /* was: FILE_SHARE_READ */<= /span>
+ = 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0= );

if (hand =3D=3D INVALID_H= ANDLE_VALUE)
{
@@ -5223,9 +498= 1,9 @@
}
else
<= span> {

- = msg(M_WARN, "NOTE: Release of DHCP-assigned IP address lease on = TAP-Windows adapter failed: %s (code=3D%u)",
- strerror_win32(status, &gc)= ,
- (uns= igned int)status);
+ = msg(M_WARN,
+ strerror_win32(status, &= gc), (unsigned int)status);
}
= }

@@ -5236,7 +4994,8 @@
= static bool
dhcp_release(const struct tuntap *tt)<= br> {
- if (tt= && tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ &&a= mp; tt->adapter_index !=3D TUN_ADAPTER_INDEX_INVALID)
+ if (tt && tt->options.i= p_win32_type =3D=3D IPW32_SET_DHCP_MASQ
+ && tt->adapter_index !=3D TUN_ADAPTE= R_INDEX_INVALID)
{
return dhc= p_release_by_adapter_index(tt->adapter_index);
}
@@ -5263,9 +5022,9 @@
}
else

{
- msg(M_WARN, "WARNING: Failed to ren= ew DHCP IP address lease on TAP-Windows adapter: %s (code=3D%u)",
- strerror_w= in32(status, &gc),
= - (unsigned int)status);
+ msg(M_WARN,
+ "WARNING: Failed to renew DHCP= IP address lease on TAP-Windows adapter: %s (code=3D%u)",
<= span style=3D"color: hsl(120, 100%, 40%);">+ strerror_win32(= status, &gc), (unsigned int)status);

}<= br> }
gc_free(&gc);
@@ -= 5275,7 +5034,8 @@
static bool
dhcp_renew(= const struct tuntap *tt)
{
- if (tt && tt->options.ip_win32_type = =3D=3D IPW32_SET_DHCP_MASQ && tt->adapter_index !=3D TUN_ADAPTER= _INDEX_INVALID)
+ = if (tt && tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ
+ && tt= ->adapter_index !=3D TUN_ADAPTER_INDEX_INVALID)
{
return dhcp_renew_by_adapter_index(tt->adapter_i= ndex);
}
@@ -5321,15 +5081,11 @@
msg(D_TUNTAP_INFO, "Start ipconfig commands for regist= er-dns...");
netcmd_semaphore_lock();
<= span>

- argv_printf= (&argv, "%s%s /flushdns",
- get_win_sys_path(),
- WIN_IPCONFIG_PATH_SUFFIX);<= /span>
+ argv_printf(&= ;argv, "%s%s /flushdns", get_win_sys_path(), WIN_IPCONFIG_PATH_SU= FFIX);
argv_msg(D_TUNTAP_INFO, &argv);
<= span> openvpn_execve_check(&argv, es, 0, err);


- argv_printf(&arg= v, "%s%s /registerdns",
- get_win_sys_path(),
- WIN_IPCONFIG_PATH_SUFFIX);=
+ argv_printf(&argv,= "%s%s /registerdns", get_win_sys_path(), WIN_IPCONFIG_PATH_SUFFI= X);
argv_msg(D_TUNTAP_INFO, &argv);
openvpn_execve_check(&argv, es, 0, err);

ar= gv_free(&argv);
@@ -5430,34 +5186,28 @@
* are cleared first.

*/
static void
-netsh_set_dns6_servers(= const struct in6_addr *addr_list,
- const int addr_len,
- DWORD adapter_index= )
+netsh_set_dns6_ser= vers(const struct in6_addr *addr_list, const int addr_len, DWORD adapter_in= dex)
{
struct gc_arena gc =3D gc_new(= );
struct argv argv =3D argv_new();
<= /span>
/* delete existing DNS settings from TAP interface */<= /span>
- argv_printf(&a= rgv, "%s%s interface ipv6 delete dns %lu all",
- get_win_sys_path(),
- NETSH_PATH= _SUFFIX,
- = adapter_index);
+ = argv_printf(&argv, "%s%s interface ipv6 delete dns %lu all"= ;, get_win_sys_path(),
- const char *fmt =3D (i = =3D=3D 0) ?
- = "%s%s interface ipv6 set dns %lu static %s"
- := "%s%s interface ipv6 add dns %lu %s";
- argv_printf(&argv, fmt, get_win_sys_= path(),
- = NETSH_PATH_SUFFIX, adapter_index,
+ const char *fmt =3D (i =3D=3D 0) ? "%s%s i= nterface ipv6 set dns %lu static %s"
+ : "%s%s inter= face ipv6 add dns %lu %s";
+ argv_printf(&argv, fmt, get_win_sys_path(), NETSH_P= ATH_SUFFIX, adapter_index,
print_in6_a= ddr(addr_list[i], 0, &gc));

= /* disable slow address validation */
argv_printf_= cat(&argv, "%s", "validate=3Dno");
=
/* Treat errors while adding as non-fatal as we = do not check for duplicates */
- netsh_command(&argv, 1, (i=3D=3D0) ? M_FATAL : M_NONFA= TAL);
+ netsh_= command(&argv, 1, (i =3D=3D 0) ? M_FATAL : M_NONFATAL);
}


argv_free(&argv);=
@@ -5465,12 +5215,8 @@
}

static void
-netsh_ifconfig_options(const char *type,
- const in_addr_t *addr_list,

- co= nst int addr_len,
- = const IP_ADDR_STRING *current,
- DWORD adapter_index,
- co= nst bool test_first)
= +netsh_ifconfig_options(const char *type, const in_addr_t *addr_list, const= int addr_len,
+ = const IP_ADDR_STRING *current, DWORD adapter_index, const= bool test_first)
{
struct gc_arena g= c =3D gc_new();
struct argv argv =3D argv_new();
@@ -5493,11 +5239,8 @@
/* delete existing D= NS/WINS settings from TAP interface */
if (delete_firs= t)
{
- argv_printf(&argv, "%s%s interface ip delete %s %lu al= l",
- = get_win_sys_path(),
- NETSH_PATH_SUFFIX,
- type,
- adapter_index);
+ argv_printf(&argv, &q= uot;%s%s interface ip delete %s %lu all", get_win_sys_path(),
+ NETSH_PA= TH_SUFFIX, type, adapter_index);
netsh_command(&am= p;argv, 2, M_FATAL);
}

@@ -5509,15 +5252,10 @@

{
= if (delete_first || !test_first || !ip_addr_member_of(addr_list[i],= current))
{
- const char *fmt =3D count ?
<= span style=3D"color: hsl(0, 100%, 40%);">- = "%s%s interface ip add %s %lu %s"

- : "%s%s inter= face ip set %s %lu static %s";
+ const char *fmt =3D count ? "%s%s inte= rface ip add %s %lu %s"
+ : "%s%s interface ip = set %s %lu static %s";

- argv_printf(&argv, fmt,<= br>- g= et_win_sys_path(),
- = NETSH_PATH_SUFFIX,
- type,
- adapter_index= ,
+ ar= gv_printf(&argv, fmt, get_win_sys_path(), NETSH_PATH_SUFFIX, type, adap= ter_index,
print_in_addr_t(add= r_list[i], 0, &gc));

= /* disable slow address validation for DNS */
@@ -5532,9 += 5270,7 @@
}
else<= /span>
{
- msg(M_INFO, "NETSH: %lu %s %s [already set]&q= uot;,
- = adapter_index,
- = type,
-netsh_ifconfig(const struct tuntap_options *to,- DWORD adapter_in= dex,
- co= nst in_addr_t ip,
- = const in_addr_t netmask,
- const unsigned int flags)
+netsh_ifconfig(const struct tuntap_optio= ns *to, DWORD adapter_index, const in_addr_t ip,
+ const in_addr_t netmask, const = unsigned int flags)
{
struct gc_arena= gc =3D gc_new();
struct argv argv =3D argv_new();
@@ -5585,19 +5318,14 @@
{
if (test_adapter_ip_netmask(ai, ip, netmask))

= {
- ms= g(M_INFO, "NETSH: %lu %s/%s [already set]",
- adapter_index,
- print_in_addr_t(ip= , 0, &gc),

- = print_in_addr_t(netmask, 0, &gc));
+ msg(M_INFO, "NETSH: %lu %s/%s = [already set]", adapter_index,
+ print_in_addr_t(ip, 0, &gc), print_in_a= ddr_t(netmask, 0, &gc));
}
= else
{
/* examp= le: netsh interface ip set address 42 static 10.3.0.1 255.255.255.0 */
- argv_printf(&a= mp;argv, "%s%s interface ip set address %lu static %s %s",=
- get_= win_sys_path(),
- = NETSH_PATH_SUFFIX,
- adapter_index,
- print_in_addr_t(ip,= 0, &gc),
+ = argv_printf(&argv, "%s%s interface ip set address %lu static= %s %s", get_win_sys_path(),
+ NETSH_PATH_SUFFIX, adapter_index, pri= nt_in_addr_t(ip, 0, &gc),
prin= t_in_addr_t(netmask, 0, &gc));

= netsh_command(&argv, 4, M_FATAL);
@@ -5611,22 +5= 339,14 @@
CLEAR(wins[0]);
= CLEAR(wins[1]);

- netsh_ifconfig_options("dns",
- to-&g= t;dns,

- = to->dns_len,
- pai ? &pai->DnsServerList := NULL,
- = adapter_index,
- BOOL_CAST(flags & NI_TEST_FIRST= ));
+ netsh_if= config_options("dns", to->dns, to->dns_len, pai ? &pai-= >DnsServerList : NULL,
+ adapter_index, BOOL_CAST(flags & N= I_TEST_FIRST));
if (ai && ai->HaveWins)=
{
init_ip_addr_strin= g2(wins, &ai->PrimaryWinsServer, &ai->SecondaryWinsServer);
}

- netsh_ifconfig_options("wins",
- = to->wins,
- = to->wins_len,
- ai ? wins : NULL,
- = adapter_index,
+= netsh_ifconfig_options("wins", to->wins, to->wins_l= en, ai ? wins : NULL, adapter_index,
= BOOL_CAST(flags & NI_TEST_FIRST));
}

@@ -5640,11 +5360,8 @@
= struct argv argv =3D argv_new();

/* = example: netsh interface ip set address 42 dhcp */
- argv_printf(&argv,
- "%s%s interface ip s= et address %lu dhcp",
- get_win_sys_path(),
- NETSH_PATH_SUFFIX,
- adapter_index);
<= span style=3D"color: hsl(120, 100%, 40%);">+ argv_printf(&argv, &quo= t;%s%s interface ip set address %lu dhcp", get_win_sys_path(),
<= br>+ NETSH_PATH_= SUFFIX, adapter_index);

netsh_comman= d(&argv, 4, M_FATAL);

@@ -5660,14 +53= 77,8 @@
struct gc_arena gc =3D gc_new();
HANDLE pipe =3D tt->options.msg_channel;


- enable_dhcp_message_t d= hcp =3D {
- .hea= der =3D {
- = msg_enable_dhcp,
- = sizeof(enable_dhcp_message_t),
- 0
- },
- = .iface =3D { .index =3D tt->adapter_index, .name =3D "" }=
- };
+ enable_dhcp_message_t dhcp =3D= { .header =3D { msg_enable_dhcp, sizeof(enable_dhcp_message_t), 0 },
+ = .iface =3D { .index =3D tt->adapter_index, .name =3D "&qu= ot; } };

if (!send_msg_iservice(pipe= , &dhcp, sizeof(dhcp), &ack, "Enable_dhcp"))
{

@@ -5691,8 +5402,7 @@
}<= br>
static void
-windows_set_mtu(const int iface_index, const short family= ,
- cons= t int mtu)
+windows_s= et_mtu(const int iface_index, const short family, const int mtu)
= {
DWORD err =3D 0;
struct = gc_arena gc =3D gc_new();
@@ -5703,7 +5413,8 @@
<= span> ipiface.InterfaceIndex =3D iface_index;

if (= family =3D=3D AF_INET6 && mtu < 1280)
{
- msg(M_INFO, "= ;NOTE: IPv6 interface MTU < 1280 conflicts with IETF standards and might= not work");
+ = msg(M_INFO,
+ = "NOTE: IPv6 interface MTU < 1280 conflicts with IETF stan= dards and might not work");
}

err =3D GetIpInterfaceEntry(&ipiface);
@@ -5719,12 +5430,13 @@


if (err = !=3D NO_ERROR)
{
- msg(M_WARN, "TUN: Setting %s mtu failed: %s [s= tatus=3D%lu if_index=3D%d]",
- family_name, strerror_win32(err, &gc), err, ifa= ce_index);
+ m= sg(M_WARN, "TUN: Setting %s mtu failed: %s [status=3D%lu if_index=3D%d= ]", family_name,
+ strerror_win32(err, &gc), err, iface_index);
}

else
{
- msg(M_INFO, "%s MTU set = to %d on interface %d using SetIpInterfaceEntry()", family_name, mtu, = iface_index);

+ = msg(M_INFO, "%s MTU set to %d on interface %d using SetIpInterfaceEn= try()", family_name,
+ mtu, iface_index);
}
}


@@ -5744,13 +5456,16 @@

if (dev_node)
{
- guid =3D get_device_guid(d= ev_node, BPTR(&actual), BCAP(&actual), NULL, tap_reg, panel_reg, gc= );

+ guid =3D<= /span>
+ get_devi= ce_guid(dev_node, BPTR(&actual), BCAP(&actual), NULL, tap_reg, pane= l_reg, gc);
}
else
{

- guid = =3D get_unspecified_device_guid(0, BPTR(&actual), BCAP(&actual), ta= p_reg, panel_reg, NULL, gc);
+ guid =3D get_unspecified_device_guid(0, BPTR(&actual),= BCAP(&actual), tap_reg, panel_reg,
+ NULL, gc);

- = if (get_unspecified_device_guid(1, NULL, 0, tap_reg, panel_reg, NULL, gc= )) /* ambiguous if more than one TAP-Windows adapter */
+ if (get_unspecified_device_guid= (1, NULL, 0, tap_reg, panel_reg, NULL,
+ gc)) /* ambiguou= s if more than one TAP-Windows adapter */
{=
guid =3D NULL;
}
= @@ -5758,7 +5473,7 @@

if (!gui= d)
{
- return "NULL"; /* not found */
+ return "NULL"; /* no= t found */
}
else if (strcmp(BSTR= (&actual), "NULL"))
{
@@= -5766,7 +5481,7 @@
}
else=
{
- = return guid; /* no control panel name, return GUID instead */
+ return guid; /* = no control panel name, return GUID instead */
}=
}

@@ -5789,13 +5504,10 @@
if (tt->standby_iter =3D=3D IPW32_SET_ADAPTIVE_TRY_= NETSH)
{
msg(M_INFO, = "NOTE: now trying netsh (this may take some time)");
- netsh_ifconfig(&tt= ->options,

- = tt->adapter_index,
- tt->local,
- tt->ada= pter_netmask,

- = NI_TEST_FIRST|NI_IP_NETMASK|NI_OPTIONS);
+ netsh_ifconfig(&tt-= >options, tt->adapter_index, tt->local, tt->adapter_netmask,
+ = NI_TEST_FIRST | NI_IP_NETMASK | NI_OPTIONS);
= }
- else if (tt-= >standby_iter >=3D IPW32_SET_ADAPTIVE_TRY_NETSH*2)
+ else if (tt->standby_iter &= gt;=3D IPW32_SET_ADAPTIVE_TRY_NETSH * 2)
{<= br> ret =3D false;
}
<= span>@@ -5823,7 +5535,8 @@

}

<= span> static void

-writ= e_dhcp_u32_array(struct buffer *buf, const int type, const uint32_t *data, = const unsigned int len, bool *error)
+write_dhcp_u32_array(struct buffer *buf, const int type, c= onst uint32_t *data,
= + const unsigned int len, bool *error)
= {
if (len > 0)
{
@@ -5891,7 +5604,7 @@


for (i =3D= 0; i < array_len; i++)
{
- const char *ptr =3D str_array[i];
+ const char *ptr = =3D str_array[i];

if (strlen(ptr= ) + len + 1 > sizeof(tmp_buf))
{
@@ -5910,7 +5623,7 @@

{
= if (*ptr =3D=3D '.' || *ptr =3D=3D '\0')
{

- = tmp_buf[label_length_pos] =3D (len-label_length_pos)-1;<= br>+ tmp_buf[lab= el_length_pos] =3D (len - label_length_pos) - 1;
= label_length_pos =3D len;
if (*ptr = =3D=3D '\0')
{
@@ = -5967,9 +5680,7 @@

if (o->domain_= search_list_len > 0)
{
- write_dhcp_search_str(buf, 119, o->doma= in_search_list,
- = o->domain_search_list_len,
- &error);<= /span>
+ write_dhcp_s= earch_str(buf, 119, o->domain_search_list, o->domain_search_list_len,= &error);
}

= /* the MS DHCP server option 'Disable Netbios-over-TCP/IP
@@ -5982,10 +5693,10 @@

msg(M_WARN, "= build_dhcp_options_string: buffer overflow building DHCP options");
return false;
}<= br>- buf_write_u8(buf, 43= );
- buf_write_u= 8(buf, 6);/* total length field */
- buf_write_u8(buf, 0x001);
- buf_write_u8(buf, 4);/* length of the v= endor specified field */
+ buf_write_u8(buf, 43);
+ buf_write_u8(buf, 6); /* total length field */
+ buf_write_u8(buf= , 0x001);
+ bu= f_write_u8(buf, 4); /* length of the vendor specified field */
buf_write_u32(buf, 0x002);

}
return !error;

@@ -6082,7 +5793,9 @@

if (dsa =3D=3D local)
{
- msg(M_FATAL, "= ;ERROR: There is a clash between the --ifconfig local address and the inter= nal DHCP server address -- both are set to %s -- please use the --ip-win32 = dynamic option to choose a different free address from the --ifconfig subne= t for the internal DHCP server", print_in_addr_t(dsa, 0, &gc));
+ msg(M_FATAL,
+ "ERR= OR: There is a clash between the --ifconfig local address and the internal = DHCP server address -- both are set to %s -- please use the --ip-win32 dyna= mic option to choose a different free address from the --ifconfig subnet fo= r the internal DHCP server",
+ print_in_addr_t(dsa, 0, &gc));
}


if ((local & netmask) != =3D (dsa & netmask))
@@ -6100,38 +5813,38 @@
= ULONG info[3];
DWORD len;
= CLEAR(info);
- i= f (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_VERSION,
- &info, siz= eof(info),
- = &info, sizeof(info), &len, NULL))
+ if (DeviceIoControl(tt->hand, TAP= _WIN_IOCTL_GET_VERSION, &info, sizeof(info), &info,
+ sizeof(info= ), &len, NULL))

{
- msg(D_TUNTAP_INFO, "TAP-Windows Driver Ve= rsion %d.%d %s",
-= (int)info[0],
- (int)info[1],
+ msg(D_TUNTAP_INFO, "TAP-Windows Driver Version %d.%d= %s", (int)info[0], (int)info[1],
(info[2= ] ? "(DEBUG)" : ""));
-
}
if (!(info= [0] =3D=3D TAP_WIN_MIN_MAJOR && info[1] >=3D TAP_WIN_MIN_MINOR))=
{
- msg(M_FATAL, "ERROR: This version of " PACKAGE_NAME &q= uot; requires a TAP-Windows driver that is at least version %d.%d -- If you= recently upgraded your " PACKAGE_NAME " distribution, a reboot i= s probably required at this point to get Windows to see the new driver.&quo= t;,
- TAP_WI= N_MIN_MAJOR,
- = TAP_WIN_MIN_MINOR);
+ "ERROR: This version of " PACKAGE_NAME+ " requires a= TAP-Windows driver that is at least version %d.%d -- If you recently upgra= ded your " PACKAGE_NAME
+ " distribution, a reboot is probably required at = this point to get Windows to see the new driver.",
+ TAP_WIN_MIN_MAJOR, TAP_WIN_= MIN_MINOR);
}

/= * usage of numeric constants is ugly, but this is really tied to
= * *this* version of the driver
*/<= br>- if (tt->type =3D=3D DE= V_TYPE_TUN
- &am= p;& info[0] =3D=3D 9 && info[1] < 8)
+ if (tt->type =3D=3D DEV_TYPE_TUN &= amp;& info[0] =3D=3D 9 && info[1] < 8)
= {
- msg(M_INFO, = "WARNING: Tap-Win32 driver version %d.%d does not support IPv6 in TUN= mode. IPv6 will not work. Upgrade your Tap-Win32 driver.", (int)info[= 0], (int)info[1]);
+ = msg(M_INFO,
+ = "WARNING: Tap-Win32 driver version %d.%d does not support = IPv6 in TUN mode. IPv6 will not work. Upgrade your Tap-Win32 driver.",=
+ (int)in= fo[0], (int)info[1]);
}

/* tap driver 9.8 (2.2.0 and 2.2.1 release) is buggy

*/

- if (tt= ->type =3D=3D DEV_TYPE_TUN
- && info[0] =3D=3D 9 && info[1] =3D=3D 8)
+ if (tt->type = =3D=3D DEV_TYPE_TUN && info[0] =3D=3D 9 && info[1] =3D=3D 8= )
{
+ msg(M_FATAL,
+ "ERROR: Tap-Win32 driver version %d.%d = is buggy regarding small IPv4 packets in TUN mode. Upgrade your Tap-Win32 d= river.",
+ = (int)info[0], (int)info[1]);
}
= }

@@ -6140,43 +5853,33 @@
{

ULONG mtu =3D 0;
DWORD len;
- if (DeviceIoControl= (tt->hand, TAP_WIN_IOCTL_GET_MTU,
- &mtu, sizeof(mtu),
- &mtu, s= izeof(mtu), &len, NULL))

+ if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_MTU, &m= tu, sizeof(mtu), &mtu, sizeof(mtu), &len,
+ NULL))
{

msg(D_MTU_INFO, "TAP-Windows MTU=3D%= d", (int)mtu);
}
}

static void
-tuntap_set_ip_addr(struct tuntap *tt,
- const char *device_guid,
- bool d= hcp_masq_post)
+tunta= p_set_ip_addr(struct tuntap *tt, const char *device_guid, bool dhcp_masq_po= st)
{
struct gc_arena gc =3D gc_new()= ;
const DWORD index =3D tt->adapter_index;
/* flush arp cache */
- if (tt->backend_driver =3D=3D WINDOW= S_DRIVER_TAP_WINDOWS6
-= && index !=3D TUN_ADAPTER_INDEX_INVALID)
+ if (tt->backend_driver =3D=3D W= INDOWS_DRIVER_TAP_WINDOWS6 && index !=3D TUN_ADAPTER_INDEX_INVALID)=
{
DWORD status =3D -1;

if (tt->options.msg_channel)
{
ack_message_t ack;
- flush_neighbors= _message_t msg =3D {
- = .header =3D {
- msg_flush_neighbors,
- sizeof(flush_neighbors_messag= e_t),
- = 0
- = },
- .fa= mily =3D AF_INET,
- = .iface =3D {.index =3D index, .name =3D "" }- };
+ flush_neighbors_message= _t msg =3D { .header =3D { msg_flush_neighbors,

+ = sizeof(flush_neighbors_message_t), 0 },
+ = .family =3D AF_INET,
- if (send_msg_iservice(tt->optio= ns.msg_channel, &msg, sizeof(msg),
- &ack, "TUN"= ;))
+ if (= send_msg_iservice(tt->options.msg_channel, &msg, sizeof(msg), &a= ck, "TUN"))
{
= status =3D ack.error_number;
}
@@ -6188,17 +5891,13 @@

= if (status =3D=3D NO_ERROR)
{
- msg(M_INFO, "Successf= ul ARP Flush on interface [%lu] %s",
- index,
- device_guid);
+ msg(M_INFO, "Successful ARP= Flush on interface [%lu] %s", index, device_guid);
= }
else if (status !=3D -1)
= {
- = msg(D_TUNTAP_INFO, "NOTE: FlushIpNetTable failed on interface [%lu] %= s (status=3D%lu) : %s",
- index,
- device_guid,
- status,
- strerror_win32(status, &gc));+ msg(D_TUNTAP_INF= O,
+ &= quot;NOTE: FlushIpNetTable failed on interface [%lu] %s (status=3D%lu) : %s= ", index,
+ = device_guid, status, strerror_win32(status, &gc)); }

/*
<= span>@@ -6211,7 +5910,8 @@

/* check dhcp enabl= e status */
if (dhcp_status(index) =3D=3D DHCP= _STATUS_DISABLED)
{
- msg(M_WARN, "WARNING: You h= ave selected '--ip-win32 dynamic', which will not work unless the T= AP-Windows TCP/IP properties are set to 'Obtain an IP address automatic= ally'");
+ = msg(M_WARN,
+ "WARNING: You have selected '--ip-win32 = dynamic', which will not work unless the TAP-Windows TCP/IP properties = are set to 'Obtain an IP address automatically'");
<= span> }


/* force= an explicit DHCP lease renewal on TAP adapter? */
@@ -6233= ,20 +5933,21 @@
if (tt->did_ifconfig_setup &&am= p; tt->options.ip_win32_type =3D=3D IPW32_SET_IPAPI)
= {
DWORD status;
- const char *error_suffix =3D "I am having= trouble using the Windows 'IP helper API' to automatically set the= IP address -- consider using other --ip-win32 methods (not 'ipapi'= )";
+ con= st char *error_suffix =3D
+ "I am having trouble using the Windows 'IP helpe= r API' to automatically set the IP address -- consider using other --ip= -win32 methods (not 'ipapi')";

/* couldn't get adapter index */

i= f (index =3D=3D TUN_ADAPTER_INDEX_INVALID)
{
- msg(M_FATAL, &q= uot;ERROR: unable to get adapter index for interface %s -- %s",=
- device_guid,=
+ msg(M_F= ATAL, "ERROR: unable to get adapter index for interface %s -- %s"= , device_guid,
error_suffix);
}


/* check dhcp ena= ble status */
if (dhcp_status(index) =3D=3D DHCP_S= TATUS_DISABLED)
{
- msg(M_WARN, "NOTE: You have selected = (explicitly or by default) '--ip-win32 ipapi', which has a better c= hance of working correctly if the TAP-Windows TCP/IP properties are set to = 'Obtain an IP address automatically'");
+ msg(M_WARN,
+ "NOTE: You have = selected (explicitly or by default) '--ip-win32 ipapi', which has a= better chance of working correctly if the TAP-Windows TCP/IP properties ar= e set to 'Obtain an IP address automatically'");
}


/* delete previous= ly added IP addresses which were not
@@ -6254,28 +5955,21 @= @
delete_temp_addresses(index);
<= /span>
/* add a new IP address */
- if ((status =3D AddIPAddress(htonl(= tt->local),
- = htonl(tt->adapter_netmask),
- ind= ex,
- = &tt->ipapi_context,
- &tt->ipapi_= instance)) =3D=3D NO_ERROR)
+ if ((status =3D AddIPAddress(htonl(tt->local), htonl(tt-= >adapter_netmask), index,
+ &tt->ipapi_context, &= ;tt->ipapi_instance))
+ =3D=3D NO_ERROR)
{
- msg(M_INFO, "Succee= ded in adding a temporary IP/netmask of %s/%s to interface %s using the Win= 32 IP Helper API",

- print_in_addr_t(tt->local, 0, &gc),
- print_in_addr_t(tt-&= gt;adapter_netmask, 0, &gc),

- device_guid
- );
+ msg(M_INFO,
+ "Succeeded in adding a temporary I= P/netmask of %s/%s to interface %s using the Win32 IP Helper API",
+ print_i= n_addr_t(tt->local, 0, &gc), print_in_addr_t(tt->adapter_netmask,= 0, &gc),
+ = device_guid);
}
= else
{
- msg(M_FATAL, "ERROR: AddIPAddress %s/%s failed = on interface %s, index=3D%lu, status=3D%lu (windows error: '%s') --= %s",
- = print_in_addr_t(tt->local, 0, &gc),
- print_in_addr_t(tt->adapter_ne= tmask, 0, &gc),
- = device_guid,
- index,
- status,
- strerror_win32(status, &gc),
- error_suffix);+ msg(M_FATAL,
+ "ER= ROR: AddIPAddress %s/%s failed on interface %s, index=3D%lu, status=3D%lu (= windows error: '%s') -- %s",
+ print_in_addr_t(tt->local, 0, &= ;gc), print_in_addr_t(tt->adapter_netmask, 0, &gc),
+ device_guid, index, = status, strerror_win32(status, &gc), error_suffix);
= }
tt->ipapi_context_defined =3D true;
}
@@ -6288,11 +5982,11 @@
{

ULONG status =3D TRUE;
DWORD = len;
- if (!DeviceIo= Control(tt->hand, TAP_WIN_IOCTL_SET_MEDIA_STATUS,
- &status, sizeo= f(status),
- = &status, sizeof(status), &len, NULL))
+ if (!DeviceIoControl(tt->han= d, TAP_WIN_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status= ,

+ = sizeof(status), &len, NULL))
{
- msg(M_WARN, "WARNING:= The TAP-Windows driver rejected a TAP_WIN_IOCTL_SET_MEDIA_STATUS DeviceIoC= ontrol call.");

= + msg(M_WARN,
= + "WARNING: The TAP-Windows driver rejected a TAP_WIN_IOCTL= _SET_MEDIA_STATUS DeviceIoControl call.");
}

int s =3D tt->options.tap_sleep;
@@ -6326,17 +6020,16 @@
ep[1] =3D hton= l(tt->local & tt->remote_netmask);
ep[2]= =3D htonl(tt->remote_netmask);

- status =3D DeviceIoControl(tt->h= and, TAP_WIN_IOCTL_CONFIG_TUN,
- ep, sizeof(ep),
- ep, si= zeof(ep), &len, NULL);
+ status =3D DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG= _TUN, ep, sizeof(ep), ep, sizeof(ep),
+ &len, NULL);<= br>
if (tt->did_ifconfig_setup) {
- = msg(status ? M_INFO : M_FATAL, "Set TAP-Windows TUN subnet mo= de network/local/netmask =3D %s/%s/%s [%s]",
+ msg(status ? M_INFO : M_FATAL,
+ "= Set TAP-Windows TUN subnet mode network/local/netmask =3D %s/%s/%s [%s]&quo= t;,
print_in_addr_t(ep[1], IA_NET_ORDER, &= amp;gc),
print_in_addr_t(ep[0], IA_NET_ORD= ER, &gc),
- = print_in_addr_t(ep[2], IA_NET_ORDER, &gc),
- status ? "SUCCEEDED&q= uot; : "FAILED");
+ print_in_addr_t(ep[2], IA_NET_ORDER, &gc), stat= us ? "SUCCEEDED" : "FAILED");
= }
else
{
= @@ -6350,11 +6043,11 @@
ep[0] =3D htonl(tt->loc= al);
ep[1] =3D htonl(tt->remote_netmask);

- i= f (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT,
- = ep, sizeof(ep),
- = ep, sizeof(ep), &len, NULL))
+ if (!DeviceIoControl(tt->h= and, TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT, ep, sizeof(ep), ep,
+ size= of(ep), &len, NULL))

{
- msg(M_FATAL, "ERROR: The T= AP-Windows driver rejected a DeviceIoControl call to set Point-to-Point mod= e, which is required for --dev tun");
+ msg(M_FATAL,
+ "ERROR: The TAP-Windows dr= iver rejected a DeviceIoControl call to set Point-to-Point mode, which is r= equired for --dev tun");
}
= }

@@ -6377,7 +6070,9 @@
{

if (tt->topology =3D=3D TOP_SUBNET)
{
+ ep= [2] =3D dhcp_masq_addr(
+ tt->local, tt->remote_netmask,
+ tt->options.dhcp_ma= sq_custom_offset ? tt->options.dhcp_masq_offset : 0);
= }
else
{@@ -6387,7 +6082,9 @@
else
= {
ASSERT(tt->type =3D=3D DEV_TYPE_TAP);=
- ep[2] =3D dhcp_masq_= addr(tt->local, tt->adapter_netmask, tt->options.dhcp_masq_custom_= offset ? tt->options.dhcp_masq_offset : 0);
+ ep[2] =3D
+ dhcp_masq_addr(tt->local, tt->ad= apter_netmask,
+ = tt->options.dhcp_masq_custom_offset ? tt->optio= ns.dhcp_masq_offset : 0);
}
/* lease time in seconds */
@@ -6396,20 +6093,= 17 @@
ASSERT(ep[3] > 0);
#ifndef SIMULATE_DHCP_FAILED /* this code is disabled to simulate = bad DHCP negotiation */
- if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_CONFIG_DHCP_MASQ,
- = ep, sizeof(ep),
- = ep, sizeof(ep), &len, NULL))
+ if (!DeviceIoControl(tt->hand, TAP= _WIN_IOCTL_CONFIG_DHCP_MASQ, ep, sizeof(ep), ep, sizeof(ep),
+ &len,= NULL))

{
- msg(M_FATAL, "ERROR: The TAP-Windows driver rejected = a DeviceIoControl call to set TAP_WIN_IOCTL_CONFIG_DHCP_MASQ mode");
+ msg(M_FATAL,<= /span>
+ "ER= ROR: The TAP-Windows driver rejected a DeviceIoControl call to set TAP_WIN_= IOCTL_CONFIG_DHCP_MASQ mode");
}
=
- msg(M_INFO, &quo= t;Notified TAP-Windows driver to set a DHCP IP/netmask of %s/%s on interfac= e %s [DHCP-serv: %s, lease-time: %d]",
- print_in_addr_t(tt->local, 0, &gc),
- print_in_addr_t(= tt->adapter_netmask, 0, &gc),
- device_guid,
- print_in_addr_t(ep[2], IA_NET_ORDER, &gc),=
- ep[3]
- );

+ msg(M_INFO,
+ "Notified TAP-Windows driver to set = a DHCP IP/netmask of %s/%s on interface %s [DHCP-serv: %s, lease-time: %d]&= quot;,
+ print= _in_addr_t(tt->local, 0, &gc), print_in_addr_t(tt->adapter_netmas= k, 0, &gc),
+ = device_guid, print_in_addr_t(ep[2], IA_NET_ORDER, &gc), ep[3]);

/* user-supplied DHCP options capabilit= y */
if (tt->options.dhcp_options)
= @@ -6418,11 +6112,11 @@
if (build_dhcp_options_str= ing(&buf, &tt->options))
{
msg(D_DHCP_OPT, "DHCP option string: %s", format= _hex(BPTR(&buf), BLEN(&buf), 0, &gc));

- if (!DeviceIoControl(tt->hand, = TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT,
- BPTR(&buf), BLEN(&buf= ),
- = BPTR(&buf), BLEN(&buf), &len, NULL))
+ if (!DeviceIoControl= (tt->hand, TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT, BPTR(&buf),

= + = BLEN(&buf), BPTR(&buf), BLEN(&buf), &len, NULL))<= br> {
- msg(M_FATAL, "ERROR: The TAP-Windows driver rejected= a TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT DeviceIoControl call");+ msg(M_FATAL,<= /span>
+ = "ERROR: The TAP-Windows driver rejected a TAP_WIN_IOCTL_CONFIG_DHCP_SE= T_OPT DeviceIoControl call");
} }
else
@@ -6431,13= +6125,14 @@
}
free_buf(&= amp;buf);
}
-#endif /* ifndef SIMULATE_DHCP_FAILED */
+#endif /* ifndef SI= MULATE_DHCP_FAILED */

gc_free(&g= c);
}

static bool
-tun_try_open_device(struct = tuntap *tt, const char *device_guid, const struct device_instance_id_interf= ace *device_instance_id_interface)
+tun_try_open_device(struct tuntap *tt, const char *device_gu= id,
+ = const struct device_instance_id_interface *device_instance_id_interface= )
{
const char *path =3D NULL;=
char tuntap_device_path[256];
@@ -6456,8 +61= 51,7 @@
if (tt->backend_driver =3D=3D DRIVE= R_DCO)
{
char= *last_sep =3D strrchr(dev_if->device_interface, '\\');- if (!last_sep<= /span>
- ||= strcmp(last_sep + 1, DCO_WIN_REFERENCE_STRING) !=3D 0)
+ if (!last_sep || strcmp= (last_sep + 1, DCO_WIN_REFERENCE_STRING) !=3D 0)
= {
continue;
= }
@@ -6474,25 +6168,19 @@
= else
{
/* Open TAP-Windows = */
- snprintf(tu= ntap_device_path, sizeof(tuntap_device_path), "%s%s%s",- USERMODEDEVICE= DIR,
- = device_guid,
- = TAP_WIN_SUFFIX);
+ snprintf(tuntap_device_path, sizeof(tuntap_device_path), "= ;%s%s%s", USERMODEDEVICEDIR,
+ device_guid, TAP_WIN_SUFFIX);
path =3D tuntap_device_path;

}

msg(D_TAP_WIN_DEBUG, "Using device interfac= e: %s", path);

- tt->hand =3D CreateFile(path,
- GENERIC_READ | GE= NERIC_WRITE,
- = 0, /* was: FILE_SHARE_READ */
- 0,
- OPEN_EXIS= TING,

- = FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
- 0);
<= span style=3D"color: hsl(120, 100%, 40%);">+ tt->hand =3D CreateFile(= path, GENERIC_READ | GENERIC_WRITE, 0, /* was: FILE_SHARE_READ */
+ 0, = OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);
= if (tt->hand =3D=3D INVALID_HANDLE_VALUE)
= {
- msg(D_TUNT= AP_INFO | M_ERRNO, "CreateFile failed on %s device: %s", print_tu= n_backend_driver(tt->backend_driver), path);
+ msg(D_TUNTAP_INFO | M_ERRNO, "Crea= teFile failed on %s device: %s",
+ print_tun_backend_driver(tt->backend_drive= r), path);
return false;
}

@@ -6500,11 +6188,13 @@
}<= /span>

void
-tun_open_device(struct tuntap *tt, const char *dev_node, = const char **device_guid, struct gc_arena *gc)
+tun_open_device(struct tuntap *tt, const char *d= ev_node, const char **device_guid,
+ struct gc_arena *gc)
{
const struct tap_reg *tap_reg =3D get_tap_reg(gc);<= br> const struct panel_reg *panel_reg =3D get_panel_reg(gc);
- const struct device_in= stance_id_interface *device_instance_id_interface =3D get_device_instance_i= d_interface(gc);
+ = const struct device_instance_id_interface *device_instance_id_interface = =3D
+ get_devi= ce_instance_id_interface(gc);

uint8_= t actual_buffer[256];

@@ -6516,7 +6206,8 = @@
enum tun_driver_type windows_driver =3D WINDOWS= _DRIVER_UNSPECIFIED;

/* Get the = device GUID for the device specified with --dev-node. */
- *device_guid =3D get_device_guid= (dev_node, actual_buffer, sizeof(actual_buffer), &windows_driver, tap_r= eg, panel_reg, gc);
+= *device_guid =3D get_device_guid(dev_node, actual_buffer, sizeof(ac= tual_buffer),
+ = &windows_driver, tap_reg, panel_reg, g= c);

if (!*device_guid) {
@@ -6525,13 +6216,16 @@
=
if (tt->backend_driver !=3D windows_driver)
{
- dev_= node, print_tun_backend_driver(windows_driver), print_tun_backend_driver(tt= ->backend_driver));
+ "Adapter '%s' is using %s driver, %s e= xpected. If you want to use this device, adjust --windows-driver.",
+ dev_no= de, print_tun_backend_driver(windows_driver),
+ print_tun_backend_driver(tt->b= ackend_driver));
}

if (!tun_try_open_device(tt, *device_guid, device_instance_id_i= nterface))

{
- msg(M_FATAL, "Failed to open %s adapter: %= s", print_tun_backend_driver(tt->backend_driver), dev_node);=
+ msg(M_FATAL, &= quot;Failed to open %s adapter: %s",
+ print_tun_backend_driver(tt->backe= nd_driver), dev_node);
}
}
else
@@ -6543,20 +6237,18 @@
<= span> while (true)

{
= enum tun_driver_type windows_driver =3D WINDOWS_DRIVER_UNSPECIFIED;=
- *device_g= uid =3D get_unspecified_device_guid(device_number,
- = actual_buffer,
- sizeof(actual_buff= er),
- = tap_reg,
- = panel_reg,
- = &windows_driver,
- = gc);
+ *device_guid =3D
+ get_unspecified_device_guid(device_nu= mber, actual_buffer, sizeof(actual_buffer),
+ tap_reg= , panel_reg, &windows_driver, gc);

= if (!*device_guid)
{
/* try to create an adapter a few times if we have a ser= vice pipe handle */

- = if ((++adapters_created > 10) || !do_create_adapter_servic= e(tt->options.msg_channel, tt->backend_driver))
+ if ((++adapters_created &= gt; 10)
+ = || !do_create_adapter_service(tt->options.msg_channel, tt->ba= ckend_driver))
{
- msg(M_FATAL, "All %s a= dapters on this system are currently in use or disabled.", print_tun_b= ackend_driver(tt->backend_driver));
+ msg(M_FATAL, "All %s adapters o= n this system are currently in use or disabled.",
+ print_tun_backen= d_driver(tt->backend_driver));
}=
else
{@@ -6623,10 +6315,7 @@
*/
if (dhcp_status(tt->adapter_index) !=3D DHCP_STATUS_ENABLED)
{
- netsh_ifconfig(&tt->options,
- tt->adapter_i= ndex,
- = tt->local,
+ netsh_ifconfig(&tt->op= tions, tt->adapter_index, tt->local, tt->adapter_netmask, NI_TEST_FIRST | NI_IP_NETMASK | NI_OPTI= ONS);
}
else
@@ -6687,9 +6376,11 @@

if ((tt->options.dhcp_op= tions & DHCP_OPTIONS_DHCP_REQUIRED)
&&= tt->backend_driver !=3D WINDOWS_DRIVER_TAP_WINDOWS6)
= {
- msg(M_WAR= N, "Some --dhcp-option or --dns options require DHCP server,"
+ msg(M_WARN,
+ "Some = --dhcp-option or --dns options require DHCP server,"
= " which is not supported by the selected %s driver. They w= ill be"
- = " ignored.", print_tun_backend_driver(tt->backend_driver));=
+ " = ignored.",
+ = print_tun_backend_driver(tt->backend_driver));
= }

/* dco-win already opened the = device, which handle we treat as socket */
@@ -6702,11 +639= 3,11 @@

/*netcmd_semaphore_lock ();*= /

- = msg( M_INFO, "open_tun");
+ msg(M_INFO, "open_tun");
<= /span>
if (tt->type !=3D DEV_TYPE_TAP && tt->ty= pe !=3D DEV_TYPE_TUN)
{
- msg(M_FATAL|M_NOPREFIX, "Unknown virtua= l device type: '%s'", dev);
+ msg(M_FATAL | M_NOPREFIX, "Unknown virtua= l device type: '%s'", dev);
}
<= span>

struct gc_arena gc =3D gc_new(); /* used also f= or device_guid allocation */
@@ -6726,10 +6417,8 @@<= br> {
struct buffer out =3D alloc_buf_gc= (256, gc);
DWORD len;
- if (DeviceIoControl(tt->hand, TAP_WIN_I= OCTL_GET_INFO,
- = BSTR(&out), BCAP(&out),
- BSTR(&out),= BCAP(&out),
- = &len, NULL))
+ if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_= GET_INFO, BSTR(&out), BCAP(&out), BSTR(&out),
+ BCAP(&= ;out), &len, NULL))
{
= return BSTR(&out);
}
@@ -= 6744,10 +6433,8 @@
{
struct b= uffer out =3D alloc_buf(1024);
DWORD len;- while (DeviceIoControl= (tt->hand, TAP_WIN_IOCTL_GET_LOG_LINE,
- BSTR(&out), BCAP(&am= p;out),
- = BSTR(&out), BCAP(&out),
- &len, NULL))<= /span>
+ while (Devic= eIoControl(tt->hand, TAP_WIN_IOCTL_GET_LOG_LINE, BSTR(&out), BCAP(&a= mp;out),
+ = BSTR(&out), BCAP(&out), &len, NULL))=
{
msg(D_TAP_WIN_DEBUG, &quo= t;TAP-Windows: %s", BSTR(&out));
}=
@@ -6765,22 +6452,15 @@
int len =3D ipv6 ? t= t->options.dns6_len : tt->options.dns_len;
if (l= en > 0)
{
- argv_printf(&argv,
- "%s%s interface %s delete dns= %lu all",
- = get_win_sys_path(),
- NETSH_PATH_SUFFIX,
- ipv6 ? "ipv6" : = "ipv4",
- = tt->adapter_index);
+ argv_printf(&argv, "%s%s interface %s d= elete dns %lu all", get_win_sys_path(),
+ NETSH_PATH_SUFFIX, ipv6 ? &quo= t;ipv6" : "ipv4", tt->adapter_index);
= netsh_command(&argv, 1, M_WARN);
}
if (!ipv6 && tt->options.wins_len = > 0)
{
- argv_printf(&argv,
- "%s%s interface ipv4 delete wins= servers %lu all",
= - get_win_sys_path(),
- NETSH_PATH_SUFFIX,
- tt->adapter_inde= x);
+ argv_pri= ntf(&argv, "%s%s interface ipv4 delete winsservers %lu all", = get_win_sys_path(),
+= NETSH_PATH_SUFFIX, tt->adapter_index);
netsh_command(&argv, 1, M_WARN);

}

@@ -6802,13 +6482,8 @@
= {
ifconfig_ip_local =3D print_in_addr_t(tt->loc= al, 0, gc);
}
- argv_printf(&argv,
- "%s%s interface %s delete address %l= u %s store=3Dactive",
- get_win_sys_path(),
- NETSH_PATH_SUFFIX,
- ipv6 ? "ipv6" : &= quot;ipv4",
- = tt->adapter_index,
- ifconfig_ip_local);
+ argv_printf(&argv, "%s%s interface = %s delete address %lu %s store=3Dactive", get_win_sys_path(),+ NETSH_PATH_S= UFFIX, ipv6 ? "ipv6" : "ipv4", tt->adapter_index, if= config_ip_local);
netsh_command(&argv, 1, M_WARN);=

argv_free(&argv);
@@ -6886,7 +6561,8 @@

{
= /* We didn't do ifconfig. */
}- else if (tt->options= .ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ || tt->options.ip_win32_type = =3D=3D IPW32_SET_ADAPTIVE)
+ else if (tt->options.ip_win32_type =3D=3D IPW32_SET_DHCP_= MASQ
+ = || tt->options.ip_win32_type =3D=3D IPW32_SET_ADAPTIVE)
{

/* We don't have to clean the= configuration with DHCP. */
}
@@ = -6913,10 +6589,9 @@
DWORD status;
= if ((status =3D DeleteIPAddress(tt->ipapi_context)) !=3D NO_ERR= OR)
{
- msg(M_WARN, "Warning: DeleteIPAddress[%u] failed = on TAP-Windows adapter, status=3D%u : %s",
- (unsigned int)tt->ipapi_contex= t,
- (un= signed int)status,
- = strerror_win32(status, &gc));
+ msg(M_WARN,
+ "Warning: DeleteIPAddre= ss[%u] failed on TAP-Windows adapter, status=3D%u : %s",
+ (unsigned int)tt-= >ipapi_context, (unsigned int)status, strerror_win32(status, &gc));<= /span>
}
}
<= br>@@ -6935,17 +6610,14 @@
* Convert --ip-win32 con= stants between index and ascii form.
*/
=
-struct ipset_names {<= /span>
+struct ipset_names
+{
= const char *short_form;
};

<= span> /* Indexed by IPW32_SET_x */

static const struct ips= et_names ipset_names[] =3D {
- {"manual"},
- {"netsh"},
- {"ipapi"},
- {"dynamic"},
- {"adaptive"}
+ { "manual" }, { "netsh"= ; }, { "ipapi" }, { "dynamic" }, { "adaptive"= }
};

int
@@ -6995,7 +6667,7 @@

return BSTR(&out);=
}

-#else /* generic */
+#else /* generic */

void
open_tun(const char *dev, const char *dev= _type, const char *dev_node, struct tuntap *tt,
@@ -7025,4 = +6697,4 @@
return read(tt->fd, buf, len); }

-#endif /* if defined (TARGET_ANDROID) */
+#endif /* if defined (TARG= ET_ANDROID) */
diff --git a/src/openvpn/tun.h b/src/openvpn= /tun.h
index 5407e47..1c0f6f50 100644
--- a= /src/openvpn/tun.h
+++ b/src/openvpn/tun.h
= @@ -41,7 +41,8 @@
#include "networking.h"=
#include "dco.h"

-enum tun_driver_type {
+enum tun_driver_type
+{
WINDOWS_DRIVER= _UNSPECIFIED,
WINDOWS_DRIVER_TAP_WINDOWS6,
<= span> DRIVER_GENERIC_TUNTAP,

@@ -68,19 +69,20 @@=
#define IPW32_SET_ADAPTIVE_TRY_NETSH 20

/* bit flags for DHCP options */
-#define DHCP_OPTIONS_DHCP_OPTIONAL (1<<0)
-#define DHCP_OPTIONS_DHC= P_REQUIRED (1<<1)
+#define DHCP_OPTIONS_DHCP_OPTIONAL (1 << 0)
+#define DHCP_OPTIONS_DHCP_REQUIRED (1 <= ;< 1)

-struct tuntap_options {
+struct tuntap_options
+{
/* --ip-win32 options */
= bool ip_win32_defined;

-#define IPW32_SET_MANUAL 0 /* "--ip-wi= n32 manual" */
-#d= efine IPW32_SET_NETSH 1 /* "--ip-win32 netsh" */<= br>-#define IPW32_SET_IPAPI = 2 /* "--ip-win32 ipapi" */
-#define IPW32_SET_DHCP_MASQ 3 /* "--ip-win32 d= ynamic" */
-#defin= e IPW32_SET_ADAPTIVE 4 /* "--ip-win32 adaptive" */-#define IPW32_SET_N = 5
+#define IPW32_SET= _MANUAL 0 /* "--ip-win32 manual" */
+#define IPW32_SET_NETSH 1 /* "--ip-wi= n32 netsh" */
+#= define IPW32_SET_IPAPI 2 /* "--ip-win32 ipapi" */
<= span style=3D"color: hsl(120, 100%, 40%);">+#define IPW32_SET_DHCP_MASQ 3 /= * "--ip-win32 dynamic" */

+#define IPW32_SET_ADAPTIVE 4 /* "--ip-win32 adaptive&= quot; */
+#define IPW= 32_SET_N 5
int ip_win32_type;
=
#ifdef _WIN32
@@ -99,14 +101,15 @@

int dhcp_options;

- const char *domain; = /* DOMAIN (15) */
+= const char *domain; /* DOMAIN (15) */
const char *netbios_scope; /* NBS (47) */

- int netbios_node_typ= e; /* NBT 1,2,4,8 (46) */
+ int netbios_node_type; /* NBT 1,2,4,8 (46) */

-#define N_DHCP_AD= DR 4 /* Max # of addresses allowed for
- * DNS, WINS, etc. */<= /span>
+#define N_DHCP_ADDR = \
+ 4 /* Max # of addresses allowed for \
+ * DNS, WINS, etc. */

/* DNS (6) */
in_addr_t dns[N_DHCP_ADD= R];
@@ -148,13 +151,15 @@

#elif defined(TARGET_LINUX)


-struct tuntap_options {
+struct tuntap_options
+{
int txqueuelen;
};

#else /* if defined(_= WIN32) || defined(TARGET_ANDROID) */

-struct tuntap_options {
+struct tuntap_options
+{
int dummy; /*= not used */
};

@@ -170,= 7 +175,8 @@
} afunix_context_t;
#else /* ifndef WIN32 */
-typedef struct {
+typedef struct
+{
int dummy;
} afunix_context_t;<= /span>
#endif
@@ -196,11 +202,11 @@
* been set up. This does NOT mean ifconfig has been called */
bool did_ifconfig_ipv6_setup;

= - bool persistent_if; = /* if existed before, keep on program end */
+ bool persistent_if; /* if existed b= efore, keep on program end */

struct= tuntap_options options; /* options set on command line */
=
- char *actual_nam= e; /* actual name of TUN/TAP dev, usually including unit number */+ char *actual_name; = /* actual name of TUN/TAP dev, usually including unit number */

/* ifconfig parameters */
in_addr_t local;

@@ -231,7 +237,7 @@

int standby_iter;

- #else /* ifdef _WIN32 */
<= br>+#else /* ifdef _WIN32 */
int fd; /* file descriptor for TUN/TAP dev */ #endif /* ifdef _WIN32 */

@@ -260= ,13 +266,13 @@
* Function prototypes
*/=

-voi= d open_tun(const char *dev, const char *dev_type, const char *dev_node,
- struct tunt= ap *tt, openvpn_net_ctx_t *ctx);
+void open_tun(const char *dev, const char *dev_type, const cha= r *dev_node, struct tuntap *tt,
+ openvpn_net_ctx_t *ctx);
=
void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx);

-void tun_= open_device(struct tuntap *tt, const char *dev_node,
- const char **device_gu= id, struct gc_arena *gc);
+void tun_open_device(struct tuntap *tt, const char *dev_node, const c= har **device_guid,
+ = struct gc_arena *gc);

void close_tun_handle(struct tuntap *tt);


@@ -274,37 +280,29 @@


int read_tun(st= ruct tuntap *tt, uint8_t *buf, int len);

-void tuncfg(const char *dev, const cha= r *dev_type, const char *dev_node,
- int persist_mode, const char *username,
= - const char *groupnam= e, const struct tuntap_options *options,
+void tuncfg(const char *dev, const char *dev_type, con= st char *dev_node, int persist_mode,
+ const char *username, const char *groupname, c= onst struct tuntap_options *options,
openvpn_n= et_ctx_t *ctx);

-const char *guess_tuntap_dev(const char *dev,
- const char= *dev_type,
- = const char *dev_node,
+const char *guess_tuntap_dev(const char *dev, const ch= ar *dev_type, const char *dev_node,
= struct gc_arena *gc);

-struct tuntap *init_tun(const char *dev, /*= --dev option */
- = const char *dev_type, /* --dev-type option */- int to= pology, /* one of the TOP_x values */
- const char *ifconfig_loca= l_parm, /* --ifconfig parm 1 */
- const char *ifconfig_remote_net= mask_parm, /* --ifconfig parm 2 */
- const char *ifconfig_ipv6_local_parm,= /* --ifconfig parm 1 / IPv6 */
- int ifconfig_ipv6_netbits_parm, = /* --ifconfig parm 1 / bits */
- const char *ifconfig_ipv6_remote_pa= rm, /* --ifconfig parm 2 / IPv6 */
- struct addrinfo *local_public,
- s= truct addrinfo *remote_public,
- const bool strict_warn,
- struct env_set *= es,
- = openvpn_net_ctx_t *ctx,
+struct tuntap *init_tun(const char *dev, = /* --dev option */
+= const char *dev_type, /* --dev-= type option */
+ = int topology, /* one of the = TOP_x values */
+ = const char *ifconfig_local_parm, /* --ifconfig= parm 1 */
+ = const char *ifconfig_remote_netmask_parm, /* --ifconfig parm= 2 */
+ = const char *ifconfig_ipv6_local_parm, /* --ifconfig parm 1 / = IPv6 */
+ = int ifconfig_ipv6_netbits_parm, /* --ifconfig parm 1 = / bits */
+ = const char *ifconfig_ipv6_remote_parm, /* --ifconfig parm = 2 / IPv6 */
+ = struct addrinfo *local_public, struct addrinfo *remote_publ= ic,
+ = const bool strict_warn, struct env_set *es, openvpn_net_ctx_t *ctx,=
struct tuntap *tt);

-void init_tun_pos= t(struct tuntap *tt,
- = const struct frame *frame,
+void init_tun_post(struct tuntap *tt, const struct= frame *frame,
const struct tuntap_opti= ons *options);

-void do_ifconfig_setenv(const struct tuntap *tt,
- struct env_se= t *es);

+void do_ifco= nfig_setenv(const struct tuntap *tt, struct env_set *es);
=
/**
* do_ifconfig - configure the tunne= l interface
@@ -315,8 +313,8 @@
* @param = es the environment to be used when executing the commands
= * @param ctx the networking API opaque context
*/

-void do_ifconfi= g(struct tuntap *tt, const char *ifname, int tun_mtu,
- const struct env_set *es, = openvpn_net_ctx_t *ctx);
+void do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu, c= onst struct env_set *es,
+ openvpn_net_ctx_t *ctx);

= /**
* undo_ifconfig - undo configuration of the tu= nnel interface
@@ -332,7 +330,8 @@
=
const char *dev_type_string(const char *dev, const char *dev_typ= e);

-= const char *ifconfig_options_string(const struct tuntap *tt, bool remote, b= ool disable, struct gc_arena *gc);
+const char *ifconfig_options_string(const struct tuntap *tt,= bool remote, bool disable,
+ struct gc_arena *gc);
bool is_tun_p2p(const struct tuntap *tt);<= br>
@@ -341,8 +340,7 @@
/**<= br> * Return a string representation of the tun backed driver type
*/
-co= nst char *
-print_tun_b= ackend_driver(enum tun_driver_type driver);
+const char *print_tun_backend_driver(enum tun_drive= r_type driver);

/*
* S= hould ifconfig be called before or after
@@ -352,7 +350,7 @= @
#define IFCONFIG_BEFORE_TUN_OPEN 0
#def= ine IFCONFIG_AFTER_TUN_OPEN 1

-#define IFCONFIG_DEFAULT IFCONFIG_AFTER_= TUN_OPEN
+#define IFC= ONFIG_DEFAULT IFCONFIG_AFTER_TUN_OPEN

st= atic inline int
ifconfig_order(struct tuntap *tt)@@ -375,13 +373,13 @@
return IFCONFIG_AFTER_TU= N_OPEN;
#elif defined(TARGET_ANDROID)
= return IFCONFIG_BEFORE_TUN_OPEN;
-#else /* if defined(TARGET_LINUX) */
+#else /* if defined(TARGET_LINUX) */ return IFCONFIG_DEFAULT;
#endif
}


-#define ROUTE_BEFORE_TUN 0
-#define ROUTE_AFTER_TUN 1
+#define ROUTE_BEFORE_TUN 0
+#define ROUTE_AFTER_TUN 1
#defi= ne ROUTE_ORDER_DEFAULT ROUTE_AFTER_TUN

s= tatic inline int
@@ -442,11 +440,10 @@

bool is_adapter_up(const struct tuntap *tt, const IP_ADAPTER= _INFO *list);

-bool is_ip_in_adapter_subnet(const IP_ADAPTER_INFO *ai, const in_= addr_t ip, in_addr_t *highest_netmask);
+bool is_ip_in_adapter_subnet(const IP_ADAPTER_INFO *ai,= const in_addr_t ip,
= + in_addr_t *highest_netmask);
=
-DWORD adapter_index_= of_ip(const IP_ADAPTER_INFO *list,
- const in_addr_t ip,
- int *count,<= /span>
+DWORD adapter_index_= of_ip(const IP_ADAPTER_INFO *list, const in_addr_t ip, int *count, in_addr_t *netmask);

void show_tap_win_adapters(int msglev, int warnlev);=
@@ -600,10 +597,7 @@
}
<= br> static inline void
-tun_set(struct tuntap *tt,
- struct event_set *es,
- unsigned int rwflags,
- void *arg,
+tun_set(struct tuntap *tt, struct event_set *es,= unsigned int rwflags, void *arg,
unsigned int *pe= rsistent)
{
if (!tuntap_defined(tt) |= | tuntap_is_dco_win(tt))
@@ -627,7 +621,6 @@
}

#endif
tt->rwflags_debug = =3D rwflags;
- }

const char *tun_stat(const st= ruct tuntap *tt, unsigned int rwflags, struct gc_arena *gc);
diff --git a/src/openvpn/tun_afunix.c b/src/openvpn/tun_afunix.c
index 50ef765..fb8da91 100644
--- a/src/openvpn/tun= _afunix.c
+++ b/src/openvpn/tun_afunix.c
@@= -48,7 +48,6 @@
#include <stdlib.h>
=

-
static void
tun_afunix_exec_child(const ch= ar *dev_node, struct tuntap *tt, struct env_set *env)
{
@@ -61,8 +60,7 @@

argv= _printf(&argv, "%s", program);

- tt->afunix.childprocess =3D= openvpn_execve_check(&argv, env, S_NOWAITPID,

- = msgprefix);
+ = tt->afunix.childprocess =3D openvpn_execve_check(&argv, env, S_NOWA= ITPID, msgprefix);
if (!openvpn_waitpid_check(tt->a= funix.childprocess, msgprefix, M_WARN))
{
tt->afunix.childprocess =3D 0;

@@ -71,10 +6= 9,7 @@
}

void-open_tun_afunix(struct options = *o,
- in= t mtu,
- = struct tuntap *tt,
- = struct env_set *orig_env)
+open_tun_afunix(struct options *o, int mtu, struct tunt= ap *tt, struct env_set *orig_env)
{
s= truct gc_arena gc =3D gc_new();

@@ -82,14= +77,14 @@
if (!(socketpair(AF_UNIX, SOCK_DGRAM, 0, fd= s) =3D=3D 0))
{
msg(M_ERR, &q= uot;Cannot create socket pair for AF_UNIX socket to external "<= br>- "program&quo= t;);
+ = "program");
return;
= }


/* Ensure t= hat the buffer sizes are decently sized. Otherwise macOS will
* just have 2048 */

- struct socket_buffer_size newsizes =3D {65536, 65536 };+ struct socket_buffer_siz= e newsizes =3D { 65536, 65536 };
socket_set_buffers(fd= s[0], &newsizes, false);
socket_set_buffers(fds[1]= , &newsizes, false);

@@ -168,8 +163,8= @@
}
#else /* ifndef WIN32 */ void
-open_tun_= afunix(const char *dev, const char *dev_type, int mtu,
- struct tuntap *tt, struct = env_set env)
+open_tu= n_afunix(const char *dev, const char *dev_type, int mtu, struct tuntap *tt,=
+ str= uct env_set env)
{
msg(M_ERR, "A= F_UNIX socket support not available on this platform");
}

diff --git a/src/openvpn/tun_afunix.h b/src/openvpn/tu= n_afunix.h
index 21ae676..1a3467c 100644
--= - a/src/openvpn/tun_afunix.h
+++ b/src/openvpn/tun_afunix.h=
@@ -32,31 +32,24 @@
* the user provided = taking care of implementing the actual tun
* device.
*/
-void<= /span>
-open_tun_afunix(struct= options *o,
- = int mtu,
- = struct tuntap *tt,
- struct env_set *env);
+void open_tun_afunix(struct options *o, int mtu, s= truct tuntap *tt, struct env_set *env);

=
/**
* Closes the socket used for the AF= _UNIX based device. Also sends a
* SIGINT to the child pr= ocess that was spawned to handle the tun device
*/=
-void
-close_tun_afunix(struct tuntap *tt);=
+void close_tun_afunix(stru= ct tuntap *tt);

/**
* = Writes a packet to a AF_UNIX based tun device.
*/<= br>-ssize_t
-write_tun_afunix(struct tuntap *tt, uint8_t= *buf, int len);
+ssi= ze_t write_tun_afunix(struct tuntap *tt, uint8_t *buf, int len);
=
/**
* Reads a packet from a AF_U= NIX based tun device.
*/
-ssize_t
-read_tun_afunix(struct tuntap *tt, uint8_t *buf, int len);+ssize_t read_tun_afunix(struc= t tuntap *tt, uint8_t *buf, int len);

#e= ndif /* AFUNIX_TUN_H */

diff --git a/src/= openvpn/vlan.c b/src/openvpn/vlan.c
index d0beb48..638554d = 100644
--- a/src/openvpn/vlan.c
+++ b/src/o= penvpn/vlan.c
@@ -53,8 +53,8 @@
static voi= d
vlanhdr_set_vid(struct openvpn_8021qhdr *hdr, const uint= 16_t vid)
{
- hdr->pcp_cfi_vid =3D (hdr->pcp_cfi_vid & ~OPENVPN_8021= Q_MASK_VID)
- = | (htons(vid) & OPENVPN_8021Q_MASK_VID);
+ hdr->pcp_cfi_vid =3D+ (hdr->pcp_cfi_vid = & ~OPENVPN_8021Q_MASK_VID) | (htons(vid) & OPENVPN_8021Q_MASK_VID);=
}

/*
@= @ -97,15 +97,13 @@
/* reject untagged frame */
if (c->options.vlan_accept =3D=3D VLAN_ONLY_TAGGED= )
{
- msg(D_VLAN_DEBUG,
- "dropping frame without vlan-tag (proto= /len 0x%04x)",
+= msg(D_VLAN_DEBUG, "dropping frame without vlan-tag (proto/= len 0x%04x)",
ntohs(ethhdr->proto)= );
goto drop;
}

/* untagged frame is accepted and ass= ociated with the global VID */
- msg(D_VLAN_DEBUG,
- "assuming pvid for frame without vlan-tag, pv= id: %u (proto/len 0x%04x)",
+ msg(D_VLAN_DEBUG, "assuming pvid for frame withou= t vlan-tag, pvid: %u (proto/len 0x%04x)",
= c->options.vlan_pvid, ntohs(ethhdr->proto));

return c->options.vlan_pvid;
@@ -126= ,8 +124,8 @@
/* VLAN-tagged frame: drop packet= */
if (vid !=3D 0)
= {
- m= sg(D_VLAN_DEBUG, "dropping frame with vlan-tag, vid: %u (proto/len 0x%= 04x)",
- = vid, ntohs(vlanhdr->proto));
+ msg(D_VLAN_DEBUG, "dropping fram= e with vlan-tag, vid: %u (proto/len 0x%04x)", vid,
+ ntohs(vlanhdr->p= roto));
goto drop;
= }

@@ -149,8 +147,7 @@
/* here we have a proper VLAN tagged frame: perform decapsu= lation

* and return embedded VID
*/

- = msg(D_VLAN_DEBUG,
- "removing vlan-tag from frame: vid: %u, wrapped= proto/len: 0x%04x",
+ msg(D_VLAN_DEBUG, "removing vlan-tag from frame: vid= : %u, wrapped proto/len: 0x%04x",
vid= , ntohs(vlanhdr->proto));

= /* save inner protocol to be restored later after decapsulation */<= br>@@ -225,8 +222,7 @@
goto drop;=
}

- vlanhdr =3D (struct openvpn_8021qhdr *)buf_prepend= (buf,
- = SIZE_ETH_TO_8021Q_HDR);
= + vlanhdr =3D (struct op= envpn_8021qhdr *)buf_prepend(buf, SIZE_ETH_TO_8021Q_HDR);
=
/* Initialise VLAN/802.1q header.
* Move the Eth header so to keep dst/src addresses the same and = then

@@ -245,8 +241,8 @@
/* set the VI= D corresponding to the current context (client) */
vla= nhdr_set_vid(vlanhdr, c->options.vlan_pvid);
- msg(D_VLAN_DEBUG, "tag= ging frame: vid %u (wrapping proto/len: %04x)",
- c->options.vlan_pvid, vlanhdr-&g= t;proto);
+ msg(D_= VLAN_DEBUG, "tagging frame: vid %u (wrapping proto/len: %04x)", c= ->options.vlan_pvid,
+ vlanhdr->proto);
return;

drop:
diff --git a/src/openvpn/vlan.h = b/src/openvpn/vlan.h
index f6cf385..30f2c2d 100644--- a/src/openvpn/vlan.h
+++ b/src/openvpn/vlan.h
@@ -32,13 +32,10 @@
struct multi_context;
struct multi_instance;

-int16_t
-vlan_decapsulate(const struct context *c, struct buffe= r *buf);
+int16_t vla= n_decapsulate(const struct context *c, struct buffer *buf);

-bool
-vlan_is_tagged(const struct buffer *= buf);

+bool vlan_is_t= agged(const struct buffer *buf);

-void
-vlan_process_outgoing_tun(struct multi_context *m, struct multi= _instance *mi);
+void= vlan_process_outgoing_tun(struct multi_context *m, struct multi_instance *= mi);

#endif /* VLAN_H */
diff --git a/src/openvpn/wfp_block.c b/src/openvpn/wfp_block.c

<= span>index 2f13001..b7cb511 100644

--- a/src/openvpn/wfp_bl= ock.c
+++ b/src/openvpn/wfp_block.c
@@ -49,= 68 +49,33 @@
#endif

/* = c38d57d1-05a7-4c33-904f-7fbceee60e82 */
-DEFINE_GUID(
- FWPM_LAYER_ALE_AUTH_CONNECT_V4,
- 0xc38d57d1,
- 0x05a7,
- 0x4c33,
- = 0x90, 0x4f, 0x7f, 0xbc, 0xee, 0xe6, 0x0e, 0x82
- );
+DEFINE_GUID(FWPM_LAYER_ALE_AUTH_CONNECT_V4, 0xc38d57d1, 0x05a7= , 0x4c33, 0x90, 0x4f, 0x7f, 0xbc,
+ 0xee, 0xe6, 0x0e, 0x82);
=
/* 4a72393b-319f-44bc-84c3-ba54dcb3b6b4 */
-DEFINE_GUID(
- FWPM_LAYER_ALE_AUTH_CONNECT_V6,
- 0x4a72393b,
- 0x319f,
- 0x44bc,
- 0x84, 0xc3, 0xba, 0x54, 0xdc, 0xb3, 0xb6, 0xb4
- );

+DEFINE_GUID(FWPM_LAYER_ALE_AUTH_CONNECT_V6, 0x4= a72393b, 0x319f, 0x44bc, 0x84, 0xc3, 0xba, 0x54,
+ 0xdc, 0xb3, 0xb6, 0xb4);
/* d78e1e87-8644-4ea5-9437-d809ecefc971 */=
-DEFINE_GUID(
- FWPM_CONDITION_ALE_APP_ID,
=
- 0xd78e1e87,
- 0x8644,

- 0x4ea5,
- 0x94, 0x37, 0xd8, 0x09, 0xec, 0xef, 0xc9, 0x71
- );
+DEFINE_GUID(FWPM_CONDITION_ALE_APP_ID= , 0xd78e1e87, 0x8644, 0x4ea5, 0x94, 0x37, 0xd8, 0x09, 0xec,
+ 0xef, 0xc9, 0x71);

/* c35a604d-d22b-4e1a-91b4-68f674ee674b */
-DEFINE_GUID(
= - FWPM_CONDITION_IP_REMOTE_POR= T,
- 0xc35a604d,
- 0xd22b,
- 0x4e1a,

- 0x91, 0xb4, 0x68, 0xf6, 0x74, 0xee, 0x6= 7, 0x4b
- );<= br>+DEFINE_GUID(FWPM_CONDITION_= IP_REMOTE_PORT, 0xc35a604d, 0xd22b, 0x4e1a, 0x91, 0xb4, 0x68, 0xf6, 0x74,
+ 0xee, 0x6= 7, 0x4b);

/* 4cd62a49-59c3-4969-b7f3-bda= 5d32890a4 */
-DEFINE_GU= ID(
- FWPM_CONDITION= _IP_LOCAL_INTERFACE,
- = 0x4cd62a49,
- 0x5= 9c3,
- 0x4969,

- 0xb7, 0xf3, 0xbd, 0xa5,= 0xd3, 0x28, 0x90, 0xa4
- );
+DEFINE_GUID= (FWPM_CONDITION_IP_LOCAL_INTERFACE, 0x4cd62a49, 0x59c3, 0x4969, 0xb7, 0xf3,= 0xbd, 0xa5,
+ = 0xd3, 0x28, 0x90, 0xa4);

/* 632ce23= b-5167-435c-86d7-e903684aa80c */
-DEFINE_GUID(
- FWPM_CONDITION_FLAGS,
- 0x632ce23b,
-= 0x5167,
- 0x435c= ,
- 0x86, 0xd7, 0xe9= , 0x03, 0x68, 0x4a, 0xa8, 0x0c
- );
+DEFI= NE_GUID(FWPM_CONDITION_FLAGS, 0x632ce23b, 0x5167, 0x435c, 0x86, 0xd7, 0xe9,= 0x03, 0x68, 0x4a,
+ = 0xa8, 0x0c);

/* UUID of WFP s= ublayer used by all instances of openvpn
* 2f660d7e-6a37-= 11e6-a181-001e8c6e04a2 */
-DEFINE_GUID(
- O= PENVPN_WFP_BLOCK_SUBLAYER,
- 0x2f660d7e,
- = 0x6a37,
- 0x11e6,=
- 0xa1, 0x81, 0x00,= 0x1e, 0x8c, 0x6e, 0x04, 0xa2
- );
+DEFIN= E_GUID(OPENVPN_WFP_BLOCK_SUBLAYER, 0x2f660d7e, 0x6a37, 0x11e6, 0xa1, 0x81, = 0x00, 0x1e, 0x8c,
+ = 0x6e, 0x04, 0xa2);

static WCHA= R *FIREWALL_NAME =3D L"OpenVPN";

@@ -124,7 +89,11 @@

}

= #define OUT_ON_ERROR(err, msg) \
- if (err) { msg_handler(err, msg); goto out; }
+ if (err) \<= /span>
+ { = \
+ = msg_handler(err, msg); \
+ goto out; \
+ }

/*
* Add a persistent sublayer with specified uuid.

@@ -= 182,24 +151,21 @@
*/

D= WORD
-add_wfp_block_fil= ters(HANDLE *engine_handle,
- int index,
- const WCHAR *exe_path,
- wfp_block_msg= _handler_t msg_handler,

- BOOL dns_only)
+add_wfp_block_filters(HANDLE *engine_handle, int index, = const WCHAR *exe_path,
- = FWPM_SESSION0 session =3D {0};
+ FWPM_SESSION0 session =3D { 0 };
FWP= M_SUBLAYER0 *sublayer_ptr =3D NULL;
NET_LUID itf_luid;=
UINT64 filterid;
FWP_BYTE_BLOB *= openvpnblob =3D NULL;
-= FWPM_FILTER0 Filter =3D {0};
+ FWPM_FILTER0 Filter =3D { 0 };
FWPM_F= ILTER_CONDITION0 Condition[2];
- FWPM_FILTER_CONDITION0 match_openvpn =3D {0};
- FWPM_FILTER_CONDITION0 match_port_= 53 =3D {0};
- FWPM_F= ILTER_CONDITION0 match_interface =3D {0};
- FWPM_FILTER_CONDITION0 match_loopback =3D {0};
- FWPM_FILTER_CONDITION0= match_not_loopback =3D {0};
+ FWPM_FILTER_CONDITION0 match_openvpn =3D { 0 };
+ FWPM_FILTER_CONDITION0 match_p= ort_53 =3D { 0 };

+ = FWPM_FILTER_CONDITION0 match_interface =3D { 0 };
+ FWPM_FILTER_CONDITION0 match_loopback= =3D { 0 };
+ FWPM= _FILTER_CONDITION0 match_not_loopback =3D { 0 };
DWORD= err =3D 0;

if (!msg_handler)=
@@ -224,8 +190,8 @@
FwpmFreeMemory0((voi= d **)&sublayer_ptr);
}
else
- { /* Add a new sub= layer -- as another process may add it in the meantime,
- * do not treat "already exis= ts" as an error */
+ { /* Add a new sublayer -- as another process may add it in the mea= ntime,
+ * do n= ot treat "already exists" as an error */
= err =3D add_sublayer(OPENVPN_WFP_BLOCK_SUBLAYER);
=
if (err =3D=3D FWP_E_ALREADY_EXISTS || err =3D=3D ERROR_= SUCCESS)
@@ -440,8 +406,7 @@
*/
DWORD
-set_interface_metric(const NET_IFINDEX index, const ADDRESS_FAMIL= Y family,
- = const ULONG metric)
+set_interface_metric(const NET_IFINDEX index, const ADDRESS_FAMILY= family, const ULONG metric)
{
DWORD = err =3D 0;
MIB_IPINTERFACE_ROW ipiface;
diff --git a/src/openvpn/wfp_block.h b/src/openvpn/wfp_block.h

= index fc5ec7e..0fb2554 100644
--- a/src/openvpn/wfp_b= lock.h
+++ b/src/openvpn/wfp_block.h
@@ -33= ,7 +33,7 @@
/* Any value less than 5 should work fine. 3 i= s chosen without any real reason. */
#define WFP_BLOCK_IFA= CE_METRIC 3

-typedef void (*wfp_block_msg_handler_t) (DWORD err, const char *msg= );
+typedef void (*wf= p_block_msg_handler_t)(DWORD err, const char *msg);

DWORD
delete_wfp_block_filters(HANDLE engine);=
@@ -52,8 +52,7 @@
*
* = @return positive interface metric on success or -1 on error
*/

-int
-get_interface_metric(const NET_IFI= NDEX index, const ADDRESS_FAMILY family, int *is_auto);

+int get_interface_metric(const NET_IFIN= DEX index, const ADDRESS_FAMILY family, int *is_auto);

/**
* Sets interface metric value for spec= ified interface index.
@@ -66,8 +65,7 @@
= */

DWORD
-set_interface_metric(const NET_IFINDEX index, const A= DDRESS_FAMILY family,
-= const ULONG metric);
+set_interface_metric(const NET_IFINDEX index, const A= DDRESS_FAMILY family, const ULONG metric);

#endif /* ifndef WFP_BLOCK_H */

#endif /* ifdef _WIN32 = */
diff --git a/src/openvpn/win32-util.c b/src/openvpn/win3= 2-util.c
index dd55743..9c45842 100644
--- = a/src/openvpn/win32-util.c
+++ b/src/openvpn/win32-util.c
@@ -162,7 +162,7 @@
if (WideCharToMulti= Byte(CP_UTF8, 0, wtmpdir, -1, NULL, 0, NULL, NULL) > sizeof(tmpdir))
{
msg(M_WARN, "Could not ge= t temporary directory. Path is too long."
- " Consider using --tmp-dir"= );
+ = " Consider using --tmp-dir");
return= NULL;
}

diff --git = a/src/openvpn/win32.c b/src/openvpn/win32.c
index 8d6f9c3..= a0cc62e 100644
--- a/src/openvpn/win32.c
++= + b/src/openvpn/win32.c
@@ -102,8 +102,7 @@
/**

* Set OpenSSL environment variables to a safe direc= tory
*/
-static void
-set_op= enssl_env_vars(void);
+static void set_openssl_env_vars(void);

void

init_win32(void)
@@ -168,9 +167,7 @= @
}

void
-overlapped_io_init(struct overlapped= _io *o,

- = const struct frame *frame,
- BOOL event_state)
+overlapped_io_init(struct overlapped_io *o, cons= t struct frame *frame, BOOL event_state)
{
CLEAR(*o);


@@ -220,7 +217,8 @@
*/

void
-init_net_event_win32(struct rw_handle *e= vent, long network_events, socket_descriptor_t sd, unsigned int flags)
+init_net_event_win32(str= uct rw_handle *event, long network_events, socket_descriptor_t sd,+ unsigne= d int flags)
{
/* manual reset events= , initially set to unsignaled */

@@ -293,= 7 +291,8 @@
{
if (!Cl= oseHandle(event->read))
{
- msg(M_WARN | M_ERRNO, &= quot;Warning: CloseHandle (read) failed in close_net_event_win32");
+ msg(M_= WARN | M_ERRNO,
+ = "Warning: CloseHandle (read) failed in close_net_event= _win32");
}
= event->read =3D NULL;
}
@@ -309= ,7 +308,8 @@
{
if (!C= loseHandle(event->write))
{
- msg(M_WARN | M_ERRNO,= "Warning: CloseHandle (write) failed in close_net_event_win32");=

+ msg= (M_WARN | M_ERRNO,
+ = "Warning: CloseHandle (write) failed in close_net_e= vent_win32");
}
= event->write =3D NULL;
}
@@= -333,7 +333,7 @@
ASSERT(!socket_defined(ne->sd));<= /span>
ne->sd =3D sd;
ne->event_ma= sk =3D 0;
- init_net= _event_win32(&ne->handle, network_events, sd, NE32_PERSIST_EVENT|NE3= 2_WRITE_EVENT);
+ = init_net_event_win32(&ne->handle, network_events, sd, NE32_PERSIST_E= VENT | NE32_WRITE_EVENT);
}

void

@@ -407,7 +407,7 @@
ir.E= vent.KeyEvent.bKeyDown =3D true;
if (!stdin_handle= || !WriteConsoleInput(stdin_handle, &ir, 1, &tmp))
{

- = msg(M_WARN|M_ERRNO, "WARN: win_trigger_event: WriteConsoleInput"= ;);
+ msg(= M_WARN | M_ERRNO, "WARN: win_trigger_event: WriteConsoleInput");<= /span>
}
}
}=
@@ -418,7 +418,7 @@
static bool WINAPI win_ctrl_handler(DWORD signum)
{
- msg(D_LOW, "win_ctrl_handler: = signal received (code=3D%lu)", (unsigned long) signum);
+ msg(D_LOW, "win_ctrl_hand= ler: signal received (code=3D%lu)", (unsigned long)signum);

=
if (siginfo_static.signal_received =3D=3D SIGT= ERM)
{
@@ -436,7 +436,7 @@
<= span> break;


default= :
- msg(D_LO= W, "win_ctrl_handler: signal (code=3D%lu) not handled", (unsigned= long) signum);
+ = msg(D_LOW, "win_ctrl_handler: signal (code=3D%lu) not handled&= quot;, (unsigned long)signum);
break; }
/* pass all other signals to the next h= andler */
@@ -450,9 +450,7 @@
}
=
void
-win32_signal_open(struct win32_signal *ws,
- int force,
- const char *exit_even= t_name,
+win32_signal= _open(struct win32_signal *ws, int force, const char *exit_event_name,
bool exit_event_initial_state)
{

CLEAR(*ws);
@@ -474,12 +472,10 @= @
if (GetConsoleMode(ws->in.read, &ws-&= gt;console_mode_save))
{
= /* running on a console */
- const DWORD new_console_mode =3D ws->co= nsole_mode_save
- = & ~(ENABLE_WINDOW_INPUT=
- = | ENABLE_PROCESSED_INPUT
- = | ENABLE_LINE_INPUT
-= | ENABLE_ECHO_INPUT
- = | ENABLE_MOUSE_INPUT);
+ const DWORD new_console_mode = =3D
+ = ws->console_mode_save
+ & ~(ENABLE_WINDOW_INPUT | ENABLE_PROCESSED= _INPUT | ENABLE_LINE_INPUT
+ | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT);

if (new_console_mode !=3D= ws->console_mode_save)
{
@@ -502,8 +498,8 @@

* If console open failed, assu= me we are running
* as a service.
= */
- if ((force = =3D=3D WSO_NOFORCE || force =3D=3D WSO_FORCE_SERVICE)
- && !HANDLE_DEFINED(ws->i= n.read) && exit_event_name)
+ if ((force =3D=3D WSO_NOFORCE || force =3D=3D WSO_FORCE= _SERVICE) && !HANDLE_DEFINED(ws->in.read)
+ && exit_event_name)
{
struct security_attributes sa;
struct gc_arena gc =3D gc_new();
@@= -514,11 +510,11 @@
msg(M_ERR, "Error: wi= n32_signal_open: init SA failed");
}
- ws-&= gt;in.read =3D CreateEventW(&sa.sa, TRUE, exit_event_initial_state ? TR= UE : FALSE,
- = exit_event_nameW);
+ ws->in.read =3D
+ CreateEventW(&sa.sa, TRUE, e= xit_event_initial_state ? TRUE : FALSE, exit_event_nameW);
= if (ws->in.read =3D=3D NULL)
{<= br>- msg(M_WARN|M_ERRN= O, "NOTE: CreateEventW '%s' failed", exit_event_name);
+ msg(M_WARN= | M_ERRNO, "NOTE: CreateEventW '%s' failed", exit_event_= name);
}
else
<= span> {

@@ -534,9 +530,9 @@
= gc_free(&gc);
}
/* set the = ctrl handler in both console and service modes */
- if (!SetConsoleCtrlHandler((PHANDLER_ROUTIN= E) win_ctrl_handler, true))
+ if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)win_ctrl_handler, = true))
{
- msg(M_WARN|M_ERRNO, "WARN: SetConsoleCtrlHandler faile= d");
+ ms= g(M_WARN | M_ERRNO, "WARN: SetConsoleCtrlHandler failed");=
}
}

@@ -5= 63,8 +559,7 @@
return ir->Event.KeyEvent.wVirtu= alScanCode;
}

- if ((ir->Event.KeyEvent.dwControlKey= State
- & (= LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
+ if ((ir->Event.KeyEvent.dwControlKeyState & (= LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
&& = (ir->Event.KeyEvent.wVirtualKeyCode !=3D 18))
{
return ir->Event.KeyEvent.wVirtualScanCode * 256;<= /span>
@@ -626,8 +621,7 @@
{
= if (ws->mode =3D=3D WSO_MODE_SERVICE)
{
= - if (HANDLE_DEFINED(ws-&g= t;in.read)
- = && WaitForSingleObject(ws->in.read, 0) =3D=3D WAIT_OBJECT_0)
+ if (HANDLE_DEF= INED(ws->in.read) && WaitForSingleObject(ws->in.read, 0) =3D= =3D WAIT_OBJECT_0)
{
= return true;
}
@@ -684,7 +678,7 @@=
{
if (ws->mode =3D=3D WSO_MODE_CO= NSOLE && HANDLE_DEFINED(ws->in.read))
{
- msg(M_INFO|M_NOPR= EFIX, "Press any key to continue...");
+ msg(M_INFO | M_NOPREFIX, "Press a= ny key to continue...");
do
= {
WaitForSingleObject(ws->in.read, = INFINITE);
@@ -735,7 +729,8 @@
{
title =3D "";
}- buf_printf(&out, "= ;[%s] " PACKAGE_NAME " " PACKAGE_VERSION " F4:EXIT F1:U= SR1 F2:USR2 F3:HUP", title);
+ buf_printf(&out, "[%s] " PACKAGE_NAME "= ; " PACKAGE_VERSION " F4:EXIT F1:USR1 F2:USR2 F3:HUP",
+ title);
SetConsoleTitle(BSTR(&out));
gc= _free(&gc);
}
@@ -764,7 +759,7 @@

if (s->hand =3D=3D NULL)
{

- msg= (M_WARN|M_ERRNO, "WARNING: Cannot create Win32 semaphore '%s'&= quot;, name);
+ = msg(M_WARN | M_ERRNO, "WARNING: Cannot create Win32 semaphore '%= s'", name);
}
else
{
@@ -782,9 +777,10 @@
= DWORD status;
ASSERT(!s->locked);
- dmsg= (D_SEMAPHORE_LOW, "Attempting to lock Win32 semaphore '%s' pri= or to net shell command (timeout =3D %d sec)",
- s->name,
- timeout_milliseconds / 1000= );
+ dmsg(
+ D_SEMAPHORE= _LOW,
+ &q= uot;Attempting to lock Win32 semaphore '%s' prior to net shell comm= and (timeout =3D %d sec)",
+ s->name, timeout_milliseconds / 1000); status =3D WaitForSingleObject(s->hand, timeout_millisec= onds);
if (status =3D=3D WAIT_FAILED)
{

@@ -799,8 +795,7 @@
= else
{
dmsg(D_SEMAPH= ORE, "Wait on Win32 semaphore '%s' timed out after %d millisec= onds",
- = s->name,
- = timeout_milliseconds);
+ s->name, timeout_milliseconds);=
}
}
return ret= ;
@@ -815,8 +810,7 @@
dmsg(D_SEMAP= HORE, "Releasing Win32 semaphore '%s'", s->name);
if (!ReleaseSemaphore(s->hand, 1, NULL))
= {
- = msg(M_WARN | M_ERRNO, "ReleaseSemaphore failed on Win32 semapho= re '%s'",
= - s->name);
+ msg(M_WARN | M_ERRNO, "ReleaseSemaphore failed o= n Win32 semaphore '%s'", s->name);
= }
s->locked =3D false;
}<= /span>
@@ -907,9 +901,9 @@
nchars += =3D strlen(e->string) + 1;
}
<= /span>
- nchars +=3D st= rlen(force_path)+1;
+= nchars +=3D strlen(force_path) + 1;

- ret =3D (char *) malloc(nch= ars);

+ ret = =3D (char *)malloc(nchars);
check_malloc_return(re= t);

p =3D ret;
@= @ -920,7 +914,7 @@
strcpy(p, e->string)= ;
p +=3D strlen(e->string) + 1;<= br> }
- if (strncmp(e->string, "PATH=3D", 5 ) =3D=3D 0)<= /span>
+ if (strn= cmp(e->string, "PATH=3D", 5) =3D=3D 0)
= {
path_seen =3D true;
}

@@ -929,8 +923,8 @@
= /* make sure PATH is set */
if (!path_seen)
{
- msg( M_INFO, "env_block: add %s", force_path );
- strcpy( p, fo= rce_path );
+ = msg(M_INFO, "env_block: add %s", force_path);
+ strcpy(p, force_path);<= /span>
p +=3D strlen(force_path) + 1;
}


@@ -976,7 +970,7 @@ {
const char *arg =3D a->argv[i];
strcpy(work, arg);
- string_mod(work, CC_PRINT, CC_DOUBLE_QUOTE|CC_= CRLF, '_');
+= string_mod(work, CC_PRINT, CC_DOUBLE_QUOTE | CC_CRLF, '_');=
if (i)
{
buf_printf(&buf, " ");

@@ -1027= ,7 +1021,8 @@
start_info.dwFlags =3D STARTF_US= ESHOWWINDOW;
start_info.wShowWindow =3D SW_HID= E;

- = if (CreateProcessW(cmd, cl, NULL, NULL, FALSE, proc_flags, env, = NULL, &start_info, &proc_info))
+ if (CreateProcessW(cmd, cl, NULL, NULL, FAL= SE, proc_flags, env, NULL, &start_info,
+ &proc_info))
{
DWORD exit_sta= tus =3D 0;
CloseHandle(proc_info.hThread);=
@@ -1038,13 +1033,13 @@
}=
else
{
- msg= (M_WARN|M_ERRNO, "openvpn_execve: GetExitCodeProcess %ls failed",= cmd);
+ = msg(M_WARN | M_ERRNO, "openvpn_execve: GetExitCodeProcess %ls f= ailed", cmd);
}
= CloseHandle(proc_info.hProcess);
}=
else
{- msg(M_WARN|M_ER= RNO, "openvpn_execve: CreateProcess %ls failed", cmd);
= + msg(M_WARN | M= _ERRNO, "openvpn_execve: CreateProcess %ls failed", cmd);<= br> }
free(env);
<= span> gc_free(&gc);

@@ -1085,7 +1080,8 @@
status =3D GetModuleFileName(NULL, self_exe, sizeof(sel= f_exe));
if (status =3D=3D 0 || status =3D=3D sizeof(s= elf_exe))
{
- msg(M_WARN|M_ERRNO, "fork_to_self: CreateProcess fa= iled: cannot get module name via GetModuleFileName");
+ msg(M_WARN | M_ERRNO,=
+ "fork_to_= self: CreateProcess failed: cannot get module name via GetModuleFileName&qu= ot;);
goto done;
}
=
@@ -1102,7 +1098,7 @@
}=
else
{
- msg(M_WARN|M_ERRNO, "fork_to_self: Create= Process failed: %s", cmdline);
+ msg(M_WARN | M_ERRNO, "fork_to_self: CreatePro= cess failed: %s", cmdline);
}

done:
@@ -1135,7 +1131,8 @@
}

if (status > sizeof(buf) - 1)
{

- msg(= M_FATAL, "String overflow attempting to read environmental variable %s= ", SYS_PATH_ENV_VAR_NAME);
+ msg(M_FATAL, "String overflow attempting to read e= nvironmental variable %s",
+ SYS_PATH_ENV_VAR_NAME);
}
set_win_sys_path(buf, es);
}
@@ -1146,7 +1143,7 @@

DWORD status =3D GetModuleFi= leNameW(NULL, path, size);
if (status =3D=3D 0 || stat= us =3D=3D size)
{
- msg(M_WARN|M_ERRNO, "cannot get executable pa= th");
+ m= sg(M_WARN | M_ERRNO, "cannot get executable path");
return false;

}
retur= n true;
@@ -1163,8 +1160,7 @@
}=
else
{
- msg(M_WARN, "Error in WFP: %s : %s [statu= s=3D0x%lx]",
- = msg, strerror_win32(err, &gc), err);
+ msg(M_WARN, "Error in WFP: %s : %= s [status=3D0x%lx]", msg, strerror_win32(err, &gc), err); }

gc_free(&gc);
@@ -1177,15 +1173,10 @@
ack_message_t ack= ;
struct gc_arena gc =3D gc_new();

- wfp_block_message_t= data =3D {
- .h= eader =3D {
- = (add ? msg_add_wfp_block : msg_del_wfp_block),
- sizeof(wfp_block_message_t),<= br>- 0
- },

- .flags =3D dns_only ? wfp_block_dns : wf= p_block_local,
- = .iface =3D { .index =3D index, .name =3D "" }
- };
+ wfp_block_message_t data =3D { .header =3D { (add= ? msg_add_wfp_block : msg_del_wfp_block),
+ sizeof(= wfp_block_message_t), 0 },
+ .flags =3D dns_only ? wfp_block_dns= : wfp_block_local,
+= .iface =3D { .index =3D index, .name =3D &= quot;" } };

if (!send_msg_iserv= ice(pipe, &data, sizeof(data), &ack, "WFP block"))=
{
@@ -1194,9 +1185,10 @@

if (ack.error_number !=3D NO_ERROR)
= {
- msg(M_WARN= , "WFP block: %s block filters using service failed: %s [status=3D0x%x= if_index=3D%d]",
= - (add ? "adding" : "deleting"), strerror_wi= n32(ack.error_number, &gc),
- ack.error_number, data.iface.index);
+ msg(M_WARN,
+ "WFP block: %s bloc= k filters using service failed: %s [status=3D0x%x if_index=3D%d]",
+ (add ? &quo= t;adding" : "deleting"), strerror_win32(ack.error_number, &a= mp;gc), ack.error_number,
+ data.iface.index);
goto out;
}

@@ -1227,8 +1219,8 @@=
goto out;
}
=
- status =3D add_w= fp_block_filters(&m_hEngineHandle, index, openvpnpath,
- win= _wfp_msg_handler, dns_only);
+ status =3D
+ add_wfp_block_filters(&m_hEngineHandle, index, openvpnpath,= win_wfp_msg_handler, dns_only);
if (status =3D=3D 0)<= /span>
{
int is_auto =3D 0;@@ -1283,7 +1275,8 @@
return true;
<= span> }


-typedef enum {
+t= ypedef enum
+{=
ARCH_X86,
ARCH_AMD64,
= ARCH_ARM64,
@@ -1297,9 +1290,9 @@
= *process_arch =3D ARCH_UNKNOWN;
*host_arch =3D ARCH_NA= TIVE;

- typedef BOOL (WINAPI *is_wow64_process2_t)(HANDLE, USHORT *, USHORT *= );
- is_wow64_proces= s2_t is_wow64_process2 =3D (is_wow64_process2_t)
- GetP= rocAddress(GetModuleHandle("Kernel32.dll"), "IsWow64Process2= ");
+ typedef= BOOL(WINAPI * is_wow64_process2_t)(HANDLE, USHORT *, USHORT *);
= + is_wow64_process2_t is_wow= 64_process2 =3D
+ = (is_wow64_process2_t)GetProcAddress(GetModuleHandle("Kernel32.dll&= quot;), "IsWow64Process2");

= USHORT process_machine =3D 0;
USHORT native_machine = =3D 0;
@@ -1311,8 +1304,7 @@
if (is_wo= w64_process2)
{
/* this could= be amd64 on arm64 */
-= BOOL is_wow64 =3D is_wow64_process2(GetCurrentProcess(),
= - = &process_machine, &native_machine);
+ BOOL is_wow64 =3D is_wow64_proces= s2(GetCurrentProcess(), &process_machine, &native_machine);<= br> if (is_wow64 && native_machine =3D=3D IMAGE_FILE_= MACHINE_ARM64)
{
*hos= t_arch =3D ARCH_ARM64;
@@ -1324,8 +1316,7 @@
if (is_wow64_process2)

{
= /* check if we're running on arm64 or amd64 machine */
- BOOL is_wow64 =3D is_wow64_= process2(GetCurrentProcess(),

- &process_machine, &am= p;native_machine);
+ = BOOL is_wow64 =3D is_wow64_process2(GetCurrentProcess(), &proces= s_machine, &native_machine);
if (is_wow64)
{
switch (native_machine= )
@@ -1384,7 +1375,7 @@
}
}


+typedef LONG(WINAPI *RtlGetVer= sionPtr)(PRTL_OSVERSIONINFOW);

const cha= r *
win32_version_string(struct gc_arena *gc)
@@ -1429,18 +1420,16 @@

}

= bool
-send_msg_i= service(HANDLE pipe, const void *data, size_t size,
- ack_message_t *ack, const= char *context)
+send= _msg_iservice(HANDLE pipe, const void *data, size_t size, ack_message_t *ac= k,
+ = const char *context)
{
struct gc_are= na gc =3D gc_new();
DWORD len;
bo= ol ret =3D true;

- if (!WriteFile(pipe, data, size, &len, NULL)- || !ReadFile(pipe, ack,= sizeof(*ack), &len, NULL))
+ if (!WriteFile(pipe, data, size, &len, NULL) || !ReadFi= le(pipe, ack, sizeof(*ack), &len, NULL))
{<= br>- msg(M_WARN, "%s:= could not talk to service: %s [%lu]",
- context ? context : "Unknown",<= /span>
+ msg(M_WARN, = "%s: could not talk to service: %s [%lu]", context ? context : &q= uot;Unknown",
strerror_win32(GetLastError= (), &gc), GetLastError());
ret =3D false;
}
@@ -1488,14 +1477,13 @@
= install_path[wcslen(install_path) - 1] =3D L'\0'; }

- static struct {
+ static struct
+ {
WCHAR *name;
= WCHAR *value;
- }= ossl_env[] =3D {
- = {L"OPENSSL_CONF", L"openssl.cnf"},
- {L"OPENSSL_ENGINES",= L"engines"},
- {L"OPENSSL_MODULES", L"modules"}
- };

+ } ossl_env[] =3D { { L"OPENSSL_CONF&qu= ot;, L"openssl.cnf" },
+ { L"OPENSSL_ENGINES", L"en= gines" },
+ = { L"OPENSSL_MODULES", L"modules" } };

for (size_t i =3D 0; i < SIZE(ossl= _env); ++i)
{
@@ -1504,7 +1492,7 @@
_wgetenv_s(&size, NULL, 0, ossl_env[i].name);
if (size =3D=3D 0)
{=
- WCHAR val[MAX_PA= TH] =3D {0};
+ = WCHAR val[MAX_PATH] =3D { 0 };
swprintf(v= al, _countof(val), L"%ls\\ssl\\%ls", install_path, ossl_env[i].va= lue);
_wputenv_s(ossl_env[i].name, val);
}
@@ -1525,7 +1513,7 @@
{

if (n > 0)
{
- Sleep(n*100= 0);
+ Slee= p(n * 1000);
}
return;
}
@@ -1535,9 +1523,8 @@
=
while (expire >=3D now)
{
- DWORD status =3D= WaitForSingleObject(win32_signal.in.read, (expire-now)*1000);
- if ((status =3D=3D WAIT_OB= JECT_0 && win32_signal_get(&win32_signal))

- || status =3D=3D WAIT_TIMEOUT)=
+ DWORD statu= s =3D WaitForSingleObject(win32_signal.in.read, (expire - now) * 1000);
+ if ((status =3D= =3D WAIT_OBJECT_0 && win32_signal_get(&win32_signal)) || status= =3D=3D WAIT_TIMEOUT)
{
= return;
}
@@ -1548,7 +1535,7 @@=
{
if (expire > no= w)
{
- Sleep((expire-now)*1000);
+ Sleep((expire - now) * 10= 00);
}
return;
}
@@ -1600,8 +1587,8 @@
}


/* Check if the plugin pa= th resides within the plugin/install directory */
- if ((wcslen(normalized_plugin_dir) > 0) = && (wcsnicmp(normalized_plugin_dir,
- = plugin_path, wcslen(normalized_plugin_dir)) =3D=3D 0))
+ if ((wcslen(normalized_plugin_di= r) > 0)
+ &= amp;& (wcsnicmp(normalized_plugin_dir, plugin_path, wcslen(normalized_p= lugin_dir)) =3D=3D 0))
{
retu= rn true;
}
diff --git a/src/openvpn/wi= n32.h b/src/openvpn/win32.h
index 4b07d9e..34f622d 100644
--- a/src/openvpn/win32.h
+++ b/src/openvpn/= win32.h
@@ -35,12 +35,13 @@
#include "= ;win32-util.h"

/* location of execu= tables */
-#define SYS_= PATH_ENV_VAR_NAME "SystemRoot" /* environmental variable name th= at normally contains the system path */
-#define NETSH_PATH_SUFFIX "\\system32\\netsh.exe= "
-#define WIN_ROU= TE_PATH_SUFFIX "\\system32\\route.exe"
+#define SYS_PATH_ENV_VAR_NAME \
+ "SystemRoot" /* envi= ronmental variable name that normally contains the system path */
+#define NETSH_PATH_SUFFIX = "\\system32\\netsh.exe"
+#define WIN_ROUTE_PATH_SUFFIX "\\system32\\route.= exe"
#define WIN_IPCONFIG_PATH_SUFFIX "\\system3= 2\\ipconfig.exe"
-= #define WIN_NET_PATH_SUFFIX "\\system32\\net.exe"
-#define WMIC_PATH_SUFFIX "\\syst= em32\\wbem\\wmic.exe"

+#define WIN_NET_PATH_SUFFIX "\\system32\\net.exe"
+#define WMIC_PATH_SUFFI= X "\\system32\\wbem\\wmic.exe"
/*
* Win32-specific OpenVPN code, targeted at th= e mingw
@@ -76,7 +77,8 @@
char old_win= dow_title[256];
};

-struct rw_handle {
+struct rw_handle
+{
HANDLE read;
<= span> HANDLE write;

};
@@ -85,8 +87,8 = @@
* Event-based notification of incoming TCP connections=
*/

-#define NE32_PERSIST_EVENT (1<<0)
-#define NE32_WRITE_EVENT (1<<1)=
+#define NE32_PERSIS= T_EVENT (1 << 0)
-void init_net_event_win32(= struct rw_handle *event, long network_events, socket_descriptor_t sd, unsig= ned int flags);
+void= init_net_event_win32(struct rw_handle *event, long network_events, socket_= descriptor_t sd,
+ = unsigned int flags);

long reset_net_event_win32(struct rw_handle *event, socket_descriptor_t= sd);


@@ -150,7 +153,8 @@
/*

* Signal handling
*/
-struct win32_signal {

+struct win32_signal

+{

#define WSO_MO= DE_UNDEF 0
#define WSO_MODE_SERVICE 1
#= define WSO_MODE_CONSOLE 2
@@ -170,10 +174,8 @@
#define WSO_FORCE_SERVICE 1

#define WSO_FORCE_CONSOLE= 2

-v= oid win32_signal_open(struct win32_signal *ws,
- int force, /* set to WSO f= orce parm */
- = const char *exit_event_name,
- bool exit_event_initial_state);=
+void win32_signal_o= pen(struct win32_signal *ws, int force, /* set to WSO force parm */<= br>+ cons= t char *exit_event_name, bool exit_event_initial_state);
<= /span>
void win32_signal_close(struct win32_signal *ws);
@@ -199,17 +201,19 @@
* We try = to do all Win32 I/O using overlapped
* (i.e. asynchronous= ) I/O for a performance win.
*/
-struct overlapped_io {
+struct overlapped_io
+{
#define IOSTATE_INITIA= L 0
-#define I= OSTATE_QUEUED 1 /* overlapped I/O has been queued */
<= span style=3D"color: hsl(0, 100%, 40%);">-#define IOSTATE_IMMEDIATE_RETURN = 2 /* I/O function returned immediately without queueing */

+#define IOSTATE_QUEUED 1 = /* overlapped I/O has been queued */

+#define IOSTATE_IMMEDIATE_RETURN 2 /* I/O function returne= d immediately without queueing */
int iostate;<= br> OVERLAPPED overlapped;
DWORD size;
DWORD flags;
int status;
bool addr_defined;

- union {
+ = union
+ {<= br> struct sockaddr_in addr;
struct = sockaddr_in6 addr6;
};
@@ -218,9 +222,= 7 @@
struct buffer buf;
};
=
-void overlappe= d_io_init(struct overlapped_io *o,
- const struct frame *frame,
<= span style=3D"color: hsl(0, 100%, 40%);">- BOOL even= t_state);

+void overl= apped_io_init(struct overlapped_io *o, const struct frame *frame, BOOL even= t_state);

void overlapped_io_close(struc= t overlapped_io *o);

@@ -305,14 +307,13 @= @
* and read the result in |ack|. Returns false on commun= ication error.
* The string in |context| is used to prefi= x error messages.
*/
-bool send_msg_iservice(HANDLE pipe, const void *data, size= _t size,
- = ack_message_t *ack, const char *context);
+bool send_msg_iservice(HANDLE pipe, const= void *data, size_t size, ack_message_t *ack,
+ const char *context);

/*
* Attempt to simulate f= ork/execve on Windows
*/
-int
+in= t openvpn_execve(const struct argv *a, const struct env_set *es, const unsi= gned int flags);

/* Sleep that can be in= terrupted by signals and exit event */
void win32_sleep(co= nst int n);
@@ -325,8 +326,7 @@
* @param = size Size of `value` buffer in bytes.
* @return `true` if= successful, `false` otherwise.
*/
-bool
-get_openvpn_reg_value(const WCHAR *key, WCHAR *value, DWORD = size);
+bool get_open= vpn_reg_value(const WCHAR *key, WCHAR *value, DWORD size);
=
/**
* @brief Checks if a plugin is loc= ated in a trusted directory.
@@ -341,8 +341,7 @@
= * @param plugin_path Normalized path to the plugin.
* @return \c true if the plugin is in a trusted directory and not a UNC = path; \c false otherwise.

*/
-bool
-plugin_in_trusted_dir(const WCHAR *plugin_path);
+bool plugin_in_trusted_dir(const WCHAR= *plugin_path);

/**
* = Encrypt a region of memory using CryptProtectMemory()
@@ -3= 52,8 +351,7 @@
* - len number of bytes to encrypt -- mu= st be a multiple of
* CRYPTPROTECTMEMORY_BLOCK_SI= ZE =3D 16
*/
-bool
-protect_= buffer_win32(char *buf, size_t len);
+bool protect_buffer_win32(char *buf, size_t len);
/**
* Decrypt a previously enc= rypted region of memory using CryptUnProtectMemory()
@@ -36= 3,8 +361,7 @@
* - len number of bytes to encrypt -- mus= t be a multiple of
* CRYPTPROTECTMEMORY_BLOCK_SIZ= E =3D 16
*/
-bool
-unprotect= _buffer_win32(char *buf, size_t len);
+bool unprotect_buffer_win32(char *buf, size_t len);

#endif /* ifndef OPENVPN_WIN32_H */ #endif /* ifdef _WIN32 */
diff --git a/src/openvpn/= xkey_common.h b/src/openvpn/xkey_common.h
index 84c6329..3f= 63919 100644
--- a/src/openvpn/xkey_common.h
+++ b/src/openvpn/xkey_common.h

@@ -47,12 +47,13 @@
* Struct to encapsulate signature algorithm parameters to pass=
* to sign operation.
*/
-typedef struct {

+typedef struct
+{
const char *padmode; = /**< "pkcs1", "pss" or "none" */- const char *mdname; /**<= "SHA256" or "SHA2-256" etc. */
+ const char *mdname; /**< "SH= A256" or "SHA2-256" etc. */
const char = *saltlen; /**< "digest", "auto" or "max" *= /
const char *keytype; /**< "EC" or "= ;RSA" */
- cons= t char *op; /**< "Sign" or "DigestSign" */
+ const char *op; = /**< "Sign" or "DigestSign" */
} XK= EY_SIGALG;

/**
@@ -79,15= +80,14 @@
* before signing. The digest algorithm used (o= r to be used) is passed in the sigalg
* structure.=
*/
-typedef= int (XKEY_EXTERNAL_SIGN_fn)(void *handle, unsigned char *sig, size_t *sigl= en,
- = const unsigned char *tbs, size_t tbslen,
- XK= EY_SIGALG sigalg);
+t= ypedef int(XKEY_EXTERNAL_SIGN_fn)(void *handle, unsigned char *sig, size_t = *siglen,
+ = const unsigned char *tbs, size_t tbslen, XKEY_SIGAL= G sigalg);
/**
* Signature of private ke= y free function callback used
* to free the opaque privat= e key handle obtained from the
* backend. Not required fo= r management-external-key.
*/
-typedef void (XKEY_PRIVKEY_FREE_fn)(void *handle)= ;
+typedef void(XKEY_= PRIVKEY_FREE_fn)(void *handle);

/**
* Generate an encapsulated EVP_PKEY for management-external-k= ey
@@ -116,9 +116,8 @@
* to the required = size and false is returned.
*
*/=
-bool
-encode_pkcs1(unsigned char *enc, size_t *en= c_len, const char *mdname,
- const unsigned char *tbs, size_t tbslen);
+bool encode_pkcs1(unsigned char *en= c, size_t *enc_len, const char *mdname, const unsigned char *tbs,
+ size_t tbsl= en);

/**
* Compute mes= sage digest
@@ -134,9 +133,8 @@
* On succ= essful return *buflen is set to the actual size of the result.
* TIP: EVP_MD_MAX_SIZE should be enough capacity of buf for al algori= thms.

*/
-int
-xkey_digest(c= onst unsigned char *src, size_t srclen, unsigned char *buf,
- size_t *buflen, const cha= r *mdname);

+int xkey= _digest(const unsigned char *src, size_t srclen, unsigned char *buf, size_t= *buflen,
+ = const char *mdname);

/** * Load a generic external key with custom sign and free ops=
@@ -151,9 +149,8 @@
* IMPORTANT: a reference to= the handle is retained by the provider and
* relased by = calling free_op. The caller should not free it.
*/=
-EVP_PKEY *
-xkey_load_generic_key(OSSL_LIB_CTX *lib= ctx, void *handle, EVP_PKEY *pubkey,
- XKEY_EXTERNAL_SIGN_fn *sign_op, XKEY_P= RIVKEY_FREE_fn *free_op);
+EVP_PKEY *xkey_load_generic_key(OSSL_LIB_CTX *libctx, void *handle, E= VP_PKEY *pubkey,
+ = XKEY_EXTERNAL_SIGN_fn *sign_op, XKEY_PRIVKEY_F= REE_fn *free_op);

extern OSSL_LIB_CTX *t= ls_libctx; /* Global */

@@ -167,7 +164,7 = @@
static inline int
xkey_max_saltlen(int= modBits, int hLen)
{
- int emLen =3D (modBits - 1 + 7)/8; /* ceil((modBits - = 1)/8) */
+ int emL= en =3D (modBits - 1 + 7) / 8; /* ceil((modBits - 1)/8) */
=
return emLen - hLen - 2;
}@@ -182,8 +179,7 @@
* @returns the size of the con= verted signature or <=3D 0 on error.
* On success, buf= is overwritten by its DER encoding
*/
-int
-ecdsa_bin2der(unsigned char *buf, int len, size_t capacity= );
+int ecdsa_bin2der= (unsigned char *buf, int len, size_t capacity);
#endif /* HAVE_XKEY_PROVIDER */

d= iff --git a/src/openvpn/xkey_helper.c b/src/openvpn/xkey_helper.cindex b5ed73c..2ff9e4b 100644
--- a/src/openvpn/xkey= _helper.c
+++ b/src/openvpn/xkey_helper.c
@= @ -60,8 +60,8 @@

/** helper to compute d= igest */
int
-xkey_digest(const unsigned char *src, size_t srclen, unsigned char = *buf,
- size= _t *buflen, const char *mdname)
+xkey_digest(const unsigned char *src, size_t srclen, unsigned c= har *buf, size_t *buflen,
+ const char *mdname)
{
= dmsg(D_XKEY, "In xkey_digest");
EVP_MD *m= d =3D EVP_MD_fetch(NULL, mdname, NULL); /* from default context */@@ -71,7 +71,7 @@
return 0;
}


- unsigned int len =3D (unsigned int) *buflen;
+ unsigned int len =3D (unsigned int)*b= uflen;
if (EVP_Digest(src, srclen, buf, &len, md, = NULL) !=3D 1)
{
msg(M_WARN, &= quot;WARN: xkey_digest: EVP_Digest failed");
@@ -122,1= 8 +122,17 @@

/* UTF8 string pointers= in here are only read from, so cast is safe */
OSSL_P= ARAM params[] =3D {
- = {"xkey-origin", OSSL_PARAM_UTF8_STRING, (char *) origin, 0,= 0},
- {"pu= bkey", OSSL_PARAM_OCTET_STRING, &pubkey, sizeof(pubkey), 0},
- {"handle"= , OSSL_PARAM_OCTET_PTR, &handle, sizeof(handle), 0},
- {"sign_op", OSSL_PARAM= _OCTET_PTR, (void **) &sign_op, sizeof(sign_op), 0},
- {"free_op", OSSL_PARAM= _OCTET_PTR, (void **) &free_op, sizeof(free_op), 0},
- {NULL, 0, NULL, 0, 0}
= + { "xkey-origin&qu= ot;, OSSL_PARAM_UTF8_STRING, (char *)origin, 0, 0 },
+ { "pubkey", OSSL_PARAM_= OCTET_STRING, &pubkey, sizeof(pubkey), 0 },
+ { "handle", OSSL_PARAM_OCTET_= PTR, &handle, sizeof(handle), 0 },
+ { "sign_op", OSSL_PARAM_OCTET_PTR, (vo= id **)&sign_op, sizeof(sign_op), 0 },
+ { "free_op", OSSL_PARAM_OCTET_PTR, = (void **)&free_op, sizeof(free_op), 0 },
+ { NULL, 0, NULL, 0, 0 }
= };

/* Do not use EVP_PKEY_new_fro= m_pkey as that will take keymgmt from pubkey */
EVP_PK= EY_CTX *ctx =3D EVP_PKEY_CTX_new_from_name(libctx, EVP_PKEY_get0_type_name(= pubkey), props);
- i= f (!ctx
- || EVP= _PKEY_fromdata_init(ctx) !=3D 1
+ if (!ctx || EVP_PKEY_fromdata_init(ctx) !=3D 1
|| EVP_PKEY_fromdata(ctx, &pkey, EVP_PKEY_KEYPAIR, params)= !=3D 1)

{
print_openssl_erro= rs();
@@ -162,13 +161,12 @@
* @return = signature length or -1 on error.
*/
<= span> int

-xkey_managem= ent_sign(void *unused, unsigned char *sig, size_t *siglen,
- const unsigned ch= ar *tbs, size_t tbslen, XKEY_SIGALG alg)
+xkey_management_sign(void *unused, unsigned char *sig,= size_t *siglen, const unsigned char *tbs,
+ size_t tbslen, XKEY_SIGALG alg)=
{
- = dmsg(D_XKEY, "In xkey_management_sign with keytype =3D %s, op =3D %s= ",
- alg.k= eytype, alg.op);
+ = dmsg(D_XKEY, "In xkey_management_sign with keytype =3D %s, op =3D %s&= quot;, alg.keytype, alg.op);

- (void) unused;
+ (void)unused;
char alg_str= [128];
unsigned char buf[EVP_MAX_MD_SIZE]; /* for comp= uting digest if required */
size_t buflen =3D sizeof(b= uf);
@@ -229,8 +227,7 @@
/* For un= digested message, add hashalg=3Ddigest parameter */
= else
{
- snprintf(alg_str, sizeof(alg_str), "%s,hashalg= =3D%s",
- = "RSA_PKCS1_PADDING", alg.mdname);
+ snprintf(alg_str, sizeof(al= g_str), "%s,hashalg=3D%s", "RSA_PKCS1_PADDING", alg.mdn= ame);
}
}
= else if (!strcmp(alg.padmode, "none") && (flags & M= F_EXTERNAL_KEY_NOPADDING)
@@ -240,13 +237,12 @@
<= span> }

else if (!strcmp(alg.padmode, "pss&qu= ot;) && (flags & MF_EXTERNAL_KEY_PSSPAD))
= {
- snprintf(alg= _str, sizeof(alg_str), "%s,hashalg=3D%s,saltlen=3D%s",
= - "RSA_PKCS1= _PSS_PADDING", alg.mdname, alg.saltlen);
+ snprintf(alg_str, sizeof(alg_str), "= %s,hashalg=3D%s,saltlen=3D%s", "RSA_PKCS1_PSS_PADDING",
+ alg.mdn= ame, alg.saltlen);
}
else<= br> {
- = msg(M_NONFATAL, "RSA padding mode not supported by management-client= <%s>",
- = alg.padmode);
- int bencret =3D openvpn_base64_encode(tbs, (int) tbslen, &in= _b64);
+ int bencr= et =3D openvpn_base64_encode(tbs, (int)tbslen, &in_b64);

if (management && bencret > 0) {
@@ -269,7 +265,7 @@
}
if (out_b64)
{
- len =3D openvpn_base64_decode(out= _b64, sig, (int) *siglen);
+ len =3D openvpn_base64_decode(out_b64, sig, (int)*siglen);
}
free(in_b64);
= free(out_b64);
@@ -296,8 +292,8 @@
* t= o the required size and false is returned.
*/
<= span> bool

-encode_pkcs= 1(unsigned char *enc, size_t *enc_len, const char *mdname,
- const unsigned char *tbs,= size_t tbslen)
+enco= de_pkcs1(unsigned char *enc, size_t *enc_len, const char *mdname, const uns= igned char *tbs,
+ = size_t tbslen)
{
ASSERT(enc= _len !=3D NULL);
ASSERT(tbs !=3D NULL);
@@ -310,32 +306,34 @@

* Also see the table in RFC 8= 017 section 9.2, Note 1.
*/
<= br>- const unsigned char sha1[= ] =3D {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b,
- 0x0e, 0x03, 0x= 02, 0x1a, 0x05, 0x00, 0x04, 0x14};
- const unsigned char sha256[] =3D {0x30, 0x31, 0x30, 0x0d, = 0x06, 0x09, 0x60, 0x86, 0x48,
- 0x01, 0x65, 0x03, 0x04, 0x02, 0= x01, 0x05, 0x00, 0x04, 0x20};
- const unsigned char sha384[] =3D {0x30, 0x41, 0x30, 0x0d, 0x06,= 0x09, 0x60, 0x86, 0x48,
- = 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05,= 0x00, 0x04, 0x40};
- = const unsigned char sha224[] =3D {0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x6= 0, 0x86, 0x48,
- = 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00= , 0x04, 0x1c};
- con= st unsigned char sha512_224[] =3D {0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60= , 0x86, 0x48,
- = 0x01, 0x65, 0x03, 0x04, 0x02, 0x05, 0x05, 0= x00, 0x04, 0x1c};
- = const unsigned char sha512_256[] =3D {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0= x60, 0x86, 0x48,
- = 0x01, 0x65, 0x03, 0x04, 0x02, 0x06, 0x05= , 0x00, 0x04, 0x20};
= + const unsigned char sha1[] =3D { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0= x2b, 0x0e,
+ = 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
+ const unsigned char s= ha256[] =3D { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
+ = 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 };
+ const unsigned char= sha384[] =3D { 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,=
+ = 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30 };
+ const unsigned ch= ar sha512[] =3D { 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x0= 1,
+ = 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40 };=
+ const unsigned = char sha224[] =3D { 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0= x01,
+ = 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c = };
+ const unsigne= d char sha512_224[] =3D { 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0= x48, 0x01,
+ = 0x65, 0x03, 0x04, 0x02, 0x05, 0x05, 0x00, 0= x04, 0x1c };
+ con= st unsigned char sha512_256[] =3D { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x6= 0, 0x86, 0x48, 0x01,
= + 0x65, 0x03, 0x04, 0x02, 0x06, 0x0= 5, 0x00, 0x04, 0x20 };

- typedef struct {
+ typedef struct
+ {
const int nid;
= const unsigned char *header;
size_t= sz;
} DIG_INFO;

-#define MAKE_DI(x) {NID_ ## x, x, sizeof(= x)}
+#define MAKE_DI(= x) { NID_##x, x, sizeof(x) }

- DIG_INFO dinfo[] =3D {MAKE_DI(sha1), MAKE_DI(s= ha256), MAKE_DI(sha384),
- = MAKE_DI(sha512_256), {0, NULL, 0}};
+ DIG_INFO dinfo[] =3D {
+ MAKE_DI(sha1), MAKE_DI(sha256),= MAKE_DI(sha384), MAKE_DI(sha512),
+ MAKE_DI(sha224), MAKE_DI(sha512_224), MAKE_D= I(sha512_256), { 0, NULL, 0 }
+ };

size_t out_len =3D = 0;
bool ret =3D false;
@@ -388,8 +386,= 7 @@
/* combine header and digest */
memcpy(enc, di->header, di->sz);

= memcpy(enc + di->sz, tbs, tbslen);
- dmsg(D_XKEY, "encode_pkcs1: digest length =3D= %zu encoded length =3D %zu",
- tbslen, out_len);
+ dmsg(D_XKEY, "encode_pkcs1: digest len= gth =3D %zu encoded length =3D %zu", tbslen, out_len);
ret =3D true;

}

= @@ -409,9 +406,9 @@
ecdsa_bin2der(unsigned char *buf= , int len, size_t capacity)
{
ECDSA_S= IG *ecsig =3D NULL;
- = int rlen =3D len/2;
+ int rlen =3D len / 2;
BIGNUM *r =3D BN_bin2bn(bu= f, rlen, NULL);
- BI= GNUM *s =3D BN_bin2bn(buf+rlen, rlen, NULL);
+ BIGNUM *s =3D BN_bin2bn(buf + rlen, rlen, NULL= );
if (!r || !s)
{
goto err;

@@ -428,7 +425,7 @@
= }

int derlen =3D i2d_ECDSA_SIG(ec= sig, NULL);
- if (de= rlen > (int) capacity)
+ if (derlen > (int)capacity)
{
<= span> ECDSA_SIG_free(ecsig);

msg(M_NONFATA= L, "Error: DER encoded ECDSA signature is too long (%d)\n", derle= n);
diff --git a/src/openvpn/xkey_provider.c b/src/openvpn/= xkey_provider.c
index deaca38..cbc9033 100644
--- a/src/openvpn/xkey_provider.c

+++ b/src/openvpn/xkey= _provider.c
@@ -47,15 +47,16 @@
typedef struct
{
- OSSL_LIB_CTX *libctx; /**< a child libctx for o= ur own use */
+ OS= SL_LIB_CTX *libctx; /**< a child libctx for our own use */
} XKEY_PROVIDER_CTX;


/* helper to pr= int debug messages */
-= #define xkey_dmsg(f, ...) \
- do { \
- dmsg(f|M_NOLF, &q= uot;xkey_provider: In %s: ", __func__); \
- dmsg(f|M_NOPREFIX, __VA_ARGS__); = \
- }= while(0)
+#define xk= ey_dmsg(f, ...) \
+ do = \
+ dmsg(f | M_NOLF, &qu= ot;xkey_provider: In %s: ", __func__); \
+ dmsg(f | M_NOPREFIX, __VA_ARGS__); = \
+ }= while (0)

typedef enum
= {
@@ -94,7 +95,7 @@
/** keydata handl= e free function of backend */
XKEY_PRIVKEY_FREE_fn *fr= ee;
XKEY_PROVIDER_CTX *prov;
- int refcount; /**< refere= nce count */
+ int= refcount; /**< reference count */
} XKEY_KEYDATA;

static inline const char *
@= @ -129,9 +130,8 @@
* Helper sign function for native keys=
* Implemented using OpenSSL calls.
*/<= /span>
-int
-xkey_native_sign(XKEY_KEYDATA *key, unsi= gned char *sig, size_t *siglen,
- const unsigned char *tbs, size_t tbslen, XKEY_SI= GALG sigalg);
+int xk= ey_native_sign(XKEY_KEYDATA *key, unsigned char *sig, size_t *siglen,
+ cons= t unsigned char *tbs, size_t tbslen, XKEY_SIGALG sigalg);
=

/* keymgmt provider */
= @@ -151,8 +151,7 @@
static OSSL_FUNC_keymgmt_query_operati= on_name_fn rsa_keymgmt_name;
static OSSL_FUNC_keymgmt_quer= y_operation_name_fn ec_keymgmt_name;

-static int
-keymgmt_import_helper(XKEY_KEYDATA *key, const OSSL_P= ARAM params[]);
+stat= ic int keymgmt_import_helper(XKEY_KEYDATA *key, const OSSL_PARAM params[]);=

static XKEY_KEYDATA *
= keydata_new(void)
@@ -274,9 +273,8 @@
= int selection_pub =3D selection & ~OSSL_KEYMGMT_SELECT_PRIVATE_KEY;

EVP_PKEY_CTX *ctx =3D EVP_PKEY_CTX_new_= from_name(key->prov->libctx, name, NULL);
- if (!ctx
- || (EVP_PKEY_fromdata_init(ctx) !=3D 1)
= - || (EVP_PKEY_fromdata(ct= x, &pkey, selection_pub, (OSSL_PARAM *) params) !=3D1))
+ if (!ctx || (EVP_PKEY_fromdata_= init(ctx) !=3D 1)

+ = || (EVP_PKEY_fromdata(ctx, &pkey, selection_pub, (OSSL_PARAM *)pa= rams) !=3D 1))
{
msg(M_WARN, = "Error: keymgmt_import failed for key type <%s>", name);
if (pkey)
@@ -296,10 +294,10 @@
{
/* create private key */=
pkey =3D NULL;
- if (EVP_PKEY_fromdata(ctx, &pkey, selection, (OSSL_= PARAM *) params) =3D=3D 1)
+ if (EVP_PKEY_fromdata(ctx, &pkey, selection, (OSSL_PARAM= *)params) =3D=3D 1)
{
= key->handle =3D pkey;
- key->free =3D (XKEY_PRIVKEY_FREE_fn *) EVP_PKEY_free;
+ key->f= ree =3D (XKEY_PRIVKEY_FREE_fn *)EVP_PKEY_free;
}
}
EVP_PKEY_CTX_free(ctx);@@ -420,12 +418,10 @@
{
xkey_= dmsg(D_XKEY, "entry");

- static OSSL_PARAM gettable[] =3D {<= br>- OSSL_PARAM_int(OSSL_P= KEY_PARAM_BITS, NULL),
= - OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL),
- OSSL_PARAM_int(OSSL_PKEY_PA= RAM_MAX_SIZE, NULL),

- = OSSL_PARAM_END
-= };
+ static OS= SL_PARAM gettable[] =3D { OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS, NULL),
+ = OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL),
= + = OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE, NULL),
+ OSS= L_PARAM_END };
return gettable;
}

@@ -472,14 +468,14 @@
/= * only check params we understand and ignore the rest */
<= /span>
p =3D OSSL_PARAM_locate_const(params, "pubkey&quo= t;); /*setting pubkey on our keydata */
- if (p && p->data_type =3D=3D OSSL_PARAM_OC= TET_STRING
- &am= p;& p->data_size =3D=3D sizeof(pkey))
+ if (p && p->data_type =3D=3D OSSL_P= ARAM_OCTET_STRING && p->data_size =3D=3D sizeof(pkey)) {
pkey =3D *(EVP_PKEY **)p->data;
ASSERT(pkey);

= int id =3D EVP_PKEY_get_id(pkey);
- if (id !=3D EVP_PKEY_RSA && id !=3D EVP_P= KEY_EC && id !=3D EVP_PKEY_ED25519 && id !=3D EVP_PKEY_ED44= 8)
+ if (id != =3D EVP_PKEY_RSA && id !=3D EVP_PKEY_EC && id !=3D EVP_PKEY= _ED25519
+ = && id !=3D EVP_PKEY_ED448)
{
msg(M_WARN, "Error: xkey keymgmt_import: unknown key = type (%d)", id);

return 0;
@@ -494,8 +490,7 @@

}

p =3D OSSL_PARAM_locate_const(params, "handle"); /*setti= ng privkey */

- if (= p && p->data_type =3D=3D OSSL_PARAM_OCTET_PTR
- && p->data_size =3D= =3D sizeof(key->handle))
+ if (p && p->data_type =3D=3D OSSL_PARAM_OCTET_PTR &a= mp;& p->data_size =3D=3D sizeof(key->handle))
= {
key->handle =3D *(void **)p->data;
/* caller should keep the reference alive until we call= free */
@@ -503,8 +498,7 @@
}<= br>
p =3D OSSL_PARAM_locate_const(params, "= ;sign_op"); /*setting sign_op */
- if (p && p->data_type =3D=3D OSSL_PARAM_OCTE= T_PTR
- &&am= p; p->data_size =3D=3D sizeof(key->sign))
+ if (p && p->data_type =3D=3D OSS= L_PARAM_OCTET_PTR && p->data_size =3D=3D sizeof(key->sign))
{
key->sign =3D *(void **)p= ->data;
ASSERT(key->sign); /* fix your param= s array */
@@ -512,8 +506,7 @@

= /* optional parameters */
p =3D OSSL_PARAM_= locate_const(params, "free_op"); /*setting free_op */
<= span style=3D"color: hsl(0, 100%, 40%);">- if (p && p->data_t= ype =3D=3D OSSL_PARAM_OCTET_PTR

- && p->data_size =3D=3D sizeof(key->free))
+ if (p && = p->data_type =3D=3D OSSL_PARAM_OCTET_PTR && p->data_size =3D= =3D sizeof(key->free))
{
k= ey->free =3D *(void **)p->data;
}
@@ -587,75 +580,80 @@

}

static const OSSL_DISPATCH rsa_keymgmt_functions[] =3D {

- {OSSL_FUNC_KEYMGMT_NEW, (void (*)= (void))keymgmt_new},

- = {OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free},
- {OSSL_FUNC_KEYMGMT_LOAD, (void (*)= (void))keymgmt_load},
-= {OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has},
- {OSSL_FUNC_KEYMGMT_MATCH, (void (*)= (void))keymgmt_match},
= - {OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))rsa_keymgmt_import},=
- {OSSL_FUNC_KEYMGMT_IMPOR= T_TYPES, (void (*)(void))keymgmt_import_types},
- {OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)= (void))keymgmt_gettable_params},
- {OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_p= arams},
- {OSSL_FUNC= _KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params},
- {OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS,= (void (*)(void))keymgmt_gettable_params}, /* same as gettable */<= br>- {OSSL_FUNC_KEYMGMT_QUERY_= OPERATION_NAME, (void (*)(void))rsa_keymgmt_name},
- {0, NULL }
+ { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgm= t_new },
+ { OSSL_= FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free },
+ { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void= ))keymgmt_load },
+ = { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has },
+ { OSSL_FUNC_KEYMGMT_MATCH, (void = (*)(void))keymgmt_match },
+ { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))rsa_keymgmt_import }= ,
+ { OSSL_FUNC_KE= YMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types },
+ { OSSL_FUNC_KEYMGMT_GETTABLE_PA= RAMS, (void (*)(void))keymgmt_gettable_params },

+ { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(= void))keymgmt_get_params },
+ { OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_par= ams },
+ { OSSL_FU= NC_KEYMGMT_SETTABLE_PARAMS,
+ (void (*)(void))keymgmt_gettable_params }, /* same as gettabl= e */
+ { OSSL_FUNC= _KEYMGMT_QUERY_OPERATION_NAME, (void (*)(void))rsa_keymgmt_name },+ { 0, NULL }
};


static const OSSL_DISPATCH ec_ke= ymgmt_functions[] =3D {
- {OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))keymgmt_new},
- {OSSL_FUNC_KEYMGMT_FREE, (void (*= )(void))keymgmt_free},

= - {OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load},
- {OSSL_FUNC_KEYMGMT_HAS, (void (*= )(void))keymgmt_has},

-= {OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match},
- {OSSL_FUNC_KEYMGMT_IMPORT, (voi= d (*)(void))ec_keymgmt_import},

- {OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_impo= rt_types},
- {OSSL_F= UNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_params},
- {OSSL_FUNC_KEYMGMT_GET= _PARAMS, (void (*)(void))keymgmt_get_params},
- {OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))= keymgmt_set_params},
- = {OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_par= ams}, /* same as gettable */
- {OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME, (void (*)(void))ec_ke= ymgmt_name},
- {0, N= ULL }
+ { OSSL_FUN= C_KEYMGMT_NEW, (void (*)(void))keymgmt_new },
+ { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))key= mgmt_free },
+ { O= SSL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load },
+ { OSSL_FUNC_KEYMGMT_HAS, (void (*)(v= oid))keymgmt_has },
+= { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match },
<= span style=3D"color: hsl(120, 100%, 40%);">+ { OSSL_FUNC_KEYMGMT_IMPORT,= (void (*)(void))ec_keymgmt_import },

+ { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))key= mgmt_import_types },
= + { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_= params },
+ { OSSL= _FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params },
<= span style=3D"color: hsl(120, 100%, 40%);">+ { OSSL_FUNC_KEYMGMT_SET_PAR= AMS, (void (*)(void))keymgmt_set_params },

+ { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS,
<= span style=3D"color: hsl(120, 100%, 40%);">+ (void (*)(void))keymgmt_g= ettable_params }, /* same as gettable */

+ { OSSL_FUNC_KEYMGMT_QUERY_OPERATION_NAME, (void (*= )(void))ec_keymgmt_name },
+ { 0, NULL }
};

static const OSSL_DISPATCH ed448_keymgmt_functions[] =3D {

- {OSSL_FUNC_KEYMGMT_NEW, (void (= *)(void))keymgmt_new},

= - {OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free},
- {OSSL_FUNC_KEYMGMT_LOAD, (void (= *)(void))keymgmt_load},

- {OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has},
- {OSSL_FUNC_KEYMGMT_MATCH, (void (= *)(void))keymgmt_match},

- {OSSL_FUNC_KEYMGMT_I= MPORT_TYPES, (void (*)(void))keymgmt_import_types},
- {OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (vo= id (*)(void))keymgmt_gettable_params},
- {OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt= _get_params},
- {OSS= L_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params},
<= span style=3D"color: hsl(0, 100%, 40%);">- {OSSL_FUNC_KEYMGMT_SETTABLE_P= ARAMS, (void (*)(void))keymgmt_gettable_params}, /* same as gettable = */

- {0, NULL }
+ { OSSL_FUNC_KEYMGMT_= NEW, (void (*)(void))keymgmt_new },
+ { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free = },
+ { OSSL_FUNC_K= EYMGMT_LOAD, (void (*)(void))keymgmt_load },
+ { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymg= mt_has },
+ { OSSL= _FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match },
+ { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)= (void))ed448_keymgmt_import },
+ { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_im= port_types },
+ { = OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_params = },
+ { OSSL_FUNC_K= EYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params },
+ { OSSL_FUNC_KEYMGMT_SET_PARAMS, (v= oid (*)(void))keymgmt_set_params },
+ { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS,
+ (void (*)(void))keymgmt_gettable= _params }, /* same as gettable */
+ { 0, NULL }
};
<= br> static const OSSL_DISPATCH ed25519_keymgmt_functions[] =3D {
- {OSSL_FUNC_KEYMGMT_NEW= , (void (*)(void))keymgmt_new},
- {OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keymgmt_free},
- {OSSL_FUNC_KEYMGMT_LOAD= , (void (*)(void))keymgmt_load},
- {OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))keymgmt_has},=
- {OSSL_FUNC_KEYMGMT_MATCH= , (void (*)(void))keymgmt_match},
- {OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))ed25519_keymgmt_= import},
- {OSSL_FUN= C_KEYMGMT_IMPORT_TYPES, (void (*)(void))keymgmt_import_types},
- {OSSL_FUNC_KEYMGMT_GETTABLE_PA= RAMS, (void (*)(void))keymgmt_gettable_params},

- {OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void= ))keymgmt_get_params},
= - {OSSL_FUNC_KEYMGMT_SET_PARAMS, (void (*)(void))keymgmt_set_params},
- {OSSL_FUNC_KEYMGMT_S= ETTABLE_PARAMS, (void (*)(void))keymgmt_gettable_params}, /* same as = gettable */
- {0, NU= LL }
+ { OSSL_FUNC= _KEYMGMT_NEW, (void (*)(void))keymgmt_new },
+ { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))keym= gmt_free },
+ { OS= SL_FUNC_KEYMGMT_LOAD, (void (*)(void))keymgmt_load },
+ { OSSL_FUNC_KEYMGMT_HAS, (void (*)(vo= id))keymgmt_has },
+ = { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))keymgmt_match },
+ { OSSL_FUNC_KEYMGMT_IMPORT, = (void (*)(void))ed25519_keymgmt_import },

+ { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void)= )keymgmt_import_types },
+ { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*)(void))keymgmt_getta= ble_params },
+ { = OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*)(void))keymgmt_get_params },<= br>+ { OSSL_FUNC_KEYMGMT_SET= _PARAMS, (void (*)(void))keymgmt_set_params },
+ { OSSL_FUNC_KEYMGMT_SETTABLE_PARAMS,<= br>+ (void (*)(void))keymg= mt_gettable_params }, /* same as gettable */
+ { 0, NULL }
};


const OSSL_ALGORITHM keymgmts[] =3D = {
- {"RSA:rsaEn= cryption", XKEY_PROV_PROPS, rsa_keymgmt_functions, "OpenVPN xkey = RSA Key Manager"},
- {"RSA-PSS:RSASSA-PSS", XKEY_PROV_PROPS, rsa_keymgmt_functio= ns, "OpenVPN xkey RSA-PSS Key Manager"},
- {"EC:id-ecPublicKey", XKEY_PROV_= PROPS, ec_keymgmt_functions, "OpenVPN xkey EC Key Manager"},
- {"ED448", XK= EY_PROV_PROPS, ed448_keymgmt_functions, "OpenVPN xkey ED448 Key Manage= r"},
- {"E= D25519", XKEY_PROV_PROPS, ed25519_keymgmt_functions, "OpenVPN xke= y ED25519 Key Manager"},
- {NULL, NULL, NULL, NULL}
+ { "RSA:rsaEncryption", XKEY_PROV_PROPS, rsa_= keymgmt_functions, "OpenVPN xkey RSA Key Manager" },
+ { "RSA-PSS:RSASSA-PSS&q= uot;, XKEY_PROV_PROPS, rsa_keymgmt_functions,

+ "OpenVPN xkey RSA-PSS Key Manager"= ; },
+ { "EC:= id-ecPublicKey", XKEY_PROV_PROPS, ec_keymgmt_functions, "OpenVPN = xkey EC Key Manager" },
+ { "ED448", XKEY_PROV_PROPS, ed448_keymgmt_functions,= "OpenVPN xkey ED448 Key Manager" },
+ { "ED25519", XKEY_PROV_PROPS, ed25= 519_keymgmt_functions, "OpenVPN xkey ED25519 Key Manager" },
+ { NULL, NULL, NULL, = NULL }
};


@@ -682,29 +680,39 @@

XKEY_SIGALG sigalg; } XKEY_SIGNATURE_CTX;

-static const XKEY_SIGALG default_sigalg =3D { .m= dname =3D "MD5-SHA1", .saltlen =3D "digest",
= - = .padmode =3D "pkcs1", .keytype =3D "RSA"};<= /span>
+static const XKEY_SI= GALG default_sigalg =3D {
+ .mdname =3D "MD5-SHA1", .saltlen =3D "digest"= , .padmode =3D "pkcs1", .keytype =3D "RSA"
+};


<= span style=3D"color: hsl(0, 100%, 40%);">-const struct {

+const struct
+{
int nid;
const char *name;

-} digest_names[] =3D {{NID_md5_sha1, "MD5-SHA1"}, {NID_sha1, = "SHA1"},
- = {NID_sha224, "SHA224", }, {NID_sha256, "SHA= 256"}, {NID_sha384, "SHA384"},
- {NID_sha512, "SHA512"= }, {0, NULL}};
+} dig= est_names[] =3D { { NID_md5_sha1, "MD5-SHA1" },
+ { NID_sha1, &quo= t;SHA1" },
+ = {
+ = NID_sha224,
+ "SHA224",
+ },

= + { NID_sha= 256, "SHA256" },
+ { NID_sha384, "SHA384" },
<= span style=3D"color: hsl(120, 100%, 40%);">+ { NID_sha5= 12, "SHA512" },

+ { 0, NULL } };
/* Use of NIDs a= s opposed to EVP_MD_fetch is okay here
* as these are onl= y used for converting names passed in
* by OpenSSL to con= st strings.
*/

-static struct {
+static struct
+{
int id;
cons= t char *name;
-} padmod= e_names[] =3D {{RSA_PKCS1_PADDING, "pkcs1"},
- {RSA_PKCS1_PSS_PADDIN= G, "pss"},
- = {RSA_NO_PADDING, "none"},
- {0, NULL}};+} padmode_names[] =3D { { RS= A_PKCS1_PADDING, "pkcs1" },
+ { RSA_PKCS1_PSS_PADDING, "pss&= quot; },
+ = { RSA_NO_PADDING, "none" },
+ { 0, NULL } };
-static const = char *saltlen_names[] =3D {"digest", "max", "auto&= quot;, NULL};
+static= const char *saltlen_names[] =3D { "digest", "max", &qu= ot;auto", NULL };

/* Return a strin= g literal for digest name - normalizes
* alternate names = like SHA2-256 to SHA256 etc.
@@ -725,7 +733,7 @@
= {
i++;
}- return digest_names[i].name= ? digest_names[i].name : "MD5-SHA1";
+ return digest_names[i].name ? digest_names= [i].name : "MD5-SHA1";
}

static void *
@@ -733,7 +741,7 @@
{

xkey_dmsg(D_XKEY, "entry");
=
- (void) pro= pq; /* unused */
+ = (void)propq; /* unused */

XKEY_SIGN= ATURE_CTX *sctx =3D OPENSSL_zalloc(sizeof(*sctx));
if = (!sctx)
@@ -768,8 +776,7 @@
static OSS= L_PARAM settable[] =3D {
OSSL_PARAM_utf8_string(OS= SL_SIGNATURE_PARAM_PAD_MODE, NULL, 0),
OSSL_PARAM_= utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
- OSSL_PARAM_utf8_string(OSSL_SIGNATURE_= PARAM_PSS_SALTLEN, NULL, 0),
- OSSL_PARAM_END
+ OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_PSS_SALTLEN, = NULL, 0), OSSL_PARAM_END
};
return settable;
@@ -785,7 +792,7 @@
if (params =3D=3D NULL)
= {
- return 1; /= * not an error */
+ = return 1; /* not an error */
}
= p =3D OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_PAD_MODE);
if (p && p->data_type =3D=3D OSSL_PARAM_UTF8= _STRING)
@@ -801,8 +808,7 @@
}
if (sctx->sigalg.padmode =3D=3D NULL)
{

- = msg(M_WARN, "xkey signature_ctx: padmode <%s>, treating as = <none>",
- = (char *)p->data);
+ msg(M_WARN, "xkey signature_ctx: padmode &l= t;%s>, treating as <none>", (char *)p->data);
sctx->sigalg.padmode =3D "none";

}

xkey_dmsg(D_XKEY, "setting pad= mode as %s", sctx->sigalg.padmode);
@@ -835,7 +841,= 7 @@
}

p =3D OS= SL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
- if (p && p->data_typ= e =3D=3D OSSL_PARAM_UTF8_STRING)

+ if (p && p->data_type =3D=3D OSSL_PARAM_UTF8_ST= RING)
{
sctx->sigalg.mdnam= e =3D xkey_mdname(p->data);
xkey_dmsg(D_XKEY, &= quot;setting hashalg as %s", sctx->sigalg.mdname);
= @@ -859,8 +865,7 @@
}
if = (sctx->sigalg.saltlen =3D=3D NULL)
{
= - msg(M_WARN, "xk= ey_signature_params: unknown saltlen <%s>",
- (char *)p->data);
+ msg(M_WARN, &= quot;xkey_signature_params: unknown saltlen <%s>", (char *)p->= ;data);
sctx->sigalg.saltlen =3D "dige= st"; /* most common */
}
= xkey_dmsg(D_XKEY, "setting saltlen to %s", sctx->sigalg.s= altlen);
@@ -925,7 +930,8 @@
else if (= sign)
{
ret =3D sign(sctx->= ;keydata->handle, sig, siglen, tbs, tbslen, sctx->sigalg);
= - xkey_dmsg(D_XKEY, "= xkey_provider: external sign op returned ret =3D %d siglen =3D %d", re= t, (int) *siglen);
+ = xkey_dmsg(D_XKEY, "xkey_provider: external sign op returned ret= =3D %d siglen =3D %d", ret,
+ (int)*siglen);
}
else
{
@@ -980,8 +986,= 7 @@
}

static int
-signature_digest_sign_init(= void *ctx, const char *mdname,
- void *provkey, const OSSL_PARAM params[= ])
+signature_digest_= sign_init(void *ctx, const char *mdname, void *provkey, const OSSL_PARAM pa= rams[])
{
xkey_dmsg(D_XKEY, "mdn= ame =3D <%s>", mdname);

@@ -10= 23,8 +1028,8 @@
}

stati= c int
-signature_digest= _sign(void *ctx, unsigned char *sig, size_t *siglen,
- size_t sigsize, const= unsigned char *tbs, size_t tbslen)
+signature_digest_sign(void *ctx, unsigned char *sig, size_t= *siglen, size_t sigsize,
+ const unsigned char *tbs, size_t tbslen)=
{
xkey_dmsg(D_XKEY, "entry");

@@ -1073,8 +1078,8 @@
/* Si= gn digest using native sign function -- will only work for native keys
*/
int
-xkey_native_sign(XKEY_KEYDATA *key, unsigned char *sig, siz= e_t *siglen,
- = const unsigned char *tbs, size_t tbslen, XKEY_SIGALG sigalg)=
+xkey_native_sign(XKEY_KEYD= ATA *key, unsigned char *sig, size_t *siglen, const unsigned char *tbs,
+ size_t= tbslen, XKEY_SIGALG sigalg)
{
xkey_d= msg(D_XKEY, "entry");

@@ -1101,= 13 +1106,17 @@
OSSL_PARAM params[6];
= if (EVP_PKEY_get_id(pkey) =3D=3D EVP_PKEY_RSA)
{
- params[i++] =3D= OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, (char *)mdna= me, 0);
- params= [i++] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE, (= char *)padmode, 0);
+= params[i++] =3D
+ OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGES= T, (char *)mdname, 0);
+ OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PA= D_MODE, (char *)padmode, 0);
if (!strcmp(sigalg.pa= dmode, "pss"))
{
- params[i++] =3D OSSL_PARAM_cons= truct_utf8_string(OSSL_SIGNATURE_PARAM_PSS_SALTLEN, (char *) saltlen, 0);
+ params[i+= +] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PSS_SALTLEN,
+ = (char *)saltlen, 0);
= /* same digest for mgf1 */
- params[i++] =3D OSSL_PARAM_construct_utf8_str= ing(OSSL_SIGNATURE_PARAM_MGF1_DIGEST, (char *) mdname, 0);
+ params[i++] =3D OSSL_PAR= AM_construct_utf8_string(OSSL_SIGNATURE_PARAM_MGF1_DIGEST,
+ = (char *)mdname, 0);
}
}
params[i++] =3D OSSL_PARAM_construct= _end();
@@ -1134,27 +1143,27 @@
}
static const OSSL_DISPATCH signature_functions[]= =3D {
- {OSSL_FUNC_= SIGNATURE_NEWCTX, (void (*)(void))signature_newctx},
- {OSSL_FUNC_SIGNATURE_FREECTX, (void (*)= (void))signature_freectx},
- {OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))signature_sign_ini= t},
- {OSSL_FUNC_SIG= NATURE_SIGN, (void (*)(void))signature_sign},
- {OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, (void = (*)(void))signature_digest_verify_init},
- {OSSL_FUNC_SIGNATURE_DIGEST_VERIFY, (void (*)(void))= signature_digest_verify},
- {OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, (void (*)(void))signature_di= gest_sign_init},
- {= OSSL_FUNC_SIGNATURE_DIGEST_SIGN, (void (*)(void))signature_digest_sign},
- {OSSL_FUNC_SIGNATURE= _SET_CTX_PARAMS, (void (*)(void))signature_set_ctx_params},
- {OSSL_FUNC_SIGNATURE_SETTABLE_CTX= _PARAMS, (void (*)(void))signature_settable_ctx_params},

- {OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS,= (void (*)(void))signature_get_ctx_params},
- {OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, (void (= *)(void))signature_gettable_ctx_params},
- {0, NULL }
+ { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))signature_n= ewctx },
+ { OSSL_= FUNC_SIGNATURE_FREECTX, (void (*)(void))signature_freectx },
+ { OSSL_FUNC_SIGNATURE_SIGN_INI= T, (void (*)(void))signature_sign_init },

+ { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))signa= ture_sign },
+ { O= SSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, (void (*)(void))signature_digest_ver= ify_init },
+ { OS= SL_FUNC_SIGNATURE_DIGEST_VERIFY, (void (*)(void))signature_digest_verify },=
+ { OSSL_FUNC_SIG= NATURE_DIGEST_SIGN_INIT, (void (*)(void))signature_digest_sign_init },
+ { OSSL_FUNC_SIGNATUR= E_DIGEST_SIGN, (void (*)(void))signature_digest_sign },
+ { OSSL_FUNC_SIGNATURE_SET_CTX_PARAM= S, (void (*)(void))signature_set_ctx_params },
+ { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS, (= void (*)(void))signature_settable_ctx_params },
+ { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void= (*)(void))signature_get_ctx_params },
+ { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS, (void (*)= (void))signature_gettable_ctx_params },
+ { 0, NULL }
};

const OSSL_ALGORITHM signatures[] =3D {
- {"RSA:rsaEncryption", XKEY_= PROV_PROPS, signature_functions, "OpenVPN xkey RSA Signature"},
- {"ECDSA",= XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey ECDSA Signature&q= uot;},
- {"ED44= 8", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey Ed448 Sig= nature"},
- {&q= uot;ED25519", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey= Ed25519 Signature"},
- {NULL, NULL, NULL, NULL}
+ { "RSA:rsaEncryption", XKEY_PROV_PROPS, signatu= re_functions, "OpenVPN xkey RSA Signature" },
+ { "ECDSA", XKEY_PROV_PROP= S, signature_functions, "OpenVPN xkey ECDSA Signature" },<= br>+ { "ED448", XK= EY_PROV_PROPS, signature_functions, "OpenVPN xkey Ed448 Signature"= ; },
+ { "ED2= 5519", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey Ed2551= 9 Signature" },
= + { NULL, NULL, NULL, NULL }
};

/* main provider interface */
@@ -1193,8 +1202,= 7 @@
xkey_dmsg(D_XKEY, "entry");
<= span>

static const OSSL_PARAM param_types[] =3D {
- OSSL_PARAM_DEFN(O= SSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
- OSSL_PARAM_END
+ OSSL_PARAM_DEFN(OSSL_PROV_PARAM_= NAME, OSSL_PARAM_UTF8_PTR, NULL, 0), OSSL_PARAM_END
};=

return param_types;
@@ -1229,11 +1237,11 @@

}

static const OSSL_DISPATCH dispatch_table[] =3D {

- {OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (v= oid (*)(void))gettable_params},
- {OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))get_params},<= /span>
- {OSSL_FUNC_PROVIDE= R_QUERY_OPERATION, (void (*)(void))query_operation},
- {OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)= (void))teardown},
- = {0, NULL}
+ { OSSL= _FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))gettable_params },+ { OSSL_FUNC_PROVIDER_GET= _PARAMS, (void (*)(void))get_params },
+ { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void= ))query_operation },
= + { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))teardown },
<= span style=3D"color: hsl(120, 100%, 40%);">+ { 0, NULL }

};


int
diff --git a/sr= c/openvpnmsica/dllmain.c b/src/openvpnmsica/dllmain.c
index= 6f14a5c..242b804 100644
--- a/src/openvpnmsica/dllmain.c
+++ b/src/openvpnmsica/dllmain.c
@@ -42,10 += 42,7 @@
* DLL entry point
*/
= BOOL WINAPI
-Dll= Main(
- _In_ HINSTAN= CE hinstDLL,
- _In_ = DWORD dwReason,
- _I= n_ LPVOID lpReserved)
+DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD dwReason, _In_ LPVOID lpReser= ved)
{
UNREFERENCED_PARAMETER(hinstDL= L);
UNREFERENCED_PARAMETER(lpReserved);
@@ -59,12 +56,13 @@

{
= return FALSE;
}
- /* Fall through. */
+ /* Fall through. */

case DLL_THREAD_ATTACH: {
/* Create thread local stora= ge data. */
- = struct openvpnmsica_thread_data *s =3D (struct openvpnmsica_thread_data *= )calloc(1, sizeof(struct openvpnmsica_thread_data));
+ struct openvpnmsica_thread_da= ta *s =3D (struct openvpnmsica_thread_data *)calloc(
+ 1, sizeof(struct openvpnm= sica_thread_data));
if (s =3D=3D NULL)<= br> {
return FALSE;
@@ -108,7 +106,8 @@
/* Secure last error b= efore it is overridden. */
DWORD dwResult =3D (flags &= amp; M_ERRNO) !=3D 0 ? GetLastError() : ERROR_SUCCESS;

- struct openvpnmsica_= thread_data *s =3D (struct openvpnmsica_thread_data *)TlsGetValue(openvpnms= ica_thread_data_idx);
+ struct openvpnmsica_thread_data *s =3D
+ (struct openvpnmsica_thread_data *)TlsGetV= alue(openvpnmsica_thread_data_idx);
if (s->hInstall= =3D=3D 0)
{
/* No MSI sessio= n, no fun. */
@@ -161,16 +160,13 @@

/* Field 4: The Windows error description. */ LPWSTR szErrMessage =3D NULL;
- if (FormatMessage(
- FORMAT_MESSAGE_FROM_SYSTEM | F= ORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
- 0,

- dwResult,

<= span style=3D"color: hsl(0, 100%, 40%);">- 0,

- (LPWSTR)&szErrMe= ssage,

- = 0,
- NU= LL) && szErrMessage)
+ if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESS= AGE_ALLOCATE_BUFFER
+= | FORMAT_MESSAGE_IGNORE_INSERTS,
+ 0, dwR= esult, 0, (LPWSTR)&szErrMessage, 0, NULL)

+ && szErrMessage)
{

- = /* Trim trailing whitespace. Set terminator after the last non-whitesp= ace character. This prevents excessive trailing line breaks. */
<= span style=3D"color: hsl(120, 100%, 40%);">+ /* Trim trailing wh= itespace. Set terminator after the last non-whitespace character.
+ * This prevents = excessive trailing line breaks. */
for (size_t= i =3D 0, i_last =3D 0;; i++)
{
if (szErrMessage[i])

@@ -191,6 +187,7 @@=
}
}
=
- MsiProcessMessage(s->= hInstall, (flags & M_WARN) ? INSTALLMESSAGE_INFO : INSTALLMESSAGE_ERROR= , hRecordProg);
+ = MsiProcessMessage(s->hInstall, (flags & M_WARN) ? INSTALLMESSAGE_INF= O : INSTALLMESSAGE_ERROR,
+ hRecordProg);
MsiCloseHand= le(hRecordProg);
}
diff --git a/src/openvp= nmsica/msica_arg.c b/src/openvpnmsica/msica_arg.c
index 0f5= b2fb..2f1bbba 100644
--- a/src/openvpnmsica/msica_arg.c
+++ b/src/openvpnmsica/msica_arg.c
@@ -52,15 += 52,14 @@


void-msica_arg_seq_add_head(=
- _Inout_ struct msica_arg= _seq *seq,
- _In_z_ = LPCWSTR argument)
+ms= ica_arg_seq_add_head(_Inout_ struct msica_arg_seq *seq, _In_z_ LPCWSTR argu= ment)
{
size_t argument_size =3D (wcs= len(argument) + 1) * sizeof(WCHAR);
struct msica_arg *= p =3D malloc(sizeof(struct msica_arg) + argument_size);
= if (p =3D=3D NULL)
{
- msg(M_FATAL, "%s: malloc(%u) failed"= ;, __FUNCTION__, sizeof(struct msica_arg) + argument_size);
+ msg(M_FATAL, "%s: mall= oc(%u) failed", __FUNCTION__,

+ sizeof(struct msica_arg) + argument_size);
}
memcpy(p->val, argument, argument= _size);
p->next =3D seq->head;
@= @ -73,15 +72,14 @@


voi= d
-msica_arg_seq_add_ta= il(
- _Inout_ struct= msica_arg_seq *seq,
- = _Inout_ LPCWSTR argument)
+msica_arg_seq_add_tail(_Inout_ struct msica_arg_seq *seq, _Inout_ = LPCWSTR argument)
{
size_t argument_s= ize =3D (wcslen(argument) + 1) * sizeof(WCHAR);
struct= msica_arg *p =3D malloc(sizeof(struct msica_arg) + argument_size);<= br> if (p =3D=3D NULL)
{
- msg(M_FATAL, "%s: malloc(%u)= failed", __FUNCTION__, sizeof(struct msica_arg) + argument_size);
+ msg(M_FATAL, &q= uot;%s: malloc(%u) failed", __FUNCTION__,
+ sizeof(struct msica_arg) + argument_= size);
}
memcpy(p->val, argume= nt, argument_size);
p->next =3D NULL;
@@ -111,10 +109,13 @@


#ifdef _MSC_VER=
#pragma warning(push)
-#pragma warning(disable: 4996) /* Using unsafe string fun= ctions: The space in s and termination of p->val has been implicitly ver= ified at the beginning of this function. */
+#pragma warning( = \
+ disable : 4996) /* Using unsafe string fu= nctions: The space in s and termination of p->val has \
+ been implicit= ly verified at the beginning of this function. */
#endif

- /= * Dummy argv[0] (i.e. executable name), for CommandLineToArgvW to work corr= ectly when parsing this string. */
+ /* Dummy argv[0] (i.e. executable name), for CommandLine= ToArgvW to work correctly when parsing
+ * this string. */
wcscpy(str, = L"x");

/* Join. */<= br>diff --git a/src/openvpnmsica/msica_arg.h b/src/openvpnmsica/msica= _arg.h
index 2a3e931..67bddde 100644
--- a/= src/openvpnmsica/msica_arg.h
+++ b/src/openvpnmsica/msica_a= rg.h
@@ -28,7 +28,7 @@

#= ifdef _MSC_VER
#pragma warning(push)
-#pragma warning(disable: 4200) /* Using zer= o-sized arrays in struct/union. */
+#pragma warning(disable : 4200) /* Using zero-sized arrays i= n struct/union. */
#endif


@@ -57,8 +57,7 @@
*
= * @param seq Pointer to uninitialized argument sequence */
-void
-msica_arg_seq_init(_Inout_= struct msica_arg_seq *seq);
+void msica_arg_seq_init(_Inout_ struct msica_arg_seq *seq);=


/**
@@ -66,8= +65,7 @@
*
* @param seq Poin= ter to the argument sequence
*/
-void
-msica_arg_seq_free(_Inout_ struct msica_arg_seq *seq);+void msica_arg_seq_free(_Inou= t_ struct msica_arg_seq *seq);

/**
@@ -77,10 +75,7 @@
*<= br> * @param argument Zero-terminated argument string to insert= .
*/
= -void
-msica_arg_seq_ad= d_head(
- _Inout_ st= ruct msica_arg_seq *seq,
+void msica_arg_seq_add_head(_Inout_ struct msica_arg_seq *seq,= _In_z_ LPCWSTR argument);


/**

@@ -90,10 +85,7 @@
*
<= span> * @param argument Zero-terminated argument string to append.
*/
-voi= d
-msica_arg_seq_add_ta= il(
- _Inout_ struct= msica_arg_seq *seq,
- = _Inout_ LPCWSTR argument);
+void msica_arg_seq_add_tail(_Inout_ struct msica_arg_seq *seq, _I= nout_ LPCWSTR argument);

/**
<= span> * Join arguments of the argument sequence into a space delimited str= ing

diff --git a/src/openvpnmsica/msiex.c b/src/openvpnmsic= a/msiex.c
index c0f5853..ddf078f 100644
---= a/src/openvpnmsica/msiex.c
+++ b/src/openvpnmsica/msiex.c<= /span>
@@ -35,10 +35,7 @@


UINT
-msi_= get_string(
- _In_ M= SIHANDLE hInstall,
- = _In_z_ LPCWSTR szName,
- _Out_ LPWSTR *pszValue)
+msi_get_string(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _O= ut_ LPWSTR *pszValue)
{
if (pszValue = =3D=3D NULL)
{
@@ -85,7 +82,8 @@
}
else
{- SetLastError(uiResult)= ; /* MSDN does not mention MsiGetProperty() to set GetLastError(). But we d= o have an error code. Set last error manually. */
+ SetLastError(uiResult); /* MSDN does = not mention MsiGetProperty() to set GetLastError(). But
+ we d= o have an error code. Set last error manually. */
= msg(M_NONFATAL | M_ERRNO, "%s: MsiGetProperty failed", __FUNCTION= __);
return uiResult;
}
@@ -93,10 +91,7 @@

UINT
-msi_get_r= ecord_string(
- _In_= MSIHANDLE hRecord,
- = _In_ unsigned int iField,
- _Out_ LPWSTR *pszValue)
+msi_get_record_string(_In_ MSIHANDLE hRecord, _In_ unsigned i= nt iField, _Out_ LPWSTR *pszValue)
{
= if (pszValue =3D=3D NULL)
{
@@ -143,7 = +138,8 @@
}
else
= {
- SetLast= Error(uiResult); /* MSDN does not mention MsiRecordGetString() to set GetLa= stError(). But we do have an error code. Set last error manually. */=
+ SetLastError(uiRes= ult); /* MSDN does not mention MsiRecordGetString() to set GetLastError().<= /span>
+ = But we do have an error code. Set last error manually. */
msg(M_NONFATAL | M_ERRNO, "%s: MsiRecordGetStri= ng failed", __FUNCTION__);
return uiResult;
}
@@ -151,10 +147,7 @@
=

UINT
-msi_format_record(
- _In_ MSIHANDLE hInstall,
- _In_ MSIHANDLE hRecord,
- _Out_ LPWSTR *pszValue)
+msi_format_record(_In_ MSIHANDLE hI= nstall, _In_ MSIHANDLE hRecord, _Out_ LPWSTR *pszValue)

{<= /span>
if (pszValue =3D=3D NULL)
{
@@ -201,7 +194,8 @@
}
= else
{
- SetLastError(uiResult); /* MSDN does not mention MsiFormatRec= ord() to set GetLastError(). But we do have an error code. Set last error m= anually. */
+ = SetLastError(uiResult); /* MSDN does not mention MsiFormatRecord() to set G= etLastError().
+ = But we do have an error code. Set last error = manually. */
msg(M_NONFATAL | M_ERRNO, "%s: M= siFormatRecord failed", __FUNCTION__);
return= uiResult;
}
@@ -209,11 +203,8 @@


UINT
-msi_format_field(
- _In_ MSIHANDLE hInstall,
- _In_ MSIHANDLE hRecord,
- _In_ unsigned int iField,
- _Out_ LPWSTR *pszValue= )
+msi_format_field(_= In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _In_ unsigned int iField,
+ _Out= _ LPWSTR *pszValue)
{
if (pszValue = =3D=3D NULL)
{
@@ -247,7 +238,8 @@
uiResult =3D MsiRecordSetString(hRecordEx, 0, szValue);
if (uiResult !=3D ERROR_SUCCESS)
{=
- SetLastError(= uiResult); /* MSDN does not mention MsiRecordSetString() to set GetLastErro= r(). But we do have an error code. Set last error manually. */
+ SetLastError(uiResult); = /* MSDN does not mention MsiRecordSetString() to set GetLastError().
=
+ = But we do have an error code. Set last error manually. */ msg(M_NONFATAL | M_ERRNO, "%s: MsiRecordSetString fai= led", __FUNCTION__);
goto cleanup_hRecordEx;<= /span>
}
diff --git a/src/openvpnmsica/msiex.= h b/src/openvpnmsica/msiex.h
index ab029cc..3fb1b90 100644<= /span>
--- a/src/openvpnmsica/msiex.h
+++ b/src/op= envpnmsica/msiex.h
@@ -38,11 +38,7 @@
*
* @return ERROR_SUCCESS on success; Win32 error code other= wise
*/
-UINT
-msi_get_strin= g(
- _In_ MSIHANDLE = hInstall,
- _In_z_ L= PCWSTR szName,
- _Ou= t_ LPWSTR *pszValue);
+UINT msi_get_string(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Out_= LPWSTR *pszValue);


/*= *
@@ -57,11 +53,8 @@
*
= * @return ERROR_SUCCESS on success; Win32 error code otherwise
*/

-UINT-msi_get_record_string(<= br>- _In_ MSIHANDLE hRecord,
- _In_ unsigned int i= Field,
- _Out_ LPWST= R *pszValue);
+UINT m= si_get_record_string(_In_ MSIHANDLE hRecord, _In_ unsigned int iField,
+ = _Out_ LPWSTR *pszValue);


<= span> /**

@@ -79,11 +72,7 @@
*
= * @return ERROR_SUCCESS on success; Win32 error code otherwise
*/
-UINT<= /span>
-msi_format_record(
- _In_ MSIHANDLE hInsta= ll,
- _In_ MSIHANDLE= hRecord,
- _Out_ LP= WSTR *pszValue);
+UIN= T msi_format_record(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Out_ = LPWSTR *pszValue);


/**=
@@ -102,11 +91,7 @@
*
= * @return ERROR_SUCCESS on success; Win32 error code otherwise
*/

-UINT-msi_format_field(
- _In_ MSIHANDLE hInstall,
- _In_ MSIHANDLE hRecord,=
- _In_ unsigned int= iField,
- _Out_ LPW= STR *pszValue);
+UINT= msi_format_field(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _In_ uns= igned int iField,
+ = _Out_ LPWSTR *pszValue);

#endif /* ifndef MSIHLP_H */

diff --git a/src/openvpnm= sica/openvpnmsica.c b/src/openvpnmsica/openvpnmsica.c
index= 003da6e..188f6bc 100644
--- a/src/openvpnmsica/openvpnmsic= a.c
+++ b/src/openvpnmsica/openvpnmsica.c
@= @ -60,9 +60,9 @@
*/

/*= * Amount of tick space to reserve for one TAP/TUN adapter creation/deletiti= on. */
-#define MSICA_A= DAPTER_TICK_SIZE (16 * 1024)
+#define MSICA_ADAPTER_TICK_SIZE (16 * 1024)

-#define FILE_NEED_R= EBOOT L".ovpn_need_reboot"
+#define FILE_NEED_REBOOT L".ovpn_need_r= eboot"

#define OPENVPN_CONNECT_ADAP= TER_SUBSTR L"OpenVPN Connect"

@= @ -78,10 +78,7 @@
* @return ERROR_SUCCESS on success; An = error code otherwise
*/
static UINT
-setup_sequence(
= - _In_ MSIHANDLE hInstall,
- _In_z_ LPCWSTR szProp= erty,
- _In_ struct = msica_arg_seq *seq)
+= setup_sequence(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szProperty, _In_ str= uct msica_arg_seq *seq)
{
UINT uiResu= lt;
LPWSTR szSequence =3D msica_arg_seq_join(seq);
@@ -111,12 +108,11 @@
static void
<= span> _debug_popup(_In_z_ LPCSTR szFunctionName)

{<= br>- WCHAR szTitle[0x100], szM= essage[0x100+MAX_PATH], szProcessPath[MAX_PATH];
+ WCHAR szTitle[0x100], szMessage[0x100 + MA= X_PATH], szProcessPath[MAX_PATH];

/*= Compose pop-up title. The dialog title will contain function name to ease = the process
* locating. Mind that Visual Studio displ= ays window titles on the process list. */
- swprintf_s(szTitle, _countof(szTitle), L"%hs v= %ls",
- = szFunctionName, _L(PACKAGE_VERSION));
+ swprintf_s(szTitle, _countof(szTitle), L"%hs= v%ls", szFunctionName, _L(PACKAGE_VERSION));
=
/* Get process name. */
GetModuleFileNa= me(NULL, szProcessPath, _countof(szProcessPath));
@@ -132,9= +128,7 @@
L"If you would like to debug the c= ustom action, attach a debugger to this process and set breakpoints before = dismissing this dialog.\r\n"
L"\r\n"= ;
L"If you are not debugging this custom acti= on, you can safely ignore this message.",
- szProcessName,
- GetCurrentProcessId(),
- szFunctionName);
+ szProcessName, GetCurrentPr= ocessId(), szFunctionName);


MessageB= ox(NULL, szMessage, szTitle, MB_OK);
}
@@ = -145,11 +139,8 @@
#endif /* ifdef _DEBUG */

static void
-find_adapters(
- _In_ MSIHANDLE hInstall,
- _In_z_ LPCWSTR szzHardwareIDs,
- _In_z_ LPCWSTR szAdaptersPropertyName,- _In_z_ LPCWSTR szActiveAda= ptersPropertyName)
+f= ind_adapters(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szzHardwareIDs,=
+ _In_z_ LPCWS= TR szAdaptersPropertyName, _In_z_ LPCWSTR szActiveAdaptersPropertyName)
{
UINT uiResult;

@@ -166,24 +157,26 @@
return; }

- /* Get IPv4/v6 info for all network adapters. Actually, we= 9;re interested in link status only: up/down? */
+ /* Get IPv4/v6 info for all network adapte= rs. Actually, we're interested in link status only:
+ * up/down? */
= PIP_ADAPTER_ADDRESSES pAdapterAdresses =3D NULL;
- ULONG ulAdapterAdressesSize =3D 16*1024;

+ ULONG ulAdapterAdr= essesSize =3D 16 * 1024;
for (size_t iteration =3D 0; = iteration < 2; iteration++)
{
= pAdapterAdresses =3D (PIP_ADAPTER_ADDRESSES)malloc(ulAdapterAdressesSiz= e);
if (pAdapterAdresses =3D=3D NULL)
{

msg(M_NONFATAL, "%s: mallo= c(%u) failed", __FUNCTION__, ulAdapterAdressesSize);
- uiResult =3D ERROR_OUTOFMEM= ORY; goto cleanup_pAdapterList;
+ uiResult =3D ERROR_OUTOFMEMORY;
+ goto cleanup_pAdapterList;<= /span>
}

ULONG= ulResult =3D GetAdaptersAddresses(
AF_UNSPEC,=
- GAA_FLAG_= SKIP_UNICAST | GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_S= KIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME | GAA_FLAG_INCLUDE_ALL_INTERFA= CES,
- NULL,=
- pAdapterA= dresses,
- &= amp;ulAdapterAdressesSize);
+ GAA_FLAG_SKIP_UNICAST | GAA_FLAG_SKIP_ANYCAST | GAA_FLA= G_SKIP_MULTICAST
+ = | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME
+ | GAA_FLA= G_INCLUDE_ALL_INTERFACES,
+ NULL, pAdapterAdresses, &ulAdapterAdressesSize);

if (ulResult =3D=3D ERROR_SUCCESS)
{
@@ -193,9 +186,12 @@
free(pAdapterAdresses);

if (ulResult = !=3D ERROR_BUFFER_OVERFLOW)
{
- SetLastError(ulResult); /* MSD= N does not mention GetAdaptersAddresses() to set GetLastError(). But we do = have an error code. Set last error manually. */
+ SetLastError(
+ ulResult); /* MSDN does n= ot mention GetAdaptersAddresses() to set GetLastError().
+ But we d= o have an error code. Set last error manually. */
= msg(M_NONFATAL | M_ERRNO, "%s: GetAdaptersAddresses() failed"= , __FUNCTION__);
- = uiResult =3D ulResult; goto cleanup_pAdapterList;
+ uiResult =3D ulResult;
+ goto cleanu= p_pAdapterList;
}
}
@@ -208,26 +204,33 @@

= /* Prepare semicolon delimited list of TAP adapter ID(s) and act= ive TAP adapter ID(s). */
LPWSTR
- szAdapters =3D (LPWSTR)malloc(a= dapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR)),=
- szAdaptersTai= l =3D szAdapters;
+ = szAdapters =3D
+ = (LPWSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator= */) * sizeof(WCHAR)),
+ szAdaptersTail =3D szAdapters;
if (szAdapters = =3D=3D NULL)
{
- msg(M_FATAL, "%s: malloc(%u) failed", __FUN= CTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeo= f(WCHAR));
- uiR= esult =3D ERROR_OUTOFMEMORY; goto cleanup_pAdapterAdresses;
+ msg(M_FATAL, "%s: mall= oc(%u) failed", __FUNCTION__,

+ adapter_count * (38 /*GUID*/ + 1 /*separator/ter= minator*/) * sizeof(WCHAR));
+ uiResult =3D ERROR_OUTOFMEMORY;
+ goto cleanup_pAdapterAdresses;<= br> }

LPWSTR
- szAdaptersActive =3D (L= PWSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * s= izeof(WCHAR)),

- = szAdaptersActiveTail =3D szAdaptersActive;
+ szAdaptersActive =3D
+ (LPWSTR)malloc(adapter_count * (38 /*G= UID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR)),
+ szAdaptersActiveTail =3D szAdaptersAc= tive;
if (szAdaptersActive =3D=3D NULL)
{

- msg(M= _FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (3= 8 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR));
- uiResult =3D ERROR_OUTOFMEMORY= ; goto cleanup_szAdapters;
+ msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__= ,
+ adapte= r_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(WCHAR));
+ uiResult =3D ERR= OR_OUTOFMEMORY;
+ = goto cleanup_szAdapters;
}

for (struct tap_adapter_node *pAdapter =3D pAdapterList; pA= dapter; pAdapter =3D pAdapter->pNext)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- /* exclude adapters creat= ed by OpenVPN Connect, since they're removed on Connect uninstallation = */

+ /* exclud= e adapters created by OpenVPN Connect, since they're removed on Connect=
+ * uninstal= lation */
if (wcsstr(pAdapter->szName, OPENVPN_= CONNECT_ADAPTER_SUBSTR))
{
= msg(M_WARN, "%s: skip OpenVPN Connect adapter '%ls'"= ;, __FUNCTION__, pAdapter->szName);
@@ -251,7 +254,9 @@<= /span>
{
OLECHAR szId[38 /*G= UID*/ + 1 /*terminator*/];
GUID guid;- if (MultiByteToWid= eChar(CP_ACP, MB_PRECOMPOSED, p->AdapterName, -1, szId, _countof(szId)) = > 0
+ i= f (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, p->AdapterName, -1, szId,=
+ = _countof(szId))
+ > 0
&a= mp;& SUCCEEDED(IIDFromString(szId, &guid))
= && memcmp(&guid, &pAdapter->guid, sizeof(GUID))= =3D=3D 0)
{
@@ -270,22 +275,2= 6 @@
}
CoTaskMemFree(szAd= apterId);
}
- szAdaptersTail [0] =3D 0;
+ szAdaptersTail[0] =3D 0;
= szAdaptersActiveTail[0] =3D 0;

/* S= et Installer properties. */
uiResult =3D MsiSetPropert= y(hInstall, szAdaptersPropertyName, szAdapters);
if (u= iResult !=3D ERROR_SUCCESS)
{
- SetLastError(uiResult); /* MSDN does n= ot mention MsiSetProperty() to set GetLastError(). But we do have an error = code. Set last error manually. */
- msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\&qu= ot;%s\") failed", __FUNCTION__, szAdaptersPropertyName);+ SetLastError(uiResul= t); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But
+ = we do have an error code. Set last error manually. */+ msg(M_NONFATAL | M_E= RRNO, "%s: MsiSetProperty(\"%s\") failed", __FUNCTION__= ,
+ szAdap= tersPropertyName);
goto cleanup_szAdaptersActive;<= /span>
}
uiResult =3D MsiSetProperty(hIn= stall, szActiveAdaptersPropertyName, szAdaptersActive);
= if (uiResult !=3D ERROR_SUCCESS)
{
- SetLastError(uiResult); /* MSDN= does not mention MsiSetProperty() to set GetLastError(). But we do have an= error code. Set last error manually. */
- msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProper= ty(\"%s\") failed", __FUNCTION__, szActiveAdaptersPropertyNa= me);
+ SetLast= Error(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastEr= ror(). But
+ = we do have an error code. Set last error manually= . */
+ msg(M_N= ONFATAL | M_ERRNO, "%s: MsiSetProperty(\"%s\") failed",= __FUNCTION__,
+ = szActiveAdaptersPropertyName);
goto cleanup= _szAdaptersActive;
}

@@ -300,8 +309,7 @@

}

=
-UINT __stdcall=
-FindSystemInfo(_In_ MSIHANDL= E hInstall)
+UINT __s= tdcall FindSystemInfo(_In_ MSIHANDLE hInstall)
{ #ifdef DLLEXP_EXPORT
#pragma comment(linker, DLLEX= P_EXPORT)
@@ -313,16 +321,12 @@
OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);

- find_adapters(<= br>- hInstall,
<= span style=3D"color: hsl(0, 100%, 40%);">- L"root\\" _L(TA= P_WIN_COMPONENT_ID) L"\0" _L(TAP_WIN_COMPONENT_ID) L"\0"= ;,

- L"TAPW= INDOWS6ADAPTERS",
= - L"ACTIVETAPWINDOWS6ADAPTERS");
- find_adapters(
- hInstall,
- L"ovpn-dco" L"\0",<= br>- L"OVPNDCOADAPTER= S",
- L&quo= t;ACTIVEOVPNDCOADAPTERS");
+ find_adapters(hInstall, L"root\\" _L(TAP_WIN_COMP= ONENT_ID) L"\0" _L(TAP_WIN_COMPONENT_ID) L"\0",<= br>+ L"TA= PWINDOWS6ADAPTERS", L"ACTIVETAPWINDOWS6ADAPTERS");+ find_adapters(hInstall,
+ L&q= uot;ovpn-dco"
+ = L"\0",
+ L"OVPNDCOADAPTERS", L"ACTIVE= OVPNDCOADAPTERS");

if (bIsCoIni= tialized)
{
@@ -332,13 +336,13 @@
}


-UINT __stdcall
-CloseOpenVPNGUI(_In_ MSIHANDLE hInstall)
+UINT __stdcall CloseOpenVPNGUI(_= In_ MSIHANDLE hInstall)

{
#ifdef DLLEXP_E= XPORT
#pragma comment(linker, DLLEXP_EXPORT)
#endif

- UNREFER= ENCED_PARAMETER(hInstall); /* This CA is does not interact with MSI session= (report errors, access properties, tables, etc.). */
+ UNREFERENCED_PARAMETER(hInstall); /* = This CA is does not interact with MSI session (report
+ = errors, access properties, tables, etc.). */

debug_popup(__FUNCTION__);


@@ -3= 46,7 +350,8 @@
HWND hWnd =3D FindWindow(L"OpenVPN= -GUI", NULL);
if (hWnd)
{
- /* Ask it to clo= se and wait for 100ms. Unfortunately, this will succeed only for recent Ope= nVPN GUI that do not run elevated. */
+ /* Ask it to close and wait for 100ms. Unfortunat= ely, this will succeed only for recent
+ * OpenVPN GUI that do not run elevated. */
SendMessage(hWnd, WM_CLOSE, 0, 0);
= Sleep(100);
}
@@ -355,8 +360,7 @= @
}


-UINT __stdcall
-StartOpenVPNGUI(_In_ MSIHANDLE hInstall)=
+UINT __stdcall StartOpenVP= NGUI(_In_ MSIHANDLE hInstall)
{
#ifdef DL= LEXP_EXPORT
#pragma comment(linker, DLLEXP_EXPORT)<= br>@@ -380,7 +384,8 @@
uiResult =3D MsiRecordSet= String(hRecord, 0, L"\"[#bin.openvpn_gui.exe]\"");
if (uiResult !=3D ERROR_SUCCESS)
{
- SetLastError(uiR= esult); /* MSDN does not mention MsiRecordSetString() to set GetLastError()= . But we do have an error code. Set last error manually. */
+ SetLastError(uiResult); /* = MSDN does not mention MsiRecordSetString() to set GetLastError().
+ = But we do have an error code. Set last error manually. */
<= span> msg(M_NONFATAL | M_ERRNO, "%s: MsiRecordSetString failed= ", __FUNCTION__);

goto cleanup_MsiCreateRecor= d;
}
@@ -397,25 +402,26 @@
<= span> if (szPath =3D=3D NULL)

{
= msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTI= ON__, dwPathSize * sizeof(WCHAR));
- uiResult =3D ERROR_OUTOFMEMORY; goto cleanup_MsiCr= eateRecord;
+ = uiResult =3D ERROR_OUTOFMEMORY;
+ goto cleanup_MsiCreateRecord;
= }

uiResult =3D MsiFormat= Record(hInstall, hRecord, szPath, &dwPathSize);
}<= /span>
if (uiResult !=3D ERROR_SUCCESS)
= {
- SetLastError= (uiResult); /* MSDN does not mention MsiFormatRecord() to set GetLastError(= ). But we do have an error code. Set last error manually. */
+ SetLastError(uiResult); /*= MSDN does not mention MsiFormatRecord() to set GetLastError().

<= span style=3D"color: hsl(120, 100%, 40%);">+ = But we do have an error code. Set last error manually. */

msg(M_NONFATAL | M_ERRNO, "%s: MsiFormatRecord failed"= ;, __FUNCTION__);

goto cleanup_malloc_szPath;
}

/* Launch the Ope= nVPN GUI. */
- SHELL= EXECUTEINFO sei =3D {
-= .cbSize =3D sizeof(SHELLEXECUTEINFO),
- .fMask =3D SEE_MASK_FLAG_NO_UI, /* Don'= ;t show error UI, we'll display it. */
- .lpFile =3D szPath,
- .nShow =3D SW_SHOWNORMAL
- };

+ SHELLEXECUTEINFO sei =3D { .cbSize =3D sizeof= (SHELLEXECUTEINFO),
+= .fMask =3D
+ SEE_MASK_FLAG_NO_UI, /= * Don't show error UI, we'll display it. */
+ .lpFile =3D = szPath,
+ = .nShow =3D SW_SHOWNORMAL };
if (!Shel= lExecuteEx(&sei))
{
uiRes= ult =3D GetLastError();
@@ -462,12 +468,9 @@
* @return ERROR_SUCCESS on success; An error code otherwise

<= span> */

static DWORD
-schedule_adapter_create(
- _Inout_ struct msica_arg_seq *seq,
- _Inout_opt_ struct msica_arg_seq = *seqRollback,

- _In_= z_ LPCWSTR szDisplayName,
- _In_z_ LPCWSTR szHardwareId,
- _Inout_ int *iTicks)
+schedule_adapter_create(_Inout_ struct msica_arg_seq *s= eq,
+ = _Inout_opt_ struct msica_arg_seq *seqRollback, _In_z_ LPCWSTR szDis= playName,
+ = _In_z_ LPCWSTR szHardwareId, _Inout_ int *iTicks)
<= span> {

/* Get existing network adapters. */ struct tap_adapter_node *pAdapterList =3D NULL;
@@ -478,28 +481,25 @@

}

<= span> /* Does adapter exist? */

- for (struct tap_adapter_node *pAdapterOther =3D pAdapterL= ist;; pAdapterOther =3D pAdapterOther->pNext)
+ for (struct tap_adapter_node *pAdapterOthe= r =3D pAdapterList;;
= + pAdapterOther =3D pAdapterOther->pNext)
{=
if (pAdapterOther =3D=3D NULL)
= {
/* No adapter with a same name found.= */
- WCHAR = szArgument[10 /*create=3D""|deleteN=3D""*/ + MAX_PATH /= *szDisplayName*/ + 1 /*|*/ + MAX_PATH /*szHardwareId*/ + 1 /*terminator*/];=
+ WCHAR s= zArgument[10 /*create=3D""|deleteN=3D""*/ + MAX_PATH /*= szDisplayName*/ + 1 /*|*/
+ + MAX_PATH /*szHardwareId*/ + 1 /*termin= ator*/];

/* InstallTUNTAPAda= pters will create the adapter. */
- swprintf_s(
- szArgument, _countof(szArgument),
<= span style=3D"color: hsl(0, 100%, 40%);">- L"create=3D\= "%.*s|%.*s\"",

- MAX_PATH, szDisplayName,
- MAX_PATH, szHardwareId);<= br>+ swprintf_s(szAr= gument, _countof(szArgument), L"create=3D\"%.*s|%.*s\""= , MAX_PATH,
+ = szDisplayName, MAX_PATH, szHardwareId);
= msica_arg_seq_add_tail(seq, szArgument);
<= br> if (seqRollback)
{
/* InstallTUNTAPAdaptersRollback will delete th= e adapter. */
- = swprintf_s(
- = szArgument, _countof(szArgument),
- L"deleteN=3D\"= ;%.*s\"",
- = MAX_PATH, szDisplayName);
+ swprintf_s(szArgument, _countof(szA= rgument), L"deleteN=3D\"%.*s\"", MAX_PATH,
+ szDis= playName);

msica_arg_seq_add_head(seqRollb= ack, szArgument);
}
@@ -514,13 +514,15 @@
if (hwid[0] = =3D=3D 0)
{
= /* This adapter has a different hardware ID. */
- msg(M_NONFATAL, "= %s: Adapter with name \"%ls\" already exists", __FUNCTION__,= pAdapterOther->szName);
+ msg(M_NONFATAL, "%s: Adapter with name \&q= uot;%ls\" already exists", __FUNCTION__,
+ pAdapterOther->sz= Name);
dwResult =3D ERROR_ALREADY_EXIS= TS;
goto cleanup_pAdapterList;<= br> }
else if (wcsic= mp(hwid, szHardwareId) =3D=3D 0)
{<= br>- /* This i= s an adapter with the requested hardware ID. We already have what we want! = */
+ = /* This is an adapter with the requested hardware ID. We already have wh= at we
+ = * want! */
break;
}

}
@@ -56= 2,13 +564,10 @@
* @return ERROR_SUCCESS on success; An er= ror code otherwise
*/
static DWORD
-schedule_adapter_delete(
- _Inout_ struct msica= _arg_seq *seq,
- _In= out_opt_ struct msica_arg_seq *seqCommit,
- _Inout_opt_ struct msica_arg_seq *seqRollback,
- _In_z_ LPCWSTR szDispl= ayName,
- _In_z_ LPC= WSTR szzHardwareIDs,
- = _Inout_ int *iTicks)
+schedule_adapter_delete(_Inout_ struct msica_arg_seq *seq,
+ _Inout_o= pt_ struct msica_arg_seq *seqCommit,

+ _Inout_opt_ struct msica_arg_seq *= seqRollback, _In_z_ LPCWSTR szDisplayName,
+ _In_z_ LPCWSTR szzHardwareID= s, _Inout_ int *iTicks)
{
/* Get adap= ters with given hardware ID. */
struct tap_adapter_nod= e *pAdapterList =3D NULL;
@@ -579,42 +578,36 @@
<= span> }


/* Does adapter exist? *= /
- for (struct tap_= adapter_node *pAdapter =3D pAdapterList; pAdapter !=3D NULL; pAdapter =3D p= Adapter->pNext)
+ = for (struct tap_adapter_node *pAdapter =3D pAdapterList; pAdapter !=3D N= ULL;
+ pAdapt= er =3D pAdapter->pNext)
{
= if (wcsicmp(szDisplayName, pAdapter->szName) =3D=3D 0)
= {
/* Adapter found. */
- WCHAR szArgument[8 /*disa= ble=3D|enable=3D|delete=3D*/ + 38 /*{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}*= / + 1 /*terminator*/];

+ = + 38 /*{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}*/ + 1 /*terminator*/];
if (seqCommit && seqRollback)
<= span> {

/* UninstallTUNTAPAdap= ters will disable the adapter. */
- swprintf_s(
- szArgument, _countof(szArgument),
- L&quo= t;disable=3D" _L(PRIXGUID),
- PRIGUID_PARAM(pAdapter->guid));+ swprintf_s(sz= Argument, _countof(szArgument), L"disable=3D" _L(PRIXGUID),
+ = PRIGUID_PARAM(pAdapter->guid));
msica= _arg_seq_add_tail(seq, szArgument);

= /* UninstallTUNTAPAdaptersRollback will re-enable the adapter. = */
- swp= rintf_s(
- = szArgument, _countof(szArgument),
- L"enable=3D" _L(PRIXGUID),=
- P= RIGUID_PARAM(pAdapter->guid));
+ swprintf_s(szArgument, _countof(szArgument), = L"enable=3D" _L(PRIXGUID),
+ PRIGUID_PARAM(pAdapter->guid= ));
msica_arg_seq_add_head(seqRollback, sz= Argument);

/* UninstallT= UNTAPAdaptersCommit will delete the adapter. */
- swprintf_s(
- szArgument, _countof(sz= Argument),
- = L"delete=3D" _L(PRIXGUID),
- PRIGUID_PARAM(pAdapter->guid= ));
+ = swprintf_s(szArgument, _countof(szArgument), L"delete=3D" _L(PRIX= GUID),
+ = PRIGUID_PARAM(pAdapter->guid));
= msica_arg_seq_add_tail(seqCommit, szArgument);
= }
else
{<= /span>
/* UninstallTUNTAPAdapters will delete the= adapter. */
- = swprintf_s(
- = szArgument, _countof(szArgument),
- L"delete=3D" _L(= PRIXGUID),
- = PRIGUID_PARAM(pAdapter->guid));
+ swprintf_s(szArgument, _countof(szA= rgument), L"delete=3D" _L(PRIXGUID),
+ PRIGUID_PARAM(pAdapte= r->guid));
msica_arg_seq_add_tail(seq, = szArgument);
}

@@ -628,8 +621,7 @@

}


-UINT __stdcall
-EvaluateTUNTAPAdapters(_In= _ MSIHANDLE hInstall)
+UINT __stdcall EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
= {
#ifdef DLLEXP_EXPORT
#pragma com= ment(linker, DLLEXP_EXPORT)
@@ -642,13 +634,8 @@
=
OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);

- struc= t msica_arg_seq
- = seqInstall,
- = seqInstallCommit,
- = seqInstallRollback,
- seqUninstall,
- seqUninstallCommit,
- seqUninstallRollback;
+ struct msica_arg_seq seqInstall, seqInstallCommit, se= qInstallRollback, seqUninstall,
+ seqUninstallCommit, seqUninstallRollback;
msica_arg_seq_init(&seqInstall);

msica_arg= _seq_init(&seqInstallCommit);
msica_arg_seq_init(&= amp;seqInstallRollback);
@@ -657,7 +644,8 @@
msica_arg_seq_init(&seqUninstallRollback);


/* Check rollback state. */
- bool bRollbackEnabled =3D MsiEvaluateCondition(= hInstall, L"RollbackDisabled") !=3D MSICONDITION_TRUE;
= + bool bRollbackEnabled =3D<= /span>
+ MsiEvaluateC= ondition(hInstall, L"RollbackDisabled") !=3D MSICONDITION_TRUE;

/* Open MSI database. */
MSIHANDLE hDatabase =3D MsiGetActiveDatabase(hInstall);

= @@ -672,7 +660,8 @@
switch (MsiDatabaseIsTablePe= rsistent(hDatabase, L"TUNTAPAdapter"))
{
case MSICONDITION_FALSE:
- case MSICONDITION_TRUE: break;
<= span style=3D"color: hsl(120, 100%, 40%);">+ case MSICONDITION_TRUE:=

+ break;<= /span>

default:
= uiResult =3D ERROR_SUCCESS;
@@ -681,11 +670,14 @@

/* Prepare a query to get a list/view o= f adapters. */
MSIHANDLE hViewST =3D 0;
- LPCWSTR szQuery =3D L"SELEC= T `Adapter`,`DisplayName`,`Condition`,`Component_`,`HardwareId` FROM `TUNTA= PAdapter`";

+ = LPCWSTR szQuery =3D
= + L"SELECT `Adapter`,`DisplayName`,`Condition`,`Component_`,`Ha= rdwareId` FROM `TUNTAPAdapter`";
uiResult =3D Msi= DatabaseOpenView(hDatabase, szQuery, &hViewST);
if= (uiResult !=3D ERROR_SUCCESS)
{
- SetLastError(uiResult); /* MSDN doe= s not mention MsiDatabaseOpenView() to set GetLastError(). But we do have a= n error code. Set last error manually. */
+ SetLastError(
+ uiResult); /* MSDN does not mention Msi= DatabaseOpenView() to set GetLastError(). But we
+ do have an error cod= e. Set last error manually. */
msg(M_NONFATAL | M_= ERRNO, "%s: MsiDatabaseOpenView(\"%ls\") failed", __FUN= CTION__, szQuery);
goto cleanup_hDatabase;<= br> }
@@ -694,7 +686,8 @@
ui= Result =3D MsiViewExecute(hViewST, 0);
if (uiResult != =3D ERROR_SUCCESS)
{
- SetLastError(uiResult); /* MSDN does not mentio= n MsiViewExecute() to set GetLastError(). But we do have an error code. Set= last error manually. */
+ SetLastError(uiResult); /* MSDN does not mention MsiViewExecut= e() to set GetLastError(). But
+ we do have an error code. Set= last error manually. */
msg(M_NONFATAL | M_ERRNO,= "%s: MsiViewExecute(\"%ls\") failed", __FUNCTION__, sz= Query);
goto cleanup_hViewST;
= }
@@ -708,7 +701,7 @@
goto cleanu= p_hViewST_close;
}

- for (;; )
+ for (;;)
{ /* Fetch one record from the view. */
= MSIHANDLE hRecord =3D 0;
@@ -720,7 +713,8 @@
= }
else if (uiResult !=3D ERROR_SUCC= ESS)
{
- SetLastError(uiResult); /* MSDN does not mention MsiV= iewFetch() to set GetLastError(). But we do have an error code. Set last er= ror manually. */
+ = SetLastError(uiResult); /* MSDN does not mention MsiViewFetch() to= set GetLastError().
= + But we do have an error code. Set l= ast error manually. */
msg(M_NONFATAL | M_ERRN= O, "%s: MsiViewFetch failed", __FUNCTION__);
= goto cleanup_hRecordProg;
}
@@ -739,8 +733,11 @@

uiResult =3D MsiGetCom= ponentState(hInstall, szValue, &iInstalled, &iAction);
if (uiResult !=3D ERROR_SUCCESS)

= {
- = SetLastError(uiResult); /* MSDN does not mention MsiGetComponentState() to = set GetLastError(). But we do have an error code. Set last error manually. = */
- msg= (M_NONFATAL | M_ERRNO, "%s: MsiGetComponentState(\"%ls\") fa= iled", __FUNCTION__, szValue);
+ SetLastError(uiResult); /* MSDN does not me= ntion MsiGetComponentState() to set
+ GetLastError(). = But we do have an error code. Set last
+ error manuall= y. */
+ = msg(M_NONFATAL | M_ERRNO, "%s: MsiGetComponentState(\"%ls\"= ;) failed", __FUNCTION__,
+ szValue);
f= ree(szValue);
goto cleanup_hRecord;=
}
@@ -754,7 +751,9 @@
{

goto cleanup_hRecord;
<= span> }

- = /* `DisplayName` field type is [Filename](https://docs.microsoft.com/en-u= s/windows/win32/msi/filename), which is either "8.3|long name" or= "8.3". */
= + /* `DisplayName` field type is
+ * [Filename](https://docs.microsoft.com/en-us/= windows/win32/msi/filename), which is either
+ * "8.3|long name" or "8.3&= quot;. */
LPWSTR szDisplayNameEx =3D wcschr(szDisp= layName, L'|');
szDisplayNameEx =3D szDisp= layNameEx !=3D NULL ? szDisplayNameEx + 1 : szDisplayName;
=
@@ -767,7 +766,10 @@
{
goto cleanup_szDisplayName;
= }
- = memcpy_s(szzHardwareIDs, sizeof(szzHardwareIDs) - 2*sizeof(WCHAR) /*requi= res double zero termination*/, szHwId, wcslen(szHwId)*sizeof(WCHAR));
+ memcpy_s(szzH= ardwareIDs,
+ = sizeof(szzHardwareIDs)
+ - 2 * sizeof(WCHAR) /*requires dou= ble zero termination*/,
+ szHwId, wcslen(szHwId) * sizeof(WCHAR)); free(szHwId);
}

@@ -800,7 +802,8 @@

= case MSICONDITION_ERROR:
= uiResult =3D ERROR_INVALID_FIELD;
- msg(M_NONFATAL | M_ERRNO, &q= uot;%s: MsiEvaluateCondition(\"%ls\") failed", __FUNCTION__,= szValue);
+ = msg(M_NONFATAL | M_ERRNO, "%s: MsiEvaluateCondition(\&q= uot;%ls\") failed",
+ __FUNCTION__, szValue);
free(szValue);

= goto cleanup_szDisplayName;
}
@@ -810,12 +813,10 @@
free(sz= Value);

/* Component is = or should be installed. Schedule adapter creation. */
- if (schedule_adapter_create= (
- = &seqInstall,
- = bRollbackEnabled ? &seqInstallRollback : NULL,
- = szDisplayNameEx,
- = szzHardwareIDs,
- &iTicks) !=3D ERROR_SUCCESS)
+ if (sche= dule_adapter_create(&seqInstall,
+ bRollbackEnabl= ed ? &seqInstallRollback : NULL,
+ szDisplayNameE= x, szzHardwareIDs, &iTicks)
+ !=3D ERROR_SUCCESS)
= {
uiResult =3D ERROR_INSTALL= _FAILED;
goto cleanup_szDisplayName;
@@ -823,18 +824,16 @@
}<= br> else
{
- /* Component is install= ed, but should be degraded to advertised/removed. Schedule adapter deletiti= on.
+ = /* Component is installed, but should be degraded to advertised/removed. Sc= hedule
+ = * adapter deletition.
*
- * Note: On adapter= removal (product is being uninstalled), we tolerate dwResult error.
=
- * Better a = partial uninstallation than no uninstallation at all.
+ * Note: On adapter remov= al (product is being uninstalled), we tolerate dwResult
+ * error. Better a part= ial uninstallation than no uninstallation at all.
= */
- = schedule_adapter_delete(
- &seqUninstall,
- bRollbackEnabled ? &seqUn= installCommit : NULL,
-= bRollbackEnabled ? &seqUninstallRollback : NULL,
- szDi= splayNameEx,
- = szzHardwareIDs,
- &iTicks);
+ schedule_adapter_delete(&seqUninstal= l,
+ = bRollbackEnabled ? &seqUninstallCommit : NULL,
+ = bRollbackEnabled ? &seqUninstallRollback : NULL,
+ = szDisplayNameEx, szzHardwareIDs, &iTicks);
<= span> }


/* Arran= ge the amount of tick space to add to the progress indicator.
@@ -872,12 +871,21 @@

msica_arg_seq_add_tail(&s= eqUninstallRollback, str);

/* Store = deferred custom action parameters. */
- if ((uiResult =3D setup_sequence(hInstall, L"Insta= llTUNTAPAdapters", &seqInstall )) !=3D ERROR_SUCCESS
- || (uiResult =3D s= etup_sequence(hInstall, L"InstallTUNTAPAdaptersCommit", &seqI= nstallCommit )) !=3D ERROR_SUCCESS
- || (uiResult =3D setup_sequence(hInstall, L"In= stallTUNTAPAdaptersRollback", &seqInstallRollback )) !=3D ERROR_S= UCCESS
- || (uiR= esult =3D setup_sequence(hInstall, L"UninstallTUNTAPAdapters", &a= mp;seqUninstall )) !=3D ERROR_SUCCESS
- || (uiResult =3D setup_sequence(hInstall, L&= quot;UninstallTUNTAPAdaptersCommit", &seqUninstallCommit )) !=3D = ERROR_SUCCESS
- = || (uiResult =3D setup_sequence(hInstall, L"UninstallTUNTAPAdaptersRol= lback", &seqUninstallRollback)) !=3D ERROR_SUCCESS)
+ if ((uiResult =3D setup_sequen= ce(hInstall, L"InstallTUNTAPAdapters", &seqInstall))
+ !=3D ERROR_SUCCE= SS
+ || (uiRes= ult =3D setup_sequence(hInstall, L"InstallTUNTAPAdaptersCommit", = &seqInstallCommit))
+ !=3D ERROR_SUCCESS
+ || (uiResult =3D
+ setup_sequence(hInstall, L"Inst= allTUNTAPAdaptersRollback", &seqInstallRollback))
+ !=3D ERROR_SUCCESS
+ || (uiResult = =3D setup_sequence(hInstall, L"UninstallTUNTAPAdapters", &seq= Uninstall))
+ = !=3D ERROR_SUCCESS
+ || (uiResult =3D
+ setup_sequence(hInstall, L"UninstallTUNTAPA= daptersCommit", &seqUninstallCommit))
+ !=3D ERROR_SUCCESS
+ || (uiResult =3D
+ setup_sequenc= e(hInstall, L"UninstallTUNTAPAdaptersRollback", &seqUninstall= Rollback))
+ = !=3D ERROR_SUCCESS)
{
g= oto cleanup_hRecordProg;
}
@@ -917,9 += 925,7 @@
* @return TRUE on success; FALSE otherwise
*/
static BOOL
-parse_guid(
- _In_z_ LPCWSTR szArg,
- _Out_ GUID *guid)
+parse_guid(_In_z_ LPCWSTR szArg, _Out_ GUID *guid)
{
if (swscanf_s(szArg, _L(PRIXGUID), PRIGU= ID_PARAM_REF(*guid)) !=3D 11)
{
@@ -94= 6,7 +952,8 @@

msg(M_WARN, "%s: = Reboot required, create reboot indication file \"%ls\"", __F= UNCTION__, path);

- HANDLE file =3D CreateFileW(path, GENERIC_WRITE, 0, NULL,= CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ HANDLE file =3D
+ CreateFileW(path, GENERIC_WRITE, 0, NULL,= CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (file= =3D=3D INVALID_HANDLE_VALUE)
{
= msg(M_NONFATAL | M_ERRNO, "%s: CreateFile(\"%ls\") failed= ", __FUNCTION__, path);
@@ -957,8 +964,7 @@
= }
}

-UINT __stdcall
-ProcessDeferredAction(_In_ MSIHANDLE hInstall)<= br>+UINT __stdcall ProcessDefer= redAction(_In_ MSIHANDLE hInstall)
{
#ifd= ef DLLEXP_EXPORT
#pragma comment(linker, DLLEXP_EXPORT)
@@ -968,13 +974,15 @@

= UINT uiResult;
BOOL bIsCoInitialized =3D SUCCEEDED(CoI= nitialize(NULL));
- = WCHAR tmpDir[MAX_PATH] =3D {0};
+ WCHAR tmpDir[MAX_PATH] =3D { 0 };
<= br> OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);

- BOOL bIsCleanup =3D = MsiGetMode(hInstall, MSIRUNMODE_COMMIT) || MsiGetMode(hInstall, MSIRUNMODE_= ROLLBACK);
+ BOOL = bIsCleanup =3D
+ = MsiGetMode(hInstall, MSIRUNMODE_COMMIT) || MsiGetMode(hInstall, MSIRUNMO= DE_ROLLBACK);

- /* Get sequence arguments. Always Unicode as CommandLineToArg= vW() is available as Unicode-only. */
+ /* Get sequence arguments. Always Unicode as CommandL= ineToArgvW() is available as Unicode-only.
+ */
LPWSTR szSequence =3D N= ULL;
uiResult =3D msi_get_string(hInstall, L"Cust= omActionData", &szSequence);
if (uiResult != =3D ERROR_SUCCESS)
@@ -986,7 +994,8 @@
= if (szArg =3D=3D NULL)
{
uiR= esult =3D GetLastError();
- msg(M_NONFATAL | M_ERRNO, "%s: CommandLineToArgvW(\"%= ls\") failed", __FUNCTION__, szSequence);
+ msg(M_NONFATAL | M_ERRNO, "%= s: CommandLineToArgvW(\"%ls\") failed", __FUNCTION__,=
+ szSequence);
goto cleanup_szSequence;
}

@@ -1038,8 +1047,8 @@
= dwResult =3D tap_create_adapter(NULL, NULL, szHardwareId, &bRebo= otRequired, &guidAdapter);
if (dwResult = =3D=3D ERROR_SUCCESS)
{
- /* Set adapter name. May fa= il on some machines, but that is not critical - use silent
- * flag to mute messag= ebox and print error only to log */
+ /* Set adapter name. May fail on some machi= nes, but that is not critical - use
+ * silent flag to mute messagebox and print= error only to log */
tap_set_adapter_name= (&guidAdapter, szName, TRUE);
}
= }
@@ -1068,7 +1077,8 @@
= if (dwResult =3D=3D ERROR_SUCCESS)
{<= /span>
/* Does the adapter exist? */
- for (struct tap_ad= apter_node *pAdapter =3D pAdapterList; pAdapter !=3D NULL; pAdapter =3D pAd= apter->pNext)

+ = for (struct tap_adapter_node *pAdapter =3D pAdapterList; pAdap= ter !=3D NULL;
+ = pAdapter =3D pAdapter->pNext)
= {
if (wcsicmp(szName, pAdapter-= >szName) =3D=3D 0)
{
@@ -1157,8 +1167,7 @@

return uiResult;
}


-UINT __stdcall
-Check= AndScheduleReboot(_In_ MSIHANDLE hInstall)
+UINT __stdcall CheckAndScheduleReboot(_In_ MSIHANDLE= hInstall)
{
#ifdef DLLEXP_EXPORT<= br> #pragma comment(linker, DLLEXP_EXPORT)
diff --git= a/src/openvpnmsica/openvpnmsica.h b/src/openvpnmsica/openvpnmsica.h=
index b4e3aa8..30def53 100644
--- a/src/openvpnms= ica/openvpnmsica.h
+++ b/src/openvpnmsica/openvpnmsica.h
@@ -51,10 +51,11 @@
/**
* = Set MSI session handle in thread local storage.
*/=
-#define OPENVPNMSICA_SAVE_MS= I_SESSION(hInstall) \
-= { \
- struct= openvpnmsica_thread_data *s =3D (struct openvpnmsica_thread_data *)TlsGetV= alue(openvpnmsica_thread_data_idx); \
- s->hInstall =3D (hInstall); \
+#define OPENVPNMSICA_SAVE_MSI_SESSION(= hInstall) \
+ { = \
+ struct openvpnmsica_thread_data *s = =3D \
+ (struct openvpnmsica_thread_data= *)TlsGetValue(openvpnmsica_thread_data_idx); \
+ s->hInstall =3D (hInstall); = \
}


@@ -63,7 +64,8 @@<= br> */

#ifdef __cplusplus<= br>-extern "C" {=
+extern "C"
+{
#endif=

/* Ensure that clang-cl, which does not= understand the cl specific
@@ -78,90 +80,84 @@
<= span> #endif



-/**
- * Determines Windows information:
- *
- *
- * - F= inds existing TAP-Windows6 adapters and set TAPWINDOWS6ADAPTERS and<= br>- * ACTIVETAPWINDOWS6ADAPTER= S properties with semicolon delimited list of all installed adapter<= br>- * GUIDs and active adapter= GUIDs respectively.
- = *
- * - Finds existing = ovpn-dco adapters and set OVPNDCOADAPTERS and ACTIVEOVPNDCOADAPTERS propert= ies
- * with semicolo= n delimited list of all installed adapter GUIDs and active adapter GUIDs
- * respectively.
- *
- * @param hInstall Handle to the installa= tion provided to the DLL custom action
- *
- *= @return ERROR_SUCCESS on success; An error code otherwise
- * See: https://msdn.microsoft= .com/en-us/library/windows/desktop/aa368072.aspx
- */
-DLLEXP_DECL UINT __stdcall
-FindSystemInfo(_In_ MSIHANDLE hInstall);
+ /**
+ * Determines Windows information:
+ *

+ * - Sets `OPENVPNSERVICE` MSI property to= PID of OpenVPN Service if running, or its EXE path if
+ * configured for auto-start.
+ *
+ * - Finds existing TAP-Windows6 = adapters and set TAPWINDOWS6ADAPTERS and
+ * ACTIVETAPWINDOWS6ADAPTERS properties with sem= icolon delimited list of all installed adapter
+ * GUIDs and active adapter GUIDs respecti= vely.
+ *<= br>+ * - Finds existing ovp= n-dco adapters and set OVPNDCOADAPTERS and ACTIVEOVPNDCOADAPTERS
= + * properties with semicol= on delimited list of all installed adapter GUIDs and active adapter<= br>+ * GUIDs respectively.<= /span>
+ *
+ * @param hInstall Handl= e to the installation provided to the DLL custom action

+ *
+ * @return ERROR_SUCCESS on success; An error co= de otherwise
+ * = See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368= 072.aspx
+ */
+ DLLEXP_DECL UINT __= stdcall FindSystemInfo(_In_ MSIHANDLE hInstall);

-/**- * Find OpenVPN GUI window and= send it a WM_CLOSE message.
- *
- * @param hI= nstall Handle to the installation provided to the DLL custom action
- *
- * @return ERROR_SUCCESS on success; An err= or code otherwise
- * = See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa3680= 72.aspx
- */
= -DLLEXP_DECL UINT __stdcall
-CloseOpenVPNGUI(_In_ MSIHAN= DLE hInstall);
+ /= **
+ * Find OpenV= PN GUI window and send it a WM_CLOSE message.
+ *
+ * @param hInstall Handle to the installation provide= d to the DLL custom action
+ *
+ *= @return ERROR_SUCCESS on success; An error code otherwise
+ * See: https://msdn.mic= rosoft.com/en-us/library/windows/desktop/aa368072.aspx
+ */
+ DLLEXP_DECL UINT __stdcall CloseOpenVPNGUI(_In_ = MSIHANDLE hInstall);


-/**
- * Launches OpenVPN GUI. It's path is obtained by expa= nding the `[#bin.openvpn_gui.exe]`
- * therefore, its Id field in File table must be "bin.ope= nvpn_gui.exe".
- *=
- * @param hInstall = Handle to the installation provided to the DLL custom action
<= span style=3D"color: hsl(0, 100%, 40%);">- *

- * @return ERROR_SUCCESS on success; An error code o= therwise
- * Se= e: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
- */
-DLLEXP_DECL UINT __stdcall
-StartOpenVPNGUI(_In_ MSIHANDLE hInst= all);

+ /**=
+ * Launches OpenVPN GU= I. It's path is obtained by expanding the `[#bin.openvpn_gui.exe]`
+ * therefore, its Id= field in File table must be "bin.openvpn_gui.exe".
+ *

+ * @param hInstall Handle to the inst= allation provided to the DLL custom action
+ *
+ * @return ERROR_SUCCESS on success; An error code otherwise<= /span>
+ * See: = https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
+ */
+ DLLEXP_DECL UINT __stdcall Start= OpenVPNGUI(_In_ MSIHANDLE hInstall);


-/**
- * Evaluate the TUNTAPAdapter table of the= MSI package database and prepare a list of TAP
- * adapters to install/remove.
- *
- * @param hInstall Handle to the installation provided= to the DLL custom action
- *
- * @return ERRO= R_SUCCESS on success; An error code otherwise
- * See: https://msdn.microsoft.com/en-us/li= brary/windows/desktop/aa368072.aspx
- */
-DLLE= XP_DECL UINT __stdcall
= -EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall);
+ /**
+ * Evaluate the TUNTAPAdapter table of the MSI packag= e database and prepare a list of TAP
+ * adapters to install/remove.
+ *
+ * @param hInstall Handle to the installation= provided to the DLL custom action
+ *
+ * @return ERROR_SUCCESS on success; An error code otherwise+ * See: https://= msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
+ */

+ DLLEXP_DECL UINT __stdcall EvaluateTUNTA= PAdapters(_In_ MSIHANDLE hInstall);


-/**
- * Perform scheduled deferred action.
- *
- * @param hInstall Handle to the installa= tion provided to the DLL custom action
- *
- *= @return ERROR_SUCCESS on success; An error code otherwise
- * See: https://msdn.microsoft= .com/en-us/library/windows/desktop/aa368072.aspx
- */
-DLLEXP_DECL UINT __stdcall
-ProcessDeferredAction(_In_ MSIHANDLE hInstall);
+ /**

+ * Perform scheduled deferred action.
+ *
+ * @param hInstall Handle t= o the installation provided to the DLL custom action
+ *
+ * @return ERROR_SUCCESS on success; An error code= otherwise
+ * = See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa36807= 2.aspx
+ */
+ DLLEXP_DECL UINT __st= dcall ProcessDeferredAction(_In_ MSIHANDLE hInstall);


-/**
- * Schedule reboot after = installation if reboot
= - * indication file is found in user's temp directory
- *
- * @param hInstall Handle to the installation provide= d to the DLL custom action
- *
- * @return ERR= OR_SUCCESS on success; An error code otherwise
- * See: https://msdn.microsoft.com/en-us/l= ibrary/windows/desktop/aa368072.aspx
- */
-DLL= EXP_DECL UINT __stdcall
-CheckAndScheduleReboot(_In_ MSIHANDLE hInstall);
+ /**
+ * Schedule reboot after installation if reboot
+ * indication file i= s found in user's temp directory
+ *
+ * @param hInstall Handle to the installation provided to the = DLL custom action
+ = *
+ * @return = ERROR_SUCCESS on success; An error code otherwise
+ * See: https://msdn.microsoft.co= m/en-us/library/windows/desktop/aa368072.aspx
+ */
+ DLLEXP_DECL UINT __stdcall CheckAndScheduleReboot(_In_ MS= IHANDLE hInstall);

#ifdef __cplusplus
}
diff --git a/src/openvpnserv/common.c b/sr= c/openvpnserv/common.c
index fe360fa..55cdbbe 100644=
--- a/src/openvpnserv/common.c
+++ b/src/openvpns= erv/common.c
@@ -30,12 +30,11 @@
static DW= ORD
GetRegString(HKEY key, LPCWSTR value, LPWSTR data, DWO= RD size, LPCWSTR default_value)
{
- LONG status =3D RegGetValue(key, NULL, val= ue, RRF_RT_REG_SZ,
- = NULL, (LPBYTE) data, &size);
+ LONG status =3D RegGetValue(key= , NULL, value, RRF_RT_REG_SZ, NULL, (LPBYTE)data, &size);


if (status =3D=3D ERROR_FILE_NOT_FOUND &&= default_value)
{
- size_t len =3D size/sizeof(data[0]);
+ size_t len =3D size / siz= eof(data[0]);

if (swprintf(data, len, default_valu= e))
{
status =3D ERRO= R_SUCCESS;
@@ -45,7 +44,10 @@
if (stat= us !=3D ERROR_SUCCESS)
{
SetL= astError(status);
- = return MsgToEventLog(M_SYSERR, L"Error querying registry value: HK= LM\\SOFTWARE\\" _L(PACKAGE_NAME) L"%ls\\%ls", service_instan= ce, value);
+ = return MsgToEventLog(
+ M_SYSERR,
+ L"Error querying registry value: HKLM\\SOFTWARE\\"= ; _L(PACKAGE_NAME) L"%ls\\%ls",
+ service_instance, value);
}


return ERROR_SUCCESS;=
@@ -69,7 +71,8 @@
if (status !=3D ERROR_SUCC= ESS)
{
SetLastError(status);<= /span>
- return MsgToEv= entLog(M_SYSERR, L"Could not open Registry key HKLM\\%ls not found&quo= t;, reg_path);
+ = return MsgToEventLog(M_SYSERR, L"Could not open Registry key HKLM\\= %ls not found",
= + reg_path);
}
<= span>

/* The default value of REG_KEY is the install = path */
@@ -80,8 +83,7 @@
goto out= ;
}

- swprintf(default_value, _countof(default_value), L= "%ls\\bin\\openvpn.exe",
- install_path);
+ swprintf(default_value, _countof(default_value), L= "%ls\\bin\\openvpn.exe", install_path);
erro= r =3D GetRegString(key, L"exe_path", s->exe_path, sizeof(s->= ;exe_path), default_value);
if (error !=3D ERROR_SUCCE= SS)
{
@@ -89,23 +91,20 @@
}


swprintf(default_value, _= countof(default_value), L"%ls\\config", install_path);
= - error =3D GetRegString(key, = L"config_dir", s->config_dir, sizeof(s->config_dir),=
- def= ault_value);
+ err= or =3D GetRegString(key, L"config_dir", s->config_dir, sizeof(= s->config_dir), default_value);
if (error !=3D ERRO= R_SUCCESS)
{
goto out;=
}

swprintf(default_va= lue, _countof(default_value), L"%ls\\bin", install_path);<= br>- error =3D GetRegString(ke= y, L"bin_dir", s->bin_dir, sizeof(s->bin_dir),
- default_v= alue);

+ error =3D= GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_di= r), default_value);
if (error !=3D ERROR_SUCCESS)
{
goto out;
= }

- = error =3D GetRegString(key, L"config_ext", s->ext_string, si= zeof(s->ext_string),
- L".ovpn");
+ error =3D GetRegString(key, L"config_e= xt", s->ext_string, sizeof(s->ext_string), L".ovpn");<= /span>
if (error !=3D ERROR_SUCCESS)
{
goto out;
@@ -118,8 +117,7 @@
goto out;
}

- error =3D GetRegString= (key, L"priority", priority, sizeof(priority),
- L"NORMAL_P= RIORITY_CLASS");
+ error =3D GetRegString(key, L"priority", priority, sizeof(p= riority), L"NORMAL_PRIORITY_CLASS");
if (err= or !=3D ERROR_SUCCESS)
{
goto= out;
@@ -132,8 +130,8 @@
}
=
/* read if present, else use default */=
- error =3D GetRegString(k= ey, L"ovpn_admin_group", s->ovpn_admin_group,
- sizeof(s->= ovpn_admin_group), OVPN_ADMIN_GROUP);
+ error =3D GetRegString(key, L"ovpn_admin_group&q= uot;, s->ovpn_admin_group, sizeof(s->ovpn_admin_group),
+ OVPN_ADM= IN_GROUP);

if (error !=3D ERROR_SUCCESS)
{

goto out;
@@ -186,7 +184= ,8 @@
else
{
= SetLastError(ERROR_INVALID_DATA);
- error =3D MsgToEventLog(M_ERR, L"Log file app= end flag (given as '%ls') must be '0' or '1'",= append);
+ er= ror =3D MsgToEventLog(M_ERR, L"Log file append flag (given as '%ls= ') must be '0' or '1'",
+ append);<= br> goto out;
}
=
@@ -205,10 +204,11 @@
LPWSTR tmp =3D NULL;

error =3D GetLastError();
<= span style=3D"color: hsl(0, 100%, 40%);">- len =3D FormatMessage(FORMAT_= MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUM= ENT_ARRAY,

+ len = =3D FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYST= EM
+ = | FORMAT_MESSAGE_ARGUMENT_ARRAY,
= NULL, error, LANG_NEUTRAL, tmp, 0, NULL);

- if (len =3D=3D 0 || (lo= ng) _countof(buf) < (long) len + 14)
+ if (len =3D=3D 0 || (long)_countof(buf) < (long)= len + 14)
{
buf[0] =3D L'= \0';
}
@@ -245,8 +245,7 @@<= br> hEventSource =3D RegisterEventSource(NULL, APPNAME); if (hEventSource !=3D NULL)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- swprintf(msg[0], _countof= (msg[0]),

- = L"%ls%ls%ls: %ls", APPNAME, service_instance,
+ swprintf(msg[0], _countof(= msg[0]), L"%ls%ls%ls: %ls", APPNAME, service_instance,

= (flags & MSG_FLAGS_ERROR) ? L" error"= : L"", err_msg);

va_s= tart(arglist, format);
@@ -254,9 +253,9 @@
= va_end(arglist);

const = WCHAR *mesg[] =3D { msg[0], msg[1] };
- ReportEvent(hEventSource, flags & MSG_FLAGS_ERR= OR ?
- = EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
- 0, 0, NULL, 2, 0, mesg,= NULL);
+ Repo= rtEvent(hEventSource,
+ flags & MSG_FLAGS_ERROR ? EVENTLOG_ERROR_TYPE : E= VENTLOG_INFORMATION_TYPE, 0, 0,
+ NULL, 2, 0, mesg, NULL);
= DeregisterEventSource(hEventSource);
}
diff --git a/src/openvpnserv/interactive.c b/src/= openvpnserv/interactive.c
index 628a96b..d7fa6fd 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/= openvpnserv/interactive.c
@@ -41,32 +41,30 @@
#include "validate.h"

#include "wfp_blo= ck.h"

-#define IO_TIMEOUT 2000 /*ms*/
+#define IO_TIMEOUT 2000 /*ms*/
<= br>-#define ERROR_OPENVPN_STARTUP= 0x20000000
-#de= fine ERROR_STARTUP_DATA 0x20000001
-#define ERROR_MESSAGE_DATA 0x20000002
-#define ERROR_MESSAGE_TYPE= 0x20000003
+#define ERROR_OPENVPN_STARTUP 0x20000000
+#define ERROR_STARTUP_DATA 0x20000001
<= span style=3D"color: hsl(120, 100%, 40%);">+#define ERROR_MESSAGE_DATA 0= x20000002

+#define ER= ROR_MESSAGE_TYPE 0x20000003

static SE= RVICE_STATUS_HANDLE service;
static SERVICE_STATUS status = =3D { .dwServiceType =3D SERVICE_WIN32_SHARE_PROCESS };
st= atic HANDLE exit_event =3D NULL;
static settings_t setting= s;
static HANDLE rdns_semaphore =3D NULL;
-#define RDNS_TIMEOUT 600 /* seconds t= o wait for the semaphore */
+#define RDNS_TIMEOUT 600 /* seconds to wait for the semaphore */

-#defin= e TUN_IOCTL_REGISTER_RINGS CTL_CODE(51820U, 0x970U, METHOD_BUFFERED, FILE_R= EAD_DATA | FILE_WRITE_DATA)
+#define TUN_IOCTL_REGISTER_RINGS \
+ CTL_CODE(51820U, 0x970U, METHOD_BUFFERED, FILE_R= EAD_DATA | FILE_WRITE_DATA)

-openvpn_service_t interactive_service =3D {<= br>- interactive,
- _L(PACKAGE_NAME) L"Servic= eInteractive",

- = _L(PACKAGE_NAME) L" Interactive Service",
- SERVICE_DEPENDENCIES,
- SERVICE_AUTO_START
-};
+openvpn_service_t interactive_service =3D { interactive= , _L(PACKAGE_NAME) L"ServiceInteractive",
+ = _L(PACKAGE_NAME) L" Interactive Service",
+ = SERVICE_DEPENDENCIES, SERVICE_AUTO_START };


-typedef struct {=
+typedef struct
+{
W= CHAR *directory;
WCHAR *options;
= WCHAR *std_input;
@@ -74,14 +72,16 @@


/* Datatype for linked lists */
<= span style=3D"color: hsl(0, 100%, 40%);">-typedef struct _list_item {
+typedef struct _list_item=
+{
= struct _list_item *next;
LPVOID data;
} list_item_t;



/*= Datatypes for undo information */
-typedef enum {
+typedef enum
= +{
address,
route,
wfp_block,

@@ -94,19 +94,22 @@
} un= do_type_t;
typedef list_item_t *undo_lists_t[_undo_type_ma= x];

-= typedef struct {
+typ= edef struct
+{=
HANDLE engine;
int index;
int metric_v4;

int metric_v6;
= } wfp_block_data_t;

-typedef struct {
+typedef struct
+{
char itf_name[256];
PW= STR domains;
} dns_domains_undo_data_t;
<= /span>
-typedef union {=
+typedef union
+{

message_h= eader_t header;
address_message_t address;
<= span> route_message_t route;

@@ -120,7 +123,8 @@=
create_adapter_message_t create_adapter;
} = pipe_message_t;

-typedef struct {
+typedef struct
+{
CHAR addresses[NRPT_ADDR_NUM * NRPT_ADDR_SIZE];<= /span>
WCHAR domains[512]; /* MULTI_SZ string */
DWORD domains_size; /* bytes in domains */

@@ -143= ,7 +147,7 @@
return NO_ERROR;
}

-typedef B= OOL (*match_fn_t) (LPVOID item, LPVOID ctx);
+typedef BOOL (*match_fn_t)(LPVOID item, LPVOID ctx= );

static LPVOID
Remove= ListItem(list_item_t **pfirst, match_fn_t match, LPVOID ctx)
@@ -202,7 +206,8 @@

}

=
-typedef enum {
+typedef enum
+{

peek,
read,
write
@@ -249,= 8 +254,7 @@
handles[i + 1] =3D events[i]; }

- res =3D WaitForMultipleObjects(count + 1, handles, FALSE,
- = op =3D=3D peek ? INFINITE : IO_TIMEOUT);
+ res =3D WaitForMultipleObjects(count + 1,= handles, FALSE, op =3D=3D peek ? INFINITE : IO_TIMEOUT);
= if (res !=3D WAIT_OBJECT_0)
{
= CancelIo(pipe);
@@ -310,32 +314,25 @@
= {
DWORD result_len;
LPWSTR resul= t =3D L"0xffffffff\nFormatMessage failed\nCould not return result"= ;;
- DWORD_PTR args[= ] =3D {
- (DWORD= _PTR) error,
- (= DWORD_PTR) func,
- = (DWORD_PTR) ""
- };
+ DWO= RD_PTR args[] =3D { (DWORD_PTR)error, (DWORD_PTR)func, (DWORD_PTR) "&q= uot; };

if (error !=3D ERROR_OPENVPN= _STARTUP)
{
- FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
- |FORMAT_MESSA= GE_ALLOCATE_BUFFER

- = |FORMAT_MESSAGE_IGNORE_INSERTS,
- 0, error, 0, (LPWSTR= ) &args[2], 0, NULL);
+ FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_AL= LOCATE_BUFFER
+ = | FORMAT_MESSAGE_IGNORE_INSERTS,
+ 0, error, 0, (LPWS= TR)&args[2], 0, NULL);
}
<= br>- result_len =3D FormatMess= ageW(FORMAT_MESSAGE_FROM_STRING
- |FORMAT_MESSAGE_ALLOCATE_BUFFER
- = |FORMAT_MESSAGE_ARGUMENT_ARRAY,
- L"0x%1!08x!\n%2!s!\= n%3!s!", 0, 0,
- = (LPWSTR) &result, 0, (va_list *) args);
+ result_len =3D Fo= rmatMessageW(
+ = FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESS= AGE_ARGUMENT_ARRAY,
+= L"0x%1!08x!\n%2!s!\n%3!s!", 0, 0, (LPWSTR)&result, 0,= (va_list *)args);

WritePipeAsync(pi= pe, result, (DWORD)(wcslen(result) * 2), count, events);
= MsgToEventLog(MSG_FLAGS_ERROR, result);

if (error !=3D ERROR_OPENVPN_STARTUP)

{<= br>- LocalFree((LPVOID) ar= gs[2]);
+ Loca= lFree((LPVOID)args[2]);
}
if (res= ult_len)
{
@@ -356,7 +353,8 @@<= br> * Returns true on success, false on error with reason set in err= msg.
*/
static BOOL
-ValidateOptions(HANDLE pipe, const WCHAR *= workdir, const WCHAR *options, WCHAR *errmsg, DWORD capacity)
+ValidateOptions(HANDLE pipe, cons= t WCHAR *workdir, const WCHAR *options, WCHAR *errmsg,

+ DWORD capacity) {
WCHAR **argv;
int argc= ;
@@ -381,7 +379,7 @@
}

/* Note: argv[0] is the first option */
= - if (argc < 1) /* no opti= ons */
+ if (argc = < 1) /* no options */
{
re= t =3D TRUE;
goto out;
@@ -396,8 +3= 94,7 @@

if (!CheckOption(workdir= , 2, argv_tmp, &settings))
{
- swprintf(errmsg, capacity, = msg1, argv[0], workdir,
- settings.ovpn_admin_group);
+ swprintf(errmsg, capacity, msg1,= argv[0], workdir, settings.ovpn_admin_group);
}
goto out;
}
@@= -409,17 +406,15 @@
continue;
= }

- if (!CheckOption(workdir, argc-i, &argv[i], &setting= s))
+ if (!Che= ckOption(workdir, argc - i, &argv[i], &settings))
= {
- = if (wcscmp(L"--config", argv[i]) =3D=3D 0 && argc-i > = 1)
+ if (w= cscmp(L"--config", argv[i]) =3D=3D 0 && argc - i > 1)<= /span>
{
- swprintf(errmsg, capacity, msg1, argv[i+1], workdi= r,
- = settings.ovpn_admin_group);
+ swprintf(errmsg, capacity, msg1, argv[i + 1],= workdir, settings.ovpn_admin_group);
}=
else
{
- swprintf(errmsg, capac= ity, msg2, argv[i],
- = settings.ovpn_admin_group);
+ swprintf(errmsg, capacity, m= sg2, argv[i], settings.ovpn_admin_group);
}
goto out;
}
<= span>@@ -506,7 +501,7 @@

return TRUE;
=
err:
- sud->directory =3D NULL; /* caller must not free() */=
+ sud->directo= ry =3D NULL; /* caller must not free() */
free(data);<= /span>
return FALSE;
}
@@ -5= 81,7 +576,7 @@

InitializeUnicastIpAd= dressEntry(addr_row);
addr_row->Address =3D sockadd= r_inet(msg->family, &msg->address);
- addr_row->OnLinkPrefixLength =3D (UINT8) msg= ->prefix_len;
+ = addr_row->OnLinkPrefixLength =3D (UINT8)msg->prefix_len;
<= span>

if (msg->iface.index !=3D -1)
{

@@ -663,7 +658,7 @@
fwd_row-&= gt;Protocol =3D MIB_IPPROTO_NETMGMT;
fwd_row->Metri= c =3D msg->metric;
fwd_row->DestinationPrefix.Pr= efix =3D sockaddr_inet(msg->family, &msg->prefix);
- fwd_row->DestinationPrefix.Pr= efixLength =3D (UINT8) msg->prefix_len;

+ fwd_row->DestinationPrefix.PrefixLength =3D (= UINT8)msg->prefix_len;
fwd_row->NextHop =3D sock= addr_inet(msg->family, &msg->gateway);
if (msg->iface.index !=3D -1)
@@ -741,7 +73= 6,7 @@
err_str =3D L"Unknown Win32 Error";

if (FormatMessage(FORMAT_MESSAGE_IGNO= RE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM
- | FORMAT_MESSAGE_ARGUMENT_ARRAY,
+ = | FORMAT_MESSAGE_ARGUMENT_ARRAY,
= NULL, err, 0, buf, sizeof(buf), NULL))
{
err_str =3D buf;

@@ -768,13 +763,11 @@<= br> err =3D delete_wfp_block_filters(block_data->engine);<= /span>
if (block_data->metric_v4 >=3D 0)
= {
- = set_interface_metric(msg->iface.index, AF_INET,
- block_= data->metric_v4);
= + set_interface_metric(msg->iface.index, AF_INET, block_data-= >metric_v4);
}
if (blo= ck_data->metric_v6 >=3D 0)
{
- set_interface_metric(msg-= >iface.index, AF_INET6,

- block_data->metric_v6);
= + set_interface_metr= ic(msg->iface.index, AF_INET6, block_data->metric_v6);
}

free(block_data);
= }
@@ -810,14 +803,12 @@
block_da= ta->engine =3D engine;
block_data->index =3D= msg->iface.index;
int is_auto =3D 0;- block_data->metric_v= 4 =3D get_interface_metric(msg->iface.index,
- = AF_INET, &is_auto);
+ block_data->metric_v4 =3D get_interface_metric(msg->i= face.index, AF_INET, &is_auto);
if (is_auto)
{
block_data->metri= c_v4 =3D 0;
}
- block_data->metric_v6 =3D get_interface_metric(= msg->iface.index,
- = AF_INET6, &is_auto)= ;
+ block_data= ->metric_v6 =3D get_interface_metric(msg->iface.index, AF_INET6, &= ;is_auto);
if (is_auto)
{=
block_data->metric_v6 =3D 0;
@@ -826,8 +817,7 @@

err =3D AddListItem(&(*= lists)[wfp_block], block_data);
if (!err) {
- = err =3D set_interface_metric(msg->iface.index, AF_INET,<= br>- = WFP_BLOCK_IFACE_METRIC);
+ err =3D set_interface_metric(msg->iface.index= , AF_INET, WFP_BLOCK_IFACE_METRIC);
if (!err)<= /span>
{
/* for IPv6= , we intentionally ignore errors, because
@@ -835,8 +825,7 = @@
* admin has disabled IPv6 on the tun/t= ap/dco interface
* (if OpenVPN wants IPv6= ifconfig, we'll fail there)
*/
- set_interfa= ce_metric(msg->iface.index, AF_INET6,
- WFP_BLOCK_IFACE_MET= RIC);
+ = set_interface_metric(msg->iface.index, AF_INET6, WFP_BLOCK_IFACE_METRI= C);
}
if (err)
{
@@ -881,7 +870,7 @@
= DWORD exit_code;
STARTUPINFOW si; PROCESS_INFORMATION pi;
- DWORD proc_flags =3D CREATE_NO_WINDOW|CREATE_UNICODE_ENVI= RONMENT;
+ DWORD p= roc_flags =3D CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT;
WCHAR *cmdline_dup =3D NULL;


= ZeroMemory(&si, sizeof(si));
@@ -891,8 +880,8 @@=

/* CreateProcess needs a modifiable cmdlin= e: make a copy */
cmdline_dup =3D _wcsdup(cmdline);
- if (cmdline_dup &= ;& CreateProcessW(argv0, cmdline_dup, NULL, NULL, FALSE,
- = proc_flags, NULL, NULL, &si, &pi) )

+ if (cmdline_dup
+ && CreateProcessW(argv0, cmdline_= dup, NULL, NULL, FALSE, proc_flags, NULL, NULL, &si, &pi)) {
WaitForSingleObject(pi.hProcess, ti= meout ? timeout : INFINITE);
if (!GetExitCodeProce= ss(pi.hProcess, &exit_code))
@@ -906,13 +895,12 @@

/* kill without impunity */
TerminateProcess(pi.hProcess, exit_code);- MsgToEventLog(M_ER= R, L"ExecCommand: \"%ls %ls\" killed after timeout",
- = argv0, cmdline);
+ = MsgToEventLog(M_ERR, L"ExecCommand: \"%ls %ls\" k= illed after timeout", argv0, cmdline);
}
else if (exit_code)
{<= br>- MsgToEventLog(M_E= RR, L"ExecCommand: \"%ls %ls\" exited with status =3D %lu&qu= ot;,
- = argv0, cmdline, exit_code);
+ MsgToEventLog(M_ERR, L"ExecCommand: \&quo= t;%ls %ls\" exited with status =3D %lu", argv0,
+ cmdline, ex= it_code);
}
else {
@@ -925,8 +913,7 @@
= else
{
exit_code =3D GetLast= Error();
- MsgTo= EventLog(M_SYSERR, L"ExecCommand: could not run \"%ls %ls\" = :",
- = argv0, cmdline);
+ MsgToEventLog(M_SYSERR, L"ExecCommand: could not run \&q= uot;%ls %ls\" :", argv0, cmdline);
}<= br>
free(cmdline_dup);
@@ -951,= 12 +938,12 @@
WCHAR *argv0;
= WCHAR *cmdline;
DWORD timeout;
- } cmds [] =3D {
- { ipcfg, L"ipconfig /flushd= ns", timeout },
+ } cmds[] =3D {
- HANDLE wait_handles[2] =3D {rdns_semaphore, exit_event};=
+ HANDLE wait_han= dles[2] =3D { rdns_semaphore, exit_event };

swprintf(ipcfg, MAX_PATH, L"%ls\\%ls", get_win_sys_path()= , L"ipconfig.exe");


@@ -968,9 += 955,10 @@
ExecCommand(cmds[i].argv0, cmds[i].c= mdline, cmds[i].timeout);
}
= err =3D 0;
- = if (!ReleaseSemaphore(rdns_semaphore, 1, NULL) )
+ if (!ReleaseSemaphore(rdns_semaphore, = 1, NULL))
{
- err =3D MsgToEventLog(M_SYSERR, L"RegisterD= NS: Failed to release regsiter-dns semaphore:");
+ err =3D
+ MsgToEventLog(M_SYSERR, L= "RegisterDNS: Failed to release regsiter-dns semaphore:");=
}
}
else
@@ -1047,7 +1035,7 @@

/* = max cmdline length in wchars -- include room for worst case and some */
size_t ncmdline =3D wcslen(fmt) + wcslen(if_name) + wcsle= n(action) + wcslen(addr)
+ + wcslen(addr_sta= tic) + 32 + 1;
cmdline =3D malloc(ncmdline * sizeof(wc= har_t));
if (!cmdline)
{@@ -1079,13 +1067,8 @@
static BOOL
ApplyGpolSettings32(void)

{
- typedef NTSTATUS (__stdcall *publish_fn_t)(
- DWORD StateNameL= o,
- DWORD State= NameHi,
- DWORD = TypeId,
- DWORD = Buffer,
- DWORD = Length,
- DWORD = ExplicitScope);
+ = typedef NTSTATUS(__stdcall * publish_fn_t)(DWORD StateNameLo, DWORD StateNa= meHi, DWORD TypeId,
+= DWORD Buffer, DWORD Length, = DWORD ExplicitScope);
publish_fn_t RtlPublishWnfStateD= ata;
const DWORD WNF_GPOL_SYSTEM_CHANGES_HI =3D 0x0D89= 1E2A;
const DWORD WNF_GPOL_SYSTEM_CHANGES_LO =3D 0xA3B= C0875;
@@ -1096,13 +1079,14 @@
ret= urn FALSE;
}

- RtlPublishWnfStateData =3D (publish_fn_= t) GetProcAddress(ntdll, "RtlPublishWnfStateData");
+ RtlPublishWnfStateData =3D (p= ublish_fn_t)GetProcAddress(ntdll, "RtlPublishWnfStateData");
if (RtlPublishWnfStateData =3D=3D NULL)
= {
return FALSE;
}
- if (RtlP= ublishWnfStateData(WNF_GPOL_SYSTEM_CHANGES_LO, WNF_GPOL_SYSTEM_CHANGES_HI, = 0, 0, 0, 0) !=3D ERROR_SUCCESS)
+ if (RtlPublishWnfStateData(WNF_GPOL_SYSTEM_CHANGES_LO, WNF_= GPOL_SYSTEM_CHANGES_HI, 0, 0, 0, 0)
+ !=3D ERROR_SUCCESS)
{ return FALSE;
}
@@ -1= 119,12 +1103,8 @@
static BOOL
ApplyGpolSe= ttings64(void)
{
- typedef NTSTATUS (*publish_fn_t)(
- INT64 StateName,
- INT64 TypeId,
- INT64 Buffer,
- unsigned int Length,
- INT64 ExplicitScope);
=
+ typedef NTSTATUS (*pub= lish_fn_t)(INT64 StateName, INT64 TypeId, INT64 Buffer,
+ un= signed int Length, INT64 ExplicitScope);
publish_fn_t = RtlPublishWnfStateData;
const INT64 WNF_GPOL_SYSTEM_CH= ANGES =3D 0x0D891E2AA3BC0875;

@@ -1134,7 = +1114,7 @@
return FALSE;
}

- Rt= lPublishWnfStateData =3D (publish_fn_t) GetProcAddress(ntdll, "RtlPubl= ishWnfStateData");
+ RtlPublishWnfStateData =3D (publish_fn_t)GetProcAddress(ntdll, &quo= t;RtlPublishWnfStateData");
if (RtlPublishWnfStat= eData =3D=3D NULL)
{
return F= ALSE;
@@ -1184,24 +1164,21 @@
scm =3D = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (= scm =3D=3D NULL)
{
- MsgToEventLog(M_ERR, L"%S: OpenSCManager cal= l failed (%lu)",
-= __func__, GetLastError());
+ MsgToEventLog(M_ERR, L"%S: OpenSC= Manager call failed (%lu)", __func__, GetLastError());
goto out;

}

dnssvc =3D OpenServiceA(scm, "Dnscache", SERVICE_PAUSE_CON= TINUE);

if (dnssvc =3D=3D NULL)
{=
- MsgToEventLog= (M_ERR, L"%S: OpenService call failed (%lu)",
- __func__, GetLastEr= ror());
+ MsgT= oEventLog(M_ERR, L"%S: OpenService call failed (%lu)", __func__, = GetLastError());
goto out;
}<= /span>

SERVICE_STATUS status;
if (ControlService(dnssvc, SERVICE_CONTROL_PARAMCHANGE, &status= ) =3D=3D 0)

{
- MsgToEventLog(M_ERR, L"%S: ControlService call fa= iled (%lu)",
- = __func__, GetLastError());
+ MsgToEventLog(M_ERR, L"%S: ControlSer= vice call failed (%lu)", __func__, GetLastError());
= goto out;
}

@= @ -1329,8 +1306,7 @@
*gpol =3D FALSE;
=
/* Try the group policy search list */
- err =3D RegOpenKeyExA(HKEY_LOCA= L_MACHINE,

- = "SOFTWARE\\Policies\\Microsoft\\Windows NT\\DNSClient&quo= t;,
+ err =3D RegO= penKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Microsoft\\Windows = NT\\DNSClient",
0, KEY_ALL_AC= CESS, key);
if (!err)
{@@ -1343,9 +1319,9 @@
}

/* Try the system-wide search list */
- err =3D RegOpenKeyExA(HKEY_LOCAL_MACHIN= E,
- = "System\\CurrentControlSet\\Services\\TCPIP\\Parameters",
- = 0, KEY_ALL_ACCESS, key);
+ err =3D
+ = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Ser= vices\\TCPIP\\Parameters",
+ 0, KEY_ALL_ACCESS, key);
= if (!err)
{
if (HasValid= SearchList(*key))
@@ -1363,9 +1339,10 @@
= if (!iid_err)
{
= HKEY itfs;
- = err =3D RegOpenKeyExA(HKEY_LOCAL_MACHINE,
- "System\\Curren= tControlSet\\Services\\TCPIP\\Parameters\\Interfaces",
- 0, KE= Y_ALL_ACCESS, &itfs);

+ err =3D
+ RegOpenKeyExA(HKEY_LOCAL_MACHINE,
+ "Sys= tem\\CurrentControlSet\\Services\\TCPIP\\Parameters\\Interfaces",
+ = 0, KEY_ALL_ACCESS, &itfs);
if (!err)=
{
err =3D Re= gOpenKeyExW(itfs, iid, 0, KEY_ALL_ACCESS, key);
@@ -1401,8 = +1378,7 @@
{
return F= ALSE;
}
- MsgToEventLog(M_ERR, L"%S: failed to get InitialSea= rchList (%lu)",
- = __func__, err);
+ MsgToEventLog(M_ERR, L"%S: failed to get Init= ialSearchList (%lu)", __func__, err);
}
return TRUE;
@@ -1437,8 +1413= ,7 @@
LSTATUS err =3D RegSetValueExW(key, L"Initi= alSearchList", 0, REG_SZ, (PBYTE)list, size);
if = (err)
{
- MsgToEventLog(M_ERR, L"%S: failed to set InitialSearchL= ist value (%lu)",
= - __func__, err);
+ MsgToEventLog(M_ERR, L"%S: failed to set In= itialSearchList value (%lu)", __func__, err);
= return FALSE;
}

@@ = -1458,7 +1433,7 @@
AddDnsSearchDomains(HKEY key, BOOL have= _list, PCWSTR domains)
{
LSTATUS err;=
- WCHAR list[2048] = =3D {0};
+ WCHAR l= ist[2048] =3D { 0 };
DWORD size =3D sizeof(list);

if (have_list)
@@ -1466,= 8 +1441,8 @@
err =3D RegGetValueW(key, NULL, L&quo= t;SearchList", RRF_RT_REG_SZ, NULL, list, &size);
= if (err)
{
- MsgToEventLog(M_SYSERR, L"%S: could= not get SearchList from registry (%lu)",
- __func__, err);+ MsgToEventLog(M_= SYSERR, L"%S: could not get SearchList from registry (%lu)", __fu= nc__,
+ = err);
return FALSE;
}


@@ -1499,8 +1474,7 @@=
err =3D RegSetValueExW(key, L"SearchList", 0, REG_= SZ, (PBYTE)list, size);
if (err)
= {
- MsgToEventLo= g(M_SYSERR, L"%S: could not set SearchList to registry (%lu)",
- __= func__, err);
+ = MsgToEventLog(M_SYSERR, L"%S: could not set SearchList to registry (= %lu)", __func__, err);
return FALSE; }

@@ -1541,8 +1515,7 @@
err =3D RegSetValueExW(key, L"SearchList", 0, RE= G_SZ, (PBYTE)list, size);
if (err)
= {
- MsgToEvent= Log(M_SYSERR, L"%S: could not set SearchList in registry (%lu)",<= /span>
- = __func__, err);
+ = MsgToEventLog(M_SYSERR, L"%S: could not set SearchList in registry= (%lu)", __func__, err);
goto out;
= }

@@ -1569,8 +1542,7 @@=
err =3D RegGetValueW(key, NULL, L"SearchList", RRF= _RT_REG_SZ, NULL, list, &size);
if (err) {
- = MsgToEventLog(M_SYSERR, L"%S: could not get SearchList from registry (= %lu)",
- = __func__, err);
+ MsgToEventLog(M_SYSERR, L"%S: could not get SearchList= from registry (%lu)", __func__, err);
return= ;
}

@@ -1614,8 +1586= ,7 @@
err =3D RegSetValueExW(key, L"SearchList&qu= ot;, 0, REG_SZ, (PBYTE)list, size);
if (err) {
- = MsgToEventLog(M_SYSERR, L"%S: could not set SearchList in registry (%l= u)",
- = __func__, err);
+ MsgToEventLog(M_SYSERR, L"%S: could not set SearchList i= n registry (%lu)", __func__, err);
}
}


@@ -1733,8 +1704,8 @@
GetInterfacesKey(short family, PHKEY key)

{ PCSTR itfs_key =3D family =3D=3D AF_INET6
- ? "SYSTEM\\CurrentControlSet\\= Services\\Tcpip6\\Parameters\\Interfaces"
- : "SYSTEM\\CurrentControlSet\\Service= s\\Tcpip\\Parameters\\Interfaces";
+ ? "SYSTEM\\CurrentControl= Set\\Services\\Tcpip6\\Parameters\\Interfaces"
+ : "SYSTEM\\= CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces";
LSTATUS err =3D RegOpenKeyExA(HKEY_LOCAL_MACH= INE, itfs_key, 0, KEY_ALL_ACCESS, key);
if (err)
@@ -1843,11 +1814,12 @@
return ERROR_ME= SSAGE_DATA;
}

- /* use a non-const reference with limit= ed scope to enforce null-termination of strings from client */
+ /* use a non-const reference= with limited scope to enforce null-termination of strings from

<= span style=3D"color: hsl(120, 100%, 40%);">+ * client */

{

- dns_c= fg_message_t *msgptr =3D (dns_cfg_message_t *) msg;
- msgptr->iface.name[_countof(msg-= >iface.name)-1] =3D '\0';
- msgptr->domains[_countof(msg->domains)-1] =3D = '\0';
+ = dns_cfg_message_t *msgptr =3D (dns_cfg_message_t *)msg;
+ msgptr->iface.name[_counto= f(msg->iface.name) - 1] =3D '\0';
+ msgptr->domains[_countof(msg->domain= s) - 1] =3D '\0';
}
WCHAR iid[64];
@@ -1879,7 +1851,7 @@ err =3D SetDnsSearchDomains(msg->iface.name, NULL, &= amp;gpol, lists);
}
Apply= DnsSettings(gpol);
- = return err; /* job done */
+ return err; /* job done */
}

if (msg->addr_len > 0)
<= span>@@ -2101,8 +2073,7 @@

s--;
= }

- if (inet_ntop(AF_INET6, &in_addrs[i],
- = pos, s) !=3D NULL)
+ = if (inet_ntop(AF_INET6, &in_addrs[i], pos, s) !=3D NULL)
{
*size =3D 0;
return ERROR_MORE_DATA;
@@ = -2189,7 +2160,7 @@
LSTATUS err =3D ERROR_FILE_NOT_FOUN= D;
const DWORD buf_size =3D *size;
= const size_t one_glyph =3D sizeof(*domains);
- PWSTR values[] =3D { L"SearchList", = L"Domain", L"DhcpDomainSearchList", L"DhcpDomain&q= uot;, NULL};
+ PWS= TR values[] =3D { L"SearchList", L"Domain", L"Dhcp= DomainSearchList", L"DhcpDomain", NULL };
<= /span>
for (int i =3D 0; values[i]; i++)
= {
@@ -2285,7 +2256,8 @@
/* Get GUID f= rom string */
if (IIDFromString(iid_str, &iid) != =3D S_OK)
{
- MsgToEventLog(M_SYSERR, L"%S: could not convert int= erface %s GUID string", __func__, iid_str);
+ MsgToEventLog(M_SYSERR, L"%S: cou= ld not convert interface %s GUID string", __func__,
+ iid_str);=
goto out;
}

@@ -2327,8 +2299,7 @@
HKEY v4_itfs =3D INVA= LID_HANDLE_VALUE;
HKEY v6_itfs =3D INVALID_HANDLE_VALU= E;

- = if (!GetInterfacesKey(AF_INET, &v4_itfs)
- || !GetInterfacesKey(AF_INET6, &v6_it= fs))
+ if (!GetInt= erfacesKey(AF_INET, &v4_itfs) || !GetInterfacesKey(AF_INET6, &v6_it= fs))
{
goto out;
}

@@ -2339,8 +2310,8 @@
{
WCHAR itf_guid[MAX_PATH];
DW= ORD itf_guid_len =3D _countof(itf_guid);
- LSTATUS err =3D RegEnumKeyExW(v4_itfs, enum_inde= x++, itf_guid, &itf_guid_len,
- NULL, NULL, NULL, NULL);
+ LSTATUS err = =3D
+ RegE= numKeyExW(v4_itfs, enum_index++, itf_guid, &itf_guid_len, NULL, NULL, N= ULL, NULL);
if (err)
{
if (err !=3D ERROR_NO_MORE_ITEMS)
@@ -2359,7 +2330,8 @@

HKEY v4_itf;
if (RegOpenKeyExW(v4_itfs, itf_guid, 0, KEY_READ, &v4_itf) = !=3D NO_ERROR)

{
- MsgToEventLog(M_SYSERR, L"%S: could no= t open interface %s v4 registry key", __func__, itf_guid);
<= span style=3D"color: hsl(120, 100%, 40%);">+ MsgToEventLog(M_SYS= ERR, L"%S: could not open interface %s v4 registry key", __func__= ,

+ = itf_guid);
goto out;
= }

@@ -2371,7 +2343,8 @@ {
if (err !=3D ERROR_FILE_NOT_= FOUND)
{
- MsgToEventLog(M_SYSERR, L"%S: could no= t read interface %s domain suffix", __func__, itf_guid);
+ MsgToEventLog(M_S= YSERR, L"%S: could not read interface %s domain suffix", __func__= ,

+ = itf_guid);
}
= goto next_itf;
}
@@ -2394,= 7 +2367,8 @@
HKEY v6_itf;
= if (RegOpenKeyExW(v6_itfs, itf_guid, 0, KEY_READ, &v6_itf) != =3D NO_ERROR)
{
- MsgToEventLog(M_SYSERR, L"%S: c= ould not open interface %s v6 registry key", __func__, itf_guid);
+ MsgToEve= ntLog(M_SYSERR, L"%S: could not open interface %s v6 registry key"= ;,
+ = __func__, itf_guid);
goto nex= t_itf;
}
err =3D = GetItfDnsServersV6(v6_itf, v6_addrs, &v6_addrs_size);
@= @ -2442,8 +2416,8 @@
* @return NO_ERROR on success, or Wi= ndows error code
*/
static DWORD<= br>-SetNrptRule(HKEY nrpt_key, PC= WSTR subkey, PCSTR address,
- PCWSTR domains, DWORD dom_size, BOOL dnssec)
+SetNrptRule(HKEY nrpt_key, PCWST= R subkey, PCSTR address, PCWSTR domains, DWORD dom_size,

+ BOOL dnssec)
{

/* Create rule subkey */
DW= ORD err =3D NO_ERROR;
@@ -2462,7 +2436,8 @@
}


/* Set DNS Server address */=
- err =3D RegSetVal= ueExA(rule_key, "GenericDNSServers", 0, REG_SZ, (PBYTE)address, s= trlen(address) + 1);
= + err =3D RegSetValueExA(rule_key, "GenericDNSServers", 0, REG= _SZ, (PBYTE)address,
= + strlen(address) + 1);
if (er= r)
{
goto out;
@@ -2473,21 +2448,24 @@

if (dnssec)
= {
reg_val =3D 1;
- err =3D RegSetValueExA(rule_key, "DNS= SECValidationRequired", 0, REG_DWORD, (PBYTE)&reg_val, sizeof(reg_= val));
+ err = =3D RegSetValueExA(rule_key, "DNSSECValidationRequired", 0, REG_D= WORD, (PBYTE)&reg_val,
+ sizeof(reg_val));
= if (err)
{
goto o= ut;
}

r= eg_val =3D 0;
- = err =3D RegSetValueExA(rule_key, "DNSSECQueryIPSECRequired", 0, R= EG_DWORD, (PBYTE)&reg_val, sizeof(reg_val));
+ err =3D RegSetValueExA(rule_key, "= ;DNSSECQueryIPSECRequired", 0, REG_DWORD, (PBYTE)&reg_val,<= br>+ = sizeof(reg_val));
if (err)
= {
goto out;
}

reg_val =3D 0;
- err =3D RegSetValueExA(rule_key, &= quot;DNSSECQueryIPSECEncryption", 0, REG_DWORD, (PBYTE)&reg_val, s= izeof(reg_val));
+ = err =3D RegSetValueExA(rule_key, "DNSSECQueryIPSECEncryption"= ;, 0, REG_DWORD, (PBYTE)&reg_val,
+ sizeof(reg_val));
= if (err)
{
= goto out;
@@ -2496,7 +2474,8 @@

/* Set NRPT config options */
reg_val= =3D dnssec ? 0x0000000A : 0x00000008;
- err =3D RegSetValueExA(rule_key, "ConfigOptions&q= uot;, 0, REG_DWORD, (const PBYTE)&reg_val, sizeof(reg_val));
= + err =3D RegSetValueExA(rul= e_key, "ConfigOptions", 0, REG_DWORD, (const PBYTE)&reg_val,<= /span>
+ = sizeof(reg_val));
if (err)
{=
goto out;
@@ -2654,7 +2633,8 @@
* remains in the registry even if the last GP-NRPT rul= e is deleted.
*/
static PCSTR gp= ol_key =3D "SOFTWARE\\Policies\\Microsoft\\Windows NT\\DNSClient\\DnsP= olicyConfig";
- = static PCSTR sys_key =3D "SYSTEM\\CurrentControlSet\\Services\\Dnscac= he\\Parameters\\DnsPolicyConfig";
+ static PCSTR sys_key =3D
+ "SYSTEM\\CurrentControlSet\\Servic= es\\Dnscache\\Parameters\\DnsPolicyConfig";
HKEY nrpt;
*gpol =3D TRUE;
@@ -2662,7 +2642,8 @@

if (err =3D=3D ERROR_FILE_NOT_= FOUND)
{
*gpol =3D FALSE;
- err =3D RegCreate= KeyExA(HKEY_LOCAL_MACHINE, sys_key, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &= nrpt, NULL);
+ = err =3D RegCreateKeyExA(HKEY_LOCAL_MACHINE, sys_key, 0, NULL, 0, KEY_ALL_A= CCESS, NULL, &nrpt,
+ NULL);
if (err)<= /span>
{
nrpt =3D INVALID_HA= NDLE_VALUE;
@@ -2764,15 +2745,14 @@
* @re= turn NO_ERROR on success, or a Windows error code
*/
static DWORD
-HandleDNSConfigNrptMessage(const nrpt_dns_cfg_message_t *msg,- DWOR= D ovpn_pid, undo_lists_t *lists)
+HandleDNSConfigNrptMessage(const nrpt_dns_cfg_message_t *msg, = DWORD ovpn_pid, undo_lists_t *lists)
{
= /*
* Use a non-const reference with limited scope t= o
* enforce null-termination of strings from client
*/
{
- nrpt_dns_cfg_message_t *msgptr =3D (nrpt_d= ns_cfg_message_t *) msg;
+ nrpt_dns_cfg_message_t *msgptr =3D (nrpt_dns_cfg_message_t *)m= sg;
msgptr->iface.name[_countof(msg->iface.n= ame) - 1] =3D '\0';
msgptr->search_doma= ins[_countof(msg->search_domains) - 1] =3D '\0';
msgptr->resolve_domains[_countof(msg->resolve_domains) - 1]= =3D '\0';

@@ -2865,7 +2845,8 @@
<= /span>
/* Set NRPT rules */
BOOL dnssec = =3D (msg->flags & nrpt_dnssec) !=3D 0;
- err =3D SetNrptRules(key, msg->addresses, ms= g->resolve_domains, msg->search_domains, dnssec, ovpn_pid);+ err =3D SetNrptRules(key,= msg->addresses, msg->resolve_domains, msg->search_domains, dnssec= ,
+ = ovpn_pid);
if (err)
{=
goto out;
@@ -2908,7 +2889,8 @@ return ERROR_MESSAGE_DATA;
}
- /* use a= non-const reference with limited scope to enforce null-termination of stri= ngs from client */
+ = /* use a non-const reference with limited scope to enforce null-terminat= ion of strings from
+= * client */
{
wins_cfg_m= essage_t *msgptr =3D (wins_cfg_message_t *)msg;
ms= gptr->iface.name[_countof(msg->iface.name) - 1] =3D '\0';
@@ -2935,7 +2917,7 @@

i= f (msg->header.type =3D=3D msg_del_wins_cfg)
{
- goto out; /* job = done */
+ goto= out; /* job done */
}

for (int i =3D 0; i < addr_len; ++i)

@@ -2989,7 = +2971,7 @@
* 10 chars for 32 bit int in decimal and += 1 for NUL
*/
size_t ncmdline =3D= wcslen(fmt) + 10 + 1;
= - wchar_t *cmdline =3D malloc(ncmdline*sizeof(wchar_t));
+ wchar_t *cmdline =3D malloc(ncm= dline * sizeof(wchar_t));

if (!cmdline)
{

err =3D ERROR_OUTOFMEMORY;
@@ -3074,16 +3056,12 @@

}

static VOID

-Handl= eMessage(HANDLE pipe, PPROCESS_INFORMATION proc_info,
- DWORD bytes, DWORD count, LPH= ANDLE events, undo_lists_t *lists)
+HandleMessage(HANDLE pipe, PPROCESS_INFORMATION proc_info, D= WORD bytes, DWORD count,
+ LPHANDLE events, undo_lists_t *lists)
{=
pipe_message_t msg;
ack_message_= t ack =3D {
- .h= eader =3D {
- = .type =3D msg_acknowledgement,
- .size =3D sizeof(ack),
- .message_id =3D -1
- },
+ .header =3D { .type =3D msg_acknowledgement= , .size =3D sizeof(ack), .message_id =3D -1 },
.er= ror_number =3D ERROR_MESSAGE_DATA
};
=
@@ -3265,27 +3243,24 @@
STARTUPINFOW = startup_info;
PROCESS_INFORMATION proc_info; LPVOID user_env =3D NULL;
- WCHAR ovpn_pipe_name[256]; /* The entire pipe name stri= ng can be up to 256 characters long according to MSDN. */
+ WCHAR ovpn_pipe_name[256]; /* The= entire pipe name string can be up to 256 characters long
+ acc= ording to MSDN. */
LPCWSTR exe_path;
= WCHAR *cmdline =3D NULL;
size_t cmdline_size;
undo_lists_t undo_lists;
WCHAR errmsg= [512] =3D L"";

- SECURITY_ATTRIBUTES inheritable =3D {
- .nLength =3D sizeof(inheri= table),

- .lpSec= urityDescriptor =3D NULL,
- .bInheritHandle =3D TRUE
- };
+ SECURITY_ATTRIBUTES inheritable =3D { .nLength =3D sizeof(inheritable= ),
+ = .lpSecurityDescriptor =3D NULL,
+ = .bInheritHandle =3D TRUE };

PACL ovp= n_dacl;
EXPLICIT_ACCESS ea[2];
SE= CURITY_DESCRIPTOR ovpn_sd;
- SECURITY_ATTRIBUTES ovpn_sa =3D {
- .nLength =3D sizeof(ovpn_sa),
- .lpSecurityDescriptor =3D &= ;ovpn_sd,
- .bIn= heritHandle =3D FALSE
-= };
+ SECURITY_= ATTRIBUTES ovpn_sa =3D { .nLength =3D sizeof(ovpn_sa),
+ .lpS= ecurityDescriptor =3D &ovpn_sd,
+ .bInheritHandle =3D FAL= SE };

ZeroMemory(&ea, sizeof(ea)= );
ZeroMemory(&startup_info, sizeof(startup_info))= ;
@@ -3371,7 +3346,8 @@
* OR user is = authorized to run any config.
*/
= if (!ValidateOptions(pipe, sud.directory, sud.options, errmsg, _countof(er= rmsg))
- &&a= mp; !IsAuthorizedUser(ovpn_user->User.Sid, imp_token, settings.ovpn_admi= n_group, settings.ovpn_service_user))
+ && !IsAuthorizedUser(ovpn_user->User.S= id, imp_token, settings.ovpn_admin_group,
+ settings.ovpn_service_us= er))
{
ReturnError(pipe, ERRO= R_STARTUP_DATA, errmsg, 1, &exit_event);
goto = out;
@@ -3383,14 +3359,14 @@
ea[0].grf= Inheritance =3D NO_INHERITANCE;
ea[0].Trustee.TrusteeF= orm =3D TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType =3D = TRUSTEE_IS_UNKNOWN;
- = ea[0].Trustee.ptstrName =3D (LPWSTR) svc_user->User.Sid;
- ea[1].grfAccessPermissions =3D = READ_CONTROL | SYNCHRONIZE | PROCESS_VM_READ

- |SYNCHRONIZE | PROC= ESS_TERMINATE | PROCESS_QUERY_INFORMATION;
+ ea[0].Trustee.ptstrName =3D (LPWSTR)svc_user->= ;User.Sid;
+ ea[1]= .grfAccessPermissions =3D READ_CONTROL | SYNCHRONIZE | PROCESS_VM_READ | SY= NCHRONIZE
+ = | PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION;
ea[1].grfAccessMode =3D SET_ACCESS;
= ea[1].grfInheritance =3D NO_INHERITANCE;
ea[1].Trustee= .TrusteeForm =3D TRUSTEE_IS_SID;
ea[1].Trustee.Trustee= Type =3D TRUSTEE_IS_UNKNOWN;
- ea[1].Trustee.ptstrName =3D (LPWSTR) ovpn_user->User.Sid;
+ ea[1].Trustee.ptstr= Name =3D (LPWSTR)ovpn_user->User.Sid;

= /* Set owner and DACL of OpenVPN security descriptor */
if (!SetSecurityDescriptorOwner(&ovpn_sd, svc_user->User.Sid,= FALSE))

@@ -3417,8 +3393,8 @@
}

/* use /dev/null for stdout of openvpn (c= lient should use --log for output) */
- stdout_write =3D CreateFile(_L("NUL"), GENERI= C_WRITE, FILE_SHARE_WRITE,
- &inheritable, OPEN_EXISTING, 0, NULL= );
+ stdout_write = =3D CreateFile(_L("NUL"), GENERIC_WRITE, FILE_SHARE_WRITE, &i= nheritable,
+ = OPEN_EXISTING, 0, NULL);
if (std= out_write =3D=3D INVALID_HANDLE_VALUE)
{
ReturnLastError(pipe, L"CreateFile for stdout");
@@ -3433,18 +3409,19 @@
}
=
swprintf(ovpn_pipe_name, _countof(ovpn_pipe_name),
- L"\\\= \.\\pipe\\" _L(PACKAGE) L"%ls\\service_%lu", service_instanc= e, GetCurrentThreadId());
- ovpn_pipe =3D CreateNamedPipe(ovpn_pipe_name,
- PIPE_ACCESS= _DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_OVERLAPPED,
<= span style=3D"color: hsl(0, 100%, 40%);">- P= IPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 1, 128, 128, 0, NULL)= ;

+ L&quo= t;\\\\.\\pipe\\" _L(PACKAGE) L"%ls\\service_%lu", service_in= stance,
+ = GetCurrentThreadId());
+ ovpn_pipe =3D CreateNamedPipe(
+ ovpn_pipe_name, PIPE_ACCESS_DUPLEX | FILE_FLAG_F= IRST_PIPE_INSTANCE | FILE_FLAG_OVERLAPPED,
+ PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | = PIPE_WAIT, 1, 128, 128, 0, NULL);
if (ovpn_pipe =3D=3D= INVALID_HANDLE_VALUE)
{
Retu= rnLastError(pipe, L"CreateNamedPipe");
g= oto out;
}

- svc_pipe =3D CreateFile(ovpn_pipe_name, GEN= ERIC_READ | GENERIC_WRITE, 0,
- &inheritable, OPEN_EXISTING, 0, NULL)= ;
+ svc_pipe =3D C= reateFile(ovpn_pipe_name, GENERIC_READ | GENERIC_WRITE, 0, &inheritable= ,
+ = OPEN_EXISTING, 0, NULL);
if (svc_pipe =3D=3D I= NVALID_HANDLE_VALUE)
{
Return= LastError(pipe, L"CreateFile");
@@ -3468,8 +3445,= 8 @@
/* there seem to be no common printf specifier th= at works on all
* mingw/msvc platforms without tricke= ry, so convert to void* and use
* PRIuPTR to print th= at as best compromise */
- = sud.options, (uintptr_t)svc_pipe);
+ swprintf(cmdline, cmdline_size, L"openvpn %ls = --msg-channel %" PRIuPTR, sud.options,
+ (uintptr_t)svc_pipe);
=
if (!CreateEnvironmentBlock(&user_env, imp_token= , FALSE))
{
@@ -3528,7 +3505,10 @@

if (bytes > sizeof(pipe_message_t))
{

/* process at the other side of t= he pipe is misbehaving, shut it down */
- MsgToEventLog(MSG_FLAGS_ERROR, L"OpenVPN= process sent too large payload length to the pipe (%lu bytes), it will be = terminated", bytes);
+ MsgToEventLog(
+ MSG_FLAGS_ERROR,
+ L"OpenVPN process sent too l= arge payload length to the pipe (%lu bytes), it will be terminated",
+ bytes= );
break;
}
@@ -3544,8 +3524,7 @@
else if= (exit_code !=3D 0)
{
WCHAR b= uf[256];
- swpri= ntf(buf, _countof(buf),
- L"OpenVPN exited with error: exit code =3D %lu"= ;, exit_code);
+ = swprintf(buf, _countof(buf), L"OpenVPN exited with error: exit code= =3D %lu", exit_code);
ReturnError(pipe, ERRO= R_OPENVPN_STARTUP, buf, 1, &exit_event);
}<= br> Undo(&undo_lists);
@@ -3608,17 +3587,19 @= @
* allow read/write for authenticated users * deny all access to anonymous
*/
- const WCHAR *sddlString= =3D L"D:(A;OICI;GA;;;S-1-5-18)(D;OICI;0x4;;;S-1-1-0)(A;OICI;GRGW;;;S-= 1-5-11)(D;;GA;;;S-1-5-7)";
+ const WCHAR *sddlString =3D
+ L"D:(A;OICI;GA;;;S-1-5-18)(D;OICI;0x4;= ;;S-1-1-0)(A;OICI;GRGW;;;S-1-5-11)(D;;GA;;;S-1-5-7)";
=
PSECURITY_DESCRIPTOR sd =3D NULL;
- if (!ConvertStringSecurityDescriptor= ToSecurityDescriptor(sddlString, SDDL_REVISION_1, &sd, NULL))+ if (!ConvertStringSecurit= yDescriptorToSecurityDescriptor(sddlString, SDDL_REVISION_1, &sd,
+ = NULL))
{ MsgToEventLog(M_SYSERR, L"ConvertStringSecurityDescrip= torToSecurityDescriptor failed.");
return INV= ALID_HANDLE_VALUE;
}

/* Set up SECURITY_ATTRIBUTES */

- SECURITY_ATTRIBUTES sa =3D {0};
+ SECURITY_ATTRIBUTES sa =3D { 0 };
sa.nLength =3D sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor =3D sd;

sa.bInheritHan= dle =3D FALSE;
@@ -3632,11 +3613,13 @@
= first =3D FALSE;
}

- WCHAR pipe_name[256]; /* The e= ntire pipe name string can be up to 256 characters long according to MSDN. = */

- swprintf(pipe_n= ame, _countof(pipe_name), L"\\\\.\\pipe\\" _L(PACKAGE) L"%ls= \\service", service_instance);
- HANDLE pipe =3D CreateNamedPipe(pipe_name, flags,<= br>- = PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS= ,
- = PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, &sa);
= + WCHAR pipe_name[256]; /* T= he entire pipe name string can be up to 256 characters long according
+ = to MSDN. */
+ = swprintf(pipe_name, _countof(pipe_name), L"\\\\.\\pipe\\" _L(PACK= AGE) L"%ls\\service",
+ service_instance);
+ HANDLE pipe =3D CreateNamedPipe(
+ pipe_name, flags, PIPE_TYP= E_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS,

<= span style=3D"color: hsl(120, 100%, 40%);">+ PIPE_UNLIMITED_INSTANCE= S, 1024, 1024, 0, &sa);


LocalFre= e(sd);

@@ -3651,8 +3634,8 @@


static DWORD
-UpdateWaitHandles(LPHANDLE *handles_ptr, LP= DWORD count,
- = HANDLE io_event, HANDLE exit_event, list_item_t *threads)+UpdateWaitHandles(LPHANDLE *= handles_ptr, LPDWORD count, HANDLE io_event, HANDLE exit_event,
<= span style=3D"color: hsl(120, 100%, 40%);">+ list_item_t *= threads)

{
static DWORD size =3D 10;<= /span>
static LPHANDLE handles =3D NULL;
@@ -= 3763,7 +3746,8 @@
PHANDLE handles =3D NULL;
= DWORD handle_count;

- service =3D RegisterServiceCtrlHandlerEx(int= eractive_service.name, ServiceCtrlInteractive, &status);
+ service =3D

+ RegisterServiceCtrlHandlerEx(i= nteractive_service.name, ServiceCtrlInteractive, &status);
if (!service)

{
retu= rn;
@@ -3818,8 +3802,7 @@

while (TRUE)

{
- if (ConnectNamedPipe(pipe, &overlapped) =3D= =3D FALSE
- = && GetLastError() !=3D ERROR_PIPE_CONNECTED
+ if (ConnectNamedPipe(pipe, &o= verlapped) =3D=3D FALSE && GetLastError() !=3D ERROR_PIPE_CONNECTED=
&& GetLastError() !=3D ERROR_IO_PENDI= NG)
{
MsgToEventLog(M= _SYSERR, L"Could not connect pipe");
@@ -3837,11 = +3820,13 @@
error =3D AddListItem(&thr= eads, thread);
if (!error)
{

- = error =3D UpdateWaitHandles(&handles, &handle_cou= nt, io_event, exit_event, threads);
+ error =3D
+ UpdateWaitHandles(&ha= ndles, &handle_count, io_event, exit_event, threads);
= }
if (error)
{

-= ReturnError(pipe, error, L"Insufficient resources = to service new clients", 1, &exit_event);
+ ReturnError(pipe, error,= L"Insufficient resources to service new clients", 1,
<= span style=3D"color: hsl(120, 100%, 40%);">+ = &exit_event);

/* Update wait hand= les again after removing the last worker thread */
= RemoveListItem(&threads, CmpHandle, thread);
UpdateWaitHandles(&handles, &handle_count, = io_event, exit_event, threads);

diff --git a/src/openvpnser= v/service.c b/src/openvpnserv/service.c
index a76dce7..04b2= 0d7 100644
--- a/src/openvpnserv/service.c
= +++ b/src/openvpnserv/service.c
@@ -33,8 +33,7 @@ status->dwControlsAccepted =3D SERVICE_ACCEPT_STOP;
}

- if (status->dwCurrentState =3D=3D SERVICE_RUNNING
- || status->dwC= urrentState =3D=3D SERVICE_STOPPED)
+ if (status->dwCurrentState =3D=3D SERVICE_RUNNING ||= status->dwCurrentState =3D=3D SERVICE_STOPPED)
{
status->dwCheckPoint =3D 0;
= }
@@ -79,16 +78,10 @@

= for (i =3D 0; i < _service_max; i++)
{- service =3D CreateServi= ce(svc_ctl_mgr,
- = openvpn_service[i].name,
- openvpn_servic= e[i].display_name,
- = SERVICE_QUERY_STATUS,
- SERVICE_WIN32_= SHARE_PROCESS,
- = openvpn_service[i].start_type,
- SERVICE_E= RROR_NORMAL,
- = path, NULL, NULL,
- openvpn_service[i].depen= dencies,
- = NULL, NULL);
+ service =3D CreateService(
+ svc_ctl_mgr, openvpn_service[i].name= , openvpn_service[i].display_name,
+ SERVICE_QUERY_STATUS, SERVICE_WIN32_SHARE_PROCES= S, openvpn_service[i].start_type,
+ SERVICE_ERROR_NORMAL, path, NULL, NULL, openvpn_s= ervice[i].dependencies, NULL, NULL);
if (service)<= /span>
{
wprintf(L"%ls = installed.\n", openvpn_service[i].display_name);
@@ -1= 63,8 +156,8 @@
for (i =3D 0; i < _service_max; i++)=
{
openvpn_service_t *ovpn_sv= c =3D &openvpn_service[i];
- service =3D OpenService(svc_ctl_mgr, ovpn_svc->name,
- = DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
+ service =3D
+ OpenService(svc_ctl_mgr, ovpn= _svc->name, DELETE | SERVICE_STOP | SERVICE_QUERY_STATUS);
if (service =3D=3D NULL)

{
<= span> wprintf(L"OpenService failed - %ls\n", GetLastE= rrorText());

@@ -228,15 +221,12 @@
* = This is the default.
*/
const SE= RVICE_TABLE_ENTRY dispatchTable_shared[] =3D {
- { interactive_service.name, ServiceStartIn= teractive },
- {= NULL, NULL }
+ = { interactive_service.name, ServiceStartInteractive }, { NULL, NULL }
};

/* Interactive = service only (as a SERVICE_WIN32_OWN_PROCESS) */
- const SERVICE_TABLE_ENTRY dispatchTable_inte= ractive[] =3D {
- = { L"", ServiceStartInteractiveOwn },
- { NULL, NULL }
- };
+ const SERVICE_TABLE_ENTRY dispatchTable_interactive[] = =3D { { L"", ServiceStartInteractiveOwn },
+ = { NULL, NULL } };

= const SERVICE_TABLE_ENTRY *dispatchTable =3D dispatchTable_shared;

@@ -260,7 +250,7 @@
= }
else if (argc > i + 2 && _wcsi= cmp(L"instance", argv[i] + 1) =3D=3D 0)
= {
- = if (_wcsicmp(L"interactive", argv[i+1]) =3D=3D 0)
+ if (_wcsicmp(L"= ;interactive", argv[i + 1]) =3D=3D 0)

= {
dispatchTable =3D dispatchTable_int= eractive;
service_instance =3D argv[i = + 2];
@@ -268,22 +258,28 @@
= }
else
= {
- = MsgToEventLog(M_ERR, L"Invalid argument to -instance <%s>. Servi= ce not started.", argv[i+1]);
+ MsgToEventLog(M_ERR,
+ L&quo= t;Invalid argument to -instance <%s>. Service not started.",
+ = argv[i + 1]);
return 1;
}
}
else

{
= wprintf(L"%ls -install to install the interactive se= rvice\n", APPNAME);
+ wprintf(
+ L&= quot;%ls -start [name] to start the service (name =3D \"interactive\= ") is optional\n",
+ APPNAME);
wpr= intf(L"%ls -remove to remove the service\n", APPNAME);

wprintf(L"\nService r= un-time parameters:\n");
wprintf(L&qu= ot;-instance interactive <id>\n"
= L" Runs the service as an alternate instance.\n"
L" The service settings will be= loaded from\n"
- = L" HKLM\\Software\\" _L(PACKAGE_NAME) L&= quot;<id> registry key, and the service will accept\n"- L"= requests on \\\\.\\pipe\\" _L(PACKAGE) L"<id>\\service n= amed pipe.\n");
= + L" HKLM\\Software\\" _L(
+ PACKA= GE_NAME) L"<id> registry key, and the service will accept\n"= ;

+ = L" requests on \\\\.\\pipe\\" _L(
+ = PACKAGE) L"<id>\\service named pipe.\n"= ;);

return 0;
= }
diff --git a/src/openvpnserv/service.h= b/src/openvpnserv/service.h
index bfbe466..4539262 100644<= /span>
--- a/src/openvpnserv/service.h
+++ b/src/o= penvpnserv/service.h
@@ -34,24 +34,26 @@
#= include <wchar.h>
#include "../tapctl/basic.h&q= uot;

= -#define APPNAME _L(PACKAGE) L"serv"
-#define SERVICE_DEPENDENCIES _L(TAP_WIN_COMPONEN= T_ID) L"\0Dhcp\0\0"
+#define APPNAME _L(PACKAGE) L"serv"=
+#define SERVICE_DEPENDENCI= ES _L(TAP_WIN_COMPONENT_ID) L"\0Dhcp\0\0"

/*
* Message handling
*/
-#define MSG_FLAGS_ERROR = (1<<0)
-#defi= ne MSG_FLAGS_SYS_CODE (1<<1)
-#define M_INFO (0) /* inf= ormational */
-#define = M_SYSERR (MSG_FLAGS_ERROR|MSG_FLAGS_SYS_CODE) /* error + system code */
-#define M_ERR (MSG_F= LAGS_ERROR) /* error */
+#define MSG_FLAGS_ERROR (1 << 0)
= +#define MSG_FLAGS_SYS_CODE (1 = << 1)
+#define = M_INFO (0) /* informational = */
+#define M_SYSERR = (MSG_FLAGS_ERROR | MSG_FLAGS_SYS_CODE) /* error + system code */<= /span>
+#define M_ERR = (MSG_FLAGS_ERROR) /* error */
=
-typedef enum {=
+typedef enum
+{

interactiv= e,
_service_max
} openvpn_service_typ= e;

-t= ypedef struct {
+type= def struct
+{<= br> openvpn_service_type type;
WCHAR *name;<= /span>
WCHAR *display_name;
@@ -60,7 +62,8 @@=
} openvpn_service_t;

#= define MAX_NAME 256
-ty= pedef struct {
+typed= ef struct
+{ WCHAR exe_path[MAX_PATH];
WCHAR config_di= r[MAX_PATH];
WCHAR bin_dir[MAX_PATH];
= diff --git a/src/openvpnserv/validate.c b/src/openvpnserv/validate.c=
index 9231417..1547949 100644
--- a/src/openvpnse= rv/validate.c
+++ b/src/openvpnserv/validate.c
@@ -27,8 +27,7 @@

#include <shlwapi.h> #include <lm.h>

-static const WCHAR *white_list[] =3D
-{

+static const WCHAR *white_list[] =3D {
L"auth-retry",

L"config",<= /span>
L"log",
@@ -47,7 +46,7 @@
L"pull-filter",
L"sc= ript-security",

- NULL /* last value */
+ NULL /* last valu= e */
};

static BOOL IsU= serInGroup(PSID sid, const PTOKEN_GROUPS groups, const WCHAR *group_name);<= /span>
@@ -66,7 +65,7 @@
const WCHAR *config_= dir =3D NULL;

/* convert fname to fu= ll path */
- if (Pat= hIsRelativeW(fname) )
+ if (PathIsRelativeW(fname))
{
= swprintf(tmp, _countof(tmp), L"%ls\\%ls", workdir, fname);=
config_file =3D tmp;
@@ -129,7 +1= 28,7 @@
return FALSE;
}

- b =3D= CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, admin_sid, &sid= _size);
+ b =3D Cr= eateWellKnownSid(WinBuiltinAdministratorsSid, NULL, admin_sid, &sid_siz= e);
if (b)
{
= b =3D LookupAccountSidW(NULL, admin_sid, name, &nlen, domain, &= ;dlen, &snu);
@@ -141,7 +140,8 @@
}

BOOL
-IsAuthorizedUser(PSID sid, const HANDLE token, const WCHAR = *ovpn_admin_group, const WCHAR *ovpn_service_user)
+IsAuthorizedUser(PSID sid, const HANDLE toke= n, const WCHAR *ovpn_admin_group,
+ const WCHAR *ovpn_service_user)
{

const WCHAR *admin_group[2];
= WCHAR username[MAX_NAME];
@@ -172,7 +172,8 @@
= }
else
{
- MsgToEventLog(M_SYSERR, L&q= uot;Failed to get the name of Administrators group. Using the default."= ;);

+ MsgToEve= ntLog(M_SYSERR,
+ = L"Failed to get the name of Administrators group. Us= ing the default.");
/* use the default value = */
admin_group[0] =3D SYSTEM_ADMIN_GROUP; }
@@ -184,7 +185,8 @@
= ret =3D IsUserInGroup(sid, token_groups, admin_group[i]);
= if (ret)
{
- MsgToEventLog(M_INFO, L"Authorizing= user '%ls@%ls' by virtue of membership in group '%ls'"= ;,
+ MsgTo= EventLog(M_INFO,
+ = L"Authorizing user '%ls@%ls' by virtue = of membership in group '%ls'",
= username, domain, admin_group[i]);
= goto out;
}
@@ -266,11 +268,11 @@=
int nloop =3D 0; /* a counter used to not get stuck i= n the do .. while() */

/* first chec= k in the token groups */
+ = if (token_groups && LookupSID(group_name, (PSID)grp_sid, _countof= (grp_sid)))
{
for (DWORD i = =3D 0; i < token_groups->GroupCount; ++i)
{<= /span>
- if (EqualS= id((PSID) grp_sid, token_groups->Groups[i].Sid))
+ if (EqualSid((PSID)grp_sid, t= oken_groups->Groups[i].Sid))
{
return TRUE;

}
= @@ -286,8 +288,8 @@
{
D= WORD nread, nmax;
LOCALGROUP_MEMBERS_INFO_0 *membe= rs =3D NULL;
- e= rr =3D NetLocalGroupGetMembers(NULL, group_name, 0, (LPBYTE *) &members= ,
- = MAX_PREFERRED_LENGTH, &nread, &nmax, &resume)= ;
+ err =3D Ne= tLocalGroupGetMembers(NULL, group_name, 0, (LPBYTE *)&members, MAX_PREF= ERRED_LENGTH,
+ = &nread, &nmax, &resume);=
if ((err !=3D NERR_Success && err !=3D ERROR_MOR= E_DATA))
{
break;
@@ -320,16 +322,13 @@
{
= /* Do not modify argv or *argv -- ideally it should be const WCHAR *const *= , but alas...*/

- if (wcscmp(argv[0], L"--config") =3D=3D 0<= br>- && argc > = 1
- && != CheckConfigPath(workdir, argv[1], s)
- )
+ if (wcscmp(argv[0], L"--config") =3D=3D 0 && arg= c > 1 && !CheckConfigPath(workdir, argv[1], s))
= {
return FALSE;
}=

/* option name starts at 2 characters from= argv[i] */
- if (Op= tionLookup(argv[0] + 2, white_list) =3D=3D -1) /* not found */
= + if (OptionLookup(argv[0] += 2, white_list) =3D=3D -1) /* not found */
{ return FALSE;
}
diff -= -git a/src/openvpnserv/validate.h b/src/openvpnserv/validate.h
index 3ef577b..4c55356 100644

--- a/src/openvpnserv/val= idate.h
+++ b/src/openvpnserv/validate.h
@@= -29,19 +29,20 @@

/* Authorized groups w= ho can use any options and config locations */
#define SYS= TEM_ADMIN_GROUP L"Administrators"
-#define OVPN_ADMIN_GROUP L"OpenVPN Administrator= s" /* may be set in HKLM\Software\OpenVPN\ovpn_admin_group */-#define OVPN_SERVICE_USER L&qu= ot;OpenVPNService" /* may be set in HKLM\Software\OpenVPN\ovpn_service= _user */
+#define OVP= N_ADMIN_GROUP \
+ = L"OpenVPN Administrators" /* may be set in HKLM\Software\OpenVPN\= ovpn_admin_group */
+= #define OVPN_SERVICE_USER \
+ L"OpenVPNService" /* may be set in HKLM\Softw= are\OpenVPN\ovpn_service_user */

/*
* Check whether user is a member of Administrators group or
* the group specified in ovpn_admin_group or
* OpenVPN Virtual Service Account user

*/
= -BOOL
-IsAuthorizedUser(PSID sid, const HANDLE token, co= nst WCHAR *ovpn_admin_group, const WCHAR *ovpn_service_user);
+BOOL IsAuthorizedUser(PSID sid, c= onst HANDLE token, const WCHAR *ovpn_admin_group,

+ const WCHAR *ovpn_servi= ce_user);

-BOOL
-CheckOption= (const WCHAR *workdir, int narg, WCHAR *argv[], const settings_t *s);
+BOOL CheckOption(const WC= HAR *workdir, int narg, WCHAR *argv[], const settings_t *s);

static inline BOOL
IsOption(const WCH= AR *o)
diff --git a/src/plugins/auth-pam/auth-pam.c b/src/p= lugins/auth-pam/auth-pam.c
index 8692806..c1092a0 100644
--- a/src/plugins/auth-pam/auth-pam.c
+++ b/s= rc/plugins/auth-pam/auth-pam.c
@@ -100,12 +100,14 @@=

#define N_NAME_VALUE 16

-struct name_value {=
+struct name_value+{
const= char *name;
const char *value;
};

-struct= name_value_list {
+s= truct name_value_list
+{
int len;
struct name_value da= ta[N_NAME_VALUE];
};
@@ -114,7 +116,8 @@
* Used to pass the username/password
* t= o the PAM conversation function.
*/
-struct user_pass {
+struct user_pass
+{
int verb;

char username[128];
@@ -127,7 +130= ,8 @@
};

/* Background = process function */
-st= atic void pam_server(int fd, const char *service, int verb, const struct na= me_value_list *name_value_list);
+static void pam_server(int fd, const char *service, int verb,<= /span>
+ = const struct name_value_list *name_value_list);
=

/*
@@ -153,11 +157,11 @@
static int
send_control(int fd, int code)
{
- uns= igned char c =3D (unsigned char) code;
+ unsigned char c =3D (unsigned char)code;
<= span> const ssize_t size =3D write(fd, &c, sizeof(c));

if (size =3D=3D sizeof(c))

{
- return (int) size;
<= span style=3D"color: hsl(120, 100%, 40%);">+ return (int)size;
}
else
{@@ -173,7 +177,7 @@
ssize_t size; memset(buffer, 0, len);
size =3D = read(fd, buffer, len);
= - buffer[len-1] =3D 0;
+ buffer[len - 1] =3D 0;
if (size = >=3D 1)
{
return (= int)size;
@@ -189,7 +193,7 @@
const ss= ize_t size =3D write(fd, string, len);
if (size =3D=3D= len)
{
- return (int) size;
+ return (int)size;
}
else

{
@@ -222,7 +226,7 @@
#endif
if (daemon(0, 0) < 0)
{
- plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "daemonization f= ailed");
+ = plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "daemonization failed&= quot;);
}
#if defined(__APPLE__) = && defined(__clang__)
#pragma clang diagnostic pop=
@@ -323,11 +327,11 @@
}
*resp++ =3D '\0';


- int n =3D plugin_base64_decode(pass, up= ->password, sizeof(up->password)-1);
+ int n =3D plugin_base64_decode(pass, up->pass= word, sizeof(up->password) - 1);
if (n >=3D 0)
{
up->password[n] =3D '= \0';
- n =3D= plugin_base64_decode(resp, up->response, sizeof(up->response)-1);
+ n =3D plugin_b= ase64_decode(resp, up->response, sizeof(up->response) - 1); if (n >=3D 0)
{
up->response[n] =3D '\0';

@@ -355,= 8 +359,7 @@
}

OPENVPN_E= XPORT int
-openvpn_plug= in_open_v3(const int v3structver,
- struct openvpn_plugin_args_open_in const= *args,
+openvpn_plug= in_open_v3(const int v3structver, struct openvpn_plugin_args_open_in const = *args,
struct openvpn_plugin_args_o= pen_return *ret)
{
pid_t pid;<= br>@@ -373,14 +376,15 @@
/* Check API compatibil= ity -- struct version 5 or higher needed */
if (v3stru= ctver < 5)
{
- fprintf(stderr, "AUTH-PAM: This plugin is incom= patible with the running version of OpenVPN\n");
+ fprintf(stderr,
+ "AUTH-PAM: This = plugin is incompatible with the running version of OpenVPN\n");=
return OPENVPN_PLUGIN_FUNC_ERROR;
}=

/*
* Allocate= our context
*/
- context =3D (struct auth_pam_context *) calloc(1, sizeo= f(struct auth_pam_context));
+ context =3D (struct auth_pam_context *)calloc(1, sizeof(struct= auth_pam_context));
if (!context)
= {
goto error;
@@ -428,7 +432,7 @= @
{
const int base = =3D base_parms + i * 2;
name_value_list.data[i= ].name =3D argv[base];
= - name_value_list.data[i].value =3D argv[base+1];
+ name_value_list.data[i= ].value =3D argv[base + 1];

}
= }

@@ -449,7 +453,7 @@
= */
if (socketpair(PF_UNIX, SOCK_DGRAM, 0, fd) =3D= =3D -1)
{
- plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "socketpair c= all failed");
+ = plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "socketpair call fail= ed");
goto error;
}

@@ -475,7 +479,8 @@
= /* don't let future subprocesses inherit child socket */
if (fcntl(fd[0], F_SETFD, FD_CLOEXEC) < 0)

= {
- p= lugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "Set FD_CLOEXEC flag on socket = file descriptor failed");
+ plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE,
= + "S= et FD_CLOEXEC flag on socket file descriptor failed");
}


/* wait for backgrou= nd child process to initialize */
@@ -483,8 +488,8 @@
if (status =3D=3D RESPONSE_INIT_SUCCEEDED)
{

context->foreground_fd =3D f= d[0];
- ret-= >handle =3D (openvpn_plugin_handle_t *) context;
- plugin_log( PLOG_NOTE, MODULE, = "initialization succeeded (fg)" );
+ ret->handle =3D (openvpn_plugin_han= dle_t *)context;
+ = plugin_log(PLOG_NOTE, MODULE, "initialization succeeded (fg)&= quot;);
return OPENVPN_PLUGIN_FUNC_SUCCESS;
}
}
@@ -520,9 += 525,10 @@
}

OPENVPN_EXP= ORT int
-openvpn_plugin= _func_v1(openvpn_plugin_handle_t handle, const int type, const char *argv[]= , const char *envp[])
+openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, co= nst char *argv[],
+ = const char *envp[])
{
- struct auth_pam_context *context = =3D (struct auth_pam_context *) handle;

+ struct auth_pam_context *context =3D (struct auth_p= am_context *)handle;

if (type =3D=3D= OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY && context->foreground_fd = >=3D 0)
{
@@ -551,8 +557,7 @@
{
if (DEBUG(context->ve= rb))
{
- plugin_log(PLOG_NOTE, MODULE, "do deferr= ed auth '%s'",
- auth_control_file);
+ plugin_log(PLOG_NOTE, MOD= ULE, "do deferred auth '%s'", auth_control_file);<= br> }
}
= else
@@ -569,7 +574,8 @@
= || send_string(context->foreground_fd, auth_control_file) =3D=3D -1
|| send_string(context->foreground_fd, remo= te) =3D=3D -1)
{
- plugin_log(PLOG_ERR|PLOG_ERRNO, MOD= ULE, "Error sending auth info to background process");
= + plugin_log(PLO= G_ERR | PLOG_ERRNO, MODULE,
+ "Error sending auth info to backgro= und process");
}
= else
{
@@ -588,7 +594,8 @= @
}
if (s= tatus =3D=3D -1)
{
- plugin_log(PLOG_ERR|PLO= G_ERRNO, MODULE, "Error receiving auth confirmation from background pr= ocess");
+ = plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE,
+ "Er= ror receiving auth confirmation from background process");
<= span> }

}
= }
@@ -599,7 +606,7 @@
OPENVPN_EXPORT = void
openvpn_plugin_close_v1(openvpn_plugin_handle_t handl= e)
{
-= struct auth_pam_context *context =3D (struct auth_pam_context *) handle= ;
+ struct auth_pa= m_context *context =3D (struct auth_pam_context *)handle;
=
if (DEBUG(context->verb))
{
@@ -611,7 +618,7 @@
/* tell backgro= und process to exit */
if (send_control(context-&g= t;foreground_fd, COMMAND_EXIT) =3D=3D -1)
{=
- plugin_log(PLOG_= ERR|PLOG_ERRNO, MODULE, "Error signaling background process to exit&qu= ot;);
+ pl= ugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "Error signaling background pr= ocess to exit");
}
/* wait for background process to exit */
= @@ -630,7 +637,7 @@
OPENVPN_EXPORT void
o= penvpn_plugin_abort_v1(openvpn_plugin_handle_t handle)
{
- struct auth_pam_con= text *context =3D (struct auth_pam_context *) handle;
+ struct auth_pam_context *context =3D = (struct auth_pam_context *)handle;

/= * tell background process to exit */
if (context &= & context->foreground_fd >=3D 0)
@@ -645,10 +652,= 10 @@
* PAM conversation function
*/
static int
-my_conv(int n, const struct pam_message **msg_array,
- struct pam_response **response_a= rray, void *appdata_ptr)
+my_conv(int n, const struct pam_message **msg_array, struct pam_respon= se **response_array,
= + void *appdata_ptr)
{
- const struct user_pass *up =3D ( const struct = user_pass *) appdata_ptr;
+ const struct user_pass *up =3D (const struct user_pass *)appdata_= ptr;
struct pam_response *aresp;
= int i;
int ret =3D PAM_SUCCESS;
@@ -67= 3,10 +680,8 @@

if (DEBUG(up->= verb))
{
- plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: my_= conv[%d] query=3D'%s' style=3D%d",
- i,
- msg->msg ? msg-&g= t;msg : "NULL",
- msg->msg_style);
+ plugin_log(PLOG_NOTE, MODULE, "= BACKGROUND: my_conv[%d] query=3D'%s' style=3D%d", i,+ msg-&g= t;msg ? msg->msg : "NULL", msg->msg_style);
}


if (up->name_valu= e_list && up->name_value_list->len > 0)
@@= -698,10 +703,10 @@

= if (DEBUG(up->verb))
{
- plugin_log= (PLOG_NOTE, MODULE, "BACKGROUND: name match found, query/match-string = ['%s', '%s'] =3D '%s'",

- msg->= msg,
- = match_name,
- match_value);
+ plugin_log(
+ = PLOG_NOTE, MODULE,
+ "BACKGROUND: name match found, query/= match-string ['%s', '%s'] =3D '%s'",+ m= sg->msg, match_name, match_value);
= }

if (strstr(match_v= alue, "USERNAME"))
@@ -714,7 +719,8 @@
= }
else if (= strstr(match_value, "COMMONNAME"))
= {
- = aresp[i].resp =3D searchandreplace(match_value, "COMMONNAME= ", up->common_name);
+ aresp[i].resp =3D
+ searchandreplace= (match_value, "COMMONNAME", up->common_name);
= }
else if (strstr= (match_value, "OTP"))
{
@@ -825,8 +831,7 @@
if (!ret) {
plugin_log(PLOG_ERR, MODULE= , "BACKGROUND: user '%s' failed to authenticate: %s",
- up= ->username,
- = pam_strerror(pamh, status));
+ up->username, pam_strerr= or(pamh, status));
}

<= span> /* Close PAM */

@@ -847,12 +852,12 @@<= br> */

static void
-do_deferred_pam_auth(int fd, const c= har *ac_file_name,

- = const char *service, const struct user_pass *up)+do_deferred_pam_auth(int fd,= const char *ac_file_name, const char *service,
+ const struct user_pass *up= )
{
if (send_control(fd, RESPONSE_DEF= ER) =3D=3D -1)
{
- plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKG= ROUND: write error on response socket [4]");
+ plugin_log(PLOG_ERR | PLOG_ERRNO, MOD= ULE, "BACKGROUND: write error on response socket [4]"); return;
}

= @@ -861,52 +866,50 @@

if (p1 &= lt; 0)
{
- plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: f= ork(1) failed");
+ plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "BACKGROUND: fork(= 1) failed");
return;
}
- if (p1 !=3D 0) = /* parent */
+ if (p1 !=3D 0) /* parent */
{
waitpid(p1, NULL, 0);
- return; /* parent= 9;s job succeeded */
= + return; /* parent's job succeeded */
}

/* child */
- close(fd); /* s= ocketpair no longer needed */
+ close(fd); /* socketpair no longer needed */
=
pid_t p2 =3D fork();
if (p2 <= ; 0)
{
- plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: for= k(2) failed");
+= plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "BACKGROUND: fork(2)= failed");
exit(1);
}

- if= (p2 !=3D 0) /* new parent: exit right away */
+ if (p2 !=3D 0) /*= new parent: exit right away */
{
= exit(0);
}

= /* grandchild */
- = plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: deferred auth for '%s&#= 39;, pid=3D%d",
- = up->username, (int) getpid() );
+ plugin_log(PLOG_NOTE, MODULE, "BACKGR= OUND: deferred auth for '%s', pid=3D%d", up->username,
+ (int)getp= id());

/* the rest is very simple: d= o PAM, write status byte to file, done */
- int ac_fd =3D open( ac_file_name, O_WRONLY );
+ int ac_fd =3D open(ac= _file_name, O_WRONLY);
if (ac_fd < 0)
{

- plug= in_log(PLOG_ERR|PLOG_ERRNO, MODULE, "cannot open '%s' for writ= ing",
- = ac_file_name );
+ plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "cannot open = 9;%s' for writing", ac_file_name);
exit(1= );
}
int pam_success =3D pam_auth= (service, up);

- if (write( ac_fd, pam_success ? "1" : "0"= ;, 1 ) !=3D 1)
+ i= f (write(ac_fd, pam_success ? "1" : "0", 1) !=3D 1)
{
- = plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "cannot write to '%s= '",
- = ac_file_name );
+ plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE, "cannot write = to '%s'", ac_file_name);
}
close(ac_fd);

- = plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: %s: deferred auth: PAM %= s",
- = up->username, pam_success ? "succeeded" : "rejected&quo= t; );
+ plugin_log= (PLOG_NOTE, MODULE, "BACKGROUND: %s: deferred auth: PAM %s", up-&= gt;username,
+ = pam_success ? "succeeded" : "rejected");=
exit(0);
}

@@ -937,7 +940,8 @@

*/
if (!dl= open_pam(pam_so))
{
- plugin_log(PLOG_ERR, MODULE, "BACKGROUND: c= ould not load PAM lib %s: %s", pam_so, dlerror());
+ plugin_log(PLOG_ERR, MODULE, &q= uot;BACKGROUND: could not load PAM lib %s: %s", pam_so,
+ dlerror());
send_control(fd, RESPONSE_INIT_FAILED);
goto done;

}
@@ -948,7 +95= 2,7 @@
*/
if (send_control(fd, R= ESPONSE_INIT_SUCCEEDED) =3D=3D -1)
{
- plugin_log(PLOG_ERR|PLOG_ERRNO,= MODULE, "BACKGROUND: write error on response socket [1]");
+ plugin_log(PLOG_E= RR | PLOG_ERRNO, MODULE, "BACKGROUND: write error on response socket [= 1]");
goto done;
}

@@ -980,7 +984,8 @@
= || recv_string(fd, ac_file_name, sizeof(ac_file_name)) =3D=3D -1=
|| recv_string(fd, up.remote, sizeof(= up.remote)) =3D=3D -1)
{
- plugin_log(PLOG_ERR= |PLOG_ERRNO, MODULE, "BACKGROUND: read error on command channel: code= =3D%d, exiting",
+ plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE,
<= span style=3D"color: hsl(120, 100%, 40%);">+ = "BACKGROUND: read error on command channel: code=3D%d, exiting",<= /span>
command);
= goto done;
}@@ -1015,7 +1020,8 @@
{
<= span> if (send_control(fd, RESPONSE_VERIFY_SUCCEEDED) = =3D=3D -1)

{
- plugin_log(PLOG_ERR|PLO= G_ERRNO, MODULE, "BACKGROUND: write error on response socket [2]"= );
+ = plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE,
+ "BACKG= ROUND: write error on response socket [2]");
= goto done;
} }
@@ -1023,7 +1029,8 @@
<= span> {

if (send_contr= ol(fd, RESPONSE_VERIFY_FAILED) =3D=3D -1)
= {
- = plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: write err= or on response socket [3]");
+ plugin_log(PLOG_ERR | PLOG_ERRNO, MOD= ULE,
+ = "BACKGROUND: write error on response socket [3]&qu= ot;);
goto done;
= }
}
@@= -1034,7 +1041,8 @@
goto done;
<= span>

case -1:
- plugin_log(PLOG_ERR|PLOG_ERRNO, MODU= LE, "BACKGROUND: read error on command channel");
+ plugin_log(PLOG_ERR= | PLOG_ERRNO, MODULE,

-#de= fine RESOLVE_PAM_FUNCTION(x, y, z, err) \
- { \
- union { const void *tpointer; y(*fn) z; } fptr; \
<= span style=3D"color: hsl(0, 100%, 40%);">- fptr.tpointer =3D dlsym(l= ibpam_h, #x); real_ ## x =3D fptr.fn; \

- if (real_ ## x =3D=3D NULL) { \
+#define RESOLVE_PAM_FUNCTION(x, y, z,= err) \
+ { = \
+ union = \
+ { = \
+ = const void *tpointer; = \
+ = y(*fn) z; \
+ } fptr; = \
+ fptr.tpointer =3D dlsym(= libpam_h, #x); \

+ real_##x =3D fptr.fn; = \
+ if (real_##x =3D=3D NULL) = \
+ { = \
fprintf(stderr,= "PAMDL: unable to resolve '%s': %s\n", #x, dlerror()); \=
- return er= r; \
- } \
+ return err; = \
+ } = \

}

int
@@ -34,7 +40,7 @@
{
if (libpam_h =3D=3D NULL)
{

- libp= am_h =3D dlopen(so, RTLD_GLOBAL|RTLD_NOW);
+ libpam_h =3D dlopen(so, RTLD_GLOBAL | RTLD_N= OW);
}
return libpam_h !=3D NULL;=
}
@@ -50,16 +56,13 @@
}<= /span>

int
-pam_start(const char *service_name, const char *user,
- const struct pam= _conv *pam_conversation,
+pam_start(const char *service_name, const char *user, const struct pam= _conv *pam_conversation,
pam_handle_t **pamh)
{
- i= nt (*real_pam_start)(const char *, const char *,
- const struct pam_conv = *,
- = pam_handle_t **);
- = const struct pam_conv *,
- pam_handle_t= **), PAM_ABORT);
+ = int (*real_pam_start)(const char *, const char *, const struct pam_conv *= , pam_handle_t **);
+= RESOLVE_PAM_FUNCTION(pam_start, int,
+ (const char *, const char *, = const struct pam_conv *, pam_handle_t **),
+ PAM_ABORT);
return real_pam_start(service_name, user, pam_conversation, pamh);
}

@@ -75,8 +78,7 @@=
pam_set_item(pam_handle_t *pamh, int item_type, const void *item= )
{
int (*real_pam_set_item)(pam_hand= le_t *, int, const void *);
- RESOLVE_PAM_FUNCTION(pam_set_item, int,
- (pam_handle_t *, int, = const void *), PAM_ABORT);
+ RESOLVE_PAM_FUNCTION(pam_set_item, int, (pam_handle_t *, int, co= nst void *), PAM_ABORT);
return real_pam_set_item(pamh= , item_type, item);
}

@@= -84,9 +86,7 @@
pam_get_item(const pam_handle_t *pamh, int= item_type, const void **item)
{
int = (*real_pam_get_item)(const pam_handle_t *, int, const void **);
<= span style=3D"color: hsl(0, 100%, 40%);">- RESOLVE_PAM_FUNCTION(pam_get_= item, int,

- = (const pam_handle_t *, int, const void **),
- PAM_ABORT);
+ RESOLVE_PAM_FUNCTI= ON(pam_get_item, int, (const pam_handle_t *, int, const void **), PAM_ABORT= );
return real_pam_get_item(pamh, item_type, item);
}

@@ -94,8 +94,7 @@=
pam_fail_delay(pam_handle_t *pamh, unsigned int musec_delay)
{
int (*real_pam_fail_delay)(pam_handle_= t *, unsigned int);
- = RESOLVE_PAM_FUNCTION(pam_fail_delay, int, (pam_handle_t *, unsigned int),=
- = PAM_ABORT);
+ = RESOLVE_PAM_FUNCTION(pam_fail_delay, int, (pam_handle_t *, unsigned int), P= AM_ABORT);
return real_pam_fail_delay(pamh, musec_dela= y);
}

@@ -105,8 +104,7 @= @
pam_strerror(pam_handle_t *pamh, int errnum)
<= span> {

const_char_pointer (*real_pam_strerror)(pam_ha= ndle_t *, int);
- RE= SOLVE_PAM_FUNCTION(pam_strerror, const_char_pointer,
- (pam_handle_t *, i= nt), NULL);
+ RESO= LVE_PAM_FUNCTION(pam_strerror, const_char_pointer, (pam_handle_t *, int), N= ULL);
return real_pam_strerror(pamh, errnum); }

@@ -114,8 +112,7 @@
= pam_putenv(pam_handle_t *pamh, const char *name_value)
{

int (*real_pam_putenv)(pam_handle_t *, const cha= r *);
- RESOLVE_PAM_= FUNCTION(pam_putenv, int, (pam_handle_t *, const char *),
- PAM_ABORT);
+ RESOLVE_PAM_FUNCTI= ON(pam_putenv, int, (pam_handle_t *, const char *), PAM_ABORT);
<= span> return real_pam_putenv(pamh, name_value);

}

@@ -123,8 +120,7 @@
pam_gete= nv(pam_handle_t *pamh, const char *name)
{
const_char_pointer (*real_pam_getenv)(pam_handle_t *, const char *);<= /span>
- RESOLVE_PAM_FUNCTI= ON(pam_getenv, const_char_pointer,
- (pam_handle_t *, const char *), NULL)= ;
+ RESOLVE_PAM_FU= NCTION(pam_getenv, const_char_pointer, (pam_handle_t *, const char *), NULL= );
return real_pam_getenv(pamh, name);
}


@@ -133,8 +129,7 @@
= pam_getenvlist(pam_handle_t *pamh)
{
= char_ppointer (*real_pam_getenvlist)(pam_handle_t *);
- RESOLVE_PAM_FUNCTION(pam_getenvlist, ch= ar_ppointer, (pam_handle_t *),
- NULL);
+ RESOLVE_PAM_FUNCTION(pam_getenvlist, char_ppointer= , (pam_handle_t *), NULL);
return real_pam_getenvlist(= pamh);
}

@@ -144,8 +139,= 7 @@
pam_authenticate(pam_handle_t *pamh, int flags)
{
int (*real_pam_authenticate)(pam_handle_= t *, int);
- RESOLVE= _PAM_FUNCTION(pam_authenticate, int, (pam_handle_t *, int),
- PAM_ABORT);<= /span>
+ RESOLVE_PAM_FUNC= TION(pam_authenticate, int, (pam_handle_t *, int), PAM_ABORT);
return real_pam_authenticate(pamh, flags);

}

@@ -173,8 +167,7 @@
pam_open= _session(pam_handle_t *pamh, int flags)
{
= int (*real_pam_open_session)(pam_handle_t *, int);
- RESOLVE_PAM_FUNCTION(pam_open_session= , int, (pam_handle_t *, int),
- PAM_ABORT);
+ RESOLVE_PAM_FUNCTION(pam_open_session, int, (p= am_handle_t *, int), PAM_ABORT);
return real_pam_open_= session(pamh, flags);
}

= @@ -182,8 +175,7 @@
pam_close_session(pam_handle_t *pamh, = int flags)
{
int (*real_pam_close_ses= sion)(pam_handle_t *, int);
- RESOLVE_PAM_FUNCTION(pam_close_session, int, (pam_handle_t *, int= ),
- = PAM_ABORT);
+ = RESOLVE_PAM_FUNCTION(pam_close_session, int, (pam_handle_t *, int), PAM_A= BORT);
return real_pam_close_session(pamh, flags);
}

diff --git a/src/plugins/= auth-pam/utils.c b/src/plugins/auth-pam/utils.c
index a6ccf= bf..68216e4 100644
--- a/src/plugins/auth-pam/utils.c
+++ b/src/plugins/auth-pam/utils.c
@@ -56,7 +56,= 8 @@
return NULL;
}
- bool is_p= otential_integer_overflow =3D (templen =3D=3D SIZE_MAX) || (templen / tose= archlen !=3D replacewithlen);
+ bool is_potential_integer_overflow =3D
+ (templen =3D=3D SIZE_MAX) || (tem= plen / tosearchlen !=3D replacewithlen);

= if (is_potential_integer_overflow)
{
@@ -68,7 +69,7 @@

const char *searching =3D tosear= ch;
char *scratch;

- char temp[templen+1];
+ char temp[templen + 1];
temp[0] =3D 0;

scrat= ch =3D strstr(searching, searchfor);
@@ -79,10 +80,10 @@

while (scratch)
{=
- strncat(temp,= searching, scratch-searching);
+ strncat(temp, searching, scratch - searching); strcat(temp, replacewith);

- searching =3D scratch+strle= n(searchfor);

+ = searching =3D scratch + strlen(searchfor);
scrat= ch =3D strstr(searching, searchfor);
}
return strdup(temp);

diff --git a/src/plugins/auth-pa= m/utils.h b/src/plugins/auth-pam/utils.h
index 844d2d1..916= 584a 100644
--- a/src/plugins/auth-pam/utils.h
+++ b/src/plugins/auth-pam/utils.h

@@ -35,11 +35,10 @@<= /span>
* @param searchfor needle to search for in the hayst= ack
* @param replacewith when a match is found, replac= e needle with this string
*
- * @return Returns NULL when any parameter is NULL= or the worst-case result is to large ( >=3D SIZE_MAX).
- * Otherwise it returns a poi= nter to a new buffer containing the modified input
+ * @return Returns NULL when any parameter = is NULL or the worst-case result is to large ( >=3D
+ * SIZE_MAX). Otherwise it returns a poi= nter to a new buffer containing the modified input
*/
-char *
-searchandreplace(const char *tosearch, c= onst char *searchfor, const char *replacewith);
+char *searchandreplace(const char *tosearch, co= nst char *searchfor, const char *replacewith);

= /**
* Given an environmental variable name, search=
@@ -48,10 +47,10 @@
* @param name Envir= onment variable to look up
* @param envp Environment var= iable table with all key/value pairs
*
- * @return Returns a pointer to the valu= e of the environment variable if found, otherwise NULL is returned.<= br>+ * @return Returns a pointe= r to the value of the environment variable if found, otherwise NULL is
+ * returned.
<= span> */

-const char *=
-get_env(const char *n= ame, const char *envp[]);
+const char *get_env(const char *name, const char *envp[]);
=
/**
* Return the length of a str= ing array
@@ -59,7 +58,6 @@
* @param arra= y Pointer to the array to calculate size of
* */
-int=
-string_array_len(const char = *array[]);
+int strin= g_array_len(const char *array[]);

#endif=
diff --git a/src/plugins/down-root/down-root.c b/src/plugi= ns/down-root/down-root.c
index 253adcd..795a887 100644
--- a/src/plugins/down-root/down-root.c
+++ b/s= rc/plugins/down-root/down-root.c
@@ -144,11 +144,11 @@
static int
send_control(int fd, int code)
{
- un= signed char c =3D (unsigned char) code;
+ unsigned char c =3D (unsigned char)code;
= const ssize_t size =3D write(fd, &c, sizeof(c));
<= span> if (size =3D=3D sizeof(c))

{
- return (int) size;

= + return (int)size;
}
else
{<= br>@@ -254,7 +254,7 @@
int ret =3D 0;
=
pid =3D fork();
- if (pid =3D=3D (pid_t)0) /* child side */
+ if (pid =3D=3D (pid_= t)0) /* child side */
{
execv= e(argv[0], argv, envp);
/* If execve() fails to ru= n, exit child with exit code 127 */
@@ -265,12 +265,13 @@
warn("DOWN-ROOT: Failed to fork child to run %= s", argv[0]);
return -1;
= }
- else /* par= ent side */
+ else= /* parent side */
{
if (wait= pid(pid, &ret, 0) !=3D pid)
{
= /* waitpid does not return error information via errno */
- fprintf(stderr= , "DOWN-ROOT: waitpid() failed, don't know exit code of child (%s)= \n", argv[0]);
+= fprintf(stderr, "DOWN-ROOT: waitpid() failed, don't kn= ow exit code of child (%s)\n",
+ argv[0]);
= return -1;
}
}
@@ -286,7 +287,7 @@

/*
* Alloc= ate our context
*/
- context =3D (struct down_root_context *) calloc(1, s= izeof(struct down_root_context));
+ context =3D (struct down_root_context *)calloc(1, sizeof(= struct down_root_context));
if (!context)
{

warn("DOWN-ROOT: Could not allocat= e memory for plug-in context");
@@ -322,7 +323,7 @@
/* Ignore argv[0], as it contains just the plug-in file = name */
for (i =3D 1; i < string_array_len(argv); i= ++)
{
- context->command[i-1] =3D (char *) argv[i];
+ context->command[i - 1] = =3D (char *)argv[i];

}

/*

@@ -336,7 +337,7 @@
}
}

- return (openvpn_plugin_handle_t) context;
<= span style=3D"color: hsl(120, 100%, 40%);">+ return (openvpn_plugin_hand= le_t)context;


error:
= free_context(context);
@@ -344,11 +345,13 @@
}


OPENVPN_EXPORT int
-openvpn_plugin_func_v1(openvpn_plugi= n_handle_t handle, const int type, const char *argv[], const char *envp[])<= /span>
+openvpn_plugin_func_= v1(openvpn_plugin_handle_t handle, const int type, const char *argv[],

+ c= onst char *envp[])
{
- struct down_root_context *context =3D (struct down_root= _context *) handle;
+= struct down_root_context *context =3D (struct down_root_context *)handl= e;

- = if (type =3D=3D OPENVPN_PLUGIN_UP && context->foreground_fd = =3D=3D -1) /* fork off a process to hold onto root */
+ if (type =3D=3D OPENVPN_PLUGIN_UP
+ && cont= ext->foreground_fd =3D=3D -1) /* fork off a process to hold onto root */=
{
pid_t pid;
int fd[2];

@@ -412,7 +415,7 @@
= daemonize(envp);

= /* execute the event loop */
- down_root_server(fd[1], context->command, (char *cons= t *) envp, context->verb);
+ down_root_server(fd[1], context->command, (char *c= onst *)envp, context->verb);

= close(fd[1]);
exit(0);
@@ = -434,7 +437,8 @@
}
= if (status =3D=3D -1)
{
- warn("DOWN-ROOT: Erro= r receiving script execution confirmation from background process");
+ warn(=
+ = "DOWN-ROOT: Error receiving script execution confirmation from backgr= ound process");
}
= }
}
@@ -444,7 +448,7 @@
OPENVPN_EXPORT void

openvpn_plugin_close_v1(openvpn_p= lugin_handle_t handle)
{
- struct down_root_context *context =3D (struct down_= root_context *) handle;
+ struct down_root_context *context =3D (struct down_root_context *)h= andle;

if (DEBUG(context->verb))<= /span>
{
@@ -475,7 +479,7 @@
= OPENVPN_EXPORT void
openvpn_plugin_abort_v1(openvpn_plugi= n_handle_t handle)
{
- struct down_root_context *context =3D (struct down_root= _context *) handle;
+= struct down_root_context *context =3D (struct down_root_context *)handl= e;

if (context && context-&g= t;foreground_fd >=3D 0)
{
@@ -528,7= +532,7 @@
switch (command_code)
= {
case COMMAND_RUN_SCRIPT:
<= span style=3D"color: hsl(0, 100%, 40%);">- if ( (exit_code = =3D run_script(argv, envp)) =3D=3D 0) /* Succeeded */

+ if ((exit_code =3D run_sc= ript(argv, envp)) =3D=3D 0) /* Succeeded */
= {
if (send_control(fd, RESPONSE_SCRI= PT_SUCCEEDED) =3D=3D -1)
{
<= span>@@ -538,7 +542,8 @@

}
else /* Failed */

{
- fprint= f(stderr, "DOWN-ROOT: BACKGROUND: %s exited with exit code %i\n",= argv[0], exit_code);
+ fprintf(stderr, "DOWN-ROOT: BACKGROUND: %s exite= d with exit code %i\n", argv[0],
+ exit_code);
= if (send_control(fd, RESPONSE_SCRIPT_FAILED) =3D=3D -1)=
{
= warn("DOWN-ROOT: BACKGROUND: write error on response socket [3]&= quot;);
diff --git a/src/tapctl/basic.h b/src/tapctl/basic.= h
index 3814db1..ad8b3fa 100644
--- a/src/t= apctl/basic.h
+++ b/src/tapctl/basic.h
@@ -= 27,14 +27,16 @@
#define UNICODE
#endif

-#defin= e PRIXGUID "{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%= 02hhX%02hhX%02hhX}"
- (g).Data1, (g).Data2, (g).Data3, (g).Data4[0], (g).Data4[1], (g= ).Data4[2], (g).Data4[3], (g).Data4[4], (g).Data4[5], (g).Data4[6], (g).Dat= a4[7]
-#define PRIGUID_= PARAM_REF(g) \
- &am= p;(g).Data1, &(g).Data2, &(g).Data3, &(g).Data4[0], &(g).Da= ta4[1], &(g).Data4[2], &(g).Data4[3], &(g).Data4[4], &(g).D= ata4[5], &(g).Data4[6], &(g).Data4[7]
+#define PRIXGUID "{%08lX-%04hX-%04hX-%02hhX%= 02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}"
+#define PRIGUID_PARAM(g) = \
+ (g).Data1, (g).Data2, (g).Data3, (g).Data= 4[0], (g).Data4[1], (g).Data4[2], (g).Data4[3], \
+ (g).Data4[4], (g).Data4[5], (g).Data4= [6], (g).Data4[7]
+#d= efine PRIGUID_PARAM_REF(g) = \
+ &(= g).Data1, &(g).Data2, &(g).Data3, &(g).Data4[0], &(g).Data4= [1], &(g).Data4[2], \
+ &(g).Data4[3], &(g).Data4[4], &(g).Data4[5], &= ;(g).Data4[6], &(g).Data4[7]

-#define __L(q) L ## q
-#define _L(q) __L(q)
=
+#define __L(q) L##q=
+#define _L(q) __L(q)

#ifndef _In_
#define _In_
diff --git a/src/tapctl/error.h b/src/tapctl/error.h<= br>index 42c175e..382d9eb 100644
--- a/src/tapctl/err= or.h
+++ b/src/tapctl/error.h
@@ -35,27 +35= ,27 @@

/* msg() flags */

-#define M_DEBUG_LEV= EL (0x0F) /* debug level mask */
+#define M_DEBUG_LEVEL (0x0F) /* debug level mask *= /

-#d= efine M_FATAL (1<<4) /* exit program */
<= span style=3D"color: hsl(0, 100%, 40%);">-#define M_NONFATAL (1<&= lt;5) /* non-fatal error */

-#define M_WARN (1<<6) /* call syslog= with LOG_WARNING */
-#= define M_DEBUG (1<<7)
+#define M_FATAL (1 << 4) /* exit program */
+#define M_NONFATAL (1 &= lt;< 5) /* non-fatal error */
+#define M_WARN (1 << 6) /* call syslog with LOG_WA= RNING */
+#define M_D= EBUG (1 << 7)

-#define M_ERRNO (1<<8) /* show e= rrno description */
+= #define M_ERRNO (1 << 8) /* show errno description */<= br>
-#define M_N= OMUTE (1<<11) /* don't do mute processing */
-#define M_NOPREFIX = (1<<12) /* don't show date/time prefix */
-#define M_USAGE_SMALL (1<<13= ) /* fatal options error, call usage_small */
-#define M_MSG_VIRT_OUT (1<<14) = /* output message through msg_status_output callback */
-#define M_OPTERR (1<<1= 5) /* print "Options error:" prefix */

-#define M_NOLF (1<<16) = /* don't print new line */
-#define M_NOIPREFIX (1<<17) /* don't = print instance prefix */
+#define M_NOMUTE (1 << 11) /* don't do mute processing= */
+#define M_NOPREF= IX (1 << 12) /* don't show date/time prefix */
+#define M_USAGE_SMALL (1 <<= 13) /* fatal options error, call usage_small */

+#define M_MSG_VIRT_OUT (1 << 14) /* outp= ut message through msg_status_output callback */
+#define M_OPTERR (1 << 15) /* prin= t "Options error:" prefix */
+#define M_NOLF (1 << 16) /* don't prin= t new line */
+#defin= e M_NOIPREFIX (1 << 17) /* don't print instance prefix */

/* flag combinations which are frequently us= ed */
-#define M_ERR = (M_FATAL | M_ERRNO)
-= #define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR)
-#define M_CLIENT (M_MSG_VIRT_OUT | M_N= OMUTE | M_NOIPREFIX)
= +#define M_ERR (M_FATAL | M_ERRNO)
+#define M_USAGE (M_USAGE_SMALL | M_NOPREFIX | M_OPTERR)<= /span>
+#define M_CLIENT (M_= MSG_VIRT_OUT | M_NOMUTE | M_NOIPREFIX)

<= /span>
/** Check muting filter */
@@ -63,18 +63,4= 2 @@

/* Macro to ensure (and teach stati= c analysis tools) we exit on fatal errors */
#ifdef _MSC_V= ER
-#pragma warning(dis= able: 4127) /* EXIT_FATAL(flags) macro raises "warning C4127: conditio= nal expression is constant" on each non M_FATAL invocation. */<= br>+#pragma warning(disable : 4= 127) /* EXIT_FATAL(flags) macro raises "warning C4127: conditional \
+ = expression is constant" on each non M_FATAL invocation. = */
#endif
-#define EXIT_FATAL(flags) do { if ((flags) & M_FATAL) {_exit(1);}}= while (false)
+#defi= ne EXIT_FATAL(flags) \
+ do \
+ { \
+ if ((flags) & M_FATAL) \
+ { = \
+ = _exit(1); \
+ } \
+ } while (false)

-#define msg(flags, ...) do { if (msg_test(f= lags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
+#define msg(flags, ...= ) \
= + do \
+ { \+ if (msg_test(flags))= \
+ = { \
+ x_msg((flags), __VA_ARGS__); \
+ } = \

+ EXI= T_FATAL(flags); \
+ } while (false)
#ifdef ENABLE_DEBUG=
-#define dmsg(flags, ...) do = { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } = while (false)
+#defin= e dmsg(flags, ...) \
+ do \
+ { = \

+ if (= msg_test(flags)) \
+ { \
+ x_msg((flags), __VA_ARGS__); = \
+ } = \
+ EXIT_FATAL(flags); \
+ } while (false)
#else
#define dmsg(flags, ...)
#endif

-void x_msg(const = unsigned int flags, const char *format, ...); /* should be called via m= sg above */
+void x_m= sg(const unsigned int flags, const char *format, ...); /* should be called = via msg above */

void x_msg_va(const uns= igned int flags, const char *format, va_list arglist);

diff --git a/src/tapctl/main.c b/src/tapctl/main.c
= index a67540d..2d1ccc3 100644
--- a/src/tapctl/main.c=
+++ b/src/tapctl/main.c
@@ -121,9 +121,7 @= @
static void
usage(void)
{

- fwprintf(stder= r,
- usage_= message,
- = title_string);
+ f= wprintf(stderr, usage_message, title_string);
}
=
/**
@@ -140,8 +138,10 @@ {
LPOLESTR adapter_id = =3D NULL;
StringFromIID((REFIID)&a->= ;guid, &adapter_id);
= - L"ls).\n", a->szName, adapter_id);
+ fwpri= ntf(stderr,
+ = L"Adapter \"%ls\" already exists (GUID %&qu= ot;
+ = L"ls).\n",
+ a->szName, adapter_id);
CoTaskMemFree(adapter_id);

= }

@@ -205,8 +205,7 @@
/= **
* Program entry point
*/
<= span style=3D"color: hsl(0, 100%, 40%);">-int __cdecl

-wmain(int argc, LPCWSTR argv[])
<= span style=3D"color: hsl(120, 100%, 40%);">+int __cdecl wmain(int argc, LPC= WSTR argv[])

{
int iResult; BOOL bRebootRequired =3D FALSE;
@@ -240,8 +239,= 10 @@
}
else
{

- = fwprintf(stderr, L"Unknown command \"%ls"
- L"\"= . Please, use \"tapctl help\" to list supported commands.\n"= , argv[2]);

+ = fwprintf(stderr,
= + L"Unknown command \"%ls"
+ L"\&quo= t;. Please, use \"tapctl help\" to list supported commands.\n&quo= t;,

+ = argv[2]);
}

return 1;

@@ -264,25 +265,24 @@
= }
else
= {
- fw= printf(stderr, L"Unknown option \"%ls"
- L"\". Pl= ease, use \"tapctl help create\" to list supported options. Ignor= ed.\n",
- = argv[i]);
+ fwprintf(
+ stderr,
+ L"Unknown option \"%ls&qu= ot;
+ = L"\". Please, use \"tapctl help create\" to list su= pported options. Ignored.\n",
+ argv[i]);
}=
}

/* C= reate TUN/TAP adapter. */
GUID guidAdapter;=
LPOLESTR szAdapterId =3D NULL;
- DWORD dwResult =3D tap_create_adapter(<= /span>
- NULL,
- L"Virtual= Ethernet",
- = szHwId,
- = &bRebootRequired,
- &guidAdapter);
+ DWORD dwResult =3D
+ tap_create_adapter(NULL, L"Virtual = Ethernet", szHwId, &bRebootRequired, &guidAdapter);
= if (dwResult !=3D ERROR_SUCCESS)
{<= /span>
fwprintf(stderr, L"Creating TUN/TAP adapt= er failed (error 0x%x).\n", dwResult);
- iResult =3D 1; goto quit;
+ iResult =3D 1;
+ goto quit;
}

/* Get exi= sting network adapters. */
@@ -295,7 +295,8 @@
goto create_delete_adapter;

}

- = LPWSTR adapter_name =3D szName ? wcsdup(szName) : get_unique_adapter_name(= szHwId, pAdapterList);
+ szName ? wcsdup(szName) : get_unique_adapter_nam= e(szHwId, pAdapterList);
if (adapter_name)<= br> {
/* Check for duplicates wh= en name was specified,
@@ -311,11 +312,13 @@
if (dwResult !=3D ERROR_SUCCESS)

= {
StringFromIID((REFIID)&guidAdapter= , &szAdapterId);
- = fwprintf(stderr, L"Renaming TUN/TAP adapter %ls"
+ fwpri= ntf(stderr,
+ = L"Renaming TUN/TAP adapter %ls"
= L" to \"%ls\" failed (error 0x%x).= \n",
szAdapterId, adapter_na= me, dwResult);
CoTaskMemFree(szAdapterId);=
- iResu= lt =3D 1; goto quit;
= + iResult =3D 1;
+ goto quit;
}
}

@@ -335,21 +338,19 = @@
fwprintf(stdout, L"%ls\n", szAdapterI= d);
CoTaskMemFree(szAdapterId);
<= /span>
- iResult =3D 0;= goto quit;
+ = iResult =3D 0;
+ = goto quit;

create_delete_adapter:
- tap_delete_adapte= r(
- NULL,
- &guidAd= apter,
- &am= p;bRebootRequired);
- = iResult =3D 1; goto quit;
+ tap_delete_adapter(NULL, &guidAdapter, &bReboot= Required);
+ i= Result =3D 1;
+ = goto quit;
}
else if (wcsicmp(a= rgv[1], L"list") =3D=3D 0)
{
WCHAR szzHwId[0x100] =3D

- L"root\\" _L(TAP_WIN_COMPONENT_ID) L&quo= t;\0"
- = _L(TAP_WIN_COMPONENT_ID) L"\0"
- L"ovpn-dco\0";
+ L"root\\" _L(TAP= _WIN_COMPONENT_ID) L"\0" _L(TAP_WIN_COMPONENT_ID) L"\0"=
+ = L"ovpn-dco\= 0";

/* Parse options. */
for (int i =3D 2; i < argc; i++)
= @@ -358,13 +359,17 @@
{
= memset(szzHwId, 0, sizeof(szzHwId));
= ++i;
- = memcpy_s(szzHwId, sizeof(szzHwId) - 2*sizeof(WCHAR) /*requires double = zero termination*/, argv[i], wcslen(argv[i])*sizeof(WCHAR));
+ memcpy_s(szzHwId,<= /span>
+ = sizeof(szzHwId) - 2 * sizeof(WCHAR) /*requires double zero termination= */,
+ = argv[i], wcslen(argv[i]) * sizeof(WCHAR));
= }
else
{
- fwprintf= (stderr, L"Unknown option \"%ls"
- L"\". Please, = use \"tapctl help list\" to list supported options. Ignored.\n&qu= ot;,
- = argv[i]);
+ = fwprintf(
+ stderr,
+ L"Unknown option \"%ls"

+ L&qu= ot;\". Please, use \"tapctl help list\" to list supported op= tions. Ignored.\n",
+ argv[i]);
} }

@@ -374,15 +379,18 @@
if (dwResult !=3D ERROR_SUCCESS)
= {
fwprintf(stderr, L"Enumerating T= UN/TAP adapters failed (error 0x%x).\n", dwResult);
- iResult =3D 1; goto quit;
+ iResult = =3D 1;
+ g= oto quit;
}

= for (struct tap_adapter_node *pAdapter =3D pAdapterList; pAdapter; pAd= apter =3D pAdapter->pNext)
{
= LPOLESTR szAdapterId =3D NULL;
Stri= ngFromIID((REFIID)&pAdapter->guid, &szAdapterId);
- fwprintf(stdout, L"= %ls\t%"

- = L"ls\n", szAdapterId, pAdapter->szName);+ fwprintf(stdout,<= /span>
+ = L"%ls\t%"
= + L"ls\n",
+ szAdapterId, pAdapter->szName)= ;
CoTaskMemFree(szAdapterId);
= }

@@ -393,7 +401,9 @@
= {
if (argc < 3)
= {
- fwp= rintf(stderr, L"Missing adapter GUID or name. Please, use \"tapct= l help delete\" for usage info.\n");
+ fwprintf(
+ stderr,
+ L"Missing adapter GU= ID or name. Please, use \"tapctl help delete\" for usage info.\n&= quot;);
return 1;
}

@@ -406,7 +416,8 @@
= if (dwResult !=3D ERROR_SUCCESS)
{
fwprintf(stderr, L"Enumerating TUN/TAP ad= apters failed (error 0x%x).\n", dwResult);
- iResult =3D 1; goto quit;<= br>+ iResult =3D= 1;
+ = goto quit;
}

for (struct tap_adapter_node *pAdapter =3D pAdapterList;; pAd= apter =3D pAdapter->pNext)

@@ -414,7 +425,8 @@ if (pAdapter =3D=3D NULL)
= {
fwprintf(stderr, L"\&qu= ot;%ls\" adapter not found.\n", argv[2]);
- iResult =3D 1; goto del= ete_cleanup_pAdapterList;
+ iResult =3D 1;
+ goto delete_cleanup_pAdapterList;<= /span>
}
else if= (wcsicmp(argv[2], pAdapter->szName) =3D=3D 0)
= {
@@ -434,23 +446,26 @@
}<= /span>

/* Delete the network adapter. *= /
- DWORD dwResu= lt =3D tap_delete_adapter(
- NULL,
= - &guidAdapter,
- &bRebootRequired);
+ DWORD dwResult =3D tap_delete_adapter(NULL,= &guidAdapter, &bRebootRequired);
if (dwRe= sult !=3D ERROR_SUCCESS)
{
- fwprintf(stderr, L"Deletin= g adapter \"%ls"
- L"\" failed (error 0x%x).\n", argv= [2], dwResult);
- = iResult =3D 1; goto quit;
+ fwprintf(stderr,
+ L"Deleting adapter \"%l= s"
+ = L"\" failed (error 0x%x).\n",
+ argv[2], dwResult);<= /span>
+ iResult = =3D 1;
+ g= oto quit;
}

- iResult =3D 0; goto quit;+ iResult =3D 0;
+ goto quit;=
}
else
{- fwprintf(stderr, L"= ;Unknown command \"%ls"
- L"\". Please, use \"tapctl help= \" to list supported commands.\n", argv[1]);
+ fwprintf(stderr,
+ L"Unknown com= mand \"%ls"

+ L"\". Please, use \"tapctl help\" to= list supported commands.\n",
+ argv[1]);
return 1= ;
}

@@ -485,16 +500,= 13 @@
/* Output system error message (if possible)= . */
DWORD dwResult =3D GetLastError();
= LPWSTR szErrMessage =3D NULL;
- if (FormatMessage(
- FORMAT_MESSAGE_FROM_SYSTEM | FO= RMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
- 0,

- dwResult,
- 0,

- (LPWSTR)&szErrMes= sage,

- = 0,
- NUL= L) && szErrMessage)
+ if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSA= GE_ALLOCATE_BUFFER
+ = | FORMAT_MESSAGE_IGNORE_INSERTS,
+ 0, dwRe= sult, 0, (LPWSTR)&szErrMessage, 0, NULL)

+ && szErrMessage)
{

- = /* Trim trailing whitespace. Set terminator after the last non-whitespa= ce character. This prevents excessive trailing line breaks. */
+ /* Trim trailing whi= tespace. Set terminator after the last non-whitespace character.

= + * This prevents e= xcessive trailing line breaks. */
for (size_t = i =3D 0, i_last =3D 0;; i++)
{
if (szErrMessage[i])

diff --git a/src/tap= ctl/tap.c b/src/tapctl/tap.c
index 39b43ac..eb4432a 100644<= /span>
--- a/src/tapctl/tap.c
+++ b/src/tapctl/tap= .c
@@ -41,10 +41,15 @@
#endif


-const static GUID GUID_DEVCLASS_NET =3D { 0x4d36e972L, 0xe325, 0x11ce, { = 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
+const static GUID GUID_DEVCLASS_NET =3D {=
+ 0x4d36e972L, 0x= e325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 }
= +};
-const static WCHAR szAdapterReg= KeyPathTemplate[] =3D L"SYSTEM\\CurrentControlSet\\Control\\Network\\%= ls\\%ls\\Connection";
-#define ADAPTER_REGKEY_PATH_MAX (_countof(L"SYSTEM\\CurrentContro= lSet\\Control\\Network\\") - 1 + 38 + _countof(L"\\") - 1 + = 38 + _countof(L"\\Connection"))
+const static WCHAR szAdapterRegKeyPathTemplate[] =3D<= /span>
+ L"SYSTEM\\C= urrentControlSet\\Control\\Network\\%ls\\%ls\\Connection";
<= span style=3D"color: hsl(120, 100%, 40%);">+#define ADAPTER_REGKEY_PATH_MAX= \
+ (_countof(L"SYSTEM\\= CurrentControlSet\\Control\\Network\\") - 1 + 38 + _countof(L"\\&= quot;) - 1 \
+ + = 38 + _countof(L"\\Connection"))

/**

* Dynamically load a library and find a function in= it
@@ -155,10 +160,8 @@
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise
**/
-typedef = DWORD (*devop_func_t)(
= - _In_ HDEVINFO hDeviceInfoSet,
- _In_ PSP_DEVINFO_DATA pDeviceInfoData,
- _Inout_ LPBOOL pbRebootRequired);
+typedef DWORD (*devop_f= unc_t)(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData,=
+ = _Inout_ LPBOOL pbRebootRequired);


/**
@@ -178,10 +181,8 @@
<= span> * @return ERROR_SUCCESS on success; Win32 error code otherwise
**/
static DWORD
-check_reboot(
- _In_ HDEVINFO hDeviceInfoSet,
- _In_ PSP_DEVINFO_DATA pDeviceInfoData,
- _Inout_ LPBOOL pbRebo= otRequired)
+check_re= boot(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData,
+ _Inout_ = LPBOOL pbRebootRequired)
{
if (pbRebo= otRequired =3D=3D NULL)
{
@@ -189,10 += 190,7 @@
}

SP_D= EVINSTALL_PARAMS devinstall_params =3D { .cbSize =3D sizeof(SP_DEVINSTALL_P= ARAMS) };
- if (!Set= upDiGetDeviceInstallParams(
- hDeviceInfoSet,
- pDeviceInfoData,
- &devinstall_params))
+ if (!SetupDiGetDeviceInstallParams(= hDeviceInfoSet, pDeviceInfoData, &devinstall_params))
= {
DWORD dwResult =3D GetLastError(); msg(M_NONFATAL | M_ERRNO, "%s: SetupDiGetDeviceInstall= Params failed", __FUNCTION__);
@@ -225,10 +223,8 @@
* @return ERROR_SUCCESS on success; Win32 error code otherw= ise
**/
static DWORD
-delete_device(
- _In_ HDEVINFO hDeviceInfoSet,
- _In_ PSP_DEVINFO_DATA pDeviceInf= oData,

- _Inout_ LPB= OOL pbRebootRequired)
+delete_device(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDevice= InfoData,
+ = _Inout_ LPBOOL pbRebootRequired)
{
= SP_REMOVEDEVICE_PARAMS params =3D
{
= @@ -242,11 +238,8 @@
};

/* Set class installer parameters for DIF_REMOVE. */

- if (!SetupDiSetClassInstallPara= ms(

- hDevic= eInfoSet,
- = pDeviceInfoData,
- = &params.ClassInstallHeader,
- sizeof(SP_REMOVEDEVICE_PARAMS)))
+ if (!SetupDiSetClassInstallPa= rams(hDeviceInfoSet, pDeviceInfoData, &params.ClassInstallHeader,
+ = sizeof(SP_REMOVEDEVICE_PARAMS)))
{=
DWORD dwResult =3D GetLastError();
= msg(M_NONFATAL | M_ERRNO, "%s: SetupDiSetClassInstallParams failed= ", __FUNCTION__);
@@ -254,10 +247,7 @@
}


/* Call appropriate class in= staller. */
- if (!S= etupDiCallClassInstaller(
- DIF_REMOVE,
- hDeviceInfoSet,
- pDeviceInfoData))
+ if (!SetupDiCallClassInstaller(DIF_REMOVE, hDevic= eInfoSet, pDeviceInfoData))
{
= DWORD dwResult =3D GetLastError();
msg(M_NONFATAL= | M_ERRNO, "%s: SetupDiCallClassInstaller(DIF_REMOVE) failed", _= _FUNCTION__);
@@ -289,11 +279,8 @@
* @ret= urn ERROR_SUCCESS on success; Win32 error code otherwise
= **/
static DWORD
-change_device_state(
- _In_ HDEVINFO hDeviceInfoSet,
- _In_ PSP_DEVINFO_DATA pDeviceInfoData,- _In_ BOOL bEnable,- _Inout_ LPBOOL pbRebootReq= uired)
+change_device= _state(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData,=
+ = _In_ BOOL bEnable, _Inout_ LPBOOL pbRebootRequired)
{
SP_PROPCHANGE_PARAMS params =3D
{
@@ -308,11 +295,8 @@
};
=
/* Set class installer parameters for DIF_PROPERTYCH= ANGE. */
- if (!Setu= pDiSetClassInstallParams(
- hDeviceInfoSet,
- pDeviceInfoData,
- &params.ClassInstallHeader,
- sizeof(SP_PROPCHANGE_PAR= AMS)))

+ if (!Setu= pDiSetClassInstallParams(hDeviceInfoSet, pDeviceInfoData, &params.Class= InstallHeader,
+ = sizeof(SP_PROPCHANGE_PARAMS)))
<= span> {

DWORD dwResult =3D GetLastError();
msg(M_NONFATAL | M_ERRNO, "%s: SetupDiSetClassIn= stallParams failed", __FUNCTION__);
@@ -320,13 +304,11= @@
}

/* Call a= ppropriate class installer. */
- if (!SetupDiCallClassInstaller(
- DIF_PROPERTYCHANGE,
- hDeviceInfoSet,
- pDeviceInfoData))
=
+ if (!SetupDiCallClassI= nstaller(DIF_PROPERTYCHANGE, hDeviceInfoSet, pDeviceInfoData))
{

DWORD dwResult =3D GetLastError();
- msg(M_NONFATAL | M= _ERRNO, "%s: SetupDiCallClassInstaller(DIF_PROPERTYCHANGE) failed"= ;, __FUNCTION__);
+ = msg(M_NONFATAL | M_ERRNO, "%s: SetupDiCallClassInstaller(DIF_PRO= PERTYCHANGE) failed",
+ __FUNCTION__);
return dwResult;=
}

@@ -353,10 +335,8= @@
* @return ERROR_SUCCESS on success; Win32 error code = otherwise
**/
static DWORD
-enable_device(

- _In_ HDEVINFO hDeviceInfoSet,- _In_ PSP_DEVINFO_DATA pDev= iceInfoData,
- _Inou= t_ LPBOOL pbRebootRequired)
+enable_device(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA p= DeviceInfoData,
+ = _Inout_ LPBOOL pbRebootRequired)
{
return change_device_state(hDeviceInfoSet, pDeviceInfoData, TRUE, p= bRebootRequired);

}
@@ -379,10 +359,8 @@
* @return ERROR_SUCCESS on success; Win32 error code other= wise
**/
static DWORD
-disable_device(
- _In_ HDEVINFO hDeviceInfoSet,
- _In_ PSP_DEVINFO_DATA pDeviceI= nfoData,

- _Inout_ L= PBOOL pbRebootRequired)
+disable_device(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDev= iceInfoData,
+ = _Inout_ LPBOOL pbRebootRequired)
{
return change_device_state(hDeviceInfoSet, pDeviceInfoData, FALSE, pb= RebootRequired);

}
@@ -403,10 +381,7 @@
* @return ERROR_SUCCESS on success; Win32 error code otherw= ise
*/
static DWORD
-get_reg_string(
- _In_ HKEY hKey,
- _In_ LPCWSTR szName,
- _Out_ LPWSTR *pszValue)
+get_reg_string(_In_ HKEY hKey, _In_ LPC= WSTR szName, _Out_ LPWSTR *pszValue)
{
= if (pszValue =3D=3D NULL)
{
@@ -414,= 17 +389,13 @@
}

= DWORD dwValueType =3D REG_NONE, dwSize =3D 0;
- DWORD dwResult =3D RegQueryValueEx(
= - hKey,
- szName,
- NULL,
- &dwValueType,
- NULL,
- &dwSize);
+ DWORD dwResult =3D RegQueryValueEx(hKey, szName, NUL= L, &dwValueType, NULL, &dwSize);
if (dwResult = !=3D ERROR_SUCCESS)
{
- SetLastError(dwResult); /* MSDN does not menti= on RegQueryValueEx() to set GetLastError(). But we do have an error code. S= et last error manually. */
- msg(M_NONFATAL | M_ERRNO, "%s: enumerating \"%ls\&qu= ot; registry value failed", __FUNCTION__, szName);
+ SetLastError(dwResult); /* MSDN= does not mention RegQueryValueEx() to set GetLastError().
+ B= ut we do have an error code. Set last error manually. */
+ msg(M_NONFATAL | M_ERRNO, &quo= t;%s: enumerating \"%ls\" registry value failed", __FUNCTION= __,
+ szNa= me);
return dwResult;
}

@@ -441,17 +412,14 @@
= return ERROR_OUTOFMEMORY;
}
- d= wResult =3D RegQueryValueEx(
- hKey,
- szName,
- NULL,
- NULL,
- (LPBYTE)szValue,
- &dwSize);
+ dwResult =3D RegQueryValueEx(hKey= , szName, NULL, NULL, (LPBYTE)szValue, &dwSize);
= if (dwResult !=3D ERROR_SUCCESS)
{
- SetLastErr= or(dwResult); /* MSDN does not mention RegQueryValueEx() to set GetLastErro= r(). But we do have an error code. Set last error manually. */
- msg(M_NONFATAL | M= _ERRNO, "%s: reading \"%ls\" registry value failed", __= FUNCTION__, szName);

= + SetLastError(
+ dwResult); /* MSDN does not mention RegQuery= ValueEx() to set GetLastError(). But
+ we do have an error code= . Set last error manually. */
+ msg(M_NONFATAL | M_ERRNO, "%s: reading \&quo= t;%ls\" registry value failed", __FUNCTION__,
+ szName);
= free(szValue);
retu= rn dwResult;
}
@@ -460,12 +428= ,12 @@
{
/* E= xpand the environment strings. */
DWORD
- dwSi= zeExp =3D dwSize * 2,
-= dwCountExp =3D
+ dwSizeExp =3D dwSize * 2, dwCountExp =3D
#ifdef UNICODE
- dwSizeExp / sizeof(WCHAR);
+ = dwSizeExp / sizeof(WCHAR);
#else
- dwSizeExp / sizeof(WCHA= R) - 1; /* Note: ANSI version requires one extra char. */
+ = dwSizeExp / sizeof(WCHAR)

+ - 1; /* Note: = ANSI version requires one extra char. */
#endif
= LPWSTR szValueExp =3D (LPWSTR)malloc(dwSizeExp);
if (szValueExp =3D=3D NULL)
@= @ -475,13 +443,11 @@
return ERROR_OUTO= FMEMORY;
}

- DWORD dwCountExpRes= ult =3D ExpandEnvironmentStrings(

- szValue,
- szValueExp, dwCountExp
- );

+ DWORD dwCountExp= Result =3D ExpandEnvironmentStrings(szValue, szValueExp, dwCountExp);
if (dwCountExpResult =3D=3D 0)
= {
- = msg(M_NONFATAL | M_ERRNO, "%s: expanding \"%ls\&= quot; registry value failed", __FUNCTION__, szName);
+ msg(M_NONFATAL | = M_ERRNO, "%s: expanding \"%ls\" registry value failed",=
+ = __FUNCTION__, szName);
free(szVal= ueExp);
free(szValue);
return dwResult;

@@ -512,9 +478,7 @@<= /span>
return ERROR_OUTOFMEMORY; }

- dwCountExpResult =3D ExpandE= nvironmentStrings(
- = szValue,
- szValueExp, dwCountExp);
+ dwCountExpResult = =3D ExpandEnvironmentStrings(szValue, szValueExp, dwCountExp);
free(szValue);

= *pszValue =3D szValueExp;
return ERR= OR_SUCCESS;
@@ -528,7 +492,8 @@
}<= /span>

default:
- msg(M_NONFATAL, "%s: \&quo= t;%ls\" registry value is not string (type %u)", __FUNCTION__, dw= ValueType);
+ = msg(M_NONFATAL, "%s: \"%ls\" registry value is not strin= g (type %u)", __FUNCTION__,
+ dwValueType);
ret= urn ERROR_UNSUPPORTED_TYPE;
}
}
@@ -553,11 +518,8 @@
* @return ERROR_SUCCESS o= n success; Win32 error code otherwise
**/
static DWORD

-get_net= _adapter_guid(
- _In= _ HDEVINFO hDeviceInfoSet,
- _In_ PSP_DEVINFO_DATA pDeviceInfoData,
- _In_ int iNumAttempts,
- _Out_ LPGUID pguidAdapter)
+get_net_adapter_guid(_In_ HDEVIN= FO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA pDeviceInfoData,

+ _In_ int iNumAtt= empts, _Out_ LPGUID pguidAdapter)
{
D= WORD dwResult =3D ERROR_BAD_ARGUMENTS;

@@= -567,13 +529,8 @@
}

/* Open HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\<= ;class>\<id> registry key. */

- HKEY hKey =3D SetupDiOpenDevRegKey(
- hDeviceInfoSet,
- pDeviceInfoData,
- DICS_FLAG_GLOBAL,
- 0,
- DIREG_DRV,
- KEY_READ);
+ HKEY hKey =3D SetupDiOpenDevRegKey(hDevi= ceInfoSet, pDeviceInfoData, DICS_FLAG_GLOBAL, 0,
+ DIREG_DRV= , KEY_READ);
if (hKey =3D=3D INVALID_HANDLE_VALUE)
{
dwResult =3D GetLastError();
@@ -583,7 +540,8 @@

w= hile (iNumAttempts > 0)
{
- /* Query the NetCfgInstanceId value. Us= ing get_reg_string() right on might clutter the output with error messages = while the registry is still being populated. */
+ /* Query the NetCfgInstanceId value. Us= ing get_reg_string() right on might clutter the
+ * output with error messages while the= registry is still being populated. */
LPWSTR szCf= gGuidString =3D NULL;
dwResult =3D RegQueryValueEx= (hKey, L"NetCfgInstanceId", NULL, NULL, NULL, NULL);
if (dwResult !=3D ERROR_SUCCESS)

@@ -595,22 +5= 53,24 @@
continue;
= }

- SetLastError(dwResult); /* MSDN does not mention RegQueryVa= lueEx() to set GetLastError(). But we do have an error code. Set last error= manually. */
- = msg(M_NONFATAL | M_ERRNO, "%s: querying \"NetCfgInstanceId\&q= uot; registry value failed", __FUNCTION__);
+ SetLastError(
+ dwResult); /* MSDN does = not mention RegQueryValueEx() to set GetLastError(). But we
+ do ha= ve an error code. Set last error manually. */

+ msg(M_NONFATAL | M_ERRNO, "%s: q= uerying \"NetCfgInstanceId\" registry value failed",<= br>+ __FUNCTION_= _);
break;
}
/* Read the NetCfgInstanceId value now. = */
- dwResult = =3D get_reg_string(
- = hKey,
- = L"NetCfgInstanceId",
- &szCfgGuidString);
+ dwResult =3D get_reg_string(hKey, L&q= uot;NetCfgInstanceId", &szCfgGuidString);
= if (dwResult !=3D ERROR_SUCCESS)
{
break;

}
- dwResult =3D SUCCEEDED= (CLSIDFromString(szCfgGuidString, (LPCLSID)pguidAdapter)) ? ERROR_SUCCESS := ERROR_INVALID_DATA;
= + dwResult =3D SUCCEEDED(CLSIDFromString(szCfgGuidString, (LPCLSID)p= guidAdapter))
+ = ? ERROR_SUCCESS
+ : ERROR_INVALID_DATA;
= free(szCfgGuidString);
break;
}

@@ -642,12 +602,9 @@
* @return= ERROR_SUCCESS on success; Win32 error code otherwise
**/=
static DWORD
-get_device_reg_property(
- _In_ HDEVINFO hDeviceInfoSet,
- _In_ PSP_DEVINFO_DATA pDeviceInfoData,- _In_ DWORD dwProperty,
- _Out_opt_ LPDWORD pdw= PropertyRegDataType,
- = _Out_ LPVOID *ppData)
+get_device_reg_property(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO= _DATA pDeviceInfoData,
+ = _Out_ LPVOID *ppData)
{
DWORD dwResult =3D ERROR_BAD_ARGUMENTS;

@@ -659,14 +616,9 @@
/* Try with stack buffer f= irst. */
BYTE bBufStack[128];
DWO= RD dwRequiredSize =3D 0;
- hDeviceInfoSet,
- pDeviceInfoData,
- dwProperty,
- pdwPropertyRegDataType,
- bBufStack,<= /span>
- sizeof(bBu= fStack),
- &= amp;dwRequiredSize))
= + if (SetupDiGetDeviceRegistryProperty(hDeviceInfoSet, pDeviceInfoData, = dwProperty,
+ = pdwPropertyRegDataType, bBufStack, sizeof(= bBufStack),
+ = &dwRequiredSize))
= {
/* Copy from stack. */
= *ppData =3D malloc(dwRequiredSize);
@@ -692,27 +644,24 @@<= /span>
return ERROR_OUTOFMEMORY;
= }

- if (SetupDiGetDeviceRegistryProperty(
- hDeviceInfoSet,<= /span>
- pD= eviceInfoData,
- = dwProperty,
- *ppData,
- dwRequiredSize,<= br>- &dwRe= quiredSize))
+ = if (SetupDiGetDeviceRegistryProperty(hDeviceInfoSet, pDeviceInfoData, = dwProperty,
+ = pdwPropertyRegDataType, *ppData, d= wRequiredSize,
+ = &dwRequiredSize)) {
return ERROR_SUCCESS= ;
}
else {
dwResult =3D GetLas= tError();
- = msg(M_NONFATAL | M_ERRNO, "%s: SetupDiGetDeviceRegistryProperty(%u= ) failed", __FUNCTION__, dwProperty);
+ msg(M_NONFATAL | M_ERRNO, "%s: = SetupDiGetDeviceRegistryProperty(%u) failed",
+ __FUNCTION__, dwProperty= );
return dwResult;
= }
}
else {
- = msg(M_NONFATAL | M_ERRNO, "%s: SetupDiGetDeviceRegistryPropert= y(%u) failed", __FUNCTION__, dwProperty);
+ msg(M_NONFATAL | M_ERRNO, "%s: = SetupDiGetDeviceRegistryProperty(%u) failed",
+ __FUNCTION__, dwProperty);
return dwResult;
}
}
@@ -720,19 +669,13 @@
=

DWORD
-tap_create_adapter(
- _In_opt_ HWND hwndParent,
- _In_opt_ LPCWSTR szDeviceDescription,<= br>- _In_ LPCWSTR szHwId,

- _Inout_ LPBOOL pbReboo= tRequired,
- _Out_ L= PGUID pguidAdapter)
+= tap_create_adapter(_In_opt_ HWND hwndParent, _In_opt_ LPCWSTR szDeviceDescr= iption,
+ = _In_ LPCWSTR szHwId, _Inout_ LPBOOL pbRebootRequired, _Out_ LPGUID p= guidAdapter)
{
DWORD dwResult;=
HMODULE libnewdev =3D NULL;

- if (szHwId =3D=3D NULL
- || pbRebootRequired =3D= =3D NULL
- || pg= uidAdapter =3D=3D NULL)
+ if (szHwId =3D=3D NULL || pbRebootRequired =3D=3D NULL || pguidAdap= ter =3D=3D NULL)
{
return ERR= OR_BAD_ARGUMENTS;
}
@@ -748,11 +691,7 = @@

/* Get the device class name from= GUID. */
WCHAR szClassName[MAX_CLASS_NAME_LEN];

- if (!SetupDiClassNameFr= omGuid(
- &a= mp;GUID_DEVCLASS_NET,
-= szClassName,
- NULL))
+ if (!SetupDiClassNameFromGuid(&GUID_DEVCLASS_NET, sz= ClassName, _countof(szClassName), NULL))
{
<= span> dwResult =3D GetLastError();

msg(M_N= ONFATAL, "%s: SetupDiClassNameFromGuid failed", __FUNCTION__);
@@ -761,14 +700,8 @@

/= * Create a new device info element and add it to the device info set. */
SP_DEVINFO_DATA devinfo_data =3D { .cbSize =3D sizeof(SP= _DEVINFO_DATA) };
- = if (!SetupDiCreateDeviceInfo(
- hDevInfoList,
- szClassName,
- &GUID_DEVCLASS_NET,
- szDeviceDescription,
- hwndParent,

<= span style=3D"color: hsl(0, 100%, 40%);">- DICD_GENERATE_ID,
- &devinfo_= data))
+ if (!Setu= pDiCreateDeviceInfo(hDevInfoList, szClassName, &GUID_DEVCLASS_NET, szDe= viceDescription,
+ = hwndParent, DICD_GENERATE_ID, &devinfo_da= ta))
{
dwResult =3D GetLastEr= ror();
msg(M_NONFATAL, "%s: SetupDiCreateDevi= ceInfo failed", __FUNCTION__);
@@ -776,9 +709,7 @@
}

/* Set a device = information element as the selected member of a device information set. */<= /span>
- if (!SetupDiSetSel= ectedDevice(
- = hDevInfoList,
- = &devinfo_data))
+ if (!SetupDiSetSelectedDevice(hDevInfoList, &devinfo_data))<= /span>
{
dwResult =3D GetLastError()= ;
msg(M_NONFATAL, "%s: SetupDiSetSelectedDevi= ce failed", __FUNCTION__);
@@ -786,11 +717,9 @@=
}

/* Set Plug&Pla= y device hardware ID property. */
- if (!SetupDiSetDeviceRegistryProperty(
- hDevInfoList,
- &devinfo_data,<= br>- SPDRP_HARDWAREID,=
- (const BY= TE *)szHwId, (DWORD)((wcslen(szHwId) + 1) * sizeof(WCHAR))))
+ if (!SetupDiSetDeviceRegistryP= roperty(hDevInfoList, &devinfo_data, SPDRP_HARDWAREID,

+ = (const BYTE *)szHwId,
+ (DWORD)((wcslen(szHwId) += 1) * sizeof(WCHAR))))
{
dwRe= sult =3D GetLastError();
msg(M_NONFATAL, "%s:= SetupDiSetDeviceRegistryProperty failed", __FUNCTION__);
@@ -798,10 +727,7 @@

}
/* Register the device instance with the PnP Manager */<= br>- if (!SetupDiCallClassInst= aller(
- DIF= _REGISTERDEVICE,
- = hDevInfoList,
- = &devinfo_data))
+ if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, hDevInfoL= ist, &devinfo_data))
{
dw= Result =3D GetLastError();
msg(M_NONFATAL, "%= s: SetupDiCallClassInstaller(DIF_REGISTERDEVICE) failed", __FUNCTION__= );
@@ -817,10 +743,9 @@
if (!DiInstall= Device(hwndParent, hDevInfoList, &devinfo_data, NULL, 0, pbRebootRequir= ed))
#else
/* mingw does not resolve = DiInstallDevice, so load it at run time. */
- typedef BOOL (WINAPI *DiInstallDeviceFn)(HWND, HD= EVINFO, SP_DEVINFO_DATA *,
- SP_DRVINFO_DATA *, DWORD,= BOOL *);
- DiInstal= lDeviceFn installfn
- = =3D find_function(L"newdev.dll", "DiInstallDevice"= ;, &libnewdev);
+= typedef BOOL(WINAPI * DiInstallDeviceFn)(HWND, HDEVINFO, SP_DEVINFO_DAT= A *, SP_DRVINFO_DATA *,
+ DWORD, BOOL *);
= + DiInstallDeviceFn installf= n =3D find_function(L"newdev.dll", "DiInstallDevice", &= amp;libnewdev);

if (!installfn)
{
@@ -856,24 +781,20 @@
= };

/* Set class installer= parameters for DIF_REMOVE. */
- if (SetupDiSetClassInstallParams(
- hDevInfoList,
- &devinfo_data,
- &remo= vedevice_params.ClassInstallHeader,
- sizeof(SP_REMOVEDEVICE_PARAMS)))
+ if (SetupDiSetClassInsta= llParams(hDevInfoList, &devinfo_data,

+ &removed= evice_params.ClassInstallHeader,
+ sizeof(SP_REMOVEDEVIC= E_PARAMS)))
{
/* Call= appropriate class installer. */
- if (SetupDiCallClassInstaller(
- DIF_REMOVE,
<= span style=3D"color: hsl(0, 100%, 40%);">- hDevInfoList,=

- &= amp;devinfo_data))
+ = if (SetupDiCallClassInstaller(DIF_REMOVE, hDevInfoList, &dev= info_data))
{
= /* Check if a system reboot is required. */
= check_reboot(hDevInfoList, &devinfo_data, pbRebootRequired);<= br> }
else
= {
- = msg(M_NONFATAL | M_ERRNO, "%s: SetupDiCallClassInstaller(DIF_R= EMOVE) failed", __FUNCTION__);
+ msg(M_NONFATAL | M_ERRNO, "%s: SetupDi= CallClassInstaller(DIF_REMOVE) failed",
+ __FUNCTION__);
}

}
else
@@ -913,11 +834,8 @@
* @return ERROR_SUCCES= S on success; Win32 error code otherwise
**/
static DWORD

-exec= ute_on_first_adapter(
-= _In_opt_ HWND hwndParent,
- _In_ LPCGUID pguidAdapter,
- _In_ devop_func_t funcOperation,
- _Inout_ LPBOOL pbRebootRequired)=
+execute_on_first_adapter(_= In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter,
+ _In_ devop_func_= t funcOperation, _Inout_ LPBOOL pbRebootRequired)
{=
DWORD dwResult;

@@ -927,14= +845,8 @@
}

/*= Create a list of network devices. */
- HDEVINFO hDevInfoList =3D SetupDiGetClassDevsEx(=
- &GUID_DEVCLASS_N= ET,
- NULL,
- hwndParent,=
- DIGCF_PRESENT,
- NULL,
- NULL,

- NULL);
+ HDEVINFO hDevInfoList =3D SetupDiGetClassDev= sEx(&GUID_DEVCLASS_NET, NULL, hwndParent,
+ = DIGCF_PRESENT, NULL, NULL, NULL);
if (hDevInfoList = =3D=3D INVALID_HANDLE_VALUE)
{
= dwResult =3D GetLastError();
@@ -943,7 +855,8 @@ }

/* Retrieve informati= on associated with a device information set. */
- SP_DEVINFO_LIST_DETAIL_DATA devinfo_list_deta= il_data =3D { .cbSize =3D sizeof(SP_DEVINFO_LIST_DETAIL_DATA) };
= + SP_DEVINFO_LIST_DETAIL_DAT= A devinfo_list_detail_data =3D { .cbSize =3D sizeof(
+ = SP_DEVINFO_LIST_DETAIL_DATA) };
= if (!SetupDiGetDeviceInfoListDetail(hDevInfoList, &devinfo_list_detai= l_data))
{
dwResult =3D GetLa= stError();
@@ -956,10 +869,7 @@
{
/* Get the device from the list. */
= SP_DEVINFO_DATA devinfo_data =3D { .cbSize =3D sizeof(SP_DEVINFO_DAT= A) };
- if (!Set= upDiEnumDeviceInfo(
- = hDevInfoList,
- dwIndex,
- &devinfo_data))
+ if (!SetupDiEnumDeviceInfo(hDevInfoList, d= wIndex, &devinfo_data))
{
= if (GetLastError() =3D=3D ERROR_NO_MORE_ITEMS)
= {
@@ -973,7 +883,8 @@
= else
{
/* S= omething is wrong with this device. Skip it. */
- msg(M_WARN | M_ERRNO, "%s: S= etupDiEnumDeviceInfo(%u) failed", __FUNCTION__, dwIndex);
+ msg(M_WARN | M_E= RRNO, "%s: SetupDiEnumDeviceInfo(%u) failed", __FUNCTION__,
+ dwInd= ex);
continue;
= }
}
@@ -1002,23 +913,19 @@


DWORD
-tap_delete_adapter(
- _In_opt_ HWND hwndParent,
- _In_ LPCGUID pguidAdapter,
- _Inout_ LPBOOL pbReboo= tRequired)
+tap_delet= e_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter,
+ _Inout_ LPBOO= L pbRebootRequired)

{
return execute_= on_first_adapter(hwndParent, pguidAdapter, delete_device, pbRebootRequired)= ;
}


D= WORD
-tap_enable_adapte= r(
- _In_opt_ HWND h= wndParent,
- _In_ LP= CGUID pguidAdapter,
- = _In_ BOOL bEnable,
- = _Inout_ LPBOOL pbRebootRequired)
+tap_enable_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID p= guidAdapter, _In_ BOOL bEnable,
+ _Inout_ LPBOOL pbRebootRequired)
<= span> {

- return exe= cute_on_first_adapter(hwndParent, pguidAdapter, bEnable ? enable_device : d= isable_device, pbRebootRequired);
+ return execute_on_first_adapter(hwndParent, pguidAdapter,=
+ = bEnable ? enable_device : disable_device, pbRebootRequired= );
}

/* stripped versio= n of ExecCommand in interactive.c */
@@ -1038,8 +945,8 @@

/* CreateProcess needs a modifiable c= mdline: make a copy */
cmdline_dup =3D _wcsdup(cmdline= );
- if (cmdline_dup= && CreateProcessW(NULL, cmdline_dup, NULL, NULL, FALSE,
= - = proc_flags, NULL, NULL, &si, &pi))
+ if (cmdline_dup
+ && CreateProcessW(NULL, cmdlin= e_dup, NULL, NULL, FALSE, proc_flags, NULL, NULL, &si, &pi))=
{
WaitForSingleObject(pi.hProcess, = INFINITE);
if (!GetExitCodeProcess(pi.hProcess, &a= mp;exit_code))
@@ -1060,10 +967,7 @@
}

DWORD
-tap_set_adapter_name(
- _In_ LPCGUID pguidAdapter,
- _In_ LPCWSTR szName,
- _In_ BOOL bSilent)
+tap_set_adapter_name(_In_ LPCGUID pguidAdapt= er, _In_ LPCWSTR szName, _In_ BOOL bSilent)
{
DWORD dwResult;

int msg_flag =3D bSilent ? M_= WARN : M_NONFATAL;
@@ -1084,23 +988,16 @@
=
/* Render registry key path. */
= WCHAR szRegKey[ADAPTER_REGKEY_PATH_MAX];
- swprintf_s(
- szRegKey, _countof(szRegKey),
- szAdapterRegKeyPathTemplate,- szDevClassNetId,=
- szAdapterId);=
+ swprintf_s(szRegKey, _= countof(szRegKey), szAdapterRegKeyPathTemplate, szDevClassNetId,
= + szAdapterId);

/* Open network adapter registry key.= */
HKEY hKey =3D NULL;
- dwResult =3D RegOpenKeyEx(
- HKEY_LOCAL_MACHINE,
- szRegKey,

- 0,
- KEY_QUERY_VALUE,
- &hKey);
+ dwResult =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE,= szRegKey, 0, KEY_QUERY_VALUE, &hKey);
if (dwResul= t !=3D ERROR_SUCCESS)
{
- SetLastError(dwResult); /* MSDN does not men= tion RegOpenKeyEx() to set GetLastError(). But we do have an error code. Se= t last error manually. */
+ SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx= () to set GetLastError(). But
+ we do have an error code. Set = last error manually. */
msg(msg_flag, "%s: Re= gOpenKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey);<= /span>
goto cleanup_szAdapterId;
}
@@ -1143,10 +1040,8 @@


DWORD
-= tap_list_adapters(
- = _In_opt_ HWND hwndParent,
- _In_opt_ LPCWSTR szzHwIDs,
- _Out_ struct tap_adapter_node **ppAdapter)
+tap_list_adapters(_In_opt_ HWND hw= ndParent, _In_opt_ LPCWSTR szzHwIDs,

+ _Out_ struct tap_adapter_node **ppAdapte= r)
{
DWORD dwResult;
=
@@ -1156,14 +1051,8 @@
}
<= span>

/* Create a list of network devices. */<= br>- HDEVINFO hDevInfoList =3D= SetupDiGetClassDevsEx(
- &GUID_DEVCLASS_NET,
- NULL,
- hwndParent,
- DIGCF_PRESENT,
- = NULL,
- NULL)= ;
+ HDEVINFO hDevI= nfoList =3D SetupDiGetClassDevsEx(&GUID_DEVCLASS_NET, NULL, hwndParent,=
+ = DIGCF_PRESENT, NULL, NULL, NULL);
= if (hDevInfoList =3D=3D INVALID_HANDLE_VALUE)
= {
dwResult =3D GetLastError();
= @@ -1172,7 +1061,8 @@
}

/* Retrieve information associated with a device information set. = */

- SP_DEVINFO_LIST= _DETAIL_DATA devinfo_list_detail_data =3D { .cbSize =3D sizeof(SP_DEVINFO_L= IST_DETAIL_DATA) };
+= SP_DEVINFO_LIST_DETAIL_DATA devinfo_list_detail_data =3D { .cbSize =3D = sizeof(
+ = SP_DEVINFO_LIST_DETAIL= _DATA) };
if (!SetupDiGetDeviceInfoListDetail(hDevInfo= List, &devinfo_list_detail_data))
{
dwResult =3D GetLastError();

@@ -1191,10 +1081,7= @@
{
/* Get the device from = the list. */
SP_DEVINFO_DATA devinfo_data =3D { .c= bSize =3D sizeof(SP_DEVINFO_DATA) };
- if (!SetupDiEnumDeviceInfo(
- hDevInfoList,
- dwIndex,
- &devinfo_data))=

+ if (!SetupD= iEnumDeviceInfo(hDevInfoList, dwIndex, &devinfo_data))
= {
if (GetLastError() =3D=3D ERROR_NO_= MORE_ITEMS)
{
@@ -1203,7 +1090= ,8 @@
else
{
/* Something is wrong with this device. Skip i= t. */
- = msg(M_WARN | M_ERRNO, "%s: SetupDiEnumDeviceInfo(%u) failed", __F= UNCTION__, dwIndex);
= + msg(M_WARN | M_ERRNO, "%s: SetupDiEnumDeviceInfo(%u) = failed", __FUNCTION__,
+ dwIndex);
cont= inue;
}
}
<= span>@@ -1211,12 +1099,8 @@

/* Get device hardware= ID(s). */
DWORD dwDataType =3D REG_NONE; LPWSTR szzDeviceHardwareIDs =3D NULL;
- dwResult =3D get_device_reg_proper= ty(
- hDevIn= foList,
- &a= mp;devinfo_data,
- = SPDRP_HARDWAREID,
- (LPVOID)&szzDeviceHardwareIDs);
+ dwResult =3D get_device_reg_p= roperty(hDevInfoList, &devinfo_data, SPDRP_HARDWAREID,
+ = &dwDataType, (LPVOID)&szzDeviceHardwareIDs);
if (dwResult !=3D ERROR_SUCCESS)

{
/* Something is wrong with this device. Skip it. */=
@@ -1272,48 +1156,42 @@

= /* Render registry key path. */
WCHAR szR= egKey[ADAPTER_REGKEY_PATH_MAX];
- swprintf_s(
- szRegKey, _countof(szRegKey),
- szAdapterRegKeyPathTemplate,=
- szDevClassNetId,=
- szAdapter= Id);
+ swprint= f_s(szRegKey, _countof(szRegKey), szAdapterRegKeyPathTemplate, szDevClassNe= tId,
+ = szAdapterId);

/* Open networ= k adapter registry key. */
HKEY hKey =3D NULL;
- dwResult =3D RegO= penKeyEx(
- = HKEY_LOCAL_MACHINE,
- = szRegKey,
- = 0,
- = KEY_READ,
- = &hKey);
+ = dwResult =3D RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_READ, &am= p;hKey);
if (dwResult !=3D ERROR_SUCCESS) {
- = SetLastError(dwResult); /* MSDN does not mention RegOpenKeyEx() to= set GetLastError(). But we do have an error code. Set last error manually.= */
+ SetL= astError(dwResult); /* MSDN does not mention RegOpenKeyEx() to set GetLastE= rror().
+ = But we do have an error code. Set last error man= ually. */
msg(M_WARN | M_ERRNO, "%s: RegO= penKeyEx(HKLM, \"%ls\") failed", __FUNCTION__, szRegKey);
goto cleanup_szAdapterId;
= }

/* Read adapter name. */
LPWSTR szName =3D NULL;
- dwResult =3D get_reg_string(
- hKey,

- L"Name",- &szName);
+ dwResult =3D get= _reg_string(hKey, L"Name", &szName);
= if (dwResult !=3D ERROR_SUCCESS)
{
SetLastError(dwResult);

- msg(M_WARN | M_ERRNO, "%s: Cannot determi= ne %ls adapter name", __FUNCTION__, szAdapterId);
+ msg(M_WARN | M_ERRNO, "= %s: Cannot determine %ls adapter name", __FUNCTION__,
+ szAdapterId);=
goto cleanup_hKey;
}=

/* Append to the list. */
size_t hwid_size =3D (wcszlen(szzDeviceHardwareIDs) + 1) * siz= eof(WCHAR);

size_t name_size =3D (wcslen(szName) += 1) * sizeof(WCHAR);
- = struct tap_adapter_node *node =3D (struct tap_adapter_node *)malloc(= sizeof(struct tap_adapter_node) + hwid_size + name_size);
+ struct tap_adapter_node *node= =3D (struct tap_adapter_node *)malloc(
+ sizeof(struct tap_adapter_node) + hwid_size= + name_size);
if (node =3D=3D NULL)
{

- = msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, sizeof(st= ruct tap_adapter_node) + hwid_size + name_size);
- dwResult =3D ERROR_OUTOFMEMORY; goto= cleanup_szName;
+ = msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__,
+ sizeof(s= truct tap_adapter_node) + hwid_size + name_size);
+ dwResult =3D ERROR_OUTOFMEMORY;
+ goto clea= nup_szName;
}

= memcpy(&node->guid, &guidAdapter, sizeof(GUID));@@ -1352,8 +1230,7 @@

void
-tap_free_= adapter_list(
- _In_= struct tap_adapter_node *pAdapterList)
+tap_free_adapter_list(_In_ struct tap_adapter_node *pAd= apterList)
{
/* Iterate over all node= s of the list. */
while (pAdapterList)
diff --git a/src/tapctl/tap.h b/src/tapctl/tap.h

index 1ca= 512a..3d9fb4c 100644
--- a/src/tapctl/tap.h
+++ b/src/tapctl/tap.h

@@ -50,12 +50,8 @@
= * @return ERROR_SUCCESS on success; Win32 error code otherwise
= **/
DWORD
-tap_create_adapter(
- _In_opt_ HWND hwndParent,
- _In_opt_ LPCWSTR szDeviceDescription,
- _In_ LPCWSTR szHwId,

<= span style=3D"color: hsl(0, 100%, 40%);">- _Inout_ LPBOOL pbRebootRequir= ed,

- _Out_ LPGUID p= guidAdapter);
+tap_cr= eate_adapter(_In_opt_ HWND hwndParent, _In_opt_ LPCWSTR szDeviceDescription= ,
+ = _In_ LPCWSTR szHwId, _Inout_ LPBOOL pbRebootRequired, _Out_ LPGUID pguidAd= apter);


/**
= @@ -77,10 +73,8 @@
* @return ERROR_SUCCESS on succe= ss; Win32 error code otherwise
**/
DWORD=
-tap_delete_adapter(
- _In_opt_ HWND hwndP= arent,
- _In_ LPCGUI= D pguidAdapter,
- _I= nout_ LPBOOL pbRebootRequired);
+tap_delete_adapter(_In_opt_ HWND hwndParent, _In_ LPCGUID pguid= Adapter,
+ = _Inout_ LPBOOL pbRebootRequired);


/**
@@ -104,11 +98,8 @@
* @return ERROR_SUCCESS on success; Win32 error code otherwise
**/
DWORD
-tap_enable_adapter(
- _In_opt_ HWND hwndParent,
- _In_ LPCGUID pguidAdapter,
- _In_ BOOL bEnable,
- _Inout_ LPBOOL pbRebootRequired);
+tap_enable_adapter(_In_op= t_ HWND hwndParent, _In_ LPCGUID pguidAdapter, _In_ BOOL bEnable,+ _Inout_ LP= BOOL pbRebootRequired);


/**

@@ -124,10 +115,7 @@
* @return ERRO= R_SUCCESS on success; Win32 error code otherwise
**/
DWORD
-tap= _set_adapter_name(
- = _In_ LPCGUID pguidAdapter,
- _In_ LPCWSTR szName,
- _In_ BOOL bSilent);
+tap_set_adapter_name(_In_ LPCGUID pguidAdapter, _In_ LPCWSTR s= zName, _In_ BOOL bSilent);


/**

@@ -135,9 +123,9 @@
*/ struct tap_adapter_node
{
- GUID guid; /**< Adapter GUI= D */
- LPWSTR szzHar= dwareIDs; /**< Device hardware ID(s) */
- LPWSTR szName; /**< Adapter name */
+ GUID guid; = /**< Adapter GUID */
+ LPWSTR szzHardwareIDs; /**< Device hardwar= e ID(s) */
+ LPWST= R szName; /**< Adapter name */
=
struct tap_adapter_node *pNext; /**< Pointer to next adap= ter */
};
@@ -163,10 +151,8 @@
<= span> * @return ERROR_SUCCESS on success; Win32 error code otherwise
*/
DWORD
-tap_list_adapters(
- _In_opt_ HWND hwndParent,
- _In_opt_ LPCWSTR szzHwIDs,
- _Out_ struct tap_adapter_node **ppAdapt= erList);
+tap_list_ad= apters(_In_opt_ HWND hwndParent, _In_opt_ LPCWSTR szzHwIDs,
+ _Out_ struct tap_= adapter_node **ppAdapterList);


/**
@@ -174,8 +160,6 @@
*=
* @param pAdapterList A pointer to the first adapter in the li= st to free.
*/
-void
-tap_fr= ee_adapter_list(
- _= In_ struct tap_adapter_node *pAdapterList);
+void tap_free_adapter_list(_In_ struct tap_adapter_= node *pAdapterList);

#endif /* ifndef TA= P_H */
diff --git a/tests/ntlm_support.c b/tests/ntlm_suppo= rt.c
index f5eba88..788f132 100644
--- a/te= sts/ntlm_support.c
+++ b/tests/ntlm_support.c
@@ -50,7 +50,7 @@

crypto_unload_provider("lega= cy", legacy);
crypto_unload_provider("defaul= t", def);
#endif
-#else /* ifdef NTLM */
+#else /* ifdef NTLM */
msg(M_FATA= L, "NTLM support not compiled in");
#endif
}
diff --git a/tests/unit_tests/example_test/te= st.c b/tests/unit_tests/example_test/test.c
index c174025..= 139e06f 100644
--- a/tests/unit_tests/example_test/test.c
+++ b/tests/unit_tests/example_test/test.c
@= @ -10,7 +10,7 @@
static int
setup(void **= state)
{
- int *answer =3D malloc(sizeof(int));
+ int *answer =3D malloc(sizeof(int));
*answer =3D 42;
*state = =3D answer;
@@ -29,7 +29,7 @@
static void<= /span>
null_test_success(void **state)
{<= br>- (void) state;
<= span style=3D"color: hsl(120, 100%, 40%);">+ (void)state;

}


static void
@@ -39,= 8 +39,7 @@
assert_int_equal(*answer, 42);
}


-static void
+__a= ttribute__((unused)) static void
failing_test(void **state= )
{
/* This tests fails to test that = make check fails */
@@ -53,7 +52,7 @@
= const struct CMUnitTest tests[] =3D {
cmocka_unit_= test(null_test_success),
cmocka_unit_test_setup_te= ardown(int_test_success, setup, teardown),
-/* cmocka_unit_test(failing_test), */+ /* cmocka_unit= _test(failing_test), */
};
return cmocka_run_group_tests_name("success_test", te= sts, NULL, NULL);
diff --git a/tests/unit_tests/example_tes= t/test2.c b/tests/unit_tests/example_test/test2.c
index bb5= 4633..3089432 100644
--- a/tests/unit_tests/example_test/te= st2.c
+++ b/tests/unit_tests/example_test/test2.c@@ -11,7 +11,7 @@
static void
test= _true(void **state)
{
- (void) state;
+ (void)state;
}
=

diff --git a/tests/unit_tests/openvpn/cert_data= .h b/tests/unit_tests/openvpn/cert_data.h
index bbf3736..53= b5cda 100644
--- a/tests/unit_tests/openvpn/cert_data.h
+++ b/tests/unit_tests/openvpn/cert_data.h
@@ = -53,12 +53,11 @@
"srXMaPe0lAea4etMSZsjIRPwGRMXBrw= bRmb6iN2Cq40867HdaJoAryYig7IiDwSX\n"
"htCbOA= 6sX+60+FEOYDEx5cmkogl633Pw7LJ3ICkyzIrUSEt6BOT1Gsc1eQ=3D=3D\n" "-----END CERTIFICATE-----\n";
-static const char *const key1 =3D- "-----BEGIN PRIVATE KE= Y-----\n"
- &qu= ot;MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg5Xpw/lLvBrWjAWDq\n"=
- "L6dm/4a1or6= AQ6O3yXYgw78B23ihRANCAAR4SRvnSuGdJmPitKbqcFbcgyzsMBlh\n"
- "4wWOrty4I0ZlIXxY2qEnyb3YK= z4OdMGzpK7FLfQZehHg6LGblcLs4EW7\n"

- "-----END PRIVATE KEY-----\n";
+static const char *const key1 = =3D "-----BEGIN PRIVATE KEY-----\n"

+ "MIGHAgEAMBM= GByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg5Xpw/lLvBrWjAWDq\n"
+ &= quot;L6dm/4a1or6AQ6O3yXYgw78B23ihRANCAAR4SRvnSuGdJmPitKbqcFbcgyzsMBlh\n&quo= t;

+ = "4wWOrty4I0ZlIXxY2qEnyb3YKz4OdMGzpK7FLfQZehHg6LGblcLs4E= W7\n"
+ = "-----END PRIVATE KEY-----\n";
<= span> static const char *const hash1 =3D "A4B74F1D68AF50691F62CBD675E2= 4C8655369567";

static const char *const cname1 =3D &q= uot;ovpn-test-ec1";

@@ -105,35 +104,= 34 @@
"F6MgVGSxl6eylJgDYckvJiAbmcp2PD/LRQQOxQA0yq= eAMg2cbdvclETuYD6zoFfu\n"
"Y8aO7dvDlw=3D=3D\= n"
"-----END CERTIFICATE-----\n";
-static const char *const ke= y3 =3D
- "-----= BEGIN PRIVATE KEY-----\n"
- "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC7xFoR= 6fmoyfsJ\n"
- &= quot;IQDKKgbYgFw0MzVuDAmpRx6KTEihgTchkQx9fHddWbKiOUbcEnQi3LNux7P4QVl/\n&quo= t;
- "4dRR3skis= Bug6Vd5LXeBGZqmpu5XZiF4DgLz1lX21G0aOogFWkie2qGEcso40159\n"
<= span style=3D"color: hsl(0, 100%, 40%);">- "x9FBDl5A3sLP18ubeex0pd/= BzDFv6SLOTyVWO/GCNc8IX/i0uN4mLvoVU00SeqwT\n"

- "PnS+CRXrSq4JjGDJLsXl0/PlxkjsgU0yOOA0Z= 2d8Fzk3wClwP6Hc49BOMWKstUIh\n"
- "LbG2DcIv8l29EuEj2w3ju/7gkewol96XQ2twpPvpoVAaiVh/m7h= QUcQORQCD6eJc\n"
-= "DjOZVCArAgMBAAECggEACqkuWAAJ3cyCBVWrXs8eDmLTWV9i9DmYvtS75ixIn2rf\= n"
- "v3cl= 12YevN0f6FgKLuqZT3Vqdqq+DCVhuIIQ9QkKMH8BQpSdE9NCCsFyZ23o8Gtr\n"=
- "EQ7ymfecb+RFwYx7Np= qWrvZI32VJGArgPZH/zorLTTGYrAZbmBtHEqRsXOuEDw97\n"
- "slwwcWaa9ztaYC8/N/7fgsnydaCFSaOB= yRlWuyvSmHvn6ZwLv8ANOshY6fstC0Jb\n"
- "BW0GpSe9eZPjpl71VT2RtpghqLV5+iAoFDHoT+eZvBospc= UGtfcZSU7RrBjKB8+a\n"
- "U1d6hwKhduVs2peIQzl+FiOSdWriLcsZv79q4sBhsQKBgQDUDVTf5BGJ8apO= s/17\n"
- "= ;YVk+Ad8Ey8sXvsfk49psmlCRa8Z4g0LVXfrP94qzhtl8U5kE9hs3nEF4j/kX1ZWG\n"
- "k11tdsNTZN5x5= bbAgEgPA6Ap6J/uto0HS8G0vSv0lyBymdKA3p/i5Dx+8Nc9cGns\n"
- "LGI9MvviLX7pQFIkvbaCkdKwYwK= BgQDirowjWZnm7BgVhF0G1m3DY9nQTYYU185W\n"

- "UESaO5/nVzwUrA+FypJamD+AvmlSuY8rJeQAGAS6n= Qr9G8/617r+GwJnzRtxC6Vl\n"
- "4OF5BJRsD70oX4CFOOlycMoJ8tzcYVH7NI8KVocjxb+QW82hqSvEwSs= vnwwn3eOW\n"
- = "nr5u5vIHmQKBgCuc3lL6Dl1ntdZgEIdau0cUjXDoFUo589TwxBDIID/4gaZxoMJP\n&qu= ot;
- "hPFXAVDx= MDPw4azyjSB/47tPKTUsuYcnMfT8kynIujOEwnSPLcLgxQU5kgM/ynuw\n"
= - "qhNpQOwaVRMc7f2RTCMXPB= YDpNE/GJn5eu8JWGLpZovEreBeoHX0VffvAoGAVrWn\n"
- "+3mxykhzaf+oyg3KDNysG+cbq+tlDVVE+K5o= G0kePVYX1fjIBQmJ+QhdJ3y9jCbB\n"
- "UVveqzeZVXqHEw/kgoD4aZZmsdZfnVnpRa5/y9o1ZDUr50n+2n= zUe/u/ijlb77iK\n"
= - "Is04gnGJNoI3ZWhdyrSNfXjcYH+bKClu9OM4n7kCgYAorc3PAX7M0bsQrrqYxUS8= \n"
- "56U= U0YdhAgYitjM7Fm/0iIm0vDpSevxL9js4HnnsSMVR77spCBAGOCCZrTcI3Ejg\n"
- "xKDYzh1xlfMRjJBuB= u5Pd55ZAv9NXFGpsX5SO8fDZQJMwpcbQH36+UdqRRFDpjJ0\n"
- "ZbX6nKcJ7jciJVKJds59Jg=3D=3D\n&= quot;
- "-----E= ND PRIVATE KEY-----\n";
+static const char *const key3 =3D "-----BEGIN PRIVATE KEY----= -\n"
+ = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoI= BAQC7xFoR6fmoyfsJ\n"
+ "IQDKKgbYgFw0MzVuDAmpRx6KTEihgTc= hkQx9fHddWbKiOUbcEnQi3LNux7P4QVl/\n"
+ "4dRR3skisBug6Vd= 5LXeBGZqmpu5XZiF4DgLz1lX21G0aOogFWkie2qGEcso40159\n"
+ "= ;x9FBDl5A3sLP18ubeex0pd/BzDFv6SLOTyVWO/GCNc8IX/i0uN4mLvoVU00SeqwT\n"
+ = "PnS+CRXrSq4JjGDJLsXl0/PlxkjsgU0yOOA0Z2d8Fzk3wClwP6Hc49BOMW= KstUIh\n"
+ = "LbG2DcIv8l29EuEj2w3ju/7gkewol96XQ2twpPvpoV= AaiVh/m7hQUcQORQCD6eJc\n"
+ "DjOZVCArAgMBAAECggEACqkuWA= AJ3cyCBVWrXs8eDmLTWV9i9DmYvtS75ixIn2rf\n"
+ "v3cl12YevN= 0f6FgKLuqZT3Vqdqq+DCVhuIIQ9QkKMH8BQpSdE9NCCsFyZ23o8Gtr\n"
+ = "EQ7ymfecb+RFwYx7NpqWrvZI32VJGArgPZH/zorLTTGYrAZbmBtHEqRsXOuEDw97\n&qu= ot;

+ = "slwwcWaa9ztaYC8/N/7fgsnydaCFSaOByRlWuyvSmHvn6ZwLv8ANO= shY6fstC0Jb\n"
+= "BW0GpSe9eZPjpl71VT2RtpghqLV5+iAoFDHoT= +eZvBospcUGtfcZSU7RrBjKB8+a\n"
+ "U1d6hwKhduVs2peIQzl+F= iOSdWriLcsZv79q4sBhsQKBgQDUDVTf5BGJ8apOs/17\n"
+ "YVk= +Ad8Ey8sXvsfk49psmlCRa8Z4g0LVXfrP94qzhtl8U5kE9hs3nEF4j/kX1ZWG\n"
+ = "k11tdsNTZN5x5bbAgEgPA6Ap6J/uto0HS8G0vSv0lyBymdKA3p/i5Dx+8Nc9cG= ns\n"
+ = "LGI9MvviLX7pQFIkvbaCkdKwYwKBgQDirowjWZnm7BgVhF= 0G1m3DY9nQTYYU185W\n"
+ "UESaO5/nVzwUrA+FypJamD+AvmlSuY= 8rJeQAGAS6nQr9G8/617r+GwJnzRtxC6Vl\n"
+ "4OF5BJRsD70oX4= CFOOlycMoJ8tzcYVH7NI8KVocjxb+QW82hqSvEwSsvnwwn3eOW\n"
+ &quo= t;nr5u5vIHmQKBgCuc3lL6Dl1ntdZgEIdau0cUjXDoFUo589TwxBDIID/4gaZxoMJP\n"<= /span>
+ = "hPFXAVDxMDPw4azyjSB/47tPKTUsuYcnMfT8kynIujOEwnSPLcLgxQU5k= gM/ynuw\n"
+ = "qhNpQOwaVRMc7f2RTCMXPBYDpNE/GJn5eu8JWGLpZ= ovEreBeoHX0VffvAoGAVrWn\n"
+ "+3mxykhzaf+oyg3KDNysG+cbq= +tlDVVE+K5oG0kePVYX1fjIBQmJ+QhdJ3y9jCbB\n"
+ "UVveqzeZV= XqHEw/kgoD4aZZmsdZfnVnpRa5/y9o1ZDUr50n+2nzUe/u/ijlb77iK\n"
<= span style=3D"color: hsl(120, 100%, 40%);">+ = "Is04gnGJNoI3ZWhdyrSNfXjcYH+bKClu9OM4n7kCgYAorc3PAX7M0bsQrrqYxUS8\n&q= uot;

+ = "56UU0YdhAgYitjM7Fm/0iIm0vDpSevxL9js4HnnsSMVR77spCBAG= OCCZrTcI3Ejg\n"
= + "xKDYzh1xlfMRjJBuBu5Pd55ZAv9NXFGpsX5S= O8fDZQJMwpcbQH36+UdqRRFDpjJ0\n"
+ "ZbX6nKcJ7jciJVKJds59= Jg=3D=3D\n"
+ = "-----END PRIVATE KEY-----\n";
static const char *const hash3 =3D "2463628674E362578113F5= 08BA05F29EF142E979";
static const char *const cname3 = =3D "ovpn-test-rsa1";

@@ -163,4= +161,4 @@
static const char *const hash4 =3D "E1401D= 4497C944783E3D62CDBD2A1F69F5E5071E";
#define cname4 c= name3 /* same CN as that of cert3 */

-#endif /* CERT_DATA_H */
+#endif /* CERT_DATA_H = */
diff --git a/tests/unit_tests/openvpn/mock_management.c = b/tests/unit_tests/openvpn/mock_management.c
index c3e38b9.= .2adade5 100644
--- a/tests/unit_tests/openvpn/mock_managem= ent.c
+++ b/tests/unit_tests/openvpn/mock_management.c
@@ -43,8 +43,7 @@
}
char *
-manage= ment_query_pk_sig(struct management *man, const char *b64_data,
<= span style=3D"color: hsl(0, 100%, 40%);">- const cha= r *algorithm)

+manage= ment_query_pk_sig(struct management *man, const char *b64_data, const char = *algorithm)
{
return NULL;
= }
diff --git a/tests/unit_tests/openvpn/mock_msg.c b= /tests/unit_tests/openvpn/mock_msg.c
index b6ec744..6970ad8= 100644
--- a/tests/unit_tests/openvpn/mock_msg.c+++ b/tests/unit_tests/openvpn/mock_msg.c
@@ -72,8 += 72,7 @@
}

void-x_msg_va(const unsigned int fl= ags, const char *format,
+x_msg_va(const unsigned int flags, const char *format, va_list arg= list)
{
if (flags & M_FATAL)
{
@@ -108,7 +107,7 @@
= /* Keep compiler happy. Should not happen, mock_assert() does not return = */
exit(1);
}
-#else /* ifndef NO_CMOCKA */
+#else /* ifndef NO_CMOCKA */
void
assert_failed(const char *filename, int = line, const char *condition)
{
diff --git = a/tests/unit_tests/openvpn/mock_msg.h b/tests/unit_tests/openvpn/mock_msg.h=
index bc2ee5d..ffac529 100644
--- a/tests/= unit_tests/openvpn/mock_msg.h
+++ b/tests/unit_tests/openvp= n/mock_msg.h
@@ -36,13 +36,10 @@
extern bo= ol fatal_error_triggered;
extern char mock_msg_buf[MOCK_MS= G_BUF];

-void
-mock_set_debu= g_level(int level);
+= void mock_set_debug_level(int level);

-int
-mock_get_debug_level(void);
+int mock_get_debug_level(void);

-void
-mock_set_print_debug_level(int level);
+void mock_set_print_d= ebug_level(int level);

#endif /* MOCK_MS= G */
diff --git a/tests/unit_tests/openvpn/mock_ssl_depende= ncies.c b/tests/unit_tests/openvpn/mock_ssl_dependencies.c
= index 5cfe8d0..7ae0e69 100644
--- a/tests/unit_tests/openvp= n/mock_ssl_dependencies.c
+++ b/tests/unit_tests/openvpn/mo= ck_ssl_dependencies.c
@@ -38,8 +38,8 @@
#i= nclude "ssl_verify.h"

int
-parse_line(const char *lin= e, char **p, const int n, const char *file,
- const int line_num, int msglevel, struct g= c_arena *gc)
+parse_l= ine(const char *line, char **p, const int n, const char *file, const int li= ne_num,
+ i= nt msglevel, struct gc_arena *gc)
{
/= * Dummy function to get the linker happy, should never be called */<= br> assert_true(false);
diff --git a/tests/unit_t= ests/openvpn/pkey_test_utils.c b/tests/unit_tests/openvpn/pkey_test_utils.c=
index 9a044ec..4af80ac 100644
--- a/tests/= unit_tests/openvpn/pkey_test_utils.c
+++ b/tests/unit_tests= /openvpn/pkey_test_utils.c
@@ -57,14 +57,14 @@
size_t siglen =3D 0;

int ret =3D 0;
- OSSL_PARA= M params[2] =3D {OSSL_PARAM_END};
+ OSSL_PARAM params[2] =3D { OSSL_PARAM_END };
const char *mdname =3D "SHA256";


if (EVP_PKEY_get_id(privkey) =3D=3D EVP_PKEY_RSA) {
const char *padmode =3D "pss&qu= ot;; /* RSA_PSS: for all other params, use defaults */
- params[0] =3D OSSL_PARAM_construct= _utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE,
- = (char *)padmode, 0);
= + params[0] =3D
- if (!mctx
- || EVP_DigestSignInit_ex(mctx, &pctx, m= dname, tls_libctx, NULL, privkey, params) <=3D 0)
+ if (!mctx || EVP_DigestSignInit_ex(mc= tx, &pctx, mdname, tls_libctx, NULL, privkey, params) <=3D 0)=
{
/* cmocka assert output for these= kinds of failures is hardly explanatory,
* print= a message and assert in caller. */
@@ -116,7 +115,7 @@

mctx =3D EVP_MD_CTX_new();
pctx =3D = NULL;
if (!mctx
- || EVP_DigestVerifyInit_ex(mctx, &pctx, mdname, = tls_libctx, NULL, pubkey, params) <=3D 0)
+ || EVP_DigestVerifyInit_ex(mctx, &pct= x, mdname, tls_libctx, NULL, pubkey, params) <=3D 0)
= {
print_error("Failed to initialize EVP_Dig= estVerifyInit_ex()");
goto done;
diff --git a/tests/unit_tests/openvpn/test_argv.c b/tests/unit_tests/op= envpn/test_argv.c

index 33b3dec..a65857b 100644
<= span>--- a/tests/unit_tests/openvpn/test_argv.c

+++ b/tests= /unit_tests/openvpn/test_argv.c
@@ -15,15 +15,15 @@<= br> #include "test_common.h"

/* Defines for use in the tests and the mock parse_line() */
-#define PATH1 "/s p = a c e"
-#define PA= TH2 "/foo bar/baz"
-#define PARAM1 "param1"
-#define PARAM2 "param two"
-#define SCRIPT_CMD &qu= ot;\"" PATH1 PATH2 "\"" PARAM1 "\""= PARAM2 "\""
+#define PATH1 "/s p a c e"
+#define PATH2 "/foo bar/baz"
+#define PARAM1 &q= uot;param1"
+#de= fine PARAM2 "param two"
+#define SCRIPT_CMD "\"" PATH1 PATH2 "= \"" PARAM1 "\"" PARAM2 "\""<= br>
int
-__wrap_parse_line(const char *line, char **p, const int n, const = char *file,
- = const int line_num, int msglevel, struct gc_arena *gc)
+__wrap_parse_line(const char *li= ne, char **p, const int n, const char *file, const int line_num,

= + int msglevel= , struct gc_arena *gc)
{
p[0] =3D PAT= H1 PATH2;
p[1] =3D PARAM1;
@@ -201,10 = +201,10 @@
argv_printf_cat(&a, "%s", PAR= AM2);
argv_printf_cat(&a, "%d", -1);
argv_printf_cat(&a, "%u", -1);
- argv_printf_cat(&a, "= %lu", 1L );

+ = argv_printf_cat(&a, "%lu", 1L);
output = =3D argv_str(&a, &gc, PA_BRACKET);
assert_stri= ng_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [= " PARAM2 "]"
- " [-1] [4294967295] [1]");+ = " [-1] [4294967295] [1]");

= argv_free(&a);
gc_free(&gc);
diff --git a/tests/unit_tests/openvpn/test_auth_token.c b/tests/unit_te= sts/openvpn/test_auth_token.c

index be3b2b7..ba2a1d0 100644=
--- a/tests/unit_tests/openvpn/test_auth_token.c+++ b/tests/unit_tests/openvpn/test_auth_token.c
@@ = -37,7 +37,8 @@
#include "auth_token.c" #include "test_common.h"

-struct test_context {

+struct test_context

+{

struct tls_= multi multi;
struct key_type kt;
= struct user_pass up;
@@ -53,10 +54,10 @@
v= oid
auth_set_client_reason(struct tls_multi *multi, const = char *reason)
{
-
}

-static const char *now0key0 =3D "SESS_ID_AT= _0123456789abcdefAAAAAAAAAAAAAAAAAAAAAE5JsQJOVfo8jnI3RL3tBaR5NkE4yPfcylFUHm= HSc5Bu";
+static= const char *now0key0 =3D
+ "SESS_ID_AT_0123456789abcdefAAAAAAAAAAAAAAAAAAAAAE5JsQJOVfo8= jnI3RL3tBaR5NkE4yPfcylFUHmHSc5Bu";

= static const char *zeroinline =3D "-----BEGIN OpenVPN auth-token serve= r key-----\n"
"A= AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"
@@ -64,21 +65,24 @@
= "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=3D\n"<= br> "-----END OpenVPN auth-token= server key-----";

-static const char *allx01inline =3D "-----BEGIN Op= enVPN auth-token server key-----\n"
- "AQEBAQEBAQEBAQEB= AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n"
- "= AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n"
- = "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=3D\n"
- = "-----END OpenVPN auth-token server key-----";
= +static const char *allx01inlin= e =3D
+ "----= -BEGIN OpenVPN auth-token server key-----\n"
+ "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE= BAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n"
+ "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE= BAQEBAQEBAQEBAQEB\n"
+ "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=3D\n"
+ "-----END OpenV= PN auth-token server key-----";

-static const char *random_key =3D "--= ---BEGIN OpenVPN auth-token server key-----\n"
- "+mmmf= 7IQ5cymtMVjKYTWk8IOcYanRlpQmV9Tb3EjkHYxueBVDg3yqRgzeBlVGzNLD//rAPiOVhau\n&q= uot;
- = "3NDBjNOQB8951bfs7Cc2mYfay92Bh2gRJ5XEM/DMfzCWN+7uU6NWoT= THr4FuojnIQtjtqVAj/JS9\n"
- "w+dTSp/vYHl+c7uHd19uVRu/qLqV= 85+rm4tUGIjO7FfYuwyPqwmhuIsi3hs9QkSimh888FmBpoKY\n"
- "/t= bKVTJZmSERKti9KEwtV2eVAR0znN5KW7lCB3mHVAhN7bUpcoDjfCzYIFARxwswTFu9gFkwqUMY\= n"
- = "I1KUOgIsVNs4llACioeXplYekWETR+YkJwDc/A=3D=3D\n"= ;
- = "-----END OpenVPN auth-token server key-----";=
+static const char *random_= key =3D
+ "--= ---BEGIN OpenVPN auth-token server key-----\n"
+ "+mmmf7IQ5cymtMVjKYTWk8IOcYanRlp= QmV9Tb3EjkHYxueBVDg3yqRgzeBlVGzNLD//rAPiOVhau\n"
+ "3NDBjNOQB8951bfs7Cc2mYfay92Bh2g= RJ5XEM/DMfzCWN+7uU6NWoTTHr4FuojnIQtjtqVAj/JS9\n"
+ "w+dTSp/vYHl+c7uHd19uVRu/qLqV85+= rm4tUGIjO7FfYuwyPqwmhuIsi3hs9QkSimh888FmBpoKY\n"
+ "/tbKVTJZmSERKti9KEwtV2eVAR0znN5= KW7lCB3mHVAhN7bUpcoDjfCzYIFARxwswTFu9gFkwqUMY\n"
+ "I1KUOgIsVNs4llACioeXplYekWETR+Y= kJwDc/A=3D=3D\n"
+ "-----END OpenVPN auth-token server key-----";

-static const cha= r *random_token =3D "SESS_ID_AT_ThhRItzOKNKrh3dfAAAAAFwzHpwAAAAAXDMenD= drq0RoH3dkA1f7O3wO+7kZcx2DusVZrRmFlWQM9HOb";
+static const char *random_token =3D+ "SESS_ID_AT_ThhRItzO= KNKrh3dfAAAAAFwzHpwAAAAAXDMenDdrq0RoH3dkA1f7O3wO+7kZcx2DusVZrRmFlWQM9HOb&qu= ot;;


static int=
@@ -88,7 +92,7 @@
*state =3D ctx;
=
struct key_parameters key =3D { 0 };- key.hmac_size =3D MAX_HMAC_= KEY_LENGTH; /* 64 byte of 0 */
+ key.hmac_size =3D MAX_HMAC_KEY_LENGTH; /* 64 byte of 0 *= /

ctx->kt =3D auth_token_kt();
if (!ctx->kt.digest)
@@ -116,7 +120,7= @@
static int
teardown(void **state)
{
- st= ruct test_context *ctx =3D (struct test_context *) *state;
+ struct test_context *ctx =3D (st= ruct test_context *)*state;

free_key= _ctx(&ctx->multi.opt.auth_token_key);
wipe_auth= _token(&ctx->multi);
@@ -130,23 +134,21 @@ static void
auth_token_basic_test(void **state)
{
- s= truct test_context *ctx =3D (struct test_context *) *state;
+ struct test_context *ctx =3D (s= truct test_context *)*state;


generat= e_auth_token(&ctx->up, &ctx->multi);
str= cpy(ctx->up.password, ctx->multi.auth_token);
- assert_int_equal(verify_auth_token(&= ;ctx->up, &ctx->multi, ctx->session),
- AUTH_TOKEN_HMAC_OK);
+ assert_int_equal(ver= ify_auth_token(&ctx->up, &ctx->multi, ctx->session), AUTH_= TOKEN_HMAC_OK);
}

stati= c void
auth_token_fail_invalid_key(void **state) {
- struct t= est_context *ctx =3D (struct test_context *) *state;
+ struct test_context *ctx =3D (struct = test_context *)*state;

generate_auth= _token(&ctx->up, &ctx->multi);
strcpy(ct= x->up.password, ctx->multi.auth_token);
- assert_int_equal(verify_auth_token(&ctx->= ;up, &ctx->multi, ctx->session),
- AUTH_TOKEN_HMAC_OK);
+ assert_int_equal(verify_auth= _token(&ctx->up, &ctx->multi, ctx->session), AUTH_TOKEN_HM= AC_OK);


/* Change auth-token key */<= /span>
struct key_parameters key;
@@ -162,15 = +164,13 @@
memset(&key.hmac, 0, sizeof(key.hmac));=
free_key_ctx(&ctx->multi.opt.auth_token_key);<= /span>
init_key_ctx(&ctx->multi.opt.auth_token_key, &a= mp;key, &ctx->kt, false, "TEST");
- assert_int_equal(verify_auth_token(&ct= x->up, &ctx->multi, ctx->session),
- AUTH_TOKEN_HMAC_OK);<= br>-
+ assert_int_equal(verify_auth_token(&ctx-= >up, &ctx->multi, ctx->session), AUTH_TOKEN_HMAC_OK); }

static void
= auth_token_test_timeout(void **state)
{
- struct test_context *ctx =3D (struct= test_context *) *state;
+ struct test_context *ctx =3D (struct test_context *)*state;=

now =3D 100000;
gener= ate_auth_token(&ctx->up, &ctx->multi);
@@ -18= 0,33 +180,31 @@
ctx->multi.auth_token_initial =3D N= ULL;

/* No time has passed */=
- assert_int_equal(verify_= auth_token(&ctx->up, &ctx->multi, ctx->session),- AUTH_TOKEN= _HMAC_OK);
+ asser= t_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->= session), AUTH_TOKEN_HMAC_OK);

/* To= ken before validity, should be rejected */
now =3D 100= 000 - 100;
assert_int_equal(verify_auth_token(&ctx= ->up, &ctx->multi, ctx->session),
- AUTH_TOKEN_HMAC_OK|AUTH_TOKEN= _EXPIRED);
+ = AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED);

/* Token no valid for renegotiate_seconds but still for r= enewal_time */
- now= =3D 100000 + 2*ctx->session->opt->renegotiate_seconds - 20;
+ now =3D 100000 + 2 * = ctx->session->opt->renegotiate_seconds - 20;
= assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx= ->session),
- = AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED);
+ AUTH_TOKEN_HMAC_OK |= AUTH_TOKEN_EXPIRED);


- now =3D 100000 + 2*ctx->session-= >opt->auth_token_renewal - 20;
- assert_int_equal(verify_auth_token(&ctx->up, &= ;ctx->multi, ctx->session),
- AUTH_TOKEN_HMAC_OK);
+ now =3D 100000 + 2 * ctx->session-= >opt->auth_token_renewal - 20;
+ assert_int_equal(verify_auth_token(&ctx->up, &a= mp;ctx->multi, ctx->session), AUTH_TOKEN_HMAC_OK);
<= /span>
/* Token past validity, should be rejected */- now =3D 100000 + 2*ctx->= ;session->opt->renegotiate_seconds + 20;
+ now =3D 100000 + 2 * ctx->session->opt= ->renegotiate_seconds + 20;
assert_int_equal(verify= _auth_token(&ctx->up, &ctx->multi, ctx->session),- AUTH_TOKE= N_HMAC_OK|AUTH_TOKEN_EXPIRED);
+ AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED);

/* But not when we reached our timeou= t */
now =3D 100000 + ctx->session->opt->auth= _token_lifetime + 1;
assert_int_equal(verify_auth_toke= n(&ctx->up, &ctx->multi, ctx->session),
- AUTH_TOKEN_HMAC_OK|= AUTH_TOKEN_EXPIRED);
= + AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED);
<= span>

free(ctx->multi.auth_token_initial);<= br> ctx->multi.auth_token_initial =3D NULL;
@@= -224,26 +222,25 @@


= assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, c= tx->session),
- = AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED);
+ AUTH_TOKEN_HMAC_OK= | AUTH_TOKEN_EXPIRED);
ctx->multi.opt.auth_token_l= ifetime =3D 0;

/* Non expiring token= should be fine */
- = assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ct= x->session),
- = AUTH_TOKEN_HMAC_OK);
+ assert_int_equal(verify_auth_token(&ctx->up, &am= p;ctx->multi, ctx->session), AUTH_TOKEN_HMAC_OK);
}<= /span>

static void
zerohmac(ch= ar *token)
{
- char *hmacstart =3D token + AUTH_TOKEN_SESSION_ID_LEN- + strlen(= SESSION_ID_PREFIX) + 2*sizeof(uint64_t);
+ char *hmacstart =3D
+ token + AUTH_TOKEN_SESSION_ID_LEN + strlen= (SESSION_ID_PREFIX) + 2 * sizeof(uint64_t);
memset(hma= cstart, 0x8d, strlen(hmacstart));
}

static void
auth_token_test_known_keys(void *= *state)
{
- struct test_context *ctx =3D (struct test_context *) *state;
+ struct test_context *= ctx =3D (struct test_context *)*state;

= now =3D 0;
/* Preload the session id so the same se= ssion id is used here */
@@ -258,8 +255,7 @@
assert_string_equal(now0key0, ctx->multi.auth_token);

<= span>

strcpy(ctx->up.password, ctx->multi.auth_= token);
- assert_int= _equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->sessi= on),
- = AUTH_TOKEN_HMAC_OK);
+ assert_int_equal(verify_auth_token(&ctx->up, &ctx->m= ulti, ctx->session), AUTH_TOKEN_HMAC_OK);
}
<= span>

static const char *lastsesion_statevalue;@@ -275,13 +271,12 @@
void
auth_to= ken_test_session_mismatch(void **state)
{
- struct test_context *ctx =3D (stru= ct test_context *) *state;
+ struct test_context *ctx =3D (struct test_context *)*state;

/* Generate first auth token and check i= t is correct */
generate_auth_token(&ctx->up, &= amp;ctx->multi);
strcpy(ctx->up.password, ctx-&g= t;multi.auth_token);
- = assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, = ctx->session),
- = AUTH_TOKEN_HMAC_OK);
+ assert_int_equal(verify_auth_token(&ctx->up, &= amp;ctx->multi, ctx->session), AUTH_TOKEN_HMAC_OK);
=
char *token_sessiona =3D strdup(ctx->multi.auth_to= ken);

@@ -290,8 +285,7 @@

generate_auth_token(&ctx->up, &ctx->m= ulti);
strcpy(ctx->up.password, ctx->multi.auth_= token);
- assert_int= _equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->sessi= on),
- = AUTH_TOKEN_HMAC_OK);
+ assert_int_equal(verify_auth_token(&ctx->up, &ctx->m= ulti, ctx->session), AUTH_TOKEN_HMAC_OK);

assert_int_not_equal(0, memcmp(ctx->multi.auth_token_initial + = strlen(SESSION_ID_PREFIX),

= token_sessiona + strlen(SESSION_ID_PREFIX),
@@ -307,39 = +301,37 @@
static void
auth_token_test_em= pty_user(void **state)
{
- struct test_context *ctx =3D (struct test_context *= ) *state;
+ struct= test_context *ctx =3D (struct test_context *)*state;

CLEAR(ctx->up.username);
now =3D = 0;

generate_auth_token(&ctx->= up, &ctx->multi);
strcpy(ctx->up.password, c= tx->multi.auth_token);
- assert_int_equal(verify_auth_token(&ctx->up, &ctx->mu= lti, ctx->session),
= - AUTH_TOKEN_HMAC_OK);
+ assert_int_equal(verify_auth_token(&ctx->= up, &ctx->multi, ctx->session), AUTH_TOKEN_HMAC_OK);

now =3D 100000;
assert_int_= equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->sessio= n),
- = AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED);
+ AUTH_TOKEN_HMAC_OK | AUTH_TOKEN= _EXPIRED);
strcpy(ctx->up.username, "test user= name");

now =3D 0;
<= span> assert_int_equal(verify_auth_token(&ctx->up, &ctx->= multi, ctx->session),

+ AU= TH_TOKEN_HMAC_OK | AUTH_TOKEN_VALID_EMPTYUSER);
strcpy(ctx->up.username, "test user name");=
now =3D 100000;
assert_int_equal(verify= _auth_token(&ctx->up, &ctx->multi, ctx->session),- AUTH_TOKE= N_HMAC_OK|AUTH_TOKEN_EXPIRED|AUTH_TOKEN_VALID_EMPTYUSER);
+ AUTH_TOKEN_HMAC_= OK | AUTH_TOKEN_EXPIRED | AUTH_TOKEN_VALID_EMPTYUSER);

zerohmac(ctx->up.password);
- assert_int_equal(verify_auth_token(&ctx= ->up, &ctx->multi, ctx->session),
- 0);
+ assert_int_equal(verify_auth_token(&c= tx->up, &ctx->multi, ctx->session), 0);
}

static void
auth_token_tes= t_env(void **state)
{
- struct test_context *ctx =3D (struct test_context *) *= state;
+ struct te= st_context *ctx =3D (struct test_context *)*state;
=
struct key_state *ks =3D &ctx->multi.session[TM_ACTIV= E].key[KS_PRIMARY];

@@ -357,15 +349,16 @@=
add_session_token_env(ctx->session, &ctx->m= ulti, &ctx->up);
assert_string_equal(lastsesion= _statevalue, "Authenticated");

- ks->auth_token_state_flags =3D = AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_EXPIRED;
+ ks->auth_token_state_flags =3D AUTH_TOKEN_HMAC_OK= | AUTH_TOKEN_EXPIRED;
add_session_token_env(ctx->s= ession, &ctx->multi, &ctx->up);
assert_s= tring_equal(lastsesion_statevalue, "Expired");
<= /span>
- ks->auth_token_= state_flags =3D AUTH_TOKEN_HMAC_OK|AUTH_TOKEN_VALID_EMPTYUSER;
+ ks->auth_token_state_flag= s =3D AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_VALID_EMPTYUSER;

= add_session_token_env(ctx->session, &ctx->multi, &ctx->up= );
assert_string_equal(lastsesion_statevalue, "Au= thenticatedEmptyUser");

- ks->auth_token_state_flags =3D AUTH_TOKEN_H= MAC_OK|AUTH_TOKEN_EXPIRED|AUTH_TOKEN_VALID_EMPTYUSER;
+ ks->auth_token_state_flags =3D
+ AUTH_TOKEN_HMAC= _OK | AUTH_TOKEN_EXPIRED | AUTH_TOKEN_VALID_EMPTYUSER;
= add_session_token_env(ctx->session, &ctx->multi, &ctx->up= );
assert_string_equal(lastsesion_statevalue, "Ex= piredEmptyUser");
}
@@ -373,7 +366,7 = @@
static void
auth_token_test_random_key= s(void **state)
{
- struct test_context *ctx =3D (struct test_context *) *stat= e;
+ struct test_c= ontext *ctx =3D (struct test_context *)*state;

= now =3D 0x5c331e9c;
/* Preload the session = id so the same session id is used here */
@@ -398,7 +391,7 = @@
static void
auth_token_test_key_load(v= oid **state)
{
- struct test_context *ctx =3D (struct test_context *) *state;<= /span>
+ struct test_cont= ext *ctx =3D (struct test_context *)*state;

free_key_ctx(&ctx->multi.opt.auth_token_key);

auth_token_init_secret(&ctx->multi.opt.auth_token_key, zeroin= line, true);

diff --git a/tests/unit_tests/openvpn/test_buf= fer.c b/tests/unit_tests/openvpn/test_buffer.c
index 3a1007= a..c5d5557 100644
--- a/tests/unit_tests/openvpn/test_buffe= r.c
+++ b/tests/unit_tests/openvpn/test_buffer.c
= @@ -44,13 +44,13 @@
assert_false(strprefix("= ;12", "123"));
}
-#define testsep ","<= /span>
+#define testsep &q= uot;,"
#define testnosep ""
-#define teststr1 "one"
-#define teststr2 "two= "
-#define teststr= 3 "three"
+= #define teststr1 "one"
+#define teststr2 "two"
+#define teststr3 "three"
<= span>

-#define assert_= buf_equals_str(buf, str) \
+#define assert_buf_equals_str(buf, str) \
= assert_int_equal(BLEN(buf), strlen(str)); \
assert_me= mory_equal(BPTR(buf), str, BLEN(buf));

@@= -83,9 +83,7 @@
test_buffer_format_hex_ex(void **state)
{
const int input_size =3D 10;- const uint8_t input[] =3D = {
- 0x01, 0x00, = 0xff, 0x10, 0xff, 0x00, 0xf0, 0x0f, 0x09, 0x0a
- };
+ const uint8_t input[] =3D { 0x01, 0x00, 0xff, 0x10, 0xff, 0= x00, 0xf0, 0x0f, 0x09, 0x0a };
char *output; struct gc_arena gc =3D gc_new();

@@ -114,7 +112,8 @@

gc_free(&gc);
}


+struct test_buffer_list_aggregate_ctx
+{

struct buff= er_list *empty;
struct buffer_list *one_two_three;
struct buffer_list *zero_length_strings;
= @@ -124,7 +123,7 @@
static int
test_buffe= r_list_setup(void **state)
{
- struct test_buffer_list_aggregate_ctx *ctx =3D= calloc(1, sizeof(*ctx));
+ struct test_buffer_list_aggregate_ctx *ctx =3D calloc(1, sizeof(*= ctx));
ctx->empty =3D buffer_list_new();
=
ctx->one_two_three =3D buffer_list_new();
@@ -189,8 +188,7 @@
/* Aggregate the fi= rst two elements
* (add 1 to max_len to test if "= ;three" is not sneaked in too)
*/
- buffer_list_aggregate_separator(= ctx->one_two_three, strlen(expected) + 1,

- testsep);=
+ buffer_list_aggregate_= separator(ctx->one_two_three, strlen(expected) + 1, testsep);
= assert_int_equal(ctx->one_two_three->size, 2);
<= span> struct buffer *buf =3D buffer_list_peek(ctx->one_two_three);
assert_buf_equals_str(buf, expected);
@= @ -202,11 +200,10 @@
struct test_buffer_list_aggregate= _ctx *ctx =3D *state;

/* Aggregate a= ll */
- buffer_list_= aggregate_separator(ctx->one_two_three, 1<<16, testsep);+ buffer_list_aggregate_sep= arator(ctx->one_two_three, 1 << 16, testsep);
= assert_int_equal(ctx->one_two_three->size, 1);
= struct buffer *buf =3D buffer_list_peek(ctx->one_two_three);
<= span style=3D"color: hsl(0, 100%, 40%);">- assert_buf_equals_str(buf,
- = teststr1 testsep teststr2 testsep teststr3 testsep);
+ assert_buf_equals_str(buf, teststr1 = testsep teststr2 testsep teststr3 testsep);
}

static void
@@ -215,7 +212,7 @@
struct test_buffer_list_aggregate_ctx *ctx =3D *state;

/* Aggregate all */
- buffer_list_aggregate_separator(ctx-&= gt;one_two_three, 1<<16, testnosep);
+ buffer_list_aggregate_separator(ctx->one_two_= three, 1 << 16, testnosep);
assert_int_equal(ctx= ->one_two_three->size, 1);
struct buffer *buf = =3D buffer_list_peek(ctx->one_two_three);
assert_bu= f_equals_str(buf, teststr1 teststr2 teststr3);
@@ -228,7 +2= 25,7 @@
struct buffer_list *bl_zerolen =3D ctx->zer= o_length_strings;

/* Aggregate all *= /
- buffer_list_aggr= egate_separator(bl_zerolen, 1<<16, testnosep);
+ buffer_list_aggregate_separator(bl_ze= rolen, 1 << 16, testnosep);
assert_int_equal(bl_= zerolen->size, 1);
struct buffer *buf =3D buffer_li= st_peek(bl_zerolen);
assert_buf_equals_str(buf, "= ");
@@ -241,7 +238,7 @@
struct bu= ffer_list *bl_emptybuffers =3D ctx->empty_buffers;

/* Aggregate all */
- buffer_list_aggregate_separator(bl_emptybuffers, 1<&= lt;16, testnosep);
+ = buffer_list_aggregate_separator(bl_emptybuffers, 1 << 16, testnose= p);
assert_int_equal(bl_emptybuffers->size, 1);
struct buffer *buf =3D buffer_list_peek(bl_emptybuffers);=
assert_int_equal(BLEN(buf), 0);
@@ -3= 45,11 +342,12 @@
assert_string_equal(buf, "There.= is...a.nice......year.old.tr..ee.");

strcpy(buf, "There is \x01 a 'nice' \"1234\"\n= year old \ntr\x7f ee!");

- assert_false(string_mod(buf, CC_ALPHA|CC_DIGIT|CC_NEWLINE|CC_S= INGLE_QUOTE, CC_DOUBLE_QUOTE|CC_BLANK, '.'));
+ assert_false(string_mod(buf, CC_ALPHA= | CC_DIGIT | CC_NEWLINE | CC_SINGLE_QUOTE,
+ CC_DOUBLE_QUOTE | CC_BL= ANK, '.'));
assert_string_equal(buf, "The= re.is...a.'nice'..1234.\n.year.old.\ntr..ee.");

strcpy(buf, "There is a \\'nice\\' \&= quot;1234\" [*] year old \ntree!");
- assert_false(string_mod(buf, CC_PRINT, CC_BACKS= LASH|CC_ASTERISK, '.'));
+ assert_false(string_mod(buf, CC_PRINT, CC_BACKSLASH | CC_A= STERISK, '.'));
assert_string_equal(buf, "= ;There is a .'nice.' \"1234\" [.] year old .tree!");=
}

@@ -361,7 +359,7 @@

struct buffer buf =3D alloc_buf_gc(10= 24, &gc);

- const char test1[] =3D "There is a nice 1234\x00 year o= ld tree!";
+ = const char test1[] =3D "There is a nice 1234\x00 year old tree!";=
buf_write(&buf, test1, sizeof(test1));
=
/* allow the null bytes and string but not the= ! */
@@ -433,7 +431,7 @@
struct gc_ar= ena gc =3D gc_new();
struct buffer buf =3D alloc_buf_g= c(1024, &gc);

- const char test1[] =3D "There is a nice 1234 year o= ld tree!\n\r";
+= const char test1[] =3D "There is a nice 1234 year old tree!\n\r&qu= ot;;
buf_write(&buf, test1, sizeof(test1));=
buf_chomp(&buf);
/* Check that our = own method agrees */
@@ -441,7 +439,7 @@
= assert_string_equal(BSTR(&buf), "There is a nice 1234 year old = tree!");

struct buffer buf2 =3D= alloc_buf_gc(1024, &gc);
- const char test2[] =3D "CR_RESPONSE,MTIx\x0a\x00";
+ const char test2[= ] =3D "CR_RESPONSE,MTIx\x0a\x00";
buf_write(= &buf2, test2, sizeof(test2));
buf_chomp(&buf2)= ;

@@ -462,26 +460,19 @@
= cmocka_unit_test(test_buffer_printf_catrunc),
= cmocka_unit_test(test_buffer_format_hex_ex),
c= mocka_unit_test_setup_teardown(test_buffer_list_aggregate_separator_empty,<= /span>
- = test_buffer_list_setup,
- test_buffer_lis= t_teardown),
+ = test_buffer_list_setup, test_buffer_list_t= eardown),
cmocka_unit_test_setup_teardown(test_buf= fer_list_aggregate_separator_noop,
- test_buffer_list_setup= ,
- = test_buffer_list_teardown),
+ test_bu= ffer_list_setup, test_buffer_list_teardown),
cmock= a_unit_test_setup_teardown(test_buffer_list_aggregate_separator_two,=
- = test_buffer_list_setup,
- test_buffer_list_tear= down),
+ = test_buffer_list_setup, test_buffer_list_teardow= n),
cmocka_unit_test_setup_teardown(test_buffer_li= st_aggregate_separator_all,
- test_buffer_list_setup,
- = test_buffer_list_teardown),
+ test_buffer_li= st_setup, test_buffer_list_teardown),
cmocka_unit_= test_setup_teardown(test_buffer_list_aggregate_separator_nosep,
<= span style=3D"color: hsl(0, 100%, 40%);">- = test_buffer_list_setup,

- test_buffer_list_teardown)= ,
+ = test_buffer_list_setup, test_buffer_list_teardown),
cmocka_unit_test_setup_teardown(test_buffer_list_ag= gregate_separator_zerolen,
- test_buffer_list_setup,=
- = test_buffer_list_teardown),
+ test_buffer_lis= t_setup, test_buffer_list_teardown),
cmocka_unit_t= est_setup_teardown(test_buffer_list_aggregate_separator_emptybuffers,
- = test_buffer_list_setup,
- test_buffer_list_tea= rdown),
+ = test_buffer_list_setup, test_buffer_list_teardo= wn),
cmocka_unit_test(test_buffer_free_gc_one),
cmocka_unit_test(test_buffer_free_gc_two), cmocka_unit_test(test_buffer_gc_realloc),
d= iff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_tests/openv= pn/test_crypto.c
index 5b583c7..c06d0f9 100644
--- a/tests/unit_tests/openvpn/test_crypto.c

+++ b/test= s/unit_tests/openvpn/test_crypto.c
@@ -157,7 +157,7 @@
const size_t seed_len =3D strlen(seedstr);


- = const unsigned char *secret =3D (const unsigned char *) ipsumlorem;
+ const unsigned char = *secret =3D (const unsigned char *)ipsumlorem;
size_t = secret_len =3D strlen((const char *)secret);


@@ -169,18 +169,16 @@
assert_fal= se(ret);
#else
assert_true(ret);
- uint8_t good_prf[32] = =3D {0xd9, 0x8c, 0x85, 0x18, 0xc8, 0x5e, 0x94, 0x69,
- 0x27, 0x91, 0x6= a, 0xcf, 0xc2, 0xd5, 0x92, 0xfb,
- 0xb1, 0x56, 0x7e, 0x4b, 0x4b, 0x14, = 0x59, 0xe6,
- = 0xa9, 0x04, 0xac, 0x2d, 0xda, 0xb7, 0x2d, 0x67};+ uint8_t good_prf[32] =3D= { 0xd9, 0x8c, 0x85, 0x18, 0xc8, 0x5e, 0x94, 0x69, 0x27, 0x91, 0x6a,=
+ = 0xcf, 0xc2, 0xd5, 0x92, 0xfb, 0xb1, 0x56, 0x7e, 0x4b, 0x4b, 0x14,=
+ = 0x59, 0xe6, 0xa9, 0x04, 0xac, 0x2d, 0xda, 0xb7, 0x2d, 0x67 };
= assert_memory_equal(good_prf, out, sizeof(out));
#endif

}

-static uint8_t testkey[20] =3D {0x0b, 0x00};=
-static uint8_t goodhash[20] = =3D {0x58, 0xea, 0x5a, 0xf0, 0x42, 0x94, 0xe9, 0x17,
- 0xed, 0x84, = 0xb9, 0xf0, 0x83, 0x30, 0x23, 0xae,
- 0x8b, 0xa7, 0x7e, 0xb8};
+static uint8_t testkey[20= ] =3D { 0x0b, 0x00 };
+static uint8_t goodhash[20] =3D { 0x58, 0xea, 0x5a, 0xf0, 0x42, 0x94, 0xe= 9, 0x17, 0xed, 0x84,
= + 0xb9, 0xf0, 0x83, 0x30, 0x23, 0xae, 0x8b, = 0xa7, 0x7e, 0xb8 };

static void crypto_test_hmac(void **state)
@@ -193,8 +191,8 @@=
memcpy(key, testkey, sizeof(key));
<= /span>
hmac_ctx_init(hmac, key, "SHA1");
= - hmac_ctx_update(hmac, (const= uint8_t *)ipsumlorem, (int) strlen(ipsumlorem));
- hmac_ctx_update(hmac, (const uint8_t *)ipsu= mlorem, (int) strlen(ipsumlorem));
+ hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int)= strlen(ipsumlorem));
= + hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int)strlen(ipsumlo= rem));

uint8_t hash[20];
<= span> hmac_ctx_final(hmac, hash);

@@ -204,8 +202,8 @@

/* try again */
= hmac_ctx_reset(hmac);
-= hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int) strlen(ipsumlo= rem));
- hmac_ctx_up= date(hmac, (const uint8_t *)ipsumlorem, (int) strlen(ipsumlorem));+ hmac_ctx_update(hmac, (c= onst uint8_t *)ipsumlorem, (int)strlen(ipsumlorem));
+ hmac_ctx_update(hmac, (const uint8_t = *)ipsumlorem, (int)strlen(ipsumlorem));
hmac_ctx_final= (hmac, hash);

assert_memory_equal(ha= sh, goodhash, sizeof(hash));
@@ -214,8 +212,8 @@
= memset(key, 0x55, sizeof(key));

hmac_ctx_reset(hmac);

- hmac_ctx_update(hmac, (const uint8_t *)ipsumlorem, (int) strlen(= ipsumlorem));
- hmac= _ctx_update(hmac, (const uint8_t *)ipsumlorem, (int) strlen(ipsumlorem));
+ hmac_ctx_update(h= mac, (const uint8_t *)ipsumlorem, (int)strlen(ipsumlorem));
+ hmac_ctx_update(hmac, (const ui= nt8_t *)ipsumlorem, (int)strlen(ipsumlorem));

hmac_ctx= _final(hmac, hash);

assert_memory_eq= ual(hash, goodhash, sizeof(hash));
@@ -482,22 +480,16 @@
crypto_test_hkdf_expand_testa1(void **state)
{

/* RFC 5889 A.1 Test Case 1 */
- uint8_t prk[32] =3D
- {0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e= , 0x32, 0xdf,
- 0x0= d, 0xdc, 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63,
- 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31,=
- 0x22, 0xec, 0x84= , 0x4a, 0xd7, 0xc2, 0xb3, 0xe5};
+ uint8_t prk[32] =3D { 0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, = 0x32, 0xdf, 0x0d, 0xdc, 0x3f,
+ 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6,= 0xc7, 0x3b, 0xb5, 0x0f,
+ 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2= , 0xb3, 0xe5 };

- uint8_t info[10] =3D {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5,
- = 0xf6, 0xf7, 0xf8, 0xf9};
+ uint8_t info[10] =3D { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, = 0xf7, 0xf8, 0xf9 };

- uint8_t okm[42] =3D
- {0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
- 0x90, 0x43, 0x4f, 0x6= 4, 0xd0, 0x36, 0x2f, 0x2a,
- 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
- 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4= , 0xc5, 0xbf,
- 0x3= 4, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
- 0x58, 0x65};
+ uint8_t okm[42] =3D { 0x3c, 0xb2, 0x5f, 0x25, 0xfa= , 0xac, 0xd5, 0x7a, 0x90, 0x43, 0x4f,
+ 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2= d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a,
+ 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0x= ec, 0xc4, 0xc5, 0xbf, 0x34,
+ 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0= x58, 0x65 };

uint8_t out[42];=
ovpn_hkdf_expand(prk, info, sizeof(info), out, sizeof(out));=
@@ -509,39 +501,28 @@
crypto_test_hkdf_ex= pand_testa2(void **state)
{
/* RFC 58= 89 A.2 Test Case 2 */
-= uint8_t prk[32] =3D
- {0x06, 0xa6, 0xb8, 0x8c, 0x58, 0x53, 0x36, 0x1a,
- 0x06, 0x10, 0x4c, 0x9c, 0xeb, 0x35, 0= xb4, 0x5c,
- 0xef, = 0x76, 0x00, 0x14, 0x90, 0x46, 0x71, 0x01,
- 0x4a, 0x19, 0x3f, 0x40, 0xc1, 0x5f, 0xc2, 0x44};
+ uint8_t prk[32] = =3D { 0x06, 0xa6, 0xb8, 0x8c, 0x58, 0x53, 0x36, 0x1a, 0x06, 0x10, 0x4c,
+ = 0x9c, 0xeb, 0x35, 0xb4, 0x5c, 0xef, 0x76, 0x00, 0x14, 0x90, 0x46,+ 0x71= , 0x01, 0x4a, 0x19, 0x3f, 0x40, 0xc1, 0x5f, 0xc2, 0x44 };
=
- uint8_t info[80] = =3D
- {0xb0, 0xb1, 0= xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
- 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,- 0xc0, 0xc1, 0xc2, 0xc3, 0x= c4, 0xc5, 0xc6, 0xc7,
-= 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
- 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0x= d6, 0xd7,
- 0xd8, 0= xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
- 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
- 0xe8, 0xe9, 0xea, 0x= eb, 0xec, 0xed, 0xee, 0xef,
- 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
- 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xf= d, 0xfe, 0xff};
+ = uint8_t info[80] =3D { 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8= , 0xb9, 0xba, 0xbb,
+= 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0x= c4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, = 0xd0, 0xd1, 0xd2, 0xd3,
+ 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb= , 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0x= e7, 0xe8, 0xe9, 0xea, 0xeb,
+ 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, = 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe= , 0xff };

const int L =3D 82;=
- uint8_t okm[82] =3D
- {0xb1, 0x1e, 0x39, 0x8= d, 0xc8, 0x03, 0x27, 0xa1,
- 0xc8, 0xe7, 0xf7, 0x8c, 0x59, 0x6a, 0x49, 0x34,
- 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e= , 0xfa, 0xd8,
- 0xa= 0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c,
- 0x59, 0x04, 0x5a, 0x99, 0xca, 0xc7, 0x82, 0x72,=
- 0x71, 0xcb, 0x41= , 0xc6, 0x5e, 0x59, 0x0e, 0x09,
- 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8,
- 0x36, 0x77, 0x93, 0xa9, 0xac,= 0xa3, 0xdb, 0x71,

- = 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec, 0x3e, 0x87,
- 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, = 0x4f,
- 0x1d, 0x87}= ;
+ uint8_t okm[82= ] =3D { 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7, 0xf7, 0= x8c,
+ = 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e, 0xfa, = 0xd8,
+ = 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, 0x59, 0x04, 0x5a,= 0x99,
+ = 0xca, 0xc7, 0x82, 0x72, 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, 0x0e= , 0x09,
+ = 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8, 0x36, 0x77, 0x9= 3, 0xa9,
+ = 0xac, 0xa3, 0xdb, 0x71, 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec, 0x= 3e, 0x87,
+ = 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f, 0x1d, 0x87 };=

- = uint8_t out[82] =3D {0xaa};
+ uint8_t out[82] =3D { 0xaa };
ovpn_hkdf_e= xpand(prk, info, sizeof(info), out, L);

= assert_memory_equal(out, okm, L);
@@ -551,22 +532,17 @@=
crypto_test_hkdf_expand_testa3(void **state)
{

/* RFC 5889 A.3 Test Case 3 */
- uint8_t prk[32] =3D
- {0x19, 0xef, 0x24, 0xa3, 0x2c, 0= x71, 0x7b, 0x16,

- = 0x7f, 0x33, 0xa9, 0x1d, 0x6f, 0x64, 0x8b, 0xdf,
- 0x96, 0x59, 0x67, 0x76, 0xaf, 0xdb, 0x63, 0x= 77,
- 0xac, 0x43, 0= x4c, 0x1c, 0x29, 0x3c, 0xcb, 0x04};
+ uint8_t prk[32] =3D { 0x19, 0xef, 0x24, 0xa3, 0x2c, 0x7= 1, 0x7b, 0x16, 0x7f, 0x33, 0xa9,
+ 0x1d, 0x6f, 0x64, 0x8b, 0xdf, 0x96, 0x= 59, 0x67, 0x76, 0xaf, 0xdb,
+ 0x63, 0x77, 0xac, 0x43, 0x4c, 0x1c, 0x29, 0= x3c, 0xcb, 0x04 };

uint8_t info[] = =3D {};

int L =3D 42;
- uint8_t okm[42] =3D

- {0x8d, 0xa4, 0xe7, 0x75, 0xa5,= 0x63, 0xc1, 0x8f,

- = 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
- 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, = 0x9e,
- 0xc3, 0x45,= 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
- 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,<= br>- 0x96, 0xc8};
<= span style=3D"color: hsl(120, 100%, 40%);">+ uint8_t okm[42] =3D { 0x8d,= 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f, 0x80,

+ 0x2a, 0x06= , 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1,

+ 0x87, 0x9e, 0xc= 3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, 0x9d,
+ 0x20, 0x13, 0x95, 0x= fa, 0xa4, 0xb6, 0x1a, 0x96, 0xc8 };

= uint8_t out[42];
ovpn_hkdf_expand(prk, info, 0, out, L= );
@@ -580,23 +556,17 @@
/* tests the = HDKF with a label/okm that OpenVPN itself uses in OpenSSL 3
* HDKF unit test*/


- uint8_t prk[32] =3D
- {0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf= ,
- 0x0d, 0xdc, 0x3= f, 0x0d, 0xc4, 0x7b, 0xba, 0x63,
- 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31,
<= span style=3D"color: hsl(0, 100%, 40%);">- 0x22, 0xec, 0x84, 0x4a, 0xd7= , 0xc2, 0xb3, 0xe5};

= + uint8_t prk[32] =3D { 0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, = 0x0d, 0xdc, 0x3f,
+ = 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7, 0x3b,= 0xb5, 0x0f,
+ = 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5= };

-= uint8_t info[18] =3D
- 0x75, 0x6e, 0x69, 0x74, 0x20, 0x74, = 0x65, 0x73,
- 0x74,= 0x00};
+ uint8_t = info[18] =3D { 0x00, 0x1b, 0x0e, 0x6f, 0x76, 0x70, 0x6e, 0x20, 0x75,=
+ 0= x6e, 0x69, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, 0x00 };

int L =3D 27;
- uint8_t okm[27] =3D
- {0x87, 0x5a, 0x8e, 0xec, 0x18, 0x55, 0x63, 0x80,- 0xb8, 0xd9, 0x33, 0xed, 0x= 32, 0x3c, 0x2d, 0xf8,
-= 0xe8, 0xec, 0xcf, 0x49, 0x72, 0xe6, 0x83, 0xf0,
- 0x6a, 0x83, 0xac };
+ uint8_t okm[27] =3D { 0x87, 0x5a, = 0x8e, 0xec, 0x18, 0x55, 0x63, 0x80, 0xb8,
+ 0xd9, 0x33, 0xed, 0x32, 0x3c,= 0x2d, 0xf8, 0xe8, 0xec,
+ 0xcf, 0x49, 0x72, 0xe6, 0x83, 0xf0, 0x6a, 0x83= , 0xac };

uint8_t out[27]; ovpn_hkdf_expand(prk, info, sizeof(info), out, L);
@@ -607,19 +577,16 @@

void
crypto_tes= t_ovpn_label_expand(void **state)
{
- uint8_t secret[32] =3D
- {0x07, 0x77, 0x09, 0x36, 0x2c, 0x2= e, 0x32, 0xdf,
- 0x= 0d, 0xdc, 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63,
- 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31= ,
- 0x22, 0xec, 0x8= 4, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5};
+ uint8_t secret[32] =3D { 0x07, 0x77, 0x09, 0x36, 0x2c, 0x= 2e, 0x32, 0xdf, 0x0d, 0xdc, 0x3f,
+ 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90= , 0xb6, 0xc7, 0x3b, 0xb5, 0x0f,
+ 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, = 0xd7, 0xc2, 0xb3, 0xe5 };

- const uint8_t *label =3D (const uint8_t *) ("= ;unit test");
+ = const uint8_t *label =3D (const uint8_t *)("unit test");
uint8_t out[16];
ovpn_expand_label(sec= ret, sizeof(secret), label, 9, NULL, 0, out, sizeof(out));
=
- uint8_t out_expe= cted[16] =3D
- {0x18= , 0x5e, 0xaa, 0x1c, 0x7f, 0x22, 0x8a, 0xb8,
- 0xeb, 0x29, 0x77, 0x32, 0x14, 0xd9, 0x20, 0x46};=
+ uint8_t out_exp= ected[16] =3D { 0x18, 0x5e, 0xaa, 0x1c, 0x7f, 0x22, 0x8a, 0xb8,
<= span style=3D"color: hsl(120, 100%, 40%);">+ = 0xeb, 0x29, 0x77, 0x32, 0x14, 0xd9, 0x20, 0x46 };


assert_memory_equal(out, out_expected, 16);
}

@@ -631,15 +598,13 @@
* openvpn_PRF i= fdef maze */

bool
-ossl_expand_label(const uint8_t *secret, si= ze_t secret_len,
- = const uint8_t *label, size_t label_len,
- const uint8_t *context, s= ize_t context_len,
- = uint8_t *out, uint16_t out_len)
+ossl_expand_label(const uint8_t *secret, size_t = secret_len, const uint8_t *label, size_t label_len,
+ const uint8_t *context,= size_t context_len, uint8_t *out, uint16_t out_len)
{
OSSL_LIB_CTX *libctx =3D NULL;
const= char *properties =3D NULL;

- const uint8_t *label_prefix =3D (const uint8_t = *) ("ovpn ");
+ const uint8_t *label_prefix =3D (const uint8_t *)("ovpn "= );
const size_t label_prefix_len =3D 5;

EVP_KDF *kdf =3D EVP_KDF_fetch(libctx, OSSL_KDF_NA= ME_TLS1_3_KDF, properties);
@@ -658,15 +623,12 @@ int mode =3D EVP_PKEY_HKDEF_MODE_EXPAND_ONLY;
=
*p++ =3D OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE= , &mode);
- *p++= =3D OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
- = (char *) mdname, 0);

- *p++ =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
- = (unsigned char *) secret, hashlen);
- *p++ =3D OSSL_PARAM_construct_octet= _string(OSSL_KDF_PARAM_PREFIX,
- (unsigned char *) lab= el_prefix,
+ *p++ = =3D OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, (char *)mdname,= 0);
+ *p++ =3D OS= SL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (unsigned char *)secret= , hashlen);
+ *p++= =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PREFIX, (unsigned cha= r *)label_prefix,
= label_prefix_len);
- *p++ =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_LABEL,
- = (unsigned char *) label, label_len);
+ *p++ =3D
+ OSSL_PARAM_construct_octet_string(OSSL= _KDF_PARAM_LABEL, (unsigned char *)label, label_len);

*p++ =3D OSSL_PARAM_construct_end();

@@ -681,13 +643,11 @@
void
= crypto_test_ovpn_expand_openssl3(void **state)
{- uint8_t secret[32] =3D
- {0x07, 0x77, 0x09, 0x3= 6, 0x2c, 0x2e, 0x32, 0xdf,
- 0x0d, 0xdc, 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63,
- 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f= , 0x9c, 0x31,
- 0x2= 2, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5};
+ uint8_t secret[32] =3D { 0x07, 0x77, 0x09, 0x= 36, 0x2c, 0x2e, 0x32, 0xdf, 0x0d, 0xdc, 0x3f,
+ 0x0d, 0xc4, 0x7b, 0xba= , 0x63, 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f,
+ 0x9c, 0x31, 0x22, 0xec, = 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5 };

- const uint8_t *label =3D (const uint8= _t *) ("unit test");
+ const uint8_t *label =3D (const uint8_t *)("unit test&q= uot;);
const size_t labellen =3D 9;
= uint8_t out[27];

@@ -726,11 +686,10 @@=
init_key_type(&data->kt, "AES-128-GCM&quo= t;, "none", true, false);

= /* have an epoch key that uses 0x23 for the key for all bytes */
= - struct epoch_key epoch1send = =3D { .epoch =3D 1, .epoch_key =3D {0x23} };
- struct epoch_key epoch1recv =3D { .epoch =3D 1, = .epoch_key =3D {0x27} };
+ struct epoch_key epoch1send =3D { .epoch =3D 1, .epoch_key =3D { 0= x23 } };
+ struct = epoch_key epoch1recv =3D { .epoch =3D 1, .epoch_key =3D { 0x27 } };<= br>
- epoch_i= nit_key_ctx(&data->co, &data->kt, &epoch1send,
= - &epoc= h1recv, *num_future_keys);
+ epoch_init_key_ctx(&data->co, &data->kt, &epoc= h1send, &epoch1recv, *num_future_keys);

*state =3D data;

return 0;
@@ = -914,7 +873,7 @@
void
epoch_test_derive_d= ata_key(void **state)
{
- struct epoch_key e17 =3D { .epoch =3D 17, .epoch_key= =3D { 19, 12 }};
+ = struct epoch_key e17 =3D { .epoch =3D 17, .epoch_key =3D { 19, 12 } };
struct key_type kt =3D { 0 };
struc= t key_parameters key_parameters =3D { 0 };
init_key_ty= pe(&kt, "AES-192-GCM", "none", true, false);=
@@ -925,13 +884,12 @@
assert_int_equal(key_p= arameters.cipher_size, 24);
assert_int_equal(key_param= eters.hmac_size, 12);

- uint8_t exp_cipherkey[24] =3D
- {0xed, 0x85, 0x33, 0xdb, 0x1c, 0x28, 0x= ac, 0xe4,
- 0x18, 0= xe9, 0x00, 0x6a, 0xb2, 0x9c, 0x17, 0x41,
- 0x7d, 0x60, 0xeb, 0xe6, 0xcd, 0x90, 0xbf, 0x0a};
+ uint8_t exp_cipher= key[24] =3D { 0xed, 0x85, 0x33, 0xdb, 0x1c, 0x28, 0xac, 0xe4,
+ = 0x18, 0xe9, 0x00, 0x6a, 0xb2, 0x9c, 0x17, 0x41,

+ 0x7d, 0x60, = 0xeb, 0xe6, 0xcd, 0x90, 0xbf, 0x0a };

- uint8_t exp_impl_iv[12] =3D- {0x86, 0x89, 0x0a, 0xab, 0x= f0, 0x32, 0xcb, 0x59, 0xf4, 0xcf, 0xa3, 0x4e};
+ uint8_t exp_impl_iv[12] =3D { 0x86, 0x89, 0x= 0a, 0xab, 0xf0, 0x32,
+ 0xcb, 0x59, 0xf4, 0xcf, 0xa3, 0x4e };

assert_memory_equal(key_parameters.ciph= er, exp_cipherkey, sizeof(exp_cipherkey));
assert_memo= ry_equal(key_parameters.hmac, exp_impl_iv, sizeof(exp_impl_iv));
= @@ -961,20 +919,16 @@
cmocka_unit_test(crypt= o_test_ovpn_expand_openssl3),
cmocka_unit_test_pre= state_setup_teardown(crypto_test_epoch_key_generation,
= crypto_test_epoch_setup,
- = crypto_test_epoch_teardown,
- = &prestate_num16),
+ crypto_test_epoch_tea= rdown, &prestate_num16),
cmocka_unit_test_pres= tate_setup_teardown(crypto_test_epoch_key_rotation,
= crypto_test_epoch_setup,<= br>- = crypto_test_epoch_teardown,
- = &prestate_num13),
+ crypto_test_epoch_teardo= wn, &prestate_num13),
cmocka_unit_test_prestat= e_setup_teardown(crypto_test_epoch_key_receive_lookup,
= crypto_test_epoch_setup,
- = crypto_test_epoch_teardown,
- = &prestate_num13),
+ crypto_test_epoch_tea= rdown, &prestate_num13),
cmocka_unit_test_pres= tate_setup_teardown(crypto_test_epoch_key_overflow,
= crypto_test_epoch_setup,<= br>- = crypto_test_epoch_teardown,
- = &prestate_num32),
+ crypto_test_epoch_teardo= wn, &prestate_num32),
cmocka_unit_test(epoch_t= est_derive_data_key)
};

diff --git a/tests/unit_tests/openvpn/test_cryptoapi.c b/tests/unit_tes= ts/openvpn/test_cryptoapi.c

index 9225b4d..4ee624e 100644
--- a/tests/unit_tests/openvpn/test_cryptoapi.c
+++ b/tests/unit_tests/openvpn/test_cryptoapi.c

@@ -32,= 7 +32,7 @@
#include "xkey_common.h"
#include "cert_data.h"


-#if defined(HAVE_XKEY_PROVIDER) &&= ; defined (ENABLE_CRYPTOAPI)
+#if defined(HAVE_XKEY_PROVIDER) && defined(ENABLE_CRYPTOAP= I)
#include <setjmp.h>
#include <= ;cmocka.h>
#include <openssl/bio.h>
@@ -43,19 +43,18 @@

#include "test_common.h"<= /span>

#include <cryptoapi.h>
<= span style=3D"color: hsl(0, 100%, 40%);">-#include <cryptoapi.c> /* p= ull-in the whole file to test static functions */

+#include <cryptoapi.c> /* pull-= in the whole file to test static functions */

<= span> struct management *management; /* global */

static O= SSL_PROVIDER *prov[2];

/* mock a managem= ent function that xkey_provider needs */
char *
= -management_query_pk_sig(struct m= anagement *man, const char *b64_data,
- const char *algorithm)
+management_query_pk_sig(struct m= anagement *man, const char *b64_data, const char *algorithm)

{

- (void) man;
- (void) b64_data;
- (void) algorithm;
+ (void)man;<= br>+ (void)b64_data;<= br>+ (void)algorithm;=
return NULL;
}

= @@ -74,14 +73,12 @@
OSSL_LIB_CTX *tls_libctx;=

#ifndef _countof
-#define _countof(x) sizeof((x))/sizeof(*(x))=
+#define _countof(x) sizeof= ((x)) / sizeof(*(x))
#endif

/* test data */

-s= tatic const uint8_t test_hash[] =3D {
- 0x77, 0x38, 0x65, 0x00, 0x1e, 0x96, 0x48, 0xc6, 0x57, 0= x0b, 0xae,
- 0xc0, 0= xb7, 0x96, 0xf9, 0x66, 0x4d, 0x5f, 0xd0, 0xb7
-};
+static const uint8_t test_hash[] =3D { 0x77, 0x38, 0x65, 0x00, 0x1e,= 0x96, 0x48, 0xc6, 0x57, 0x0b,
+ 0xae, 0xc0, 0xb7, 0x96, 0xf= 9, 0x66, 0x4d, 0x5f, 0xd0, 0xb7 };

/* va= lid test strings to test with and without embedded and trailing spaces */
static const char *valid_str[] =3D {
@@ -10= 2,13 +99,13 @@
*/
static struct test_cer= t
{
- = const char *const cert; /* certificate as PEM */
<= span style=3D"color: hsl(0, 100%, 40%);">- const char *const key; = /* key as unencrypted PEM */

- const char *const cname; /* common-name */
- const char *const iss= uer; /* issuer common-name */
- const char *const friendly_name; /* identifies cer= ts loaded to the store -- keep unique */
- const char *hash; /* SHA1 fingerpr= int */
- int valid; = /* nonzero if certificate has not expired */
+ const char *const cer= t; /* certificate as PEM */
+ const char *const key; /* key as unencrypted= PEM */
+ const ch= ar *const cname; /* common-name */
+ const char *const issuer; /* issuer commo= n-name */
+ const = char *const friendly_name; /* identifies certs loaded to the store -- keep = unique */
+ const = char *hash; /* SHA1 fingerprint */
+ int valid; /* nonze= ro if certificate has not expired */
} certs[5];
static bool certs_loaded;
@@ -119= ,11 +116,11 @@
init_cert_data(void)
{
struct test_cert certs_local[] =3D {
- {cert1, key1, cname1, "OVP= N TEST CA1", "OVPN Test Cert 1", hash1, 1},
- {cert2, key2, cname2, &q= uot;OVPN TEST CA2", "OVPN Test Cert 2", hash2, 1},
=
- {cert3, key3, cnam= e3, "OVPN TEST CA1", "OVPN Test Cert 3", hash3, 1},=
- {cert4, key4= , cname4, "OVPN TEST CA2", "OVPN Test Cert 4", hash= 4, 0},
- {0}
+ { cert1, key1,= cname1, "OVPN TEST CA1", "OVPN Test Cert 1", hash1, 1 = },
+ { cert2, = key2, cname2, "OVPN TEST CA2", "OVPN Test Cert 2", hash= 2, 1 },
+ { ce= rt3, key3, cname3, "OVPN TEST CA1", "OVPN Test Cert 3",= hash3, 1 },
+ = { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4&q= uot;, hash4, 0 },
+ = { 0 }
};
assert(sizeof(cert= s_local) =3D=3D sizeof(certs));
memcpy(certs, certs_lo= cal, sizeof(certs_local));
@@ -145,20 +142,21 @@
= static void
import_certs(void **state)
{

- (void) stat= e;
+ (void)state;<= /span>
if (certs_loaded)
{
return;

}
init_cert_d= ata();
- user_store = =3D CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_U= SER
- = |CERT_STORE_OPEN_EXISTING_FLAG, L"MY");
+ user_store =3D

+ CertOpenStore(CERT_STORE_= PROV_SYSTEM, 0, 0,

+ = CERT_SYSTEM_STORE_CURRENT_USER | CERT_STORE_OPEN_EXIST= ING_FLAG, L"MY");
assert_non_null(user_store= );
for (struct test_cert *c =3D certs; c->cert; c++= )
{
/* Convert PEM cert &= key to pkcs12 and import */
- const char *pass =3D "opensesame"; /* some = password */
- co= nst wchar_t *wpass =3D L"opensesame"; /* same as a wide string = */
+ const cha= r *pass =3D "opensesame"; /* some password */
+ const wchar_t *wpass =3D L= "opensesame"; /* same as a wide string */


X509 *x509 =3D NULL;
EVP_PKEY = *pkey =3D NULL;
@@ -192,7 +190,7 @@
= return;
}

- CRYPT_DATA_BLOB blob =3D {.cbD= ata =3D 0, .pbData =3D NULL};
+ CRYPT_DATA_BLOB blob =3D { .cbData =3D 0, .pbData =3D NUL= L };
int len =3D i2d_PKCS12(p12, &blob.pbData)= ; /* pbData will be allocated by OpenSSL */
if (le= n <=3D 0)
{
@@ -201,7 +199,7 @@=
}
blob.cbData =3D len;

- = DWORD flags =3D PKCS12_ALLOW_OVERWRITE_KEY|PKCS12_ALWAYS_CNG_KSP;=
+ DWORD flags =3D PK= CS12_ALLOW_OVERWRITE_KEY | PKCS12_ALWAYS_CNG_KSP;
= HCERTSTORE tmp_store =3D PFXImportCertStore(&blob, wpass, flags);
PKCS12_free(p12);
OPENSSL_free= (blob.pbData);
@@ -229,7 +227,7 @@
static = int
cleanup(void **state)
{
- (void) state;

+ (void)state;
= struct gc_arena gc =3D gc_new();
if (user_store) /* d= elete all certs we imported */
{
@@ -2= 61,7 +259,7 @@
static void
test_find_cert= _bythumb(void **state)
{
- (void) state;
+ (void)state;
char select_string[= 64];
struct gc_arena gc =3D gc_new();
= const CERT_CONTEXT *ctx;
@@ -294,7 +292,7 @@ static void
test_find_cert_byname(void **state)
{
- (= void) state;
+ (vo= id)state;
char select_string[64];
= struct gc_arena gc =3D gc_new();
const CERT_CONTEXT *= ctx;
@@ -327,7 +325,7 @@
static void
test_find_cert_byissuer(void **state)
{=
- (void) state;
= + (void)state;
char select_string[64];

struct gc_arena gc =3D= gc_new();
const CERT_CONTEXT *ctx;
@@= -360,7 +358,7 @@
static int
setup_xkey_p= rovider(void **state)
{
- (void) state;
+ (void)state;
/* Initialize provid= ers in a way matching what OpenVPN core does */
tls_li= bctx =3D OSSL_LIB_CTX_new();
prov[0] =3D OSSL_PROVIDER= _load(tls_libctx, "default");
@@ -375,7 +373,7 @@=
static int
teardown_xkey_provider(void *= *state)
{
- (void) state;
- (void) state;
+ (void)state;
char se= lect_string[64];
X509 *x509 =3D NULL;
= EVP_PKEY *privkey =3D NULL;
@@ -431,7 +429,7 @@=
void
test_ssl_ctx_use_cryptoapicert(void **stat= e)
{
-= (void) state;
+ = (void)state;
char select_string[64];

import_certs(state); /* a no-op if already imported= */
@@ -455,7 +453,8 @@
/* Use Ope= nSSL to check that the cert and private key in ssl_ctx "match" */=
if (!SSL_CTX_check_private_key(ssl_ctx)) {
- = fail_msg("Certificate and private key in ssl_ctx do not match= for <%s>", c->friendly_name);
+ fail_msg("Certificate and private= key in ssl_ctx do not match for <%s>",
+ c->friendly_name);
return;
}

@@ -467,7 +466,7 @@
test_parse_hexst= ring(void **state)
{
unsigned char ha= sh[255];
- (void) st= ate;
+ (void)state= ;

for (int i =3D 0; i < _countof(= valid_str); i++)
{
@@ -513,4 +512,4 @@=
return 0;
}
=
-#endif /* ifdef HAVE_XKEY_P= ROVIDER */
+#endif /*= ifdef HAVE_XKEY_PROVIDER */
diff --git a/tests/unit_tests/= openvpn/test_misc.c b/tests/unit_tests/openvpn/test_misc.c
= index 0c604ff..337b6aa 100644
--- a/tests/unit_tests/openvp= n/test_misc.c
+++ b/tests/unit_tests/openvpn/test_misc.c
@@ -45,14 +45,18 @@
{
s= truct gc_arena gc =3D gc_new();

- const char *input =3D "V4,dev-type tun= ,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,= tls-server";
+ = const char *input =3D
+ "V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,au= th SHA1,keysize 128,key-method 2,tls-server";
=
const char *output =3D options_string_compat_lzo(input, &= ;gc);

- assert_string_equal(output, "V4,dev-type tun,link-mtu 1458,tun-m= tu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo&= quot;);
+ assert_s= tring_equal(
+ = output,
+ &qu= ot;V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,auth SHA1,keysize= 128,key-method 2,tls-server,comp-lzo");

<= span> /* This string is has a much too small link-mtu so we should fail= on it" */

- in= put =3D "V4,dev-type tun,link-mtu 2,tun-mtu 1400,proto UDPv4,auth SHA1= ,keysize 128,key-method 2,tls-server";
+ input =3D
+ "V4,dev-type tun,link-mtu 2,tun-mtu 1400,pro= to UDPv4,auth SHA1,keysize 128,key-method 2,tls-server";

output =3D options_string_compat_lzo(input, &= gc);

@@ -65,11 +69,14 @@
= assert_string_equal(input, output);

=
- input =3D "= V4,dev-type tun,link-mtu 999,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128= ,key-method 2,tls-server";
+ input =3D
+ "V4,dev-type tun,link-mtu 999,tun-mtu 1400,proto UDPv4,a= uth SHA1,keysize 128,key-method 2,tls-server";
ou= tput =3D options_string_compat_lzo(input, &gc);

/* 999 -> 1000, 3 to 4 chars */
- assert_string_equal(output, "V4,dev-t= ype tun,link-mtu 1000,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-me= thod 2,tls-server,comp-lzo");
+ assert_string_equal(
+ output,
+ "V4,dev-type tun,link-mtu 1000,tun-mtu 1400,pr= oto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo");

gc_free(&gc);
}
@@ -111,7 +118,6 @@
}


-=
struct word
{
const char *= word;
@@ -122,7 +128,7 @@
static uint32_t<= /span>
word_hash_function(const void *key, uint32_t iv) {
- const ch= ar *str =3D (const char *) key;
+ const char *str =3D (const char *)key;
= const int len =3D strlen(str);
return hash_func((cons= t uint8_t *)str, len, iv);
}
@@ -162,11 +1= 68,10 @@
static void
test_list(void **sta= te)
{
= -
-/*
- * Test the hash code by implementing a= simple
- * word freque= ncy algorithm.
- */
+ /*
+ * Test the hash code by impleme= nting a simple
+ = * word frequency algorithm.
+ */

struct gc_arena gc = =3D gc_new();
struct hash *hash =3D hash_init(10000, g= et_random(), word_hash_function, word_compare_function);
@@= -175,7 +180,7 @@
printf("hash_init n_buckets=3D%= d mask=3D0x%08x\n", hash->n_buckets, hash->mask);

char wordfile[PATH_MAX] =3D { 0 };
- openvpn_test_get_srcdir_dir(wordf= ile, PATH_MAX, "/../../../COPYRIGHT.GPL" );

+ openvpn_test_get_srcdir_dir(wordfile,= PATH_MAX, "/../../../COPYRIGHT.GPL");
FILE *words =3D fopen(wordfile, "r");
assert_non_null(words);

@@ -201,7 +206,7 @@ c =3D buf[bi++];
if (isal= num(c) || c =3D=3D '_')
{
- assert_true(wbi &l= t; (int) sizeof(wordbuf));

+ assert_true(wbi < (int)sizeof(wordbuf)); wordbuf[wbi++] =3D c;
= }
else
@@ -210,13 +215,13 @@<= /span>
{
wor= dcount++;

- ASSERT(wbi < (int) sizeof(wordbuf));+ ASSERT(wb= i < (int)sizeof(wordbuf));
wordbuf[= wbi++] =3D '\0';

= /* word is parsed from stdin */

= /* does it already exist in table? */
- struct word *w =3D (st= ruct word *) hash_lookup(hash, wordbuf);
+ struct word *w =3D (struct word *)= hash_lookup(hash, wordbuf);

= if (w)
{
@@ -2= 31,13 +236,13 @@
w->word =3D st= ring_alloc(wordbuf, &gc);
w-&g= t;n =3D 1;
assert_true(hash_add(ha= sh, w->word, w, false));
- assert_true(hash_add(nhash, w->word, (void= *) ((ptr_type )(random() & 0x0F) + 1), false));
+ assert_true(hash_= add(nhash, w->word,
- }
- = while (c);
+ = } while (c);
}

= assert_int_equal(wordcount, 2978);
@@ -262,7 +267,7 @@

while ((he =3D hash_iterator_ne= xt(&hi)))
{
- struct word *w =3D (struct word *) h= e->value;
+ = struct word *w =3D (struct word *)he->value;
= /*printf("%6d '%s'\n", w->n, w->word= ); */
++count;
= /* check a few words to match prior results */
@@ -27= 0,19 +275,19 @@
{
= assert_int_equal(w->n, 49);
= }
- el= se if (!strcmp(w->word, "redistribute"))
+ else if (!strcmp(w->w= ord, "redistribute"))
{ assert_int_equal(w->n, 5);
= }
- = else if (!strcmp(w->word, "circumstances"))
+ else if = (!strcmp(w->word, "circumstances"))
= {
assert_int_equal(w->n, 1);=
}
- else if (!strcmp(w->word, "so")= )
+ el= se if (!strcmp(w->word, "so"))
= {
assert_int_equal(w->n, 8);
}
- else if (!strcmp(w->word, "BECAUSE")= )
+ el= se if (!strcmp(w->word, "BECAUSE"))
= {
assert_int_equal(w->n, 1);=
}
@@ -297,12 +302,12 @@
{
for (ptr_type i =3D 1; i <= ;=3D 16; ++i)
{
- struct hash_element *item =3D hash_lookup_by= _value(nhash, (void *) i);
- hash_remove_by_value(nhash, (void *) i);
+ struct hash_element *item= =3D hash_lookup_by_value(nhash, (void *)i);
+ hash_remove_by_value(nhash, (void *)i)= ;
/* check item got removed if it was present = before */
if (item)
= {
- a= ssert_null(hash_lookup_by_value(nhash, (void *) i));
+ assert_null(hash_lookup_b= y_value(nhash, (void *)i));
}
= }
}
@@ -379,14 +384,12 @@
mock_set_debug_level(saved_log_level);
}=

-con= st struct CMUnitTest misc_tests[] =3D {
- cmocka_unit_test(test_compat_lzo_string),
<= span style=3D"color: hsl(0, 100%, 40%);">- cmocka_unit_test(test_auth_fa= il_temp_no_flags),

- = cmocka_unit_test(test_auth_fail_temp_flags),
- cmocka_unit_test(test_auth_fail_temp_flags_msg)= ,
- cmocka_unit_test= (test_list),
- cmock= a_unit_test(test_atoi_variants)
-};
+const s= truct CMUnitTest misc_tests[] =3D { cmocka_unit_test(test_compat_lzo_string= ),
+ = cmocka_unit_test(test_auth_fail_temp_no_flags),
+ = cmocka_unit_test(test_auth_fail_temp_flags),
+ = cmocka_unit_test(test_auth_fail_temp_flags_msg),

+ = cmocka_unit_test(test_list),
+ cmocka_unit_test(test= _atoi_variants) };

int
= main(void)
diff --git a/tests/unit_tests/openvpn/test_ncp.c= b/tests/unit_tests/openvpn/test_ncp.c
index 9c40f5c..16bf1= cf 100644
--- a/tests/unit_tests/openvpn/test_ncp.c<= br>+++ b/tests/unit_tests/openvpn/test_ncp.c
@@ -47,8= +47,7 @@
/* Define this function here as dummy since incl= uding the ssl_*.c files
* leads to having to include even= more unrelated code */
bool
-key_state_export_keying_material(struct tls_session= *session,
- = const char *label, size_t label_size,
+key_state_export_keying_material(st= ruct tls_session *session, const char *label, size_t label_size,

= void *ekm, size_t ekm_size)<= br> {
ASSERT(0);
@@ -73,8 +72,7 = @@
bool have_blowfish =3D cipher_valid("BF-CBC&qu= ot;);

assert_string_equal(mutate_ncp= _cipher_list("none", &gc), "none");
- assert_string_equal(mutate_ncp_ci= pher_list("AES-256-GCM:none", &gc),

- "AES-256-GCM:none&= quot;);
+ assert_s= tring_equal(mutate_ncp_cipher_list("AES-256-GCM:none", &gc), = "AES-256-GCM:none");

asser= t_string_equal(mutate_ncp_cipher_list(aes_ciphers, &gc), aes_ciphers);<= /span>

@@ -86,8 +84,7 @@
if= (have_chacha && have_blowfish)
{
assert_string_equal(mutate_ncp_cipher_list(bf_chacha, &gc)= , bf_chacha);

- = assert_string_equal(mutate_ncp_cipher_list("BF-CBC:CHACHA20-POLY1305&q= uot;, &gc),
- = bf_chacha);
+ assert_string_equal(mutate_ncp_cipher_list("BF-C= BC:CHACHA20-POLY1305", &gc), bf_chacha);
}
else
{
@@ -99,14 +9= 6,14 @@
aes_ciphers);

/* Check that optional ciphers work */- assert_string_equal(mutate_= ncp_cipher_list("?AES-256-GCM:?AES-128-GCM", &gc),
= - aes_ciph= ers);
+ assert_str= ing_equal(mutate_ncp_cipher_list("?AES-256-GCM:?AES-128-GCM", &am= p;gc), aes_ciphers);

/* All unsuppor= ted should still yield an empty list */
assert_ptr_equ= al(mutate_ncp_cipher_list("?kugelfisch:?grasshopper", &gc), N= ULL);

/* If the last is optional, pr= evious invalid ciphers should be ignored */
- assert_ptr_equal(mutate_ncp_cipher_list("Vol= lbit:Littlebit:AES-256-CBC:BF-CBC:?nixbit", &gc), NULL);+ assert_ptr_equal(mutate_n= cp_cipher_list("Vollbit:Littlebit:AES-256-CBC:BF-CBC:?nixbit", &a= mp;gc),
+ = NULL);

/* We do not support= CCM ciphers */
assert_ptr_equal(mutate_ncp_cipher_lis= t("AES-256-GCM:AES-128-CCM", &gc), NULL);
@@ = -127,19 +124,19 @@
assert_ptr_equal(mutate_ncp_cipher_= list("AES-256-GCM:vollbit", &gc), NULL);
= assert_ptr_equal(mutate_ncp_cipher_list("", &gc), NULL);

- ass= ert_ptr_equal(mutate_ncp_cipher_list(
- "ChaCha20-Poly1305:ChaCha20-P= oly1305:ChaCha20-Poly1305:"
- "ChaCha20-Poly1305:ChaCha20-Poly13= 05:ChaCha20-Poly1305:"
- "ChaCha20-Poly1305", &gc), NUL= L);
+ assert_ptr_e= qual(mutate_ncp_cipher_list("ChaCha20-Poly1305:ChaCha20-Poly1305:ChaCh= a20-Poly1305:"
+= "ChaCha20-Poly1305:ChaCha2= 0-Poly1305:ChaCha20-Poly1305:"
+ "ChaCha20-= Poly1305",
+ = &gc),
+ NULL);
=
#ifdef ENABLE_CRYPTO_OPENSSL
- assert_string_equal(mutate_ncp_cipher_list(&qu= ot;id-aes128-GCM:id-aes256-GCM",
- &gc), &q= uot;AES-128-GCM:AES-256-GCM");
+ assert_string_equal(mutate_ncp_cipher_list("id-aes= 128-GCM:id-aes256-GCM", &gc),
+ "AES-128-GCM:AES-256-GCM&qu= ot;);
#else
if (have_blowfish)=
{
- = assert_string_equal(mutate_ncp_cipher_list("BLOWFISH-CBC",
- = &gc), "BF-CBC");
+ assert_string_equal(mutate_ncp= _cipher_list("BLOWFISH-CBC", &gc), "BF-CBC");
}
#endif
gc_free(&= ;gc);
@@ -193,37 +190,28 @@
const char= *serverlist =3D "CHACHA20_POLY1305:AES-128-GCM";
const char *serverlistbfcbc =3D "CHACHA20_POLY1305:AES-128-GCM:B= F-CBC:none";


- best_cipher =3D ncp_get_best_cipher(serverlist,- = "IV_YOLO=3DNO\nIV_BAR=3D7",
- "BF-CBC&q= uot;, &gc);
+ = best_cipher =3D ncp_get_best_cipher(serverlist, "IV_YOLO=3DNO\nIV_BAR= =3D7", "BF-CBC", &gc);

assert_ptr_equal(best_cipher, NULL);



- best_cipher = =3D ncp_get_best_cipher(serverlistbfcbc,
- "IV_YOLO=3DNO= \nIV_BAR=3D7",
- = "BF-CBC", &gc);+ best_cipher =3D ncp_get_b= est_cipher(serverlistbfcbc, "IV_YOLO=3DNO\nIV_BAR=3D7", "BF-= CBC", &gc);

assert_string_e= qual(best_cipher, "BF-CBC");

<= /span>
- best_cipher =3D nc= p_get_best_cipher(serverlist,
- "IV_NCP=3D1\nIV_BAR=3D7&= quot;,
- = "AES-128-GCM", &gc);
+ best_cipher =3D ncp_get_best_ciph= er(serverlist, "IV_NCP=3D1\nIV_BAR=3D7", "AES-128-GCM",= &gc);

assert_string_equal(best_= cipher, "AES-128-GCM");

- best_cipher =3D ncp_get_best_cipher(ser= verlist, NULL,
- = "AES-128-GCM", &gc);+ best_cipher =3D ncp_get_b= est_cipher(serverlist, NULL, "AES-128-GCM", &gc);
<= span>

assert_string_equal(best_cipher, "AES-128-= GCM");

- best_cipher =3D ncp_get_best_cipher(serverlist, NULL,- = "none", &gc);
+ best_cipher =3D ncp_get_best_cipher(serverlist, NULL, &q= uot;none", &gc);
assert_ptr_equal(best_cipher= , NULL);

- best_cipher =3D ncp_get_best_cipher(serverlistbfcbc, NULL,<= br>- = "none", &gc);
+ best_cipher =3D ncp_get_best_cipher(serverlistbfcbc, N= ULL, "none", &gc);
assert_string_equal(b= est_cipher, "none");

best_= cipher =3D ncp_get_best_cipher(serverlist, NULL, NULL, &gc);
= @@ -241,28 +229,23 @@

const ch= ar *serverlist =3D "CHACHA20_POLY1305:AES-128-GCM:AES-256-GCM";

- b= est_cipher =3D ncp_get_best_cipher(serverlist,
- "IV_YOL= O=3DNO\nIV_NCP=3D2\nIV_BAR=3D7",
- "BF-CBC", &= amp;gc);
+ best_ci= pher =3D ncp_get_best_cipher(serverlist, "IV_YOLO=3DNO\nIV_NCP=3D2\nIV= _BAR=3D7", "BF-CBC", &gc);

<= span> assert_string_equal(best_cipher, "AES-128-GCM");
=

/* Best cipher is in --cipher of client */=
- best_cipher =3D n= cp_get_best_cipher(serverlist, "IV_NCP=3D2\nIV_BAR=3D7",- = "CHACHA20_POLY1305", &gc);
+ best_cipher =3D ncp_get_best_cipher(server= list, "IV_NCP=3D2\nIV_BAR=3D7", "CHACHA20_POLY1305", &a= mp;gc);

assert_string_equal(best_cip= her, "CHACHA20_POLY1305");

= /* Best cipher is in --cipher of client */
- best_cipher =3D ncp_get_best_cipher(serverlist, &= quot;IV_CIPHERS=3DAES-128-GCM",
- "AES-256-CBC"= ;, &gc);
+ bes= t_cipher =3D ncp_get_best_cipher(serverlist, "IV_CIPHERS=3DAES-128-GCM= ", "AES-256-CBC", &gc);


assert_string_equal(best_cipher, "AES-128-GCM= ");

/* IV_NCP=3D2 should be ign= ored if IV_CIPHERS is sent */
- best_cipher =3D ncp_get_best_cipher(serverlist,
- = "IV_FOO=3D7\nIV_CIPHERS=3DAES-256-GCM\nIV_NCP=3D2",

+ best_cipher =3D ncp_get_best= _cipher(serverlist, "IV_FOO=3D7\nIV_CIPHERS=3DAES-256-GCM\nIV_NCP=3D2&= quot;,

"AES-256= -CBC", &gc);

assert_string_= equal(best_cipher, "AES-256-GCM");
@@ -313,11 +29= 6,14 @@

if (have_chacha)
<= span> {

- as= sert_string_equal(o.ncp_ciphers, "BF-CBC:AES-256-GCM:AES-128-GCM:CHACH= A20-POLY1305:AES-128-CBC:AES-256-CBC");
+ assert_string_equal(
+ o.ncp_ciphers,
+ "BF-CBC:AES-256-G= CM:AES-128-GCM:CHACHA20-POLY1305:AES-128-CBC:AES-256-CBC");

= }
else
{
- assert_string_equal(o.ncp_c= iphers, "BF-CBC:AES-256-GCM:AES-128-GCM:AES-128-CBC:AES-256-CBC")= ;

+ assert_str= ing_equal(o.ncp_ciphers,
+ "BF-CBC:AES-256-GCM:AES-128-GCM:AES-1= 28-CBC:AES-256-CBC");
}
asse= rt_string_equal(o.ncp_ciphers_conf, "BF-CBC:DEFAULT:AES-128-CBC:AES-25= 6-CBC");

@@ -327,7 +313,8 @@<= br>
if (have_chacha)
{
- assert_string_equ= al(o.ncp_ciphers, "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-128-C= BC:AES-192-CBC");
+ "AES-256-GCM:AES= -128-GCM:CHACHA20-POLY1305:AES-128-CBC:AES-192-CBC");
= }
else
{
@@ = -341,7 +328,8 @@

if (have_chacha)
{
- = assert_string_equal(o.ncp_ciphers, "AES-192-GCM:AES-128-CBC:AES= -256-GCM:AES-128-GCM:CHACHA20-POLY1305");
+ assert_string_equal(o.ncp_ciphers,
+ = "AES-192-GCM:AES-128-CBC:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305&= quot;);
}
else
= {
@@ -356,7 +344,7 @@
test_ncp_expand(v= oid **state)
{
bool have_chacha =3D c= ipher_valid("CHACHA20-POLY1305");
- struct options o =3D {0};
+ struct options o =3D { 0 };
o.gc =3D gc_new();
struc= t gc_arena gc =3D gc_new();
diff --git a/tests/unit_tests/o= penvpn/test_networking.c b/tests/unit_tests/openvpn/test_networking.c
index 0434707..f2da83e 100644
--- a/tests/unit_t= ests/openvpn/test_networking.c
+++ b/tests/unit_tests/openv= pn/test_networking.c
@@ -110,12 +110,10 @@
= printf("\n");

return = net_route_v4_add(NULL, &dst, prefixlen, NULL, iface, 0, metric);=
-
}
static int
-net__route_v4_add_gw(const char *dst_str, int prefixlen, co= nst char *gw_str,
- = int metric)
+net__route_v4_add_gw(const char *dst_str, int prefixlen, const cha= r *gw_str, int metric)
{
in_addr_t ds= t, gw;
int ret;
@@ -140,8 +138,7 @@
dst =3D ntohl(dst);
gw =3D ntohl(gw= );

- = printf("CMD: ip route add %s/%d dev %s via %s", dst_str, prefi= xlen, iface,
- = gw_str);
+ print= f("CMD: ip route add %s/%d dev %s via %s", dst_str, prefixlen, if= ace, gw_str);
if (metric > 0)
= {
printf(" metric %d", metric);@@ -176,12 +173,10 @@
printf("\n");<= /span>

return net_route_v6_add(NULL, &d= st, prefixlen, NULL, iface, 0, metric);
-
}

st= atic int
-net__route_v6= _add_gw(const char *dst_str, int prefixlen, const char *gw_str,
<= span style=3D"color: hsl(0, 100%, 40%);">- int metric)<= /span>
+net__route_v6_add_gw= (const char *dst_str, int prefixlen, const char *gw_str, int metric)=
{
struct in6_addr dst, gw;
= int ret;
@@ -203,8 +198,7 @@
= return -1;
}

- printf("CMD: ip -6 route add %s/%d= dev %s via %s", dst_str, prefixlen,
- iface, gw_str);
+ printf("CMD: ip -6 route add %s/%d dev = %s via %s", dst_str, prefixlen, iface, gw_str);
i= f (metric > 0)
{
printf(&q= uot; metric %d", metric);
diff --git a/tests/unit_test= s/openvpn/test_packet_id.c b/tests/unit_tests/openvpn/test_packet_id.c
index 312a6b3d..ae6eeec 100644
--- a/tests/unit= _tests/openvpn/test_packet_id.c
+++ b/tests/unit_tests/open= vpn/test_packet_id.c
@@ -37,8 +37,10 @@
#i= nclude "reliable.h"
#include "test_common.h= "

- struct {
+struct test_packet_id_write_data
+{
+ struct
+ {=
uint32_t buf_id;
uint32_= t buf_time;
} test_buf_data;
@@ -50,15= +52,14 @@
static int
test_packet_id_writ= e_setup(void **state)
{
- struct test_packet_id_write_data *data =3D- calloc(1, sizeof(struct= test_packet_id_write_data));
+ struct test_packet_id_write_data *data =3D calloc(1, sizeof(s= truct test_packet_id_write_data));

i= f (!data)
{
return -1;=
}

- data->test_buf.data =3D (void *) &data->test_buf= _data;
+ data->= test_buf.data =3D (void *)&data->test_buf_data;
= data->test_buf.capacity =3D sizeof(data->test_buf_data);
<= span> data->gc =3D gc_new();


@@ -1= 63,7 +164,6 @@
static void
test_get_num_o= utput_sequenced_available(void **state)
{
-
struct reliable = *rel =3D malloc(sizeof(struct reliable));
reliable_ini= t(rel, 100, 50, 8, false);

@@ -181,14 +18= 1,14 @@
/* test ids close to int/unsigned int barrier = */

rel->array[5].active =3D true;=
- rel->array[5].= packet_id =3D (0x80000000u -3);
+ rel->array[5].packet_id =3D (0x80000000u - 3); rel->array[6].active =3D false;
- rel->packet_id =3D (0x80000000u -1);=
+ rel->packet_id =3D = (0x80000000u - 1);

assert_int_equal(= 6, reliable_get_num_output_sequenced_available(rel));

rel->array[5].active =3D true;
- rel->array[5].packet_id =3D (0x80000= 000u -3);
+ rel-&g= t;array[5].packet_id =3D (0x80000000u - 3);
rel->pa= cket_id =3D 0x80000001u;

assert_int_= equal(4, reliable_get_num_output_sequenced_available(rel));
@@ -196,7 +196,7 @@


/* test wrappin= g */
rel->array[5].active =3D true;
- rel->array[5].packet_id =3D (0= xffffffffu -3);

+ = rel->array[5].packet_id =3D (0xffffffffu - 3);
rel-= >array[6].active =3D false;
rel->packet_id =3D (= 0xffffffffu - 1);

@@ -224,7 +224,7 @@
assert_true(packet_id_write_epoch(&data->pis, 0x23= , &buf));

assert_int_equal(buf.l= en, 8);
- uint8_t ex= pected_header[8] =3D { 0x00, 0x23, 0, 0, 0, 0, 0, 1};
+ uint8_t expected_header[8] =3D { 0x00= , 0x23, 0, 0, 0, 0, 0, 1 };
assert_memory_equal(BPTR(&= amp;buf), expected_header, 8);

/* to= o small buffer should error out */
@@ -235,7 +235,7 @@
data->pis.id =3D 0xfa079ab9d2e8;
s= truct buffer buf_48 =3D alloc_buf_gc(128, &data->gc);
assert_true(packet_id_write_epoch(&data->pis, 0xfffe, &bu= f_48));

- uint8_t ex= pected_header_48[8] =3D { 0xff, 0xfe, 0xfa, 0x07, 0x9a, 0xb9, 0xd2, 0xe9};<= /span>
+ uint8_t expected= _header_48[8] =3D { 0xff, 0xfe, 0xfa, 0x07, 0x9a, 0xb9, 0xd2, 0xe9 };
assert_memory_equal(BPTR(&buf_48), expected_header_48, = 8);

/* test writing/checking the 48 = bit per epoch packet counter
@@ -243,7 +243,7 @@
= data->pis.id =3D 0xfffffffffffe;
struct = buffer buf_of =3D alloc_buf_gc(128, &data->gc);
= assert_true(packet_id_write_epoch(&data->pis, 0xf00f, &buf_of))= ;
- uint8_t expected= _header_of[8] =3D { 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};=
+ uint8_t expected_heade= r_of[8] =3D { 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
<= span> assert_memory_equal(BPTR(&buf_of), expected_header_of, 8);

/* This is go over 2^48 - 1 and should= error out. */
@@ -265,9 +265,9 @@
static = void
test_copy_acks_to_lru(void **state)
= {
- struct reliable_= ack ack =3D { .len =3D 4, .packet_id =3D {2, 1, 3, 2} };
+ struct reliable_ack ack =3D { .len= =3D 4, .packet_id =3D { 2, 1, 3, 2 } };

- struct reliable_ack mru_ack =3D {0= };
+ struct relia= ble_ack mru_ack =3D { 0 };

/* Test c= opying to empty ack structure */
copy_acks_to_mru(&= ;ack, &mru_ack, 4);
@@ -293,7 +293,7 @@

/* Adding just two packets shoudl ignore the 42 in = array and
* reorder the order in the MRU */- struct reliable_ack ack2 = =3D { .len =3D 3, .packet_id =3D {3, 2, 42} };
+ struct reliable_ack ack2 =3D { .len =3D 3, .= packet_id =3D { 3, 2, 42 } };
copy_acks_to_mru(&ac= k2, &mru_ack2, 2);
assert_int_equal(mru_ack2.packe= t_id[0], 3);
assert_int_equal(mru_ack2.packet_id[1], 2= );
@@ -314,12 +314,12 @@
assert_int_eq= ual(mru_ack.packet_id[1], 1);
assert_int_equal(mru_ack= .packet_id[2], 3);

- struct reliable_ack ack3 =3D { .len =3D 7, .packet_id = =3D {5, 6, 7, 8, 9, 10, 11}};
+ struct reliable_ack ack3 =3D { .len =3D 7, .packet_id =3D { 5= , 6, 7, 8, 9, 10, 11 } };

/* Adding = multiple acks tests if the a full array is handled correctly */
<= span> copy_acks_to_mru(&ack3, &mru_ack, 7);


- struct reliable_ack= expected_ack =3D { .len =3D 8, .packet_id =3D {5, 6, 7, 8, 9, 10, 11, 2}};=
+ struct reliable= _ack expected_ack =3D { .len =3D 8, .packet_id =3D { 5, 6, 7, 8, 9, 10, 11,= 2 } };
assert_int_equal(mru_ack.len, expected_ack.len= );

assert_memory_equal(mru_ack.packe= t_id, expected_ack.packet_id, sizeof(expected_ack.packet_id));
@@ -330,26 +330,19 @@

{
openvpn_u= nit_test_setup();
const struct CMUnitTest tests[] =3D = {
- cmocka_unit_= test_setup_teardown(test_packet_id_write_short,
- test_pack= et_id_write_setup,
+ = cmocka_unit_test_setup_teardown(test_packet_id_write_short, test_pac= ket_id_write_setup,
= test_packet_id_write_teardown),
- cmocka_unit_test_setup_teardown(test_packet_id_write_lo= ng,
- = test_packet_id_write_setup,
+ cmocka_unit_test_setup_teardown(test_= packet_id_write_long, test_packet_id_write_setup,
= test_packet_id_write_teardown),
<= span> cmocka_unit_test_setup_teardown(test_packet_id_write_short_pr= epend,

- = test_packet_id_write_setup,
- tes= t_packet_id_write_teardown),
+ test_packet_id_write_setup= , test_packet_id_write_teardown),
cmocka_unit_test= _setup_teardown(test_packet_id_write_long_prepend,
- test_p= acket_id_write_setup,
+ test_packet_id_write_setup, test_= packet_id_write_teardown),
+ cmocka_unit_test_setup_teardown(test_packet_id_write_short_w= rap, test_packet_id_write_setup,
= test_packet_id_write_teardown),
- cmocka_unit_test_setup_teardown(test_packe= t_id_write_short_wrap,
= - test_packet_id_write_setup,=
+ cmocka_unit_test_s= etup_teardown(test_packet_id_write_long_wrap, test_packet_id_write_setup,
test_packet_id_writ= e_teardown),
- c= mocka_unit_test_setup_teardown(test_packet_id_write_long_wrap,
- = test_packet_id_write_setup,

- test_packet_id_write_te= ardown),
- cmock= a_unit_test_setup_teardown(test_packet_id_write_epoch,
- te= st_packet_id_write_setup,
+ cmocka_unit_test_setup_teardown(test_packet_id_write_epoch, t= est_packet_id_write_setup,
= test_packet_id_write_teardown),

= cmocka_unit_test(test_get_num_output_sequenced_available),<= br>diff --git a/tests/unit_tests/openvpn/test_pkcs11.c b/tests/unit_t= ests/openvpn/test_pkcs11.c
index adad40b..9327523 100644
--- a/tests/unit_tests/openvpn/test_pkcs11.c
= +++ b/tests/unit_tests/openvpn/test_pkcs11.c
@@ -40,8 +40,8= @@
#include "test_common.h"

#define token_name "Test Token"
-#define PIN "12345"-#define HASHSIZE 20
<= span style=3D"color: hsl(120, 100%, 40%);">+#define PIN "12345&= quot;

+#define HASHSI= ZE 20


struct managem= ent *management; /* global */
@@ -59,8 +59,8 @@
<= span>

/* stubs for some unused functions instead of pulli= ng in too many dependencies */
int
-parse_line(const char *line, char **p, cons= t int n, const char *file,
- const int line_num, int msglevel, struct gc_arena *gc)
+parse_line(const char *l= ine, char **p, const int n, const char *file, const int line_num,+ int msglevel, stru= ct gc_arena *gc)
{
assert_true(0);
return 0;
@@ -92,45 +92,43 @@
= void
query_user_add(char *prompt, size_t prompt_len= , char *resp, size_t resp_len, bool echo)
{
- (void) prompt;

- (void) prompt_len;
- (void) resp;
- (void) resp_len;
- (void) echo;
+ (void)prompt;
+ (void)prompt_len;
+ (void)resp;
+ (void)resp_len;
+ (void)echo;
assert_true(0= );
}
void
purge_user_pas= s(struct user_pass *up, const bool force)
{
- (void) force;

+ (void)force;
= secure_memzero(up, sizeof(*up));
}

char *
-man= agement_query_pk_sig(struct management *man, const char *b64_data,- const = char *algorithm)
+man= agement_query_pk_sig(struct management *man, const char *b64_data, const ch= ar *algorithm)
{
- (void) man;
- (void) b64_data;
- (void) algorithm;
+ (void)man;
+ (void)b64_data;
+ (void)algorithm;
return NULL;
}=

-int=
-digest_sign_verify(EV= P_PKEY *privkey, EVP_PKEY *pubkey);
+int digest_sign_verify(EVP_PKEY *privkey, EVP_PKEY *pubkey)= ;

/* Test certificate database: data for= cert1, cert2 .. key1, key2 etc.
* are defined in cert_da= ta.h
*/
static struct test_cert {
- const c= har *const cert; /* certificate as PEM */
- const char *const key; /* = key as unencrypted PEM */
- const char *const cname; /* common-name */
- const char *const issuer; = /* issuer common-name */

- const char *const friendly_name; /* identifies certs loaded = to the store -- keep unique */
- uint8_t hash[HASHSIZE]; /* SHA1 fingerprint: compu= ted and filled in later */
- char *p11_id; /* PKCS#11 id -- filled in lat= er */
+ const char= *const cert; /* certificate as PEM */
+ const char *const key; /* key as = unencrypted PEM */
+ = const char *const cname; /* common-name */
+ const char *const issuer; /* i= ssuer common-name */
= + const char *const friendly_name; /* identifies certs loaded to the sto= re -- keep unique */
= + uint8_t hash[HASHSIZE]; /* SHA1 fingerprint: computed and fil= led in later */
+ = char *p11_id; /* PKCS#11 id -- filled in later */=
} certs[5];

static bool pkcs1= 1_id_management;
@@ -145,11 +143,11 @@
ini= t_cert_data(void)
{
struct test_cert = certs_local[] =3D {
- = {cert1, key1, cname1, "OVPN TEST CA1", "OVPN Test = Cert 1", {0}, NULL},
- {cert2, key2, cname2, "OVPN TEST CA2", "OV= PN Test Cert 2", {0}, NULL},
- {cert3, key3, cname3, "OVPN TEST CA1", = "OVPN Test Cert 3", {0}, NULL},
- {cert4, key4, cname4, "OVPN TEST CA2&= quot;, "OVPN Test Cert 4", {0}, NULL},
- {0}
+ { cert1, key1, cname1, "OVPN TEST CA1&= quot;, "OVPN Test Cert 1", { 0 }, NULL },
+ { cert2, key2, cname2, "OVPN= TEST CA2", "OVPN Test Cert 2", { 0 }, NULL },
+ { cert3, key3, cname3, &q= uot;OVPN TEST CA1", "OVPN Test Cert 3", { 0 }, NULL },
+ { cert4, key4, cn= ame4, "OVPN TEST CA2", "OVPN Test Cert 4", { 0 }, NULL = },
+ { 0 }

};
assert(sizeof(certs_local) =3D=3D= sizeof(certs));
memcpy(certs, certs_local, sizeof(cer= ts_local));
@@ -160,9 +158,9 @@
get_user_p= ass_cr(struct user_pass *up, const char *auth_file, const char *prefix,
const unsigned int flags, const char *unused= )
{
- = (void) unused;
+ = (void)unused;
bool ret =3D true;
- if (!strcmp(prefix, "pkcs11-id-r= equest") && flags&GET_USER_PASS_NEED_STR)
+ if (!strcmp(prefix, "pkcs11= -id-request") && flags & GET_USER_PASS_NEED_STR) {
assert_true(pkcs11_id_management);
strncpynt(up->password, pkcs11_id_current, sizeo= f(up->password));
@@ -196,15 +194,16 @@
= static int
init(void **state)
{- (void) state;
+ (void)state;


- umask(0077); /= * ensure all files and directories we create get user only access */=
+ umask(0077); /* ensure= all files and directories we create get user only access */
char config[256];


init_cert_d= ata();
if (!mkdtemp(softhsm2_tokens_path))
<= span> {

- fa= il_msg("make tmpdir using template <%s> failed (error =3D %d)&qu= ot;, softhsm2_tokens_path, errno);
+ fail_msg("make tmpdir using template <%s>= failed (error =3D %d)", softhsm2_tokens_path,
+ errno);
= }

int fd =3D mkstemp(softhsm2_c= onf_path);
@@ -212,8 +211,7 @@
{
fail_msg("make tmpfile using template <%s> f= ailed (error =3D %d)", softhsm2_conf_path, errno);
= }
- snprintf(confi= g, sizeof(config), "directories.tokendir=3D%s/",
- softhsm2_tokens_path);
+ snprintf(config, s= izeof(config), "directories.tokendir=3D%s/", softhsm2_tokens_path= );
assert_int_equal(write(fd, config, strlen(config)),= strlen(config));
close(fd);
<= br>@@ -261,14 +259,16 @@
argv_free(&a);<= /span>
a =3D argv_new();
/* Use = numcerts+1 as a unique id of the object -- same id for matching cert and k= ey */
- argv_pri= ntf(&a, "%s --provider %s --load-certificate %s --label \"%s\= " --id %08x --login --write",
- P11TOOL_PATH, SOFTHSM2_MODULE_PATH, c= ert, c->friendly_name, num_certs+1);
+ argv_printf(
+ &a, "%s --provider %s --load-cert= ificate %s --label \"%s\" --id %08x --login --write",=
+ P11TOOL_PATH, = SOFTHSM2_MODULE_PATH, cert, c->friendly_name, num_certs + 1);
= assert_true(openvpn_execve_check(&a, es, 0, "Failed= to upload certificate into token"));

argv_free(&a);

a =3D argv_new();
- argv_printf(&= ;a, "%s --provider %s --load-privkey %s --label \"%s\" --id = %08x --login --write",
- P11TOOL_PATH, SOFTHSM2_MODULE_PATH, key, c->fr= iendly_name, num_certs+1);
+ argv_printf(&a,
+ "%s --provider %s --load-privkey %s= --label \"%s\" --id %08x --login --write",
+ P11TOOL_PATH, SO= FTHSM2_MODULE_PATH, key, c->friendly_name, num_certs + 1);
assert_true(openvpn_execve_check(&a, es, 0, "Failed to= upload key into token"));


= assert_int_equal(ftruncate(cert_fd, 0), 0);
@@ -289,7 +289,= 7 @@
static int
cleanup(void **state)
{
- (v= oid) state;
+ (voi= d)state;
struct argv a =3D argv_new();

argv_printf(&a, "%s --delete-token --token= \"%s\"", SOFTHSM2_UTIL_PATH, token_name);
@= @ -411,7 +411,7 @@
static void
test_tls_c= tx_use_pkcs11(void **state)
{
- (void) state;
+ (void)state;
struct tls_roo= t_ctx tls_ctx =3D {};
uint8_t sha1[HASHSIZE]; for (struct test_cert *c =3D certs; c->cert; c++)@@ -452,7 +452,8 @@
#else
= if (!SSL_CTX_check_private_key(tls_ctx.ctx))
{
- fail_msg(&quo= t;Certificate and private key in ssl_ctx do not match for <%s>",= c->friendly_name);
+ c->friendly_name);
= return;
}
#endif
= @@ -473,10 +474,8 @@
{
openvpn_= unit_test_setup();
const struct CMUnitTest tests[] =3D= {
- cmocka_unit= _test_setup_teardown(test_pkcs11_ids, setup_pkcs11,
- tea= rdown_pkcs11),
- = cmocka_unit_test_setup_teardown(test_tls_ctx_use_pkcs11, setup_pkcs11,
- = teardown_pkcs11),
+ cmocka_unit_test_setup_teardown(test_pkcs11_ids, setup= _pkcs11, teardown_pkcs11),
+ cmocka_unit_test_setup_teardown(test_tls_ctx_use_pkcs11, set= up_pkcs11, teardown_pkcs11),
cmocka_unit_test_setu= p_teardown(test_tls_ctx_use_pkcs11__management, setup_pkcs11,
teardown_pkcs11),

};

diff --git a/tests/unit_tests/openvpn/test_pkt.c= b/tests/unit_tests/openvpn/test_pkt.c
index ebffabe..b3b96= 80 100644
--- a/tests/unit_tests/openvpn/test_pkt.c<= br>+++ b/tests/unit_tests/openvpn/test_pkt.c
@@ -45,8= +45,8 @@
#include "reliable.h"
=
int
= -parse_line(const char *line, char **p, const int n, const char *file,
- const int line_= num, int msglevel, struct gc_arena *gc)
+parse_line(const char *line, char **p, const int n, con= st char *file, const int line_num,
+ int msglevel, struct gc_arena *gc)
{

/* Dummy function to get the linker happy, should= never be called */
assert_true(false);
@@ -56,8 +56,7 @@

/* Define this function here as dummy = since including the ssl_*.c files
* leads to having to in= clude even more unrelated code */
bool
-key_state_export_keying_material(struct t= ls_session *session,
- = const char *label, size_t label_size,
+key_state_export_keying_m= aterial(struct tls_session *session, const char *label, size_t label_size,<= /span>
void *ekm, size_t ekm_siz= e)
{
ASSERT(0);
@@ -9= 0,104 +89,73 @@
"-----END O= penVPN Static key V1-----\n"
= "</tls-auth>\n";

-const uint8_t client_reset_v2_none[] =3D
-{ 0x38, 0x68, 0x91, 0x92= , 0x3f, 0xa3, 0x10, 0x34,
- 0x37, 0x00, 0x00, 0x00, 0x00, 0x00 };
+const uint8_t client_reset_v2_none[] =3D { 0x38, 0= x68, 0x91, 0x92, 0x3f, 0xa3, 0x10,
+ 0x34, 0x37, 0x00, 0= x00, 0x00, 0x00, 0x00 };

-const uint8_t client_reset_v2_tls_auth[] =3D-{ 0x38, 0xde, 0x69, 0x4c, 0x5c,= 0x7b, 0xfb, 0xa2,
- 0= x74, 0x93, 0x53, 0x7c, 0x1d, 0xed, 0x4e, 0x78,
- 0x15, 0x29, 0xae, 0x7c, 0xfe, 0x4b, 0x8c, 0x6d,<= /span>
- 0x6b, 0x2b, 0x51, 0x= f0, 0x5a, 0x00, 0x00, 0x00,
- 0x01, 0x61, 0xd3, 0xbf, 0x6c, 0x00, 0x00, 0x00,
- 0x00, 0x00};
+const uint8_t client_reset_v2_tls_auth[] =3D {= 0x38, 0xde, 0x69, 0x4c, 0x5c, 0x7b, 0xfb, 0xa2, 0x74,
+ = 0x93, 0x53, 0x7c, 0x1d, 0xed, 0x4e, 0x78, 0x15, 0x29,
+ = 0xae, 0x7c, 0xfe, 0x4b, 0x8c, 0x6d, 0x6b, 0x2b, 0x51,
+ = 0xf0, 0x5a, 0x00, 0x00, 0x00, 0x01, 0x61, 0xd3, 0xbf,
+ = 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00 };

-const uint8_t client_res= et_v2_tls_crypt[] =3D
-= {0x38, 0xf4, 0x19, 0xcb, 0x12, 0xd1, 0xf9, 0xe4,
- 0x8f, 0x00, 0x00, 0x00, 0x01, 0x61, 0xd3, 0xf8,=
- 0xe1, 0x33, 0x02, 0x= 06, 0xf5, 0x68, 0x02, 0xbe,
- 0x44, 0xfb, 0xed, 0x90, 0x50, 0x64, 0xe3, 0xdb,
- 0x43, 0x41, 0x6b, 0xec, 0x5e, 0x52, 0x67,= 0x19,
- 0x46, 0x2b, 0x= 7e, 0xb9, 0x0c, 0x96, 0xde, 0xfc,
- 0x9b, 0x05, 0xc4, 0x48, 0x79, 0xf7};
+const uint8_t client_reset_v2_tls_crypt[] =3D= {
+ 0x38, 0xf4, 0= x19, 0xcb, 0x12, 0xd1, 0xf9, 0xe4, 0x8f, 0x00, 0x00, 0x00, 0x01, 0x61,
+ 0xd3, 0xf8, 0xe1, 0x= 33, 0x02, 0x06, 0xf5, 0x68, 0x02, 0xbe, 0x44, 0xfb, 0xed, 0x90,
<= span style=3D"color: hsl(120, 100%, 40%);">+ 0x50, 0x64, 0xe3, 0xdb, 0x4= 3, 0x41, 0x6b, 0xec, 0x5e, 0x52, 0x67, 0x19, 0x46, 0x2b,

+ 0x7e, 0xb9, 0x0c, 0x96, 0xde, 0xfc= , 0x9b, 0x05, 0xc4, 0x48, 0x79, 0xf7
+};

/* Valid tls-auth cl= ient CONTROL_V1 packet with random server id */
const uint= 8_t client_ack_tls_auth_randomid[] =3D {
- 0x20, 0x14, 0x01, 0x4e, 0xbc, 0x80, 0xc6, 0x14,
- 0x2b, 0x7b, 0xc8, 0x76= , 0xfb, 0xc5, 0x2e, 0x27,
- 0xb1, 0xc5, 0x07, 0x35, 0x5b, 0xb6, 0x00, 0x6b,
- 0xae, 0x71, 0xba, 0x4e, 0x38, 0x00, 0= x00, 0x00,
- 0x03, 0= x61, 0xd3, 0xff, 0x53, 0x00, 0x00, 0x00,
- 0x00, 0x01, 0x16, 0x03, 0x01, 0x01, 0x0c, 0x01,
- 0x00, 0x01, 0x08, 0x03= , 0x03, 0x8c, 0xaa, 0xac,
- 0x3a, 0x1a, 0x07, 0xbd, 0xe7, 0xb7, 0x50, 0x06,
- 0x9b, 0x94, 0x0c, 0x34, 0x4b, 0x5a, 0= x35, 0xca,
- 0xc4, 0= x79, 0xbd, 0xc9, 0x09, 0xb0, 0x7b, 0xd9,
- 0xee, 0xbb, 0x7d, 0xe7, 0x25, 0x20, 0x39, 0x38,
- 0xe2, 0x18, 0x33, 0x36= , 0x14, 0x9f, 0x34, 0xf0,
- 0x44, 0x59, 0x96, 0x8d, 0x0e, 0xd2, 0x47, 0x76,
- 0x64, 0x88, 0x59, 0xe9, 0x38, 0x03, 0= x97, 0x96,
- 0x98, 0= x45, 0xfb, 0xf5, 0xff, 0x23, 0x00, 0x32,
- 0x13, 0x02, 0x13, 0x03, 0x13, 0x01, 0xc0, 0x2c,
- 0xc0, 0x30, 0x00, 0x9f= , 0xcc, 0xa9, 0xcc, 0xa8,
- 0xcc, 0xaa, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e,
- 0xc0, 0x24, 0xc0, 0x28, 0x00, 0x6b, 0= xc0, 0x23,
- 0xc0, 0= x27, 0x00, 0x67, 0xc0, 0x0a, 0xc0, 0x14,
- 0x00, 0x39, 0xc0, 0x09, 0xc0, 0x13, 0x00, 0x33,
- 0x00, 0xff, 0x01, 0x00= , 0x00, 0x8d, 0x00, 0x0b,
- 0x00, 0x04, 0x03, 0x00, 0x01, 0x02, 0x00, 0x0a,
- 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x1d, 0= x00, 0x17,
- 0x00, 0= x1e, 0x00, 0x19, 0x00, 0x18, 0x00, 0x16,
- 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x0d,
- 0x00, 0x30, 0x00, 0x2e= , 0x04, 0x03, 0x05, 0x03,
- 0x06, 0x03, 0x08, 0x07, 0x08, 0x08, 0x08, 0x09,
- 0x08, 0x0a, 0x08, 0x0b, 0x08, 0x04, 0= x08, 0x05,
- 0x08, 0= x06, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01,
- 0x03, 0x03, 0x02, 0x03, 0x03, 0x01, 0x02, 0x01,
- 0x03, 0x02, 0x02, 0x02= , 0x04, 0x02, 0x05, 0x02,
- 0x06, 0x02, 0x00, 0x2b, 0x00, 0x05, 0x04, 0x03,
- 0x04, 0x03, 0x03, 0x00, 0x2d, 0x00, 0= x02, 0x01,
- 0x01, 0= x00, 0x33, 0x00, 0x26, 0x00, 0x24, 0x00,
- 0x1d, 0x00, 0x20, 0x0e, 0xc9, 0x7a, 0xff, 0x58,
- 0xdb, 0x56, 0xf6, 0x40= , 0xd1, 0xed, 0xdb, 0x91,
- 0x81, 0xd6, 0xef, 0x83, 0x86, 0x8a, 0xb2, 0x3d,
- 0x88, 0x92, 0x3f, 0xd8, 0x51, 0x9c, 0= xd6, 0x26,
- 0x56, 0= x33, 0x6b
+ 0x20, = 0x14, 0x01, 0x4e, 0xbc, 0x80, 0xc6, 0x14, 0x2b, 0x7b, 0xc8, 0x76, 0xfb, 0xc= 5, 0x2e, 0x27,
+ 0= xb1, 0xc5, 0x07, 0x35, 0x5b, 0xb6, 0x00, 0x6b, 0xae, 0x71, 0xba, 0x4e, 0x38= , 0x00, 0x00, 0x00,
+= 0x03, 0x61, 0xd3, 0xff, 0x53, 0x00, 0x00, 0x00, 0x00, 0x01, 0x16, 0x03,= 0x01, 0x01, 0x0c, 0x01,
+ 0x00, 0x01, 0x08, 0x03, 0x03, 0x8c, 0xaa, 0xac, 0x3a, 0x1a, 0x07, = 0xbd, 0xe7, 0xb7, 0x50, 0x06,
+ 0x9b, 0x94, 0x0c, 0x34, 0x4b, 0x5a, 0x35, 0xca, 0xc4, 0x79, 0= xbd, 0xc9, 0x09, 0xb0, 0x7b, 0xd9,
+ 0xee, 0xbb, 0x7d, 0xe7, 0x25, 0x20, 0x39, 0x38, 0xe2, 0x= 18, 0x33, 0x36, 0x14, 0x9f, 0x34, 0xf0,
+ 0x44, 0x59, 0x96, 0x8d, 0x0e, 0xd2, 0x47, 0x76, 0x6= 4, 0x88, 0x59, 0xe9, 0x38, 0x03, 0x97, 0x96,
+ 0x98, 0x45, 0xfb, 0xf5, 0xff, 0x23, 0x00, 0x32= , 0x13, 0x02, 0x13, 0x03, 0x13, 0x01, 0xc0, 0x2c,
+ 0xc0, 0x30, 0x00, 0x9f, 0xcc, 0xa9, 0xcc,= 0xa8, 0xcc, 0xaa, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e,
+ 0xc0, 0x24, 0xc0, 0x28, 0x00, 0x6b, = 0xc0, 0x23, 0xc0, 0x27, 0x00, 0x67, 0xc0, 0x0a, 0xc0, 0x14,
+ 0x00, 0x39, 0xc0, 0x09, 0xc0, 0= x13, 0x00, 0x33, 0x00, 0xff, 0x01, 0x00, 0x00, 0x8d, 0x00, 0x0b,

= + 0x00, 0x04, 0x03, 0x00, 0x= 01, 0x02, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x1d, 0x00, 0x17,
+ 0x00, 0x1e, 0x00, 0x1= 9, 0x00, 0x18, 0x00, 0x16, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x0d,<= /span>
+ 0x00, 0x30, 0x00= , 0x2e, 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x08, 0x07, 0x08, 0x08, 0x08, 0= x09,
+ 0x08, 0x0a,= 0x08, 0x0b, 0x08, 0x04, 0x08, 0x05, 0x08, 0x06, 0x04, 0x01, 0x05, 0x01, 0x= 06, 0x01,
+ 0x03, = 0x03, 0x02, 0x03, 0x03, 0x01, 0x02, 0x01, 0x03, 0x02, 0x02, 0x02, 0x04, 0x0= 2, 0x05, 0x02,
+ 0= x06, 0x02, 0x00, 0x2b, 0x00, 0x05, 0x04, 0x03, 0x04, 0x03, 0x03, 0x00, 0x2d= , 0x00, 0x02, 0x01,
+= 0x01, 0x00, 0x33, 0x00, 0x26, 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0x0e,= 0xc9, 0x7a, 0xff, 0x58,
+ 0xdb, 0x56, 0xf6, 0x40, 0xd1, 0xed, 0xdb, 0x91, 0x81, 0xd6, 0xef, = 0x83, 0x86, 0x8a, 0xb2, 0x3d,
+ 0x88, 0x92, 0x3f, 0xd8, 0x51, 0x9c, 0xd6, 0x26, 0x56, 0x33, 0= x6b
};

/* This is a tru= ncated packet as we do not care for the TLS payload in the
= * unit test */
-const= uint8_t client_control_with_ack[] =3D {
- 0x20, 0x78, 0x19, 0xbf, 0x2e, 0xbc, 0xd1, 0x9a,
- 0x45, 0x01, 0x00, 0x00= , 0x00, 0x00, 0xea,
- = 0xfe, 0xbf, 0xa4, 0x41, 0x8a, 0xe3, 0x1b,
- 0x00, 0x00, 0x00, 0x01, 0x16, 0x03, 0x01-};
+const uint8_t client_control_with_ack[] =3D { 0= x20, 0x78, 0x19, 0xbf, 0x2e, 0xbc, 0xd1, 0x9a,
+ 0x45= , 0x01, 0x00, 0x00, 0x00, 0x00, 0xea, 0xfe,
+ 0xbf, 0= xa4, 0x41, 0x8a, 0xe3, 0x1b, 0x00, 0x00,
+ 0x00, 0x01= , 0x16, 0x03, 0x01 };

-const uint8_t client_ack_none_random_id[] =3D {- 0x28, 0xae, 0xb9, 0xaf, 0xe= 1, 0xf0, 0x1d, 0x79,
- = 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0xdd,
- 0x85, 0xdb, 0x53, 0x56, 0x23, 0xb0, 0x2e<= br>-};
+const uint8_t client_ack_none_random_id[] =3D = { 0x28, 0xae, 0xb9, 0xaf, 0xe1, 0xf0, 0x1d, 0x79,
+ = 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0xdd, 0x85,
+ = 0xdb, 0x53, 0x56, 0x23, 0xb0, 0x2e };

st= ruct tls_auth_standalone
init_tas_auth(int key_direction)<= /span>
{
struct tls_auth_standalone tas =3D = { 0 };
- struct fram= e frame =3D { {.headroom =3D 200, .payload_size =3D 1400}, 0};
+ struct frame frame =3D { { .= headroom =3D 200, .payload_size =3D 1400 }, 0 };

tas.f= rame =3D frame;

tas.tls_wrap.mode = =3D TLS_WRAP_AUTH;
/* we ignore packet ids on for the = first packet check */
-= tas.tls_wrap.opt.flags |=3D (CO_IGNORE_PACKET_ID|CO_PACKET_ID_LONG_FORM= );
+ tas.tls_wrap.= opt.flags |=3D (CO_IGNORE_PACKET_ID | CO_PACKET_ID_LONG_FORM);

struct key_type tls_crypt_kt;
= init_key_type(&tls_crypt_kt, "none", "SHA1", tru= e, false);

- crypto_read_openvpn_key(&tls_crypt_kt, &tas.tls_wrap.opt= .key_ctx_bi,
- = static_key, true, key_direction,
- "Control C= hannel Authentication", "tls-auth",
- NULL);
<= span style=3D"color: hsl(120, 100%, 40%);">+ crypto_read_openvpn_key(&am= p;tls_crypt_kt, &tas.tls_wrap.opt.key_ctx_bi, static_key, true,
<= br>+ = key_direction, "Control Channel Authentication", "tls-auth&= quot;, NULL);
tas.workbuf =3D alloc_buf(1600);<= br>
return tas;
@@ -198,11 +166= ,10 @@
{
struct tls_auth_standalone t= as =3D { 0 };
tas.tls_wrap.mode =3D TLS_WRAP_CRYPT;
- tas.tls_wrap.opt.fla= gs |=3D (CO_IGNORE_PACKET_ID|CO_PACKET_ID_LONG_FORM);
+ tas.tls_wrap.opt.flags |=3D (CO_IGNOR= E_PACKET_ID | CO_PACKET_ID_LONG_FORM);

- tls_crypt_init_key(&tas.tls_wrap= .opt.key_ctx_bi,
- = &tas.tls_wrap.original_wrap_keydata, static_key,
- tru= e, server);
+ tls_= crypt_init_key(&tas.tls_wrap.opt.key_ctx_bi, &tas.tls_wrap.original= _wrap_keydata,
+ = static_key, true, server);
tas.workb= uf =3D alloc_buf(1600);
tas.tls_wrap.work =3D alloc_bu= f(1600);

@@ -249,7 +216,7 @@
free_tls_pre_decrypt_state(&state);

/* flip a byte in various places */
- for (int i =3D 0; i<sizeof(client_reset_v= 2_tls_crypt); i++)
+ = for (int i =3D 0; i < sizeof(client_reset_v2_tls_crypt); i++)<= br> {
buf_reset_len(&buf); buf_write(&buf, client_reset_v2_tls_crypt, sizeof(clien= t_reset_v2_tls_crypt));
@@ -392,7 +359,7 @@
assert_int_equal(ack.len, 1);

assert_int_equal(a= ck.packet_id[0], 0);

- struct session_id expected_id =3D { .id =3D {0xea, 0xf= e, 0xbf, 0xa4, 0x41, 0x8a, 0xe3, 0x1b }};
+ struct session_id expected_id =3D { .id =3D { 0xe= a, 0xfe, 0xbf, 0xa4, 0x41, 0x8a, 0xe3, 0x1b } };
asser= t_memory_equal(&sid, &expected_id, SID_SIZE);

buf_reset_len(&buf);
@@ -406,7 +373,7= @@
assert_int_equal(ack.len, 1);
= assert_int_equal(ack.packet_id[0], 0);

- struct session_id expected_id2 =3D = { .id =3D {0xdd, 0x85, 0xdb, 0x53, 0x56, 0x23, 0xb0, 0x2e }};
+ struct session_id expected_id= 2 =3D { .id =3D { 0xdd, 0x85, 0xdb, 0x53, 0x56, 0x23, 0xb0, 0x2e } };
assert_memory_equal(&sid, &expected_id2, SID_SIZE);=

buf_reset_len(&buf);
= @@ -485,7 +452,7 @@
ASSERT(md_valid("SHA256= "));
hmac_ctx_t *hmac_ctx =3D hmac_ctx_new();


- uin= t8_t key[SHA256_DIGEST_LENGTH] =3D {1, 2, 3, 0};
+ uint8_t key[SHA256_DIGEST_LENGTH] =3D { 1,= 2, 3, 0 };

hmac_ctx_init(hmac_ctx, = key, "SHA256");
return hmac_ctx;
<= span>@@ -503,28 +470,30 @@

addr.addr.in4.sin_addr.s_ad= dr =3D ntohl(0xff000ff);
addr.addr.in4.sin_port =3D nt= ohs(1195);

- struct session_id client_id =3D { {0, 1, 2, 3, 4, 5, 6, 7}};
+ struct session_id c= lient_id =3D { { 0, 1, 2, 3, 4, 5, 6, 7 } };

now =3D 1005;

struct session_id server_id =3D= calculate_session_id_hmac(client_id, &addr, hmac, handwindow, 0);


- struct session_id expected_server_id =3D {{0x84, 0x73, 0x52, = 0x2b, 0x5b, 0xa9, 0x2a, 0x70}};
+ struct session_id expected_server_id =3D { { 0x84, 0x73, 0x= 52, 0x2b, 0x5b, 0xa9, 0x2a, 0x70 } };
/* We have to de= al with different structs here annoyingly */
/* Linux = has an unsigned short int as family_t and this is field is always * stored in host endianness even though the rest of the struct= isn't...,
* so Linux little endian differs from = all BSD and Linux big endian */
- if (sizeof(addr.addr.in4.sin_family) =3D=3D sizeof(unsigned s= hort int)
- &= ;& ntohs(AF_INET) !=3D AF_INET)
+ if (sizeof(addr.addr.in4.sin_family) =3D=3D sizeof(unsi= gned short int) && ntohs(AF_INET) !=3D AF_INET)
= {
- struct ses= sion_id linuxle =3D {{0x8b, 0xeb, 0x3d, 0x20, 0x14, 0x53, 0xbe, 0x0a }};
+ struct session= _id linuxle =3D { { 0x8b, 0xeb, 0x3d, 0x20, 0x14, 0x53, 0xbe, 0x0a } };
expected_server_id =3D linuxle;
= }
assert_memory_equal(expected_server_id.id, server_id= .id, SID_SIZE);

- struct session_id server_id_m1 =3D calculate_session_id_hma= c(client_id, &addr, hmac, handwindow, -1);
- struct session_id server_id_p1 =3D calculate_s= ession_id_hmac(client_id, &addr, hmac, handwindow, 1);
- struct session_id server_id_p2 =3D= calculate_session_id_hmac(client_id, &addr, hmac, handwindow, 2);
+ struct session_id se= rver_id_m1 =3D
+ = calculate_session_id_hmac(client_id, &addr, hmac, handwindow, -1);
+ struct session_id= server_id_p1 =3D
+ = calculate_session_id_hmac(client_id, &addr, hmac, handwindow, 1);=
+ struct session_= id server_id_p2 =3D
+= calculate_session_id_hmac(client_id, &addr, hmac, handwindow, 2= );

assert_memory_not_equal(expected_= server_id.id, server_id_m1.id, SID_SIZE);
assert_memor= y_not_equal(expected_server_id.id, server_id_p1.id, SID_SIZE);
@@ -533,10 +502,13 @@

* and shifts the ids by one= */
now =3D 1062;

- struct session_id server_id2_m2 =3D = calculate_session_id_hmac(client_id, &addr, hmac, handwindow, -2);
- struct session_id serv= er_id2_m1 =3D calculate_session_id_hmac(client_id, &addr, hmac, handwin= dow, -1);
+ struct= session_id server_id2_m2 =3D
+ calculate_session_id_hmac(client_id, &addr, hmac, han= dwindow, -2);
+ st= ruct session_id server_id2_m1 =3D
+ calculate_session_id_hmac(client_id, &addr, hmac,= handwindow, -1);
struct session_id server_id2 =3D cal= culate_session_id_hmac(client_id, &addr, hmac, handwindow, 0);- struct session_id server_i= d2_p1 =3D calculate_session_id_hmac(client_id, &addr, hmac, handwindow,= 1);
+ struct sess= ion_id server_id2_p1 =3D
+ calculate_session_id_hmac(client_id, &addr, hmac, handwind= ow, 1);

assert_memory_equal(server_i= d2_m2.id, server_id_m1.id, SID_SIZE);
assert_memory_eq= ual(server_id2_m1.id, expected_server_id.id, SID_SIZE);
@@ = -554,19 +526,20 @@
struct tls_auth_standalone tas =3D = { 0 };
struct tls_pre_decrypt_state state =3D { 0 };

- s= truct session_id client_id =3D {{0, 1, 2, 3, 4, 5, 6, 7}};
- struct session_id server_id =3D {{= 8, 9, 0, 9, 8, 7, 6, 2}};
+ struct session_id client_id =3D { { 0, 1, 2, 3, 4, 5, 6, 7 } };
+ struct session_id= server_id =3D { { 8, 9, 0, 9, 8, 7, 6, 2 } };

= enum first_packet_verdict verdict;

<= span> tas.tls_wrap.mode =3D TLS_WRAP_NONE;

- struct frame frame =3D { {.headroom =3D 200, .= payload_size =3D 1400}, 0};
+ struct frame frame =3D { { .headroom =3D 200, .payload_size =3D= 1400 }, 0 };
tas.frame =3D frame;
= tas.workbuf =3D alloc_buf(1600);

u= int8_t header =3D 0 | (P_CONTROL_HARD_RESET_CLIENT_V2 << P_OPCODE_SHI= FT);

= - struct buffer buf =3D tls_reset_standalone(&tas.tls_wrap, &tas= , &client_id, &server_id, header, false);
+ struct buffer buf =3D
+ tls_reset_standalone(&tas.t= ls_wrap, &tas, &client_id, &server_id, header, false);

verdict =3D tls_pre_decryp= t_lite(&tas, &state, &from, &buf);
@@ -574,= 7 +547,8 @@

/* Assure repeated gener= ation of reset is deterministic/stateless*/
assert_mem= ory_equal(state.peer_session_id.id, client_id.id, SID_SIZE);
- struct buffer buf2 =3D tls_reset= _standalone(&tas.tls_wrap, &tas, &client_id, &server_id, he= ader, false);

+ st= ruct buffer buf2 =3D
= + tls_reset_standalone(&tas.tls_wrap, &tas, &client_id, = &server_id, header, false);
assert_int_equal(BLEN(= &buf), BLEN(&buf2));
assert_memory_equal(BPTR(= &buf), BPTR(&buf2), BLEN(&buf));

@@ -593,14 +567,15 @@


packet_id_= init(&tas_client.tls_wrap.opt.packet_id, 5, 5, "UNITTEST", 0)= ;

- = struct session_id client_id =3D {{0xab, 1, 2, 3, 4, 5, 6, 0xcd}};<= br>- struct session_id server_= id =3D {{8, 9, 0xa, 0xc, 8, 7, 6, 2}};
+ struct session_id client_id =3D { { 0xab, 1, 2, 3, 4= , 5, 6, 0xcd } };
+ = struct session_id server_id =3D { { 8, 9, 0xa, 0xc, 8, 7, 6, 2 } };

uint8_t header =3D 0 | (P_CONTROL_HARD_RE= SET_CLIENT_V2 << P_OPCODE_SHIFT);

= now =3D 0x22446688;
reset_packet_id_send(&tas_= client.tls_wrap.opt.packet_id.send);
- struct buffer buf =3D tls_reset_standalone(&tas_clie= nt.tls_wrap, &tas_client, &client_id, &server_id, header, false= );
+ struct buffer= buf =3D tls_reset_standalone(&tas_client.tls_wrap, &tas_client, &a= mp;client_id,
+ = &server_id, header, false);

enum first_packet_verdict verdict =3D tl= s_pre_decrypt_lite(&tas_server, &state, &from, &buf);
assert_int_equal(verdict, VERDICT_VALID_RESET_V2);@@ -609,7 +584,8 @@

/* Assur= e repeated generation of reset is deterministic/stateless*/
reset_packet_id_send(&tas_client.tls_wrap.opt.packet_id.send);
- struct buffer buf2 = =3D tls_reset_standalone(&tas_client.tls_wrap, &tas_client, &cl= ient_id, &server_id, header, false);
+ struct buffer buf2 =3D tls_reset_standalone(&t= as_client.tls_wrap, &tas_client, &client_id,
+ = &server_id, header, false);
assert_int_equal(= BLEN(&buf), BLEN(&buf2));
assert_memory_equal(= BPTR(&buf), BPTR(&buf2), BLEN(&buf));
<= br>@@ -645,7 +621,7 @@
assert_string_equal(BSTR(= &cmd4), "valid one again");
assert_int_e= qual(cmd5.len, 0);

- const uint8_t nonull[6] =3D { 'n', 'o', = ' ', 'N', 'U', 'L'};
+ const uint8_t nonull[6] =3D { 'n&= #39;, 'o', ' ', 'N', 'U', 'L' };
struct buffer nonull_buf =3D alloc_buf_gc(1024, &gc)= ;

buf_write(&nonull_buf, nonull,= sizeof(nonull));
@@ -659,18 +635,16 @@
ma= in(void)
{
openvpn_unit_test_setup();=
- const struct CMUn= itTest tests[] =3D {
- = cmocka_unit_test(test_tls_decrypt_lite_none),
- cmocka_unit_test(test_tls_decrypt_l= ite_auth),
- cmo= cka_unit_test(test_tls_decrypt_lite_crypt),
- cmocka_unit_test(test_parse_ack),
<= span style=3D"color: hsl(0, 100%, 40%);">- cmocka_unit_test(test_cal= c_session_id_hmac_static),

- cmocka_unit_test(test_verify_hmac_none),
- cmocka_unit_test(test_verify_hmac_t= ls_auth),
- cmoc= ka_unit_test(test_generate_reset_packet_plain),
- cmocka_unit_test(test_generate_reset_pack= et_tls_auth),
- = cmocka_unit_test(test_extract_control_message)
- };
+ const struct CMUnitTest tests[] =3D { cmocka_unit_test(test= _tls_decrypt_lite_none),
+ cmocka_unit_test(test_tls_decr= ypt_lite_auth),
+ = cmocka_unit_test(test_tls_decrypt_lite_= crypt),
+ = cmocka_unit_test(test_parse_ack),
+ = cmocka_unit_test(test_calc_session_id_hmac_static),

+ = cmocka_unit_test(test_verify_hmac_none),
+ cmocka_uni= t_test(test_verify_hmac_tls_auth),
+ cmocka_unit_test(tes= t_generate_reset_packet_plain),
+ cmocka_unit_test(test_g= enerate_reset_packet_tls_auth),
+ cmocka_unit_test(test_e= xtract_control_message) };

#if defined(E= NABLE_CRYPTO_OPENSSL)
OpenSSL_add_all_algorithms();
diff --git a/tests/unit_tests/openvpn/test_provider.c b/tests= /unit_tests/openvpn/test_provider.c
index fd38d3b..1c4af2e = 100644
--- a/tests/unit_tests/openvpn/test_provider.c
+++ b/tests/unit_tests/openvpn/test_provider.c
@= @ -46,7 +46,7 @@
static int mgmt_callback_called;
#ifndef _countof
-#define _countof(x) sizeof((x))/sizeof(*(x))+#define _countof(x) sizeof((= x)) / sizeof(*(x))
#endif

static OSSL_PROVIDER *prov[2];

@@ -71,7 +71,7 @@<= br> "MCowBQYDK2VwAyEA+q5xjF5hGyyqY= ZidJdz/0saEQabL3N4wIZJBxNGbgJE=3D\n"
= "-----END PUBLIC KEY-----";

-static const char *pubkeys[= ] =3D {pubkey1, pubkey2, pubkey3};
+static const char *pubkeys[] =3D { pubkey1, pubkey2, pubkey3= };

static const char *prov_name =3D &qu= ot;ovpn.xkey";

@@ -85,11 +85,10 @@
"bG9yZSBtYWduYSBhbGlxdWEu";
=
/* Sha256 digest of test_msg excluding NUL terminator */<= /span>
-static const uint8_t t= est_digest[] =3D {
- = 0x77, 0x38, 0x65, 0x00, 0x1e, 0x96, 0x48, 0xc6, 0x57, 0x0b, 0xae,- 0xc0, 0xb7, 0x96, 0xf9, 0x= 66, 0x4d, 0x5f, 0xd0, 0xb7, 0xdb, 0xf3,
- 0x3a, 0xbf, 0x02, 0xcc, 0x78, 0x61, 0x83, 0x20, 0x20,= 0xee
-};
+static const uint8_t test_digest[= ] =3D { 0x77, 0x38, 0x65, 0x00, 0x1e, 0x96, 0x48, 0xc6,

+ = 0x57, 0x0b, 0xae, 0xc0, 0xb7, 0x96, 0xf9, 0x66,
+ 0x4d, 0x= 5f, 0xd0, 0xb7, 0xdb, 0xf3, 0x3a, 0xbf,
+ 0x02, 0xcc, 0x78= , 0x61, 0x83, 0x20, 0x20, 0xee };

static= const char *test_digest_b64 =3D "dzhlAB6WSMZXC67At5b5Zk1f0Lfb8zq/Asx4= YYMgIO4=3D";

@@ -98,10 +97,9 @@
* --- the smallest size of the actual signature with the abov= e
* keys.
*/
-static const uint8_t good_sig[] =3D {
= - 0xd8, 0xa7, 0xd9, 0x81, 0xd8= , 0xaa, 0xd8, 0xad, 0x20, 0xd9, 0x8a, 0xd8,
- 0xa7, 0x20, 0xd8, 0xb3, 0xd9, 0x85, 0xd8, 0xb3, 0= xd9, 0x85, 0x0
-};
+static const uint8_t goo= d_sig[] =3D { 0xd8, 0xa7, 0xd9, 0x81, 0xd8, 0xaa, 0xd8, 0xad,
+ = 0x20, 0xd9, 0x8a, 0xd8, 0xa7, 0x20, 0xd8, 0xb3,

+ 0xd9, 0x= 85, 0xd8, 0xb3, 0xd9, 0x85, 0x0 };

stati= c const char *good_sig_b64 =3D "2KfZgdiq2K0g2YrYpyDYs9mF2LPZhQA=3D&quo= t;;

@@ -154,8 +152,7 @@
= * the management client.
*/
char *
-management_query_pk_sig(st= ruct management *man, const char *b64_data,
- const char *algorithm)=
+management_query_pk_sig(st= ruct management *man, const char *b64_data, const char *algorithm) {
char *out =3D NULL;

@@ -196,7 +193,7 @@
{
asse= rt_true(OSSL_PROVIDER_available(NULL, prov_name));
=
- const char *algs[] =3D {= "RSA", "ECDSA"};
+ const char *algs[] =3D { "RSA", "ECDSA&= quot; };

for (size_t i =3D 0; i <= _countof(algs); i++)
{
@@ -207,7 +204= ,7 @@
EVP_SIGNATURE_free(sig);
= }

-= const char *names[] =3D {"RSA", "EC"};
+ const char *names[] =3D { &q= uot;RSA", "EC" };


for= (size_t i =3D 0; i < _countof(names); i++)
{
@@ -226,7 +223,7 @@
uint8_t *sig =3D NULL;<= /span>
size_t siglen =3D 0;

- OSSL_PARAM params[6] =3D {OSSL_PA= RAM_END};

+ OSSL_P= ARAM params[6] =3D { OSSL_PARAM_END };

= const char *mdname =3D "SHA256";
const ch= ar *padmode =3D "pss";
@@ -234,11 +231,15 @@

if (EVP_PKEY_get_id(pkey) =3D=3D EVP_PKE= Y_RSA)
{
- params[0] =3D OSSL_PARAM_construct_utf8_string(OSSL_SIGNATU= RE_PARAM_DIGEST, (char *)mdname, 0);
- params[1] =3D OSSL_PARAM_construct_utf8_string(OSSL_= SIGNATURE_PARAM_PAD_MODE, (char *)padmode, 0);
- params[2] =3D OSSL_PARAM_construct_utf8_st= ring(OSSL_SIGNATURE_PARAM_PSS_SALTLEN, (char *)saltlen, 0);
+ params[0] =3D

+ OSSL_PARAM_construct_= utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, (char *)mdname, 0);

+ params[1] =3D

+ OSSL_PARAM_construct= _utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE, (char *)padmode, 0);

= + params[2] =3D+ OSSL_PARAM_const= ruct_utf8_string(OSSL_SIGNATURE_PARAM_PSS_SALTLEN, (char *)saltlen, 0);
/* same digest for mgf1 */
- params[3] =3D OSSL_PARAM_construct_utf8_= string(OSSL_SIGNATURE_PARAM_MGF1_DIGEST, (char *)saltlen, 0);
+ params[3] =3D

<= span style=3D"color: hsl(120, 100%, 40%);">+ OSSL_PARAM_construc= t_utf8_string(OSSL_SIGNATURE_PARAM_MGF1_DIGEST, (char *)saltlen, 0);
=
params[4] =3D OSSL_PARAM_construct_end();
}

else if (EVP_PKEY_get_id(pkey) =3D=3D EVP_PKE= Y_ED25519)
@@ -251,8 +252,7 @@
EVP_PKE= Y_CTX *pctx =3D NULL;
EVP_MD_CTX *mctx =3D EVP_MD_CTX_= new();

- = || EVP_DigestSignInit_ex(mctx, &pctx, mdname, NULL, NULL, pkey, par= ams) <=3D 0)
+ = if (!mctx || EVP_DigestSignInit_ex(mctx, &pctx, mdname, NULL, NULL, pke= y, params) <=3D 0)
{
fail_= msg("Failed to initialize EVP_DigestSignInit_ex()");
goto done;

@@ -292,7 +292,7 @@
EVP_PKEY *privkey =3D xkey_load_management_key(NULL, pubkey);
assert_true(privkey !=3D NULL);

- management->se= ttings.flags =3D MF_EXTERNAL_KEY|MF_EXTERNAL_KEY_PSSPAD;
+ management->settings.flags = =3D MF_EXTERNAL_KEY | MF_EXTERNAL_KEY_PSSPAD;

<= span> /* first without digest support in management client */

again:
@@ -329,8 +329,8 @@
}

static int
-xkey_sign(void *handle, unsigned char *sig, size_t *= siglen,
- cons= t unsigned char *tbs, size_t tbslen, XKEY_SIGALG s)
+xkey_sign(void *handle, unsigned char *si= g, size_t *siglen, const unsigned char *tbs, size_t tbslen,
+ XKEY_SIGALG s)

= {
if (!sig)
{
@@ -387,7 +387,8 @@

pubkey =3D load_pubkey(pub= keys[i]);
assert_true(pubkey !=3D NULL);
- EVP_P= KEY *privkey =3D xkey_load_generic_key(NULL, (void *)dummy, pubkey, xkey_si= gn, xkey_free);
+ = EVP_PKEY *privkey =3D
+ xkey_load_generic_key(NULL, (void *)dummy, pubkey, xkey_s= ign, xkey_free);
assert_true(privkey !=3D NULL);

xkey_sign_called =3D 0;diff --git a/tests/unit_tests/openvpn/test_ssl.c b/tests/unit_tests/= openvpn/test_ssl.c
index 2a05c4f..058883b 100644
= --- a/tests/unit_tests/openvpn/test_ssl.c
+++ b/tests= /unit_tests/openvpn/test_ssl.c
@@ -160,7 +160,7 @@ static int
init(void **state)
{<= /span>
- (void) state;
+ (void)state;<= br> global_state.gc =3D gc_new();
global_sta= te.certfile =3D platform_create_temp_file(get_tmp_dir(), "cert", = &global_state.gc);
global_state.keyfile =3D platfo= rm_create_temp_file(get_tmp_dir(), "key", &global_state.gc);<= /span>
@@ -181,7 +181,7 @@
static int
<= span> cleanup(void **state)

{
- (void) state;
+ (void)state;
unlink(global_= state.certfile);
unlink(global_state.keyfile);<= br> gc_free(&global_state.gc);
@@ -221,7 +221= ,7 @@
static void
test_load_certificate_a= nd_key(void **state)
{
- (void) state;
+ (void)state;
struct tls_root_ctx c= tx =3D { 0 };

/* test loading of inl= ined cert and key.
@@ -243,11 +243,11 @@
s= tatic void
test_load_certificate_and_key_uri(void **state)=
{
- = (void) state;
+ = (void)state;

#if !defined(HAVE_OPENSSL_S= TORE)
skip();
-#else /* HAVE_OPENSSL_STORE */
+#else /* HAVE_OPENSSL_STORE */

struct tls_root_ctx ctx =3D { 0 };
= const char *certfile =3D global_state.certfile;
@@ -307,7 = +307,6 @@
frame->buf.tailroom =3D overhead;<= br>
frame->tun_mtu =3D tls_mtu;
-

}

static void
@@ -334,7 +333,6 @@=
/* Test encryption, decryption for all packet sizes */
for (int i =3D 1; i <=3D frame.buf.payload_size; ++i)
{
-<= /span>
/* msg(M_INFO, "TESTING ENCRYPT/DECRYPT of pa= cket length=3D%d", i); */

/= *
@@ -414,7 +412,6 @@
static void check_aead_limits(struct crypto_options *co, bool chachapoly)
{
-=
/* Check that we correctly react when we have a nearing AEAD= limits */

/* manually increase the = send counter to be past
@@ -446,9 +443,8 @@
{

/* Check always against the GCM usage limi= t here to see if that
* check works */
= - assert_true(aead_usage_l= imit_reached((1ull << 36),
- &co->key_ctx= _bi.encrypt,
- = co->packet_id.send.id));
<= span style=3D"color: hsl(120, 100%, 40%);">+ assert_true(

= + aead_usage_limit_r= eached((1ull << 36), &co->key_ctx_bi.encrypt, co->packet_id= .send.id));
return;
}<= br>
@@ -465,10 +461,9 @@

static struct crypto_options
-init_crypto_options(const char *cipher, co= nst char *auth, bool epoch,
- struct key2 *statickey)
+init_crypto_options(const char *cipher, const= char *auth, bool epoch, struct key2 *statickey)
{<= br>- struct key2 key2 =3D { .n= =3D 2};
+ struct = key2 key2 =3D { .n =3D 2 };

if (stat= ickey)
{
@@ -489,7 +484,7 @@
if (epoch)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- struct epoch_key e1 =3D {= .epoch =3D 1, .epoch_key =3D { 0 }};

+ struct epoch_key e1 =3D { .epoch =3D 1, .epoch_ke= y =3D { 0 } };
memcpy(e1.epoch_key, key2.keys[0].c= ipher, sizeof(e1.epoch_key));
co.flags |=3D CO_EPO= CH_DATA_KEY_FORMAT;
epoch_init_key_ctx(&co, &a= mp;kt, &e1, &e1, 5);
@@ -634,11 +629,11 @@ static struct key2
create_key(void)
{

- struct key2 = key2 =3D {.n =3D 2};
= + struct key2 key2 =3D { .n =3D 2 };

- const uint8_t key[] =3D
<= span style=3D"color: hsl(0, 100%, 40%);">- {'a', 'b', &#= 39;c', 'd', 'e', 'f', 'g', 'h',= '0', '1', '2', '3', '4', '5= 9;, '6', '7', 'A', 'B', 'C', 'D= ', 'E', 'F',

- 'G', 'H', 'j', 'k', 'u&= #39;, 'c', 'h', 'e', 'n', 'l'};
+ const uint8_t key[]= =3D { 'a', 'b', 'c', 'd', 'e', = 9;f', 'g', 'h', '0', '1', '2',<= /span>
+ = '3', '4', '5', '6', '7', &#= 39;A', 'B', 'C', 'D', 'E', 'F',=
+ = 'G', 'H', 'j', 'k', 'u', &= #39;c', 'h', 'e', 'n', 'l' };
static_assert(sizeof(key) =3D=3D 32, "Si= ze of key should be 32 bytes");

@@ -= 648,7 +643,7 @@

for (int i =3D 0; i = < sizeof(key2.keys); i++)
{
- keydata[i] =3D (uint8_t) (key[i % s= izeof(key)] ^ i);
+ = keydata[i] =3D (uint8_t)(key[i % sizeof(key)] ^ i);
= }

ASSERT(memcpy(key2.keys[0].cip= her, keydata, sizeof(key2.keys[0].cipher)));
@@ -664,8 +659= ,7 @@
{
struct key2 key2 =3D create_k= ey();

- struct crypto_options co =3D init_crypto_options("AES-256-GCM&qu= ot;, "none", epoch,
- &key2);
+ struct crypto_option= s co =3D init_crypto_options("AES-256-GCM", "none", epo= ch, &key2);

struct gc_arena gc = =3D gc_new();

@@ -717,41 +711,40 @@

if (epoch)
{<= br>- uint8_t packetid1[8] = =3D {0, 0x04, 0, 0, 0, 0, 0, 1};
+ uint8_t packetid1[8] =3D { 0, 0x04, 0, 0, 0, 0, 0, 1 }= ;
assert_memory_equal(BPTR(&buf), packetid1, 8= );
}
else
{<= /span>
- uint8_t packet= id1[4] =3D {0, 0, 0, 1};
+ uint8_t packetid1[4] =3D { 0, 0, 0, 1 };
= assert_memory_equal(BPTR(&buf), packetid1, 4);
= }

if (epoch)
{=
uint8_t *tag_location =3D BEND(&buf) - OPENVP= N_AEAD_TAG_LENGTH;
- = const uint8_t exp_tag_epoch[16] =3D
- {0x0f, 0xff, 0xf5, 0x91, 0x3d, 0x39, 0xd7, 0x5b,=
- 0x18, 0x57, = 0x3b, 0x57, 0x48, 0x58, 0x9a, 0x7d};
+ const uint8_t exp_tag_epoch[16] =3D { 0x0f, 0xff, = 0xf5, 0x91, 0x3d, 0x39, 0xd7, 0x5b,
+ 0x18, 0x57, 0x3= b, 0x57, 0x48, 0x58, 0x9a, 0x7d };

= assert_memory_equal(tag_location, exp_tag_epoch, OPENVPN_AEAD_TAG_LENGTH= );
}
else
{<= /span>
uint8_t *tag_location =3D BPTR(&buf) + 4;
- const uint8_t exp_= tag_noepoch[16] =3D
- = {0x1f, 0xdd, 0x90, 0x8f, 0x0e, 0x9d, 0xc2, 0x5e, 0x79, 0xd8, 0x32, 0x= 02, 0x0d, 0x58, 0xe7, 0x3f};
+ const uint8_t exp_tag_noepoch[16] =3D { 0x1f, 0xdd, 0x90, = 0x8f, 0x0e, 0x9d, 0xc2, 0x5e,
+ 0x79, 0xd8, 0x32, 0= x02, 0x0d, 0x58, 0xe7, 0x3f };
assert_memory_equal= (tag_location, exp_tag_noepoch, OPENVPN_AEAD_TAG_LENGTH);
= }

/* Check some bytes at the beg= inning of the encrypted part */
if (epoch)
<= span> {

- co= nst uint8_t bytesat14[6] =3D {0x36, 0xaa, 0xb4, 0xd4, 0x9c, 0xe6};+ const uint8_t bytesa= t14[6] =3D { 0x36, 0xaa, 0xb4, 0xd4, 0x9c, 0xe6 };
= assert_memory_equal(BPTR(&buf) + 14, bytesat14, sizeof(bytesat14));
}
else
{
- const uint8_t bytes= at30[6] =3D {0xa8, 0x2e, 0x6b, 0x17, 0x06, 0xd9};
+ const uint8_t bytesat30[6] =3D { 0xa8= , 0x2e, 0x6b, 0x17, 0x06, 0xd9 };
assert_memory_eq= ual(BPTR(&buf) + 30, bytesat30, sizeof(bytesat30));
= }

diff --git a/tests/unit_tests/openvpn= /test_tls_crypt.c b/tests/unit_tests/openvpn/test_tls_crypt.c
index cc415c8..96a1fc8 100644

--- a/tests/unit_tests/ope= nvpn/test_tls_crypt.c
+++ b/tests/unit_tests/openvpn/test_t= ls_crypt.c
@@ -40,8 +40,7 @@
/* Define thi= s function here as dummy since including the ssl_*.c files
= * leads to having to include even more unrelated code */
= bool
-key_state_export= _keying_material(struct tls_session *session,
- const char *label,= size_t label_size,
+= key_state_export_keying_material(struct tls_session *session, const char *l= abel, size_t label_size,
= void *ekm, size_t ekm_size)
{
memset(= ekm, 0xba, ekm_size);
@@ -49,22 +48,22 @@
= }


-#define TESTBUF_SIZE 128
+#define TESTBUF_SIZE 128
=
/* Defines for use in the tests and the mock parse_line(= ) */
-#define PATH1 = "/s p a c e"
-#define PATH2 "/foo bar/baz"
-#define PARAM1 "param1"-#define PARAM2 "param= two"
+#define P= ATH1 "/s p a c e"
+#define PATH2 "/foo bar/baz"
+#define PARAM1 "param1"
+#define PARAM2 "param two&q= uot;


= -static const char *test_server_key =3D \
+static const char *test_server_key =3D
"-----BEGIN OpenVPN tls-crypt-v2 server key-----\n"
=
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJy= gpKissLS4v\n"
"MDEyMzQ1Njc4OTo7PD0+P0BBQkNER= UZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\n"
"YGFi= Y2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn8=3D\n"
&qu= ot;-----END OpenVPN tls-crypt-v2 server key-----\n";
=
-static const char *te= st_client_key =3D \
+= static const char *test_client_key =3D
"-----BEGI= N OpenVPN tls-crypt-v2 client key-----\n"
"A= AECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v\n"
"MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFV= WV1hZWltcXV5f\n"
@@ -82,7 +81,7 @@


/* Has custom metadata of AABBCCDD (base6= 4) */
-static const cha= r *test_client_key_metadata =3D \
+static const char *test_client_key_metadata =3D
"-----BEGIN OpenVPN tls-crypt-v2 client key-----\n"
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJ= ygpKissLS4v\n"
"MDEyMzQ1Njc4OTo7PD0+P0BBQkNE= RUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\n"
@@ -99,8 +98,8= @@
"-----END OpenVPN tls-crypt-v2 client key----= -\n";

int
-__wrap_parse_line(const char *line, char **p, c= onst int n, const char *file,
- const int line_num, int msglevel, struct gc_arena= *gc)
+__wrap_parse_l= ine(const char *line, char **p, const int n, const char *file, const int li= ne_num,
+ = int msglevel, struct gc_arena *gc)
{
p[0] =3D PATH1 PATH2;

p[1] =3D PARAM1;@@ -142,7 +141,8 @@
return true;
}


= -struct test_tls_crypt_context {
+struct test_tls_crypt_context
+{
struct crypto_options co;
struct key_type kt;
struct buffer so= urce;
@@ -157,8 +157,10 @@
struct test= _tls_crypt_context *ctx =3D calloc(1, sizeof(*ctx));
*= state =3D ctx;

- struct key_parameters key =3D { .cipher =3D { 0 }, .hmac =3D= { 0 },
- = .hmac_size =3D MAX_HMAC_KEY_LENGTH, .cipher_size =3D MA= X_CIPHER_KEY_LENGTH };
+ .hm= ac =3D { 0 },
+ = .hmac_size =3D MAX_HMAC_KEY_LENGTH,
<= span style=3D"color: hsl(120, 100%, 40%);">+ = .cipher_size =3D MAX_CIPHER_KEY_LENGTH };


ctx->kt =3D tls_crypt_kt();

if (!ctx->k= t.cipher || !ctx->kt.digest)
@@ -188,8 +190,7 @@<= br> static int
test_tls_crypt_teardown(void **state)=
{
- = struct test_tls_crypt_context *ctx =3D
- (struct test_tls_crypt_context *)*state;<= br>+ struct test_tls_crypt_c= ontext *ctx =3D (struct test_tls_crypt_context *)*state;
<= /span>
free_buf(&ctx->source);
fr= ee_buf(&ctx->ciphertext);
@@ -217,7 +218,7 @@=
static void
tls_crypt_loopback(void **state)
{
- s= truct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context *) *st= ate;
+ struct test= _tls_crypt_context *ctx =3D (struct test_tls_crypt_context *)*state;=

skip_if_tls_crypt_not_supported(ctx);

@@ -225,8 +226,7 @@
asse= rt_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext));
assert_true(tls_crypt_unwrap(&ctx->ciphertext, &= ;ctx->unwrapped, &ctx->co));
assert_int_equa= l(BLEN(&ctx->source), BLEN(&ctx->unwrapped));
- assert_memory_equal(BPTR(&ctx= ->source), BPTR(&ctx->unwrapped),

- BLEN(&ctx->source));
+ assert_memory_equ= al(BPTR(&ctx->source), BPTR(&ctx->unwrapped), BLEN(&ctx-&= gt;source));
}

<= br>@@ -236,8 +236,7 @@
static void
= test_tls_crypt_secure_reneg_key(void **state)
{
= - struct test_tls_crypt_contex= t *ctx =3D
- (st= ruct test_tls_crypt_context *)*state;
+ struct test_tls_crypt_context *ctx =3D (struct test_t= ls_crypt_context *)*state;

struct gc= _arena gc =3D gc_new();

@@ -256,19 +255,1= 9 @@
tls_crypt_wrap(&ctx->source, &rctx->= ;work, &rctx->opt);
assert_int_equal(buf_len(&a= mp;ctx->source) + 40, buf_len(&rctx->work));

- uint8_t expected_cip= hertext[] =3D {
- = 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x19, 0x27, 0x7f, 0= x1c, 0x8d, 0x6e, 0x6a,
= - 0x77, 0x96, 0xa8, 0x55, 0x33, 0x7b, 0x9c, 0xfb, 0x56, 0xe1, 0xf1, = 0x3a, 0x87, 0x0e, 0x66, 0x47,
- 0xdf, 0xa1, 0x95, 0xc9, 0x2c, 0x17, 0xa0, 0x15, 0xba, 0x49,= 0x67, 0xa1, 0x1d, 0x55, 0xea, 0x1a,
- 0x06, 0xa7
- };
+ = uint8_t expected_ciphertext[] =3D { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, = 0x00, 0x00, 0xe3, 0x19,
+ 0x27, 0x7f, 0x1c, 0x8d, 0x6e, 0x6= a, 0x77, 0x96, 0xa8, 0x55,
+ 0x33, 0x7b, 0x9c, 0xfb, 0x56, = 0xe1, 0xf1, 0x3a, 0x87, 0x0e,
+ 0x66, 0x47, 0xdf, 0xa1, 0x9= 5, 0xc9, 0x2c, 0x17, 0xa0, 0x15,
+ 0xba, 0x49, 0x67, 0xa1, = 0x1d, 0x55, 0xea, 0x1a, 0x06, 0xa7 };
assert_memory_eq= ual(BPTR(&rctx->work), expected_ciphertext, buf_len(&rctx->wo= rk));
tls_wrap_free(&session.tls_wrap_reneg);

/* Use previous tls-crypt key as 0x00, w= ith xor we should have the same key
* and expect the = same result */
session.tls_wrap.mode =3D TLS_WRAP_CRYP= T;
- memset(&ses= sion.tls_wrap.original_wrap_keydata.keys, 0x00, sizeof(session.tls_wrap.ori= ginal_wrap_keydata.keys));
+ memset(&session.tls_wrap.original_wrap_keydata.keys, 0x00,
+ sizeof(ses= sion.tls_wrap.original_wrap_keydata.keys));
session.tl= s_wrap.original_wrap_keydata.n =3D 2;

= tls_session_generate_dynamic_tls_crypt_key(&session);
@@ -279,7 +278,8 @@

tls_wrap_free(&session.tls_wr= ap_reneg);

/* XOR should not force a= different key */
- = memset(&session.tls_wrap.original_wrap_keydata.keys, 0x42, sizeof(sessi= on.tls_wrap.original_wrap_keydata.keys));
+ memset(&session.tls_wrap.original_wrap_keydat= a.keys, 0x42,
+ = sizeof(session.tls_wrap.original_wrap_keydata.keys));
= tls_session_generate_dynamic_tls_crypt_key(&session);

tls_crypt_wrap(&ctx->source, &rctx-&g= t;work, &rctx->opt);
@@ -303,7 +303,7 @@
<= span> static void

tls_crypt_loopback_zero_len(void **state= )
{
- = struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context *)= *state;
+ struct = test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context *)*state;

skip_if_tls_crypt_not_supported(ctx);<= /span>

@@ -313,8 +313,7 @@
= assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext));<= /span>
assert_true(tls_crypt_unwrap(&ctx->ciphertext, = &ctx->unwrapped, &ctx->co));
assert_int_= equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped));
<= span style=3D"color: hsl(0, 100%, 40%);">- assert_memory_equal(BPTR(&= ;ctx->source), BPTR(&ctx->unwrapped),

- BLEN(&ctx->source)= );
+ assert_memory= _equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), BLEN(&c= tx->source));
}

/**<= /span>
@@ -323,20 +322,19 @@
static void tls_crypt_loopback_max_len(void **state)
{=
- struct test_tls_crypt_co= ntext *ctx =3D (struct test_tls_crypt_context *) *state;
+ struct test_tls_crypt_context *ctx= =3D (struct test_tls_crypt_context *)*state;

<= span> skip_if_tls_crypt_not_supported(ctx);

buf_clear(&ctx->source);
- assert_non_null(buf_write_alloc(&ctx->sour= ce,
- = TESTBUF_SIZE - BLEN(&ctx->ciphertext) - tls_crypt_= buf_overhead()));
+ = assert_non_null(buf_write_alloc(&ctx->source, TESTBUF_SIZE - BLEN(= &ctx->ciphertext)
+ - tls_crypt_buf_= overhead()));

assert_true(tls_crypt_= wrap(&ctx->source, &ctx->ciphertext, &ctx->co));
assert_true(BLEN(&ctx->source) < BLEN(&ctx-&g= t;ciphertext));
assert_true(tls_crypt_unwrap(&ctx-= >ciphertext, &ctx->unwrapped, &ctx->co));
= assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrappe= d));
- assert_memory= _equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped),
<= span style=3D"color: hsl(0, 100%, 40%);">- BLEN(&= ;ctx->source));

+ = assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapp= ed), BLEN(&ctx->source));
}

/**
@@ -345,13 +343,13 @@
stat= ic void
tls_crypt_fail_msg_too_long(void **state) {
- struct = test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context *) *state;
+ struct test_tls_c= rypt_context *ctx =3D (struct test_tls_crypt_context *)*state;

skip_if_tls_crypt_not_supported(ctx);
=
buf_clear(&ctx->source);
- assert_non_null(buf_write_alloc(= &ctx->source,

- = TESTBUF_SIZE - BLEN(&ctx->ciphert= ext) - tls_crypt_buf_overhead() + 1));
+ assert_non_null(buf_write_alloc(&ctx->source,= TESTBUF_SIZE - BLEN(&ctx->ciphertext)
+ = - tls_crypt_buf_overhead() + 1));
assert_false(tl= s_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)= );
}

@@ -362,13 +360,15 = @@
static void
tls_crypt_fail_invalid_key= (void **state)
{
- struct test_tls_crypt_context *ctx =3D (struct test_tls_cry= pt_context *) *state;
+ struct test_tls_crypt_context *ctx =3D (struct test_tls_crypt_context= *)*state;

skip_if_tls_crypt_not_sup= ported(ctx);

/* Change decrypt key *= /
- struct key_param= eters key =3D { .cipher =3D { 1 }, .hmac =3D { 1 },
- .cipher_s= ize =3D MAX_CIPHER_KEY_LENGTH, .hmac_size =3D MAX_HMAC_KEY_LENGTH };=
+ struct key_parameters = key =3D { .cipher =3D { 1 },
+ .hmac =3D { 1 },
+ .= cipher_size =3D MAX_CIPHER_KEY_LENGTH,

+ .hmac_size =3D MAX_HMA= C_KEY_LENGTH };
free_key_ctx(&ctx->co.key_ctx_b= i.decrypt);
init_key_ctx(&ctx->co.key_ctx_bi.de= crypt, &key, &ctx->kt, false, "TEST");

@@ -383,7 +383,7 @@
static void<= br> tls_crypt_fail_replay(void **state)
{
= - struct test_tls_crypt_contex= t *ctx =3D (struct test_tls_crypt_context *) *state;
+ struct test_tls_crypt_context *ctx = =3D (struct test_tls_crypt_context *)*state;

skip_if_tls_crypt_not_supported(ctx);


= @@ -403,7 +403,7 @@
static void
tls= _crypt_ignore_replay(void **state)
{
- struct test_tls_crypt_context *ctx =3D = (struct test_tls_crypt_context *) *state;
+ struct test_tls_crypt_context *ctx =3D (struct te= st_tls_crypt_context *)*state;

skip_= if_tls_crypt_not_supported(ctx);

@@ -417,= 7 +417,8 @@
assert_true(tls_crypt_unwrap(&ctx->= ciphertext, &ctx->unwrapped, &ctx->co));
}

-struc= t test_tls_crypt_v2_context {
+struct test_tls_crypt_v2_context
+{
struct gc_arena gc; struct key2 server_key2;
struct key_ctx_bi= server_keys;
@@ -437,17 +438,15 @@
ct= x->gc =3D gc_new();

/* Slightly l= onger buffers to be able to test too-long data */
- ctx->metadata =3D alloc_buf_gc(TLS_CRYPT= _V2_MAX_METADATA_LEN+16, &ctx->gc);
- ctx->unwrapped_metadata =3D alloc_buf_gc(TLS_CR= YPT_V2_MAX_METADATA_LEN+16,
- &ctx->gc);- ctx->wkc =3D alloc_buf_= gc(TLS_CRYPT_V2_MAX_WKC_LEN+16, &ctx->gc);
+ ctx->metadata =3D alloc_buf_gc(TLS_CRY= PT_V2_MAX_METADATA_LEN + 16, &ctx->gc);
+ ctx->unwrapped_metadata =3D alloc_buf_gc(= TLS_CRYPT_V2_MAX_METADATA_LEN + 16, &ctx->gc);
+ ctx->wkc =3D alloc_buf_gc(TLS_CRYP= T_V2_MAX_WKC_LEN + 16, &ctx->gc);

= /* Generate server key */
rand_bytes((void *)ctx-= >server_key2.keys, sizeof(ctx->server_key2.keys));
= ctx->server_key2.n =3D 2;
struct key_type kt =3D= tls_crypt_kt();
- i= nit_key_ctx_bi(&ctx->server_keys, &ctx->server_key2,- KEY_DIRECT= ION_BIDIRECTIONAL, &kt,
+ init_key_ctx_bi(&ctx->server_keys, &ctx->server_k= ey2, KEY_DIRECTION_BIDIRECTIONAL, &kt,
= "tls-crypt-v2 server key");

/* Generate client key */

@@ -460,8 +459,7 @@=
static int
test_tls_crypt_v2_teardown(void **st= ate)
{
- struct test_tls_crypt_v2_context *ctx =3D
- (struct test_tls_crypt_v2_context *) *sta= te;
+ struct test_= tls_crypt_v2_context *ctx =3D (struct test_tls_crypt_v2_context *)*state;

free_key_ctx_bi(&ctx->server_k= eys);
free_key_ctx_bi(&ctx->client_key);=
@@ -479,27 +477,20 @@
static void
tls_crypt_v2_wrap_unwrap_no_metadata(void **state)

{
- struct test_tls_cryp= t_v2_context *ctx =3D
-= (struct test_tls_crypt_v2_context *) *state;
+ struct test_tls_crypt_v2_context *ctx= =3D (struct test_tls_crypt_v2_context *)*state;
- struct buffer wrapped_clie= nt_key =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_WKC_LEN,
- = &ctx->gc);
= - assert_true(tls_crypt_v2_wrap_client_key(&wrapped_client_key,
- = &ctx->client_key2,
- &ct= x->metadata,
- = &ctx->server_keys.encrypt,
- = &ctx->gc));
+ struct buffer wrapped_client_key =3D alloc_buf_gc(T= LS_CRYPT_V2_MAX_WKC_LEN, &ctx->gc);
+ assert_true(tls_crypt_v2_wrap_client_key(&wr= apped_client_key, &ctx->client_key2, &ctx->metadata,+ = &ctx->server_keys.encrypt, &ctx->gc));

- struc= t buffer unwrap_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN,
- = &ctx->gc);
+ struct buffer unwrap_metadata =3D alloc_buf_gc(T= LS_CRYPT_V2_MAX_METADATA_LEN, &ctx->gc);
struct= key2 unwrapped_client_key2 =3D { 0 };
- assert_true(tls_crypt_v2_unwrap_client_key(&unwrap= ped_client_key2,
- = &unwrap_metadata,
<= span style=3D"color: hsl(0, 100%, 40%);">- = wrapped_client_key,

- &ctx->ser= ver_keys.decrypt));
+= assert_true(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2, = &unwrap_metadata,
+ wrapped_client_key, &c= tx->server_keys.decrypt));

- assert_true(0 =3D=3D memcmp(ctx->client_ke= y2.keys, unwrapped_client_key2.keys,
- sizeof(ctx->client_key2.keys)= ));
+ assert_true(= 0
+ = =3D=3D memcmp(ctx->client_key2.keys, unwrapped_client_key2.keys,<= br>+ s= izeof(ctx->client_key2.keys)));
}

/**
@@ -509,26 +500,21 @@
st= atic void
tls_crypt_v2_wrap_unwrap_max_metadata(void **sta= te)
{
= - struct test_tls_crypt_v2_context *ctx =3D
- (struct test_tls_crypt_v2_context *) *stat= e;
+ struct test_t= ls_crypt_v2_context *ctx =3D (struct test_tls_crypt_v2_context *)*state;

- ui= nt8_t *metadata =3D
- = buf_write_alloc(&ctx->metadata, TLS_CRYPT_V2_MAX_METADATA_LEN)= ;
+ uint8_t *metad= ata =3D buf_write_alloc(&ctx->metadata, TLS_CRYPT_V2_MAX_METADATA_LE= N);
assert_true(rand_bytes(metadata, TLS_CRYPT_V2_MAX_= METADATA_LEN));
- as= sert_true(tls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->clien= t_key2,
- = &ctx->metadata,
- = &ctx->server_keys.encrypt,
- &ctx->gc)= );
+ assert_true(t= ls_crypt_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2, &am= p;ctx->metadata,
+= &ctx->server_keys.encry= pt, &ctx->gc));

- struct buffer unwrap_metadata =3D alloc_buf_gc(TLS_C= RYPT_V2_MAX_METADATA_LEN,
- &ctx->gc);
+ struct buffer unwrap= _metadata =3D alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN, &ctx->gc);=
struct key2 unwrapped_client_key2 =3D { 0 };- assert_true(tls_crypt_v2_u= nwrap_client_key(&unwrapped_client_key2,
- &= unwrap_metadata, ctx->wkc,
+ assert_true(tls_crypt_v2_unwrap_client_key(&unwrapped_cli= ent_key2, &unwrap_metadata, ctx->wkc,
= &ctx->server_keys.decrypt));

- asser= t_true(0 =3D=3D memcmp(ctx->client_key2.keys, unwrapped_client_key2.keys= ,
- = sizeof(ctx->client_key2.keys)));
+ assert_true(0
+ =3D=3D memcmp(ctx->client_key2.key= s, unwrapped_client_key2.keys,
+ sizeof(ctx->client_key2.keys)));
assert_true(buf_equal(&ctx->metadata, &unwrap= _metadata));

struct tls_wrap_ctx wra= p_ctx =3D {
@@ -546,14 +532,11 @@
static v= oid
tls_crypt_v2_wrap_too_long_metadata(void **state)
{
- str= uct test_tls_crypt_v2_context *ctx =3D
- (struct test_tls_crypt_v2_context *) *state;
+ struct test_tls_crypt= _v2_context *ctx =3D (struct test_tls_crypt_v2_context *)*state;
=
- assert_tru= e(buf_inc_len(&ctx->metadata, TLS_CRYPT_V2_MAX_METADATA_LEN+1));
- assert_false(tls_cryp= t_v2_wrap_client_key(&ctx->wkc, &ctx->client_key2,
= - = &ctx->metadata,
- &ctx->s= erver_keys.encrypt,
- = &ctx->gc));
+ assert_true(buf_inc_len(&= ;ctx->metadata, TLS_CRYPT_V2_MAX_METADATA_LEN + 1));

+ assert_false(tls_crypt_v2_wrap_clie= nt_key(&ctx->wkc, &ctx->client_key2, &ctx->metadata,
+ = &ctx->server_keys.encrypt, &ctx->gc)= );
}

/**
@@ -563,28 +546,22 @@

static void
tls_c= rypt_v2_wrap_unwrap_wrong_key(void **state)
{
- struct test_tls_crypt_v2_conte= xt *ctx =3D

- (s= truct test_tls_crypt_v2_context *) *state;
+ struct test_tls_crypt_v2_context *ctx =3D (struc= t test_tls_crypt_v2_context *)*state;

- assert_true(tls_crypt_v2_wrap_client_= key(&ctx->wkc, &ctx->client_key2,
- &= ;ctx->metadata,
- = &ctx->server_keys.encrypt,=
- = &ctx->gc));
+ assert_true(tls_crypt_v2_wrap_client_key(&ct= x->wkc, &ctx->client_key2, &ctx->metadata,
+ = &ctx->server_keys.encrypt, &ctx->gc));


/* Change server key */
str= uct key_type kt =3D tls_crypt_kt();
free_key_ctx_bi(&a= mp;ctx->server_keys);
memset(&ctx->server_ke= y2.keys, 0, sizeof(ctx->server_key2.keys));
- init_key_ctx_bi(&ctx->server_keys, &= ;ctx->server_key2,
-= KEY_DIRECTION_BIDIRECTIONAL, &kt,
+ init_key_ctx_bi(&ctx->serv= er_keys, &ctx->server_key2, KEY_DIRECTION_BIDIRECTIONAL, &kt,
"wrong tls-crypt-v2 server key"= ;);


struct key2 un= wrapped_client_key2 =3D { 0 };
- assert_false(tls_crypt_v2_unwrap_client_key(&unwrapped_cli= ent_key2,
- = &ctx->unwrapped_metadata,=
- = ctx->wkc,
- &ctx->ser= ver_keys.decrypt));
+= assert_false(tls_crypt_v2_unwrap_client_key(&unwrapped_client_key2,= &ctx->unwrapped_metadata,
+ ctx->wkc, = &ctx->server_keys.decrypt));

= const struct key2 zero =3D { 0 };
assert_true(0 =3D=3D= memcmp(&unwrapped_client_key2, &zero, sizeof(zero)));
@@ -598,23 +575,17 @@

static void
tls= _crypt_v2_wrap_unwrap_dst_too_small(void **state)
{=
- struct test_tls_crypt_v2= _context *ctx =3D
- = (struct test_tls_crypt_v2_context *) *state;
+ struct test_tls_crypt_v2_context *ctx =3D = (struct test_tls_crypt_v2_context *)*state;

- uint8_t *metadata =3D
- buf_write_alloc(&ct= x->metadata, TLS_CRYPT_V2_MAX_METADATA_LEN);
+ uint8_t *metadata =3D buf_write_alloc(&= ctx->metadata, TLS_CRYPT_V2_MAX_METADATA_LEN);
asse= rt_true(rand_bytes(metadata, TLS_CRYPT_V2_MAX_METADATA_LEN));
- assert_true(tls_crypt_v2_wrap_c= lient_key(&ctx->wkc, &ctx->client_key2,

- = &ctx->metadata,
- = &ctx->gc));
+ assert_true(tls_crypt_v2_wrap_client_key(&= amp;ctx->wkc, &ctx->client_key2, &ctx->metadata,+ = &ctx->server_keys.encrypt, &ctx->gc));=

struct key2 unwrapped_client_key2 =3D { 0 = };
- struct buffer u= nwrapped_metadata =3D
-= alloc_buf_gc(TLS_CRYPT_V2_MAX_METADATA_LEN-1, &ctx->gc);
- assert_false(tls_cryp= t_v2_unwrap_client_key(&unwrapped_client_key2,
- = &unwrapped_metadata, ctx->wkc,
- &ctx-= >server_keys.decrypt));
+ struct buffer unwrapped_metadata =3D alloc_buf_gc(TLS_CRYPT_V2_M= AX_METADATA_LEN - 1, &ctx->gc);
+ assert_false(tls_crypt_v2_unwrap_client_key(&unw= rapped_client_key2, &unwrapped_metadata,
+ ct= x->wkc, &ctx->server_keys.decrypt));

= const struct key2 zero =3D { 0 };
assert_tr= ue(0 =3D=3D memcmp(&unwrapped_client_key2, &zero, sizeof(zero)));
@@ -627,8 +598,7 @@
const char *filenam= e =3D "testfilename.key";

= expect_string(__wrap_buffer_write_file, filename, filename);
- expect_memory(__wrap_buffer_writ= e_file, pem, test_server_key,

- strlen(test_server_key));
+ expect_memory(__wrap_buffer_write_fil= e, pem, test_server_key, strlen(test_server_key));
wil= l_return(__wrap_buffer_write_file, true);

tls_crypt_v2_write_server_key_file(filename);

@@ -641= ,8 +611,7 @@

/* Test writing the cli= ent key */
expect_string(__wrap_buffer_write_file, fil= ename, filename);
- = expect_memory(__wrap_buffer_write_file, pem, test_client_key,
- strlen(test_clien= t_key));

+ expect_= memory(__wrap_buffer_write_file, pem, test_client_key, strlen(test_client_k= ey));
will_return(__wrap_buffer_write_file, true);

/* Key generation re-reads the created = file as a sanity check */
@@ -668,8 +637,7 @@
expect_string(__wrap_buffer_read_from_file, filename, filename);
will_return(__wrap_buffer_read_from_file, test_client_ke= y_metadata);

- tls_crypt_v2_write_client_key_file(filename, b64metadata, test= _server_key,
- = true);
+ tls_crypt_v2_write_client_key_file(filename, b64metada= ta, test_server_key, true);
}

= int
@@ -677,44 +645,31 @@
{<= br> openvpn_unit_test_setup();
const struct = CMUnitTest tests[] =3D {
- = test_tls_crypt_setup,
+ cmocka_unit_test_setup_teardown(tls_crypt_loopback, test_tl= s_crypt_setup,
tes= t_tls_crypt_teardown),
= - cmocka_unit_test_setup_teardown(tls_crypt_loopback_zero_len,
- = test_tls_crypt_setup,
+ cmocka_unit_test_setup_teardown(tls_crypt_loopback_z= ero_len, test_tls_crypt_setup,
= test_tls_crypt_teardown),
- cmocka_unit_test_setup_teardown(tls_crypt_loopback= _max_len,
- = test_tls_crypt_setup,
+ cmocka_unit_test_setup_teardown(tls_c= rypt_loopback_max_len, test_tls_crypt_setup,
= test_tls_crypt_teardown),
- cmocka_unit_test_setup_teardown(tls= _crypt_fail_msg_too_long,
- test_tls_crypt_setup,+ cmocka_unit_test_setu= p_teardown(tls_crypt_fail_msg_too_long, test_tls_crypt_setup,
test_tls_crypt_teardown),
- cmocka_unit_test_se= tup_teardown(tls_crypt_fail_invalid_key,
- test_tls_crypt_s= etup,
+ cmocka= _unit_test_setup_teardown(tls_crypt_fail_invalid_key, test_tls_crypt_setup,=
test_tls_crypt_te= ardown),
- cmock= a_unit_test_setup_teardown(tls_crypt_fail_replay,
- test_tl= s_crypt_setup,
+ = cmocka_unit_test_setup_teardown(tls_crypt_fail_replay, test_tls_crypt_se= tup,
test_tls_cryp= t_teardown),
- c= mocka_unit_test_setup_teardown(tls_crypt_ignore_replay,
- t= est_tls_crypt_setup,
= + cmocka_unit_test_setup_teardown(tls_crypt_ignore_replay, test_tls_= crypt_setup,
test_= tls_crypt_teardown),
cmocka_unit_test_setup_teardo= wn(tls_crypt_v2_wrap_unwrap_no_metadata,
- test_tls_crypt_v= 2_setup,
- = test_tls_crypt_v2_teardown),
+ = test_tls_crypt_v2_setup, test_tls_crypt_v2_teardown),
= cmocka_unit_test_setup_teardown(tls_crypt_v2_wrap_unwrap_max_metadata,=
- = test_tls_crypt_v2_setup,
- test_tls_cryp= t_v2_teardown),
+ = test_tls_crypt_v2_setup, test_tls_crypt= _v2_teardown),
cmocka_unit_test_setup_teardown(tls= _crypt_v2_wrap_too_long_metadata,
- test_tls_crypt_v2_setup= ,
- = test_tls_crypt_v2_teardown),
- cmocka_unit_test_setup_teardown(tls_cryp= t_v2_wrap_unwrap_wrong_key,
- test_tls_crypt_v2_setup,
+ = test_tls_crypt_v2_setup, test_tls_crypt_v2_teardown),
+ cmocka_unit_test_= setup_teardown(tls_crypt_v2_wrap_unwrap_wrong_key, test_tls_crypt_v2_setup,=
test_tls_crypt_v2= _teardown),
cmocka_unit_test_setup_teardown(tls_cr= ypt_v2_wrap_unwrap_dst_too_small,
- test_tls_crypt_v2_setup= ,
- = test_tls_crypt_v2_teardown),
- cmocka_unit_test_setup_teardown(test_tls= _crypt_secure_reneg_key,
+ = test_tls_crypt_v2_setup, test_tls_crypt_v2_teardown),
<= span style=3D"color: hsl(120, 100%, 40%);">+ cmocka_unit_test_setup_= teardown(test_tls_crypt_secure_reneg_key, test_tls_crypt_setup,

<= span> test_tls_crypt_teardown),

cmocka_unit_test(test_tls_crypt_v2_write_server_key_f= ile),
cmocka_unit_test(test_tls_crypt_v2_write_cli= ent_key_file),
diff --git a/tests/unit_tests/openvpn/test_u= ser_pass.c b/tests/unit_tests/openvpn/test_user_pass.c
inde= x 400c0f4..e727c4e 100644
--- a/tests/unit_tests/openvpn/te= st_user_pass.c
+++ b/tests/unit_tests/openvpn/test_user_pas= s.c
@@ -65,19 +65,16 @@
assert_true(0)= ;
}
bool
-management_query_user_pass(struct management *man,

- = struct user_pass *up,
- const char *type,
- const unsigned int flag= s,
- = const char *static_challenge)
+management_query_user_pass(struct management *man, struct= user_pass *up, const char *type,
+ const unsigned int flags, const ch= ar *static_challenge)
{
assert_true(0= );
return false;
}
/= * stubs for some unused functions instead of pulling in too many dependenci= es */
int
-parse_line(const char *line, char **p, const int n, const char *file,<= /span>
- const int l= ine_num, int msglevel, struct gc_arena *gc)
+parse_line(const char *line, char **p, const int n,= const char *file, const int line_num,
+ int msglevel, struct gc_arena *gc)
= {
assert_true(0);
return 0= ;
@@ -163,7 +160,9 @@
/*FIXME: query_u= ser_exec() called even though nothing queued */
will_r= eturn(query_user_exec_builtin, true);
/* FIXME? conten= t after first two lines just ignored */
- assert_true(get_user_pass_cr(&up, "#iuser an= d =EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0\n//ipassw=C3=B6rd!\nsome other conte= nt\nnot relevant", "UT", flags, NULL));
+ assert_true(
+ get_user_pass_cr(&up, "#= iuser and =EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0\n//ipassw=C3=B6rd!\nsome oth= er content\nnot relevant",
+ "UT", flags, NULL));<= br> assert_true(up.defined);
assert_string_e= qual(up.username, "#iuser and =EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0&quo= t;);
assert_string_equal(up.password, "//ipassw= =C3=B6rd!");
@@ -251,7 +250,7 @@
= unsigned int flags =3D 0;

char authf= ile[PATH_MAX] =3D { 0 };
+ o= penvpn_test_get_srcdir_dir(authfile, PATH_MAX, "input/user_pass.txt&qu= ot;);

/*FIXME: query_user_exec() cal= led even though nothing queued */
will_return(query_us= er_exec_builtin, true);
@@ -293,7 +292,8 @@
const char *challenge =3D "CRV1:R,E:Om01u7Fh4LrGBS7uh0SWmzwabUiG= iW6l:Y3Ix:Please enter token PIN";

unsigned int f= lags =3D GET_USER_PASS_DYNAMIC_CHALLENGE;

- expect_string(query_user_exec_bui= ltin, query_user[i].prompt, "CHALLENGE: Please enter token PIN");=

+ expect_string(q= uery_user_exec_builtin, query_user[i].prompt,
+ "CHALLENGE: Please enter t= oken PIN");
will_return(query_user_exec_builtin, = "challenge_response");
will_return(query_use= r_exec_builtin, true);
assert_true(get_user_pass_cr(&a= mp;up, NULL, "UT", flags, challenge));
@@ -315,7 = +315,8 @@
expect_string(query_user_exec_builtin, query= _user[i].prompt, "Enter UT Password:");
will= _return(query_user_exec_builtin, "cpassword");
= will_return(query_user_exec_builtin, true);
- expect_string(query_user_exec_builtin, query_u= ser[i].prompt, "CHALLENGE: Please enter token PIN");
+ expect_string(query_user_exe= c_builtin, query_user[i].prompt,

+ "CHALLENGE: Please enter token PIN"= ;);
will_return(query_user_exec_builtin, "challen= ge_response");
will_return(query_user_exec_builti= n, true);
assert_true(get_user_pass_cr(&up, NULL, = "UT", flags, challenge));
@@ -333,7 +334,8 @@
expect_string(query_user_exec_builtin, query_user[i].prom= pt, "Enter UT Password:");
will_return(query= _user_exec_builtin, "c1password");
will_retu= rn(query_user_exec_builtin, true);
- expect_string(query_user_exec_builtin, query_user[i].promp= t, "CHALLENGE: Please enter token PIN");
+ expect_string(query_user_exec_builtin, q= uery_user[i].prompt,
= + "CHALLENGE: Please enter token PIN"); will_return(query_user_exec_builtin, "0123456");
will_return(query_user_exec_builtin, true);
assert_true(get_user_pass_cr(&up, NULL, "UT", flags, = challenge));

@@ -344,11 +346,12 @@
=
reset_user_pass(&up);

- flags =3D GET_USER_PASS_STATIC_CHA= LLENGE|GET_USER_PASS_INLINE_CREDS;
+ flags =3D GET_USER_PASS_STATIC_CHALLENGE | GET_USER_PASS= _INLINE_CREDS;

/*FIXME: query_user_e= xec() called even though nothing queued */
will_return= (query_user_exec_builtin, true);
- expect_string(query_user_exec_builtin, query_user[i].prompt,= "CHALLENGE: Please enter token PIN");
+ expect_string(query_user_exec_builtin, que= ry_user[i].prompt,
+ = "CHALLENGE: Please enter token PIN");
= will_return(query_user_exec_builtin, "challenge_response&qu= ot;);
will_return(query_user_exec_builtin, true);
assert_true(get_user_pass_cr(&up, "iuser\nipasswo= rd", "UT", flags, challenge));
diff --git a/= tests/unit_tests/plugins/auth-pam/test_search_and_replace.c b/tests/unit_te= sts/plugins/auth-pam/test_search_and_replace.c
index d40467= f..5875c8e 100644
--- a/tests/unit_tests/plugins/auth-pam/t= est_search_and_replace.c
+++ b/tests/unit_tests/plugins/aut= h-pam/test_search_and_replace.c
@@ -11,7 +11,6 @@ static void
pass_any_null_param__returns_null(void= **state)
{
-
char DUMMY[] =3D "DUMMY";
=
assert_null(searchandreplace(NULL, DUMMY, DUMM= Y));
@@ -22,7 +21,6 @@
static void<= br> pass_any_empty_string__returns_null(void **state)
{

-
= char DUMMY[] =3D "DUMMY";
char EMPTY[] = =3D "";


To = view, visit change 791. To unsubscribe, or for help writing mail filters, visit = settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2566ad493629e1f5fdfa6f6483b= 8973463404e3e
Gerrit-Change-Number: 791
Gerrit-PatchSet: 22
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: cron2 <gert@...1296...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-CC: ordex <antonio@...2726...>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: ordex <antonio@...2726...= >
Gerrit-MessageType: newpatchset
--Ec64+lHvvb8=--