git: e3ef89ba9673 - stable/13 - loader: tftp: Don't let tftp timeout

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Thu, 13 Jan 2022 09:49:02 UTC
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=e3ef89ba96730180f55b9fc6af4c29e1482b9ac6

commit e3ef89ba96730180f55b9fc6af4c29e1482b9ac6
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2021-12-13 09:35:23 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-01-13 07:55:51 +0000

    loader: tftp: Don't let tftp timeout
    
    When we load a kernel or module we open/close it a few times.
    Since we're using the same port number each time and that we requested
    the same file the ACK that we send are valid on the server side and the
    server send us the file multiple times.
    This makes tftp loading time very inconsistant due to the UDP "flood" that
    we have to process.
    
    Reviewed by:    imp, tsoome
    MFC after:      2 weeks
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D33407
    
    (cherry picked from commit 4f36ed513cc8fc3fe780b23ecda8cb1fdc6edf7d)
---
 stand/libsa/tftp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/stand/libsa/tftp.c b/stand/libsa/tftp.c
index 37f8b64f99aa..a63ca8d16d4d 100644
--- a/stand/libsa/tftp.c
+++ b/stand/libsa/tftp.c
@@ -113,6 +113,8 @@ struct tftp_handle {
 	unsigned long	tftp_tsize;
 	void		*pkt;
 	struct tftphdr	*tftp_hdr;
+	char		*tftp_cache;
+	bool		lastacksent;
 };
 
 struct tftprecv_extra {
@@ -377,6 +379,7 @@ tftp_makereq(struct tftp_handle *h)
 			if (res < h->tftp_blksize) {
 				h->islastblock = 1;	/* very short file */
 				tftp_sendack(h, h->currblock);
+				h->lastacksent = true;
 			}
 			return (0);
 		}
@@ -591,7 +594,8 @@ tftp_close(struct open_file *f)
 	struct tftp_handle *tftpfile;
 	tftpfile = f->f_fsdata;
 
-	/* let it time out ... */
+	if (tftpfile->lastacksent == false)
+		tftp_senderr(tftpfile, 0, "No error: file closed");
 
 	if (tftpfile) {
 		free(tftpfile->path);