Переглянути джерело

[uuid] Abstract UUID mangling code out to a separate uuid_mangle() function

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 роки тому
джерело
коміт
d938e50136

+ 19
- 0
src/include/ipxe/uuid.h Переглянути файл

9
 FILE_LICENCE ( GPL2_OR_LATER );
9
 FILE_LICENCE ( GPL2_OR_LATER );
10
 
10
 
11
 #include <stdint.h>
11
 #include <stdint.h>
12
+#include <byteswap.h>
12
 
13
 
13
 /** A universally unique ID */
14
 /** A universally unique ID */
14
 union uuid {
15
 union uuid {
28
 	uint8_t raw[16];
29
 	uint8_t raw[16];
29
 };
30
 };
30
 
31
 
32
+/**
33
+ * Change UUID endianness
34
+ *
35
+ * @v uuid		UUID
36
+ *
37
+ * RFC4122 defines UUIDs as being encoded in network byte order, but
38
+ * leaves some wriggle room for "explicit application or presentation
39
+ * protocol specification to the contrary".  PXE, EFI and SMBIOS
40
+ * (versions 2.6 and above) treat the first three fields as being
41
+ * little-endian.
42
+ */
43
+static inline void uuid_mangle ( union uuid *uuid ) {
44
+
45
+	__bswap_32s ( &uuid->canonical.a );
46
+	__bswap_16s ( &uuid->canonical.b );
47
+	__bswap_16s ( &uuid->canonical.c );
48
+}
49
+
31
 extern char * uuid_ntoa ( const union uuid *uuid );
50
 extern char * uuid_ntoa ( const union uuid *uuid );
32
 
51
 
33
 #endif /* _IPXE_UUID_H */
52
 #endif /* _IPXE_UUID_H */

+ 1
- 4
src/interface/smbios/smbios_settings.c Переглянути файл

22
 #include <stdint.h>
22
 #include <stdint.h>
23
 #include <string.h>
23
 #include <string.h>
24
 #include <errno.h>
24
 #include <errno.h>
25
-#include <byteswap.h>
26
 #include <ipxe/settings.h>
25
 #include <ipxe/settings.h>
27
 #include <ipxe/init.h>
26
 #include <ipxe/init.h>
28
 #include <ipxe/uuid.h>
27
 #include <ipxe/uuid.h>
148
 		     ( smbios_version() >= SMBIOS_VERSION ( 2, 6 ) ) ) {
147
 		     ( smbios_version() >= SMBIOS_VERSION ( 2, 6 ) ) ) {
149
 			DBG ( "SMBIOS detected mangled UUID\n" );
148
 			DBG ( "SMBIOS detected mangled UUID\n" );
150
 			memcpy ( &uuid, &buf[tag_offset], sizeof ( uuid ) );
149
 			memcpy ( &uuid, &buf[tag_offset], sizeof ( uuid ) );
151
-			__bswap_32s ( &uuid.canonical.a );
152
-			__bswap_16s ( &uuid.canonical.b );
153
-			__bswap_16s ( &uuid.canonical.c );
150
+			uuid_mangle ( &uuid );
154
 			raw = &uuid;
151
 			raw = &uuid;
155
 		}
152
 		}
156
 
153
 

+ 1
- 3
src/net/udp/dhcp.c Переглянути файл

1049
 	client_uuid.type = DHCP_CLIENT_UUID_TYPE;
1049
 	client_uuid.type = DHCP_CLIENT_UUID_TYPE;
1050
 	if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
1050
 	if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
1051
 					  &client_uuid.uuid ) ) >= 0 ) {
1051
 					  &client_uuid.uuid ) ) >= 0 ) {
1052
-		__bswap_32s ( &client_uuid.uuid.canonical.a );
1053
-		__bswap_16s ( &client_uuid.uuid.canonical.b );
1054
-		__bswap_16s ( &client_uuid.uuid.canonical.c );
1052
+		uuid_mangle ( &client_uuid.uuid );
1055
 		if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_UUID,
1053
 		if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_UUID,
1056
 					    &client_uuid,
1054
 					    &client_uuid,
1057
 					    sizeof ( client_uuid ) ) ) != 0 ) {
1055
 					    sizeof ( client_uuid ) ) ) != 0 ) {

Завантаження…
Відмінити
Зберегти