[syslinux:pathbased] pxe: clean up/fix generation of ipappend strings

syslinux-bot for H. Peter Anvin hpa at zytor.com
Tue Feb 23 19:36:02 PST 2010


Commit-ID:  1115737d431cf3b6a02faa90a0971bf91bef2370
Gitweb:     http://syslinux.zytor.com/commit/1115737d431cf3b6a02faa90a0971bf91bef2370
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Tue, 23 Feb 2010 19:35:11 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Tue, 23 Feb 2010 19:35:11 -0800

pxe: clean up/fix generation of ipappend strings

Clean up and fix the generation of the ipappend strings.  In
particular, BOOTIF= was generated into a buffer which was too small.
Put the buffer definitions in C while we're at it.

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


---
 core/cmdline.inc  |    2 ++
 core/fs/pxe/pxe.c |   51 +++++++++++++++++++--------------------------------
 core/fs/pxe/pxe.h |    3 +--
 core/pxelinux.asm |    6 ------
 4 files changed, 22 insertions(+), 40 deletions(-)

diff --git a/core/cmdline.inc b/core/cmdline.inc
index d860ac7..54d85f4 100644
--- a/core/cmdline.inc
+++ b/core/cmdline.inc
@@ -46,6 +46,8 @@ make_plain_cmdline:
 ; Actual IPAppend strings...
 ;
 %if IS_PXELINUX
+		extern IPOption, BOOTIFStr
+
 		section .data16
 		alignz 2
 IPAppends	dw IPOption
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index 2f29343..a294db7 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -14,11 +14,13 @@ uint32_t gate_way = 0;             /* Default router */
 uint16_t server_port = TFTP_PORT;  /* TFTP server port */
 uint16_t real_base_mem;            /* Amount of DOS memory after freeing */
 
-char MAC_str[3 * (MAC_MAX + 1)];   /* MAC address as a string */
-char MAC[MAC_MAX + 1];             /* Actual MAC address */
+uint8_t MAC[MAC_MAX];		   /* Actual MAC address */
 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)
+
 char boot_file[256];		   /* From DHCP */
 char path_prefix[256];		   /* From DHCP */
 char dot_quad_buf[16];
@@ -1099,54 +1101,39 @@ static int pxe_load_config(void)
  */
 static void make_bootif_string(void)
 {
-    char mac[18];
-    char *src = mac;
-    char *dst = MAC_str;
-    int i = MAC_len + 1;
-
-    *(uint8_t *)src++ = MAC_type;
-    memcpy(src, MAC, MAC_len);
-    src = mac;
-    for (; i > 0; i--) {
-        lchexbytes(dst, src, 1);
-        dst += 2;
-        src += 1;
-        *dst++ = '-';
-    }
-    *(dst - 1) = 0;   /* Drop the last '-' and null-terminate string */
-    strcat(BOOTIFStr, "BOOTIF=");
-    strcat(BOOTIFStr, MAC_str);
+    const uint8_t *src;
+    char *dst = BOOTIFStr;
+    int i;
 
-#if 0
-    printf("%s\n", BOOTIFStr);
-#endif
+    dst += sprintf(dst, "BOOTIF=%02x", MAC_type);
+    src = MAC;
+    for (i = MAC_len; i; i--)
+	dst += sprintf(dst, "-%02x", *src++);
 }
+
 /*
  * Generate an ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
  * option into IPOption based on a DHCP packet in trackbuf.
  *
  */
+char __bss16 IPOption[3+4*16];
+
 static void genipopt(void)
 {
     char *p = IPOption;
-    int ip_len;
 
-    strcpy(p, "ip=");
-    p += 3;
+    p = stpcpy(p, "ip=");
 
-    ip_len = gendotquad(p, MyIP);
-    p += ip_len;
+    p += gendotquad(p, MyIP);
     *p++ = ':';
 
-    ip_len = gendotquad(p, server_ip);
-    p += ip_len;
+    p += gendotquad(p, server_ip);
     *p++ = ':';
 
-    ip_len = gendotquad(p, gate_way);
-    p += ip_len;
+    p += gendotquad(p, gate_way);
     *p++ = ':';
 
-    ip_len = gendotquad(p, net_mask);
+    gendotquad(p, net_mask);
 }
 
 
diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h
index a4d7d83..5e6aded 100644
--- a/core/fs/pxe/pxe.h
+++ b/core/fs/pxe/pxe.h
@@ -166,8 +166,7 @@ extern uint32_t net_mask;
 extern uint32_t gate_way;
 extern uint16_t server_port;
 
-extern char MAC_str[];
-extern char MAC[];
+extern uint8_t MAC[];
 extern char BOOTIFStr[];
 extern uint8_t MAC_len;
 extern uint8_t MAC_type;
diff --git a/core/pxelinux.asm b/core/pxelinux.asm
index a53fead..9df43bf 100644
--- a/core/pxelinux.asm
+++ b/core/pxelinux.asm
@@ -78,8 +78,6 @@ InitStack	resd 1
 
 		section .bss16
 		alignb FILENAME_MAX
-                global IPOption
-IPOption	resb 80			; ip= option buffer
 PXEStack	resd 1			; Saved stack during PXE call
 
 		alignb 4
@@ -90,10 +88,6 @@ APIVer		resw 1			; PXE API version found
 LocalBootType	resw 1			; Local boot return code
 DHCPMagic	resb 1			; PXELINUX magic flags
 
-; The relative position of these fields matter!
-                global BOOTIFStr
-BOOTIFStr	resb 7			; Space for "BOOTIF="
-
 		section .text16
 StackBuf	equ STACK_TOP-44	; Base of stack if we use our own
 StackHome	equ StackBuf



More information about the Syslinux-commits mailing list