dhcpv6

package module
v0.0.0-...-568de5a Latest Latest
Warning

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

Go to latest
Published: May 23, 2015 License: Apache-2.0 Imports: 5 Imported by: 0

README

DHCPv6 Library

Work-in-progress DHCPv6 library in Go.

API Docs

Goals

  • KISS
  • Fast
  • Learn/teach how DHCPv6 works
  • Small API (if it's easy to code it, don't)

Features

  • Marshal/Unmarshal Dhcp Messages and Options defined in RFC 3315

Documentation

Index

Examples

Constants

View Source
const (
	//addresses
	AddressAllDhcpServers               = "FF05::1:3"
	AddressAllDhcpRelayAgentsAndServers = "FF02::1:2"

	//Ports
	PortClient = 546
	PortServer = 547

	//Status Codes
	Success = iota
	UnspecFail
	NoAddrsAvail
	NoBinding
	NotOnLink
	UseMulticast

	Infinity = 0xffffffff
)

Variables

View Source
var ErrDuidTooLong = errors.New("Duid exceeds maximum length of 128 octets")
View Source
var ErrInvalidData = errors.New("Unexpected or invalid value was encountered")
View Source
var ErrInvalidIpv6Address = errors.New("Invalid IPv6 address")
View Source
var ErrInvalidType = errors.New("Invalid type for message")
View Source
var ErrNotImplemented = errors.New("Not implemented yet")
View Source
var ErrUnexpectedEOF = io.ErrUnexpectedEOF
View Source
var ErrWontFit = errors.New("The payload would exceed the size limit")

Functions

This section is empty.

Types

type AuthOption

type AuthOption struct {
	Protocol                  byte
	Algorithm                 byte
	RDM                       byte
	ReplayDetection           [8]byte
	AuthenticationInformation []byte
}

Authentication Option

func (*AuthOption) Code

func (o *AuthOption) Code() OptionCode

func (*AuthOption) MarshalBinary

func (o *AuthOption) MarshalBinary() ([]byte, error)

func (*AuthOption) UnmarshalBinary

func (o *AuthOption) UnmarshalBinary(data []byte) error

type ClientIdOption

type ClientIdOption struct {
	Duid Duid
}

