dhcpd: imp naming

This commit is contained in:
Stanislav Chzhen 2023-04-06 15:20:42 +03:00
parent e2d9ed0832
commit b6e3b62ed4
2 changed files with 8 additions and 6 deletions

View File

@ -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)

View File

@ -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 = ""
}
}