Documentation ¶
Index ¶
- Constants
- Variables
- func DHCPMarshalOption(o DHCPOption) (out []byte, err error)
- func DHCPWriteOption(w io.Writer, a DHCPOption) (n int, err error)
- type ARP
- type ChassisTLV
- type DHCP
- func NewDHCP(xid uint32, op DHCPOperation, hwtype byte) (*DHCP, error)
- func NewDHCPAck(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)
- func NewDHCPDiscover(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)
- func NewDHCPNak(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)
- func NewDHCPOffer(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)
- func NewDHCPRequest(xid uint32, hwAddr net.HardwareAddr) (d *DHCP, err error)
- type DHCPOperation
- type DHCPOption
- func DHCPIP4Option(tag byte, ips net.IP) (opt DHCPOption, err error)
- func DHCPIP4sOption(tag byte, ips []net.IP) (opt DHCPOption, err error)
- func DHCPNewOption(tag byte, data []byte) DHCPOption
- func DHCPParseOptions(in []byte) (opts []DHCPOption, err error)
- func DHCPStringOption(tag byte, s string) (opt DHCPOption, err error)
- type Ethernet
- type FragmentHeader
- type HopByHopHeader
- type ICMP
- type IPv4
- type IPv6
- type LLDP
- type Option
- type PortTLV
- type RoutingHeader
- type TCP
- type TTLTLV
- type UDP
- type VLAN
Constants ¶
const ( Type_Request = 1 Type_Reply = 2 )
const ( DHCP_MSG_BOOT_REQ byte = iota DHCP_MSG_BOOT_RES )
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 )
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_PLATEAU_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)
const ( IPv4_MSG = 0x0800 ARP_MSG = 0x0806 LLDP_MSG = 0x88cc WOL_MSG = 0x0842 RARP_MSG = 0x8035 VLAN_MSG = 0x8100 IPv6_MSG = 0x86DD STP_MSG = 0x4242 STP_BPDU_MSG = 0xAAAA )
see http://en.wikipedia.org/wiki/EtherType
const ( PCP_MASK = 0xe000 DEI_MASK = 0x1000 VID_MASK = 0x0fff )
const ( Type_ICMP = 0x01 Type_TCP = 0x06 Type_UDP = 0x11 Type_IPv6 = 0x29 Type_IPv6ICMP = 0x3a )
const ( Type_HBH = 0x0 Type_Routing = 0x2b Type_Fragment = 0x2c )
const ( CH_CHASSIS_COMPONENT CH_IFACE_ALIAS CH_PORT_COMPONENT CH_MAC_ADDR CH_NET_ADDR CH_IFACE_NAME CH_LOCAL_ASSGN )
Chassis ID subtypes
const ( PT_IFACE_ALIAS PT_PORT_COMPONENT PT_MAC_ADDR PT_NET_ADDR PT_IFACE_NAME PT_CIRCUIT_ID PT_LOCAL_ASSGN )
Port ID subtypes
const (
DHCP_FLAG_BROADCAST uint16 = 0x80
)
const (
DHCP_HW_ETHERNET byte = 0x01
)
Variables ¶
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_PLATEAU_TABLE_OPTION: "OPT_PATH_PLATEAU_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 ARP ¶
type ARP struct { HWType uint16 ProtoType uint16 HWLength uint8 ProtoLength uint8 Operation uint16 HWSrc net.HardwareAddr IPSrc net.IP HWDst net.HardwareAddr IPDst net.IP }
func (*ARP) MarshalBinary ¶
func (*ARP) UnmarshalBinary ¶
type ChassisTLV ¶
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 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)
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 ¶
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!
type Ethernet ¶
type Ethernet struct { Delimiter uint8 HWDst net.HardwareAddr HWSrc net.HardwareAddr VLANID VLAN Ethertype uint16 Data util.Message }
func NewEthernet ¶
func NewEthernet() *Ethernet
func (*Ethernet) MarshalBinary ¶
func (*Ethernet) UnmarshalBinary ¶
type FragmentHeader ¶
type FragmentHeader struct { NextHeader uint8 Reserved uint8 FragmentOffset uint16 MoreFragments bool Identification uint32 }
func NewFragmentHeader ¶
func NewFragmentHeader() *FragmentHeader
func (*FragmentHeader) Len ¶
func (h *FragmentHeader) Len() uint16
func (*FragmentHeader) MarshalBinary ¶
func (h *FragmentHeader) MarshalBinary() (data []byte, err error)
func (*FragmentHeader) UnmarshalBinary ¶
func (h *FragmentHeader) UnmarshalBinary(data []byte) error
type HopByHopHeader ¶
func NewHopByHopHeader ¶
func NewHopByHopHeader() *HopByHopHeader
func (*HopByHopHeader) Len ¶
func (h *HopByHopHeader) Len() uint16
func (*HopByHopHeader) MarshalBinary ¶
func (h *HopByHopHeader) MarshalBinary() (data []byte, err error)
func (*HopByHopHeader) UnmarshalBinary ¶
func (h *HopByHopHeader) UnmarshalBinary(data []byte) error
type IPv4 ¶
type IPv4 struct { Version uint8 //4-bits IHL uint8 //4-bits DSCP uint8 //6-bits ECN uint8 //2-bits Length uint16 Id uint16 Flags uint16 //3-bits FragmentOffset uint16 //13-bits TTL uint8 Protocol uint8 Checksum uint16 NWSrc net.IP NWDst net.IP Options util.Buffer Data util.Message }
func (*IPv4) MarshalBinary ¶
func (*IPv4) UnmarshalBinary ¶
type IPv6 ¶
type IPv6 struct { Version uint8 //4-bits TrafficClass uint8 FlowLabel uint32 //20-bits Length uint16 NextHeader uint8 HopLimit uint8 NWSrc net.IP NWDst net.IP HbhHeader *HopByHopHeader RoutingHeader *RoutingHeader FragmentHeader *FragmentHeader Data util.Message }
func (*IPv6) MarshalBinary ¶
func (*IPv6) UnmarshalBinary ¶
type LLDP ¶
type LLDP struct { Chassis ChassisTLV Port PortTLV TTL TTLTLV }
type RoutingHeader ¶
type RoutingHeader struct { NextHeader uint8 HEL uint8 RoutingType uint8 SegmentsLeft uint8 Data *util.Buffer }
func NewRoutingHeader ¶
func NewRoutingHeader() *RoutingHeader
func (*RoutingHeader) Len ¶
func (h *RoutingHeader) Len() uint16
func (*RoutingHeader) MarshalBinary ¶
func (h *RoutingHeader) MarshalBinary() (data []byte, err error)
func (*RoutingHeader) UnmarshalBinary ¶
func (h *RoutingHeader) UnmarshalBinary(data []byte) error
type TCP ¶
type TCP struct { PortSrc uint16 PortDst uint16 SeqNum uint32 AckNum uint32 HdrLen uint8 Code uint8 WinSize uint16 Checksum uint16 UrgFlag uint16 Data []byte }