blob: 427b838fe23b14c0f3629e1cf4e6b4e27ab51784 (
plain)
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
|
#!/bin/bash
# on error exit
set -e
# set vlan parent interface
INTERFACE=eth0
# assign vlan ids via commandline parameter 1
VLANS=$1
if [[ -z "$VLANS" ]];then
echo -e "No VLAN-IDs assigned through environment variable with name 'VLANS'!\nExit container."
exit 1
fi
# build interface list with parent interface and vlan ids
ALLVLANIF=$(echo -n $VLANS | sed -re "s/\b([0-9]+)/${INTERFACE}.\1/g")
# get MTU of parent interface
MTU=$(ip link show $INTERFACE | grep -Ei 'mtu \d+' | cut -d " " -f2)
# cleanup non used vlan interfaces
for VLAN in $(ls -1 /sys/class/net | grep -E "^${INTERFACE}\\." | grep -Ev "$(echo $ALLVLANIF | tr ' ' '|')") ;do
echo "Deleting orphaned interface: $VLAN"
ip link delete $VLAN
done
# for each vlan id
for VLAN in $VLANS; do
VLANIF="${INTERFACE}.$VLAN"
# create vlan interface
[[ ! -d "/sys/class/net/${VLANIF}" ]] && {
echo "Creating interface ${VLANIF}"
ip link add link $INTERFACE name "$VLANIF" mtu $MTU type vlan id $VLAN
}
echo "Bring up $VLANIF interface"
ip link set "$VLANIF" up
# starting DHCP client on interface
[[ -f "/var/run/udhcpc.${VLANIF}.pid" ]] && {
kill "$(cat "/var/run/udhcpc.${VLANIF}.pid")" >/dev/null
rm "/var/run/udhcpc.${VLANIF}.pid"
}
echo "Starting dhcp client on ${VLANIF}"
udhcpc -b -i $VLANIF -x hostname:"$HOSTNAME" -p "/var/run/udhcpc.${VLANIF}.pid"
done
echo "Starting mDNS repeater process ... "
# run repeater on vlan interfaces
exec /bin/mdns-repeater -f $ALLVLANIF
|