dhcp4

package module
Version: v0.0.0-...-03363dc Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2019 License: BSD-3-Clause Imports: 9 Imported by: 38

README

dhcp4

CircleCI Go Report Card GoDoc License

Package dhcp4 is an IPv4 DHCP library as described in RFC 2131, 2132, and 3396.

It implements encoding and decoding of DHCP messages in dhcp4. Option parsing is in the dhcp4opts package; a simple client is included in dhcp4client. Some day, there may be a server.

If you are already using another IPv4 DHCP library like krolaw's, you can still use dhcp4opts to decode options not implemented in krolaw's DHCP library.

Documentation

Overview

Package dhcp4 implements constants and marshaling for IPv4 DHCP packets as described by RFC 2131, RFC 2132, and RFC 3396.

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.
	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 OpCode

type OpCode uint8

OpCode is the BOOTP message type as defined by RFC 2131, Section 2.

Note that the DHCP message type is embedded via OptionDHCPMessageType.

const (
	BootRequest OpCode = 1
	BootReply   OpCode = 2
)

Legal op codes as defined by RFC 2131, Section 2.

type OptionCode

type OptionCode uint8

OptionCode is a DHCP option code as defined by RFC 2132.

const (
	End                                              OptionCode = 255
	Pad                                              OptionCode = 0
	OptionSubnetMask                                 OptionCode = 1
	OptionTimeOffset                                 OptionCode = 2
	OptionRouters                                    OptionCode = 3
	OptionTimeServers                                OptionCode = 4
	OptionNameServers                                OptionCode = 5
	OptionDomainNameServers                          OptionCode = 6
	OptionLogServers                                 OptionCode = 7
	OptionCookieServers                              OptionCode = 8
	OptionLPRServers                                 OptionCode = 9
	OptionImpressServers                             OptionCode = 10
	OptionResourceLocationServers                    OptionCode = 11
	OptionHostName                                   OptionCode = 12
	OptionBootFileSize                               OptionCode = 13
	OptionMeritDumpFile                              OptionCode = 14
	OptionDomainName                                 OptionCode = 15
	OptionSwapServer                                 OptionCode = 16
	OptionRootPath                                   OptionCode = 17
	OptionExtensionsPath                             OptionCode = 18
	OptionIPForwardingEnableDisable                  OptionCode = 19
	OptionNonLocalSourceRoutingEnableDisable         OptionCode = 20
	OptionPolicyFilter                               OptionCode = 21
	OptionMaximumDatagramReassemblySize              OptionCode = 22
	OptionDefaultIPTimeToLive                        OptionCode = 23
	OptionPathMTUAgingTimeout                        OptionCode = 24
	OptionPathMTUPlateauTable                        OptionCode = 25
	OptionInterfaceMTU                               OptionCode = 26
	OptionAllSubnetsAreLocal                         OptionCode = 27
	OptionBroadcastAddress                           OptionCode = 28
	OptionPerformMaskDiscovery                       OptionCode = 29
	OptionMaskSupplier                               OptionCode = 30
	OptionPerformRouterDiscovery                     OptionCode = 31
	OptionRouterSolicitationAddress                  OptionCode = 32
	OptionStaticRoute                                OptionCode = 33
	OptionTrailerEncapsulation                       OptionCode = 34
	OptionARPCacheTimeout                            OptionCode = 35
	OptionEthernetEncapsulation                      OptionCode = 36
	OptionTCPDefaultTTL                              OptionCode = 37
	OptionTCPKeepaliveInterval                       OptionCode = 38
	OptionTCPKeepaliveGarbage                        OptionCode = 39
	OptionNetworkInformationServiceDomain            OptionCode = 40
	OptionNetworkInformationServers                  OptionCode = 41
	OptionNetworkTimeProtocolServers                 OptionCode = 42
	OptionVendorSpecificInformation                  OptionCode = 43
	OptionNetBIOSOverTCPIPNameServer                 OptionCode = 44
	OptionNetBIOSOverTCPIPDatagramDistributionServer OptionCode = 45
	OptionNetBIOSOverTCPIPNodeType                   OptionCode = 46
	OptionNetBIOSOverTCPIPScope                      OptionCode = 47
	OptionXWindowSystemFontServer                    OptionCode = 48
	OptionXWindowSystemDisplayManager                OptionCode = 49

	// DHCP extensions.
	OptionRequestedIPAddress     OptionCode = 50
	OptionIPAddressLeaseTime     OptionCode = 51
	OptionOverload               OptionCode = 52
	OptionDHCPMessageType        OptionCode = 53
	OptionServerIdentifier       OptionCode = 54
	OptionParameterRequestList   OptionCode = 55
	OptionMessage                OptionCode = 56
	OptionMaximumDHCPMessageSize OptionCode = 57
	OptionRenewalTimeValue       OptionCode = 58
	OptionRebindingTimeValue     OptionCode = 59
	OptionVendorClassIdentifier  OptionCode = 60
	OptionClientIdentifier       OptionCode = 61
	OptionTFTPServerName         OptionCode = 66
	OptionBootFileName           OptionCode = 67
)

