netapi

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBlockError added in v0.3.6

func IsBlockError(err error) bool

func LogLevel added in v0.3.6

func LogLevel(err error) slog.Level

Types

type Accepter added in v0.3.5

type Accepter interface{ Server }

type Address

type Address interface {
	// Hostname return hostname of address, eg: www.example.com, 127.0.0.1, ff::ff
	Hostname() string
	// Port return port of address
	Port() uint16
	// IsFqdn return true if address is FQDN
	// fqdn must impl [DomainAddress]
	// otherwise must impl [IPAddress]
	IsFqdn() bool
	Equal(Address) bool
	net.Addr
}
var EmptyAddr Address = &DomainAddr{hostname: unique.Make("")}

func ParseAddress

func ParseAddress(network string, addr string) (ad Address, _ error)

func ParseAddressPort

func ParseAddressPort(network string, addr string, port uint16) (ad Address)

func ParseDomainPort added in v0.3.5

func ParseDomainPort(network string, addr string, port uint16) (ad Address)

func ParseIPAddr

func ParseIPAddr(net string, ip net.IP, port uint16) Address

func ParseNetipAddr added in v0.3.7

func ParseNetipAddr(net string, ip netip.Addr, port uint16) Address

func ParseSysAddr

func ParseSysAddr(ad net.Addr) (Address, error)

type AddressNetwork added in v0.3.7

type AddressNetwork byte
const (
	Unknown AddressNetwork = iota
	TCP
	UDP
	IP
)

func ParseAddressNetwork added in v0.3.7

func ParseAddressNetwork(network string) AddressNetwork

func (AddressNetwork) Network added in v0.3.7

func (n AddressNetwork) Network() string

type ChannelStreamListener added in v0.3.6

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

func NewChannelStreamListener added in v0.3.6

func NewChannelStreamListener(addr net.Addr) *ChannelStreamListener

func (*ChannelStreamListener) Accept added in v0.3.6

func (c *ChannelStreamListener) Accept() (net.Conn, error)

func (*ChannelStreamListener) Addr added in v0.3.6

func (c *ChannelStreamListener) Addr() net.Addr

func (*ChannelStreamListener) Close added in v0.3.6

func (c *ChannelStreamListener) Close() error

func (*ChannelStreamListener) NewConn added in v0.3.6

func (c *ChannelStreamListener) NewConn(conn net.Conn)

type Context added in v0.3.6

type Context struct {
	Source      net.Addr `metrics:"Source"`
	Inbound     net.Addr `metrics:"Inbound"`
	Destination net.Addr `metrics:"Destination"`
	FakeIP      net.Addr `metrics:"FakeIP"`
	Hosts       net.Addr `metrics:"Hosts"`

	context.Context

	DomainString string `metrics:"DOMAIN"`
	IPString     string `metrics:"IP"`
	Tag          string `metrics:"Tag"`
	Hash         string `metrics:"Hash"`

	// sniffy
	Protocol      string `metrics:"Protocol"`
	Process       string `metrics:"Process"`
	TLSServerName string `metrics:"TLS Servername"`
	HTTPHost      string `metrics:"HTTP Host"`

	// dns resolver
	Component string `metrics:"Component"`

	Resolver ContextResolver `metrics:"-"`

	UDPMigrateID uint64 `metrics:"UDP MigrateID"`

	ForceMode  bypass.Mode `metrics:"-"`
	SniffMode  bypass.Mode `metrics:"-"`
	Mode       bypass.Mode `metrics:"MODE"`
	ModeReason string      `metrics:"MODE Reason"`
	SkipRoute  bool        `metrics:"-"`
}

func GetContext added in v0.3.6

func GetContext(ctx context.Context) *Context

func WithContext added in v0.3.6

func WithContext(ctx context.Context) *Context

func (*Context) Map added in v0.3.6

func (addr *Context) Map() map[string]string

func (*Context) SniffHost added in v0.3.6

func (c *Context) SniffHost() string

func (*Context) Value added in v0.3.6

func (c *Context) Value(key any) any

type ContextResolver added in v0.3.6

