diff --git a/dhcpd/dhcpd_test.go b/dhcpd/dhcpd_test.go index 95eb6461..47ddef53 100644 --- a/dhcpd/dhcpd_test.go +++ b/dhcpd/dhcpd_test.go @@ -53,7 +53,7 @@ func TestDB(t *testing.T) { _ = os.Remove("leases.db") s.dbStore() - s.srv4.Reset() + s.srv4.ResetLeases(nil) s.dbLoad() diff --git a/dhcpd/server.go b/dhcpd/server.go index a8e15101..21d8560f 100644 --- a/dhcpd/server.go +++ b/dhcpd/server.go @@ -7,42 +7,52 @@ import ( // DHCPServer - DHCP server interface type DHCPServer interface { + // ResetLeases - reset leases ResetLeases(leases []*Lease) + // GetLeases - get leases GetLeases(flags int) []Lease + // GetLeasesRef - get reference to leases array GetLeasesRef() []*Lease + // AddStaticLease - add a static lease AddStaticLease(lease Lease) error + // RemoveStaticLease - remove a static lease RemoveStaticLease(l Lease) error + // FindMACbyIP - find a MAC address by IP address in the currently active DHCP leases FindMACbyIP(ip net.IP) net.HardwareAddr + // WriteDiskConfig4 - copy disk configuration WriteDiskConfig4(c *V4ServerConf) + // WriteDiskConfig6 - copy disk configuration WriteDiskConfig6(c *V6ServerConf) + // Start - start server Start() error + // Stop - stop server Stop() - Reset() } // V4ServerConf - server configuration type V4ServerConf struct { Enabled bool `yaml:"enabled"` - InterfaceName string `yaml:"interface_name"` // eth0, en0 and so on + InterfaceName string `yaml:"interface_name"` GatewayIP string `yaml:"gateway_ip"` SubnetMask string `yaml:"subnet_mask"` RangeStart string `yaml:"range_start"` RangeEnd string `yaml:"range_end"` LeaseDuration uint32 `yaml:"lease_duration"` // in seconds - // IP conflict detector: time (ms) to wait for ICMP reply. + // IP conflict detector: time (ms) to wait for ICMP reply // 0: disable ICMPTimeout uint32 `yaml:"icmp_timeout_msec"` - ipStart net.IP - ipEnd net.IP - leaseTime time.Duration - dnsIPAddrs []net.IP // IPv4 addresses to return to DHCP clients as DNS server addresses - routerIP net.IP - subnetMask net.IPMask + ipStart net.IP // starting IP address for dynamic leases + ipEnd net.IP // ending IP address for dynamic leases + leaseTime time.Duration // the time during which a dynamic lease is considered valid + dnsIPAddrs []net.IP // IPv4 addresses to return to DHCP clients as DNS server addresses + routerIP net.IP // value for Option Router + subnetMask net.IPMask // value for Option SubnetMask + // Server calls this function when leases data changes notify func(uint32) } @@ -53,9 +63,10 @@ type V6ServerConf struct { RangeStart string `yaml:"range_start"` LeaseDuration uint32 `yaml:"lease_duration"` // in seconds - ipStart net.IP - leaseTime time.Duration - dnsIPAddrs []net.IP // IPv6 addresses to return to DHCP clients as DNS server addresses + ipStart net.IP // starting IP address for dynamic leases + leaseTime time.Duration // the time during which a dynamic lease is considered valid + dnsIPAddrs []net.IP // IPv6 addresses to return to DHCP clients as DNS server addresses + // Server calls this function when leases data changes notify func(uint32) } diff --git a/dhcpd/v4.go b/dhcpd/v4.go index f56163ff..e80eb6e6 100644 --- a/dhcpd/v4.go +++ b/dhcpd/v4.go @@ -562,13 +562,6 @@ func (s *v4Server) Stop() { s.srv = nil } -// Reset - stop server -func (s *v4Server) Reset() { - s.leasesLock.Lock() - s.leases = nil - s.leasesLock.Unlock() -} - // Create DHCPv4 server func v4Create(conf V4ServerConf) (DHCPServer, error) { s := &v4Server{} diff --git a/dhcpd/v46_windows.go b/dhcpd/v46_windows.go index bf3c2781..152899b9 100644 --- a/dhcpd/v46_windows.go +++ b/dhcpd/v46_windows.go @@ -1,5 +1,7 @@ package dhcpd +// 'u-root/u-root' package, a dependency of 'insomniacslk/dhcp' package, doesn't build on Windows + import "net" type winServer struct { diff --git a/dhcpd/v6.go b/dhcpd/v6.go index cabe688e..cd23e250 100644 --- a/dhcpd/v6.go +++ b/dhcpd/v6.go @@ -606,13 +606,6 @@ func (s *v6Server) Stop() { s.srv = nil } -// Reset - stop server -func (s *v6Server) Reset() { - s.leasesLock.Lock() - s.leases = nil - s.leasesLock.Unlock() -} - // Create DHCPv6 server func v6Create(conf V6ServerConf) (DHCPServer, error) { s := &v6Server{}