The VLAN devices will now automatically be created after a parent device has been added.
Mainly this will resolve a race-condition between udev initialising the network adapters and sysvinit running scripts that will do the initialisation of the VLAN.
Signed-off-by: Michael Tremer michael.tremer@ipfire.org --- config/rootfiles/common/udev | 1 + config/udev/60-net.rules | 4 ++ config/udev/network-hotplug-vlan | 87 ++++++++++++++++++++++++++++++++++++++++ lfs/udev | 2 + 4 files changed, 94 insertions(+) create mode 100644 config/udev/network-hotplug-vlan
diff --git a/config/rootfiles/common/udev b/config/rootfiles/common/udev index d01c461..4d51954 100644 --- a/config/rootfiles/common/udev +++ b/config/rootfiles/common/udev @@ -29,6 +29,7 @@ lib/udev #lib/udev/init-net-rules.sh #lib/udev/mtd_probe #lib/udev/network-hotplug-rename +#lib/udev/network-hotplug-vlan #lib/udev/rule_generator.functions #lib/udev/rules.d #lib/udev/rules.d/25-alsa.rules diff --git a/config/udev/60-net.rules b/config/udev/60-net.rules index 4f22a1e..dc39ff0 100644 --- a/config/udev/60-net.rules +++ b/config/udev/60-net.rules @@ -1,3 +1,7 @@ # 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" + +# Call a script that will create all virtual devices for a parent device +# that has just come up. +ACTION=="add", SUBSYSTEM=="net", PROGRAM="/lib/udev/network-hotplug-vlan" diff --git a/config/udev/network-hotplug-vlan b/config/udev/network-hotplug-vlan new file mode 100644 index 0000000..f7b6a9d --- /dev/null +++ b/config/udev/network-hotplug-vlan @@ -0,0 +1,87 @@ +#!/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) 2015 IPFire Team info@ipfire.org # +# # +############################################################################ + +[ -n "${INTERFACE}" ] || exit 2 + +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}) + +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 + + # If the parent device does not match the interface that + # has just come up, we will go on for the next one. + [ "${PARENT_DEV}" = "${INTERFACE}" ] || 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 + + 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 +done + +exit 0 diff --git a/lfs/udev b/lfs/udev index e58839c..7d5bdbc 100644 --- a/lfs/udev +++ b/lfs/udev @@ -107,6 +107,8 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) # Install network rules. install -v -m 755 $(DIR_SRC)/config/udev/network-hotplug-rename \ /lib/udev/network-hotplug-rename + install -v -m 755 $(DIR_SRC)/config/udev/network-hotplug-vlan \ + /lib/udev/network-hotplug-vlan install -v -m 644 $(DIR_SRC)/config/udev/60-net.rules \ /lib/udev/rules.d
Signed-off-by: Michael Tremer michael.tremer@ipfire.org --- config/rootfiles/common/armv5tel/initscripts | 2 - config/rootfiles/common/i586/initscripts | 2 - lfs/initscripts | 1 - src/initscripts/init.d/network-vlans | 113 --------------------------- 4 files changed, 118 deletions(-) delete mode 100644 src/initscripts/init.d/network-vlans
diff --git a/config/rootfiles/common/armv5tel/initscripts b/config/rootfiles/common/armv5tel/initscripts index b4cd8f8..a174c5b 100644 --- a/config/rootfiles/common/armv5tel/initscripts +++ b/config/rootfiles/common/armv5tel/initscripts @@ -62,7 +62,6 @@ etc/rc.d/init.d/mounttmpfs #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 etc/rc.d/init.d/networking/blue @@ -232,7 +231,6 @@ 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 #etc/sysconfig diff --git a/config/rootfiles/common/i586/initscripts b/config/rootfiles/common/i586/initscripts index 878ba66..84c432a 100644 --- a/config/rootfiles/common/i586/initscripts +++ b/config/rootfiles/common/i586/initscripts @@ -64,7 +64,6 @@ etc/rc.d/init.d/mounttmpfs #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 etc/rc.d/init.d/networking/blue @@ -237,7 +236,6 @@ 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 #etc/sysconfig diff --git a/lfs/initscripts b/lfs/initscripts index 4005941..141fd66 100755 --- a/lfs/initscripts +++ b/lfs/initscripts @@ -177,7 +177,6 @@ $(TARGET) : 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 ln -sf ../init.d/wlanclient /etc/rc.d/rc3.d/S19wlanclient diff --git a/src/initscripts/init.d/network-vlans b/src/initscripts/init.d/network-vlans deleted file mode 100644 index a6a75c3..0000000 --- a/src/initscripts/init.d/network-vlans +++ /dev/null @@ -1,113 +0,0 @@ -#!/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
Hello guys,
could someone please review this patch?
This is a result from a bug report on the forum and supposed to resolve a race-condition. Someone has already confirmed that this works, but I want to have more feedback before merging this into the next tree.
http://forum.ipfire.org/viewtopic.php?f=6&t=14459
Best, -Michael
On Wed, 2015-08-05 at 12:45 +0100, Michael Tremer wrote:
The VLAN devices will now automatically be created after a parent device has been added.
Mainly this will resolve a race-condition between udev initialising the network adapters and sysvinit running scripts that will do the initialisation of the VLAN.
Signed-off-by: Michael Tremer michael.tremer@ipfire.org
config/rootfiles/common/udev | 1 + config/udev/60-net.rules | 4 ++ config/udev/network-hotplug-vlan | 87 ++++++++++++++++++++++++++++++++++++++++ lfs/udev | 2 + 4 files changed, 94 insertions(+) create mode 100644 config/udev/network-hotplug-vlan
diff --git a/config/rootfiles/common/udev b/config/rootfiles/common/udev index d01c461..4d51954 100644 --- a/config/rootfiles/common/udev +++ b/config/rootfiles/common/udev @@ -29,6 +29,7 @@ lib/udev #lib/udev/init-net-rules.sh #lib/udev/mtd_probe #lib/udev/network-hotplug-rename +#lib/udev/network-hotplug-vlan #lib/udev/rule_generator.functions #lib/udev/rules.d #lib/udev/rules.d/25-alsa.rules diff --git a/config/udev/60-net.rules b/config/udev/60-net.rules index 4f22a1e..dc39ff0 100644 --- a/config/udev/60-net.rules +++ b/config/udev/60-net.rules @@ -1,3 +1,7 @@ # 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"
+# Call a script that will create all virtual devices for a parent device +# that has just come up. +ACTION=="add", SUBSYSTEM=="net", PROGRAM="/lib/udev/network-hotplug-vlan" diff --git a/config/udev/network-hotplug-vlan b/config/udev/network-hotplug-vlan new file mode 100644 index 0000000..f7b6a9d --- /dev/null +++ b/config/udev/network-hotplug-vlan @@ -0,0 +1,87 @@ +#!/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) 2015 IPFire Team info@ipfire.org # +# # +############################################################################
+[ -n "${INTERFACE}" ] || exit 2
+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})
+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
+> > # If the parent device does not match the interface that +> > # has just come up, we will go on for the next one. +> > [ "${PARENT_DEV}" = "${INTERFACE}" ] || 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
+> > 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 +done
+exit 0 diff --git a/lfs/udev b/lfs/udev index e58839c..7d5bdbc 100644 --- a/lfs/udev +++ b/lfs/udev @@ -107,6 +107,8 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
# Install network rules. install -v -m 755 $(DIR_SRC)/config/udev/network-hotplug-rename \
/lib/udev/network-hotplug-rename
+> > install -v -m 755 $(DIR_SRC)/config/udev/network-hotplug-vlan \ +> > > /lib/udev/network-hotplug-vlan
install -v -m 644 $(DIR_SRC)/config/udev/60-net.rules \
/lib/udev/rules.d