]> git.ipfire.org Git - people/ms/network.git/blobdiff - functions.cli
Add support for pptp dialin.
[people/ms/network.git] / functions.cli
index 66d7be5a07c03189e21a10c8bad1adf9fe9d9657..3389b4106898d22c15a399978061e963b746d23d 100644 (file)
@@ -172,30 +172,60 @@ function cli_device_bonded() {
        local master=$(bonding_slave_get_master ${port})
        cli_print_fmt1 2 "Master" "${master}"
 
-       local active
-       [ "$(bonding_get_active_slave ${master})" = "${port}" ]
-       cli_print_fmt1 2 "Active slave" "$(cli_print_yesno $?)"
+       local mode=$(bonding_get_mode ${master})
+       if [ "${mode}" = "active-backup" ]; then
+               local active_slaves=$(bonding_get_slaves ${master} --active)
+               local active="false"
+               if list_match "${device}" ${active_slaves}; then
+                       active="true"
+               fi
+               cli_print_fmt1 2 "Active slave" "$(cli_print_yesno ${active})"
+       fi
+
        cli_space
 }
 
 function cli_device_bonding() {
        local device=${1}
+       assert isset device
 
        cli_headline 2 "Bonding information"
 
-       cli_print_fmt1 2 "Mode" "$(bonding_get_mode ${port})"
-       # XXX lacp rate
+       local mode=$(bonding_get_mode ${device})
+
+       cli_print_fmt1 2 "Mode" "${mode}"
+       if [ "${mode}" = "802.3ad" ]; then
+               local lacp_rate=$(bonding_get_lacp_rate ${device})
+               cli_print_fmt1 2 "LACP rate" "${lacp_rate}"
+       fi
        cli_space
 
-       local slave slave_prefix
-       local slave_active=$(bonding_get_active_slave ${device})
+       local slave slave_suffix
+       local active_slaves=$(bonding_get_slaves ${device} --active)
        for slave in $(bonding_get_slaves ${device}); do
-               if [ "${slave_active}" = "${slave}" ]; then
-                       slave_prefix="Slave (active)"
+               # Print the device status.
+               local status
+               case "$(device_get_status ${slave})" in
+                       ${STATUS_UP})
+                               status=${MSG_DEVICE_STATUS_UP}
+                               ;;
+                       ${STATUS_DOWN})
+                               status=${MSG_DEVICE_STATUS_DOWN}
+                               ;;
+                       ${STATUS_NOCARRIER})
+                               status=${MSG_DEVICE_STATUS_NOCARRIER}
+                               ;;
+                       *)
+                               status=${MSG_DEVICE_STATUS_UNKNOWN}
+                               ;;
+               esac
+
+               if list_match "${slave}" ${active_slaves}; then
+                       slave_suffix="(active)"
                else
-                       slave_prefix="Slave"
+                       slave_suffix=""
                fi
-               cli_print_fmt1 2 "${slave_prefix}" "${slave}"
+               cli_print_fmt1 2 "Slave ${slave}" "${status} ${slave_suffix}"
        done
        cli_space
 }
@@ -238,7 +268,7 @@ function cli_print_fmt1() {
        local level=${1}
        shift
 
-       local space=$(( 30 - (${level} * ${#IDENT}) ))
+       local space=$(( 34 - (${level} * ${#IDENT}) ))
        local format="%-${space}s %s"
 
        cli_print ${level} "${format}" "$@"
@@ -270,7 +300,7 @@ function cli_print_warning() {
        local level=${1}
        shift
 
-       cli_print ${level} "${COLOUR_WARN}%s${COLOUR_NORMAL}" "$@"
+       cli_print ${level} "${CLR_YELLOW_B}%s${CLR_RESET}" "$@"
 }
 
 function cli_space() {
@@ -318,6 +348,18 @@ function cli_get_val() {
        echo "${@#*=}"
 }
 
+function cli_get_bool() {
+       local value="$(cli_get_val "$@")"
+
+       if enabled value; then
+               print "true"
+               return ${EXIT_TRUE}
+       fi
+
+       print "false"
+       return ${EXIT_FALSE}
+}
+
 function cli_usage() {
        local command="$@"
        local basename="$(basename ${0})"