dhcp

package
Version: v0.0.0-...-0e9ae86 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2015 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DHCP_MSG_BOOT_REQ byte = iota
	DHCP_MSG_BOOT_RES
)
View Source
const (
	DHCP_OPT_REQUEST_IP     byte = iota + 50 // 0x32, 4, net.IP
	DHCP_OPT_LEASE_TIME                      // 0x33, 4, uint32
	DHCP_OPT_EXT_OPTS                        // 0x34, 1, 1/2/3
	DHCP_OPT_MESSAGE_TYPE                    // 0x35, 1, 1-7
	DHCP_OPT_SERVER_ID                       // 0x36, 4, net.IP
	DHCP_OPT_PARAMS_REQUEST                  // 0x37, n, []byte
	DHCP_OPT_MESSAGE                         // 0x38, n, string
	DHCP_OPT_MAX_DHCP_SIZE                   // 0x39, 2, uint16
	DHCP_OPT_T1                              // 0x3a, 4, uint32
	DHCP_OPT_T2                              // 0x3b, 4, uint32
	DHCP_OPT_CLASS_ID                        // 0x3c, n, []byte
	DHCP_OPT_CLIENT_ID                       // 0x3d, n >=  2, []byte

)
View Source
const (
	DHCP_OPT_PAD                      byte = iota
	DHCP_OPT_SUBNET_MASK                   // 0x01, 4, net.IP
	DHCP_OPT_TIME_OFFSET                   // 0x02, 4, int32 (signed seconds from UTC)
	DHCP_OPT_DEFAULT_GATEWAY               // 0x03, n*4, [n]net.IP
	DHCP_OPT_TIME_SERVER                   // 0x04, n*4, [n]net.IP
	DHCP_OPT_NAME_SERVER                   // 0x05, n*4, [n]net.IP
	DHCP_OPT_DOMAIN_NAME_SERVERS           // 0x06, n*4, [n]net.IP
	DHCP_OPT_LOG_SERVER                    // 0x07, n*4, [n]net.IP
	DHCP_OPT_COOKIE_SERVER                 // 0x08, n*4, [n]net.IP
	DHCP_OPT_LPR_SERVER                    // 0x09, n*4, [n]net.IP
	DHCP_OPT_IMPRESS_SERVER                // 0x0a, n*4, [n]net.IP
	DHCP_OPT_RLSERVER                      // 0x0b, n*4, [n]net.IP
	DHCP_OPT_HOST_NAME                     // 0x0c, n, string
	DHCP_OPT_BOOTFILE_SIZE                 // 0x0d, 2, uint16
	DHCP_OPT_MERIT_DUMP_FILE               // 0x0e, >1, string
	DHCP_OPT_DOMAIN_NAME                   // 0x0f, n, string
	DHCP_OPT_SWAP_SERVER                   // 0x10, n*4, [n]net.IP
	DHCP_OPT_ROOT_PATH                     // 0x11, n, string
	DHCP_OPT_EXTENSIONS_PATH               // 0x12, n, string
	DHCP_OPT_IP_FORWARDING                 // 0x13, 1, bool
	DHCP_OPT_SOURCE_ROUTING                // 0x14, 1, bool
	DHCP_OPT_POLICY_FILTER                 // 0x15, 8*n, [n]{net.IP/net.IP}
	DHCP_OPT_DGRAM_MTU                     // 0x16, 2, uint16
	DHCP_OPT_DEFAULT_TTL                   // 0x17, 1, byte
	DHCP_OPT_PATH_MTU_AGING_TIMEOUT        // 0x18, 4, uint32
	DHCP_OPT_PATH_PLATEU_TABLE_OPTION      // 0x19, 2*n, []uint16
	DHCP_OPT_INTERFACE_MTU                 //0x1a, 2, uint16
	DHCP_OPT_ALL_SUBS_LOCAL                // 0x1b, 1, bool
	DHCP_OPT_BROADCAST_ADDR                // 0x1c, 4, net.IP
	DHCP_OPT_MASK_DISCOVERY                // 0x1d, 1, bool
	DHCP_OPT_MASK_SUPPLIER                 // 0x1e, 1, bool
	DHCP_OPT_ROUTER_DISCOVERY              // 0x1f, 1, bool
	DHCP_OPT_ROUTER_SOLICIT_ADDR           // 0x20, 4, net.IP
	DHCP_OPT_STATIC_ROUTE                  // 0x21, n*8, [n]{net.IP/net.IP} -- note the 2nd is router not mask
	DHCP_OPT_ARP_TRAILERS                  // 0x22, 1, bool
	DHCP_OPT_ARP_TIMEOUT                   // 0x23, 4, uint32
	DHCP_OPT_ETHERNET_ENCAP                // 0x24, 1, bool
	DHCP_OPT_TCP_TTL                       // 0x25,1, byte
	DHCP_OPT_TCP_KEEPALIVE_INT             // 0x26,4, uint32
	DHCP_OPT_TCP_KEEPALIVE_GARBAGE         // 0x27,1, bool
	DHCP_OPT_NIS_DOMAIN                    // 0x28,n, string
	DHCP_OPT_NIS_SERVERS                   // 0x29,4*n,  [n]net.IP
	DHCP_OPT_NTP_SERVERS                   // 0x2a, 4*n, [n]net.IP
	DHCP_OPT_VENDOR_OPT                    // 0x2b, n, [n]byte // may be encapsulated.
	DHCP_OPT_NETBIOS_IPNS                  // 0x2c, 4*n, [n]net.IP
	DHCP_OPT_NETBIOS_DDS                   // 0x2d, 4*n, [n]net.IP
	DHCP_OPT_NETBIOS_NODE_TYPE             // 0x2e, 1, magic byte
	DHCP_OPT_NETBIOS_SCOPE                 // 0x2f, n, string
	DHCP_OPT_X_FONT_SERVER                 // 0x30, n, string
	DHCP_OPT_X_DISPLAY_MANAGER             // 0x31, n, string

	DHCP_OPT_SIP_SERVERS byte = 0x78 // 0x78!, n, url
	DHCP_OPT_END         byte = 0xff
)