type ContextResolver struct {
	Resolver     Resolver
	ResolverSelf Resolver
	Mode         ResolverMode
	SkipResolve  bool `metrics:"-"`
	ForceFakeIP  bool `metrics:"-"`
}

func (ContextResolver) Opts added in v0.3.6

func (r ContextResolver) Opts(reverse bool) []func(*LookupIPOption)

type DNSRawRequest added in v0.3.6

type DNSRawRequest struct {
	WriteBack func([]byte) error
	Question  []byte
	Stream    bool
}

type DNSServer added in v0.3.5

type DNSServer interface {
	Server
	HandleUDP(context.Context, net.PacketConn) error
	HandleTCP(context.Context, net.Conn) error
	Do(context.Context, *DNSRawRequest) error
}
var EmptyDNSServer DNSServer = &emptyDNSServer{}

type DialError added in v0.3.7

type DialError struct {
	// Op is the operation which caused the error, such as
	// "read" or "write".
	Op string

	// Net is the network type on which this error occurred,
	// such as "tcp" or "udp6".
	Net string

	Sniff string

	// Addr is the network address for which this error occurred.
	// For local operations, like Listen or SetDeadline, Addr is
	// the address of the local endpoint being manipulated.
	// For operations involving a remote network connection, like
	// Dial, Read, or Write, Addr is the remote address of that
	// connection.
	Addr net.Addr

	// Err is the error that occurred during the operation.
	// The Error method panics if the error is nil.
	Err error
}

OpError is the error type usually returned by functions in the net package. It describes the operation, network type, and address of an error.

func NewDialError added in v0.3.7

func NewDialError(network string, err error, addr net.Addr) *DialError

func (*DialError) Error added in v0.3.7

func (e *DialError) Error() string

func (*DialError) Unwrap added in v0.3.7

func (e *DialError) Unwrap() error

type DomainAddr

type DomainAddr struct {
	AddressNetwork
	// contains filtered or unexported fields
}

func (*DomainAddr) Equal added in v0.3.7

func (d *DomainAddr) Equal(o Address) bool

func (*DomainAddr) Hostname

func (d *DomainAddr) Hostname() string

func (*DomainAddr) IsFqdn added in v0.3.4

func (d *DomainAddr) IsFqdn() bool

func (*DomainAddr) Port

func (d *DomainAddr) Port() uint16

func (*DomainAddr) String

func (d *DomainAddr) String() string

func (*DomainAddr) UniqueHostname added in v0.3.7

func (d *DomainAddr) UniqueHostname() unique.Handle[string]

type DomainAddress added in v0.3.7

type DomainAddress interface {
	Address
	UniqueHostname() unique.Handle[string]
}

type DynamicProxy

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

func NewDynamicProxy

func NewDynamicProxy(p Proxy) *DynamicProxy

func (*DynamicProxy) Conn

func (d *DynamicProxy) Conn(ctx context.Context, a Address) (net.Conn, error)

func (*DynamicProxy) Dispatch

func (d *DynamicProxy) Dispatch(ctx context.Context, a Address) (Address, error)

func (*DynamicProxy) PacketConn

func (d *DynamicProxy) PacketConn(ctx context.Context, a Address) (net.PacketConn, error)

func (*DynamicProxy) Set

func (d *DynamicProxy) Set(p Proxy)

type EmptyDispatch

type EmptyDispatch struct{}

func (EmptyDispatch) Dispatch

func (EmptyDispatch) Dispatch(_ context.Context, a Address) (Address, error)

type ErrorResolver

type ErrorResolver func(domain string) error

func (ErrorResolver) Close

func (e ErrorResolver) Close() error

func (ErrorResolver) LookupIP

func (e ErrorResolver) LookupIP(_ context.Context, domain string, opts ...func(*LookupIPOption)) ([]net.IP, error)

func (ErrorResolver) Raw

type Handler

type Handler interface {
	HandleStream(*StreamMeta)
	HandlePacket(*Packet)
}

type IPAddr added in v0.3.5

type IPAddr struct {
	Addr netip.Addr
	AddressNetwork
	// contains filtered or unexported fields
}

