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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 87411158099 for ; Sun, 26 Nov 2023 05:31:14 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 980892BC01E; Sun, 26 Nov 2023 05:31:13 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 731BC2BC01E for ; Sun, 26 Nov 2023 05:31:13 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4A221340943 for ; Sun, 26 Nov 2023 05:31:12 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 58EE1136A for ; Sun, 26 Nov 2023 05:31:10 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1700976657.8b4f91a94fad6666c957304b0108aa5c895b4d1e.robbat2@OpenRC> Subject: [gentoo-commits] proj/netifrc:master commit in: net/ X-VCS-Repository: proj/netifrc X-VCS-Files: net/dummy.sh X-VCS-Directories: net/ X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: 8b4f91a94fad6666c957304b0108aa5c895b4d1e X-VCS-Branch: master Date: Sun, 26 Nov 2023 05:31:10 +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: 62d54328-165c-4d69-ad7c-c38ed555f0c6 X-Archives-Hash: ed43d652ff1025b0dcabb4f814fbb782 commit: 8b4f91a94fad6666c957304b0108aa5c895b4d1e Author: Matoro Mahri matoro tk> AuthorDate: Sat Nov 25 18:17:41 2023 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Sun Nov 26 05:30:57 2023 +0000 URL: https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=8b4f91a9 net/dummy.sh: preload module, create interface conditionally The dummy module has a numdummies parameter which will cause it to automatically create N dummy interfaces at load time. Because creating a dummy interface causes the kernel to load the module if it is not already loaded, then if the name of the interface to be created matches the name of one of the interfaces the kernel creates, an error will be returned indicating that the interface already exists, despite it not existing before the command was invoked. Ensure we load the module before attempting to create any interface, then only create the interface if it does not already exist, otherwise simply configure it. See: https://serverfault.com/q/839430 Signed-off-by: Matoro Mahri matoro.tk> Signed-off-by: Robin H. Johnson gentoo.org> Closes: https://github.com/gentoo/netifrc/pull/43 net/dummy.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/net/dummy.sh b/net/dummy.sh index 091e08c..94437c3 100644 --- a/net/dummy.sh +++ b/net/dummy.sh @@ -25,12 +25,18 @@ dummy_pre_start() eval dummy="\$type_${IFVAR}" [ "${dummy}" = "dummy" ] || return 0 - ebegin "Creating dummy interface ${IFACE}" - if _ip link add name "${IFACE}" type dummy ; then - eend 0 && _up && set_interface_type dummy - else - eend 1 + if ! test -d /sys/module/dummy && ! modprobe dummy; then + eerror "Couldn't load the dummy module (perhaps the CONFIG_DUMMY kernel option is disabled)" + return 1 fi + + if ! _exists ; then + ebegin "Creating dummy interface ${IFACE}" + _ip link add name "${IFACE}" type dummy + eend $? + fi + + _up && set_interface_type dummy }