- dhcp: store lease data in database on each change rather than once on app stop
This commit is contained in:
parent
eff23f3b62
commit
0b3ba82242
|
@ -207,8 +207,6 @@ func (s *Server) Stop() error {
|
||||||
s.cond.Wait()
|
s.cond.Wait()
|
||||||
}
|
}
|
||||||
s.mutex.Unlock()
|
s.mutex.Unlock()
|
||||||
|
|
||||||
s.dbStore()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,6 +248,7 @@ func (s *Server) reserveLease(p dhcp4.Packet) (*Lease, error) {
|
||||||
s.leases[i].IP, hwaddr, s.leases[i].HWAddr, s.leases[i].Expiry)
|
s.leases[i].IP, hwaddr, s.leases[i].HWAddr, s.leases[i].Expiry)
|
||||||
lease.IP = s.leases[i].IP
|
lease.IP = s.leases[i].IP
|
||||||
s.leases[i] = lease
|
s.leases[i] = lease
|
||||||
|
s.dbStore()
|
||||||
|
|
||||||
s.reserveIP(lease.IP, hwaddr)
|
s.reserveIP(lease.IP, hwaddr)
|
||||||
return lease, nil
|
return lease, nil
|
||||||
|
@ -258,6 +257,7 @@ func (s *Server) reserveLease(p dhcp4.Packet) (*Lease, error) {
|
||||||
log.Tracef("Assigning to %s IP address %s", hwaddr, ip.String())
|
log.Tracef("Assigning to %s IP address %s", hwaddr, ip.String())
|
||||||
lease.IP = ip
|
lease.IP = ip
|
||||||
s.leases = append(s.leases, lease)
|
s.leases = append(s.leases, lease)
|
||||||
|
s.dbStore()
|
||||||
return lease, nil
|
return lease, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,6 +410,7 @@ func (s *Server) blacklistLease(lease *Lease) {
|
||||||
lease.HWAddr = hw
|
lease.HWAddr = hw
|
||||||
lease.Hostname = ""
|
lease.Hostname = ""
|
||||||
lease.Expiry = time.Now().Add(s.leaseTime)
|
lease.Expiry = time.Now().Add(s.leaseTime)
|
||||||
|
s.dbStore()
|
||||||
s.leasesLock.Unlock()
|
s.leasesLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue