]> git.ipfire.org Git - thirdparty/ipxe.git/log
thirdparty/ipxe.git
2 years ago[tls] Handle fragmented handshake records 930/head
Michael Brown [Thu, 30 Mar 2023 15:28:40 +0000 (16:28 +0100)] 
[tls] Handle fragmented handshake records

Originally-implemented-by: Christopher Schenk <christopher@cschenk.net>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tls] Pass I/O buffer to received record handlers
Michael Brown [Thu, 30 Mar 2023 15:28:40 +0000 (16:28 +0100)] 
[tls] Pass I/O buffer to received record handlers

Prepare for the possibility that a record handler may choose not to
consume the entire record by passing the I/O buffer and requiring the
handler to mark consumed data using iob_pull().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tls] Clean up change cipher spec record handling
Michael Brown [Thu, 30 Mar 2023 15:57:12 +0000 (16:57 +0100)] 
[tls] Clean up change cipher spec record handling

Define and use data structures and constants for the (single-byte)
change cipher spec records.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Claim fixed device paths by uninstalling device path protocol initrd
Michael Brown [Wed, 15 Mar 2023 16:20:16 +0000 (16:20 +0000)] 
[efi] Claim fixed device paths by uninstalling device path protocol

As documented in commits 6a004be ("[efi] Support the initrd
autodetection mechanism in newer Linux kernels") and 04e60a2 ("[efi]
Omit EFI_LOAD_FILE2_PROTOCOL for a zero-length initrd"), the choice in
Linux of using a fixed device path requires bootloaders to allow for
the fact that a previous bootloader may have already installed a
handle with the fixed device path.

We currently deal with this situation by reusing the existing handle,
replacing the EFI_LOAD_FILE2_PROTOCOL instance with our own.  Simplify
the code by instead uninstalling the EFI_DEVICE_PATH_PROTOCOL instance
from the existing handle (if present), thereby allowing the creation
of a new handle to succeed.

Create the new handle only if we have a non-empty initrd to provide.
This works around bugs in bootloaders such as the systemd EFI stub
that fail to allow for the existence of multiple-bootloader chains.
(The workaround is not comprehensive: if the user has downloaded other
images in iPXE before invoking the systemd Unified Kernel Image (UKI),
then the systemd EFI stub will still crash and burn since it fails to
allow for the fact that a previous bootloader has already installed a
handle with the fixed device path.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[intel] Add workaround for I210 reset hardware bugs 907/head
Matt Parrella [Tue, 14 Mar 2023 14:43:19 +0000 (14:43 +0000)] 
[intel] Add workaround for I210 reset hardware bugs

The Intel I210's packet buffer size registers reset only on power up,
not when a reset signal is asserted.  This can lead to the inability
to pass traffic in the event that the DMA TX Maximum Packet Size
(which does reset to its default value on reset) is bigger than the TX
Packet Buffer Size.

For example, an operating system may be using the time sensitive
networking features of the I210 and the registers may be programmed
correctly, but then a reset signal is asserted and iPXE on the next
boot will be unable to use the I210.

Mimic what Linux does and forcibly set the registers to their default
values.

Signed-off-by: Matt Parrella <parrella.matthew@gmail.com>
2 years ago[dhcp] Unregister ProxyDHCP and PXEBS settings on a successful DHCPACK
Michael Brown [Wed, 8 Mar 2023 00:43:33 +0000 (00:43 +0000)] 
[dhcp] Unregister ProxyDHCP and PXEBS settings on a successful DHCPACK

When a DHCP transaction does not result in the registration of a new
"proxydhcp" or "pxebs" settings block, any existing settings blocks
are currently left unaltered.

This can cause surprising behaviour.  For example: when chainloading
iPXE, the "proxydhcp" and "pxebs" settings blocks may be prepopulated
using cached values from the previous PXE bootloader.  If iPXE
performs a subsequent DHCP request, then the DHCP or ProxyDHCP servers
may choose to respond differently to iPXE.  The response may choose to
omit the ProxyDHCP or PXEBS stages, in which case no new "proxydhcp"
or "pxebs" settings blocks may be registered.  This will result in
iPXE using a combination of both old and new DHCP responses.

Fix by assuming that a successful DHCPACK effectively acquires
ownership of the "proxydhcp" and "pxebs" settings blocks, and that any
existing settings blocks should therefore be unregistered.

Reported-by: Henry Tung <htung@palantir.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Use image name instead of pointer value in debug messages
Michael Brown [Tue, 7 Mar 2023 14:18:00 +0000 (14:18 +0000)] 
[efi] Use image name instead of pointer value in debug messages

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[image] Always unregister currently executing image
Michael Brown [Mon, 6 Mar 2023 16:28:48 +0000 (16:28 +0000)] 
[image] Always unregister currently executing image

We unregister script images during their execution, to prevent a
"boot" command from re-executing the containing script.  This also has
the side effect of preventing executing scripts from showing up within
the Linux magic initrd image (or the Multiboot module list).

Additional logic in bzimage.c and efi_file.c prevents a currently
executing kernel from showing up within the magic initrd image.
Similar logic in multiboot.c prevents the Multiboot kernel from
showing up as a Multiboot module.

This still leaves some corner cases that are not covered correctly.
For example: when using a gzip-compressed kernel image, nothing will
currently hide the original compressed image from the magic initrd.

Fix by moving the logic that temporarily unregisters the current image
from script_exec() to image_exec(), so that it applies to all image
types, and simplify the magic initrd and Multiboot module list
construction logic on the basis that no further filtering of the
registered image list is necessary.

This change has the side effect of hiding currently executing EFI
images from the virtual filesystem exposed by iPXE.  For example, when
using iPXE to boot wimboot, the wimboot binary itself will no longer
be visible within the virtual filesystem.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[image] Consistently use for_each_image() to iterate over images
Michael Brown [Mon, 6 Mar 2023 16:55:54 +0000 (16:55 +0000)] 
[image] Consistently use for_each_image() to iterate over images

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[intelx] Add PCI IDs for Intel 82599 10GBASE-T NIC 911/head
Forest Crossman [Mon, 6 Mar 2023 00:22:18 +0000 (18:22 -0600)] 
[intelx] Add PCI IDs for Intel 82599 10GBASE-T NIC

Signed-off-by: Forest Crossman <cyrozap@gmail.com>
2 years ago[params] Allow for arbitrary HTTP request headers to be specified
Michael Brown [Tue, 28 Feb 2023 17:46:13 +0000 (17:46 +0000)] 
[params] Allow for arbitrary HTTP request headers to be specified

Extend the request parameter mechanism to allow for arbitrary HTTP
headers to be specified via e.g.:

  params
  param --header Referer http://www.example.com
  imgfetch http://192.168.0.1/script.ipxe##params

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[params] Rename "form parameter" to "request parameter"
Michael Brown [Tue, 28 Feb 2023 16:22:19 +0000 (16:22 +0000)] 
[params] Rename "form parameter" to "request parameter"

Prepare for the parameter mechanism to be generalised to specifying
request parameters that are passed via mechanisms other than an
application/x-www-form-urlencoded form.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[http] Use POST method only if the form parameter list is non-empty
Michael Brown [Wed, 1 Mar 2023 11:06:46 +0000 (11:06 +0000)] 
[http] Use POST method only if the form parameter list is non-empty

An attempt to use an existent but empty form parameter list will
currently result in an invalid POST request since the Content-Length
header will be missing.

Fix by using GET instead of POST if the form parameter list is empty.
This is a non-breaking change (since the current behaviour produces an
invalid request), and simplifies the imminent generalisation of the
parameter list concept to handle both header and form parameters.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Omit EFI_LOAD_FILE2_PROTOCOL for a zero-length initrd 905/head
Michael Brown [Tue, 28 Feb 2023 12:04:58 +0000 (12:04 +0000)] 
[efi] Omit EFI_LOAD_FILE2_PROTOCOL for a zero-length initrd

When the Linux kernel is being used with no initrd, iPXE will still
provide a zero-length initrd.magic file within the virtual filesystem.
As of commit 6a004be ("[efi] Support the initrd autodetection
mechanism in newer Linux kernels"), this zero-length file will also be
exposed via an EFI_LOAD_FILE2_PROTOCOL instance on a handle with a
fixed device path.

The correct handling of zero-length files via EFI_LOAD_FILE2_PROTOCOL
is unfortunately not well defined.

Linux expects the first call to LoadFile() to always fail with
EFI_BUFFER_TOO_SMALL.  When the initrd is genuinely zero-length, iPXE
will return success since the buffer is not too small to hold the
(zero-length) file.  This causes Linux to immediately report a
spurious EFI_LOAD_ERROR boot failure.

We could change the logic in iPXE's efi_file_load() to always return
EFI_BUFFER_TOO_SMALL if Buffer is NULL on entry.  Since the correct
behaviour of LoadFile() in the corner case of a zero-length file is
left undefined by the UEFI specification, this would be permissible.

Unfortunately this approach would not fix the problem.  If we return
EFI_BUFFER_TOO_SMALL and set the file length to zero, then Linux will
call the boot services AllocatePages() method with a zero length.  In
at least the EDK2 implementation, this combination of parameters will
cause AllocatePages() to return EFI_OUT_OF_RESOURCES, and Linux will
again report a boot failure.

Another approach would be to install the initrd device path handle
only if we have a non-empty initrd to offer.  Unfortunately this would
lead to a failure in yet another corner case: if a previous bootloader
has installed an initrd device path handle (e.g. to pass a boot script
to iPXE) then we must not leave that initrd in place, since then our
loaded kernel would end up seeing the wrong initrd content.

The cleanest fix seems to be to ensure that the initrd device path
handle is installed with the EFI_DEVICE_PATH_PROTOCOL instance present
but with the EFI_LOAD_FILE2_PROTOCOL instance absent (and forcibly
uninstalled if necessary), matching the state in which we leave the
handle after uninstalling our virtual filesystem.  Linux will then not
find any handle that supports EFI_LOAD_FILE2_PROTOCOL within the fixed
device path, and so will fall through to trying other mechanisms to
locate the initrd.

Reported-by: Chris Bradshaw <cwbshaw@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Split out EFI_RNG_PROTOCOL as a separate entropy source
Michael Brown [Mon, 20 Feb 2023 14:08:49 +0000 (14:08 +0000)] 
[efi] Split out EFI_RNG_PROTOCOL as a separate entropy source

Commit 7ca801d ("[efi] Use the EFI_RNG_PROTOCOL as an entropy source
if available") added EFI_RNG_PROTOCOL as an alternative entropy source
via an ad-hoc mechanism specific to efi_entropy.c.

Split out EFI_RNG_PROTOCOL to a separate entropy source, and allow the
entropy core to handle the selection of RDRAND, EFI_RNG_PROTOCOL, or
timer ticks as the active source.

The fault detection logic added in commit a87537d ("[efi] Detect and
disable seriously broken EFI_RNG_PROTOCOL implementations") may be
removed completely, since the failure will already be detected by the
generic ANS X9.82-mandated repetition count test and will now be
handled gracefully by the entropy core.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[rng] Allow for entropy sources that fail during startup tests
Michael Brown [Mon, 20 Feb 2023 13:55:40 +0000 (13:55 +0000)] 
[rng] Allow for entropy sources that fail during startup tests

Provide per-source state variables for the repetition count test and
adaptive proportion test, to allow for the situation in which an
entropy source can be enabled but then fails during the startup tests,
thereby requiring an alternative entropy source to be used.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tables] Allow any lvalue to be used as a table iterator
Michael Brown [Mon, 20 Feb 2023 13:46:45 +0000 (13:46 +0000)] 
[tables] Allow any lvalue to be used as a table iterator

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[rng] Allow entropy source to be selected at runtime
Michael Brown [Fri, 17 Feb 2023 16:56:11 +0000 (16:56 +0000)] 
[rng] Allow entropy source to be selected at runtime

As noted in commit 3c83843 ("[rng] Check for several functioning RTC
interrupts"), experimentation shows that Hyper-V cannot be trusted to
reliably generate RTC interrupts.  (As noted in commit f3ba0fb
("[hyperv] Provide timer based on the 10MHz time reference count
MSR"), Hyper-V appears to suffer from a general problem in reliably
generating any legacy interrupts.)  An alternative entropy source is
therefore required for an image that may be used in a Hyper-V Gen1
virtual machine.

The x86 RDRAND instruction provides a suitable alternative entropy
source, but may not be supported by all CPUs.  We must therefore allow
for multiple entropy sources to be compiled in, with the single active
entropy source selected only at runtime.

Restructure the internal entropy API to allow a working entropy source
to be detected and chosen at runtime.

Enable the RDRAND entropy source for all x86 builds, since it is
likely to be substantially faster than any other source.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[iscsi] Limit maximum transfer size to MaxBurstLength 898/head
Michael Brown [Thu, 16 Feb 2023 12:54:47 +0000 (12:54 +0000)] 
[iscsi] Limit maximum transfer size to MaxBurstLength

We currently specify only the iSCSI default value for MaxBurstLength
and ignore any negotiated value, since our internal block device API
allows only for receiving directly into caller-allocated buffers and
so we have no intrinsic limit on burst length.

A conscientious target may however refuse to attempt a transfer that
we request for a number of blocks that would exceed the negotiated
maximum burst length.

Fix by recording the negotiated maximum burst length and using it to
limit the maximum number of blocks per transfer as reported by the
SCSI layer.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[rng] Add RDRAND as an entropy source
Michael Brown [Wed, 15 Feb 2023 22:43:33 +0000 (22:43 +0000)] 
[rng] Add RDRAND as an entropy source

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Support the initrd autodetection mechanism in newer Linux kernels 895/head
Michael Brown [Wed, 15 Feb 2023 15:48:31 +0000 (15:48 +0000)] 
[efi] Support the initrd autodetection mechanism in newer Linux kernels

Linux 5.7 added the ability to autodetect an initrd by searching for a
handle via a fixed vendor-specific "Linux initrd device path" and then
locating and using the EFI_LOAD_FILE2_PROTOCOL instance on that
handle.

This maps quite naturally onto our existing concept of a "magic
initrd" as introduced for EFI in commit e5f0255 ("[efi] Provide an
"initrd.magic" file for use by UEFI kernels").

Add an EFI_LOAD_FILE2_PROTOCOL instance to our EFI virtual files
(backed by simply calling the existing EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
method to read from the file), and install the protocol instance for
the "initrd.magic" virtual file onto a new device handle that also
provides the Linux initrd device path.

The design choice in Linux of using a single fixed device path makes
this unfortunately messy to support, since device paths must be unique
within a system.  When multiple bootloaders are used (e.g. GRUB
loading iPXE loading Linux) then only one bootloader can ever install
the device path onto a handle.  Subsequent bootloaders must locate the
existing handle and replace the load file protocol instance with their
own.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Fix debug message when reading from EFI virtual files
Michael Brown [Wed, 15 Feb 2023 17:17:43 +0000 (17:17 +0000)] 
[efi] Fix debug message when reading from EFI virtual files

Show the requested range when a caller reads from a virtual file via
the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL interface.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[image] Check delimiters when parsing command-line key-value arguments 892/head
Michael Brown [Mon, 13 Feb 2023 20:40:42 +0000 (20:40 +0000)] 
[image] Check delimiters when parsing command-line key-value arguments

The Linux kernel bzImage image format and the CPIO archive constructor
will parse the image command line for certain arguments of the form
"key=value".  This parsing is currently implemented using strstr() in
a way that can cause a false positive suffix match.  For example, a
command line containing "highmem=<n>" would erroneously be treated as
containing a value for "mem=<n>".

Fix by centralising the logic used for parsing such arguments, and
including a check that the argument immediately follows a whitespace
delimiter (or is at the start of the string).

Reported-by: Filippo Giunchedi <filippo@esaurito.net>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[rng] Check for several functioning RTC interrupts
Michael Brown [Sat, 11 Feb 2023 15:07:00 +0000 (15:07 +0000)] 
[rng] Check for several functioning RTC interrupts

Commit 74222cd ("[rng] Check for functioning RTC interrupt") added a
check that the RTC is capable of generating interrupts via the legacy
PIC, since this mechanism appears to be broken in some Hyper-V virtual
machines.

Experimentation shows that the RTC is sometimes capable of generating
a single interrupt, but will then generate no subsequent interrupts.
This currently causes rtc_entropy_check() to falsely detect that the
entropy gathering mechanism is functional.

Fix by checking for several RTC interrupts before declaring that it is
a functional entropy source.

Reported-by: Andreas Hammarskjöld <junior@2PintSoftware.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[eisa] Check for system board presence before probing for slots 888/head
Michael Brown [Fri, 10 Feb 2023 23:18:47 +0000 (23:18 +0000)] 
[eisa] Check for system board presence before probing for slots

EISA expansion slot I/O port addresses overlap space that may be
assigned to PCI devices, which can lead to register reads and writes
with unwanted side effects during EISA probing.

Reduce the chances of performing EISA probing on PCI devices by
probing EISA slot vendor and product ID registers only if the EISA
system board vendor ID register indicates that the motherboard
supports EISA.

Debugged-by: Václav Ovsík <vaclav.ovsik@gmail.com>
Tested-by: Václav Ovsík <vaclav.ovsik@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[loong64] Add initial support for LoongArch64
Xiaotian Wu [Mon, 6 Feb 2023 12:48:50 +0000 (12:48 +0000)] 
[loong64] Add initial support for LoongArch64

Add support for building a LoongArch64 Linux userspace binary.

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[test] Include build architecture in test suite banner
Michael Brown [Mon, 6 Feb 2023 21:03:39 +0000 (21:03 +0000)] 
[test] Include build architecture in test suite banner

The test suites for the various architectures are often run back to
back, and there is currently nothing to visually distinguish one test
run from another.

Include the architecture name within the self-test startup banner, to
aid in visual identification of test results.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[ci] Cache downloaded packages for GitHub actions
Michael Brown [Mon, 6 Feb 2023 18:30:06 +0000 (18:30 +0000)] 
[ci] Cache downloaded packages for GitHub actions

Speed up the "Install packages" step for each CI run by caching the
downloaded packages in /var/cache/apt.

Do not include libc6-dbg:i386 within the cache, since apt seems to
complain if asked to download both gcc-aarch64-linux-gnu and
libc6-dbg:i386 at the same time.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[ioapi] Move PAGE_SHIFT to bits/io.h
Michael Brown [Mon, 6 Feb 2023 12:32:50 +0000 (12:32 +0000)] 
[ioapi] Move PAGE_SHIFT to bits/io.h

The PAGE_SHIFT definition is an architectural property, rather than an
aspect of a particular I/O API implementation (of which, in theory,
there may be more than one per architecture).

Reflect this by moving the definition to the top-level bits/io.h for
each architecture.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[build] Allow for per-architecture unprefixed constant operand modifier
Michael Brown [Sun, 5 Feb 2023 23:55:14 +0000 (23:55 +0000)] 
[build] Allow for per-architecture unprefixed constant operand modifier

Over the years, the undocumented operand modifier used to produce the
unprefixed constant values in __einfo_error() has varied from "%c0" to
"%a0" in commit 1a77466 ("[build] Fix use of inline assembly on GCC
4.8 ARM64 builds") and back to "%c0" in commit 3fb3ffc ("[build] Fix
use of inline assembly on GCC 8 ARM64 builds"), according to the
evolving demands of the toolchain.

LoongArch64 suffers from a similar issue: GCC 13 will allow either,
but the currently released GCC 12 allows only the "%a0" form.

Introduce a macro ASM_NO_PREFIX, defined in bits/compiler.h, to
abstract away this difference and allow different architectures to use
different operand modifiers.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[xen] Allow for platforms that have no Xen support
Michael Brown [Sun, 5 Feb 2023 22:02:05 +0000 (22:02 +0000)] 
[xen] Allow for platforms that have no Xen support

The Xen headers support only x86 and ARM.  Allow for platforms such as
LoongArch64 to build despite the absence of Xen support by providing
an architecture-specific <bits/xen.h> that simply does:

  #ifndef _BITS_XEN_H
  #define _BITS_XEN_H
  #include <ipxe/nonxen.h>
  #endif /* _BITS_XEN_H */

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Enable NET_PROTO_LLDP by default
Michael Brown [Sun, 5 Feb 2023 18:53:03 +0000 (18:53 +0000)] 
[efi] Enable NET_PROTO_LLDP by default

Requested-by: Christian I. Nilsson <nikize@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[lldp] Add support for the Link Layer Discovery Protocol 882/head
Michael Brown [Sun, 5 Feb 2023 13:07:30 +0000 (13:07 +0000)] 
[lldp] Add support for the Link Layer Discovery Protocol

Add support for recording LLDP packets and exposing TLV values via the
settings mechanism.  LLDP settings are encoded as

  ${netX.lldp/<prefix>.<type>.<index>.<offset>.<length>}

where

  <type> is the TLV type

  <offset> is the starting offset within the TLV value

  <length> is the length (or zero to read the from <offset> to the end)

  <prefix>, if it has a non-zero value, is the subtype byte string of
  length <offset> to match at the start of the TLV value, up to a
  maximum matched length of 4 bytes

  <index> is the index of the entry matching <type> and <prefix> to be
  accessed, with zero indicating the first matching entry

The <prefix> is designed to accommodate both matching of the OUI
within an organization-specific TLV (e.g. 0x0080c2 for IEEE 802.1
TLVs) and of a subtype byte as found within many TLVs.

This encoding allows most LLDP values to be extracted easily.  For
example

  System name: ${netX.lldp/5.0.0.0:string}

  System description: ${netX.lldp/6.0.0.0:string}

  Port description: ${netX.lldp/4.0.0.0:string}

  Port interface name: ${netX.lldp/5.2.0.1.0:string}

  Chassis MAC address: ${netX.lldp/4.1.0.1.0:hex}

  Management IPv4 address: ${netX.lldp/5.1.8.0.2.4:ipv4}

  Port VLAN ID: ${netX.lldp/0x0080c2.1.127.0.4.2:int16}

  Port VLAN name: ${netX.lldp/0x0080c2.3.127.0.7.0:string}

  Maximum frame size: ${netX.lldp/0x00120f.4.127.0.4.2:uint16}

Originally-implemented-by: Marin Hannache <git@mareo.fr>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[ci] Update to ubuntu-22.04 GitHub actions runner
Michael Brown [Fri, 3 Feb 2023 20:08:16 +0000 (20:08 +0000)] 
[ci] Update to ubuntu-22.04 GitHub actions runner

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[dhcp] Ignore DHCPNAK unless originating from the selected DHCP server 879/head
Michael Brown [Fri, 3 Feb 2023 19:36:57 +0000 (19:36 +0000)] 
[dhcp] Ignore DHCPNAK unless originating from the selected DHCP server

RFC 2131 leaves undefined the behaviour of the client in response to a
DHCPNAK that comes from a server other than the selected DHCP server.

A substantial amount of online documentation suggests using multiple
independent DHCP servers with non-overlapping ranges in the same
subnet in order to provide some minimal redundancy.  Experimentation
shows that in this setup, at least ISC dhcpd will send a DHCPNAK in
response to the client's DHCPREQUEST for an address that is not within
the range defined on that server.  (Since the requested address does
lie within the subnet defined on that server, this will happen
regardless of the "authoritative" parameter.)  The client will
therefore receive a DHCPACK from the selected DHCP server along with
one or more DHCPNAKs from each of the non-selected DHCP servers.

Filter out responses from non-selected DHCP servers before checking
for a DHCPNAK, so that these arguably spurious DHCPNAKs will not cause
iPXE to return to the discovery state.

Continue to check for DHCPNAK before filtering out responses for
non-selected lease addresses, since experimentation shows that the
DHCPNAK will usually have an empty yiaddr field.

Reported-by: Anders Blomdell <anders.blomdell@control.lth.se>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Do not attempt to drive PCI bridge devices 878/head
Michael Brown [Fri, 3 Feb 2023 16:10:31 +0000 (16:10 +0000)] 
[efi] Do not attempt to drive PCI bridge devices

The "bridge" driver introduced in 3aa6b79 ("[pci] Add minimal PCI
bridge driver") is required only for BIOS builds using the ENA driver,
where experimentation shows that we cannot rely on the BIOS to fully
assign MMIO addresses.

Since the driver is a valid PCI driver, it will end up binding to all
PCI bridge devices even on a UEFI platform, where the firmware is
likely to have completed MMIO address assignment correctly.  This has
no impact on most systems since there is generally no UEFI driver for
PCI bridges: the enumeration of the whole PCI bus is handled by the
PciBusDxe driver bound to the root bridge.

Experimentation shows that at least one laptop will freeze at the
point that iPXE attempts to bind to the bridge device.  No deeper
investigation has been carried out to find the root cause.

Fix by causing efipci_supported() to return an error unless the
configuration space header type indicates a non-bridge device.

Reported-by: Marcel Petersen <mp@sbe.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[util] Add support for LoongArch64 binaries
Xiaotian Wu [Fri, 3 Feb 2023 12:44:11 +0000 (12:44 +0000)] 
[util] Add support for LoongArch64 binaries

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[ci] Update to actions/checkout@v3 to silence GitHub warnings
Michael Brown [Fri, 3 Feb 2023 00:50:16 +0000 (00:50 +0000)] 
[ci] Update to actions/checkout@v3 to silence GitHub warnings

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[xen] Update to current Xen headers
Michael Brown [Thu, 2 Feb 2023 11:19:44 +0000 (11:19 +0000)] 
[xen] Update to current Xen headers

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Allow autoexec script to be located alongside iPXE binary
Michael Brown [Wed, 1 Feb 2023 23:54:19 +0000 (23:54 +0000)] 
[efi] Allow autoexec script to be located alongside iPXE binary

Try loading the autoexec.ipxe script first from the directory
containing the iPXE binary (based on the relative file path provided
to us via EFI_LOADED_IMAGE_PROTOCOL), then fall back to trying the
root directory.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[realtek] Explicitly disable VLAN offload 874/head
Michael Brown [Wed, 1 Feb 2023 18:19:32 +0000 (18:19 +0000)] 
[realtek] Explicitly disable VLAN offload

Some cards seem to have the receive VLAN tag stripping feature enabled
by default, which causes received VLAN packets to be misinterpreted as
being received by the trunk device.

Fix by disabling VLAN tag stripping in the C+ Command Register.

Debugged-by: Xinming Lai <yiyihu@gmail.com>
Tested-by: Xinming Lai <yiyihu@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Update to current EDK2 headers
Michael Brown [Wed, 1 Feb 2023 10:49:02 +0000 (10:49 +0000)] 
[efi] Update to current EDK2 headers

Update to pick up the upstream commit bda715b ("MdePkg: Fix UINT64 and
INT64 word length for LoongArch64").

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tests] Verify ability to sleep the CPU
Michael Brown [Tue, 31 Jan 2023 10:17:57 +0000 (10:17 +0000)] 
[tests] Verify ability to sleep the CPU

The self-test suite does not currently ever attempt to sleep the CPU.
This is an operation that may fail (e.g. by attempting to execute a
privileged instruction while running as a Linux userspace binary, or
by halting the CPU with all interrupts disabled).

Add a trivial self-test to exercise the ability to sleep the CPU
without crashing or halting forever.

Inspired-by: Xiaotian Wu <wuxiaotian@loongson.cn>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[dhcp] Add IANA-defined values for all current EFI client architectures
Michael Brown [Tue, 31 Jan 2023 01:56:56 +0000 (01:56 +0000)] 
[dhcp] Add IANA-defined values for all current EFI client architectures

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Accept a command line passed to an iPXE image via LoadOptions 871/head
Michael Brown [Sun, 29 Jan 2023 18:48:08 +0000 (18:48 +0000)] 
[efi] Accept a command line passed to an iPXE image via LoadOptions

Treat a command line passed to iPXE via UEFI LoadOptions as an image
to be registered at startup, as is already done for the .lkrn, .pxe,
and .exe BIOS images.

Originally-implemented-by: Ladi Prosek <lprosek@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[la64] Import LoongArch64 ProcessorBind.h from EDK2 headers
Michael Brown [Sat, 28 Jan 2023 19:09:46 +0000 (19:09 +0000)] 
[la64] Import LoongArch64 ProcessorBind.h from EDK2 headers

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Update to current EDK2 headers
Michael Brown [Sat, 28 Jan 2023 15:32:26 +0000 (15:32 +0000)] 
[efi] Update to current EDK2 headers

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Mark ConsoleControl.h as a non-imported header
Michael Brown [Sat, 28 Jan 2023 15:22:22 +0000 (15:22 +0000)] 
[efi] Mark ConsoleControl.h as a non-imported header

The obsolete ConsoleControl.h header is no longer present in the
current EDK2 codebase, but is still required for interoperability with
old iMacs.

Add an iPXE include guard to this file so that the EDK2 header import
script will no longer attempt to import it from the EDK2 tree.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Remove deleted directories from EDK2 header import script
Michael Brown [Sat, 28 Jan 2023 15:24:54 +0000 (15:24 +0000)] 
[efi] Remove deleted directories from EDK2 header import script

The IntelFrameworkPkg and EdkCompatibilityPkg directories have been
removed from the EDK2 codebase.  Remove these directories from the
EDK2 header import script.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Allow for whitespace before #include in imported EDK2 header files
Michael Brown [Sat, 28 Jan 2023 15:36:23 +0000 (15:36 +0000)] 
[efi] Allow for whitespace before #include in imported EDK2 header files

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Detect SPDX licence identifiers in imported EDK2 headers
Michael Brown [Sat, 28 Jan 2023 15:31:28 +0000 (15:31 +0000)] 
[efi] Detect SPDX licence identifiers in imported EDK2 headers

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[legal] Add missing FILE_LICENCE declaration to efi_path.c
Michael Brown [Sat, 28 Jan 2023 17:15:16 +0000 (17:15 +0000)] 
[legal] Add missing FILE_LICENCE declaration to efi_path.c

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[legal] Add support for the BSD-2-Clause-Patent licence
Michael Brown [Sat, 28 Jan 2023 15:30:11 +0000 (15:30 +0000)] 
[legal] Add support for the BSD-2-Clause-Patent licence

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Build util/efirom as a host-only binary
Michael Brown [Sat, 28 Jan 2023 16:24:05 +0000 (16:24 +0000)] 
[efi] Build util/efirom as a host-only binary

As with util/elf2efi32 and util/elf2efi64 in commit a99e435 ("[efi] Do
not rely on ProcessorBind.h when building host binaries"), build
util/efirom without using any architecture-specific EDK2 headers since
the build host's CPU architecture may not be supported by EDK2.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tcp] Update maximum window size to 2MB
Michael Brown [Wed, 25 Jan 2023 00:02:11 +0000 (00:02 +0000)] 
[tcp] Update maximum window size to 2MB

The current maximum window size of 256kB was calculated based on rough
link bandwidth and RTT measurements taken in 2012, and is too small to
avoid filling the TCP window on some modern links.

Update the list of typical link bandwidth and RTT figures to reflect
the modern world, and increase the maximum window size accordingly.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[pxe] Discard queued PXE UDP packets when under memory pressure 859/head
Michael Brown [Mon, 23 Jan 2023 22:20:36 +0000 (22:20 +0000)] 
[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 <shorer@amazon.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[golan] Add new PCI ID for NVIDIA BlueField-3 network device
Mohammed Taha [Mon, 23 Jan 2023 22:52:30 +0000 (22:52 +0000)] 
[golan] Add new PCI ID for NVIDIA BlueField-3 network device

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[pxe] Avoid drawing menu items on bottom row of screen 858/head
Michael Brown [Mon, 23 Jan 2023 14:35:57 +0000 (14:35 +0000)] 
[pxe] Avoid drawing menu items on bottom row of screen

Many consoles will scroll immediately upon drawing a character in the
rightmost column of the bottom row of the display, in order to be able
to advance the cursor to the next character (even if the cursor is
disabled).

This causes PXE menus to display incorrectly.  Specifically, pressing
the down arrow key while already on the last menu item may cause the
whole screen to scroll and the line to be duplicated.

Fix by moving the PXE menu one row up from the bottom of the screen.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Bind to only the topmost instance of the SNP or NII protocols
Michael Brown [Mon, 23 Jan 2023 19:18:21 +0000 (19:18 +0000)] 
[efi] Bind to only the topmost instance of the SNP or NII protocols

UEFI has the mildly annoying habit of installing copies of the
EFI_SIMPLE_NETWORK_PROTOCOL instance on the IPv4 and IPv6 child device
handles.  This can cause iPXE's SNP driver to attempt to bind to a
copy of the EFI_SIMPLE_NETWORK_PROTOCOL that iPXE itself provided on a
different handle.

Fix by refusing to bind to an SNP (or NII) handle if there exists
another instance of the same protocol further up the device path (on
the basis that we always want to bind to the highest possible device).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Extend efi_locate_device() to allow searching up the device path
Michael Brown [Mon, 23 Jan 2023 19:15:45 +0000 (19:15 +0000)] 
[efi] Extend efi_locate_device() to allow searching up the device path

Extend the functionality of efi_locate_device() to allow callers to
find instances of the protocol that may exist further up the device
path.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Add efi_path_prev() utility function
Michael Brown [Mon, 23 Jan 2023 19:12:49 +0000 (19:12 +0000)] 
[efi] Add efi_path_prev() utility function

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Add efi_path_terminate() utility function
Michael Brown [Mon, 23 Jan 2023 19:07:35 +0000 (19:07 +0000)] 
[efi] Add efi_path_terminate() utility function

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[arm] Inhibit linker warnings about an implied executable stack
Michael Brown [Mon, 23 Jan 2023 12:30:41 +0000 (12:30 +0000)] 
[arm] Inhibit linker warnings about an implied executable stack

Some versions of the 32-bit ARM linker seem to treat the absence of a
.note.GNU-stack section as implying an executable stack, and will
print a warning that this is deprecated behaviour.

Silence the warning by adding a .note.GNU-stack section to each
assembly file and retaining the sections in the Linux linker script.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[arm] Use -mfloat-abi=soft only for EFI builds
Michael Brown [Mon, 23 Jan 2023 01:32:14 +0000 (01:32 +0000)] 
[arm] Use -mfloat-abi=soft only for EFI builds

The EFI ABI requires the use of -mfloat-abi=soft, but other platforms
may require -mfloat-abi=hard.

Allow for this by using -mfloat-abi=soft only for EFI builds.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[arm] Use -fno-short-enums for all 32-bit ARM builds
Michael Brown [Mon, 23 Jan 2023 01:26:46 +0000 (01:26 +0000)] 
[arm] Use -fno-short-enums for all 32-bit ARM builds

The EFI ABI requires the use of -fno-short-enums, and the EDK2 headers
will perform a compile-time check that enums are 32 bits.

The EDK2 headers may be included even in builds for non-EFI platforms,
and so the -fno-short-enums flag must be used in all 32-bit ARM
builds.  Fortunately, nothing else currently cares about enum sizes.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[arm] Support building as a Linux userspace binary for AArch64
Michael Brown [Sun, 22 Jan 2023 20:31:30 +0000 (20:31 +0000)] 
[arm] Support building as a Linux userspace binary for AArch64

Add support for building as a Linux userspace binary for AArch64.
This allows the self-test suite to be more easily run for the 64-bit
ARM code.  For example:

  # On a native AArch64 system:
  #
  make bin-arm64-efi/tests.linux && ./bin-arm64-efi/tests.linux

  # On a non-AArch64 system (e.g. x86_64) via cross-compilation,
  # assuming that kernel and glibc headers are present within
  # /usr/aarch64-linux-gnu/sys-root/:
  #
  make bin-arm64-linux/tests.linux CROSS=aarch64-linux-gnu- && \
  qemu-aarch64 -L /usr/aarch64-linux-gnu/sys-root/ \
               ./bin-arm64-linux/tests.linux

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[dhcp] Simplify platform-specific client architecture definitions
Michael Brown [Sun, 22 Jan 2023 16:54:20 +0000 (16:54 +0000)] 
[dhcp] Simplify platform-specific client architecture definitions

Move the platform-specific DHCP client architecture definitions to
header files of the form <ipxe/$(PLATFORM)/dhcparch.h>.  This
simplifies the directory structure and allows the otherwise unused
arch/$(ARCH)/include/$(PLATFORM) to be removed from the include
directory search path, which avoids the confusing situation in which a
header file may potentially be accessed through more than one path.

For Linux userspace binaries on any architecture, use the EFI values
for that architecture by delegating to the EFI header file.  This
avoids the need to explicitly select values for Linux userspace
binaries for each architecture.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[build] Move -Ulinux to common Makefile
Michael Brown [Sun, 22 Jan 2023 16:15:55 +0000 (16:15 +0000)] 
[build] Move -Ulinux to common Makefile

The requirement to undo the implicit "-Dlinux" is not specific to the
x86 architecture.  Move this out of the x86-specific Makefile.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[linux] Centralise the linker script for Linux binaries
Michael Brown [Sun, 22 Jan 2023 12:05:14 +0000 (12:05 +0000)] 
[linux] Centralise the linker script for Linux binaries

Reduce duplication between i386 and x86_64 by providing a single
shared linker script that both architectures can include.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Do not rely on ProcessorBind.h when building host binaries 857/head
Michael Brown [Fri, 20 Jan 2023 00:13:04 +0000 (00:13 +0000)] 
[efi] Do not rely on ProcessorBind.h when building host binaries

We cannot rely on the EDK2 ProcessorBind.h headers when compiling a
binary for execution on the build host itself (e.g. elf2efi), since
the host's CPU architecture may not even be supported by EDK2.

Fix by skipping ProcessorBind.h when building a host binary, and
defining the bare minimum required to allow other EDK2 headers to
compile cleanly.

Reported-by: Michal Suchánek <msuchanek@suse.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[ena] Allocate an unused Asynchronous Event Notification Queue (AENQ) 852/head
Alexander Graf [Mon, 16 Jan 2023 21:56:53 +0000 (21:56 +0000)] 
[ena] Allocate an unused Asynchronous Event Notification Queue (AENQ)

We currently don't allocate an Asynchronous Event Notification Queue
(AENQ) because we don't actually care about any of the events that may
come in.

The ENA firmware found on Graviton instances requires the AENQ to
exist, otherwise all admin queue commands will fail.

Fix by allocating an AENQ and disabling all events (so that we do not
need to include code to acknowledge any events that may arrive).

Signed-off-by: Alexander Graf <graf@amazon.com>
2 years ago[netdevice] Ensure consistent interpretation of "netX" device name
Michael Brown [Tue, 17 Jan 2023 12:42:46 +0000 (12:42 +0000)] 
[netdevice] Ensure consistent interpretation of "netX" device name

Ensure that the "${netX/...}" settings mechanism always uses the same
interpretation of the network device corresponding to "netX" as any
other mechanism that performs a name-based lookup of a network device.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Create VLAN autoboot device automatically
Michael Brown [Sun, 15 Jan 2023 22:42:30 +0000 (22:42 +0000)] 
[efi] Create VLAN autoboot device automatically

When chainloading iPXE from an EFI VLAN device, configure the
corresponding iPXE VLAN device to be created automatically.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[vlan] Support automatic VLAN device creation
Michael Brown [Sun, 15 Jan 2023 22:35:44 +0000 (22:35 +0000)] 
[vlan] Support automatic VLAN device creation

Add the ability to automatically create a VLAN device for a specified
trunk device link-layer address and VLAN tag.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[autoboot] Include VLAN tag in filter for identifying autoboot device
Michael Brown [Sun, 15 Jan 2023 21:36:08 +0000 (21:36 +0000)] 
[autoboot] Include VLAN tag in filter for identifying autoboot device

When chainloading iPXE from a VLAN device, the MAC address of the
loaded image's device handle will match the MAC address of the trunk
device created by iPXE, and the autoboot process will then erroneously
consider the trunk device to be an autoboot device.

Fix by recording the VLAN tag along with the MAC address, and treating
the VLAN tag as part of the filter used to match the MAC address
against candidate network devices.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[netdevice] Allow duplicate MAC addresses
Michael Brown [Sat, 14 Jan 2023 00:31:54 +0000 (00:31 +0000)] 
[netdevice] Allow duplicate MAC addresses

Many laptops now include the ability to specify a "system-specific MAC
address" (also known as "pass-through MAC"), which is supposed to be
used for both the onboard NIC and for any attached docking station or
other USB NIC.  This is intended to simplify interoperability with
software or hardware that relies on a MAC address to recognise an
individual machine: for example, a deployment server may associate the
MAC address with a particular operating system image to be deployed.
This therefore creates legitimate situations in which duplicate MAC
addresses may exist within the same system.

As described in commit 98d09a1 ("[netdevice] Avoid registering
duplicate network devices"), the Xen netfront driver relies on the
rejection of duplicate MAC addresses in order to inhibit registration
of the emulated PCI devices that a Xen PV-HVM guest will create to
shadow each of the paravirtual network devices.

Move the code that rejects duplicate MAC addresses from the network
device core to the Xen netfront driver, to allow for the existence of
duplicate MAC addresses in non-Xen setups.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[netdevice] Separate concept of scope ID from network device name index
Michael Brown [Sat, 14 Jan 2023 00:09:20 +0000 (00:09 +0000)] 
[netdevice] Separate concept of scope ID from network device name index

The network device index currently serves two purposes: acting as a
sequential index for network device names ("net0", "net1", etc), and
acting as an opaque unique integer identifier used in socket address
scope IDs.

There is no particular need for these usages to be linked, and it can
lead to situations in which devices are named unexpectedly.  For
example: if a system has two network devices "net0" and "net1", a VLAN
is created as "net1-42", and then a USB NIC is connected, then the USB
NIC will be named "net3" rather than the expected "net2" since the
VLAN device "net1-42" will have consumed an index.

Separate the usages: rename the "index" field to "scope_id" (matching
its one and only use case), and assign the name without reference to
the scope ID by finding the first unused name.  For consistency,
assign the scope ID by similarly finding the first unused scope ID.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Disable receive filters to work around buggy UNDI drivers
Michael Brown [Wed, 11 Jan 2023 00:18:18 +0000 (00:18 +0000)] 
[efi] Disable receive filters to work around buggy UNDI drivers

Some UNDI drivers (such as the AMI UsbNetworkPkg currently in the
process of being upstreamed into EDK2) have a bug that will prevent
any packets from being received unless at least one attempt has been
made to disable some receive filters.

Work around these buggy drivers by attempting to disable receive
filters before enabling them.  Ignore any errors, since we genuinely
do not care whether or not the disabling succeeds.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[cachedhcp] Retain cached DHCPACK after startup if not already consumed 844/head
Michael Brown [Thu, 22 Dec 2022 15:12:34 +0000 (15:12 +0000)] 
[cachedhcp] Retain cached DHCPACK after startup if not already consumed

We currently free an unclaimed cached DHCPACK immediately after
startup, in order to free up memory.  This prevents the cached DHCPACK
from being applied to a device that is created after startup, such as
a VLAN device created via the "vcreate" command.

Retain any unclaimed DHCPACK after startup to allow it to be matched
against (and applied to) any device that gets created at runtime.
Free the DHCPACK during shutdown if it still remains unclaimed, in
order to exit with memory cleanly freed.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[cachedhcp] Include VLAN tag in filter for applying cached DHCPACK
Michael Brown [Thu, 22 Dec 2022 14:59:29 +0000 (14:59 +0000)] 
[cachedhcp] Include VLAN tag in filter for applying cached DHCPACK

When chainloading iPXE from a VLAN device, the MAC address within the
cached DHCPACK will match the MAC address of the trunk device created
by iPXE, and the cached DHCPACK will then end up being erroneously
applied to the trunk device.  This tends to break outbound IPv4
routing, since both the trunk and VLAN devices will have the same
assigned IPv4 address.

Fix by recording the VLAN tag along with the cached DHCPACK, and
treating the VLAN tag as part of the filter used to match the cached
DHCPACK against candidate network devices.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Add efi_path_vlan() utility function
Michael Brown [Thu, 22 Dec 2022 14:27:56 +0000 (14:27 +0000)] 
[efi] Add efi_path_vlan() utility function

EFI provides no API for determining the VLAN tag (if any) for a
specified device handle.  There is the EFI_VLAN_CONFIG_PROTOCOL, but
that exists only on the trunk device handle (not on the VLAN device
handle), and provides no way to match VLAN tags against the trunk
device's child device handles.

The EDK2 codebase seems to rely solely on the device path to determine
the VLAN tag for a specified device handle: both NetLibGetVlanId() and
BmGetNetworkDescription() will parse the device path to search for a
VLAN_DEVICE_PATH component.

Add efi_path_vlan() which uses the same device path parsing logic to
determine the VLAN tag.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Expose efi_path_next() utility function
Michael Brown [Thu, 22 Dec 2022 13:33:38 +0000 (13:33 +0000)] 
[efi] Expose efi_path_next() utility function

Provide a single central implementation of the logic for stepping
through elements of an EFI device path.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Allow passing a NULL device path to path utility functions
Michael Brown [Thu, 22 Dec 2022 13:28:06 +0000 (13:28 +0000)] 
[efi] Allow passing a NULL device path to path utility functions

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[efi] Provide VLAN configuration protocol 838/head
Michael Brown [Tue, 13 Dec 2022 14:45:44 +0000 (14:45 +0000)] 
[efi] Provide VLAN configuration protocol

UEFI implements VLAN support within the Managed Network Protocol (MNP)
driver, which may create child VLAN devices automatically based on
stored UEFI variables.  These child devices do not themselves provide
a raw-packet interface via EFI_SIMPLE_NETWORK_PROTOCOL, and may be
consumed only via the EFI_MANAGED_NETWORK_PROTOCOL interface.

The device paths constructed for these child devices may conflict with
those for the EFI_SIMPLE_NETWORK_PROTOCOL instances that iPXE attempts
to install for its own VLAN devices.  The upshot is that creating an
iPXE VLAN device (e.g. via the "vcreate" command) will fail if the
UEFI Managed Network Protocol has already created a device for the
same VLAN tag.

Fix by providing our own EFI_VLAN_CONFIG_PROTOCOL instance on the same
device handle as EFI_SIMPLE_NETWORK_PROTOCOL.  This causes the MNP
driver to treat iPXE's device as supporting hardware VLAN offload, and
it will therefore not attempt to install its own instance of the
protocol.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[vlan] Allow external code to identify VLAN priority as well as tag
Michael Brown [Fri, 9 Dec 2022 14:40:54 +0000 (14:40 +0000)] 
[vlan] Allow external code to identify VLAN priority as well as tag

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[build] Disable dangling pointer checking for GCC
Michael Brown [Wed, 14 Dec 2022 01:26:03 +0000 (01:26 +0000)] 
[build] Disable dangling pointer checking for GCC

The dangling pointer warning introduced in GCC 12 reports false
positives that result in build failures.  In particular, storing the
address of a local code label used to record the current state of a
state machine (as done in crypto/deflate.c) is reported as an error.

There seems to be no way to mark the pointer type as being permitted
to hold such a value, so unconditionally disable the warning.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[build] Disable array bounds checking for GCC
Michael Brown [Wed, 14 Dec 2022 00:51:00 +0000 (00:51 +0000)] 
[build] Disable array bounds checking for GCC

The array bounds checker on GCC 12 and newer reports a very large
number of false positives that result in build failures.  In
particular, accesses through pointers to zero-length arrays (such as
those used by the linker table mechanism in include/ipxe/tables.h) are
reported as errors, contrary to the GCC documentation.

Work around this GCC issue by unconditionally disabling the warning.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[intel] Add PCI ID for I219-V and -LM 16,17
Christian I. Nilsson [Tue, 15 Nov 2022 13:05:28 +0000 (13:05 +0000)] 
[intel] Add PCI ID for I219-V and -LM 16,17

Signed-off-by: Christian I. Nilsson <nikize@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[pci] Backup and restore standard config space across PCIe FLR 801/head
Michael Brown [Sun, 13 Nov 2022 20:45:38 +0000 (20:45 +0000)] 
[pci] Backup and restore standard config space across PCIe FLR

The behaviour of PCI devices across a function-level reset seems to be
inconsistent in practice: some devices will preserve PCI BARs, some
will not.

Fix the behaviour of FLR on devices that do not preserve PCI BARs by
backing up and restoring PCI configuration space across the reset.
Preserve only the standard portion of the configuration space, since
there may be registers with unexpected side effects in the remaining
non-standardised space.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[pci] Allow PCI config space backup to be limited by maximum offset
Michael Brown [Sun, 13 Nov 2022 20:42:09 +0000 (20:42 +0000)] 
[pci] Allow PCI config space backup to be limited by maximum offset

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tls] Add GCM cipher suites
Michael Brown [Mon, 7 Nov 2022 18:09:09 +0000 (18:09 +0000)] 
[tls] Add GCM cipher suites

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tests] Verify ability to perform in-place encryption and decryption
Michael Brown [Wed, 9 Nov 2022 16:50:01 +0000 (16:50 +0000)] 
[tests] Verify ability to perform in-place encryption and decryption

TLS relies upon the ability of ciphers to perform in-place decryption,
in order to avoid allocating additional I/O buffers for received data.

Add verification of in-place encryption and decryption to the cipher
self-tests.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[crypto] Support in-place decryption for GCM ciphers
Michael Brown [Wed, 9 Nov 2022 16:48:04 +0000 (16:48 +0000)] 
[crypto] Support in-place decryption for GCM ciphers

The hash calculation is currently performed incorrectly when
decrypting in place, since the ciphertext will have been overwritten
with the plaintext before being used to update the hash value.

Restructure the code to allow for in-place encryption and decryption.
Choose to optimise for the decryption case, since we are likely to
decrypt much more data than we encrypt.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tests] Verify ability to reset cipher initialisation vector
Michael Brown [Wed, 9 Nov 2022 16:14:42 +0000 (16:14 +0000)] 
[tests] Verify ability to reset cipher initialisation vector

TLS relies upon the ability to reuse a cipher by resetting only the
initialisation vector while reusing the existing key.

Add verification of resetting the initialisation vector to the cipher
self-tests.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[crypto] Ensure relevant GCM cipher state is cleared by cipher_setiv()
Michael Brown [Wed, 9 Nov 2022 16:45:54 +0000 (16:45 +0000)] 
[crypto] Ensure relevant GCM cipher state is cleared by cipher_setiv()

Reset the accumulated authentication state when cipher_setiv() is
called, to allow the cipher to be reused without resetting the key.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tls] Allow handshake digest algorithm to be specified by cipher suite
Michael Brown [Wed, 9 Nov 2022 14:04:43 +0000 (14:04 +0000)] 
[tls] Allow handshake digest algorithm to be specified by cipher suite

All existing cipher suites use SHA-256 as the TLSv1.2 and above
handshake digest algorithm (even when using SHA-1 as the MAC digest
algorithm).  Some GCM cipher suites use SHA-384 as the handshake
digest algorithm.

Allow the cipher suite to specify the handshake (and PRF) digest
algorithm to be used for TLSv1.2 and above.

This requires some restructuring to allow for the fact that the
ClientHello message must be included within the handshake digest, even
though the relevant digest algorithm is not yet known at the point
that the ClientHello is sent.  Fortunately, the ClientHello may be
reproduced verbatim at the point of receiving the ServerHello, so we
rely on reconstructing (rather than storing) this message.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tls] Always send maximum supported version in ClientHello
Michael Brown [Wed, 9 Nov 2022 14:01:15 +0000 (14:01 +0000)] 
[tls] Always send maximum supported version in ClientHello

Always send the maximum supported version in our ClientHello message,
even when performing renegotiation (in which case the current version
may already be lower than the maximum supported version).

This is permitted by the specification, and allows the ClientHello to
be reconstructed verbatim at the point of selecting the handshake
digest algorithm in tls_new_server_hello().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tls] Add support for AEAD ciphers
Michael Brown [Tue, 8 Nov 2022 14:29:08 +0000 (14:29 +0000)] 
[tls] Add support for AEAD ciphers

Allow for AEAD cipher suites where the MAC length may be zero and the
authentication is instead provided by an authenticating cipher, with
the plaintext authentication tag appended to the ciphertext.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tls] Treat invalid block padding as zero length padding
Michael Brown [Tue, 8 Nov 2022 15:10:25 +0000 (15:10 +0000)] 
[tls] Treat invalid block padding as zero length padding

Harden against padding oracle attacks by treating invalid block
padding as zero length padding, thereby deferring the failure until
after computing the (incorrect) MAC.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2 years ago[tls] Allow for arbitrary-length initialisation vectors
Michael Brown [Mon, 7 Nov 2022 23:42:02 +0000 (23:42 +0000)] 
[tls] Allow for arbitrary-length initialisation vectors

Restructure the encryption and decryption operations to allow for the
use of ciphers where the initialisation vector is constructed by
concatenating the fixed IV (derived as part of key expansion) with a
record IV (prepended to the ciphertext).

Signed-off-by: Michael Brown <mcb30@ipxe.org>