From c82b18f1408d9e353aec517f4283e2f3eb260890 Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Mon, 20 Mar 2023 13:56:31 +0300 Subject: [PATCH] all: imp code --- internal/aghnet/hostgen.go | 5 +---- internal/aghnet/hostgen_test.go | 14 +------------- internal/dhcpd/v6_unix.go | 4 +--- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/internal/aghnet/hostgen.go b/internal/aghnet/hostgen.go index eae43b58..fde02cab 100644 --- a/internal/aghnet/hostgen.go +++ b/internal/aghnet/hostgen.go @@ -22,14 +22,11 @@ func GenerateHostname(ip netip.Addr) (hostname string) { } ip = ip.Unmap() + hostname = ip.StringExpanded() if ip.Is4() { - hostname = ip.String() - return strings.Replace(hostname, ".", "-", -1) } - hostname = ip.StringExpanded() - return strings.Replace(hostname, ":", "-", -1) } diff --git a/internal/aghnet/hostgen_test.go b/internal/aghnet/hostgen_test.go index b6ed6190..5896720d 100644 --- a/internal/aghnet/hostgen_test.go +++ b/internal/aghnet/hostgen_test.go @@ -36,18 +36,6 @@ func TestGenerateHostName(t *testing.T) { }) t.Run("invalid", func(t *testing.T) { - testCases := []struct { - name string - ip netip.Addr - }{{ - name: "nil", - ip: netip.Addr{}, - }} - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - assert.Panics(t, func() { GenerateHostname(tc.ip) }) - }) - } + assert.Panics(t, func() { GenerateHostname(netip.Addr{}) }) }) } diff --git a/internal/dhcpd/v6_unix.go b/internal/dhcpd/v6_unix.go index 4bcf258d..95bd33ad 100644 --- a/internal/dhcpd/v6_unix.go +++ b/internal/dhcpd/v6_unix.go @@ -309,9 +309,7 @@ func (s *v6Server) reserveLease(mac net.HardwareAddr) *Lease { s.leasesLock.Lock() defer s.leasesLock.Unlock() - var ip net.IP - copy(ip, s.conf.ipStart) - ip = s.findFreeIP() + ip := s.findFreeIP() if ip == nil { i := s.findExpiredLease() if i < 0 {