On Tue, Nov 01, 2022 at 02:45:58PM +, Job Snijders wrote:
> It can be useful to see a little bit more detail on what exactly isn't
> working.
>
> OK?
>
> Index: http.c
> ===
> RCS file: /cvs/src/usr.sbin/rpki-client/http.c,v
> retrieving revision 1.70
> diff -u -p -r1.70 http.c
> --- http.c18 Oct 2022 14:03:39 - 1.70
> +++ http.c1 Nov 2022 14:36:44 -
> @@ -210,6 +210,21 @@ http_info(const char *uri)
> }
>
> /*
> + * Return IP address in presentation format.
> + */
> +static const char *
> +ip_info(const struct http_connection *conn)
> +{
> + static char buf[NI_MAXHOST];
> +
> + if (getnameinfo(conn->res0->ai_addr, conn->res0->ai_addrlen,
> + buf, sizeof(buf), NULL, 0, NI_NUMERICHOST))
This can not be right. conn->res is the address which was use by the last
connect call. Also conn->res / conn->res0 are only valid in STATE_CONNECT.
In http_connect_done() conn->res0 is freed and both res and res0 are set
to NULL.
> + return ("unknown");
> +
> + return buf;
> +}
> +
> +/*
> * Determine whether the character needs encoding, per RFC2396.
> */
> static int
> @@ -870,7 +885,8 @@ http_connect(struct http_connection *con
>
> if (conn->fd == -1) {
> if (cause != NULL)
> - warn("%s: %s", http_info(conn->req->uri), cause);
> + warn("%s (%s): %s", http_info(conn->req->uri),
> + ip_info(conn), cause);
> return http_failed(conn);
> }
>
> @@ -1930,12 +1946,14 @@ 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",
> - http_info(conn->host));
> + warnx("%s (%s): connect timeout",
> + http_info(conn->host),
> + ip_info(conn));
> http_do(conn, http_connect_failed);
> } else {
> - warnx("%s: timeout, connection closed",
> - http_info(conn->host));
> + warnx("%s (%s): timeout, connection "
> + "closed", http_info(conn->host),
> + ip_info(conn));
This will not work since conn->res is most probably not available anymore.
An option is to keep conn->res0 around and not free it in
http_connect_done().
> http_do(conn, http_failed);
> }
> }
>
--
:wq Claudio