binary

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNetbootNotAllowed = errors.New("netboot is not allowed for this hardware: netboot.allowPXE is false in the Hardware record")

ErrNetbootNotAllowed marks a request that was declined solely because the Hardware matching the client has netboot disabled (netboot.allowPXE=false in the Hardware, which dhcp.Convert* turns into hardware.Info.AllowNetboot).

It exists to keep that case distinguishable from "this file does not exist". In the L3 scenarios (external DHCP, static IPs, DHCP relay) Smee's DHCP handler never runs, so the operator never sees the "/netboot-not-allowed" boot file name it would otherwise hand out; the first and only signal is whatever TFTP/HTTP answers. A plain 404 (or TFTP "file not found") for that is indistinguishable from a missing file or a typo'd path and sends people hunting through the asset directory instead of at the Hardware record.

Routes return it alongside handled=false so the Router can keep trying later routes; if none of them serve the request, the Router returns this instead of os.ErrNotExist, and the transports turn it into 403 Forbidden (HTTP) or a TFTP error whose message names the cause.

Functions

This section is empty.

Types

type DiskAssetRoute added in v0.25.0

type DiskAssetRoute struct {
	Log logr.Logger
	Dir string
}

DiskAssetRoute streams files from a local directory. The requested path is opened relative to Dir via openAsset, which confines access to Dir and rejects directory traversal (absolute paths, ".." segments, escaping symlinks).

Returns handled=false when Dir is unset or the file does not exist (or the path escaped Dir), so the Router can continue to a later route or fall through to the 404 response.

func (DiskAssetRoute) Name added in v0.25.0

func (r DiskAssetRoute) Name() string

func (DiskAssetRoute) TryServe added in v0.25.0

func (r DiskAssetRoute) TryServe(ctx context.Context, req Request, w io.ReaderFrom) (bool, error)

type EmbeddedIPXERoute added in v0.25.0

type EmbeddedIPXERoute struct {
	Log   logr.Logger
	Patch []byte
}

EmbeddedIPXERoute serves iPXE binaries from the embedded file map (smee/internal/ipxe/binary/file). Hits the route on filename basename match; if Patch is set, the binary is patched before serving.

func (EmbeddedIPXERoute) Name added in v0.25.0

func (r EmbeddedIPXERoute) Name() string

func (EmbeddedIPXERoute) TryServe added in v0.25.0

func (r EmbeddedIPXERoute) TryServe(ctx context.Context, req Request, w io.ReaderFrom) (bool, error)

type HTTPHandler added in v0.25.0

type HTTPHandler struct {
	Log logr.Logger
	// Router dispatches each request through its configured Routes in order.
	// The caller is responsible for constructing the Router with the routes it
	// wants to enable.
	Router Router
	// contains filtered or unexported fields
}

