pcap

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Goroutinewg *sync.WaitGroup
View Source
var OpsChan chan gowid.RunFunction

Functions

func CanRestart

func CanRestart(src IPacketSource) bool

func HandleBegin

func HandleBegin(code HandlerCode, app gowid.IApp, cb interface{}) bool

func HandleEnd

func HandleEnd(code HandlerCode, app gowid.IApp, cb interface{}) bool

func HandleError

func HandleError(code HandlerCode, app gowid.IApp, err error, cb interface{}) bool

func HandleUnpack

func HandleUnpack(code HandlerCode, cb interface{}, handler unpackedHandlerFunc, app gowid.IApp) bool

func MakeUsefulError

func MakeUsefulError(cmd IBasicCommand, err error) gowid.KeyValueError

func SnappyMe

func SnappyMe(p interface{}, w io.Writer)

SnappyMe compresses the object within interface p to the writer w.

func SourcesNames

func SourcesNames(srcs []IPacketSource) []string

func SourcesString

func SourcesString(srcs []IPacketSource) string

func UIName

func UIName(src IPacketSource) string

func UnsnappyMe

func UnsnappyMe(res interface{}, r io.Reader)

UnsnappyMe decompresses from reader r into res. Afterwards, res will be an interface whose type is a pointer to whatever was serialized in the first place.

Types

type CacheEntry

type CacheEntry struct {
	Pdml         []IPdmlPacket
	Pcap         [][]byte
	PdmlComplete bool
	PcapComplete bool
}

func (CacheEntry) Complete

func (c CacheEntry) Complete() bool

type Command

type Command struct {
	sync.Mutex
	*exec.Cmd
	// contains filtered or unexported fields
}

func (*Command) Close

func (c *Command) Close() error

If stdout supports Close(), call it. If stdout is a pipe, for example, this can be used to have EOF appear on the reading side (e.g. tshark -T psml)

func (*Command) Kill

func (c *Command) Kill() error

func (*Command) Pid

func (c *Command) Pid() int

func (*Command) PutInNewGroupOnUnix

func (c *Command) PutInNewGroupOnUnix()

func (*Command) SetStdout

func (c *Command) SetStdout(w io.Writer)

func (*Command) Start

func (c *Command) Start() error

func (*Command) StderrSummary

func (c *Command) StderrSummary() []string

func (*Command) StdoutReader

func (c *Command) StdoutReader() (io.ReadCloser, error)

func (*Command) String

func (c *Command) String() string

func (*Command) Wait

func (c *Command) Wait() error

type Commands

type Commands struct {
	DecodeAs []string
	Args     []string
	PdmlArgs []string
	PsmlArgs []string
	Color    bool
}

func MakeCommands

func MakeCommands(decodeAs []string, args []string, pdml []string, psml []string, color bool) Commands

func (Commands) Iface

func (c Commands) Iface(ifaces []string, captureFilter string, tmpfile string) IBasicCommand

func (Commands) Pcap

func (c Commands) Pcap(pcap string, displayFilter string) IPcapCommand

func (Commands) Pdml

func (c Commands) Pdml(pcap string, displayFilter string) IPcapCommand

func (Commands) Psml

func (c Commands) Psml(pcap interface{}, displayFilter string) IPcapCommand

func (Commands) Tail

func (c Commands) Tail(tmpfile string) ITailCommand

type FifoSource

type FifoSource struct {
	Filename string
}

func (FifoSource) IsFifo

func (p FifoSource) IsFifo() bool

func (FifoSource) IsFile

func (p FifoSource) IsFile() bool

func (FifoSource) IsInterface

func (p FifoSource) IsInterface() bool

func (FifoSource) IsPipe

func (p FifoSource) IsPipe() bool

func (FifoSource) Name

func (p FifoSource) Name() string

func (FifoSource) String

func (p FifoSource) String() string

type FileSource

type FileSource struct {
	Filename string
}

func (FileSource) IsFifo

func (p FileSource) IsFifo() bool

func (FileSource) IsFile

func (p FileSource) IsFile() bool

func (FileSource) IsInterface

func (p FileSource) IsInterface() bool

func (FileSource) IsPipe

func (p FileSource) IsPipe() bool

func (FileSource) Name

func (p FileSource) Name() string

func (FileSource) String

func (p FileSource) String() string

type GzippedPdmlPacket

type GzippedPdmlPacket struct {
	Data bytes.Buffer
}

func (GzippedPdmlPacket) Packet

func (p GzippedPdmlPacket) Packet() PdmlPacket

func (GzippedPdmlPacket) Uncompress

func (p GzippedPdmlPacket) Uncompress() PdmlPacket

type HandlerCode

