]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
network: Improvements of the code.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 Aug 2009 10:42:25 +0000 (12:42 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 Aug 2009 10:42:25 +0000 (12:42 +0200)
Bonding does work much better.
"network zone show" gives some nice output now.

src/network/functions
src/network/hook-header
src/network/hooks/bonding
src/network/hooks/ethernet
src/network/hooks/ipv4-dhcp
src/network/hooks/ipv4-static
src/network/hooks/stp
src/network/network

index e4dfed4286d8c17337007ef22c349153a565978f..6b78d2214e9f24b82dfedc96293656f608ccf6f8 100644 (file)
@@ -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}/carrier)" = "1" ]
+}
+
 function device_get_free() {
        local destination=${1}
 
@@ -220,9 +225,17 @@ function device_rename() {
                return 4
        fi
 
-       ip link set ${source} down
+       local up
+       if device_is_up ${source}; then
+               ip link set ${source} down
+               up=1
+       fi
+
        ip link set ${source} name ${destination}
-       ip link set ${destination} up
+
+       if [ "${up}" = "1" ]; then
+               ip link set ${destination} up
+       fi
 }
 
 function hook_exists() {
index 8a5fb43b08e9ee8bc39da093dfff584d01ccb7c2..b2693b89d286915b096149802cdcd81020a17363 100644 (file)
@@ -5,6 +5,8 @@
 
 INDENT=" "
 
+HOOK_PRIO=100
+
 # Parse the command line
 action=
 port=
index decf30fc6bec98b00ab77b4288120fe2119d6da0..03f0a70b6c799f688f1445cce4e2a89c2e48bcea 100755 (executable)
 
 HOOK_NAME=bonding
 HOOK_TYPE=port
+HOOK_PRIO=50
 
 DEFAULT_MODE=
 
-# TODO: Need to detect link failures!
-
 function port_name() {
        echo "${zone}t+"
 }
@@ -55,15 +54,17 @@ case "${action}" in
        
                [ -n "${MODE}" ] && \
                        echo "${MODE}" > /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 $(</sys/class/net/${DEVICE}/bonding/slaves); do
+                               echo -e "#    ${CLR_BOLD_CYN}Slave port ${slave}${NORMAL}"
+
+                               echo -n "#      State: " 
+                               if device_is_up ${slave}; then
+                                       echo -e "${CLR_BOLD_GRN}up${NORMAL}"
+                               else
+                                       echo -e "${CLR_BOLD_RED}down${NORMAL}"
+                               fi
+
+                               echo -n "#      Link : "
+                               if device_has_carrier ${slave}; then
+                                       echo -e "${CLR_BOLD_GRN}yes${NORMAL}"
+                               else
+                                       echo -e "${CLR_BOLD_RED}no${NORMAL}" 
+                               fi
+                        done
                else
-                       log_failure_msg "Port $(port_name) is down"
+                       echo -e "#    State: ${CLR_BOLD_RED}down${NORMAL}"
                fi
-               exit ${RET}
+
+               device_is_up ${MAC}
+               exit ${?}
                ;;
 
        *)
index 61839176ebc2f0fc4bf436edfd08a00f1fa625d8..e6e364ff66a42971209381e459df108f039eca08 100755 (executable)
@@ -109,14 +109,23 @@ EOF
                ;;
 
        status)
-               device_is_up ${MAC}
-               RET=$?
-               if [ $RET -eq 0 ]; then
-                       echo "Port $(port_name) is up"
+               echo -e "#  ${CLR_BOLD_CYN}Ethernet port $(devicify ${MAC}) (${MAC})${NORMAL}"
+               echo -n "#   State: "
+               if device_is_up ${MAC}; then
+                       echo -e "${CLR_BOLD_GRN}up${NORMAL}"
+               else
+                       echo -e "${CLR_BOLD_RED}down${NORMAL}"
+               fi
+               echo -n "#   Link : "
+               if device_has_carrier ${MAC}; then
+                       echo -e "${CLR_BOLD_GRN}yes${NORMAL}"
                else
-                       echo "Port $(port_name) is down"
+                       echo -e "${CLR_BOLD_RED}no${NORMAL}" 
                fi
-               exit ${RET}
+               echo "#"
+
+               device_is_up ${MAC}
+               exit ${?}
                ;;
 
        *)
index dd372714337962ca39c088f1f083ba2e2ddde5b5..829182f6262a3b6eebeb7ebe5951ee97de832456 100755 (executable)
@@ -48,7 +48,7 @@ case "${action}" in
        post-down)
                ;;
 
-       config)
+       add)
                while [ $# -gt 0 ]; do
                        case "$1" in
                                --hostname=*)
@@ -67,6 +67,9 @@ HOSTNAME="${HOSTNAME}"
 EOF
                [ "$?" = "0" ] && exit ${EXIT_OK} || exit ${EXIT_ERROR}
                ;;
+
+       rem)
+               ;;
        
        *)
                echo "Usage: ${0} {config|pre-up|post-up|pre-down|post-down|status} [interface]"
index 21097f94d9dc5e77544e0da18dda7485abecea2d..7db442884c2398ce2392910a5fa57585b6dfbd13 100755 (executable)
@@ -58,12 +58,18 @@ case "${action}" in
 
        status)
                check_config
-               # XXX Is there a better way?
-               if (ip route get ${IP} | grep -q ^local); then
-                       exit ${EXIT_OK}
-               else
-                       exit ${EXIT_ERROR}
+               echo -e "#  ${CLR_BOLD_CYN}IPv4 static: ${IP}/${PREFIX}${NORMAL}"
+               if [ -n "${GATEWAY}" ]; then
+                       echo    "#    Gateway: ${GATEWAY}"
+                       echo -n "#      Reachable: "
+                       if ping -c1 -w1 -I ${zone} ${GATEWAY} &>/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}
index 038b001ba2bba733883f675a1cd7491c860485b5..503c4e9e8ed991de54e2818cd835d25dbfe72c3a 100755 (executable)
@@ -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
index e02d549a6af3428c9a4bb20b81186e2362db6a10..38ca3ba43ddd614a1f737cb86ae05a47d404233a 100644 (file)
@@ -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    "#"
 
 }