Skip to content

Commit

Permalink
Properly accommodate IPv6 addresses in LOG_CONNEVENTS logs
Browse files Browse the repository at this point in the history
  • Loading branch information
LINKIWI authored and dormando committed Sep 27, 2021
1 parent 3a8ca31 commit 32349be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ static void _logger_log_item_store(logentry *e, const entry_details *d, const vo
}

static void _logger_log_conn_event(logentry *e, const entry_details *d, const void *entry, va_list ap) {
struct sockaddr *addr = va_arg(ap, struct sockaddr *);
struct sockaddr_in6 *addr = va_arg(ap, struct sockaddr_in6 *);
socklen_t addrlen = va_arg(ap, socklen_t);
enum network_transport transport = va_arg(ap, enum network_transport);
enum close_reasons reason = va_arg(ap, enum close_reasons);
int sfd = va_arg(ap, int);

struct logentry_conn_event *le = (struct logentry_conn_event *) e->data;

memcpy(&le->addr, addr, sizeof(struct sockaddr));
memcpy(&le->addr, addr, addrlen);
le->sfd = sfd;
le->transport = transport;
le->reason = reason;
Expand All @@ -156,11 +157,11 @@ static void _logger_log_conn_event(logentry *e, const entry_details *d, const vo
* Util functions used by the logger background thread
*************************/

static int _logger_util_addr_endpoint(struct sockaddr *addr, char *rip,
static int _logger_util_addr_endpoint(struct sockaddr_in6 *addr, char *rip,
size_t riplen, unsigned short *rport) {
memset(rip, 0, riplen);

switch (addr->sa_family) {
switch (addr->sin6_family) {
case AF_INET:
inet_ntop(AF_INET, &((struct sockaddr_in *) addr)->sin_addr,
rip, riplen - 1);
Expand Down
2 changes: 1 addition & 1 deletion logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct logentry_conn_event {
int transport;
int reason;
int sfd;
struct sockaddr addr;
struct sockaddr_in6 addr;
};

/* end intermediary structures */
Expand Down
4 changes: 2 additions & 2 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ conn *conn_new(const int sfd, enum conn_states init_state,

if (init_state == conn_new_cmd) {
LOGGER_LOG(NULL, LOG_CONNEVENTS, LOGGER_CONNECTION_NEW, NULL,
(struct sockaddr *) &c->request_addr, c->transport, 0, sfd);
&c->request_addr, c->request_addr_size, c->transport, 0, sfd);
}

if (settings.verbose > 1) {
Expand Down Expand Up @@ -897,7 +897,7 @@ static void conn_close(conn *c) {

if (c->thread) {
LOGGER_LOG(c->thread->l, LOG_CONNEVENTS, LOGGER_CONNECTION_CLOSE, NULL,
(struct sockaddr *) &c->request_addr, c->transport,
&c->request_addr, c->request_addr_size, c->transport,
c->close_reason, c->sfd);
}

Expand Down

0 comments on commit 32349be

Please sign in to comment.