Merge: control: DHCP: don't return expired leases #584 #567

* commit 'ef789acee4ef990d9f93fa7f718f819b5bdea03d':
  * control: DHCP: don't return expired leases
This commit is contained in:
Simon Zolin 2019-03-20 12:58:03 +03:00
commit 8defb3b39e
1 changed files with 9 additions and 2 deletions

View File

@ -517,10 +517,17 @@ func (s *Server) handleDecline(p dhcp4.Packet, options dhcp4.Options) dhcp4.Pack
}
// Leases returns the list of current DHCP leases (thread-safe)
func (s *Server) Leases() []*Lease {
func (s *Server) Leases() []Lease {
var result []Lease
now := time.Now().Unix()
s.RLock()
result := s.leases
for _, lease := range s.leases {
if lease.Expiry.Unix() > now {
result = append(result, *lease)
}
}
s.RUnlock()
return result
}