]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/initscripts/init.d/network-vlans
Merge remote-tracking branch 'stevee/axel-log-fix' into axel-fixperms
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / network-vlans
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
24 CONFIG_FILE="/var/ipfire/ethernet/vlans"
25
26 # Skip immediately if no configuration file has been found.
27 [ -e "${CONFIG_FILE}" ] || exit 0
28
29 eval $(/usr/local/bin/readhash ${CONFIG_FILE})
30
31 # This is start or stop.
32 action=${1}
33
34 for 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 # If no parent device has been configured, we assume
56 # that this interface is not set up for VLANs and
57 # silently go on.
58 [ -z "${PARENT_DEV}" ] && continue
59
60 # Check if the interface does already exists.
61 # If so, we skip creating it.
62 if [ -d "/sys/class/net/${interface}" ]; then
63 echo "Interface ${interface} already exists." >&2
64 continue
65 fi
66
67 # Check if the parent interface exists.
68 if [ ! -d "/sys/class/net/${PARENT_DEV}" ]; then
69 echo "${interface}: Parent device is not set or does not exist: ${PARENT_DEV}" >&2
70 continue
71 fi
72
73 if [ -z "${VLAN_ID}" ]; then
74 echo "${interface}: You did not set the VLAN ID." >&2
75 continue
76 fi
77
78 echo "Creating VLAN interface ${interface}..."
79 vconfig add ${PARENT_DEV} ${VLAN_ID}
80 ip link set ${PARENT_DEV}.${VLAN_ID} name ${interface}
81
82 if [ -n "${MAC_ADDRESS}" ]; then
83 ip link set ${interface} address ${MAC_ADDRESS}
84 fi
85
86 # Bring up the parent device.
87 ip link set ${PARENT_DEV} up
88 ;;
89
90 stop)
91 if [ ! -e "/proc/net/vlan/${interface}" ]; then
92 echo "${interface} is not a VLAN interface. Skipping."
93 continue
94 fi
95
96 echo "Removing VLAN interface ${interface}..."
97 ip link set ${interface} down
98 vconfig rem ${interface}
99 ;;
100
101 *)
102 echo "Invalid action: ${action}"
103 exit 1
104 ;;
105 esac
106 done