]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
Updated networking scripts.
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 13 Apr 2009 20:06:39 +0000 (22:06 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 13 Apr 2009 20:06:39 +0000 (22:06 +0200)
src/initscripts/core/network
src/initscripts/networking/functions
src/initscripts/networking/hooks/ipv4-static
src/initscripts/networking/hooks/ipv4-static-route
src/initscripts/networking/hooks/mtu
src/initscripts/networking/hooks/stp
src/initscripts/networking/zone
src/network/network

index 6eefa9a4f9b9b3b3775d5951db90132dba62d06e..19c3ff08cf6344a0e90dcc54761e0153b80cfa4d 100644 (file)
@@ -22,7 +22,7 @@
 case "${1}" in
        start)
                # Start all network interfaces
-               for zone in $(find ${CONFIG_ZONES}/* -maxdepth 1); do
+               for zone in $(find ${CONFIG_ZONES}/* -maxdepth 1 2>/dev/null); do
                        [ -d "${zone}" ] || continue
                        /etc/init.d/networking/zone ${zone##*/} up
                done
@@ -31,7 +31,7 @@ case "${1}" in
 
        stop)
                # Stop all network interfaces
-               for zone in $(find ${CONFIG_ZONES}/* -maxdepth 1); do
+               for zone in $(find ${CONFIG_ZONES}/* -maxdepth 1 2>/dev/null); do
                        [ -d "${zone}" ] || continue
                        /etc/init.d/networking/zone ${zone##*/} down
                done
index 13619cfeb895984a4298f962d3e083d26193a83c..5bf04f5847dc554bdf9ebfcc11c636e8c07a1646 100644 (file)
@@ -216,3 +216,39 @@ function all_zones() {
                [ -d "${zone}" ] && echo ${zone}
        done
 }
+
+function run_hooks() {
+       local action
+       local dir
+       local failed
+       local hook
+       local hooks
+
+       action=${1}
+       dir=${2}
+       shift 2
+
+       if [ -z "${action}" ] || [ -z "${dir}" ]; then
+               echo "Not enough parameters given." >&2
+               return 1
+       fi
+
+       for hook in $(find ${dir} -type f); do
+               (
+                       . ${hook}
+                       if [ -n "${HOOK}" -a -x "/etc/init.d/networking/hooks/${HOOK}" ]; then
+                               CONFIG=${hook} /etc/init.d/networking/hooks/${HOOK} ${action} $@
+                               RET=$?
+                       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
+                       exit ${RET}
+               ) || failed=1
+       done
+
+       return ${failed}
+}
index 13fbbc37e528d66e085ca1210c12d178bbb5f689..7a3ca9be5408230e5f77ca759d552d3f2a41a191 100644 (file)
 ########################################################################
 
 . /lib/lsb/init-functions
+. /etc/init.d/networking/functions
 [ -n "${CONFIG}" ] && . ${CONFIG}
 
-zone=$1
+zone=$2
 
-if [ -z "${IP}" ]; then
-       log_failure_msg "IP variable missing from ${CONFIG}, cannot continue."
-       exit 1
-fi
-
-if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
-       log_warning_msg "PREFIX variable missing from ${CONFIG}, assuming 24."
-       PREFIX=24
-       args="${args} ${IP}/${PREFIX}"
-elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
-       log_failure_msg "PREFIX and PEER both specified in ${CONFIG}, cannot continue."
-       exit 1
-elif [ -n "${PREFIX}" ]; then
-       args="${args} ${IP}/${PREFIX}"
-elif [ -n "${PEER}" ]; then
-       args="${args} ${IP} peer ${PEER}"
-fi
-
-if [ -n "${BROADCAST}" ]; then
-       args="${args} broadcast ${BROADCAST}"
-fi
+function check_config() {
+       if [ -z "${IP}" ]; then
+               log_failure_msg "IP variable missing, cannot continue."
+               exit 1
+       fi
+       
+       if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
+               log_warning_msg "PREFIX variable missing, assuming 24."
+               PREFIX=24
+               args="${args} ${IP}/${PREFIX}"
+       elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
+               log_failure_msg "PREFIX and PEER both specified, cannot continue."
+               exit 1
+       elif [ -n "${PREFIX}" ]; then
+               args="${args} ${IP}/${PREFIX}"
+       elif [ -n "${PEER}" ]; then
+               args="${args} ${IP} peer ${PEER}"
+       fi
+       
+       if [ -n "${BROADCAST}" ]; then
+               args="${args} broadcast ${BROADCAST}"
+       fi
+       
+       if [ -n "${SOURCE}" ]; then
+               args="${args} src ${SOURCE}"
+       fi
+}
 
-if [ -n "${SOURCE}" ]; then
-       args="${args} src ${SOURCE}"
-fi
+case "${1}" in
+       pre-up)
+               ;;
 
