]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
Added brup and brdown.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 20 Dec 2008 16:33:05 +0000 (17:33 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 20 Dec 2008 16:33:05 +0000 (17:33 +0100)
These scripts do control the new bridge interfaces.

src/initscripts/core/network
src/initscripts/networking/brdown [new file with mode: 0644]
src/initscripts/networking/brup [new file with mode: 0644]

index cb9d118b0e4f949c2af887ac153141ee3321e9e0..45418932a35396e611f4ef38508fc1aba71300cb 100644 (file)
 case "${1}" in
        start)
                # Start all network interfaces
-               for file in ${NETWORK_DEVICES}/ifconfig.*
+               for file in ${NETWORK_DEVICES}/*
                do
-                       interface=${file##*/ifconfig.}
+                       interface=$(basename ${file})
 
-                       # skip if $file is * (because nothing was found)
-                       if [ "${interface}" = "*" ]
-                       then
-                               continue
-                       fi
-                       IN_BOOT=1 ${NETWORK_DEVICES}/ifup ${interface}
+                       IN_BOOT=1 ${NETWORK_DEVICES}/brup ${interface}
                done
                ;;
 
        stop)
                # Reverse list
                FILES=""
-               for file in ${NETWORK_DEVICES}/ifconfig.*
+               for file in ${NETWORK_DEVICES}/*
                do
                        FILES="${file} ${FILES}"
                done
@@ -46,15 +41,9 @@ case "${1}" in
                # Stop all network interfaces
                for file in ${FILES}
                do
-                       interface=${file##*/ifconfig.}
+                       interface=$(basename ${file})
 
-                       # skip if $file is * (because nothing was found)
-                       if [ "${interface}" = "*" ]
-                       then
-                               continue
-                       fi
-
-                       IN_BOOT=1 ${NETWORK_DEVICES}/ifdown ${interface}
+                       IN_BOOT=1 ${NETWORK_DEVICES}/brdown ${interface}
                done
                ;;
 
diff --git a/src/initscripts/networking/brdown b/src/initscripts/networking/brdown
new file mode 100644 (file)
index 0000000..05fab54
--- /dev/null
@@ -0,0 +1,88 @@
+#!/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}" =~ "^nic" ]]; then
+               FILES2="${FILES2} ${file}"
+               continue
+       fi
+
+       # append the rest
+       FILES2="${file} ${FILES2}"
+done
+FILES=${FILES2}
+
+# Process each configuration file
+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
+
+       (
+               . ${file}
+
+               if [ -n "${SERVICE}" -a -x "${NETWORK_DEVICES}/services/${SERVICE}" ]; then
+                       IFCONFIG=${file} ${NETWORK_DEVICES}/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
+       )
+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
new file mode 100644 (file)
index 0000000..a57e6f3
--- /dev/null
@@ -0,0 +1,87 @@
+#!/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}" =~ "^nic" ]]; 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
+
+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
+
+       (
+               . ${file}
+
+               if [ -n "${SERVICE}" -a -x "${NETWORK_DEVICES}/services/${SERVICE}" ]; then
+                       IFCONFIG=${file} ${NETWORK_DEVICES}/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
+       )
+done