]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/40network/dhclient-script.sh
Move wait for if functions to net lib
[thirdparty/dracut.git] / modules.d / 40network / dhclient-script.sh
CommitLineData
3b403b32 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
7e9919b9
DD
4
5setup_interface() {
580bb541
PS
6 ip=$new_ip_address
7 mtu=$new_interface_mtu
8 mask=$new_subnet_mask
9 bcast=$new_broadcast_address
10 gw=${new_routers%%,*}
11 domain=$new_domain_name
e663608c 12 search=$(printf "$new_domain_search")
580bb541
PS
13 namesrv=$new_domain_name_servers
14 hostname=$new_host_name
15
16 [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override
17
d1dd6bb7
PS
18 # Taken from debian dhclient-script:
19 # The 576 MTU is only used for X.25 and dialup connections
20 # where the admin wants low latency. Such a low MTU can cause
21 # problems with UDP traffic, among other things. As such,
22 # disallow MTUs from 576 and below by default, so that broken
23 # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc).
24 if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then
c6c704fd
HH
25 if ! ip link set $netif mtu $mtu ; then
26 ip link set $netif down
27 ip link set $netif mtu $mtu
28 ip link set $netif up
29 wait_for_if_up $netif
30 fi
31 fi
7e9919b9 32
c6c704fd 33 ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif
db815843
PS
34
35 [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw
36
157a8ddf 37 [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
db815843 38 if [ -n "$namesrv" ] ; then
cc02093d 39 for s in $namesrv; do
3b403b32 40 echo nameserver $s
cc02093d 41 done
157a8ddf 42 fi >> /tmp/net.$netif.resolv.conf
db815843 43
da55af47
ID
44 # Note: hostname can be fqdn OR short hostname, so chop off any
45 # trailing domain name and explicity add any domain if set.
46 [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
7e9919b9
DD
47}
48
fb59f4c9 49PATH=/usr/sbin:/usr/bin:/sbin:/bin
580bb541 50
e54a8411 51export PS4="dhclient.$interface.$$ + "
7eb40c48 52exec >>/run/initramfs/loginit.pipe 2>>/run/initramfs/loginit.pipe
c9f1e3d1 53type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
efa5eb42 54type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh
580bb541 55
580bb541
PS
56# We already need a set netif here
57netif=$interface
58
00c0d5b8
PS
59# Huh? Interface configured?
60[ -f "/tmp/net.$netif.up" ] && exit 0
61
7e9919b9
DD
62case $reason in
63 PREINIT)
cc02093d
HH
64 echo "dhcp: PREINIT $netif up"
65 ip link set $netif up
66 wait_for_if_up $netif
67 ;;
7e9919b9 68 BOUND)
cc02093d 69 echo "dhcp: BOND setting $netif"
8b88dc7f
HH
70 unset layer2
71 if [ -f /sys/class/net/$netif/device/layer2 ]; then
72 read layer2 < /sys/class/net/$netif/device/layer2
cc02093d 73 fi
8b88dc7f
HH
74 if [ "$layer2" != "0" ]; then
75 if ! arping -q -D -c 2 -I $netif $new_ip_address ; then
76 warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
77 exit 1
78 fi
79 fi
80 unset layer2
3b403b32 81 setup_interface
cc02093d
HH
82 set | while read line; do
83 [ "${line#new_}" = "$line" ] && continue
3b403b32 84 echo "$line"
cc02093d 85 done >/tmp/dhclient.$netif.dhcpopts
957bc5c9 86
c6c704fd
HH
87 {
88 echo '. /lib/net-lib.sh'
89 echo "setup_net $netif"
90 echo "source_hook initqueue/online $netif"
91 [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif"
a17fc990 92 echo "> /tmp/setup_net_$netif.ok"
c6c704fd
HH
93 echo "rm -f $hookdir/initqueue/setup_net_$netif.sh"
94 } > $hookdir/initqueue/setup_net_$netif.sh
95
a17fc990 96 echo "[ -f /tmp/setup_net_$netif.ok ]" > $hookdir/initqueue/finished/dhclient-$netif.sh
c6c704fd 97 >/tmp/net.$netif.up
cc02093d 98 ;;
9ab14265 99 *) echo "dhcp: $reason";;
0ac9584d 100esac
7e9919b9 101
7e9919b9 102exit 0