]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/40network/net-genrules.sh
network: fix an error message
[thirdparty/dracut.git] / modules.d / 40network / net-genrules.sh
1 #!/bin/sh
2
3 getargbool 0 rd.neednet && NEEDNET=1
4
5 # Don't continue if we don't need network
6 if [ -z "$netroot" ] && [ ! -e "/tmp/net.ifaces" ] && [ "$NEEDNET" != "1" ]; then
7 return
8 fi
9
10 command -v fix_bootif >/dev/null || . /lib/net-lib.sh
11
12 # Write udev rules
13 {
14 # bridge: attempt only the defined interface
15 for i in /tmp/bridge.*.info; do
16 [ -e "$i" ] || continue
17 unset bridgeslaves
18 unset bridgename
19 . "$i"
20 RAW_IFACES="$RAW_IFACES $bridgeslaves"
21 MASTER_IFACES="$MASTER_IFACES $bridgename"
22 done
23
24 # bond: attempt only the defined interface (override bridge defines)
25 for i in /tmp/bond.*.info; do
26 [ -e "$i" ] || continue
27 unset bondslaves
28 unset bondname
29 . "$i"
30 # It is enough to fire up only one
31 RAW_IFACES="$RAW_IFACES $bondslaves"
32 MASTER_IFACES="$MASTER_IFACES ${bondname}"
33 done
34
35 for i in /tmp/team.*.info; do
36 [ -e "$i" ] || continue
37 unset teamslaves
38 unset teammaster
39 . "$i"
40 RAW_IFACES="$RAW_IFACES ${teamslaves}"
41 MASTER_IFACES="$MASTER_IFACES ${teammaster}"
42 done
43
44 for i in /tmp/vlan.*.phy; do
45 [ -e "$i" ] || continue
46 unset phydevice
47 . "$i"
48 RAW_IFACES="$RAW_IFACES $phydevice"
49 for j in /tmp/vlan.*.${phydevice}; do
50 [ -e "$j" ] || continue
51 unset vlanname
52 . "$j"
53 MASTER_IFACES="$MASTER_IFACES ${vlanname}"
54 done
55 done
56
57 MASTER_IFACES="$(trim "$MASTER_IFACES")"
58 RAW_IFACES="$(trim "$RAW_IFACES")"
59
60 if [ -z "$IFACES" ]; then
61 [ -e /tmp/net.ifaces ] && read IFACES < /tmp/net.ifaces
62 fi
63
64 if [ -e /tmp/net.bootdev ]; then
65 bootdev=$(cat /tmp/net.bootdev)
66 fi
67
68 ifup='/sbin/ifup $env{INTERFACE}'
69
70 runcmd="RUN+=\"/sbin/initqueue --name ifup-\$env{INTERFACE} --unique --onetime $ifup\""
71
72 # We have some specific interfaces to handle
73 if [ -n "${RAW_IFACES}${IFACES}" ]; then
74 echo 'SUBSYSTEM!="net", GOTO="net_end"'
75 echo 'ACTION!="add|change|move", GOTO="net_end"'
76 for iface in $IFACES $RAW_IFACES; do
77 case "$iface" in
78 ??:??:??:??:??:??) # MAC address
79 cond="ATTR{address}==\"$iface\""
80 echo "$cond, $runcmd, GOTO=\"net_end\""
81 ;;
82 ??-??-??-??-??-??) # MAC address in BOOTIF form
83 cond="ATTR{address}==\"$(fix_bootif $iface)\""
84 echo "$cond, $runcmd, GOTO=\"net_end\""
85 ;;
86 *) # an interface name
87 cond="ENV{INTERFACE}==\"$iface\""
88 echo "$cond, $runcmd, GOTO=\"net_end\""
89 cond="NAME==\"$iface\""
90 echo "$cond, $runcmd, GOTO=\"net_end\""
91 ;;
92 esac
93 # The GOTO prevents us from trying to ifup the same device twice
94 done
95 echo 'LABEL="net_end"'
96
97 for iface in $IFACES; do
98 if [ "$bootdev" = "$iface" ] || [ "$NEEDNET" = "1" ]; then
99 echo "[ -f /tmp/net.${iface}.did-setup ]" >$hookdir/initqueue/finished/wait-$iface.sh
100 fi
101 done
102 # Default: We don't know the interface to use, handle all
103 # Fixme: waiting for the interface as well.
104 else
105 cond='ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}!="wlan|wwan"'
106 # if you change the name of "91-default-net.rules", also change modules.d/80cms/cmssetup.sh
107 echo "$cond, $runcmd" > /etc/udev/rules.d/91-default-net.rules
108 if [ "$NEEDNET" = "1" ]; then
109 echo 'for i in /tmp/net.*.did-setup; do [ -f "$i" ] && exit 0; done; exit 1' >$hookdir/initqueue/finished/wait-network.sh
110 fi
111 fi
112
113 # if you change the name of "90-net.rules", also change modules.d/80cms/cmssetup.sh
114 } > /etc/udev/rules.d/90-net.rules