]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
3d8f85ec | 29 | eval $(/usr/local/bin/readhash ${CONFIG_FILE}) |
d23fc912 MT |
30 | |
31 | # This is start or stop. | |
32 | action=${1} | |
33 | ||
3de19c87 | 34 | for 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 | ||
ba25f014 MT |
83 | # Build command line. |
84 | command="ip link add link ${PARENT_DEV} name ${interface}" | |
d23fc912 | 85 | if [ -n "${MAC_ADDRESS}" ]; then |
ba25f014 | 86 | command="${command} address ${MAC_ADDRESS}" |
d23fc912 | 87 | fi |
ba25f014 MT |
88 | command="${command} type vlan id ${VLAN_ID}" |
89 | ||
90 | echo "Creating VLAN interface ${interface}..." | |
91 | ${command} | |
d23fc912 MT |
92 | |
93 | # Bring up the parent device. | |
94 | ip link set ${PARENT_DEV} up | |
95 | ;; | |
96 | ||
97 | stop) | |
98 | if [ ! -e "/proc/net/vlan/${interface}" ]; then | |
99 | echo "${interface} is not a VLAN interface. Skipping." | |
100 | continue | |
101 | fi | |
102 | ||
103 | echo "Removing VLAN interface ${interface}..." | |
104 | ip link set ${interface} down | |
ba25f014 | 105 | ip link delete ${interface} |
d23fc912 MT |
106 | ;; |
107 | ||
108 | *) | |
109 | echo "Invalid action: ${action}" | |
110 | exit 1 | |
111 | ;; | |
112 | esac | |
113 | done |