diff options
author | Michael Brown <mcb30@ipxe.org> | 2022-06-10 13:42:01 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2022-06-10 13:44:40 +0100 |
commit | d3c8944d5c3ab262826ed33b16f3fc4dd43bc304 (patch) | |
tree | 9ede1532c9f784a205e3aac120614f8d53ceb67a | |
parent | d72c8fdc902bc5d605fef081a18f6fe84f3d0512 (diff) | |
download | ipxe-d3c8944d5c3ab262826ed33b16f3fc4dd43bc304.tar.gz |
[acpi] Expose system MAC address via ${sysmac} settingsysmac
Expose the system MAC address (if any) via the ${sysmac} setting.
This allows scripts to access the system MAC address even when iPXE
has decided not to apply it to a network device (e.g. because the
cached DHCPACK MAC address was selected in order to match the
behaviour of a previous boot stage).
The setting is named ${sysmac} rather than ${acpimac} in order to
allow for forward compatibility with non-ACPI mechanisms that may
exist in future for specifying a system MAC address.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r-- | src/core/acpimac.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/core/acpimac.c b/src/core/acpimac.c index 5920480dd..e0074ba43 100644 --- a/src/core/acpimac.c +++ b/src/core/acpimac.c @@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/base16.h> #include <ipxe/ethernet.h> #include <ipxe/if_ether.h> +#include <ipxe/settings.h> #include <ipxe/acpimac.h> /** @file @@ -249,3 +250,39 @@ int acpi_mac ( uint8_t *hw_addr ) { return -ENOENT; } + +/** + * Fetch system MAC address setting + * + * @v data Buffer to fill with setting data + * @v len Length of buffer + * @ret len Length of setting data, or negative error + */ +static int sysmac_fetch ( void *data, size_t len ) { + uint8_t mac[ETH_ALEN]; + int rc; + + /* Try fetching ACPI MAC address */ + if ( ( rc = acpi_mac ( mac ) ) != 0 ) + return rc; + + /* Return MAC address */ + if ( len > sizeof ( mac ) ) + len = sizeof ( mac ); + memcpy ( data, mac, len ); + return ( sizeof ( mac ) ); +} + +/** System MAC address setting */ +const struct setting sysmac_setting __setting ( SETTING_MISC, sysmac ) = { + .name = "sysmac", + .description = "System MAC", + .type = &setting_type_hex, + .scope = &builtin_scope, +}; + +/** System MAC address built-in setting */ +struct builtin_setting sysmac_builtin_setting __builtin_setting = { + .setting = &sysmac_setting, + .fetch = sysmac_fetch, +}; |