func (*IPAddr) Equal added in v0.3.7

func (d *IPAddr) Equal(o Address) bool

func (*IPAddr) Hostname added in v0.3.5

func (d *IPAddr) Hostname() string

func (*IPAddr) IP added in v0.3.5

func (d *IPAddr) IP() net.IP

func (*IPAddr) IsFqdn added in v0.3.5

func (d *IPAddr) IsFqdn() bool

func (*IPAddr) Port added in v0.3.5

func (d *IPAddr) Port() uint16

func (*IPAddr) String added in v0.3.5

func (d *IPAddr) String() string

func (*IPAddr) WithZone added in v0.3.6

func (d *IPAddr) WithZone(zone string)

type IPAddress added in v0.3.6

type IPAddress interface {
	Address
	IP() net.IP
	WithZone(zone string)
}

type Listener added in v0.3.3

type Listener interface {
	PacketListener
	StreamListener
	Server
}

func NewListener added in v0.3.6

func NewListener(s net.Listener, p PacketListener) Listener

type LogConn

type LogConn struct {
	net.Conn
}

func (*LogConn) Read

func (l *LogConn) Read(b []byte) (int, error)

func (*LogConn) SetDeadline

func (l *LogConn) SetDeadline(t time.Time) error

func (*LogConn) SetReadDeadline

func (l *LogConn) SetReadDeadline(t time.Time) error

func (*LogConn) SetWriteDeadline

func (l *LogConn) SetWriteDeadline(t time.Time) error

func (*LogConn) Write

func (l *LogConn) Write(b []byte) (int, error)

type LookupIPOption added in v0.3.4

type LookupIPOption struct {
	Mode ResolverMode
}

type Packet

type Packet struct {
	Src       net.Addr
	Dst       Address
	WriteBack WriteBack
	Payload   []byte
	MigrateID uint64
	// contains filtered or unexported fields
}

func (*Packet) DecRef added in v0.3.7

func (p *Packet) DecRef()

func (*Packet) IncRef added in v0.3.7

func (p *Packet) IncRef()

type PacketListener added in v0.3.6

type PacketListener interface {
	Server
	Packet(context.Context) (net.PacketConn, error)
}

type PacketProxy

type PacketProxy interface {
	PacketConn(context.Context, Address) (net.PacketConn, error)
}

type ProcessDumper added in v0.3.5

type ProcessDumper interface {
	ProcessName(network string, src, dst Address) (string, error)
}

type Proxy

type Proxy interface {
	StreamProxy
	PacketProxy
	Dispatch(context.Context, Address) (Address, error)
}

func NewErrProxy

func NewErrProxy(err error) Proxy

type Resolver

type Resolver interface {
	LookupIP(ctx context.Context, domain string, opts ...func(*LookupIPOption)) ([]net.IP, error)
	Raw(ctx context.Context, req dnsmessage.Question) (dnsmessage.Message, error)
	io.Closer
}

type ResolverMode added in v0.3.6

type ResolverMode int
const (
	ResolverModeNoSpecified ResolverMode = iota
	ResolverModePreferIPv6
	ResolverModePreferIPv4
)

type Server

type Server interface {
	io.Closer
}

type StreamListener added in v0.3.6

type StreamListener interface {
	Server
	Stream(context.Context) (net.Listener, error)
}

type StreamMeta

type StreamMeta struct {
	Source      net.Addr
	Destination net.Addr
	Inbound     net.Addr

	Src     net.Conn
	Address Address
}

type StreamProxy

type StreamProxy interface {
	Conn(context.Context, Address) (net.Conn, error)
}

type WriteBack added in v0.3.3

type WriteBack interface {
	WriteBack(b []byte, addr net.Addr) (int, error)
}

type WriteBackFunc added in v0.3.7

type WriteBackFunc func(b []byte, addr net.Addr) (int, error)

func (WriteBackFunc) WriteBack added in v0.3.7

func (f WriteBackFunc) WriteBack(b []byte, addr net.Addr) (int, error)

Jump to

Keyboard shortcuts

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