Skip to contentSkip to conversation

busybox: udhcpc create leases file

PATCH Superseded Matt Weber 2 participants 3 messages May 26, 2015 – Jul 14, 2015

lore
Share & tools
lore

Matt Weber

author
#0 lore raw

PATCH v2 1/1 busybox: udhcpc create leases file

Capture the lease information for use by applications after a lease is aquired.

---

Changes v1 -> v2
- Changed from appending to keeping just the last lease
- Adjusted format to pure shell variables instead of dhclient format.
- Moved location to /var/run instead of /var/lib/misc

---
 package/busybox/udhcpc.script | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
package/busybox/udhcpc.script +21 -0
index 50c52e6..e913111 100755
@@ -61,6 +61,27 @@ case "$1" in
 			echo adding dns $i
 			echo "nameserver $i # $interface" >> $RESOLV_CONF
 		done
+
+		# Record last lease
+		{
+		    echo "IFACE=$interface"
+		    echo "IP=$ip"
+		    [ -n "$subnet" ]    && echo "MASK=$subnet"
+		    [ -n "$router" ]    && echo "ROUTER=$router"
+		    [ -n "$dns" ]       && echo "DNS=\"$dns\""
+		    [ -n "$domain" ]    && echo "DOMAIN=$domain"
+		    [ -n "$boot_file" ] && echo "BOOT_FILE=$boot_file"
+		    echo "DHCP_LEASE_TIME=$lease"
+		    echo "DHCP_MSG_TYPE=$dhcptype"
+		    echo "DHCP_SERVER_ID=${siaddr:-$serverid}"
+		    d=$(expr "$(date "+%Y.%m.%d-%H:%M:%S")" : "\(.*\):")
+		    t=$(date -d "$d:$(expr $lease / 2)" "+%w %Y/%m/%d %H:%M:%S" 2>/dev/null)
+		    [ -n "$t" ] && echo "DHCP_RENEW=\"$t\""
+		    t=$(date -d "$d:$(expr 7 '*' $lease / 8)" "+%w %Y/%m/%d %H:%M:%S" 2>/dev/null)
+		    [ -n "$t" ] && echo "DHCP_REBIND=\"$t\""
+		    t=$(date -d "$d:$lease" "+%w %Y/%m/%d %H:%M:%S" 2>/dev/null)
+		    [ -n "$t" ] && echo "DHCP_EXPIRE=\"$t\""
+		} > /var/run/udhcpc.$interface.leases
 		;;
 esac
 
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/1 busybox: udhcpc create leases file

All,

Quoted 48 lines · Matt Weber

Capture the lease information for use by applications after a lease is aquired.

---

Changes v1 -> v2
- Changed from appending to keeping just the last lease
- Adjusted format to pure shell variables instead of dhclient format.
- Moved location to /var/run instead of /var/lib/misc

---
 package/busybox/udhcpc.script | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
package/busybox/udhcpc.script +21 -0
index 50c52e6..e913111 100755
@@ -61,6 +61,27 @@ case "$1" in
                        echo adding dns $i
                        echo "nameserver $i # $interface" >> $RESOLV_CONF
                done
+
+               # Record last lease
+               {
+                   echo "IFACE=$interface"
+                   echo "IP=$ip"
+                   [ -n "$subnet" ]    && echo "MASK=$subnet"
+                   [ -n "$router" ]    && echo "ROUTER=$router"
+                   [ -n "$dns" ]       && echo "DNS=\"$dns\""
+                   [ -n "$domain" ]    && echo "DOMAIN=$domain"
+                   [ -n "$boot_file" ] && echo "BOOT_FILE=$boot_file"
+                   echo "DHCP_LEASE_TIME=$lease"
+                   echo "DHCP_MSG_TYPE=$dhcptype"
+                   echo "DHCP_SERVER_ID=${siaddr:-$serverid}"
+                   d=$(expr "$(date "+%Y.%m.%d-%H:%M:%S")" : "\(.*\):")
+                   t=$(date -d "$d:$(expr $lease / 2)" "+%w %Y/%m/%d
 %H:%M:%S" 2>/dev/null)
+                   [ -n "$t" ] && echo "DHCP_RENEW=\"$t\""
+                   t=$(date -d "$d:$(expr 7 '*' $lease / 8)" "+%w
 %Y/%m/%d %H:%M:%S" 2>/dev/null)
+                   [ -n "$t" ] && echo "DHCP_REBIND=\"$t\""
+                   t=$(date -d "$d:$lease" "+%w %Y/%m/%d %H:%M:%S"
 2>/dev/null)
+                   [ -n "$t" ] && echo "DHCP_EXPIRE=\"$t\""
+               } > /var/run/udhcpc.$interface.leases
                ;;
Quoted 6 lines

esac

--
1.9.1

Since the hook scripts where added for the udhcpc.script, is the preference to use a hook for something like a record of the last lease?

Signature · 5 lines
Thanks,
Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150712/132de537/attachment.html>
#2 lore raw

PATCH v2 1/1 busybox: udhcpc create leases file

Dear Matthew Weber,

Quoted 2 lines · Matthew Weber

Since the hook scripts where added for the udhcpc.script, is the preference to use a hook for something like a record of the last lease?

Yes. Your patch looks too much application-specific, so please use the udhcpc hook mechanism to install your script through your own rootfs overlay.

I'll mark the patch as Rejected.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com