Use list_etcnet_iface_filtered() to list interfaces

This commit is contained in:
Mikhail Efremov 2016-03-16 19:52:34 +03:00
parent 12565b2122
commit 28f27e4a55

View File

@ -550,13 +550,21 @@ __filter_etcnet_iface_default()
[ -n "$ifname" -a "$ifname" != "lo" -a "$ifname" != "default" -a "$ifname" != "unknown" ]
}
__filter_iface_type()
{
local ifacedir="$1"
local iftype="$2"
__filter_etcnet_iface_default "$ifacedir" || return 1
[ -n "$iftype" -a "$(read_iface_option "$ifacedir" TYPE)" = "$iftype" ] || return 1
}
__filter_iface_ppp()
{
local ifacedir="$1"
local t="${2:-}"
__filter_etcnet_iface_default "$ifacedir" || return 1
[ "$(read_iface_option "$ifacedir" TYPE)" = "ppp" ] || return 1
__filter_iface_type "$ifacedir" "ppp" || return 1
if [ -n "$t" ]; then
[ "$(read_iface_option "$ifacedir" PPPTYPE)" = "$t" ] || return 1
@ -565,6 +573,15 @@ __filter_iface_ppp()
return 0
}
__filter_iface_static()
{
local ifacedir="$1"
local ipv="${2:-4}"
__filter_etcnet_iface_default "$ifacedir" || return 1
[ "$(read_iface_option "$ifacedir" BOOTPROTO)" = "static" -a -s "$ifacedir/ipv${ipv}address" ] || return 1
}
### list various interface types
# list_etcnet_iface_filtered [ ifaces_dir [ filter_func [ filter_func params ... ]]]
#
@ -602,12 +619,7 @@ list_bond()
{
local dir="${1:-$etcnet_iface_dir}"
for i in `find "$dir" -mindepth 1 -maxdepth 1 -type d`; do
local name="${i##*/}"
[ "$name" != "lo" -a "$name" != "default" -a "$name" != "unknown" ] || continue
[ "$(read_iface_option $i TYPE)" = "bond" ] || continue
echo "$name"
done
list_etcnet_iface_filtered "$dir" __filter_iface_type "bond"
}
list_eth()
@ -634,17 +646,13 @@ list_iface()
done
}
# list_static_iface [ ip_version ]
# list_static_iface [ ip_version [ ifaces_dir ] ]
list_static_iface()
{
local p="${1:-4}"
local ipv="${1:-4}"
local dir="${2:-$etcnet_iface_dir}"
for i in `find "$etcnet_iface_dir" -type d`; do
local name="${i##*/}"
[ "$name" != "lo" -a "$name" != "default" -a "$name" != "unknown" ] || continue
[ "$(read_iface_option $i BOOTPROTO)" = "static" -a -s "$i/ipv${p}address" ] || continue
echo "${i##*/}"
done
list_etcnet_iface_filtered "$dir" __filter_iface_static "$ipv"
}
# list_network [ ip_version ]