-case "${2}" in
-       up)
+       post-up)
+               check_config
                MESSAGE="Adding IPv4 address ${IP} to zone ${zone} interface..."
                ip addr add ${args} dev ${zone}
                evaluate_retval
@@ -60,8 +67,9 @@ case "${2}" in
                         fi
                fi
        ;;
-       
-       down)
+
+       pre-down)
+               check_config
                if [ -n "${GATEWAY}" ]; then
                        MESSAGE="Removing default gateway..."
                        ip route del default
@@ -71,14 +79,60 @@ case "${2}" in
                MESSAGE="Removing IPv4 address ${IP} from zone ${zone}..."
                ip addr del ${args} dev ${zone}
                evaluate_retval
-       ;;
-       
+               ;;
+
+       post-down)
+               ;;
+
        config)
-               : # TODO
-       ;;
+               shift 2
+               while [ $# -gt 0 ]; do
+                       case "$1" in
+                               --ip)
+                                       IP=$2
+                                       shift 2
+                                       ;;
+                               --prefix)
+                                       PREFIX=$2
+                                       shift 2
+                                       ;;
+                               --peer)
+                                       PEER=$2
+                                       shift 2
+                                       ;;
+                               --broadcast)
+                                       BROADCAST=$2
+                                       shift 2
+                                       ;;
+                               --source)
+                                       SOURCE=$2
+                                       shift 2
+                                       ;;
+                               --gateway)
+                                       GATEWAY=$2
+                                       shift 2
+                                       ;;
+                               *)
+                                       echo "Unknown option: $1" >&2
+                                       exit 1
+                                       ;;
+                       esac
+               done
+               check_config
+               cat << EOF >> ${CONFIG_ZONES}/${zone}/ipv4-static_$IP
+HOOK=ipv4-static
+IP=$IP
+PREFIX=$PREFIX
+PEER=$PEER
+BROADCAST=$BROADCAST
+SOURCE=$SOURCE
+GATEWAY=$GATEWAY
+EOF
+               exit $?
+               ;;
        
        *)
-               echo "Usage: ${0} [interface] {up|down|config}"
+               echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]"
                exit 1
        ;;
 esac
index 436154279753eedec84ee3010477f1e1c97e35da..9daff1971284bc50c0172736c8bc2bc46212074c 100644 (file)
@@ -15,7 +15,7 @@
 . /lib/lsb/init-functions
 [ -n "${CONFIG}" ] && . ${CONFIG}
 
-zone=$1
+zone=$2
 
 case "${TYPE}" in
        ("" | "network")
@@ -72,7 +72,7 @@ if [ -n "${need_gateway}" ]; then
        args="${args} via ${GATEWAY}"
 fi
 
-case "${2}" in
+case "${1}" in
        up)
                boot_mesg "Adding '${desc}' route to zone ${zone}..."
                ip route add ${args} dev ${zone}
index 685c8df26fb9139928d4ffb17177b7141baf41de..93280fe6de396c49204dc805fd0fe6f85e254e3e 100644 (file)
 ########################################################################
 
 . /lib/lsb/init-functions
+. /etc/init.d/networking/functions
 [ -n "${CONFIG}" ] && . ${CONFIG}
 
-zone=$1
+function check_config() {
+       if [ -z "${MTU}" ]; then
+               log_failure_msg "MTU variable missing from ${CONFIG}, cannot continue."
+               exit 1
+       fi
+       if [ -z "${zone}" ]; then
+               usage
+               exit 1
+       fi
+}
+
+function usage() {
+       echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]"
+}
 
-if [ -z "${MTU}" ]
-then
-       log_failure_msg "MTU variable missing from ${CONFIG}, cannot continue."
-       exit 1
-fi
+zone=$2
 
-case "${2}" in
-       up)
+case "${1}" in
+       pre-up)
+               ;;
+
+       post-up)
+               check_config
                message="Setting the MTU for ${zone} to ${MTU}..."
                echo "${MTU}" > "/sys/class/net/${zone}/mtu"
                evaluate_retval standard
-       ;;
+               ;;
 
-       down)
-       ;;
+       pre-down)
+               check_config
+               message="Resetting MTU for ${zone} to 1500..."
+               echo "1500" > "/sys/class/net/${zone}/mtu"
+               evaluate_retval standard
+               ;;
+
+       post-down)
+               ;;
+
+       config)
+               ;;
 
        *)
-               echo "Usage: ${0} [interface] {up|down}"
+               usage
                exit 1
        ;;
 esac
index 4a8f2b0b591da0fe8b4873276a23cce7ec712fa7..ed128dd35f9a587960763cb294914afe24f883b3 100644 (file)
 . /lib/lsb/init-functions
 [ -n "${CONFIG}" ] && . ${CONFIG}
 
