commit: 97c0c1761b977b0ddc1100111b608a2dba32e32a
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 29 16:26:25 2019 +0000
Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Mon Jul 29 20:02:21 2019 +0000
URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=97c0c176
initrd.scripts: start_network(): Handle already running interface
When kernel was built with CONFIG_IP_PNP_DHCP=y option for example and
ip=dhcp was specified on kernel command-line, interface maybe already
up and running (configured). In this case it doesn't make any sense to
fire up udhcpc which would only get the same network configuration.
However, when interface is already up but manual IP configuration was
specified, we must restart interface to get back into a known state and
apply our own configuration like told by the user because we support
more complex configurations.
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>
defaults/initrd.scripts | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index ce38bd8..e01f461 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -1727,10 +1727,23 @@ start_network() {
warn_msg "Will not try to start network ..."
return 1
+ elif [ "${interface_identifier}" = 'mac' ]
+ then
+ good_msg "Interface detected as ${GK_NET_IFACE}"
fi
if [ -z "${IP}" -o "${IP}" = 'dhcp' ]
then
+ if is_interface_up
+ then
+ # CONFIG_IP_PNP_DHCP and ip=dhcp probably caused kernel
to bring up
+ # network for us. Really no need re-run dhcp...
+ warn_msg "Interface ${GK_NET_IFACE} is already up."
+ warn_msg "Skipping network setup; Will use existing
network configuration ..."
+ touch "${GK_NET_LOCKFILE}"
+ return 0
+ fi
+
good_msg "Bringing up interface ${GK_NET_IFACE} using dhcp ..."
${QUIET}
busybox udhcpc -i "${GK_NET_IFACE}" -n -t
${GK_NET_DHCP_RETRIES} -T ${GK_NET_TIMEOUT_DHCP} -R -p "${GK_NET_DHCP_PIDFILE}"
if [ $? -ne 0 ]
@@ -1739,6 +1752,15 @@ start_network() {
return 1
fi
else
+ if is_interface_up
+ then
+ # At this point we don't know if kernel has brought up
network the
+ # way we wanted. It's safer to restart interface and do
it on our own...
+ warn_msg "Interface ${GK_NET_IFACE} is already up and
therefore in an unknown state!"
+ warn_msg "Will now restart interface ${GK_NET_IFACE} to
get into a known state ..."
+ kill_network
+ fi
+
good_msg "Bringing up interface ${GK_NET_IFACE} ..." ${QUIET}
ip link set "${GK_NET_IFACE}" up
@@ -1835,7 +1857,16 @@ kill_network() {
return
fi
- rm "${GK_NET_LOCKFILE}"
+ [ -f "${GK_NET_LOCKFILE}" ] && rm "${GK_NET_LOCKFILE}"
+}
+
+is_interface_up() {
+ if ip link show dev "${GK_NET_IFACE}" 2>/dev/null | grep -q ',UP,'
+ then
+ return 0
+ else
+ return 1
+ fi
}
ipv6_tentative() {