*(dhcpd): refactoring, use dhcpd/network_utils where possible

This commit is contained in:
Andrey Meshkov
2020-02-12 15:04:25 +03:00
parent 8d039c572f
commit d8d48c5386
6 changed files with 88 additions and 247 deletions

View File

@@ -93,10 +93,9 @@ func (s *Server) handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
s.conf.ConfigModified()
if newconfig.Enabled {
staticIP, err := hasStaticIP(newconfig.InterfaceName)
staticIP, err := HasStaticIP(newconfig.InterfaceName)
if !staticIP && err == nil {
err = setStaticIP(newconfig.InterfaceName)
err = SetStaticIP(newconfig.InterfaceName)
if err != nil {
httpError(r, w, http.StatusInternalServerError, "Failed to configure static IP: %s", err)
return
@@ -122,7 +121,7 @@ type netInterfaceJSON struct {
func (s *Server) handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) {
response := map[string]interface{}{}
ifaces, err := getValidNetInterfaces()
ifaces, err := GetValidNetInterfaces()
if err != nil {
httpError(r, w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err)
return
@@ -213,14 +212,14 @@ func (s *Server) handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Reque
othSrv["found"] = foundVal
staticIP := map[string]interface{}{}
isStaticIP, err := hasStaticIP(interfaceName)
isStaticIP, err := HasStaticIP(interfaceName)
staticIPStatus := "yes"
if err != nil {
staticIPStatus = "error"
staticIP["error"] = err.Error()
} else if !isStaticIP {
staticIPStatus = "no"
staticIP["ip"] = getFullIP(interfaceName)
staticIP["ip"] = GetFullIP(interfaceName)
}
staticIP["static"] = staticIPStatus