]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
I worked on that stupid networking stuff...
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Mar 2009 20:55:52 +0000 (21:55 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Mar 2009 20:55:52 +0000 (21:55 +0100)
Don't expect that this works, but I wanted to commit it.

18 files changed:
src/initscripts/core/network
src/initscripts/networking/brdown [deleted file]
src/initscripts/networking/brup [deleted file]
src/initscripts/networking/functions
src/initscripts/networking/hooks/bridge-slave
src/initscripts/networking/hooks/ethernet
src/initscripts/networking/hooks/ipv4-static
src/initscripts/networking/hooks/ipv4-static-route
src/initscripts/networking/hooks/stp
src/initscripts/networking/hooks/vlan
src/initscripts/networking/ifdown [deleted file]
src/initscripts/networking/ifup [deleted file]
src/initscripts/networking/port [new file with mode: 0644]
src/initscripts/networking/zone [new file with mode: 0644]
src/initscripts/sysconfig/network
src/network/network
src/rootfiles/core/initscripts
src/rootfiles/core/stage3

index 2cc3a06979a01f1d289681f06136b8218ebdab9d..9f42d1c3a76fdd1ecce8180e61b667a780af7255 100644 (file)
 ### END INIT INFO
 
 . /lib/lsb/init-functions
-. /etc/sysconfig/network
+. /etc/init.d/networking/functions
 
 case "${1}" in
        start)
                # Start all network interfaces
