From: claudio Date: Tue, 9 Aug 2022 09:02:26 +0000 (+0000) Subject: Make the http code respect MAX_CONN_TIMEOUT and fail connects once they X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9170c2da45e8f5d1121ee75c5272742ea03b39c9;p=openbsd Make the http code respect MAX_CONN_TIMEOUT and fail connects once they hit this timeout. This is in line with the rsync code. OK tb@ job@ --- diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 58a584239f6..e5868ffa15b 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.145 2022/08/08 15:22:31 job Exp $ */ +/* $OpenBSD: extern.h,v 1.146 2022/08/09 09:02:26 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -728,7 +728,7 @@ int mkpathat(int, const char *); #define MAX_RSYNC_REQUESTS 16 /* How many seconds to wait for a connection to succeed. */ -#define MAX_CONTIMEOUT 15 +#define MAX_CONN_TIMEOUT 15 /* How long to wait for IO from a remote server. */ #define MAX_IO_TIMEOUT 180 diff --git a/usr.sbin/rpki-client/http.c b/usr.sbin/rpki-client/http.c index d55482e8eb2..d3263fe2d49 100644 --- a/usr.sbin/rpki-client/http.c +++ b/usr.sbin/rpki-client/http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: http.c,v 1.63 2022/08/08 15:22:31 job Exp $ */ +/* $OpenBSD: http.c,v 1.64 2022/08/09 09:02:26 claudio Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2020 Claudio Jeker @@ -755,6 +755,19 @@ http_failed(struct http_connection *conn) return DONE; } +/* + * Called in case of connect timeout, try an alternate connection. + */ +static enum res +http_connect_failed(struct http_connection *conn) +{ + assert(conn->state == STATE_CONNECT); + close(conn->fd); + conn->fd = -1; + + return http_connect(conn); +} + /* * Call the function f and update the connection events based * on the return value. @@ -1812,8 +1825,12 @@ proc_http(char *bind_addr, int fd) if (i >= NPFDS) errx(1, "too many connections"); - if (conn->io_time == 0) - conn->io_time = now + MAX_IO_TIMEOUT; + if (conn->io_time == 0) { + if (conn->state == STATE_CONNECT) + conn->io_time = now + MAX_CONN_TIMEOUT; + else + conn->io_time = now + MAX_IO_TIMEOUT; + } if (conn->io_time <= now) timeout = 0; @@ -1901,9 +1918,15 @@ proc_http(char *bind_addr, int fd) if (conn->pfd != NULL && conn->pfd->revents != 0) http_do(conn, http_handle); else if (conn->io_time <= now) { - warnx("%s: timeout, connection closed", - http_info(conn->host)); - http_do(conn, http_failed); + if (conn->state == STATE_CONNECT) { + warnx("%s: connect timeout", + http_info(conn->host)); + http_do(conn, http_connect_failed); + } else { + warnx("%s: timeout, connection closed", + http_info(conn->host)); + http_do(conn, http_failed); + } } if (conn->state == STATE_FREE) diff --git a/usr.sbin/rpki-client/rsync.c b/usr.sbin/rpki-client/rsync.c index 5139e516a07..6fc689d3f13 100644 --- a/usr.sbin/rpki-client/rsync.c +++ b/usr.sbin/rpki-client/rsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsync.c,v 1.40 2022/08/08 15:22:31 job Exp $ */ +/* $OpenBSD: rsync.c,v 1.41 2022/08/09 09:02:26 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -312,7 +312,7 @@ proc_rsync(char *prog, char *bind_addr, int fd) args[i++] = "-rt"; args[i++] = "--no-motd"; args[i++] = "--max-size=" STRINGIFY(MAX_FILE_SIZE); - args[i++] = "--contimeout=" STRINGIFY(MAX_CONTIMEOUT); + args[i++] = "--contimeout=" STRINGIFY(MAX_CONN_TIMEOUT); args[i++] = "--timeout=" STRINGIFY(MAX_IO_TIMEOUT); args[i++] = "--include=*/"; args[i++] = "--include=*.cer";