Skip to contentSkip to conversation

busybox: udhcpc create leases file

PATCH Superseded Matt Weber 4 participants 7 messages Apr 30, 2015 – May 1, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Matt Weber

author
#0 lore raw

PATCH 1/1 busybox: udhcpc create leases file

---
 package/busybox/udhcpc.script | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
package/busybox/udhcpc.script +23 -0
index 50c52e6..d5d81bf 100755
@@ -61,6 +61,29 @@ case "$1" in
 			echo adding dns $i
 			echo "nameserver $i # $interface" >> $RESOLV_CONF
 		done
+
+		# Based on http://sourceforge.net/p/kboot/mailman/message/1168535/
+		{
+		    echo "lease {"
+		    echo "  interface \"$interface\";"
+		    echo "  fixed-address $ip;"
+		    [ -n "$boot_file" ] && echo "  filename \"$boot_file\";"
+		    [ -n "$subnet" ] && echo "  option subnet-mask $subnet;"
+		    [ -n "$router" ] && echo "  option routers $router;"
+		    echo "  option dhcp-lease-time $lease;"
+		    echo "  option dhcp-message-type $dhcptype;"
+		    [ -n "$dns" ] && echo "  option domain-name-servers $dns;"
+		    echo "  option dhcp-server-identifier ${siaddr:-$serverid};"
+		    [ -n "$domain" ] && echo "  option domain-name \"$domain\";"
+		    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 "  renew $t;"
+		    t=$(date -d "$d:$(expr 7 '*' $lease / 8)" "+%w %Y/%m/%d %H:%M:%S" 2>/dev/null)
+		    [ -n "$t" ] && echo "  rebind $t;"
+		    t=$(date -d "$d:$lease" "+%w %Y/%m/%d %H:%M:%S" 2>/dev/null)
+		    [ -n "$t" ] && echo "  expire $t;"
+		    echo "}"
+		} >> /var/lib/misc/udhcpc-$interface.leases
 		;;
 esac
 

--
1.9.1

#1 lore raw

PATCH 1/1 busybox: udhcpc create leases file

Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Matt" == Matt Weber <[email protected]> writes:

---
 package/busybox/udhcpc.script | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
package/busybox/udhcpc.script +0 -0
index 50c52e6..d5d81bf 100755

package/busybox/udhcpc.script case "$1" in · line 65

Quoted 5 lines
package/busybox/udhcpc.script +2 -0
@@ -61,6 +61,29 @@ case "$1" in
 			echo adding dns $i
 			echo "nameserver $i # $interface" >> $RESOLV_CONF
 		done
+
+		# Based on http://sourceforge.net/p/kboot/mailman/message/1168535/

A more detailed commit message would be good. After looking at that URL I'm still not quite sure what this is needed for? It doesn't seem to be read again anywhere.

package/busybox/udhcpc.script case "$1" in · line 86

Quoted 1 line
package/busybox/udhcpc.script +1 -0
+		} >> /var/lib/misc/udhcpc-$interface.leases

Are you sure this should append the file and not overwrite it? Why would you want to keep older lease info around when you receive a new one?

Perhaps this belongs in a hook in your rootfs overlay?

Signature · 1 line
Bye, Peter Korsgaard
#2 lore raw

PATCH 1/1 busybox: udhcpc create leases file

Peter,

Quoted 7 lines · Peter Korsgaard
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Matt" == Matt Weber <[email protected]> writes:

---
 package/busybox/udhcpc.script | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
Quoted 14 lines

package/busybox/udhcpc.script case "$1" in · line 65

Quoted 10 lines
package/busybox/udhcpc.script +2 -0
index 50c52e6..d5d81bf 100755
@@ -61,6 +61,29 @@ case "$1" in
                     echo adding dns $i
                     echo "nameserver $i # $interface" >> $RESOLV_CONF
             done
+
+            # Based on http://sourceforge.net/p/kboot/mailman/message/1168535/

A more detailed commit message would be good. After looking at that URL I'm still not quite sure what this is needed for? It doesn't seem to be read again anywhere.

Sorry, I can add that. In general, it adds the leases functionality that mimics full dhclient behavior. This file can then be used at a system level to know least expiration and other server provided information.

Quoted 5 lines

package/busybox/udhcpc.script case "$1" in · line 86

Quoted 2 lines
package/busybox/udhcpc.script +1 -0
+             } >> /var/lib/misc/udhcpc-$interface.leases

Are you sure this should append the file and not overwrite it? Why would you want to keep older lease info around when you receive a new one?

I just mimic'd dhclient but I could see in a embedded space you might only want to keep the latest and when a lease expires, removing this file. I think the full client usually used this file to set an interface after reboot to the previous lease if one was still valid. I wasn't going to keep this behavior since for embedded devices it doesn't make sense.

Quoted 2 lines

Perhaps this belongs in a hook in your rootfs overlay?

Right now there isn't any way to get dhcp lease information after a lease is provided. It seemed this should be a standard capability of the script. I do agree I should make it not append and clean up when there isnt' a lease.

Thanks for the feedback!

Signature · 8 lines
Matthew L Weber / Pr Software Engineer
Airborne Information Systems / Security Systems and Software / Secure Platforms
MS 131-100, C Ave NE, Cedar Rapids, IA, 52498, USA
www.rockwellcollins.com

Note: Any Export License Required Information and License Restricted
Third Party Intellectual Property (TPIP) content must be encrypted and
sent to matthew.weber at corp.rockwellcollins.com.
#3 lore raw

PATCH 1/1 busybox: udhcpc create leases file

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Matthew" == Matthew Weber <[email protected]> writes:

Hi,

Quoted 10 lines
Quoted 5 lines
Quoted 1 line

