diff mbox series

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

Message ID 1526658340-1992-12-git-send-email-thuth@redhat.com
State Superseded
Headers show
Series Support network booting with pxelinux.cfg files | expand

Commit Message

Thomas Huth May 18, 2018, 3:45 p.m. UTC
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@redhat.com>
---
 lib/libnet/netload.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)
diff mbox series

Patch

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;