]>
Commit | Line | Data |
---|---|---|
0ac9584d | 1 | #!/bin/sh |
db815843 PS |
2 | # |
3 | # We don't need to check for ip= errors here, that is handled by the | |
4 | # cmdline parser script | |
5 | # | |
957bc5c9 DY |
6 | # without $2 means this is for real netroot case |
7 | # or it is for manually bring up network ie. for kdump scp vmcore | |
fb59f4c9 | 8 | PATH=/usr/sbin:/usr/bin:/sbin:/bin |
db815843 | 9 | |
9a52c3fd HH |
10 | type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh |
11 | type ip_to_var > /dev/null 2>&1 || . /lib/net-lib.sh | |
957bc5c9 DY |
12 | |
13 | # Huh? No $1? | |
14 | [ -z "$1" ] && exit 1 | |
15 | ||
16 | # $netif reads easier than $1 | |
17 | netif=$1 | |
18 | ||
24a78b26 | 19 | # loopback is always handled the same way |
9a52c3fd | 20 | if [ "$netif" = "lo" ]; then |
24a78b26 HH |
21 | ip link set lo up |
22 | ip addr add 127.0.0.1/8 dev lo | |
23 | exit 0 | |
d61a423f | 24 | fi |
7e9919b9 | 25 | |
4026cd3b AK |
26 | do_dhcp_parallel() { |
27 | # dhclient-script will mark the netif up and generate the online | |
28 | # event for nfsroot | |
29 | # XXX add -V vendor class and option parsing per kernel | |
30 | ||
8c0fcdd9 | 31 | [ -e "/tmp/dhclient.$netif.pid" ] && return 0 |
4026cd3b | 32 | |
8c0fcdd9 | 33 | if ! iface_has_carrier "$netif"; then |
4026cd3b AK |
34 | warn "No carrier detected on interface $netif" |
35 | return 1 | |
36 | fi | |
37 | ||
8c0fcdd9 HH |
38 | bootintf=$(readlink "$IFNETFILE") |
39 | if [ -n "$bootintf" ] && [ -e "/tmp/dhclient.${bootintf}.lease" ]; then | |
4026cd3b | 40 | info "DHCP already succeeded for $bootintf, exiting for $netif" |
9a52c3fd | 41 | return 1 |
4026cd3b AK |
42 | fi |
43 | ||
44 | if [ ! -e /run/NetworkManager/conf.d/10-dracut-dhclient.conf ]; then | |
45 | mkdir -p /run/NetworkManager/conf.d | |
46 | echo '[main]' > /run/NetworkManager/conf.d/10-dracut-dhclient.conf | |
9a52c3fd | 47 | echo 'dhcp=dhclient' >> /run/NetworkManager/conf.d/10-dracut-dhclient.conf |
4026cd3b AK |
48 | fi |
49 | ||
50 | chmod +x /sbin/dhcp-multi.sh | |
51 | /sbin/dhcp-multi.sh "$netif" "$DO_VLAN" "$@" & | |
52 | return 0 | |
53 | } | |
54 | ||
db815843 | 55 | # Run dhclient |
7e9919b9 | 56 | do_dhcp() { |
fb59f4c9 | 57 | # dhclient-script will mark the netif up and generate the online |
7e9919b9 DD |
58 | # event for nfsroot |
59 | # XXX add -V vendor class and option parsing per kernel | |
c84618d7 | 60 | |
8c0fcdd9 HH |
61 | local _COUNT |
62 | local _timeout | |
63 | local _DHCPRETRY | |
64 | ||
65 | _COUNT=0 | |
66 | _timeout=$(getarg rd.net.timeout.dhcp=) | |
67 | _DHCPRETRY=$(getargnum 1 1 1000000000 rd.net.dhcp.retry=) | |
2448fbf1 | 68 | |
8c0fcdd9 | 69 | [ -e "/tmp/dhclient.${netif}.pid" ] && return 0 |
c84618d7 | 70 | |
8c0fcdd9 | 71 | if ! iface_has_carrier "$netif"; then |
2448fbf1 | 72 | warn "No carrier detected on interface $netif" |
271cd19d HH |
73 | return 1 |
74 | fi | |
2448fbf1 | 75 | |
23654c50 AAF |
76 | if [ -n "$_timeout" ]; then |
77 | if ! (dhclient --help 2>&1 | grep -q -F -- '--timeout' 2> /dev/null); then | |
78 | warn "rd.net.timeout.dhcp has no effect because dhclient does not implement the --timeout option" | |
79 | unset _timeout | |
80 | fi | |
81 | fi | |
82 | ||
0454dc24 LR |
83 | if [ ! -e /run/NetworkManager/conf.d/10-dracut-dhclient.conf ]; then |
84 | mkdir -p /run/NetworkManager/conf.d | |
85 | echo '[main]' > /run/NetworkManager/conf.d/10-dracut-dhclient.conf | |
9a52c3fd | 86 | echo 'dhcp=dhclient' >> /run/NetworkManager/conf.d/10-dracut-dhclient.conf |
0454dc24 LR |
87 | fi |
88 | ||
8c0fcdd9 | 89 | while [ "$_COUNT" -lt "$_DHCPRETRY" ]; do |
2448fbf1 HH |
90 | info "Starting dhcp for interface $netif" |
91 | dhclient "$@" \ | |
8c0fcdd9 | 92 | ${_timeout:+--timeout "$_timeout"} \ |
9a52c3fd HH |
93 | -q \ |
94 | -1 \ | |
95 | -cf /etc/dhclient.conf \ | |
8c0fcdd9 HH |
96 | -pf "/tmp/dhclient.${netif}.pid" \ |
97 | -lf "/tmp/dhclient.${netif}.lease" \ | |
98 | "$netif" \ | |
2448fbf1 | 99 | && return 0 |
75d758e8 | 100 | _COUNT=$((_COUNT + 1)) |
8c0fcdd9 | 101 | [ "$_COUNT" -lt "$_DHCPRETRY" ] && sleep 1 |
2448fbf1 HH |
102 | done |
103 | warn "dhcp for interface $netif failed" | |
d0de58f2 JL |
104 | # nuke those files since we failed; we might retry dhcp again if it's e.g. |
105 | # `ip=dhcp,dhcp6` and we check for the PID file at the top | |
909961d0 | 106 | rm -f /tmp/dhclient."$netif".pid /tmp/dhclient."$netif".lease |
2448fbf1 | 107 | return 1 |
c98bcec8 HH |
108 | } |
109 | ||
110 | load_ipv6() { | |
28f3f537 | 111 | [ -d /proc/sys/net/ipv6 ] && return |
c98bcec8 HH |
112 | modprobe ipv6 |
113 | i=0 | |
114 | while [ ! -d /proc/sys/net/ipv6 ]; do | |
75d758e8 | 115 | i=$((i + 1)) |
cc02093d HH |
116 | [ $i -gt 10 ] && break |
117 | sleep 0.1 | |
c98bcec8 HH |
118 | done |
119 | } | |
120 | ||
121 | do_ipv6auto() { | |
67354eeb | 122 | local ret |
c98bcec8 | 123 | load_ipv6 |
8c0fcdd9 HH |
124 | echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/forwarding |
125 | echo 1 > /proc/sys/net/ipv6/conf/"${netif}"/accept_ra | |
126 | echo 1 > /proc/sys/net/ipv6/conf/"${netif}"/accept_redirects | |
127 | linkup "$netif" | |
128 | wait_for_ipv6_auto "$netif" | |
67354eeb | 129 | ret=$? |
c98bcec8 | 130 | |
8c0fcdd9 | 131 | [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > "/tmp/net.${netif}.hostname" |
8bf25df6 | 132 | |
8c0fcdd9 | 133 | return "$ret" |
db815843 PS |
134 | } |
135 | ||
b12f8188 JJ |
136 | do_ipv6link() { |
137 | local ret | |
138 | load_ipv6 | |
8c0fcdd9 HH |
139 | echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/forwarding |
140 | echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/accept_ra | |
141 | echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/accept_redirects | |
142 | linkup "$netif" | |
b12f8188 | 143 | |
8c0fcdd9 | 144 | [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > "/tmp/net.${netif}.hostname" |
b12f8188 | 145 | |
8c0fcdd9 | 146 | return "$ret" |
b12f8188 JJ |
147 | } |
148 | ||
db815843 PS |
149 | # Handle static ip configuration |
150 | do_static() { | |
8c0fcdd9 | 151 | strglobin "$ip" '*:*:*' && load_ipv6 |
c98bcec8 | 152 | |
c574c3f5 | 153 | if ! iface_has_carrier "$netif"; then |
df95b100 HH |
154 | warn "No carrier detected on interface $netif" |
155 | return 1 | |
156 | elif ! linkup "$netif"; then | |
b519ae70 | 157 | warn "Could not bring interface $netif up!" |
5193198d HH |
158 | return 1 |
159 | fi | |
160 | ||
9a52c3fd | 161 | ip route get "$ip" 2> /dev/null | { |
8c0fcdd9 | 162 | read -r a rest |
27a5aecf HH |
163 | if [ "$a" = "local" ]; then |
164 | warn "Not assigning $ip to interface $netif, cause it is already assigned!" | |
165 | return 1 | |
166 | fi | |
167 | return 0 | |
168 | } || return 1 | |
169 | ||
8c0fcdd9 HH |
170 | [ -n "$macaddr" ] && ip link set address "$macaddr" dev "$netif" |
171 | [ -n "$mtu" ] && ip link set mtu "$mtu" dev "$netif" | |
172 | if strglobin "$ip" '*:*:*'; then | |
50b08e7b | 173 | # note no ip addr flush for ipv6 |
8c0fcdd9 HH |
174 | ip addr add "$ip/$mask" ${srv:+peer "$srv"} dev "$netif" |
175 | echo 0 > /proc/sys/net/ipv6/conf/"${netif}"/forwarding | |
176 | echo 1 > /proc/sys/net/ipv6/conf/"${netif}"/accept_ra | |
177 | echo 1 > /proc/sys/net/ipv6/conf/"${netif}"/accept_redirects | |
178 | wait_for_ipv6_dad "$netif" | |
50b08e7b | 179 | else |
5abd692f | 180 | if [ -z "$srv" ]; then |
9a52c3fd | 181 | if command -v arping2 > /dev/null; then |
8c0fcdd9 | 182 | if arping2 -q -C 1 -c 2 -I "$netif" -0 "$ip"; then |
5abd692f HH |
183 | warn "Duplicate address detected for $ip for interface $netif." |
184 | return 1 | |
185 | fi | |
186 | else | |
8c0fcdd9 | 187 | if ! arping -f -q -D -c 2 -I "$netif" "$ip"; then |
5abd692f HH |
188 | warn "Duplicate address detected for $ip for interface $netif." |
189 | return 1 | |
190 | fi | |
9853791d | 191 | fi |
9ab5ddf1 | 192 | fi |
8c0fcdd9 HH |
193 | ip addr flush dev "$netif" |
194 | ip addr add "$ip/$mask" ${srv:+peer "$srv"} brd + dev "$netif" | |
50b08e7b | 195 | fi |
db815843 | 196 | |
8c0fcdd9 HH |
197 | [ -n "$gw" ] && echo "ip route replace default via '$gw' dev '$netif'" > "/tmp/net.$netif.gw" |
198 | [ -n "$hostname" ] && echo "echo '$hostname' > /proc/sys/kernel/hostname" > "/tmp/net.$netif.hostname" | |
8bf25df6 WC |
199 | |
200 | return 0 | |
957bc5c9 | 201 | } |
580bb541 | 202 | |
24a78b26 HH |
203 | get_vid() { |
204 | case "$1" in | |
9a52c3fd | 205 | vlan*) |
8c0fcdd9 | 206 | echo "${1#vlan}" |
9a52c3fd HH |
207 | ;; |
208 | *.*) | |
8c0fcdd9 | 209 | echo "${1##*.}" |
9a52c3fd | 210 | ;; |
24a78b26 HH |
211 | esac |
212 | } | |
213 | ||
214 | # check, if we need VLAN's for this interface | |
8c0fcdd9 | 215 | if [ -z "$DO_VLAN_PHY" ] && [ -e "/tmp/vlan.${netif}.phy" ]; then |
e7838a83 | 216 | unset DO_VLAN |
24a78b26 HH |
217 | NO_AUTO_DHCP=yes DO_VLAN_PHY=yes ifup "$netif" |
218 | modprobe -b -q 8021q | |
219 | ||
8c0fcdd9 | 220 | for i in /tmp/vlan.*."${netif}"; do |
24a78b26 | 221 | [ -e "$i" ] || continue |
0cf826a1 HH |
222 | unset vlanname |
223 | unset phydevice | |
8c0fcdd9 | 224 | # shellcheck disable=SC1090 |
0cf826a1 | 225 | . "$i" |
24a78b26 HH |
226 | if [ -n "$vlanname" ]; then |
227 | linkup "$phydevice" | |
8c0fcdd9 | 228 | ip link add dev "$vlanname" link "$phydevice" type vlan id "$(get_vid "$vlanname")" |
24a78b26 HH |
229 | ifup "$vlanname" |
230 | fi | |
231 | done | |
580bb541 PS |
232 | exit 0 |
233 | fi | |
234 | ||
e7838a83 | 235 | # Check, if interface is VLAN interface |
8c0fcdd9 HH |
236 | if ! [ -e "/tmp/vlan.${netif}.phy" ]; then |
237 | for i in "/tmp/vlan.${netif}".*; do | |
e7838a83 HH |
238 | [ -e "$i" ] || continue |
239 | export DO_VLAN=yes | |
240 | break | |
241 | done | |
242 | fi | |
243 | ||
24a78b26 HH |
244 | # bridge this interface? |
245 | if [ -z "$NO_BRIDGE_MASTER" ]; then | |
246 | for i in /tmp/bridge.*.info; do | |
247 | [ -e "$i" ] || continue | |
248 | unset bridgeslaves | |
249 | unset bridgename | |
8c0fcdd9 | 250 | # shellcheck disable=SC1090 |
24a78b26 | 251 | . "$i" |
9a52c3fd | 252 | for ethname in $bridgeslaves; do |
24a78b26 HH |
253 | [ "$netif" != "$ethname" ] && continue |
254 | ||
8c0fcdd9 HH |
255 | NO_BRIDGE_MASTER=yes NO_AUTO_DHCP=yes ifup "$ethname" |
256 | linkup "$ethname" | |
257 | if [ ! -e "/tmp/bridge.$bridgename.up" ]; then | |
258 | ip link add name "$bridgename" type bridge | |
259 | echo 0 > "/sys/devices/virtual/net/$bridgename/bridge/forward_delay" | |
260 | : > "/tmp/bridge.$bridgename.up" | |
96fb9c8d | 261 | fi |
8c0fcdd9 HH |
262 | ip link set dev "$ethname" master "$bridgename" |
263 | ifup "$bridgename" | |
24a78b26 | 264 | exit 0 |
96fb9c8d | 265 | done |
24a78b26 HH |
266 | done |
267 | fi | |
96fb9c8d | 268 | |
24a78b26 HH |
269 | # enslave this interface to bond? |
270 | if [ -z "$NO_BOND_MASTER" ]; then | |
271 | for i in /tmp/bond.*.info; do | |
272 | [ -e "$i" ] || continue | |
273 | unset bondslaves | |
274 | unset bondname | |
8c0fcdd9 | 275 | # shellcheck disable=SC1090 |
24a78b26 | 276 | . "$i" |
8c0fcdd9 | 277 | for testslave in $bondslaves; do |
909961d0 | 278 | [ "$netif" != "$testslave" ] && continue |
96fb9c8d | 279 | |
24a78b26 | 280 | # already setup |
8c0fcdd9 | 281 | [ -e "/tmp/bond.$bondname.up" ] && exit 0 |
24a78b26 HH |
282 | |
283 | # wait for all slaves to show up | |
9a52c3fd | 284 | for slave in $bondslaves; do |
24a78b26 | 285 | # try to create the slave (maybe vlan or bridge) |
8c0fcdd9 | 286 | NO_BOND_MASTER=yes NO_AUTO_DHCP=yes ifup "$slave" |
24a78b26 | 287 | |
8c0fcdd9 | 288 | if ! ip link show dev "$slave" > /dev/null 2>&1; then |
24a78b26 HH |
289 | # wait for the last slave to show up |
290 | exit 0 | |
291 | fi | |
292 | done | |
293 | ||
294 | modprobe -q -b bonding | |
9a52c3fd | 295 | echo "+$bondname" > /sys/class/net/bonding_masters 2> /dev/null |
8c0fcdd9 | 296 | ip link set "$bondname" down |
24a78b26 HH |
297 | |
298 | # Stolen from ifup-eth | |
299 | # add the bits to setup driver parameters here | |
9a52c3fd HH |
300 | for arg in $bondoptions; do |
301 | key=${arg%%=*} | |
302 | value=${arg##*=} | |
24a78b26 HH |
303 | # %{value:0:1} is replaced with non-bash specific construct |
304 | if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then | |
9a52c3fd HH |
305 | OLDIFS=$IFS |
306 | IFS=',' | |
24a78b26 | 307 | for arp_ip in $value; do |
8c0fcdd9 | 308 | echo "+$arp_ip" > "/sys/class/net/${bondname}/bonding/$key" |
24a78b26 | 309 | done |
9a52c3fd | 310 | IFS=$OLDIFS |
24a78b26 | 311 | else |
8c0fcdd9 | 312 | echo "$value" > "/sys/class/net/${bondname}/bonding/$key" |
24a78b26 HH |
313 | fi |
314 | done | |
315 | ||
8c0fcdd9 | 316 | linkup "$bondname" |
24a78b26 | 317 | |
9a52c3fd | 318 | for slave in $bondslaves; do |
8c0fcdd9 HH |
319 | cat "/sys/class/net/$slave/address" > "/tmp/net.${bondname}.${slave}.hwaddr" |
320 | ip link set "$slave" down | |
321 | echo "+$slave" > "/sys/class/net/$bondname/bonding/slaves" | |
322 | linkup "$slave" | |
24a78b26 HH |
323 | done |
324 | ||
292548be | 325 | # Set mtu on bond master |
8c0fcdd9 | 326 | [ -n "$bondmtu" ] && ip link set mtu "$bondmtu" dev "$bondname" |
292548be | 327 | |
24a78b26 | 328 | # add the bits to setup the needed post enslavement parameters |
9a52c3fd HH |
329 | for arg in $bondoptions; do |
330 | key=${arg%%=*} | |
331 | value=${arg##*=} | |
24a78b26 | 332 | if [ "${key}" = "primary" ]; then |
8c0fcdd9 | 333 | echo "$value" > "/sys/class/net/${bondname}/bonding/$key" |
24a78b26 HH |
334 | fi |
335 | done | |
336 | ||
8c0fcdd9 | 337 | : > "/tmp/bond.$bondname.up" |
24a78b26 | 338 | |
8c0fcdd9 | 339 | NO_BOND_MASTER=yes ifup "$bondname" |
24a78b26 | 340 | exit $? |
96fb9c8d | 341 | done |
24a78b26 | 342 | done |
96fb9c8d VB |
343 | fi |
344 | ||
24a78b26 HH |
345 | if [ -z "$NO_TEAM_MASTER" ]; then |
346 | for i in /tmp/team.*.info; do | |
347 | [ -e "$i" ] || continue | |
348 | unset teammaster | |
349 | unset teamslaves | |
8c0fcdd9 | 350 | # shellcheck disable=SC1090 |
24a78b26 | 351 | . "$i" |
8c0fcdd9 HH |
352 | for testslave in $teamslaves; do |
353 | [ "$netif" != "$testslave" ] && continue | |
96fb9c8d | 354 | |
8c0fcdd9 | 355 | [ -e "/tmp/team.$teammaster.up" ] && exit 0 |
7e9919b9 | 356 | |
24a78b26 | 357 | # wait for all slaves to show up |
9a52c3fd | 358 | for slave in $teamslaves; do |
24a78b26 | 359 | # try to create the slave (maybe vlan or bridge) |
8c0fcdd9 | 360 | NO_TEAM_MASTER=yes NO_AUTO_DHCP=yes ifup "$slave" |
24a78b26 | 361 | |
8c0fcdd9 | 362 | if ! ip link show dev "$slave" > /dev/null 2>&1; then |
24a78b26 HH |
363 | # wait for the last slave to show up |
364 | exit 0 | |
365 | fi | |
366 | done | |
367 | ||
8c0fcdd9 | 368 | if [ ! -e "/tmp/team.$teammaster.up" ]; then |
24a78b26 HH |
369 | # We shall only bring up those _can_ come up |
370 | # in case of some slave is gone in active-backup mode | |
371 | working_slaves="" | |
9a52c3fd | 372 | for slave in $teamslaves; do |
8c0fcdd9 | 373 | teamdctl "${teammaster}" port present "${slave}" 2> /dev/null \ |
041e49ee | 374 | && continue |
8c0fcdd9 HH |
375 | ip link set dev "$slave" up 2> /dev/null |
376 | if wait_for_if_up "$slave"; then | |
bcabe0fe | 377 | working_slaves="$working_slaves$slave " |
24a78b26 HH |
378 | fi |
379 | done | |
380 | # Do not add slaves now | |
8c0fcdd9 | 381 | teamd -d -U -n -N -t "$teammaster" -f "/etc/teamd/${teammaster}.conf" |
24a78b26 HH |
382 | for slave in $working_slaves; do |
383 | # team requires the slaves to be down before joining team | |
8c0fcdd9 | 384 | ip link set dev "$slave" down |
041e49ee HH |
385 | ( |
386 | unset TEAM_PORT_CONFIG | |
28f37724 | 387 | read -r _hwaddr < "/sys/class/net/$slave/address" |
041e49ee HH |
388 | _subchannels=$(iface_get_subchannels "$slave") |
389 | if [ -n "$_hwaddr" ] && [ -e "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf" ]; then | |
8c0fcdd9 | 390 | # shellcheck disable=SC1090 |
041e49ee HH |
391 | . "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf" |
392 | elif [ -n "$_subchannels" ] && [ -e "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf" ]; then | |
8c0fcdd9 | 393 | # shellcheck disable=SC1090 |
041e49ee HH |
394 | . "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf" |
395 | elif [ -e "/etc/sysconfig/network-scripts/ifcfg-${slave}" ]; then | |
8c0fcdd9 | 396 | # shellcheck disable=SC1090 |
041e49ee HH |
397 | . "/etc/sysconfig/network-scripts/ifcfg-${slave}" |
398 | fi | |
399 | ||
400 | if [ -n "${TEAM_PORT_CONFIG}" ]; then | |
8c0fcdd9 | 401 | /usr/bin/teamdctl "${teammaster}" port config update "${slave}" "${TEAM_PORT_CONFIG}" |
041e49ee HH |
402 | fi |
403 | ) | |
8c0fcdd9 | 404 | teamdctl "$teammaster" port add "$slave" |
24a78b26 HH |
405 | done |
406 | ||
8c0fcdd9 | 407 | ip link set dev "$teammaster" up |
24a78b26 | 408 | |
8c0fcdd9 HH |
409 | : > "/tmp/team.$teammaster.up" |
410 | NO_TEAM_MASTER=yes ifup "$teammaster" | |
24a78b26 | 411 | exit $? |
21928b97 | 412 | fi |
21928b97 | 413 | done |
24a78b26 | 414 | done |
beb097d9 WT |
415 | fi |
416 | ||
24a78b26 | 417 | # all synthetic interfaces done.. now check if the interface is available |
8c0fcdd9 | 418 | if ! ip link show dev "$netif" > /dev/null 2>&1; then |
24a78b26 HH |
419 | exit 1 |
420 | fi | |
8eb81d48 | 421 | |
24a78b26 | 422 | # disable manual ifup while netroot is set for simplifying our logic |
ddf63231 | 423 | # in netroot case we prefer netroot to bringup $netif automatically |
24a78b26 HH |
424 | [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2" |
425 | ||
426 | if [ -n "$manualup" ]; then | |
8c0fcdd9 HH |
427 | : > "/tmp/net.$netif.manualup" |
428 | rm -f "/tmp/net.${netif}.did-setup" | |
24a78b26 | 429 | else |
8c0fcdd9 | 430 | [ -e "/tmp/net.${netif}.did-setup" ] && exit 0 |
9a52c3fd | 431 | [ -z "$DO_VLAN" ] \ |
8c0fcdd9 HH |
432 | && [ -e "/sys/class/net/$netif/address" ] \ |
433 | && [ -e "/tmp/net.$(cat "/sys/class/net/$netif/address").did-setup" ] && exit 0 | |
8eb81d48 AW |
434 | fi |
435 | ||
580bb541 PS |
436 | # Specific configuration, spin through the kernel command line |
437 | # looking for ip= lines | |
3e6d2b31 | 438 | for p in $(getargs ip=); do |
8c0fcdd9 | 439 | ip_to_var "$p" |
38ba0d7a HH |
440 | # skip ibft |
441 | [ "$autoconf" = "ibft" ] && continue | |
990e945f | 442 | |
c5f8b69a | 443 | case "$dev" in |
9a52c3fd | 444 | ??:??:??:??:??:??) # MAC address |
8c0fcdd9 | 445 | _dev=$(iface_for_mac "$dev") |
c5f8b69a HH |
446 | [ -n "$_dev" ] && dev="$_dev" |
447 | ;; | |
9a52c3fd | 448 | ??-??-??-??-??-??) # MAC address in BOOTIF form |
8c0fcdd9 | 449 | _dev=$(iface_for_mac "$(fix_bootif "$dev")") |
c5f8b69a HH |
450 | [ -n "$_dev" ] && dev="$_dev" |
451 | ;; | |
452 | esac | |
453 | ||
580bb541 | 454 | # If this option isn't directed at our interface, skip it |
f6e3b59e | 455 | if [ -n "$dev" ]; then |
79389352 PV |
456 | if [ "$dev" != "$netif" ]; then |
457 | [ ! -e "/sys/class/net/$dev" ] \ | |
458 | && warn "Network interface '$dev' does not exist!" | |
459 | continue | |
460 | fi | |
f6e3b59e HH |
461 | else |
462 | iface_is_enslaved "$netif" && continue | |
463 | fi | |
580bb541 | 464 | |
73fb5e76 LN |
465 | # Store config for later use |
466 | for i in ip srv gw mask hostname macaddr mtu dns1 dns2; do | |
467 | eval '[ "$'$i'" ] && echo '$i'="$'$i'"' | |
8c0fcdd9 | 468 | done > "/tmp/net.$netif.override" |
73fb5e76 | 469 | |
93342718 HH |
470 | for autoopt in $(str_replace "$autoconf" "," " "); do |
471 | case $autoopt in | |
9a52c3fd HH |
472 | dhcp | on | any) |
473 | do_dhcp -4 | |
474 | ;; | |
4026cd3b AK |
475 | single-dhcp) |
476 | do_dhcp_parallel -4 | |
9a52c3fd HH |
477 | exit 0 |
478 | ;; | |
93342718 HH |
479 | dhcp6) |
480 | load_ipv6 | |
9a52c3fd HH |
481 | do_dhcp -6 |
482 | ;; | |
93342718 | 483 | auto6) |
9a52c3fd HH |
484 | do_ipv6auto |
485 | ;; | |
67354eeb | 486 | either6) |
9a52c3fd HH |
487 | do_ipv6auto || do_dhcp -6 |
488 | ;; | |
b12f8188 | 489 | link6) |
9a52c3fd HH |
490 | do_ipv6link |
491 | ;; | |
93342718 | 492 | *) |
9a52c3fd HH |
493 | do_static |
494 | ;; | |
93342718 HH |
495 | esac |
496 | done | |
744c6593 | 497 | ret=$? |
c6c704fd | 498 | |
cf376023 XP |
499 | # setup nameserver |
500 | for s in "$dns1" "$dns2" $(getargs nameserver); do | |
501 | [ -n "$s" ] || continue | |
8c0fcdd9 | 502 | echo "nameserver $s" >> "/tmp/net.$netif.resolv.conf" |
cf376023 XP |
503 | done |
504 | ||
df95b100 | 505 | if [ $ret -eq 0 ]; then |
8c0fcdd9 | 506 | : > "/tmp/net.${netif}.up" |
43a85a73 | 507 | |
8c0fcdd9 HH |
508 | if [ -z "$DO_VLAN" ] && [ -e "/sys/class/net/${netif}/address" ]; then |
509 | : > "/tmp/net.$(cat "/sys/class/net/${netif}/address").up" | |
df95b100 | 510 | fi |
26fbe97b | 511 | |
4985aa8c JL |
512 | # and finally, finish interface set up if there isn't already a script |
513 | # to do so (which is the case in the dhcp path) | |
8c0fcdd9 HH |
514 | if [ ! -e "$hookdir/initqueue/setup_net_$netif.sh" ]; then |
515 | setup_net "$netif" | |
516 | source_hook initqueue/online "$netif" | |
4985aa8c | 517 | if [ -z "$manualup" ]; then |
8c0fcdd9 | 518 | /sbin/netroot "$netif" |
4985aa8c JL |
519 | fi |
520 | fi | |
8c6ab479 | 521 | |
df95b100 HH |
522 | exit $ret |
523 | fi | |
db815843 | 524 | done |
debf483d HH |
525 | |
526 | # no ip option directed at our interface? | |
8c0fcdd9 | 527 | if [ -z "$NO_AUTO_DHCP" ] && [ ! -e "/tmp/net.${netif}.up" ]; then |
3f5bf54f | 528 | ret=1 |
6cfdb5aa | 529 | if [ -e /tmp/net.bootdev ]; then |
28f37724 | 530 | read -r BOOTDEV < /tmp/net.bootdev |
8c0fcdd9 | 531 | if [ "$netif" = "$BOOTDEV" ] || [ "$BOOTDEV" = "$(cat "/sys/class/net/${netif}/address")" ]; then |
6cfdb5aa | 532 | do_dhcp |
3f5bf54f | 533 | ret=$? |
6cfdb5aa HH |
534 | fi |
535 | else | |
3f5bf54f TB |
536 | # No ip lines, no bootdev -> default to dhcp |
537 | ip=$(getarg ip) | |
538 | ||
9a52c3fd | 539 | if getargs 'ip=dhcp6' > /dev/null || [ -z "$ip" -a "$netroot" = "dhcp6" ]; then |
6cfdb5aa HH |
540 | load_ipv6 |
541 | do_dhcp -6 | |
3f5bf54f | 542 | ret=$? |
6cfdb5aa | 543 | fi |
9a52c3fd | 544 | if getargs 'ip=dhcp' > /dev/null || [ -z "$ip" -a "$netroot" != "dhcp6" ]; then |
6cfdb5aa | 545 | do_dhcp -4 |
3f5bf54f | 546 | ret=$? |
6cfdb5aa | 547 | fi |
2c7f7a33 | 548 | fi |
3f5bf54f TB |
549 | |
550 | for s in $(getargs nameserver); do | |
551 | [ -n "$s" ] || continue | |
8c0fcdd9 | 552 | echo "nameserver $s" >> "/tmp/net.$netif.resolv.conf" |
3f5bf54f TB |
553 | done |
554 | ||
8c0fcdd9 HH |
555 | if [ "$ret" -eq 0 ] && [ -n "$(ls "/tmp/leaseinfo.${netif}"* 2> /dev/null)" ]; then |
556 | : > "/tmp/net.${netif}.did-setup" | |
557 | if [ -e "/sys/class/net/${netif}/address" ]; then | |
558 | : > "/tmp/net.$(cat "/sys/class/net/${netif}/address").did-setup" | |
9a52c3fd | 559 | fi |
3f5bf54f | 560 | fi |
debf483d HH |
561 | fi |
562 | ||
7e9919b9 | 563 | exit 0 |