diff mbox series

[v3,8/8] libnet: Support UUID-based pxelinux.cfg file names

Message ID 1527314768-4797-9-git-send-email-thuth@redhat.com
State Accepted
Headers show
Series Support network booting with pxelinux.cfg files | expand

Commit Message

Thomas Huth May 26, 2018, 6:06 a.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  | 18 +++++++++++++++++-
 lib/libnet/pxelinux.c | 16 +++++++++++++---
 lib/libnet/pxelinux.h |  2 +-
 3 files changed, 31 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c
index 4c7ac37..4b95eab 100644
--- a/lib/libnet/netload.c
+++ b/lib/libnet/netload.c
@@ -427,6 +427,21 @@  static int tftp_load(filename_ip_t *fnip, void *buffer, int len,
 	return rc;
 }
 
+static const char *get_uuid(void)
+{
+	char *addr;
+	int len;
+
+	if (SLOF_get_property("/", "system-id", &addr, &len))
+		return NULL;
+	if (len < 37) {    /* This should never happen... */
+		puts("Warning: UUID property is too short.");
+		return NULL;
+	}
+
+	return addr;
+}
+
 #define CFG_BUF_SIZE 2048
 #define MAX_PL_CFG_ENTRIES 16
 static int net_pxelinux_load(filename_ip_t *fnip, char *loadbase,
@@ -442,7 +457,8 @@  static int net_pxelinux_load(filename_ip_t *fnip, char *loadbase,
 		return -1;
 	}
 
-	rc = pxelinux_load_parse_cfg(fnip, mac, retries, cfgbuf, CFG_BUF_SIZE,
+	rc = pxelinux_load_parse_cfg(fnip, mac, get_uuid(), retries, 
+	                             cfgbuf, CFG_BUF_SIZE,
 	                             entries, MAX_PL_CFG_ENTRIES, &def);
 	if (rc < 0)
 		goto out_free;
diff --git a/lib/libnet/pxelinux.c b/lib/libnet/pxelinux.c
index 91b3c13..718ceca 100644
--- a/lib/libnet/pxelinux.c
+++ b/lib/libnet/pxelinux.c
@@ -51,7 +51,7 @@  static int pxelinux_tftp_load(filename_ip_t *fnip, void *buffer, int len,
  * Try to load a pxelinux.cfg file by probing the possible file names.
  * Note that this function will overwrite filename_ip_t->filename.
  */
-static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac,
+static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uuid,
                              int retries, char *cfgbuf, int cfgbufsize)
 {
 	int rc, idx;
@@ -101,6 +101,15 @@  static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac,
 		}
 	}
 
+	/* Try to load config file with name based on the VM UUID */
+	if (uuid) {
+		strcpy(baseptr, uuid);
+		rc = pxelinux_tftp_load(fn_ip, cfgbuf, cfgbufsize - 1, retries);
+		if (rc > 0) {
+			return rc;
+		}
+	}
+
 	/* Look for config file with MAC address in its name */
 	sprintf(baseptr, "01-%02x-%02x-%02x-%02x-%02x-%02x",
 		mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
@@ -215,6 +224,7 @@  nextline:
  * Try to load and parse a pxelinux-style configuration file.
  * @param fn_ip        must contain server and client IP information
  * @param mac          MAC address which should be used for probing
+ * @param uuid         UUID which should be used for probing (can be NULL)
  * @param retries      Amount of TFTP retries before giving up
  * @param cfgbuf       Pointer to the buffer where config file should be loaded
  * @param cfgsize      Size of the cfgbuf buffer
@@ -223,14 +233,14 @@  nextline:
  * @param def_ent      Used to return the index of the default entry
  * @return             Number of valid entries
  */
-int pxelinux_load_parse_cfg(filename_ip_t *fn_ip, uint8_t *mac,
+int pxelinux_load_parse_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uuid,
                             int retries, char *cfgbuf, int cfgsize,
                             struct pl_cfg_entry *entries, int max_entries,
                             int *def_ent)
 {
 	int rc;
 
-	rc = pxelinux_load_cfg(fn_ip, mac, retries, cfgbuf, cfgsize);
+	rc = pxelinux_load_cfg(fn_ip, mac, uuid, retries, cfgbuf, cfgsize);
 	if (rc < 0)
 		return rc;
 
diff --git a/lib/libnet/pxelinux.h b/lib/libnet/pxelinux.h
index 98b3925..0514d0d 100644
--- a/lib/libnet/pxelinux.h
+++ b/lib/libnet/pxelinux.h
@@ -25,7 +25,7 @@  struct pl_cfg_entry {
 
 int pxelinux_parse_cfg(char *cfg, int cfgsize, struct pl_cfg_entry *entries,
                        int max_entries, int *def_ent);
-int pxelinux_load_parse_cfg(filename_ip_t *fn_ip, uint8_t *mac,
+int pxelinux_load_parse_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uuid,
                             int retries, char *cfgbuf, int cfgsize,
                             struct pl_cfg_entry *entries,
                             int max_entries, int *def_ent);