ethernet

package
v0.0.0-...-4087627 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OpReserved is a special reserved OpCode
	OpReserved uint16 = iota // see RFC5494
	// OpRequest is the OpCode for ARP requests
	OpRequest
	// OpReply is the OpCode for ARP replies
	OpReply
)

Variables

View Source
var (
	// ErrNotVLAN is an error returned when calling EthernetFrame.ExtractVLAN
	// if the frame is not of type EthernetTypeVLAN
	ErrNotVLAN = errors.New("ethernet frame not of type VLAN")
	// ErrMalformedVLAN is an error returned when parsing a VLAN tag
	// that is malformed
	ErrMalformedVLAN = errors.New("VLAN tag is malformed")
	// ErrMalformedFrame is an error returned when parsing an ethernet frame
	// that is malformed
	ErrMalformedFrame = errors.New("malformed ethernet frame")
)
View Source
var (
	// ErrMalformedPacket is an error returned when parsing a malformed ARP packet
	ErrMalformedARPPacket = errors.New("malformed ARP packet")
)

Functions

This section is empty.

Types

type ARPPacket

type ARPPacket struct {
	SendIPAddr      netip.Addr
	TgtIPAddr       netip.Addr
	SendHwAddr      net.HardwareAddr
	TgtHwAddr       net.HardwareAddr
	HardwareType    HardwareType
	OpCode          uint16
	ProtocolType    ProtocolType
	HardwareAddrLen uint8
	ProtocolAddrLen uint8
}

ARPPacket is a struct containing the data of an ARP packet

func (*ARPPacket) UnmarshalBinary

func (pkt *ARPPacket) UnmarshalBinary(buf []byte) error

UnmarshalBinary takes the ARP packet bytes and parses it into a Packet

type EthernetFrame

type EthernetFrame struct {
	SrcMAC       net.HardwareAddr
	DstMAC       net.HardwareAddr
	Payload      []byte
	Len          uint16
	EthernetType EthernetType
}

EthernetFrame represents an ethernet frame

func (*EthernetFrame) ExtractARPPacket

func (e *EthernetFrame) ExtractARPPacket() (*ARPPacket, error)

ExtractARPPacket will extract an ARP packet from the ethernet frame's payload

func (*EthernetFrame) ExtractVLAN

func (e *EthernetFrame) ExtractVLAN() (*VLAN, error)

ExtractVLAN will extract the VLAN tag from the ethernet frame's payload if one is present and return ErrNotVLAN if not

func (*EthernetFrame) UnmarshalBinary

func (e *EthernetFrame) UnmarshalBinary(buf []byte) error

UnmarshalBinary parses ethernet frame bytes into an EthernetFrame

type EthernetType

type EthernetType uint16
const (
	// EthernetTypeLLC is a special ethernet type, if found the frame is truncated
	EthernetTypeLLC EthernetType = 0
	// EthernetTypeIPv4 is the ethernet type for a frame containing an IPv4 packet
	EthernetTypeIPv4 EthernetType = 0x0800
	// EthernetTypeARP is the ethernet type for a frame containing an ARP packet
	EthernetTypeARP EthernetType = 0x0806
	// EthernetTypeIPv6 is the ethernet type for a frame containing an IPv6 packet
	EthernetTypeIPv6 EthernetType = 0x86dd
	// EthernetTypeVLAN is the ethernet type for a frame containing a VLAN tag,
	// the VLAN tag bytes will indicate the actual type of packet the frame contains
	EthernetTypeVLAN EthernetType = 0x8100

	// NonStdLenEthernetTypes is a magic number to find any non-standard types
	// and mark them as EthernetTypeLLC
	NonStdLenEthernetTypes EthernetType = 0x600
)

func (EthernetType) String

func (i EthernetType) String() string

type HardwareType

type HardwareType uint16
const (
	// HardwareTypeReserved is a special value for hardware type
	HardwareTypeReserved HardwareType = 0 // see RFC5494
	// HardwareTypeEthernet is the hardware type value for Ethernet
	// we only care about ethernet, but additional types are defined for
	// testing and possible future use
	HardwareTypeEthernet HardwareType = 1
	// HardwareTypeExpEth is the hardware type for experimental ethernet
	HardwareTypeExpEth HardwareType = 2
	// HardwareTypeAX25 is the hardware type for Radio AX.25
	HardwareTypeAX25 HardwareType = 3
	// HardwareTypeChaos is a chaos value for hardware type
	HardwareTypeChaos HardwareType = 4
	// HardwareTypeIEEE802 is for IEEE 802 networks
	HardwareTypeIEEE802 HardwareType = 5

	// HardwareTypeFiberChannel is the hardware type for fiber channel
	HardwareTypeFiberChannel HardwareType = 18
	// HardwareTypeSerialLine is the hardware type for serial line
	HardwareTypeSerialLine HardwareType = 19
	// HardwareTypeHIPARP is the hardware type for HIPARP
	HardwareTypeHIPARP HardwareType = 28
	// HardwareTypeIPARPISO7163 is the hardware type for IP and ARP over ISO 7816-3
	HardwareTypeIPARPISO7163 HardwareType = 29
	// HardwareTypeARPSec is the hardware type for ARPSec
	HardwareTypeARPSec HardwareType = 30
	// HardwareTypeIPSec is the hardware type for IPSec tunnel
	HardwareTypeIPSec HardwareType = 31
	// HardwareTypeInfiniBand is the hardware type for InfiniBand
	HardwareTypeInfiniBand HardwareType = 32
)

func (HardwareType) String

func (i HardwareType) String() string

type ProtocolType

type ProtocolType uint16
const (
	// ProtocolTypeIPv4 is the value for IPv4 ARP packets
	ProtocolTypeIPv4 ProtocolType = 0x0800
	// ProtocolTypeIPv6 is the value for IPv6 ARP packets,
	// which shouldn't be used, this is defined for testing purposes
	ProtocolTypeIPv6 ProtocolType = 0x86dd
	// ProtocolTypeARP is the value for ARP packets with a protocol
	// value of ARP itself
	ProtocolTypeARP ProtocolType = 0x0806
)

func (ProtocolType) String

func (i ProtocolType) String() string

type VLAN

type VLAN struct {
	Priority     uint8
	DropEligible bool
	ID           uint16
	EthernetType EthernetType
}

VLAN represents a VLAN tag within an ethernet frame

func (*VLAN) UnmarshalBinary

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

UnmarshalBinary will take the ethernet frame's payload and extract a VLAN tag if one is present

Jump to

Keyboard shortcuts

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