ipw
2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/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