From: Will Woods Date: Wed, 22 Aug 2012 20:59:16 +0000 (-0400) Subject: net-genrules: accept MAC address for $iface, cleanups X-Git-Tag: 029~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57f257928116a8e614bb1933a9f8fbf9d9c39c52;p=thirdparty%2Fdracut.git net-genrules: accept MAC address for $iface, cleanups A MAC address is a unique identifier for a particular network interface. We can use the MAC to generate udev rules to bring up that interface, like we currently do with BOOTIF. This patch allows interfaces to be specified as a MAC address, either in the usual colon-separated form or the PXE-style dash-separated form. (The latter is more useful on the commandline, since it allows for arguments like: "ip=77-77-6f-6f-64-73:dhcp") This is useful since it's common for a user who is booting a new OS for the first time to know the MAC of the device, but not know what the kernel name will be. --- diff --git a/modules.d/40network/net-genrules.sh b/modules.d/40network/net-genrules.sh index f4b1f88c0..43aa9e391 100755 --- a/modules.d/40network/net-genrules.sh +++ b/modules.d/40network/net-genrules.sh @@ -54,21 +54,25 @@ command -v fix_bootif >/dev/null || . /lib/net-lib.sh ifup='/sbin/ifup $env{INTERFACE}' [ -z "$netroot" ] && ifup="$ifup -m" - # BOOTIF says everything, use only that one - BOOTIF=$(getarg 'BOOTIF=') - if [ -n "$BOOTIF" ] ; then - BOOTIF=$(fix_bootif "$BOOTIF") - printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="%s"\n' "$BOOTIF" "/sbin/initqueue --onetime $ifup" - echo "[ -f /tmp/setup_net_${BOOTIF}.ok ]" >$hookdir/initqueue/finished/wait-${BOOTIF}.sh + runcmd="RUN+=\"/sbin/initqueue --onetime $ifup\"" - # If we have to handle multiple interfaces, handle only them. - elif [ -n "$IFACES" ] ; then - for iface in $IFACES ; do - printf 'SUBSYSTEM=="net", ENV{INTERFACE}=="%s", RUN+="%s"\n' "$iface" "/sbin/initqueue --onetime $ifup" - if [ "$bootdev" = "$iface" ] || [ "$NEEDNET" = "1" ]; then - echo "[ -f /tmp/setup_net_${iface}.ok ]" >$hookdir/initqueue/finished/wait-$iface.sh - fi + # We have some specific interfaces to handle + if [ -n "$IFACES" ]; then + echo 'SUBSYSTEM!="net", GOTO="net_end"' + echo 'ACTION=="remove", GOTO="net_end"' + for iface in $IFACES; do + case "$iface" in + ??:??:??:??:??:??) # MAC address + cond="ATTR{address}==\"$iface\"" ;; + ??-??-??-??-??-??) # MAC address in BOOTIF form + cond="ATTR{address}==\"$(fix_bootif $iface)\"" ;; + *) # an interface name + cond="ENV{INTERFACE}==\"$iface\"" ;; + esac + # The GOTO prevents us from trying to ifup the same device twice + echo "$cond, $runcmd, GOTO=\"net_end\"" done + echo 'LABEL="net_end"' for iface in $MASTER_IFACES; do if [ "$bootdev" = "$iface" ] || [ "$NEEDNET" = "1" ]; then @@ -78,8 +82,9 @@ command -v fix_bootif >/dev/null || . /lib/net-lib.sh # Default: We don't know the interface to use, handle all # Fixme: waiting for the interface as well. else + cond='ACTION=="add|change", SUBSYSTEM=="net"' # if you change the name of "91-default-net.rules", also change modules.d/80cms/cmssetup.sh - printf 'SUBSYSTEM=="net", RUN+="%s"\n' "/sbin/initqueue --onetime $ifup" > /etc/udev/rules.d/91-default-net.rules + echo "$cond, $runcmd" > /etc/udev/rules.d/91-default-net.rules fi # if you change the name of "90-net.rules", also change modules.d/80cms/cmssetup.sh