+ dhcp: /dhcp/status: return static leases
This commit is contained in:
parent
342699d933
commit
763b986955
2
dhcp.go
2
dhcp.go
|
@ -42,9 +42,11 @@ func convertLeases(inputLeases []dhcpd.Lease, includeExpires bool) []map[string]
|
||||||
func handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
|
func handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Tracef("%s %v", r.Method, r.URL)
|
log.Tracef("%s %v", r.Method, r.URL)
|
||||||
leases := convertLeases(dhcpServer.Leases(), true)
|
leases := convertLeases(dhcpServer.Leases(), true)
|
||||||
|
staticLeases := convertLeases(dhcpServer.StaticLeases(), false)
|
||||||
status := map[string]interface{}{
|
status := map[string]interface{}{
|
||||||
"config": config.DHCP,
|
"config": config.DHCP,
|
||||||
"leases": leases,
|
"leases": leases,
|
||||||
|
"static_leases": staticLeases,
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
|
@ -55,7 +55,9 @@ func (s *Server) dbLoad() {
|
||||||
numLeases := len(obj)
|
numLeases := len(obj)
|
||||||
for i := range obj {
|
for i := range obj {
|
||||||
|
|
||||||
if !ipInRange(s.leaseStart, s.leaseStop, obj[i].IP) {
|
if obj[i].Expiry != leaseExpireStatic &&
|
||||||
|
!ipInRange(s.leaseStart, s.leaseStop, obj[i].IP) {
|
||||||
|
|
||||||
log.Tracef("Skipping a lease with IP %s: not within current IP range", obj[i].IP)
|
log.Tracef("Skipping a lease with IP %s: not within current IP range", obj[i].IP)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -606,6 +606,25 @@ func (s *Server) Leases() []Lease {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StaticLeases returns the list of statically-configured DHCP leases (thread-safe)
|
||||||
|
func (s *Server) StaticLeases() []Lease {
|
||||||
|
s.Lock()
|
||||||
|
if s.IPpool == nil {
|
||||||
|
s.dbLoad()
|
||||||
|
}
|
||||||
|
s.Unlock()
|
||||||
|
|
||||||
|
var result []Lease
|
||||||
|
s.RLock()
|
||||||
|
for _, lease := range s.leases {
|
||||||
|
if lease.Expiry.Unix() == 1 {
|
||||||
|
result = append(result, *lease)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.RUnlock()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// Print information about the current leases
|
// Print information about the current leases
|
||||||
func (s *Server) printLeases() {
|
func (s *Server) printLeases() {
|
||||||
log.Tracef("Leases:")
|
log.Tracef("Leases:")
|
||||||
|
|
Loading…
Reference in New Issue