mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-05-01 07:50:23 +02:00
This patch gets rid of using vconfig for configuring VLAN devices. ip link is much more suitable for that and creates the interface with the right name and MAC address in just one step.
114 lines
3.7 KiB
Bash
114 lines
3.7 KiB
Bash
#!/bin/bash
|
|
############################################################################
|
|
# #
|
|
# This file is part of the IPFire Firewall. #
|
|
# #
|
|
# IPFire 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 2 of the License, or #
|
|
# (at your option) any later version. #
|
|
# #
|
|
# IPFire 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 IPFire; if not, write to the Free Software #
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
# #
|
|
# Copyright (C) 2012 IPFire Team <info@ipfire.org> #
|
|
# #
|
|
############################################################################
|
|
|
|
CONFIG_FILE="/var/ipfire/ethernet/vlans"
|
|
|
|
# Skip immediately if no configuration file has been found.
|
|
[ -e "${CONFIG_FILE}" ] || exit 0
|
|
|
|
eval $(/usr/local/bin/readhash ${CONFIG_FILE})
|
|
|
|
# This is start or stop.
|
|
action=${1}
|
|
|
|
for interface in green0 red0 blue0 orange0; do
|
|
case "${interface}" in
|
|
green*)
|
|
PARENT_DEV=${GREEN_PARENT_DEV}
|
|
VLAN_ID=${GREEN_VLAN_ID}
|
|
MAC_ADDRESS=${GREEN_MAC_ADDRESS}
|
|
;;
|
|
red*)
|
|
PARENT_DEV=${RED_PARENT_DEV}
|
|
VLAN_ID=${RED_VLAN_ID}
|
|
MAC_ADDRESS=${RED_MAC_ADDRESS}
|
|
;;
|
|
blue*)
|
|
PARENT_DEV=${BLUE_PARENT_DEV}
|
|
VLAN_ID=${BLUE_VLAN_ID}
|
|
MAC_ADDRESS=${BLUE_MAC_ADDRESS}
|
|
;;
|
|
orange*)
|
|
PARENT_DEV=${ORANGE_PARENT_DEV}
|
|
VLAN_ID=${ORANGE_VLAN_ID}
|
|
MAC_ADDRESS=${ORANGE_MAC_ADDRESS}
|
|
;;
|
|
esac
|
|
|
|
case "${action}" in
|
|
start)
|
|
# If no parent device has been configured, we assume
|
|
# that this interface is not set up for VLANs and
|
|
# silently go on.
|
|
[ -z "${PARENT_DEV}" ] && continue
|
|
|
|
# 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
|
|
|
|
# Check if the parent interface exists.
|
|
if [ ! -d "/sys/class/net/${PARENT_DEV}" ]; then
|
|
echo "${interface}: Parent device is not set or does not exist: ${PARENT_DEV}" >&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 ${PARENT_DEV} 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 ${PARENT_DEV} up
|
|
;;
|
|
|
|
stop)
|
|
if [ ! -e "/proc/net/vlan/${interface}" ]; then
|
|
echo "${interface} is not a VLAN interface. Skipping."
|
|
continue
|
|
fi
|
|
|
|
echo "Removing VLAN interface ${interface}..."
|
|
ip link set ${interface} down
|
|
ip link delete ${interface}
|
|
;;
|
|
|
|
*)
|
|
echo "Invalid action: ${action}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|