From: Michael Tremer Date: Fri, 28 Aug 2009 10:42:25 +0000 (+0200) Subject: network: Improvements of the code. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26bfb5416f5e96527fb66d47f37191edb0be0828;p=ipfire-3.x.git network: Improvements of the code. Bonding does work much better. "network zone show" gives some nice output now. --- diff --git a/src/network/functions b/src/network/functions index e4dfed428..6b78d2214 100644 --- a/src/network/functions +++ b/src/network/functions @@ -193,6 +193,11 @@ function device_has_vlans() { grep -q "${1}$" /proc/net/vlan/config } +function device_has_carrier() { + local device=$(devicify ${1}) + [ "$( /sys/class/net/${device}/bonding/mode - + + echo "${MIIMON-100}" > /sys/class/net/${device}/bonding/miimon + for slave in ${SLAVES}; do if device_exists ${slave}; then if device_is_up ${slave}; then log_warning_msg "Cannot enslave device \"${slave}\"." continue fi - echo "+$(devicify ${slave})" > /sys/class/net/${device}/bonding/slaves device_rename "$(devicify ${slave})" "${device}s+" + echo "+$(devicify ${slave})" > /sys/class/net/${device}/bonding/slaves else log_warning_msg "Device ${slave} does not exist." fi @@ -137,14 +138,34 @@ EOF ;; status) - device_is_up $(devicify ${MAC}) - RET=$? - if [ $RET -eq 0 ]; then - log_success_msg "Port $(port_name) is up" + DEVICE=$(devicify ${MAC}) + echo -e "# ${CLR_BOLD_CYN}Trunk ${DEVICE} (${MAC})${NORMAL}" + if device_is_up ${MAC}; then + echo -e "# State: ${CLR_BOLD_GRN}up${NORMAL}" + echo "#" + for slave in $(/dev/null; then + echo -e "${CLR_BOLD_GRN}yes${NORMAL}" + else + echo -e "${CLR_BOLD_RED}no${NORMAL}" + fi fi + ip addr show ${zone} | grep "inet " | fgrep -q "${IP}/${PREFIX}" + exit ${?} ;; pre-up) @@ -106,7 +112,7 @@ case "${action}" in post-down) ;; - config) + add) while [ $# -gt 0 ]; do case "$1" in --ip=*) @@ -146,7 +152,10 @@ GATEWAY="${GATEWAY}" EOF [ "$?" = "0" ] && exit ${EXIT_OK} || exit ${EXIT_ERROR} ;; - + + rem) + ;; + *) echo "Usage: ${0} {config|pre-up|post-up|pre-down|post-down|status} [interface]" exit ${EXIT_ERROR} diff --git a/src/network/hooks/stp b/src/network/hooks/stp index 038b001ba..503c4e9e8 100755 --- a/src/network/hooks/stp +++ b/src/network/hooks/stp @@ -75,7 +75,7 @@ case "${action}" in post-down) ;; - config) + add) shift 2 while [ $# -gt 0 ]; do case "$1" in @@ -112,6 +112,9 @@ EOF exit $? ;; + rem) + ;; + *) echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]" exit 1 diff --git a/src/network/network b/src/network/network index e02d549a6..38ca3ba43 100644 --- a/src/network/network +++ b/src/network/network @@ -23,6 +23,8 @@ BOLD="\\033[1;39m" NORMAL="\\033[0;39m" ERROR="\\033[1;31m" +. /etc/init/functions + if [ -e "/lib/network/functions" ]; then . /lib/network/functions elif [ -e "lib/functions" ]; then @@ -309,30 +311,26 @@ function zone_show() { fi echo "##################################################" - echo -e "# ${ERROR}ZONE INFO - ${zone}${NORMAL}" - echo "##################################################" + echo "#" + echo -e "# Zone ${CLR_BOLD_BLU}${zone}${NORMAL}" + echo "# ------------------------------------------------" # Up or down? - if device_is_up ${zone}; then - echo -e "# Device is ${ERROR}up${NORMAL}." + if zone_is_up ${zone}; then + echo -e "# Status: ${CLR_BOLD_GRN}up${NORMAL}" else - echo -e "# Device is ${ERROR}down${NORMAL}." + echo -e "# Status: ${CLR_BOLD_RED}down${NORMAL}" fi echo "#" # Ports - echo -e "# ${ERROR}Ports:${NORMAL}" - local config - local port - for config in ${CONFIG_ZONES}/${zone}/port-*; do - port=${config##*/}; port=${port#port-}; port=${port%%-*} - if ZONE=${zone} cmd /lib/network/port ${port} attach ${config} &>/dev/null; then - echo "# ${config#port-} is up" - else - echo "# ${config#port-} is down" - fi - done - echo "#" + echo -e "# ${CLR_BOLD_BLU}Ports:${NORMAL}" + hooks_run_ports status ${CONFIG_ZONES}/${zone} --zone=${zone} + + echo "#" + echo -e "# ${CLR_BOLD_BLU}Zone configurations:${NORMAL}" + hooks_run_zones status ${CONFIG_ZONES}/${zone} --zone=${zone} + echo "#" }