net

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NetbirdFwmark is the fwmark value used by Netbird via wireguard
	NetbirdFwmark = 0x1BD00

	PreroutingFwmarkRedirected       = 0x1BD01
	PreroutingFwmarkMasquerade       = 0x1BD11
	PreroutingFwmarkMasqueradeReturn = 0x1BD12
)

Variables

This section is empty.

Functions

func AddDialerCloseHook added in v0.27.0

func AddDialerCloseHook(hook DialerCloseHookFunc)

AddDialerCloseHook allows adding a new hook to be executed on connection close.

func AddDialerHook added in v0.27.0

func AddDialerHook(hook DialerDialHookFunc)

AddDialerHook allows adding a new hook to be executed before dialing.

func AddListenerCloseHook added in v0.27.0

func AddListenerCloseHook(hook ListenerCloseHookFunc)

AddListenerCloseHook allows adding a new hook to be executed upon closing a UDP connection.

func AddListenerWriteHook added in v0.27.0

func AddListenerWriteHook(hook ListenerWriteHookFunc)

AddListenerWriteHook allows adding a new write hook to be executed before a UDP packet is sent.

func CustomRoutingDisabled added in v0.27.3

func CustomRoutingDisabled() bool

func DialTCP

func DialTCP(network string, laddr, raddr *net.TCPAddr) (*net.TCPConn, error)

func DialUDP

func DialUDP(network string, laddr, raddr *net.UDPAddr) (*net.UDPConn, error)

func ListenUDP

func ListenUDP(network string, laddr *net.UDPAddr) (transport.UDPConn, error)

ListenUDP listens on the network address and returns a transport.UDPConn which includes support for write and close hooks.

func RemoveDialerHooks added in v0.27.0

func RemoveDialerHooks()

RemoveDialerHooks removes all dialer hooks.

func RemoveListenerHooks added in v0.27.0

func RemoveListenerHooks()

RemoveListenerHooks removes all dialer hooks.

func SetRawSocketMark

func SetRawSocketMark(conn syscall.RawConn) error

func SetSocketMark

func SetSocketMark(conn syscall.Conn) error

SetSocketMark sets the SO_MARK option on the given socket connection

func SetSocketOpt added in v0.27.3

func SetSocketOpt(fd int) error

Types

type AddHookFunc added in v0.28.0

type AddHookFunc func(connID ConnectionID, IP net.IP) error

type Conn added in v0.27.0

type Conn struct {
	net.Conn
	ID ConnectionID
}

Conn wraps a net.Conn to override the Close method

func (*Conn) Close added in v0.27.0

func (c *Conn) Close() error

Close overrides the net.Conn Close method to execute all registered hooks after closing the connection

type ConnectionID added in v0.27.0

type ConnectionID string

ConnectionID provides a globally unique identifier for network connections. It's used to track connections throughout their lifecycle so the close hook can correlate with the dial hook.

func GenerateConnID added in v0.27.0

func GenerateConnID() ConnectionID

GenerateConnID generates a unique identifier for each connection.

type Dialer added in v0.27.0

type Dialer struct {
	*net.Dialer
}

Dialer extends the standard net.Dialer with the ability to execute hooks before and after connections. This can be used to bypass the VPN for connections using this dialer.

func NewDialer

func NewDialer() *Dialer

NewDialer returns a customized net.Dialer with overridden Control method

func (*Dialer) Dial added in v0.27.0

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial wraps the net.Dialer's Dial method to use the custom connection

func (*Dialer) DialContext added in v0.27.0

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext wraps the net.Dialer's DialContext method to use the custom connection

type DialerCloseHookFunc added in v0.27.0

type DialerCloseHookFunc func(connID ConnectionID, conn *net.Conn) error

type DialerDialHookFunc added in v0.27.0

type DialerDialHookFunc func(ctx context.Context, connID ConnectionID, resolvedAddresses []net.IPAddr) error

type ListenerCloseHookFunc added in v0.27.0

type ListenerCloseHookFunc func(connID ConnectionID, conn net.PacketConn) error

ListenerCloseHookFunc defines the function signature for close hooks for PacketConn.

type ListenerConfig added in v0.27.0

type ListenerConfig struct {
	*net.ListenConfig
}

ListenerConfig extends the standard net.ListenConfig with the ability to execute hooks before responding via the socket and after closing. This can be used to bypass the VPN for listeners.

func NewListener

func NewListener() *ListenerConfig

NewListener creates a new ListenerConfig instance.

func (*ListenerConfig) ListenPacket added in v0.27.0

func (l *ListenerConfig) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)

ListenPacket listens on the network address and returns a PacketConn which includes support for write hooks.

type ListenerWriteHookFunc added in v0.27.0

type ListenerWriteHookFunc func(connID ConnectionID, ip *net.IPAddr, data []byte) error

ListenerWriteHookFunc defines the function signature for write hooks for PacketConn.

type PacketConn added in v0.27.0

type PacketConn struct {
	net.PacketConn
	ID ConnectionID
	// contains filtered or unexported fields
}

PacketConn wraps net.PacketConn to override its WriteTo and Close methods to include hook functionality.

func (*PacketConn) Close added in v0.27.0

func (c *PacketConn) Close() error

Close overrides the net.PacketConn Close method to execute all registered hooks before closing the connection.

func (*PacketConn) WriteTo added in v0.27.0

func (c *PacketConn) WriteTo(b []byte, addr net.Addr) (n int, err error)

WriteTo writes a packet with payload b to addr, executing registered write hooks beforehand.

type RemoveHookFunc added in v0.28.0

type RemoveHookFunc func(connID ConnectionID) error

type UDPConn added in v0.27.0

type UDPConn struct {
	*net.UDPConn
	ID ConnectionID
	// contains filtered or unexported fields
}

UDPConn wraps net.UDPConn to override its WriteTo and Close methods to include hook functionality.

func (*UDPConn) Close added in v0.27.0

func (c *UDPConn) Close() error

Close overrides the net.UDPConn Close method to execute all registered hooks before closing the connection.

func (*UDPConn) WriteTo added in v0.27.0

func (c *UDPConn) WriteTo(b []byte, addr net.Addr) (n int, err error)

WriteTo writes a packet with payload b to addr, executing registered write hooks beforehand.

Jump to

Keyboard shortcuts

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