From 00923627c080cfd56815519b4ddf021773bae80f Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 24 Jul 2019 16:48:24 -0700 Subject: [PATCH] client: add more descriptive string cases --- lib/core-net/close.c | 3 ++- lib/roles/http/client/client.c | 25 ++++++++++++++++++++----- lib/roles/ws/client-ws.c | 1 + lib/tls/mbedtls/mbedtls-client.c | 1 + 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/core-net/close.c b/lib/core-net/close.c index 95b0bf4ef..eceec6cf4 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -355,7 +355,8 @@ just_kill_connection: !wsi->already_did_cce && wsi->protocol) wsi->protocol->callback(wsi, LWS_CALLBACK_CLIENT_CONNECTION_ERROR, - wsi->user_space, NULL, 0); + wsi->user_space, + (void *)"closed before established", 24); /* * Testing with ab shows that we have to stage the socket close when diff --git a/lib/roles/http/client/client.c b/lib/roles/http/client/client.c index 7dc1dc215..e3e3192c5 100644 --- a/lib/roles/http/client/client.c +++ b/lib/roles/http/client/client.c @@ -161,6 +161,7 @@ lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, if (pollfd->revents & LWS_POLLHUP) { lwsl_warn("SOCKS connection %p (fd=%d) dead\n", (void *)wsi, pollfd->fd); + cce = "socks conn dead"; goto bail3; } @@ -171,6 +172,7 @@ lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, return 0; } lwsl_err("ERROR reading from SOCKS socket\n"); + cce = "socks recv fail"; goto bail3; } @@ -183,7 +185,7 @@ lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, if (pt->serv_buf[1] == SOCKS_AUTH_NO_AUTH) { lwsl_client("SOCKS GR: No Auth Method\n"); if (socks_generate_msg(wsi, SOCKS_MSG_CONNECT, &len)) - goto bail3; + goto socks_send_msg_fail; conn_mode = LRS_WAITING_SOCKS_CONNECT_REPLY; pending_timeout = PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY; @@ -195,7 +197,7 @@ lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, if (socks_generate_msg(wsi, SOCKS_MSG_USERNAME_PASSWORD, &len)) - goto bail3; + goto socks_send_msg_fail; conn_mode = LRS_WAITING_SOCKS_AUTH_REPLY; pending_timeout = PENDING_TIMEOUT_AWAITING_SOCKS_AUTH_REPLY; @@ -210,8 +212,11 @@ lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, goto socks_reply_fail; lwsl_client("SOCKS password OK, sending connect\n"); - if (socks_generate_msg(wsi, SOCKS_MSG_CONNECT, &len)) + if (socks_generate_msg(wsi, SOCKS_MSG_CONNECT, &len)) { +socks_send_msg_fail: + *cce = "socks gen msg fail"; goto bail3; + } conn_mode = LRS_WAITING_SOCKS_CONNECT_REPLY; pending_timeout = PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY; @@ -220,6 +225,7 @@ socks_send: MSG_NOSIGNAL); if (n < 0) { lwsl_debug("ERROR writing to socks proxy\n"); + cce = "socks write fail"; goto bail3; } @@ -230,6 +236,7 @@ socks_send: socks_reply_fail: lwsl_notice("socks reply: v%d, err %d\n", pt->serv_buf[0], pt->serv_buf[1]); + cce = "socks reply fail"; goto bail3; case LRS_WAITING_SOCKS_CONNECT_REPLY: @@ -243,8 +250,10 @@ socks_reply_fail: lws_client_stash_destroy(wsi); if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS, - wsi->vhost->socks_proxy_address)) + wsi->vhost->socks_proxy_address)) { + cce = "socks connect fail"; goto bail3; + } wsi->c_port = wsi->vhost->socks_proxy_port; @@ -266,6 +275,7 @@ socks_reply_fail: lwsl_warn("Proxy connection %p (fd=%d) dead\n", (void *)wsi, pollfd->fd); + cce = "proxy conn dead"; goto bail3; } @@ -276,6 +286,7 @@ socks_reply_fail: return 0; } lwsl_err("ERROR reading from proxy socket\n"); + cce = "proxy read err"; goto bail3; } @@ -284,6 +295,7 @@ socks_reply_fail: strncmp(sb, "HTTP/1.1 200 ", 13)) { lwsl_err("%s: ERROR proxy did not reply with h1\n", __func__); + cce = "proxy not h1"; goto bail3; } @@ -527,6 +539,7 @@ client_http_body_sent: if (lws_parse(wsi, &c, &plen)) { lwsl_warn("problems parsing header\n"); + cce = "problems parsing header"; goto bail3; } } @@ -826,8 +839,10 @@ lws_client_interpret_server_handshake(struct lws *wsi) } #endif - if (!ads) /* make coverity happy */ + if (!ads) /* make coverity happy */ { + cce = "no ads"; goto bail3; + } if (!lws_client_reset(&wsi, ssl, ads, port, path, ads)) { /* there are two ways to fail out with NULL return... diff --git a/lib/roles/ws/client-ws.c b/lib/roles/ws/client-ws.c index 4fc0fa3da..4a44624fb 100644 --- a/lib/roles/ws/client-ws.c +++ b/lib/roles/ws/client-ws.c @@ -421,6 +421,7 @@ identify_protocol: wsi->protocol->name); else lwsl_err("No protocol on client\n"); + *cce = "ws protocol no match"; goto bail2; } } diff --git a/lib/tls/mbedtls/mbedtls-client.c b/lib/tls/mbedtls/mbedtls-client.c index 82c0ec3ae..d3de9918d 100644 --- a/lib/tls/mbedtls/mbedtls-client.c +++ b/lib/tls/mbedtls/mbedtls-client.c @@ -142,6 +142,7 @@ lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len) if (!peer) { lwsl_info("peer did not provide cert\n"); + lws_snprintf(ebuf, ebuf_len, "no peer cert"); return -1; }