Documentation ¶
Index ¶
- Constants
- func CheckIfOtherDHCPServersPresentV4(ifaceName string) (bool, error)
- func CheckIfOtherDHCPServersPresentV6(ifaceName string) (bool, error)
- func HasStaticIP(ifaceName string) (bool, error)
- func SetStaticIP(ifaceName string) error
- type DHCPServer
- type Lease
- type OnLeaseChangedT
- type Server
- func (s *Server) AddStaticLease(lease Lease) error
- func (s *Server) CheckConfig(config ServerConfig) error
- func (s *Server) FindMACbyIP(ip net.IP) net.HardwareAddr
- func (s *Server) Leases(flags int) []Lease
- func (s *Server) SetOnLeaseChanged(onLeaseChanged OnLeaseChangedT)
- func (s *Server) Start() error
- func (s *Server) Stop()
- func (s *Server) WriteDiskConfig(c *ServerConfig)
- type ServerConfig
- type ServerInterface
- type V4ServerConf
- type V6ServerConf
Constants ¶
const ( LeaseChangedAdded = iota LeaseChangedAddedStatic LeaseChangedRemovedStatic LeaseChangedDBStore )
flags for onLeaseChanged()
const ( LeasesDynamic = 1 LeasesStatic = 2 LeasesAll = LeasesDynamic | LeasesStatic )
flags for Leases() function
Variables ¶
This section is empty.
Functions ¶
func CheckIfOtherDHCPServersPresentV4 ¶
CheckIfOtherDHCPServersPresentV4 sends a DHCP request to the specified network interface, and waits for a response for a period defined by defaultDiscoverTime
func CheckIfOtherDHCPServersPresentV6 ¶
CheckIfOtherDHCPServersPresentV6 sends a DHCP request to the specified network interface, and waits for a response for a period defined by defaultDiscoverTime
func HasStaticIP ¶
Check if network interface has a static IP configured Supports: Raspbian.
func SetStaticIP ¶
Set a static IP for the specified network interface
Types ¶
type DHCPServer ¶
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() }
DHCPServer - DHCP server interface
type Lease ¶
type Lease struct { HWAddr net.HardwareAddr `json:"mac"` IP net.IP `json:"ip"` Hostname string `json:"hostname"` // Lease expiration time // 1: static lease Expiry time.Time `json:"expires"` }
Lease contains the necessary information about a DHCP lease
type OnLeaseChangedT ¶
type OnLeaseChangedT func(flags int)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server - the current state of the DHCP server
func (*Server) AddStaticLease ¶
AddStaticLease - add static v4 lease
func (*Server) CheckConfig ¶
func (s *Server) CheckConfig(config ServerConfig) error
CheckConfig checks the configuration
func (*Server) FindMACbyIP ¶
func (s *Server) FindMACbyIP(ip net.IP) net.HardwareAddr
FindMACbyIP - find a MAC address by IP address in the currently active DHCP leases
func (*Server) SetOnLeaseChanged ¶
func (s *Server) SetOnLeaseChanged(onLeaseChanged OnLeaseChangedT)
SetOnLeaseChanged - set callback
func (*Server) WriteDiskConfig ¶
func (s *Server) WriteDiskConfig(c *ServerConfig)
WriteDiskConfig - write configuration
type ServerConfig ¶
type ServerConfig struct { Enabled bool `yaml:"enabled"` InterfaceName string `yaml:"interface_name"` Conf4 V4ServerConf `yaml:"dhcpv4"` Conf6 V6ServerConf `yaml:"dhcpv6"` WorkDir string `yaml:"-"` DBFilePath string `yaml:"-"` // path to DB file // Called when the configuration is changed by HTTP request ConfigModified func() `yaml:"-"` // Register an HTTP handler HTTPRegister func(string, string, func(http.ResponseWriter, *http.Request)) `yaml:"-"` }
ServerConfig - DHCP server configuration field ordering is important -- yaml fields will mirror ordering from here
type ServerInterface ¶
type ServerInterface interface { Leases(flags int) []Lease SetOnLeaseChanged(onLeaseChanged OnLeaseChangedT) }
type V4ServerConf ¶
type V4ServerConf struct { Enabled bool `yaml:"-"` InterfaceName string `yaml:"-"` GatewayIP string `yaml:"gateway_ip"` SubnetMask string `yaml:"subnet_mask"` // The first & the last IP address for dynamic leases // Bytes [0..2] of the last allowed IP address must match the first IP 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 // 0: disable ICMPTimeout uint32 `yaml:"icmp_timeout_msec"` // Custom Options. // // Option with arbitrary hexadecimal data: // DEC_CODE hex HEX_DATA // where DEC_CODE is a decimal DHCPv4 option code in range [1..255] // // Option with IP data (only 1 IP is supported): // DEC_CODE ip IP_ADDR Options []string `yaml:"options"` // contains filtered or unexported fields }
V4ServerConf - server configuration
type V6ServerConf ¶
type V6ServerConf struct { Enabled bool `yaml:"-"` InterfaceName string `yaml:"-"` // The first IP address for dynamic leases // The last allowed IP address ends with 0xff byte RangeStart string `yaml:"range_start"` LeaseDuration uint32 `yaml:"lease_duration"` // in seconds RaSlaacOnly bool `yaml:"ra_slaac_only"` // send ICMPv6.RA packets without MO flags RaAllowSlaac bool `yaml:"ra_allow_slaac"` // send ICMPv6.RA packets with MO flags // contains filtered or unexported fields }
V6ServerConf - server configuration