type HandlerCode int
const (
	NoneCode HandlerCode = 1 << iota
	PdmlCode
	PsmlCode
	TailCode
	IfaceCode
	ConvCode
	StreamCode
	CapinfoCode
)

type HandlerList

type HandlerList []interface{}

func (HandlerList) Unpack

func (h HandlerList) Unpack() []interface{}

type IAfterEnd

type IAfterEnd interface {
	AfterEnd(code HandlerCode, app gowid.IApp)
}

type IBasicCommand

type IBasicCommand interface {
	fmt.Stringer
	Start() error
	Wait() error
	Pid() int
	Kill() error
	StderrSummary() []string
}

type IBeforeBegin

type IBeforeBegin interface {
	BeforeBegin(code HandlerCode, app gowid.IApp)
}

type IClear

type IClear interface {
	OnClear(code HandlerCode, app gowid.IApp)
}

type ILoaderCmds

type ILoaderCmds interface {
	Iface(ifaces []string, captureFilter string, tmpfile string) IBasicCommand
	Tail(tmpfile string) ITailCommand
	Psml(pcap interface{}, displayFilter string) IPcapCommand
	Pcap(pcap string, displayFilter string) IPcapCommand
	Pdml(pcap string, displayFilter string) IPcapCommand
}
var PcapCmds ILoaderCmds

type IMainRunner

type IMainRunner interface {
	Run(fn gowid.RunFunction)
}

IMainRunner is implemented by a type that runs a closure on termshark's main loop (via gowid's App.Run)

type INewSource

type INewSource interface {
	OnNewSource(code HandlerCode, app gowid.IApp)
}

type IOnError

type IOnError interface {
	OnError(code HandlerCode, app gowid.IApp, err error)
}

type IPacketSource

type IPacketSource interface {
	Name() string
	IsFile() bool
	IsInterface() bool
	IsFifo() bool
	IsPipe() bool
}

func FileSystemSources

func FileSystemSources(srcs []IPacketSource) []IPacketSource

type IPcapCommand

type IPcapCommand interface {
	IBasicCommand
	StdoutReader() (io.ReadCloser, error) // termshark will .Read() from result
}

type IPdmlPacket

type IPdmlPacket interface {
	Packet() PdmlPacket
}

func GzipPdmlPacket

func GzipPdmlPacket(p PdmlPacket) IPdmlPacket

func SnappyPdmlPacket

func SnappyPdmlPacket(p PdmlPacket) IPdmlPacket

type IPsmlHeader

type IPsmlHeader interface {
	OnPsmlHeader(code HandlerCode, app gowid.IApp)
}

type ISourceRemover

type ISourceRemover interface {
	Remove() error
}

type ITailCommand

type ITailCommand interface {
	IBasicCommand
	SetStdout(io.Writer) // set to the write side of a fifo, for example - the command will .Write() here
	Close() error        // closes stdout, which signals tshark -T psml
}

type IUnpack

type IUnpack interface {
	Unpack() []interface{}
}

type InterfaceLoader

type InterfaceLoader struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*InterfaceLoader) IsLoading

func (c *InterfaceLoader) IsLoading() bool

type InterfaceSource

type InterfaceSource struct {
	Iface string
}

func (InterfaceSource) IsFifo

func (p InterfaceSource) IsFifo() bool

func (InterfaceSource) IsFile

func (p InterfaceSource) IsFile() bool

func (InterfaceSource) IsInterface

func (p InterfaceSource) IsInterface() bool

func (InterfaceSource) IsPipe

func (p InterfaceSource) IsPipe() bool

func (InterfaceSource) Name

func (p InterfaceSource) Name() string

func (InterfaceSource) String

func (p InterfaceSource) String() string

type LoadPcapSlice

type LoadPcapSlice struct {
	Row           int
	CancelCurrent bool
	Jump          int // 0 means no jump
}

func ProcessPdmlRequests

func ProcessPdmlRequests(requests []LoadPcapSlice, mloader *ParentLoader,
	loader *PdmlLoader, cb interface{}, app gowid.IApp) []LoadPcapSlice

func (LoadPcapSlice) String

func (m LoadPcapSlice) String() string

type LoaderState

type LoaderState bool
const (
	NotLoading LoaderState = false
	Loading    LoaderState = true
)

func (LoaderState) String

func (t LoaderState) String() string

type Options

type Options struct {
	CacheSize      int
	PacketsPerLoad int
}
var PcapOpts Options

type PacketColors

type PacketColors struct {
	FG gowid.IColor
	BG gowid.IColor
}

type PacketLoader

type PacketLoader struct {
	*ParentLoader
}

PacketLoader supports swapping out loaders

func (*PacketLoader) ClearPcap

func (c *PacketLoader) ClearPcap(cb interface{})

