dhcp

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: GPL-3.0, LGPL-3.0 Imports: 7 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

Overview

Package dhcp reads an ISC dhcpd configuration.

The file is split into tokens and parsed rather than grepped or read line by line. Reading a fixed number of lines after a match, which the shell tools did, breaks as soon as a declaration is one line longer or the options are in another order. Reading line by line breaks as soon as a brace shares a line with a statement. Either silently reports a neighbour's address. A construct the parser does not understand is an error rather than a guess.

A node's boot address is taken only from the one declaration named after it. A second interface and a comment that names the node are shown, but never give the node an address.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoAddress is returned when no declaration named after a node
	// carries an address.
	ErrNoAddress = errors.New("no DHCP declaration named after the node carries an address")
	// ErrAmbiguous is returned when a node's address is not decided by one
	// declaration, or the one declaration hands out several addresses.
	ErrAmbiguous = errors.New("the DHCP address is ambiguous")
	// ErrInvalidAddress is returned when the fixed address of a node's
	// declaration is not an IP address.
	ErrInvalidAddress = errors.New("the DHCP fixed-address is not an IP address")
)

Functions

func GUIDFromMAC

func GUIDFromMAC(mac string) (string, error)

GUIDFromMAC derives the InfiniBand port GUID of a Mellanox adapter from its hardware address, which is what the fabric tools are asked about.

The address is split in the middle and 0300 is inserted, which is the mapping Mellanox firmware uses between the two.

Types

type Config

type Config struct {
	Hosts []Host `json:"hosts" yaml:"hosts"`
}

Config is a parsed dhcpd configuration.

func Parse

func Parse(data []byte) (*Config, error)

Parse reads a dhcpd configuration held in memory. An include statement in it is an error, because there is nothing to read the named file from.

func ParseFile added in v0.3.0

func ParseFile(file string, read Reader) (*Config, error)

ParseFile reads the dhcpd configuration at file, and every file it includes, through read.

func (*Config) BootAddress added in v0.3.0

func (c *Config) BootAddress(node string) (string, error)

BootAddress returns the address a node boots with: the fixed address of the one declaration named after the node or its fully qualified name.

Another interface of the node, such as its BMC, and a declaration that a comment associates with the node never give the address. When more than one declaration named after the node carries an address, or the one hands out several, which of them the node boots with cannot be told, and the answer is an error rather than a guess.

func (*Config) Lookup

func (c *Config) Lookup(node string) []Match

Lookup finds the declarations that belong to a node by their name: the node's own and those of its other interfaces.

A comment that names the node is not enough; Mentions finds those.

func (*Config) Mentions added in v0.3.0

func (c *Config) Mentions(node string) []Match

Mentions finds the declarations that do not belong to a node by name but that a comment directly above them names it in. A comment such as "# chassis C07: exe0003 exe0004" names several nodes, so these are for display only.

type Host

type Host struct {
	// Name is the name the declaration carries.
	Name string `json:"name" yaml:"name"`
	// MACs are the hardware addresses it matches.
	MACs []string `json:"macs,omitempty" yaml:"macs,omitempty"`
	// Address is the fixed address it hands out. A declaration that hands
	// out several has them separated by ", ".
	Address string `json:"address,omitempty" yaml:"address,omitempty"`
	// Filename is the boot file it offers.
	Filename string `json:"filename,omitempty" yaml:"filename,omitempty"`
	// ClientIdentifier is the dhcp-client-identifier option it matches.
	ClientIdentifier string `json:"clientIdentifier,omitempty" yaml:"clientIdentifier,omitempty"`
	// Options holds every other option of the declaration.
	Options map[string]string `json:"options,omitempty" yaml:"options,omitempty"`
	// Comments are the comment lines directly above the declaration, which
	// is where sites often write the node name.
	Comments []string `json:"comments,omitempty" yaml:"comments,omitempty"`
}

Host is one host declaration.

type Match added in v0.3.0

type Match struct {
	Host
	// By is how the declaration was found.
	By MatchKind `json:"match" yaml:"match"`
}

Match is a declaration found for a node.

type MatchKind added in v0.3.0

type MatchKind string

MatchKind says how a declaration belongs to a node.

const (
	// ByName is a declaration named after the node, or after a fully
	// qualified name whose first label is the node.
	ByName MatchKind = "name"
	// ByInterface is a declaration whose name is the node name followed by
	// "-" or "_", which is how a second interface or the BMC is usually
	// written.
	ByInterface MatchKind = "interface"
	// ByComment is a declaration that a comment directly above it
	// associates with the node. It is shown, never used.
	ByComment MatchKind = "comment"
)

type Reader added in v0.3.0

type Reader func(path string) ([]byte, error)

Reader returns the content of a file that an include statement names.

Jump to

Keyboard shortcuts

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