Skip to content

Commit

Permalink
dhcpd: imp code, naming
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Aug 23, 2022
1 parent 7a71292 commit fe03c8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions internal/dhcpd/v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/dhcpd/v4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fe03c8e

Please sign in to comment.