summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2014-09-23 13:08:54 +0200
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2014-09-23 13:08:54 +0200
commit534735d686bccbff59ec6d417fb359e7294cf544 (patch)
tree175393bf56739d67d053f3051a5f865367447e3a
parent584b6eec65563fb15cdff83c93ab3c6187f8ac4c (diff)
downloadipset-534735d686bccbff59ec6d417fb359e7294cf544.tar.gz
The utils are updated from their sources
-rw-r--r--utils/ipset_bash_completion/ipset_bash_completion186
1 files changed, 109 insertions, 77 deletions
diff --git a/utils/ipset_bash_completion/ipset_bash_completion b/utils/ipset_bash_completion/ipset_bash_completion
index 25f8db2..b6d94c2 100644
--- a/utils/ipset_bash_completion/ipset_bash_completion
+++ b/utils/ipset_bash_completion/ipset_bash_completion
@@ -25,7 +25,7 @@
# -----------------------------------------------------------------
# Compatible with ipset versions: 6+
# Tested with ipset versions:
-# 6.20.1
+# 6.22
# -----------------------------------------------------------------
# Requirements:
#
@@ -46,7 +46,7 @@
#
# -----------------------------------------------------------------
#
-# Version 2.5
+# Version 2.6
#
# -----------------------------------------------------------------
@@ -765,6 +765,47 @@ else
fi
}
+_ipset_complete_mac_spec() {
+local lcur="$1" mac rest a b addr str_tmp
+local str_regex='^([[:xdigit:]]{2})(:[[:xdigit:]]{2}){5}$'
+local -i x=y=0
+if [[ ${_IPSET_MAC_COMPL_MODE:=both} = both ]]; then
+ x=1 y=1
+elif [[ $_IPSET_MAC_COMPL_MODE = file ]]; then
+ x=1
+elif [[ $_IPSET_MAC_COMPL_MODE = system ]]; then
+ y=1
+fi
+if ((x)); then
+ if [[ $_IPSET_MACLIST_FILE && -r $_IPSET_MACLIST_FILE ]]; then
+ # if a file with mac addresses is in env var, load em
+ while read -r mac rest; do
+ [[ $mac = *([[:blank:]])\#* ]] && continue
+ mac="${mac//\#*/}"
+ [[ $mac =~ $str_regex ]] && printf "%s\n" "$mac"
+ done < "${_IPSET_MACLIST_FILE}"
+ fi
+fi
+if ((y)); then
+ # read arp cache, addresses of local interfaces and /etc/ethers
+ str_tmp=$(while read a b addr rest; do
+ [[ $addr =~ $str_regex ]] && printf "%s\n" "$addr"
+ done < <(PATH=$PATH:/sbin command arp -n 2>/dev/null))
+ str_tmp+=" $(while read -r; do
+ [[ $REPLY = *link/loopback* ]] && continue
+ REPLY=${REPLY#*link/*+([[:blank:]])}
+ REPLY=${REPLY%+([[:blank:]])brd*}
+ [[ $REPLY =~ $str_regex ]] && printf "%s\n" "$REPLY"
+ done < <(PATH=$PATH:/sbin command ip -o link show 2>/dev/null))"
+ if [[ -r /etc/ethers ]]; then
+ str_tmp+=" $(while read -r addr rest; do
+ [[ $addr =~ $str_regex ]] && printf "%s\n" "$addr"
+ done < /etc/ethers)"
+ fi
+ printf "%s\n" "$str_tmp"
+fi
+}
+
# -----------------------------------------------------------------
# Main
# -----------------------------------------------------------------
@@ -776,6 +817,7 @@ local str_glob str_regex str_prefix str_suffix
local str_tmp="" str_var=""
local str_timeout="timeout" str_order="before after" str_forceadd=""
local str_counters="" str_bp_counters="" str_comment="" str_markmask=""
+local str_skbinfo="" str_skbflags=""
local -i i=x=y=0
local -i got_bashcompl=got_action=action_index=order_index=set_has_timeout=0
local -i got_bp_proto=0
@@ -867,28 +909,36 @@ read -a ips_version <<< ${ips_version//./ }
# ipset -ge v6.19 has counters flag
# ipset -ge v6.20 has comment flag
-# ipset -ge v6.2? has hash:ip,mark markmask flag
+# ipset -ge v6.21 has hash:ip,mark markmask flag
+# ipset -ge v6.22 has skbinfo flag
if ((ips_version[0] > 6)); then
str_counters="counters"
str_bp_counters="bytes packets"
str_comment="comment"
str_markmask="markmask"
+ str_skbinfo="skbinfo" str_skbflags="skbmark skbprio skbqueue"
got_bp_proto=1
-else
- if ((ips_version[0] == 6 && ips_version[1] >= 19)); then
- str_counters="counters"
- str_bp_counters="bytes packets"
- fi
- if ((ips_version[0] == 6 && ips_version[1] >= 20)); then
+elif ((ips_version[0] == 6)); then
+ if ((ips_version[1] >= 22)); then
str_comment="comment"
+ str_markmask="markmask"
+ str_forceadd="forceadd"
+ str_skbinfo="skbinfo" str_skbflags="skbmark skbprio skbqueue"
got_bp_proto=1
- fi
- if ((ips_version[0] == 6 && ips_version[1] >= 21)); then
+ elif ((ips_version[1] >= 21)); then
str_comment="comment"
str_markmask="markmask"
str_forceadd="forceadd"
got_bp_proto=1
+ elif ((ips_version[1] >= 20)); then
+ str_comment="comment"
+ got_bp_proto=1
+ elif ((ips_version[1] >= 19)); then
+ str_counters="counters"
+ str_bp_counters="bytes packets"
fi
+else
+ return 0
fi
# expecting _get_comp_words_by_ref() to exist from bash_completion
@@ -1004,7 +1054,7 @@ case "${words[i]}" in
order_index=$i str_order=""
fi
;;
- timeout|range|maxelem|family|hashsize|size|netmask|nomatch|counters|bytes|packets|comment|markmask|forceadd)
+ timeout|range|maxelem|family|hashsize|size|netmask|nomatch|counters|bytes|packets|comment|markmask|forceadd|skbinfo|skbmark|skbprio|skbqueue)
if ((got_action && i > action_index+2)); then
str_tmp="$COMP_LINE"
[[ $str_setname = ${words[i]} ]] && str_tmp="${str_tmp/${words[i]}/}"
@@ -1174,53 +1224,17 @@ elif ((cword == action_index+2)) && [[ $str_setname = $prev ]]; then
_ipset_complete_netnet_spec "$cur"
_ipset_colon_ltrim "$cur"
;;
+ hash:mac)
+ COMPREPLY=( $( compgen -W '$(_ipset_complete_mac_spec)' -- "$cur" ) )
+ _ipset_colon_ltrim "$cur"
+ ;;
bitmap:ip,mac)
if [[ $cur = *,* ]]; then
str_prefix="$cur" cur="${cur#*,}"
str_prefix="${str_prefix%$cur}"
- str_regex='^([[:xdigit:]]{2})(:[[:xdigit:]]{2}){5}$'
- x=0 y=0
- if [[ ${_IPSET_MAC_COMPL_MODE:=both} = both ]]; then
- x=1 y=1
- elif [[ $_IPSET_MAC_COMPL_MODE = file ]]; then
- x=1
- elif [[ $_IPSET_MAC_COMPL_MODE = system ]]; then
- y=1
- fi
- if ((x)); then
- if [[ $_IPSET_MACLIST_FILE && -r $_IPSET_MACLIST_FILE ]]
- then
- # if a file with mac addresses is in env var, load em
- str_tmp=$(while read -r mac rest; do
- [[ $mac = *([[:blank:]])\#* ]] && continue
- mac="${mac//\#*/}"
- [[ $mac =~ $str_regex ]] && printf "%s\n" "$mac"
- done < "${_IPSET_MACLIST_FILE}")
- COMPREPLY=( $( compgen -P "$str_prefix" \
- -W "$str_tmp" -- "$cur" ) )
- _ipset_colon_ltrim "$str_prefix$cur"
- fi
- fi
- if ((y)); then
- # read arp cache, addresses of local interfaces and /etc/ethers
- str_tmp=$(while read a b addr rest; do
- [[ $addr =~ $str_regex ]] && printf "%s\n" "$addr"
- done < <(PATH=$PATH:/sbin command arp -n 2>/dev/null))
- str_tmp+=" $(while read -r; do
- [[ $REPLY = *link/loopback* ]] && continue
- REPLY=${REPLY#*link/*+([[:blank:]])}
- REPLY=${REPLY%+([[:blank:]])brd*}
- [[ $REPLY =~ $str_regex ]] && printf "%s\n" "$REPLY"
- done < <(PATH=$PATH:/sbin command ip -o link show 2>/dev/null))"
- if [[ -r /etc/ethers ]]; then
- str_tmp+=" $(while read -r addr rest; do
- [[ $addr =~ $str_regex ]] && printf "%s\n" "$addr"
- done < /etc/ethers)"
- fi
- COMPREPLY+=( $( compgen -P "$str_prefix" -W "$str_tmp" \
- -- "$cur" ) )
- _ipset_colon_ltrim "$str_prefix$cur"
- fi
+ COMPREPLY+=( $( compgen -P "$str_prefix" -W '$(_ipset_complete_mac_spec)' \
+ -- "$cur" ) )
+ _ipset_colon_ltrim "$str_prefix$cur"
else
compopt -o nospace
_ipset_complete_host_spec "$cur" --v4 --no-range
@@ -1480,20 +1494,23 @@ elif ((cword == action_index+3)) && [[ $cur != -* ]]; then
if ! _ipset_set_has_option comment "$str_setname"; then
str_comment=""
fi
+ if ! _ipset_set_has_option skbinfo "$str_setname"; then
+ str_skbflags=""
+ fi
case "$str_type" in
hash:*net*)
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts $str_timeout $str_bp_counters $str_comment nomatch)' \
+ '$(_ipset_dedupe_cmd_opts $str_timeout $str_bp_counters $str_comment $str_skbflags nomatch)' \
-- "$cur" ) )
;;
hash:*!(net)*|bitmap:*)
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts $str_timeout $str_bp_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts $str_timeout $str_bp_counters $str_skbflags $str_comment)' \
-- "$cur" ) )
;;
list:*)
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts $str_order $str_timeout $str_bp_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts $str_order $str_timeout $str_bp_counters $str_skbflags $str_comment)' \
-- "$cur" ) )
;;
esac
@@ -1502,27 +1519,27 @@ elif ((cword == action_index+3)) && [[ $cur != -* ]]; then
case "$prev" in
hash:ip,mark)
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts family hashsize timeout maxelem $str_counters $str_markmask $str_comment $str_forceadd)' \
+ '$(_ipset_dedupe_cmd_opts family hashsize timeout maxelem $str_counters $str_skbinfo $str_markmask $str_comment $str_forceadd)' \
-- "$cur" ) )
;;
hash:*)
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts family hashsize timeout maxelem $str_counters $str_comment $str_forceadd)' \
+ '$(_ipset_dedupe_cmd_opts family hashsize timeout maxelem $str_counters $str_skbinfo $str_comment $str_forceadd)' \
-- "$cur" ) )
;;
bitmap:ip)
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts range netmask timeout $str_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts range netmask timeout $str_counters $str_skbinfo $str_comment)' \
-- "$cur" ) )
;;
bitmap:!(ip)?*)
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts range timeout $str_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts range timeout $str_counters $str_skbinfo $str_comment)' \
-- "$cur" ) )
;;
list:*)
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts size timeout $str_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts size timeout $str_counters $str_skbinfo $str_comment)' \
-- "$cur" ) )
;;
esac
@@ -1539,7 +1556,7 @@ elif ((cword == action_index+3)) && [[ $cur != -* ]]; then
elif ((cword == action_index+3)) && [[ $cur = -* ]]; then
_ipset_get_options
elif ((cword >= action_index+4)) && [[ $cur = -* ]]; then # add all following hyphen options
- if [[ $prev != @(timeout|hashsize|size|family|maxelem|range|netmask|before|after|bytes|packets|comment|markmask) ]]
+ if [[ $prev != @(timeout|hashsize|size|family|maxelem|range|netmask|before|after|bytes|packets|comment|markmask|skbmark|skbprio|skbqueue) ]]
then
_ipset_get_options
fi
@@ -1558,25 +1575,40 @@ elif ((cword >= action_index+4)); then # add all following non-hyphen options
if ! _ipset_set_has_option comment "$str_setname"; then
str_comment=""
fi
+ if ! _ipset_set_has_option skbinfo "$str_setname"; then
+ str_skbflags=""
+ fi
# validate option argument values
if [[ ${_IPSET_VALIDATE_INPUT-1} ]]; then
for ((x=$action_index+3; x < ${#words[@]}; x++)); do
- [[ ${words[x]} = @(timeout|bytes|packets) && \
- ${words[x+1]} != @(+([[:digit:]])|0[xX]+([[:xdigit:]])) ]] && return 0
+ if [[ ${words[x]} = @(timeout|bytes|packets) ]]; then
+ [[ ${words[x+1]} = @(+([[:digit:]])|0[xX]+([[:xdigit:]])) ]] || return 0
+ elif [[ ${words[x]} = skbmark ]]; then
+ if [[ ${words[x+1]} = 0[xX]+([[:xdigit:]])?(/0[xX]+([[:xdigit:]])) ]]; then
+ (( ${words[x+1]%/*} >= 0 && ${words[x+1]%/*} <= 0xFFFFFFFF )) || return 0
+ (( ${words[x+1]#*/} >= 0 && ${words[x+1]#*/} <= 0xFFFFFFFF )) || return 0
+ else
+ return 0
+ fi
+ elif [[ ${words[x]} = skbprio ]]; then
+ [[ ${words[x+1]} = +([[:xdigit:]]):?(+([[:xdigit:]])) ]] || return 0
+ elif [[ ${words[x]} = skbqueue ]]; then
+ [[ ${words[x+1]} = +([[:digit:]]) ]] || return 0
+ fi
done
fi
case "$str_type" in
hash:*net*)
- if [[ $prev != @(timeout|bytes|packets|comment) ]]; then
+ if [[ $prev != @(timeout|bytes|packets|comment|skbmark|skbprio|skbqueue) ]]; then
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts $str_timeout $str_bp_counters $str_comment nomatch)' \
+ '$(_ipset_dedupe_cmd_opts $str_timeout $str_bp_counters $str_comment $str_skbflags nomatch)' \
-- "$cur" ) )
fi
;;
hash:*!(net)*|bitmap:*)
- if [[ $prev != @(timeout|bytes|packets|comment) ]]; then
+ if [[ $prev != @(timeout|bytes|packets|comment|skbmark|skbprio|skbqueue) ]]; then
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts $str_timeout $str_bp_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts $str_timeout $str_bp_counters $str_comment $str_skbflags)' \
-- "$cur" ) )
fi
;;
@@ -1584,9 +1616,9 @@ elif ((cword >= action_index+4)); then # add all following non-hyphen options
if [[ $prev = @(before|after) ]] && ((cword-1 == order_index)); then
_ipset_complete_elements "$cur"
_ipset_colon_ltrim "$cur"
- elif [[ $prev != @(timeout|bytes|packets) ]]; then
+ elif [[ $prev != @(timeout|bytes|packets|skbmark|skbprio|skbqueue) ]]; then
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts $str_order $str_timeout $str_bp_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts $str_order $str_timeout $str_bp_counters $str_comment $str_skbflags)' \
-- "$cur" ) )
fi
;;
@@ -1626,7 +1658,7 @@ elif ((cword >= action_index+4)); then # add all following non-hyphen options
-- "$cur" ) )
elif [[ $prev != @(hashsize|timeout|maxelem|markmask) ]]; then
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts family hashsize timeout maxelem $str_counters $str_markmask $str_comment $str_forceadd)' \
+ '$(_ipset_dedupe_cmd_opts family hashsize timeout maxelem $str_counters $str_markmask $str_comment $str_forceadd $str_skbinfo)' \
-- "$cur" ) )
fi
;;
@@ -1637,28 +1669,28 @@ elif ((cword >= action_index+4)); then # add all following non-hyphen options
-- "$cur" ) )
elif [[ $prev != @(hashsize|timeout|maxelem) ]]; then
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts family hashsize timeout maxelem $str_counters $str_comment $str_forceadd)' \
+ '$(_ipset_dedupe_cmd_opts family hashsize timeout maxelem $str_counters $str_comment $str_forceadd $str_skbinfo)' \
-- "$cur" ) )
fi
;;
bitmap:ip)
if [[ $prev != @(range|netmask|timeout) ]]; then
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts range netmask timeout $str_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts range netmask timeout $str_counters $str_comment $str_skbinfo)' \
-- "$cur" ) )
fi
;;
bitmap:!(ip)?*)
if [[ $prev != @(range|timeout) ]]; then
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts range timeout $str_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts range timeout $str_counters $str_comment $str_skbinfo)' \
-- "$cur" ) )
fi
;;
list:*)
if [[ $prev != @(size|timeout) ]]; then
COMPREPLY=( $( compgen -W \
- '$(_ipset_dedupe_cmd_opts size timeout $str_counters $str_comment)' \
+ '$(_ipset_dedupe_cmd_opts size timeout $str_counters $str_comment $str_skbinfo)' \
-- "$cur" ) )
fi
;;