From 761ffdddb917f2ae777f5d04a32c16fb94467103 Mon Sep 17 00:00:00 2001 From: Philippe Seewer Date: Tue, 16 Jun 2009 19:26:35 +0200 Subject: [PATCH] netroot: Only start interface configuration if really needed Currently network configuration is launched by udev as soon as it discovers a driver. This isn't such a good idea since we don't know if network configuration is actually required. Change this by writing the udev rules on the fly if required. --- modules.d/40network/60-net.rules | 2 -- modules.d/40network/install | 2 +- modules.d/40network/net-genrules.sh | 10 ++++++++++ modules.d/40network/parse-ip-opts.sh | 8 ++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) delete mode 100644 modules.d/40network/60-net.rules create mode 100755 modules.d/40network/net-genrules.sh diff --git a/modules.d/40network/60-net.rules b/modules.d/40network/60-net.rules deleted file mode 100644 index 6c795081..00000000 --- a/modules.d/40network/60-net.rules +++ /dev/null @@ -1,2 +0,0 @@ -ACTION=="add", SUBSYSTEM=="net", RUN+="/sbin/ifup $env{INTERFACE}" -ACTION=="online", SUBSYSTEM=="net", RUN+="/sbin/netroot $env{INTERFACE}" diff --git a/modules.d/40network/install b/modules.d/40network/install index cb9359e9..0b76cbd7 100755 --- a/modules.d/40network/install +++ b/modules.d/40network/install @@ -15,7 +15,7 @@ inst "$moddir/netroot" "/sbin/netroot" inst "$moddir/dhclient-script" "/sbin/dhclient-script" inst "$moddir/dhclient.conf" "/etc/dhclient.conf" instmods ecb arc4 -inst_rules "$moddir/60-net.rules" +inst_hook pre-udev 60 "$moddir/net-genrules.sh" inst_hook cmdline 91 "$moddir/dhcp-root.sh" inst_hook cmdline 99 "$moddir/parse-ip-opts.sh" inst_hook pre-pivot 10 "$moddir/kill-dhclient.sh" diff --git a/modules.d/40network/net-genrules.sh b/modules.d/40network/net-genrules.sh new file mode 100755 index 00000000..ae5d38f1 --- /dev/null +++ b/modules.d/40network/net-genrules.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Don't continue if we don't need network +[ -z "$netroot" ] && return; + +# Write udev rules +{ + printf 'ACTION=="add", SUBSYSTEM=="net", RUN+="/sbin/ifup $env{INTERFACE}"\n' + printf 'ACTION=="online", SUBSYSTEM=="net", RUN+="/sbin/netroot $env{INTERFACE}"\n' +} > /etc/udev/rules.d/60-net.rules diff --git a/modules.d/40network/parse-ip-opts.sh b/modules.d/40network/parse-ip-opts.sh index df1a071e..d87c851e 100755 --- a/modules.d/40network/parse-ip-opts.sh +++ b/modules.d/40network/parse-ip-opts.sh @@ -26,6 +26,14 @@ ip_to_var() { esac } +# Check if ip= lines should be used +if getarg ip= >/dev/null ; then + if [ -z "$netroot" ] ; then + echo "Warning: No netboot configured, ignoring ip= lines" + return; + fi +fi + # Warn if defaulting to ip=dhcp if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] ; then warn "No ip= argument(s) for netroot provided, defaulting to DHCP"