]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
network: Some changes.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 25 Jul 2009 21:09:46 +0000 (23:09 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 25 Jul 2009 21:09:46 +0000 (23:09 +0200)
New hook: ipv4-dhcp.
A lot of minor changes and changes that beatify the output.

src/network/functions
src/network/hook-header [new file with mode: 0644]
src/network/hooks/ethernet
src/network/hooks/ipv4-dhcp [new file with mode: 0755]
src/network/hooks/ipv4-static
src/network/hooks/mtu
src/network/hooks/vlan
src/network/port
src/network/zone

index aca6e55a00a33b1738a59f0c53ccffa8093aa29d..2a5d8979185a21c5c50465107474d0406bd12e73 100644 (file)
@@ -148,7 +148,7 @@ function device_rename() {
        local destination=$2
 
        # Replace + by a valid number
-       if grep -qE "+$" <<<${destination}; then
+       if grep -q "+$" <<<${destination}; then
                local number=0
                destination=$(sed -e "s/+//" <<<$destination)
                while [ "${number}" -le "100" ]; do
diff --git a/src/network/hook-header b/src/network/hook-header
new file mode 100644 (file)
index 0000000..a0b9f9f
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+. /lib/lsb/init-functions
+. /lib/network/functions
+
+INDENT=" "
+
+# Parse the command line
+action=
+port=
+zone=
+
+while [ $# -gt 0 ]; do
+       case "${1}" in
+               --zone=*)
+                       zone=${1#--zone=}
+                       ;;
+               --config=*)
+                       . ${1#--config=}
+                       ;;
+               --port=*)
+                       port=${1#--port=}
+                       ;;
+               -*)
+                       log_failure_msg "Unrecognized option: ${1}"
+                       exit ${EXIT_ERROR}
+                       ;;
+               *)
+                       action=${1}
+                       shift
+                       break
+                       ;;
+       esac
+       shift
+done
+
index 5a3902c543a48aa57b913fe586592a28cb52b8ed..00087287cc92a1a7e3635da9655c71114ec8a3dd 100755 (executable)
@@ -12,8 +12,7 @@
 #
 ########################################################################
 
-. /lib/lsb/init-functions
-. /lib/network/functions
+. /lib/network/hook-header
 
 HOOK_NAME=ethernet
 HOOK_TYPE=port
@@ -37,14 +36,18 @@ function do_attach() {
                # Device is already attached to the bridge
                return 0
        fi
+       message="Attaching ethernet port ${port}..."
        device_rename $(get_device ${port}) $(port_name)
        zone_add_port ${zone} $(get_device_by_mac ${port})
+       evaluate_retval
 }
 
 function do_detach() {
        if zone_has_device_attached ${zone} $(get_device ${port}); then
+               message="Detatching ethernet port ${port}..."
                zone_del_port ${zone} $(get_device_by_mac ${port})
                device_rename $(get_device_by_mac ${port}) ${COMMON_DEVICE}
+               evaluate_retval
        fi
 }
 
@@ -60,33 +63,6 @@ function do_status() {
        # TODO: Check if device is attached to a bridge.
 }
 
-# First, parse the command line
-
-while [ $# -gt 0 ]; do
-       case "${1}" in
-               --port=*)
-                       port=$(macify ${1#--port=})
-                       ;;
-               --config=*)
-                       . ${1#--config=}
-                       check_config
-                       ;;
-               --zone=*)
-                       zone=${1#--zone=}
-                       ;;
-               -*)
-                       log_failure_msg "Unrecognized option: ${1}"
-                       exit ${EXIT_ERROR}
-                       ;;
-               *)
-                       action=${1}
-                       shift
-                       break
-                       ;;
-       esac
-       shift
-done
-
 case "${action}" in
        help)
                echo -e "${BOLD}Hook (${HOOK_NAME}) help:"
