dhcp6

package
v0.0.0-...-64f6de6 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// Client ID Option
	OptClientID uint16 = 1
	// Server ID Option
	OptServerID = 2
	// Identity Association for Non-temporary Addresses Option
	OptIaNa = 3
	// Identity Association for Temporary Addresses Option
	OptIaTa = 4
	// IA Address Option
	OptIaAddr = 5
	// Option Request Option
	OptOro = 6
	// Preference Option
	OptPreference = 7
	// Elapsed Time Option
	OptElapsedTime = 8
	// Relay Message Option
	OptRelayMessage = 9
	// Authentication Option
	OptAuth = 11
	// Server Unicast Option
	OptUnicast = 12
	// Status Code Option
	OptStatusCode = 13
	// Rapid Commit Option
	OptRapidCommit = 14
	// User Class Option
	OptUserClass = 15
	// Vendor Class Option
	OptVendorClass = 16
	// Vendor-specific Information Option
	OptVendorOpts = 17
	// Interface-Id Option
	OptInterfaceID = 18
	// Reconfigure Message Option
	OptReconfMsg = 19
	// Reconfigure Accept Option
	OptReconfAccept = 20
	// Recursive DNS name servers Option
	OptRecursiveDNS = 23
	// Boot File URL Option
	OptBootfileURL = 59
	// Boot File Parameters Option
	OptBootfileParam = 60
	// Client Architecture Type Option
	OptClientArchType = 61
)

DHCPv6 option IDs

Variables

This section is empty.

Functions

func InterfaceByAddress

func InterfaceByAddress(ifAddr string) (*net.Interface, error)

InterfaceByAddress finds the interface bound to an ip address, or returns an error if none were found

Types

type AddressPool

type AddressPool interface {
	ReserveAddresses(clientID []byte, interfaceIds [][]byte) ([]*IdentityAssociation, error)
	ReleaseAddresses(clientID []byte, interfaceIds [][]byte)
}

AddressPool keeps track of assigned and available ip address in an address pool

type BootConfiguration

type BootConfiguration interface {
	GetBootURL(id []byte, clientArchType uint16) ([]byte, error)
	GetPreference() []byte
	GetRecursiveDNS() []net.IP
}

BootConfiguration implementation provides values for dhcp options served to dhcp clients

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is dhcpv6-specific socket

func NewConn

func NewConn(addr, port string) (*Conn, error)

NewConn creates a new Conn bound to specified address and port

func (*Conn) Close

func (c *Conn) Close() error

Close closes Conn

func (*Conn) RecvDHCP

func (c *Conn) RecvDHCP() (*Packet, net.IP, error)

RecvDHCP reads next available dhcp packet from Conn

func (*Conn) SendDHCP

func (c *Conn) SendDHCP(dst net.IP, p []byte) error

SendDHCP sends a dhcp packet to the specified ip address using Conn

func (*Conn) SourceHardwareAddress

func (c *Conn) SourceHardwareAddress() net.HardwareAddr

SourceHardwareAddress returns hardware address of the interface used by Conn

type IdentityAssociation

type IdentityAssociation struct {
	IPAddress   net.IP
	ClientID    []byte
	InterfaceID []byte
	CreatedAt   time.Time
}

IdentityAssociation associates an ip address with a network interface of a client

type MessageType

type MessageType uint8

MessageType contains ID identifying DHCP message type. See RFC 3315

const (
	MsgSolicit MessageType = iota + 1
	MsgAdvertise
	MsgRequest
	MsgConfirm
	MsgRenew
	MsgRebind
	MsgReply
	MsgRelease
	MsgDecline
	MsgReconfigure
	MsgInformationRequest
	MsgRelayForw
	MsgRelayRepl
)

Constants for each of the dhcp message types defined in RFC 3315

type Option

type Option struct {
	ID     uint16
	Length uint16
	Value  []byte
}

Option represents a DHCPv6 Option

func MakeDNSServersOption

func MakeDNSServersOption(addresses []net.IP) *Option

MakeDNSServersOption creates a Recursive DNS servers Option with the specified list of IP addresses

func MakeIaAddrOption

func MakeIaAddrOption(addr net.IP, preferredLifetime, validLifetime uint32) *Option

MakeIaAddrOption creates an IA Address Option using IP address, preferred and valid lifetimes

func MakeIaNaOption

