]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/initscripts/init.d/network-vlans
Add a script to create VLAN interfaces (on console).
[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
29eval $(readhash ${CONFIG_FILE})
30
31# This is start or stop.
32action=${1}
33
34for interface in green0 blue0 orange0; do
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 ;;
41 blue*)
42 PARENT_DEV=${BLUE_PARENT_DEV}
43 VLAN_ID=${BLUE_VLAN_ID}
44 MAC_ADDRESS=${BLUE_MAC_ADDRESS}
45 ;;
46 orange*)
47 PARENT_DEV=${ORANGE_PARENT_DEV}
48 VLAN_ID=${ORANGE_VLAN_ID}
49 MAC_ADDRESS=${ORANGE_MAC_ADDRESS}
50 ;;
51 esac
52
53 case "${action}" in
54 start)
55 # Check if the interface does already exists.
56 # If so, we skip creating it.
57 if [ -d "/sys/class/net/${interface}" ]; then
58 echo "Interface ${interface} already exists."
59 continue
60 fi
61
62 # Check if the parent interface exists.
63 if [ -z "${PARENT_DEV}" ] || [ ! -d "/sys/class/net/${PARENT_DEV}" ]; then
64 echo "${interface}: Parent device is not set or does not exist: ${PARENT_DEV}"
65 continue
66 fi
67
68 if [ -z "${VLAN_ID}" ]; then
69 echo "${interface}: You did not set the VLAN ID."
70 continue
71 fi
72
73 echo "Creating VLAN interface ${interface}..."
74 vconfig add ${PARENT_DEV} ${VLAN_ID}
75 ip link set ${PARENT_DEV}.${VLAN_ID} name ${interface}
76
77 if [ -n "${MAC_ADDRESS}" ]; then
78 ip link set ${interface} address ${MAC_ADDRESS}
79 fi
80
81 # Bring up the parent device.
82 ip link set ${PARENT_DEV} up
83 ;;
84
85 stop)
86 if [ ! -e "/proc/net/vlan/${interface}" ]; then
87 echo "${interface} is not a VLAN interface. Skipping."
88 continue
89 fi
90
91 echo "Removing VLAN interface ${interface}..."
92 ip link set ${interface} down
93 vconfig rem ${interface}
94 ;;
95
96 *)
97 echo "Invalid action: ${action}"
98 exit 1
99 ;;
100 esac
101done