Types
This commit is contained in:
parent
dd62484615
commit
377e4744ec
8 changed files with 119 additions and 2 deletions
10
src/pdns-dhcp/Options/KeaDhcpOptions.cs
Normal file
10
src/pdns-dhcp/Options/KeaDhcpOptions.cs
Normal 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);
|
||||||
11
src/pdns-dhcp/Options/PowerDnsOptions.cs
Normal file
11
src/pdns-dhcp/Options/PowerDnsOptions.cs
Normal 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;
|
||||||
|
}
|
||||||
11
src/pdns-dhcp/PowerDns/PowerDnsSocket.cs
Normal file
11
src/pdns-dhcp/PowerDns/PowerDnsSocket.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
|
namespace pdns_dhcp.PowerDns;
|
||||||
|
|
||||||
|
public class PowerDnsSocket
|
||||||
|
{
|
||||||
|
public PowerDnsSocket()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/pdns-dhcp/PowerDns/SocketFactory.cs
Normal file
8
src/pdns-dhcp/PowerDns/SocketFactory.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Stl.Interception;
|
||||||
|
|
||||||
|
namespace pdns_dhcp.PowerDns;
|
||||||
|
|
||||||
|
public interface SocketFactory : IRequiresFullProxy
|
||||||
|
{
|
||||||
|
PowerDnsSocket Create();
|
||||||
|
}
|
||||||
|
|
@ -1,2 +1,19 @@
|
||||||
// See https://aka.ms/new-console-template for more information
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
Console.WriteLine("Hello, World!");
|
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();
|
||||||
|
|
|
||||||
29
src/pdns-dhcp/Services/DhcpLeaseWatcher.cs
Normal file
29
src/pdns-dhcp/Services/DhcpLeaseWatcher.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/pdns-dhcp/Services/PowerDnsBackend.cs
Normal file
16
src/pdns-dhcp/Services/PowerDnsBackend.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/pdns-dhcp/appsettings.json
Normal file
15
src/pdns-dhcp/appsettings.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue