summaryrefslogtreecommitdiffstats
path: root/src/core/settings.c
diff options
context:
space:
mode:
authorMichael Brown2022-01-04 14:31:15 +0100
committerMichael Brown2022-01-04 15:03:12 +0100
commitf43c2fd69749bb9a44f2a3ab61b6735938432b52 (patch)
treeb5afddef6c6f701312dda21aa4732e9c0253d587 /src/core/settings.c
parent[efi] Disable EFI watchdog timer when shutting down to boot an OS (diff)
downloadipxe-f43c2fd69749bb9a44f2a3ab61b6735938432b52.tar.gz
ipxe-f43c2fd69749bb9a44f2a3ab61b6735938432b52.tar.xz
ipxe-f43c2fd69749bb9a44f2a3ab61b6735938432b52.zip
[settings] Support formatting UUIDs as little-endian GUIDs
The RFC4122 specification defines UUIDs as being in network byte order, but an unfortunately significant amount of (mostly Microsoft) software treats them as having the first three fields in little-endian byte order. In an ideal world, any server-side software that compares UUIDs for equality would perform an endian-insensitive comparison (analogous to comparing strings for equality using a case-insensitive comparison), and would therefore not care about byte order differences. Define a setting type name ":guid" to allow a UUID setting to be formatted in little-endian order, to simplify interoperability with server-side software that expects such a formatting. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/settings.c')
-rw-r--r--src/core/settings.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index 430cdc84..fcdf98d2 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -2199,7 +2199,7 @@ const struct setting_type setting_type_base64 __setting_type = {
};
/**
- * Format UUID setting value
+ * Format UUID/GUID setting value
*
* @v type Setting type
* @v raw Raw setting value
@@ -2208,17 +2208,24 @@ const struct setting_type setting_type_base64 __setting_type = {
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_uuid_setting ( const struct setting_type *type __unused,
+static int format_uuid_setting ( const struct setting_type *type,
const void *raw, size_t raw_len, char *buf,
size_t len ) {
- const union uuid *uuid = raw;
+ union uuid uuid;
/* Range check */
- if ( raw_len != sizeof ( *uuid ) )
+ if ( raw_len != sizeof ( uuid ) )
return -ERANGE;
+ /* Copy value */
+ memcpy ( &uuid, raw, sizeof ( uuid ) );
+
+ /* Mangle GUID byte ordering */
+ if ( type == &setting_type_guid )
+ uuid_mangle ( &uuid );
+
/* Format value */
- return snprintf ( buf, len, "%s", uuid_ntoa ( uuid ) );
+ return snprintf ( buf, len, "%s", uuid_ntoa ( &uuid ) );
}
/** UUID setting type */
@@ -2227,6 +2234,12 @@ const struct setting_type setting_type_uuid __setting_type = {
.format = format_uuid_setting,
};
+/** GUID setting type */
+const struct setting_type setting_type_guid __setting_type = {
+ .name = "guid",
+ .format = format_uuid_setting,
+};
+
/**
* Format PCI bus:dev.fn setting value
*