[PATCH] Only write leasefile if anything changed

Phil Sutter phil.sutter at viprinet.com
Wed May 7 09:19:51 UTC 2014


Hi,

This patch is left unapplied for nearly two years now. Was it forgotten
or are there good reasons to reject it? If so, something one could fix?
:)

On Tue, May 08, 2012 at 04:09:34PM +0200, Phil Sutter wrote:
> Also, move the check for changed leases to before the select(), so
> changes will occur immediately instead only after select() returns the
> next time.
> 
> Signed-off-by: Phil Sutter <phil.sutter at viprinet.com>
> Signed-off-by: Nico Erfurth <nico.erfurth at viprinet.com>
> ---
>  networking/udhcp/dhcpd.c |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)
> 
> diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
> index dd55e70..356c81f 100644
> --- a/networking/udhcp/dhcpd.c
> +++ b/networking/udhcp/dhcpd.c
> @@ -298,6 +298,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
>  {
>  	int server_socket = -1, retval, max_sock;
>  	uint8_t *state;
> +	uint8_t leases_changed = 0;
>  	unsigned timeout_end;
>  	unsigned num_ips;
>  	unsigned opt;
> @@ -389,6 +390,11 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
>  		uint32_t static_lease_nip;
>  		struct dyn_lease *lease, fake_lease;
>  
> +		if (leases_changed) {
> +			write_leases();
> +			leases_changed = 0;
> +		}
> +
>  		if (server_socket < 0) {
>  			server_socket = udhcp_listen_socket(/*INADDR_ANY,*/ SERVER_PORT,
>  					server_config.interface);
> @@ -405,7 +411,6 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
>  					server_config.auto_time ? &tv : NULL);
>  		}
>  		if (retval == 0) {
> -			write_leases();
>  			timeout_end = monotonic_sec() + server_config.auto_time;
>  			continue;
>  		}
> @@ -591,6 +596,7 @@ o DHCPREQUEST generated during REBINDING state:
>  				/* client requested or configured IP matches the lease.
>  				 * ACK it, and bump lease expiration time. */
>  				send_ACK(&packet, lease->lease_nip);
> +				leases_changed = 1;
>  				break;
>  			}
>  			/* No lease for this MAC, or lease IP != requested IP */
> @@ -626,6 +632,7 @@ o DHCPREQUEST generated during REBINDING state:
>  			) {
>  				memset(lease->lease_mac, 0, sizeof(lease->lease_mac));
>  				lease->expires = time(NULL) + server_config.decline_time;
> +				leases_changed = 1;
>  			}
>  			break;
>  
> @@ -644,6 +651,7 @@ o DHCPREQUEST generated during REBINDING state:
>  			 && packet.ciaddr == lease->lease_nip
>  			) {
>  				lease->expires = time(NULL);
> +				leases_changed = 1;
>  			}
>  			break;
>  
> -- 
> 1.7.3.4
> 
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
> 


Best wishes,

Phil Sutter
Software Engineer

-- 
Viprinet Europe GmbH
Gaustr. 22-32
55411 Bingen am Rhein
Germany

Phone/Zentrale:               +49 6721 49030-0
Direct line/Durchwahl:        +49 6721 49030-134
Fax:                          +49 6721 49030-109

phil.sutter at viprinet.com
http://www.viprinet.com

Registered office/Sitz der Gesellschaft: Bingen am Rhein, Germany
Commercial register/Handelsregister: Amtsgericht Mainz HRB44090
CEO/Geschäftsführer: Simon Kissel


More information about the busybox mailing list