aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-07-29 05:59:23 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-07-29 05:59:23 +0800
commitd9768e3d54b0c2c273dfacd6a0b2f6b0641f2f6e (patch)
tree1a5732193349821d827d7f08cbaab111236287fe
parente3378ba7a06a2628dbde49cd39c3d2258f46c630 (diff)
downloadpxelinux-d9768e3d54b0c2c273dfacd6a0b2f6b0641f2f6e.tar.gz
pxelinux-d9768e3d54b0c2c273dfacd6a0b2f6b0641f2f6e.tar.xz
pxelinux-d9768e3d54b0c2c273dfacd6a0b2f6b0641f2f6e.zip
Core:PXELINUX: parse_dhcp conveted
-rw-r--r--core/pxe.c84
-rw-r--r--core/pxelinux.asm69
2 files changed, 79 insertions, 74 deletions
diff --git a/core/pxe.c b/core/pxe.c
index a9a357ed..a1bf807f 100644
--- a/core/pxe.c
+++ b/core/pxe.c
@@ -13,6 +13,11 @@
#define is_digit(c) (((c) >= '0') && ((c) <= '9'))
#define htons(x) ( ( ((x) & 0xff) << 8) + ( ((x) &0xff00) >> 8) )
#define ntohs(x) htons(x)
+#define htonl(x) ( ( ((x) & 0xff) << 24) + ( ((x) & 0xff00) << 8 ) + \
+ ( ((x) & 0xff0000) >> 8 ) + ( ((x) & 0xff000000) >> 24) )
+#define ntohl(x) htonl(x)
+
+#define BOOTP_OPTION_MAGIC htonl(0x63825363)
struct bootp_t {
uint8_t opcode; /* BOOTP/DHCP "opcode" */
@@ -89,6 +94,7 @@ extern uint8_t MACType; /* MAC address type */
extern uint8_t DHCPMagic;
+extern uint8_t OverLoad;
/* TFTP ACK packet */
@@ -866,7 +872,10 @@ void parse_dhcp_options(com32sys_t *regs)
uint8_t opt_num;
uint8_t opt_len;
uint8_t opt_filter = regs->edx.b[1] == 208 ? 208 : 0;
-
+
+ if (opt_filter)
+ printf("***NOTE!:*** we hit a pxelinux-specific options\n");
+
while (size --) {
c = *option++;
@@ -896,7 +905,7 @@ void parse_dhcp_options(com32sys_t *regs)
regs->esi.w[0] = option;
regs->eax.w[0] = opt_len;
regs->edx.b[1] = opt_num;
- call16(fun_addr, regs, NULL);
+ call16((void *)fun_addr, regs, NULL);
popa(regs);
break;
}
@@ -909,6 +918,70 @@ void parse_dhcp_options(com32sys_t *regs)
}
}
+
+/*
+ *
+ ;
+ ; parse_dhcp
+ ;
+ ; Parse a DHCP packet. This includes dealing with "overloaded"
+ ; option fields (see RFC 2132, section 9.3)
+ ;
+ ; This should fill in the following global variables, if the
+ ; information is present:
+ ;
+ ; MyIP - client IP address
+ ; ServerIP - boot server IP address
+ ; Netmask - network mask
+ ; Gateway - default gateway router IP
+ ; BootFile - boot file name
+ ; DNSServers - DNS server IPs
+ ; LocalDomain - Local domain name
+ ; MACLen, MAC - Client identifier, if MACLen == 0
+ ;
+ ; This assumes the DHCP packet is in "trackbuf" and the length
+ ; of the packet in in CX on entry.
+ ;
+*/
+void parse_dhcp(com32sys_t *regs)
+{
+ struct bootp_t *dhcp = (struct bootp_t *)trackbuf;
+ int pkt_len = regs->ecx.w[0];
+ int opt_len;
+
+ OverLoad = 0;
+ regs->eax.l = dhcp->yip;
+ ip_ok(regs);
+ if ((regs->eflags.l & EFLAGS_ZF) == 0) /* IP is ok */
+ MyIP = dhcp->yip;
+
+ regs->eax.l = dhcp->sip;
+ ip_ok(regs);
+ if ((regs->eflags.l & EFLAGS_ZF) == 0)
+ ServerIP = dhcp->sip;
+
+ opt_len = (char *)dhcp + pkt_len - (char *)&dhcp->options;
+ if (opt_len && (dhcp->option_magic == BOOTP_OPTION_MAGIC)) {
+ regs->ecx.w[0] = opt_len;
+ regs->esi.w[0] = &dhcp->options;
+ parse_dhcp_options(regs);
+ }
+
+ if (OverLoad & 1) {
+ regs->ecx.w[0] = 128;
+ regs->esi.w[0] = &dhcp->bootfile;
+ parse_dhcp_options(regs);
+ } else if (dhcp->bootfile[0]) {
+ strcpy(BootFile, dhcp->bootfile);
+ }
+
+ if (OverLoad & 2) {
+ regs->ecx.w[0] = 64;
+ regs->esi.w[0] = dhcp->sname;
+ parse_dhcp_options(regs);
+ }
+}
+
/*
@@ -916,7 +989,6 @@ void parse_dhcp_options(com32sys_t *regs)
*/
void network_init(com32sys_t *regs)
{
- extern void parse_dhcp();
struct bootp_t *bp = (struct bootp_t *)trackbuf;
*LocalDomain = 0; /* No LocalDomain received */
@@ -927,7 +999,7 @@ void network_init(com32sys_t *regs)
printf("%s", get_packet_msg);
regs->edx.b[0] = 1;
pxe_get_cached_info(regs);
- call16(parse_dhcp, regs, regs);
+ parse_dhcp(regs);
/*
; We don't use flags from the request packet, so
; this is a good time to initialize DHCPMagic...
@@ -946,7 +1018,7 @@ void network_init(com32sys_t *regs)
*/
regs->edx.b[0] = 2;
pxe_get_cached_info(regs);
- call16(parse_dhcp, regs, regs);
+ parse_dhcp(regs);
/*
* Save away MAC address (assume this is in query info 2. If this
* turns out to be problematic it might be better getting it from
@@ -963,7 +1035,7 @@ void network_init(com32sys_t *regs)
*/
regs->edx.b[0] = 3;
pxe_get_cached_info(regs);
- call16(parse_dhcp, regs, regs);
+ parse_dhcp(regs);
printf("\n");
}
diff --git a/core/pxelinux.asm b/core/pxelinux.asm
index ac310ac9..0ff0518d 100644
--- a/core/pxelinux.asm
+++ b/core/pxelinux.asm
@@ -181,7 +181,7 @@ InitStack resd 1 ; Pointer to reset stack (SS:SP)
PXEStack resd 1 ; Saved stack during PXE call
alignb 4
- global DHCPMagic
+ global DHCPMagic, OverLoad
RebootTime resd 1 ; Reboot timeout, if set by option
StrucPtr resd 1 ; Pointer to PXENV+ or !PXE structure
APIVer resw 1 ; PXE API version found
@@ -1568,73 +1568,6 @@ reset_pxe:
pop es
ret
- section .text16
-;
-; parse_dhcp
-;
-; Parse a DHCP packet. This includes dealing with "overloaded"
-; option fields (see RFC 2132, section 9.3)
-;
-; This should fill in the following global variables, if the
-; information is present:
-;
-; MyIP - client IP address
-; ServerIP - boot server IP address
-; Netmask - network mask
-; Gateway - default gateway router IP
-; BootFile - boot file name
-; DNSServers - DNS server IPs
-; LocalDomain - Local domain name
-; MACLen, MAC - Client identifier, if MACLen == 0
-;
-; This assumes the DHCP packet is in "trackbuf" and the length
-; of the packet in in CX on entry.
-;
- global parse_dhcp
-parse_dhcp:
- mov byte [OverLoad],0 ; Assume no overload
- mov eax, [trackbuf+bootp.yip]
- pm_call ip_ok
- jz .noyip
- mov [MyIP], eax
-.noyip:
- mov eax, [trackbuf+bootp.sip]
- and eax, eax
- pm_call ip_ok
- jz .nosip
- mov [ServerIP], eax
-.nosip:
- sub cx, bootp.options
- jbe .nooptions
- mov si, trackbuf+bootp.option_magic
- lodsd
- cmp eax, BOOTP_OPTION_MAGIC
- jne .nooptions
- pm_call parse_dhcp_options
-.nooptions:
- mov si, trackbuf+bootp.bootfile
- test byte [OverLoad],1
- jz .nofileoverload
- mov cx,128
- pm_call parse_dhcp_options
- jmp short .parsed_file
-.nofileoverload:
- cmp byte [si], 0
- jz .parsed_file ; No bootfile name
- mov di,BootFile
- mov cx,32
- rep movsd
- xor al,al
- stosb ; Null-terminate
-.parsed_file:
- mov si, trackbuf+bootp.sname
- test byte [OverLoad],2
- jz .nosnameoverload
- mov cx,64
- pm_call parse_dhcp_options
-.nosnameoverload:
- ret
-
section .data16
global dhcp_option_list