]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
network: Configure device names from /var/ipfire/ethernet/settings
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Mar 2015 14:35:57 +0000 (15:35 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 Mar 2015 15:31:59 +0000 (16:31 +0100)
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, ...).

config/rootfiles/common/armv5tel/initscripts
config/rootfiles/common/i586/initscripts
config/rootfiles/common/udev
config/udev/60-net.rules [new file with mode: 0644]
config/udev/network-hotplug-rename [new file with mode: 0644]
lfs/initscripts
lfs/udev
src/initscripts/init.d/network-trigger [new file with mode: 0644]

index 53bc64f9a896e55f164ae4bc37a76e3c2a78525c..05b8ceebe84d45295eec6c4d5b7cad8320243d1f 100755 (executable)
@@ -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
index 7bab7c4f946c1e1994a352cfe1b04fc8fd4fca20..d4779ab054230c54c893e27120899faf9b791be1 100755 (executable)
@@ -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
index bc1cdaa1ff3ba1ceae448a37f13ed5b8314b6e85..d01c4610158f05d6da4b1febd2f1ac5b1e6ee772 100644 (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
diff --git a/config/udev/60-net.rules b/config/udev/60-net.rules
new file mode 100644 (file)
index 0000000..4f22a1e
--- /dev/null
@@ -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"
diff --git a/config/udev/network-hotplug-rename b/config/udev/network-hotplug-rename
new file mode 100644 (file)
index 0000000..331b788
--- /dev/null
@@ -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
index f656c72a7458025459f1481a568a1721f4059804..400594136230363a5ea32c29bab06658cffbe7bb 100755 (executable)
@@ -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
index 15dae817b2b35dd6d02f7ccbfb80be7dbdb487b1..e58839c405e93a214b37774d3cb06cf83fe1a996 100644 (file)
--- a/lfs/udev
+++ b/lfs/udev
@@ -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
diff --git a/src/initscripts/init.d/network-trigger b/src/initscripts/init.d/network-trigger
new file mode 100644 (file)
index 0000000..0d9de45
--- /dev/null
@@ -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