]>
Commit | Line | Data |
---|---|---|
7d7efa4a | 1 | #!/bin/sh |
cc02093d HH |
2 | # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- |
3 | # ex: ts=8 sw=4 sts=4 et filetype=sh | |
7d7efa4a | 4 | |
fb59f4c9 | 5 | PATH=/usr/sbin:/usr/bin:/sbin:/bin |
c9f1e3d1 | 6 | type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
7d7efa4a | 7 | |
05e2c592 PS |
8 | # Huh? Empty $1? |
9 | [ -z "$1" ] && exit 1 | |
10 | ||
11 | # Huh? No interface config? | |
12 | [ ! -e /tmp/net.$1.up ] && exit 1 | |
13 | ||
957bc5c9 DY |
14 | # [ ! -z $2 ] means this is for manually bringing up network |
15 | # instead of real netroot; If It's called without $2, then there's | |
16 | # no sense in doing something if no (net)root info is available | |
a55d10c0 | 17 | # or root is already there |
957bc5c9 DY |
18 | if [ -z "$2" ]; then |
19 | [ -d $NEWROOT/proc ] && exit 0 | |
20 | [ -z "$netroot" ] && exit 1 | |
21 | fi | |
7d7efa4a | 22 | |
8ecd9d01 | 23 | # Let's see if we have to wait for other interfaces |
3b403b32 | 24 | # Note: exit works just fine, since the last interface to be |
8ecd9d01 PS |
25 | # online'd should see all files |
26 | [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces | |
27 | for iface in $IFACES ; do | |
28 | [ -e /tmp/net.$iface.up ] || exit 1 | |
29 | done | |
30 | ||
3b403b32 | 31 | # Set or override primary interface |
a55d10c0 | 32 | netif=$1 |
8ecd9d01 | 33 | [ -e "/tmp/net.bootdev" ] && read netif < /tmp/net.bootdev |
7d7efa4a | 34 | |
957bc5c9 DY |
35 | if [ -e /tmp/net.$netif.manualup ]; then |
36 | rm -f /tmp/net.$netif.manualup | |
37 | fi | |
38 | ||
3b403b32 | 39 | # Figure out the handler for root=dhcp by recalling all netroot cmdline |
957bc5c9 DY |
40 | # handlers when this is not called from manually network bringing up. |
41 | if [ -z "$2" ]; then | |
42 | if [ "$netroot" = "dhcp" ] || [ "$netroot" = "dhcp6" ] ; then | |
43 | # Unset root so we can check later | |
44 | unset root | |
45 | ||
46 | # Load dhcp options | |
47 | [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts | |
48 | ||
49 | # If we have a specific bootdev with no dhcpoptions or empty root-path, | |
50 | # we die. Otherwise we just warn | |
51 | if [ -z "$new_root_path" ] ; then | |
52 | [ -n "$BOOTDEV" ] && die "No dhcp root-path received for '$BOOTDEV'" | |
53 | warn "No dhcp root-path received for '$BOOTDEV' trying other interfaces if available" | |
54 | exit 1 | |
55 | fi | |
8ecd9d01 | 56 | |
957bc5c9 DY |
57 | # Set netroot to new_root_path, so cmdline parsers don't call |
58 | netroot=$new_root_path | |
50e7ff76 | 59 | |
957bc5c9 DY |
60 | # FIXME! |
61 | for f in $hookdir/cmdline/90*.sh; do | |
62 | [ -f "$f" ] && . "$f"; | |
63 | done | |
64 | else | |
65 | rootok="1" | |
66 | fi | |
7d7efa4a | 67 | |
957bc5c9 DY |
68 | # Check: do we really know how to handle (net)root? |
69 | [ -z "$root" ] && die "No or empty root= argument" | |
70 | [ -z "$rootok" ] && die "Don't know how to handle 'root=$root'" | |
50e7ff76 | 71 | |
957bc5c9 DY |
72 | handler=${netroot%%:*} |
73 | handler=${handler%%4} | |
74 | handler=$(command -v ${handler}root) | |
75 | if [ -z "$netroot" ] || [ ! -e "$handler" ] ; then | |
76 | die "No handler for netroot type '$netroot'" | |
77 | fi | |
50e7ff76 PS |
78 | fi |
79 | ||
db815843 | 80 | # We're here, so we can assume that upping interfaces is now ok |
8ecd9d01 PS |
81 | [ -z "$IFACES" ] && IFACES="$netif" |
82 | for iface in $IFACES ; do | |
83 | . /tmp/net.$iface.up | |
84 | done | |
85 | ||
db815843 PS |
86 | [ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw |
87 | [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname | |
157a8ddf | 88 | [ -e /tmp/net.$netif.resolv.conf ] && cp -f /tmp/net.$netif.resolv.conf /etc/resolv.conf |
db815843 | 89 | |
98f25e96 PS |
90 | # Load interface options |
91 | [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override | |
92 | [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts | |
93 | ||
c8584872 PB |
94 | # Handle STP Timeout: arping the default router if root server is |
95 | # unknown or not local, or if not available the root server. | |
96 | # Note: This assumes that if no router is present the | |
98f25e96 PS |
97 | # root server is on the same subnet. |
98 | # | |
3b403b32 | 99 | # TODO There's some netroot variants that don't (yet) have their |
98f25e96 | 100 | # server-ip netroot |
c8584872 PB |
101 | |
102 | # Get router IP if set | |
103 | [ -n "$new_routers" ] && gw_ip=${new_routers%%,*} | |
104 | [ -n "$gw" ] && gw_ip=$gw | |
105 | # Get root server IP if set | |
106 | if [ -n "$netroot" ]; then | |
98f25e96 PS |
107 | dummy=${netroot#*:} |
108 | dummy=${dummy%%:*} | |
109 | case "$dummy" in | |
c8584872 | 110 | [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) netroot_ip=$dummy;; |
98f25e96 PS |
111 | esac |
112 | fi | |
c8584872 PB |
113 | # Default arping dest to router |
114 | dest="$gw_ip" | |
115 | # Change to arping root server if appropriate | |
116 | if [ -n "$netroot_ip" ]; then | |
117 | if [ -z "$dest" ]; then | |
118 | # no gateway so check root server | |
119 | dest="$netroot_ip" | |
120 | else | |
121 | r=$(ip route get "$netroot_ip") | |
122 | if ! strstr "$r" ' via ' ; then | |
123 | # local root server, so don't arping gateway | |
124 | dest="$netroot_ip" | |
125 | fi | |
126 | fi | |
127 | fi | |
98f25e96 | 128 | if [ -n "$dest" ] && ! arping -q -f -w 60 -I $netif $dest ; then |
d3be5a89 | 129 | dinfo "Resolving $dest via ARP on $netif failed" |
98f25e96 PS |
130 | fi |
131 | ||
957bc5c9 DY |
132 | # exit in case manually bring up network |
133 | [ -n "$2" ] && exit 0 | |
134 | ||
50e7ff76 | 135 | # Source netroot hooks before we start the handler |
a2a74022 | 136 | source_all $hookdir/netroot |
50e7ff76 | 137 | |
7d7efa4a DD |
138 | # Run the handler; don't store the root, it may change from device to device |
139 | # XXX other variables to export? | |
9cdfd735 | 140 | if $handler $netif $netroot $NEWROOT; then |
9a9777a1 | 141 | # Network rootfs mount successful |
8ecd9d01 | 142 | for iface in $IFACES ; do |
cc02093d HH |
143 | [ -f /tmp/dhclient.$iface.lease ] && cp /tmp/dhclient.$iface.lease /tmp/net.$iface.lease |
144 | [ -f /tmp/dhclient.$iface.dhcpopts ] && cp /tmp/dhclient.$iface.dhcpopts /tmp/net.$iface.dhcpopts | |
8ecd9d01 | 145 | done |
9f73fedf PS |
146 | |
147 | # Save used netif for later use | |
8ecd9d01 | 148 | [ ! -f /tmp/net.ifaces ] && echo $netif > /tmp/net.ifaces |
3b403b32 | 149 | else |
db815843 PS |
150 | warn "Mounting root via '$netif' failed" |
151 | # If we're trying with multiple interfaces, put that one down. | |
152 | # ip down/flush ensures that routeing info goes away as well | |
8ecd9d01 | 153 | if [ -z "$BOOTDEV" ] ; then |
cc02093d HH |
154 | ip link set $netif down |
155 | ip addr flush dev $netif | |
156 | echo "#empty" > /etc/resolv.conf | |
8ecd9d01 | 157 | fi |
7d7efa4a DD |
158 | fi |
159 | exit 0 |