Documentation ¶
Index ¶
- Constants
- func FormatID(buf []byte) string
- type Config
- type ConfigBroadcaster
- type ConfigProvider
- type DHCPMessage
- type DHCPServer
- type DHCPServerSourcer
- type DuidType
- type FileSourcer
- type LogMessage
- type MessageType
- type OptionType
- type Override
- type Overrides
- type Packet6
- func (p Packet6) Duid() ([]byte, error)
- func (p Packet6) DuidTypeName() (string, error)
- func (p Packet6) Encapsulate(peer net.IP) Packet6
- func (p Packet6) GetInnerMostPeerAddr() (net.IP, error)
- func (p Packet6) Hops() (byte, error)
- func (p Packet6) LinkAddr() (net.IP, error)
- func (p Packet6) Mac() ([]byte, error)
- func (p Packet6) PeerAddr() (net.IP, error)
- func (p Packet6) Type() (MessageType, error)
- func (p Packet6) Unwind() (Packet6, net.IP, error)
- func (p Packet6) XID() (uint32, error)
- type PersonalizedLogger
- type Server
- type Throttle
Constants ¶
const ( ErrUnknown = "E_UNKNOWN" ErrPanic = "E_PANIC" ErrRead = "E_READ" ErrConnect = "E_CONN" ErrWrite = "E_WRITE" ErrGi0 = "E_GI_0" ErrParse = "E_PARSE" ErrNoServer = "E_NO_SERVER" ErrConnRate = "E_CONN_RATE" )
List of possible errors.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Version int Addr *net.UDPAddr Algorithm dhcpBalancingAlgorithm ServerUpdateInterval time.Duration PacketBufSize int HostSourcer DHCPServerSourcer FreeConnTimeout time.Duration RCRatio uint32 Overrides map[string]Override Extras interface{} TCacheSize int TCacheRate int TRate int }
Config represents the server configuration.
func LoadConfig ¶
func LoadConfig(path, overridesPath string, version int, provider ConfigProvider) (*Config, error)
LoadConfig will take the path of the json file, the path of the override json file, an integer version and a ConfigProvider and will return a pointer to a Config object.
func ParseConfig ¶
func ParseConfig(jsonConfig, jsonOverrides []byte, version int, provider ConfigProvider) (*Config, error)
ParseConfig will take JSON config files, a version and a ConfigProvider, and return a pointer to a Config struct
type ConfigBroadcaster ¶
type ConfigBroadcaster struct {
// contains filtered or unexported fields
}
ConfigBroadcaster is a convenience struct that broadcasts its input channel to a list of receivers.
func NewConfigBroadcaster ¶
func NewConfigBroadcaster(input <-chan *Config) *ConfigBroadcaster
func WatchConfig ¶
func WatchConfig( configPath, overridesPath string, version int, provider ConfigProvider, ) (*ConfigBroadcaster, chan error, error)
WatchConfig will keep watching for changes to both config and override json files. It uses fsnotify library (it uses inotify in Linux), and call LoadConfig when it an inotify event signals the modification of the json files. It returns a configBroadcaster which the a goroutine in the main will use to reload the configuration when it changes.
func (*ConfigBroadcaster) NewReceiver ¶
func (c *ConfigBroadcaster) NewReceiver() <-chan *Config
NewReceiver allows the caller to register to receive new Config messages when the server config changes. This is typically used by a main go routine to reload the server configuration.
type ConfigProvider ¶
type ConfigProvider interface { NewHostSourcer( sourcerType, args string, version int) (DHCPServerSourcer, error) ParseExtras(extras json.RawMessage) (interface{}, error) }
ConfigProvider is an interface which provides methods to fetch the HostSourcer and parse extra configuration.
type DHCPMessage ¶
DHCPMessage represents coordinates of a dhcp message.
type DHCPServer ¶
type DHCPServer struct { Hostname string Address net.IP Port int IsRC bool // contains filtered or unexported fields }
DHCPServer holds information about a single dhcp server
func NewDHCPServer ¶
func NewDHCPServer(hostname string, ip net.IP, port int) *DHCPServer
NewDHCPServer returns an instance of DHCPServer
func (*DHCPServer) String ¶
func (d *DHCPServer) String() string
type DHCPServerSourcer ¶
type DHCPServerSourcer interface { GetStableServers() ([]*DHCPServer, error) GetRCServers() ([]*DHCPServer, error) GetServersFromTier(tier string) ([]*DHCPServer, error) }
DHCPServerSourcer is an interface used to fetch stable, rc and servers from a "tier" (group of servers).
type DuidType ¶
type DuidType uint16
DuidType is a uint16 integer, there can be 3 of them, see the enum below.
type FileSourcer ¶
type FileSourcer struct {
// contains filtered or unexported fields
}
FileSourcer holds various information about json the config files, list of stable and rc servers, the fsnotify Watcher and stuff needed for synchronization.
func NewFileSourcer ¶
func NewFileSourcer(stablePath, rcPath string, version int) (*FileSourcer, error)
NewFileSourcer returns a new FileSourcer, stablePath and rcPath are the paths of the text files containing list of servers. If rcPath is empty it will be ignored, stablePath must be not null, version is the protocol version and should be either 4 or 6.
func (*FileSourcer) GetRCServers ¶
func (fs *FileSourcer) GetRCServers() ([]*DHCPServer, error)
GetRCServers returns a list of rc dhcp servers
func (*FileSourcer) GetServersFromTier ¶
func (fs *FileSourcer) GetServersFromTier(path string) ([]*DHCPServer, error)
GetServersFromTier returns a list of DHCPServer from a file
func (*FileSourcer) GetStableServers ¶
func (fs *FileSourcer) GetStableServers() ([]*DHCPServer, error)
GetStableServers returns a list of stable dhcp servers
type LogMessage ¶
type LogMessage struct { Version int Packet []byte Peer *net.UDPAddr Server string ServerIsRC bool Latency time.Duration Success bool ErrorName string ErrorDetails error }
LogMessage holds the info of a log line.
type MessageType ¶
type MessageType byte
MessageType represents various dhcpv6 message types go:generate stringer -type=MessageType packet6.go
const ( Solicit MessageType = iota + 1 Advertise Request Confirm Renew Rebind Reply Release Decline Reconfigure InformationRequest RelayForw RelayRepl )
Various message types for DHCPv6
func (MessageType) String ¶
func (i MessageType) String() string
type OptionType ¶
type OptionType uint16
OptionType represents various dhcpv6 option types
const ( ClientID OptionType = iota + 1 ServerID IdentAssocNonTempAddr IdentAssocTempAddr IaAddr OptionRequest Preference ElapsedTime RelayMessage Auth OptionType = iota + 2 ServerUnicast StatusCode RapidCommit UserClass VendorClass VendorOpts InterfaceID ReconfigureMessage ReconfigureAccept )
List of Option Types
func (OptionType) String ¶
func (i OptionType) String() string
type Override ¶
type Override struct { // note that Host override takes precedence over Tier Host string `json:"host"` Tier string `json:"tier"` Expiration string `json:"expiration"` }
Override represents the dhcp server or the group of dhcp servers (tier) we want to send packets to.
type Overrides ¶
Overrides is a struct that holds v4 and v6 list of overrides. The keys of the map are mac addresses.
type Packet6 ¶
type Packet6 []byte
Packet6 contains raw bytes for a dhcpv6 packet
func (Packet6) DuidTypeName ¶
func (Packet6) Encapsulate ¶
Encapsulate embeds this message in a relay-forward message in preparation for forwarding to a relay/server
func (Packet6) GetInnerMostPeerAddr ¶
GetInnerMostPeerAddress returns the peer address in the inner most relay info header, this is typically the mac address of the relay closer to the dhcp client making the request.
func (Packet6) LinkAddr ¶
LinkAddr returns the LinkAddr field in the RelayInfo header. Will return error if the message is not a RelayForw or RelayRepl.
func (Packet6) Mac ¶
Mac returns the Mac addressed embededded in the DUID, note that this only works with type DuidLL and DuidLLT. If the request is not using DUID-LL[T] then we look into the PeerAddr field in the RelayInfo header. This contains the EUI-64 address of the client making the request, populated by the dhcp relay, it is possible to extract the mac address from that IP. If a mac address cannot be fonud an error will be returned.
func (Packet6) PeerAddr ¶
PeerAddr returns the PeerAddr field in the RelayInfo header. Will return error if the message is not a RelayForw or RelayRepl.
func (Packet6) Type ¶
func (p Packet6) Type() (MessageType, error)
Type returns the MessageType for a Packet6
type PersonalizedLogger ¶
type PersonalizedLogger interface {
Log(msg LogMessage) error
}
PersonalizedLogger is an interface used to log a LogMessage using your own logic. It will be used in loggerHelperImpl.
type Throttle ¶
type Throttle interface { // Returns whether the rate is below max for a key OK(interface{}) (bool, error) // contains filtered or unexported methods }
Throttle is interface that implements rate limiting per key
func NewThrottle ¶
NewThrottle returns a Throttle struct
Capacity: Maximum capacity of the LRU cache CacheRate (per second): Maximum allowed rate for adding new items to the cache. By that way it prevents the cache invalidation to happen too soon for the existing rate items in the cache. Cache rate will be infinite for 0 or negative values. MaxRatePerItem (per second): Maximum allowed requests rate for each key in the cache. Throttling will be disabled for 0 or negative values. No cache will be created in that case.