summaryrefslogtreecommitdiff
path: root/net/lwip/tftp.c
diff options
context:
space:
mode:
authorJerome Forissier <jerome.forissier@linaro.org>2025-04-28 11:24:07 +0200
committerJerome Forissier <jerome.forissier@linaro.org>2025-05-20 15:43:09 +0200
commit722e41ad9931bf6f327a66b5f8ec0dadfb32e0f3 (patch)
tree3c29421dce6cf3d50f376bb729fa1c0fd0cdf908 /net/lwip/tftp.c
parent1bc91fa98c020c1f737680cc43a4c7584e17db15 (diff)
net: lwip: tftp: time out if there is no reply from server
When there is no reply from the TFTP server, do_tftpb() should eventually time out. Add a 10 second timer for that purpose. Reported-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Diffstat (limited to 'net/lwip/tftp.c')
-rw-r--r--net/lwip/tftp.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/net/lwip/tftp.c b/net/lwip/tftp.c
index 162c141105c..fae701bad2e 100644
--- a/net/lwip/tftp.c
+++ b/net/lwip/tftp.c
@@ -16,6 +16,8 @@
#include <time.h>
#define PROGRESS_PRINT_STEP_BYTES (10 * 1024)
+/* Max time to wait for first data packet from server */
+#define NO_RSP_TIMEOUT_MS 10000
enum done_state {
NOT_DONE = 0,
@@ -140,6 +142,17 @@ static const struct tftp_context tftp_context = {
tftp_error
};
+static void no_response(void *arg)
+{
+ struct tftp_ctx *ctx = (struct tftp_ctx *)arg;
+
+ if (ctx->size)
+ return;
+
+ printf("Timeout!\n");
+ ctx->done = FAILURE;
+}
+
static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
ip_addr_t srvip, uint16_t srvport)
{
@@ -184,6 +197,7 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
return -1;
}
+ sys_timeout(NO_RSP_TIMEOUT_MS, no_response, &ctx);
while (!ctx.done) {
net_lwip_rx(udev, netif);
sys_check_timeouts();
@@ -193,6 +207,7 @@ static int tftp_loop(struct udevice *udev, ulong addr, char *fname,
break;
}
}
+ sys_untimeout(no_response, (void *)&ctx);
tftp_cleanup();