Documentation ¶
Overview ¶
Package dhcpd provides a DHCP server.
Index ¶
- Constants
- type DHCPServer
- type GetLeasesFlags
- type Lease
- type OnLeaseChangedT
- type Server
- func (s *Server) AddStaticLease(l *Lease) error
- func (s *Server) Enabled() (ok bool)
- func (s *Server) FindMACbyIP(ip net.IP) net.HardwareAddr
- func (s *Server) Leases(flags GetLeasesFlags) (leases []*Lease)
- func (s *Server) SetOnLeaseChanged(onLeaseChanged OnLeaseChangedT)
- func (s *Server) Start() (err error)
- func (s *Server) Stop() (err error)
- func (s *Server) WriteDiskConfig(c *ServerConfig)
- type ServerConfig
- type ServerInterface
- type V4ServerConf
- type V6ServerConf
Constants ¶
const ( LeaseChangedAdded = iota LeaseChangedAddedStatic LeaseChangedRemovedStatic LeaseChangedRemovedAll LeaseChangedDBStore )
flags for onLeaseChanged()
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DHCPServer ¶
type DHCPServer interface { // ResetLeases resets leases. ResetLeases(leases []*Lease) (err error) // GetLeases returns deep clones of the current leases. GetLeases(flags GetLeasesFlags) (leases []*Lease) // AddStaticLease - add a static lease AddStaticLease(l *Lease) (err error) // RemoveStaticLease - remove a static lease RemoveStaticLease(l *Lease) (err 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() (err error) // Stop - stop server Stop() (err error) // contains filtered or unexported methods }
DHCPServer - DHCP server interface
type GetLeasesFlags ¶ added in v0.107.0
type GetLeasesFlags uint8
GetLeasesFlags are the flags for GetLeases.
const ( LeasesDynamic GetLeasesFlags = 0b0001 LeasesStatic GetLeasesFlags = 0b0010 LeasesAll = LeasesDynamic | LeasesStatic )
GetLeasesFlags values
type Lease ¶
type Lease struct { // Expiry is the expiration time of the lease. The unix timestamp value // of 1 means that this is a static lease. Expiry time.Time `json:"expires"` Hostname string `json:"hostname"` HWAddr net.HardwareAddr `json:"mac"` IP net.IP `json:"ip"` }
Lease contains the necessary information about a DHCP lease
func (*Lease) IsBlocklisted ¶ added in v0.107.0
IsBlocklisted returns true if the lease is blocklisted.
TODO(a.garipov): Just make it a boolean field.
func (*Lease) IsStatic ¶ added in v0.106.0
IsStatic returns true if the lease is static.
TODO(a.garipov): Just make it a boolean field.
func (Lease) MarshalJSON ¶ added in v0.105.0
MarshalJSON implements the json.Marshaler interface for Lease.
func (*Lease) UnmarshalJSON ¶ added in v0.105.0
UnmarshalJSON implements the json.Unmarshaler interface for *Lease.
type OnLeaseChangedT ¶
type OnLeaseChangedT func(flags int)
OnLeaseChangedT is a callback for lease changes.
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) 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) Leases ¶
func (s *Server) Leases(flags GetLeasesFlags) (leases []*Lease)
Leases returns the list of active IPv4 and IPv6 DHCP leases. It's safe for concurrent use.
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 { Enabled() (ok bool) Leases(flags GetLeasesFlags) (leases []*Lease) SetOnLeaseChanged(onLeaseChanged OnLeaseChangedT) }
ServerInterface is an interface for servers.
type V4ServerConf ¶
type V4ServerConf struct { Enabled bool `yaml:"-" json:"-"` InterfaceName string `yaml:"-" json:"-"` GatewayIP net.IP `yaml:"gateway_ip" json:"gateway_ip"` SubnetMask net.IP `yaml:"subnet_mask" json:"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 net.IP `yaml:"range_start" json:"range_start"` RangeEnd net.IP `yaml:"range_end" json:"range_end"` LeaseDuration uint32 `yaml:"lease_duration" json:"lease_duration"` // in seconds // IP conflict detector: time (ms) to wait for ICMP reply // 0: disable ICMPTimeout uint32 `yaml:"icmp_timeout_msec" json:"-"` // 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" json:"-"` // contains filtered or unexported fields }
V4ServerConf - server configuration
type V6ServerConf ¶
type V6ServerConf struct { Enabled bool `yaml:"-" json:"-"` InterfaceName string `yaml:"-" json:"-"` // The first IP address for dynamic leases // The last allowed IP address ends with 0xff byte RangeStart net.IP `yaml:"range_start" json:"range_start"` LeaseDuration uint32 `yaml:"lease_duration" json:"lease_duration"` // in seconds RASLAACOnly bool `yaml:"ra_slaac_only" json:"-"` // send ICMPv6.RA packets without MO flags RAAllowSLAAC bool `yaml:"ra_allow_slaac" json:"-"` // send ICMPv6.RA packets with MO flags // contains filtered or unexported fields }
V6ServerConf - server configuration