ソースを参照

[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
3個のファイルの変更21行の追加7行の削除
  1. 19
    0
      src/include/ipxe/uuid.h
  2. 1
    4
      src/interface/smbios/smbios_settings.c
  3. 1
    3
      src/net/udp/dhcp.c

+ 19
- 0
src/include/ipxe/uuid.h ファイルの表示

@@ -9,6 +9,7 @@
9 9
 FILE_LICENCE ( GPL2_OR_LATER );
10 10
 
11 11
 #include <stdint.h>
12
+#include <byteswap.h>
12 13
 
13 14
 /** A universally unique ID */
14 15
 union uuid {
@@ -28,6 +29,24 @@ union uuid {
28 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 50
 extern char * uuid_ntoa ( const union uuid *uuid );
32 51
 
33 52
 #endif /* _IPXE_UUID_H */

+ 1
- 4
src/interface/smbios/smbios_settings.c ファイルの表示

@@ -22,7 +22,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
22 22
 #include <stdint.h>
23 23
 #include <string.h>
24 24
 #include <errno.h>
25
-#include <byteswap.h>
26 25
 #include <ipxe/settings.h>
27 26
 #include <ipxe/init.h>
28 27
 #include <ipxe/uuid.h>
@@ -148,9 +147,7 @@ static int smbios_fetch ( struct settings *settings __unused,
148 147
 		     ( smbios_version() >= SMBIOS_VERSION ( 2, 6 ) ) ) {
149 148
 			DBG ( "SMBIOS detected mangled UUID\n" );
150 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 151
 			raw = &uuid;
155 152
 		}
156 153
 

+ 1
- 3
src/net/udp/dhcp.c ファイルの表示

@@ -1049,9 +1049,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
1049 1049
 	client_uuid.type = DHCP_CLIENT_UUID_TYPE;
1050 1050
 	if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
1051 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 1053
 		if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_UUID,
1056 1054
 					    &client_uuid,
1057 1055
 					    sizeof ( client_uuid ) ) ) != 0 ) {

読み込み中…
キャンセル
保存