]>
Commit | Line | Data |
---|---|---|
36f7fe6a 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) 2015 IPFire Team <info@ipfire.org> # | |
21 | # # | |
22 | ############################################################################ | |
23 | ||
24 | [ -n "${INTERFACE}" ] || exit 2 | |
25 | ||
26 | CONFIG_FILE="/var/ipfire/ethernet/vlans" | |
27 | ||
28 | # Skip immediately if no configuration file has been found. | |
29 | [ -e "${CONFIG_FILE}" ] || exit 0 | |
30 | ||
31 | eval $(/usr/local/bin/readhash ${CONFIG_FILE}) | |
32 | ||
33 | for interface in green0 red0 blue0 orange0; do | |
34 | case "${interface}" in | |
35 | green*) | |
36 | PARENT_DEV=${GREEN_PARENT_DEV} | |
37 | VLAN_ID=${GREEN_VLAN_ID} | |
38 | MAC_ADDRESS=${GREEN_MAC_ADDRESS} | |
39 | ;; | |
40 | red*) | |
41 | PARENT_DEV=${RED_PARENT_DEV} | |
42 | VLAN_ID=${RED_VLAN_ID} | |
43 | MAC_ADDRESS=${RED_MAC_ADDRESS} | |
44 | ;; | |
45 | blue*) | |
46 | PARENT_DEV=${BLUE_PARENT_DEV} | |
47 | VLAN_ID=${BLUE_VLAN_ID} | |
48 | MAC_ADDRESS=${BLUE_MAC_ADDRESS} | |
49 | ;; | |
50 | orange*) | |
51 | PARENT_DEV=${ORANGE_PARENT_DEV} | |
52 | VLAN_ID=${ORANGE_VLAN_ID} | |
53 | MAC_ADDRESS=${ORANGE_MAC_ADDRESS} | |
54 | ;; | |
55 | esac | |
56 | ||
57 | # If the parent device does not match the interface that | |
58 | # has just come up, we will go on for the next one. | |
59 | [ "${PARENT_DEV}" = "${INTERFACE}" ] || continue | |
60 | ||
61 | # Check if the interface does already exists. | |
62 | # If so, we skip creating it. | |
63 | if [ -d "/sys/class/net/${interface}" ]; then | |
64 | echo "Interface ${interface} already exists." >&2 | |
65 | continue | |
66 | fi | |
67 | ||
68 | if [ -z "${VLAN_ID}" ]; then | |
69 | echo "${interface}: You did not set the VLAN ID." >&2 | |
70 | continue | |
71 | fi | |
72 | ||
73 | # Build command line. | |
74 | command="ip link add link ${PARENT_DEV} name ${interface}" | |
75 | if [ -n "${MAC_ADDRESS}" ]; then | |
76 | command="${command} address ${MAC_ADDRESS}" | |
77 | fi | |
78 | command="${command} type vlan id ${VLAN_ID}" | |
79 | ||
80 | echo "Creating VLAN interface ${interface}..." | |
81 | ${command} | |
82 | ||
83 | # Bring up the parent device. | |
84 | ip link set ${PARENT_DEV} up | |
85 | done | |
86 | ||
87 | exit 0 |