Also print IP address of the connection that timed out to aid debugging
authorjob <job@openbsd.org>
Wed, 2 Nov 2022 10:41:43 +0000 (10:41 +0000)
committerjob <job@openbsd.org>
Wed, 2 Nov 2022 10:41:43 +0000 (10:41 +0000)
OK claudio@

usr.sbin/rpki-client/http.c

index f89a10f..171c330 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: http.c,v 1.70 2022/10/18 14:03:39 claudio Exp $ */
+/*     $OpenBSD: http.c,v 1.71 2022/11/02 10:41:43 job Exp $ */
 /*
  * Copyright (c) 2020 Nils Fisher <nils_fisher@hotmail.com>
  * Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
@@ -209,6 +209,32 @@ http_info(const char *uri)
        return buf;
 }
 
+/*
+ * Return IP address in presentation format.
+ */
+static const char *
+ip_info(const struct http_connection *conn)
+{
+       static char     buf[NI_MAXHOST + 3];
+       char            ipbuf[NI_MAXHOST];
+       int             ret;
+
+       assert(conn->state == STATE_CONNECT);
+
+       if (conn->res == NULL)
+               return (" (unknown)");
+
+       if (getnameinfo(conn->res->ai_addr, conn->res->ai_addrlen, ipbuf,
+           sizeof(ipbuf), NULL, 0, NI_NUMERICHOST) != 0)
+               return (" (unknown)");
+
+       ret = snprintf(buf, sizeof(buf), " (%s)", ipbuf);
+       if (ret < 0 || (size_t)ret >= sizeof(buf))
+               err(1, NULL);
+
+       return buf;
+}
+
 /*
  * Determine whether the character needs encoding, per RFC2396.
  */
@@ -1930,7 +1956,8 @@ proc_http(char *bind_addr, int fd)
                                http_do(conn, http_handle);
                        else if (conn->io_time <= now) {
                                if (conn->state == STATE_CONNECT) {
-                                       warnx("%s: connect timeout",
+                                       warnx("%s%s: connect timeout",
+                                           ip_info(conn),
                                            http_info(conn->host));
                                        http_do(conn, http_connect_failed);
                                } else {