diff --git a/lib/core-net/adopt.c b/lib/core-net/adopt.c index af19aba3c..1458c8a01 100644 --- a/lib/core-net/adopt.c +++ b/lib/core-net/adopt.c @@ -384,12 +384,8 @@ lws_adopt_descriptor_vhost2(struct lws *new_wsi, lws_adoption_type type, #if defined(LWS_WITH_SERVER) else if (lws_server_socket_service_ssl(new_wsi, fd.sockfd, 0)) { -#if defined(LWS_WITH_ACCESS_LOG) - lwsl_notice("%s: fail ssl negotiation: %s\n", __func__, - new_wsi->simple_ip); -#else lwsl_info("%s: fail ssl negotiation\n", __func__); -#endif + goto fail; } #endif @@ -470,7 +466,14 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, struct lws * lws_adopt_descriptor_vhost_via_info(const lws_adopt_desc_t *info) { + socklen_t slen = sizeof(sa46); struct lws *new_wsi; + + if (info->type & LWS_ADOPT_SOCKET && + getpeername(info->fd.sockfd, (struct sockaddr *)&wsi->sa46_peer, + &slen) < 0) + lwsl_info("%s: getpeername failed\n", __func__); + #if defined(LWS_WITH_PEER_LIMITS) struct lws_peer *peer = NULL; @@ -504,11 +507,6 @@ lws_adopt_descriptor_vhost_via_info(const lws_adopt_desc_t *info) return NULL; } -#if defined(LWS_WITH_ACCESS_LOG) - lws_get_peer_simple_fd(info->fd.sockfd, new_wsi->simple_ip, - sizeof(new_wsi->simple_ip)); -#endif - #if defined(LWS_WITH_PEER_LIMITS) if (peer) lws_peer_add_wsi(info->vh->context, peer, new_wsi); diff --git a/lib/core-net/client/connect3.c b/lib/core-net/client/connect3.c index bf80ed748..275f70987 100644 --- a/lib/core-net/client/connect3.c +++ b/lib/core-net/client/connect3.c @@ -402,6 +402,10 @@ ads_known: #if defined(LWS_ESP_PLATFORM) errno = 0; #endif + + /* grab a copy for peer tracking */ + wsi->sa46_peer = *psa; + m = connect(wsi->desc.sockfd, (const struct sockaddr *)psa, n); if (m == -1) { int errno_copy = LWS_ERRNO; diff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h index 044b69803..7889a2189 100644 --- a/lib/core-net/private-lib-core-net.h +++ b/lib/core-net/private-lib-core-net.h @@ -729,9 +729,8 @@ struct lws { struct lws_dll2_owner dll2_cli_txn_queue_owner; #endif -#if defined(LWS_WITH_ACCESS_LOG) - char simple_ip[(8 * 5)]; -#endif + lws_sockaddr46 sa46_peer; + /* pointers */ struct lws *parent; /* points to parent, if any */ diff --git a/lib/roles/http/server/access-log.c b/lib/roles/http/server/access-log.c index 06f441d34..9a29ae955 100644 --- a/lib/roles/http/server/access-log.c +++ b/lib/roles/http/server/access-log.c @@ -43,7 +43,7 @@ static const char * const hver[] = { void lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int meth) { - char da[64], uri[256]; + char da[64], uri[256], ta[64]; time_t t = time(NULL); struct lws *nwsi; const char *me; @@ -89,10 +89,14 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met nwsi = lws_get_network_wsi(wsi); + if (wsi->sa46_peer.sa4.sin_family) + lws_sa46_write_numeric_address(&nwsi->sa46_peer, ta, sizeof(ta)); + else + strncpy(ta, "unknown", sizeof(ta)); + lws_snprintf(wsi->http.access_log.header_log, l, "%s - - [%s] \"%s %s %s\"", - nwsi->simple_ip[0] ? nwsi->simple_ip : "unknown", da, me, uri, - hver[wsi->http.request_version]); + ta, da, me, uri, hver[wsi->http.request_version]); //lwsl_notice("%s\n", wsi->http.access_log.header_log);