Merge: DHCP: show static leases all the time
Closes #1023 * commit '60cbb93488ec3fa1ca720d88e79ae48130ac9461': + client: show DHCP static leases all the time * dhcp: now static leases functionality works before DHCP is started
This commit is contained in:
commit
24e8ef6b32
@ -219,7 +219,6 @@ class Dhcp extends Component {
|
|||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
{dhcp.config.enabled && (
|
{dhcp.config.enabled && (
|
||||||
<Fragment>
|
|
||||||
<Card
|
<Card
|
||||||
title={t('dhcp_leases')}
|
title={t('dhcp_leases')}
|
||||||
bodyType="card-body box-body--settings"
|
bodyType="card-body box-body--settings"
|
||||||
@ -230,6 +229,7 @@ class Dhcp extends Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
)}
|
||||||
<Card
|
<Card
|
||||||
title={t('dhcp_static_leases')}
|
title={t('dhcp_static_leases')}
|
||||||
bodyType="card-body box-body--settings"
|
bodyType="card-body box-body--settings"
|
||||||
@ -260,8 +260,6 @@ class Dhcp extends Component {
|
|||||||
</Fragment>
|
</Fragment>
|
||||||
)}
|
)}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)}
|
|
||||||
</Fragment>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,9 +100,14 @@ func (s *Server) CheckConfig(config ServerConfig) error {
|
|||||||
func Create(config ServerConfig) *Server {
|
func Create(config ServerConfig) *Server {
|
||||||
s := Server{}
|
s := Server{}
|
||||||
s.conf = config
|
s.conf = config
|
||||||
|
s.conf.DBFilePath = filepath.Join(config.WorkDir, dbFilename)
|
||||||
if s.conf.HTTPRegister != nil {
|
if s.conf.HTTPRegister != nil {
|
||||||
s.registerHandlers()
|
s.registerHandlers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we can't delay database loading until DHCP server is started,
|
||||||
|
// because we need static leases functionality available beforehand
|
||||||
|
s.dbLoad()
|
||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +117,6 @@ func (s *Server) Init(config ServerConfig) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.dbLoad()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +182,7 @@ func (s *Server) setConfig(config ServerConfig) error {
|
|||||||
s.conf.WorkDir = oldconf.WorkDir
|
s.conf.WorkDir = oldconf.WorkDir
|
||||||
s.conf.HTTPRegister = oldconf.HTTPRegister
|
s.conf.HTTPRegister = oldconf.HTTPRegister
|
||||||
s.conf.ConfigModified = oldconf.ConfigModified
|
s.conf.ConfigModified = oldconf.ConfigModified
|
||||||
s.conf.DBFilePath = filepath.Join(config.WorkDir, dbFilename)
|
s.conf.DBFilePath = oldconf.DBFilePath
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,10 +569,6 @@ func (s *Server) handleDecline(p dhcp4.Packet, options dhcp4.Options) dhcp4.Pack
|
|||||||
|
|
||||||
// AddStaticLease adds a static lease (thread-safe)
|
// AddStaticLease adds a static lease (thread-safe)
|
||||||
func (s *Server) AddStaticLease(l Lease) error {
|
func (s *Server) AddStaticLease(l Lease) error {
|
||||||
if s.IPpool == nil {
|
|
||||||
return fmt.Errorf("DHCP server isn't started")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(l.IP) != 4 {
|
if len(l.IP) != 4 {
|
||||||
return fmt.Errorf("Invalid IP")
|
return fmt.Errorf("Invalid IP")
|
||||||
}
|
}
|
||||||
@ -629,10 +629,6 @@ func (s *Server) rmLease(l Lease) error {
|
|||||||
|
|
||||||
// RemoveStaticLease removes a static lease (thread-safe)
|
// RemoveStaticLease removes a static lease (thread-safe)
|
||||||
func (s *Server) RemoveStaticLease(l Lease) error {
|
func (s *Server) RemoveStaticLease(l Lease) error {
|
||||||
if s.IPpool == nil {
|
|
||||||
return fmt.Errorf("DHCP server isn't started")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(l.IP) != 4 {
|
if len(l.IP) != 4 {
|
||||||
return fmt.Errorf("Invalid IP")
|
return fmt.Errorf("Invalid IP")
|
||||||
}
|
}
|
||||||
@ -675,10 +671,6 @@ func (s *Server) StaticLeases() []Lease {
|
|||||||
s.leasesLock.Lock()
|
s.leasesLock.Lock()
|
||||||
defer s.leasesLock.Unlock()
|
defer s.leasesLock.Unlock()
|
||||||
|
|
||||||
if s.IPpool == nil {
|
|
||||||
s.dbLoad()
|
|
||||||
}
|
|
||||||
|
|
||||||
var result []Lease
|
var result []Lease
|
||||||
for _, lease := range s.leases {
|
for _, lease := range s.leases {
|
||||||
if lease.Expiry.Unix() == 1 {
|
if lease.Expiry.Unix() == 1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user