From c3204664c391de9cde30577e60f315998b9dd048 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 14 May 2019 16:59:21 +0300 Subject: [PATCH] * control: use new DHCP functions: CheckConfig, Init, Start --- dhcp.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/dhcp.go b/dhcp.go index 35c4d22f..e2938fa8 100644 --- a/dhcp.go +++ b/dhcp.go @@ -60,11 +60,23 @@ func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) { return } + err = dhcpServer.CheckConfig(newconfig.ServerConfig) + if err != nil { + httpError(w, http.StatusBadRequest, "Invalid DHCP configuration: %s", err) + return + } + err = dhcpServer.Stop() if err != nil { 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 { 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 { httpError(w, http.StatusBadRequest, "Failed to start DHCP server: %s", err) return @@ -342,7 +354,13 @@ func startDHCPServer() error { // not enabled, don't do anything 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 { return errorx.Decorate(err, "Couldn't start DHCP server") }