Documentation
¶
Index ¶
- Constants
- type MockRouter
- func (m *MockRouter) AddPeer(peer netip.Prefix, conn connection.Connection) (netip.Addr, []netip.Prefix, error)
- func (m *MockRouter) Close() error
- func (m *MockRouter) GetMuxedConnection() *connection.MuxedConnection
- func (m *MockRouter) GetRoutes() []netip.Prefix
- func (m *MockRouter) RemovePeer(peer netip.Prefix) error
- func (m *MockRouter) SetAddPeerError(err error)
- func (m *MockRouter) SetCloseError(err error)
- func (m *MockRouter) SetGetTunnelDeviceError(err error)
- func (m *MockRouter) SetRemovePeerError(err error)
- func (m *MockRouter) SetStartError(err error)
- func (m *MockRouter) SetTunnelDevice(dev tun.Device)
- func (m *MockRouter) Start(ctx context.Context) error
- type NetlinkRouter
- func (r *NetlinkRouter) AddPeer(peer netip.Prefix, conn connection.Connection) (netip.Addr, []netip.Prefix, error)
- func (r *NetlinkRouter) Close() error
- func (r *NetlinkRouter) GetMuxedConnection() *connection.MuxedConnection
- func (r *NetlinkRouter) RemovePeer(peer netip.Prefix) error
- func (r *NetlinkRouter) Start(ctx context.Context) error
- type NetstackRouter
- func (r *NetstackRouter) AddPeer(peer netip.Prefix, conn connection.Connection) (netip.Addr, []netip.Prefix, error)
- func (r *NetstackRouter) Close() error
- func (r *NetstackRouter) GetMuxedConnection() *connection.MuxedConnection
- func (r *NetstackRouter) RemovePeer(peer netip.Prefix) error
- func (r *NetstackRouter) Start(ctx context.Context) error
- type NetstackRouterOption
- type Option
- type Router
Constants ¶
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.
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.
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.
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 ¶
WithExternalInterface sets the external interface name.
func WithTunnelInterface ¶
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.