2 ############################################################################
4 # This file is part of the IPFire Firewall. #
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. #
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. #
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 #
20 # Copyright (C) 2012 IPFire Team <info@ipfire.org> #
22 ############################################################################
24 CONFIG_FILE
="/var/ipfire/ethernet/vlans"
26 # Skip immediately if no configuration file has been found.
27 [ -e "${CONFIG_FILE}" ] ||
exit 0
29 eval $
(/usr
/local
/bin
/readhash
${CONFIG_FILE})
31 # This is start or stop.
34 for interface
in green0 red0 blue0 orange0
; do
35 case "${interface}" in
37 PARENT_DEV
=${GREEN_PARENT_DEV}
38 VLAN_ID
=${GREEN_VLAN_ID}
39 MAC_ADDRESS
=${GREEN_MAC_ADDRESS}
42 PARENT_DEV
=${RED_PARENT_DEV}
43 VLAN_ID
=${RED_VLAN_ID}
44 MAC_ADDRESS
=${RED_MAC_ADDRESS}
47 PARENT_DEV
=${BLUE_PARENT_DEV}
48 VLAN_ID
=${BLUE_VLAN_ID}
49 MAC_ADDRESS
=${BLUE_MAC_ADDRESS}
52 PARENT_DEV
=${ORANGE_PARENT_DEV}
53 VLAN_ID
=${ORANGE_VLAN_ID}
54 MAC_ADDRESS
=${ORANGE_MAC_ADDRESS}
60 # If no parent device has been configured, we assume
61 # that this interface is not set up for VLANs and
63 [ -z "${PARENT_DEV}" ] && continue
65 # Check if the interface does already exists.
66 # If so, we skip creating it.
67 if [ -d "/sys/class/net/${interface}" ]; then
68 echo "Interface ${interface} already exists." >&2
72 # Check if the parent interface exists.
73 if [ ! -d "/sys/class/net/${PARENT_DEV}" ]; then
74 echo "${interface}: Parent device is not set or does not exist: ${PARENT_DEV}" >&2
78 if [ -z "${VLAN_ID}" ]; then
79 echo "${interface}: You did not set the VLAN ID." >&2
84 command="ip link add link ${PARENT_DEV} name ${interface}"
85 if [ -n "${MAC_ADDRESS}" ]; then
86 command="${command} address ${MAC_ADDRESS}"
88 command="${command} type vlan id ${VLAN_ID}"
90 echo "Creating VLAN interface ${interface}..."
93 # Bring up the parent device.
94 ip link
set ${PARENT_DEV} up
98 if [ ! -e "/proc/net/vlan/${interface}" ]; then
99 echo "${interface} is not a VLAN interface. Skipping."
103 echo "Removing VLAN interface ${interface}..."
104 ip link
set ${interface} down
105 ip link delete
${interface}
109 echo "Invalid action: ${action}"