[systemd-devel] [PATCH 5/8] sd-dhcp6-lease: Add helper function to compute remaining expiry time

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Thu Jun 26 04:01:44 PDT 2014


On Thu, Jun 26, 2014 at 01:24:15PM +0300, Patrik Flykt wrote:
> Create a helper function to compute the remaining time in seconds from
> time T2 to the IPv6 address with the longest lifetime. The computed
> time is used as the Maximum Retransmission Duration in Rebinding state.
> See RFC 3315, section 18.1.4. for details.
> ---
>  src/libsystemd-network/dhcp6-lease-internal.h |  1 +
>  src/libsystemd-network/sd-dhcp6-lease.c       | 24 ++++++++++++++++++++++++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/src/libsystemd-network/dhcp6-lease-internal.h b/src/libsystemd-network/dhcp6-lease-internal.h
> index 295c223..62c16c5 100644
> --- a/src/libsystemd-network/dhcp6-lease-internal.h
> +++ b/src/libsystemd-network/dhcp6-lease-internal.h
> @@ -42,6 +42,7 @@ struct sd_dhcp6_lease {
>  };
>  
>  int dhcp6_lease_clear_timers(DHCP6IA *ia);
> +int dhcp6_lease_ia_rebind_expire(const DHCP6IA *ia, uint32_t *expire);
>  DHCP6IA *dhcp6_lease_free_ia(DHCP6IA *ia);
>  
>  int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id,
> diff --git a/src/libsystemd-network/sd-dhcp6-lease.c b/src/libsystemd-network/sd-dhcp6-lease.c
> index cbda7d8..9426b52 100644
> --- a/src/libsystemd-network/sd-dhcp6-lease.c
> +++ b/src/libsystemd-network/sd-dhcp6-lease.c
> @@ -33,6 +33,30 @@ int dhcp6_lease_clear_timers(DHCP6IA *ia) {
>          return 0;
>  }
>  
> +int dhcp6_lease_ia_rebind_expire(const DHCP6IA *ia, uint32_t *expire) {
> +        DHCP6Address *addr;
> +        uint32_t t;
> +
> +        assert_return(ia, -EINVAL);
> +        assert_return(expire, -EINVAL);
> +
> +        *expire = 0;
> +
> +        LIST_FOREACH(addresses, addr, ia->addresses) {
> +                t = be32toh(addr->lifetime_valid);
> +                if (*expire < t)
> +                        *expire = t;
> +        }
> +
> +        t = be32toh(ia->lifetime_t2);
> +        if (t > *expire)
> +                return -EINVAL;
> +
> +        *expire -= t;
> +
> +        return 0;
Please use a temporary variable so that *expire is only written to when 0 is returned.

Zbyszek


More information about the systemd-devel mailing list