Standard options (RFC1533)

View Source
const (
	DHCP_FLAG_BROADCAST uint16 = 0x80
)
View Source
const (
	DHCP_HW_ETHERNET byte = 0x01
)

Variables

View Source
var DHCPOptionTypeStrings = [256]string{
	DHCP_OPT_PAD:                      "(padding)",
	DHCP_OPT_SUBNET_MASK:              "SubnetMask",
	DHCP_OPT_TIME_OFFSET:              "TimeOffset",
	DHCP_OPT_DEFAULT_GATEWAY:          "DefaultGateway",
	DHCP_OPT_TIME_SERVER:              "rfc868",
	DHCP_OPT_NAME_SERVER:              "ien116",
	DHCP_OPT_DOMAIN_NAME_SERVERS:      "DNS",
	DHCP_OPT_LOG_SERVER:               "mitLCS",
	DHCP_OPT_COOKIE_SERVER:            "OPT_COOKIE_SERVER",
	DHCP_OPT_LPR_SERVER:               "OPT_LPR_SERVER",
	DHCP_OPT_IMPRESS_SERVER:           "OPT_IMPRESS_SERVER",
	DHCP_OPT_RLSERVER:                 "OPT_RLSERVER",
	DHCP_OPT_HOST_NAME:                "Hostname",
	DHCP_OPT_BOOTFILE_SIZE:            "BootfileSize",
	DHCP_OPT_MERIT_DUMP_FILE:          "OPT_MERIT_DUMP_FILE",
	DHCP_OPT_DOMAIN_NAME:              "DomainName",
	DHCP_OPT_SWAP_SERVER:              "OPT_SWAP_SERVER",
	DHCP_OPT_ROOT_PATH:                "RootPath",
	DHCP_OPT_EXTENSIONS_PATH:          "OPT_EXTENSIONS_PATH",
	DHCP_OPT_IP_FORWARDING:            "OPT_IP_FORWARDING",
	DHCP_OPT_SOURCE_ROUTING:           "OPT_SOURCE_ROUTING",
	DHCP_OPT_POLICY_FILTER:            "OPT_POLICY_FILTER",
	DHCP_OPT_DGRAM_MTU:                "OPT_DGRAM_MTU",
	DHCP_OPT_DEFAULT_TTL:              "OPT_DEFAULT_TTL",
	DHCP_OPT_PATH_MTU_AGING_TIMEOUT:   "OPT_PATH_MTU_AGING_TIMEOUT",
	DHCP_OPT_PATH_PLATEU_TABLE_OPTION: "OPT_PATH_PLATEU_TABLE_OPTION",
	DHCP_OPT_INTERFACE_MTU:            "OPT_INTERFACE_MTU",
	DHCP_OPT_ALL_SUBS_LOCAL:           "OPT_ALL_SUBS_LOCAL",
	DHCP_OPT_BROADCAST_ADDR:           "OPT_BROADCAST_ADDR",
	DHCP_OPT_MASK_DISCOVERY:           "OPT_MASK_DISCOVERY",
	DHCP_OPT_MASK_SUPPLIER:            "OPT_MASK_SUPPLIER",
	DHCP_OPT_ROUTER_DISCOVERY:         "OPT_ROUTER_DISCOVERY",
	DHCP_OPT_ROUTER_SOLICIT_ADDR:      "OPT_ROUTER_SOLICIT_ADDR",
	DHCP_OPT_STATIC_ROUTE:             "OPT_STATIC_ROUTE",
	DHCP_OPT_ARP_TRAILERS:             "OPT_ARP_TRAILERS",
	DHCP_OPT_ARP_TIMEOUT:              "OPT_ARP_TIMEOUT",
	DHCP_OPT_ETHERNET_ENCAP:           "OPT_ETHERNET_ENCAP",
	DHCP_OPT_TCP_TTL:                  "OPT_TCP_TTL",
	DHCP_OPT_TCP_KEEPALIVE_INT:        "OPT_TCP_KEEPALIVE_INT",
	DHCP_OPT_TCP_KEEPALIVE_GARBAGE:    "OPT_TCP_KEEPALIVE_GARBAGE",
	DHCP_OPT_NIS_DOMAIN:               "OPT_NIS_DOMAIN",
	DHCP_OPT_NIS_SERVERS:              "OPT_NIS_SERVERS",
	DHCP_OPT_NTP_SERVERS:              "OPT_NTP_SERVERS",
	DHCP_OPT_VENDOR_OPT:               "OPT_VENDOR_OPT",
	DHCP_OPT_NETBIOS_IPNS:             "OPT_NETBIOS_IPNS",
	DHCP_OPT_NETBIOS_DDS:              "OPT_NETBIOS_DDS",
	DHCP_OPT_NETBIOS_NODE_TYPE:        "OPT_NETBIOS_NODE_TYPE",
	DHCP_OPT_NETBIOS_SCOPE:            "OPT_NETBIOS_SCOPE",
	DHCP_OPT_X_FONT_SERVER:            "OPT_X_FONT_SERVER",
	DHCP_OPT_X_DISPLAY_MANAGER:        "OPT_X_DISPLAY_MANAGER",
	DHCP_OPT_END:                      "(end)",
	DHCP_OPT_SIP_SERVERS:              "SipServers",
	DHCP_OPT_REQUEST_IP:               "RequestIP",
	DHCP_OPT_LEASE_TIME:               "LeaseTime",
	DHCP_OPT_EXT_OPTS:                 "ExtOpts",
	DHCP_OPT_MESSAGE_TYPE:             "MessageType",
	DHCP_OPT_SERVER_ID:                "ServerID",
	DHCP_OPT_PARAMS_REQUEST:           "ParamsRequest",
	DHCP_OPT_MESSAGE:                  "Message",
	DHCP_OPT_MAX_DHCP_SIZE:            "MaxDHCPSize",
	DHCP_OPT_T1:                       "Timer1",
	DHCP_OPT_T2:                       "Timer2",
	DHCP_OPT_CLASS_ID:                 "ClassID",
	DHCP_OPT_CLIENT_ID:                "ClientID",
}

