From: Michael Brown Date: Mon, 23 Jan 2023 22:20:36 +0000 (+0000) Subject: [pxe] Discard queued PXE UDP packets when under memory pressure X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F859%2Fhead;p=thirdparty%2Fipxe.git [pxe] Discard queued PXE UDP packets when under memory pressure The PXE UDP receive queue may grow without limit if the PXE NBP does not call PXENV_UDP_READ sufficiently frequently. Fix by implementing a cache discarder for received PXE UDP packets (similar to the TCP cache discarder). Reported-by: Tal Shorer Signed-off-by: Michael Brown --- diff --git a/src/arch/x86/interface/pxe/pxe_udp.c b/src/arch/x86/interface/pxe/pxe_udp.c index 5a04f0865..a5d5eb77b 100644 --- a/src/arch/x86/interface/pxe/pxe_udp.c +++ b/src/arch/x86/interface/pxe/pxe_udp.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -482,3 +483,28 @@ struct pxe_api_call pxe_udp_api[] __pxe_api_call = { PXE_API_CALL ( PXENV_UDP_READ, pxenv_udp_read, struct s_PXENV_UDP_READ ), }; + +/** + * Discard some cached PXE UDP data + * + * @ret discarded Number of cached items discarded + */ +static unsigned int pxe_udp_discard ( void ) { + struct io_buffer *iobuf; + unsigned int discarded = 0; + + /* Try to discard the oldest received UDP packet */ + iobuf = list_first_entry ( &pxe_udp.list, struct io_buffer, list ); + if ( iobuf ) { + list_del ( &iobuf->list ); + free_iob ( iobuf ); + discarded++; + } + + return discarded; +} + +/** PXE UDP cache discarder */ +struct cache_discarder pxe_udp_discarder __cache_discarder ( CACHE_NORMAL ) = { + .discard = pxe_udp_discard, +};