summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/recipes-connectivity/dhcp/files/dhclient-systemd-wrapper26
1 files changed, 25 insertions, 1 deletions
diff --git a/meta/recipes-connectivity/dhcp/files/dhclient-systemd-wrapper b/meta/recipes-connectivity/dhcp/files/dhclient-systemd-wrapper
index 7d0e224a1d..87c60fa95f 100644
--- a/meta/recipes-connectivity/dhcp/files/dhclient-systemd-wrapper
+++ b/meta/recipes-connectivity/dhcp/files/dhclient-systemd-wrapper
@@ -1,5 +1,19 @@
1#!/bin/sh 1#!/bin/sh
2 2
3# Add an initial /var/lib/dhcp/dhclient.leases to make
4# sure the IP which dhclient try to renew is the same
5# with the IP which kernel got from dhcp server during
6# boot
7update_dhclient_leases()
8{
9 local addr=$1
10 local interface=$2
11 echo "lease {" >> /var/lib/dhcp/dhclient.leases
12 echo " interface \"${addr}\";" >> /var/lib/dhcp/dhclient.leases
13 echo " fixed-address ${interface:0:-3};" >> /var/lib/dhcp/dhclient.leases
14 echo "}" >> /var/lib/dhcp/dhclient.leases
15}
16
3# In case the interface is used for nfs, skip it. 17# In case the interface is used for nfs, skip it.
4nfsroot=0 18nfsroot=0
5interfaces="" 19interfaces=""
@@ -19,6 +33,7 @@ while read dev mtpt fstype rest; do
19done 33done
20exec 0<&9 9<&- 34exec 0<&9 9<&-
21 35
36
22if [ $nfsroot -eq 0 ]; then 37if [ $nfsroot -eq 0 ]; then
23 interfaces="$INTERFACES" 38 interfaces="$INTERFACES"
24else 39else
@@ -27,7 +42,16 @@ else
27 fi 42 fi
28 for i in $INTERFACES; do 43 for i in $INTERFACES; do
29 if test "x$i" = "x$nfs_iface"; then 44 if test "x$i" = "x$nfs_iface"; then
30 echo "dhclient skipping nfsroot interface $i" 45 interface_addr=`ip -4 address show $nfs_iface | grep 'inet '|sed 's/.*inet \(\S\+\).*/\1/'`
46 if [ "x$interface_addr" != "x" ] && cat /proc/cmdline | grep "ip=dhcp" > /dev/null ; then
47 # use to renew lease if needed
48 interfaces="$interfaces $i"
49 # use to update /var/lib/dhcp/dhclient.leases if needed
50 # when the ip got by kernel, we need use dhclient to renew the ip
51 update_dhclient_leases $nfs_iface $interface_addr
52 else
53 echo "dhclient skipping nfsroot interface $i"
54 fi
31 else 55 else
32 interfaces="$interfaces $i" 56 interfaces="$interfaces $i"
33 fi 57 fi