-               for file in $(find ${NETWORK_DEVICES} -maxdepth 1); do
-                       interface=${file##*/}
-
-                       if [ -d "${file}" ] || [ -n "${interface}" ]; then
-                               continue
-                       fi
-
-                       IN_BOOT=1 ${NETWORK_SCRIPTS}/brup ${interface}
+               for zone in $(find ${CONFIG_ZONES}/ -maxdepth 1); do
+                       [ -d "${zone}" ] || continue
+                       IN_BOOT=1 /etc/init.d/networking/zone ${zone##*/} up
                done
                touch /var/lock/subsys/network
                ;;
 
        stop)
-               # Reverse list
-               FILES=""
-               for file in $(find ${NETWORK_DEVICES} -maxdepth 1); do
-                       interface=${file##*/}
-
-                       if [ -d "${file}" ] || [ -n "${interface}" ]; then
-                               continue
-                       fi
-                       FILES="${file} ${FILES}"
-               done
-
                # Stop all network interfaces
-               for file in ${FILES}
-               do
-                       interface=${file##*/}
-
-                       IN_BOOT=1 ${NETWORK_SCRIPTS}/brdown ${interface}
+               for zone in $(find ${CONFIG_ZONES}/ -maxdepth 1); do
+                       [ -d "${zone}" ] || continue
+                       IN_BOOT=1 /etc/init.d/networking/zone ${zone##*/} down
                done
                rm -f /var/lock/subsys/network
                ;;
diff --git a/src/initscripts/networking/brdown b/src/initscripts/networking/brdown
deleted file mode 100644 (file)
index 68a005f..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/sh
-########################################################################
-# Begin $NETWORK_DEVICES/brdown
-#
-# Description : Bridge Down
-#
-# Authors     : Michael Tremer - michael.tremer@ipfire.org
-#
-# Version     : 00.00
-#
-# Notes       : This script removes the created bridge, removes 
-#               all child interface from it and then
-#               the IFCONFIG variable is passed to the scripts found
-#               in the services directory, to indicate what file the
-#               service should source to get environmental variables.
-#
-########################################################################
-
-. /lib/lsb/init-functions
-
-message="Bringing down the ${1} interface..."
-
-# Collect a list of configuration files for our interface
-if [ -n "${2}" ]; then
-       for file in ${@#$1} # All parameters except $1
-       do
-               FILES="${FILES} ${NETWORK_DEVICES}/${1}/${file}"
-       done
-elif [ -d "${NETWORK_DEVICES}/${1}" ]; then
-       FILES=`echo ${NETWORK_DEVICES}/${1}/*`
-else 
-       FILES="${NETWORK_DEVICES}/${1}"
-fi
-
-# Reverse the order configuration files are processed in
-for file in ${FILES}; do
-       # skip backup files
-       if [ "${file}" != "${file%""~""}" ]; then
-               continue
-       fi
-
-       # place interfaces at last position
-       if [[ "${file}" =~ "^[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]$" ]]; then
-               FILES2="${FILES2} ${file}"
-               continue
-       fi
-
-       # append the rest
-       FILES2="${file} ${FILES2}"
-done
-FILES=${FILES2}
-
-# Process each configuration file
-export BRIDGE_DOWN=1
-for file in ${FILES}; do
-       if [ ! -f "${file}" ]; then
-               log_warning_msg
-               message="${file} is not a network configuration file or directory."
-               log_warning_msg
-       fi
-       /etc/init.d/networking/ifdown ${file}
-done
-
-if [ -z "${2}" ]; then
-       # Check if bridge already exists
-       bridge_status=`brctl show 2>/dev/null`
-       if echo "${bridge_status}" | grep -q "^${1}"; then
-               # Create and bring up the bridge
-               ip link set ${1} down || failed=1
-               brctl delbr ${1} || failed=1
-               (exit ${failed})
-               evaluate_retval standard
-       fi
-fi
-
-# End $NETWORK_DEVICES/brdown
diff --git a/src/initscripts/networking/brup b/src/initscripts/networking/brup
deleted file mode 100644 (file)
index 03afe72..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/sh
-########################################################################
-# Begin $NETWORK_DEVICES/brup
-#
-# Description : Bridge Up
-#
-# Authors     : Michael Tremer - michael.tremer@ipfire.org
-#
-# Version     : 00.00
-#
-# Notes       : This script creates a bridge with a given name.
-#               Then all required interfaces are added to the brige and
-#               the IFCONFIG variable is passed to the scripts found
-#               in the services directory, to indicate what file the
-#               service should source to get environmental variables.
-#
-########################################################################
-
-. /lib/lsb/init-functions
-
-message="Bringing up ${1} interface..."
-
-# Collect a list of configuration files for our interface
-if [ -n "${2}" ]; then
-       for file in ${@#$1} # All parameters except $1
-       do
-               FILES="${FILES} ${NETWORK_DEVICES}/${1}/${file}"
-       done
-elif [ -d "${NETWORK_DEVICES}/${1}" ]; then
-       FILES=`echo ${NETWORK_DEVICES}/${1}/*`
-else 
-       FILES="${NETWORK_DEVICES}/${1}"
-fi
-
-# Sort files
-for file in ${FILES}; do
-       # skip backup files
-       if [ "${file}" != "${file%""~""}" ]; then
-               continue
-       fi
-
-       # place interfaces at first position
-       if [[ "${file}" =~ "^[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]$" ]]; then
-               FILES2="${file} ${FILES2}"
-               continue
-       fi
-
-       # append the rest
-       FILES2="${FILES2} ${file}"
-done
-FILES=${FILES2}
-
-# Check if bridge already exists
-bridge_status=`brctl show 2>/dev/null`
-if ! echo "${bridge_status}" | grep -q "^${1}"; then
-       # Create and bring up the bridge
-       brctl addbr ${1} || failed=1
-       ip link set ${1} up || failed=1
-       (exit ${failed})
-       evaluate_retval standard
-else
-       log_warning_msg
-       message="Bridge does already exist."
-       log_warning_msg
-fi
-
-# Process each configuration file
-export BRIDGE_UP=1
-for file in ${FILES}; do
-       if [ ! -f "${file}" ]; then
-               log_warning_msg
-               message="${file} is not a network configuration file or directory."
-               log_warning_msg
-       fi
-       /etc/init.d/networking/ifup ${file}
-done
index ee65e3c63539dadfab200617792286ee4c5442f4..5dd1bec52a79993d05f6c208ec3bf37cd51b93da 100644 (file)
 #                                                                             #
 ###############################################################################
 
-[ -f "/etc/sysconfig/network" ] && . /etc/sysconfig/network
+CONFIG_DIR=/etc/sysconfig/networking
+
+CONFIG_ZONES=${CONFIG_DIR}/zones
+CONFIG_PORTS=${CONFIG_DIR}/ports
 
 function is_mac() {
-       egrep "^[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]$" <<<$1
+       egrep -q "^[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]$" <<<$1
 }
 
 function get_device_by_mac() {
-       local mac=$1
+       local mac
+       local i
+
+       mac=$1
+
        for i in /sys/class/net/*; do
                if [ "$(cat $i/address)" = "$mac" ]; then
-                       echo $(basename $i)
+                       grep -q "^${i##*/}" /proc/net/vlan/config 2>/dev/null && continue
+                       echo ${i##*/}
+                       break
                fi
        done
 }
 
+function get_device_by_mac_and_vid() {
+       local mac
+       local vid
+
+       mac=$1
+       vid=$2
+
+       local i
+       local VID
+       local DEVICE
+       for i in $(cat /proc/net/vlan/config 2>/dev/null); do
+               awk -F'|' '{ print $2 $3 }' | read DEVICE VID PARENT
+               if [ -n "${VID}" ] || [ -n "${DEVICE}" ]; then
+                       continue
+               fi
+               if [ "${vid}" = "${VID}" ] && [ "$(macify ${PARENT})" = "${mac}" ]; then
+                       echo "${DEVICE}"
+                       return 0
+               fi
+       done
+       return 1
+}
+
 function get_mac_by_device() {
-       local device=$1
+       local device
+       device=$1
        if [ -d "/sys/class/net/$device" ]; then
                cat /sys/class/net/$device/address
                return 0
@@ -43,8 +76,51 @@ function get_mac_by_device() {
        return 1
 }
 
+function devicify() {
+       local device
+       local mac
+
+       device=$1
+
+       if is_mac ${device}; then
+               mac=${device}
+               device=$(get_device_by_mac ${device})
+       fi
+       echo ${device}
+}
+
+function macify() {
+       local input
+       local mac
+       
+       input=$1
+       
+       if is_mac ${input}; then
+               mac=${input}
+       else
+               mac=$(get_mac_by_device ${input})
+       fi
+       echo ${mac}
+}
+
 function device_exists() {
-       ip link show ${1} &>/dev/null
+       ip link show $(devicify ${1}) &>/dev/null
+}
+
+function rename_device() {
+       local source
+       local destination
+       
+       source=$1
+       destination=$2
+
+       # Check if devices exist
+       if ! device_exists ${source} || device_exists ${destination}; then
+               return 4
+       fi
+
+       ip link set ${source} name ${destination}
+       return $?
 }
 
 function zone_exists() {
@@ -52,5 +128,19 @@ function zone_exists() {
 }
 
 function bridge_devices() {
-       : #TODO
+       local bridge
+       bridge=$1
+       [ -z "${bridge}" ] && return 2
+       brctl show | grep "^${bridge}" | awk '{ print $NF }' | grep -v "^interfaces$"
+}
+
+function zone_add_port() {
+       brctl addif ${1} ${2}
+}
+
+function all_zones() {
+       local zone
+       for zone in ${CONFIG_ZONES}/*; do
+               [ -d "${zone}" ] && echo ${zone}
+       done
 }
index 16b9eb7e28bc92128805fe065eba979f33b81e38..62ef54deb5c3e051cfb60a478bec26a767750e3c 100644 (file)
@@ -13,7 +13,7 @@
 ########################################################################
 
 . /lib/lsb/init-functions
-. ${IFCONFIG}
+[ -n "${CONFIG}" ] && . ${CONFIG}
 
 interface=${IFCONFIG##*/}
 
index ca247be6bd35275906482f93bc01b5d074e536b0..72842d16598fc696a3f1025efbdf24e6a9b1db23 100644 (file)
 ########################################################################
 
 . /lib/lsb/init-functions
-. ${CONFIG}
+. /etc/init.d/networking/functions
+[ -n "${CONFIG}" ] && . ${CONFIG}
+
+port=$(macify ${1})
 
 case "${2}" in
        up)
@@ -24,8 +27,22 @@ case "${2}" in
                : # Do nothing
        ;;
 
+       add)
+               cat <<EOF > ${CONFIG_PORTS}/${port}/ethernet
+HOOK=ethernet
+EOF
+               ln -sf ${CONFIG_PORTS}/${port}/ethernet \
+                       ${CONFIG_ZONES}/${ZONE}/port-${port}-ethernet
+       ;;
+
+       remove)
+               rm -f \
+                       ${CONFIG_ZONES}/${ZONE}/port-${port}-ethernet \
+                       ${CONFIG_PORTS}/${port}/ethernet
+       ;;
+
        *)
-               echo "Usage: ${0} [interface] {up|down}"
+               echo "Usage: ${0} [interface] {up|down|add|remove}"
                exit 1
        ;;
 esac
index 417d22de6c47ac65f19fc0223898fb2419b1f849..1a192764fe982fc0477382810ca4b884bc67d420 100644 (file)
@@ -14,7 +14,7 @@
 ########################################################################
 
 . /lib/lsb/init-functions
-. ${IFCONFIG}
+[ -n "${CONFIG}" ] && . ${CONFIG}
 
 if [ -z "${IP}" ]; then
        log_failure_msg "IP variable missing from ${IFCONFIG}, cannot continue."
index 4205a022db774c1ddb76a4ebd3c8d2d58a62cbd9..7dc90fe9f9b2158a99995edbb270ac909105397c 100644 (file)
@@ -13,7 +13,7 @@
 ########################################################################
 
 . /lib/lsb/init-functions
-. ${IFCONFIG}
+[ -n "${CONFIG}" ] && . ${CONFIG}
 
 case "${TYPE}" in
        ("" | "network")
index ee294fc15a5ab5ca3160cd817333e3a1b61cceda..9e87e4a85be676470b3a33800588e37a0d3c5501 100644 (file)
@@ -13,7 +13,7 @@
 ########################################################################
 
 . /lib/lsb/init-functions
-. ${IFCONFIG}
+[ -n "${CONFIG}" ] && . ${CONFIG}
 
 case "${2}" in
        up)
index 43420ef7042e64c390d86f7a510be684abd45ea0..907c72f0d3e1cfff131720fc8f5646ce297b9725 100644 (file)
 ########################################################################
 
 . /lib/lsb/init-functions
-. ${CONFIG}
+. /etc/init.d/networking/functions
+[ -n "${CONFIG}" ] && . ${CONFIG}
+
+port=$(macify ${1})
+device=$(devicify ${port})
 
 case "${2}" in
        up)
                modprobe 8021q
-               MESSAGE="Adding VLAN ${ID} to interface ${1}..."
-               vconfig add ${1} ${ID} &>/dev/null
+               MESSAGE="Adding VLAN ${ID} to port ${port}..."
+               vconfig add ${device} ${ID} &>/dev/null
                evaluate_retval
        ;;
 
        down)
-               MESSAGE="Removing VLAN ${ID} from interface ${1}..."
-               vconfig rem ${1} ${ID} &>/dev/null
+               MESSAGE="Removing VLAN ${ID} from port ${port}..."
+               vconfig rem ${device} ${ID} &>/dev/null
                evaluate_retval
        ;;
 
+       add)
+               ID=$3
+               cat <<EOF > ${CONFIG_PORTS}/${port}/vlan-${ID}
+HOOK=vlan
+ID=${ID}
+EOF
+               ln -sf ${CONFIG_PORTS}/${port}/vlan-${ID} \
+                       ${CONFIG_ZONES}/${ZONE}/port-${port}-vlan-${ID}
+       ;;
+
+       remove)
+               rm -f \
+                       ${CONFIG_PORTS}/${port}/vlan-${ID} \
+                       ${CONFIG_ZONES}/${ZONE}/port-${port}-vlan-${ID}
+       ;;
+
        *)
