socktest

package
v1.21.6 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package socktest provides utilities for socket testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfterFilter

type AfterFilter func(*Status) error

An AfterFilter represents a socket system call filter after an execution of a system call.

It will only be executed after a system call for a socket that has an entry in internal table. If the filter returns a non-nil error, the system call function returns the non-nil error.

type Cookie uint64

A Cookie represents a 3-tuple of a socket; address family, socket type and protocol number.

func (Cookie) Family

func (c Cookie) Family() int

Family returns an address family.

func (Cookie) Protocol

func (c Cookie) Protocol() int

Protocol returns a protocol number.

func (Cookie) Type

func (c Cookie) Type() int

Type returns a socket type.

type Filter

type Filter func(*Status) (AfterFilter, error)

A Filter represents a socket system call filter.

It will only be executed before a system call for a socket that has an entry in internal table. If the filter returns a non-nil error, the execution of system call will be canceled and the system call function returns the non-nil error. It can return a non-nil AfterFilter for filtering after the execution of the system call.

type FilterType

type FilterType int

A FilterType represents a filter type.

const (
	FilterSocket FilterType = iota
	FilterConnect
	FilterListen
	FilterAccept
	FilterGetsockoptInt
	FilterClose
)

type Sockets

type Sockets map[int]Status

Sockets maps a socket descriptor to the status of socket.

type Stat

type Stat struct {
	Family   int
	Type     int
	Protocol int

	Opened    uint64
	Connected uint64
	Listened  uint64
	Accepted  uint64
	Closed    uint64

	OpenFailed    uint64
	ConnectFailed uint64
	ListenFailed  uint64
	AcceptFailed  uint64
	CloseFailed   uint64
}

A Stat represents a per-cookie socket statistics.

func (Stat) String

func (st Stat) String() string

type Status

type Status struct {
	Cookie    Cookie
	Err       error
	SocketErr error
}

A Status represents the status of a socket.

func (Status) String

func (so Status) String() string

type Switch

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

A Switch represents a callpath point switch for socket system calls.

func (*Switch) Accept

func (sw *Switch) Accept(s int) (ns int, sa syscall.Sockaddr, err error)

Accept wraps syscall.Accept.

func (*Switch) Accept4

func (sw *Switch) Accept4(s, flags int) (ns int, sa syscall.Sockaddr, err error)

Accept4 wraps syscall.Accept4.

func (*Switch) Close

func (sw *Switch) Close(s int) (err error)

Close wraps syscall.Close.

func (*Switch) Connect

func (sw *Switch) Connect(s int, sa syscall.Sockaddr) (err error)

Connect wraps syscall.Connect.

func (*Switch) GetsockoptInt

func (sw *Switch) GetsockoptInt(s, level, opt int) (soerr int, err error)

GetsockoptInt wraps syscall.GetsockoptInt.

func (*Switch) Listen

func (sw *Switch) Listen(s, backlog int) (err error)

Listen wraps syscall.Listen.

func (*Switch) Set

func (sw *Switch) Set(t FilterType, f Filter)

Set deploys the socket system call filter f for the filter type t.

func (*Switch) Socket

func (sw *Switch) Socket(family, sotype, proto int) (s int, err error)

Socket wraps syscall.Socket.

func (*Switch) Sockets

func (sw *Switch) Sockets() Sockets

Sockets returns mappings of socket descriptor to socket status.

func (*Switch) Stats

func (sw *Switch) Stats() []Stat

Stats returns a list of per-cookie socket statistics.

Jump to

Keyboard shortcuts

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