Documentation ¶
Overview ¶
Package socket implements AF_PACKET sockets / file descriptors (both for `afring` and plain `afpacket` modes). In addition, allocated sockets provide access to packet capture statistics for the underlying network interface during capture.
Index ¶
- Constants
- type FileDescriptor
- func (sd FileDescriptor) Close() error
- func (sd FileDescriptor) GetSocketStats() (ss TPacketStats, err error)
- func (sd FileDescriptor) IsOpen() bool
- func (sd FileDescriptor) SetSocketOptions(iface *link.Link, snapLen int, promisc bool) error
- func (sd FileDescriptor) SetupRingBuffer(val unsafe.Pointer, vallen uintptr) error
- type MockFileDescriptor
- func (m *MockFileDescriptor) Get() capture.Packet
- func (m *MockFileDescriptor) GetSocketStats() (ss TPacketStats, err error)
- func (m *MockFileDescriptor) GetSocketStatsNoReset() (ss TPacketStats, err error)
- func (m *MockFileDescriptor) HasPackets() bool
- func (m *MockFileDescriptor) IncrementPacketCount(delta uint64)
- func (m *MockFileDescriptor) LastPoll() int64
- func (m *MockFileDescriptor) Put(pkt capture.Packet)
- func (m *MockFileDescriptor) ReleaseSemaphore() (errno unix.Errno)
- func (m *MockFileDescriptor) SetNoRelease(enable bool) *MockFileDescriptor
- type TPacketStats
Constants ¶
const (
TPacketVersion = unix.TPACKET_V3 // TPacketVersion : The TPacket header version to use
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileDescriptor ¶
type FileDescriptor int
FileDescriptor denotes a generic system level file descriptor (an int)
func (FileDescriptor) Close ¶
func (sd FileDescriptor) Close() error
Close closes the file descriptor
func (FileDescriptor) GetSocketStats ¶
func (sd FileDescriptor) GetSocketStats() (ss TPacketStats, err error)
GetSocketStats returns (and resets) socket / traffic statistics
func (FileDescriptor) IsOpen ¶
func (sd FileDescriptor) IsOpen() bool
IsOpen determines if the file descriptor is open / valid
func (FileDescriptor) SetSocketOptions ¶
SetSocketOptions sets several socket options on the underlying file descriptor required to perform AF_PACKET capture and retrieval of socket / traffic statistics
func (FileDescriptor) SetupRingBuffer ¶
func (sd FileDescriptor) SetupRingBuffer(val unsafe.Pointer, vallen uintptr) error
SetupRingBuffer peforms a call via setsockopt() to prepare a mmmap'ed ring buffer
type MockFileDescriptor ¶
type MockFileDescriptor struct { FileDescriptor // contains filtered or unexported fields }
MockFileDescriptor denotes a mock file descriptor mimicking the behavior of an AF_PACKET socket by means of using a simple event file descriptor instead
func NewMock ¶
func NewMock() (MockFileDescriptor, error)
NewMock instantiates a new mock file descriptor
func (*MockFileDescriptor) Get ¶
func (m *MockFileDescriptor) Get() capture.Packet
Get fetches a single packets from the (buffered) mock file descriptor
func (*MockFileDescriptor) GetSocketStats ¶
func (m *MockFileDescriptor) GetSocketStats() (ss TPacketStats, err error)
GetSocketStats returns (and resets) socket / traffic statistics
func (*MockFileDescriptor) GetSocketStatsNoReset ¶
func (m *MockFileDescriptor) GetSocketStatsNoReset() (ss TPacketStats, err error)
GetSocketStatsNoReset returns socket / traffic statistics (without resetting the counters)
func (*MockFileDescriptor) HasPackets ¶
func (m *MockFileDescriptor) HasPackets() bool
HasPackets returns if there are currently any packets in the mock buffer
func (*MockFileDescriptor) IncrementPacketCount ¶
func (m *MockFileDescriptor) IncrementPacketCount(delta uint64)
IncrementPacketCount allows for simulation of packet / traffic statistics by means of manual counting (to be used during population of a mock data source)
func (*MockFileDescriptor) LastPoll ¶
func (m *MockFileDescriptor) LastPoll() int64
LastPoll return the timestamp of the last poll on the FileDescriptor
func (*MockFileDescriptor) Put ¶
func (m *MockFileDescriptor) Put(pkt capture.Packet)
Put sends a single packets via the (buffered) mock file descriptor
func (*MockFileDescriptor) ReleaseSemaphore ¶
func (m *MockFileDescriptor) ReleaseSemaphore() (errno unix.Errno)
ReleaseSemaphore consumes from the event fd, releasing the semaphore and indicating that the next event can be sent
func (*MockFileDescriptor) SetNoRelease ¶
func (m *MockFileDescriptor) SetNoRelease(enable bool) *MockFileDescriptor
SetNoRelease disables reading from the eventFD after data has been consumed (thereby not releasing the block which has to be handled elsewhere instead)
type TPacketStats ¶
TPacketStats denotes the V3 tpacket_stats structure, c.f. https://github.com/torvalds/linux/blob/master/include/uapi/linux/if_packet.h