2020-05-25 12:48:24 +03:00
|
|
|
package dhcpd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DHCPServer - DHCP server interface
|
|
|
|
type DHCPServer interface {
|
2020-05-28 15:15:42 +03:00
|
|
|
// ResetLeases - reset leases
|
2020-05-25 12:48:24 +03:00
|
|
|
ResetLeases(leases []*Lease)
|
2020-05-28 15:15:42 +03:00
|
|
|
// GetLeases - get leases
|
2020-05-25 12:48:24 +03:00
|
|
|
GetLeases(flags int) []Lease
|
2020-05-28 15:15:42 +03:00
|
|
|
// GetLeasesRef - get reference to leases array
|
2020-05-25 12:48:24 +03:00
|
|
|
GetLeasesRef() []*Lease
|
2020-05-28 15:15:42 +03:00
|
|
|
// AddStaticLease - add a static lease
|
2020-05-25 12:48:24 +03:00
|
|
|
AddStaticLease(lease Lease) error
|
2020-05-28 15:15:42 +03:00
|
|
|
// RemoveStaticLease - remove a static lease
|
2020-05-25 12:48:24 +03:00
|
|
|
RemoveStaticLease(l Lease) error
|
2020-05-28 15:15:42 +03:00
|
|
|
// FindMACbyIP - find a MAC address by IP address in the currently active DHCP leases
|
2020-05-25 12:48:24 +03:00
|
|
|
FindMACbyIP(ip net.IP) net.HardwareAddr
|
|
|
|
|
2020-05-28 15:15:42 +03:00
|
|
|
// WriteDiskConfig4 - copy disk configuration
|
2020-05-25 12:48:24 +03:00
|
|
|
WriteDiskConfig4(c *V4ServerConf)
|
2020-05-28 15:15:42 +03:00
|
|
|
// WriteDiskConfig6 - copy disk configuration
|
2020-05-25 12:48:24 +03:00
|
|
|
WriteDiskConfig6(c *V6ServerConf)
|
|
|
|
|
2020-05-28 15:15:42 +03:00
|
|
|
// Start - start server
|
2020-05-25 12:48:24 +03:00
|
|
|
Start() error
|
2020-05-28 15:15:42 +03:00
|
|
|
// Stop - stop server
|
2020-05-25 12:48:24 +03:00
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
// V4ServerConf - server configuration
|
|
|
|
type V4ServerConf struct {
|
2020-05-29 13:26:04 +03:00
|
|
|
Enabled bool `yaml:"-"`
|
|
|
|
InterfaceName string `yaml:"-"`
|
2020-05-25 12:48:24 +03:00
|
|
|
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
|
|
|
|
|
2020-05-28 15:15:42 +03:00
|
|
|
// IP conflict detector: time (ms) to wait for ICMP reply
|
2020-05-25 12:48:24 +03:00
|
|
|
// 0: disable
|
|
|
|
ICMPTimeout uint32 `yaml:"icmp_timeout_msec"`
|
|
|
|
|
2020-05-28 15:15:42 +03:00
|
|
|
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
|
2020-05-25 12:48:24 +03:00
|
|
|
|
2020-05-28 15:15:42 +03:00
|
|
|
// Server calls this function when leases data changes
|
2020-05-25 12:48:24 +03:00
|
|
|
notify func(uint32)
|
|
|
|
}
|
|
|
|
|
|
|
|
// V6ServerConf - server configuration
|
|
|
|
type V6ServerConf struct {
|
2020-05-29 13:26:04 +03:00
|
|
|
Enabled bool `yaml:"-"`
|
|
|
|
InterfaceName string `yaml:"-"`
|
2020-05-25 12:48:24 +03:00
|
|
|
RangeStart string `yaml:"range_start"`
|
|
|
|
LeaseDuration uint32 `yaml:"lease_duration"` // in seconds
|
|
|
|
|
2020-05-28 15:15:42 +03:00
|
|
|
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
|
2020-05-25 12:48:24 +03:00
|
|
|
|
2020-05-28 15:15:42 +03:00
|
|
|
// Server calls this function when leases data changes
|
2020-05-25 12:48:24 +03:00
|
|
|
notify func(uint32)
|
|
|
|
}
|