package nclient6
import "github.com/insomniacslk/dhcp/dhcpv6/nclient6"
Package nclient6 is a minimum-functionality client for DHCPv6.
Index ¶
- Variables
- func NewIPv6UDPConn(iface string, port int) (net.PacketConn, error)
- type Client
- func New(iface string, opts ...ClientOpt) (*Client, error)
- func NewWithConn(conn net.PacketConn, ifaceHWAddr net.HardwareAddr, opts ...ClientOpt) (*Client, error)
- func (c *Client) Close() error
- func (c *Client) InterfaceAddr() net.HardwareAddr
- func (c *Client) RapidSolicit(ctx context.Context, modifiers ...dhcpv6.Modifier) (*dhcpv6.Message, error)
- func (c *Client) RemoteAddr() *net.UDPAddr
- func (c *Client) Request(ctx context.Context, advertise *dhcpv6.Message, modifiers ...dhcpv6.Modifier) (*dhcpv6.Message, error)
- func (c *Client) SendAndRead(ctx context.Context, dest *net.UDPAddr, msg *dhcpv6.Message, match Matcher) (*dhcpv6.Message, error)
- func (c *Client) Solicit(ctx context.Context, modifiers ...dhcpv6.Modifier) (*dhcpv6.Message, error)
- type ClientOpt
- func WithBroadcastAddr(n *net.UDPAddr) ClientOpt
- func WithConn(conn net.PacketConn) ClientOpt
- func WithDebugLogger() ClientOpt
- func WithLogDroppedPackets() ClientOpt
- func WithRetry(r int) ClientOpt
- func WithSummaryLogger() ClientOpt
- func WithTimeout(d time.Duration) ClientOpt
- type Matcher
Variables ¶
var ( AllDHCPRelayAgentsAndServers = &net.UDPAddr{ IP: net.ParseIP("ff02::1:2"), Port: dhcpv6.DefaultServerPort, } AllDHCPServers = &net.UDPAddr{ IP: net.ParseIP("ff05::1:3"), Port: dhcpv6.DefaultServerPort, } )
Broadcast destination IP addresses as defined by RFC 3315
var ( // ErrNoResponse is returned when no response packet is received. ErrNoResponse = errors.New("no matching response packet received") )
Functions ¶
func NewIPv6UDPConn ¶
func NewIPv6UDPConn(iface string, port int) (net.PacketConn, error)
NewIPv6UDPConn returns a UDP connection bound to both the interface and port given based on a IPv6 DGRAM socket.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a DHCPv6 client.
func New ¶
New returns a new DHCPv6 client for the given network interface.
func NewWithConn ¶
func NewWithConn(conn net.PacketConn, ifaceHWAddr net.HardwareAddr, opts ...ClientOpt) (*Client, error)
NewWithConn creates a new DHCP client that sends and receives packets on the given interface.
func (*Client) Close ¶
Close closes the underlying connection.
func (*Client) InterfaceAddr ¶
func (c *Client) InterfaceAddr() net.HardwareAddr
InterfaceAddr returns the MAC address of the client's interface.
func (*Client) RapidSolicit ¶
func (c *Client) RapidSolicit(ctx context.Context, modifiers ...dhcpv6.Modifier) (*dhcpv6.Message, error)
RapidSolicit sends a solicitation message with the RapidCommit option and returns the first valid reply received.
func (*Client) RemoteAddr ¶
RemoteAddr is the default DHCP server address this client sends messages to.
func (*Client) Request ¶
func (c *Client) Request(ctx context.Context, advertise *dhcpv6.Message, modifiers ...dhcpv6.Modifier) (*dhcpv6.Message, error)
Request requests an IP Assignment from peer given an advertise message.
func (*Client) SendAndRead ¶
func (c *Client) SendAndRead(ctx context.Context, dest *net.UDPAddr, msg *dhcpv6.Message, match Matcher) (*dhcpv6.Message, error)
SendAndRead sends a packet p to a destination dest and waits for the first response matching `match` as well as its Transaction ID.
If match is nil, the first packet matching the Transaction ID is returned.
func (*Client) Solicit ¶
func (c *Client) Solicit(ctx context.Context, modifiers ...dhcpv6.Modifier) (*dhcpv6.Message, error)
Solicit sends a solicitation message and returns the first valid advertisement received.
type ClientOpt ¶
type ClientOpt func(*Client)
ClientOpt is a function that configures the Client.
func WithBroadcastAddr ¶
WithBroadcastAddr configures the address to broadcast to.
func WithConn ¶
func WithConn(conn net.PacketConn) ClientOpt
WithConn configures the packet connection to use.
func WithDebugLogger ¶
func WithDebugLogger() ClientOpt
WithDebugLogger logs multi-line full DHCPv6 messages when sent & received.
func WithLogDroppedPackets ¶
func WithLogDroppedPackets() ClientOpt
WithLogDroppedPackets logs a short message for dropped packets.
func WithRetry ¶
WithRetry configures the number of retransmissions to attempt.
Default is 3.
func WithSummaryLogger ¶
func WithSummaryLogger() ClientOpt
WithSummaryLogger logs one-line DHCPv6 message summarys when sent & received.
func WithTimeout ¶
WithTimeout configures the retransmission timeout.
Default is 5 seconds.
type Matcher ¶
Matcher matches DHCP packets.
func IsMessageType ¶
func IsMessageType(t dhcpv6.MessageType, tt ...dhcpv6.MessageType) Matcher
IsMessageType returns a matcher that checks for the message type.
Source Files ¶
- Version
- v0.0.0-20250109001534-8abf58130905 (latest)
- Published
- Jan 9, 2025
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 2 months ago –
Tools for package owners.