Showing
3 changed files
with
180 additions
and
0 deletions
README
0 → 100644
File mode changed
ipw
0 → 100755
1 | +#!/bin/bash | ||
2 | + | ||
3 | +CONFIG_PATH="./ipw-configsample" | ||
4 | + | ||
5 | +source "$CONFIG_PATH" | ||
6 | + | ||
7 | +NEWCONFIG_TMPPATH="/tmp/.~ipw" | ||
8 | + | ||
9 | + | ||
10 | +CMD="$1"; shift; | ||
11 | + | ||
12 | +NEWCONFIG=0 | ||
13 | +case "$CMD" in | ||
14 | + add1qif) | ||
15 | + NEWCONFIG=1 # we need to update the config after the command | ||
16 | + | ||
17 | + | ||
18 | + D1Q_IFACES[ ${#D1Q_IFACES}] | ||
19 | + | ||
20 | + ;; | ||
21 | + addbrif) | ||
22 | + NEWCONFIG=1 # we need to update the config after the command | ||
23 | + | ||
24 | + BRNAME="$1"; shift | ||
25 | + SLAVE="$1"; shift | ||
26 | + | ||
27 | + # TODO: implement this | ||
28 | + #bond0_SLAVES[ ${#bond0_SLAVES[@]} ]="eth2" | ||
29 | + ;; | ||
30 | + fix) | ||
31 | + #brctl addif bond0 eth2 | ||
32 | + ;; | ||
33 | + *) | ||
34 | + ;; | ||
35 | +esac | ||
36 | + | ||
37 | +newconfig_open() { | ||
38 | + echo -n > "$NEWCONFIG_TMPPATH" | ||
39 | +} | ||
40 | + | ||
41 | +newconfig_write() { | ||
42 | + LINE="$1"; shift; | ||
43 | + | ||
44 | + [[ $NEWCONFIG -eq 0 ]] && return | ||
45 | + | ||
46 | + echo "$LINE" >> "$NEWCONFIG_TMPPATH" | ||
47 | +} | ||
48 | + | ||
49 | +newconfig_commit() { | ||
50 | + rm -f "$CONFIG_PATH" | ||
51 | + mv "$NEWCONFIG_TMPPATH" "$CONFIG_PATH" | ||
52 | +} | ||
53 | + | ||
54 | +newconfig_push() { | ||
55 | + BUFNUM="$1"; shift; | ||
56 | + LINE="$1"; shift; | ||
57 | + | ||
58 | + BUF[$BUFNUM]="${BUF[$BUFNUM]} | ||
59 | +$LINE" | ||
60 | +} | ||
61 | + | ||
62 | +newconfig_popall() { | ||
63 | + BUFNUM="$1"; shift; | ||
64 | + | ||
65 | + BUF[$BUFNUM]="" | ||
66 | +} | ||
67 | + | ||
68 | +newconfig_popallwrite() { | ||
69 | + BUFNUM="$1"; shift; | ||
70 | + | ||
71 | + newconfig_write "${BUF[$BUFNUM]}" | ||
72 | + BUF[$BUFNUM]="" | ||
73 | +} | ||
74 | + | ||
75 | +newconfig_open | ||
76 | +newconfig_write "#" | ||
77 | +newconfig_write "" | ||
78 | +newconfig_write "D1Q_IFACES=(" | ||
79 | + | ||
80 | +for D1Q_IFACE in ${D1Q_IFACES[@]}; do | ||
81 | + newconfig_write " $D1Q_IFACE" | ||
82 | + | ||
83 | + newconfig_push 1 "${D1Q_IFACE}_SLAVES=(" | ||
84 | + | ||
85 | + SLAVES_VARIABLE="${D1Q_IFACE}_SLAVES" | ||
86 | + SLAVES_VARIABLE="${SLAVES_VARIABLE//[.]/_}[@]" | ||
87 | + for SLAVE in "${!SLAVES_VARIABLE}"; do | ||
88 | + newconfig_push 1 " $SLAVE"; | ||
89 | + done | ||
90 | + | ||
91 | + newconfig_push 1 ")" | ||
92 | + | ||
93 | + # If there're no slaves then don't write anything about them | ||
94 | + [[ $SLAVE_i -eq 0 ]] && newconfig_popall 1 | ||
95 | + | ||
96 | + VLAN_N_BRIDGE_VARIABLE="${D1Q_IFACE}_VLAN_N_BRIDGES" | ||
97 | + VLAN_N_BRIDGE_VARIABLE="${VLAN_N_BRIDGE_VARIABLE//[.]/_}[@]" | ||
98 | + for VLANS_N_BRIDGE in "${!VLAN_N_BRIDGE_VARIABLE}"; do | ||
99 | + # Checking if no "vlan(.subvlan)?" is set | ||
100 | + if [[ "${VLANS_N_BRIDGE:0:1}" = ":" ]]; then | ||
101 | + VLAN="" | ||
102 | + BRNAME="${VLANS_N_BRIDGE:1}" | ||
103 | + else | ||
104 | + # Splitting by ":" | ||
105 | + WORDS=( ${VLANS_N_BRIDGE//[:]/ } ) | ||
106 | + | ||
107 | + # The second word defines interface name. If it's empty, "vlan$VLAN.$SUBVLAN" is used. | ||
108 | + VLAN="${WORDS[0]}" | ||
109 | + BRNAME="${WORDS[1]}" | ||
110 | + | ||
111 | + # Splitting by "." | ||
112 | + WORDS=( ${VLAN//[.]/ } ) | ||
113 | + | ||
114 | + # The second word defines subvlan (1q-in-1q) if it's used. It's empty if no subvlan is used. | ||
115 | + VLAN="${WORDS[0]}" | ||
116 | + SUBVLAN="${WORDS[1]}" | ||
117 | + fi | ||
118 | + | ||
119 | + # Checking if no "vlan(.subvlan)?" is set | ||
120 | + if ! [[ "${VLANS_N_BRIDGE: -1}" = ":" ]]; then | ||
121 | + # Setting default values | ||
122 | + [[ "$SUBVLAN" = "" ]] && BRNAME="${BRNAME:-vlan${VLAN}}" || BRNAME="${BRNAME:-vlan${VLAN}.${SUBVLAN}}" | ||
123 | + | ||
124 | + # Getting commands for "ip" | ||
125 | + IP_CMDS_VARIABLE="${BRNAME}_IP" | ||
126 | + IP_CMDS_VARIABLE="${IP_CMDS_VARIABLE//[.]/_}[@]" | ||
127 | + for IP_CMD in "${!IP_CMDS_VARIABLE}"; do | ||
128 | + echo ip $IP_CMD dev $BRNAME | ||
129 | + (( IP_CMD_i++ )) | ||
130 | + done | ||
131 | + fi | ||
132 | + | ||
133 | + printf "br: %-10s vlan:%4s subvlan:%4s\n" "$BRNAME" "$VLAN" "$SUBVLAN" | ||
134 | + | ||
135 | + (( VLAN_N_BRIDGE_i++ )) | ||
136 | + done | ||
137 | + | ||
138 | +done | ||
139 | + | ||
140 | +newconfig_write ")" | ||
141 | +newconfig_write "" | ||
142 | + | ||
143 | +newconfig_popallwrite 1 | ||
144 | +newconfig_popallwrite 2 | ||
145 | +newconfig_popallwrite 3 | ||
146 | + | ||
147 | +echo ${D1Q_IFACES[@]} | ||
148 | + | ||
149 | +#[[ $NEWCONFIG -ne 0 ]] && newconfig_commit | ||
150 | + | ||
151 | +exit 0 |
ipw-configsample
0 → 100755
1 | +# | ||
2 | + | ||
3 | +D1Q_IFACES=(bond0) | ||
4 | + | ||
5 | +bond0_SLAVES=(eth0 eth1) | ||
6 | + | ||
7 | +# vlan.subvlan:bridge-name | ||
8 | +# if vlan.subvlan is set to "" then bridge is created without creating (and enslaving) the vlan interface | ||
9 | +# if bridge is set to "" then vlan interface is created without creating the bridge (to be enslaved by) | ||
10 | +# if bridge is not set then "vlan$VLAN.$SUBVLAN"/"vlan$VLAN" is used | ||
11 | + | ||
12 | +bond0_VLAN_N_BRIDGES=( | ||
13 | + 10.2:thor.ext | ||
14 | + 10.3:cps | ||
15 | + 10.4 | ||
16 | + 50 | ||
17 | + 12: | ||
18 | + 55 | ||
19 | + 85 | ||
20 | + 433 | ||
21 | + 441 | ||
22 | + :cps.int | ||
23 | +) | ||
24 | + | ||
25 | +thor_ext_IP=( | ||
26 | + "addr add 10.10.2.2/24" | ||
27 | + "route add default gw 10.10.2.1" | ||
28 | +) | ||
29 | + |
-
Please register or login to post a comment