Client Identifier Option The Client Identifier option is used to carry a DUID (see https://tools.ietf.org/html/rfc3315#section-9) identifying a client between a client and a server.

func (*ClientIdOption) Code

func (o *ClientIdOption) Code() OptionCode

func (*ClientIdOption) MarshalBinary

func (o *ClientIdOption) MarshalBinary() ([]byte, error)

func (*ClientIdOption) UnmarshalBinary

func (o *ClientIdOption) UnmarshalBinary(data []byte) error

type DhcpMessage

type DhcpMessage struct {
	MsgType       DhcpMessageType
	TransactionId [3]byte
	Options       []Option
}

Client/Server Message Format

func (*DhcpMessage) MarshalBinary

func (d *DhcpMessage) MarshalBinary() ([]byte, error)
Example

Create a DHCPv6 Solicit message from scratch and print it

d := DhcpMessage{
	MsgType:       TypeSolicit,
	TransactionId: [3]byte{0xa0, 0xa7, 0xa2},
	Options: []Option{
		&RapidCommitOption{},
		&IaNaOption{
			IAID: [4]byte{0xaf, 0xaa, 0xac, 0xa3},
			T1:   0,
			T2:   0,
		},
		&OroOption{
			RequestedOptionCodes: []uint16{
				23, //DNS recursive name server
				24, //Domain Search List
				56, //NTP Server
			},
		},
		&ClientIdOption{
			Duid: &EnDuid{
				EnterpriseNumber: 43793,
				Identifier:       []byte{0xac, 0xa2, 0xa8, 0xaf, 0xae, 0xa3, 0xa3, 0xaf},
			},
		},
		&ElapsedTimeOption{
			ElapsedTime: 0,
		},
	},
}
data, _ := d.MarshalBinary()
fmt.Println(hex.EncodeToString(data))
Output:

01a0a7a2000e00000003000cafaaaca30000000000000000000600060017001800380001000e00020000ab11aca2a8afaea3a3af000800020000

func (*DhcpMessage) UnmarshalBinary

func (d *DhcpMessage) UnmarshalBinary(data []byte) error

type DhcpMessageType

type DhcpMessageType byte
const (
	//message types
	TypeSolicit            DhcpMessageType = 1
	TypeAdvertise          DhcpMessageType = 2
	TypeRequest            DhcpMessageType = 3
	TypeConfirm            DhcpMessageType = 4
	TypeRenew              DhcpMessageType = 5
	TypeRebind             DhcpMessageType = 6
	TypeReply              DhcpMessageType = 7
	TypeRelease            DhcpMessageType = 8
	TypeDecline            DhcpMessageType = 9
	TypeReconfigure        DhcpMessageType = 10
	TypeInformationRequest DhcpMessageType = 11
	TypeRelayForward       DhcpMessageType = 12
	TypeRelayReply         DhcpMessageType = 13
)

type DhcpRelayMessage

type DhcpRelayMessage struct {
	MsgType     DhcpMessageType
	HopCount    byte
	LinkAddress net.IP
	PeerAddress net.IP
	Options     []Option
}

Relay Agent/Server Message Format

func (*DhcpRelayMessage) MarshalBinary

func (d *DhcpRelayMessage) MarshalBinary() ([]byte, error)

func (*DhcpRelayMessage) UnmarshalBinary

func (d *DhcpRelayMessage) UnmarshalBinary(data []byte) error

type Duid

DHCP Unique Identifier (DUID) Each DHCP client and server has a DUID. DHCP servers use DUIDs to identify clients for the selection of configuration parameters and in the association of IAs with clients. DHCP clients use DUIDs to identify a server in messages where a server needs to be identified.

A DUID consists of a two-octet type code represented in network byte order, followed by a variable number of octets that make up the actual identifier. A DUID can be no more than 128 octets long (not including the type code).

func UnmarshalBinaryDuid

func UnmarshalBinaryDuid(data []byte) (duid Duid, err error)

UnmarshalBinaryDuid will take the raw wire-format data and construct the correct structure underneath, returning the Duid interface.

type DuidType

type DuidType uint16

The motivation for having more than one type of DUID is that the DUID must be globally unique, and must also be easy to generate. The sort of globally-unique identifier that is easy to generate for any given device can differ quite widely. Also, some devices may not contain any persistent storage. Retaining a generated DUID in such a device is not possible, so the DUID scheme must accommodate such devices.

const (

	// Link-layer address plus time
	DuidTypeLlt DuidType = 1

	// Vendor-assigned unique ID based on Enterprise Number
	DuidTypeEn DuidType = 2

	// Link-layer address
	DuidTypeLl DuidType = 3
)

type ElapsedTimeOption

type ElapsedTimeOption struct {
	ElapsedTime uint16
}

Elapsed Time Option

func (*ElapsedTimeOption) Code

func (o *ElapsedTimeOption) Code() OptionCode

func (*ElapsedTimeOption) MarshalBinary

func (o *ElapsedTimeOption) MarshalBinary() ([]byte, error)

func (*ElapsedTimeOption) UnmarshalBinary

func (o *ElapsedTimeOption) UnmarshalBinary(data []byte) error

type EnDuid

type EnDuid struct {
	EnterpriseNumber uint32
	Identifier       []byte
}

DUID Assigned by Vendor Based on Enterprise Number [DUID-EN]

https://tools.ietf.org/html/rfc3315#section-9.3

func (*EnDuid) MarshalBinary

func (d *EnDuid) MarshalBinary() ([]byte, error)

func (*EnDuid) Type

func (d *EnDuid) Type() DuidType

func (*EnDuid) UnmarshalBinary

func (d *EnDuid) UnmarshalBinary(data []byte) error

type FQDNOption

type FQDNOption struct {
	Flags      uint8
	DomainName string
}

FQDN Option

func (*FQDNOption) Code

func (o *FQDNOption) Code() OptionCode

func (*FQDNOption) MarshalBinary

func (o *FQDNOption) MarshalBinary() ([]byte, error)

func (*FQDNOption) UnmarshalBinary

func (o *FQDNOption) UnmarshalBinary(data []byte) error

type IaAddrOption

type IaAddrOption struct {
	Ipv6Address       net.IP
	PreferredLifetime uint32
	ValidLifetime     uint32
	IAddrOptions      []Option
}

IA Address Option

func (*IaAddrOption) Code

func (o *IaAddrOption) Code() OptionCode

func (*IaAddrOption) MarshalBinary

func (o *IaAddrOption) MarshalBinary() ([]byte, error)

func (*IaAddrOption) UnmarshalBinary

func (o *IaAddrOption) UnmarshalBinary(data []byte) error

type IaNaOption

type IaNaOption struct {
	IAID        [4]byte
	T1          uint32
	T2          uint32
	IaNaOptions []Option
}

Identity Association for Non-temporary Addresses Option

func (*IaNaOption) Code

func (o *IaNaOption) Code() OptionCode

func (*IaNaOption) MarshalBinary

func (o *IaNaOption) MarshalBinary() ([]byte, error)

func (*IaNaOption) UnmarshalBinary

func (o *IaNaOption) UnmarshalBinary(data []byte) error

type IaTaOption

type IaTaOption struct {
	IAID        [4]byte
	IaTaOptions []Option
}

Identity Association for Temporary Addresses Option

func (*IaTaOption) Code

func (o *IaTaOption) Code() OptionCode

func (*IaTaOption) MarshalBinary

func (o *IaTaOption) MarshalBinary() ([]byte, error)

func (*IaTaOption) UnmarshalBinary

func (o *IaTaOption) UnmarshalBinary(data []byte) error

type InterfaceIdOption

type InterfaceIdOption struct {
	InterfaceId []byte
}

Interface-Id Option

func (*InterfaceIdOption) Code

func (o *InterfaceIdOption) Code() OptionCode

func (*InterfaceIdOption) MarshalBinary

func (o *InterfaceIdOption) MarshalBinary() ([]byte, error)

func (*InterfaceIdOption) UnmarshalBinary

func (o *InterfaceIdOption) UnmarshalBinary(data []byte) error

type LlDuid

type LlDuid struct {
	HardwareType uint16
	LlAddress    []byte
}

DUID Based on Link-layer Address [DUID-LL]

https://tools.ietf.org/html/rfc3315#section-9.4

func (*LlDuid) MarshalBinary

func (d *LlDuid) MarshalBinary() ([]byte, error)

func (*LlDuid) Type

func (d *LlDuid) Type() DuidType

func (*LlDuid) UnmarshalBinary

func (d *LlDuid) UnmarshalBinary(data []byte) error

type LltDuid

type LltDuid struct {
	HardwareType uint16
	Time         uint32
	LlAddress    []byte
}

DUID Based on Link-layer Address Plus Time [DUID-LLT]

https://tools.ietf.org/html/rfc3315#section-9.2

func (*LltDuid) MarshalBinary

func (d *LltDuid) MarshalBinary() ([]byte, error)

func (*LltDuid) Type

func (d *LltDuid) Type() DuidType

func (*LltDuid) UnmarshalBinary

func (d *LltDuid) UnmarshalBinary(data []byte) error

type MTUOption

type MTUOption struct {
	MTU uint16
}

MTU Option

func (*MTUOption) Code

func (o *MTUOption) Code() OptionCode

func (*MTUOption) MarshalBinary

func (o *MTUOption) MarshalBinary() ([]byte, error)

func (*MTUOption) UnmarshalBinary

func (o *MTUOption) UnmarshalBinary(data []byte) error

type NextHopOption

type NextHopOption struct {
	NextHop        net.IP
	NextHopOptions []Option
}

Next Hop Option

func (*NextHopOption) Code

func (o *NextHopOption) Code() OptionCode

func (*NextHopOption) MarshalBinary

func (o *NextHopOption) MarshalBinary() ([]byte, error)

func (*NextHopOption) UnmarshalBinary

func (o *NextHopOption) UnmarshalBinary(data []byte) error

type Option

type Option interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	Code() OptionCode
}

