nclient6

package
v0.0.0-...-7803ee8 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package nclient6 is a minimum-functionality client for DHCPv6.

Index

Constants

This section is empty.

Variables

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

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

func New(iface string, opts ...ClientOpt) (*Client, error)

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

func (c *Client) Close() error

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

func (c *Client) RemoteAddr() *net.UDPAddr

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

func WithBroadcastAddr(n *net.UDPAddr) ClientOpt

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

func WithRetry(r int) ClientOpt

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

func WithTimeout(d time.Duration) ClientOpt

WithTimeout configures the retransmission timeout.

Default is 5 seconds.

type Matcher

type Matcher func(*dhcpv6.Message) bool

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.

Jump to

Keyboard shortcuts

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