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) 2015 IPFire Team <info@ipfire.org> #
22 ############################################################################
24 [ -n "${INTERFACE}" ] ||
exit 2
26 VLAN_CONFIG_FILE
="/var/ipfire/ethernet/vlans"
27 MAIN_CONFIG_FILE
="/var/ipfire/ethernet/settings"
29 # Skip immediately if a configuration file is missing.
30 [ -e "${VLAN_CONFIG_FILE}" ] && [ -e "${MAIN_CONFIG_FILE}" ] ||
exit 0
32 eval $
(/usr
/local
/bin
/readhash
${VLAN_CONFIG_FILE})
33 eval $
(/usr
/local
/bin
/readhash
${MAIN_CONFIG_FILE})
35 for interface
in green0 red0 blue0 orange0
; do
36 case "${interface}" in
38 ZONE_MODE
=${GREEN_MODE}
39 PARENT_DEV
=${GREEN_PARENT_DEV}
40 VLAN_ID
=${GREEN_VLAN_ID}
41 MAC_ADDRESS
=${GREEN_MAC_ADDRESS}
45 PARENT_DEV
=${RED_PARENT_DEV}
46 VLAN_ID
=${RED_VLAN_ID}
47 MAC_ADDRESS
=${RED_MAC_ADDRESS}
50 ZONE_MODE
=${BLUE_MODE}
51 PARENT_DEV
=${BLUE_PARENT_DEV}
52 VLAN_ID
=${BLUE_VLAN_ID}
53 MAC_ADDRESS
=${BLUE_MAC_ADDRESS}
56 ZONE_MODE
=${ORANGE_MODE}
57 PARENT_DEV
=${ORANGE_PARENT_DEV}
58 VLAN_ID
=${ORANGE_VLAN_ID}
59 MAC_ADDRESS
=${ORANGE_MAC_ADDRESS}
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
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}"
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
79 if [ -z "${VLAN_ID}" ]; then
80 echo "${interface}: You did not set the VLAN ID." >&2
85 command="ip link add link ${INTERFACE} name ${interface}"
86 if [ -n "${MAC_ADDRESS}" ]; then
87 command="${command} address ${MAC_ADDRESS}"
89 command="${command} type vlan id ${VLAN_ID}"
91 echo "Creating VLAN interface ${interface}..."
94 # Bring up the parent device.
95 ip link
set ${INTERFACE} up