diff --git a/src/network/hooks/ipv4-dhcp b/src/network/hooks/ipv4-dhcp
new file mode 100755 (executable)
index 0000000..dd37271
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+. /lib/network/hook-header
+
+HOOK_NAME="ipv4-dhcp"
+HOOK_TYPE="zone"
+
+MESSAGE="DHCP Daemon..."
+EXECUTEABLE="/sbin/dhclient"
+
+case "${action}" in
+       help)
+               ;;
+
+       info)
+               echo "HOOK_NAME=$HOOK_NAME"
+               echo "HOOK_TYPE=$HOOK_TYPE"
+               ;;
+
+       status)
+               check_config zone
+               pidfile="/var/run/dhclient_${zone}.pid"
+               pidofproc -p ${pidfile} ${EXECUTEABLE} &>/dev/null
+               exit $? 
+               ;;
+
+       pre-up)
+               ;;
+
+       post-up)
+               check_config zone
+               pidfile="/var/run/dhclient_${zone}.pid"
+               if [ -e "${pidfile}" ]; then
+                       kill $(<${pidfile}) &>/dev/null
+                       sleep 1
+               fi
+               ${EXECUTEABLE} -pf ${pidfile} ${zone}
+               evaluate_retval start
+               ;;
+
+       pre-down)
+               check_config zone
+               pidfile="/var/run/dhclient_${zone}.pid"
+               killproc -p ${pidfile} ${EXECUTEABLE}
+               evaluate_retval stop
+               ;;
+
+       post-down)
+               ;;
+
+       config)
+               while [ $# -gt 0 ]; do
+                       case "$1" in
+                               --hostname=*)
+                                       HOSTNAME=${1#--hostname=}
+                                       ;;
+                               *)
+                                       echo "Unknown option: $1" >&2
+                                       exit 1
+                                       ;;
+                       esac
+                       shift
+               done
+               cat <<EOF >${CONFIG_ZONES}/${zone}/ipv4-dhcp
+HOOK="${HOOK_NAME}"
+HOSTNAME="${HOSTNAME}"
+EOF
+               [ "$?" = "0" ] && exit ${EXIT_OK} || exit ${EXIT_ERROR}
+               ;;
+       
+       *)
+               echo "Usage: ${0} {config|pre-up|post-up|pre-down|post-down|status} [interface]"
+               exit ${EXIT_ERROR}
+       ;;
+esac
+
+# End $NETWORK_DEVICES/services/ipv4-dhcp
index 99bc810c59c29627ff0e7f7cf214b096bc3a96aa..21097f94d9dc5e77544e0da18dda7485abecea2d 100755 (executable)
@@ -13,8 +13,7 @@
 #
 ########################################################################
 
-. /lib/lsb/init-functions
-. /lib/network/functions
+. /lib/network/hook-header
 
 HOOK_NAME="ipv4-static"
 HOOK_TYPE="zone"
@@ -48,32 +47,6 @@ function check_config() {
        fi
 }
 
-# First, parse the command line
-
-while [ $# -gt 0 ]; do
-       case "${1}" in
-               --zone=*)
-                       zone=${1#--zone=}
-                       ;;
-               --config=*)
-                       . ${1#--config=}
-                       check_config
-                       ;;
-               -*)
-                       log_failure_msg "Unrecognized option: ${1}"
-                       exit ${EXIT_ERROR}
-                       ;;
-               *)
-                       action=${1}
-                       shift
-                       break
-                       ;;
-       esac
-       shift
-done
-
-# Second, do the $action
-
 case "${action}" in
        help)
                ;;
index 6607de9887cec32eaada633faecc19ccfb4022ac..f22e79f678c86c8b38a107ba7ab3c0e959c2bb40 100755 (executable)
 #
 ########################################################################
 
-. /lib/lsb/init-functions
-. /lib/network/functions
+. /lib/network/hook-header
 
 HOOK_NAME=mtu
 HOOK_TYPE=zone
 
-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
-}
+DEFAULT_MTU=1500
 
 function usage() {
        echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]"
 }
 