-zone=$1
+zone=$2
 
-case "${2}" in
-       up)
+case "${1}" in
+       pre-up)
+               ;;
+
+       post-up)
                MESSAGE="Enabling Spanning Tree Protocol on zone ${zone}..."
                brctl stp ${zone} on
                evaluate_retval
-       ;;
+               ;;
 
-       down)
+       pre-down)
                MESSAGE="Disabling Spanning Tree Protocol on zone ${zone}..."
                brctl stp ${zone} off
                evaluate_retval
-       ;;
+               ;;
+
+       post-down)
+               ;;
 
        config)
                : # TODO
-       ;;
+               ;;
 
        *)
-               echo "Usage: ${0} [interface] {up|down|config}"
+               echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]"
                exit 1
-       ;;
+               ;;
 esac
 
 # End $NETWORK_DEVICES/services/stp
index d2ae48b01456d5e6cf7be3cfcd06a9f501be9ab4..ec194f8db26c56e248976931df398d53579a2298 100644 (file)
@@ -40,6 +40,8 @@ case "$action" in
        up)
                message="Bringing up zone ${zone}..."
 
+               run_hooks pre-up ${CONFIG_ZONES}/${zone} ${zone}
+
                # Check if bridge already exists
                zone_status=`brctl show 2>/dev/null`
                if ! echo "${zone_status}" | grep -q "^${zone}"; then
@@ -48,19 +50,15 @@ case "$action" in
                        ip link set ${zone} up || failed=1
                        (exit ${failed})
                        evaluate_retval standard
+               fi
 
-                       # Attach ports
-                       for config in ${CONFIG_ZONES}/${zone}/port-*; do
-                               port=${config##*/}; port=${port#port-}; port=${port%%-*}
-                               ZONE=${zone} /etc/init.d/networking/port ${port} attach ${config}
-                       done
+               # Attach ports
+               for config in $(find ${CONFIG_ZONES}/${zone}/ -name "port-*" 2>/dev/null); do
+                       port=${config##*/}; port=${port#port-}; port=${port%%-*}
+                       ZONE=${zone} /etc/init.d/networking/port ${port} attach ${config}
+               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
+               run_hooks post-up ${CONFIG_ZONES}/${zone} ${zone}
                ;;
 
        down)
@@ -68,10 +66,10 @@ case "$action" in
                # 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}
+                       run_hooks pre-down ${CONFIG_ZONES}/${zone} ${zone}
 
                        # Detach ports
-                       for config in ${CONFIG_ZONES}/${zone}/port-*; do
+                       for config in $(find ${CONFIG_ZONES}/${zone}/ -name "port-*" 2>/dev/null); do
                                port=${config##*/}; port=${port#port-}; port=${port%%-*}
                                ZONE=${zone} /etc/init.d/networking/port ${port} detach ${config}
                        done
@@ -81,10 +79,11 @@ case "$action" in
                        brctl delbr ${zone} || failed=1
                        (exit ${failed})
                        evaluate_retval standard
+
+                       run_hooks post-down ${CONFIG_ZONES}/${zone} ${zone}
                else
-                       log_warning_msg
-                       message="Zone ${zone} does not exist."
-                       log_warning_msg
+                       log_warning_msg ${message}
+                       log_warning_msg "Zone ${zone} does not exist."
                fi
                ;;
 esac
index 163ccd8a0007e7b47444af63be160ba9debef848..39091b192231741b6572c5ae6be11bb4be573e80 100644 (file)
@@ -169,7 +169,7 @@ function _exit() {
 
 function cmd() {
        decho "Running command: $@"
-       if verbose; then
+       if debug; then
                $@
        else
                $@ >/dev/null
@@ -233,6 +233,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
 }
 
 function port_del() {
@@ -320,6 +321,7 @@ function zone_add() {
 
        mkdir -p ${CONFIG_ZONES}/${zone}
        vecho "Successfully added zone ${zone}."
+       cmd /etc/init.d/networking/zone ${zone} up
 }
 
 function zone_del() {
@@ -331,6 +333,7 @@ function zone_del() {
                return 1
        fi
 
+       cmd /etc/init.d/networking/zone ${zone} down
        rm -rf ${CONFIG_ZONES}/${zone}
        vecho "Successfully removed zone ${zone}."
 }
@@ -393,6 +396,21 @@ while [ "$#" -gt 0 ]; do
                                        port_del $@
                                        _exit $?
                                        ;;
+                               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} $@
+                                               RET=$?
+                                       else
+                                               error "\"${hook}\" is not a known hook."
+                                       fi
+                                       _exit $RET
+                                       ;;
                                help)
                                        DO_RELOAD=0 usage zone 0
                                        ;;