]> git.ipfire.org Git - ipfire-2.x.git/blame - config/udev/network-hotplug-vlan
udev: Accept MAC addresses for PARENT_DEV
[ipfire-2.x.git] / config / udev / network-hotplug-vlan
CommitLineData
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
a4941749
FB
26VLAN_CONFIG_FILE="/var/ipfire/ethernet/vlans"
27MAIN_CONFIG_FILE="/var/ipfire/ethernet/settings"
36f7fe6a 28
a4941749
FB
29# Skip immediately if a configuration file is missing.
30[ -e "${VLAN_CONFIG_FILE}" ] && [ -e "${MAIN_CONFIG_FILE}" ] || exit 0
36f7fe6a 31
a4941749
FB
32eval $(/usr/local/bin/readhash ${VLAN_CONFIG_FILE})
33eval $(/usr/local/bin/readhash ${MAIN_CONFIG_FILE})
36f7fe6a
MT
34
35for interface in green0 red0 blue0 orange0; do
36 case "${interface}" in
37 green*)
a4941749 38 ZONE_MODE=${GREEN_MODE}
36f7fe6a
MT
39 PARENT_DEV=${GREEN_PARENT_DEV}
40 VLAN_ID=${GREEN_VLAN_ID}
41 MAC_ADDRESS=${GREEN_MAC_ADDRESS}
42 ;;
43 red*)
a4941749 44 ZONE_MODE=${RED_MODE}
36f7fe6a
MT
45 PARENT_DEV=${RED_PARENT_DEV}
46 VLAN_ID=${RED_VLAN_ID}
47 MAC_ADDRESS=${RED_MAC_ADDRESS}
48 ;;
49 blue*)
a4941749 50 ZONE_MODE=${BLUE_MODE}
36f7fe6a
MT
51 PARENT_DEV=${BLUE_PARENT_DEV}
52 VLAN_ID=${BLUE_VLAN_ID}
53 MAC_ADDRESS=${BLUE_MAC_ADDRESS}
54 ;;
55 orange*)
a4941749 56 ZONE_MODE=${ORANGE_MODE}
36f7fe6a
MT
57 PARENT_DEV=${ORANGE_PARENT_DEV}
58 VLAN_ID=${ORANGE_VLAN_ID}
59 MAC_ADDRESS=${ORANGE_MAC_ADDRESS}
60 ;;
61 esac
62
a4941749 63 # If the parent device (MAC or name) does not match the interface that
36f7fe6a 64 # has just come up, we will go on for the next one.
a4941749
FB
65 [ "${PARENT_DEV}" = "${INTERFACE}" ] || [ "${PARENT_DEV}" = "$(</sys/class/net/${INTERFACE}/address)" ] || continue
66
67 # If the current zone is operating in bridge mode, give the VLAN interface a generic name (e.g. eth0.99 for VLAN 99 on eth0)
68 if [ "${ZONE_MODE}" = "bridge" ]; then
69 interface="${INTERFACE}.${VLAN_ID}"
70 fi
36f7fe6a
MT
71
72 # Check if the interface does already exists.
73 # If so, we skip creating it.
74 if [ -d "/sys/class/net/${interface}" ]; then
75 echo "Interface ${interface} already exists." >&2
76 continue
77 fi
78
79 if [ -z "${VLAN_ID}" ]; then
80 echo "${interface}: You did not set the VLAN ID." >&2
81 continue
82 fi
83
84 # Build command line.
a4941749 85 command="ip link add link ${INTERFACE} name ${interface}"
36f7fe6a
MT
86 if [ -n "${MAC_ADDRESS}" ]; then
87 command="${command} address ${MAC_ADDRESS}"
88 fi
89 command="${command} type vlan id ${VLAN_ID}"
90
91 echo "Creating VLAN interface ${interface}..."
92 ${command}
93
94 # Bring up the parent device.
a4941749 95 ip link set ${INTERFACE} up
36f7fe6a
MT
96done
97
98exit 0