From: Stephan Bosch Date: Sun, 15 Sep 2013 00:33:04 +0000 (+0300) Subject: lib-http: Fixed client connection and peer log labels to show proper IPv6 peers. X-Git-Tag: 2.2.6~88 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=930a2323047a5f0cdcc79a090488b72205c913f3;p=thirdparty%2Fdovecot%2Fcore.git lib-http: Fixed client connection and peer log labels to show proper IPv6 peers. The labels did not put IPv6 addresses in square brackets. --- diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index ed4363f330..33247b3b0d 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -134,6 +134,7 @@ static void http_client_host_port_soft_connect_timeout(struct http_client_host_port *hport) { struct http_client_host *host = hport->host; + const struct http_client_peer_addr *addr = &hport->addr; if (hport->to_connect != NULL) timeout_remove(&hport->to_connect); @@ -146,12 +147,10 @@ http_client_host_port_soft_connect_timeout(struct http_client_host_port *hport) /* if our our previous connection attempt takes longer than the soft_connect_timeout, we start a connection attempt to the next IP in parallel */ - - http_client_host_debug(host, "Connection to %s:%u%s is taking a long time; " + http_client_host_debug(host, "Connection to %s%s is taking a long time; " "starting parallel connection attempt to next IP", - net_ip2addr(&hport->addr.ip), hport->addr.port, - hport->addr.https_name == NULL ? "" : - t_strdup_printf(" (SSL=%s)", hport->addr.https_name)); + http_client_peer_addr2str(addr), addr->https_name == NULL ? "" : + t_strdup_printf(" (SSL=%s)", addr->https_name)); /* next IP */ hport->ips_connect_idx = (hport->ips_connect_idx + 1) % host->ips_count; @@ -174,10 +173,10 @@ http_client_host_port_connection_setup(struct http_client_host_port *hport) /* update our peer address */ hport->addr.ip = host->ips[hport->ips_connect_idx]; - http_client_host_debug(host, "Setting up connection to %s:%u%s " - "(%u requests pending)", net_ip2addr(&addr->ip), addr->port, - addr->https_name == NULL ? "" : - t_strdup_printf(" (SSL=%s)", addr->https_name), num_requests); + http_client_host_debug(host, "Setting up connection to %s%s " + "(%u requests pending)", http_client_peer_addr2str(addr), + (addr->https_name == NULL ? "" : + t_strdup_printf(" (SSL=%s)", addr->https_name)), num_requests); /* create/get peer */ peer = http_client_peer_get(host->client, addr); @@ -307,8 +306,8 @@ void http_client_host_connection_success(struct http_client_host *host, { struct http_client_host_port *hport; - http_client_host_debug(host, "Successfully connected to %s:%u", - net_ip2addr(&addr->ip), addr->port); + http_client_host_debug(host, "Successfully connected to %s", + http_client_peer_addr2str(addr)); hport = http_client_host_port_find(host, addr->port, addr->https_name); if (hport == NULL) @@ -322,8 +321,8 @@ void http_client_host_connection_failure(struct http_client_host *host, { struct http_client_host_port *hport; - http_client_host_debug(host, "Failed to connect to %s:%u: %s", - net_ip2addr(&addr->ip), addr->port, reason); + http_client_host_debug(host, "Failed to connect to %s: %s", + http_client_peer_addr2str(addr), reason); hport = http_client_host_port_find(host, addr->port, addr->https_name); if (hport == NULL) @@ -513,8 +512,8 @@ http_client_host_claim_request(struct http_client_host *host, array_delete(&hport->request_queue, i, 1); http_client_host_debug(host, - "Connection to peer %s:%u claimed request %s %s", - net_ip2addr(&addr->ip), addr->port, http_client_request_label(req), + "Connection to peer %s claimed request %s %s", + http_client_peer_addr2str(addr), http_client_request_label(req), (req->urgent ? "(urgent)" : "")); return req; diff --git a/src/lib-http/http-client-peer.c b/src/lib-http/http-client-peer.c index c06b98c6fb..e4791122b6 100644 --- a/src/lib-http/http-client-peer.c +++ b/src/lib-http/http-client-peer.c @@ -29,9 +29,8 @@ http_client_peer_debug(struct http_client_peer *peer, if (peer->client->set.debug) { va_start(args, format); - i_debug("http-client: peer %s:%u: %s", - net_ip2addr(&peer->addr.ip), peer->addr.port, - t_strdup_vprintf(format, args)); + i_debug("http-client: peer %s: %s", + http_client_peer_label(peer), t_strdup_vprintf(format, args)); va_end(args); } } diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index bcd010ea38..d80d09583e 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -189,6 +189,14 @@ struct http_client { unsigned int pending_requests; }; +static inline const char * +http_client_peer_addr2str(const struct http_client_peer_addr *addr) +{ + if (addr->ip.family == AF_INET6) + return t_strdup_printf("[%s]:%u", net_ip2addr(&addr->ip), addr->port); + return t_strdup_printf("%s:%u", net_ip2addr(&addr->ip), addr->port); +} + static inline const char * http_client_request_label(struct http_client_request *req) { @@ -199,8 +207,14 @@ http_client_request_label(struct http_client_request *req) static inline const char * http_client_connection_label(struct http_client_connection *conn) { - return t_strdup_printf("%s:%u [%d]", - net_ip2addr(&conn->conn.ip), conn->conn.port, conn->id); + return t_strdup_printf("%s [%d]", + http_client_peer_addr2str(&conn->peer->addr), conn->id); +} + +static inline const char * +http_client_peer_label(struct http_client_peer *peer) +{ + return http_client_peer_addr2str(&peer->addr); } int http_client_init_ssl_ctx(struct http_client *client, const char **error_r);