From b9c0b5535694fea37fad8fc85e3b1e897860f6ea Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Wed, 6 Nov 2019 13:04:01 +0300 Subject: [PATCH 1/2] * dhcp: now static leases functionality works before DHCP is started --- dhcpd/dhcpd.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/dhcpd/dhcpd.go b/dhcpd/dhcpd.go index ac90050f..0fb38f24 100644 --- a/dhcpd/dhcpd.go +++ b/dhcpd/dhcpd.go @@ -100,9 +100,14 @@ func (s *Server) CheckConfig(config ServerConfig) error { func Create(config ServerConfig) *Server { s := Server{} s.conf = config + s.conf.DBFilePath = filepath.Join(config.WorkDir, dbFilename) if s.conf.HTTPRegister != nil { 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 } @@ -112,7 +117,6 @@ func (s *Server) Init(config ServerConfig) error { if err != nil { return err } - s.dbLoad() return nil } @@ -178,7 +182,7 @@ func (s *Server) setConfig(config ServerConfig) error { s.conf.WorkDir = oldconf.WorkDir s.conf.HTTPRegister = oldconf.HTTPRegister s.conf.ConfigModified = oldconf.ConfigModified - s.conf.DBFilePath = filepath.Join(config.WorkDir, dbFilename) + s.conf.DBFilePath = oldconf.DBFilePath 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) func (s *Server) AddStaticLease(l Lease) error { - if s.IPpool == nil { - return fmt.Errorf("DHCP server isn't started") - } - if len(l.IP) != 4 { return fmt.Errorf("Invalid IP") } @@ -629,10 +629,6 @@ func (s *Server) rmLease(l Lease) error { // RemoveStaticLease removes a static lease (thread-safe) func (s *Server) RemoveStaticLease(l Lease) error { - if s.IPpool == nil { - return fmt.Errorf("DHCP server isn't started") - } - if len(l.IP) != 4 { return fmt.Errorf("Invalid IP") } @@ -675,10 +671,6 @@ func (s *Server) StaticLeases() []Lease { s.leasesLock.Lock() defer s.leasesLock.Unlock() - if s.IPpool == nil { - s.dbLoad() - } - var result []Lease for _, lease := range s.leases { if lease.Expiry.Unix() == 1 { From 60cbb93488ec3fa1ca720d88e79ae48130ac9461 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Wed, 18 Dec 2019 13:40:05 +0300 Subject: [PATCH 2/2] + client: show DHCP static leases all the time --- client/src/components/Settings/Dhcp/index.js | 74 ++++++++++---------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/client/src/components/Settings/Dhcp/index.js b/client/src/components/Settings/Dhcp/index.js index 959922ce..9aba37da 100644 --- a/client/src/components/Settings/Dhcp/index.js +++ b/client/src/components/Settings/Dhcp/index.js @@ -219,46 +219,44 @@ class Dhcp extends Component { {dhcp.config.enabled && ( - - -
-
- -
+ +
+
+
- - -
-
- -
-
- -
-
-
- +
+
)} + +
+
+ +
+
+ +
+
+
)}