[SLOF] [PATCH v2 11/11] libnet: Support UUID-based pxelinux.cfg file names

Thomas Huth thuth at redhat.com
Sat May 19 01:45:40 AEST 2018


Retrieve the UUID from the device tree and pass it to the pxelinux.cfg
function, so that we can look there for UUID-based file names, too.

Signed-off-by: Thomas Huth <thuth at redhat.com>
---
 lib/libnet/netload.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c
index 5af4e26..5d69c3b 100644
--- a/lib/libnet/netload.c
+++ b/lib/libnet/netload.c
@@ -426,6 +426,42 @@ static int tftp_load(filename_ip_t *fnip, void *buffer, int len)
 	return rc;
 }
 
+static int get_uuid(uint8_t *uuid)
+{
+	char *addr;
+	int len;
+	char tmp[5];
+
+	if (SLOF_get_property("/", "system-id", &addr, &len))
+		return 0;
+
+	if (len < 36) {    /* This should never happen... */
+		puts("Warning: UUID property is too short");
+		return 0;
+	}
+
+	/* Parse property string */
+	*(uint32_t *)&uuid[0] = strtoul(addr, &addr, 16);
+	if (*addr++ != '-')
+		return 0;
+	*(uint16_t *)&uuid[4] = strtoul(addr, &addr, 16);
+	if (*addr++ != '-')
+		return 0;
+	*(uint16_t *)&uuid[6] = strtoul(addr, &addr, 16);
+	if (*addr++ != '-')
+		return 0;
+	*(uint16_t *)&uuid[8] = strtoul(addr, &addr, 16);
+	if (*addr++ != '-')
+		return 0;
+	memcpy(tmp, addr, 4);
+	tmp[4] = 0;
+	*(uint16_t *)&uuid[10] = strtoul(tmp, NULL, 16);
+	addr += 4;
+	*(uint32_t *)&uuid[12] = strtoul(addr, NULL, 16);
+
+	return 1;
+}
+
 #define CFG_BUF_SIZE 2048
 #define MAX_LKIA_ENTRIES 16
 static int net_pxelinux_cfg_load(filename_ip_t *fnip, char *loadbase,
@@ -433,10 +469,13 @@ static int net_pxelinux_cfg_load(filename_ip_t *fnip, char *loadbase,
 {
 	static char cfgbuf[CFG_BUF_SIZE];
 	struct lkia entries[MAX_LKIA_ENTRIES];
-	int def, num_entries, rc, ilen;
+	int def, num_entries, rc, ilen, has_uuid;
+	uint8_t uuid[16];
+
+	has_uuid = get_uuid(uuid);
 
-	num_entries = pxelinux_load_parse_cfg(fnip, mac, NULL, cfgbuf,
-	                                      CFG_BUF_SIZE, entries,
+	num_entries = pxelinux_load_parse_cfg(fnip, mac, has_uuid ? uuid : NULL,
+	                                      cfgbuf, CFG_BUF_SIZE, entries,
 	                                      MAX_LKIA_ENTRIES, &def);
 	if (num_entries <= 0)
 		return -1;
-- 
1.8.3.1



More information about the SLOF mailing list