lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200331084253.2377588-4-idosch@idosch.org>
Date:   Tue, 31 Mar 2020 11:42:53 +0300
From:   Ido Schimmel <idosch@...sch.org>
To:     netdev@...r.kernel.org
Cc:     dsahern@...il.com, stephen@...workplumber.org, jiri@...lanox.com,
        mlxsw@...lanox.com, Ido Schimmel <idosch@...lanox.com>
Subject: [PATCH iproute2-next v2 3/3] bash-completion: devlink: Extend bash-completion for new commands

From: Ido Schimmel <idosch@...lanox.com>

Extend bash-completion for two new commands:

devlink trap policer set DEV policer POLICER [ rate RATE ] [ burst BURST ]
devlink trap policer show DEV policer POLICER

And for "policer" / "nopolicer" parameters in existing command:

devlink trap group set DEV group GROUP [ action { trap | drop } ]
                       [ policer POLICER ] [ nopolicer ]

Signed-off-by: Ido Schimmel <idosch@...lanox.com>
---
 bash-completion/devlink | 131 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 130 insertions(+), 1 deletion(-)

diff --git a/bash-completion/devlink b/bash-completion/devlink
index 45fba75c1539..45ca1fe6231e 100644
--- a/bash-completion/devlink
+++ b/bash-completion/devlink
@@ -62,6 +62,11 @@ _devlink_direct_complete()
             value=$(devlink -j trap group show 2>/dev/null \
                     | jq ".trap_group[\"$dev\"][].name")
             ;;
+        trap_policer)
+            dev=${words[4]}
+            value=$(devlink -j trap policer show 2>/dev/null \
+                    | jq ".trap_policer[\"$dev\"][].policer")
+            ;;
         health_dev)
             value=$(devlink -j health show 2>/dev/null | jq '.health' \
                     | jq 'keys[]')
@@ -678,6 +683,53 @@ _devlink_trap_set_action()
     esac
 }
 
+# Completion for devlink trap group set
+_devlink_trap_group_set()
+{
+    local -A settings=(
+        [action]=notseen
+        [policer]=notseen
+        [nopolicer]=notseen
+    )
+
+    if [[ $cword -eq 7 ]]; then
+        COMPREPLY=( $( compgen -W "action policer nopolicer" -- "$cur" ) )
+    fi
+
+    # Mark seen settings
+    local word
+    for word in "${words[@]:7:${#words[@]}-1}"; do
+        if [[ -n $word ]]; then
+            if [[ "${settings[$word]}" ]]; then
+                settings[$word]=seen
+            fi
+        fi
+    done
+
+    case $prev in
+        action)
+            COMPREPLY=( $( compgen -W "trap drop" -- "$cur" ) )
+            return
+            ;;
+        policer)
+            _devlink_direct_complete "trap_policer"
+            return
+            ;;
+    esac
+
+    local -a comp_words=()
+
+    # Add settings not seen to completions
+    local setting
+    for setting in "${!settings[@]}"; do
+        if [ "${settings[$setting]}" = notseen ]; then
+            comp_words+=( "$setting" )
+        fi
+    done
+
+    COMPREPLY=( $( compgen -W "${comp_words[*]}" -- "$cur" ) )
+}
+
 # Completion for devlink trap group
 _devlink_trap_group()
 {
@@ -701,7 +753,80 @@ _devlink_trap_group()
     esac
 
     if [[ ${words[3]} == "set" ]]; then
-        _devlink_trap_set_action 1
+        _devlink_trap_group_set
+    fi
+}
+
+# Completion for devlink trap policer set
+_devlink_trap_policer_set()
+{
+    local -A settings=(
+        [rate]=notseen
+        [burst]=notseen
+    )
+
+    if [[ $cword -eq 7 ]]; then
+        COMPREPLY=( $( compgen -W "rate burst" -- "$cur" ) )
+    fi
+
+    # Mark seen settings
+    local word
+    for word in "${words[@]:7:${#words[@]}-1}"; do
+        if [[ -n $word ]]; then
+            if [[ "${settings[$word]}" ]]; then
+                settings[$word]=seen
+            fi
+        fi
+    done
+
+    case $prev in
+        rate)
+            # Integer argument
+            return
+            ;;
+        burst)
+            # Integer argument
+            return
+            ;;
+    esac
+
+    local -a comp_words=()
+
+    # Add settings not seen to completions
+    local setting
+    for setting in "${!settings[@]}"; do
+        if [ "${settings[$setting]}" = notseen ]; then
+            comp_words+=( "$setting" )
+        fi
+    done
+
+    COMPREPLY=( $( compgen -W "${comp_words[*]}" -- "$cur" ) )
+}
+
+# Completion for devlink trap policer
+_devlink_trap_policer()
+{
+    case $cword in
+        3)
+            COMPREPLY=( $( compgen -W "set show" -- "$cur" ) )
+            return
+            ;;
+        4)
+            _devlink_direct_complete "dev"
+            return
+            ;;
+        5)
+            COMPREPLY=( $( compgen -W "policer" -- "$cur" ) )
+            return
+            ;;
+        6)
+            _devlink_direct_complete "trap_policer"
+            return
+            ;;
+    esac
+
+    if [[ ${words[3]} == "set" ]]; then
+        _devlink_trap_policer_set
     fi
 }
 
@@ -731,6 +856,10 @@ _devlink_trap()
             _devlink_trap_$command
             return
             ;;
+        policer)
+            _devlink_trap_$command
+            return
+            ;;
     esac
 }
 
-- 
2.24.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