mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-09 18:45:54 +02:00
- https://bugzilla.ipfire.org/show_bug.cgi?id=12676#c3 Suggested-by: Michael Tremer <michael.tremer@ipfire.org> Signed-off-by: Adolf Belka <adolf.belka@ipfire.org> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
97 lines
3.5 KiB
Bash
97 lines
3.5 KiB
Bash
#!/bin/bash
|
|
###############################################################################
|
|
# #
|
|
# IPFire.org - A linux based firewall #
|
|
# Copyright (C) 2015-2024 IPFire Team <info@ipfire.org> #
|
|
# #
|
|
# This program is free software: you can redistribute it and/or modify #
|
|
# it under the terms of the GNU General Public License as published by #
|
|
# the Free Software Foundation, either version 3 of the License, or #
|
|
# (at your option) any later version. #
|
|
# #
|
|
# This program is distributed in the hope that it will be useful, #
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
# GNU General Public License for more details. #
|
|
# #
|
|
# You should have received a copy of the GNU General Public License #
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
|
# #
|
|
###############################################################################
|
|
|
|
[ -n "${INTERFACE}" ] || exit 2
|
|
|
|
VLAN_CONFIG_FILE="/var/ipfire/ethernet/vlans"
|
|
MAIN_CONFIG_FILE="/var/ipfire/ethernet/settings"
|
|
|
|
# Skip immediately if a configuration file is missing.
|
|
[ -e "${VLAN_CONFIG_FILE}" ] && [ -e "${MAIN_CONFIG_FILE}" ] || exit 0
|
|
|
|
eval $(/usr/local/bin/readhash ${VLAN_CONFIG_FILE})
|
|
eval $(/usr/local/bin/readhash ${MAIN_CONFIG_FILE})
|
|
|
|
for interface in green0 red0 blue0 orange0; do
|
|
case "${interface}" in
|
|
green*)
|
|
ZONE_MODE=${GREEN_MODE}
|
|
PARENT_DEV=${GREEN_PARENT_DEV}
|
|
VLAN_ID=${GREEN_VLAN_ID}
|
|
MAC_ADDRESS=${GREEN_MAC_ADDRESS}
|
|
;;
|
|
red*)
|
|
ZONE_MODE=${RED_MODE}
|
|
PARENT_DEV=${RED_PARENT_DEV}
|
|
VLAN_ID=${RED_VLAN_ID}
|
|
MAC_ADDRESS=${RED_MAC_ADDRESS}
|
|
;;
|
|
blue*)
|
|
ZONE_MODE=${BLUE_MODE}
|
|
PARENT_DEV=${BLUE_PARENT_DEV}
|
|
VLAN_ID=${BLUE_VLAN_ID}
|
|
MAC_ADDRESS=${BLUE_MAC_ADDRESS}
|
|
;;
|
|
orange*)
|
|
ZONE_MODE=${ORANGE_MODE}
|
|
PARENT_DEV=${ORANGE_PARENT_DEV}
|
|
VLAN_ID=${ORANGE_VLAN_ID}
|
|
MAC_ADDRESS=${ORANGE_MAC_ADDRESS}
|
|
;;
|
|
esac
|
|
|
|
# If the parent device (MAC or name) does not match the interface that
|
|
# has just come up, we will go on for the next one.
|
|
[ "${PARENT_DEV}" = "${INTERFACE}" -o "${PARENT_DEV}" = "$(</sys/class/net/${INTERFACE}/address)" ] || continue
|
|
|
|
# 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)
|
|
if [ "${ZONE_MODE}" = "bridge" ]; then
|
|
interface="${INTERFACE}.${VLAN_ID}"
|
|
fi
|
|
|
|
# Check if the interface does already exists.
|
|
# If so, we skip creating it.
|
|
if [ -d "/sys/class/net/${interface}" ]; then
|
|
echo "Interface ${interface} already exists." >&2
|
|
continue
|
|
fi
|
|
|
|
if [ -z "${VLAN_ID}" ]; then
|
|
echo "${interface}: You did not set the VLAN ID." >&2
|
|
continue
|
|
fi
|
|
|
|
# Build command line.
|
|
command="ip link add link ${INTERFACE} name ${interface}"
|
|
if [ -n "${MAC_ADDRESS}" ]; then
|
|
command="${command} address ${MAC_ADDRESS}"
|
|
fi
|
|
command="${command} type vlan id ${VLAN_ID}"
|
|
|
|
echo "Creating VLAN interface ${interface}..."
|
|
${command}
|
|
|
|
# Bring up the parent device.
|
|
ip link set ${INTERFACE} up
|
|
done
|
|
|
|
exit 0
|