Pull request 1755: imp-home-gocyclo

Updates .

Squashed commit of the following:

commit 9db0df757ef4e61a066264948436d465a720e2ec
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Mar 1 13:24:12 2023 +0300

    home: imp docs

commit d1e419962d7b0fa2347e141f600c89854bf7ebb2
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Mar 1 13:19:42 2023 +0300

    home: imp docs, names

commit 176368649729e6949ef2f7325aafa336f4725d88
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Feb 28 20:45:50 2023 +0300

    all: imp cyclo, docs; use netip.Addr
This commit is contained in:
Ainar Garipov 2023-03-01 13:27:24 +03:00
parent bb226434f8
commit f13dc59bfa
12 changed files with 291 additions and 219 deletions
internal/dhcpd

View file

@ -6,6 +6,7 @@ import (
"bytes"
"fmt"
"net"
"net/netip"
"sync"
"time"
@ -107,21 +108,26 @@ func (s *v6Server) getLeasesRef() []*Lease {
return s.leases
}
// FindMACbyIP - find a MAC address by IP address in the currently active DHCP leases
func (s *v6Server) FindMACbyIP(ip net.IP) net.HardwareAddr {
now := time.Now().Unix()
// FindMACbyIP implements the [Interface] for *v6Server.
func (s *v6Server) FindMACbyIP(ip netip.Addr) (mac net.HardwareAddr) {
now := time.Now()
s.leasesLock.Lock()
defer s.leasesLock.Unlock()
if !ip.Is6() {
return nil
}
netIP := ip.AsSlice()
for _, l := range s.leases {
if l.IP.Equal(ip) {
unix := l.Expiry.Unix()
if unix > now || unix == leaseExpireStatic {
if l.IP.Equal(netIP) {
if l.Expiry.After(now) || l.IsStatic() {
return l.HWAddr
}
}
}
return nil
}