Artyom A Anikeev

There are a lot of changes. One may test))

Showing 1 changed file with 182 additions and 9 deletions
... ... @@ -71,6 +71,7 @@ parse_vlan_subvlan_bridge() {
if [[ "${VLAN_N_BRIDGE:0:1}" = ":" ]]; then
VLAN=""
VLANNAME=""
BRNAME="${VLAN_N_BRIDGE:1}"
else
# Splitting by ":"
... ... @@ -139,6 +140,8 @@ case "$CMD" in
eval "${SLAVES_VARIABLE}[\${#${SLAVES_VARIABLE}}]=\"$NEW_SLAVE\""
;;
del1qif)
;;
addbrif) #allow to add bridge/vlan in bonding
NEWCONFIG=1 # we need to update the config after the command
... ... @@ -184,6 +187,8 @@ case "$CMD" in
#D1Q_IFACES[ ${#D1Q_IFACES}]
;;
delbrif)
;;
addbr) #allow to add bridge without interfaces
NEWCONFIG=1 # we need to update the config after the command
... ... @@ -195,6 +200,8 @@ case "$CMD" in
eval "${VLAN_N_BRIDGE_VARIABLE}[\${#${VLAN_N_BRIDGE_VARIABLE}}]=\":${NEW_BRIDGE}\""
;;
delbr)
;;
addipcmd) #allow to add ip commnds for bridges/vlans
NEWCONFIG=1 # we need to update the config after the command
NEW_BRIDGE="$1"; shift
... ... @@ -204,23 +211,189 @@ case "$CMD" in
if [[ "${NEW_BRIDGE}" != "" ]]; then
# Getting commands for "ip"
IP_CMDS_VARIABLE="${NEW_BRIDGE//[.]/_}_IP" # br is used to start variable's name from non numerical symbol
IP_CMDS_VARIABLE="${NEW_BRIDGE//[.]/_}_IP"
IP_CMDS_VARIABLE="${IP_CMDS_VARIABLE}"
eval "${IP_CMDS_VARIABLE}[\${#${IP_CMDS_VARIABLE}}]=\"$NEW_IP_CMD\""
#echo $IP_CMDS_VARIABLE
fi
;;
delipcmd)
NEWCONFIG=1 # we need to update the config after the command
NEW_BRIDGE="$1"; shift
#ADDRMASK="$1"; shift
#GW="$1"; shift
NEW_IP_CMD="$@"
# TODO: implement this
#bond0_SLAVES[ ${#bond0_SLAVES
#[@]} ]="eth2"
;;
fix)
if [[ "${NEW_BRIDGE}" != "" ]]; then
IP_CMDS_VARIABLE="${NEW_BRIDGE//[.]/_}_IP"
IP_CMDS_VARIABLE="${IP_CMDS_VARIABLE}"
i=0
CMD_founded=0
for IP_CMD in "${!IP_CMDS_VARIABLE}"; do
if [[ "$IP_CMD" = "$NEW_IP_CMD" ]]; then
CMD_founded=1
else
TMP[$i]=$IP_CMD
(( i++ ))
fi
done
if [[ $CMD_founded -eq 0 ]]; then
eerror "There's no such command"
exit -1
fi
i=0
for IP_CMD in "${!TMP}"; do
IP_CMDS_VARIABLE[$i]=$IP_CMD
(( i++ ))
done
#eval "${IP_CMDS_VARIABLE}[\${#${IP_CMDS_VARIABLE}}]=\"$NEW_IP_CMD\""
#echo $IP_CMDS_VARIABLE
fi ;;
fix) #fix all interfaces to config state
#brctl addif bond0 eth2
for D1Q_IFACE in ${D1Q_IFACES[@]}; do
SLAVES_VARIABLE="${D1Q_IFACE}_SLAVES"
SLAVES_VARIABLE="${SLAVES_VARIABLE//[.]/_}[@]"
for SLAVE in "${!SLAVES_VARIABLE}"; do
#if [[ ]]; then
#???TODO:ask bircoph how to ensalve with ip
#else
#fi
echo "There are a place for a bond creating. Coming soon..."
done
VLAN_N_BRIDGE_VARIABLE="${D1Q_IFACE}_VLAN_N_BRIDGES"
VLAN_N_BRIDGE_VARIABLE="${VLAN_N_BRIDGE_VARIABLE//[.]/_}[@]"
#REMOVING UNNECESSARY BRIDGES AND VLANS
LINE_NUM=3;#skip lo, etc.
#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"
##
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"
fi
if [[ "$VLAN_IN_USE" = 0 ]]; then
echo "ip link delete $OLD_VLANNAME"
fi
if [[ "$BRIDGE_IN_USE" = 0 ]]; then
echo "ip link delete $OLD_BRNAME"
fi
let "LINE_NUM += 1";
LINE="`ip link show | grep master | awk '{ if (NR=="'"$LINE_NUM"'") printf $2 $9 "\n"}' | sed -e 's/@.*:/:/g'`"
##
echo "LINE $LINE"
##
done
#CREATING OF NECESSARY BRIDGES AND VLANS
for VLAN_N_BRIDGE in "${!VLAN_N_BRIDGE_VARIABLE}"; do
##
#echo $VLAN_N_BRIDGE
##
parse_vlan_subvlan_bridge "${VLAN_N_BRIDGE}"
##
echo BRNAME $BRNAME
echo VLANNAME $VLANNAME
echo VLAN $VLAN
echo SUBVLAN $SUBVLAN
##
FULL_VLAN_NAME="$D1Q_IFACE"."$VLANNAME"
##
echo FULL_VLAN_NAME $FULL_VLAN_NAME
##
#VLAN STUFF
if [[ "$VLAN" != "" ]]; then
if [[ "`ip link show | grep "$FULL_VLAN_NAME"`" = "" ]]; 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?
FULL_PARVLAN_NAME="$D1Q_IFACE"."$VLAN"
##
echo FULL_PARVLAN_NAME $FULL_PARVLAN_NAME
echo D1Q_IFACE $D1Q_IFACE
##
if [[ "`ip link show | grep "$VLAN"`" = "" ]]; 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
fi
echo "ip link add link $FULL_PARVLAN_NAME name $FULL_VLAN_NAME type vlan id $SUBVLAN" #subvlan in vlan
else
echo "ip link add link $D1Q_IFACE name $FULL_VLAN_NAME type vlan id $VLANNAME" #vlan in bond
fi
fi
fi
#BRIDGE STUFF
if [[ "$BRNAME" != "" ]]; then
#if [[ "`brctl show | grep "$BRNAME"`" = "" ]]; then #do this bridge exists?
if [[ "`ip link show | grep "$BRNAME"`" = "" ]]; then #do this bridge exists?
#brctl addbr "$BRNAME"
echo "ip link add "$BRNAME" type bridge"
fi
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?
#brctl addif "$BRNAME" "$FULL_VLANNAME"
echo "ip link set "$FULL_VLAN_NAME" master "$BRNAME
else
#brctl delif "$OLD_BRNAME" "FULL_VLANNAME"
echo "ip link set "$FULL_VLAN_NAME" nomaster"
#brctl addif "$BRNAME" "$FULL_VLANNAME"
echo "ip link set "$FULL_VLAN_NAME" master "$BRNAME
fi
fi
fi
done
done
;;
*)
;;
... ...