Documentation ¶
Overview ¶
Package dhcpv4 provides encoding and decoding of DHCPv4 packets and options.
Example Usage:
p, err := dhcpv4.New( dhcpv4.WithClientIP(net.IP{192, 168, 0, 1}), dhcpv4.WithMessageType(dhcpv4.MessageTypeInform), ) p.UpdateOption(dhcpv4.OptServerIdentifier(net.IP{192, 110, 110, 110})) // Retrieve the DHCP Message Type option. m := p.MessageType() bytesOnTheWire := p.ToBytes() longSummary := p.Summary()
Index ¶
- Constants
- Variables
- func BindToInterface(fd int, ifname string) error
- func GetByte(code OptionCode, o Options) (byte, error)
- func GetExternalIPv4Addrs(addrs []net.Addr) ([]net.IP, error)
- func GetIP(code OptionCode, o Options) net.IP
- func GetIPs(code OptionCode, o Options) []net.IP
- func GetString(code OptionCode, o Options) string
- func GetUint16(code OptionCode, o Options) (uint16, error)
- func IPv4AddrsForInterface(iface *net.Interface) ([]net.IP, error)
- func WithNetboot(d *DHCPv4)
- type AlgorithmType
- type AutoConfiguration
- type DHCPv4
- func FromBytes(q []byte) (*DHCPv4, error)
- func New(modifiers ...Modifier) (*DHCPv4, error)
- func NewDiscovery(hwaddr net.HardwareAddr, modifiers ...Modifier) (*DHCPv4, error)
- func NewDiscoveryForInterface(ifname string, modifiers ...Modifier) (*DHCPv4, error)
- func NewInform(hwaddr net.HardwareAddr, localIP net.IP, modifiers ...Modifier) (*DHCPv4, error)
- func NewInformForInterface(ifname string, needsBroadcast bool) (*DHCPv4, error)
- func NewReleaseFromACK(ack *DHCPv4, modifiers ...Modifier) (*DHCPv4, error)
- func NewRenewFromAck(ack *DHCPv4, modifiers ...Modifier) (*DHCPv4, error)
- func NewReplyFromRequest(request *DHCPv4, modifiers ...Modifier) (*DHCPv4, error)
- func NewRequestFromOffer(offer *DHCPv4, modifiers ...Modifier) (*DHCPv4, error)
- func (d *DHCPv4) AutoConfigure() (AutoConfiguration, bool)
- func (d *DHCPv4) BootFileNameOption() string
- func (d *DHCPv4) BroadcastAddress() net.IP
- func (d *DHCPv4) ClassIdentifier() string
- func (d *DHCPv4) ClasslessStaticRoute() []*Route
- func (d *DHCPv4) ClientArch() []iana.Arch
- func (d *DHCPv4) DNS() []net.IP
- func (d *DHCPv4) DeleteOption(code OptionCode)
- func (d *DHCPv4) DomainName() string
- func (d *DHCPv4) DomainSearch() *rfc1035label.Labels
- func (d *DHCPv4) FlagsToString() string
- func (d *DHCPv4) GetOneOption(code OptionCode) []byte
- func (d *DHCPv4) HostName() string
- func (d *DHCPv4) IPAddressLeaseTime(def time.Duration) time.Duration
- func (d *DHCPv4) IPAddressRebindingTime(def time.Duration) time.Duration
- func (d *DHCPv4) IPAddressRenewalTime(def time.Duration) time.Duration
- func (d *DHCPv4) IPv6OnlyPreferred() (time.Duration, bool)
- func (d *DHCPv4) IsBroadcast() bool
- func (d *DHCPv4) IsOptionRequested(requested OptionCode) bool
- func (d *DHCPv4) IsUnicast() bool
- func (d *DHCPv4) MaxMessageSize() (uint16, error)
- func (d *DHCPv4) Message() string
- func (d *DHCPv4) MessageType() MessageType
- func (d *DHCPv4) NTPServers() []net.IP
- func (d *DHCPv4) ParameterRequestList() OptionCodeList
- func (d *DHCPv4) RelayAgentInfo() *RelayOptions
- func (d *DHCPv4) RequestedIPAddress() net.IP
- func (d *DHCPv4) RootPath() string
- func (d *DHCPv4) Router() []net.IP
- func (d *DHCPv4) ServerIdentifier() net.IP
- func (d *DHCPv4) SetBroadcast()
- func (d *DHCPv4) SetUnicast()
- func (d *DHCPv4) String() string
- func (d *DHCPv4) SubnetMask() net.IPMask
- func (d *DHCPv4) Summary() string
- func (d *DHCPv4) SummaryWithVendor(vendorDecoder OptionDecoder) string
- func (d *DHCPv4) TFTPServerName() string
- func (d *DHCPv4) ToBytes() []byte
- func (d *DHCPv4) UpdateOption(opt Option)
- func (d *DHCPv4) UserClass() []string
- func (d *DHCPv4) VIVC() VIVCIdentifiers
- type Duration
- type GenericOptionCode
- type IP
- type IPMask
- type IPs
- type MessageType
- type Modifier
- func PrependModifiers(m []Modifier, other ...Modifier) []Modifier
- func WithBroadcast(broadcast bool) Modifier
- func WithClientIP(ip net.IP) Modifier
- func WithDNS(servers ...net.IP) Modifier
- func WithDomainSearchList(searchList ...string) Modifier
- func WithGatewayIP(ip net.IP) Modifier
- func WithGeneric(code OptionCode, value []byte) Modifier
- func WithHWType(hwt iana.HWType) Modifier
- func WithHwAddr(hwaddr net.HardwareAddr) Modifier
- func WithIPv6OnlyPreferred(v6OnlyWait uint32) Modifier
- func WithLeaseTime(leaseTime uint32) Modifier
- func WithMessageType(m MessageType) Modifier
- func WithNetmask(mask net.IPMask) Modifier
- func WithOption(opt Option) Modifier
- func WithOptionCopied(request *DHCPv4, opt OptionCode) Modifier
- func WithRelay(ip net.IP) Modifier
- func WithReply(request *DHCPv4) Modifier
- func WithRequestedOptions(optionCodes ...OptionCode) Modifier
- func WithRouter(routers ...net.IP) Modifier
- func WithServerIP(ip net.IP) Modifier
- func WithTransactionID(xid TransactionID) Modifier
- func WithUserClass(uc string, rfc bool) Modifier
- func WithYourIP(ip net.IP) Modifier
- func WithoutOption(code OptionCode) Modifier
- type OpcodeType
- type Option
- func OptAutoConfigure(autoconf AutoConfiguration) Option
- func OptBootFileName(name string) Option
- func OptBroadcastAddress(ip net.IP) Option
- func OptClassIdentifier(name string) Option
- func OptClasslessStaticRoute(routes ...*Route) Option
- func OptClientArch(archs ...iana.Arch) Option
- func OptClientIdentifier(ident []byte) Option
- func OptDNS(servers ...net.IP) Option
- func OptDomainName(name string) Option
- func OptDomainSearch(labels *rfc1035label.Labels) Option
- func OptGeneric(code OptionCode, value []byte) Option
- func OptHostName(name string) Option
- func OptIPAddressLeaseTime(d time.Duration) Option
- func OptIPv6OnlyPreferred(d time.Duration) Option
- func OptMaxMessageSize(size uint16) Option
- func OptMessage(msg string) Option
- func OptMessageType(m MessageType) Option
- func OptNTPServers(ntpServers ...net.IP) Option
- func OptParameterRequestList(codes ...OptionCode) Option
- func OptRFC3004UserClass(v []string) Option
- func OptRebindingTimeValue(d time.Duration) Option
- func OptRelayAgentInfo(o ...Option) Option
- func OptRenewTimeValue(d time.Duration) Option
- func OptRequestedIPAddress(ip net.IP) Option
- func OptRootPath(name string) Option
- func OptRouter(routers ...net.IP) Option
- func OptServerIdentifier(ip net.IP) Option
- func OptSubnetMask(mask net.IPMask) Option
- func OptTFTPServerName(name string) Option
- func OptUserClass(name string) Option
- func OptVIVC(identifiers ...VIVCIdentifier) Option
- type OptionCode
- type OptionCodeList
- type OptionDecoder
- type OptionGeneric
- type OptionHumanizer
- type OptionParser
- type OptionValue
- type Options
- func (o Options) Del(opcode OptionCode)
- func (o Options) FromBytes(data []byte) error
- func (o Options) Get(code OptionCode) []byte
- func (o Options) Has(opcode OptionCode) bool
- func (o Options) Marshal(b *uio.Lexer)
- func (o Options) String() string
- func (o Options) Summary(vendorDecoder OptionDecoder) string
- func (o Options) ToBytes() []byte
- func (o Options) ToString(humanizer OptionHumanizer) string
- func (o Options) Update(option Option)
- type RelayOptions
- type Route
- type Routes
- type String
- type Strings
- type TransactionID
- type Uint16
- type VIVCIdentifier
- type VIVCIdentifiers
Constants ¶
const ( ServerPort = 67 ClientPort = 68 )
const ( // MaxHWAddrLen is the maximum hardware address length of the ClientHWAddr // (client hardware address) according to RFC 2131, Section 2. This is the // link-layer destination a server must send responses to. MaxHWAddrLen = 16 // MaxMessageSize is the maximum size in bytes that a DHCPv4 packet can hold. MaxMessageSize = 576 )
const ( AgentCircuitIDSubOption raiSubOptionCode = 1 // RFC 3046 AgentRemoteIDSubOption raiSubOptionCode = 2 // RFC 3046 DOCSISDeviceClassSubOption raiSubOptionCode = 4 // RFC 3256 LinkSelectionSubOption raiSubOptionCode = 5 // RFC 3527 SubscriberIDSubOption raiSubOptionCode = 6 // RFC 3993 RADIUSAttributesSubOption raiSubOptionCode = 7 // RFC 4014 AuthenticationSubOption raiSubOptionCode = 8 // RFC 4030 VendorSpecificInformationSubOption raiSubOptionCode = 9 // RFC 4243 RelayAgentFlagsSubOption raiSubOptionCode = 10 // RFC 5010 ServerIdentifierOverrideSubOption raiSubOptionCode = 11 // RFC 5107 RelaySourcePortSubOption raiSubOptionCode = 19 // RFC 8357 VirtualSubnetSelectionSubOption raiSubOptionCode = 151 // RFC 6607 VirtualSubnetSelectionControlSubOption raiSubOptionCode = 152 // RFC 6607 )
Option 82 Relay Agention Information Sub Options
const ( OptionPad optionCode = 0 OptionSubnetMask optionCode = 1 OptionTimeOffset optionCode = 2 OptionRouter optionCode = 3 OptionTimeServer optionCode = 4 OptionNameServer optionCode = 5 OptionDomainNameServer optionCode = 6 OptionLogServer optionCode = 7 OptionQuoteServer optionCode = 8 OptionLPRServer optionCode = 9 OptionImpressServer optionCode = 10 OptionResourceLocationServer optionCode = 11 OptionHostName optionCode = 12 OptionBootFileSize optionCode = 13 OptionMeritDumpFile optionCode = 14 OptionDomainName optionCode = 15 OptionSwapServer optionCode = 16 OptionRootPath optionCode = 17 OptionExtensionsPath optionCode = 18 OptionIPForwarding optionCode = 19 OptionNonLocalSourceRouting optionCode = 20 OptionPolicyFilter optionCode = 21 OptionMaximumDatagramAssemblySize optionCode = 22 OptionDefaultIPTTL 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 OptionStaticRoutingTable optionCode = 33 OptionTrailerEncapsulation optionCode = 34 OptionArpCacheTimeout optionCode = 35 OptionEthernetEncapsulation optionCode = 36 OptionDefaulTCPTTL optionCode = 37 OptionTCPKeepaliveInterval optionCode = 38 OptionTCPKeepaliveGarbage optionCode = 39 OptionNetworkInformationServiceDomain optionCode = 40 OptionNetworkInformationServers optionCode = 41 OptionNTPServers optionCode = 42 OptionVendorSpecificInformation optionCode = 43 OptionNetBIOSOverTCPIPNameServer optionCode = 44 OptionNetBIOSOverTCPIPDatagramDistributionServer optionCode = 45 OptionNetBIOSOverTCPIPNodeType optionCode = 46 OptionNetBIOSOverTCPIPScope optionCode = 47 OptionXWindowSystemFontServer optionCode = 48 OptionXWindowSystemDisplayManger optionCode = 49 OptionRequestedIPAddress optionCode = 50 OptionIPAddressLeaseTime optionCode = 51 OptionOptionOverload optionCode = 52 OptionDHCPMessageType optionCode = 53 OptionServerIdentifier optionCode = 54 OptionParameterRequestList optionCode = 55 OptionMessage optionCode = 56 OptionMaximumDHCPMessageSize optionCode = 57 OptionRenewTimeValue optionCode = 58 OptionRebindingTimeValue optionCode = 59 OptionClassIdentifier optionCode = 60 OptionClientIdentifier optionCode = 61 OptionNetWareIPDomainName optionCode = 62 OptionNetWareIPInformation optionCode = 63 OptionNetworkInformationServicePlusDomain optionCode = 64 OptionNetworkInformationServicePlusServers optionCode = 65 OptionTFTPServerName optionCode = 66 OptionBootfileName optionCode = 67 OptionMobileIPHomeAgent optionCode = 68 OptionSimpleMailTransportProtocolServer optionCode = 69 OptionPostOfficeProtocolServer optionCode = 70 OptionNetworkNewsTransportProtocolServer optionCode = 71 OptionDefaultWorldWideWebServer optionCode = 72 OptionDefaultFingerServer optionCode = 73 OptionDefaultInternetRelayChatServer optionCode = 74 OptionStreetTalkServer optionCode = 75 OptionStreetTalkDirectoryAssistanceServer optionCode = 76 OptionUserClassInformation optionCode = 77 OptionSLPDirectoryAgent optionCode = 78 OptionSLPServiceScope optionCode = 79 OptionRapidCommit optionCode = 80 OptionFQDN optionCode = 81 OptionRelayAgentInformation optionCode = 82 OptionInternetStorageNameService optionCode = 83 // Option 84 returned in RFC 3679 OptionNDSServers optionCode = 85 OptionNDSTreeName optionCode = 86 OptionNDSContext optionCode = 87 OptionBCMCSControllerDomainNameList optionCode = 88 OptionBCMCSControllerIPv4AddressList optionCode = 89 OptionAuthentication optionCode = 90 OptionClientLastTransactionTime optionCode = 91 OptionAssociatedIP optionCode = 92 OptionClientSystemArchitectureType optionCode = 93 OptionClientNetworkInterfaceIdentifier optionCode = 94 OptionLDAP optionCode = 95 // Option 96 returned in RFC 3679 OptionClientMachineIdentifier optionCode = 97 OptionOpenGroupUserAuthentication optionCode = 98 OptionGeoConfCivic optionCode = 99 OptionIEEE10031TZString optionCode = 100 OptionReferenceToTZDatabase optionCode = 101 // Option 108 returned in RFC 8925 OptionIPv6OnlyPreferred optionCode = 108 // Options 102-111 returned in RFC 3679 OptionNetInfoParentServerAddress optionCode = 112 OptionNetInfoParentServerTag optionCode = 113 OptionURL optionCode = 114 // Option 115 returned in RFC 3679 OptionAutoConfigure optionCode = 116 OptionNameServiceSearch optionCode = 117 OptionSubnetSelection optionCode = 118 OptionDNSDomainSearchList optionCode = 119 OptionSIPServers optionCode = 120 OptionClasslessStaticRoute optionCode = 121 OptionCCC optionCode = 122 OptionGeoConf optionCode = 123 OptionVendorIdentifyingVendorClass optionCode = 124 OptionVendorIdentifyingVendorSpecific optionCode = 125 // Options 126-127 returned in RFC 3679 OptionTFTPServerIPAddress optionCode = 128 OptionCallServerIPAddress optionCode = 129 OptionDiscriminationString optionCode = 130 OptionRemoteStatisticsServerIPAddress optionCode = 131 Option8021PVLANID optionCode = 132 Option8021QL2Priority optionCode = 133 OptionDiffservCodePoint optionCode = 134 OptionHTTPProxyForPhoneSpecificApplications optionCode = 135 OptionPANAAuthenticationAgent optionCode = 136 OptionLoSTServer optionCode = 137 OptionCAPWAPAccessControllerAddresses optionCode = 138 OptionOPTIONIPv4AddressMoS optionCode = 139 OptionOPTIONIPv4FQDNMoS optionCode = 140 OptionSIPUAConfigurationServiceDomains optionCode = 141 OptionOPTIONIPv4AddressANDSF optionCode = 142 OptionOPTIONIPv6AddressANDSF optionCode = 143 // Option 144 returned in RFC 3679 OptionForcerenewNonceCapable optionCode = 145 // Options 146-149 returned in RFC 3679 OptionTFTPServerAddress optionCode = 150 OptionStatusCode optionCode = 151 OptionBaseTime optionCode = 152 OptionStartTimeOfState optionCode = 153 OptionQueryStartTime optionCode = 154 OptionQueryEndTime optionCode = 155 OptionDHCPState optionCode = 156 OptionDataSource optionCode = 157 // Options 158-174 returned in RFC 3679 OptionEtherboot optionCode = 175 OptionIPTelephone optionCode = 176 OptionEtherbootPacketCableAndCableHome optionCode = 177 // Options 178-207 returned in RFC 3679 OptionPXELinuxMagicString optionCode = 208 OptionPXELinuxConfigFile optionCode = 209 OptionPXELinuxPathPrefix optionCode = 210 OptionPXELinuxRebootTime optionCode = 211 OptionOPTION6RD optionCode = 212 OptionOPTIONv4AccessDomain optionCode = 213 // Options 214-219 returned in RFC 3679 OptionSubnetAllocation optionCode = 220 OptionVirtualSubnetAllocation optionCode = 221 // Options 222-223 returned in RFC 3679 // Options 224-254 are reserved for private use OptionEnd optionCode = 255 )
DHCPv4 Options
Variables ¶
var ( // ErrShortByteStream is an error that is thrown any time a short byte stream is // detected during option parsing. ErrShortByteStream = errors.New("short byte stream") // ErrZeroLengthByteStream is an error that is thrown any time a zero-length // byte stream is encountered. ErrZeroLengthByteStream = errors.New("zero-length byte stream") // 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") )
var MaxLeaseTime = math.MaxUint32 * time.Second
MaxLeaseTime is the maximum lease time that can be encoded.
var RandomTimeout = 2 * time.Minute
RandomTimeout is the amount of time to wait until random number generation is canceled.
Functions ¶
func BindToInterface ¶
BindToInterface (deprecated) redirects to interfaces.BindToInterface
func GetByte ¶
func GetByte(code OptionCode, o Options) (byte, error)
GetByte parses any single-byte option
func GetExternalIPv4Addrs ¶
GetExternalIPv4Addrs obtains the currently-configured, non-loopback IPv4 addresses from `addrs` coming from a particular interface (e.g. net.Interface.Addrs).
func GetIP ¶
func GetIP(code OptionCode, o Options) net.IP
GetIP returns code out of o parsed as an IP.
func GetIPs ¶
func GetIPs(code OptionCode, o Options) []net.IP
GetIPs parses a list of IPs from code in o.
func GetString ¶
func GetString(code OptionCode, o Options) string
GetString parses an RFC 2132 string from o[code].
func GetUint16 ¶
func GetUint16(code OptionCode, o Options) (uint16, error)
GetUint16 parses a uint16 from code in o.
func IPv4AddrsForInterface ¶
IPv4AddrsForInterface obtains the currently-configured, non-loopback IPv4 addresses for iface.
func WithNetboot ¶
func WithNetboot(d *DHCPv4)
WithNetboot adds bootfile URL and bootfile param options to a DHCPv4 packet.
Types ¶
type AlgorithmType ¶
type AlgorithmType uint8
AlgorithmType represents a DHCPv4-allowed generation algorithm
const (
AlgorithmHMAC_MD5 AlgorithmType = 1
)
constants that represent valid values for AlgorithmType
func (AlgorithmType) String ¶
func (a AlgorithmType) String() string
func (AlgorithmType) ToBytes ¶
func (a AlgorithmType) ToBytes() []byte
ToBytes returns the serialized version of this algorithm.
type AutoConfiguration ¶
type AutoConfiguration byte
AutoConfiguration implements encoding and decoding functions for a byte enumeration as used in RFC 2563, Section 2.
const ( DoNotAutoConfigure AutoConfiguration = 0 AutoConfigure AutoConfiguration = 1 )
func (*AutoConfiguration) FromBytes ¶
func (o *AutoConfiguration) FromBytes(data []byte) error
FromBytes parses a a single byte into AutoConfiguration
func (AutoConfiguration) String ¶
func (o AutoConfiguration) String() string
String returns a human-readable string for this option.
func (AutoConfiguration) ToBytes ¶
func (o AutoConfiguration) ToBytes() []byte
ToBytes returns a serialized stream of bytes for this option.
type DHCPv4 ¶
type DHCPv4 struct { OpCode OpcodeType HWType iana.HWType HopCount uint8 TransactionID TransactionID NumSeconds uint16 Flags uint16 ClientIPAddr net.IP YourIPAddr net.IP ServerIPAddr net.IP GatewayIPAddr net.IP ClientHWAddr net.HardwareAddr ServerHostName string BootFileName string Options Options }
DHCPv4 represents a DHCPv4 packet header and options. See the New* functions to build DHCPv4 packets.
func FromBytes ¶
FromBytes decodes a DHCPv4 packet from a sequence of bytes, and returns an error if the packet is not valid.
func New ¶
New creates a new DHCPv4 structure and fill it up with default values. It won't be a valid DHCPv4 message so you will need to adjust its fields. See also NewDiscovery, NewRequest, NewAcknowledge, NewInform and NewRelease.
func NewDiscovery ¶
func NewDiscovery(hwaddr net.HardwareAddr, modifiers ...Modifier) (*DHCPv4, error)
NewDiscovery builds a new DHCPv4 Discovery message, with a default Ethernet HW type and specified hardware address.
func NewDiscoveryForInterface ¶
NewDiscoveryForInterface builds a new DHCPv4 Discovery message, with a default Ethernet HW type and the hardware address obtained from the specified interface.
func NewInform ¶
NewInform builds a new DHCPv4 Informational message with the specified hardware address.
func NewInformForInterface ¶
NewInformForInterface builds a new DHCPv4 Informational message with default Ethernet HW type and the hardware address obtained from the specified interface.
func NewReleaseFromACK ¶
NewReleaseFromACK creates a DHCPv4 Release message from ACK. default Release message without any Modifer is created as following:
- option Message Type is Release
- ClientIP is set to ack.YourIPAddr
- ClientHWAddr is set to ack.ClientHWAddr
- Unicast
- option Server Identifier is set to ack's ServerIdentifier
func NewRenewFromAck ¶
NewRenewFromAck builds a DHCPv4 RENEW-style request from the ACK of a lease. RENEW requests have minor changes to their options compared to SELECT requests as specified by RFC 2131, section 4.3.2.
func NewReplyFromRequest ¶
NewReplyFromRequest builds a DHCPv4 reply from a request.
func NewRequestFromOffer ¶
NewRequestFromOffer builds a DHCPv4 request from an offer. It assumes the SELECTING state by default, see Section 4.3.2 in RFC 2131 for more details.
func (*DHCPv4) AutoConfigure ¶
func (d *DHCPv4) AutoConfigure() (AutoConfiguration, bool)
AutoConfigure returns the value of the AutoConfigure option, and a boolean indicating if it was present.
The AutoConfigure option is described by RFC 2563, Section 2.
func (*DHCPv4) BootFileNameOption ¶
BootFileNameOption parses the DHCPv4 Bootfile Name option if present.
The Bootfile Name option is described by RFC 2132, Section 9.5.
func (*DHCPv4) BroadcastAddress ¶
GetBroadcastAddress returns the DHCPv4 Broadcast Address value in d.
The broadcast address option is described in RFC 2132, Section 5.3.
func (*DHCPv4) ClassIdentifier ¶
ClassIdentifier parses the DHCPv4 Class Identifier option if present.
The Vendor Class Identifier option is described by RFC 2132, Section 9.13.
func (*DHCPv4) ClasslessStaticRoute ¶
ClasslessStaticRoute parses the DHCPv4 Classless Static Route option if present.
The Classless Static Route option is described by RFC 3442.
func (*DHCPv4) ClientArch ¶
ClientArch returns the Client System Architecture Type option.
func (*DHCPv4) DNS ¶
DNS parses the DHCPv4 Domain Name Server option if present.
The DNS server option is described by RFC 2132, Section 3.8.
func (*DHCPv4) DeleteOption ¶
func (d *DHCPv4) DeleteOption(code OptionCode)
DeleteOption deletes an existing option with the given option code.
func (*DHCPv4) DomainName ¶
DomainName parses the DHCPv4 Domain Name option if present.
The Domain Name option is described by RFC 2132, Section 3.17.
func (*DHCPv4) DomainSearch ¶
func (d *DHCPv4) DomainSearch() *rfc1035label.Labels
DomainSearch returns the domain search list if present.
The domain search option is described by RFC 3397, Section 2.
func (*DHCPv4) FlagsToString ¶
FlagsToString returns a human-readable representation of the flags field.
func (*DHCPv4) GetOneOption ¶
func (d *DHCPv4) GetOneOption(code OptionCode) []byte
GetOneOption returns the option that matches the given option code.
According to RFC 3396, options that are specified more than once are concatenated, and hence this should always just return one option.
func (*DHCPv4) HostName ¶
HostName parses the DHCPv4 Host Name option if present.
The Host Name option is described by RFC 2132, Section 3.14.
func (*DHCPv4) IPAddressLeaseTime ¶
IPAddressLeaseTime returns the IP address lease time or the given default duration if not present.
The IP address lease time option is described by RFC 2132, Section 9.2.
func (*DHCPv4) IPAddressRebindingTime ¶
IPAddressRebindingTime returns the IP address rebinding time or the given default duration if not present.
The IP address rebinding time option is described by RFC 2132, Section 9.12.
func (*DHCPv4) IPAddressRenewalTime ¶
IPAddressRenewalTime returns the IP address renewal time or the given default duration if not present.
The IP address renewal time option is described by RFC 2132, Section 9.11.
func (*DHCPv4) IPv6OnlyPreferred ¶
IPv6OnlyPreferred returns the V6ONLY_WAIT duration, and a boolean indicating whether this option was present.
The IPv6-Only Preferred option is described by RFC 8925, Section 3.1.
func (*DHCPv4) IsBroadcast ¶
IsBroadcast indicates whether the packet is a broadcast packet.
func (*DHCPv4) IsOptionRequested ¶
func (d *DHCPv4) IsOptionRequested(requested OptionCode) bool
IsOptionRequested returns true if that option is within the requested options of the DHCPv4 message.
func (*DHCPv4) MaxMessageSize ¶
MaxMessageSize returns the DHCP Maximum Message Size if present.
The Maximum DHCP Message Size option is described by RFC 2132, Section 9.10.
func (*DHCPv4) Message ¶
Message returns the DHCPv4 (Error) Message option.
The message options is described in RFC 2132, Section 9.9.
func (*DHCPv4) MessageType ¶
func (d *DHCPv4) MessageType() MessageType
MessageType returns the DHCPv4 Message Type option.
func (*DHCPv4) NTPServers ¶
NTPServers parses the DHCPv4 NTP Servers option if present.
The NTP servers option is described by RFC 2132, Section 8.3.
func (*DHCPv4) ParameterRequestList ¶
func (d *DHCPv4) ParameterRequestList() OptionCodeList
ParameterRequestList returns the DHCPv4 Parameter Request List.
The parameter request list option is described by RFC 2132, Section 9.8.
func (*DHCPv4) RelayAgentInfo ¶
func (d *DHCPv4) RelayAgentInfo() *RelayOptions
RelayAgentInfo returns options embedded by the relay agent.
The relay agent info option is described by RFC 3046.
func (*DHCPv4) RequestedIPAddress ¶
RequestedIPAddress returns the DHCPv4 Requested IP Address value in d.
The requested IP address option is described by RFC 2132, Section 9.1.
func (*DHCPv4) RootPath ¶
RootPath parses the DHCPv4 Root Path option if present.
The Root Path option is described by RFC 2132, Section 3.19.
func (*DHCPv4) Router ¶
Router parses the DHCPv4 Router option if present.
The Router option is described by RFC 2132, Section 3.5.
func (*DHCPv4) ServerIdentifier ¶
ServerIdentifier returns the DHCPv4 Server Identifier value in d.
The server identifier option is described by RFC 2132, Section 9.7.
func (*DHCPv4) SetBroadcast ¶
func (d *DHCPv4) SetBroadcast()
SetBroadcast sets the packet to be a broadcast packet.
func (*DHCPv4) SetUnicast ¶
func (d *DHCPv4) SetUnicast()
SetUnicast sets the packet to be a unicast packet.
func (*DHCPv4) SubnetMask ¶
SubnetMask returns a subnet mask option contained if present.
The subnet mask option is described by RFC 2132, Section 3.3.
func (*DHCPv4) SummaryWithVendor ¶
func (d *DHCPv4) SummaryWithVendor(vendorDecoder OptionDecoder) string
SummaryWithVendor prints a summary of the packet, interpreting the vendor-specific info option using the given parser (can be nil).
func (*DHCPv4) TFTPServerName ¶
TFTPServerName parses the DHCPv4 TFTP Server Name option if present.
The TFTP Server Name option is described by RFC 2132, Section 9.4.
func (*DHCPv4) UpdateOption ¶
UpdateOption replaces an existing option with the same option code with the given one, adding it if not already present.
func (*DHCPv4) UserClass ¶
UserClass returns the user class if present.
The user class information option is defined by RFC 3004.
func (*DHCPv4) VIVC ¶
func (d *DHCPv4) VIVC() VIVCIdentifiers
VIVC returns the vendor-identifying vendor class option if present.
type Duration ¶
Duration implements the IP address lease time option described by RFC 2132, Section 9.2.
func (*Duration) FromBytes ¶
FromBytes parses a duration from a byte stream according to RFC 2132, Section 9.2.
type GenericOptionCode ¶
type GenericOptionCode uint8
GenericOptionCode is an unnamed option code.
func (GenericOptionCode) Code ¶
func (o GenericOptionCode) Code() uint8
Code implements OptionCode.Code.
func (GenericOptionCode) String ¶
func (o GenericOptionCode) String() string
String returns the option's name.
type IP ¶
IP implements DHCPv4 IP option marshaling and unmarshaling as described by RFC 2132, Sections 5.3, 9.1, 9.7, and others.
type IPMask ¶
IPMask represents an option encapsulating the subnet mask.
This option implements the subnet mask option in RFC 2132, Section 3.3.
type IPs ¶
IPs are IPv4 addresses from a DHCP packet as used and specified by options in RFC 2132, Sections 3.5 through 3.13, 8.2, 8.3, 8.5, 8.6, 8.9, and 8.10.
IPs implements the OptionValue type.
func (*IPs) FromBytes ¶
FromBytes parses an IPv4 address from a DHCP packet as used and specified by options in RFC 2132, Sections 3.5 through 3.13, 8.2, 8.3, 8.5, 8.6, 8.9, and 8.10.
func (IPs) ToBytes ¶
ToBytes marshals IPv4 addresses to a DHCP packet as specified by RFC 2132, Section 3.5 et al.
type MessageType ¶
type MessageType byte
MessageType represents the possible DHCP message types - DISCOVER, OFFER, etc
const ( // MessageTypeNone is not a real message type, it is used by certain // functions to signal that no explicit message type is requested MessageTypeNone MessageType = 0 MessageTypeDiscover MessageType = 1 MessageTypeOffer MessageType = 2 MessageTypeRequest MessageType = 3 MessageTypeDecline MessageType = 4 MessageTypeAck MessageType = 5 MessageTypeNak MessageType = 6 MessageTypeRelease MessageType = 7 MessageTypeInform MessageType = 8 MessageTypeForceRenew MessageType = 9 )
DHCP message types
func (*MessageType) FromBytes ¶
func (m *MessageType) FromBytes(data []byte) error
FromBytes reads a message type from data as described by RFC 2132, Section 9.6.
func (MessageType) String ¶
func (m MessageType) String() string
String prints a human-readable message type name.
func (MessageType) ToBytes ¶
func (m MessageType) ToBytes() []byte
ToBytes returns the serialized version of this option described by RFC 2132, Section 9.6.
type Modifier ¶
type Modifier func(d *DHCPv4)
Modifier defines the signature for functions that can modify DHCPv4 structures. This is used to simplify packet manipulation
func PrependModifiers ¶
PrependModifiers prepends other to m.
func WithBroadcast ¶
WithBroadcast sets the packet to be broadcast or unicast
func WithClientIP ¶
WithClientIP sets the Client IP for a DHCPv4 packet.
func WithDomainSearchList ¶
WithDomainSearchList adds or updates an OptionDomainSearch
func WithGatewayIP ¶
WithGatewayIP sets the Gateway IP for the DHCPv4 packet.
func WithGeneric ¶
func WithGeneric(code OptionCode, value []byte) Modifier
func WithHWType ¶
WithHWType sets the Hardware Type for a DHCPv4 packet.
func WithHwAddr ¶
func WithHwAddr(hwaddr net.HardwareAddr) Modifier
WithHwAddr sets the hardware address for a packet
func WithIPv6OnlyPreferred ¶
WithIPv6OnlyPreferred adds or updates an OptIPv6OnlyPreferred
func WithLeaseTime ¶
WithLeaseTime adds or updates an OptIPAddressLeaseTime
func WithMessageType ¶
func WithMessageType(m MessageType) Modifier
WithMessageType adds the DHCPv4 message type m to a packet.
func WithNetmask ¶
WithNetmask adds or updates an OptSubnetMask
func WithOption ¶
WithOption appends a DHCPv4 option provided by the user
func WithOptionCopied ¶
func WithOptionCopied(request *DHCPv4, opt OptionCode) Modifier
WithOptionCopied copies the value of option opt from request.
func WithRelay ¶
WithRelay adds parameters required for DHCPv4 to be relayed by the relay server with given ip
func WithReply ¶
WithReply fills in opcode, hwtype, xid, clienthwaddr, and flags from the given packet.
func WithRequestedOptions ¶
func WithRequestedOptions(optionCodes ...OptionCode) Modifier
WithRequestedOptions adds requested options to the packet.
func WithRouter ¶
WithRouter updates a packet with the DHCPv4 Router option.
func WithServerIP ¶
WithServerIP sets the Server IP for a DHCPv4 packet.
func WithTransactionID ¶
func WithTransactionID(xid TransactionID) Modifier
WithTransactionID sets the Transaction ID for the DHCPv4 packet
func WithUserClass ¶
WithUserClass adds a user class option to the packet. The rfc parameter allows you to specify if the userclass should be rfc compliant or not. More details in issue #113
func WithYourIP ¶
WithYourIP sets the Your IP for a DHCPv4 packet.
func WithoutOption ¶
func WithoutOption(code OptionCode) Modifier
WithoutOption removes the DHCPv4 option with the given code
type OpcodeType ¶
type OpcodeType uint8
OpcodeType represents a DHCPv4 opcode.
const ( OpcodeBootRequest OpcodeType = 1 OpcodeBootReply OpcodeType = 2 )
constants that represent valid values for OpcodeType
func (OpcodeType) String ¶
func (o OpcodeType) String() string
type Option ¶
type Option struct { Code OptionCode Value OptionValue }
Option is a DHCPv4 option and consists of a 1-byte option code and a value stream of bytes.
The value is to be interpreted based on the option code.
func OptAutoConfigure ¶
func OptAutoConfigure(autoconf AutoConfiguration) Option
OptAutoConfigure returns a new AutoConfigure option.
The AutoConfigure option is described by RFC 2563, Section 2.
func OptBootFileName ¶
OptBootFileName returns a new DHCPv4 Boot File Name option.
The Bootfile Name option is described by RFC 2132, Section 9.5.
func OptBroadcastAddress ¶
OptBroadcastAddress returns a new DHCPv4 Broadcast Address option.
The broadcast address option is described in RFC 2132, Section 5.3.
func OptClassIdentifier ¶
OptClassIdentifier returns a new DHCPv4 Class Identifier option.
The Vendor Class Identifier option is described by RFC 2132, Section 9.13.
func OptClasslessStaticRoute ¶
OptClasslessStaticRoute returns a new DHCPv4 Classless Static Route option.
The Classless Static Route option is described by RFC 3442.
func OptClientArch ¶
OptClientArch returns a new Client System Architecture Type option.
func OptClientIdentifier ¶
OptClientIdentifier returns a new Client Identifier option.
func OptDNS ¶
OptDNS returns a new DHCPv4 Domain Name Server option.
The DNS server option is described by RFC 2132, Section 3.8.
func OptDomainName ¶
OptDomainName returns a new DHCPv4 Domain Name option.
The Domain Name option is described by RFC 2132, Section 3.17.
func OptDomainSearch ¶
func OptDomainSearch(labels *rfc1035label.Labels) Option
OptDomainSearch returns a new domain search option.
The domain search option is described by RFC 3397, Section 2.
func OptGeneric ¶
func OptGeneric(code OptionCode, value []byte) Option
OptGeneric returns a generic option.
func OptHostName ¶
OptHostName returns a new DHCPv4 Host Name option.
The Host Name option is described by RFC 2132, Section 3.14.
func OptIPAddressLeaseTime ¶
OptIPAddressLeaseTime returns a new IP address lease time option.
The IP address lease time option is described by RFC 2132, Section 9.2.
func OptIPv6OnlyPreferred ¶
The IPv6-Only Preferred option is described by RFC 8925, Section 3.1
func OptMaxMessageSize ¶
OptMaxMessageSize returns a new DHCP Maximum Message Size option.
The Maximum DHCP Message Size option is described by RFC 2132, Section 9.10.
func OptMessage ¶
OptMessage returns a new DHCPv4 (Error) Message option.
func OptMessageType ¶
func OptMessageType(m MessageType) Option
OptMessageType returns a new DHCPv4 Message Type option.
func OptNTPServers ¶
OptNTPServers returns a new DHCPv4 NTP Server option.
The NTP servers option is described by RFC 2132, Section 8.3.
func OptParameterRequestList ¶
func OptParameterRequestList(codes ...OptionCode) Option
OptParameterRequestList returns a new DHCPv4 Parameter Request List.
The parameter request list option is described by RFC 2132, Section 9.8.
func OptRFC3004UserClass ¶
OptRFC3004UserClass returns a new user class option according to RFC 3004.
func OptRebindingTimeValue ¶
The IP address rebinding time option as described by RFC 2132, Section 9.12.
func OptRelayAgentInfo ¶
OptRelayAgentInfo returns a new DHCP Relay Agent Info option.
The relay agent info option is described by RFC 3046.
func OptRenewTimeValue ¶
The IP address renew time option as described by RFC 2132, Section 9.11.
func OptRequestedIPAddress ¶
OptRequestedIPAddress returns a new DHCPv4 Requested IP Address option.
The requested IP address option is described by RFC 2132, Section 9.1.
func OptRootPath ¶
OptRootPath returns a new DHCPv4 Root Path option.
The Root Path option is described by RFC 2132, Section 3.19.
func OptRouter ¶
OptRouter returns a new DHCPv4 Router option.
The Router option is described by RFC 2132, Section 3.5.
func OptServerIdentifier ¶
OptServerIdentifier returns a new DHCPv4 Server Identifier option.
The server identifier option is described by RFC 2132, Section 9.7.
func OptSubnetMask ¶
OptSubnetMask returns a new DHCPv4 SubnetMask option per RFC 2132, Section 3.3.
func OptTFTPServerName ¶
OptTFTPServerName returns a new DHCPv4 TFTP Server Name option.
The TFTP Server Name option is described by RFC 2132, Section 9.4.
func OptUserClass ¶
OptUserClass returns a new DHCPv4 User Class option.
func OptVIVC ¶
func OptVIVC(identifiers ...VIVCIdentifier) Option
OptVIVC returns a new vendor-identifying vendor class option.
The option is described by RFC 3925.
type OptionCode ¶
type OptionCode interface { // Code is the 1 byte option code for the wire. Code() uint8 // String returns the option's name. String() string }
OptionCode is a single byte representing the code for a given Option.
OptionCode is an interface purely to support different stringers on options with the same Code value, as vendor-specific options use option codes that have the same value, but mean a different thing.
type OptionCodeList ¶
type OptionCodeList []OptionCode
OptionCodeList is a list of DHCP option codes.
func (*OptionCodeList) Add ¶
func (ol *OptionCodeList) Add(cs ...OptionCode)
Add adds option codes in cs to ol.
func (*OptionCodeList) FromBytes ¶
func (ol *OptionCodeList) FromBytes(data []byte) error
FromBytes parses a byte stream for this option as described by RFC 2132, Section 9.8.
func (OptionCodeList) Has ¶
func (ol OptionCodeList) Has(c OptionCode) bool
Has returns whether c is in the list.
func (OptionCodeList) String ¶
func (ol OptionCodeList) String() string
String returns a human-readable string for the option names.
func (OptionCodeList) ToBytes ¶
func (ol OptionCodeList) ToBytes() []byte
ToBytes returns a serialized stream of bytes for this option as defined by RFC 2132, Section 9.8.
type OptionDecoder ¶
OptionDecoder can decode a byte stream into a human-readable option.
type OptionGeneric ¶
type OptionGeneric struct {
Data []byte
}
OptionGeneric is an option that only contains the option code and associated data. Every option that does not have a specific implementation will fall back to this option.
func (OptionGeneric) String ¶
func (o OptionGeneric) String() string
String returns a human-readable representation of a generic option.
func (OptionGeneric) ToBytes ¶
func (o OptionGeneric) ToBytes() []byte
ToBytes returns a serialized generic option as a slice of bytes.
type OptionHumanizer ¶
type OptionHumanizer struct { ValueHumanizer OptionParser CodeHumanizer func(code uint8) OptionCode }
OptionHumanizer is used to interpret a set of Options for their option code name and values.
There should be separate OptionHumanizers for each Option "space": DHCP, BSDP, Relay Agent Info, and others.
type OptionParser ¶
type OptionParser func(code OptionCode, data []byte) fmt.Stringer
OptionParser gives a human-legible interpretation of data for the given option code.
type OptionValue ¶
OptionValue is an interface that all DHCP v4 options adhere to.
type Options ¶
Options is a collection of options.
func OptionsFromList ¶
OptionsFromList adds all given options to an options map.
func (Options) Del ¶
func (o Options) Del(opcode OptionCode)
Del deletes the option matching the option code.
func (Options) FromBytes ¶
FromBytes parses a sequence of bytes until the end and builds a list of options from it.
The sequence should not contain the DHCP magic cookie.
Returns an error if any invalid option or length is found.
func (Options) Get ¶
func (o Options) Get(code OptionCode) []byte
Get will attempt to get all options that match a DHCPv4 option from its OptionCode. If the option was not found it will return an empty list.
According to RFC 3396, options that are specified more than once are concatenated, and hence this should always just return one option. This currently returns a list to be API compatible.
func (Options) Has ¶
func (o Options) Has(opcode OptionCode) bool
Has checks whether o has the given opcode.
func (Options) Summary ¶
func (o Options) Summary(vendorDecoder OptionDecoder) string
Summary prints options in human-readable values.
Summary uses vendorParser to interpret the OptionVendorSpecificInformation option.
func (Options) ToBytes ¶
ToBytes makes Options usable as an OptionValue as well.
Used in the case of vendor-specific and relay agent options.
func (Options) ToString ¶
func (o Options) ToString(humanizer OptionHumanizer) string
ToString uses parse to parse options into human-readable values.
type RelayOptions ¶
type RelayOptions struct {
Options
}
RelayOptions is like Options, but stringifies using the Relay Agent Specific option space.
func (*RelayOptions) FromBytes ¶
func (r *RelayOptions) FromBytes(data []byte) error
FromBytes parses relay agent options from data.
func (RelayOptions) String ¶
func (r RelayOptions) String() string
String prints the contained options using Relay Agent-specific option code parsing.
type Route ¶
type Route struct { // Dest is the destination network. Dest *net.IPNet // Router is the router to use for the given destination network. Router net.IP }
Route is a classless static route as per RFC 3442.
func (Route) Marshal ¶
Marshal implements uio.Marshaler.
Format described in RFC 3442:
<size of mask in number of bits> <destination address, omitting octets that must be zero per mask> <route IP>
type Routes ¶
type Routes []*Route
Routes is a collection of network routes.
type String ¶
type String string
String represents an option encapsulating a string in IPv4 DHCP.
This representation is shared by multiple options specified by RFC 2132, Sections 3.14, 3.16, 3.17, 3.19, and 3.20.
type Strings ¶
type Strings []string
Strings represents an option encapsulating a list of strings in IPv4 DHCP as specified in RFC 3004
Strings implements the OptionValue type.
type TransactionID ¶
type TransactionID [4]byte
TransactionID represents a 4-byte DHCP transaction ID as defined in RFC 951, Section 3.
The TransactionID is used to match DHCP replies to their original request.
func GenerateTransactionID ¶
func GenerateTransactionID() (TransactionID, error)
GenerateTransactionID generates a random 32-bits number suitable for use as TransactionID
func (TransactionID) String ¶
func (xid TransactionID) String() string
String prints a hex transaction ID.
type Uint16 ¶
type Uint16 uint16
Uint16 implements encoding and decoding functions for a uint16 as used in RFC 2132, Section 9.10.
func (*Uint16) FromBytes ¶
FromBytes decodes data into o as per RFC 2132, Section 9.10.
type VIVCIdentifier ¶
type VIVCIdentifier struct { // EntID is the enterprise ID. EntID iana.EnterpriseID Data []byte }
VIVCIdentifier implements the vendor-identifying vendor class option described by RFC 3925.
type VIVCIdentifiers ¶
type VIVCIdentifiers []VIVCIdentifier
VIVCIdentifiers implements encoding and decoding methods for a DHCP option described in RFC 3925.
func (*VIVCIdentifiers) FromBytes ¶
func (ids *VIVCIdentifiers) FromBytes(data []byte) error
FromBytes parses data into ids per RFC 3925.
func (VIVCIdentifiers) String ¶
func (ids VIVCIdentifiers) String() string
String returns a human-readable string for this option.
func (VIVCIdentifiers) ToBytes ¶
func (ids VIVCIdentifiers) ToBytes() []byte
ToBytes returns a serialized stream of bytes for this option.
Source Files ¶
- bindtointerface.go
- defaults.go
- dhcpv4.go
- modifiers.go
- option_autoconfigure.go
- option_duration.go
- option_generic.go
- option_ip.go
- option_ips.go
- option_maximum_dhcp_message_size.go
- option_message_type.go
- option_misc.go
- option_parameter_request_list.go
- option_relay_agent_information.go
- option_routes.go
- option_string.go
- option_strings.go
- option_subnet_mask.go
- option_vivc.go
- options.go
- types.go
Directories ¶
Path | Synopsis |
---|---|
Package client4 is deprecated.
|
Package client4 is deprecated. |
Package nclient4 is a small, minimum-functionality client for DHCPv4.
|
Package nclient4 is a small, minimum-functionality client for DHCPv4. |
Package server4 is a basic, extensible DHCPv4 server.
|
Package server4 is a basic, extensible DHCPv4 server. |