AdGuardDNS/internal/bindtodevice/manager_others.go

74 lines
2.0 KiB
Go
Raw Normal View History

2023-03-18 17:11:10 +03:00
//go:build !linux
package bindtodevice
import (
"context"
2024-01-04 19:22:32 +03:00
"fmt"
2023-03-18 17:11:10 +03:00
"net/netip"
"github.com/AdguardTeam/golibs/errors"
2024-03-11 12:21:07 +03:00
"github.com/AdguardTeam/golibs/service"
2023-03-18 17:11:10 +03:00
)
// Manager creates individual listeners and dispatches connections to them.
//
2023-06-11 12:58:40 +03:00
// It is only supported on Linux.
2023-03-18 17:11:10 +03:00
type Manager struct{}
// NewManager returns a new manager of interface listeners.
//
2023-06-11 12:58:40 +03:00
// It is only supported on Linux.
2023-03-18 17:11:10 +03:00
func NewManager(c *ManagerConfig) (m *Manager) {
return &Manager{}
}
// Add creates a new interface-listener record in m.
//
2023-06-11 12:58:40 +03:00
// It is only supported on Linux.
func (m *Manager) Add(id ID, ifaceName string, port uint16, cc *ControlConfig) (err error) {
2024-01-04 19:22:32 +03:00
return fmt.Errorf("bindtodevice: add: %w; only supported on linux", errors.ErrUnsupported)
2023-06-11 12:58:40 +03:00
}
2023-03-18 17:11:10 +03:00
2023-09-06 08:22:07 +03:00
// 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.
2023-03-18 17:11:10 +03:00
//
2023-06-11 12:58:40 +03:00
// It is only supported on Linux.
2023-09-06 08:22:07 +03:00
func (m *Manager) ListenConfig(id ID, subnet netip.Prefix) (c *ListenConfig, err error) {
2024-01-04 19:22:32 +03:00
return nil, fmt.Errorf(
"bindtodevice: listenconfig: %w; only supported on linux",
errors.ErrUnsupported,
)
2023-03-18 17:11:10 +03:00
}
// type check
2024-03-11 12:21:07 +03:00
var _ service.Interface = (*Manager)(nil)
2023-03-18 17:11:10 +03:00
2024-03-11 12:21:07 +03:00
// Start implements the [service.Interface] interface for *Manager. If m is
2024-01-04 19:22:32 +03:00
// nil, Start returns nil, since this feature is optional.
2023-03-18 17:11:10 +03:00
//
2023-06-11 12:58:40 +03:00
// It is only supported on Linux.
2024-01-04 19:22:32 +03:00
func (m *Manager) Start(_ context.Context) (err error) {
2023-06-11 12:58:40 +03:00
if m == nil {
return nil
}
2024-01-04 19:22:32 +03:00
return fmt.Errorf("bindtodevice: starting: %w; only supported on linux", errors.ErrUnsupported)
2023-06-11 12:58:40 +03:00
}
2023-03-18 17:11:10 +03:00
2024-03-11 12:21:07 +03:00
// Shutdown implements the [service.Interface] interface for *Manager. If m is
// nil, Shutdown returns nil, since this feature is optional.
2023-03-18 17:11:10 +03:00
//
2023-06-11 12:58:40 +03:00
// It is only supported on Linux.
func (m *Manager) Shutdown(_ context.Context) (err error) {
if m == nil {
return nil
}
2024-01-04 19:22:32 +03:00
return fmt.Errorf(
"bindtodevice: shutting down: %w; only supported on linux",
errors.ErrUnsupported,
)
2023-06-11 12:58:40 +03:00
}