I'm amazed that this is syntactically valid. cool though.

Functions

func DHCPMarshalOption

func DHCPMarshalOption(o DHCPOption) (out []byte, err error)

A more json.Marshal like version of WriteOption.

func DHCPWriteOption

func DHCPWriteOption(w io.Writer, a DHCPOption) (n int, err error)

Write an option to an io.Writer, including tag & length (if length is appropriate to the tag type). Utilizes the MarshalOption as the underlying serializer.

Types

type DHCP

type DHCP struct {
	Operation    DHCPOperation
	HardwareType byte
	HardwareLen  uint8
	HardwareOpts uint8
	Xid          uint32
	Secs         uint16
	Flags        uint16
	ClientIP     net.IP
	YourIP       net.IP
	ServerIP     net.IP
	GatewayIP    net.IP
	ClientHWAddr net.HardwareAddr
	ServerName   [64]byte
	File         [128]byte
	Options      []DHCPOption
}

func NewDHCP

func NewDHCP(xid uint32, op DHCPOperation, hwtype byte) (*DHCP, error)

func NewDHCPAck

func NewDHCPAck(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)

func NewDHCPDiscover

func NewDHCPDiscover(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)

func NewDHCPNak

func NewDHCPNak(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)

func NewDHCPOffer

func NewDHCPOffer(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)

func NewDHCPRequest

func NewDHCPRequest(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)

func (*DHCP) Len

func (d *DHCP) Len() (n uint16)

func (*DHCP) Read

func (d *DHCP) Read(b []byte) (n int, err error)

func (*DHCP) Write

func (d *DHCP) Write(b []byte) (n int, err error)

type DHCPOperation

type DHCPOperation byte
const (
	DHCP_MSG_UNSPEC DHCPOperation = iota
	DHCP_MSG_DISCOVER
	DHCP_MSG_OFFER
	DHCP_MSG_REQUEST
	DHCP_MSG_DECLINE
	DHCP_MSG_ACK
	DHCP_MSG_NAK
	DHCP_MSG_RELEASE
	DHCP_MSG_INFORM
)

type DHCPOption

type DHCPOption interface {
	OptionType() byte
	Bytes() []byte
	Len() uint16
}

func DHCPIP4Option

func DHCPIP4Option(tag byte, ips net.IP) (opt DHCPOption, err error)

NB: We don't validate that you have /any/ IP's in the option here, simply that if you do that they're valid. Most DHCP options are only valid with 1(+|) values

func DHCPIP4sOption

func DHCPIP4sOption(tag byte, ips []net.IP) (opt DHCPOption, err error)

NB: We don't validate that you have /any/ IP's in the option here, simply that if you do that they're valid. Most DHCP options are only valid with 1(+|) values

func DHCPNewOption

func DHCPNewOption(tag byte, data []byte) DHCPOption

func DHCPParseOptions

func DHCPParseOptions(in []byte) (opts []DHCPOption, err error)

func DHCPStringOption

func DHCPStringOption(tag byte, s string) (opt DHCPOption, err error)

NB: I'm not checking tag : min length here!

Source Files

Jump to

Keyboard shortcuts

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