dhcpd: imp naming
This commit is contained in:
parent
e2d9ed0832
commit
b6e3b62ed4
|
@ -88,8 +88,8 @@ func leasesToStatic(leases []*Lease) (static []*leaseStatic) {
|
|||
return static
|
||||
}
|
||||
|
||||
// Unwrap converts leaseStatic to Lease or returns error.
|
||||
func (l *leaseStatic) Unwrap() (lease *Lease, err error) {
|
||||
// toLease converts leaseStatic to Lease or returns error.
|
||||
func (l *leaseStatic) toLease() (lease *Lease, err error) {
|
||||
addr, err := net.ParseMAC(l.HWAddr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't parse MAC address: %w", err)
|
||||
|
@ -577,7 +577,7 @@ func (s *server) handleDHCPAddStaticLease(w http.ResponseWriter, r *http.Request
|
|||
srv = s.srv6
|
||||
}
|
||||
|
||||
lease, err := l.Unwrap()
|
||||
lease, err := l.toLease()
|
||||
if err != nil {
|
||||
aghhttp.Error(r, w, http.StatusBadRequest, "parsing: %s", err)
|
||||
|
||||
|
@ -616,7 +616,7 @@ func (s *server) handleDHCPRemoveStaticLease(w http.ResponseWriter, r *http.Requ
|
|||
srv = s.srv6
|
||||
}
|
||||
|
||||
lease, err := l.Unwrap()
|
||||
lease, err := l.toLease()
|
||||
if err != nil {
|
||||
aghhttp.Error(r, w, http.StatusBadRequest, "parsing: %s", err)
|
||||
|
||||
|
|
|
@ -259,8 +259,10 @@ func (s *v4Server) rmLeaseByIndex(i int) {
|
|||
// Return error if a static lease is found
|
||||
func (s *v4Server) rmDynamicLease(lease *Lease) (err error) {
|
||||
for i, l := range s.leases {
|
||||
isStatic := l.IsStatic
|
||||
|
||||
if bytes.Equal(l.HWAddr, lease.HWAddr) || l.IP == lease.IP {
|
||||
if l.IsStatic {
|
||||
if isStatic {
|
||||
return errors.Error("static lease already exists")
|
||||
}
|
||||
|
||||
|
@ -272,7 +274,7 @@ func (s *v4Server) rmDynamicLease(lease *Lease) (err error) {
|
|||
l = s.leases[i]
|
||||
}
|
||||
|
||||
if !l.IsStatic && l.Hostname == lease.Hostname {
|
||||
if !isStatic && l.Hostname == lease.Hostname {
|
||||
l.Hostname = ""
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue