+ dhcpv6 server; rewrite dhcpv4 server; changed API
This commit is contained in:
@@ -86,6 +86,7 @@ type clientsContainer struct {
|
||||
}
|
||||
|
||||
// Init initializes clients container
|
||||
// dhcpServer: optional
|
||||
// Note: this function must be called only once
|
||||
func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.Server, autoHosts *util.AutoHosts) {
|
||||
if clients.list != nil {
|
||||
@@ -106,7 +107,9 @@ func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.
|
||||
|
||||
if !clients.testing {
|
||||
clients.addFromDHCP()
|
||||
clients.dhcpServer.SetOnLeaseChanged(clients.onDHCPLeaseChanged)
|
||||
if clients.dhcpServer != nil {
|
||||
clients.dhcpServer.SetOnLeaseChanged(clients.onDHCPLeaseChanged)
|
||||
}
|
||||
clients.autoHosts.SetOnChanged(clients.onHostsChanged)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,10 +127,6 @@ var config = configuration{
|
||||
PortHTTPS: 443,
|
||||
PortDNSOverTLS: 853, // needs to be passed through to dnsproxy
|
||||
},
|
||||
DHCP: dhcpd.ServerConfig{
|
||||
LeaseDuration: 86400,
|
||||
ICMPTimeout: 1000,
|
||||
},
|
||||
logSettings: logSettings{
|
||||
LogCompress: false,
|
||||
LogLocalTime: false,
|
||||
@@ -156,6 +152,10 @@ func initConfig() {
|
||||
config.DNS.DnsfilterConf.ParentalCacheSize = 1 * 1024 * 1024
|
||||
config.DNS.DnsfilterConf.CacheTime = 30
|
||||
config.Filters = defaultFilters()
|
||||
|
||||
config.DHCP.Conf4.LeaseDuration = 86400
|
||||
config.DHCP.Conf4.ICMPTimeout = 1000
|
||||
config.DHCP.Conf6.LeaseDuration = 86400
|
||||
}
|
||||
|
||||
// getConfigFilename returns path to the current config file
|
||||
|
||||
@@ -56,6 +56,7 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
"protection_enabled": c.ProtectionEnabled,
|
||||
}
|
||||
data["dhcp_available"] = (Context.dhcpServer != nil)
|
||||
|
||||
jsonVal, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
||||
36
home/dhcp.go
36
home/dhcp.go
@@ -1,36 +0,0 @@
|
||||
package home
|
||||
|
||||
import (
|
||||
"github.com/joomcode/errorx"
|
||||
)
|
||||
|
||||
func startDHCPServer() error {
|
||||
if !config.DHCP.Enabled {
|
||||
// not enabled, don't do anything
|
||||
return nil
|
||||
}
|
||||
|
||||
err := Context.dhcpServer.Init(config.DHCP)
|
||||
if err != nil {
|
||||
return errorx.Decorate(err, "Couldn't init DHCP server")
|
||||
}
|
||||
|
||||
err = Context.dhcpServer.Start()
|
||||
if err != nil {
|
||||
return errorx.Decorate(err, "Couldn't start DHCP server")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func stopDHCPServer() error {
|
||||
if !config.DHCP.Enabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := Context.dhcpServer.Stop()
|
||||
if err != nil {
|
||||
return errorx.Decorate(err, "Couldn't stop DHCP server")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
17
home/home.go
17
home/home.go
@@ -219,10 +219,8 @@ func run(args options) {
|
||||
config.DHCP.WorkDir = Context.workDir
|
||||
config.DHCP.HTTPRegister = httpRegister
|
||||
config.DHCP.ConfigModified = onConfigModified
|
||||
Context.dhcpServer = dhcpd.Create(config.DHCP)
|
||||
if Context.dhcpServer == nil {
|
||||
log.Error("Failed to initialize DHCP server, exiting")
|
||||
os.Exit(1)
|
||||
if runtime.GOOS != "windows" {
|
||||
Context.dhcpServer = dhcpd.Create(config.DHCP)
|
||||
}
|
||||
Context.autoHosts.Init("")
|
||||
|
||||
@@ -317,9 +315,8 @@ func run(args options) {
|
||||
}
|
||||
}()
|
||||
|
||||
err = startDHCPServer()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
if Context.dhcpServer != nil {
|
||||
_ = Context.dhcpServer.Start()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,9 +502,9 @@ func cleanup() {
|
||||
if err != nil {
|
||||
log.Error("Couldn't stop DNS server: %s", err)
|
||||
}
|
||||
err = stopDHCPServer()
|
||||
if err != nil {
|
||||
log.Error("Couldn't stop DHCP server: %s", err)
|
||||
|
||||
if Context.dhcpServer != nil {
|
||||
Context.dhcpServer.Stop()
|
||||
}
|
||||
|
||||
Context.autoHosts.Close()
|
||||
|
||||
Reference in New Issue
Block a user