]> git.ipfire.org Git - people/stevee/network.git/blobdiff - functions.cli
Don't use connection tracking for loopback traffic.
[people/stevee/network.git] / functions.cli
index 32458d80ee907ff6d1489e18cf9d90020d3c6edc..2d35e6420354108c82f203f31033940360cf3337 100644 (file)
@@ -118,7 +118,7 @@ function cli_device_headline() {
 
        if enabled long; then
                # Virtual devices.
-               device_is_virtual ${device} && cli_device_virtual ${device}
+               device_is_vlan ${device} && cli_device_vlan ${device}
 
                # Bonded devices.
                device_is_bonded ${device} && cli_device_bonded ${device}
@@ -154,13 +154,13 @@ function cli_device_stats() {
        cli_space
 }
 
-function cli_device_virtual() {
+function cli_device_vlan() {
        local device=${1}
 
        cli_headline 2 "VLAN"
 
-       cli_print_fmt1 2 "Parent" "$(virtual_get_parent ${device})"
-       cli_print_fmt1 2 "VID" "$(virtual_get_id ${device})"
+       cli_print_fmt1 2 "Parent" "$(vlan_get_parent ${device})"
+       cli_print_fmt1 2 "VID" "$(vlan_get_id ${device})"
        cli_space
 }
 
@@ -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
 }
@@ -208,7 +238,7 @@ function cli_headline() {
        local ident=$(cli_ident ${level})
 
        local out
-       printf -v out "${ident}${COLOUR_BOLD}${format}${COLOUR_NORMAL}\n" "$@"
+       printf -v out "${ident}${CLR_BLACK_B}${format}${CLR_RESET}\n" "$@"
        printf "${out}"
 }
 
@@ -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() {