]> git.ipfire.org Git - people/arne_f/network.git/blobdiff - hooks/bridge
network: New function beautify_time.
[people/arne_f/network.git] / hooks / bridge
index 257a12fb66418c652360165e07790da2d4fef7a2..9b98d482c6e40339278af959271bf544407166d4 100755 (executable)
@@ -21,7 +21,8 @@
 
 . /lib/network/header-zone
 
-HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE MAC MTU"
+HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE STP_PRIORITY"
+HOOK_SETTINGS="${HOOK_SETTINGS} MAC MTU"
 
 # Default values
 MAC=$(mac_generate)
@@ -30,12 +31,14 @@ STP="on"
 STP_FORWARD_DELAY=0
 STP_HELLO=2
 STP_MAXAGE=20
+STP_PRIORITY=512 # XXX check out better value
 
 function _check() {
        assert ismac MAC
        assert isbool STP
        assert isinteger STP_HELLO
        assert isinteger STP_FORWARD_DELAY
+       assert isinteger STP_PRIORITY
        assert isinteger MTU
 }
 
@@ -51,6 +54,9 @@ function _parse_cmdline() {
                        --stp-forward-delay=*)
                                STP_FORWARD_DELAY=${1#--stp-forward-delay=}
                                ;;
+                       --stp-priority=*)
+                               STP_PRIORITY=${1#--stp-priority=}
+                               ;;
                        --mtu=*)
                                MTU=${1#--mtu=}
                                ;;
@@ -75,7 +81,7 @@ function _up() {
                brctl addbr ${zone}
        fi
 
-       [ -n "${MAC}" ] && device_set_mac ${zone} ${MAC}
+       [ -n "${MAC}" ] && device_set_address ${zone} ${MAC}
        [ -n "${MTU}" ] && device_set_mtu ${zone} ${MTU} 
 
        # Enable STP
@@ -93,6 +99,10 @@ function _up() {
                if [ -n "${STP_MAXAGE}" ]; then
                        brctl setmaxage ${zone} ${STP_MAXAGE}
                fi
+
+               if [ -n "${STP_PRIORITY}" ]; then
+                       brctl setbridgeprio ${zone} ${STP_PRIORITY}
+               fi
        else
                brctl stp ${zone} off
        fi
@@ -136,6 +146,41 @@ function _down() {
        exit $?
 }
 
+function _status() {
+       local zone=${1}
+
+       cli_status_headline ${zone}
+
+       # Exit if zone is down
+       if ! zone_is_up ${zone}; then
+               echo # Empty line
+               exit ${EXIT_ERROR}
+       fi
+
+       # XXX Add bridge stp priority here
+       # brctl does not give any information about that
+
+       cli_headline "    Spanning Tree Protocol information:"
+       echo   "        Bridge ID             : $(stp_bridge_id ${zone})"
+       echo   "        Designated root       : $(stp_designated_root ${zone})"
+       echo   "        Path cost             : $(stp_pathcost ${zone})"
+       echo # Empty line
+
+       # Topology information
+       printf "        Topology changing     : %6s\n" $(stp_topology_change ${zone})
+       printf "        Topology change time  : %6s\n" $(beautify_time $(stp_topology_change_time ${zone}))
+       printf "        Topology change count : %6s\n" $(stp_topology_change_count ${zone})
+
+       cli_headline "    Ports:"
+       zone_ports_cmd status ${zone}
+
+       cli_headline "    Configurations:"
+       zone_configs_cmd status ${zone}
+
+       echo # Empty line
+       exit ${EXIT_OK}
+}
+
 function _addport() {
        local zone=${1}
        local hook=${2}