dhcp6

package module
v0.0.0-...-2a67805 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 5 Imported by: 131

README

dhcp6 Build Status GoDoc Go Report Card

Package dhcp6 implements a DHCPv6 server, as described in IETF RFC 3315. MIT Licensed.

At this time, the API is not stable, and may change over time. The eventual goal is to implement a server, client, and testing facilities for consumers of this package.

The design of this package is inspired by Go's net/http package. The Go standard library is Copyright (c) 2012 The Go Authors. All rights reserved. The Go license can be found at https://golang.org/LICENSE.

Documentation

Overview

Package dhcp6 implements a DHCPv6 server, as described in RFC 3315.

Unless otherwise stated, any reference to "DHCP" in this package refers to DHCPv6 only.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOptions is returned when invalid options data is encountered
	// during parsing.  The data could report an incorrect length or have
	// trailing bytes which are not part of the option.
	ErrInvalidOptions = errors.New("invalid options data")

	// ErrInvalidPacket is returned when a byte slice does not contain enough
	// data to create a valid Packet.  A Packet must have at least a message type
	// and transaction ID.
	ErrInvalidPacket = errors.New("not enough bytes for valid packet")

	// ErrOptionNotPresent is returned when a requested opcode is not in
	// the packet.
	ErrOptionNotPresent = errors.New("option code not present in packet")
)

Functions

This section is empty.

Types

type MessageType

type MessageType uint8

MessageType represents a DHCP message type, as defined in RFC 3315, Section 5.3. Different DHCP message types are used to perform different actions between a client and server.

const (
	// RFC 3315
	MessageTypeSolicit            MessageType = 1
	MessageTypeAdvertise          MessageType = 2
	MessageTypeRequest            MessageType = 3
	MessageTypeConfirm            MessageType = 4
	MessageTypeRenew              MessageType = 5
	MessageTypeRebind             MessageType = 6
	MessageTypeReply              MessageType = 7
	MessageTypeRelease            MessageType = 8
	MessageTypeDecline            MessageType = 9
	MessageTypeReconfigure        MessageType = 10
	MessageTypeInformationRequest MessageType = 11
	MessageTypeRelayForw          MessageType = 12
	MessageTypeRelayRepl          MessageType = 13

	// RFC 5007
	MessageTypeLeasequery      MessageType = 14
	MessageTypeLeasequeryReply MessageType = 15

	// RFC 5460
	MessageTypeLeasequeryDone MessageType = 16
	MessageTypeLeasequeryData MessageType = 17

	// RFC 6977
	MessageTypeReconfigureRequest MessageType = 18
	MessageTypeReconfigureReply   MessageType = 19

	// RFC 7341
	MessageTypeDHCPv4Query    MessageType = 20
	MessageTypeDHCPv4Response MessageType = 21
)

MessageType constants which indicate the message types described in RFCs 3315, 5007, 5460, 6977, and 7341.

These message types are taken from IANA's DHCPv6 parameters registry: http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml.

func (MessageType) String

func (i MessageType) String() string

type OptionCode

type OptionCode uint16

OptionCode represents a DHCP option, as defined in RFC 3315, Section 22. Options are used to carry additional information and parameters in DHCP messages between client and server.

const (
	// RFC 3315
	OptionClientID    OptionCode = 1
	OptionServerID    OptionCode = 2
	OptionIANA        OptionCode = 3
	OptionIATA        OptionCode = 4
	OptionIAAddr      OptionCode = 5
	OptionORO         OptionCode = 6
	OptionPreference  OptionCode = 7
	OptionElapsedTime OptionCode = 8
	OptionRelayMsg    OptionCode = 9

	OptionAuth         OptionCode = 11
	OptionUnicast      OptionCode = 12
	OptionStatusCode   OptionCode = 13
	OptionRapidCommit  OptionCode = 14
	OptionUserClass    OptionCode = 15
	OptionVendorClass  OptionCode = 16
	OptionVendorOpts   OptionCode = 17
	OptionInterfaceID  OptionCode = 18
	OptionReconfMsg    OptionCode = 19
	OptionReconfAccept OptionCode = 20

	// RFC 3646
	OptionDNSServers OptionCode = 23

	// RFC 3633
	OptionIAPD     OptionCode = 25
	OptionIAPrefix OptionCode = 26

	// RFC 4649
	OptionRemoteIdentifier OptionCode = 37

	// RFC 5970
	OptionBootFileURL    OptionCode = 59
	OptionBootFileParam  OptionCode = 60
	OptionClientArchType OptionCode = 61
	OptionNII            OptionCode = 62
)

