Toggle navigation
Toggle navigation
This project
Loading...
Sign in
UT
/
ipw
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Artyom A Anikeev
2014-02-26 12:31:10 +0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d2ef9d667d5c9b57ae4eadd59dbf08dea76e12dc
d2ef9d66
1 parent
ea74e812
added VLANS_N_BRIDGE config writing, add1qsl
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
14 deletions
ipw
ipw
View file @
d2ef9d6
#!/bin/bash
# Copyright (C) 2013 Artyom A Anikeev <anikeev@ut.mephi.ru> 0xB5385841,
# Dmitry Yu Okunev <xai@mephi.ru> 0x8E30679C
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
CONFIG_PATH
=
"./ipw-configsample"
source
"
$CONFIG_PATH
"
...
...
@@ -11,11 +28,50 @@ CMD="$1"; shift;
NEWCONFIG
=
0
case
"
$CMD
"
in
add1qsl
)
NEWCONFIG
=
1
# we need to update the config after the command
NEW_D1Q_IFACE
=
"
$1
"
;
shift
NEW_SLAVE
=
"
$1
"
;
shift
# 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
fi
SLAVES_VARIABLE
=
"
${
D1Q_IFACE
}
_SLAVES"
SLAVES_VARIABLE
=
"
${
SLAVES_VARIABLE
//[.]/_
}
[@]"
for
SLAVE
in
"
${
!SLAVES_VARIABLE
}
"
;
do
if
[[
"
$SLAVE
"
=
"
$NEW_SLAVE
"
]]
;
then
SLAVE_CONFLICT
=
1
fi
done
done
if
[[
$D1Q_IFACE_USED
-eq 0
]]
;
then
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
;;
add1qif
)
NEWCONFIG
=
1
# we need to update the config after the command
#D1Q_IFACE="$1"; shift
D1Q_IFACES[
${#
D1Q_IFACES
}
]
#
D1Q_IFACES[ ${#D1Q_IFACES}]
;;
addbrif
)
...
...
@@ -34,6 +90,10 @@ case "$CMD" in
;;
esac
eerror
()
{
echo
"
$@
"
>&2
}
newconfig_open
()
{
echo
-n >
"
$NEWCONFIG_TMPPATH
"
}
...
...
@@ -59,6 +119,14 @@ newconfig_push() {
$LINE
"
}
newconfig_pushpopall
()
{
BUFNUMTO
=
"
$1
"
;
shift
;
BUFNUMFROM
=
"
$1
"
;
shift
;
newconfig_push
"
$BUFNUMTO
"
"
${
BUF
[
$BUFNUMFROM
]
}
"
newconfig_popall
"
$BUFNUMFROM
"
}
newconfig_popall
()
{
BUFNUM
=
"
$1
"
;
shift
;
...
...
@@ -80,29 +148,35 @@ newconfig_write "D1Q_IFACES=("
for
D1Q_IFACE
in
${
D1Q_IFACES
[@]
}
;
do
newconfig_write
"
$D1Q_IFACE
"
newconfig_push 1
"
${
D1Q_IFACE
}
_SLAVES=("
newconfig_push 1
28
"
${
D1Q_IFACE
}
_SLAVES=("
haveaslave
=
0
SLAVES_VARIABLE
=
"
${
D1Q_IFACE
}
_SLAVES"
SLAVES_VARIABLE
=
"
${
SLAVES_VARIABLE
//[.]/_
}
[@]"
for
SLAVE
in
"
${
!SLAVES_VARIABLE
}
"
;
do
newconfig_push 1
"
$SLAVE
"
;
newconfig_push 128
"
$SLAVE
"
;
haveaslave
=
1
done
newconfig_push 1
")"
newconfig_push 1
28
")"
# If there're no slaves then don't write anything about them
[[
$
SLAVE_i
-eq 0
]]
&&
newconfig_popall 1
[[
$
haveaslave
-ne 0
]]
&&
newconfig_pushpopall 1 128
||
newconfig_popall 128
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
newconfig_push 1
"
${
D1Q_IFACE
}
_VLAN_N_BRIGES=("
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
S
_N_BRIDGE
:0:1
}
"
=
":"
]]
;
then
if
[[
"
${
VLAN_N_BRIDGE
:0:1
}
"
=
":"
]]
;
then
VLAN
=
""
BRNAME
=
"
${
VLAN
S
_N_BRIDGE
:1
}
"
BRNAME
=
"
${
VLAN_N_BRIDGE
:1
}
"
else
# Splitting by ":"
WORDS
=(
${
VLAN
S
_N_BRIDGE
//[
:]/
}
)
WORDS
=(
${
VLAN_N_BRIDGE
//[
:]/
}
)
# The second word defines interface name. If it's empty, "vlan$VLAN.$SUBVLAN" is used.
VLAN
=
"
${
WORDS
[0]
}
"
...
...
@@ -117,7 +191,7 @@ for D1Q_IFACE in ${D1Q_IFACES[@]}; do
fi
# Checking if no "vlan(.subvlan)?" is set
if
!
[[
"
${
VLAN
S
_N_BRIDGE
:
-1
}
"
=
":"
]]
;
then
if
!
[[
"
${
VLAN_N_BRIDGE
:
-1
}
"
=
":"
]]
;
then
# Setting default values
[[
"
$SUBVLAN
"
=
""
]]
&&
BRNAME
=
"
${
BRNAME
:-
vlan
${
VLAN
}}
"
||
BRNAME
=
"
${
BRNAME
:-
vlan
${
VLAN
}
.
${
SUBVLAN
}}
"
...
...
@@ -131,14 +205,13 @@ for D1Q_IFACE in ${D1Q_IFACES[@]}; do
fi
printf
"br: %-10s vlan:%4s subvlan:%4s
\n
"
"
$BRNAME
"
"
$VLAN
"
"
$SUBVLAN
"
((
VLAN_N_BRIDGE_i++
))
done
newconfig_push 1
")"
done
newconfig_write
")"
newconfig_write
""
newconfig_popallwrite 1
newconfig_popallwrite 2
...
...
Please
register
or
login
to post a comment