[syslinux:master] pxelinux: new IPAPPEND 4 to generate a SYSUUID= option.

syslinux-bot for H. Peter Anvin hpa at zytor.com
Fri Jul 2 09:18:27 PDT 2010


Commit-ID:  ccce101b32ae26dd180ecaebe95cc749c2f90373
Gitweb:     http://syslinux.zytor.com/commit/ccce101b32ae26dd180ecaebe95cc749c2f90373
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Thu, 1 Jul 2010 19:44:53 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Thu, 1 Jul 2010 19:44:53 -0700

pxelinux: new IPAPPEND 4 to generate a SYSUUID= option.

Add a new IPAPPEND option to generate a SYSUUID= option with the
in-system UUID.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 NEWS                      |    4 ++
 com32/menu/readconfig.c   |    3 +-
 core/cmdline.inc          |    4 ++-
 core/fs/pxe/dhcp_option.c |    3 +-
 core/fs/pxe/pxe.c         |   73 ++++++++++++++++++++++++++++++++------------
 core/fs/pxe/pxe.h         |    2 +-
 doc/syslinux.txt          |    8 +++++
 7 files changed, 72 insertions(+), 25 deletions(-)

diff --git a/NEWS b/NEWS
index fb6179f..60a8306 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,10 @@ Changes in 4.01:
 	* Correct a severe memory overwrite bug (mainly related to the
 	  menu system.)
 	* lua.c32: Lua script interpreter, currently experimental.
+	* PXELINUX: new option IPAPPEND 4 to append the system UUID to
+	  the kernel command line.
+	* PXELINUX: display BOOTIF and SYSUUID at startup time, and
+	  when Ctrl-N is pressed on the command line.
 
 Changes in 4.00:
 	* Major code base changes; all filesystem rewritten in C.
diff --git a/com32/menu/readconfig.c b/com32/menu/readconfig.c
index ca9c35e..8c16fda 100644
--- a/com32/menu/readconfig.c
+++ b/com32/menu/readconfig.c
@@ -343,7 +343,8 @@ static void record(struct menu *m, struct labeldata *ld, const char *append)
 	    if (ld->ipappend) {
 		ipappend = syslinux_ipappend_strings();
 		for (i = 0; i < ipappend->count; i++) {
-		    if ((ld->ipappend & (1U << i)) && ipappend->ptr[i])
+		    if ((ld->ipappend & (1U << i)) && ipappend->ptr[i] &&
+			ipappend->ptr[i][0])
 			ipp += sprintf(ipp, " %s", ipappend->ptr[i]);
 		}
 	    }
diff --git a/core/cmdline.inc b/core/cmdline.inc
index 7fa5381..3e63f9a 100644
--- a/core/cmdline.inc
+++ b/core/cmdline.inc
@@ -48,12 +48,14 @@ make_plain_cmdline:
 ; Actual IPAppend strings...
 ;
 %if IS_PXELINUX
-		extern IPOption, BOOTIFStr
+		extern IPOption, BOOTIFStr, SYSUUIDStr
+		global IPAppends, numIPAppends
 
 		section .data16
 		alignz 2
 IPAppends	dw IPOption
 		dw BOOTIFStr
+		dw SYSUUIDStr
 numIPAppends	equ ($-IPAppends)/2
 %else
 IPAppends	equ 0
diff --git a/core/fs/pxe/dhcp_option.c b/core/fs/pxe/dhcp_option.c
index ab0f4c0..50f2de0 100644
--- a/core/fs/pxe/dhcp_option.c
+++ b/core/fs/pxe/dhcp_option.c
@@ -8,7 +8,7 @@ char LocalDomain[256];
 
 int over_load;
 uint8_t uuid_type;
-char uuid[17];
+uint8_t uuid[16];
 
 static void parse_dhcp_options(const void *, int, uint8_t);
 
@@ -113,7 +113,6 @@ static void uuid_client_identifier(const void *data, int opt_len)
     have_uuid = true;
     uuid_type = type;
     memcpy(uuid, data+1, 16);
-    uuid[16] = 0;
 }
 
 static void pxelinux_configfile(const void *data, int opt_len)
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index dd209fc..25bd094 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -16,7 +16,9 @@ uint8_t MAC_len;                   /* MAC address len */
 uint8_t MAC_type;                  /* MAC address type */
 
 char __bss16 BOOTIFStr[7+3*(MAC_MAX+1)];
-#define MAC_str (BOOTIFStr+7)
+#define MAC_str (BOOTIFStr+7)	/* The actual hardware address */
+char __bss16 SYSUUIDStr[8+32+5];
+#define UUID_str (SYSUUIDStr+8)	/* The actual UUID */
 
 char boot_file[256];		   /* From DHCP */
 char path_prefix[256];		   /* From DHCP */
