]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
net-genrules: accept MAC address for $iface, cleanups
authorWill Woods <wwoods@redhat.com>
Wed, 22 Aug 2012 20:59:16 +0000 (16:59 -0400)
committerHarald Hoyer <harald@redhat.com>
Thu, 13 Jun 2013 12:07:17 +0000 (14:07 +0200)
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.

modules.d/40network/net-genrules.sh

index f4b1f88c0c4789e6bfe90eb3ce936b1a4a3780dc..43aa9e39192546982426f8defef90e4b131ade41 100755 (executable)
@@ -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