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

[Patch] Lease IP address from some specific DHCP server



When a Debian live system leasing an IP address from DHCP server, if
there are 2 or more (seldom, but it might happen) DHCP servers in the
LAN, it would be better there is an option so that the client machine
can pick up the specific one via DHCP vendor class identifier.
Attached please find the patch to support this. For example, if the boot
parameter
dhcp-vendor-id=DebianLiveClient
is used, then the ipconfig in the initrd will try to lease the IP
address from the DHCP server which has the config in the dhcpd.conf:
class "My-Live-Client" {
  match if
  (substring(option vendor-class-identifier, 0, 9) = "PXEClient") or
  (substring(option vendor-class-identifier, 0, 10) = "DebianLiveClient") ;
}

Hope this helps.
My 2 cents.

Steven
-- 
Steven Shiau <steven _at_ stevenshiau org>
Public Key Server PGP Key ID: 4096R/47CF935C
Fingerprint: 0240 1FEB 695D 7112 62F0  8796 11C1 12DA 47CF 935C



diff -uNr orig/9990-cmdline-old new/9990-cmdline-old
--- orig/9990-cmdline-old	2016-05-11 21:44:15.000000000 +0800
+++ new/9990-cmdline-old	2016-06-17 11:48:59.537265469 +0800
@@ -135,6 +135,11 @@
 				export NETBOOT
 				;;
 
+			dhcp-vendor-id=*)
+				DHCP_VENDOR_ID="${_PARAMETER#dhcp-vendor-id=}"
+				export DHCP_VENDOR_ID
+				;;
+
 			nfsopts=*)
 				NFSOPTS="${_PARAMETER#nfsopts=}"
 				export NFSOPTS
diff -uNr orig/9990-networking.sh new/9990-networking.sh
--- orig/9990-networking.sh	2016-05-11 21:44:15.000000000 +0800
+++ new/9990-networking.sh	2016-06-17 11:54:13.846824046 +0800
@@ -61,6 +61,11 @@
 
 	[ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
 	echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
+	if [ -n "$DHCP_VENDOR_ID" ]
+	then
+	  echo "Using DHCP vendor class ID: $DHCP_VENDOR_ID"
+	  DHCP_VENDOR_ID_OPT="-i $DHCP_VENDOR_ID"
+        fi
 
 	if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
 	then
@@ -94,8 +99,8 @@
 		# why we use '$devlist $devlist $devlist' for the other for loop
 		for dev in $devlist $devlist $devlist
 		do
-			echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
-			ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
+			echo "Executing ipconfig -t $ETHDEV_TIMEOUT $DHCP_VENDOR_ID_OPT $dev"
+			ipconfig -t "$ETHDEV_TIMEOUT" $DHCP_VENDOR_ID_OPT $dev | tee -a /netboot.config &
 			jobid=$!
 			sleep "$ETHDEV_TIMEOUT" ; sleep 1
 			if [ -r /proc/"$jobid"/status ]
@@ -115,7 +120,7 @@
 		done
 	else
 		for interface in ${DEVICE}; do
-			ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
+			ipconfig -t "$ETHDEV_TIMEOUT" $DHCP_VENDOR_ID_OPT ${interface} | tee /netboot-${interface}.config
 
 			[ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
 

Reply to: