dhclient

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package dhclient allows for getting both DHCPv4 and DHCPv6 leases on multiple network interfaces in parallel.

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")

	// ErrNoRootPath means no root path option was found in DHCP message.
	ErrNoRootPath = errors.New("no root path 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, linkUpTimeout time.Duration) (netlink.Link, error)

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

func Interfaces added in v0.6.0

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 ParseISCSIURI added in v0.7.0

func ParseISCSIURI(s string) (*net.TCPAddr, string, error)

Format:

iscsi:@"<servername>":"<protocol>":"<port>":"<LUN>":"<targetname>"

@ for now will be ignored. Eventually we would want complete support. iscsi:[<username>:<password>[:<reverse>:<password>]@]"<servername>":"<protocol>":"<port>"[:[<iscsi_iface_name>]:[<netdev_name>]]:"<LUN>":"<targetname>" "<servername>" may contain an IPv6 address enclosed with [] with an arbitrary but bounded number of colons.

"<targetname>" may contain an arbitrary string with an arbitrary number of colons.

func SendRequests added in v0.5.0

func SendRequests(ctx context.Context, ifs []netlink.Link, ipv4, ipv6 bool, c Config, linkUpTimeout time.Duration) 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 added in v0.5.0

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

	// Modifiers4 allows modifications to the IPv4 DHCP request.
	Modifiers4 []dhcpv4.Modifier

	// Modifiers6 allows modifications to the IPv6 DHCP request.
	Modifiers6 []dhcpv6.Modifier

	// V6ServerAddr can be a unicast or broadcast destination for DHCPv6
	// messages.
	//
	// If not set, it will default to nclient6's default (all servers &
	// relay agents).
	V6ServerAddr *net.UDPAddr

	// V4ServerAddr can be a unicast or broadcast destination for IPv4 DHCP
	// messages.
	//
	// If not set, it will default to nclient4's default (DHCP broadcast
	// address).
	V4ServerAddr *net.UDPAddr
}

Config is a DHCP client configuration.

type Lease added in v0.5.0

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)

	// ISCSIBoot returns the target address and volume name to boot from if
	// they were part of the DHCP message.
	ISCSIBoot() (*net.TCPAddr, string, error)

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

	// Return the full DHCP response, this is either a *dhcpv4.DHCPv4 or a
	// *dhcpv6.Message.
	Message() (*dhcpv4.DHCPv4, *dhcpv6.Message)
}

Lease is a network configuration obtained by DHCP.

type LogLevel added in v0.5.0

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 NetworkProtocol added in v0.7.0

type NetworkProtocol int

NetworkProtocol is either IPv4 or IPv6.

const (
	NetIPv4 NetworkProtocol = 1
	NetIPv6 NetworkProtocol = 2
	NetBoth NetworkProtocol = 3
)

Possible network protocols; either IPv4, IPv6, or both.

func (NetworkProtocol) String added in v0.7.0

func (n NetworkProtocol) String() string

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 added in v0.5.0

func (p *Packet4) Configure() error

Configure configures interface using this packet.

func (*Packet4) GatherDNSSettings added in v0.6.0

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) ISCSIBoot added in v0.7.0

func (p *Packet4) ISCSIBoot() (*net.TCPAddr, string, error)

ISCSIBoot returns the target address and volume name to boot from if they were part of the DHCP message.

Parses the IPv4 DHCP Root Path for iSCSI target and volume as specified by RFC 4173.

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) Message added in v0.7.0

func (p *Packet4) Message() (*dhcpv4.DHCPv4, *dhcpv6.Message)

Message returns the unwrapped DHCPv4 packet.

func (*Packet4) Response added in v0.7.0

func (p *Packet4) Response() interface{}

Response returns the DHCP response

func (*Packet4) String added in v0.5.0

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.

func (*Packet6) Configure added in v0.5.0

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) ISCSIBoot added in v0.7.0

func (p *Packet6) ISCSIBoot() (*net.TCPAddr, string, error)

ISCSIBoot returns the target address and volume name to boot from if they were part of the DHCP message.

Parses the DHCPv6 Boot File for iSCSI target and volume as specified by RFC 4173 and RFC 5970.

func (*Packet6) Lease

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

Lease returns lease information assigned.

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

Link returns the interface this packet was received for.

func (*Packet6) Message added in v0.7.0

func (p *Packet6) Message() (*dhcpv4.DHCPv4, *dhcpv6.Message)

Message returns the unwrapped DHCPv6 packet.

func (*Packet6) String added in v0.5.0

func (p *Packet6) String() string

type Result added in v0.5.0

type Result struct {
	// Protocol is the IP protocol that we tried to configure.
	Protocol NetworkProtocol

	// 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