Intended to restart iface loader - since a clear will discard all data up to here.

func (*PacketLoader) LoadInterfaces

func (c *PacketLoader) LoadInterfaces(psrcs []IPacketSource, captureFilter string, displayFilter string, tmpfile string, cb interface{}, app gowid.IApp) error

Always called from app goroutine context - so don't need to protect for race on cancelfn Assumes gstate is ready iface can be a number, or a fifo, or a pipe...

func (*PacketLoader) LoadPcap

func (c *PacketLoader) LoadPcap(pcap string, displayFilter string, cb interface{}, app gowid.IApp)

func (*PacketLoader) Reload

func (c *PacketLoader) Reload(filter string, cb interface{}, app gowid.IApp)

func (*PacketLoader) Renew

func (c *PacketLoader) Renew()

Renew is called when a new pcap is loaded from an open termshark session i.e. termshark was started with one packet source, then a new one is selected. This ensures that all connected loaders that might still be doing work are cancelled.

type ParentLoader

type ParentLoader struct {
	// Note that a nil InterfaceLoader implies this loader is not handling a "live" packet source
	*InterfaceLoader // these are only replaced from the main goroutine, so no lock needed
	*PsmlLoader
	*PdmlLoader
	// contains filtered or unexported fields
}

func NewPcapLoader

func NewPcapLoader(cmds ILoaderCmds, runner IMainRunner, opts ...Options) *ParentLoader

func (*ParentLoader) CaptureFilter

func (p *ParentLoader) CaptureFilter() string

func (*ParentLoader) CloseMain

func (c *ParentLoader) CloseMain()

CloseMain shuts down the whole loader, including progress monitoring goroutines. Use this only when about to load a new pcap (use a new loader)

func (*ParentLoader) Commands

func (p *ParentLoader) Commands() ILoaderCmds

func (*ParentLoader) Context

func (p *ParentLoader) Context() context.Context

func (*ParentLoader) DisplayFilter

func (p *ParentLoader) DisplayFilter() string

func (*ParentLoader) Empty

func (c *ParentLoader) Empty() bool

func (*ParentLoader) InterfaceFile

func (p *ParentLoader) InterfaceFile() string

func (*ParentLoader) Interfaces

func (c *ParentLoader) Interfaces() []string

func (*ParentLoader) LoadWasCancelled

func (p *ParentLoader) LoadWasCancelled() bool

func (*ParentLoader) LoadingAnything

func (p *ParentLoader) LoadingAnything() bool

func (*ParentLoader) MainRun

func (p *ParentLoader) MainRun(fn gowid.RunFunction)

func (*ParentLoader) PacketSources

func (p *ParentLoader) PacketSources() []IPacketSource

func (*ParentLoader) Pcap

func (c *ParentLoader) Pcap() string

func (*ParentLoader) PsmlStoppedDeliberately

func (p *ParentLoader) PsmlStoppedDeliberately() bool

func (*ParentLoader) RenewIfaceLoader

func (c *ParentLoader) RenewIfaceLoader()

func (*ParentLoader) RenewPdmlLoader

func (c *ParentLoader) RenewPdmlLoader()

func (*ParentLoader) RenewPsmlLoader

func (c *ParentLoader) RenewPsmlLoader()

func (*ParentLoader) StopLoadPsmlAndIface

func (c *ParentLoader) StopLoadPsmlAndIface(cb interface{})

func (*ParentLoader) String

func (c *ParentLoader) String() string

func (*ParentLoader) TailStoppedDeliberately

func (p *ParentLoader) TailStoppedDeliberately() bool

func (*ParentLoader) TurnOffPipe

func (p *ParentLoader) TurnOffPipe()

type PdmlLoader

type PdmlLoader struct {
	PcapPdml string // Pcap file source for the pdml reader - tmpfile if iface; pcap otherwise
	PcapPcap string // Pcap file source for the pcap reader - tmpfile if iface; pcap otherwise

	Stage2FinishedChan chan struct{} // closed when entire pdml+pcap load process is done

	PdmlPid int // 0 if process not started
	PcapPid int // 0 if process not started

	sync.Mutex

	KillAfterReadingThisMany int // A shortcut - tell pcap/pdml to read one - no lock worked out yet
	// contains filtered or unexported fields
}

func (*PdmlLoader) IsLoading

func (c *PdmlLoader) IsLoading() bool

func (*PdmlLoader) LoadIsVisible

func (c *PdmlLoader) LoadIsVisible() bool

func (*PdmlLoader) LoadingRow

func (c *PdmlLoader) LoadingRow() int

Only call from main goroutine

type PdmlPacket

type PdmlPacket struct {
	XMLName xml.Name `xml:"packet"`
	Content []byte   `xml:",innerxml"`
}

