This commit is contained in:
Jöran Malek 2023-11-15 00:21:36 +01:00
parent dd62484615
commit 377e4744ec
8 changed files with 119 additions and 2 deletions

View file

@ -0,0 +1,10 @@
namespace pdns_dhcp.Options;
public class KeaDhcpOptions
{
public KeaDhcpServerOptions? Dhcp4 { get; set; }
public KeaDhcpServerOptions? Dhcp6 { get; set; }
}
public record class KeaDhcpServerOptions(FileInfo Leases);

View file

@ -0,0 +1,11 @@
namespace pdns_dhcp.Options;
public class PowerDnsOptions
{
public PowerDnsListenerOptions Listener { get; set; }
}
public class PowerDnsListenerOptions(string socket)
{
public string Socket { get; } = socket;
}

View file

@ -0,0 +1,11 @@
using System.Net.Sockets;
namespace pdns_dhcp.PowerDns;
public class PowerDnsSocket
{
public PowerDnsSocket()
{
}
}

View file

@ -0,0 +1,8 @@
using Stl.Interception;
namespace pdns_dhcp.PowerDns;
public interface SocketFactory : IRequiresFullProxy
{
PowerDnsSocket Create();
}

View file

@ -1,2 +1,19 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using pdns_dhcp.Options;
using pdns_dhcp.PowerDns;
using pdns_dhcp.Services;
using Stl.Interception;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.Configure<KeaDhcpOptions>(builder.Configuration.GetSection("KeaDhcp"));
builder.Services.Configure<PowerDnsOptions>(builder.Configuration.GetSection("PowerDns"));
builder.Services.AddHostedService<DhcpLeaseWatcher>();
builder.Services.AddHostedService<PowerDnsBackend>();
builder.Services.AddTypedFactory<SocketFactory>();
builder.Build().Run();

View file

@ -0,0 +1,29 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using pdns_dhcp.Options;
using pdns_dhcp.PowerDns;
namespace pdns_dhcp.Services;
public class DhcpLeaseWatcher : IHostedService
{
private readonly PowerDnsOptions _options;
private readonly PowerDnsSocket _socket;
public DhcpLeaseWatcher(IOptions<PowerDnsOptions> options, SocketFactory factory)
{
_options = options.Value;
_socket = factory.Create();
}
public Task StartAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task StopAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View file

@ -0,0 +1,16 @@
using Microsoft.Extensions.Hosting;
namespace pdns_dhcp.Services;
public class PowerDnsBackend : IHostedService
{
public Task StartAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public Task StopAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View file

@ -0,0 +1,15 @@
{
"PowerDns": {
"Listener": {
"Socket": "/run/pdns-dhcp/pdns.sock"
}
},
"KeaDhcp": {
"Dhcp4": {
"Leases": "/var/lib/kea/dhcp4.leases"
},
"Dhcp6": {
"Leases": "/var/lib/kea/dhcp6.leases"
}
}
}