rawsocket

package
v0.0.0-...-11e162c Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TPacketAlignment = 16

	MinimumFrameSize = TPacketAlignment << 7
	MaximumFrameSize = TPacketAlignment << 11

	DefaultMaxPackets = 128
)
View Source
const (
	// Packet socket options
	PacketRxRing  = 5
	PacketVersion = 10
	PacketReserve = 12
	PacketTxRing  = 13
	// TODO: Support for any of the following useful?
	PacketStatistics  = 6 /// Counts packets and drops
	PacketLoss        = 14
	PacketVnetHdr     = 15
	PacketTxTimestamp = 16
	PacketTimestamp   = 17
)
View Source
const (
	HostByteSize  = 1
	HostShortSize = 2
	HostIntSize   = 4
	HostLongSize  = 8
)
View Source
const (
	PacketHost      = 0 // To us
	PacketBroadcast = 1 // To all
	PacketMulticast = 2 // To group
	PacketOtherHost = 3 // To someone else
	PacketOutgoing  = 4 // Outgoing of any type
	PacketLoopback  = 5 // MC/BRD frame looped back
	PacketUser      = 6 // To user space
	PacketFastRoute = 6 // Fastrouted frame
	PacketKernel    = 7 // To kernel space

)

Packet types

View Source
const DefaultFrameSize uint16 = MinimumFrameSize
View Source
const DefaultProtocol uint16 = syscall.ETH_P_ALL

Variables

This section is empty.

Functions

func Addr

func Addr(sa *SockAddr) []byte

func AddrLen

func AddrLen(sa *SockAddr) uint8

func AddrType

func AddrType(sa *SockAddr) uint16

func Family

func Family(sa *SockAddr) uint16

func Htons

func Htons(value uint16) uint16

func Ifindex

func Ifindex(sa *SockAddr) uint32

func PacketType

func PacketType(sa *SockAddr) uint8

func SockProtocol

func SockProtocol(sa *SockAddr) uint16

Types

type Option

type Option func(*RawSocket)

func BerkleyPacketFilter

func BerkleyPacketFilter(bpf string) Option

func Domain

func Domain(domain int) Option

func MaxFrameSize

func MaxFrameSize(frameSize uint16) Option

func MaxTotalFrames

func MaxTotalFrames(maxFrames uint) Option

func PacketRxFilter

func PacketRxFilter(filter func(nettypes.Frame, uint32, uint32) nettypes.Frame) Option

func Protocol

func Protocol(proto uint16) Option

func RxChannel

func RxChannel(channel chan nettypes.Frame) Option

func RxEnable

func RxEnable(enable bool) Option

func TxEnable

func TxEnable(enable bool) Option

func Version

func Version(version TPacketVersion) Option

func VlanRxAdjustEnable

func VlanRxAdjustEnable(enable bool) Option

type RawSocket

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

func NewRawSocket

func NewRawSocket(intf string, opts ...Option) (*RawSocket, error)

NewRawSocket initializes a new raw socket but does not open it

func (*RawSocket) Close

func (sock *RawSocket) Close()

func (*RawSocket) Flush

func (sock *RawSocket) Flush() (uint, error, []error)

Flush tells the kernel to flush all packets written to the TX ring buffer

func (*RawSocket) MaxPacketSize

func (sock *RawSocket) MaxPacketSize() uint16

MaxPacketSize returns the frame size in bytes

func (*RawSocket) MaxPackets

func (sock *RawSocket) MaxPackets() int32

MaxPackets returns the maximum amount of frame packets that can be written

func (*RawSocket) MaxTxPacketSize

func (sock *RawSocket) MaxTxPacketSize() uint16

MaxTxPacketSize returns the frame size in bytes

func (*RawSocket) Open

func (sock *RawSocket) Open() error

func (*RawSocket) String

func (sock *RawSocket) String() string

func (*RawSocket) TPacketVersion

func (sock *RawSocket) TPacketVersion() TPacketVersion

func (*RawSocket) TxFrame

func (sock *RawSocket) TxFrame(buf []byte, l uint16) (int32, error)

TxFrame writes a raw frame in bytes to the TX ring buffer. The length of the frame must be specified or 0 can be provided and the size of the byte buffer will be used.

func (*RawSocket) WrittenPackets

func (sock *RawSocket) WrittenPackets() int32

WrittenPackets returns the amount of packets, written to the tx ring, that haven't been flushed.

type SockAddr

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

func NewSockAddr

func NewSockAddr(rawData []byte) *SockAddr

type TPacket2Hdr

type TPacket2Hdr struct {
	TpStatus   uint32
	TpLen      uint32
	TpSnapLen  uint32
	TpMac      uint16
	TpNet      uint16
	TpSec      uint32
	TpNsec     uint32
	TpVlanTci  uint16
	TpVlanTpid uint16
	// contains filtered or unexported fields
}

func NewTPacket2Hdr

func NewTPacket2Hdr(rawData []byte) *TPacket2Hdr

type TPacketReq

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

type TPacketVersion

type TPacketVersion int
const DefaultTPacketVersion TPacketVersion = TpacketV2

TODO: This will soon change to TpacketV3

const TpacketV2 TPacketVersion = 1
const TpacketV3 TPacketVersion = 2

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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