DHCPv6 options are scoped by using encapsulation. Some options apply generally to the client, some are specific to an IA, and some are specific to the addresses within an IA.

func UnmarshalBinaryOption

func UnmarshalBinaryOption(data []byte) (option Option, err error)

UnmarshalBinaryOption will take the raw wire-format data and construct the correct structure underneath, returning the Option interface.

If the option type is not defined the option will be decoded as an UnknownOption allowing raw access to the option code and data.

type OptionCode

type OptionCode uint16
const (
	//Options
	OptionCodeClientId     OptionCode = 1
	OptionCodeServerId     OptionCode = 2
	OptionCodeIaNa         OptionCode = 3
	OptionCodeIaTa         OptionCode = 4
	OptionCodeIaAddr       OptionCode = 5
	OptionCodeOro          OptionCode = 6
	OptionCodePreference   OptionCode = 7
	OptionCodeElapsedTime  OptionCode = 8
	OptionCodeRelayMsg     OptionCode = 9
	OptionCodeAuth         OptionCode = 11
	OptionCodeUnicast      OptionCode = 12
	OptionCodeStatusCode   OptionCode = 13
	OptionCodeRapidCommit  OptionCode = 14
	OptionCodeUserClass    OptionCode = 15
	OptionCodeVendorClass  OptionCode = 16
	OptionCodeVendorOpts   OptionCode = 17
	OptionCodeInterfaceId  OptionCode = 18
	OptionCodeReconfMsg    OptionCode = 19
	OptionCodeReconfAccept OptionCode = 20
	OptionCodeIaPd         OptionCode = 25
	OptionCodeIaPrefix     OptionCode = 26
	OptionCodeFQDN         OptionCode = 39
	OptionCodeNextHop      OptionCode = 242
	OptionCodeRtPrefix     OptionCode = 243
	OptionCodeMTU          OptionCode = 244
)

