dnsserver

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package dnsserver implements a DNS server for sidecars

Index

Constants

View Source
const (
	// DefaultSecurePort is the TCP port used by
	// default to serve DNS over TLS (a.k.a. DoT)
	DefaultSecurePort = 853

	// DefaultInsecurePort is the UDP/TCP port used by default to
	// serve plain DNS
	DefaultInsecurePort = 53
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BindingConfig

type BindingConfig struct {
	Addrs   []netip.Addr
	Port    uint16
	TLSPort uint16

	PortStrict   bool
	PortAttempts int
}

BindingConfig describes what the Server will listen.

type Config

type Config struct {
	Logger  slog.Logger
	Context context.Context

	Bind      BindingConfig
	TLSConfig *tls.Config

	// DNS
	MaxTCPQueries int
	ReadTimeout   time.Duration
	IdleTimeout   time.Duration

	GracefulTimeout time.Duration
}

Config describes how the Server will be assembled and operate.

func (*Config) New

func (sc *Config) New(eg *core.ErrGroup) (*Server, error)

New creates a new Server from the Config, optionally taking a shared core.ErrGroup for cancellations.

func (*Config) SetDefaults

func (sc *Config) SetDefaults() error

SetDefaults fills gaps in the Config.

type Listeners

type Listeners struct {
	UDP []*net.UDPConn
	TCP []*net.TCPListener
	TLS []net.Listener
}

Listeners contains the listeners to be used by this DNS server.

func (*Listeners) Close

func (sl *Listeners) Close() error

Close closes all listeners.

type Server

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

Server is a DNS/DoT Server built around a shared core.ErrGroup.

func (*Server) Cancel

func (ds *Server) Cancel(cause error)

Cancel initiates a cancellation with the given reason.

func (*Server) HasSecure

func (srv *Server) HasSecure() bool

HasSecure tells if the Server will handle DoT requests.

func (*Server) ListenWithListener

func (srv *Server) ListenWithListener(lc bind.TCPUDPListener) error

ListenWithListener uses a given bind.TCPUDPListener to listen to the addresses specified on the Config.

func (*Server) Serve

func (ds *Server) Serve(h dns.Handler) error

Serve starts all workers and waits until they have finished.

func (*Server) Spawn

func (ds *Server) Spawn(h dns.Handler, wait time.Duration) error

Spawn starts all workers and optionally waits a given amount to make sure they didn't fail.

func (*Server) Wait

func (ds *Server) Wait() error

Wait waits until all workers have finished.

Jump to

Keyboard shortcuts

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