network: Configure device names from /var/ipfire/ethernet/settings

Instead of creating a copy of the configuration values and
for better extensibility, we will have udev execute a script
that parses /var/ipfire/ethernet/settings and will return the
correct name of the corresponding device (green0, blue0, ...).
This commit is contained in:
Michael Tremer
2015-03-09 15:35:57 +01:00
parent 5604dc748d
commit 600b99fb31
8 changed files with 113 additions and 4 deletions

View File

@@ -60,6 +60,7 @@ etc/rc.d/init.d/mounttmpfs
#etc/rc.d/init.d/mysql
#etc/rc.d/init.d/netsnmpd
etc/rc.d/init.d/network
etc/rc.d/init.d/network-trigger
etc/rc.d/init.d/network-vlans
#etc/rc.d/init.d/networking
etc/rc.d/init.d/networking/any
@@ -228,6 +229,7 @@ etc/rc.d/rcsysinit.d/S73swconfig
etc/rc.d/rcsysinit.d/S75firstsetup
etc/rc.d/rcsysinit.d/S80localnet
etc/rc.d/rcsysinit.d/S85firewall
etc/rc.d/rcsysinit.d/S90network-trigger
etc/rc.d/rcsysinit.d/S91network-vlans
etc/rc.d/rcsysinit.d/S92rngd
etc/rc.d/rc3.d/S15fireinfo

View File

@@ -62,6 +62,7 @@ etc/rc.d/init.d/mounttmpfs
#etc/rc.d/init.d/mysql
#etc/rc.d/init.d/netsnmpd
etc/rc.d/init.d/network
etc/rc.d/init.d/network-trigger
etc/rc.d/init.d/network-vlans
#etc/rc.d/init.d/networking
etc/rc.d/init.d/networking/any
@@ -233,6 +234,7 @@ etc/rc.d/rcsysinit.d/S70console
etc/rc.d/rcsysinit.d/S75firstsetup
etc/rc.d/rcsysinit.d/S80localnet
etc/rc.d/rcsysinit.d/S85firewall
etc/rc.d/rcsysinit.d/S90network-trigger
etc/rc.d/rcsysinit.d/S91network-vlans
etc/rc.d/rcsysinit.d/S92rngd
etc/rc.d/rc3.d/S15fireinfo

View File

@@ -2,7 +2,6 @@ bin/udevadm
etc/modprobe.d/blacklist.conf
etc/udev
#etc/udev/rules.d
#etc/udev/rules.d/30-persistent-network.rules
#etc/udev/rules.d/55-lfs.rules
#etc/udev/rules.d/81-cdrom.rules
#etc/udev/rules.d/83-cdrom-symlinks.rules
@@ -29,6 +28,7 @@ lib/udev
#lib/udev/hwdb.d/60-keyboard.hwdb
#lib/udev/init-net-rules.sh
#lib/udev/mtd_probe
#lib/udev/network-hotplug-rename
#lib/udev/rule_generator.functions
#lib/udev/rules.d
#lib/udev/rules.d/25-alsa.rules
@@ -37,6 +37,7 @@ lib/udev
#lib/udev/rules.d/50-udev-default.rules
#lib/udev/rules.d/60-cdrom_id.rules
#lib/udev/rules.d/60-keyboard.rules
#lib/udev/rules.d/60-net.rules
#lib/udev/rules.d/60-persistent-alsa.rules
#lib/udev/rules.d/60-persistent-input.rules
#lib/udev/rules.d/60-persistent-serial.rules

3
config/udev/60-net.rules Normal file
View File

@@ -0,0 +1,3 @@
# Call a script that checks for the right name of the new device.
# If it matches the configuration it will be renamed accordingly.
ACTION=="add", SUBSYSTEM=="net", PROGRAM="/lib/udev/network-hotplug-rename", RESULT=="?*", NAME="$result"

View File

@@ -0,0 +1,75 @@
#!/bin/bash
###############################################################################
# #
# IPFire.org - A linux based firewall #
# Copyright (C) 2015 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/>. #
# #
###############################################################################
# Check if all appropriate variables are set
[ -n "${INTERFACE}" ] || exit 2
# Ignore virtual interfaces, etc.
case "${INTERFACE}" in
lo)
exit 0
;;
tun*)
exit 0
;;
ppp*)
exit 0
;;
esac
# Check if INTERFACE actually exists
[ -d "/sys/class/net/${INTERFACE}" ] || exit 1
# If the network configuration is not readable,
# we cannot go on.
if [ ! -r "/var/ipfire/ethernet/settings" ]; then
exit 1
fi
# Read network settings
eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
# Standard zones
ZONES="RED GREEN ORANGE BLUE"
# Determine the address of INTERFACE
ADDRESS="$(</sys/class/net/${INTERFACE}/address)"
# Walk through all zones and find the matching interface
for zone in ${ZONES}; do
address="${zone}_MACADDR"
device="${zone}_DEV"
# Skip if address or device is unset
[ -n "${!address}" -a -n "${!device}" ] || continue
# If a matching interface has been found we will
# print the name to which udev will rename it.
if [ "${ADDRESS}" = "${!address}" ]; then
echo "${!device}"
exit 0
fi
done
# If we get here we have not found a matching device,
# but we won't return an error any way. The new device
# will remain with the previous name.
exit 0

View File

@@ -176,6 +176,7 @@ $(TARGET) :
ln -sf ../init.d/firstsetup /etc/rc.d/rcsysinit.d/S75firstsetup
ln -sf ../init.d/localnet /etc/rc.d/rcsysinit.d/S80localnet
ln -sf ../init.d/firewall /etc/rc.d/rcsysinit.d/S85firewall
ln -sf ../init.d/network-trigger /etc/rc.d/rcsysinit.d/S90network-trigger
ln -sf ../init.d/network-vlans /etc/rc.d/rcsysinit.d/S91network-vlans
ln -sf ../init.d/rngd /etc/rc.d/rcsysinit.d/S92rngd
ln -sf ../init.d/wlanclient /etc/rc.d/rc0.d/K82wlanclient

View File

@@ -93,9 +93,6 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
rm -f /lib/udev/rules.d/75-persistent-net-generator.rules
rm -f /lib/udev/rules.d/80-net-name-slot.rules
# Create rule file for the setup
touch /etc/udev/rules.d/30-persistent-network.rules
# Blacklist some modules
cp -vf $(DIR_SRC)/config/udev/blacklist.conf /etc/modprobe.d/blacklist.conf
@@ -107,6 +104,12 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
install -v -m 644 $(DIR_SRC)/config/udev/25-alsa.rules \
/lib/udev/rules.d
# Install network rules.
install -v -m 755 $(DIR_SRC)/config/udev/network-hotplug-rename \
/lib/udev/network-hotplug-rename
install -v -m 644 $(DIR_SRC)/config/udev/60-net.rules \
/lib/udev/rules.d
# Install hwrng rules.
install -v -m 644 $(DIR_SRC)/config/udev/90-hwrng.rules \
/lib/udev/rules.d

View File

@@ -0,0 +1,22 @@
#!/bin/sh
########################################################################
# Begin $rc_base/init.d/network-trigger
########################################################################
. /etc/sysconfig/rc
. ${rc_functions}
case "${1}" in
start)
boot_mesg "Triggering network devices..."
udevadm trigger --action="add" --subsystem-match="net"
evaluate_retval
;;
*)
echo "Usage: ${0} {start}"
exit 1
;;
esac
# End $rc_base/init.d/network-trigger