⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhcpid.txt

📁 linux下从网卡远程启动
💻 TXT
📖 第 1 页 / 共 2 页
字号:
From daniel@insu.com Thu Apr 27 14:14:55 2000Sender: root@iNsu.COMMessage-ID: <39075669.FAEB20F2@insu.com>Date: Wed, 26 Apr 2000 16:49:45 -0400From: Daniel Shane <daniel@insu.com>X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-5.0 i686)X-Accept-Language: enMIME-Version: 1.0Subject: Re: New feature added to etherbootReferences: <20000425170804.6677127D8A@Goffman.iNsu.COM>Content-Type: multipart/mixed; boundary="------------4734FDA0BF2F2FBDF8EB8DF6"This is a multi-part message in MIME format.--------------4734FDA0BF2F2FBDF8EB8DF6Content-Type: text/plain; charset=us-asciiContent-Transfer-Encoding: 7bitOk, here is a diff for etherboot 4.6.0 that adds identifiers.To test this you need to use a class in the dhcpd.conf file andalso send back a string in option 208.These identifiers prevent a client from booting from other DHCPservers when you have more than 1 in your network.In will also prevent any client, except the valid ones, to use thisDHCP server.Here is a subset of my dhcpd.conf :option iNdiskless-state code 208 = text;class "iNdiskless-boot" {    match if substring(option iNdiskless-state,0,4) = "BOOT";}class "iNdiskless-setup" {    match if substring(option iNdiskless-state,0,5) = "SETUP";}           subnet 10.4.1.0 netmask 255.255.255.0 {pool {  allow members of "iNdiskless-boot";  deny unknown clients;  range 10.4.1.2 10.4.1.200;  next-server 10.4.1.1;# Identify ourselves to the etherboot/DHCP client  option iNdiskless-state       "BOOT";   host labo01 {       hardware ethernet 00:80:c8:ec:04:1b;     }  host labo02 {       hardware ethernet 00:4f:4c:04:45:d6;     }  host labo03 {       hardware ethernet 00:50:ba:c8:db:d6;  }}pool {  allow members of "iNdiskless-setup";  range 10.4.1.201 10.4.1.254;  option iNdiskless-state       "SETUP";# send another kernel to setup the diskless workstation  }}    Daniel Shane.--------------4734FDA0BF2F2FBDF8EB8DF6Content-Type: text/plain; charset=us-ascii; name="main.c.diff"Content-Transfer-Encoding: 7bitContent-Disposition: inline; filename="main.c.diff"--- etherboot-4.6.0/src/main.c	Tue Apr 25 08:30:01 2000+++ etherboot-4.5.6-new/src/main.c	Wed Apr 26 16:17:09 2000@@ -42,6 +42,23 @@ char	*motd[RFC1533_VENDOR_NUMOFMOTD]; #ifdef	IMAGE_FREEBSD int freebsd_howto = 0; #endif++#ifdef SERVER_IDENT +#ifdef DEFAULT_SERVER_IDENT+char server_ident[9] = DEFAULT_SERVER_IDENT;+#else+char server_ident[9] = {};+#endif   +#endif++#ifdef CLIENT_IDENT +#ifdef DEFAULT_CLIENT_IDENT+char client_ident[9] = DEFAULT_CLIENT_IDENT;+#else+char client_ident[9] = {};+#endif+#endif+ int     vendorext_isvalid; char	config_buffer[TFTP_MAX_PACKET+1];	/* +1 for null byte */ unsigned long	netmask;@@ -63,61 +80,85 @@ char    rfc1533_cookie[5] = { RFC1533_CO char    rfc1533_cookie[] = { RFC1533_COOKIE}; char    rfc1533_end[]={RFC1533_END }; static const 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-	};-static const 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,-		/* request parameters */-		RFC2132_PARAM_LIST,-#ifdef	IMAGE_FREEBSD-		/* 4 standard + 4 vendortags + 8 motd + 16 menu items */-		4 + 4 + 8 + 16,+	RFC2132_MSG_TYPE,1,DHCPDISCOVER,+	RFC2132_MAX_SIZE,2,2,64,+#ifdef CLIENT_IDENT +	RFC1533_VENDOR_CLIENT_IDENT,8,0,0,0,0,0,0,0,0,+#endif+	RFC2132_PARAM_LIST,+#ifdef SERVER_IDENT +	5, #else-		/* 4 standard + 3 vendortags + 8 motd + 16 menu items */-		4 + 3 + 8 + 16,+	4, #endif-		/* Standard parameters */-		RFC1533_NETMASK, RFC1533_GATEWAY,-		RFC1533_HOSTNAME, RFC1533_EXTENSIONPATH,-		/* Etherboot vendortags */-		RFC1533_VENDOR_MAGIC,+#ifdef SERVER_IDENT +	RFC1533_VENDOR_SERVER_IDENT,   +#endif+	RFC1533_NETMASK,+	RFC1533_GATEWAY,+	RFC1533_HOSTNAME,+	RFC1533_EXTENSIONPATH+};+static const char dhcprequest []={+	RFC2132_MSG_TYPE,1,DHCPREQUEST,+	RFC2132_SRV_ID,4,0,0,0,0,+	RFC2132_REQ_ADDR,4,0,0,0,0,+#ifdef CLIENT_IDENT +	RFC1533_VENDOR_CLIENT_IDENT,8,0,0,0,0,0,0,0,0,+#endif+	RFC2132_MAX_SIZE,2,2,64,+	/* request parameters */+	RFC2132_PARAM_LIST,+	/* 4 standard + 3 vendortags + 8 motd + 16 menu items */+	4 + +	3 + +#ifdef  IMAGE_FREEBSD+	1 + /* One more vendortags for VENDOR_HOWTO */+#endif+#ifdef SERVER_IDENT +	1 + /* One more vendortags for VENDOR_SERVER_IDENT */+#endif+	8 + +	16,+	/* Standard parameters */+	RFC1533_NETMASK, RFC1533_GATEWAY,+	RFC1533_HOSTNAME, RFC1533_EXTENSIONPATH,+	/* Etherboot vendortags */+	RFC1533_VENDOR_MAGIC, #ifdef	IMAGE_FREEBSD-		RFC1533_VENDOR_HOWTO,+	RFC1533_VENDOR_HOWTO, #endif-		RFC1533_VENDOR_MNUOPTS, RFC1533_VENDOR_SELECTION,-		/* 8 MOTD entries */-		RFC1533_VENDOR_MOTD,-		RFC1533_VENDOR_MOTD+1,-		RFC1533_VENDOR_MOTD+2,-		RFC1533_VENDOR_MOTD+3,-		RFC1533_VENDOR_MOTD+4,-		RFC1533_VENDOR_MOTD+5,-		RFC1533_VENDOR_MOTD+6,-		RFC1533_VENDOR_MOTD+7,-		/* 16 image entries */-		RFC1533_VENDOR_IMG,-		RFC1533_VENDOR_IMG+1,-		RFC1533_VENDOR_IMG+2,-		RFC1533_VENDOR_IMG+3,-		RFC1533_VENDOR_IMG+4,-		RFC1533_VENDOR_IMG+5,-		RFC1533_VENDOR_IMG+6,-		RFC1533_VENDOR_IMG+7,-		RFC1533_VENDOR_IMG+8,-		RFC1533_VENDOR_IMG+9,-		RFC1533_VENDOR_IMG+10,-		RFC1533_VENDOR_IMG+11,-		RFC1533_VENDOR_IMG+12,-		RFC1533_VENDOR_IMG+13,-		RFC1533_VENDOR_IMG+14,-		RFC1533_VENDOR_IMG+15,-	};+#ifdef SERVER_IDENT+	RFC1533_VENDOR_SERVER_IDENT,+#endif+	RFC1533_VENDOR_MNUOPTS, RFC1533_VENDOR_SELECTION,+	/* 8 MOTD entries */+	RFC1533_VENDOR_MOTD,+	RFC1533_VENDOR_MOTD+1,+	RFC1533_VENDOR_MOTD+2,+	RFC1533_VENDOR_MOTD+3,+	RFC1533_VENDOR_MOTD+4,+	RFC1533_VENDOR_MOTD+5,+	RFC1533_VENDOR_MOTD+6,+	RFC1533_VENDOR_MOTD+7,+	/* 16 image entries */+	RFC1533_VENDOR_IMG,+	RFC1533_VENDOR_IMG+1,+	RFC1533_VENDOR_IMG+2,+	RFC1533_VENDOR_IMG+3,+	RFC1533_VENDOR_IMG+4,+	RFC1533_VENDOR_IMG+5,+	RFC1533_VENDOR_IMG+6,+	RFC1533_VENDOR_IMG+7,+	RFC1533_VENDOR_IMG+8,+	RFC1533_VENDOR_IMG+9,+	RFC1533_VENDOR_IMG+10,+	RFC1533_VENDOR_IMG+11,+	RFC1533_VENDOR_IMG+12,+	RFC1533_VENDOR_IMG+13,+	RFC1533_VENDOR_IMG+14,+	RFC1533_VENDOR_IMG+15,+};  #endif	/* NO_DHCP_SUPPORT */ static const char broadcast[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };@@ -176,6 +217,55 @@ done: 			break; 	} #endif++#ifdef SHIFTED_IDENT_INPUT+	if (getshift() & 3)+		{+#endif+	+#ifdef  CLIENT_IDENT+#   ifdef ASK_CLIENT_IDENT+			{+				char tmp_ident[9] = {};+#      ifdef  DEFAULT_CLIENT_IDENT+				printf("Enter the client identifier (8 char max.) default [%s] : ",client_ident);+#      else+				printf("Enter the client identifier (8 char max.) : ");+#      endif+				getstr(tmp_ident,8);+				if (strlen(tmp_ident) != 0)+					memcpy(client_ident,tmp_ident,8);+				else+					printf("%s",client_ident);+				putchar('\n');+			}+#   endif+#endif++#ifdef  SERVER_IDENT+#   ifdef ASK_SERVER_IDENT+			{+				char tmp_ident[9] = {};+#      ifdef  DEFAULT_SERVER_IDENT+				printf("Enter the server identifier (8 char max.) default [%s] : ",server_ident);+#      else+				printf("Enter the server identifier (8 char max.) : ");+#      endif+				getstr(tmp_ident,8);+				if (strlen(tmp_ident) != 0)+					memcpy(server_ident,tmp_ident,8);+				else+					printf("%s",server_ident);+				putchar('\n');+			}+#   endif+#endif++#ifdef SHIFTED_IDENT_INPUT+		}+#endif++	print_config(); #if	(TRY_FLOPPY_FIRST > 0) && defined(FLOPPY) 	disk_init(); 	printf("Trying floppy");@@ -188,7 +278,7 @@ done: 	} 	printf("no floppy\n"); #endif	/* TRY_FLOPPY_FIRST && FLOPPY */-	print_config();+        print_config(); 	gateA20_set(); #ifdef	EMERGENCYDISKBOOT 	if (!eth_probe()) {@@ -663,6 +753,8 @@ BOOTP - Get my IP address and load infor int bootp() { 	int retry;+        int offset = 0;+ #ifndef	NO_DHCP_SUPPORT 	int retry1; #endif	/* NO_DHCP_SUPPORT */@@ -680,11 +772,18 @@ int bootp() 	bp.bp_xid = xid = starttime = currticks(); 	memcpy(bp.bp_hwaddr, arptable[ARP_CLIENT].node, ETHER_ADDR_SIZE); #ifdef	NO_DHCP_SUPPORT-	memcpy(bp.bp_vend, rfc1533_cookie, 5); /* request RFC-style options */+	memcpy(bp.bp_vend+offset, rfc1533_cookie, 5); /* request RFC-style options */+	offset += sizeof rfc1533_cookie; #else-	memcpy(bp.bp_vend, rfc1533_cookie, sizeof rfc1533_cookie); /* request RFC-style options */-	memcpy(bp.bp_vend+sizeof rfc1533_cookie, dhcpdiscover, sizeof dhcpdiscover);-	memcpy(bp.bp_vend+sizeof rfc1533_cookie +sizeof dhcpdiscover, rfc1533_end, sizeof rfc1533_end);+	memcpy(bp.bp_vend+offset, rfc1533_cookie, sizeof rfc1533_cookie); /* request RFC-style options */+	offset += sizeof rfc1533_cookie; 	+	memcpy(bp.bp_vend+offset, dhcpdiscover, sizeof dhcpdiscover);+	offset += sizeof dhcpdiscover;+#ifdef CLIENT_IDENT +	memcpy(bp.bp_vend+13, client_ident, strlen(client_ident));+#endif+	memcpy(bp.bp_vend+offset, rfc1533_end, sizeof rfc1533_end);+	offset += sizeof rfc1533_end; #endif	/* NO_DHCP_SUPPORT */  	for (retry = 0; retry < MAX_BOOTP_RETRIES; ) {@@ -715,19 +814,22 @@ int bootp() #else 		if (await_reply(AWAIT_BOOTP, 0, NULL, TIMEOUT)){ 			if (dhcp_reply==DHCPOFFER){-		dhcp_reply=0;-		memcpy(bp.bp_vend, rfc1533_cookie, sizeof rfc1533_cookie);-		memcpy(bp.bp_vend+sizeof rfc1533_cookie, dhcprequest, sizeof dhcprequest);-		memcpy(bp.bp_vend+sizeof rfc1533_cookie +sizeof dhcprequest, rfc1533_end, sizeof rfc1533_end);-		memcpy(bp.bp_vend+9, &dhcp_server, sizeof(in_addr));-		memcpy(bp.bp_vend+15, &dhcp_addr, sizeof(in_addr));-			for (retry1 = 0; retry1 < MAX_BOOTP_RETRIES;) {-			udp_transmit(IP_BROADCAST, 0, BOOTP_SERVER,-				sizeof(struct bootp_t), &bp); 				dhcp_reply=0;-				if (await_reply(AWAIT_BOOTP, 0, NULL, TIMEOUT))-					if (dhcp_reply==DHCPACK)-						return(1);+				memcpy(bp.bp_vend, rfc1533_cookie, sizeof rfc1533_cookie);+				memcpy(bp.bp_vend+sizeof rfc1533_cookie, dhcprequest, sizeof dhcprequest);+				memcpy(bp.bp_vend+sizeof rfc1533_cookie +sizeof dhcprequest, rfc1533_end, sizeof rfc1533_end);+				memcpy(bp.bp_vend+9, &dhcp_server, sizeof(in_addr));+				memcpy(bp.bp_vend+15, &dhcp_addr, sizeof(in_addr));+#ifdef CLIENT_IDENT+				memcpy(bp.bp_vend+21, client_ident, strlen(client_ident));+#endif+				for (retry1 = 0; retry1 < MAX_BOOTP_RETRIES;) {+					udp_transmit(IP_BROADCAST, 0, BOOTP_SERVER,+						     sizeof(struct bootp_t), &bp);+					dhcp_reply=0;+					if (await_reply(AWAIT_BOOTP, 0, NULL, TIMEOUT))+						if (dhcp_reply==DHCPACK)+							return(1); 					rfc951_sleep(++retry1); 				} 			} else@@ -750,6 +852,7 @@ AWAIT_REPLY - Wait until we get a respon **************************************************************************/ int await_reply(int type, int ival, void *ptr, int timeout) {+	int result; 	unsigned long time; 	struct	iphdr *ip; 	struct	udphdr *udp;@@ -757,6 +860,7 @@ int await_reply(int type, int ival, void 	struct	bootp_t *bootpreply; 	struct	rpc_t *rpc; 	unsigned short ptype;+	unsigned int min_packetlen;  	unsigned int protohdrlen = ETHER_HDR_SIZE + sizeof(struct iphdr) + 				sizeof(struct udphdr);@@ -766,35 +870,35 @@ int await_reply(int type, int ival, void 	 * needs a negligible amount of time.  */ 	for (;;) { 		if (eth_poll()) {	/* We have something! */-					/* Check for ARP - No IP hdr */+			/* Check for ARP - No IP hdr */ 			if (nic.packetlen >= ETHER_HDR_SIZE) { 				ptype = ((unsigned short) nic.packet[12]) << 8 					| ((unsigned short) nic.packet[13]); 			} else continue; /* what else could we do with it? */ 			if ((nic.packetlen >= ETHER_HDR_SIZE +-				sizeof(struct arprequest)) &&-			   (ptype == ARP) ) {+			     sizeof(struct arprequest)) &&+			    (ptype == ARP) ) { 				unsigned long tmp;-+				 				arpreply = (struct arprequest *) 					&nic.packet[ETHER_HDR_SIZE]; 				if ((arpreply->opcode == ntohs(ARP_REPLY)) &&-				   !memcmp(arpreply->sipaddr, ptr, sizeof(in_addr)) &&-				   (type == AWAIT_ARP)) {+				    !memcmp(arpreply->sipaddr, ptr, sizeof(in_addr)) &&+				    (type == AWAIT_ARP)) { 					memcpy(arptable[ival].node, arpreply->shwaddr, ETHER_ADDR_SIZE); 					return(1); 				} 				memcpy(&tmp, arpreply->tipaddr, sizeof(in_addr)); 				if ((arpreply->opcode == ntohs(ARP_REQUEST)) &&-					(tmp == arptable[ARP_CLIENT].ipaddr.s_addr)) {+				    (tmp == arptable[ARP_CLIENT].ipaddr.s_addr)) { 					arpreply->opcode = htons(ARP_REPLY); 					memcpy(arpreply->tipaddr, arpreply->sipaddr, sizeof(in_addr)); 					memcpy(arpreply->thwaddr, arpreply->shwaddr, ETHER_ADDR_SIZE); 					memcpy(arpreply->sipaddr, &arptable[ARP_CLIENT].ipaddr, sizeof(in_addr)); 					memcpy(arpreply->shwaddr, arptable[ARP_CLIENT].node, ETHER_ADDR_SIZE); 					eth_transmit(arpreply->thwaddr, ARP,-						sizeof(struct  arprequest),-						arpreply);+						     sizeof(struct  arprequest),+						     arpreply); #ifdef	MDEBUG 					memcpy(&tmp, arpreply->tipaddr, sizeof(in_addr)); 					printf("Sent ARP reply to: %I\n",tmp);@@ -802,20 +906,20 @@ int await_reply(int type, int ival, void 				} 				continue; 			}-+			 			if (type == AWAIT_QDRAIN) { 				continue; 			}-

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -