Message ID | 20230523172314.7826-5-jonatan.schlag@ipfire.org |
---|---|
State | Changes Requested |
Headers |
Return-Path: <development-bounces@lists.ipfire.org> 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 4QQh4Y3TvRz3wlf for <patchwork@web04.haj.ipfire.org>; Tue, 23 May 2023 17:23:57 +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 4QQh4X24lqz315; Tue, 23 May 2023 17:23:56 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4QQh4X1VzXz2ySG; Tue, 23 May 2023 17:23:56 +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 4QQh4V32XMz2ySG for <development@lists.ipfire.org>; Tue, 23 May 2023 17:23:54 +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 4QQh4V1nd2z4gy; Tue, 23 May 2023 17:23:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1684862634; 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=k6vUyLvBLOl2P1ze/IcGqig15OHuUHLx/C/GywljNZw=; b=LBge7Q7NT5opYUaZFfEADvQzu+kajtF6ZT+f/2UQsNQLjN+meSwSJvQZXPaztNn++bBcok h1XtQ6Sq6Ozyc86Ybq1CkmD+BSYSB+5t3SQf3WMcKsfSk9dug1bISN0b4uyUZSSyOHAhvp 2FpJUWHSp5PzfNKRdHO4MvzjjAsU7wENT6vKOZOKdTJR4G2eAMrQ04UFdfe41bfPoSf1eW h1oLGxASLHNtqGNyTMu4B9I70HH/zq+KQnLe0Yw1XMk4rWgLe4nQ/W6AvqXpPQQUOB76rd mFvwxWLB7qjGDpcdsFNL9U3SvRFKmR945Ck7H0YLu9pSTkOD10XEPvc1YZXooQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1684862634; 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=k6vUyLvBLOl2P1ze/IcGqig15OHuUHLx/C/GywljNZw=; b=U5yV7pqqfk5aubeYkWGtHvNDraxfvyhnKcKBcE20xHm7fQgOpZoQ+T7ExYRiSBVxj7pKbs pp9Oqk6O0fPvv8Bw== From: Jonatan Schlag <jonatan.schlag@ipfire.org> To: development@lists.ipfire.org Subject: [Patch RFC 04/15] network initscripts: check if the zone in the current config exists Date: Tue, 23 May 2023 19:23:04 +0200 Message-Id: <20230523172314.7826-5-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 Content-Transfer-Encoding: 8bit X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk <development.lists.ipfire.org> List-Unsubscribe: <https://lists.ipfire.org/mailman/options/development>, <mailto:development-request@lists.ipfire.org?subject=unsubscribe> List-Archive: <http://lists.ipfire.org/pipermail/development/> List-Post: <mailto:development@lists.ipfire.org> List-Help: <mailto:development-request@lists.ipfire.org?subject=help> List-Subscribe: <https://lists.ipfire.org/mailman/listinfo/development>, <mailto:development-request@lists.ipfire.org?subject=subscribe> Errors-To: development-bounces@lists.ipfire.org Sender: "Development" <development-bounces@lists.ipfire.org> |
Series |
[RFC,01/15] Remove ipsec interface creation from network startup
|
|
Commit Message
Jonatan Schlag
May 23, 2023, 5:23 p.m. UTC
We check in /etc/init.d/network if the current Configuration (RED+GREEN
or RED+GREEN+BLUE) contains the zone we want to start or stop.
We do this not in /etc/init.d/networking/green,blue,orange
As this checks make sense also there and as these scripts are called
form /etc/init.d/network I moved the check to these scripts.
As CONFIG_TYPE == 2 is unreadable I wrote functions to make things at least a
litte bit prettier.
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
src/initscripts/networking/any | 27 +++++++++++++++++---
src/initscripts/networking/functions.network | 12 +++++++++
src/initscripts/system/network | 16 ++++--------
3 files changed, 41 insertions(+), 14 deletions(-)
Comments
Hello, If you want to make this script better, why not give the zone name as a parameter? First of all it should be renamed to something like “local” (as in: not RED) and then you don’t have to use any symlinks and read back the script name like this: ZONE="$(basename $0)” Otherwise I agree with introducing unified functions that check whether we have GREEN/BLUE/ORANGE and have them in one function. We should then go through the entire code base and replace those calls first before we are introducing any new changes. I would prefer to give those function a “network_” prefix so that it becomes clear where this function is from and ideally shorten “is used” to just “have”. Like so: network_have_BLUE() and network_have_ORANGE(). Can we do that instead? -Michael > On 23 May 2023, at 18:23, Jonatan Schlag <jonatan.schlag@ipfire.org> wrote: > > We check in /etc/init.d/network if the current Configuration (RED+GREEN > or RED+GREEN+BLUE) contains the zone we want to start or stop. > We do this not in /etc/init.d/networking/green,blue,orange > > As this checks make sense also there and as these scripts are called > form /etc/init.d/network I moved the check to these scripts. > > As CONFIG_TYPE == 2 is unreadable I wrote functions to make things at least a > litte bit prettier. > > Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> > --- > src/initscripts/networking/any | 27 +++++++++++++++++--- > src/initscripts/networking/functions.network | 12 +++++++++ > src/initscripts/system/network | 16 ++++-------- > 3 files changed, 41 insertions(+), 14 deletions(-) > > diff --git a/src/initscripts/networking/any b/src/initscripts/networking/any > index dc4796e91..6dba5bef9 100644 > --- a/src/initscripts/networking/any > +++ b/src/initscripts/networking/any > @@ -21,23 +21,44 @@ > > . /etc/sysconfig/rc > . ${rc_functions} > +. /etc/init.d/networking/functions.network > + > eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) > > -if [ "$(basename $0)" == "green" ]; then > +ZONE="$(basename $0)" > + > + > +if [ "${ZONE}" == "green" ]; then > + if ! is_green_used; then > + boot_mesg "Green zone is not configured. No action can be taken on this zone." ${FAILURE} > + echo_failure > + exit 1 > + fi > + > DEVICE="${GREEN_DEV}" > ADDRESS="${GREEN_ADDRESS}" > NETADDRESS="${GREEN_NETADDRESS}" > NETMASK="${GREEN_NETMASK}" > DEVICE="${GREEN_DEV}" > MTU="${GREEN_MTU}" > -elif [ "$(basename $0)" == "blue" ]; then > +elif [ "${ZONE}" == "blue" ]; then > + if ! is_blue_used; then > + boot_mesg "Blue zone is not configured. No action can be taken on this zone." ${FAILURE} > + echo_failure > + exit 1 > + fi > DEVICE="${BLUE_DEV}" > ADDRESS="${BLUE_ADDRESS}" > NETADDRESS="${BLUE_NETADDRESS}" > NETMASK="${BLUE_NETMASK}" > DEVICE="${BLUE_DEV}" > MTU="${BLUE_MTU}" > -elif [ "$(basename $0)" == "orange" ]; then > +elif [ "${ZONE}" == "orange" ]; then > + if ! is_orange_used; then > + boot_mesg "Orange zone is not configured. No action can be taken on this zone." ${FAILURE} > + echo_failure > + exit 1 > + fi > DEVICE="${ORANGE_DEV}" > ADDRESS="${ORANGE_ADDRESS}" > NETADDRESS="${ORANGE_NETADDRESS}" > diff --git a/src/initscripts/networking/functions.network b/src/initscripts/networking/functions.network > index 4c7ad51d4..9cc4da24b 100644 > --- a/src/initscripts/networking/functions.network > +++ b/src/initscripts/networking/functions.network > @@ -285,3 +285,15 @@ qmi_assign_address() { > # Change the MAC address > ip link set "${intf}" address "${address}" > } > + > +is_blue_used() { > + [ "${CONFIG_TYPE}" = "3" ] || [ "${CONFIG_TYPE}" = "4" ] > +} > + > +is_green_used() { > + [ -n "${GREEN_DEV}" ] && [ -v "GREEN_DEV" ] > +} > + > +is_orange_used() { > + [ "${CONFIG_TYPE}" = "2" ] || [ "${CONFIG_TYPE}" = "4" ] > +} > diff --git a/src/initscripts/system/network b/src/initscripts/system/network > index 0d63b4e8b..fda16919d 100644 > --- a/src/initscripts/system/network > +++ b/src/initscripts/system/network > @@ -54,12 +54,10 @@ case "${DO}" in > [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green start > > # BLUE > - [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ] && \ > - /etc/rc.d/init.d/networking/blue start > + [ "$blue" == "1" ] && /etc/rc.d/init.d/networking/blue start > > # ORANGE > - [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "4" ] && \ > - /etc/rc.d/init.d/networking/orange start > + [ "$orange" == "1" ] && /etc/rc.d/init.d/networking/orange start > > # RED > if [ "$red" == "1" ]; then > @@ -87,18 +85,14 @@ case "${DO}" in > [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green stop > > # BLUE > - [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ] && \ > - /etc/rc.d/init.d/networking/blue stop > + [ "$blue" == "1" ] && /etc/rc.d/init.d/networking/blue stop > > # ORANGE > - [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "4" ] && \ > - /etc/rc.d/init.d/networking/orange stop > + [ "$orange" == "1" ] && /etc/rc.d/init.d/networking/orange stop > > # RED > if [ "$red" == "1" ]; then > - if [ "$CONFIG_TYPE" = "1" -o "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ]; then > - /etc/rc.d/init.d/networking/red stop > - fi > + /etc/rc.d/init.d/networking/red stop > fi > > exit 0 > -- > 2.30.2 >
Hi list, Am Mittwoch, dem 24.05.2023 um 10:00 +0100 schrieb Michael Tremer: > Hello, > > If you want to make this script better, why not give the zone name as > a parameter? > > First of all it should be renamed to something like “local” (as in: > not RED) and then you don’t have to use any symlinks and read back > the script name like this: > > ZONE="$(basename $0)” > I did not want to make such a big change, as people might rely on these files. But I am happy to create a script and delete the other scripts/links. I suggest as naming: /etc/init.d/networking/local Calling the script could look like: For one Zone /etc/init.d/networking/local start ${ZONE} /etc/init.d/networking/local stop ${ZONE} For all Zones /etc/init.d/networking/local start /etc/init.d/networking/local stop Look this fine to you? > Otherwise I agree with introducing unified functions that check > whether we have GREEN/BLUE/ORANGE and have them in one function. We > should then go through the entire code base and replace those calls > first before we are introducing any new changes. Ok, fine by me. > > I would prefer to give those function a “network_” prefix so that it > becomes clear where this function is from and ideally shorten “is > used” to just “have”. Like so: network_have_BLUE() and > network_have_ORANGE(). > > Can we do that instead? Yes, we can do that. I have only comments on the naming of the functions. I would like to reuse the naming style of the old ipfire-3.x networking code. So I would propose: network_zone_exists(ZONE) network_zones_get_all() network_zones_get_local() network_zones_get_nonlocal() As we all agreed on this naming some time ago, I think it faster to use these names instead of inventing new ones. Greetings Jonatan > > -Michael > > > On 23 May 2023, at 18:23, Jonatan Schlag > > <jonatan.schlag@ipfire.org> wrote: > > > > We check in /etc/init.d/network if the current Configuration > > (RED+GREEN > > or RED+GREEN+BLUE) contains the zone we want to start or stop. > > We do this not in /etc/init.d/networking/green,blue,orange > > > > As this checks make sense also there and as these scripts are > > called > > form /etc/init.d/network I moved the check to these scripts. > > > > As CONFIG_TYPE == 2 is unreadable I wrote functions to make things > > at least a > > litte bit prettier. > > > > Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> > > --- > > src/initscripts/networking/any | 27 > > +++++++++++++++++--- > > src/initscripts/networking/functions.network | 12 +++++++++ > > src/initscripts/system/network | 16 ++++-------- > > 3 files changed, 41 insertions(+), 14 deletions(-) > > > > diff --git a/src/initscripts/networking/any > > b/src/initscripts/networking/any > > index dc4796e91..6dba5bef9 100644 > > --- a/src/initscripts/networking/any > > +++ b/src/initscripts/networking/any > > @@ -21,23 +21,44 @@ > > > > . /etc/sysconfig/rc > > . ${rc_functions} > > +. /etc/init.d/networking/functions.network > > + > > eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) > > > > -if [ "$(basename $0)" == "green" ]; then > > +ZONE="$(basename $0)" > > + > > + > > +if [ "${ZONE}" == "green" ]; then > > + if ! is_green_used; then > > + boot_mesg "Green zone is not configured. No action can be taken > > on this zone." ${FAILURE} > > + echo_failure > > + exit 1 > > + fi > > + > > DEVICE="${GREEN_DEV}" > > ADDRESS="${GREEN_ADDRESS}" > > NETADDRESS="${GREEN_NETADDRESS}" > > NETMASK="${GREEN_NETMASK}" > > DEVICE="${GREEN_DEV}" > > MTU="${GREEN_MTU}" > > -elif [ "$(basename $0)" == "blue" ]; then > > +elif [ "${ZONE}" == "blue" ]; then > > + if ! is_blue_used; then > > + boot_mesg "Blue zone is not configured. No action can be taken on > > this zone." ${FAILURE} > > + echo_failure > > + exit 1 > > + fi > > DEVICE="${BLUE_DEV}" > > ADDRESS="${BLUE_ADDRESS}" > > NETADDRESS="${BLUE_NETADDRESS}" > > NETMASK="${BLUE_NETMASK}" > > DEVICE="${BLUE_DEV}" > > MTU="${BLUE_MTU}" > > -elif [ "$(basename $0)" == "orange" ]; then > > +elif [ "${ZONE}" == "orange" ]; then > > + if ! is_orange_used; then > > + boot_mesg "Orange zone is not configured. No action can be taken > > on this zone." ${FAILURE} > > + echo_failure > > + exit 1 > > + fi > > DEVICE="${ORANGE_DEV}" > > ADDRESS="${ORANGE_ADDRESS}" > > NETADDRESS="${ORANGE_NETADDRESS}" > > diff --git a/src/initscripts/networking/functions.network > > b/src/initscripts/networking/functions.network > > index 4c7ad51d4..9cc4da24b 100644 > > --- a/src/initscripts/networking/functions.network > > +++ b/src/initscripts/networking/functions.network > > @@ -285,3 +285,15 @@ qmi_assign_address() { > > # Change the MAC address > > ip link set "${intf}" address "${address}" > > } > > + > > +is_blue_used() { > > + [ "${CONFIG_TYPE}" = "3" ] || [ "${CONFIG_TYPE}" = "4" ] > > +} > > + > > +is_green_used() { > > + [ -n "${GREEN_DEV}" ] && [ -v "GREEN_DEV" ] > > +} > > + > > +is_orange_used() { > > + [ "${CONFIG_TYPE}" = "2" ] || [ "${CONFIG_TYPE}" = "4" ] > > +} > > diff --git a/src/initscripts/system/network > > b/src/initscripts/system/network > > index 0d63b4e8b..fda16919d 100644 > > --- a/src/initscripts/system/network > > +++ b/src/initscripts/system/network > > @@ -54,12 +54,10 @@ case "${DO}" in > > [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green start > > > > # BLUE > > - [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = > > "4" ] && \ > > - /etc/rc.d/init.d/networking/blue start > > + [ "$blue" == "1" ] && /etc/rc.d/init.d/networking/blue start > > > > # ORANGE > > - [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" > > = "4" ] && \ > > - /etc/rc.d/init.d/networking/orange start > > + [ "$orange" == "1" ] && /etc/rc.d/init.d/networking/orange start > > > > # RED > > if [ "$red" == "1" ]; then > > @@ -87,18 +85,14 @@ case "${DO}" in > > [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green stop > > > > # BLUE > > - [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = > > "4" ] && \ > > - /etc/rc.d/init.d/networking/blue stop > > + [ "$blue" == "1" ] && /etc/rc.d/init.d/networking/blue stop > > > > # ORANGE > > - [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" > > = "4" ] && \ > > - /etc/rc.d/init.d/networking/orange stop > > + [ "$orange" == "1" ] && /etc/rc.d/init.d/networking/orange stop > > > > # RED > > if [ "$red" == "1" ]; then > > - if [ "$CONFIG_TYPE" = "1" -o "$CONFIG_TYPE" = "2" -o > > "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ]; then > > - /etc/rc.d/init.d/networking/red stop > > - fi > > + /etc/rc.d/init.d/networking/red stop > > fi > > > > exit 0 > > -- > > 2.30.2 > > >
Hello, > On 18 Aug 2023, at 13:55, Jonatan Schlag <jonatan.schlag@ipfire.org> wrote: > > Hi list, > > Am Mittwoch, dem 24.05.2023 um 10:00 +0100 schrieb Michael Tremer: >> Hello, >> >> If you want to make this script better, why not give the zone name as >> a parameter? >> >> First of all it should be renamed to something like “local” (as in: >> not RED) and then you don’t have to use any symlinks and read back >> the script name like this: >> >> ZONE="$(basename $0)” >> > > I did not want to make such a big change, as people might rely on these > files. But I am happy to create a script and delete the other > scripts/links. I suggest as naming: > > /etc/init.d/networking/local > > Calling the script could look like: > > For one Zone > > /etc/init.d/networking/local start ${ZONE} > /etc/init.d/networking/local stop ${ZONE} > > For all Zones > > /etc/init.d/networking/local start > /etc/init.d/networking/local stop > > Look this fine to you? This looks good to me. >> Otherwise I agree with introducing unified functions that check >> whether we have GREEN/BLUE/ORANGE and have them in one function. We >> should then go through the entire code base and replace those calls >> first before we are introducing any new changes. > > Ok, fine by me. >> >> I would prefer to give those function a “network_” prefix so that it >> becomes clear where this function is from and ideally shorten “is >> used” to just “have”. Like so: network_have_BLUE() and >> network_have_ORANGE(). >> >> Can we do that instead? > > > Yes, we can do that. I have only comments on the naming of the > functions. I would like to reuse the naming style of the old ipfire-3.x > networking code. So I would propose: > > network_zone_exists(ZONE) > > network_zones_get_all() > > network_zones_get_local() > > network_zones_get_nonlocal() > > > As we all agreed on this naming some time ago, I think it faster to use > these names instead of inventing new ones. Also okay for me. Best, -Michael > > Greetings Jonatan >> >> -Michael >> >>> On 23 May 2023, at 18:23, Jonatan Schlag >>> <jonatan.schlag@ipfire.org> wrote: >>> >>> We check in /etc/init.d/network if the current Configuration >>> (RED+GREEN >>> or RED+GREEN+BLUE) contains the zone we want to start or stop. >>> We do this not in /etc/init.d/networking/green,blue,orange >>> >>> As this checks make sense also there and as these scripts are >>> called >>> form /etc/init.d/network I moved the check to these scripts. >>> >>> As CONFIG_TYPE == 2 is unreadable I wrote functions to make things >>> at least a >>> litte bit prettier. >>> >>> Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> >>> --- >>> src/initscripts/networking/any | 27 >>> +++++++++++++++++--- >>> src/initscripts/networking/functions.network | 12 +++++++++ >>> src/initscripts/system/network | 16 ++++-------- >>> 3 files changed, 41 insertions(+), 14 deletions(-) >>> >>> diff --git a/src/initscripts/networking/any >>> b/src/initscripts/networking/any >>> index dc4796e91..6dba5bef9 100644 >>> --- a/src/initscripts/networking/any >>> +++ b/src/initscripts/networking/any >>> @@ -21,23 +21,44 @@ >>> >>> . /etc/sysconfig/rc >>> . ${rc_functions} >>> +. /etc/init.d/networking/functions.network >>> + >>> eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) >>> >>> -if [ "$(basename $0)" == "green" ]; then >>> +ZONE="$(basename $0)" >>> + >>> + >>> +if [ "${ZONE}" == "green" ]; then >>> + if ! is_green_used; then >>> + boot_mesg "Green zone is not configured. No action can be taken >>> on this zone." ${FAILURE} >>> + echo_failure >>> + exit 1 >>> + fi >>> + >>> DEVICE="${GREEN_DEV}" >>> ADDRESS="${GREEN_ADDRESS}" >>> NETADDRESS="${GREEN_NETADDRESS}" >>> NETMASK="${GREEN_NETMASK}" >>> DEVICE="${GREEN_DEV}" >>> MTU="${GREEN_MTU}" >>> -elif [ "$(basename $0)" == "blue" ]; then >>> +elif [ "${ZONE}" == "blue" ]; then >>> + if ! is_blue_used; then >>> + boot_mesg "Blue zone is not configured. No action can be taken on >>> this zone." ${FAILURE} >>> + echo_failure >>> + exit 1 >>> + fi >>> DEVICE="${BLUE_DEV}" >>> ADDRESS="${BLUE_ADDRESS}" >>> NETADDRESS="${BLUE_NETADDRESS}" >>> NETMASK="${BLUE_NETMASK}" >>> DEVICE="${BLUE_DEV}" >>> MTU="${BLUE_MTU}" >>> -elif [ "$(basename $0)" == "orange" ]; then >>> +elif [ "${ZONE}" == "orange" ]; then >>> + if ! is_orange_used; then >>> + boot_mesg "Orange zone is not configured. No action can be taken >>> on this zone." ${FAILURE} >>> + echo_failure >>> + exit 1 >>> + fi >>> DEVICE="${ORANGE_DEV}" >>> ADDRESS="${ORANGE_ADDRESS}" >>> NETADDRESS="${ORANGE_NETADDRESS}" >>> diff --git a/src/initscripts/networking/functions.network >>> b/src/initscripts/networking/functions.network >>> index 4c7ad51d4..9cc4da24b 100644 >>> --- a/src/initscripts/networking/functions.network >>> +++ b/src/initscripts/networking/functions.network >>> @@ -285,3 +285,15 @@ qmi_assign_address() { >>> # Change the MAC address >>> ip link set "${intf}" address "${address}" >>> } >>> + >>> +is_blue_used() { >>> + [ "${CONFIG_TYPE}" = "3" ] || [ "${CONFIG_TYPE}" = "4" ] >>> +} >>> + >>> +is_green_used() { >>> + [ -n "${GREEN_DEV}" ] && [ -v "GREEN_DEV" ] >>> +} >>> + >>> +is_orange_used() { >>> + [ "${CONFIG_TYPE}" = "2" ] || [ "${CONFIG_TYPE}" = "4" ] >>> +} >>> diff --git a/src/initscripts/system/network >>> b/src/initscripts/system/network >>> index 0d63b4e8b..fda16919d 100644 >>> --- a/src/initscripts/system/network >>> +++ b/src/initscripts/system/network >>> @@ -54,12 +54,10 @@ case "${DO}" in >>> [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green start >>> >>> # BLUE >>> - [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = >>> "4" ] && \ >>> - /etc/rc.d/init.d/networking/blue start >>> + [ "$blue" == "1" ] && /etc/rc.d/init.d/networking/blue start >>> >>> # ORANGE >>> - [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" >>> = "4" ] && \ >>> - /etc/rc.d/init.d/networking/orange start >>> + [ "$orange" == "1" ] && /etc/rc.d/init.d/networking/orange start >>> >>> # RED >>> if [ "$red" == "1" ]; then >>> @@ -87,18 +85,14 @@ case "${DO}" in >>> [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green stop >>> >>> # BLUE >>> - [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = >>> "4" ] && \ >>> - /etc/rc.d/init.d/networking/blue stop >>> + [ "$blue" == "1" ] && /etc/rc.d/init.d/networking/blue stop >>> >>> # ORANGE >>> - [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" >>> = "4" ] && \ >>> - /etc/rc.d/init.d/networking/orange stop >>> + [ "$orange" == "1" ] && /etc/rc.d/init.d/networking/orange stop >>> >>> # RED >>> if [ "$red" == "1" ]; then >>> - if [ "$CONFIG_TYPE" = "1" -o "$CONFIG_TYPE" = "2" -o >>> "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ]; then >>> - /etc/rc.d/init.d/networking/red stop >>> - fi >>> + /etc/rc.d/init.d/networking/red stop >>> fi >>> >>> exit 0 >>> -- >>> 2.30.2 >>> >> > >
diff --git a/src/initscripts/networking/any b/src/initscripts/networking/any index dc4796e91..6dba5bef9 100644 --- a/src/initscripts/networking/any +++ b/src/initscripts/networking/any @@ -21,23 +21,44 @@ . /etc/sysconfig/rc . ${rc_functions} +. /etc/init.d/networking/functions.network + eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) -if [ "$(basename $0)" == "green" ]; then +ZONE="$(basename $0)" + + +if [ "${ZONE}" == "green" ]; then + if ! is_green_used; then + boot_mesg "Green zone is not configured. No action can be taken on this zone." ${FAILURE} + echo_failure + exit 1 + fi + DEVICE="${GREEN_DEV}" ADDRESS="${GREEN_ADDRESS}" NETADDRESS="${GREEN_NETADDRESS}" NETMASK="${GREEN_NETMASK}" DEVICE="${GREEN_DEV}" MTU="${GREEN_MTU}" -elif [ "$(basename $0)" == "blue" ]; then +elif [ "${ZONE}" == "blue" ]; then + if ! is_blue_used; then + boot_mesg "Blue zone is not configured. No action can be taken on this zone." ${FAILURE} + echo_failure + exit 1 + fi DEVICE="${BLUE_DEV}" ADDRESS="${BLUE_ADDRESS}" NETADDRESS="${BLUE_NETADDRESS}" NETMASK="${BLUE_NETMASK}" DEVICE="${BLUE_DEV}" MTU="${BLUE_MTU}" -elif [ "$(basename $0)" == "orange" ]; then +elif [ "${ZONE}" == "orange" ]; then + if ! is_orange_used; then + boot_mesg "Orange zone is not configured. No action can be taken on this zone." ${FAILURE} + echo_failure + exit 1 + fi DEVICE="${ORANGE_DEV}" ADDRESS="${ORANGE_ADDRESS}" NETADDRESS="${ORANGE_NETADDRESS}" diff --git a/src/initscripts/networking/functions.network b/src/initscripts/networking/functions.network index 4c7ad51d4..9cc4da24b 100644 --- a/src/initscripts/networking/functions.network +++ b/src/initscripts/networking/functions.network @@ -285,3 +285,15 @@ qmi_assign_address() { # Change the MAC address ip link set "${intf}" address "${address}" } + +is_blue_used() { + [ "${CONFIG_TYPE}" = "3" ] || [ "${CONFIG_TYPE}" = "4" ] +} + +is_green_used() { + [ -n "${GREEN_DEV}" ] && [ -v "GREEN_DEV" ] +} + +is_orange_used() { + [ "${CONFIG_TYPE}" = "2" ] || [ "${CONFIG_TYPE}" = "4" ] +} diff --git a/src/initscripts/system/network b/src/initscripts/system/network index 0d63b4e8b..fda16919d 100644 --- a/src/initscripts/system/network +++ b/src/initscripts/system/network @@ -54,12 +54,10 @@ case "${DO}" in [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green start # BLUE - [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ] && \ - /etc/rc.d/init.d/networking/blue start + [ "$blue" == "1" ] && /etc/rc.d/init.d/networking/blue start # ORANGE - [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "4" ] && \ - /etc/rc.d/init.d/networking/orange start + [ "$orange" == "1" ] && /etc/rc.d/init.d/networking/orange start # RED if [ "$red" == "1" ]; then @@ -87,18 +85,14 @@ case "${DO}" in [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green stop # BLUE - [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ] && \ - /etc/rc.d/init.d/networking/blue stop + [ "$blue" == "1" ] && /etc/rc.d/init.d/networking/blue stop # ORANGE - [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "4" ] && \ - /etc/rc.d/init.d/networking/orange stop + [ "$orange" == "1" ] && /etc/rc.d/init.d/networking/orange stop # RED if [ "$red" == "1" ]; then - if [ "$CONFIG_TYPE" = "1" -o "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ]; then - /etc/rc.d/init.d/networking/red stop - fi + /etc/rc.d/init.d/networking/red stop fi exit 0