dhcp

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ArchToBootFile = map[iana.Arch]string{
	iana.INTEL_X86PC:       "undionly.kpxe",
	iana.NEC_PC98:          "undionly.kpxe",
	iana.EFI_ITANIUM:       "undionly.kpxe",
	iana.DEC_ALPHA:         "undionly.kpxe",
	iana.ARC_X86:           "undionly.kpxe",
	iana.INTEL_LEAN_CLIENT: "undionly.kpxe",
	iana.EFI_IA32:          "ipxe.efi",
	iana.EFI_X86_64:        "ipxe.efi",
	iana.EFI_XSCALE:        "ipxe.efi",
	iana.EFI_BC:            "ipxe.efi",
	iana.EFI_ARM32:         "snp.efi",
	iana.EFI_ARM64:         "snp.efi",
	iana.EFI_X86_HTTP:      "ipxe.efi",
	iana.EFI_X86_64_HTTP:   "ipxe.efi",
	iana.EFI_ARM32_HTTP:    "snp.efi",
	iana.EFI_ARM64_HTTP:    "snp.efi",
	iana.Arch(41):          "snp.efi",
}

ArchToBootFile maps supported hardware PXE architectures types to iPXE binary files.

View Source
var ErrUnknownArch = fmt.Errorf("could not determine client architecture from option 93")

ErrUnknownArch is used when the PXE client request is from an unknown architecture.

Functions

func Arch

func Arch(d *dhcpv4.DHCPv4) iana.Arch

Arch returns the Arch of the client pulled from DHCP option 93.

func IsNetbootClient

func IsNetbootClient(pkt *dhcpv4.DHCPv4) error

IsNetbootClient returns nil if the client is a valid netboot client. Otherwise it returns an error.

A valid netboot client will have the following in its DHCP request: 1. is a DHCP discovery/request message type. 2. option 93 is set. 3. option 94 is set. 4. option 97 is correct length. 5. option 60 is set with this format: "PXEClient:Arch:xxxxx:UNDI:yyyzzz" or "HTTPClient:Arch:xxxxx:UNDI:yyyzzz".

See: http://www.pix.net/software/pxeboot/archive/pxespec.pdf

See: https://www.rfc-editor.org/rfc/rfc4578.html

Types

type ClientType

type ClientType string

ClientType is from DHCP option 60. Normally only PXEClient or HTTPClient.

const (
	PXEClient  ClientType = "PXEClient"
	HTTPClient ClientType = "HTTPClient"
)

func (ClientType) String

func (c ClientType) String() string

String function for clientType.

type Info

type Info struct {
	// Pkt is the dhcp packet that was received from the client.
	Pkt *dhcpv4.DHCPv4
	// Arch is the architecture of the client. Use NewInfo to automatically populate this field.
	Arch iana.Arch
	// Mac is the mac address of the client. Use NewInfo to automatically populate this field.
	Mac net.HardwareAddr
	// UserClass is the user class of the client. Use NewInfo to automatically populate this field.
	UserClass UserClass
	// ClientType is the client type of the client. Use NewInfo to automatically populate this field.
	ClientType ClientType
	// IsNetbootClient returns nil if the client is a valid netboot client.	Otherwise it returns an error.
	// Use NewInfo to automatically populate this field.
	IsNetbootClient error
	// IPXEBinary is the iPXE binary file to boot. Use NewInfo to automatically populate this field.
	IPXEBinary string
}

Info holds details about the dhcp request. Use NewInfo to populate the struct fields from a dhcp packet.

func NewInfo

func NewInfo(pkt *dhcpv4.DHCPv4) Info

func (Info) AddRPIOpt43

func (i Info) AddRPIOpt43(opts dhcpv4.Options) []byte

AddRPIOpt43 adds the Raspberry PI required option43 sub options to an existing opt 43.

func (Info) Bootfile

func (i Info) Bootfile(customUC UserClass, ipxeScript, ipxeHTTPBinServer *url.URL, ipxeTFTPBinServer netip.AddrPort) string

Bootfile returns the calculated dhcp header: "file" value. see https://datatracker.ietf.org/doc/html/rfc2131#section-2 .

func (Info) ClientTypeFrom

func (i Info) ClientTypeFrom() ClientType

func (Info) IPXEBinaryFrom

func (i Info) IPXEBinaryFrom() string

func (Info) NextServer

func (i Info) NextServer(ipxeHTTPBinServer *url.URL, ipxeTFTPBinServer netip.AddrPort) net.IP

NextServer returns the calculated dhcp header (ServerIPAddr): "siaddr" value. see https://datatracker.ietf.org/doc/html/rfc2131#section-2 .

func (Info) UserClassFrom

func (i Info) UserClassFrom() UserClass

type UserClass

type UserClass string

UserClass is DHCP option 77 (https://www.rfc-editor.org/rfc/rfc3004.html).

const (
	// If the client has had iPXE burned into its ROM (or is a VM
	// that uses iPXE as the PXE "ROM"), special handling is
	// needed because in this mode the client is using iPXE native
	// drivers and chainloading to a UNDI stack won't work.
	IPXE UserClass = "iPXE"
	// If the client identifies as "Tinkerbell", we've already
	// chainloaded this client to the full-featured copy of iPXE
	// we supply. We have to distinguish this case so we don't
	// loop on the chainload step.
	Tinkerbell UserClass = "Tinkerbell"
)

known user-class types. must correspond to DHCP option 77 - User-Class https://www.rfc-editor.org/rfc/rfc3004.html

func (UserClass) String

func (u UserClass) String() string

String function for UserClass.

Directories

Path Synopsis
Package data is an interface between DHCP backend implementations and the DHCP server.
Package data is an interface between DHCP backend implementations and the DHCP server.
Package handler holds the interface that backends implement, handlers take in, and the top level dhcp package passes to handlers.
Package handler holds the interface that backends implement, handlers take in, and the top level dhcp package passes to handlers.
proxy
Package proxy implements a DHCP handler that provides proxyDHCP functionality.
Package proxy implements a DHCP handler that provides proxyDHCP functionality.
reservation
Package noop is a backend handler that does nothing.
Package noop is a backend handler that does nothing.
Package otel handles translating DHCP headers and options to otel key/value attributes.
Package otel handles translating DHCP headers and options to otel key/value attributes.
Package dhcp providers UDP listening and serving functionality.
Package dhcp providers UDP listening and serving functionality.

Jump to

Keyboard shortcuts

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