netboot: go.universe.tf/netboot/dhcp4 Index | Files

package dhcp4

import "go.universe.tf/netboot/dhcp4"

Package dhcp4 provides building blocks for DHCP clients and servers.

Index

Package Files

conn.go conn_linux.go doc.go options.go packet.go

type Conn Uses

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

Conn is a DHCP-oriented packet socket.

Multiple goroutines may invoke methods on a Conn simultaneously.

func NewConn Uses

func NewConn(addr string) (*Conn, error)

NewConn creates a Conn bound to the given UDP ip:port.

func NewSnooperConn Uses

func NewSnooperConn(addr string) (*Conn, error)

NewSnooperConn creates a Conn that listens on the given UDP ip:port.

Unlike NewConn, NewSnooperConn does not bind to the ip:port, enabling the Conn to coexist with other services on the machine.

func (*Conn) Close Uses

func (c *Conn) Close() error

Close closes the DHCP socket. Any blocked Read or Write operations will be unblocked and return errors.

func (*Conn) RecvDHCP Uses

func (c *Conn) RecvDHCP() (*Packet, *net.Interface, error)

RecvDHCP reads a Packet from the connection. It returns the packet and the interface it was received on.

func (*Conn) SendDHCP Uses

func (c *Conn) SendDHCP(pkt *Packet, intf *net.Interface) error

SendDHCP sends pkt. The precise transmission mechanism depends on pkt.txType(). intf should be the net.Interface returned by RecvDHCP if responding to a DHCP client, or the interface for which configuration is desired if acting as a client.

func (*Conn) SetReadDeadline Uses

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls. If the deadline is reached, Read will fail with a timeout (see net.Error) instead of blocking. A zero value for t means Read will not time out.

func (*Conn) SetWriteDeadline Uses

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls. If the deadline is reached, Write will fail with a timeout (see net.Error) instead of blocking. A zero value for t means Write will not time out.

type MessageType Uses

type MessageType int

MessageType is the type of a DHCP message.

const (
    MsgDiscover MessageType = iota + 1
    MsgOffer
    MsgRequest
    MsgDecline
    MsgAck
    MsgNack
    MsgRelease
    MsgInform
)

Message types as described in RFC 2131.

func (MessageType) String Uses

func (mt MessageType) String() string

type Option Uses

type Option byte

Option is a DHCP option.

const (
    OptSubnetMask         Option = 1  // IPMask
    OptTimeOffset         Option = 2  // int32
    OptRouters            Option = 3  // IPs
    OptDNSServers         Option = 6  // IPs
    OptHostname           Option = 12 // string
    OptBootFileSize       Option = 13 // uint16
    OptDomainName         Option = 15 // string
    OptInterfaceMTU       Option = 26 // uint16
    OptBroadcastAddr      Option = 28 // IP
    OptNTPServers         Option = 42 // IP
    OptVendorSpecific     Option = 43 // []byte
    OptRequestedIP        Option = 50 // IP
    OptLeaseTime          Option = 51 // uint32
    OptOverload           Option = 52 // byte
    OptServerIdentifier   Option = 54 // IP
    OptRequestedOptions   Option = 55 // []byte
    OptMessage            Option = 56 // string
    OptMaximumMessageSize Option = 57 // uint16
    OptRenewalTime        Option = 58 // uint32
    OptRebindingTime      Option = 59 // uint32
    OptVendorIdentifier   Option = 60 // string
    OptClientIdentifier   Option = 61 // string
    OptFQDN               Option = 81 // string

    OptTFTPServer      Option = 66 // string
    OptBootFile        Option = 67 // string
    OptDHCPMessageType Option = 53 // byte
)

Some of the more commonly seen DHCP options. Refer to http://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml for the full authoritative list.

type Options Uses

type Options map[Option][]byte

Options stores DHCP options.

func (Options) Byte Uses

func (o Options) Byte(n Option) (byte, error)

Byte returns the value of option n as a byte.

func (Options) Bytes Uses

func (o Options) Bytes(n Option) ([]byte, error)

Bytes returns the value of option n as a byte slice.

func (Options) Copy Uses

func (o Options) Copy() Options

Copy returns a shallow copy of o.

func (Options) IP Uses

func (o Options) IP(n Option) (net.IP, error)

IP returns the value of option n as an IPv4 address.

func (Options) IPMask Uses

func (o Options) IPMask(n Option) (net.IPMask, error)

IPMask returns the value of option n as a net.IPMask.

func (Options) IPs Uses

func (o Options) IPs(n Option) ([]net.IP, error)

IPs returns the value of option n as a list of IPv4 addresses.

func (Options) Int32 Uses

func (o Options) Int32(n Option) (int32, error)

Int32 returns the value of option n as an int32.

func (Options) Marshal Uses

func (o Options) Marshal() ([]byte, error)

Marshal returns the wire encoding of o.

func (Options) String Uses

func (o Options) String(n Option) (string, error)

String returns the value of option n as a string.

func (Options) Uint16 Uses

func (o Options) Uint16(n Option) (uint16, error)

Uint16 returns the value of option n as a uint16.

func (Options) Uint32 Uses

func (o Options) Uint32(n Option) (uint32, error)

Uint32 returns the value of option n as a uint32.

func (Options) Unmarshal Uses

func (o Options) Unmarshal(bs []byte) error

Unmarshal parses DHCP options into o.

type Packet Uses

type Packet struct {
    Type          MessageType
    TransactionID []byte // Always 4 bytes
    Broadcast     bool
    HardwareAddr  net.HardwareAddr // Only ethernet supported at the moment

    ClientAddr net.IP // Client's current IP address (it will respond to ARP for this IP)
    YourAddr   net.IP // Client IP address offered/assigned by server
    ServerAddr net.IP // Responding server's IP address
    RelayAddr  net.IP // IP address of DHCP relay agent, if an agent forwarded the request

    BootServerName string
    BootFilename   string

    Options Options
}

Packet represents a DHCP packet.

func Unmarshal Uses

func Unmarshal(bs []byte) (*Packet, error)

Unmarshal parses a DHCP message and returns a Packet.

func (*Packet) DebugString Uses

func (p *Packet) DebugString() string

DebugString prints the contents of a DHCP packet for human consumption.

func (*Packet) Marshal Uses

func (p *Packet) Marshal() ([]byte, error)

Marshal returns the wire encoding of p.

Package dhcp4 imports 10 packages (graph) and is imported by 3 packages. Updated 2019-02-17. Refresh now. Tools for package owners.