Listen on HTTP port and PowerDns socket
This commit is contained in:
parent
dd914cc0c7
commit
2a9d7f46ed
3 changed files with 17 additions and 34 deletions
|
|
@ -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;
|
||||||
|
|
@ -66,14 +35,14 @@ builder.WebHost.ConfigureKestrel((context, options) =>
|
||||||
isSystemd = true;
|
isSystemd = true;
|
||||||
options.UseConnectionHandler<PowerDnsHandler>();
|
options.UseConnectionHandler<PowerDnsHandler>();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isSystemd && context.Configuration.GetRequiredSection("PowerDns:Listener").Get<PowerDnsListenerOptions>() is { } pdnsOptions)
|
if (!isSystemd && context.Configuration.GetRequiredSection("PowerDns:Listener").Get<PowerDnsListenerOptions>() is { } pdnsOptions)
|
||||||
{
|
{
|
||||||
var path = PathEx.ExpandPath(pdnsOptions.Socket);
|
var path = PathEx.ExpandPath(pdnsOptions.Socket);
|
||||||
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>();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,5 +14,12 @@
|
||||||
"Listener": {
|
"Listener": {
|
||||||
"Socket": "/run/pdns-dhcp/pdns.sock"
|
"Socket": "/run/pdns-dhcp/pdns.sock"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Kestrel": {
|
||||||
|
"Endpoints": {
|
||||||
|
"Http":{
|
||||||
|
"Url": "http://[::]:80"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue