dhcp4client

package module
v0.0.0-...-be92465 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2019 License: MPL-2.0 Imports: 10 Imported by: 0

README

dhcp4client GoDoc Coverage Status Codeship Status for d2g/dhcp4client

DHCP Client

Thanks to:

@eyakubovich For AF_PACKET support.

Documentation

Index

Constants

View Source
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 Broadcast

func Broadcast(b bool) func(*Client) error

func Connection

func Connection(conn connection) func(*Client) error

func CryptoGenerateXID

func CryptoGenerateXID(b []byte)

func GenerateXID

func GenerateXID(g func([]byte)) func(*Client) error

func HardwareAddr

func HardwareAddr(h net.HardwareAddr) func(*Client) error

func IgnoreServers

func IgnoreServers(s []net.IP) func(*Client) error

func MathGenerateXID

func MathGenerateXID(b []byte)

func NewInetSock

func NewInetSock(options ...func(*inetSock) error) (*inetSock, error)

func NewPacketSock

func NewPacketSock(ifindex int) (*packetSock, error)

func SetLocalAddr

func SetLocalAddr(l net.UDPAddr) func(*inetSock) error

func SetRemoteAddr

func SetRemoteAddr(r net.UDPAddr) func(*inetSock) error

func Timeout

func Timeout(t time.Duration) func(*Client) error

func WriteTimeout

func WriteTimeout(t time.Duration) func(*Client) error

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(options ...func(*Client) error) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

Close Connections

func (*Client) DeclinePacket

func (c *Client) DeclinePacket(acknowledgement *dhcp4.Packet) dhcp4.Packet

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) GetOffer

func (c *Client) GetOffer(discoverPacket *dhcp4.Packet) (dhcp4.Packet, error)

Retreive Offer... Wait for the offer for a specific Discovery 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) Release

func (c *Client) Release(acknowledgement dhcp4.Packet) error

Release a lease backed on the Acknowledgement Packet. Returns Any Errors

func (*Client) ReleasePacket

func (c *Client) ReleasePacket(acknowledgement *dhcp4.Packet) dhcp4.Packet

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

func (c *Client) Request(opts *DhcpRequestOptions) (int, dhcp4.Packet, error)

Request will do a Full DHCP Request. If a broadcast discover fails, we will try a unicast discover

func (*Client) RequestAsUnicast

func (c *Client) RequestAsUnicast(opts *DhcpRequestOptions) (int, dhcp4.Packet, error)

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

func (c *Client) RequestPacket(offerPacket *dhcp4.Packet) dhcp4.Packet

Create Request Packet

func (*Client) SendDecline

func (c *Client) SendDecline(acknowledgementPacket *dhcp4.Packet) (dhcp4.Packet, error)

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

func (c *Client) SendPacket(packet dhcp4.Packet) error

Send a DHCP Packet.

func (*Client) SendRequest

func (c *Client) SendRequest(offerPacket *dhcp4.Packet) (dhcp4.Packet, error)

Send Request Based On the offer Received. func (c *Client) SendRequest(offerPacket *dhcp4.Packet, opts *DhcpRequestOptions) (dhcp4.Packet, error) {

func (*Client) SetOption

func (c *Client) SetOption(options ...func(*Client) error) 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)

type RequestProgressCB

type RequestProgressCB func(state int, addinfo string) (keepgoing bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL