bsdp

package
v0.0.0-...-7803ee8 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	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
)

Options (occur as sub-options of DHCP option 43).

View Source
const AppleVendorID = "AAPLBSDPC"

AppleVendorID is the string constant set in the vendor class identifier (DHCP option 60) that is sent by the server.

View Source
const DefaultMacOSVendorClassIdentifier = AppleVendorID + "/i386/MacMini6,1"

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.

View Source
const MaxDHCPMessageSize = 1500

MaxDHCPMessageSize is the size set in DHCP option 57 (DHCP Maximum Message Size). BSDP includes its own sub-option (12) to indicate to NetBoot servers that the client can support larger message sizes, and modern NetBoot servers will prefer this BSDP-specific option over the DHCP standard option.

Variables

View Source
var (
	Version1_0 = Version{1, 0}
	Version1_1 = Version{1, 1}
)

Specific versions.

Functions

func MakeVendorClassIdentifier

func MakeVendorClassIdentifier() (string, error)

MakeVendorClassIdentifier returns a static vendor class identifier for BSDP use on non-darwin hosts.

func OptBootImageList

func OptBootImageList(b ...BootImage) dhcpv4.Option

OptBootImageList returns a new BSDP boot image list.

func OptDefaultBootImageID

func OptDefaultBootImageID(b BootImageID) dhcpv4.Option

OptDefaultBootImageID returns a new default boot image ID option as per BSDP.

func OptMachineName

func OptMachineName(name string) dhcpv4.Option

OptMachineName returns a BSDP Machine Name option.

func OptMessageType

func OptMessageType(mt MessageType) dhcpv4.Option

OptMessageType returns a new BSDP Message Type option.

func OptReplyPort

func OptReplyPort(port uint16) dhcpv4.Option

OptReplyPort returns a new BSDP reply port option.

Implements the BSDP option reply port. This is used when BSDP responses should be sent to a reply port other than the DHCP default. The macOS GUI "Startup Disk Select" sends this option since it's operating in an unprivileged context.

func OptSelectedBootImageID

func OptSelectedBootImageID(b BootImageID) dhcpv4.Option

OptSelectedBootImageID returns a new selected boot image ID option as per BSDP.

func OptServerIdentifier

func OptServerIdentifier(ip net.IP) dhcpv4.Option

OptServerIdentifier returns a new BSDP Server Identifier option.

func OptServerPriority

func OptServerPriority(prio uint16) dhcpv4.Option

OptServerPriority returns a new BSDP server priority option.

func OptVendorOptions

func OptVendorOptions(o ...dhcpv4.Option) dhcpv4.Option

OptVendorOptions returns the BSDP Vendor Specific Info in o.

func OptVersion

func OptVersion(version Version) dhcpv4.Option

OptVersion returns a new BSDP version option.

Types

type BootImage

type BootImage struct {
	ID   BootImageID
	Name string
}

BootImage describes a boot image - contains the boot image ID and the name.

func ParseBootImageListFromAck

func ParseBootImageListFromAck(ack *dhcpv4.DHCPv4) ([]BootImage, error)

ParseBootImageListFromAck parses the list of boot images presented in the ACK[LIST] packet and returns them as a list of BootImages.

func (BootImage) Marshal

func (b BootImage) Marshal(buf *uio.Lexer)

Marshal write a BootImage to buf.

func (BootImage) String

func (b BootImage) String() string

String converts a BootImage to a human-readable representation.

func (*BootImage) Unmarshal

func (b *BootImage) Unmarshal(buf *uio.Lexer) error

Unmarshal reads data from buf into b.

type BootImageID

type BootImageID struct {
	IsInstall bool
	ImageType BootImageType
	Index     uint16
}

BootImageID describes a boot image ID - whether it's an install image and what kind of boot image (e.g. OS 9, macOS, hardware diagnostics)

func (*BootImageID) FromBytes

func (b *BootImageID) FromBytes(data []byte) error

FromBytes reads data into b.

func (BootImageID) Marshal

func (b BootImageID) Marshal(buf *uio.Lexer)

Marshal writes the binary representation to buf.

func (BootImageID) String

func (b BootImageID) String() string

String converts a BootImageID to a human-readable representation.

func (BootImageID) ToBytes

func (b BootImageID) ToBytes() []byte

ToBytes implements dhcpv4.OptionValue.

func (*BootImageID) Unmarshal

func (b *BootImageID) Unmarshal(buf *uio.Lexer) error

Unmarshal reads b's binary representation from buf.

type BootImageList

type BootImageList []BootImage

BootImageList contains a list of boot images presented by a netboot server.

Implements the BSDP option listing the boot images.

func (*BootImageList) FromBytes

func (bil *BootImageList) FromBytes(data []byte) error

FromBytes deserializes data into bil.

func (BootImageList) String

func (bil BootImageList) String() string

String returns a human-readable string for this option.

func (BootImageList) ToBytes

func (bil BootImageList) ToBytes() []byte

ToBytes returns a serialized stream of bytes for this option.

type BootImageType

type BootImageType byte

BootImageType represents the different BSDP boot image types.

const (
	BootImageTypeMacOS9              BootImageType = 0
	BootImageTypeMacOSX              BootImageType = 1
	BootImageTypeMacOSXServer        BootImageType = 2
	BootImageTypeHardwareDiagnostics BootImageType = 3
)

Different types of BootImages - e.g. for different flavors of macOS.

type Client

type Client struct {
	client4.Client
}

Client represents a BSDP client that can perform BSDP exchanges via the broadcast address.

func NewClient

func NewClient() *Client

NewClient constructs a new client with default read and write timeouts from dhcpv4.Client.

func (*Client) Exchange

func (c *Client) Exchange(ifname string) ([]*Packet, error)

