Imports #
"syscall"
"internal/syscall/windows"
"syscall"
"fmt"
"sync"
"fmt"
"syscall"
"syscall"
"syscall"
"syscall"
"internal/syscall/windows"
"syscall"
"fmt"
"sync"
"fmt"
"syscall"
"syscall"
"syscall"
const FilterAccept
const FilterClose
const FilterConnect
const FilterGetsockoptInt
const FilterListen
const FilterSocket FilterType = iota
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
A Cookie represents a 3-tuple of a socket; address family, socket type and protocol number.
type Cookie uint64
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)
A FilterType represents a filter type.
type FilterType int
Sockets maps a socket descriptor to the status of socket.
type Sockets map[int]Status
Sockets maps a socket descriptor to the status of socket.
type Sockets map[int]Status
Sockets maps a socket descriptor to the status of socket.
type Sockets map[syscall.Handle]Status
type stats map[Cookie]*Stat
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
}
A Status represents the status of a socket.
type Status struct {
Cookie Cookie
Err error
SocketErr error
}
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
}
Accept wraps syscall.Accept.
func (sw *Switch) Accept(s int) (ns int, sa syscall.Sockaddr, err error)
Accept4 wraps syscall.Accept4.
func (sw *Switch) Accept4(s int, flags int) (ns int, sa syscall.Sockaddr, err error)
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 wraps syscall.Close.
func (sw *Switch) Close(s int) (err error)
Closesocket wraps [syscall.Closesocket].
func (sw *Switch) Closesocket(s syscall.Handle) (err error)
Connect wraps syscall.Connect.
func (sw *Switch) Connect(s int, sa syscall.Sockaddr) (err error)
Connect wraps [syscall.Connect].
func (sw *Switch) Connect(s syscall.Handle, sa syscall.Sockaddr) (err error)
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 returns an address family.
func (c Cookie) Family() int
GetsockoptInt wraps syscall.GetsockoptInt.
func (sw *Switch) GetsockoptInt(s int, level int, opt int) (soerr int, err error)
Listen wraps syscall.Listen.
func (sw *Switch) Listen(s int, backlog int) (err error)
Listen wraps [syscall.Listen].
func (sw *Switch) Listen(s syscall.Handle, backlog int) (err error)
Protocol returns a protocol number.
func (c Cookie) Protocol() int
Set deploys the socket system call filter f for the filter type t.
func (sw *Switch) Set(t FilterType, f Filter)
Socket wraps [syscall.Socket].
func (sw *Switch) Socket(family int, sotype int, proto int) (s int, err error)
Sockets returns mappings of socket descriptor to socket status.
func (sw *Switch) Sockets() Sockets
Stats returns a list of per-cookie socket statistics.
func (sw *Switch) Stats() []Stat
func (so Status) String() string
func (st Stat) String() string
Type returns a socket type.
func (c Cookie) Type() int
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 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 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
func (f Filter) apply(st *Status) (AfterFilter, error)
func (f AfterFilter) apply(st *Status) error
func cookie(family int, sotype int, proto int) Cookie
func familyString(family int) string
func familyString(family int) string
func (st stats) getLocked(c Cookie) *Stat
func (sw *Switch) init()
func protocolString(proto int) string
func protocolString(proto int) string
func (sw *Switch) sockso(s int) *Status
func (sw *Switch) sockso(s syscall.Handle) *Status
func typeString(sotype int) string
func typeString(sotype int) string
Generated with Arrow