Help us shape the future of Go! Take the 2026 Go Developer Survey

dhcp6c

package module
v1.0.5 Latest Latest
Warning

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

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

README

testdhcpv6pd

Sends a DHCPv6-PD solicit message and displays the response (no request is done)

usage

testdhcpv6pd [options] [interface name] or [interface index]

Available options:
  -a string
        anonymize ip addresses (format = list word indexes to show) (default "12345678")
  -dll string
        specify type 3 DUID-LL using the provided mac address ( : or - separated digits)
  -dllt string
        specify type 1 DUID-LLT using the provided mac address ( : or - separated digits)
  -dlltt uint
        specify the Time field for DUID-LLT
  -duu string
        specify type 4 DUID-UUID (format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  -p value
        ask for a specific prefix and/or length (repeatable, default is one prefix of ::/64)
  -s    dont print debug messages
  -test
        dry-run only,  print the solicit paquet, nothing is send on the network
  -v    display version````

Without argument, `testdhcpv6pd` will display the available interfaces

Use `-s` to suppress packet debugging 

Use `-a format` to anonymize the prefix where format is a list of indexes. Each index, from 1 to 8, is the part number of the address to keep. For instance `-a "18"` only keeps the first and last part of the address.

Use `-p ::/60` to request a /60 prefix or even `-p 2a01:xxx:xxxx:xxxx::/64,` to request a specific prefix. can be repeated. `iaid` used 1, 2, etc

Other options allow to change the DUID.

## notes

Not tested on *bsd, plan9

Linux systems require *at least* `cap_net_bind_service` capability to bind to port 546 (see `man 7 capabilities`) or just use `sudo`

Darwin/MacOS: use `sudo`

Documentation

Overview

was: Package nclient6 is a minimum-functionality client for DHCPv6. renamed to dhcp6c: this is an extended version with more features added/changed: logger is new public Logger added WithLogger(logger Logger)

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.

func WithIAPD

func WithIAPD(iaid [4]byte, prefix *dhcpv6.OptIAPrefix) dhcpv6.Modifier

WithIAPD adds an IAPD option with the provided IAID and prefix option to a DHCPv6 packet. no check is done if same iaid is added again

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

func (c *Client) PrintMessage(prefix string, message *dhcpv6.Message)

func (*Client) Printf

func (c *Client) Printf(format string, v ...any)

logging - todo: review

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 WithLogger

func WithLogger(logger Logger) ClientOpt

WithLogger logs DHCPv6 messages using provided logger.

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 Logger

type Logger interface {
	Printf(format string, v ...any)
	PrintMessage(prefix string, message *dhcpv6.Message)
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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