Option codes defined by RFC 2132. (Incomplete)

type Options

type Options map[OptionCode][]byte

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

Its methods can be used to easily check for additional information from a packet. Get 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'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

Get attempts to retrieve the value specified by an OptionCode key.

If a value is found, get returns a non-nil byte slice. If it is not found, Get returns nil.

func (Options) Marshal

func (o Options) Marshal(b *uio.Lexer)

Marshal writes options into the provided Buffer sorted by option codes.

func (*Options) Unmarshal

func (o *Options) Unmarshal(buf *uio.Lexer) error

Unmarshal 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. If options data is malformed, it returns ErrInvalidOptions or io.ErrUnexpectedEOF.

type Packet

type Packet struct {
	// Op is the BOOTP message op code / message type.
	//
	// This is not to be confused with the DHCP message type, which is
	// defined as an option value.
	Op OpCode

	// HType is the hardware type.
	//
	// The possible values are listed in the IANA ARP assigned numbers.
	HType uint8

	// Hops is the number of hops this packet has taken.
	Hops uint8

	// TransactionID is a random number used to associate server responses
	// with client requests.
	TransactionID [4]byte

	// Secs is the number of seconds elapsed since the client began address
	// acquisition or renewal process.
	Secs uint16

	// Broadcast is the broadcast flag of the flags field.
	Broadcast bool

	// Client IP address.
	CIAddr net.IP

	// Your IP address.
	YIAddr net.IP

	// Server IP address.
	SIAddr net.IP

	// Gateway IP address.
	GIAddr net.IP

	// Client hardware address.
	CHAddr net.HardwareAddr

	// ServerName is an optional server host name.
	ServerName string

	// BootFile is a fully qualified directory path to the boot file.
	BootFile string

	// Options is the list of vendor-specific extensions.
	Options Options
}

Packet is a DHCPv4 packet as described in RFC 2131, Section 2.

func NewPacket

func NewPacket(op OpCode) *Packet

NewPacket returns a new DHCP packet with the given op code.

func ParsePacket

func ParsePacket(q []byte) (*Packet, error)

ParsePacket parses a DHCP4 packet from q.

func (*Packet) MarshalBinary

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

MarshalBinary writes the packet to binary.

func (*Packet) UnmarshalBinary

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

UnmarshalBinary reads the packet from binary.

Directories

Path Synopsis
cmd
Package dhcp4client is a small, minimum-functionality client for DHCPv4.
Package dhcp4client is a small, minimum-functionality client for DHCPv4.
Package dhcp4opts implements Options parsing for DHCPv4 options as described in RFC 2132.
Package dhcp4opts implements Options parsing for DHCPv4 options as described in RFC 2132.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL