From ea5f732e242ab59d8886f823cbee989064bf5f8d Mon Sep 17 00:00:00 2001 From: AliveDevil Date: Mon, 1 Jan 2024 23:10:37 +0100 Subject: [PATCH] Handling --- src/pdns-dhcp/Kea/KeaDhcp4Lease.cs | 4 ++-- src/pdns-dhcp/Kea/KeaDhcp4LeaseHandler.cs | 8 +++++++- src/pdns-dhcp/Kea/KeaDhcp6Lease.cs | 4 ++-- src/pdns-dhcp/Kea/KeaDhcp6LeaseHandler.cs | 8 +++++++- src/pdns-dhcp/PowerDns/Methods.cs | 1 + 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/pdns-dhcp/Kea/KeaDhcp4Lease.cs b/src/pdns-dhcp/Kea/KeaDhcp4Lease.cs index fa748b3..c869a60 100644 --- a/src/pdns-dhcp/Kea/KeaDhcp4Lease.cs +++ b/src/pdns-dhcp/Kea/KeaDhcp4Lease.cs @@ -14,7 +14,7 @@ public record struct KeaDhcp4Lease( IPAddress Address, PhysicalAddress HWAddr, string? ClientId, - uint ValidLifetime, + TimeSpan ValidLifetime, DateTimeOffset Expire, uint SubnetId, bool FqdnFwd, @@ -81,7 +81,7 @@ public record struct KeaDhcp4Lease( static bool ToValidLifetime(ref Lease lease, in Cell span) { bool result = uint.TryParse(span, out var validLifetime); - lease.ValidLifetime = validLifetime; + lease.ValidLifetime = TimeSpan.FromSeconds(validLifetime); return result; } diff --git a/src/pdns-dhcp/Kea/KeaDhcp4LeaseHandler.cs b/src/pdns-dhcp/Kea/KeaDhcp4LeaseHandler.cs index e26c2ad..d9e8365 100644 --- a/src/pdns-dhcp/Kea/KeaDhcp4LeaseHandler.cs +++ b/src/pdns-dhcp/Kea/KeaDhcp4LeaseHandler.cs @@ -13,6 +13,12 @@ public class KeaDhcp4LeaseHandler : IKeaDhcpLeaseHandler return null; } - return new(lease.Address, lease.Hostname, null, default); + DhcpLeaseIdentifier identifier = lease.ClientId switch + { + string clientId when !string.IsNullOrWhiteSpace(clientId) => new DhcpLeaseClientIdentifier(clientId), + _ => new DhcpLeaseHWAddrIdentifier(lease.HWAddr) + }; + + return new(lease.Address, lease.Hostname, identifier, lease.ValidLifetime); } } diff --git a/src/pdns-dhcp/Kea/KeaDhcp6Lease.cs b/src/pdns-dhcp/Kea/KeaDhcp6Lease.cs index 3e4299a..654ed82 100644 --- a/src/pdns-dhcp/Kea/KeaDhcp6Lease.cs +++ b/src/pdns-dhcp/Kea/KeaDhcp6Lease.cs @@ -13,7 +13,7 @@ using Lease = KeaDhcp6Lease; public record struct KeaDhcp6Lease( IPAddress Address, string DUId, - uint ValidLifetime, + TimeSpan ValidLifetime, DateTimeOffset Expire, uint SubnetId, uint PrefLifetime, @@ -86,7 +86,7 @@ public record struct KeaDhcp6Lease( static bool ToValidLifetime(ref Lease lease, in Cell span) { bool result = uint.TryParse(span, out var validLifetime); - lease.ValidLifetime = validLifetime; + lease.ValidLifetime = TimeSpan.FromSeconds(validLifetime); return result; } diff --git a/src/pdns-dhcp/Kea/KeaDhcp6LeaseHandler.cs b/src/pdns-dhcp/Kea/KeaDhcp6LeaseHandler.cs index 3bfd098..8a614d6 100644 --- a/src/pdns-dhcp/Kea/KeaDhcp6LeaseHandler.cs +++ b/src/pdns-dhcp/Kea/KeaDhcp6LeaseHandler.cs @@ -13,6 +13,12 @@ public class KeaDhcp6LeaseHandler : IKeaDhcpLeaseHandler return null; } - return new(lease.Address, lease.Hostname, null, default); + DhcpLeaseIdentifier identifier = lease.DUId switch + { + string clientId when !string.IsNullOrWhiteSpace(clientId) => new DhcpLeaseClientIdentifier(clientId), + _ => new DhcpLeaseHWAddrIdentifier(lease.HWAddr) + }; + + return new(lease.Address, lease.Hostname, identifier, lease.ValidLifetime); } } diff --git a/src/pdns-dhcp/PowerDns/Methods.cs b/src/pdns-dhcp/PowerDns/Methods.cs index acce31c..2259203 100644 --- a/src/pdns-dhcp/PowerDns/Methods.cs +++ b/src/pdns-dhcp/PowerDns/Methods.cs @@ -19,6 +19,7 @@ internal partial class MethodContext : JsonSerializerContext; public abstract class Method(TParam parameters) : Method where TParam : MethodParameters { + [JsonPropertyName("parameters")] public TParam Parameters => parameters; }