tracer

package
v0.0.0-...-d3e8d28 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2019 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotImplemented = errors.New("BPF-based network tracing not implemented on non-linux systems")
)

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func CurrentKernelVersion

func CurrentKernelVersion() (uint32, error)

func IsTracerSupportedByOS

func IsTracerSupportedByOS() (bool, error)

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type BPFMapName

type BPFMapName string
const (
	UDPv4Map           BPFMapName = "udp_stats_ipv4"
	UDPv6Map           BPFMapName = "udp_stats_ipv6"
	TCPv4Map           BPFMapName = "tcp_stats_ipv4"
	TCPv6Map           BPFMapName = "tcp_stats_ipv6"
	LatestTimestampMap BPFMapName = "latest_ts"
	TCPTracerStatusMap BPFMapName = "tcptracer_status"
)

type Callback

type Callback interface {
	LostV4(uint64)
	LostV6(uint64)
}

type Config

type Config struct {
	// CollectTCPConns specifies whether the tracer should collect traffic statistics for TCP connections
	CollectTCPConns bool

	// CollectUDPConns specifies whether the tracer should collect traffic statistics for UDP connections
	CollectUDPConns bool

	// CollectIPv6Conns specifics whether the tracer should capture traffic for IPv6 TCP/UDP connections
	CollectIPv6Conns bool

	// UDPConnTimeout determines the length of traffic inactivity between two (IP, port)-pairs before declaring a UDP
	// connection as inactive.
	// Note: As UDP traffic is technically "connection-less", for tracking, we consider a UDP connection to be traffic
	//       between a source and destination IP and port.
	UDPConnTimeout time.Duration

	// TCPConnTimeout is like UDPConnTimeout, but for TCP connections. TCP connections are cleared when
	// the BPF module receives a tcp_close call, but TCP connections also age out to catch cases where
	// tcp_close is not intercepted for some reason.
	TCPConnTimeout time.Duration
}

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig enables traffic collection for all connection types

func (*Config) EnabledKProbes

func (c *Config) EnabledKProbes() map[KProbeName]struct{}

EnabledKProbes returns a map of kprobes that are enabled per config settings

type ConnectionFamily

type ConnectionFamily uint8
const (
	AF_INET  ConnectionFamily = 0
	AF_INET6 ConnectionFamily = 1
)

type ConnectionStats

type ConnectionStats struct {
	Pid    uint32           `json:"pid"`
	Type   ConnectionType   `json:"type"`
	Family ConnectionFamily `json:"family"`

	// Source & Dest represented as a string to handle both IPv4 & IPv6
	Source string `json:"source"`
	Dest   string `json:"dest"`
	SPort  uint16 `json:"sport"`
	DPort  uint16 `json:"dport"`

	SendBytes uint64 `json:"send_bytes"`
	RecvBytes uint64 `json:"recv_bytes"`
}

func (ConnectionStats) ByteKey

func (c ConnectionStats) ByteKey(buffer *bytes.Buffer) ([]byte, error)

func (ConnectionStats) MarshalEasyJSON

func (v ConnectionStats) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ConnectionStats) MarshalJSON

func (v ConnectionStats) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (ConnectionStats) String

func (c ConnectionStats) String() string

func (*ConnectionStats) UnmarshalEasyJSON

func (v *ConnectionStats) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ConnectionStats) UnmarshalJSON

func (v *ConnectionStats) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ConnectionType

type ConnectionType uint8
const (
	TCP ConnectionType = 0
	UDP ConnectionType = 1
)

func (ConnectionType) String

func (c ConnectionType) String() string

type Connections

type Connections struct {
	Conns []ConnectionStats `json:"connections"`
}

func (Connections) MarshalEasyJSON

func (v Connections) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Connections) MarshalJSON

func (v Connections) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Connections) UnmarshalEasyJSON

func (v *Connections) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Connections) UnmarshalJSON

func (v *Connections) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type KProbeName

type KProbeName string
const (
	TCPv4Connect       KProbeName = "kprobe/tcp_v4_connect"
	TCPv4ConnectReturn KProbeName = "kretprobe/tcp_v4_connect"
	TCPv6Connect       KProbeName = "kprobe/tcp_v6_connect"
	TCPv6ConnectReturn KProbeName = "kretprobe/tcp_v6_connect"

	TCPSendMsg     KProbeName = "kprobe/tcp_sendmsg"
	TCPCleanupRBuf KProbeName = "kprobe/tcp_cleanup_rbuf"
	TCPClose       KProbeName = "kprobe/tcp_close"

	UDPSendMsg       KProbeName = "kprobe/udp_sendmsg"
	UDPRecvMsg       KProbeName = "kprobe/udp_recvmsg"
	UDPRecvMsgReturn KProbeName = "kretprobe/udp_recvmsg"
)

type Tracer

type Tracer struct{}

func NewEventTracer

func NewEventTracer(cb Callback) (*Tracer, error)

func NewTracer

func NewTracer(config *Config) (*Tracer, error)

func (*Tracer) GetActiveConnections

func (t *Tracer) GetActiveConnections() (*Connections, error)

func (*Tracer) Start

func (t *Tracer) Start()

func (*Tracer) Stop

func (t *Tracer) Stop()

Jump to

Keyboard shortcuts

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