From 6d7a7f24549ed745ffae88025c67ccae3a79571f Mon Sep 17 00:00:00 2001 From: Eugene K Date: Thu, 9 Jun 2022 08:26:29 -0400 Subject: [PATCH 1/9] modify Ziti_accept() to return peer address (caller_id) Ziti_accept() should not fail if client timeout waiting for it --- includes/ziti/zitilib.h | 12 +--- library/zitilib.c | 97 ++++++++++++++++++++++--------- programs/zitilib-samples/server.c | 15 ++--- 3 files changed, 79 insertions(+), 45 deletions(-) diff --git a/includes/ziti/zitilib.h b/includes/ziti/zitilib.h index 3b8f2c64..bafe018e 100644 --- a/includes/ziti/zitilib.h +++ b/includes/ziti/zitilib.h @@ -106,16 +106,6 @@ int Ziti_connect_addr(ziti_socket_t socket, const char *host, unsigned int port) ZITI_FUNC int Ziti_bind(ziti_socket_t socket, ziti_context ztx, const char *service); -/** - * @brief Bind socket to a Ziti service with the given intercept address - * @param socket socket handle created with [Ziti_socket()] - * @param host target hostname - * @param port target port - * @return - */ -ZITI_FUNC -int Ziti_bind_addr(ziti_socket_t socket, const char *host, unsigned int port); - /** * @brief marks the [socket] as a socket able to accept incoming connections * @param socket a file descriptor created with [Ziti_socket()] and bound to a service with [Ziti_bind] or [Ziti_bind_addr] @@ -138,7 +128,7 @@ int Ziti_listen(ziti_socket_t socket, int backlog); * @return on success returns a file descriptor for the accepted connection. on error -1 is returned, use [Ziti_last_error()] to get actual error code. */ ZITI_FUNC -ziti_socket_t Ziti_accept(ziti_socket_t socket); +ziti_socket_t Ziti_accept(ziti_socket_t socket, char *caller, int caller_len); /** * @brief Shutdown Ziti library. diff --git a/library/zitilib.c b/library/zitilib.c index c06c5206..207731c6 100644 --- a/library/zitilib.c +++ b/library/zitilib.c @@ -137,7 +137,10 @@ typedef struct ztx_wrap { } ztx_wrap_t; struct backlog_entry_s { + struct ziti_sock_s *parent; ziti_connection conn; + char *caller_id; + future_t *accept_f; TAILQ_ENTRY(backlog_entry_s) _next; }; @@ -569,20 +572,31 @@ static bool is_blocking(ziti_socket_t s) { #endif } +struct sock_info_s { + ziti_socket_t fd; + char *peer; +}; static void on_ziti_accept(ziti_connection client, int status) { - future_t *f = ziti_conn_data(client); + struct backlog_entry_s *pending = ziti_conn_data(client); if (status != ZITI_OK) { - fail_future(f, status); + ZITI_LOG(WARN, "ziti_accept failed!"); + // ziti accept failed, so just put the accept future back into accept_q + TAILQ_INSERT_HEAD(&pending->parent->accept_q, pending->accept_f, _next); + ziti_close(client, NULL); + free(pending->caller_id); + free(pending); return; } ziti_socket_t fd, ziti_fd; int rc = make_socketpair(SOCK_STREAM, &fd, &ziti_fd); if (rc != 0) { - fail_future(f, rc); + fail_future(pending->accept_f, rc); ziti_close(client, NULL); + free(pending->caller_id); + free(pending); return; } @@ -592,7 +606,12 @@ static void on_ziti_accept(ziti_connection client, int status) { ziti_conn_set_data(client, zs); model_map_set_key(&ziti_sockets, &zs->fd, sizeof(zs->fd), zs); ziti_conn_bridge_fds(client, (uv_os_fd_t) zs->ziti_fd, (uv_os_fd_t) zs->ziti_fd, on_bridge_close, zs); - complete_future(f, (void *) (uintptr_t) zs->fd); + NEWP(si, struct sock_info_s); + si->fd = zs->fd; + si->peer = pending->caller_id; + + complete_future(pending->accept_f, si); + free(pending); } static void on_ziti_client(ziti_connection server, ziti_connection client, int status, ziti_client_ctx *clt_ctx) { @@ -604,29 +623,40 @@ static void on_ziti_client(ziti_connection server, ziti_connection client, int s return; } + char notify = 1; + + NEWP(pending, struct backlog_entry_s); + pending->parent = server_sock; + pending->conn = client; + pending->caller_id = strdup(clt_ctx->caller_id); + if (!TAILQ_EMPTY(&server_sock->accept_q)) { future_t *accept_f = TAILQ_FIRST(&server_sock->accept_q); - TAILQ_REMOVE(&server_sock->accept_q, accept_f, _next); - ziti_conn_set_data(client, accept_f); - ziti_accept(client, on_ziti_accept, NULL); + ziti_conn_set_data(client, pending); + // this should not happen but check anyway + if (ziti_accept(client, on_ziti_accept, NULL) != ZITI_OK) { + ziti_close(client, NULL); + free(pending->caller_id); + free(pending); + return; + } + pending->accept_f = accept_f; + TAILQ_REMOVE(&server_sock->accept_q, accept_f, _next); + write(server_sock->ziti_fd, ¬ify, sizeof(notify)); return; } if (server_sock->pending < server_sock->max_pending) { - NEWP(pending, struct backlog_entry_s); - pending->conn = client; TAILQ_INSERT_TAIL(&server_sock->backlog, pending, _next); server_sock->pending++; - if (!is_blocking(server_sock->fd)) { - char b = 1; #if _WIN32 send(server_sock->ziti_fd, &b, 1, 0); #else - write(server_sock->ziti_fd, &b, 1); + write(server_sock->ziti_fd, ¬ify, sizeof(notify)); #endif - } } else { + ZITI_LOG(WARN, "accept backlog is full, client[%s] rejected", clt_ctx->caller_id); ziti_close(client, NULL); } } @@ -740,32 +770,45 @@ static void do_ziti_accept(void *r, future_t *f, uv_loop_t *l) { return; } - struct backlog_entry_s *pending = TAILQ_FIRST(&zs->backlog); - TAILQ_REMOVE(&zs->backlog, pending, _next); + while (!TAILQ_EMPTY(&zs->backlog)) { + struct backlog_entry_s *pending = TAILQ_FIRST(&zs->backlog); + TAILQ_REMOVE(&zs->backlog, pending, _next); - ziti_connection conn = pending->conn; - free(pending); + ziti_connection conn = pending->conn; + pending->accept_f = f; + ziti_conn_set_data(conn, pending); + int rc = ziti_accept(conn, on_ziti_accept, NULL); - ziti_conn_set_data(conn, f); - ziti_accept(conn, on_ziti_accept, NULL); + if (rc == ZITI_OK) { + break; + } + + ZITI_LOG(WARN, "failed to accept: client gone? [%d/%s]", rc, ziti_errorstr(rc)); + ziti_close(conn, NULL); + free(pending->caller_id); + free(pending); + } } -ziti_socket_t Ziti_accept(ziti_socket_t server) { +ziti_socket_t Ziti_accept(ziti_socket_t server, char *caller, int caller_len) { future_t *f = schedule_on_loop(do_ziti_accept, (void *) (uintptr_t) server, true); ziti_socket_t clt = -1; int err = await_future(f); if (!err) { - clt = (ziti_socket_t) (uintptr_t) f->result; - if (!is_blocking(server)) { - char b; + struct sock_info_s *si = f->result; + clt = si->fd; + if (caller != NULL) { + strncpy(caller, si->peer, caller_len); + } + free(si->peer); + free(si); + char b; #if _WIN32 - recv(server, &b, 1, 0); + recv(server, &b, 1, 0); #else - read(server, &b, 1); + read(server, &b, 1); #endif - - } } set_error(err); destroy_future(f); diff --git a/programs/zitilib-samples/server.c b/programs/zitilib-samples/server.c index 8211e22c..306db593 100644 --- a/programs/zitilib-samples/server.c +++ b/programs/zitilib-samples/server.c @@ -39,7 +39,7 @@ // - clients are processed on at a time, client queue is managed by Ziti server socket implementation. // set this to 1 to verify that Ziti server socket works in non-blocking mode -#define NON_BLOCKING_SERVER 0 +#define NON_BLOCKING_SERVER 1 #define CHECK(desc, op) do{ \ int rc = (op); \ @@ -51,7 +51,7 @@ goto DONE;\ } \ } while(0) -static ziti_socket_t non_blocking_accept(ziti_socket_t srv) { +static ziti_socket_t non_blocking_accept(ziti_socket_t srv, char *caller, int caller_len) { #if _WIN32 u_long opt = 1; ioctlsocket(srv, FIONBIO, &opt); @@ -81,9 +81,9 @@ static ziti_socket_t non_blocking_accept(ziti_socket_t srv) { fprintf(stderr, "select failure"); return -1; } - // srv socket is readable, accept should succeed - return Ziti_accept(srv); + ziti_socket_t clt = Ziti_accept(srv, caller, caller_len); + return clt; } int main(int argc, char *argv[]) { @@ -103,13 +103,14 @@ int main(int argc, char *argv[]) { char readbuf[8 * 1024]; do { + char caller[128]; #if NON_BLOCKING_SERVER - CHECK("non blocking accept", (clt = non_blocking_accept(srv)) < 0); + CHECK("non blocking accept", (clt = non_blocking_accept(srv, caller, sizeof(caller))) < 0); #else - CHECK("accept", (clt = Ziti_accept(srv)) < 0); + CHECK("accept", (clt = Ziti_accept(srv, caller, sizeof(caller))) < 0); #endif - printf("client connected\n"); + printf("client[%s] connected\n", caller); size_t count = 0; size_t total = 0; do { From 2e1ae31a12422321c032fc8154d930817280de74 Mon Sep 17 00:00:00 2001 From: Eugene K Date: Thu, 9 Jun 2022 08:33:12 -0400 Subject: [PATCH 2/9] fix win32 --- library/zitilib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/zitilib.c b/library/zitilib.c index 207731c6..66b46d41 100644 --- a/library/zitilib.c +++ b/library/zitilib.c @@ -651,7 +651,7 @@ static void on_ziti_client(ziti_connection server, ziti_connection client, int s TAILQ_INSERT_TAIL(&server_sock->backlog, pending, _next); server_sock->pending++; #if _WIN32 - send(server_sock->ziti_fd, &b, 1, 0); + send(server_sock->ziti_fd, ¬ify, sizeof(notify), 0); #else write(server_sock->ziti_fd, ¬ify, sizeof(notify)); #endif From c8df8e1f7f4f07a3ea8d298def0da89a6bc7dcbb Mon Sep 17 00:00:00 2001 From: Eugene K Date: Thu, 9 Jun 2022 08:41:00 -0400 Subject: [PATCH 3/9] update Ziti_accept() doc --- includes/ziti/zitilib.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/ziti/zitilib.h b/includes/ziti/zitilib.h index bafe018e..485b1996 100644 --- a/includes/ziti/zitilib.h +++ b/includes/ziti/zitilib.h @@ -125,6 +125,8 @@ int Ziti_listen(ziti_socket_t socket, int backlog); * - not marked as non-blocking: blocks until a connection request is present. * * @param socket socket created with [Ziti_socket()], bound to a service with [Ziti_bind()] or [Ziti_bind_addr()], and is listening after [Ziti_listen()] + * @param caller buffer to store caller ID (dialing identity name) + * @param caller_len length of the [caller] buffer * @return on success returns a file descriptor for the accepted connection. on error -1 is returned, use [Ziti_last_error()] to get actual error code. */ ZITI_FUNC From dc24ba104ce5c6b3ce087bfb4543ef9f9c41c320 Mon Sep 17 00:00:00 2001 From: Eugene K Date: Thu, 9 Jun 2022 12:22:53 -0400 Subject: [PATCH 4/9] better logging --- library/zitilib.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/library/zitilib.c b/library/zitilib.c index 66b46d41..48c5c7f6 100644 --- a/library/zitilib.c +++ b/library/zitilib.c @@ -151,6 +151,7 @@ typedef struct ziti_sock_s { ziti_context ztx; ziti_connection conn; + char *service; bool server; int pending; int max_pending; @@ -406,13 +407,14 @@ static void on_bridge_close(void *ctx) { #else close(zs->ziti_fd); #endif + free(zs->service); free(zs); } static void on_ziti_connect(ziti_connection conn, int status) { ziti_sock_t *zs = ziti_conn_data(conn); if (status == ZITI_OK) { - ZITI_LOG(INFO, "bridge connected to ziti service"); + ZITI_LOG(DEBUG, "bridge connected to ziti service[%s]", zs->service); ziti_conn_bridge_fds(conn, (uv_os_fd_t) zs->ziti_fd, (uv_os_fd_t) zs->ziti_fd, on_bridge_close, zs); complete_future(zs->f, conn); } else { @@ -494,6 +496,7 @@ static void do_ziti_connect(struct conn_req_s *req, future_t *f, uv_loop_t *l) { const char *proto_str = proto == SOCK_DGRAM ? "udp" : "tcp"; if (req->ztx != NULL) { + zs->service = strdup(req->service); ziti_conn_init(req->ztx, &zs->conn, zs); char app_data[1024]; size_t len = snprintf(app_data, sizeof(app_data), @@ -616,7 +619,7 @@ static void on_ziti_accept(ziti_connection client, int status) { static void on_ziti_client(ziti_connection server, ziti_connection client, int status, ziti_client_ctx *clt_ctx) { ziti_sock_t *server_sock = ziti_conn_data(server); - ZITI_LOG(INFO, "incoming client = %s", clt_ctx->caller_id); + ZITI_LOG(DEBUG, "incoming client[%s] for service[%s]", clt_ctx->caller_id, server_sock->service); if (status != ZITI_OK) { on_bridge_close(server_sock); @@ -656,7 +659,7 @@ static void on_ziti_client(ziti_connection server, ziti_connection client, int s write(server_sock->ziti_fd, ¬ify, sizeof(notify)); #endif } else { - ZITI_LOG(WARN, "accept backlog is full, client[%s] rejected", clt_ctx->caller_id); + ZITI_LOG(DEBUG, "accept backlog is full, client[%s] rejected", clt_ctx->caller_id); ziti_close(client, NULL); } } @@ -683,7 +686,8 @@ static void do_ziti_bind(struct conn_req_s *req, future_t *f, uv_loop_t *l) { fail_future(f, EALREADY); } else { if (req->ztx != NULL) { - ZITI_LOG(INFO, "requesting bind fd[%d] to service[%s]", zs->fd, req->service); + ZITI_LOG(DEBUG, "requesting bind fd[%d] to service[%s]", zs->fd, req->service); + zs->service = strdup(req->service); ziti_conn_init(req->ztx, &zs->conn, zs); ziti_listen(zs->conn, req->service, on_ziti_bind, on_ziti_client); zs->f = f; @@ -772,6 +776,7 @@ static void do_ziti_accept(void *r, future_t *f, uv_loop_t *l) { while (!TAILQ_EMPTY(&zs->backlog)) { struct backlog_entry_s *pending = TAILQ_FIRST(&zs->backlog); + ZITI_LOG(DEBUG, "pending connection[%s] for service[%s]", pending->caller_id, zs->service); TAILQ_REMOVE(&zs->backlog, pending, _next); ziti_connection conn = pending->conn; @@ -783,7 +788,7 @@ static void do_ziti_accept(void *r, future_t *f, uv_loop_t *l) { break; } - ZITI_LOG(WARN, "failed to accept: client gone? [%d/%s]", rc, ziti_errorstr(rc)); + ZITI_LOG(DEBUG, "failed to accept: client gone? [%d/%s]", rc, ziti_errorstr(rc)); ziti_close(conn, NULL); free(pending->caller_id); free(pending); @@ -804,6 +809,7 @@ ziti_socket_t Ziti_accept(ziti_socket_t server, char *caller, int caller_len) { free(si->peer); free(si); char b; + fprintf(stderr, "\n>>>> reading notify <<<<\n"); #if _WIN32 recv(server, &b, 1, 0); #else From edcd2208ce1dfca7c8cd9657a273aa19b818e388 Mon Sep 17 00:00:00 2001 From: Eugene K Date: Thu, 9 Jun 2022 15:03:49 -0400 Subject: [PATCH 5/9] cleanup --- library/zitilib.c | 1 - 1 file changed, 1 deletion(-) diff --git a/library/zitilib.c b/library/zitilib.c index 48c5c7f6..5c40f440 100644 --- a/library/zitilib.c +++ b/library/zitilib.c @@ -809,7 +809,6 @@ ziti_socket_t Ziti_accept(ziti_socket_t server, char *caller, int caller_len) { free(si->peer); free(si); char b; - fprintf(stderr, "\n>>>> reading notify <<<<\n"); #if _WIN32 recv(server, &b, 1, 0); #else From 9dc7840eb1c51fc2fcf603dd84ab3d9d753aafee Mon Sep 17 00:00:00 2001 From: Eugene K Date: Thu, 9 Jun 2022 16:10:30 -0400 Subject: [PATCH 6/9] add error log --- library/zitilib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/library/zitilib.c b/library/zitilib.c index 5c40f440..a2ed7bce 100644 --- a/library/zitilib.c +++ b/library/zitilib.c @@ -639,6 +639,7 @@ static void on_ziti_client(ziti_connection server, ziti_connection client, int s ziti_conn_set_data(client, pending); // this should not happen but check anyway if (ziti_accept(client, on_ziti_accept, NULL) != ZITI_OK) { + ZITI_LOG(WARN, "ziti_accept() failed unexpectedly"); ziti_close(client, NULL); free(pending->caller_id); free(pending); From 0e87739749a043b4da8e59abdf80626a3c33df02 Mon Sep 17 00:00:00 2001 From: Eugene K Date: Thu, 9 Jun 2022 16:38:22 -0400 Subject: [PATCH 7/9] set errors consistently --- library/zitilib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/zitilib.c b/library/zitilib.c index a2ed7bce..73645e53 100644 --- a/library/zitilib.c +++ b/library/zitilib.c @@ -526,8 +526,9 @@ int Ziti_connect_addr(ziti_socket_t socket, const char *host, unsigned int port) future_t *f = schedule_on_loop((loop_work_cb) do_ziti_connect, &req, true); int err = await_future(f); + set_error(err); destroy_future(f); - return err; + return err ? -1 : 0; } int Ziti_connect(ziti_socket_t socket, ziti_context ztx, const char *service) { @@ -543,8 +544,9 @@ int Ziti_connect(ziti_socket_t socket, ziti_context ztx, const char *service) { future_t *f = schedule_on_loop((loop_work_cb) do_ziti_connect, &req, true); int err = await_future(f); + set_error(err); destroy_future(f); - return err; + return err ? -1 : 0; } static bool is_blocking(ziti_socket_t s) { From 3f240407fbe5106ce7c720a8935d6485782c32cd Mon Sep 17 00:00:00 2001 From: Shawn Carey Date: Mon, 13 Jun 2022 13:29:07 -0400 Subject: [PATCH 8/9] define in4addr_loopback when not using visual studio (#410) define in4addr_loopback when not using visual studio - fixes mingw build error --- library/zitilib.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/zitilib.c b/library/zitilib.c index 73645e53..30e1b61d 100644 --- a/library/zitilib.c +++ b/library/zitilib.c @@ -299,6 +299,16 @@ static const char * fmt_win32err(int err) { } #endif +#ifdef __MINGW32__ +static const IN_ADDR in4addr_loopback; +static void init_in4addr_loopback() { + IN_ADDR *lo = (IN_ADDR *)&in4addr_loopback; + lo->S_un.S_addr = htonl(INADDR_LOOPBACK); +} +#else +#define init_in4addr_loopback() {} +#endif + static int make_socketpair(int type, ziti_socket_t *fd0, ziti_socket_t *fd1) { int rc = 0; #if _WIN32 @@ -872,6 +882,7 @@ void process_on_loop(uv_async_t *async) { } static void internal_init() { + init_in4addr_loopback(); uv_key_create(&err_key); uv_mutex_init(&q_mut); lib_loop = uv_loop_new(); From c6879b1a4888755b35dccdaed870ddbb3410c789 Mon Sep 17 00:00:00 2001 From: Eugene K Date: Thu, 16 Jun 2022 12:30:30 -0400 Subject: [PATCH 9/9] fix Ziti_load_context() hang with invalid file [fixes #411] --- library/channel.c | 10 +++++----- library/zitilib.c | 25 +++++++++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/library/channel.c b/library/channel.c index d4efadd6..e2e1d005 100644 --- a/library/channel.c +++ b/library/channel.c @@ -1,4 +1,4 @@ -// Copyright (c) 2022. NetFoundry, Inc. +// Copyright (c) 2022. NetFoundry Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -237,22 +237,22 @@ static void check_connecting_state(ziti_channel_t *ch) { // verify channel state bool reset = false; if (!uv_is_active((const uv_handle_t *) &ch->timer)) { - CH_LOG(ERROR, "state check: timer not active!"); + CH_LOG(DEBUG, "state check: timer not active!"); reset = true; } if (ch->timer->timer_cb != ch_connect_timeout) { - CH_LOG(ERROR, "state check: unexpected callback(%s)!", get_timeout_cb(ch)); + CH_LOG(DEBUG, "state check: unexpected callback(%s)!", get_timeout_cb(ch)); reset = true; } if (ch->timer->timeout < uv_now(ch->loop)) { - CH_LOG(ERROR, "state check: timer is in the past!"); + CH_LOG(DEBUG, "state check: timer is in the past!"); reset = true; } if (ch->timer->timeout - uv_now(ch->loop) > CONNECT_TIMEOUT) { - CH_LOG(ERROR, "state check: timer is too far into the future!"); + CH_LOG(DEBUG, "state check: timer is too far into the future!"); reset = true; } } diff --git a/library/zitilib.c b/library/zitilib.c index 30e1b61d..60c2b941 100644 --- a/library/zitilib.c +++ b/library/zitilib.c @@ -205,7 +205,6 @@ static void on_ctx_event(ziti_context ztx, const ziti_event_t *ev) { } } else if (ev->type == ZitiServiceEvent) { - for (int i = 0; ev->event.service.removed && ev->event.service.removed[i] != NULL; i++) { ziti_intercept_cfg_v1 *intercept = model_map_remove(&wrap->intercepts, ev->event.service.removed[i]->name); free_ziti_intercept_cfg_v1(intercept); @@ -247,7 +246,7 @@ static const char *configs[] = { }; static void load_ziti_ctx(void *arg, future_t *f, uv_loop_t *l) { - + int rc = 0; struct ztx_wrap *wrap = model_map_get(&ziti_contexts, arg); if (wrap == NULL) { wrap = calloc(1, sizeof(struct ztx_wrap)); @@ -260,10 +259,15 @@ static void load_ziti_ctx(void *arg, future_t *f, uv_loop_t *l) { wrap->services_loaded = new_future(); TAILQ_INIT(&wrap->futures); + rc = ziti_init_opts(&wrap->opts, l); + if (rc != ZITI_OK) { + fail_future(f, rc); + ZITI_LOG(WARN, "identity file[%s] not found", (const char *) arg); + free(wrap); + return; + } model_map_set(&ziti_contexts, arg, wrap); TAILQ_INSERT_TAIL(&wrap->futures, f, _next); - - ziti_init_opts(&wrap->opts, l); } else if (wrap->ztx) { complete_future(f, wrap->ztx); } else { @@ -272,12 +276,14 @@ static void load_ziti_ctx(void *arg, future_t *f, uv_loop_t *l) { } ziti_context Ziti_load_context(const char *identity) { - future_t *f = schedule_on_loop(load_ziti_ctx, (void*)identity, true); + future_t *f = schedule_on_loop(load_ziti_ctx, (void *) identity, true); int err = await_future(f); set_error(err); ziti_context ztx = (ziti_context) f->result; - ztx_wrap_t *wrap = ziti_app_ctx(ztx); - await_future(wrap->services_loaded); + if (err == 0) { + ztx_wrap_t *wrap = ziti_app_ctx(ztx); + await_future(wrap->services_loaded); + } destroy_future(f); return ztx; } @@ -542,9 +548,8 @@ int Ziti_connect_addr(ziti_socket_t socket, const char *host, unsigned int port) } int Ziti_connect(ziti_socket_t socket, ziti_context ztx, const char *service) { - - if (ztx == NULL) return -EINVAL; - if (service == NULL) return -EINVAL; + if (ztx == NULL) { return EINVAL; } + if (service == NULL) { return EINVAL; } struct conn_req_s req = { .fd = socket,