Documentation ¶
Index ¶
- Variables
- func GenerateXID() uint32
- type Connection
- type ConnectionResolver
- type ConnectionType
- func (c ConnectionType) MarshalJSON() ([]byte, error)
- func (c ConnectionType) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (c ConnectionType) MarshalYAML() (interface{}, error)
- func (c *ConnectionType) Parse(txt string) error
- func (c ConnectionType) String() string
- func (c *ConnectionType) UnmarshalJSON(b []byte) error
- func (c *ConnectionType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- func (c *ConnectionType) UnmarshalYAML(value *yaml.Node) error
- type DHCP4
- func (d *DHCP4) GetDNS() net.IP
- func (d *DHCP4) GetMsgType() layers.DHCPMsgType
- func (d *DHCP4) GetOption(option layers.DHCPOpt) *layers.DHCPOption
- func (d *DHCP4) GetRouter() net.IP
- func (d *DHCP4) GetSubnetMask() net.IP
- func (d *DHCP4) SetHostname(hostname string)
- func (d *DHCP4) SetMsgType(msgType layers.DHCPMsgType)
- func (d *DHCP4) SetOption(opt layers.DHCPOpt, data []byte)
- func (d *DHCP4) ToJSON() []byte
- func (d *DHCP4) ToYAML() []byte
- type DHCPClient
- type DefaultConnectioneResolver
- type DualConn
- func (c *DualConn) Block(ctx context.Context) chan bool
- func (c *DualConn) Close() error
- func (c *DualConn) GetPort() layers.UDPPort
- func (c *DualConn) Local() *net.UDPAddr
- func (c *DualConn) Receive(ctx context.Context) (chan *DHCP4, chan error)
- func (c *DualConn) Remote() *net.UDPAddr
- func (c *DualConn) Send(ctx context.Context, dhcp *DHCP4) (chan int, chan error)
- type IPResolver
- type KubeServiceConfig
- type KubernetesExternalIPResolver
- type Lease
- func (l *Lease) CheckResponseType(dhcp *DHCP4) bool
- func (l *Lease) Error() error
- func (l *Lease) GetExpireTime() time.Time
- func (l *Lease) GetRebindTime() time.Time
- func (l *Lease) GetRenewalTime() time.Time
- func (l *Lease) GetRequest(msgType layers.DHCPMsgType, options layers.DHCPOptions) *Lease
- func (l *Lease) Lock()
- func (l *Lease) Ok() bool
- func (l *Lease) SetError(err error)
- func (l *Lease) SetHostname(hostname string)
- func (l *Lease) Touch()
- func (l *Lease) Unlock()
- type LeaseStore
- func (l *LeaseStore) Clean()
- func (l *LeaseStore) Get(xid uint32) (*Lease, bool, context.CancelFunc)
- func (l *LeaseStore) GetItem(xid uint32) (*LeaseStoreItem, bool)
- func (l *LeaseStore) Has(xid uint32) bool
- func (l *LeaseStore) HasStatus(xid uint32, status layers.DHCPMsgType) bool
- func (l *LeaseStore) Remove(xid uint32) bool
- func (l *LeaseStore) Run(ctx context.Context)
- func (l *LeaseStore) Set(lease *Lease) error
- func (l *LeaseStore) Touch(xid uint32) bool
- type LeaseStoreItem
- type LocalIPResolver
- type RawConn
- func (c *RawConn) Block(ctx context.Context) chan bool
- func (c *RawConn) Close() error
- func (c *RawConn) Local() *net.UDPAddr
- func (c *RawConn) Receive(ctx context.Context) (chan *DHCP4, chan error)
- func (c *RawConn) Remote() *net.UDPAddr
- func (c *RawConn) Send(ctx context.Context, dhcp *DHCP4) (chan int, chan error)
- type StaticIPResolver
- type UDPConn
- func (c *UDPConn) Block(ctx context.Context) chan bool
- func (c *UDPConn) Close() error
- func (c *UDPConn) Local() *net.UDPAddr
- func (c *UDPConn) Receive(ctx context.Context) (chan *DHCP4, chan error)
- func (c *UDPConn) Remote() *net.UDPAddr
- func (c *UDPConn) Send(ctx context.Context, dhcp *DHCP4) (chan int, chan error)
- type UDPPacketConn
Constants ¶
This section is empty.
Variables ¶
var AllConnectionTypes = []string{ UDP.String(), Dual.String(), Fritzbox.String(), Packet.String(), Broken.String(), }
AllConnectionTypes is a list of all possible connection types
Functions ¶
Types ¶
type Connection ¶
type Connection interface { Close() error Send(ctx context.Context, dhcp *DHCP4) (chan int, chan error) Receive(ctx context.Context) (chan *DHCP4, chan error) Local() *net.UDPAddr Remote() *net.UDPAddr Block(ctx context.Context) chan bool }
Connection is an interface for a DHCP connection
func NewDualConn ¶
func NewDualConn(local *net.UDPAddr, remote *net.UDPAddr, fixPort bool, out net.PacketConn, in UDPPacketConn, logger logger.Logger) Connection
NewDualConn initializes a new connection
func NewRawConn ¶
func NewRawConn(local *net.UDPAddr, remote *net.UDPAddr, conn net.PacketConn, logger logger.Logger) Connection
NewRawConn initializes a new connection
func NewUDPConn ¶
func NewUDPConn(local *net.UDPAddr, remote *net.UDPAddr, conn UDPPacketConn, logger logger.Logger) Connection
NewUDPConn initializes a new udp connection
type ConnectionResolver ¶ added in v1.2.0
type ConnectionResolver interface {
GetConnection(local net.IP, remote net.IP, t ConnectionType, logger logger.Logger) Connection
}
type ConnectionType ¶
type ConnectionType string
ConnectionType is enumeration of teh connection types
const ( AutoDetect ConnectionType = "auto" UDP ConnectionType = "udp" Dual ConnectionType = "dual" Fritzbox ConnectionType = "fritzbox" Broken ConnectionType = "broken" Packet ConnectionType = "packet" )
Existing connection types
func (ConnectionType) MarshalJSON ¶
func (c ConnectionType) MarshalJSON() ([]byte, error)
MarshalJSON custom marshal for JSON
func (ConnectionType) MarshalXML ¶
func (c ConnectionType) MarshalXML(e *xml.Encoder, start xml.StartElement) error
MarshalXML custom marshal for XML
func (ConnectionType) MarshalYAML ¶
func (c ConnectionType) MarshalYAML() (interface{}, error)
func (ConnectionType) String ¶
func (c ConnectionType) String() string
func (*ConnectionType) UnmarshalJSON ¶
func (c *ConnectionType) UnmarshalJSON(b []byte) error
UnmarshalJSON custom unmarshal for JSON
func (*ConnectionType) UnmarshalXML ¶
func (c *ConnectionType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML custom unmarshal for XML
func (*ConnectionType) UnmarshalYAML ¶
func (c *ConnectionType) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML custom unmarshal for YAMLv3
type DHCP4 ¶
DHCP4 extends layers.DHCPv4 with helper functions
func NewPackage ¶
func NewPackage(msgType layers.DHCPMsgType, xid uint32, chaddr net.HardwareAddr, options layers.DHCPOptions) *DHCP4
NewPackage creates a DHCPv4 package
func (*DHCP4) GetMsgType ¶
func (d *DHCP4) GetMsgType() layers.DHCPMsgType
GetMsgType returns the DHCP message type option
func (*DHCP4) GetOption ¶
func (d *DHCP4) GetOption(option layers.DHCPOpt) *layers.DHCPOption
GetOption returns a requested DHCP option
func (*DHCP4) GetSubnetMask ¶
GetSubnetMask return the option layers.DHCPOptSubnetMask
func (*DHCP4) SetHostname ¶
SetHostname sets the DHCP option layers.DHCPOptHostname
func (*DHCP4) SetMsgType ¶
func (d *DHCP4) SetMsgType(msgType layers.DHCPMsgType)
SetMsgType sets the DHCP message type option
type DHCPClient ¶ added in v1.2.0
type DHCPClient interface { Start() chan bool Stop() GetLease(ctx context.Context, hostname string, chaddr net.HardwareAddr) chan *Lease Renew(ctx context.Context, hostname string, chaddr net.HardwareAddr, ip net.IP) chan *Lease Release(ctx context.Context, hostname string, chaddr net.HardwareAddr, ip net.IP) chan error }
func NewClient ¶
func NewClient(resolver IPResolver, connResolver ConnectionResolver, connType ConnectionType, timeout time.Duration, retry time.Duration, logger logger.Logger) DHCPClient
NewClient initialize a new client
type DefaultConnectioneResolver ¶ added in v1.2.0
type DefaultConnectioneResolver struct { }
func NewDefaultConnectioneResolver ¶ added in v1.2.0
func NewDefaultConnectioneResolver() *DefaultConnectioneResolver
func (*DefaultConnectioneResolver) GetConnection ¶ added in v1.2.0
func (r *DefaultConnectioneResolver) GetConnection(local net.IP, remote net.IP, t ConnectionType, logger logger.Logger) Connection
type DualConn ¶
type DualConn struct {
// contains filtered or unexported fields
}
DualConn is a udp listener on a local port and a packet connection to use free src port for outgoing messages
type IPResolver ¶ added in v1.2.0
type KubeServiceConfig ¶ added in v1.2.0
type KubeServiceConfig struct { Config string `yaml:"config,omitempty" json:"config,omitempty" xml:"config,omitempty"` Namespace string `yaml:"namespace,omitempty" json:"namespace,omitempty" xml:"namespace,omitempty"` Service string `yaml:"service,omitempty" json:"service,omitempty" xml:"service,omitempty"` }
KubeServiceConfig is the optional configuration to read the relay ip
func (*KubeServiceConfig) String ¶ added in v1.2.0
func (c *KubeServiceConfig) String() string
type KubernetesExternalIPResolver ¶ added in v1.2.0
type KubernetesExternalIPResolver struct { LocalIPResolver // contains filtered or unexported fields }
func NewKubernetesExternalIPResolver ¶ added in v1.2.0
func NewKubernetesExternalIPResolver(local net.IP, remote net.IP, config *KubeServiceConfig, client kubernetes.KubeClient, logger logger.Logger) *KubernetesExternalIPResolver
func (*KubernetesExternalIPResolver) GetRelayIP ¶ added in v1.2.0
type Lease ¶
type Lease struct { *DHCP4 Timestamp time.Time Hostname string Done chan bool // contains filtered or unexported fields }
Lease extends DHCP4 with extra fields and an error
func NewLease ¶
func NewLease(msgType layers.DHCPMsgType, xid uint32, chaddr net.HardwareAddr, options layers.DHCPOptions) *Lease
NewLease creates a lease object
func NewLeaseError ¶
NewLeaseError creates an empty lease with an error
func (*Lease) CheckResponseType ¶
CheckResponseType checks if a new status is allowed
func (*Lease) GetExpireTime ¶ added in v1.2.0
GetExpireTime return the option layers.DHCPOptLeaseTime
func (*Lease) GetRebindTime ¶ added in v1.2.0
GetRebindTime return the option layers.DHCPOptT2
func (*Lease) GetRenewalTime ¶ added in v1.2.0
GetRenewalTime return the option layers.DHCPOptT1
func (*Lease) GetRequest ¶
func (l *Lease) GetRequest(msgType layers.DHCPMsgType, options layers.DHCPOptions) *Lease
GetRequest creates a DHCP request out of an lease
func (*Lease) SetHostname ¶
SetHostname sets the DHCP option layers.DHCPOptHostname and the hostname field
type LeaseStore ¶
type LeaseStore struct {
// contains filtered or unexported fields
}
LeaseStore is thread-safe store for temporary DHCP lease packets with a TTL
func NewStore ¶
func NewStore(ttl time.Duration, logger logger.Logger) *LeaseStore
NewStore creates a new lease store
func (*LeaseStore) Clean ¶
func (l *LeaseStore) Clean()
Clean removes outdated entries from the store
func (*LeaseStore) Get ¶
func (l *LeaseStore) Get(xid uint32) (*Lease, bool, context.CancelFunc)
Get a value from the store
func (*LeaseStore) GetItem ¶ added in v1.2.0
func (l *LeaseStore) GetItem(xid uint32) (*LeaseStoreItem, bool)
GetItem returns an item from the store
func (*LeaseStore) Has ¶
func (l *LeaseStore) Has(xid uint32) bool
Has checks if a xid is in the store
func (*LeaseStore) HasStatus ¶ added in v1.2.0
func (l *LeaseStore) HasStatus(xid uint32, status layers.DHCPMsgType) bool
Touch extends the expire time of an entry
func (*LeaseStore) Remove ¶
func (l *LeaseStore) Remove(xid uint32) bool
Remove a value from the store
func (*LeaseStore) Run ¶
func (l *LeaseStore) Run(ctx context.Context)
Run the process to clean the store periodically
func (*LeaseStore) Set ¶
func (l *LeaseStore) Set(lease *Lease) error
Set or add a lease to the store
func (*LeaseStore) Touch ¶
func (l *LeaseStore) Touch(xid uint32) bool
Touch extends the expire time of an entry
type LeaseStoreItem ¶
type LeaseStoreItem struct { Lease *Lease Expire time.Time Status layers.DHCPMsgType }
LeaseStoreItem describes a lease store item
type LocalIPResolver ¶ added in v1.2.0
type LocalIPResolver struct {
// contains filtered or unexported fields
}
func (*LocalIPResolver) GetLocalIP ¶ added in v1.2.0
func (*LocalIPResolver) GetServerIP ¶ added in v1.2.0
func (l *LocalIPResolver) GetServerIP() (net.IP, error)
type RawConn ¶
type RawConn struct {
// contains filtered or unexported fields
}
RawConn is a packet connection between local and remote
type StaticIPResolver ¶ added in v1.2.0
type StaticIPResolver struct { LocalIPResolver // contains filtered or unexported fields }
func NewStaticIPResolver ¶ added in v1.2.0
func (*StaticIPResolver) GetRelayIP ¶ added in v1.2.0
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is a simple upd connection using the same src and destination port