socktest

Imports

Imports #

"syscall"
"internal/syscall/windows"
"syscall"
"fmt"
"sync"
"fmt"
"syscall"
"syscall"
"syscall"

Constants & Variables

FilterAccept const #

const FilterAccept

FilterClose const #

const FilterClose

FilterConnect const #

const FilterConnect

FilterGetsockoptInt const #

const FilterGetsockoptInt

FilterListen const #

const FilterListen

FilterSocket const #

const FilterSocket FilterType = iota

Type Aliases

AfterFilter type #

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 AfterFilter func(*Status) error

Filter type #

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 Filter func(*Status) (AfterFilter, error)

FilterType type #

A FilterType represents a filter type.

type FilterType int

Sockets type #

Sockets maps a socket descriptor to the status of socket.

type Sockets map[int]Status

Sockets type #

Sockets maps a socket descriptor to the status of socket.

type Sockets map[int]Status

Sockets type #

Sockets maps a socket descriptor to the status of socket.

type Sockets map[syscall.Handle]Status

stats type #

type stats map[Cookie]*Stat

Structs

Stat struct #

A Stat represents a per-cookie socket statistics.

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
}

Status struct #

A Status represents the status of a socket.

type Status struct {
Cookie Cookie
Err error
SocketErr error
}

Switch struct #

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

type Switch struct {
once sync.Once
fmu sync.RWMutex
fltab map[FilterType]Filter
smu sync.RWMutex
sotab Sockets
stats stats
}

Functions

Accept method #

Accept wraps syscall.Accept.

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

Accept4 method #

Accept4 wraps syscall.Accept4.

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

AcceptEx method #

AcceptEx wraps [syscall.AcceptEx].

func (sw *Switch) AcceptEx(ls syscall.Handle, as syscall.Handle, b *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, rcvd *uint32, overlapped *syscall.Overlapped) error

Close method #

Close wraps syscall.Close.

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

Closesocket method #

Closesocket wraps [syscall.Closesocket].

func (sw *Switch) Closesocket(s syscall.Handle) (err error)

Connect method #

Connect wraps syscall.Connect.

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

Connect method #

Connect wraps [syscall.Connect].

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

ConnectEx method #

ConnectEx wraps [syscall.ConnectEx].

func (sw *Switch) ConnectEx(s syscall.Handle, sa syscall.Sockaddr, b *byte, n uint32, nwr *uint32, o *syscall.Overlapped) (err error)

Family method #

Family returns an address family.

func (c Cookie) Family() int

GetsockoptInt method #

GetsockoptInt wraps syscall.GetsockoptInt.

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

Listen method #

Listen wraps syscall.Listen.

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

Listen method #

Listen wraps [syscall.Listen].

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

Protocol method #

Protocol returns a protocol number.

func (c Cookie) Protocol() int

Set method #

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

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

Socket method #

Socket wraps [syscall.Socket].

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

Sockets method #

Sockets returns mappings of socket descriptor to socket status.

func (sw *Switch) Sockets() Sockets

Stats method #

Stats returns a list of per-cookie socket statistics.

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

String method #

func (so Status) String() string

String method #

func (st Stat) String() string

Type method #

Type returns a socket type.

func (c Cookie) Type() int

WSASocket method #

WSASocket wraps [syscall.WSASocket].

func (sw *Switch) WSASocket(family int32, sotype int32, proto int32, protinfo *syscall.WSAProtocolInfo, group uint32, flags uint32) (s syscall.Handle, err error)

addLocked method #

addLocked returns a new Status without locking. sw.smu must be held before call.

func (sw *Switch) addLocked(s int, family int, sotype int, proto int) *Status

addLocked method #

addLocked returns a new Status without locking. sw.smu must be held before call.

func (sw *Switch) addLocked(s syscall.Handle, family int, sotype int, proto int) *Status

apply method #

func (f Filter) apply(st *Status) (AfterFilter, error)

apply method #

func (f AfterFilter) apply(st *Status) error

familyString function #

func familyString(family int) string

familyString function #

func familyString(family int) string

getLocked method #

func (st stats) getLocked(c Cookie) *Stat

init method #

func (sw *Switch) init()

protocolString function #

func protocolString(proto int) string

protocolString function #

func protocolString(proto int) string

sockso method #

func (sw *Switch) sockso(s int) *Status

sockso method #

func (sw *Switch) sockso(s syscall.Handle) *Status

typeString function #

func typeString(sotype int) string

typeString function #

func typeString(sotype int) string

Generated with Arrow