protocol

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Type_Request = 1
	Type_Reply   = 2
)
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 (
	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

View Source
const (
	PCP_MASK = 0xe000
	DEI_MASK = 0x1000
	VID_MASK = 0x0fff
)
View Source
const (
	Type_ICMP     = 0x01
	Type_TCP      = 0x06
	Type_UDP      = 0x11
	Type_IPv6     = 0x29
	Type_IPv6ICMP = 0x3a
)
View Source
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

View Source
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

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

func NewARP(opt int) (*ARP, error)

func (*ARP) Len

func (a *ARP) Len() (n uint16)

func (*ARP) MarshalBinary

func (a *ARP) MarshalBinary() (data []byte, err error)

func (*ARP) UnmarshalBinary

func (a *ARP) UnmarshalBinary(data []byte) error

type ChassisTLV

type ChassisTLV struct {
	Type    uint8
	Length  uint16
	Subtype uint8
	Data    []uint8
}

func (*ChassisTLV) Read

func (t *ChassisTLV) Read(b []byte) (n int, err error)

func (*ChassisTLV) Write

func (t *ChassisTLV) Write(b []byte) (n int, err error)

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!

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

func (e *Ethernet) Len() (n uint16)

func (*Ethernet) MarshalBinary

func (e *Ethernet) MarshalBinary() (data []byte, err error)

func (*Ethernet) UnmarshalBinary

func (e *Ethernet) UnmarshalBinary(data []byte) error

type ICMP

type ICMP struct {
	Type     uint8
	Code     uint8
	Checksum uint16
	Data     []byte
}

func NewICMP

func NewICMP() *ICMP

func (*ICMP) Len

func (i *ICMP) Len() (n uint16)

func (*ICMP) MarshalBinary

func (i *ICMP) MarshalBinary() (data []byte, err error)

func (*ICMP) UnmarshalBinary

func (i *ICMP) 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 NewIPv4

func NewIPv4() *IPv4

func (*IPv4) Len

func (i *IPv4) Len() (n uint16)

func (*IPv4) MarshalBinary

func (i *IPv4) MarshalBinary() (data []byte, err error)

func (*IPv4) UnmarshalBinary

func (i *IPv4) UnmarshalBinary(data []byte) error

type LLDP

type LLDP struct {
	Chassis ChassisTLV
	Port    PortTLV
	TTL     TTLTLV
}

func (*LLDP) Len

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

func (*LLDP) Read

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

func (*LLDP) Write

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

type PortTLV

type PortTLV struct {
	Type    uint8  //7bits
	Length  uint16 //9bits
	Subtype uint8
	Data    []uint8
}

func (*PortTLV) Read

func (t *PortTLV) Read(b []byte) (n int, err error)

func (*PortTLV) Write

func (t *PortTLV) Write(b []byte) (n int, err 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
}

func NewTCP

func NewTCP() *TCP

func (*TCP) Len

func (t *TCP) Len() (n uint16)

func (*TCP) MarshalBinary

func (t *TCP) MarshalBinary() (data []byte, err error)

func (*TCP) UnmarshalBinary

func (t *TCP) UnmarshalBinary(data []byte) error

type TTLTLV

type TTLTLV struct {
	Type    uint8  //7 bits
	Length  uint16 //9 bits
	Seconds uint16
}

func (*TTLTLV) Read

func (t *TTLTLV) Read(b []byte) (n int, err error)

func (*TTLTLV) Write

func (t *TTLTLV) Write(b []byte) (n int, err error)

type UDP

type UDP struct {
	PortSrc  uint16
	PortDst  uint16
	Length   uint16
	Checksum uint16
	Data     []byte
}

func NewUDP

func NewUDP() *UDP

func (*UDP) Len

func (u *UDP) Len() (n uint16)

func (*UDP) MarshalBinary

func (u *UDP) MarshalBinary() (data []byte, err error)

func (*UDP) UnmarshalBinary

func (u *UDP) UnmarshalBinary(data []byte) error

type VLAN

type VLAN struct {
	TPID uint16
	PCP  uint8
	DEI  uint8
	VID  uint16
}

func NewVLAN

func NewVLAN() *VLAN

func (*VLAN) Len

func (v *VLAN) Len() (n uint16)

func (*VLAN) MarshalBinary

func (v *VLAN) MarshalBinary() (data []byte, err error)

func (*VLAN) UnmarshalBinary

func (v *VLAN) UnmarshalBinary(data []byte) error

Jump to

Keyboard shortcuts

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