func MakeIaNaOption(iaid []byte, t1, t2 uint32, iaOption *Option) *Option

MakeIaNaOption creates a Identity Association for Non-temporary Addresses Option with specified interface ID, t1 and t2 times, and an interface-specific option (an IA Address Option or a Status Option)

func MakeOption

func MakeOption(id uint16, value []byte) *Option

MakeOption creates an Option with given ID and value

func MakeStatusOption

func MakeStatusOption(statusCode uint16, message string) *Option

MakeStatusOption creates a Status Option with given status code and message

func UnmarshalOption

func UnmarshalOption(bs []byte) (*Option, error)

UnmarshalOption de-serializes an Option

func (*Option) Marshal

func (o *Option) Marshal() ([]byte, error)

Marshal serializes the Option

type Options

type Options map[uint16][]*Option

Options contains all options of a DHCPv6 packet

func UnmarshalOptions

func UnmarshalOptions(bs []byte) (Options, error)

UnmarshalOptions unmarshals individual Options and returns them in a new Options data structure

func (Options) Add

func (o Options) Add(option *Option)

Add adds an option to Options

func (Options) BootFileURL

func (o Options) BootFileURL() []byte

BootFileURL returns the value in the Boot File URL Option, or nil if the option doesn't exist

func (Options) ClientArchType

func (o Options) ClientArchType() uint16

ClientArchType returns the value in the Client Architecture Type Option, or 0 if the option doesn't exist

func (Options) ClientID

func (o Options) ClientID() []byte

ClientID returns the value in the Client ID Option or nil if the option doesn't exist

func (Options) HasBootFileURLOption

func (o Options) HasBootFileURLOption() bool

HasBootFileURLOption returns true if Options contains Boot File URL Option

func (Options) HasClientArchType

func (o Options) HasClientArchType() bool

HasClientArchType returns true if Options contains Client Architecture Type Option

func (Options) HasClientID

func (o Options) HasClientID() bool

HasClientID returns true if Options contains Client ID Option

func (Options) HasIaNa

func (o Options) HasIaNa() bool

HasIaNa returns true oif Options contains Identity Association for Non-Temporary Addresses Option

func (Options) HasIaTa

func (o Options) HasIaTa() bool

HasIaTa returns true if Options contains Identity Association for Temporary Addresses Option

func (Options) HasServerID

func (o Options) HasServerID() bool

HasServerID returns true if Options contains Server ID Option

func (Options) HumanReadable

func (o Options) HumanReadable() []string

HumanReadable presents DHCPv6 options in a human-readable form

func (Options) IaNaIDs

func (o Options) IaNaIDs() [][]byte

IaNaIDs returns a list of interface IDs in all Identity Association for Non-Temporary Addresses Options, or an empty list if none exist

func (Options) Marshal

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

Marshal serializes Options

func (Options) ServerID

func (o Options) ServerID() []byte

ServerID returns the value in the Server ID Option or nil if the option doesn't exist

func (Options) UnmarshalOptionRequestOption

func (o Options) UnmarshalOptionRequestOption() map[uint16]bool

UnmarshalOptionRequestOption de-serializes Option Request Option

type Packet

type Packet struct {
	Type          MessageType
	TransactionID [3]byte
	Options       Options
}

Packet represents a DHCPv6 packet

func Unmarshal

func Unmarshal(bs []byte, packetLength int) (*Packet, error)

Unmarshal creates a Packet out of its serialized representation

func (*Packet) Marshal

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

Marshal serializes the Packet

func (*Packet) ShouldDiscard

func (p *Packet) ShouldDiscard(serverDuid []byte) error

ShouldDiscard returns true if the Packet fails validation

type PacketBuilder

type PacketBuilder struct {
	PreferredLifetime uint32
	ValidLifetime     uint32
}

PacketBuilder is used for generating responses to requests received from dhcp clients

func MakePacketBuilder

func MakePacketBuilder(preferredLifetime, validLifetime uint32) *PacketBuilder

MakePacketBuilder creates a new PacketBuilder and initializes it with preferred and valid lifetimes

func (*PacketBuilder) BuildResponse

func (b *PacketBuilder) BuildResponse(in *Packet, serverDUID []byte, configuration BootConfiguration, addresses AddressPool) (*Packet, error)

BuildResponse generates a response packet for a packet received from a client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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