From: Michael Tremer Date: Sat, 25 Jul 2009 21:09:46 +0000 (+0200) Subject: network: Some changes. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02dbf7e7f38f84d469e0d4e8408079b820fd30fe;p=ipfire-3.x.git network: Some changes. New hook: ipv4-dhcp. A lot of minor changes and changes that beatify the output. --- diff --git a/src/network/functions b/src/network/functions index aca6e55a0..2a5d89791 100644 --- a/src/network/functions +++ b/src/network/functions @@ -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 index 000000000..a0b9f9ff3 --- /dev/null +++ b/src/network/hook-header @@ -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 + diff --git a/src/network/hooks/ethernet b/src/network/hooks/ethernet index 5a3902c54..00087287c 100755 --- a/src/network/hooks/ethernet +++ b/src/network/hooks/ethernet @@ -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 index 000000000..dd3727143 --- /dev/null +++ b/src/network/hooks/ipv4-dhcp @@ -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 <${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 diff --git a/src/network/hooks/ipv4-static b/src/network/hooks/ipv4-static index 99bc810c5..21097f94d 100755 --- a/src/network/hooks/ipv4-static +++ b/src/network/hooks/ipv4-static @@ -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) ;; diff --git a/src/network/hooks/mtu b/src/network/hooks/mtu index 6607de988..f22e79f67 100755 --- a/src/network/hooks/mtu +++ b/src/network/hooks/mtu @@ -15,53 +15,17 @@ # ######################################################################## -. /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}" diff --git a/src/network/hooks/vlan b/src/network/hooks/vlan index b7a5123c9..a5fe21f29 100755 --- a/src/network/hooks/vlan +++ b/src/network/hooks/vlan @@ -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) ;; diff --git a/src/network/port b/src/network/port index 3c3e4b51b..fceeeb7bd 100755 --- a/src/network/port +++ b/src/network/port @@ -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" diff --git a/src/network/zone b/src/network/zone index fb3bdf78f..86d943b06 100755 --- a/src/network/zone +++ b/src/network/zone @@ -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