Documentation ¶
Overview ¶
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func Init(l log.Logger)
- func ListenAndServe(addr string, h Handler) error
- func PacketToBytes(p Packet, opts *packetToBytesOptions) ([]byte, error)
- func Serve(pc PacketConn, h Handler) error
- func SetOptionFormatter(o Option, fn func([]byte) []interface{})
- func Validate(p Packet, vs []Validation) error
- type Ack
- type Handler
- type MessageType
- type Nak
- type Offer
- type OpCode
- type Option
- type OptionGetter
- type OptionMap
- func (om OptionMap) Decode(dst interface{})
- func (om OptionMap) Deserialize(x []byte, opts *OptionMapDeserializeOptions) error
- func (om OptionMap) Encode(dst interface{})
- func (om OptionMap) GetDuration(o Option) (time.Duration, bool)
- func (om OptionMap) GetIP(o Option) (net.IP, bool)
- func (om OptionMap) GetMessageType() MessageType
- func (om OptionMap) GetOption(o Option) ([]byte, bool)
- func (om OptionMap) GetSortedOptions() []Option
- func (om OptionMap) GetString(o Option) (string, bool)
- func (om OptionMap) GetUint16(o Option) (uint16, bool)
- func (om OptionMap) GetUint32(o Option) (uint32, bool)
- func (om OptionMap) GetUint8(o Option) (uint8, bool)
- func (om OptionMap) Serialize() []byte
- func (om OptionMap) SetDuration(o Option, v time.Duration)
- func (om OptionMap) SetIP(o Option, v net.IP)
- func (om OptionMap) SetMessageType(m MessageType)
- func (om OptionMap) SetOption(o Option, v []byte)
- func (om OptionMap) SetString(o Option, v string)
- func (om OptionMap) SetUint16(o Option, v uint16)
- func (om OptionMap) SetUint32(o Option, v uint32)
- func (om OptionMap) SetUint8(o Option, v uint8)
- type OptionMapDeserializeOptions
- type OptionSetter
- type Packet
- type PacketConn
- type PacketGetter
- type PacketReader
- type PacketSetter
- type PacketWriter
- type RawPacket
- func (p RawPacket) CHAddr() []byte
- func (p RawPacket) CIAddr() []byte
- func (p RawPacket) Cookie() []byte
- func (p RawPacket) File() []byte
- func (p RawPacket) Flags() []byte
- func (p RawPacket) GIAddr() []byte
- func (p RawPacket) GetCHAddr() net.HardwareAddr
- func (p RawPacket) GetCIAddr() net.IP
- func (p RawPacket) GetFlags() []byte
- func (p RawPacket) GetGIAddr() net.IP
- func (p RawPacket) GetHLen() uint8
- func (p RawPacket) GetHType() uint8
- func (p RawPacket) GetSIAddr() net.IP
- func (p RawPacket) GetXID() []byte
- func (p RawPacket) GetYIAddr() net.IP
- func (p RawPacket) HLen() []byte
- func (p RawPacket) HType() []byte
- func (p RawPacket) Hops() []byte
- func (p RawPacket) Op() []byte
- func (p RawPacket) Options() []byte
- func (p RawPacket) ParseOptions() (OptionMap, error)
- func (p RawPacket) SIAddr() []byte
- func (p RawPacket) SName() []byte
- func (p RawPacket) Secs() []byte
- func (p RawPacket) SetCIAddr(ip net.IP)
- func (p RawPacket) SetGIAddr(ip net.IP)
- func (p RawPacket) SetSIAddr(ip net.IP)
- func (p RawPacket) SetYIAddr(ip net.IP)
- func (p RawPacket) XID() []byte
- func (p RawPacket) YIAddr() []byte
- type Reply
- type ReplyWriter
- type Validation
- type ValidationError
Constants ¶
const ( MessageTypeDiscover = MessageType(1) MessageTypeOffer = MessageType(2) MessageTypeRequest = MessageType(3) MessageTypeDecline = MessageType(4) MessageTypeAck = MessageType(5) MessageTypeNak = MessageType(6) MessageTypeRelease = MessageType(7) MessageTypeInform = MessageType(8) )
const ( // RFC2132 Section 3: RFC 1497 Vendor Extensions OptionPad = Option(0) OptionEnd = Option(255) OptionSubnetMask = Option(1) OptionTimeOffset = Option(2) OptionRouter = Option(3) OptionTimeServer = Option(4) OptionNameServer = Option(5) OptionDomainServer = Option(6) OptionLogServer = Option(7) OptionQuotesServer = Option(8) OptionLPRServer = Option(9) OptionImpressServer = Option(10) OptionRLPServer = Option(11) OptionHostname = Option(12) OptionBootFileSize = Option(13) OptionMeritDumpFile = Option(14) OptionDomainName = Option(15) OptionSwapServer = Option(16) OptionRootPath = Option(17) OptionExtensionFile = Option(18) // RFC2132 Section 4: IP Layer Parameters per Host OptionForwardOnOff = Option(19) OptionSrcRteOnOff = Option(20) OptionPolicyFilter = Option(21) OptionMaxDGAssembly = Option(22) OptionDefaultIPTTL = Option(23) OptionMTUTimeout = Option(24) OptionMTUPlateau = Option(25) // RFC2132 Section 5: IP Layer Parameters per Interface OptionMTUInterface = Option(26) OptionMTUSubnet = Option(27) OptionBroadcastAddress = Option(28) OptionMaskDiscovery = Option(29) OptionMaskSupplier = Option(30) OptionRouterDiscovery = Option(31) OptionRouterRequest = Option(32) OptionStaticRoute = Option(33) // RFC2132 Section 6: Link Layer Parameters per Interface OptionTrailers = Option(34) OptionARPTimeout = Option(35) OptionEthernet = Option(36) // RFC2132 Section 7: TCP Parameters OptionDefaultTCPTTL = Option(37) OptionKeepaliveTime = Option(38) OptionKeepaliveData = Option(39) // RFC2132 Section 8: Application and Service Parameters OptionNISDomain = Option(40) OptionNISServers = Option(41) OptionNTPServers = Option(42) OptionVendorSpecific = Option(43) OptionNETBIOSNameSrv = Option(44) OptionNETBIOSDistSrv = Option(45) OptionNETBIOSNodeType = Option(46) OptionNETBIOSScope = Option(47) OptionXWindowFont = Option(48) OptionXWindowManager = Option(49) OptionNISDomainName = Option(64) OptionNISServerAddr = Option(65) OptionHomeAgentAddrs = Option(68) OptionSMTPServer = Option(69) OptionPOP3Server = Option(70) OptionNNTPServer = Option(71) OptionWWWServer = Option(72) OptionFingerServer = Option(73) OptionIRCServer = Option(74) OptionStreetTalkServer = Option(75) OptionSTDAServer = Option(76) // RFC2132 Section 9: DHCP Extensions OptionAddressRequest = Option(50) OptionAddressTime = Option(51) OptionOverload = Option(52) OptionServerName = Option(66) OptionBootfileName = Option(67) OptionDHCPMsgType = Option(53) OptionDHCPServerID = Option(54) OptionParameterList = Option(55) OptionDHCPMessage = Option(56) OptionDHCPMaxMsgSize = Option(57) OptionRenewalTime = Option(58) OptionRebindingTime = Option(59) OptionClassID = Option(60) OptionClientID = Option(61) )
From RFC2132: DHCP Options and BOOTP Vendor Extensions
const ( OptionNDSServers = Option(85) OptionNDSTreeName = Option(86) OptionNDSContext = Option(87) )
From RFC2241: DHCP Options for Novell Directory Services
const ( OptionNetWareIPDomain = Option(62) OptionNetWareIPOption = Option(63) )
From RFC2242: NetWare/IP Domain Name and Information
const ( OptionDirectoryAgent = Option(78) OptionServiceScope = Option(79) )
From RFC2610: DHCP Options for Service Location Protocol
const ( OptionLDAP = Option(95) OptionNetinfoAddress = Option(112) OptionNetinfoTag = Option(113) OptionURL = Option(114) )
From RFC3679: Unused Dynamic Host Configuration Protocol (DHCP) Option Codes
const ( OptionVIVendorClass = Option(124) OptionVIVendorSpecificInformation = Option(125) )
From RFC3925: Vendor-Identifying Vendor Options for Dynamic Host Configuration Protocol version 4 (DHCPv4)
const ( OptionBCMCSControllerDomainNameList = Option(88) OptionBCMCSControllerIPv4AddressOption = Option(89) )
From RFC4280: Dynamic Host Configuration Protocol (DHCP) Options for Broadcast and Multicast Control Servers
const ( OptionClientLastTransactionTimeOption = Option(91) OptionAssociatedIPOption = Option(92) )
From RFC4388: Dynamic Host Configuration Protocol (DHCP) Leasequery
const ( OptionClientSystem = Option(93) OptionClientNDI = Option(94) OptionUUIDGUID = Option(97) OptionPXEUndefined128 = Option(128) OptionPXEUndefined129 = Option(129) OptionPXEUndefined130 = Option(130) OptionPXEUndefined131 = Option(131) OptionPXEUndefined132 = Option(132) OptionPXEUndefined133 = Option(133) OptionPXEUndefined134 = Option(134) OptionPXEUndefined135 = Option(135) )
From RFC4578: Dynamic Host Configuration Protocol (DHCP) Options for the Intel Preboot eXecution Environment (PXE)
const ( OptionPCode = Option(100) OptionTCode = Option(101) )
From RFC4833: Timezone Options for DHCP
const ( OptionGeoConfOption = Option(123) OptionGeoLoc = Option(144) )
From RFC6225: Dynamic Host Configuration Protocol Options for Coordinate-Based Location Configuration Information
const ( BootRequest = OpCode(1) BootReply = OpCode(2) )
Message op codes defined in RFC2132.
const (
OptionAuthentication = Option(90)
)
From RFC3118: Authentication for DHCP Messages
const (
OptionAutoConfig = Option(116)
)
From RFC2563: DHCP Option to Disable Stateless Auto-Configuration in IPv4 Clients
const (
OptionCCC = Option(122)
)
From RFC3495: Dynamic Host Configuration Protocol (DHCP) Option for CableLabs Client Configuration
const (
OptionClasslessStaticRouteOption = Option(121)
)
From RFC3442: The Classless Static Route Option for Dynamic Host Configuration Protocol (DHCP) version 4
const (
OptionClientFQDN = Option(81)
)
From RFC4702: The Dynamic Host Configuration Protocol (DHCP) Client Fully Qualified Domain Name (FQDN) Option
const (
OptionDomainSearch = Option(119)
)
From RFC3397: Dynamic Host Configuration Protocol (DHCP) Domain Search Option
const (
OptionGeoConfCivic = Option(99)
)
From RFC4776: Dynamic Host Configuration Protocol (DHCPv4 and DHCPv6) Option for Civic Addresses Configuration Information
const (
OptionNameServiceSearch = Option(117)
)
From RFC2937: The Name Service Search Option for DHCP
const (
OptionRapidCommit = Option(80)
)
From RFC4039: Rapid Commit Option for the Dynamic Host Configuration Protocol version 4 (DHCPv4)
const (
OptionRelayAgentInformation = Option(82)
)
From RFC3046: DHCP Relay Agent Information Option
const (
OptionSIPServersDHCPOption = Option(120)
)
From RFC3361: Dynamic Host Configuration Protocol (DHCP-for-IPv4) Option for Session Initiation Protocol (SIP) Servers
const (
OptionSubnetSelectionOption = Option(118)
)
From RFC3011: The IPv4 Subnet Selection Option for DHCP
const (
OptionUserAuth = Option(98)
)
From RFC2485: DHCP Option for The Open Group\x27s User Authentication Protocol
const (
OptionUserClass = Option(77)
)
From RFC3004: The User Class Option for DHCP
const (
OptioniSNS = Option(83)
)
From RFC4174: The IPv4 Dynamic Host Configuration Protocol (DHCP) Option for the Internet Storage Name Service
Variables ¶
var ( ErrShortPacket = errors.New("dhcp4: short packet") ErrInvalidPacket = errors.New("dhcp4: invalid packet") )
Functions ¶
func ListenAndServe ¶
func PacketToBytes ¶
PacketToBytes serializes the DHCP packet pointed to by p into its wire-level representation. The function may return an error if it cannot successfully serialize the packet. Otherwise, it returns a newly created byte slice.
func Serve ¶
func Serve(pc PacketConn, h Handler) error
Serve reads packets off the network and calls the specified handler.
func SetOptionFormatter ¶
func Validate ¶
func Validate(p Packet, vs []Validation) error
Types ¶
type Ack ¶
type Ack struct { Packet // contains filtered or unexported fields }
Ack is a server to client packet with configuration parameters, including committed network address.
type Handler ¶
type Handler interface {
ServeDHCP(w ReplyWriter, p *Packet)
}
FIXME(betawaffle) Handler defines the interface an object needs to implement to handle DHCP packets. The handler should do a type switch on the Message object that is passed as argument to determine what kind of packet it is dealing with. It can use the WriteReply function on the request to send a reply back to the peer responsible for sending the request packet. While the handler may be blocking, it is not encouraged. Rather, the handler should return as soon as possible to avoid blocking the serve loop. If blocking operations need to be executed to determine if the request packet needs a reply, and if so, what kind of reply, it is recommended to handle this in separate goroutines. The WriteReply function can be called from multiple goroutines without needing extra synchronization.
type MessageType ¶
type MessageType byte
MessageType is the type for the various DHCP messages defined in RFC2132.
func (MessageType) String ¶
func (t MessageType) String() string
type Nak ¶
type Nak struct { Packet // contains filtered or unexported fields }
Nak is a server to client packet indicating client's notion of network address is incorrect (e.g., client has moved to new subnet) or client's lease as expired.
type Offer ¶
type Offer struct { Packet // contains filtered or unexported fields }
Offer is a server to client packet in response to DHCPDISCOVER with offer of configuration parameters.
func CreateOffer ¶
type OptionGetter ¶
type OptionGetter interface { GetSortedOptions() []Option GetOption(Option) ([]byte, bool) GetMessageType() MessageType GetUint8(Option) (uint8, bool) GetUint16(Option) (uint16, bool) GetUint32(Option) (uint32, bool) GetString(Option) (string, bool) GetIP(Option) (net.IP, bool) GetDuration(Option) (time.Duration, bool) }
OptionGetter defines a bag of functions that can be used to get options.
type OptionMap ¶
OptionMap maps DHCP option tags to their values.
func (OptionMap) Deserialize ¶
func (om OptionMap) Deserialize(x []byte, opts *OptionMapDeserializeOptions) error
Deserialize reads options from the []byte into the option map.
func (OptionMap) GetDuration ¶
GetDuration gets the duration value of an option, stored as a 32 bit unsigned integer.
func (OptionMap) GetMessageType ¶
func (om OptionMap) GetMessageType() MessageType
GetMessageType gets the message type from the DHCPMsgType option field.
func (OptionMap) GetSortedOptions ¶
GetSortedOptions gets all the options (keys) in sorted order.
func (OptionMap) SetDuration ¶
SetDuration sets the duration value of an option, stored as a 32 bit unsigned integer.
func (OptionMap) SetMessageType ¶
func (om OptionMap) SetMessageType(m MessageType)
SetMessageType sets the message type in the DHCPMsgType option field.
type OptionMapDeserializeOptions ¶
type OptionMapDeserializeOptions struct {
IgnoreMissingEndTag bool
}
type OptionSetter ¶
type OptionSetter interface { SetOption(Option, []byte) SetMessageType(MessageType) SetUint8(Option, uint8) SetUint16(Option, uint16) SetUint32(Option, uint32) SetString(Option, string) SetIP(Option, net.IP) SetDuration(Option, time.Duration) }
OptionSetter defines a bag of functions that can be used to set options.
type Packet ¶
func NewReply ¶
func NewReply(msg PacketGetter) Packet
NewReply creates and returns a new reply packet given a request.
func PacketFromBytes ¶
PacketFromBytes deserializes the wire-level representation of a DHCP packet contained in the []byte b into a Packet struct. The function returns an error if the packet is malformed. The contents of []byte b is copied into the resulting structure and can be reused after this function has returned.
type PacketConn ¶
type PacketConn interface { PacketReader PacketWriter Close() error LocalAddr() net.Addr }
PacketConn groups PacketReader and PacketWriter to form a subset of net.PacketConn.
func Listen ¶
func Listen(addr string) (PacketConn, error)
func NewPacketConn ¶
func NewPacketConn(pc net.PacketConn) (PacketConn, error)
NewPacketConn returns a PacketConn based on the specified net.PacketConn. It adds functionality to return the interface index from calls to ReadFrom and include the interface index argument in calls to WriteTo.
type PacketGetter ¶
type PacketReader ¶
PacketReader defines an adaptation of the ReadFrom function (as defined net.PacketConn) that includes the interface index the packet arrived on.
type PacketSetter ¶
type PacketWriter ¶
PacketWriter defines an adaptation of the WriteTo function (as defined net.PacketConn) that includes the interface index the packet should be sent on.
type RawPacket ¶
type RawPacket []byte
func (RawPacket) Cookie ¶
Cookie returns the fixed-value prefix to the `options` portion of the packet. According to the RFC, this should equal the 4-octet { 99, 130, 83, 99 }.
func (RawPacket) File ¶
File returns the `file` portion of the packet. This field can be used as extra space to extend the DHCP options, if necessary. To enable this, the "Option Overload" option needs to be set in the regular options. Also see RFC2132, section 9.3.
func (RawPacket) GetCHAddr ¶
func (p RawPacket) GetCHAddr() net.HardwareAddr
GetCHAddr gets the client's hardware address.
func (RawPacket) ParseOptions ¶
func (RawPacket) SName ¶
SName returns the `sname` portion of the packet. This field can be used as extra space to extend the DHCP options, if necessary. To enable this, the "Option Overload" option needs to be set in the regular options. Also see RFC2132, section 9.3.
func (RawPacket) SetCIAddr ¶
SetCIAddr sets the current IP address of the client.
From RFC2131 section 3.5: The client fills in the 'ciaddr' field only when correctly configured with an IP address in BOUND, RENEWING or REBINDING state.
func (RawPacket) SetGIAddr ¶
SetGIAddr sets the IP address of the relay agent.
From RFC2131 section 2: Relay agent IP address, used in booting via a relay agent.
func (RawPacket) SetSIAddr ¶
SetSIAddr sets the IP address of the next server to use in bootstrap.
From RFC2131 section 2: DHCP clarifies the interpretation of the 'siaddr' field as the address of the server to use in the next step of the client's bootstrap process. Returned in DHCPOFFER, DHCPACK by server.
type Reply ¶
type Reply interface { Validate() error ToBytes() ([]byte, error) Message() *Packet Reply() *Packet PacketSetter OptionSetter }
Reply defines an interface implemented by DHCP replies.
type ReplyWriter ¶
ReplyWriter defines an interface for the object that writes a reply to the network to the intended received, be it via broadcast or unicast.
type Validation ¶
func ValidateAllowedOptions ¶
func ValidateAllowedOptions(os []Option) Validation
func ValidateMust ¶
func ValidateMust(o Option) Validation
func ValidateMustNot ¶
func ValidateMustNot(o Option) Validation
type ValidationError ¶
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string