func (PdmlPacket) Packet

func (p PdmlPacket) Packet() PdmlPacket

type PipeSource

type PipeSource struct {
	Descriptor string
	Fd         int
}

func (PipeSource) Close

func (p PipeSource) Close() error

func (PipeSource) IsFifo

func (p PipeSource) IsFifo() bool

func (PipeSource) IsFile

func (p PipeSource) IsFile() bool

func (PipeSource) IsInterface

func (p PipeSource) IsInterface() bool

func (PipeSource) IsPipe

func (p PipeSource) IsPipe() bool

func (PipeSource) Name

func (p PipeSource) Name() string

func (PipeSource) String

func (p PipeSource) String() string

type ProcessNotStarted

type ProcessNotStarted struct {
	Command *exec.Cmd
}

func (ProcessNotStarted) Error

func (e ProcessNotStarted) Error() string

type ProcessState

type ProcessState int
const (
	NotStarted ProcessState = 0
	Started    ProcessState = 1
	Terminated ProcessState = 2
)

func (ProcessState) String

func (p ProcessState) String() string

type PsmlLoader

type PsmlLoader struct {
	PcapPsml interface{} // Pcap file source for the psml reader - fifo if iface+!stopped; tmpfile if iface+stopped; pcap otherwise

	PsmlFinishedChan chan struct{} // closed when entire psml load process is done

	PsmlCmd IPcapCommand // gcla later todo - change to pid like PdmlPid

	sync.Mutex

	PacketNumberMap map[int]int // map from actual packet row <packet>12</packet> to pos in unsorted table
	// This would be affected by a display filter e.g. packet 12 might be the 1st packet in the table.
	// I need this so that if the user jumps to a mark stored as "packet 12", I can find the right table row.
	PacketNumberOrder map[int]int // e.g. {12->44, 44->71, 71->72,...} - the packet numbers, in order, affected by a filter.

	PacketCache *lru.Cache // i -> [pdml(i * 1000)..pdml(i+1*1000)] - accessed from any goroutine
	// contains filtered or unexported fields
}

func (*PsmlLoader) CacheAt

func (c *PsmlLoader) CacheAt(row int) (CacheEntry, bool)

func (*PsmlLoader) DoWithPsmlData

func (c *PsmlLoader) DoWithPsmlData(fn func([][]string))

func (*PsmlLoader) IsLoading

func (c *PsmlLoader) IsLoading() bool

func (*PsmlLoader) LengthOfPcapCacheEntry

func (p *PsmlLoader) LengthOfPcapCacheEntry(row int) (int, error)

func (*PsmlLoader) LengthOfPdmlCacheEntry

func (p *PsmlLoader) LengthOfPdmlCacheEntry(row int) (int, error)

func (*PsmlLoader) NumLoaded

func (c *PsmlLoader) NumLoaded() int

func (*PsmlLoader) PacketCacheFn

func (c *PsmlLoader) PacketCacheFn() *lru.Cache

func (*PsmlLoader) PacketsPerLoad

func (p *PsmlLoader) PacketsPerLoad() int

func (*PsmlLoader) PsmlAverageLengths

func (p *PsmlLoader) PsmlAverageLengths() []gwutil.IntOption

func (*PsmlLoader) PsmlColors

func (p *PsmlLoader) PsmlColors() []PacketColors

func (*PsmlLoader) PsmlData

func (p *PsmlLoader) PsmlData() [][]string

func (*PsmlLoader) PsmlHeaders

func (p *PsmlLoader) PsmlHeaders() []string

func (*PsmlLoader) PsmlMaxLengths

func (p *PsmlLoader) PsmlMaxLengths() []int

func (*PsmlLoader) ReadingFromFifo

func (c *PsmlLoader) ReadingFromFifo() bool

func (*PsmlLoader) StartStage2ChanFn

func (c *PsmlLoader) StartStage2ChanFn() chan struct{}

type RunFn

type RunFn func()

type Runner

type Runner struct {
	gowid.IApp
}

func (*Runner) Run

func (a *Runner) Run(fn gowid.RunFunction)

type SnappiedPdmlPacket

type SnappiedPdmlPacket struct {
	Data bytes.Buffer
}

func (SnappiedPdmlPacket) Packet

func (p SnappiedPdmlPacket) Packet() PdmlPacket

func (SnappiedPdmlPacket) Uncompress

func (p SnappiedPdmlPacket) Uncompress() PdmlPacket

type TemporaryFileSource

type TemporaryFileSource struct {
	FileSource
}

func (TemporaryFileSource) Remove

func (p TemporaryFileSource) Remove() error

func (TemporaryFileSource) String

func (p TemporaryFileSource) String() string

Jump to

Keyboard shortcuts

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