* clients: multiple IP, CIDR, MAC addresses

+ /clients/find
* clients: move code for config read/write
* clients: move HTTP handlers
This commit is contained in:
Simon Zolin
2019-09-26 16:40:52 +03:00
parent db703283ba
commit 71ce0c6da9
7 changed files with 543 additions and 355 deletions

View File

@@ -684,6 +684,21 @@ func (s *Server) FindIPbyMAC(mac net.HardwareAddr) net.IP {
return nil
}
// FindMACbyIP - find a MAC address by IP address in the currently active DHCP leases
func (s *Server) FindMACbyIP(ip net.IP) net.HardwareAddr {
now := time.Now().Unix()
s.leasesLock.RLock()
defer s.leasesLock.RUnlock()
for _, l := range s.leases {
if l.Expiry.Unix() > now && l.IP.Equal(ip) {
return l.HWAddr
}
}
return nil
}
// Reset internal state
func (s *Server) reset() {
s.leasesLock.Lock()