-               echo "Usage: ${0} [interface] {up|down}"
+               echo "Usage: ${0} [interface] {up|down|add|remove}"
                exit 1
        ;;
 esac
diff --git a/src/initscripts/networking/ifdown b/src/initscripts/networking/ifdown
deleted file mode 100644 (file)
index fe9258e..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/sh
-########################################################################
-# Begin $NETWORK_DEVICES/ifdown
-#
-# Description : Interface Down
-#
-# Authors     : Michael Tremer - michael.tremer@ipfire.org
-#
-# Version     : 00.00
-#
-# Notes       : This script brings up the configuration of each interface.
-#               It handles some dependencies.
-#
-########################################################################
-
-. /lib/lsb/init-functions
-
-file=${1}
-
-if [ ! -f "${file}" ]; then
-       message="Unable to process ${file}. File does not exist."
-       log_failure_msg
-       exit 1
-fi
-
-. ${file}
-
-if [ -n "${SERVICE}" -a -x "${NETWORK_SCRIPTS}/services/${SERVICE}" ]; then
-       IFCONFIG=${file} ${NETWORK_SCRIPTS}/services/${SERVICE} ${1} down
-else
-       echo -e "${FAILURE}Unable to process ${file}.  Either"
-       echo -e "${FAILURE}the SERVICE variable was not set,"
-       echo -e "${FAILURE}or the specified service cannot be executed."
-       message=""
-       log_failure_msg
-fi
-
-# XXX We must check if a bridge has no devices left.
-
-# End $NETWORK_DEVICES/ifdown
diff --git a/src/initscripts/networking/ifup b/src/initscripts/networking/ifup
deleted file mode 100644 (file)
index 092d13a..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/sh
-########################################################################
-# Begin $NETWORK_DEVICES/ifup
-#
-# Description : Interface Up
-#
-# Authors     : Michael Tremer - michael.tremer@ipfire.org
-#
-# Version     : 00.00
-#
-# Notes       : This script brings up the configuration of each interface.
-#               It handles some dependencies.
-#
-########################################################################
-
-. /lib/lsb/init-functions
-
-file=${1}
-
-if [ ! -f "${file}" ]; then
-       message="Unable to process ${file}. File does not exist."
-       log_failure_msg
-       exit 1
-fi
-
-. ${file}
-
-# XXX We must check if a bridge is there and up.
-
-if [ -n "${SERVICE}" -a -x "${NETWORK_SCRIPTS}/services/${SERVICE}" ]; then
-       IFCONFIG=${file} ${NETWORK_SCRIPTS}/services/${SERVICE} ${1} up
-else
-       echo -e "${FAILURE}Unable to process ${file}.  Either"
-       echo -e "${FAILURE}the SERVICE variable was not set,"
-       echo -e "${FAILURE}or the specified service cannot be executed."
-       message=""
-       log_failure_msg
-fi
-
-# End $NETWORK_DEVICES/ifup
diff --git a/src/initscripts/networking/port b/src/initscripts/networking/port
new file mode 100644 (file)
index 0000000..f2b7e61
--- /dev/null
@@ -0,0 +1,107 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+. /lib/lsb/init-functions
+. /etc/init.d/networking/functions
+
+port=$(macify $1)
+action=$2
+
+shift 2
+
+if ! device_exists ${port}; then
+       echo "Port ${port} does not exist."
+       exit 1
+fi
+
+if [ -z "${port}" ] || [ -z "${action}" ]; then
+       echo "Usage: $0 <port> <up|down> [hooks]"
+       echo
+fi
+
+for arg in ${@-$(find ${CONFIG_PORTS}/${port}/)}; do
+       arg=${arg##*/}
+       [ -e "${CONFIG_PORTS}/${port}/${arg}" ] || continue
+       hooks="${hooks} ${CONFIG_PORTS}/${port}/${arg}"
+done
+
+echo "DEBUG: hooks: $hooks"
+
+# Getting zone variable
+#local zone
+#if [ -z "$ZONE" ]; then
+#      for zone in $(all_zones); do
+#              for i in ${zone}/port-*; do
+#                      i=$(readlink ${i})
+#                      for j in ${ports}; do
+#                              if [ "${i}" = "${j}" ]; then
+#                                      ZONE=${i%/*}
+#                                      ZONE=${ZONE##*/}
+#                              fi
+#                      done
+#              done
+#      done
+#fi
+
+case "$action" in
+       up)
+               message="Setting up port ${port}..."
+               ip link set $(devicify ${port}) up
+               evaluate_retval
+
+               for hook in ${hooks}; do
+                       [ -d "${hook}" ] && continue
+                       (
+                               . ${hook}
+                               if [ -n "${HOOK}" -a -x "/etc/init.d/networking/hooks/${HOOK}" ]; then
+                                       CONFIG=${hook} /etc/init.d/networking/hooks/${HOOK} ${port} up
+                               else
+                                       echo -e "${FAILURE}Unable to process ${hook}. Either"
+                                       echo -e "${FAILURE}the HOOK variable was not set,"
+                                       echo -e "${FAILURE}or the specified hook cannot be executed."
+                                       message=""
+                                       log_failure_msg
+                               fi
+                       )
+               done
+               ;;
+       down)
+               for hook in ${hooks}; do
+                       [ -d "${hook}" ] && continue
+                       (
+                               . ${hook}
+                               if [ -n "${HOOK}" -a -x "/etc/init.d/networking/hooks/${HOOK}" ]; then
+                                       CONFIG=${hook} /etc/init.d/networking/hooks/${HOOK} ${port} down
+                               else
+                                       echo -e "${FAILURE}Unable to process ${hook}. Either"
+                                       echo -e "${FAILURE}the HOOK variable was not set,"
+                                       echo -e "${FAILURE}or the specified hook cannot be executed."
+                                       message=""
+                                       log_failure_msg
+                               fi
+                       )
+               done
+
+               message="Pushing down port ${port}..."
+               ip link set $(devicify ${port}) down
+               evaluate_retval
+               ;;
+esac
diff --git a/src/initscripts/networking/zone b/src/initscripts/networking/zone
new file mode 100644 (file)
index 0000000..54e06c4
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+. /lib/lsb/init-functions
+. /etc/init.d/networking/functions
+
+zone=$1
+action=$2
+
+case "$action" in
+       up)
+               message="Bringing up zone ${zone}..."
+               
+               # Check if bridge already exists
+               zone_status=`brctl show 2>/dev/null`
+               if ! echo "${zone_status}" | grep -q "^${zone}"; then
+                       #/etc/init.d/networking/hooks pre-up ${CONFIG_ZONES}/${zone}
+
+                       # Create and bring up the zone
+                       brctl addbr ${zone} || failed=1
+                       ip link set ${zone} up || failed=1
+                       (exit ${failed})
+                       evaluate_retval standard
+
+                       [ "${IN_BOOT}" = "1" ] && \
+                               for port in ${CONFIG_ZONES}/${zone}/port-*; do
+                                       #port=$(readlink ${port})
+                                       ZONE=${zone} /etc/init.d/networking/port ${port} up
+                               done
+
+                       ###/etc/init.d/networking/hooks post-up ${CONFIG_ZONES}/${zone}
+               else
+                       log_warning_msg
+                       message="Zone ${zone} does already exist."
+                       log_warning_msg
+               fi
+               ;;
+
+       down)
+               message="Bringing down zone ${zone}..."
+               # Check if bridge already exists
+               zone_status=`brctl show 2>/dev/null`
+               if echo "${zone_status}" | grep -q "^${zone}"; then
+                       #/etc/init.d/networking/hooks pre-down ${CONFIG_ZONES}/${zone}
+                       # remove devices
+
+                       for port in ${CONFIG_ZONES}/${zone}/port-*; do
+                               brctl delif ${zone} ${port##*/}
+                               /etc/init.d/networking/port ${port} down
+                       done
+
+                       # Bring down the zone and delete it
+                       ip link set ${zone} down || failed=1
+                       brctl delbr ${zone} || failed=1
+                       (exit ${failed})
+                       evaluate_retval standard
+
+                       #/etc/init.d/networking/hooks post-down ${CONFIG_ZONES}/${zone}
+               else
+                       log_warning_msg
+                       message="Zone ${zone} does not exist."
+                       log_warning_msg
+               fi
+               ;;
+esac
index 4cfa7f92f26e47feedd82f79d8df23397cf0beb1..45e537e7fc07e1d2016fea05cc950e68dc4ccce9 100644 (file)
@@ -1,2 +1 @@
 HOSTNAME=ipfire.localdomain
-NETWORK_DEVICES=/etc/sysconfig/network-devices
index cad8d640be34d6df2c6a3b31eb981fe180fdd422..59422f60121af43156e07ac56cec168a1a9cb135 100644 (file)
@@ -26,12 +26,7 @@ BOLD="\\033[1;39m"
 NORMAL="\\033[0;39m"
 ERROR="\\033[1;31m"
 
-. ../src/initscripts/networking/functions
-
-CONFIG_DIR=${CONFIG_DIR-/etc/sysconfig/networking}
-
-CONFIG_ZONES=${CONFIG_DIR}/zones
-CONFIG_PORTS=${CONFIG_DIR}/ports
+. /etc/init.d/networking/functions
 
 function usage() {
        echo "Usage $0 - TODO"
@@ -83,21 +78,6 @@ function _exit() {
        exit $1
 }
 
-function devicify() {
-       local device
-       local mac
-
-       device=$1
-
-       if is_mac ${device}; then
-               mac=${device}
-               device=$(get_device_by_mac ${device})
-               decho "Figured out that ${mac} is ${device}."
-       fi
-       decho "Function: devicify $@ -> ${device}"
-       echo ${device}
-}
-
 function port_show() {
        local port
 
@@ -114,16 +94,16 @@ function port_show() {
 function port_add() {
        local port
        local zone
-       local vid
+       local hook
        
        zone=$1
-       port=$(devicify $2)
-       vid=${3-0}
+       port=$(macify $2)
+       hook=${3-ethernet}
 
-       decho "Function: port_add $@"
-       decho "  Zone: ${zone} Port: ${port} VLAN-ID: ${vid}"
+       shift 3
 
-       # XXX Check if vlan id is valid
+       decho "Function: port_add"
+       decho "  Zone: ${zone} Port: ${port} Hook: ${hook} $@"
 
        if ! zone_exists ${zone}; then
                error "Zone ${BOLD}${zone}${NORMAL} does not exist."
@@ -131,46 +111,60 @@ function port_add() {
        fi
 
        if [ -z "$port" ]; then
-               error "Port ${BOLD}${2}${NORMAL} could not be found."
+               error "Port ${BOLD}${port}${NORMAL} could not be found."
                return 1
        fi
-       
+
        if ! device_exists ${port}; then
                error "Port ${BOLD}${port}${NORMAL} does not exist."
                return 1
        fi
 
-       local mac
-       mac=$(get_mac_by_device ${port})
-
-       mkdir -p ${CONFIG_PORTS}/${mac} 2>/dev/null
-       touch ${CONFIG_PORTS}/${mac}/${vid}
-       ln -sf ${CONFIG_PORTS}/${mac}/${vid} ${CONFIG_ZONES}/${zone}/port-${mac}-${vid}
-
-       # XXX add code to bring up device immediately
-
-       vecho "Successfully added port ${BOLD}${port}${NORMAL} (${mac} - ${vid}) to ${BOLD}${zone}${NORMAL}."
+       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 $@
+               RET=$?
+               if [ "$RET" -eq "0" ]; then
+                       vecho "Successfully added port ${BOLD}${port}${NORMAL} (${hook} $@) to ${BOLD}${zone}${NORMAL}."
+                       /etc/init.d/networking/port ${port} up
+               else
+                       error "Hook ${BOLD}${hook}${NORMAL} exited with $RET."
+                       return $RET
+               fi
+       else
+               error "Hook ${BOLD}${hook}${NORMAL} does not exist or is not executeable."
+               return 1
+       fi
 }
 
 function port_del() {
        local port
        local zone
-       local vid
-       
+       local hook
+
        zone=$1
        port=$(devicify $2)
-       vid=${3-0}
+       hook=${3-ethernet}
 
-       decho "Function: port_del $@"
-       decho "  Zone: ${zone} Port: ${port} VLAN-ID: ${vid}"
+       shift 3
 
-       rm -f ${CONFIG_ZONES}/${zone}/port-${mac}-${vid} \
-                       ${CONFIG_PORTS}/${mac}/${vid} 2>/dev/null
-       rm -r ${CONFIG_PORTS}/${mac}/ 2>/dev/null # XXX Does this only remove if dir is empty?
+       decho "Function: port_del"
+       decho "  Zone: ${zone} Port: ${port} Hook: ${hook}"
 
-       # XXX add code to bring down device immediately
-
-       vecho "Successfully removed port ${BOLD}${port}${NORMAL} (${mac} - ${vid}) from ${BOLD}${zone}${NORMAL}."
+       if [ -x "/etc/init.d/networking/hooks/${hook}" ]; then
+               /etc/init.d/networking/port ${port} down ## XXX How do we identify only that one hook?
+               ZONE=${zone} /etc/init.d/networking/hooks/${hook} ${port} remove $@
+               RET=$?
+               if [ "$RET" -eq "0" ]; then
+                       vecho "Successfully removed port ${BOLD}${port}${NORMAL} (${hook} $@) from ${BOLD}${zone}${NORMAL}."
+               else
+                       error "Hook ${BOLD}${hook}${NORMAL} exited with $RET."
+                       return $RET
+               fi
+       else
+               error "Hook ${BOLD}${hook}${NORMAL} does not exist or is not executeable."
+               return 1
+       fi
 }
 
 function zone_show() {
@@ -205,7 +199,7 @@ function zone_show() {
        echo -e "# ${ERROR}Ports:${NORMAL}"
        local port
        for port in ${CONFIG_ZONES}/${zone}/port-*; do
-               port=$(basename ${port})
+               port=${port##*/}
                echo "#  ${port#port-}"
                debug && echo "#  TODO: Is port up or down?"
        done
index c5f49cf9c16c66467632bbd96af63200ebfbd769..1519abab8b7f659b27192fafebfea471e0135117 100644 (file)
@@ -15,18 +15,18 @@ etc/init.d/mountfs
 etc/init.d/mountkernfs
 etc/init.d/network
 etc/init.d/networking
-etc/init.d/networking/brdown
-etc/init.d/networking/brup
 etc/init.d/networking/functions
-etc/init.d/networking/ifdown
-etc/init.d/networking/ifup
+etc/init.d/networking/hooks
+etc/init.d/networking/hooks/bonding
+etc/init.d/networking/hooks/bridge-slave
+etc/init.d/networking/hooks/ethernet
+etc/init.d/networking/hooks/ipv4-static
+etc/init.d/networking/hooks/ipv4-static-route
+etc/init.d/networking/hooks/stp
+etc/init.d/networking/hooks/vlan
 etc/init.d/networking/net-hotplug
-etc/init.d/networking/services
-etc/init.d/networking/services/bonding
-etc/init.d/networking/services/bridge-slave
-etc/init.d/networking/services/ipv4-static
-etc/init.d/networking/services/ipv4-static-route
-etc/init.d/networking/services/stp
+etc/init.d/networking/port
+etc/init.d/networking/zone
 etc/init.d/ntpd
 etc/init.d/openldap
 etc/init.d/random
index efd161749f51c16974f2c974731983b950ef8ce8..163027188f31436718359ce69c4c3b786e7c07fc 100644 (file)
@@ -6,6 +6,5 @@ etc/ipfire/certs
 etc/ipfire/certs/index.txt
 etc/ipfire/certs/serial
 etc/ipfire/crls
-etc/ipfire/network
-etc/ipfire/network/devices
-etc/sysconfig/network-devices
+etc/ipfire/networking
+etc/sysconfig/networking