···
prefixLength = i.ipv6PrefixLength;
29
+
SLAVES=$(ip link | grep 'master ${i}' | awk -F: '{print $2}')
30
+
for I in $SLAVES; do
32
+
ip link set "$I" nomaster
34
+
[ "$UPDATED" -eq "1" ] && break
36
+
ip link set "${i}" down || true
37
+
ip link del "${i}" || true
···
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
177
-
path = [ pkgs.bridge_utils pkgs.iproute ];
180
-
# Remove Dead Interfaces
181
-
ip link show "${n}" >/dev/null 2>&1 && ip link delete "${n}"
191
+
path = [ pkgs.iproute ];
193
+
# Remove Dead Interfaces
194
+
echo "Removing old bridge ${n}..."
195
+
ip link show "${n}" >/dev/null 2>&1 && ip link del "${n}"
197
+
echo "Adding bridge ${n}..."
198
+
ip link add name "${n}" type bridge
185
-
# Set bridge's hello time to 0 to avoid startup delays.
186
-
brctl setfd "${n}" 0
200
+
# Set bridge's hello time to 0 to avoid startup delays.
201
+
echo 0 >"/sys/class/net/${n}/bridge/hello_time"
202
+
echo 0 >"/sys/class/net/${n}/bridge/forward_delay"
188
-
${flip concatMapStrings v.interfaces (i: ''
189
-
brctl addif "${n}" "${i}"
190
-
ip link set "${i}" up
191
-
ip addr flush dev "${i}"
193
-
echo "bringing up network device ${n}..."
194
-
ip link set "${n}" up
204
+
# Enslave child interfaces
205
+
${flip concatMapStrings v.interfaces (i: ''
206
+
ip link set "${i}" master "${n}"
207
+
ip link set "${i}" up
197
-
# !!! Should delete (brctl delif) any interfaces that
198
-
# no longer belong to the bridge.
202
-
ip link set "${n}" down
210
+
ip link set "${n}" up
213
+
ip link set "${n}" down || true
214
+
ip link del "${n}" || true
createBondDevice = n: v: nameValuePair "${n}-netdev"
···
before = [ "${n}-cfg.service" ];
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
218
-
path = [ pkgs.ifenslave pkgs.iproute ];
229
+
path = [ pkgs.iproute ];
220
-
ip link add name "${n}" type bond
231
+
echo "Destroying old bond ${n}..."
234
+
echo "Creating new bond ${n}..."
235
+
ip link add name "${n}" type bond \
236
+
${optionalString (v.mode != null) "mode ${toString v.mode}"} \
237
+
${optionalString (v.miimon != null) "miimon ${toString v.miimon}"} \
238
+
${optionalString (v.xmit_hash_policy != null) "xmit_hash_policy ${toString v.xmit_hash_policy}"} \
239
+
${optionalString (v.lacp_rate != null) "lacp_rate ${toString v.lacp_rate}"}
# !!! There must be a better way to wait for the interface
223
-
while [ ! -d /sys/class/net/${n} ]; do sleep 0.1; done;
225
-
# Ensure the link is down so that we can set options
226
-
ip link set "${n}" down
228
-
# Set the miimon and mode options
229
-
${optionalString (v.miimon != null)
230
-
"echo \"${toString v.miimon}\" >/sys/class/net/${n}/bonding/miimon"}
231
-
${optionalString (v.mode != null)
232
-
"echo \"${v.mode}\" >/sys/class/net/${n}/bonding/mode"}
233
-
${optionalString (v.lacp_rate != null)
234
-
"echo \"${v.lacp_rate}\" >/sys/class/net/${n}/bonding/lacp_rate"}
235
-
${optionalString (v.xmit_hash_policy != null)
236
-
"echo \"${v.xmit_hash_policy}\" >/sys/class/net/${n}/bonding/xmit_hash_policy"}
242
+
while [ ! -d "/sys/class/net/${n}" ]; do sleep 0.1; done;
# Bring up the bond and enslave the specified interfaces
${flip concatMapStrings v.interfaces (i: ''
241
-
ifenslave "${n}" "${i}"
245
-
${flip concatMapStrings v.interfaces (i: ''
246
-
ifenslave -d "${n}" "${i}" >/dev/null 2>&1 || true
247
+
ip link set "${i}" master "${n}"
248
-
ip link set "${n}" down >/dev/null 2>&1 || true
249
-
ip link del "${n}" >/dev/null 2>&1 || true
250
+
postStop = destroyBond n;
createSitDevice = n: v: nameValuePair "${n}-netdev"