Exchange runs a full BSDP exchange (Inform[list], Ack, Inform[select], Ack). Returns a list of DHCPv4 structures representing the exchange.

type MessageType

type MessageType byte

MessageType represents the different BSDP message types.

Implements the BSDP option message type. Can be one of LIST, SELECT, or FAILED.

const (
	MessageTypeNone   MessageType = 0
	MessageTypeList   MessageType = 1
	MessageTypeSelect MessageType = 2
	MessageTypeFailed MessageType = 3
)

BSDP Message types - e.g. LIST, SELECT, FAILED

func MessageTypeFromPacket

func MessageTypeFromPacket(packet *dhcpv4.DHCPv4) MessageType

MessageTypeFromPacket extracts the BSDP message type (LIST, SELECT) from the vendor-specific options and returns it. If the message type option cannot be found, returns false.

func (*MessageType) FromBytes

func (m *MessageType) FromBytes(data []byte) error

FromBytes reads data into m.

func (MessageType) String

func (m MessageType) String() string

String returns a human-friendly representation of MessageType.

func (MessageType) ToBytes

func (m MessageType) ToBytes() []byte

ToBytes returns a serialized stream of bytes for this option.

type Packet

type Packet struct {
	dhcpv4.DHCPv4
}

Packet is a BSDP packet wrapper around a DHCPv4 packet in order to print the correct vendor-specific BSDP information in String().

func InformSelectForAck

func InformSelectForAck(ack *Packet, replyPort uint16, selectedImage BootImage) (*Packet, error)

InformSelectForAck constructs an INFORM[SELECT] packet given an ACK to the previously-sent INFORM[LIST].

func NewInformList

func NewInformList(hwaddr net.HardwareAddr, localIP net.IP, replyPort uint16, modifiers ...dhcpv4.Modifier) (*Packet, error)

NewInformList creates a new INFORM packet for interface with hardware address `hwaddr` and IP `localIP`. Packet will be sent out on port `replyPort`.

func NewInformListForInterface

func NewInformListForInterface(ifname string, replyPort uint16) (*Packet, error)

NewInformListForInterface creates a new INFORM packet for interface ifname with configuration options specified by config.

func NewReplyForInformList

func NewReplyForInformList(inform *Packet, config ReplyConfig) (*Packet, error)

NewReplyForInformList constructs an ACK for the INFORM[LIST] packet `inform` with additional options in `config`.

func NewReplyForInformSelect

func NewReplyForInformSelect(inform *Packet, config ReplyConfig) (*Packet, error)

NewReplyForInformSelect constructs an ACK for the INFORM[Select] packet `inform` with additional options in `config`.

func PacketFor

func PacketFor(d *dhcpv4.DHCPv4) *Packet

PacketFor returns a wrapped BSDP Packet given a DHCPv4 packet.

func (Packet) String

func (p Packet) String() string

func (Packet) Summary

func (p Packet) Summary() string

Summary prints the BSDP packet with the correct vendor-specific options.

type ReplyConfig

type ReplyConfig struct {
	ServerIP                     net.IP
	ServerHostname, BootFileName string
	ServerPriority               uint16
	Images                       []BootImage
	DefaultImage, SelectedImage  *BootImage
}

ReplyConfig is a struct containing some common configuration values for a BSDP reply (ACK).

type VendorOptions

type VendorOptions struct {
	dhcpv4.Options
}

VendorOptions is like dhcpv4.Options, but stringifies using BSDP-specific option codes.

func GetVendorOptions

func GetVendorOptions(o dhcpv4.Options) *VendorOptions

GetVendorOptions returns a new BSDP Vendor Specific Info option.

func (VendorOptions) BootImageList

func (v VendorOptions) BootImageList() BootImageList

BootImageList returns the BSDP boot image list in v.

func (VendorOptions) DefaultBootImageID

func (v VendorOptions) DefaultBootImageID() *BootImageID

DefaultBootImageID returns the default boot image ID in v.

func (*VendorOptions) FromBytes

func (v *VendorOptions) FromBytes(data []byte) error

FromBytes parses vendor options from

func (VendorOptions) MachineName

func (v VendorOptions) MachineName() string

GetMachineName finds and parses the BSDP Machine Name option from v.

func (VendorOptions) MessageType

func (v VendorOptions) MessageType() MessageType

MessageType returns the BSDP Message Type in v.

func (VendorOptions) ReplyPort

func (v VendorOptions) ReplyPort() (uint16, error)

GetReplyPort returns the BSDP reply port in v if present.

func (VendorOptions) SelectedBootImageID

func (v VendorOptions) SelectedBootImageID() *BootImageID

SelectedBootImageID returns the selected boot image ID in v.

func (VendorOptions) ServerIdentifier

func (v VendorOptions) ServerIdentifier() net.IP

GetServerIdentifier returns the BSDP Server Identifier value in v if present.

func (VendorOptions) ServerPriority

func (v VendorOptions) ServerPriority() (uint16, error)

GetServerPriority returns the BSDP server priority in v if present.

func (VendorOptions) String

func (v VendorOptions) String() string

String prints the contained options using BSDP-specific option code parsing.

func (VendorOptions) Version

func (v VendorOptions) Version() (Version, error)

GetVersion returns the BSDP version in v if present.

type Version

type Version [2]byte

Version is the BSDP protocol version. Can be one of 1.0 or 1.1.

func (*Version) FromBytes

func (o *Version) FromBytes(data []byte) error

FromBytes constructs a Version struct from a sequence of bytes and returns it, or an error.

func (Version) String

func (o Version) String() string

String returns a human-readable string for this option.

func (Version) ToBytes

func (o Version) ToBytes() []byte

ToBytes returns a serialized stream of bytes for this option.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL