aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-07-28 05:58:39 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-07-28 05:58:39 +0800
commit1052e638453f6913f17c5d25f796113202ccbf90 (patch)
tree70ba35b8479002fb6826b3ea776af088fcc58dc7
parent7c381cc0b8d4ff3431b40aafddaefbfbb9b6eeb8 (diff)
downloadpxelinux-1052e638453f6913f17c5d25f796113202ccbf90.tar.gz
pxelinux-1052e638453f6913f17c5d25f796113202ccbf90.tar.xz
pxelinux-1052e638453f6913f17c5d25f796113202ccbf90.zip
Core:PXELINUX: network-specific initialization converted
-rw-r--r--core/dnsresolv.inc1
-rw-r--r--core/extern.inc2
-rw-r--r--core/pxe.c88
-rw-r--r--core/pxelinux.asm74
4 files changed, 91 insertions, 74 deletions
diff --git a/core/dnsresolv.inc b/core/dnsresolv.inc
index 7105f791..23e617b6 100644
--- a/core/dnsresolv.inc
+++ b/core/dnsresolv.inc
@@ -154,6 +154,7 @@ dns_skiplabel:
alignb 2
DNSSendBuf resb DNS_MAX_PACKET
DNSRecvBuf resb DNS_MAX_PACKET
+ global LocalDomain
LocalDomain resb 256 ; Max possible length
DNSServers resd DNS_MAX_SERVERS
diff --git a/core/extern.inc b/core/extern.inc
index a9d81767..5cf15e3e 100644
--- a/core/extern.inc
+++ b/core/extern.inc
@@ -17,7 +17,7 @@
extern memory_scan_for_pxe_struct, memory_scan_for_pxenv_struct
extern gendotquad, pxe_load_config, try_load, allocate_socket
extern free_socket, ip_ok, mangle_name, ack_packet, pxe_get_cached_info
- extern udp_init, get_prefix
+ extern udp_init, get_prefix, network_init
; debug.c
extern debug, print_reg
diff --git a/core/pxe.c b/core/pxe.c
index 5262453b..1e996c19 100644
--- a/core/pxe.c
+++ b/core/pxe.c
@@ -14,6 +14,25 @@
#define htons(x) ( ( ((x) & 0xff) << 8) + ( ((x) &0xff00) >> 8) )
#define ntohs(x) htons(x)
+struct bootp_t {
+ uint8_t opcode; /* BOOTP/DHCP "opcode" */
+ uint8_t hardware; /* ARP hreadware type */
+ uint8_t hardlen; /* Hardware address length */
+ uint8_t gatehops; /* Used by forwarders */
+ uint32_t ident; /* Transaction ID */
+ uint16_t seconds; /* Seconds elapsed */
+ uint16_t flags; /* Broadcast flags */
+ uint32_t cip; /* Cient IP */
+ uint32_t yip; /* "Your" IP */
+ uint32_t sip; /* Next Server IP */
+ uint32_t gip; /* Relay agent IP */
+ uint8_t macaddr[16]; /* Client MAC address */
+ uint8_t sname[64]; /* Server name (optional) */
+ char bootfile[128]; /* Boot file name */
+ uint32_t option_magic; /* Vendor option magic cookie */
+ uint8_t options[1260]; /* Vendor options */
+} __attribute__ ((packed));
+
struct open_file_t {
uint16_t tftp_localport; /* Local port number (0=not in us)*/
uint16_t tftp_remoteport; /* Remote port number */
@@ -27,7 +46,7 @@ struct open_file_t {
uint8_t tftp_goteof; /* 1 if the EOF packet received */
uint8_t tftp_unused[3]; /* Currently unused */
uint16_t tftp_pktbuf; /* Packet buffer offset */
-};
+} __attribute__ ((packed));
extern char Files[];
struct pxe_udp_write_pkt {
@@ -61,6 +80,14 @@ extern uint32_t MyIP;
extern uint32_t Netmask;
extern uint32_t Gateway;
+#define MAC_MAX 32
+extern char MACStr[]; /* MAC address as a string */
+extern char MAC[]; /* Actual MAC address */
+extern char BOOTIFStr[]; /* Space for "BOOTIF=" */
+extern uint8_t MACLen; /* MAC address len */
+extern uint8_t MACType; /* MAC address type */
+
+
extern uint8_t DHCPMagic;
@@ -72,6 +99,7 @@ extern char trackbuf[];
extern char BootFile[];
extern char PathPrefix[];
extern char CurrentDirName[];
+extern char LocalDomain[];
char *err_nopxe = "No !PXE or PXENV+ API found; we're dead...\n";
char *err_pxefailed = "PXE API call failed, error ";
@@ -80,6 +108,7 @@ char *err_noconfig = "Unable to locate configuration file\n";
char *err_damage = "TFTP server sent an incomprehesible reply\n";
char *tftpprefix_msg = "TFTP prefix: ";
+char *get_packet_msg = "Getting cached packet ";
uint16_t NextSocket = 49152;
@@ -501,7 +530,6 @@ void pxe_load_config(com32sys_t *regs)
{
extern char ConfigName[FILENAME_MAX];
extern char UUID[];
- extern char MACStr[];
extern void no_config();
char *cfgprefix = "pxelinux.cfg/";
char *default_str = "default";
@@ -805,4 +833,60 @@ void get_prefix()
printf("%s%s\n", tftpprefix_msg, PathPrefix);
strcpy(CurrentDirName, PathPrefix);
}
+
+/*
+ * Network-specific initialization
+ */
+void network_init(com32sys_t *regs)
+{
+ extern void parse_dhcp();
+ struct bootp_t *bp = (struct bootp_t *)trackbuf;
+
+ *LocalDomain = 0; /* No LocalDomain received */
+ /*
+ * Get the DHCP client identifiers (query info 1)
+ */
+ printf("%s", get_packet_msg);
+ regs->edx.b[0] = 1;
+ pxe_get_cached_info(regs);
+ call16(parse_dhcp, regs, regs);
+ /*
+ ; We don't use flags from the request packet, so
+ ; this is a good time to initialize DHCPMagic...
+ ; Initialize it to 1 meaning we will accept options found;
+ ; in earlier versions of PXELINUX bit 0 was used to indicate
+ ; we have found option 208 with the appropriate magic number;
+ ; we no longer require that, but MAY want to re-introduce
+ ; it in the future for vendor encapsulated options.
+ */
+ *(char *)&DHCPMagic = 1;
+
+
+ /*
+ * Get the BOOTP/DHCP packet that brought us file (and an IP
+ * address). This lives in the DHCPACK packet (query info 2)
+ */
+ regs->edx.b[0] = 2;
+ pxe_get_cached_info(regs);
+ call16(parse_dhcp, regs, 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
+ * the query info 1 packet
+ */
+ MACLen = bp->hardlen > 16 ? 0 : bp->hardlen;
+ MACType = bp->hardware;
+ memcpy(MAC, bp->macaddr, MACLen);
+
+
+ /*
+ * Get the boot file and other info. This lives in the CACHED_REPLY
+ * packet (query info 3)
+ */
+ regs->edx.b[0] = 3;
+ pxe_get_cached_info(regs);
+ call16(parse_dhcp, regs, regs);
+
+ printf("\n");
+}
diff --git a/core/pxelinux.asm b/core/pxelinux.asm
index 7017cf51..a7e10535 100644
--- a/core/pxelinux.asm
+++ b/core/pxelinux.asm
@@ -191,7 +191,7 @@ OverLoad resb 1 ; Set if DHCP packet uses "overloading"
DHCPMagic resb 1 ; PXELINUX magic flags
; The relative position of these fields matter!
- global MACStr
+ global MACStr, MACLen, MACType, MAC, BOOTIFStr
MAC_MAX equ 32 ; Handle hardware addresses this long
MACLen resb 1 ; MAC address len
MACType resb 1 ; MAC address type
@@ -458,75 +458,10 @@ have_entrypoint:
shr ax,6 ; Convert to kilobytes
mov [RealBaseMem],ax
-
;
; Network-specific initialization
;
- xor ax,ax
- mov [LocalDomain],al ; No LocalDomain received
-
-;
-; The DHCP client identifiers are best gotten from the DHCPREQUEST
-; packet (query info 1).
-;
-query_bootp_1:
- mov si,get_packet_msg
- call writestr_early
-
- mov dl,1
- pm_call pxe_get_cached_info
- call parse_dhcp
-
- ; We don't use flags from the request packet, so
- ; this is a good time to initialize DHCPMagic...
- ; Initialize it to 1 meaning we will accept options found;
- ; in earlier versions of PXELINUX bit 0 was used to indicate
- ; we have found option 208 with the appropriate magic number;
- ; we no longer require that, but MAY want to re-introduce
- ; it in the future for vendor encapsulated options.
- mov byte [DHCPMagic],1
-
-;
-; Now attempt to get the BOOTP/DHCP packet that brought us life (and an IP
-; address). This lives in the DHCPACK packet (query info 2).
-;
-query_bootp_2:
- mov dl,2
- pm_call pxe_get_cached_info
- call parse_dhcp ; Parse DHCP packet
-;
-; 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
-; the query info 1 packet.)
-;
-.save_mac:
- movzx cx,byte [trackbuf+bootp.hardlen]
- cmp cx,16
- jna .mac_ok
- xor cx,cx ; Bad hardware address length
-.mac_ok:
- mov [MACLen],cl
- mov al,[trackbuf+bootp.hardware]
- mov [MACType],al
- mov si,trackbuf+bootp.macaddr
- mov di,MAC
- rep movsb
-
-; Enable this if we really need to zero-pad this field...
-; mov cx,MAC+MAC_MAX+1
-; sub cx,di
-; xor ax,ax
-; rep stosb
-
-;
-; Now, get the boot file and other info. This lives in the CACHED_REPLY
-; packet (query info 3).
-;
-query_bootp_3:
- mov dl,3
- pm_call pxe_get_cached_info
- call parse_dhcp ; Parse DHCP packet
- call crlf
+ pm_call network_init
;
; Generate the bootif string, and the hardware-based config string.
@@ -1633,9 +1568,6 @@ reset_pxe:
pop es
ret
- section .data16
-get_packet_msg db 'Getting cached packet', 0
-
section .text16
;
; parse_dhcp
@@ -1658,7 +1590,7 @@ get_packet_msg db 'Getting cached packet', 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]