packetsniff

package module
v0.0.0-...-771c136 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: AGPL-3.0 Imports: 8 Imported by: 1 module, 8 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorsBuffer sets the size of error channels
	ErrorsBuffer = 20
)

Functions

This section is empty.

Types

type BPFilter

type BPFilter struct {
	//Base is base filter
	Base string
	//Include is a list of CIDR or IP to include in the filter
	Include []string
	//Exclude is a list of CIDR or IP to exclude from the filter
	Exclude []string
}

BPFilter is a simple helper for constructing bpf filters

func (BPFilter) Filter

func (bpf BPFilter) Filter() (string, error)

Filter returns the filter in bpf format

type BasicSniff

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

BasicSniff implements an standar processor

func NewBasic

func NewBasic(tick time.Duration) *BasicSniff

NewBasic creates a new basic sniff processor

func (BasicSniff) Process

func (p BasicSniff) Process(source *gopacket.PacketSource, hooks *Hooks) (func(), <-chan error)

Process implements Processor.Process interface

type CbCleanUp

type CbCleanUp func()

CbCleanUp defines callback for cleanups

type CbPacket

type CbPacket func(gopacket.Packet) (bool, *ProcessError)

CbPacket defines a callback on packet

type CbTick

type CbTick func(time.Time, time.Time)

CbTick defines callback for tick routines

type Hooks

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

Hooks is responsible for packet processor

func NewHooks

func NewHooks() *Hooks

NewHooks returns a new hooks collection

func (*Hooks) CleanUp

func (h *Hooks) CleanUp(fn CbCleanUp)

CleanUp adds a callback function when cleanup

func (*Hooks) OnPacket

func (h *Hooks) OnPacket(layer gopacket.LayerType, fn CbPacket)

OnPacket adds a callback function on new packet

func (*Hooks) OnTick

func (h *Hooks) OnTick(fn CbTick)

OnTick adds a callback function on each tick

type HooksRunner

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

HooksRunner executes Hooks

func NewHooksRunner

func NewHooksRunner(h *Hooks) *HooksRunner

NewHooksRunner returns a HooksRunner

func (*HooksRunner) CleanUp

func (h *HooksRunner) CleanUp() error

CleanUp executes cleanUp registered hooks.

func (*HooksRunner) Layers

func (h *HooksRunner) Layers() []gopacket.LayerType

Layers returns registered layers

func (*HooksRunner) OnPacket

func (h *HooksRunner) OnPacket(layer gopacket.LayerType, packet gopacket.Packet) (bool, []error)

OnPacket executes all registered onPacket hooks for the layerType passed in a secuencial way. If some of the hooks returns true, then the execution stops and returns true.

func (*HooksRunner) OnTick

func (h *HooksRunner) OnTick(lastTick, lastPacket time.Time) error

OnTick executes onTick registered hooks. It pass the last timestamp.

type Option

type Option func(*options)

Option is used for component configuration

func SetLogger

func SetLogger(l yalogi.Logger) Option

SetLogger option allows set a custom logger

type Plugin

type Plugin interface {
	Name() string
	RegisterHooks(*Hooks)
	CleanUp()
}

Plugin defines interface for plugins

type ProcessError

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

ProcessError is used for packet processing

func NewError

func NewError(packet gopacket.Packet, err string) *ProcessError

NewError creates a new packet processing error

func (*ProcessError) Error

func (e *ProcessError) Error() string

Error implements error interface

type Processor

type Processor interface {
	Process(source *gopacket.PacketSource, hooks *Hooks) (stop func(), errs <-chan error)
}

Processor process packets from a packet source

type Service

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

Service processor

func NewService

func NewService(p Processor, plugins []Plugin, opt ...Option) *Service

NewService creates a new service

func (*Service) Ping

func (s *Service) Ping() error

Ping returns true if errors

func (*Service) Register

func (s *Service) Register(name string, source *gopacket.PacketSource) error

Register packet source with name

func (*Service) Shutdown

func (s *Service) Shutdown()

Shutdown the service

func (*Service) Start

func (s *Service) Start() error

Start the service

func (*Service) Unregister

func (s *Service) Unregister(name string) error

Unregister packet source by name

Jump to

Keyboard shortcuts

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