Netboot Mailing List (by thread)

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

Re: DHCP support again





On Tue, 13 Jan 1998, Vlad Lungu wrote:

> This is the 0.0.1 release of my DHCP patch for etherboot-3.2.
It's 0.0.2 now.
> The retry mechanism is linear, not exponential so we should modify
> rfc951_retry to handle multiple timers.
I should drink and code, it's much better :-). No need to modify anything.
> 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.
Ok, I get the picture, so if you want correct DHCP support undefine
T509HACK or write it yourself :-).

I have also changed the bootp_t->bp_vend to char[DHCP_OPT_LEN] which is
312 bytes, the minimum that a DHCP client must accept according to
RFC2131. 
I'm sending also a "maximum packet size" option set to 576 bytes,
to avoid bufer overruns.
In await_reply(), the size of the BOOTP/DHCP packet is checked against the 
length of the standard packet WITHOUT vendor extensions, which is better
than nothing.

That's all folks. I'm waiting for positive/negative test results.
Bye for now,
Vlad


------------------------------------cut here----------------------------
diff -r -u 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	Wed Jan 14 14:51:09 1998
@@ -44,9 +44,24 @@
 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[] = { RFC1533_COOKIE};
+char    rfc1533_end[]={RFC1533_END };
+char    dhcpdiscover[]={RFC2132_MSG_TYPE,1,DHCPDISCOVER,
+			RFC2132_MAX_SIZE,2,2,64,
+			RFC2132_PARAM_LIST,4,RFC1533_NETMASK,RFC1533_GATEWAY,
+					    RFC1533_HOSTNAME,RFC1533_EXTENSIONPATH};
+char    dhcprequest []={RFC2132_MSG_TYPE,1,DHCPREQUEST,
+			RFC2132_SRV_ID,4,0,0,0,0,
+			RFC2132_REQ_ADDR,4,0,0,0,0,
+			RFC2132_MAX_SIZE,2,2,64,
+			RFC2132_PARAM_LIST,4,RFC1533_NETMASK,RFC1533_GATEWAY,
+					    RFC1533_HOSTNAME,RFC1533_EXTENSIONPATH};
+
 char	broadcast[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
 
 void sleep (int secs);
@@ -705,6 +720,7 @@
 int bootp()
 {
 	int retry;
+	int retry1;
 	struct bootp_t bp;
 	unsigned long  starttime;
 #ifdef T509HACK
@@ -718,7 +734,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 +751,27 @@
 
 		}
 #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;) {
+		udp_transmit(IP_BROADCAST, 0, BOOTP_SERVER,
+			sizeof(struct bootp_t), (char *)&bp);
+			dhcp_reply=0;
+			if (await_reply(AWAIT_BOOTP, 0, NULL))
+			  if (dhcp_reply==DHCPACK) return(1);
+			 rfc951_sleep(++retry1); 
+			}
+			} else
 			return(1);
+		}
+		rfc951_sleep(++retry);		
+	
 #endif
 		bp.bp_secs = htons((currticks()-starttime)/20);
 	}
@@ -793,11 +830,12 @@
 			bootpreply = (struct bootp_t *)&nic.packet[ETHER_HDR_SIZE];
 			if ((type == AWAIT_BOOTP) &&
 			   (nic.packetlen >= (ETHER_HDR_SIZE +
-			     sizeof(struct bootp_t))) &&
+			     sizeof(struct bootp_t))-DHCP_OPT_LEN) &&
 			   (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);
@@ -816,7 +854,7 @@
 				      (char *)&bootp_data,
 				      sizeof(struct bootp_t));
 				decode_rfc1533(bootp_data.bootp_reply.bp_vend,
-					       0, BOOTP_VENDOR_LEN, 1);
+					       0, DHCP_OPT_LEN, 1);
 				return(1);
 			}
 
@@ -910,6 +948,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 -r -u 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	Wed Jan 14 11:47:54 1998
@@ -154,6 +154,16 @@
 #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 RFC2132_MAX_SIZE	57
+
+#define DHCPDISCOVER		1
+#define DHCPOFFER		2
+#define DHCPREQUEST		3
+#define DHCPACK			5
 
 #define RFC1533_VENDOR_MAJOR	0
 #define RFC1533_VENDOR_MINOR	0
@@ -169,6 +179,7 @@
 
 #define RFC1533_END		255
 #define BOOTP_VENDOR_LEN	64
+#define DHCP_OPT_LEN		312
 
 #define	TFTP_DEFAULTSIZE_PACKET	512
 #define	TFTP_MAX_PACKET		1432 /* 512 */
@@ -262,7 +273,7 @@
 	char bp_hwaddr[16];
 	char bp_sname[64];
 	char bp_file[128];
-	char bp_vend[BOOTP_VENDOR_LEN];
+	char bp_vend[DHCP_OPT_LEN];
 };
 
 struct bootpd_t {
diff -r -u 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 23:19:04 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.