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 ¶
- type ControlConfig
- type DefaultInterfaceStorage
- type EmptyMetrics
- func (EmptyMetrics) IncrementUnknownTCPRequests(_ context.Context)
- func (EmptyMetrics) IncrementUnknownUDPRequests(_ context.Context)
- func (EmptyMetrics) ObserveUDPWriteDuration(_ context.Context, _ string, _ time.Duration)
- func (EmptyMetrics) SetTCPConnsChanSize(_ context.Context, _ netip.Prefix, _ uint)
- func (EmptyMetrics) SetUDPSessionsChanSize(_ context.Context, _ netip.Prefix, _ uint)
- func (EmptyMetrics) SetUDPWriteRequestsChanSize(_ context.Context, _ string, _ uint)
- type ID
- type InterfaceStorage
- type ListenConfig
- type Manager
- type ManagerConfig
- type Metrics
- type NetInterface
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 EmptyMetrics ¶
type EmptyMetrics struct{}
EmptyMetrics is the implementation of the Metrics interface that does nothing.
func (EmptyMetrics) IncrementUnknownTCPRequests ¶
func (EmptyMetrics) IncrementUnknownTCPRequests(_ context.Context)
IncrementUnknownTCPRequests implements the Metrics interface for EmptyMetrics.
func (EmptyMetrics) IncrementUnknownUDPRequests ¶
func (EmptyMetrics) IncrementUnknownUDPRequests(_ context.Context)
IncrementUnknownUDPRequests implements the Metrics interface for EmptyMetrics.
func (EmptyMetrics) ObserveUDPWriteDuration ¶
ObserveUDPWriteDuration implements the Metrics interface for EmptyMetrics.
func (EmptyMetrics) SetTCPConnsChanSize ¶
SetTCPConnsChanSize implements the Metrics interface for EmptyMetrics.
func (EmptyMetrics) SetUDPSessionsChanSize ¶
SetUDPSessionsChanSize implements the Metrics interface for EmptyMetrics.
func (EmptyMetrics) SetUDPWriteRequestsChanSize ¶
func (EmptyMetrics) SetUDPWriteRequestsChanSize(_ context.Context, _ string, _ uint)
SetUDPWriteRequestsChanSize implements the Metrics interface for EmptyMetrics.
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 ¶
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 ¶
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 ¶
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 cancellation.
TODO(a.garipov): Consider an interface solution instead of the nil exception.
func (*Manager) Start ¶
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 cancellation.
type ManagerConfig ¶
type ManagerConfig struct {
// Logger is used to log the operation of the manager.
Logger *slog.Logger
// 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
// Metrics collects bindtodevice-related statistics. It must not be nil.
Metrics Metrics
// 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 Metrics ¶
type Metrics interface {
// IncrementUnknownTCPRequests increments the counter for TCP requests to
// unknown local address.
IncrementUnknownTCPRequests(ctx context.Context)
// IncrementUnknownUDPRequests increments the counter for UDP requests to
// unknown local address.
IncrementUnknownUDPRequests(ctx context.Context)
// SetTCPConnsChanSize sets the current number of TCP connections in the
// channel by subnet.
SetTCPConnsChanSize(ctx context.Context, subnet netip.Prefix, n uint)
// SetUDPConnsChanSize sets the current number of UDP connections in the
// channel by subnet.
SetUDPSessionsChanSize(ctx context.Context, subnet netip.Prefix, n uint)
// SetUDPWriteRequestsChanSize sets the current number of UDP write requests
// in the channel by interface name.
SetUDPWriteRequestsChanSize(ctx context.Context, name string, n uint)
// ObserveUDPWriteDuration observes the duration of a UDP write operation by
// interface name.
ObserveUDPWriteDuration(ctx context.Context, name string, dur time.Duration)
}
Metrics is an interface for collecting bindtodevice-related statistics.
type NetInterface ¶
NetInterface represents a network interface (aka device).
TODO(a.garipov): Consider moving this and InterfaceStorage to netutil.