]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[acpi] Expose system MAC address via ${sysmac} setting 136/head
authorMichael Brown <mcb30@ipxe.org>
Fri, 10 Jun 2022 12:42:01 +0000 (13:42 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 10 Jun 2022 12:44:40 +0000 (13:44 +0100)
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>
src/core/acpimac.c

index 5920480ddc569acb2903cb84f866984e16e783a6..e0074ba43d8be86b0348be5b88357b3ff32148a0 100644 (file)
@@ -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,
+};