pxe: clean up/fix generation of ipappend strings
authorH. Peter Anvin <hpa@zytor.com>
Wed, 24 Feb 2010 03:35:11 +0000 (19:35 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 24 Feb 2010 03:35:11 +0000 (19:35 -0800)
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@zytor.com>
core/cmdline.inc
core/fs/pxe/pxe.c
core/fs/pxe/pxe.h
core/pxelinux.asm

index d860ac7..54d85f4 100644 (file)
@@ -46,6 +46,8 @@ make_plain_cmdline:
 ; Actual IPAppend strings...
 ;
 %if IS_PXELINUX
+               extern IPOption, BOOTIFStr
+
                section .data16
                alignz 2
 IPAppends      dw IPOption
index 2f29343..a294db7 100644 (file)
@@ -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);
 }
 
 
index a4d7d83..5e6aded 100644 (file)
@@ -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;
index a53fead..9df43bf 100644 (file)
@@ -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