+ # Based on http://sourceforge.net/p/kboot/mailman/message/1168535/

A more detailed commit message would be good. After looking at that URL I'm still not quite sure what this is needed for? It doesn't seem to be read again anywhere.

Sorry, I can add that. In general, it adds the leases functionality that mimics full dhclient behavior. This file can then be used at a system level to know least expiration and other server provided information.

Ok, good. Is that really something we want to enforce for everyone using udhcpc with Buildroot?

Quoted 11 lines
Quoted 4 lines
Quoted 1 line

+ } >> /var/lib/misc/udhcpc-$interface.leases

Are you sure this should append the file and not overwrite it? Why would you want to keep older lease info around when you receive a new one?

I just mimic'd dhclient but I could see in a embedded space you might only want to keep the latest and when a lease expires, removing this file. I think the full client usually used this file to set an interface after reboot to the previous lease if one was still valid. I wasn't going to keep this behavior since for embedded devices it doesn't make sense.

Ok.

Quoted 7 lines
Quoted 2 lines

Perhaps this belongs in a hook in your rootfs overlay?

Right now there isn't any way to get dhcp lease information after a lease is provided. It seemed this should be a standard capability of the script. I do agree I should make it not append and clean up when there isnt' a lease.

I'm still not convinced this isn't something that belongs in a project specific rootfs overlay instead. That's part of the reason why we now support custom hooks in the udhcpc script.

Signature · 2 lines
Venlig hilsen,
Peter Korsgaard 
#4 lore raw

PATCH 1/1 busybox: udhcpc create leases file

Peter,

Quoted 10 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Matthew" == Matthew Weber <[email protected]> writes:

Hi,

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

+ # Based on http://sourceforge.net/p/kboot/mailman/message/1168535/

A more detailed commit message would be good. After looking at that URL I'm still not quite sure what this is needed for? It doesn't seem to be read again anywhere.

Quoted 7 lines
Quoted 4 lines

Sorry, I can add that. In general, it adds the leases functionality that mimics full dhclient behavior. This file can then be used at a system level to know least expiration and other server provided information.

Ok, good. Is that really something we want to enforce for everyone using udhcpc with Buildroot?

Possibly not. I'm good with doing a hook script for now. Half of my sending this patch in was to just publish the concept if anyone else wants to use/add to it.

Thanks!

Signature · 8 lines
Matthew L Weber / Pr Software Engineer
Airborne Information Systems / Security Systems and Software / Secure Platforms
MS 131-100, C Ave NE, Cedar Rapids, IA, 52498, USA
www.rockwellcollins.com

Note: Any Export License Required Information and License Restricted
Third Party Intellectual Property (TPIP) content must be encrypted and
sent to matthew.weber at corp.rockwellcollins.com.
#5 lore raw

PATCH 1/1 busybox: udhcpc create leases file

In reply to Peter Korsgaard
Quoted 10 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Matthew" == Matthew Weber <[email protected]> writes:

Hi,

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

+ # Based on http://sourceforge.net/p/kboot/mailman/message/1168535/

A more detailed commit message would be good. After looking at that URL I'm still not quite sure what this is needed for? It doesn't seem to be read again anywhere.

Quoted 7 lines
Quoted 4 lines

Sorry, I can add that. In general, it adds the leases functionality that mimics full dhclient behavior. This file can then be used at a system level to know least expiration and other server provided information.

Ok, good. Is that really something we want to enforce for everyone using udhcpc with Buildroot?

I don't see why not. It's creating a small file in /tmp, that's all. Except for
the appending, of course, otherwise a long-running system could just fill up /tmp with leases. Overwriting has the disadvantage that there's a race condition when the file is truncated at the same time that another process is reading from it, but I don't think the complexity of fixing that race is worth the bother.

Regards,
Arnout

Quoted 27 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

+ } >> /var/lib/misc/udhcpc-$interface.leases

Are you sure this should append the file and not overwrite it? Why would you want to keep older lease info around when you receive a new one?

Quoted 6 lines

I just mimic'd dhclient but I could see in a embedded space you might only want to keep the latest and when a lease expires, removing this file. I think the full client usually used this file to set an interface after reboot to the previous lease if one was still valid. I wasn't going to keep this behavior since for embedded devices it doesn't make sense.

Ok.

Quoted 7 lines
Quoted 2 lines

Perhaps this belongs in a hook in your rootfs overlay?

Right now there isn't any way to get dhcp lease information after a lease is provided. It seemed this should be a standard capability of the script. I do agree I should make it not append and clean up when there isnt' a lease.

I'm still not convinced this isn't something that belongs in a project specific rootfs overlay instead. That's part of the reason why we now support custom hooks in the udhcpc script.

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#6 lore raw

PATCH 1/1 busybox: udhcpc create leases file

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

Hi,

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Sorry, I can add that. In general, it adds the leases functionality that mimics full dhclient behavior. This file can then be used at a system level to know least expiration and other server provided information.

Quoted 8 lines
Quoted 2 lines

Ok, good. Is that really something we want to enforce for everyone using udhcpc with Buildroot?

I don't see why not. It's creating a small file in /tmp, that's all. Except for
the appending, of course, otherwise a long-running system could just fill up /tmp with leases. Overwriting has the disadvantage that there's a race condition when the file is truncated at the same time that another process is reading from it, but I don't think the complexity of fixing that race is worth the bother.

True. I would like to see this (and other non-essential things like E.G. avahi-autoipd) move to hooks though.

I wonder if the dhclient format is a sensible choice. Is that something any "standard" programs can work with? It doesn't seem very easy to parse in shell scripts. Maybe just shell compatible NAME="<val>" strings would be better?

Signature · 2 lines
Venlig hilsen,
Peter Korsgaard