diff options
Diffstat (limited to 'src/arch/x86')
| -rw-r--r-- | src/arch/x86/Makefile | 3 | ||||
| -rw-r--r-- | src/arch/x86/Makefile.linux | 4 | ||||
| -rw-r--r-- | src/arch/x86/core/rdrand.c | 103 | ||||
| -rw-r--r-- | src/arch/x86/image/bzimage.c | 53 | ||||
| -rw-r--r-- | src/arch/x86/image/multiboot.c | 4 | ||||
| -rw-r--r-- | src/arch/x86/include/bits/entropy.h | 14 | ||||
| -rw-r--r-- | src/arch/x86/include/bits/errfile.h | 1 | ||||
| -rw-r--r-- | src/arch/x86/include/bits/io.h | 3 | ||||
| -rw-r--r-- | src/arch/x86/include/ipxe/cpuid.h | 3 | ||||
| -rw-r--r-- | src/arch/x86/include/ipxe/pcbios/dhcparch.h | 20 | ||||
| -rw-r--r-- | src/arch/x86/include/ipxe/rtc_entropy.h | 62 | ||||
| -rw-r--r-- | src/arch/x86/include/ipxe/x86_io.h | 3 | ||||
| -rw-r--r-- | src/arch/x86/include/linux/ipxe/dhcp_arch.h | 41 | ||||
| -rw-r--r-- | src/arch/x86/interface/pcbios/bios_cachedhcp.c | 2 | ||||
| -rw-r--r-- | src/arch/x86/interface/pcbios/rtc_entropy.c | 52 | ||||
| -rw-r--r-- | src/arch/x86/interface/pxe/pxe_udp.c | 26 |
16 files changed, 221 insertions, 173 deletions
diff --git a/src/arch/x86/Makefile b/src/arch/x86/Makefile index 011260cac..ef801365e 100644 --- a/src/arch/x86/Makefile +++ b/src/arch/x86/Makefile @@ -22,9 +22,6 @@ SRCDIRS += arch/x86/drivers/xen SRCDIRS += arch/x86/drivers/hyperv SRCDIRS += arch/x86/transitions -# breaks building some of the linux-related objects -CFLAGS += -Ulinux - # disable valgrind CFLAGS += -DNVALGRIND diff --git a/src/arch/x86/Makefile.linux b/src/arch/x86/Makefile.linux index b60065567..42590441e 100644 --- a/src/arch/x86/Makefile.linux +++ b/src/arch/x86/Makefile.linux @@ -1,9 +1,5 @@ # -*- makefile -*- : Force emacs to use Makefile mode -# Include x86 Linux headers -# -INCDIRS += arch/x86/include/linux - # Include generic Linux Makefile # MAKEDEPS += Makefile.linux diff --git a/src/arch/x86/core/rdrand.c b/src/arch/x86/core/rdrand.c new file mode 100644 index 000000000..850ab1f11 --- /dev/null +++ b/src/arch/x86/core/rdrand.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2023 Michael Brown <mbrown@fensystems.co.uk>. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * You can also choose to distribute this program under the terms of + * the Unmodified Binary Distribution Licence (as given in the file + * COPYING.UBDL), provided that you have satisfied its requirements. + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +/** @file + * + * Hardware random number generator + * + */ + +#include <errno.h> +#include <ipxe/cpuid.h> +#include <ipxe/entropy.h> +#include <ipxe/drbg.h> + +struct entropy_source rdrand_entropy __entropy_source ( ENTROPY_PREFERRED ); + +/** Number of times to retry RDRAND instruction */ +#define RDRAND_RETRY_COUNT 16 + +/** Colour for debug messages */ +#define colour &rdrand_entropy + +/** + * Enable entropy gathering + * + * @ret rc Return status code + */ +static int rdrand_entropy_enable ( void ) { + struct x86_features features; + + /* Check that RDRAND is supported */ + x86_features ( &features ); + if ( ! ( features.intel.ecx & CPUID_FEATURES_INTEL_ECX_RDRAND ) ) { + DBGC ( colour, "RDRAND not supported\n" ); + return -ENOTSUP; + } + + /* Data returned by RDRAND is theoretically full entropy, up + * to a security strength of 128 bits, so assume that each + * sample contains exactly 8 bits of entropy. + */ + if ( DRBG_SECURITY_STRENGTH > 128 ) + return -ENOTSUP; + entropy_init ( &rdrand_entropy, MIN_ENTROPY ( 8.0 ) ); + + return 0; +} + +/** + * Get noise sample + * + * @ret noise Noise sample + * @ret rc Return status code + */ +static int rdrand_get_noise ( noise_sample_t *noise ) { + unsigned int result; + unsigned int discard_c; + unsigned int ok; + + /* Issue RDRAND, retrying until CF is set */ + __asm__ ( "\n1:\n\t" + "rdrand %0\n\t" + "sbb %1, %1\n\t" + "loopz 1b\n\t" + : "=r" ( result ), "=r" ( ok ), "=c" ( discard_c ) + : "2" ( RDRAND_RETRY_COUNT ) ); + if ( ! ok ) { + DBGC ( colour, "RDRAND failed to become ready\n" ); + return -EBUSY; + } + + *noise = result; + return 0; +} + +/** Hardware random number generator entropy source */ +struct entropy_source rdrand_entropy __entropy_source ( ENTROPY_PREFERRED ) = { + .name = "rdrand", + .enable = rdrand_entropy_enable, + .get_noise = rdrand_get_noise, +}; diff --git a/src/arch/x86/image/bzimage.c b/src/arch/x86/image/bzimage.c index a782127a1..b15bd5563 100644 --- a/src/arch/x86/image/bzimage.c +++ b/src/arch/x86/image/bzimage.c @@ -247,18 +247,20 @@ static void bzimage_update_header ( struct image *image, * * @v image bzImage file * @v bzimg bzImage context - * @v cmdline Kernel command line * @ret rc Return status code */ static int bzimage_parse_cmdline ( struct image *image, - struct bzimage_context *bzimg, - const char *cmdline ) { - char *vga; - char *mem; + struct bzimage_context *bzimg ) { + const char *vga; + const char *mem; + char *sep; + char *end; /* Look for "vga=" */ - if ( ( vga = strstr ( cmdline, "vga=" ) ) ) { - vga += 4; + if ( ( vga = image_argument ( image, "vga=" ) ) ) { + sep = strchr ( vga, ' ' ); + if ( sep ) + *sep = '\0'; if ( strcmp ( vga, "normal" ) == 0 ) { bzimg->vid_mode = BZI_VID_MODE_NORMAL; } else if ( strcmp ( vga, "ext" ) == 0 ) { @@ -266,19 +268,20 @@ static int bzimage_parse_cmdline ( struct image *image, } else if ( strcmp ( vga, "ask" ) == 0 ) { bzimg->vid_mode = BZI_VID_MODE_ASK; } else { - bzimg->vid_mode = strtoul ( vga, &vga, 0 ); - if ( *vga && ( *vga != ' ' ) ) { - DBGC ( image, "bzImage %p strange \"vga=\"" - "terminator '%c'\n", image, *vga ); + bzimg->vid_mode = strtoul ( vga, &end, 0 ); + if ( *end ) { + DBGC ( image, "bzImage %p strange \"vga=\" " + "terminator '%c'\n", image, *end ); } } + if ( sep ) + *sep = ' '; } /* Look for "mem=" */ - if ( ( mem = strstr ( cmdline, "mem=" ) ) ) { - mem += 4; - bzimg->mem_limit = strtoul ( mem, &mem, 0 ); - switch ( *mem ) { + if ( ( mem = image_argument ( image, "mem=" ) ) ) { + bzimg->mem_limit = strtoul ( mem, &end, 0 ); + switch ( *end ) { case 'G': case 'g': bzimg->mem_limit <<= 10; @@ -296,7 +299,7 @@ static int bzimage_parse_cmdline ( struct image *image, break; default: DBGC ( image, "bzImage %p strange \"mem=\" " - "terminator '%c'\n", image, *mem ); + "terminator '%c'\n", image, *end ); break; } bzimg->mem_limit -= 1; @@ -310,11 +313,10 @@ static int bzimage_parse_cmdline ( struct image *image, * * @v image bzImage image * @v bzimg bzImage context - * @v cmdline Kernel command line */ static void bzimage_set_cmdline ( struct image *image, - struct bzimage_context *bzimg, - const char *cmdline ) { + struct bzimage_context *bzimg ) { + const char *cmdline = ( image->cmdline ? image->cmdline : "" ); size_t cmdline_len; /* Copy command line down to real-mode portion */ @@ -353,10 +355,6 @@ static size_t bzimage_load_initrd ( struct image *image, size_t offset; size_t pad_len; - /* Do not include kernel image itself as an initrd */ - if ( initrd == image ) - return 0; - /* Create cpio header for non-prebuilt images */ offset = cpio_header ( initrd, &cpio ); @@ -404,10 +402,6 @@ static int bzimage_check_initrds ( struct image *image, /* Calculate total loaded length of initrds */ for_each_image ( initrd ) { - /* Skip kernel */ - if ( initrd == image ) - continue; - /* Calculate length */ len += bzimage_load_initrd ( image, initrd, UNULL ); len = bzimage_align ( len ); @@ -522,7 +516,6 @@ static void bzimage_load_initrds ( struct image *image, */ static int bzimage_exec ( struct image *image ) { struct bzimage_context bzimg; - const char *cmdline = ( image->cmdline ? image->cmdline : "" ); int rc; /* Read and parse header from image */ @@ -545,7 +538,7 @@ static int bzimage_exec ( struct image *image ) { } /* Parse command line for bootloader parameters */ - if ( ( rc = bzimage_parse_cmdline ( image, &bzimg, cmdline ) ) != 0) + if ( ( rc = bzimage_parse_cmdline ( image, &bzimg ) ) != 0) return rc; /* Check that initrds can be loaded */ @@ -562,7 +555,7 @@ static int bzimage_exec ( struct image *image ) { bzimg.rm_filesz, bzimg.pm_sz ); /* Store command line */ - bzimage_set_cmdline ( image, &bzimg, cmdline ); + bzimage_set_cmdline ( image, &bzimg ); /* Prepare for exiting. Must do this before loading initrds, * since loading the initrds will corrupt the external heap. diff --git a/src/arch/x86/image/multiboot.c b/src/arch/x86/image/multiboot.c index 0c85df708..c1c63bc97 100644 --- a/src/arch/x86/image/multiboot.c +++ b/src/arch/x86/image/multiboot.c @@ -204,10 +204,6 @@ static int multiboot_add_modules ( struct image *image, physaddr_t start, break; } - /* Do not include kernel image itself as a module */ - if ( module_image == image ) - continue; - /* Page-align the module */ start = ( ( start + 0xfff ) & ~0xfff ); diff --git a/src/arch/x86/include/bits/entropy.h b/src/arch/x86/include/bits/entropy.h deleted file mode 100644 index 5ac7fcd2e..000000000 --- a/src/arch/x86/include/bits/entropy.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _BITS_ENTROPY_H -#define _BITS_ENTROPY_H - -/** @file - * - * x86-specific entropy API implementations - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <ipxe/rtc_entropy.h> - -#endif /* _BITS_ENTROPY_H */ diff --git a/src/arch/x86/include/bits/errfile.h b/src/arch/x86/include/bits/errfile.h index b0ae1abc2..b5316a586 100644 --- a/src/arch/x86/include/bits/errfile.h +++ b/src/arch/x86/include/bits/errfile.h @@ -28,6 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ERRFILE_cpuid ( ERRFILE_ARCH | ERRFILE_CORE | 0x00110000 ) #define ERRFILE_rdtsc_timer ( ERRFILE_ARCH | ERRFILE_CORE | 0x00120000 ) #define ERRFILE_acpi_timer ( ERRFILE_ARCH | ERRFILE_CORE | 0x00130000 ) +#define ERRFILE_rdrand ( ERRFILE_ARCH | ERRFILE_CORE | 0x00140000 ) #define ERRFILE_bootsector ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00000000 ) #define ERRFILE_bzimage ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00010000 ) diff --git a/src/arch/x86/include/bits/io.h b/src/arch/x86/include/bits/io.h index 60c2e3edf..95673ad8d 100644 --- a/src/arch/x86/include/bits/io.h +++ b/src/arch/x86/include/bits/io.h @@ -9,6 +9,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +/** Page shift */ +#define PAGE_SHIFT 12 + #include <ipxe/x86_io.h> #endif /* _BITS_IO_H */ diff --git a/src/arch/x86/include/ipxe/cpuid.h b/src/arch/x86/include/ipxe/cpuid.h index 3983dfb89..90d1bf01d 100644 --- a/src/arch/x86/include/ipxe/cpuid.h +++ b/src/arch/x86/include/ipxe/cpuid.h @@ -39,6 +39,9 @@ struct x86_features { /** Get standard features */ #define CPUID_FEATURES 0x00000001UL +/** RDRAND instruction is supported */ +#define CPUID_FEATURES_INTEL_ECX_RDRAND 0x40000000UL + /** Hypervisor is present */ #define CPUID_FEATURES_INTEL_ECX_HYPERVISOR 0x80000000UL diff --git a/src/arch/x86/include/ipxe/pcbios/dhcparch.h b/src/arch/x86/include/ipxe/pcbios/dhcparch.h new file mode 100644 index 000000000..13138ea96 --- /dev/null +++ b/src/arch/x86/include/ipxe/pcbios/dhcparch.h @@ -0,0 +1,20 @@ +#ifndef _IPXE_PCBIOS_DHCPARCH_H +#define _IPXE_PCBIOS_DHCPARCH_H + +/** @file + * + * DHCP client architecture definitions + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include <ipxe/dhcp.h> + +/** DHCP client architecture */ +#define DHCP_ARCH_CLIENT_ARCHITECTURE DHCP_CLIENT_ARCHITECTURE_X86 + +/** DHCP client network device interface */ +#define DHCP_ARCH_CLIENT_NDI 1 /* UNDI */ , 2, 1 /* v2.1 */ + +#endif /* _IPXE_PCBIOS_DHCPARCH_H */ diff --git a/src/arch/x86/include/ipxe/rtc_entropy.h b/src/arch/x86/include/ipxe/rtc_entropy.h deleted file mode 100644 index 581abcd3e..000000000 --- a/src/arch/x86/include/ipxe/rtc_entropy.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _IPXE_RTC_ENTROPY_H -#define _IPXE_RTC_ENTROPY_H - -/** @file - * - * RTC-based entropy source - * - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#include <stdint.h> - -#ifdef ENTROPY_RTC -#define ENTROPY_PREFIX_rtc -#else -#define ENTROPY_PREFIX_rtc __rtc_ -#endif - -/** - * min-entropy per sample - * - * @ret min_entropy min-entropy of each sample - */ -static inline __always_inline min_entropy_t -ENTROPY_INLINE ( rtc, min_entropy_per_sample ) ( void ) { - - /* The min-entropy has been measured on several platforms - * using the entropy_sample test code. Modelling the samples - * as independent, and using a confidence level of 99.99%, the - * measurements were as follows: - * - * qemu-kvm : 7.38 bits - * VMware : 7.46 bits - * Physical hardware : 2.67 bits - * - * We choose the lowest of these (2.67 bits) and apply a 50% - * safety margin to allow for some potential non-independence - * of samples. - */ - return MIN_ENTROPY ( 1.3 ); -} - -extern uint8_t rtc_sample ( void ); - -/** - * Get noise sample - * - * @ret noise Noise sample - * @ret rc Return status code - */ -static inline __always_inline int -ENTROPY_INLINE ( rtc, get_noise ) ( noise_sample_t *noise ) { - - /* Get sample */ - *noise = rtc_sample(); - - /* Always successful */ - return 0; -} - -#endif /* _IPXE_RTC_ENTROPY_H */ diff --git a/src/arch/x86/include/ipxe/x86_io.h b/src/arch/x86/include/ipxe/x86_io.h index a6ebe1f4c..eeb3f8454 100644 --- a/src/arch/x86/include/ipxe/x86_io.h +++ b/src/arch/x86/include/ipxe/x86_io.h @@ -28,9 +28,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * */ -/** Page shift */ -#define PAGE_SHIFT 12 - /* * Physical<->Bus address mappings * diff --git a/src/arch/x86/include/linux/ipxe/dhcp_arch.h b/src/arch/x86/include/linux/ipxe/dhcp_arch.h deleted file mode 100644 index d60905f22..000000000 --- a/src/arch/x86/include/linux/ipxe/dhcp_arch.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2010 Piotr JaroszyĆski <p.jaroszynski@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * You can also choose to distribute this program under the terms of - * the Unmodified Binary Distribution Licence (as given in the file - * COPYING.UBDL), provided that you have satisfied its requirements. - */ - -#ifndef _LINUX_DHCP_ARCH_H -#define _LINUX_DHCP_ARCH_H - -/** @file - * - * Architecture-specific DHCP options - */ - -FILE_LICENCE(GPL2_OR_LATER_OR_UBDL); - -#include <ipxe/dhcp.h> - -// Emulate one of the supported arch-platforms -#include <arch/i386/include/pcbios/ipxe/dhcp_arch.h> -//#include <arch/i386/include/efi/ipxe/dhcp_arch.h> -//#include <arch/x86_64/include/efi/ipxe/dhcp_arch.h> - -#endif diff --git a/src/arch/x86/interface/pcbios/bios_cachedhcp.c b/src/arch/x86/interface/pcbios/bios_cachedhcp.c index 277c40d6f..bea803d6e 100644 --- a/src/arch/x86/interface/pcbios/bios_cachedhcp.c +++ b/src/arch/x86/interface/pcbios/bios_cachedhcp.c @@ -59,7 +59,7 @@ static void cachedhcp_init ( void ) { } /* Record cached DHCPACK */ - if ( ( rc = cachedhcp_record ( &cached_dhcpack, + if ( ( rc = cachedhcp_record ( &cached_dhcpack, 0, phys_to_user ( cached_dhcpack_phys ), sizeof ( BOOTPLAYER_t ) ) ) != 0 ) { DBGC ( colour, "CACHEDHCP could not record DHCPACK: %s\n", diff --git a/src/arch/x86/interface/pcbios/rtc_entropy.c b/src/arch/x86/interface/pcbios/rtc_entropy.c index e0c175685..8f47ff6b8 100644 --- a/src/arch/x86/interface/pcbios/rtc_entropy.c +++ b/src/arch/x86/interface/pcbios/rtc_entropy.c @@ -39,9 +39,14 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/cpuid.h> #include <ipxe/entropy.h> +struct entropy_source rtc_entropy __entropy_source ( ENTROPY_NORMAL ); + /** Maximum time to wait for an RTC interrupt, in milliseconds */ #define RTC_MAX_WAIT_MS 100 +/** Number of RTC interrupts to check for */ +#define RTC_CHECK_COUNT 3 + /** RTC interrupt handler */ extern void rtc_isr ( void ); @@ -145,6 +150,7 @@ static void rtc_disable_int ( void ) { * @ret rc Return status code */ static int rtc_entropy_check ( void ) { + unsigned int count = 0; unsigned int i; /* Check that RTC interrupts are working */ @@ -158,14 +164,18 @@ static int rtc_entropy_check ( void ) { "cli\n\t" ); /* Check for RTC interrupt flag */ - if ( rtc_flag ) - return 0; + if ( rtc_flag ) { + rtc_flag = 0; + if ( ++count >= RTC_CHECK_COUNT ) + return 0; + } /* Delay */ mdelay ( 1 ); } - DBGC ( &rtc_flag, "RTC timed out waiting for interrupt\n" ); + DBGC ( &rtc_flag, "RTC timed out waiting for interrupt %d/%d\n", + ( count + 1 ), RTC_CHECK_COUNT ); return -ETIMEDOUT; } @@ -195,6 +205,21 @@ static int rtc_entropy_enable ( void ) { if ( ( rc = rtc_entropy_check() ) != 0 ) goto err_check; + /* The min-entropy has been measured on several platforms + * using the entropy_sample test code. Modelling the samples + * as independent, and using a confidence level of 99.99%, the + * measurements were as follows: + * + * qemu-kvm : 7.38 bits + * VMware : 7.46 bits + * Physical hardware : 2.67 bits + * + * We choose the lowest of these (2.67 bits) and apply a 50% + * safety margin to allow for some potential non-independence + * of samples. + */ + entropy_init ( &rtc_entropy, MIN_ENTROPY ( 1.3 ) ); + return 0; err_check: @@ -218,11 +243,12 @@ static void rtc_entropy_disable ( void ) { } /** - * Measure a single RTC tick + * Get noise sample * - * @ret delta Length of RTC tick (in TSC units) + * @ret noise Noise sample + * @ret rc Return status code */ -uint8_t rtc_sample ( void ) { +static int rtc_get_noise ( noise_sample_t *noise ) { uint32_t before; uint32_t after; uint32_t temp; @@ -257,10 +283,14 @@ uint8_t rtc_sample ( void ) { : "=a" ( after ), "=d" ( before ), "=Q" ( temp ) : "2" ( 0 ) ); - return ( after - before ); + *noise = ( after - before ); + return 0; } -PROVIDE_ENTROPY_INLINE ( rtc, min_entropy_per_sample ); -PROVIDE_ENTROPY ( rtc, entropy_enable, rtc_entropy_enable ); -PROVIDE_ENTROPY ( rtc, entropy_disable, rtc_entropy_disable ); -PROVIDE_ENTROPY_INLINE ( rtc, get_noise ); +/** RTC entropy source */ +struct entropy_source rtc_entropy __entropy_source ( ENTROPY_NORMAL ) = { + .name = "rtc", + .enable = rtc_entropy_enable, + .disable = rtc_entropy_disable, + .get_noise = rtc_get_noise, +}; 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 <ipxe/uaccess.h> #include <ipxe/process.h> #include <ipxe/netdevice.h> +#include <ipxe/malloc.h> #include <realmode.h> #include <pxe.h> @@ -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, +}; |
