redmine
Committed by Artyom A Anikeev

Initial commit

File mode changed
#!/bin/bash
CONFIG_PATH="./ipw-configsample"
source "$CONFIG_PATH"
NEWCONFIG_TMPPATH="/tmp/.~ipw"
CMD="$1"; shift;
NEWCONFIG=0
case "$CMD" in
add1qif)
NEWCONFIG=1 # we need to update the config after the command
D1Q_IFACES[ ${#D1Q_IFACES}]
;;
addbrif)
NEWCONFIG=1 # we need to update the config after the command
BRNAME="$1"; shift
SLAVE="$1"; shift
# TODO: implement this
#bond0_SLAVES[ ${#bond0_SLAVES[@]} ]="eth2"
;;
fix)
#brctl addif bond0 eth2
;;
*)
;;
esac
newconfig_open() {
echo -n > "$NEWCONFIG_TMPPATH"
}
newconfig_write() {
LINE="$1"; shift;
[[ $NEWCONFIG -eq 0 ]] && return
echo "$LINE" >> "$NEWCONFIG_TMPPATH"
}
newconfig_commit() {
rm -f "$CONFIG_PATH"
mv "$NEWCONFIG_TMPPATH" "$CONFIG_PATH"
}
newconfig_push() {
BUFNUM="$1"; shift;
LINE="$1"; shift;
BUF[$BUFNUM]="${BUF[$BUFNUM]}
$LINE"
}
newconfig_popall() {
BUFNUM="$1"; shift;
BUF[$BUFNUM]=""
}
newconfig_popallwrite() {
BUFNUM="$1"; shift;
newconfig_write "${BUF[$BUFNUM]}"
BUF[$BUFNUM]=""
}
newconfig_open
newconfig_write "#"
newconfig_write ""
newconfig_write "D1Q_IFACES=("
for D1Q_IFACE in ${D1Q_IFACES[@]}; do
newconfig_write " $D1Q_IFACE"
newconfig_push 1 "${D1Q_IFACE}_SLAVES=("
SLAVES_VARIABLE="${D1Q_IFACE}_SLAVES"
SLAVES_VARIABLE="${SLAVES_VARIABLE//[.]/_}[@]"
for SLAVE in "${!SLAVES_VARIABLE}"; do
newconfig_push 1 " $SLAVE";
done
newconfig_push 1 ")"
# If there're no slaves then don't write anything about them
[[ $SLAVE_i -eq 0 ]] && newconfig_popall 1
VLAN_N_BRIDGE_VARIABLE="${D1Q_IFACE}_VLAN_N_BRIDGES"
VLAN_N_BRIDGE_VARIABLE="${VLAN_N_BRIDGE_VARIABLE//[.]/_}[@]"
for VLANS_N_BRIDGE in "${!VLAN_N_BRIDGE_VARIABLE}"; do
# Checking if no "vlan(.subvlan)?" is set
if [[ "${VLANS_N_BRIDGE:0:1}" = ":" ]]; then
VLAN=""
BRNAME="${VLANS_N_BRIDGE:1}"
else
# Splitting by ":"
WORDS=( ${VLANS_N_BRIDGE//[:]/ } )
# The second word defines interface name. If it's empty, "vlan$VLAN.$SUBVLAN" is used.
VLAN="${WORDS[0]}"
BRNAME="${WORDS[1]}"
# Splitting by "."
WORDS=( ${VLAN//[.]/ } )
# The second word defines subvlan (1q-in-1q) if it's used. It's empty if no subvlan is used.
VLAN="${WORDS[0]}"
SUBVLAN="${WORDS[1]}"
fi
# Checking if no "vlan(.subvlan)?" is set
if ! [[ "${VLANS_N_BRIDGE: -1}" = ":" ]]; then
# Setting default values
[[ "$SUBVLAN" = "" ]] && BRNAME="${BRNAME:-vlan${VLAN}}" || BRNAME="${BRNAME:-vlan${VLAN}.${SUBVLAN}}"
# Getting commands for "ip"
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
(( IP_CMD_i++ ))
done
fi
printf "br: %-10s vlan:%4s subvlan:%4s\n" "$BRNAME" "$VLAN" "$SUBVLAN"
(( VLAN_N_BRIDGE_i++ ))
done
done
newconfig_write ")"
newconfig_write ""
newconfig_popallwrite 1
newconfig_popallwrite 2
newconfig_popallwrite 3
echo ${D1Q_IFACES[@]}
#[[ $NEWCONFIG -ne 0 ]] && newconfig_commit
exit 0
... ...
#
D1Q_IFACES=(bond0)
bond0_SLAVES=(eth0 eth1)
# vlan.subvlan:bridge-name
# if vlan.subvlan is set to "" then bridge is created without creating (and enslaving) the vlan interface
# if bridge is set to "" then vlan interface is created without creating the bridge (to be enslaved by)
# if bridge is not set then "vlan$VLAN.$SUBVLAN"/"vlan$VLAN" is used
bond0_VLAN_N_BRIDGES=(
10.2:thor.ext
10.3:cps
10.4
50
12:
55
85
433
441
:cps.int
)
thor_ext_IP=(
"addr add 10.10.2.2/24"
"route add default gw 10.10.2.1"
)
... ...