Netboot Mailing List (by thread)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

DHCP support again



This is the 0.0.1 release of my DHCP patch for etherboot-3.2.
The code now sends a DHCPREQUEST to the server and waits for DHCPACK after
a DHCPOFFER is received, which is a MUST according RFC2132.
The retry mechanism is linear, not exponential so we should modify
rfc951_retry to handle multiple timers.
Also, I must admit that I didn't get the picture with the T509HACK
(it's 23:47 ,folks :-] ) so if someone understands my code and wants to
make the modifications, it's fine by me.
The code works for me as expected, the log entries produced by the dhcp
server looks like the ones for the Win95 workstations (yuck!). If you have
any problems, le me know (details wanted).
Thanks again,
Vlad

--------------------cut here------------------------------------
diff -u -r etherboot-3.2.orig/src/main.c etherboot-3.2/src/main.c
--- etherboot-3.2.orig/src/main.c	Wed Sep  3 16:54:56 1997
+++ etherboot-3.2/src/main.c	Tue Jan 13 23:14:52 1998
@@ -44,9 +44,17 @@
 unsigned long	netmask;
 struct bootpd_t bootp_data;
 unsigned char   *end_of_rfc1533 = NULL;
+int dhcp_reply;
+char dhcp_server[4]={0,0,0,0};
+char dhcp_addr[4]={0,0,0,0};
 
 unsigned char vendorext_magic[] = {0xE4,0x45,0x74,0x68}; /* äEth */
-char    rfc1533_cookie[5] = { RFC1533_COOKIE, RFC1533_END };
+char    rfc1533_cookie[4] = { RFC1533_COOKIE};
+char    rfc1533_end[1]={RFC1533_END };
+char    dhcpdiscover[6]={RFC2132_MSG_TYPE,1,DHCPDISCOVER,RFC2132_PARAM_LIST,1,3};
+char    dhcprequest [18]={RFC2132_MSG_TYPE,1,DHCPREQUEST,
+			 RFC2132_SRV_ID,4,0,0,0,0,RFC2132_REQ_ADDR,4,0,0,0,0,RFC2132_PARAM_LIST,1,3};
+
 char	broadcast[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
 
 void sleep (int secs);
@@ -705,6 +713,7 @@
 int bootp()
 {
 	int retry;
+	int retry1;
 	struct bootp_t bp;
 	unsigned long  starttime;
 #ifdef T509HACK
@@ -718,7 +727,9 @@
 	bp.bp_hlen = ETHER_ADDR_SIZE;
 	bp.bp_xid = starttime = currticks();
 	bcopy(arptable[ARP_CLIENT].node, bp.bp_hwaddr, ETHER_ADDR_SIZE);
-	bcopy(rfc1533_cookie, bp.bp_vend, 5); /* request RFC-style options */
+	bcopy(rfc1533_cookie, bp.bp_vend, sizeof rfc1533_cookie); /* request RFC-style options */
+	bcopy(dhcpdiscover, bp.bp_vend+sizeof rfc1533_cookie,sizeof dhcpdiscover); 
+	bcopy(rfc1533_end, bp.bp_vend+sizeof rfc1533_cookie +sizeof dhcpdiscover,sizeof rfc1533_end); 
 	
 	for (retry = 0; retry < MAX_BOOTP_RETRIES; ) {
 		udp_transmit(IP_BROADCAST, 0, BOOTP_SERVER,
@@ -733,8 +744,25 @@
 
 		}
 #else
-		if (await_reply(AWAIT_BOOTP, 0, NULL))
+		if (await_reply(AWAIT_BOOTP, 0, NULL)){
+			if (dhcp_reply==DHCPOFFER){
+	dhcp_reply=0;		
+	bcopy(rfc1533_cookie, bp.bp_vend, sizeof rfc1533_cookie); 
+	bcopy(dhcprequest, bp.bp_vend+sizeof rfc1533_cookie,sizeof dhcprequest); 
+	bcopy(rfc1533_end, bp.bp_vend+sizeof rfc1533_cookie +sizeof dhcprequest,sizeof rfc1533_end); 
+	bcopy(dhcp_server,bp.bp_vend+9,4);
+	bcopy(dhcp_addr,bp.bp_vend+15,4);
+        	for (retry1 = 0; retry < MAX_BOOTP_RETRIES;retry1++ ) {
+		udp_transmit(IP_BROADCAST, 0, BOOTP_SERVER,
+			sizeof(struct bootp_t), (char *)&bp);
+			if (await_reply(AWAIT_BOOTP, 0, NULL))
+			  if (dhcp_reply==DHCPACK) return(1);
+			}
+			} else
 			return(1);
+		}
+		rfc951_sleep(++retry);		
+	
 #endif
 		bp.bp_secs = htons((currticks()-starttime)/20);
 	}
@@ -791,13 +819,14 @@
 
 					/* BOOTP ? */
 			bootpreply = (struct bootp_t *)&nic.packet[ETHER_HDR_SIZE];
-			if ((type == AWAIT_BOOTP) &&
+			if ((type == AWAIT_BOOTP) /*&&
 			   (nic.packetlen >= (ETHER_HDR_SIZE +
-			     sizeof(struct bootp_t))) &&
+			     sizeof(struct bootp_t))) */&&
 			   (ntohs(udp->dest) == BOOTP_CLIENT) &&
 			   (bootpreply->bp_op == BOOTP_REPLY)) {
 				convert_ipaddr((char *)&arptable[ARP_CLIENT].ipaddr,
 					bootpreply->bp_yiaddr);
+				bcopy(bootpreply->bp_yiaddr,dhcp_addr,4);
 				default_netmask();
 				convert_ipaddr((char *)&arptable[ARP_SERVER].ipaddr,
 					bootpreply->bp_siaddr);
@@ -910,6 +939,13 @@
 			}
 			else if (c == RFC1533_EXTENSIONPATH)
 				extpath = p;
+			else if (c == RFC2132_MSG_TYPE)
+				{ dhcp_reply=*(p+2);
+				}
+			else if (c == RFC2132_SRV_ID)
+				{
+				bcopy(p+2,dhcp_server,4); 
+				}
 			else if (c == RFC1533_VENDOR_MAGIC &&
 				 TAG_LEN(p) >= 6 &&
 				 !bcmp(p+2,vendorext_magic,4) &&
diff -u -r etherboot-3.2.orig/src/netboot.h etherboot-3.2/src/netboot.h
--- etherboot-3.2.orig/src/netboot.h	Sun Jun 22 15:16:57 1997
+++ etherboot-3.2/src/netboot.h	Tue Jan 13 21:51:03 1998
@@ -81,7 +81,8 @@
 #define ARP_GATEWAY	2
 #define ARP_ROOTSERVER	3
 #define ARP_SWAPSERVER	4
-#define MAX_ARP		ARP_SWAPSERVER+1
+#define ARP_DHCP_SRV	5
+#define MAX_ARP		ARP_DHCP_SRV+1
 
 #define IP		0x0800
 #define ARP		0x0806
@@ -154,6 +155,14 @@
 #define RFC1533_NBSCOPE		47
 #define RFC1533_XFS		48
 #define RFC1533_XDM		49
+#define RFC2132_REQ_ADDR	50
+#define RFC2132_MSG_TYPE	53
+#define RFC2132_SRV_ID		54
+#define RFC2132_PARAM_LIST	55
+#define DHCPDISCOVER		1
+#define DHCPOFFER		2
+#define DHCPREQUEST		3
+#define DHCPACK			5
 
 #define RFC1533_VENDOR_MAJOR	0
 #define RFC1533_VENDOR_MINOR	0
diff -u -r etherboot-3.2.orig/src/ns8390.c etherboot-3.2/src/ns8390.c
--- etherboot-3.2.orig/src/ns8390.c	Thu Jul 17 17:12:35 1997
+++ etherboot-3.2/src/ns8390.c	Tue Jan 13 14:22:20 1998
@@ -94,15 +94,15 @@
 	if (eth_flags & FLAG_16BIT) {
 		cnt >>= 1;	/* number of words */
 		while (cnt--) {
-			outw_p(eth_asic_base + NE_DATA, *((unsigned short *)src));
+			outw(eth_asic_base + NE_DATA, *((unsigned short *)src));
 			src += 2;
 		}
 	}
 	else {
 		while (cnt--)
-			outb_p(eth_asic_base + NE_DATA, *(src++));
+			outb(eth_asic_base + NE_DATA, *(src++));
 	}
-	while((inb_p(eth_nic_base + D8390_P0_ISR) & D8390_ISR_RDC)
+	while((inb(eth_nic_base + D8390_P0_ISR) & D8390_ISR_RDC)
 		!= D8390_ISR_RDC);
 }
 #else






For requests or suggestions regarding this mailing list archive please write to netboot@gkminix.han.de.