dhclient

package
v6.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: BSD-3-Clause Imports: 18 Imported by: 104

Documentation

Overview

Package dhclient provides a unified interface for interfacing with both DHCPv4 and DHCPv6 clients.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoBootFile represents that no pxe boot file was found.
	ErrNoBootFile = errors.New("no boot file name present in DHCP message")
	// ErrNoServerHostName represents that no pxe boot server was found.
	ErrNoServerHostName = errors.New("no server host name present in DHCP message")
)

Functions

func Configure4

func Configure4(iface netlink.Link, packet *dhcpv4.DHCPv4) error

Configure4 adds IP addresses, routes, and DNS servers to the system.

func Configure6

func Configure6(iface netlink.Link, packet *dhcpv6.Message) error

Configure6 adds IPv6 addresses, routes, and DNS servers to the system.

func IfUp

func IfUp(ifname string) (netlink.Link, error)

IfUp ensures the given network interface is up and returns the link object.

func Interfaces

func Interfaces(ifName string) ([]netlink.Link, error)

Interfaces takes an RE and returns a []netlink.Link that matches it, or an error. It is an error for the returned list to be empty.

func SendRequests

func SendRequests(ctx context.Context, ifs []netlink.Link, ipv4, ipv6 bool, c Config) chan *Result

SendRequests coordinates soliciting DHCP configuration on all ifs.

ipv4 and ipv6 determine whether to send DHCPv4 and DHCPv6 requests, respectively.

The *Result channel will be closed when all requests have completed.

func WriteDNSSettings

func WriteDNSSettings(ns []net.IP, sl []string, domain string) error

WriteDNSSettings writes the given nameservers, search list, and domain to resolv.conf.

Types

type Config

type Config struct {
	// Timeout is the timeout for one DHCP request attempt.
	Timeout time.Duration

	// Retries is how many times to retry DHCP attempts.
	Retries int

	// LogLevel determines the amount of information printed for each
	// attempt. The highest log level should print each entire packet sent
	// and received.
	LogLevel LogLevel
}

Config is a DHCP client configuration.

type Lease

type Lease interface {
	fmt.Stringer

	// Configure configures the associated interface with the network
	// configuration.
	Configure() error

	// Boot is a URL to obtain booting information from that was part of
	// the network config.
	Boot() (*url.URL, error)

	// Link is the interface the configuration is for.
	Link() netlink.Link
}

Lease is a network configuration obtained by DHCP.

type LogLevel

type LogLevel uint8

LogLevel is the amount of information to log.

const (
	LogInfo    LogLevel = 0
	LogSummary LogLevel = 1
	LogDebug   LogLevel = 2
)

LogLevel are the levels.

type Packet4

type Packet4 struct {
	P *dhcpv4.DHCPv4
	// contains filtered or unexported fields
}

Packet4 implements convenience functions for DHCPv4 packets.

func NewPacket4

func NewPacket4(iface netlink.Link, p *dhcpv4.DHCPv4) *Packet4

NewPacket4 wraps a DHCPv4 packet with some convenience methods.

func (*Packet4) Boot

func (p *Packet4) Boot() (*url.URL, error)

Boot returns the boot file assigned.

func (*Packet4) Configure

func (p *Packet4) Configure() error

Configure configures interface using this packet.

func (*Packet4) GatherDNSSettings

func (p *Packet4) GatherDNSSettings() (ns []net.IP, sl []string, dom string)

GatherDNSSettings gets the DNS related infromation from a dhcp packet including, nameservers, domain, and search options

func (*Packet4) Lease

func (p *Packet4) Lease() *net.IPNet

Lease returns the IPNet assigned.

func (p *Packet4) Link() netlink.Link

Link is a netlink link

func (*Packet4) String

func (p *Packet4) String() string

type Packet6

type Packet6 struct {
	// contains filtered or unexported fields
}

Packet6 implements Packet for IPv6 DHCP.

func NewPacket6

func NewPacket6(iface netlink.Link, p *dhcpv6.Message) *Packet6

NewPacket6 wraps a DHCPv6 packet with some convenience methods.

func (*Packet6) Boot

func (p *Packet6) Boot() (*url.URL, error)

Boot returns the boot file URL and parameters assigned.

TODO: RFC 5970 is helpfully avoidant of where these options are used. Are they added to the packet? Are they added to an IANA? It *seems* like it's in the packet.

func (*Packet6) Configure

func (p *Packet6) Configure() error

Configure configures interface using this packet.

func (*Packet6) DNS

func (p *Packet6) DNS() []net.IP

DNS returns DNS servers assigned.

func (*Packet6) Lease

func (p *Packet6) Lease() *dhcpv6.OptIAAddress

Lease returns lease information assigned.

func (p *Packet6) Link() netlink.Link

func (*Packet6) String

func (p *Packet6) String() string

type Result

type Result struct {
	// Interface is the network interface the attempt was sent on.
	Interface netlink.Link

	// Lease is the DHCP configuration returned.
	//
	// If Lease is set, Err is nil.
	Lease Lease

	// Err is an error that occured during the DHCP attempt.
	Err error
}

Result is the result of a particular DHCP attempt.

Jump to

Keyboard shortcuts

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