Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 May 2018 11:30:09 +0900 (JST)
From:      Masachika ISHIZUKA <ish@amail.plala.or.jp>
To:        freebsd-hackers@freebsd.org
Subject:   How can I wait for a USB Ethernet adapter to appear to configure lagg on startup?
Message-ID:  <20180518.113009.439302765921485452.ish@amail.plala.or.jp>

next in thread | raw e-mail | index | archive | help
----Next_Part(Fri_May_18_11_30_09_2018_552)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi.

I use a nootbook machine.
As this machine has no internal nic, I use a USB ethernet adapter(ue0).
I want to configure lagg0 of ue0 and iwm0, but I must wait to start
/etc/rc.d/netif until appearing the ue0.
I'm using patched netif as follows, but I must keep it whenever
'mergemaster -Ui' is run.
Is there a more elegant way?
-- 
Masachika ISHIZUKA

----Next_Part(Fri_May_18_11_30_09_2018_552)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="netif.diff"

--- /etc/rc.d.inactive/netif.org	2018-05-18 10:11:57.204047000 +0900
+++ /etc/rc.d/netif	2018-05-18 10:44:02.017318000 +0900
@@ -53,11 +53,45 @@
 
 netif_start()
 {
-	local _if
+	local _if count wait_if output got_if any_error
 
 	# Set the list of interfaces to work on.
 	#
 	cmdifn=$*
+
+	if [ ${netif_wait_timeout} -lt 1 ]; then
+		err 1 "netif_wait_timeout must be >= 1"
+	fi
+
+	if [ -n "${netif_wait_if}" ]; then
+		any_error=0
+		for wait_if in ${netif_wait_if}; do
+			echo -n "Waiting for ${wait_if}"
+			got_if=0
+			count=1
+			# Handle SIGINT (Ctrl-C); force abort of while() loop
+			trap break SIGINT
+			while [ ${count} -le ${netif_wait_timeout} ]; do
+				if output=`/sbin/ifconfig ${wait_if} 2>/dev/null`; then
+					echo -n ", interface present"
+					got_if=1
+					break
+				fi
+				sleep 1
+				count=$((count+1))
+			done
+			# Restore default SIGINT handler
+			trap - SIGINT
+			if [ ${got_if} -eq 0 ]; then
+				echo ", wait failed: interface never appeared."
+				any_error=1
+			fi
+		done
+		if [ ${any_error} -eq 1 ]; then
+			warn "Continuing with startup, but be aware you may not have "
+			warn "a fully functional networking layer at this point."
+		fi
+	fi
 
 	if [ -z "$cmdifn" ]; then
 		#

----Next_Part(Fri_May_18_11_30_09_2018_552)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="add-to-rc.conf"

netif_wait_timeout=60
netif_wait_if="ue0"

----Next_Part(Fri_May_18_11_30_09_2018_552)----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180518.113009.439302765921485452.ish>