OptionCode constants which indicate the option codes described in RFC 3315, RFC 3633, and RFC 5970.

These option codes are taken from IANA's DHCPv6 parameters registry: http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml.

func (OptionCode) String

func (i OptionCode) String() string

type Options

type Options map[OptionCode][][]byte

Options is a map of OptionCode keys with a slice of byte slice values.

Its methods can be used to easily check for additional information from a packet. Get and GetOne should be used to access data from Options.

func (Options) Add

func (o Options) Add(key OptionCode, value encoding.BinaryMarshaler) error

Add adds a new OptionCode key and BinaryMarshaler struct's bytes to the Options map.

func (Options) AddRaw

func (o Options) AddRaw(key OptionCode, value []byte)

AddRaw adds a new OptionCode key and raw value byte slice to the Options map.

func (Options) Get

func (o Options) Get(key OptionCode) ([][]byte, error)

Get attempts to retrieve all values specified by an OptionCode key.

If a value is found, get returns a non-nil [][]byte and nil. If it is not found, Get returns nil and ErrOptionNotPresent.

func (Options) GetOne

func (o Options) GetOne(key OptionCode) ([]byte, error)

GetOne attempts to retrieve the first and only value specified by an OptionCode key. GetOne should only be used for OptionCode keys that must have at most one value.

GetOne works just like Get, but if there is more than one value for the OptionCode key, ErrInvalidPacket will be returned.

func (Options) MarshalBinary

func (o Options) MarshalBinary() ([]byte, error)

MarshalBinary allocates a buffer and writes options in their DHCPv6 binary format into the buffer.

func (*Options) UnmarshalBinary

func (o *Options) UnmarshalBinary(p []byte) error

UnmarshalBinary fills opts with option codes and corresponding values from an input byte slice.

It is used with various different types to enable parsing of both top-level options, and options embedded within other options. If options data is malformed, it returns ErrInvalidOptions.

type Packet

type Packet struct {
	// MessageType specifies the DHCP message type constant, such as
	// MessageTypeSolicit, MessageTypeAdvertise, etc.
	MessageType MessageType

	// TransactionID specifies the DHCP transaction ID.  The transaction ID must
	// be the same for all message exchanges in one DHCP transaction.
	TransactionID [3]byte

	// Options specifies a map of DHCP options.  Its methods can be used to
	// retrieve data from an incoming packet, or send data with an outgoing
	// packet.
	Options Options
}

Packet represents a raw DHCPv6 packet, using the format described in RFC 3315, Section 6.

The Packet type is typically only needed for low-level operations within the client, server, or in tests.

func (*Packet) MarshalBinary

func (p *Packet) MarshalBinary() ([]byte, error)

MarshalBinary allocates a byte slice containing the data from a Packet.

func (*Packet) UnmarshalBinary

func (p *Packet) UnmarshalBinary(q []byte) error

UnmarshalBinary unmarshals a raw byte slice into a Packet.

If the byte slice does not contain enough data to form a valid Packet, ErrInvalidPacket is returned.

type Status

type Status uint16

Status represesents a DHCP status code, as defined in RFC 3315, Section 5.4. Status codes are used to communicate success or failure between client and server.

const (
	// RFC 3315
	StatusSuccess      Status = 0
	StatusUnspecFail   Status = 1
	StatusNoAddrsAvail Status = 2
	StatusNoBinding    Status = 3
	StatusNotOnLink    Status = 4
	StatusUseMulticast Status = 5

	// RFC 3633
	StatusNoPrefixAvail Status = 6

	// RFC 5007
	StatusUnknownQueryType Status = 7
	StatusMalformedQuery   Status = 8
	StatusNotConfigured    Status = 9
	StatusNotAllowed       Status = 10

	// RFC 5460
	StatusQueryTerminated Status = 11
)

Status constants which indicate the status codes described in RFCs 3315, 3633, 5007, and 5460.

These status codes are taken from IANA's DHCPv6 parameters registry: http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml.

func (Status) String

func (i Status) String() string

Notes

Bugs

  • add additional option code types defined by IANA

Directories

Path Synopsis
cmd
dhcp6d
Command dhcp6d is an example DHCPv6 dhcp6server.
Command dhcp6d is an example DHCPv6 dhcp6server.
Package dhcp6test provides utilities for testing DHCPv6 clients and servers.
Package dhcp6test provides utilities for testing DHCPv6 clients and servers.
internal

Jump to

Keyboard shortcuts

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