]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/40network/net-genrules.sh
Bridged network boot
[thirdparty/dracut.git] / modules.d / 40network / net-genrules.sh
1 #!/bin/sh
2
3 # pxelinux provides macaddr '-' separated, but we need ':'
4 fix_bootif() {
5 local macaddr=${1}
6 local IFS='-'
7 macaddr=$(for i in ${macaddr} ; do echo -n $i:; done)
8 macaddr=${macaddr%:}
9 echo $macaddr
10 }
11
12 # Don't continue if we don't need network
13 [ -z "$netroot" ] && return;
14
15 # Write udev rules
16 {
17 # bridge: attempt only the defined interface
18 if [ -e /tmp/bridge.info ]; then
19 . /tmp/bridge.info
20 IFACES=$ethname
21 fi
22
23 # BOOTIF says everything, use only that one
24 BOOTIF=$(getarg 'BOOTIF=')
25 if [ -n "$BOOTIF" ] ; then
26 BOOTIF=$(fix_bootif "$BOOTIF")
27 printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/ifup $env{INTERFACE}"\n' "$BOOTIF"
28
29 # If we have to handle multiple interfaces, handle only them.
30 elif [ -n "$IFACES" ] ; then
31 for iface in $IFACES ; do
32 printf 'ACTION=="add", SUBSYSTEM=="net", KERNEL=="%s", RUN+="/sbin/ifup $env{INTERFACE}"\n' "$iface"
33 done
34
35 # Default: We don't know the interface to use, handle all
36 else
37 printf 'ACTION=="add", SUBSYSTEM=="net", RUN+="/sbin/ifup $env{INTERFACE}"\n'
38 fi
39
40 # Udev event 'online' only gets fired from ifup/dhclient-script.
41 # No special rules required
42 printf 'ACTION=="online", SUBSYSTEM=="net", RUN+="/sbin/netroot $env{INTERFACE}"\n'
43 } > /etc/udev/rules.d/60-net.rules