diff options
author | Sean Karlage <skarlage@get9.io> | 2018-03-30 11:59:09 -0700 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-03-30 19:59:09 +0100 |
commit | e54ed8cc0a75ad30c54286a0bc0b369c29c6941d (patch) | |
tree | a01c484688913606c081c12edbb6fc80674998b6 /dhcpv4 | |
parent | 984e562bca486c32b5d609e93b13da753a270ce8 (diff) |
Remove build tags (#27)
Removes build tags from BSDP and breaks vendor class identifier into
OS-specific implementations so it is easier to integrate bsdp with other
libs.
Diffstat (limited to 'dhcpv4')
31 files changed, 49 insertions, 79 deletions
diff --git a/dhcpv4/bsdp/boot_image.go b/dhcpv4/bsdp/boot_image.go index 954432e..88a9404 100644 --- a/dhcpv4/bsdp/boot_image.go +++ b/dhcpv4/bsdp/boot_image.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/boot_image_test.go b/dhcpv4/bsdp/boot_image_test.go index 86a2e9f..004aa30 100644 --- a/dhcpv4/bsdp/boot_image_test.go +++ b/dhcpv4/bsdp/boot_image_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp.go b/dhcpv4/bsdp/bsdp.go index dac45a6..bb5166e 100644 --- a/dhcpv4/bsdp/bsdp.go +++ b/dhcpv4/bsdp/bsdp.go @@ -1,16 +1,9 @@ -// +build darwin - package bsdp -// Implements Apple's netboot protocol BSDP (Boot Service Discovery Protocol). -// Canonical implementation is defined here: -// http://opensource.apple.com/source/bootp/bootp-198.1/Documentation/BSDP.doc - import ( "errors" "fmt" "net" - "syscall" "github.com/insomniacslk/dhcp/dhcpv4" ) @@ -21,17 +14,6 @@ import ( // prefer this BSDP-specific option over the DHCP standard option. const MaxDHCPMessageSize = 1500 -// makeVendorClassIdentifier calls the sysctl syscall on macOS to get the -// platform model. -func makeVendorClassIdentifier() (string, error) { - // Fetch hardware model for class ID. - hwModel, err := syscall.Sysctl("hw.model") - if err != nil { - return "", err - } - return fmt.Sprintf("AAPLBSDPC/i386/%s", hwModel), nil -} - // ParseBootImageListFromAck parses the list of boot images presented in the // ACK[LIST] packet and returns them as a list of BootImages. func ParseBootImageListFromAck(ack dhcpv4.DHCPv4) ([]BootImage, error) { @@ -79,18 +61,18 @@ func NewInformListForInterface(iface string, replyPort uint16) (*dhcpv4.DHCPv4, d.AddOption(&OptVendorSpecificInformation{vendorOpts}) d.AddOption(&dhcpv4.OptParameterRequestList{ - []dhcpv4.OptionCode{ + RequestedOpts: []dhcpv4.OptionCode{ dhcpv4.OptionVendorSpecificInformation, dhcpv4.OptionClassIdentifier, }, }) d.AddOption(&dhcpv4.OptMaximumDHCPMessageSize{Size: MaxDHCPMessageSize}) - vendorClassID, err := makeVendorClassIdentifier() + vendorClassID, err := MakeVendorClassIdentifier() if err != nil { return nil, err } - d.AddOption(&dhcpv4.OptClassIdentifier{vendorClassID}) + d.AddOption(&dhcpv4.OptClassIdentifier{Identifier: vendorClassID}) d.AddOption(&dhcpv4.OptionGeneric{OptionCode: dhcpv4.OptionEnd}) return d, nil } @@ -143,13 +125,13 @@ func InformSelectForAck(ack dhcpv4.DHCPv4, replyPort uint16, selectedImage BootI vendorOpts = append(vendorOpts, &OptReplyPort{replyPort}) } - vendorClassID, err := makeVendorClassIdentifier() + vendorClassID, err := MakeVendorClassIdentifier() if err != nil { return nil, err } - d.AddOption(&dhcpv4.OptClassIdentifier{vendorClassID}) + d.AddOption(&dhcpv4.OptClassIdentifier{Identifier: vendorClassID}) d.AddOption(&dhcpv4.OptParameterRequestList{ - []dhcpv4.OptionCode{ + RequestedOpts: []dhcpv4.OptionCode{ dhcpv4.OptionSubnetMask, dhcpv4.OptionRouter, dhcpv4.OptionBootfileName, @@ -157,7 +139,7 @@ func InformSelectForAck(ack dhcpv4.DHCPv4, replyPort uint16, selectedImage BootI dhcpv4.OptionClassIdentifier, }, }) - d.AddOption(&dhcpv4.OptMessageType{dhcpv4.MessageTypeInform}) + d.AddOption(&dhcpv4.OptMessageType{MessageType: dhcpv4.MessageTypeInform}) d.AddOption(&OptVendorSpecificInformation{vendorOpts}) d.AddOption(&dhcpv4.OptionGeneric{OptionCode: dhcpv4.OptionEnd}) return d, nil diff --git a/dhcpv4/bsdp/bsdp_option_boot_image_list.go b/dhcpv4/bsdp/bsdp_option_boot_image_list.go index 37e61fa..04eb7cd 100644 --- a/dhcpv4/bsdp/bsdp_option_boot_image_list.go +++ b/dhcpv4/bsdp/bsdp_option_boot_image_list.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_boot_image_list_test.go b/dhcpv4/bsdp/bsdp_option_boot_image_list_test.go index 29a2ccc..42bf91c 100644 --- a/dhcpv4/bsdp/bsdp_option_boot_image_list_test.go +++ b/dhcpv4/bsdp/bsdp_option_boot_image_list_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_default_boot_image_id.go b/dhcpv4/bsdp/bsdp_option_default_boot_image_id.go index 70e340d..4c87df8 100644 --- a/dhcpv4/bsdp/bsdp_option_default_boot_image_id.go +++ b/dhcpv4/bsdp/bsdp_option_default_boot_image_id.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_default_boot_image_id_test.go b/dhcpv4/bsdp/bsdp_option_default_boot_image_id_test.go index 0ca6a32..e062e2d 100644 --- a/dhcpv4/bsdp/bsdp_option_default_boot_image_id_test.go +++ b/dhcpv4/bsdp/bsdp_option_default_boot_image_id_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_generic.go b/dhcpv4/bsdp/bsdp_option_generic.go index 7ac2a73..6a51e29 100644 --- a/dhcpv4/bsdp/bsdp_option_generic.go +++ b/dhcpv4/bsdp/bsdp_option_generic.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_generic_test.go b/dhcpv4/bsdp/bsdp_option_generic_test.go index 5a5ad25..5abcfbd 100644 --- a/dhcpv4/bsdp/bsdp_option_generic_test.go +++ b/dhcpv4/bsdp/bsdp_option_generic_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_machine_name.go b/dhcpv4/bsdp/bsdp_option_machine_name.go index 42e29d8..dc05378 100644 --- a/dhcpv4/bsdp/bsdp_option_machine_name.go +++ b/dhcpv4/bsdp/bsdp_option_machine_name.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_machine_name_test.go b/dhcpv4/bsdp/bsdp_option_machine_name_test.go index 7e4e3a1..9019020 100644 --- a/dhcpv4/bsdp/bsdp_option_machine_name_test.go +++ b/dhcpv4/bsdp/bsdp_option_machine_name_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_message_type.go b/dhcpv4/bsdp/bsdp_option_message_type.go index ad80fc1..d73eff5 100644 --- a/dhcpv4/bsdp/bsdp_option_message_type.go +++ b/dhcpv4/bsdp/bsdp_option_message_type.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_message_type_test.go b/dhcpv4/bsdp/bsdp_option_message_type_test.go index f74644c..b853dc9 100644 --- a/dhcpv4/bsdp/bsdp_option_message_type_test.go +++ b/dhcpv4/bsdp/bsdp_option_message_type_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_reply_port.go b/dhcpv4/bsdp/bsdp_option_reply_port.go index 5e11058..f1cc49f 100644 --- a/dhcpv4/bsdp/bsdp_option_reply_port.go +++ b/dhcpv4/bsdp/bsdp_option_reply_port.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_reply_port_test.go b/dhcpv4/bsdp/bsdp_option_reply_port_test.go index 0c9e03a..c9906ff 100644 --- a/dhcpv4/bsdp/bsdp_option_reply_port_test.go +++ b/dhcpv4/bsdp/bsdp_option_reply_port_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_selected_boot_image_id.go b/dhcpv4/bsdp/bsdp_option_selected_boot_image_id.go index 6f426d2..5b00ded 100644 --- a/dhcpv4/bsdp/bsdp_option_selected_boot_image_id.go +++ b/dhcpv4/bsdp/bsdp_option_selected_boot_image_id.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_selected_boot_image_id_test.go b/dhcpv4/bsdp/bsdp_option_selected_boot_image_id_test.go index 9087076..9529e41 100644 --- a/dhcpv4/bsdp/bsdp_option_selected_boot_image_id_test.go +++ b/dhcpv4/bsdp/bsdp_option_selected_boot_image_id_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_server_identifier.go b/dhcpv4/bsdp/bsdp_option_server_identifier.go index 2f7b1bd..252a0aa 100644 --- a/dhcpv4/bsdp/bsdp_option_server_identifier.go +++ b/dhcpv4/bsdp/bsdp_option_server_identifier.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_server_identifier_test.go b/dhcpv4/bsdp/bsdp_option_server_identifier_test.go index 8e712d9..5267caa 100644 --- a/dhcpv4/bsdp/bsdp_option_server_identifier_test.go +++ b/dhcpv4/bsdp/bsdp_option_server_identifier_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_server_priority.go b/dhcpv4/bsdp/bsdp_option_server_priority.go index dc03c28..1952b7e 100644 --- a/dhcpv4/bsdp/bsdp_option_server_priority.go +++ b/dhcpv4/bsdp/bsdp_option_server_priority.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_server_priority_test.go b/dhcpv4/bsdp/bsdp_option_server_priority_test.go index e029ffc..d12ad55 100644 --- a/dhcpv4/bsdp/bsdp_option_server_priority_test.go +++ b/dhcpv4/bsdp/bsdp_option_server_priority_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_version.go b/dhcpv4/bsdp/bsdp_option_version.go index 15acb86..8431a94 100644 --- a/dhcpv4/bsdp/bsdp_option_version.go +++ b/dhcpv4/bsdp/bsdp_option_version.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_option_version_test.go b/dhcpv4/bsdp/bsdp_option_version_test.go index 8c09c6a..c6a6afc 100644 --- a/dhcpv4/bsdp/bsdp_option_version_test.go +++ b/dhcpv4/bsdp/bsdp_option_version_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/bsdp_test.go b/dhcpv4/bsdp/bsdp_test.go index 4fed612..fb0a1e5 100644 --- a/dhcpv4/bsdp/bsdp_test.go +++ b/dhcpv4/bsdp/bsdp_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/client.go b/dhcpv4/bsdp/client.go index 68d5288..307f09a 100644 --- a/dhcpv4/bsdp/client.go +++ b/dhcpv4/bsdp/client.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/doc.go b/dhcpv4/bsdp/doc.go new file mode 100644 index 0000000..b3a2186 --- /dev/null +++ b/dhcpv4/bsdp/doc.go @@ -0,0 +1,10 @@ +/* +The BSDP package implements Apple's Boot Service Discovery Protocol (a +pxe-boot-like netboot protocol for booting macOS hardware from +network-connected servers). + +The Canonical implementation is defined here: +http://opensource.apple.com/source/bootp/bootp-198.1/Documentation/BSDP.doc +*/ + +package bsdp diff --git a/dhcpv4/bsdp/option_vendor_specific_information.go b/dhcpv4/bsdp/option_vendor_specific_information.go index 51f68b5..99c72d1 100644 --- a/dhcpv4/bsdp/option_vendor_specific_information.go +++ b/dhcpv4/bsdp/option_vendor_specific_information.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/option_vendor_specific_information_test.go b/dhcpv4/bsdp/option_vendor_specific_information_test.go index 5fbba0c..f125d5a 100644 --- a/dhcpv4/bsdp/option_vendor_specific_information_test.go +++ b/dhcpv4/bsdp/option_vendor_specific_information_test.go @@ -1,5 +1,3 @@ -// +build darwin - package bsdp import ( diff --git a/dhcpv4/bsdp/types.go b/dhcpv4/bsdp/types.go index efe99a8..4f1c140 100644 --- a/dhcpv4/bsdp/types.go +++ b/dhcpv4/bsdp/types.go @@ -1,9 +1,13 @@ -// +build darwin - 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 = "AAPLBSDP/i386/MacMini6,1" + // Options (occur as sub-options of DHCP option 43). const ( OptionMessageType dhcpv4.OptionCode = 1 diff --git a/dhcpv4/bsdp/vendor_class_identifier.go b/dhcpv4/bsdp/vendor_class_identifier.go new file mode 100644 index 0000000..dfd1ca9 --- /dev/null +++ b/dhcpv4/bsdp/vendor_class_identifier.go @@ -0,0 +1,9 @@ +// +build !darwin + +package bsdp + +// MakeVendorClassIdentifier returns a static vendor class identifier for BSDP +// use on non-darwin hosts. +func MakeVendorClassIdentifier() (string, error) { + return DefaultMacOSVendorClassIdentifier, nil +} diff --git a/dhcpv4/bsdp/vendor_class_identifier_darwin.go b/dhcpv4/bsdp/vendor_class_identifier_darwin.go new file mode 100644 index 0000000..530d843 --- /dev/null +++ b/dhcpv4/bsdp/vendor_class_identifier_darwin.go @@ -0,0 +1,17 @@ +package bsdp + +import ( + "fmt" + "syscall" +) + +// MakeVendorClassIdentifier calls the sysctl syscall on macOS to get the +// platform model. +func MakeVendorClassIdentifier() (string, error) { + // Fetch hardware model for class ID. + hwModel, err := syscall.Sysctl("hw.model") + if err != nil { + return "", err + } + return fmt.Sprintf("AAPLBSDPC/i386/%s", hwModel), nil +} |