blob: fd8209091179ae9bbdb89be604065f65eafa4713 (
plain) (
blame)
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
|
#!/bin/bash
#
# Small script scanning sysfs for physical network interfaces
# and creating additional network bridges 'br-nic-[0-9]'.
. /opt/openslx/config
# do nothing if not netbooted
[ -z "$SLX_PXE_NETIF" ] && exit 1
declare -g id=1
for nic in /sys/class/net/*; do
# The presence of this symlink pointing to the physical device
# seems to be the better way to detect them.
[ -h "${nic}/device" ] || continue
# do not handle the primary interface
[ "$SLX_PXE_NETIF" = "${nic##*/}" ] && continue
# physical nic found, create a bridge with the same MAC
bridge="br-nic-${id}"
mac="$(cat "${nic}/address")"
if ! [[ $mac =~ ^([0-9a-f]{2}:){5}[0-9a-f]{2}$ ]]; then
echo "'$mac' does not seems like a valid MAC address."
continue
fi
(
set -e
brctl addbr "$bridge"
brctl stp "$bridge" 0
ip link set addr "$mac" "$bridge"
ip link set dev "${nic##*/}" up
brctl addif "$bridge" "${nic##*/}"
ip link set dev "$bridge" up
)
ret=$?
if [ "$ret" != 0 ]; then
echo "Failed to setup additional bridge '$bridge' for '$nic'."
brctl delbr "$bridge"
continue
fi
# all fine, increase counter and continue
(( id++ ))
done
exit 0
|