-# First, parse the command line
-
-while [ $# -gt 0 ]; do
-       case "${1}" in
-               --zone=*)
-                       zone=${1#--zone=}
-                       ;;
-               --config=*)
-                       . ${1#--config=}
-                       check_config
-                       ;;
-               -*)
-                       log_failure_msg "Unrecognized option: ${1}"
-                       exit ${EXIT_ERROR}
-                       ;;
-               *)
-                       action=${1}
-                       shift
-                       break
-                       ;;
-       esac
-       shift
-done
-
-# Second, do the $action
-
 case "${action}" in
        help)
                ;;
@@ -72,7 +36,7 @@ case "${action}" in
                ;;
 
        status)
-               check_config
+               check_config zone MTU
                mtu=$(cat /sys/class/net/${zone}/mtu 2>/dev/null)
                [ "$MTU" = "$mtu" ]
                exit $?
@@ -82,16 +46,16 @@ case "${action}" in
                ;;
 
        post-up)
-               check_config
+               check_config zone MTU
                message="Setting the MTU for ${zone} to ${MTU}..."
                echo "${MTU}" > "/sys/class/net/${zone}/mtu"
                evaluate_retval standard
                ;;
 
        pre-down)
-               check_config
+               check_config zone MTU
                message="Resetting MTU for ${zone} to 1500..."
-               echo "1500" > "/sys/class/net/${zone}/mtu"
+               echo ${DEFAULT_MTU} > "/sys/class/net/${zone}/mtu"
                evaluate_retval standard
                ;;
 
@@ -100,7 +64,7 @@ case "${action}" in
 
        config)
                MTU=$1
-               check_config
+               check_config zone MTU
                cat << EOF >> ${CONFIG_ZONES}/${zone}/${HOOK_NAME}
 HOOK="${HOOK_NAME}"
 MTU="${MTU}"
index b7a5123c91ae9ff458652df317363bb8fd087618..a5fe21f29c7930bd5c92715f6b07e8795bce8666 100755 (executable)
@@ -12,8 +12,7 @@
 #
 ########################################################################
 
-. /lib/lsb/init-functions
-. /lib/network/functions
+. /lib/network/hook-header
 
 HOOK_NAME=vlan
 HOOK_TYPE=port
@@ -68,33 +67,6 @@ function do_status() {
        return $RET
 }
 
-# First, parse the command line
-
-while [ $# -gt 0 ]; do
-       case "${1}" in
-               --port=*)
-                       port=$(macify ${1#--port=})
-                       ;;
-               --config=*)
-                       . ${1#--config=}
-                       check_config
-                       ;;
-               --zone=*)
-                       zone=${1#--zone=}
-                       ;;
-               -*)
-                       log_failure_msg "Unrecognized option: ${1}"
-                       exit ${EXIT_ERROR}
-                       ;;
-               *)
-                       action=${1}
-                       shift
-                       break
-                       ;;
-       esac
-       shift
-done
-
 case "${action}" in
        help)
                ;;
index 3c3e4b51bf8e99fcb71a03bcbfec3073176f1e90..fceeeb7bd1d7a7c3f45f5bd0d61c1a8e761d156b 100755 (executable)
@@ -91,7 +91,7 @@ for hook in ${hooks}; do
        (
                . ${hook}
                if [ -n "${HOOK}" ] && hook_exists ${HOOK}; then
-                       /lib/network/hooks/${HOOK} --config=${hook} --port=${port} --zone=${zone} ${action}
+                       hook_run ${HOOK} --config=${hook} --port=${port} --zone=${zone} ${action}
                        RET=$?
                else
                        echo -e "${FAILURE}Unable to process ${hook}. Either"
index fb3bdf78fcf1905a48a21eddd3761b65a36dc322..86d943b061d3512e9e187a5324470bb995ea359c 100755 (executable)
@@ -56,6 +56,8 @@ case "$action" in
                if ! echo "${zone_status}" | grep -q "^${zone}"; then
                        # Create and bring up the zone
                        brctl addbr ${zone} || failed=1
+                       brctl stp ${zone} on || failed=1
+                       brctl setfd ${zone} 0 || failed=1
                        ip link set ${zone} up || failed=1
                        (exit ${failed})
                        evaluate_retval standard