bindtodevice

package
v0.0.0-...-b6e3791 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package bindtodevice contains an implementation of the netext.ListenConfig interface that uses Linux's SO_BINDTODEVICE socket option to be able to bind to a device.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControlConfig

type ControlConfig struct {
	// RcvBufSize defines the size of socket receive buffer in bytes.  Default
	// is zero (uses system settings).
	RcvBufSize int

	// SndBufSize defines the size of socket send buffer in bytes.  Default is
	// zero (uses system settings).
	SndBufSize int
}

ControlConfig is the configuration of socket options.

type DefaultInterfaceStorage

type DefaultInterfaceStorage struct{}

DefaultInterfaceStorage is the storage that uses the OS's network interfaces.

func (DefaultInterfaceStorage) InterfaceByName

func (DefaultInterfaceStorage) InterfaceByName(name string) (iface NetInterface, err error)

InterfaceByName implements the InterfaceStorage interface for DefaultInterfaceStorage.

type ID

type ID string

ID is the unique identifier of an interface listener.

type InterfaceStorage

type InterfaceStorage interface {
	InterfaceByName(name string) (iface NetInterface, err error)
}

InterfaceStorage is the interface for storages of network interfaces (aka devices). Its main implementation is DefaultInterfaceStorage.

type ListenConfig

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

ListenConfig is a netext.ListenConfig implementation that uses the provided channel-based packet connection and listener to implement the methods of the interface.

netext.ListenConfig instances of this type are the ones that are going to be set as [dnsserver.ConfigBase.ListenConfig] to make the bind-to-device logic work.

func (*ListenConfig) Addr

func (lc *ListenConfig) Addr() (addr *agdnet.PrefixNetAddr)

Addr returns the address on which lc accepts connections. addr.Net is empty.

func (*ListenConfig) Listen

func (lc *ListenConfig) Listen(
	ctx context.Context,
	network string,
	address string,
) (l net.Listener, err error)

Listen implements the netext.ListenConfig interface for *ListenConfig.

func (*ListenConfig) ListenPacket

func (lc *ListenConfig) ListenPacket(
	ctx context.Context,
	network string,
	address string,
) (c net.PacketConn, err error)

ListenPacket implements the netext.ListenConfig interface for *ListenConfig.

type Manager

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

Manager creates individual listeners and dispatches connections to them.

func NewManager

func NewManager(c *ManagerConfig) (m *Manager)

NewManager returns a new manager of interface listeners.

func (*Manager) Add

func (m *Manager) Add(id ID, ifaceName string, port uint16, ctrlConf *ControlConfig) (err error)

Add creates a new interface-listener record in m. If conf is nil, a default configuration is used.

Add must not be called after Start is called.

func (*Manager) ListenConfig

func (m *Manager) ListenConfig(id ID, subnet netip.Prefix) (c *ListenConfig, err error)

ListenConfig returns a new *ListenConfig that receives connections from the interface listener with the given id and the destination addresses of which fall within subnet. subnet should be masked.

ListenConfig must not be called after Start is called.

func (*Manager) Shutdown

func (m *Manager) Shutdown(_ context.Context) (err error)

Shutdown implements the service.Interface interface for *Manager. Shutdown does not actually wait for all sockets to close. If m is nil, Shutdown returns nil, since this feature is optional.

TODO(a.garipov): Consider waiting for all sockets to close.

TODO(a.garipov): Use the context for cancelation.

TODO(a.garipov): Consider an interface solution instead of the nil exception.

func (*Manager) Start

func (m *Manager) Start(_ context.Context) (err error)

Start implements the service.Interface interface for *Manager. If m is nil, Start returns nil, since this feature is optional.

TODO(a.garipov): Consider an interface solution instead of the nil exception.

TODO(a.garipov): Use the context for cancelation.

type ManagerConfig

type ManagerConfig struct {
	// InterfaceStorage is used to get the information about the system's
	// network interfaces.  Normally, this is [DefaultInterfaceStorage].
	InterfaceStorage InterfaceStorage

	// ErrColl is the error collector that is used to collect non-critical
	// errors.
	ErrColl errcoll.Interface

	// ChannelBufferSize is the size of the buffers of the channels used to
	// dispatch TCP connections and UDP sessions.
	ChannelBufferSize int
}

ManagerConfig is the configuration structure for NewManager. All fields must be set.

type NetInterface

type NetInterface interface {
	Subnets() (subnets []netip.Prefix, err error)
}

NetInterface represents a network interface (aka device).

TODO(a.garipov): Consider moving this and InterfaceStorage to netutil.

Jump to

Keyboard shortcuts

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