mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
wsi: store peer lws_sockaddr46
If we connect out to an IP address, or we adopt a connected socket, from now on we want to hold the peer sockaddr in the wsi. Adapt ACCESS_LOG to use this new copy rather than keep the stringified version.
This commit is contained in:
parent
67d24d7c00
commit
21719898e8
4 changed files with 21 additions and 16 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue