From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 43C21138334 for ; Mon, 29 Jul 2019 20:10:35 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BDF13E086D; Mon, 29 Jul 2019 20:10:30 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 90319E0869 for ; Mon, 29 Jul 2019 20:10:30 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BD4CD348F8B for ; Mon, 29 Jul 2019 20:10:29 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 85350762 for ; Mon, 29 Jul 2019 20:10:25 +0000 (UTC) From: "Thomas Deutschmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Thomas Deutschmann" Message-ID: <1564430541.97c0c1761b977b0ddc1100111b608a2dba32e32a.whissi@gentoo> Subject: [gentoo-commits] proj/genkernel:master commit in: defaults/ X-VCS-Repository: proj/genkernel X-VCS-Files: defaults/initrd.scripts X-VCS-Directories: defaults/ X-VCS-Committer: whissi X-VCS-Committer-Name: Thomas Deutschmann X-VCS-Revision: 97c0c1761b977b0ddc1100111b608a2dba32e32a X-VCS-Branch: master Date: Mon, 29 Jul 2019 20:10:25 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 9015aa41-1d9f-4785-ac98-b09f188ed458 X-Archives-Hash: 144646c1fa98e1e530152048041ad7b2 commit: 97c0c1761b977b0ddc1100111b608a2dba32e32a Author: Thomas Deutschmann gentoo org> AuthorDate: Mon Jul 29 16:26:25 2019 +0000 Commit: Thomas Deutschmann gentoo 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 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() {