Artyom A Anikeev

addbrif works

... ... @@ -16,6 +16,86 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
eerror() {
echo "$@" >&2
}
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_pushpopall() {
BUFNUMTO="$1"; shift;
BUFNUMFROM="$1"; shift;
newconfig_push "$BUFNUMTO" "${BUF[$BUFNUMFROM]}"
newconfig_popall "$BUFNUMFROM"
}
newconfig_popall() {
BUFNUM="$1"; shift;
BUF[$BUFNUM]=""
}
newconfig_popallwrite() {
BUFNUM="$1"; shift;
newconfig_write "${BUF[$BUFNUM]}"
BUF[$BUFNUM]=""
}
parse_vlan_subvlan_bridge() {
VLAN_N_BRIDGE="$1"; shift
if [[ "${VLAN_N_BRIDGE:0:1}" = ":" ]]; then
VLAN=""
BRNAME="${VLAN_N_BRIDGE:1}"
else
# Splitting by ":"
WORDS=( ${VLAN_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 ! [[ "${VLAN_N_BRIDGE: -1}" = ":" ]]; then
# Setting default values
[[ "$SUBVLAN" = "" ]] && BRNAME="${BRNAME:-vlan${VLAN}}" || BRNAME="${BRNAME:-vlan${VLAN}.${SUBVLAN}}"
fi
return;
}
CONFIG_PATH="./ipw-configsample"
... ... @@ -28,7 +108,7 @@ CMD="$1"; shift;
NEWCONFIG=0
case "$CMD" in
add1qsl)
add1qif)
NEWCONFIG=1 # we need to update the config after the command
NEW_D1Q_IFACE="$1"; shift
... ... @@ -36,7 +116,6 @@ case "$CMD" in
# checking for duplicated slaves or d1q_ifaces
D1Q_IFACE_USED=0
SLAVE_CONFLICT=0
for D1Q_IFACE in ${D1Q_IFACES[@]}; do
if [[ "$D1Q_IFACE" = "$NEW_D1Q_IFACE" ]]; then
D1Q_IFACE_USED=1
... ... @@ -45,7 +124,8 @@ case "$CMD" in
SLAVES_VARIABLE="${SLAVES_VARIABLE//[.]/_}[@]"
for SLAVE in "${!SLAVES_VARIABLE}"; do
if [[ "$SLAVE" = "$NEW_SLAVE" ]]; then
SLAVE_CONFLICT=1
eerror "This interface have already been enslaved"
exit -1
fi
done
done
... ... @@ -54,27 +134,57 @@ case "$CMD" in
D1Q_IFACES[ ${#D1Q_IFACES} ]="$NEW_D1Q_IFACE"
fi
if [[ $SLAVE_CONFLICT -eq 0 ]]; then
SLAVES_VARIABLE="${NEW_D1Q_IFACE}_SLAVES"
SLAVES_VARIABLE="${SLAVES_VARIABLE//[.]/_}"
eval "${SLAVES_VARIABLE}[\${#${SLAVES_VARIABLE}}]=\"$NEW_SLAVE\""
print
else
eerror "This interface have already been enslaved"
exit -1
fi
SLAVES_VARIABLE="${NEW_D1Q_IFACE}_SLAVES"
SLAVES_VARIABLE="${SLAVES_VARIABLE//[.]/_}"
eval "${SLAVES_VARIABLE}[\${#${SLAVES_VARIABLE}}]=\"$NEW_SLAVE\""
;;
add1qif)
addbrif)
NEWCONFIG=1 # we need to update the config after the command
#D1Q_IFACE="$1"; shift
NEW_D1Q_IFACE="$1"; shift
NEW_VLAN_SUBVLAN="$1"; shift
NEW_BRIDGE="$1"; shift
[[ -z $NEW_BRIDGE ]] && NEW_VLAN_N_BRIDGE="${NEW_VLAN_SUBVLAN}" || NEW_VLAN_N_BRIDGE="${NEW_VLAN_SUBVLAN}:${NEW_BRIDGE}"
D1Q_IFACE_USED=0
for D1Q_IFACE in ${D1Q_IFACES[@]}; do
if [[ "$D1Q_IFACE" = "$NEW_D1Q_IFACE" ]]; then
D1Q_IFACE_USED=1
break;
fi
done
parse_vlan_subvlan_bridge "${NEW_VLAN_N_BRIDGE}"
NEW_VLAN=$VLAN
NEW_SUBVLAN=$SUBVLAN
if [[ $D1Q_IFACE_USED -eq 0 ]]; then
eerror "There's no such interface: $NEW_D1Q_IFACE"
exit -1
fi
VLAN_N_BRIDGE_VARIABLE="${NEW_D1Q_IFACE}_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 [[ "$VLAN" = "$NEW_VLAN" && "$SUBVLAN" = "$NEW_SUBVLAN" ]]; then
eerror "This vlan is alredy used"
exit -1
fi
done
VLAN_N_BRIDGE_VARIABLE="${D1Q_IFACE}_VLAN_N_BRIDGES"
VLAN_N_BRIDGE_VARIABLE="${VLAN_N_BRIDGE_VARIABLE//[.]/_}"
eval "${VLAN_N_BRIDGE_VARIABLE}[\${#${VLAN_N_BRIDGE_VARIABLE}}]=\"$NEW_VLAN_N_BRIDGE\""
#D1Q_IFACES[ ${#D1Q_IFACES}]
;;
addbrif)
addbrifstale)
NEWCONFIG=1 # we need to update the config after the command
BRNAME="$1"; shift
... ... @@ -90,56 +200,6 @@ case "$CMD" in
;;
esac
eerror() {
echo "$@" >&2
}
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_pushpopall() {
BUFNUMTO="$1"; shift;
BUFNUMFROM="$1"; shift;
newconfig_push "$BUFNUMTO" "${BUF[$BUFNUMFROM]}"
newconfig_popall "$BUFNUMFROM"
}
newconfig_popall() {
BUFNUM="$1"; shift;
BUF[$BUFNUM]=""
}
newconfig_popallwrite() {
BUFNUM="$1"; shift;
newconfig_write "${BUF[$BUFNUM]}"
BUF[$BUFNUM]=""
}
newconfig_open
newconfig_write "#"
newconfig_write ""
... ... @@ -170,38 +230,27 @@ for D1Q_IFACE in ${D1Q_IFACES[@]}; do
for VLAN_N_BRIDGE in "${!VLAN_N_BRIDGE_VARIABLE}"; do
newconfig_push 1 " ${VLAN_N_BRIDGE}"
# Checking if no "vlan(.subvlan)?" is set
if [[ "${VLAN_N_BRIDGE:0:1}" = ":" ]]; then
VLAN=""
BRNAME="${VLAN_N_BRIDGE:1}"
else
# Splitting by ":"
WORDS=( ${VLAN_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
parse_vlan_subvlan_bridge "${VLAN_N_BRIDGE}"
# Checking if no "vlan(.subvlan)?" is set
if ! [[ "${VLAN_N_BRIDGE: -1}" = ":" ]]; then
# Setting default values
[[ "$SUBVLAN" = "" ]] && BRNAME="${BRNAME:-vlan${VLAN}}" || BRNAME="${BRNAME:-vlan${VLAN}.${SUBVLAN}}"
if [[ "${BRNAME}" != "" ]]; then
# Getting commands for "ip"
IP_CMDS_VARIABLE="${BRNAME}_IP"
IP_CMDS_VARIABLE="${IP_CMDS_VARIABLE//[.]/_}[@]"
IP_CMDS_VARIABLE="${BRNAME//[.]/_}_IP"
newconfig_push 128 "${IP_CMDS_VARIABLE}=("
IP_CMDS_VARIABLE="${IP_CMDS_VARIABLE}[@]"
hasanIP_CMD=0
for IP_CMD in "${!IP_CMDS_VARIABLE}"; do
newconfig_push 128 " \"$IP_CMD\""
echo ip $IP_CMD dev $BRNAME
(( IP_CMD_i++ ))
hasanIP_CMD=1
done
newconfig_push 128 ")"
newconfig_push 128 ""
[[ $hasanIP_CMD -ne 0 ]] && newconfig_pushpopall 2 128 || newconfig_popall 128
fi
printf "br: %-10s vlan:%4s subvlan:%4s\n" "$BRNAME" "$VLAN" "$SUBVLAN"
... ...
#
D1Q_IFACES=(bond0)
D1Q_IFACES=(bond0 bond1)
bond0_SLAVES=(eth0 eth1)
bond1_SLAVES=(eth2)
# vlan.subvlan:bridge-name
# if vlan.subvlan is set to "" then bridge is created without creating (and enslaving) the vlan interface
... ... @@ -22,6 +23,11 @@ bond0_VLAN_N_BRIDGES=(
:cps.int
)
bond1_VLAN_N_BRIDGES=(
441
:cps.int
)
thor_ext_IP=(
"addr add 10.10.2.2/24"
"route add default gw 10.10.2.1"
... ...