Listen on HTTP port and PowerDns socket

This commit is contained in:
Jöran Malek 2025-01-27 00:02:07 +01:00
parent dd914cc0c7
commit 2a9d7f46ed
3 changed files with 17 additions and 34 deletions

View file

@ -1,15 +1,10 @@
using System.Net; using Microsoft.AspNetCore.Builder;
using System.Net.Sockets;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using pdns_dhcp.Connections;
using pdns_dhcp.Dhcp; using pdns_dhcp.Dhcp;
using pdns_dhcp.Dns; using pdns_dhcp.Dns;
using pdns_dhcp.Kea; using pdns_dhcp.Kea;
@ -32,32 +27,6 @@ builder.Services.AddSingleton<DnsRepository>();
builder.Services.AddDhcpWatcherFactory(); builder.Services.AddDhcpWatcherFactory();
builder.Services.AddKeaFactory(); builder.Services.AddKeaFactory();
builder.Services.Configure<SocketTransportOptions>(options =>
{
options.CreateBoundListenSocket = endpoint =>
{
Socket socket;
switch (endpoint)
{
case ProtocolSocketIPEndPoint socketIp:
socket = new Socket(socketIp.AddressFamily, socketIp.SocketType, socketIp.ProtocolType);
if (socketIp.Address.Equals(IPAddress.IPv6Any))
{
socket.DualMode = true;
}
break;
default:
return SocketTransportOptions.CreateDefaultBoundListenSocket(endpoint);
}
socket.Bind(endpoint);
return socket;
};
});
builder.WebHost.ConfigureKestrel((context, options) => builder.WebHost.ConfigureKestrel((context, options) =>
{ {
bool isSystemd = false; bool isSystemd = false;
@ -73,7 +42,7 @@ builder.WebHost.ConfigureKestrel((context, options) =>
FileInfo file = new(path); FileInfo file = new(path);
file.Directory!.Create(); file.Directory!.Create();
file.Delete(); file.Delete();
options.ListenUnixSocket(path, options => options.ConfigurationLoader!.UnixSocketEndpoint(path, options =>
{ {
options.UseConnectionHandler<PowerDnsHandler>(); options.UseConnectionHandler<PowerDnsHandler>();
}); });

View file

@ -13,5 +13,12 @@
"Listener": { "Listener": {
"Socket": "${XDG_RUNTIME_DIR}/pdns-dhcp/pdns.sock" "Socket": "${XDG_RUNTIME_DIR}/pdns-dhcp/pdns.sock"
} }
},
"Kestrel": {
"Endpoints": {
"Http":{
"Url": "http://[::1]:5000"
}
}
} }
} }

View file

@ -14,5 +14,12 @@
"Listener": { "Listener": {
"Socket": "/run/pdns-dhcp/pdns.sock" "Socket": "/run/pdns-dhcp/pdns.sock"
} }
},
"Kestrel": {
"Endpoints": {
"Http":{
"Url": "http://[::]:80"
}
}
} }
} }