mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-10-31 18:58:01 +00:00
library script to parse vrf devices into associative array
This commit is contained in:
49
lib_vrf.bash
Executable file
49
lib_vrf.bash
Executable file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# create an associative array of vrf interfaces and their ports
|
||||||
|
|
||||||
|
IFLINES=()
|
||||||
|
declare -A IFNAMES
|
||||||
|
declare -A VRFNAMES
|
||||||
|
|
||||||
|
while read line; do
|
||||||
|
IFLINES+=("$line")
|
||||||
|
done < <(ip -o link show)
|
||||||
|
|
||||||
|
RE_MASTER=' master ([^ ]+) state '
|
||||||
|
for item in "${IFLINES[@]}"; do
|
||||||
|
#echo -e "\t$item"
|
||||||
|
[[ x$item = x ]] && continue
|
||||||
|
|
||||||
|
IFS=': ' hunks=($item)
|
||||||
|
[[ "${hunks[1]}" = "" ]] && continue
|
||||||
|
|
||||||
|
ifname="${hunks[1]}"
|
||||||
|
[[ "$ifname" = *NOARP,MASTER* ]] && continue
|
||||||
|
|
||||||
|
IFNAMES["$ifname"]="unknown"
|
||||||
|
|
||||||
|
if [[ $item = *master* ]] && [[ $item = *vrf* ]]; then
|
||||||
|
#echo "Looking for vrf in $ifname"
|
||||||
|
if [[ $item =~ $RE_MASTER ]]; then
|
||||||
|
[[ x${BASH_REMATCH[1]} = x ]] && continue;
|
||||||
|
vrfname=${BASH_REMATCH[1]};
|
||||||
|
#echo "[[[$ifname]]] [[[$vrfname]]]"
|
||||||
|
IFNAMES["$ifname"]="$vrfname"
|
||||||
|
VRFNAMES["$vrfname"]="$ifname"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ x$VRF_DEBUG = x1 ]]; then
|
||||||
|
echo "Interfaces: "
|
||||||
|
for ifname in "${!IFNAMES[@]}"; do
|
||||||
|
echo "IFN $ifname => ${IFNAMES[$ifname]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "virtual routers: "
|
||||||
|
for vrfname in "${!VRFNAMES[@]}"; do
|
||||||
|
echo "VRF $vrfname => ${VRFNAMES[$vrfname]}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
#
|
||||||
Reference in New Issue
Block a user