mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2026-08-31 09:39:44 +00:00
dhcpsvc: imp code, docs
Some checks failed
build / test (macOS-latest) (push) Has been cancelled
build / test (ubuntu-latest) (push) Has been cancelled
build / test (windows-latest) (push) Has been cancelled
lint / go-lint (push) Has been cancelled
lint / eslint (push) Has been cancelled
build / build-release (push) Has been cancelled
build / notify (push) Has been cancelled
lint / notify (push) Has been cancelled
Some checks failed
build / test (macOS-latest) (push) Has been cancelled
build / test (ubuntu-latest) (push) Has been cancelled
build / test (windows-latest) (push) Has been cancelled
lint / go-lint (push) Has been cancelled
lint / eslint (push) Has been cancelled
build / build-release (push) Has been cancelled
build / notify (push) Has been cancelled
lint / notify (push) Has been cancelled
This commit is contained in:
parent
5e39e4aba2
commit
5dfd12df4f
5 changed files with 27 additions and 14 deletions
|
|
@ -6,10 +6,12 @@ import (
|
||||||
|
|
||||||
// Database is the interface for storing DHCP leases.
|
// Database is the interface for storing DHCP leases.
|
||||||
type Database interface {
|
type Database interface {
|
||||||
// Load loads leases from the database. It must be safe for concurrent use.
|
// Load loads leases from the database. If err is not nil, leases must be
|
||||||
|
// nil. It must be safe for concurrent use.
|
||||||
Load(ctx context.Context) (leases []*Lease, err error)
|
Load(ctx context.Context) (leases []*Lease, err error)
|
||||||
|
|
||||||
// Store stores leases to the database. It must be safe for concurrent use.
|
// Store stores leases to the database. leases must be valid. It must be
|
||||||
|
// safe for concurrent use.
|
||||||
Store(ctx context.Context, leases []*Lease) (err error)
|
Store(ctx context.Context, leases []*Lease) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -223,6 +223,7 @@ func TestDHCPServer_ServeEther4_release(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(e.burkov): Increase maintainability index.
|
||||||
func TestDHCPServer_ServeEther4_requestSelecting(t *testing.T) {
|
func TestDHCPServer_ServeEther4_requestSelecting(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ var (
|
||||||
testIPv6Static = netip.MustParseAddr("2001:db8::65")
|
testIPv6Static = netip.MustParseAddr("2001:db8::65")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO(e.burkov): Increase maintainability index.
|
||||||
func TestDHCPServer_ServeEther6_solicit(t *testing.T) {
|
func TestDHCPServer_ServeEther6_solicit(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
@ -215,6 +216,8 @@ func TestDHCPServer_ServeEther6_solicit(t *testing.T) {
|
||||||
|
|
||||||
// TODO(e.burkov): Add tests for REQUEST causing errors. This would require a
|
// TODO(e.burkov): Add tests for REQUEST causing errors. This would require a
|
||||||
// custom implementation of the address checker at least.
|
// custom implementation of the address checker at least.
|
||||||
|
//
|
||||||
|
// TODO(e.burkov): Increase maintainability index.
|
||||||
func TestDHCPServer_ServeEther6_request(t *testing.T) {
|
func TestDHCPServer_ServeEther6_request(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,25 @@ type jsonLeasesData struct {
|
||||||
//
|
//
|
||||||
// TODO(e.burkov): Migrate to add DUID and IAID fields for DHCPv6 leases.
|
// TODO(e.burkov): Migrate to add DUID and IAID fields for DHCPv6 leases.
|
||||||
type jsonLease struct {
|
type jsonLease struct {
|
||||||
Expiry string `json:"expires"`
|
// Expiry is the expiration time of the lease in RFC 3339 format. It is
|
||||||
IP netip.Addr `json:"ip"`
|
// empty for static leases.
|
||||||
Hostname string `json:"hostname"`
|
Expiry string `json:"expires"`
|
||||||
HWAddr string `json:"mac"`
|
|
||||||
IsStatic bool `json:"static"`
|
// IP is the IP address leased to the client. It must not be empty.
|
||||||
|
IP netip.Addr `json:"ip"`
|
||||||
|
|
||||||
|
// Hostname is the hostname of the client.
|
||||||
|
Hostname string `json:"hostname"`
|
||||||
|
|
||||||
|
// HWAddr is the MAC address of the client. It must be a valid hardware
|
||||||
|
// address string according to [netutil.IsValidMACString].
|
||||||
|
HWAddr string `json:"mac"`
|
||||||
|
|
||||||
|
// IsStatic defines if the lease is static.
|
||||||
|
IsStatic bool `json:"static"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// compareNames returns the result of comparing the hostnames of dl and other
|
// compareNames returns the result of comparing the hostnames of jl and other
|
||||||
// lexicographically.
|
// lexicographically.
|
||||||
func (jl *jsonLease) compareNames(other *jsonLease) (res int) {
|
func (jl *jsonLease) compareNames(other *jsonLease) (res int) {
|
||||||
return strings.Compare(jl.Hostname, other.Hostname)
|
return strings.Compare(jl.Hostname, other.Hostname)
|
||||||
|
|
@ -71,7 +82,7 @@ func toJSONLease(l *Lease) (jl *jsonLease) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// toInternal converts dl to *Lease.
|
// toInternal converts jl to *Lease.
|
||||||
func (jl *jsonLease) toInternal() (l *Lease, err error) {
|
func (jl *jsonLease) toInternal() (l *Lease, err error) {
|
||||||
mac, err := net.ParseMAC(jl.HWAddr)
|
mac, err := net.ParseMAC(jl.HWAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -186,11 +186,7 @@ func (idx *leaseIndex) dbLoad(
|
||||||
) (err error) {
|
) (err error) {
|
||||||
leases, err := idx.database.Load(ctx)
|
leases, err := idx.database.Load(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if leases == nil {
|
return fmt.Errorf("loading leases: %w", err)
|
||||||
return fmt.Errorf("loading leases: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.ErrorContext(ctx, "loading leases", slogutil.KeyError, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
idx.addDBLeases(ctx, logger, leases, ifaces4, ifaces6)
|
idx.addDBLeases(ctx, logger, leases, ifaces4, ifaces6)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue