Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiskAssetRoute ¶ added in v0.25.0
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
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 PXELinuxMACRoute ¶ added in v0.25.0
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, or when the matched Hardware has no PXELINUX.Config. In all of those cases the next Route in the Router gets a chance.
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
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.
Returns handled=false when there's no Hardware match, 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.
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
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.
type Router ¶ added in v0.25.0
Router walks its Routes in order and returns the first handled result, or a 404-style error if no route claims the request.
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 ¶
HandleWrite handles TFTP PUT requests. It will always return an error. This library does not support PUT.