dhclient: Using dhcp-lease-time in expressions

Glenn Satchell glenn.satchell at uniq.com.au
Fri Dec 16 06:40:42 UTC 2011


You're stuck in a chicken and egg situation here. When you send out the
initial DHCPDISCOVER, there is no lease-time assigned yet, so the value is
undefined and causes the expression to fail.

Looking at the dhcp-eval man page you could wrap this with "if exists".
Although that says it wants an option it may also work with lease-time.

if exists lease-time {
  supersede dhcp-renewal-time = encode-int(lease-time / 10, 32);
}

Alternatively to using "if exists" you coul duse
pick-first-value(lease-time, 1000) to give a default.

Of you could try testing client-state > 1 (ie anything except booting).

Maybe add a log() call inside the if... to see what value is being set?

regards,
-glenn

> [dhclient 4.2.1-P1]
>
> For testing purposes, I'm attempting to set dhcp-renewal-time to 10% of
> dhcp-lease-time. But I can't seem to figure out the right way to specify
> dhcp-lease-time in thema numeric expression.
>
> Here's what I've tried:
>
> (1) supersede dhcp-renewal-time = encode-int(lease-time / 10, 32);
>
> (2) supersede dhcp-renewal-time =
>       encode-int(extract-int(option dhcp-lease-time, 32) / 10, 32);
>
> (3) supersede dhcp-renewal-time = encode-int(3000 / 10, 32);
>
> Results:
>
> (1) Fails with error:  "data: leased_lease: not available"
>
> (2) No error, but doesn't produce any dhcp-renewal-time option in
>     the leases file. (Perhaps because extract-int() returns null?)
>
> (3) Using a constant works, so apparently the rest of the
>     expression is correct.
>
> Any ideas?
>
> --
> Jordan Russell
> _______________________________________________
> dhcp-users mailing list
> dhcp-users at lists.isc.org
> https://lists.isc.org/mailman/listinfo/dhcp-users
>





More information about the dhcp-users mailing list