type OroOption

type OroOption struct {
	RequestedOptionCodes []uint16
}

Option Request Option

func (*OroOption) Code

func (o *OroOption) Code() OptionCode

func (*OroOption) MarshalBinary

func (o *OroOption) MarshalBinary() ([]byte, error)

func (*OroOption) UnmarshalBinary

func (o *OroOption) UnmarshalBinary(data []byte) error

type PreferenceOption

type PreferenceOption struct {
	PreferenceValue byte
}

Preference Option

func (*PreferenceOption) Code

func (o *PreferenceOption) Code() OptionCode

func (*PreferenceOption) MarshalBinary

func (o *PreferenceOption) MarshalBinary() ([]byte, error)

func (*PreferenceOption) UnmarshalBinary

func (o *PreferenceOption) UnmarshalBinary(data []byte) error

type RapidCommitOption

type RapidCommitOption struct{}

Rapid Commit Option

func (*RapidCommitOption) Code

func (o *RapidCommitOption) Code() OptionCode

func (*RapidCommitOption) MarshalBinary

func (o *RapidCommitOption) MarshalBinary() ([]byte, error)

func (*RapidCommitOption) UnmarshalBinary

func (o *RapidCommitOption) UnmarshalBinary(data []byte) error

type ReconfAcceptOption

type ReconfAcceptOption struct{}

Reconfigure Accept Option

func (*ReconfAcceptOption) Code

func (o *ReconfAcceptOption) Code() OptionCode

func (*ReconfAcceptOption) MarshalBinary

func (o *ReconfAcceptOption) MarshalBinary() ([]byte, error)

func (*ReconfAcceptOption) UnmarshalBinary

func (o *ReconfAcceptOption) UnmarshalBinary(data []byte) error

type ReconfMsgOption

type ReconfMsgOption struct {
	MsgType byte
}

Reconfigure Message Option

func (*ReconfMsgOption) Code

func (o *ReconfMsgOption) Code() OptionCode

func (*ReconfMsgOption) MarshalBinary

func (o *ReconfMsgOption) MarshalBinary() ([]byte, error)

func (*ReconfMsgOption) UnmarshalBinary

func (o *ReconfMsgOption) UnmarshalBinary(data []byte) error

type RelayMsgOption

type RelayMsgOption struct {
	DhcpRelayMessage DhcpMessage
}

Relay Message Option

func (*RelayMsgOption) Code

func (o *RelayMsgOption) Code() OptionCode

func (*RelayMsgOption) MarshalBinary

func (o *RelayMsgOption) MarshalBinary() ([]byte, error)

