* control: use new DHCP functions: CheckConfig, Init, Start

This commit is contained in:
Simon Zolin 2019-05-14 16:59:21 +03:00
parent 626c1ae753
commit c3204664c3
1 changed files with 20 additions and 2 deletions

22
dhcp.go
View File

@ -60,11 +60,23 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
return return
} }
err = dhcpServer.CheckConfig(newconfig.ServerConfig)
if err != nil {
httpError(w, http.StatusBadRequest, "Invalid DHCP configuration: %s", err)
return
}
err = dhcpServer.Stop() err = dhcpServer.Stop()
if err != nil { if err != nil {
log.Error("failed to stop the DHCP server: %s", err) log.Error("failed to stop the DHCP server: %s", err)
} }
err = dhcpServer.Init(newconfig.ServerConfig)
if err != nil {
httpError(w, http.StatusBadRequest, "Invalid DHCP configuration: %s", err)
return
}
if newconfig.Enabled { if newconfig.Enabled {
staticIP, err := hasStaticIP(newconfig.InterfaceName) staticIP, err := hasStaticIP(newconfig.InterfaceName)
@ -76,7 +88,7 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
} }
} }
err = dhcpServer.Start(&newconfig.ServerConfig) err = dhcpServer.Start()
if err != nil { if err != nil {
httpError(w, http.StatusBadRequest, "Failed to start DHCP server: %s", err) httpError(w, http.StatusBadRequest, "Failed to start DHCP server: %s", err)
return return
@ -342,7 +354,13 @@ func startDHCPServer() error {
// not enabled, don't do anything // not enabled, don't do anything
return nil return nil
} }
err := dhcpServer.Start(&config.DHCP)
err := dhcpServer.Init(config.DHCP)
if err != nil {
return errorx.Decorate(err, "Couldn't init DHCP server")
}
err = dhcpServer.Start()
if err != nil { if err != nil {
return errorx.Decorate(err, "Couldn't start DHCP server") return errorx.Decorate(err, "Couldn't start DHCP server")
} }