Documentation
¶
Index ¶
- Constants
- func IsRegisteredByIP(s LeaseStore, ip net.IP) (bool, error)
- type Config
- type Device
- type DeviceStore
- type Environment
- type Handler
- type Lease
- func GetAllLeases(s LeaseStore) ([]*Lease, error)
- func GetAllLeasesByMAC(s LeaseStore, mac net.HardwareAddr) ([]*Lease, error)
- func GetLeaseByIP(s LeaseStore, ip net.IP) (*Lease, error)
- func GetLeaseByMAC(s LeaseStore, mac net.HardwareAddr) (*Lease, error)
- func NewLease(s LeaseStore) *Lease
- func SearchLeases(s LeaseStore, where string, vals ...interface{}) ([]*Lease, error)
- type LeaseStore
- type PoolStat
- type ServerConfig
Constants ¶
const ( ILLEGAL token = iota EOF COMMENT NUMBER STRING IP_ADDRESS BOOLEAN END GLOBAL NETWORK SUBNET POOL REGISTERED UNREGISTERED SERVER_IDENTIFIER RANGE OPTION FREE_LEASE_AFTER DEFAULT_LEASE_TIME MAX_LEASE_TIME )
Variables ¶
This section is empty.
Functions ¶
func IsRegisteredByIP ¶
func IsRegisteredByIP(s LeaseStore, ip net.IP) (bool, error)
IsRegisteredByIP checks if an IP is leased to a registered MAC address. It will return false if an error occurs as well as the error itself.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
A Config is the parsed object generated from a PG-DHCP configuration file.
type DeviceStore ¶
type DeviceStore interface {
GetDeviceByMAC(net.HardwareAddr) (Device, error)
}
type Environment ¶
type Environment string
const ( EnvTesting Environment = "testing" EnvDev Environment = "dev" EnvProd Environment = "prod" )
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
A Handler processes all incoming DHCP packets.
func NewDHCPServer ¶
func NewDHCPServer(conf *Config, s *ServerConfig) *Handler
NewDHCPServer creates and sets up a new DHCP Handler with the give configuration.
func (*Handler) GetPoolStats ¶
func (*Handler) ListenAndServe ¶
ListenAndServe starts the DHCP Handler listening on port 67 for packets. This is blocking like HTTP's ListenAndServe method.
func (*Handler) LoadLeases ¶
LoadLeases will import any current leases saved to the database.
type Lease ¶
type Lease struct {
ID int
IP net.IP
MAC net.HardwareAddr
Network string
Start time.Time
End time.Time
Hostname string
IsAbandoned bool
Offered bool
Registered bool
// contains filtered or unexported fields
}
A Lease represents a single DHCP lease in a pool. It is bound to a particular pool and network.
func GetAllLeases ¶
func GetAllLeases(s LeaseStore) ([]*Lease, error)
GetAllLeases will return a slice of all leases in the database.
func GetAllLeasesByMAC ¶
func GetAllLeasesByMAC(s LeaseStore, mac net.HardwareAddr) ([]*Lease, error)
GetAllLeasesByMAC returns a slice of Lease given the mac address. If no leases exist, the slice will be nil.
func GetLeaseByIP ¶
func GetLeaseByIP(s LeaseStore, ip net.IP) (*Lease, error)
GetLeaseByIP returns a Lease given the IP address. This method will always return a Lease. Make sure to check if error is nil. If a new lease object was created it will have an ID = 0.
func GetLeaseByMAC ¶
func GetLeaseByMAC(s LeaseStore, mac net.HardwareAddr) (*Lease, error)
GetLeaseByMAC returns a Lease given the mac address. This method will always return a Lease. Make sure to check if error is nil. If a new lease object was created it will have an ID = 0. The lease returned will be the most recent least given to the provided MAC address.
func NewLease ¶
func NewLease(s LeaseStore) *Lease
func SearchLeases ¶
func SearchLeases(s LeaseStore, where string, vals ...interface{}) ([]*Lease, error)
type LeaseStore ¶
type LeaseStore interface {
GetAllLeases() ([]*Lease, error)
GetLeaseByIP(net.IP) (*Lease, error)
GetRecentLeaseByMAC(net.HardwareAddr) (*Lease, error)
GetAllLeasesByMAC(net.HardwareAddr) ([]*Lease, error)
CreateLease(*Lease) error
UpdateLease(*Lease) error
DeleteLease(*Lease) error
SearchLeases(string, ...interface{}) ([]*Lease, error)
}
type ServerConfig ¶
type ServerConfig struct {
LeaseStore LeaseStore
DeviceStore DeviceStore
Log *verbose.Logger
LogPath string
Env Environment
}
func (*ServerConfig) IsDev ¶
func (s *ServerConfig) IsDev() bool
func (*ServerConfig) IsProd ¶
func (s *ServerConfig) IsProd() bool
func (*ServerConfig) IsTesting ¶
func (s *ServerConfig) IsTesting() bool