HTTPHandler serves the same TFTP Routes over HTTP. It is used to expose pxelinux.cfg and the on-disk asset directory to clients that fetch them via HTTP (eg. u-boot's pxe-over-http, which uses wget) instead of TFTP, using the exact same request path shapes.

The requested URL path has the mount prefix stripped and is then handed to the Router as a binary.Request, so the underlying Route implementations (PXELinuxMACRoute, DiskAssetRoute, ...) are reused unchanged.

Construct it with NewHTTPHandler so the mount prefix is normalized once.

func NewHTTPHandler added in v0.25.0

func NewHTTPHandler(log logr.Logger, router Router, pathPrefix string) HTTPHandler

NewHTTPHandler builds an HTTPHandler, normalizing pathPrefix once (via normalizePathPrefix) so it does not have to be recomputed on every request.

func (HTTPHandler) Handle added in v0.25.0

func (h HTTPHandler) Handle(w http.ResponseWriter, req *http.Request)

Handle handles GET and HEAD HTTP requests by dispatching them through the Router. A request that no Route claims results in a 404.

type Handler

type Handler struct {
	Log   logr.Logger
	Patch []byte
}

implements the TFTP read and write function handlers.

func (Handler) Handle

func (h Handler) Handle(w http.ResponseWriter, req *http.Request)

Handle handles GET and HEAD responses to HTTP requests. Serves embedded iPXE binaries.

type PXELinuxMACRoute added in v0.25.0

type PXELinuxMACRoute struct {
	Log      logr.Logger
	Resolver hardware.Resolver
}

PXELinuxMACRoute handles PXELinux requests of the exact form "pxelinux.cfg/01-AA-BB-CC-DD-EE-FF", where the trailing token is a dash-separated MAC address (parsed via net.ParseMAC, so either case is accepted). The MAC is extracted from the path, used to look up Hardware, and the Hardware's PXELINUX.Config is served.

The route returns handled=false when the path doesn't have that exact shape, when MAC parsing fails, when the Hardware lookup fails, when netboot is not allowed for the matched Hardware, or when it has no PXELINUX.Config. In all of those cases the next Route in the Router gets a chance. The netboot-not-allowed decline also returns ErrNetbootNotAllowed, so the Router can report that cause if no other route serves the request.

func (PXELinuxMACRoute) Name added in v0.25.0

func (r PXELinuxMACRoute) Name() string

func (PXELinuxMACRoute) TryServe added in v0.25.0

func (r PXELinuxMACRoute) TryServe(ctx context.Context, req Request, w io.ReaderFrom) (bool, error)

type RPiNetbootRoute added in v0.25.0

type RPiNetbootRoute struct {
	Log      logr.Logger
	Resolver hardware.Resolver
	AssetDir string
}

RPiNetbootRoute handles RaspberryPi EEPROM netboot, which addresses by serial number rather than MAC: requests arrive as "<SerialNum>/<file>" from the client identified by IP.

The route:

  • Looks up Hardware by req.Client.IP.
  • If the Hardware has RPI.SerialNum and FirmwarePath set and AssetDir is configured, and req.Filename starts with "<SerialNum>/", either serves an inline value (RPI.ConfigTxt for config.txt; the joined OSIE.KernelParams for cmdline.txt) or rewrites the path's serial prefix to FirmwarePath and streams the file from AssetDir.
  • Matches the inline files on the cleaned path, so the doubled-slash form the bootloader also asks for ("<SerialNum>//config.txt") is answered as well as the single-slash one.

Returns handled=false when there's no Hardware match, netboot is not allowed for it, no RPI config on the Hardware, no AssetDir, the path doesn't have the serial prefix, or the rewritten on-disk file does not exist. The netboot-not-allowed decline also returns ErrNetbootNotAllowed, so the Router can report that cause if no other route serves the request.

func (RPiNetbootRoute) Name added in v0.25.0

func (r RPiNetbootRoute) Name() string

func (RPiNetbootRoute) TryServe added in v0.25.0

func (r RPiNetbootRoute) TryServe(ctx context.Context, req Request, w io.ReaderFrom) (bool, error)

type Request added in v0.25.0

type Request struct {
	Filename string
	Base     string
	Client   net.UDPAddr
}

Request is the parsed TFTP read request handed to each Route. Filename is the raw path as received from the client; Base is its basename, precomputed so routes that key on the leaf (eg. embedded iPXE) don't all repeat the same filepath.Base call.

type Route added in v0.25.0

type Route interface {
	Name() string
	TryServe(ctx context.Context, req Request, w io.ReaderFrom) (handled bool, err error)
}

Route is one step in the TFTP read-dispatch chain. Returning handled=true means the route owns this request (whether it succeeded or returned an error); the Router will not consult later routes. Returning handled=false means the request didn't match this route and the Router should continue.

A route may return handled=false with a non-nil error to explain why it declined. The Router remembers the explanation and returns it if no later route serves the request, so a decline with a known cause (currently ErrNetbootNotAllowed) surfaces to the client instead of a generic 404.

type Router added in v0.25.0

type Router struct {
	Log    logr.Logger
	Routes []Route
}

Router walks its Routes in order and returns the first handled result, or a 404-style error if no route claims the request.

func (Router) Handle added in v0.25.0

func (r Router) Handle(ctx context.Context, req Request, w io.ReaderFrom) error

type TFTP

type TFTP struct {
	Log                  logr.Logger
	EnableTFTPSinglePort bool
	Addr                 netip.AddrPort
	Timeout              time.Duration
	BlockSize            int
	// Router dispatches each TFTP read request through its configured
	// Routes in order. The caller is responsible for constructing the
	// Router with the routes it wants to enable.
	Router Router
}

TFTP config settings.

func (TFTP) HandleRead

func (h TFTP) HandleRead(filename string, rf io.ReaderFrom) error

HandleRead handlers TFTP GET requests. The function signature satisfies the tftp.Server.readHandler parameter type.

func (TFTP) HandleWrite

func (h TFTP) HandleWrite(filename string, wt io.WriterTo) error

HandleWrite handles TFTP PUT requests. It will always return an error. This library does not support PUT.

func (*TFTP) ListenAndServe

func (h *TFTP) ListenAndServe(ctx context.Context) error

ListenAndServe will listen and serve iPXE binaries over TFTP.

Directories

Path Synopsis
Package binary handles embedding of the iPXE binaries.
Package binary handles embedding of the iPXE binaries.

Jump to

Keyboard shortcuts

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