func (*RelayMsgOption) UnmarshalBinary

func (o *RelayMsgOption) UnmarshalBinary(data []byte) error

type RtPrefixOption

type RtPrefixOption struct {
	Lifetime  uint32
	Prefixlen uint8
	Metric    uint8
	Prefix    net.IP
}

RtPrefix Option

func (*RtPrefixOption) Code

func (o *RtPrefixOption) Code() OptionCode

func (*RtPrefixOption) MarshalBinary

func (o *RtPrefixOption) MarshalBinary() ([]byte, error)

func (*RtPrefixOption) UnmarshalBinary

func (o *RtPrefixOption) UnmarshalBinary(data []byte) error

type ServerIdOption

type ServerIdOption struct {
	Duid Duid
}

Server Identifier Option

The Server Identifier option is used to carry a DUID (see section 9) identifying a server between a client and a server.

func (*ServerIdOption) Code

func (o *ServerIdOption) Code() OptionCode

func (*ServerIdOption) MarshalBinary

func (o *ServerIdOption) MarshalBinary() ([]byte, error)

func (*ServerIdOption) UnmarshalBinary

func (o *ServerIdOption) UnmarshalBinary(data []byte) error

type StatusCodeOption

type StatusCodeOption struct {
	StatusCode    uint16
	StatusMessage string
}

Status Code Option

func (*StatusCodeOption) Code

func (o *StatusCodeOption) Code() OptionCode

func (*StatusCodeOption) MarshalBinary

func (o *StatusCodeOption) MarshalBinary() ([]byte, error)

func (*StatusCodeOption) UnmarshalBinary

func (o *StatusCodeOption) UnmarshalBinary(data []byte) error

type UnicastOption

type UnicastOption struct {
	ServerAddress net.IP
}

Server Unicast Option

func (*UnicastOption) Code

func (o *UnicastOption) Code() OptionCode

func (*UnicastOption) MarshalBinary

func (o *UnicastOption) MarshalBinary() ([]byte, error)

func (*UnicastOption) UnmarshalBinary

func (o *UnicastOption) UnmarshalBinary(data []byte) error

type UnknownOption

type UnknownOption struct {
	OptionCode OptionCode
	OptionData []byte
}

UnknownOption is not a defined type, it is just a placeholder for undefined option types.

func (*UnknownOption) Code

func (o *UnknownOption) Code() OptionCode

func (*UnknownOption) MarshalBinary

func (o *UnknownOption) MarshalBinary() ([]byte, error)

func (*UnknownOption) UnmarshalBinary

func (o *UnknownOption) UnmarshalBinary(data []byte) error

type UserClassOption

type UserClassOption struct {
	UserClassData [][]byte
}

User Class Option

func (*UserClassOption) Code

func (o *UserClassOption) Code() OptionCode

func (*UserClassOption) MarshalBinary

func (o *UserClassOption) MarshalBinary() ([]byte, error)

func (*UserClassOption) UnmarshalBinary

func (o *UserClassOption) UnmarshalBinary(data []byte) error

type VendorClassOption

type VendorClassOption struct {
	VendorClassData [][]byte
}

Vendor Class Option

func (*VendorClassOption) Code

func (o *VendorClassOption) Code() OptionCode

func (*VendorClassOption) MarshalBinary

func (o *VendorClassOption) MarshalBinary() ([]byte, error)

func (*VendorClassOption) UnmarshalBinary

func (o *VendorClassOption) UnmarshalBinary(data []byte) error

type VendorOptsOption

type VendorOptsOption struct {
	EnterpriseNumber uint32
	OptionData       []VendorOptsOptionData
}

Vendor-specific Information Option

func (*VendorOptsOption) Code

func (o *VendorOptsOption) Code() OptionCode

func (*VendorOptsOption) MarshalBinary

func (o *VendorOptsOption) MarshalBinary() ([]byte, error)

func (*VendorOptsOption) UnmarshalBinary

func (o *VendorOptsOption) UnmarshalBinary(data []byte) error

type VendorOptsOptionData

type VendorOptsOptionData struct {
	OptionCode uint16
	OptionData []byte
}

Jump to

Keyboard shortcuts

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