Documentation
¶
Overview ¶
Package dhcp implements a DHCP client and server as described in RFC 2131.
Index ¶
Constants ¶
View Source
const ( // ServerPort is the well-known UDP port number for a DHCP server. ServerPort = 67 // ClientPort is the well-known UDP port number for a DHCP client. ClientPort = 68 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcquiredFunc ¶
type AcquiredFunc func(lost, acquired tcpip.AddressWithPrefix, cfg Config)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a DHCP client.
func NewClient ¶
func NewClient( s *stack.Stack, nicid tcpip.NICID, linkAddr tcpip.LinkAddress, acquisition, backoff, retransmission time.Duration, acquiredFunc AcquiredFunc, ) *Client
NewClient creates a DHCP client.
acquiredFunc will be called after each DHCP acquisition, and is responsible for making necessary modifications to the stack state.
func (*Client) Run ¶
Run runs the DHCP client.
The function periodically searches for a new IP address.
func (*Client) StateRecentHistory ¶
type Config ¶
type Config struct { ServerAddress tcpip.Address // address of the server SubnetMask tcpip.AddressMask // client address subnet mask Router []tcpip.Address // client router addresses DNS []tcpip.Address // client DNS server addresses UpdatedAt time.Time // monotonic time at which lease was last updated LeaseLength Seconds // time until lease expires, relative to the value of UpdatedAt RenewTime Seconds // time until client enters RENEWING state, relative to the value of UpdatedAt RebindTime Seconds // time until client enters REBINDING state, relative to the value of UpdatedAt Declined bool // server sent a NAK }
Config is standard DHCP configuration.
type Info ¶
type Info struct { // NICID is the identifer to the associated NIC. NICID tcpip.NICID // LinkAddr is the link-address of the associated NIC. LinkAddr tcpip.LinkAddress // Acquisition is the duration within which a complete DHCP transaction must // complete before timing out. Acquisition time.Duration // Backoff is the duration for which the client must wait before starting a // new DHCP transaction after a failed transaction. Backoff time.Duration // Retransmission is the duration to wait before resending a DISCOVER or // REQUEST within an active transaction. Retransmission time.Duration // Acquired is the network address most recently acquired by the client. Acquired tcpip.AddressWithPrefix // State is the DHCP client state. State dhcpClientState // Assigned is the network address added by the client to its stack. Assigned tcpip.AddressWithPrefix // LeaseExpiration is the time at which the client's current lease will // expire. LeaseExpiration time.Time // RenewTime is the at which the client will transition to its renewing state. RenewTime time.Time // RebindTime is the time at which the client will transition to its rebinding // state. RebindTime time.Time // Config is the last DHCP configuration assigned to the client by the server. Config Config }
type PacketDiscardStats ¶
type PacketDiscardStats struct { InvalidPort tcpip.IntegralStatCounterMap InvalidTransProto tcpip.IntegralStatCounterMap InvalidPacketType tcpip.IntegralStatCounterMap }
type Seconds ¶
type Seconds uint32
Seconds represents a time duration in seconds.
RFC 2131 Section 3.3 https://tools.ietf.org/html/rfc2131#section-3.3
Throughout the protocol, times are to be represented in units of seconds. Representing relative times in units of seconds in an unsigned 32 bit word gives a range of relative times from 0 to approximately 100 years, which is sufficient for the relative times to be measured using DHCP.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a DHCP server.
type Stats ¶
type Stats struct { PacketDiscardStats PacketDiscardStats InitAcquire tcpip.StatCounter RenewAcquire tcpip.StatCounter RebindAcquire tcpip.StatCounter SendDiscovers tcpip.StatCounter RecvOffers tcpip.StatCounter SendRequests tcpip.StatCounter RecvAcks tcpip.StatCounter RecvNaks tcpip.StatCounter SendDiscoverErrors tcpip.StatCounter SendRequestErrors tcpip.StatCounter RecvOfferErrors tcpip.StatCounter RecvOfferUnexpectedType tcpip.StatCounter RecvOfferOptsDecodeErrors tcpip.StatCounter RecvOfferTimeout tcpip.StatCounter RecvOfferAcquisitionTimeout tcpip.StatCounter RecvAckErrors tcpip.StatCounter RecvNakErrors tcpip.StatCounter RecvAckOptsDecodeErrors tcpip.StatCounter RecvAckAddrErrors tcpip.StatCounter RecvAckUnexpectedType tcpip.StatCounter RecvAckTimeout tcpip.StatCounter RecvAckAcquisitionTimeout tcpip.StatCounter ReacquireAfterNAK tcpip.StatCounter }
Stats collects DHCP statistics per client.
Click to show internal directories.
Click to hide internal directories.