+ /dhcp/reset: clear leases

This commit is contained in:
Simon Zolin
2020-06-01 11:20:58 +03:00
parent 93b99039c0
commit 4b5f8537be
3 changed files with 56 additions and 13 deletions

View File

@@ -415,26 +415,50 @@ func (s *Server) handleDHCPRemoveStaticLease(w http.ResponseWriter, r *http.Requ
}
}
type resetJSON struct {
What string `json:"what"`
}
func (s *Server) handleReset(w http.ResponseWriter, r *http.Request) {
err := s.Stop()
req := resetJSON{}
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
log.Error("DHCP: Stop: %s", err)
httpError(r, w, http.StatusBadRequest, "json.Decode: %s", err)
return
}
switch req.What {
case "all":
err = s.Stop()
if err != nil {
log.Error("DHCP: Stop: %s", err)
}
oldconf := s.conf
s.conf = ServerConfig{}
s.conf.WorkDir = oldconf.WorkDir
s.conf.HTTPRegister = oldconf.HTTPRegister
s.conf.ConfigModified = oldconf.ConfigModified
s.conf.DBFilePath = oldconf.DBFilePath
s.conf.ConfigModified()
case "leases":
//
default:
httpError(r, w, http.StatusBadRequest, "unsupported 'what' value")
return
}
s.srv4.ResetLeases(nil)
s.srv6.ResetLeases(nil)
err = os.Remove(s.conf.DBFilePath)
if err != nil && !os.IsNotExist(err) {
log.Error("DHCP: os.Remove: %s: %s", s.conf.DBFilePath, err)
} else if err == nil {
log.Debug("DHCP: Deleted leases file")
}
oldconf := s.conf
s.conf = ServerConfig{}
s.conf.WorkDir = oldconf.WorkDir
s.conf.HTTPRegister = oldconf.HTTPRegister
s.conf.ConfigModified = oldconf.ConfigModified
s.conf.DBFilePath = oldconf.DBFilePath
s.conf.ConfigModified()
}
func (s *Server) registerHandlers() {