@@ -1062,7 +1064,6 @@ static int pxe_load_config(void)
     const char *default_str = "default";
     char *config_file;
     char *last;
-    char *p;
     int tries = 8;
 
     get_prefix();
@@ -1079,22 +1080,7 @@ static int pxe_load_config(void)
 
     /* Try loading by UUID */
     if (have_uuid) {
-	static const uint8_t uuid_dashes[] = {4, 2, 2, 2, 6, 0};
-	char *src = uuid;
-	const uint8_t *uuid_ptr = uuid_dashes;
-
-	p = config_file;
-        while (*uuid_ptr) {
-	    int len = *uuid_ptr;
-
-            lchexbytes(p, src, len);
-            p += len * 2;
-            src += len;
-            uuid_ptr++;
-            *p++ = '-';
-        }
-        /* Remove last dash and zero-terminate */
-	*--p = '\0';
+	strcpy(config_file, UUID_str);
 	if (try_load(ConfigName))
             return 0;
     }
@@ -1125,7 +1111,7 @@ static int pxe_load_config(void)
 }
 
 /*
- * Generate the botif string, and the hardware-based config string
+ * Generate the bootif string.
  */
 static void make_bootif_string(void)
 {
@@ -1138,6 +1124,35 @@ static void make_bootif_string(void)
     for (i = MAC_len; i; i--)
 	dst += sprintf(dst, "-%02x", *src++);
 }
+/*
+ * Generate the SYSUUID string, if we have one...
+ */
+static void make_sysuuid_string(void)
+{
+    static const uint8_t uuid_dashes[] = {4, 2, 2, 2, 6, 0};
+    const uint8_t *src = uuid;
+    const uint8_t *uuid_ptr = uuid_dashes;
+    char *dst;
+
+    SYSUUIDStr[0] = '\0';	/* If nothing there... */
+
+    /* Try loading by UUID */
+    if (have_uuid) {
+	dst = stpcpy(SYSUUIDStr, "SYSUUID=");
+
+        while (*uuid_ptr) {
+	    int len = *uuid_ptr;
+
+            lchexbytes(dst, src, len);
+            dst += len * 2;
+            src += len;
+            uuid_ptr++;
+            *dst++ = '-';
+        }
+        /* Remove last dash and zero-terminate */
+	*--dst = '\0';
+    }
+}
 
 /*
  * Generate an ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
@@ -1172,7 +1187,23 @@ static void ip_init(void)
 
     ip = ntohl(ip);
     printf("My IP address seems to be %08X %s\n", ip, dot_quad_buf);
-    printf("%s\n", IPOption);
+}
+
+/*
+ * Print the IPAPPEND strings, in order
+ */
+extern const uint16_t IPAppends[];
+extern const char numIPAppends[];
+
+static void print_ipappend(void)
+{
+    size_t i;
+
+    for (i = 0; i < (size_t)numIPAppends; i++) {
+	const char *p = (const char *)(size_t)IPAppends[i];
+	if (*p)
+	    printf("%s\n", p);
+    }
 }
 
 /*
@@ -1468,7 +1499,9 @@ static void network_init(void)
     printf("\n");
 
     make_bootif_string();
+    make_sysuuid_string();
     ip_init();
+    print_ipappend();
 
     /*
      * Check to see if we got any PXELINUX-specific DHCP options; in particular,
diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h
index 8a9dbcc..1e6fa76 100644
--- a/core/fs/pxe/pxe.h
+++ b/core/fs/pxe/pxe.h
@@ -209,7 +209,7 @@ extern far_ptr_t InitStack;
 
 extern bool have_uuid;
 extern uint8_t uuid_type;
-extern char uuid[];
+extern uint8_t uuid[];
 
 extern uint16_t BIOS_fbm;
 extern const uint8_t TimeoutTable[];
diff --git a/doc/syslinux.txt b/doc/syslinux.txt
index 5a93b90..51d1332 100644
--- a/doc/syslinux.txt
+++ b/doc/syslinux.txt
@@ -179,6 +179,14 @@ IPAPPEND flag_val			[PXELINUX only]
 	This allows an initrd program to determine from which
 	interface the system booted.
 
+	4: indicates that an option of the following format
+	should be generated and added to the kernel command line:
+
+		SYSUUID=<system uuid>
+
+	... in lower case hexadecimal in the format normally used for
+	UUIDs (same as for the configuration file; see pxelinux.txt.)
+
 LABEL label
     KERNEL image
     APPEND options...



More information about the Syslinux-commits mailing list