diff options
author | Christopher Koch <chrisko@google.com> | 2019-01-10 16:19:02 -0800 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-01-14 23:19:04 +0000 |
commit | 81af01ddbffafdc6904a8092cba3adf92008c715 (patch) | |
tree | 0bccb58f602c9289cdf4893297d579119591f98f /dhcpv4/bsdp/types.go | |
parent | 833f274e1aca3b23320f6d31c246c73eefd38974 (diff) |
dhcpv4: change OptionCode to an interface for humanization.
Interface'd OptionCodes can print the correct human string.
It sucks because option codes are just a byte, but depending on where
you use them, they are interpreted differently. BSDP option codes !=
DHCP option codes.
Diffstat (limited to 'dhcpv4/bsdp/types.go')
-rw-r--r-- | dhcpv4/bsdp/types.go | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/dhcpv4/bsdp/types.go b/dhcpv4/bsdp/types.go index aa9a824..4ce840f 100644 --- a/dhcpv4/bsdp/types.go +++ b/dhcpv4/bsdp/types.go @@ -1,34 +1,48 @@ package bsdp -import "github.com/insomniacslk/dhcp/dhcpv4" - // DefaultMacOSVendorClassIdentifier is a default vendor class identifier used // on non-darwin hosts where the vendor class identifier cannot be determined. // It should mostly be used for debugging if testing BSDP on a non-darwin // system. const DefaultMacOSVendorClassIdentifier = AppleVendorID + "/i386/MacMini6,1" +// optionCode are BSDP option codes. +// +// optionCode implements the dhcpv4.OptionCode interface. +type optionCode uint8 + +func (o optionCode) Code() uint8 { + return uint8(o) +} + +func (o optionCode) String() string { + if s, ok := optionCodeToString[o]; ok { + return s + } + return "unknown" +} + // Options (occur as sub-options of DHCP option 43). const ( - OptionMessageType dhcpv4.OptionCode = 1 - OptionVersion dhcpv4.OptionCode = 2 - OptionServerIdentifier dhcpv4.OptionCode = 3 - OptionServerPriority dhcpv4.OptionCode = 4 - OptionReplyPort dhcpv4.OptionCode = 5 - OptionBootImageListPath dhcpv4.OptionCode = 6 // Not used - OptionDefaultBootImageID dhcpv4.OptionCode = 7 - OptionSelectedBootImageID dhcpv4.OptionCode = 8 - OptionBootImageList dhcpv4.OptionCode = 9 - OptionNetboot1_0Firmware dhcpv4.OptionCode = 10 - OptionBootImageAttributesFilterList dhcpv4.OptionCode = 11 - OptionShadowMountPath dhcpv4.OptionCode = 128 - OptionShadowFilePath dhcpv4.OptionCode = 129 - OptionMachineName dhcpv4.OptionCode = 130 + OptionMessageType optionCode = 1 + OptionVersion optionCode = 2 + OptionServerIdentifier optionCode = 3 + OptionServerPriority optionCode = 4 + OptionReplyPort optionCode = 5 + OptionBootImageListPath optionCode = 6 // Not used + OptionDefaultBootImageID optionCode = 7 + OptionSelectedBootImageID optionCode = 8 + OptionBootImageList optionCode = 9 + OptionNetboot1_0Firmware optionCode = 10 + OptionBootImageAttributesFilterList optionCode = 11 + OptionShadowMountPath optionCode = 128 + OptionShadowFilePath optionCode = 129 + OptionMachineName optionCode = 130 ) // optionCodeToString maps BSDP OptionCodes to human-readable strings // describing what they are. -var optionCodeToString = map[dhcpv4.OptionCode]string{ +var optionCodeToString = map[optionCode]string{ OptionMessageType: "BSDP Message Type", OptionVersion: "BSDP Version", OptionServerIdentifier: "BSDP Server Identifier", |