router

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainA3yTunRules utiliptables.Chain = "A3Y-TUN-RULES"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MockRouter

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

MockRouter implements the Router interface for testing purposes.

func NewMockRouter

func NewMockRouter() *MockRouter

NewMockRouter creates a new MockRouter for testing.

func (*MockRouter) AddPeer

func (m *MockRouter) AddPeer(peer netip.Prefix, conn connection.Connection) (netip.Addr, []netip.Prefix, error)

AddPeer adds a peer route to the tunnel.

func (*MockRouter) Close

func (m *MockRouter) Close() error

Close releases any resources associated with the router.

func (*MockRouter) GetMuxedConnection

func (m *MockRouter) GetMuxedConnection() *connection.MuxedConnection

GetMuxedConnection returns the muxed connection for testing.

func (*MockRouter) GetRoutes

func (m *MockRouter) GetRoutes() []netip.Prefix

GetRoutes returns all routes currently added to the router.

func (*MockRouter) RemovePeer

func (m *MockRouter) RemovePeer(peer netip.Prefix) error

RemovePeer removes a peer route from the tunnel.

func (*MockRouter) SetAddPeerError

func (m *MockRouter) SetAddPeerError(err error)

SetAddPeerError sets the error that will be returned by AddPeer.

func (*MockRouter) SetCloseError

func (m *MockRouter) SetCloseError(err error)

SetCloseError sets the error that will be returned by Close.

func (*MockRouter) SetGetTunnelDeviceError

func (m *MockRouter) SetGetTunnelDeviceError(err error)

SetGetTunnelDeviceError sets the error that will be returned by GetTunnelDevice.

func (*MockRouter) SetRemovePeerError

func (m *MockRouter) SetRemovePeerError(err error)

SetRemovePeerError sets the error that will be returned by RemovePeer.

func (*MockRouter) SetStartError

func (m *MockRouter) SetStartError(err error)

SetStartError sets the error that will be returned by Start.

func (*MockRouter) SetTunnelDevice

func (m *MockRouter) SetTunnelDevice(dev tun.Device)

SetTunnelDevice sets the mock tunnel device.

func (*MockRouter) Start

func (m *MockRouter) Start(ctx context.Context) error

Start is a mock implementation that satisfies the Router interface.

type NetlinkRouter

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

NetlinkRouter implements Router using Linux's netlink subsystem.

func NewNetlinkRouter

func NewNetlinkRouter(opts ...Option) (*NetlinkRouter, error)

NewNetlinkRouter creates a new netlink-based tunnel router.

func (*NetlinkRouter) AddPeer

func (r *NetlinkRouter) AddPeer(peer netip.Prefix, conn connection.Connection) (netip.Addr, []netip.Prefix, error)

AddPeer adds a peer route to the tunnel.

func (*NetlinkRouter) Close

func (r *NetlinkRouter) Close() error

Close releases any resources associated with the router.

func (*NetlinkRouter) GetMuxedConnection

func (r *NetlinkRouter) GetMuxedConnection() *connection.MuxedConnection

GetMuxedConnection returns the muxed connection for adding/removing connections.

func (*NetlinkRouter) RemovePeer

func (r *NetlinkRouter) RemovePeer(peer netip.Prefix) error

RemovePeer removes a peer route from the tunnel.

func (*NetlinkRouter) Start

func (r *NetlinkRouter) Start(ctx context.Context) error

Start initializes the router and starts forwarding traffic.

type NetstackRouter

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

NetstackRouter implements Router using a userspace network stack.

func NewNetstackRouter

func NewNetstackRouter(opts ...NetstackRouterOption) (*NetstackRouter, error)

NewNetstackRouter creates a new netstack-based tunnel router.

func (*NetstackRouter) AddPeer

func (r *NetstackRouter) AddPeer(peer netip.Prefix, conn connection.Connection) (netip.Addr, []netip.Prefix, error)

AddPeer adds a peer route to the tunnel.

func (*NetstackRouter) Close

func (r *NetstackRouter) Close() error

Close releases any resources associated with the router.

func (*NetstackRouter) GetMuxedConnection

func (r *NetstackRouter) GetMuxedConnection() *connection.MuxedConnection

GetMuxedConnection returns the muxed connection for adding/removing connections.

func (*NetstackRouter) RemovePeer

func (r *NetstackRouter) RemovePeer(peer netip.Prefix) error

RemovePeer removes a peer route from the tunnel.

func (*NetstackRouter) Start

func (r *NetstackRouter) Start(ctx context.Context) error

Start initializes the router and starts forwarding traffic.

type NetstackRouterOption

type NetstackRouterOption func(*netstackRouterOptions)

func WithLocalAddresses

func WithLocalAddresses(localAddresses []netip.Prefix) NetstackRouterOption

WithLocalAddresses sets the local addresses for the netstack router.

func WithPcapPath

func WithPcapPath(path string) NetstackRouterOption

WithPcapPath sets the optional path to a packet capture file for the netstack router.

func WithResolveConfig

func WithResolveConfig(conf *network.ResolveConfig) NetstackRouterOption

WithResolveConfig sets the DNS configuration for the netstack router.

func WithSocksListenAddr

func WithSocksListenAddr(addr string) NetstackRouterOption

WithSocksListenAddr sets the SOCKS listen address for the netstack router.

type Option

type Option func(*routerOptions)

NewNetlinkRouter creates a new netlink-based tunnel router. Option represents a router configuration option.

func WithExternalInterface

func WithExternalInterface(name string) Option

WithExternalInterface sets the external interface name.

func WithTunnelInterface

func WithTunnelInterface(name string) Option

WithTunnelInterface sets the tunnel interface name.

type Router

type Router interface {
	// Start initializes the router and starts forwarding traffic.
	// It's a blocking call that should be run in a separate goroutine.
	Start(ctx context.Context) error

	// AddPeer adds a peer route to the tunnel. Returns the list of IP prefixes
	// to be advertised to the peer (if none returned, no prefixes should be advertised).
	AddPeer(peer netip.Prefix, conn connection.Connection) (privAddr netip.Addr, routes []netip.Prefix, err error)

	// RemovePeer removes a peer route from the tunnel identified by the given prefix.
	RemovePeer(peer netip.Prefix) error

	// Close releases any resources associated with the router.
	Close() error
}

Router is an interface for managing tunnel routing.

Jump to

Keyboard shortcuts

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