From patchwork Tue May 23 17:23:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 6914 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4QQh4k5kK0z3wls for ; Tue, 23 May 2023 17:24:06 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4QQh4k299Vz67K; Tue, 23 May 2023 17:24:06 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4QQh4k1Tszz302K; Tue, 23 May 2023 17:24:06 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4QQh4g3y6xz302K for ; Tue, 23 May 2023 17:24:03 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4QQh4g2grwz1V2; Tue, 23 May 2023 17:24:03 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1684862643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N7u0bJIlNLWekW7VTNnYHj6I5dd8Cfp5OhsyA61X6ys=; b=RZTtZGiXOAK2n7vSoR9+LLu7CaOz5Nb7sLu51nrTpG7gUoWhZyAPJQpFKzhlYau7Dpy8Ty 4cZCrx/RcvStpqBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1684862643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N7u0bJIlNLWekW7VTNnYHj6I5dd8Cfp5OhsyA61X6ys=; b=WTIlQfyEfrb012rWFVFhr5FTxhwFF60eX74AR5Idff8BtKnAGg5vlPWOjIDIDhbk7ZghIg UXZ3DwPsKw1u0MiDo+cmpgK9i+LTJ7tpgHndZrYFil9gSa9FG4wr0pVOkeOXvYgvYIpMNU 1g4AA7anMr5uOSBFYN+/w2f3RpArQAIbfW1ttL50x2w4hn0x4xTTzibz31CdqSdmBRaVi/ gbOBdNLEMrsyT8Z9Pdc50JyOcoyHeq4KcOilfqiRXzx3r9lE+awReb6yR3oxt7biwOB88A gTdbJFlobWl5k0fU7ygKs9aoUrvUNwbdShBEuakyjopw5M+0U1aUsWLZonSjFw== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [Patch RFC 15/15] network startup: Only work with configured zones Date: Tue, 23 May 2023 19:23:15 +0200 Message-Id: <20230523172314.7826-16-jonatan.schlag@ipfire.org> In-Reply-To: <20230523172314.7826-1-jonatan.schlag@ipfire.org> References: <20230523172314.7826-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Otherwise the called script fails with an failure message. This does not hurt but is ugly. I also changed my mind about the wording here. Because we only have four possible zones we could talk about valid zones. But I think it is easier and more future proof to talk about what is configured on the system. Should make further changes easier. Signed-off-by: Jonatan Schlag --- src/initscripts/system/network | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/initscripts/system/network b/src/initscripts/system/network index ff305e472..abbd5bd88 100644 --- a/src/initscripts/system/network +++ b/src/initscripts/system/network @@ -21,6 +21,8 @@ . /etc/sysconfig/rc . ${rc_functions} +. /etc/init.d/networking/functions.network + eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) DO="${1}" @@ -31,34 +33,37 @@ if ! [[ "${DO}" == "start" || "${DO}" == "restart" || "${DO}" == "stop" ]]; the exit 1 fi -declare -a VALID_ZONES +declare -a CONFIGURED_ZONES -VALID_ZONES+=("blue") -VALID_ZONES+=("green") -VALID_ZONES+=("orange") +for zone in blue green orange; do + if is_${zone}_used; then + CONFIGURED_ZONES+=("${zone}") + fi +done -# If we are called as /etc/init.d/network also red is a valid zone. -# Otherwise we are called as /etc/init.d/network-local where red -# is invalid. +# If we are called as /etc/init.d/network also red is a configured zone. +# Otherwise we are called as /etc/init.d/network-local where we do +# not need to take care of red if [[ "$(basename $0)" == "network" ]]; then - VALID_ZONES+=("red") + CONFIGURED_ZONES+=("red") fi declare -A ZONE_ACTION -for i in "${VALID_ZONES[@]}"; do +for i in "${CONFIGURED_ZONES[@]}"; do ZONE_ACTION[${i}]=false done if [ $# -eq 0 ]; then - for i in "${VALID_ZONES[@]}"; do - ZONE_ACTION[${i}]=true + for zone in "${CONFIGURED_ZONES[@]}"; do + ZONE_ACTION[${zone}]=true done fi + while [ $# -ne 0 ]; do ZONE_VALID=false - for i in "${VALID_ZONES[@]}"; do + for i in "${CONFIGURED_ZONES[@]}"; do if [ "${i}" == "${1}" ]; then ZONE_ACTION[${i}]=true ZONE_VALID=true @@ -68,7 +73,7 @@ while [ $# -ne 0 ]; do done if ! ${ZONE_VALID}; then - echo "'${1}' is not a valid zone. Cannot go on." + echo "'${1}' is not configured on this system. Cannot go on." exit 1 fi done @@ -76,14 +81,14 @@ done case "${DO}" in start) # Starting interfaces... - for i in "${VALID_ZONES[@]}"; do + for i in "${CONFIGURED_ZONES[@]}"; do ${ZONE_ACTION[${i}]} && /etc/rc.d/init.d/networking/${i} start done ;; stop) # Stopping interfaces... - for i in "${VALID_ZONES[@]}"; do + for i in "${CONFIGURED_ZONES[@]}"; do ${ZONE_ACTION[${i}]} && /etc/rc.d/init.d/networking/${i} stop done @@ -91,7 +96,7 @@ case "${DO}" in ;; restart) - for i in "${VALID_ZONES[@]}"; do + for i in "${CONFIGURED_ZONES[@]}"; do if ${ZONE_ACTION[${i}]}; then ARGS+=" ${i}" fi