Artyom A Anikeev

completed "fix", added "down"

... ... @@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
CMD="$1"; shift;
eerror() {
echo "$@" >&2
}
... ... @@ -66,6 +68,7 @@ newconfig_popallwrite() {
BUF[$BUFNUM]=""
}
# INPUT: 10.2:thor.ext; OUTPUT: environments: VLAN, SUBVLAN, BRNAME
parse_vlan_subvlan_bridge() {
VLAN_N_BRIDGE="$1"; shift
... ... @@ -98,14 +101,30 @@ parse_vlan_subvlan_bridge() {
return;
}
CONFIG_PATH="./ipw-configsample"
get_brname_byslave() {
SLAVE="$1"; shift
source "$CONFIG_PATH"
find /sys/devices/virtual/net -wholename '*/brif/'"$SLAVE" | awk -F '/' '{print $6}'
}
NEWCONFIG_TMPPATH="/tmp/.~ipw"
get_vlan_n_bridges() {
awk '{if(NR>2) if( system( "[ -d /sys/devices/virtual/net/*/brif/"$1" ] " ) != 0 ) print $1":"}' < /proc/1/net/vlan/config
find /sys/devices/virtual/net -wholename '*/brif' -empty | awk -F '/' '{print ":"$6}'
find /sys/devices/virtual/net -wholename '*/brif/*' | awk -F '/' '{print $8":"$6}'
}
case "$CMD" in
down)
IPW_CONFIG_PATH=/dev/null
CMD='fix'
;;
esac
CMD="$1"; shift;
IPW_CONFIG_PATH="${IPW_CONFIG_PATH:-/etc/ipw.conf}"
source "$IPW_CONFIG_PATH"
NEWCONFIG_TMPPATH="/tmp/.~ipw"
NEWCONFIG=0
case "$CMD" in
... ... @@ -264,16 +283,15 @@ case "$CMD" in
for OLD_D1Q_IFACE in ${OLD_D1Q_IFACES[@]}; do
D1Q_IS_USED=0
OLD_SLAVES_VARIABLE="`cat /sys/class/net/`$OLD_D1Q_IFACE`/bonding/slaves`"
OLD_SLAVES_VARIABLE="${OLD_SLAVES_VARIABLE//[.]/_}[@]"
OLD_SLAVES="`cat /sys/class/net/"$OLD_D1Q_IFACE"/bonding/slaves`"
for D1Q_IFACE in ${D1Q_IFACES[@]}; do
if [[ "$D1Q_IFACE" == "$OLD_D1Q_IFACE" ]]; then #let's kick out useless slaves
SLAVES_VARIABLE="${D1Q_IFACE}_SLAVES"
SLAVES_VARIABLE="${SLAVES_VARIABLE//[.]/_}[@]"
for OLD_SLAVE in "${!OLD_SLAVES_VARIABLE}"; do
for OLD_SLAVE in ${OLD_SLAVES[@]}; do
SLAVE_IS_USED=0
for SLAVE in "${!SLAVES_VARIABLE}"; do
if [[ "$SLAVE" == "OLD_SLAVE" ]]; then
if [[ "$SLAVE" == "$OLD_SLAVE" ]]; then
SLAVE_IS_USED=1
break;
fi
... ... @@ -282,6 +300,7 @@ case "$CMD" in
if [[ "$SLAVE_IS_USED" == 0 ]]; then
#echo "ip link set dev $OLD_SLAVE down"
#echo "echo '-$OLD_SLAVE' > /sys/class/net/"$OLD_D1Q_IFACE"/bonding/slaves"
# [[ "$OLD_SLAVE" != "" ]] &&
echo "-$OLD_SLAVE" > /sys/class/net/"$OLD_D1Q_IFACE"/bonding/slaves
fi
done
... ... @@ -293,7 +312,51 @@ case "$CMD" in
if [[ "$D1Q_IS_USED" == 0 ]]; then #let's kick out useless d1q
#echo "ip link set dev $OLD_D1Q_IFACE down"
#echo "echo '-$D1Q_IFACE' > /sys/class/net/bonding_masters"
echo "-$D1Q_IFACE" > /sys/class/net/bonding_masters
echo "-$OLD_D1Q_IFACE" > /sys/class/net/bonding_masters
fi
done
#REMOVING UNNECESSARY BRIDGES AND VLANS
OLD_VLAN_N_BRIDGES=(`get_vlan_n_bridges`)
for LINE in ${OLD_VLAN_N_BRIDGES[@]}; do
echo ITERATION
parse_vlan_subvlan_bridge "$LINE"
OLD_BRNAME="$BRNAME"
OLD_VLANNAME="$VLANNAME"
##
echo "BRNAME $BRNAME"
echo "VLANNAME $VLANNAME"
##
IS_SLAVE=0
BRIDGE_IN_USE=0
VLAN_IN_USE=0
VLAN_N_BRIDGE_IN_USE=0
for D1Q_IFACE_TMP in ${D1Q_IFACES[@]}; do #we should keep slave ifaces
VLAN_N_BRIDGE_VARIABLE="${D1Q_IFACE_TMP}_VLAN_N_BRIDGES"
VLAN_N_BRIDGE_VARIABLE="${VLAN_N_BRIDGE_VARIABLE//[.]/_}[@]"
for VLAN_N_BRIDGE in "${!VLAN_N_BRIDGE_VARIABLE}"; do
parse_vlan_subvlan_bridge "${VLAN_N_BRIDGE}"
if [[ "$LINE" = "$D1Q_IFACE_TMP"."$VLAN_N_BRIDGE" ]]; then
BRIDGE_IN_USE=1
VLAN_IN_USE=1
VLAN_N_BRIDGE_IN_USE=1
break 2
elif [[ "$BRNAME" = "$OLD_BRNAME" ]]; then
BRIDGE_IN_USE=1
elif [[ "$VLANNAME" = "$OLD_VLANNAME" ]]; then
VLAN_IN_USE=1
fi
done
done
if [[ "$BRIDGE_IN_USE" = 0 ]]; then
#echo "ip link delete $OLD_BRNAME"
if [[ "$OLD_VLANNAME" != '' ]]; then
ip link set "$OLD_VLANNAME" nomaster
ip link delete "$OLD_VLANNAME"
fi
ip link delete "$OLD_BRNAME"
fi
done
... ... @@ -305,11 +368,10 @@ case "$CMD" in
D1Q_EXISTS=0
for OLD_D1Q_IFACE in ${OLD_D1Q_IFACES[@]}; do
if [[ "$D1Q_IFACE" == "$OLD_D1Q_IFACE" ]]; then #it's here. Let's fix it.
OLD_SLAVES_VARIABLE="`cat /sys/class/net/`$OLD_D1Q_IFACE`/bonding/slaves`"
OLD_SLAVES_VARIABLE="${OLD_SLAVES_VARIABLE//[.]/_}[@]"
OLD_SLAVES="`cat /sys/class/net/"$OLD_D1Q_IFACE"/bonding/slaves`"
for SLAVE in "${!SLAVES_VARIABLE}"; do
SLAVE_EXISTS=0
for OLD_SLAVE in "${!OLD_SLAVES_VARIABLE}"; do
for OLD_SLAVE in ${OLD_SLAVES[@]}; do
if [[ "$SLAVE" == "$OLD_SLAVE" ]]; then
SLAVE_EXISTS=1
break;
... ... @@ -340,7 +402,7 @@ case "$CMD" in
fi
echo "ip link set dev $D1Q_IFACE up"
#echo "ip link set dev $D1Q_IFACE up"
ip link set dev "$D1Q_IFACE" up
for SLAVE in "${!SLAVES_VARIABLE}"; do #slave starts after bond
... ... @@ -350,73 +412,6 @@ case "$CMD" in
VLAN_N_BRIDGE_VARIABLE="${D1Q_IFACE}_VLAN_N_BRIDGES"
VLAN_N_BRIDGE_VARIABLE="${VLAN_N_BRIDGE_VARIABLE//[.]/_}[@]"
#REMOVING UNNECESSARY BRIDGES AND VLANS
LINE_NUM=1;
#LINE_NUM=3;#skip lo, etc. Not necessary due to grep master
#LINE="`pwd | awk '{ printf $1 }'`"
LINE="`ip link show | grep master | awk '{ if (NR=="'"$LINE_NUM"'") printf $2 $9 "\n"}' | sed -e 's/@.*:/:/g'`"
##
echo "LINE <$LINE>"
echo "LINE_NUM <$LINE_NUM> ip link show | grep master | awk '{ if (NR==\"$LINE_NUM\") printf \$2 \$9 \"\\n\"}' | sed -e 's/@.*:/:/g'"
##
while [[ "$LINE" != "" ]]; do
parse_vlan_subvlan_bridge "$LINE"
OLD_BRNAME=$BRNAME
OLD_VLANNAME=$VLANNAME
##
echo "BRNAME $BRNAME"
echo "VLANNAME $VLANNAME"
##
let "LINE_NUM += 1";
LINE="`ip link show | grep master | awk '{ if (NR=="'"$LINE_NUM"'") printf $2 $9 "\n"}' | sed -e 's/@.*:/:/g'`"
IS_SLAVE=0
for D1Q_IFACE_TMP in ${D1Q_IFACES[@]}; do #we should keep slave ifaces
SLAVES_VARIABLE_TMP="${D1Q_IFACE_TMP}_SLAVES"
SLAVES_VARIABLE_TMP="${SLAVES_VARIABLE_TMP//[.]/_}[@]"
for SLAVE_TMP in "${!SLAVES_VARIABLE_TMP}"; do
if [[ "$SLAVE_TMP" == "$VLANNAME" ]]; then
IS_SLAVE=1
break;
fi
done
done
if [[ "$IS_SLAVE" = 0 ]]; then
BRIDGE_IN_USE=0
VLAN_IN_USE=0
VLAN_N_BRIDGE_IN_USE=0
for VLAN_N_BRIDGE in "${!VLAN_N_BRIDGE_VARIABLE}"; do
parse_vlan_subvlan_bridge "${VLAN_N_BRIDGE}"
if [[ "$LINE" = "$VLAN_N_BRIDGE" ]]; then
BRIDGE_IN_USE=1
VLAN_IN_USE=1
VLAN_N_BRIDGE_IN_USE=1
elif [[ "$BRNAME" = "$OLD_BRNAME" ]]; then
BRIDGE_IN_USE=1
elif [[ "$VLANNAME" = "$OLD_VLANNAME" ]]; then
VLAN_IN_USE=1
fi
done
if [[ "$VLAN_N_BRIDGE_IN_USE" = 0 ]]; then
#echo "ip link set $OLD_VLANNAME nomaster"
ip link set "$OLD_VLANNAME" nomaster
fi
if [[ "$VLAN_IN_USE" = 0 ]]; then
#echo "ip link delete $OLD_VLANNAME"
ip link delete "$OLD_VLANNAME"
fi
if [[ "$BRIDGE_IN_USE" = 0 ]]; then
#echo "ip link delete $OLD_BRNAME"
ip link delete "$OLD_BRNAME"
fi
fi
done
#CREATING OF NECESSARY BRIDGES AND VLANS
... ... @@ -428,7 +423,7 @@ case "$CMD" in
##
echo BRNAME $BRNAME
echo VLANNAME $VLANNAME
echo VLAN $VLAN
echo VLAN $VLApN
echo SUBVLAN $SUBVLAN
##
... ... @@ -439,7 +434,7 @@ case "$CMD" in
#VLAN STUFF
if [[ "$VLAN" != "" ]]; then
if [[ "`ip link show | grep "$FULL_VLAN_NAME"`" = "" ]]; then #should we create a new vlan?
if ! ip link show "$FULL_VLAN_NAME" 2>/dev/null; then #should we create a new vlan?
#ip link show | grep -q "$FULL_VLAN_NAME"
#if $?; then #should we create a new vlan?
if [[ "$SUBVLAN" != "" ]]; then #is it subvlan?
... ... @@ -448,7 +443,7 @@ case "$CMD" in
echo FULL_PARVLAN_NAME $FULL_PARVLAN_NAME
echo D1Q_IFACE $D1Q_IFACE
##
if [[ "`ip link show | grep "$FULL_PARVLAN_NAME"`" = "" ]]; then #should we create a new parent vlan?
if ! ip link show "$FULL_PARVLAN_NAME" 2>/dev/null; then #should we create a new parent vlan?
#echo "ip link add link $D1Q_IFACE name $FULL_PARVLAN_NAME type vlan id $VLAN" #vlan in bond
ip link add link "$D1Q_IFACE" name "$FULL_PARVLAN_NAME" type vlan id "$VLAN" #vlan in bond
#echo "ip link set dev $FULL_PARVLAN_NAME up"
... ... @@ -469,10 +464,11 @@ case "$CMD" in
#BRIDGE STUFF
echo BRIDGE STUFF "$BRNAME"
if [[ "$BRNAME" != "" ]]; then
#if [[ "`brctl show | grep "$BRNAME"`" = "" ]]; then #do this bridge exists?
if [[ "`ip link show | grep "$BRNAME"`" = "" ]]; then #do this bridge exists?
if ! ip link show "$BRNAME" 2>/dev/null; then #do this bridge exists?
#brctl addbr "$BRNAME"
#echo "ip link add "$BRNAME" type bridge"
ip link add "$BRNAME" type bridge
... ... @@ -480,8 +476,8 @@ case "$CMD" in
if [[ "$VLAN" != "" ]]; then
#OLD_BRNAME="`brctl show | grep "$FULL_VLANNAME" | awk '{print $1}'`"
OLD_BRNAME="`ip link show | grep master | grep "FULL_VLANNAME" | awk '{printf $9}'`"
if [[ "$OLD_BRNAME" = "" ]]; then #is this vlan nave been already enslaved?
OLD_BRNAME="`get_brname_byslave "$FULL_VLANNAME"`"
if [[ "$OLD_BRNAME" = "" ]]; then #is this vlan have been already enslaved?
#brctl addif "$BRNAME" "$FULL_VLANNAME"
#echo "ip link set "$FULL_VLAN_NAME" master "$BRNAME
ip link set "$FULL_VLAN_NAME" master "$BRNAME"
... ... @@ -502,13 +498,15 @@ case "$CMD" in
IP_CMDS_VARIABLE="${BRNAME//[.]/_}_IP"
IP_CMDS_VARIABLE="${IP_CMDS_VARIABLE}[@]"
for IP_CMD in "${!IP_CMDS_VARIABLE}"; do
echo ip "$IP_CMD" dev "$BRNAME" | bash
echo ip $IP_CMD dev "$BRNAME" | bash #2>/dev/null ||
# echo ip $IP_CMD | bash
done
else
IP_CMDS_VARIABLE="vlan${VLANNAME//[.]/_}_IP"
IP_CMDS_VARIABLE="${IP_CMDS_VARIABLE}[@]"
for IP_CMD in "${!IP_CMDS_VARIABLE}"; do
echo ip "$IP_CMD" dev "$VLANNAME" | bash
echo ip $IP_CMD dev "$VLANNAME" | bash #2>/dev/null ||
# echo ip $IP_CMD | bash
done
fi
done
... ...
... ... @@ -31,7 +31,7 @@ bond1_VLAN_N_BRIDGES=(
thor_ext_IP=(
"addr add 10.10.2.2/24"
"route add default gw 10.10.2.1"
"route add default via 10.10.2.1"
)
vlan10_5_IP=(
... ...