ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ell@lists.01.org
Subject: Re: [PATCH 1/4] dhcp-server: Fix lease expiry time calculation
Date: Tue, 01 Jun 2021 09:38:39 -0500	[thread overview]
Message-ID: <183b5df6-d81c-392c-c106-68f82ec2912a@gmail.com> (raw)
In-Reply-To: <20210601020346.35502-1-andrew.zaborowski@intel.com>

[-- Attachment #1: Type: text/plain, Size: 1675 bytes --]

Hi Andrew,

On 5/31/21 9:03 PM, Andrew Zaborowski wrote:
> We were comparing the l_time_now() (usecs) with lease->lifetime (secs)
> and then converting the result from usecs to secs, so the "diff" and the
> "to_sec" operations should be switched around.  While there also replace
> the "diff" operation so that if lease->lifetime is already in the past
> (e.g. because processing took to long), we schedule the timeout in 0
> seconds instead of the absolute value of the difference.
> 
> Since we're using uint32_t for the timestamps, use the overflow-safe(r)
> comparison.
> ---
>   ell/dhcp-server.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/ell/dhcp-server.c b/ell/dhcp-server.c
> index d390856..9e39fe6 100644
> --- a/ell/dhcp-server.c
> +++ b/ell/dhcp-server.c
> @@ -192,6 +192,7 @@ static void set_next_expire_timer(struct l_dhcp_server *server,
>   {
>   	struct l_dhcp_lease *next;
>   	unsigned int next_timeout;
> +	uint32_t now;
>   
>   	/*
>   	 * If this is an expiring lease put it into the expired queue, removing
> @@ -213,8 +214,9 @@ static void set_next_expire_timer(struct l_dhcp_server *server,
>   		return;
>   	}
>   
> -	next_timeout = l_time_to_secs(l_time_diff(l_time_now(),
> -							next->lifetime));
> +	now = l_time_to_secs(l_time_now());
> +	next_timeout = (int32_t) (next->lifetime - now) > 0 ?
> +		next->lifetime - now : 0;

0 is not a valid timeout value, it is used to rearm the timer.  So this case 
probably needs a different approach.

>   
>   	if (server->next_expire)
>   		l_timeout_modify(server->next_expire, next_timeout);
> 

Regards,
-Denis

      parent reply	other threads:[~2021-06-01 14:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01  2:03 [PATCH 1/4] dhcp-server: Fix lease expiry time calculation Andrew Zaborowski
2021-06-01  2:03 ` [PATCH 2/4] dhcp-server: Expire the lease from the right list Andrew Zaborowski
2021-06-01 14:44   ` Denis Kenzior
2021-06-01  2:03 ` [PATCH 3/4] dhcp-server: Don't check if lease expired in lease_release Andrew Zaborowski
2021-06-01  2:03 ` [PATCH 4/4] dhcp-server: Validate the offering state when handling message Andrew Zaborowski
2021-06-01 14:38 ` Denis Kenzior [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=183b5df6-d81c-392c-c106-68f82ec2912a@gmail.com \
    --to=denkenz@gmail.com \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).