From fe03c8eda6c8ee35a10eb5f5a8e4d4d0c7373246 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Tue, 23 Aug 2022 18:16:16 +0300 Subject: [PATCH] dhcpd: imp code, naming --- internal/dhcpd/v4.go | 9 +++++---- internal/dhcpd/v4_test.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/dhcpd/v4.go b/internal/dhcpd/v4.go index b083be7e07d..4fb85552d98 100644 --- a/internal/dhcpd/v4.go +++ b/internal/dhcpd/v4.go @@ -20,6 +20,7 @@ import ( "github.com/go-ping/ping" "github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4/server4" + "golang.org/x/exp/slices" //lint:ignore SA1019 See the TODO in go.mod. "github.com/mdlayher/raw" @@ -279,9 +280,9 @@ func (s *v4Server) rmDynamicLease(lease *Lease) (err error) { return nil } -// DupHostnameErr is returned by addLease when the added lease has a not empty +// ErrDupHostname is returned by addLease when the added lease has a not empty // non-unique hostname. -const DupHostnameErr = errors.Error("hostname is not unique") +const ErrDupHostname = errors.Error("hostname is not unique") // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { @@ -300,7 +301,7 @@ func (s *v4Server) addLease(l *Lease) (err error) { if l.Hostname != "" { if s.leaseHosts.Has(l.Hostname) { - return DupHostnameErr + return ErrDupHostname } s.leaseHosts.Add(l.Hostname) @@ -522,7 +523,7 @@ func (s *v4Server) findExpiredLease() int { // reserveLease reserves a lease for a client by its MAC-address. It returns // nil if it couldn't allocate a new lease. func (s *v4Server) reserveLease(mac net.HardwareAddr) (l *Lease, err error) { - l = &Lease{HWAddr: netutil.CloneMAC(mac)} + l = &Lease{HWAddr: slices.Clone(mac)} l.IP = s.nextIP() if l.IP == nil { diff --git a/internal/dhcpd/v4_test.go b/internal/dhcpd/v4_test.go index df0f75c6dd7..e720d1137cb 100644 --- a/internal/dhcpd/v4_test.go +++ b/internal/dhcpd/v4_test.go @@ -87,7 +87,7 @@ func TestV4Server_leasing(t *testing.T) { HWAddr: anotherMAC, IP: anotherIP, }) - assert.ErrorIs(t, err, DupHostnameErr) + assert.ErrorIs(t, err, ErrDupHostname) }) t.Run("same_mac", func(t *testing.T) {