Documentation ¶
Index ¶
- Constants
- func AuxOpts(opts *DhcpRequestOptions) func(*Client) error
- func Broadcast(b bool) func(*Client) error
- func Connection(conn connection) func(*Client) error
- func CryptoGenerateXID(b []byte)
- func GenerateXID(g func([]byte)) func(*Client) error
- func HardwareAddr(h net.HardwareAddr) func(*Client) error
- func IgnoreServers(s []net.IP) func(*Client) error
- func MathGenerateXID(b []byte)
- func NewInetSock(options ...func(*inetSock) error) (*inetSock, error)
- func NewPacketSock(ifindex int) (*packetSock, error)
- func SetLocalAddr(l net.UDPAddr) func(*inetSock) error
- func SetRemoteAddr(r net.UDPAddr) func(*inetSock) error
- func Timeout(t time.Duration) func(*Client) error
- func WriteTimeout(t time.Duration) func(*Client) error
- type Client
- func (c *Client) Close() error
- func (c *Client) DeclinePacket(acknowledgement *dhcp4.Packet) dhcp4.Packet
- func (c *Client) DiscoverPacket(opts *DhcpRequestOptions) dhcp4.Packet
- func (c *Client) DiscoverPacketUnicast(opts *DhcpRequestOptions) dhcp4.Packet
- func (c *Client) GetAcknowledgement(requestPacket *dhcp4.Packet) (pack dhcp4.Packet, ackval int, err error)
- func (c *Client) GetOffer(discoverPacket *dhcp4.Packet) (dhcp4.Packet, error)
- func (c *Client) InitRebootRequest(currentIP net.IP, opts *DhcpRequestOptions) (int, dhcp4.Packet, error)
- func (c *Client) Release(acknowledgement dhcp4.Packet) error
- func (c *Client) ReleasePacket(acknowledgement *dhcp4.Packet) dhcp4.Packet
- func (c *Client) Renew(acknowledgement dhcp4.Packet, opts *DhcpRequestOptions) (int, dhcp4.Packet, error)
- func (c *Client) RenewalRequestPacket(acknowledgement *dhcp4.Packet, opts *DhcpRequestOptions) dhcp4.Packet
- func (c *Client) RenewalRequestPacketInitReboot(currentIP net.IP, opts *DhcpRequestOptions) dhcp4.Packet
- func (c *Client) Request(opts *DhcpRequestOptions) (int, dhcp4.Packet, error)
- func (c *Client) RequestAsUnicast(opts *DhcpRequestOptions) (int, dhcp4.Packet, error)
- func (c *Client) RequestPacket(offerPacket *dhcp4.Packet) dhcp4.Packet
- func (c *Client) SendDecline(acknowledgementPacket *dhcp4.Packet) (dhcp4.Packet, error)
- func (c *Client) SendDiscoverAsUnicastPacket(opts *DhcpRequestOptions) (dhcp4.Packet, error)
- func (c *Client) SendDiscoverPacket(opts *DhcpRequestOptions) (dhcp4.Packet, error)
- func (c *Client) SendDiscoverPacketExistingIP(opts *DhcpRequestOptions, currentIP net.IP) (dhcp4.Packet, error)
- func (c *Client) SendPacket(packet dhcp4.Packet) error
- func (c *Client) SendRequest(offerPacket *dhcp4.Packet) (dhcp4.Packet, error)
- func (c *Client) SetOption(options ...func(*Client) error) error
- type DhcpRequestOptions
- type RequestProgressCB
Constants ¶
const ( MaxDHCPLen = 576 // progress states AtGetOffer = 0x01 AtSendRequest = 0x02 AtGetAcknowledgement = 0x03 AtSendRenewalRequest = 0x04 AtEndOfRequest = 0x05 AtEndOfRenewal = 0x06 AtGetOfferLoop = 0x50 AtGetAckLoop = 0x51 AtGetOfferLoopTimedOut = 0xF1 AtGetOfferError = 0xF2 AtGetAckError = 0xF3 AtSendRenewalRequestInitReboot = 0x10 AtGetOfferUnicast = 0xA01 SyscallFailed = 0x1001 // used by GetAcknowledgement() Failed = 0x00 Success = int(dhcp4.ACK) Rejected = int(dhcp4.NAK) )
Variables ¶
This section is empty.
Functions ¶
func AuxOpts ¶
func AuxOpts(opts *DhcpRequestOptions) func(*Client) error
func Connection ¶
func CryptoGenerateXID ¶
func CryptoGenerateXID(b []byte)
func GenerateXID ¶
func HardwareAddr ¶
func HardwareAddr(h net.HardwareAddr) func(*Client) error
func MathGenerateXID ¶
func MathGenerateXID(b []byte)
func NewInetSock ¶
func NewPacketSock ¶
func SetLocalAddr ¶
func SetRemoteAddr ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) DeclinePacket ¶
Create Decline Packet
func (*Client) DiscoverPacket ¶
func (c *Client) DiscoverPacket(opts *DhcpRequestOptions) dhcp4.Packet
Create Discover Packet
func (*Client) DiscoverPacketUnicast ¶
func (c *Client) DiscoverPacketUnicast(opts *DhcpRequestOptions) dhcp4.Packet
Create Discover Packet
func (*Client) GetAcknowledgement ¶
func (c *Client) GetAcknowledgement(requestPacket *dhcp4.Packet) (pack dhcp4.Packet, ackval int, err error)
Retreive Acknowledgement Wait for the offer for a specific Request Packet.
func (*Client) InitRebootRequest ¶
func (c *Client) InitRebootRequest(currentIP net.IP, opts *DhcpRequestOptions) (int, dhcp4.Packet, error)
InitRebootRequest is called when we want to use an existing IP, and just try to send a DISCOVER pack with out exising IP. What happens next depends on if the DHCP server is "authoritive" or not. If it is, and we have asked for an IP it will nto provide, then we will get a deny answer, otherwise we should wait for the timeout, and return this back. In this case a fresh Request should be sent out.
func (*Client) ReleasePacket ¶
Create Release Packet For a Release
func (*Client) Renew ¶
func (c *Client) Renew(acknowledgement dhcp4.Packet, opts *DhcpRequestOptions) (int, dhcp4.Packet, error)
Renew a lease backed on the Acknowledgement Packet. Returns Sucessfull, The AcknoledgementPacket, Any Errors
func (*Client) RenewalRequestPacket ¶
func (c *Client) RenewalRequestPacket(acknowledgement *dhcp4.Packet, opts *DhcpRequestOptions) dhcp4.Packet
Create Request Packet For a Renew
func (*Client) RenewalRequestPacketInitReboot ¶
func (c *Client) RenewalRequestPacketInitReboot(currentIP net.IP, opts *DhcpRequestOptions) dhcp4.Packet
RenewalRequestPacketInitReboot - creates a Request packet for the INIT-REBOOT state as defined in RFC2131
func (*Client) Request ¶
Request will do a Full DHCP Request. If a broadcast discover fails, we will try a unicast discover
func (*Client) RequestAsUnicast ¶
RequestAsUnicast does a normal request process, but starts with a Unicast flag DISCOVER packet this is actually what udhcp does on Linux. Apparently, some routers have poor DHCP server implementations or don't like broadcast flag and/or a broadcast Ethernet frame for some reason.
func (*Client) RequestPacket ¶
Create Request Packet
func (*Client) SendDecline ¶
Send Decline to the received acknowledgement.
func (*Client) SendDiscoverAsUnicastPacket ¶
func (c *Client) SendDiscoverAsUnicastPacket(opts *DhcpRequestOptions) (dhcp4.Packet, error)
Send the Discovery Packet to the Broadcast Channel
func (*Client) SendDiscoverPacket ¶
func (c *Client) SendDiscoverPacket(opts *DhcpRequestOptions) (dhcp4.Packet, error)
Send the Discovery Packet to the Broadcast Channel
func (*Client) SendDiscoverPacketExistingIP ¶
func (c *Client) SendDiscoverPacketExistingIP(opts *DhcpRequestOptions, currentIP net.IP) (dhcp4.Packet, error)
Send the Discovery Packet to the Broadcast Channel
func (*Client) SendPacket ¶
Send a DHCP Packet.
func (*Client) SendRequest ¶
Send Request Based On the offer Received. func (c *Client) SendRequest(offerPacket *dhcp4.Packet, opts *DhcpRequestOptions) (dhcp4.Packet, error) {
type DhcpRequestOptions ¶
type DhcpRequestOptions struct { RequestedParams []byte ProgressCB RequestProgressCB // the amount of time we allow for a step in the DHCP communication to // take. After this time, we consider the entire operation timedout StepTimeout time.Duration }
func (*DhcpRequestOptions) AddRequestParam ¶
func (opts *DhcpRequestOptions) AddRequestParam(code dhcp4.OptionCode)