all: imp code
This commit is contained in:
parent
27e5181200
commit
c82b18f140
|
@ -22,14 +22,11 @@ func GenerateHostname(ip netip.Addr) (hostname string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ip = ip.Unmap()
|
ip = ip.Unmap()
|
||||||
|
hostname = ip.StringExpanded()
|
||||||
|
|
||||||
if ip.Is4() {
|
if ip.Is4() {
|
||||||
hostname = ip.String()
|
|
||||||
|
|
||||||
return strings.Replace(hostname, ".", "-", -1)
|
return strings.Replace(hostname, ".", "-", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostname = ip.StringExpanded()
|
|
||||||
|
|
||||||
return strings.Replace(hostname, ":", "-", -1)
|
return strings.Replace(hostname, ":", "-", -1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,18 +36,6 @@ func TestGenerateHostName(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid", func(t *testing.T) {
|
t.Run("invalid", func(t *testing.T) {
|
||||||
testCases := []struct {
|
assert.Panics(t, func() { GenerateHostname(netip.Addr{}) })
|
||||||
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) })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,9 +309,7 @@ func (s *v6Server) reserveLease(mac net.HardwareAddr) *Lease {
|
||||||
s.leasesLock.Lock()
|
s.leasesLock.Lock()
|
||||||
defer s.leasesLock.Unlock()
|
defer s.leasesLock.Unlock()
|
||||||
|
|
||||||
var ip net.IP
|
ip := s.findFreeIP()
|
||||||
copy(ip, s.conf.ipStart)
|
|
||||||
ip = s.findFreeIP()
|
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
i := s.findExpiredLease()
|
i := s.findExpiredLease()
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
|
|
Loading…
Reference in New Issue