From: Michael Tremer Date: Sun, 24 May 2009 14:53:50 +0000 (+0200) Subject: Moved networking files from initscript package to network package. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b994738307cdd32777e9318d5387feb6a5ecd2cb;p=ipfire-3.x.git Moved networking files from initscript package to network package. --- diff --git a/lfs/network b/lfs/network index c4bea37c2..146799451 100644 --- a/lfs/network +++ b/lfs/network @@ -39,7 +39,7 @@ CORE = yes EXTRA = no DEBUG = no BUILD_DEPS = -DEPS = initscripts +DEPS = URL = http://www.ipfire.org/ LICENSE = GPL3+ @@ -74,6 +74,8 @@ $(objects): $(OBJECT): $(objects) @$(PREBUILD) - install -m 755 -v $(DIR_APP)/network /usr/bin + install -m 755 -v $(DIR_APP)/network /sbin + -mkdir -pv /lib/network + cp -av $(DIR_APP)/lib/* /lib/network/ $(INSTALL_INITSCRIPT) @$(POSTBUILD) diff --git a/src/initscripts/networking/hooks/bridge-slave b/src/initscripts/networking/hooks/bridge-slave deleted file mode 100644 index 62ef54deb..000000000 --- a/src/initscripts/networking/hooks/bridge-slave +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -######################################################################## -# Begin $NETWORK_DEVICES/services/bridge-slave -# -# Description : Bridge Slave Script -# -# Authors : Michael Tremer - michael.tremer@ipfire.org -# -# Version : 00.00 -# -# Notes : This script adds a nic to a bridge. -# -######################################################################## - -. /lib/lsb/init-functions -[ -n "${CONFIG}" ] && . ${CONFIG} - -interface=${IFCONFIG##*/} - -. /etc/init.d/networking/functions - -case "${2}" in - up) - if ! device_exists ${BRIDGE}; then - MESSAGE="Bringing up bridge ${BRIDGE}..." - brctl addbr ${BRIDGE} || failed=1 - ip link set ${BRIDGE} up || failed=1 - (exit ${failed}) - evaluate_retval - fi - - MESSAGE="Adding slave interface ${interface} to the ${1} interface..." - brctl addif ${1} ${interface} - evaluate_retval - ;; - - down) - MESSAGE="Removing slave interface ${interface} from the ${1} interface..." - brctl delif ${1} ${interface} - evaluate_retval - ;; - - *) - echo "Usage: ${0} [interface] {up|down}" - exit 1 - ;; -esac - -# End $NETWORK_DEVICES/services/bridge-slave diff --git a/src/initscripts/networking/net-hotplug b/src/initscripts/networking/net-hotplug deleted file mode 100644 index 405eff231..000000000 --- a/src/initscripts/networking/net-hotplug +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -############################################################################### -# # -# IPFire.org - A linux based firewall # -# Copyright (C) 2007, 2008, 2009 Michael Tremer & Christian Schmidt # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -############################################################################### - -. /etc/init.d/networking/functions - -if [ "$INTERFACE" = "" ]; then - exit 1 -fi - -MAC=$(get_mac ${INTERFACE}) - -case $ACTION in - add|register) - # Don't do anything if the network is stopped - if [ -f /dev/.in_sysinit ] ; then - exit 0 - fi - if [ ! -f /var/lock/subsys/network ]; then - exit 0 - fi - case $INTERFACE in - # interfaces that are brought up as a part of configuration - ppp*|ippp*|isdn*|plip*|lo*|irda*|dummy*|ipsec*|tun*|tap*) - exit 0 - ;; - # interfaces that are registered then brought up - *) - export IN_HOTPLUG=1 - /etc/init.d/networking/port ${MAC} up - # XXX Walk through zones here? - ;; - esac - ;; - - remove|unregister) - case $INTERFACE in - # interfaces that are brought down as part of deconfiguration - ppp*|ippp*|isdn*|plip*|lo*|irda*|dummy*|ipsec*|tun*|tap*) - exit 0 - ;; - *) - export IN_HOTPLUG=1 - : # Nothing to do here at the moment - ;; - esac - ;; - - *) - exit 1 - ;; - -esac diff --git a/src/initscripts/networking/functions b/src/network/lib/functions similarity index 100% rename from src/initscripts/networking/functions rename to src/network/lib/functions diff --git a/src/initscripts/networking/hooks/bonding b/src/network/lib/hooks/bonding similarity index 100% rename from src/initscripts/networking/hooks/bonding rename to src/network/lib/hooks/bonding diff --git a/src/initscripts/networking/hooks/ethernet b/src/network/lib/hooks/ethernet similarity index 97% rename from src/initscripts/networking/hooks/ethernet rename to src/network/lib/hooks/ethernet index 392642092..085fad774 100644 --- a/src/initscripts/networking/hooks/ethernet +++ b/src/network/lib/hooks/ethernet @@ -13,7 +13,8 @@ ######################################################################## . /lib/lsb/init-functions -. /etc/init.d/networking/functions +. /lib/network/functions + [ -n "${CONFIG}" ] && . ${CONFIG} port=$(macify ${1}) diff --git a/src/initscripts/networking/hooks/ipv4-static b/src/network/lib/hooks/ipv4-static similarity index 87% rename from src/initscripts/networking/hooks/ipv4-static rename to src/network/lib/hooks/ipv4-static index 689932ffe..41e73eee6 100644 --- a/src/initscripts/networking/hooks/ipv4-static +++ b/src/network/lib/hooks/ipv4-static @@ -14,7 +14,8 @@ ######################################################################## . /lib/lsb/init-functions -. /etc/init.d/networking/functions +. /lib/network/functions + [ -n "${CONFIG}" ] && . ${CONFIG} zone=$2 @@ -94,23 +95,23 @@ case "${1}" in shift 2 while [ $# -gt 0 ]; do case "$1" in - --ip=) - IP=${2#--ip=} + --ip=*) + IP=${1#--ip=} ;; - --prefix=) - PREFIX=${2#--prefix=} + --prefix=*) + PREFIX=${1#--prefix=} ;; - --peer=) - PEER=${2#--peer=} + --peer=*) + PEER=${1#--peer=} ;; - --broadcast=) - BROADCAST=${2#--broadcast=} + --broadcast=*) + BROADCAST=${1#--broadcast=} ;; - --source=) - SOURCE=${2#--source=} + --source=*) + SOURCE=${1#--source=} ;; - --gateway=) - GATEWAY=${2#--gateway=} + --gateway=*) + GATEWAY=${1#--gateway=} ;; *) echo "Unknown option: $1" >&2 @@ -133,7 +134,7 @@ EOF ;; *) - echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]" + echo "Usage: ${0} {config|pre-up|post-up|pre-down|post-down|status} [interface]" exit 1 ;; esac diff --git a/src/initscripts/networking/hooks/ipv4-static-route b/src/network/lib/hooks/ipv4-static-route similarity index 98% rename from src/initscripts/networking/hooks/ipv4-static-route rename to src/network/lib/hooks/ipv4-static-route index 9daff1971..73386779d 100644 --- a/src/initscripts/networking/hooks/ipv4-static-route +++ b/src/network/lib/hooks/ipv4-static-route @@ -13,6 +13,8 @@ ######################################################################## . /lib/lsb/init-functions +. /lib/network/functions + [ -n "${CONFIG}" ] && . ${CONFIG} zone=$2 diff --git a/src/initscripts/networking/hooks/mtu b/src/network/lib/hooks/mtu similarity index 97% rename from src/initscripts/networking/hooks/mtu rename to src/network/lib/hooks/mtu index 99b1c9d92..2cbd039ab 100644 --- a/src/initscripts/networking/hooks/mtu +++ b/src/network/lib/hooks/mtu @@ -16,7 +16,8 @@ ######################################################################## . /lib/lsb/init-functions -. /etc/init.d/networking/functions +. /lib/network/functions + [ -n "${CONFIG}" ] && . ${CONFIG} function check_config() { diff --git a/src/initscripts/networking/hooks/stp b/src/network/lib/hooks/stp similarity index 97% rename from src/initscripts/networking/hooks/stp rename to src/network/lib/hooks/stp index ed128dd35..7b795edb2 100644 --- a/src/initscripts/networking/hooks/stp +++ b/src/network/lib/hooks/stp @@ -13,6 +13,8 @@ ######################################################################## . /lib/lsb/init-functions +. /lib/network/functions + [ -n "${CONFIG}" ] && . ${CONFIG} zone=$2 diff --git a/src/initscripts/networking/hooks/vlan b/src/network/lib/hooks/vlan similarity index 98% rename from src/initscripts/networking/hooks/vlan rename to src/network/lib/hooks/vlan index 3feaef976..cc61e398b 100644 --- a/src/initscripts/networking/hooks/vlan +++ b/src/network/lib/hooks/vlan @@ -13,7 +13,8 @@ ######################################################################## . /lib/lsb/init-functions -. /etc/init.d/networking/functions +. /lib/network/functions + [ -n "${CONFIG}" ] && . ${CONFIG} port=$(macify ${1}) diff --git a/src/initscripts/networking/port b/src/network/lib/port similarity index 98% rename from src/initscripts/networking/port rename to src/network/lib/port index 3fbd2bd6e..7bd56724b 100644 --- a/src/initscripts/networking/port +++ b/src/network/lib/port @@ -20,7 +20,7 @@ ############################################################################### . /lib/lsb/init-functions -. /etc/init.d/networking/functions +. /lib/network/functions port=$(macify $1) action=$2 diff --git a/src/initscripts/networking/zone b/src/network/lib/zone similarity index 98% rename from src/initscripts/networking/zone rename to src/network/lib/zone index ec194f8db..7a0fcce7d 100644 --- a/src/initscripts/networking/zone +++ b/src/network/lib/zone @@ -20,7 +20,7 @@ ############################################################################### . /lib/lsb/init-functions -. /etc/init.d/networking/functions +. /lib/network/functions zone=$1 action=$2 diff --git a/src/network/network b/src/network/network index 39091b192..462dcb93d 100644 --- a/src/network/network +++ b/src/network/network @@ -26,7 +26,7 @@ BOLD="\\033[1;39m" NORMAL="\\033[0;39m" ERROR="\\033[1;31m" -. /etc/init.d/networking/functions +. /lib/network/functions function usage() { echo -e "${BOLD}Usage $0${NORMAL}\n" @@ -98,7 +98,7 @@ function usage() { echo " Adds a port to a zone." echo echo " Requires a \"zone\" and \"port\"." - echo " Example: $0 zone addport green0" + echo " Example: $0 zone addport green0 black0" echo echo " You may also pass a hook and its parameters:" echo " $0 zone addport green0 black0 vlan 10" @@ -148,7 +148,7 @@ function decho() { } function vecho() { - verbose && echo -e "$@" >&2 + verbose && echo -e "$@" >&2 } function error() { @@ -157,14 +157,31 @@ function error() { } function _exit() { - if [ $1 -eq 0 ] && [ "$DO_RELOAD" = "1" ]; then + local code + local reload + + while [ $# -gt 0 ]; do + case "$1" in + --reload) + reload=1 + ;; + [0-9]*) + code=$1 + ;; + *) + error "Unrecognized argument: $1" + ;; + esac + shift + done + if [ ${reload} -eq 1 ]; then # Reloading network to apply changes immediately vecho "Reloading network settings..." cmd $0 $(verbose && echo "-v") $(debug && echo "-d") reload fi - decho "Exiting with code $1." - exit $1 + decho "Exiting with code ${code}." + exit ${code} } function cmd() { @@ -219,12 +236,12 @@ function port_add() { fi mkdir -p ${CONFIG_PORTS}/${port} 2>/dev/null - if [ -x "/etc/init.d/networking/hooks/${hook}" ]; then - ZONE=${zone} /etc/init.d/networking/hooks/${hook} ${port} add $@ + if [ -x "/lib/network/hooks/${hook}" ]; then + ZONE=${zone} /lib/network/hooks/${hook} ${port} add $@ RET=$? if [ "$RET" -eq "0" ]; then vecho "Successfully added port ${BOLD}${port}${NORMAL} (${hook} $@) to ${BOLD}${zone}${NORMAL}." - cmd /etc/init.d/networking/port ${port} up + cmd /lib/network/port ${port} up else error "Hook ${BOLD}${hook}${NORMAL} exited with $RET." return $RET @@ -233,7 +250,7 @@ function port_add() { error "Hook ${BOLD}${hook}${NORMAL} does not exist or is not executeable." return 1 fi - cmd /etc/init.d/networking/zone ${zone} up + cmd /lib/network/zone ${zone} up } function port_del() { @@ -250,9 +267,9 @@ function port_del() { decho "Function: port_del" decho " Zone: ${zone} Port: ${port} Hook: ${hook}" - if [ -x "/etc/init.d/networking/hooks/${hook}" ]; then - cmd /etc/init.d/networking/port ${port} down ## XXX How do we identify only that one hook? - ZONE=${zone} cmd /etc/init.d/networking/hooks/${hook} ${port} remove $@ + if [ -x "/lib/network/hooks/${hook}" ]; then + cmd /lib/network/port ${port} down ## XXX How do we identify only that one hook? + ZONE=${zone} cmd /lib/network/hooks/${hook} ${port} remove $@ RET=$? if [ "$RET" -eq "0" ]; then vecho "Successfully removed port ${BOLD}${port}${NORMAL} (${hook} $@) from ${BOLD}${zone}${NORMAL}." @@ -300,7 +317,7 @@ function zone_show() { local port for config in ${CONFIG_ZONES}/${zone}/port-*; do port=${config##*/}; port=${port#port-}; port=${port%%-*} - if ZONE=${zone} cmd /etc/init.d/networking/port ${port} attach ${config} &>/dev/null; then + if ZONE=${zone} cmd /lib/network/port ${port} attach ${config} &>/dev/null; then echo "# ${config#port-} is up" else echo "# ${config#port-} is down" @@ -321,7 +338,7 @@ function zone_add() { mkdir -p ${CONFIG_ZONES}/${zone} vecho "Successfully added zone ${zone}." - cmd /etc/init.d/networking/zone ${zone} up + cmd /lib/network/zone ${zone} up } function zone_del() { @@ -333,13 +350,11 @@ function zone_del() { return 1 fi - cmd /etc/init.d/networking/zone ${zone} down + cmd /lib/network/zone ${zone} down rm -rf ${CONFIG_ZONES}/${zone} vecho "Successfully removed zone ${zone}." } -DO_RELOAD=1 - # See what to do while [ "$#" -gt 0 ]; do arg=$1 @@ -365,7 +380,7 @@ while [ "$#" -gt 0 ]; do case "$arg" in show) port_show $@ - DO_RELOAD=0 _exit $? + _exit $? ;; help) usage port 0 @@ -378,33 +393,35 @@ while [ "$#" -gt 0 ]; do case "$arg" in add) zone_add $@ - _exit $? + _exit --reload $? ;; del) zone_del $@ - _exit $? + _exit --reload $? ;; show) zone_show $@ - DO_RELOAD=0 _exit $? + _exit $? ;; addport) port_add $@ - _exit $? + _exit --reload $? ;; delport) port_del $@ - _exit $? + _exit --reload $? ;; list) all_zones _exit $? ;; config) - zone=$1; shift - hook=$1; shift - if [ -x /etc/init.d/networking/hooks/${hook} ]; then - /etc/init.d/networking/hooks/${hook} config ${zone} $@ + zone=$1; hook=$2; shift 2 + if [ -z "${zone}" ] || [ -z "${hook}" ]; then + usage config + fi + if [ -x /lib/network/hooks/${hook} ]; then + /lib/network/hooks/${hook} config ${zone} $@ RET=$? else error "\"${hook}\" is not a known hook." @@ -412,12 +429,12 @@ while [ "$#" -gt 0 ]; do _exit $RET ;; help) - DO_RELOAD=0 usage zone 0 + usage zone 0 ;; esac ;; -*) - DO_RELOAD=0 error "Option \"$arg\" is not known." + error "Option \"$arg\" is not known." ;; esac done diff --git a/src/rootfiles/core/network b/src/rootfiles/core/network index ecc4cb922..8c1dded09 100644 --- a/src/rootfiles/core/network +++ b/src/rootfiles/core/network @@ -1,2 +1,13 @@ -etc/init.d/network -usr/bin/network +lib/network +lib/network/functions +lib/network/hooks +lib/network/hooks/bonding +lib/network/hooks/ethernet +lib/network/hooks/ipv4-static +lib/network/hooks/ipv4-static-route +lib/network/hooks/mtu +lib/network/hooks/stp +lib/network/hooks/vlan +lib/network/port +lib/network/zone +sbin/network