capture

package
v0.0.0-...-9d29f1b Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package capture formats packet logging into a debug pcap stream.

Index

Constants

This section is empty.

Variables

View Source
var DissectorLua string

Functions

This section is empty.

Types

type Callback

type Callback func(Path, time.Time, []byte, packet.CaptureMeta)

Callback describes a function which is called to record packets when debugging packet-capture. Such callbacks must not take ownership of the provided data slice: it may only copy out of it within the lifetime of the function.

type Path

type Path uint8

Path describes where in the data path the packet was captured.

const (
	// FromLocal indicates the packet was logged as it traversed the FromLocal path:
	// i.e.: A packet from the local system into the TUN.
	FromLocal Path = 0
	// FromPeer indicates the packet was logged upon reception from a remote peer.
	FromPeer Path = 1
	// SynthesizedToLocal indicates the packet was generated from within tailscaled,
	// and is being routed to the local machine's network stack.
	SynthesizedToLocal Path = 2
	// SynthesizedToPeer indicates the packet was generated from within tailscaled,
	// and is being routed to a remote Wireguard peer.
	SynthesizedToPeer Path = 3

	// PathDisco indicates the packet is information about a disco frame.
	PathDisco Path = 254
)

Valid Path values.

type Sink

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

Type Sink handles callbacks with packets to be logged, formatting them into a pcap stream which is mirrored to all registered outputs.

func New

func New() *Sink

New creates a new capture sink.

func (*Sink) Close

func (s *Sink) Close() error

Close shuts down the sink. Future calls to LogPacket are ignored, and any registered output that implements io.Closer is closed.

func (*Sink) LogPacket

func (s *Sink) LogPacket(path Path, when time.Time, data []byte, meta packet.CaptureMeta)

LogPacket is called to insert a packet into the capture.

This function does not take ownership of the provided data slice.

func (*Sink) NumOutputs

func (s *Sink) NumOutputs() int

NumOutputs returns the number of outputs registered with the sink.

func (*Sink) RegisterOutput

func (s *Sink) RegisterOutput(w io.Writer) (unregister func())

RegisterOutput connects an output to this sink, which will be written to with a pcap stream as packets are logged. A function is returned which unregisters the output when called.

If w implements io.Closer, it will be closed upon error or when the sink is closed. If w implements http.Flusher, it will be flushed periodically.

func (*Sink) WaitCh

func (s *Sink) WaitCh() <-chan struct{}

WaitCh returns a channel which blocks until the sink is closed.

Jump to

Keyboard shortcuts

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