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

Bug#439397: initramfs-tools: split networking code into separate function



Package: initramfs-tools
Severity: wishlist

please consider the attached patch that splits the networking code from
the nfs scripts into a separate function, which would allow other
network boot methods to re-use it.

live well,
  vagrant
diff --git a/scripts/functions b/scripts/functions
index db223cd..6f222f5 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -270,3 +270,38 @@ parse_numeric() {
 	chmod 600 /dev/root
 	ROOT=/dev/root
 }
+
+configure_networking()
+{
+	# support ip options see linux sources Documentation/nfsroot.txt
+	case ${IPOPTS} in
+		none|off)
+			# Do nothing
+			;;
+		""|on|any)
+			# Bring up device
+			ipconfig ${DEVICE}
+			;;
+		dhcp|bootp|rarp|both)
+			ipconfig -c ${IPOPTS} -d ${DEVICE}
+			;;
+		*)
+			ipconfig -d $IPOPTS
+
+			# grab device entry from ip option
+			NEW_DEVICE=${IPOPTS#*:*:*:*:*:*}
+			if [ "${NEW_DEVICE}" != "${IPOPTS}" ]; then
+				NEW_DEVICE=${NEW_DEVICE%:*}
+			else
+				# wrong parse, possibly only a partial string
+				NEW_DEVICE=
+			fi
+			if [ -n "${NEW_DEVICE}" ]; then
+				DEVICE="${NEW_DEVICE}"
+			fi
+			;;
+	esac
+
+	# source relevant ipconfig output
+	. /tmp/net-${DEVICE}.conf
+}
diff --git a/scripts/nfs b/scripts/nfs
index 717dfe8..f233368 100644
--- a/scripts/nfs
+++ b/scripts/nfs
@@ -4,40 +4,11 @@
 
 retry_nr=0
 
-# parse nfs bootargs + launch ipconfig and nfsmount
+# parse nfs bootargs and mount nfs 
 do_nfsmount()
 {
-	# support ip options see linux sources Documentation/nfsroot.txt
-	case ${IPOPTS} in
-		none|off)
-			# Do nothing
-			;;
-		""|on|any)
-			# Bring up device
-			ipconfig ${DEVICE}
-			;;
-		dhcp|bootp|rarp|both)
-			ipconfig -c ${IPOPTS} -d ${DEVICE}
-			;;
-		*)
-			ipconfig -d $IPOPTS
 
-			# grab device entry from ip option
-			NEW_DEVICE=${IPOPTS#*:*:*:*:*:*}
-			if [ "${NEW_DEVICE}" != "${IPOPTS}" ]; then
-				NEW_DEVICE=${NEW_DEVICE%:*}
-			else
-				# wrong parse, possibly only a partial string
-				NEW_DEVICE=
-			fi
-			if [ -n "${NEW_DEVICE}" ]; then
-				DEVICE="${NEW_DEVICE}"
-			fi
-			;;
-	esac
-
-	# source relevant ipconfig output
-	. /tmp/net-${DEVICE}.conf
+    configure_networking
 
 	# get nfs root from dhcp
 	if [ "x${NFSROOT}" = "xauto" ]; then

Reply to: