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