]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/initscripts/init.d/network-vlans
iptables: Replace state module by conntrack module.
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / network-vlans
CommitLineData
d23fc912
MT
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) 2012 IPFire Team <info@ipfire.org> #
21# #
22############################################################################
23
24CONFIG_FILE="/var/ipfire/ethernet/vlans"
25
26# Skip immediately if no configuration file has been found.
27[ -e "${CONFIG_FILE}" ] || exit 0
28
3d8f85ec 29eval $(/usr/local/bin/readhash ${CONFIG_FILE})
d23fc912
MT
30
31# This is start or stop.
32action=${1}
33
3de19c87 34for interface in green0 red0 blue0 orange0; do
d23fc912
MT
35 case "${interface}" in
36 green*)
37 PARENT_DEV=${GREEN_PARENT_DEV}
38 VLAN_ID=${GREEN_VLAN_ID}
39 MAC_ADDRESS=${GREEN_MAC_ADDRESS}
40 ;;
3de19c87
MT
41 red*)
42 PARENT_DEV=${RED_PARENT_DEV}
43 VLAN_ID=${RED_VLAN_ID}
44 MAC_ADDRESS=${RED_MAC_ADDRESS}
45 ;;
d23fc912
MT
46 blue*)
47 PARENT_DEV=${BLUE_PARENT_DEV}
48 VLAN_ID=${BLUE_VLAN_ID}
49 MAC_ADDRESS=${BLUE_MAC_ADDRESS}
50 ;;
51 orange*)
52 PARENT_DEV=${ORANGE_PARENT_DEV}
53 VLAN_ID=${ORANGE_VLAN_ID}
54 MAC_ADDRESS=${ORANGE_MAC_ADDRESS}
55 ;;
56 esac
57
58 case "${action}" in
59 start)
3d8f85ec
MT
60 # If no parent device has been configured, we assume
61 # that this interface is not set up for VLANs and
62 # silently go on.
63 [ -z "${PARENT_DEV}" ] && continue
64
d23fc912
MT
65 # Check if the interface does already exists.
66 # If so, we skip creating it.
67 if [ -d "/sys/class/net/${interface}" ]; then
3d8f85ec 68 echo "Interface ${interface} already exists." >&2
d23fc912
MT
69 continue
70 fi
71
72 # Check if the parent interface exists.
3d8f85ec
MT
73 if [ ! -d "/sys/class/net/${PARENT_DEV}" ]; then
74 echo "${interface}: Parent device is not set or does not exist: ${PARENT_DEV}" >&2
d23fc912
MT
75 continue
76 fi
77
78 if [ -z "${VLAN_ID}" ]; then
3d8f85ec 79 echo "${interface}: You did not set the VLAN ID." >&2
d23fc912
MT
80 continue
81 fi
82
83 echo "Creating VLAN interface ${interface}..."
84 vconfig add ${PARENT_DEV} ${VLAN_ID}
85 ip link set ${PARENT_DEV}.${VLAN_ID} name ${interface}
86
87 if [ -n "${MAC_ADDRESS}" ]; then
88 ip link set ${interface} address ${MAC_ADDRESS}
89 fi
90
91 # Bring up the parent device.
92 ip link set ${PARENT_DEV} up
93 ;;
94
95 stop)
96 if [ ! -e "/proc/net/vlan/${interface}" ]; then
97 echo "${interface} is not a VLAN interface. Skipping."
98 continue
99 fi
100
101 echo "Removing VLAN interface ${interface}..."
102 ip link set ${interface} down
103 vconfig rem ${interface}
104 ;;
105
106 *)
107 echo "Invalid action: ${action}"
108 exit 1
109 ;;
110 esac
111done