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 ¶
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 ¶
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 ¶
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
ParseFile reads the dhcpd configuration at file, and every file it includes, through read.
func (*Config) BootAddress ¶ added in v0.3.0
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 ¶
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.
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" )