]> git.ipfire.org Git - ipfire-2.x.git/blob - config/udev/network-hotplug-vlan
hostapd: update to git 64d60bb4
[ipfire-2.x.git] / config / udev / network-hotplug-vlan
1 #!/bin/bash
2 ############################################################################
3 # #
4 # This file is part of the IPFire Firewall. #
5 # #
6 # IPFire is free software; you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation; either version 2 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # IPFire is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with IPFire; if not, write to the Free Software #
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
19 # #
20 # Copyright (C) 2015 IPFire Team <info@ipfire.org> #
21 # #
22 ############################################################################
23
24 [ -n "${INTERFACE}" ] || exit 2
25
26 VLAN_CONFIG_FILE="/var/ipfire/ethernet/vlans"
27 MAIN_CONFIG_FILE="/var/ipfire/ethernet/settings"
28
29 # Skip immediately if a configuration file is missing.
30 [ -e "${VLAN_CONFIG_FILE}" ] && [ -e "${MAIN_CONFIG_FILE}" ] || exit 0
31
32 eval $(/usr/local/bin/readhash ${VLAN_CONFIG_FILE})
33 eval $(/usr/local/bin/readhash ${MAIN_CONFIG_FILE})
34
35 for interface in green0 red0 blue0 orange0; do
36 case "${interface}" in
37 green*)
38 ZONE_MODE=${GREEN_MODE}
39 PARENT_DEV=${GREEN_PARENT_DEV}
40 VLAN_ID=${GREEN_VLAN_ID}
41 MAC_ADDRESS=${GREEN_MAC_ADDRESS}
42 ;;
43 red*)
44 ZONE_MODE=${RED_MODE}
45 PARENT_DEV=${RED_PARENT_DEV}
46 VLAN_ID=${RED_VLAN_ID}
47 MAC_ADDRESS=${RED_MAC_ADDRESS}
48 ;;
49 blue*)
50 ZONE_MODE=${BLUE_MODE}
51 PARENT_DEV=${BLUE_PARENT_DEV}
52 VLAN_ID=${BLUE_VLAN_ID}
53 MAC_ADDRESS=${BLUE_MAC_ADDRESS}
54 ;;
55 orange*)
56 ZONE_MODE=${ORANGE_MODE}
57 PARENT_DEV=${ORANGE_PARENT_DEV}
58 VLAN_ID=${ORANGE_VLAN_ID}
59 MAC_ADDRESS=${ORANGE_MAC_ADDRESS}
60 ;;
61 esac
62
63 # If the parent device (MAC or name) does not match the interface that
64 # has just come up, we will go on for the next one.
65 [ "${PARENT_DEV}" = "${INTERFACE}" ] || [ "${PARENT_DEV}" = "$(</sys/class/net/${INTERFACE}/address)" ] || continue
66
67 # If the current zone is operating in bridge mode, give the VLAN interface a generic name (e.g. eth0.99 for VLAN 99 on eth0)
68 if [ "${ZONE_MODE}" = "bridge" ]; then
69 interface="${INTERFACE}.${VLAN_ID}"
70 fi
71
72 # Check if the interface does already exists.
73 # If so, we skip creating it.
74 if [ -d "/sys/class/net/${interface}" ]; then
75 echo "Interface ${interface} already exists." >&2
76 continue
77 fi
78
79 if [ -z "${VLAN_ID}" ]; then
80 echo "${interface}: You did not set the VLAN ID." >&2
81 continue
82 fi
83
84 # Build command line.
85 command="ip link add link ${INTERFACE} name ${interface}"
86 if [ -n "${MAC_ADDRESS}" ]; then
87 command="${command} address ${MAC_ADDRESS}"
88 fi
89 command="${command} type vlan id ${VLAN_ID}"
90
91 echo "Creating VLAN interface ${interface}..."
92 ${command}
93
94 # Bring up the parent device.
95 ip link set ${INTERFACE} up
96 done
97
98 exit 0