From patchwork Tue Feb 7 13:50:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yotam Gigi X-Patchwork-Id: 725120 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vHlzq1m9qz9s3s for ; Wed, 8 Feb 2017 00:48:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754442AbdBGNsc (ORCPT ); Tue, 7 Feb 2017 08:48:32 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:38672 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754016AbdBGNsW (ORCPT ); Tue, 7 Feb 2017 08:48:22 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yotamg@mellanox.com) with ESMTPS (AES256-SHA encrypted); 7 Feb 2017 15:48:15 +0200 Received: from dev-r-vrt-156.mtr.labs.mlnx (dev-r-vrt-156.mtr.labs.mlnx [10.212.156.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v17DmEwF006131; Tue, 7 Feb 2017 15:48:15 +0200 From: Yotam Gigi To: netdev@vger.kernel.org, stephen@networkplumber.org, eladr@mellanox.com, idosch@mellanox.com, jiri@mellanox.com, jhs@mojatatu.com, mrv@mojatatu.com Cc: Yotam Gigi Subject: [PATCH net-next/iproute v2 4/5] tc: bash-completion: Add support for filter actions Date: Tue, 7 Feb 2017 15:50:51 +0200 Message-Id: <1486475452-39214-5-git-send-email-yotamg@mellanox.com> X-Mailer: git-send-email 2.4.11 In-Reply-To: <1486475452-39214-1-git-send-email-yotamg@mellanox.com> References: <1486475452-39214-1-git-send-email-yotamg@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Previously, the autocomplete routine did not complete actions after a filter keyword, for example: $ tc filter add dev eth0 u32 [...] action did not suggest the actions list, and: $ tc filter add dev eth0 u32 [...] action mirred did not suggest the specific mirred parameters. Add the support for this kind of completion by adding the _tc_filter_action_options routine and invoking it from inside _tc_filter_options. Signed-off-by: Yotam Gigi --- bash-completion/tc | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/bash-completion/tc b/bash-completion/tc index e23f69c..e4c6804 100644 --- a/bash-completion/tc +++ b/bash-completion/tc @@ -386,11 +386,44 @@ _tc_bpf_options() return 0 } +# Complete with options names for filter actions. +# This function is recursive, thus allowing multiple actions statement to be +# parsed. +# Returns 0 is completion should stop after running this function, 1 otherwise. +_tc_filter_action_options() +{ + for ((acwd=$1; acwd < ${#words[@]}-1; acwd++)); + do + if [[ action == ${words[acwd]} ]]; then + _tc_filter_action_options $((acwd+1)) && return 0 + fi + done + + local action acwd + for ((acwd=$1; acwd < ${#words[@]}-1; acwd++)); do + if [[ $ACTION_KIND =~ ' '${words[acwd]}' ' ]]; then + _tc_one_of_list_from $acwd action + _tc_action_options $acwd && return 0 + fi + done + _tc_one_of_list_from $acwd $ACTION_KIND + return 0 +} + # Complete with options names for filters. # Returns 0 is completion should stop after running this function, 1 otherwise. _tc_filter_options() { - case $1 in + + for ((acwd=$1; acwd < ${#words[@]}-1; acwd++)); + do + if [[ action == ${words[acwd]} ]]; then + _tc_filter_action_options $((acwd+1)) && return 0 + fi + done + + filter=${words[$1]} + case $filter in basic) _tc_once_attr 'match action classid' return 0 @@ -685,8 +718,7 @@ _tc() for ((fltwd=$subcword; fltwd < ${#words[@]}-1; fltwd++)); do if [[ $FILTER_KIND =~ ' '${words[fltwd]}' ' ]]; then - filter=${words[fltwd]} - _tc_filter_options $filter && return 0 + _tc_filter_options $fltwd && return 0 fi done _tc_one_of_list $FILTER_KIND