mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-28 01:42:26 +03:00
332621f268
Squashed commit of the following: commit 425f1bd28074d22890629d06f43257e0353ce3d5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Feb 8 20:15:58 2024 +0300 all: upd deps, go, scripts
52 lines
994 B
Go
52 lines
994 B
Go
package dhcpsvc
|
|
|
|
import (
|
|
"bytes"
|
|
"net"
|
|
"net/netip"
|
|
"slices"
|
|
"time"
|
|
)
|
|
|
|
// Lease is a DHCP lease.
|
|
//
|
|
// TODO(e.burkov): Consider moving it to [agh], since it also may be needed in
|
|
// [websvc].
|
|
//
|
|
// TODO(e.burkov): Add validation method.
|
|
type Lease struct {
|
|
// IP is the IP address leased to the client.
|
|
IP netip.Addr
|
|
|
|
// Expiry is the expiration time of the lease.
|
|
Expiry time.Time
|
|
|
|
// Hostname of the client.
|
|
Hostname string
|
|
|
|
// HWAddr is the physical hardware address (MAC address).
|
|
HWAddr net.HardwareAddr
|
|
|
|
// IsStatic defines if the lease is static.
|
|
IsStatic bool
|
|
}
|
|
|
|
// Clone returns a deep copy of l.
|
|
func (l *Lease) Clone() (clone *Lease) {
|
|
if l == nil {
|
|
return nil
|
|
}
|
|
|
|
return &Lease{
|
|
Expiry: l.Expiry,
|
|
Hostname: l.Hostname,
|
|
HWAddr: slices.Clone(l.HWAddr),
|
|
IP: l.IP,
|
|
IsStatic: l.IsStatic,
|
|
}
|
|
}
|
|
|
|
// compareLeaseMAC compares two [Lease]s by hardware address.
|
|
func compareLeaseMAC(a, b *Lease) (res int) {
|
|
return bytes.Compare(a.HWAddr, b.HWAddr)
|
|
}
|