fdyn

package module
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

README

fdyn

Name

fdyn - simple Dynamic DNS plugin for CoreDNS, using a mix of forward and Redis.

Description

The fdyn plugin is a forked version of the standard CoreDNS forward plugin, with a difference: if the returned IP from the upstream server is 0.0.0.0 (IPv4) or ::/0 (IPv6), fdyn will look up the name in the local Redis (using GET of the FQDN, including trailing period) and substitutes that instead. Thus you can set up all the paraphernalia of SOA, NS and authority records in a proper DNS server, and just override the dynamic IP address that is usually all you want to do.

If the queried string does not exist, fdyn will look for wildcard entries, e.g. if foo.bar.example.com is the domain looked up, fdyn will look up in Redis:

  • foo.bar.example.com
  • *.foo.bar.example.com
  • *.bar.example.com
  • *.example.com
  • *.com

Documentation

Overview

Package forward implements a forwarding proxy. It caches an upstream net.Conn for some time, so if the same client returns the upstream's Conn will be precached. Depending on how you benchmark this looks to be 50% faster than just opening a new connection for every client. It works with UDP and TCP and uses inband healthchecking.

Package forward implements a forwarding proxy. It caches an upstream net.Conn for some time, so if the same client returns the upstream's Conn will be precached. Depending on how you benchmark this looks to be 50% faster than just opening a new connection for every client. It works with UDP and TCP and uses inband healthchecking.

Package forward implements a forwarding proxy. It caches an upstream net.Conn for some time, so if the same client returns the upstream's Conn will be precached. Depending on how you benchmark this looks to be 50% faster than just opening a new connection for every client. It works with UDP and TCP and uses inband healthchecking.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoHealthy means no healthy proxies left.
	ErrNoHealthy = errors.New("no healthy proxies")
	// ErrNoFdyn means no forwarder defined.
	ErrNoFdyn = errors.New("no forwarder defined")
	// ErrCachedClosed means cached connection was closed by peer.
	ErrCachedClosed = errors.New("cached connection was closed by peer")
)
View Source
var (
	RequestCount = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "fdyn",
		Name:      "request_count_total",
		Help:      "Counter of requests made per upstream.",
	}, []string{"to"})
	RcodeCount = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "fdyn",
		Name:      "response_rcode_count_total",
		Help:      "Counter of requests made per upstream.",
	}, []string{"rcode", "to"})
	RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: plugin.Namespace,
		Subsystem: "fdyn",
		Name:      "request_duration_seconds",
		Buckets:   plugin.TimeBuckets,
		Help:      "Histogram of the time each request took.",
	}, []string{"to"})
	HealthcheckFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "fdyn",
		Name:      "healthcheck_failure_count_total",
		Help:      "Counter of the number of failed healtchecks.",
	}, []string{"to"})
	HealthcheckBrokenCount = promauto.NewCounter(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "fdyn",
		Name:      "healthcheck_broken_count_total",
		Help:      "Counter of the number of complete failures of the healtchecks.",
	})
	SocketGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: plugin.Namespace,
		Subsystem: "fdyn",
		Name:      "sockets_open",
		Help:      "Gauge of open sockets per upstream.",
	}, []string{"to"})
)

Variables declared for monitoring.

Functions

This section is empty.

Types

type Fdyn

type Fdyn struct {
	Next plugin.Handler

	Pool *redis.Pool
	// contains filtered or unexported fields
}

Fdyn represents a plugin instance that can proxy requests to another (DNS) server. It has a list of proxies each representing one upstream proxy.

func New

func New() *Fdyn

New returns a new Fdyn.

func NewLookup

func NewLookup(addr []string) *Fdyn

NewLookup returns a Fdyn that can be used for plugin that need an upstream to resolve external names. Note that the caller MUST run Close on the forward to stop the health checking goroutines.

func ParseFdynStanza

func ParseFdynStanza(c *caddyfile.Dispenser) (*Fdyn, error)

ParseFdynStanza parses one forward stanza

func (*Fdyn) Close

func (f *Fdyn) Close()

Close is a synonym for OnShutdown().

func (*Fdyn) Fdyn

func (f *Fdyn) Fdyn(state request.Request) (*dns.Msg, error)

Fdyn forward the request in state as-is. Unlike Lookup that adds EDNS0 suffix to the message. Fdyn may be called with a nil f, an error is returned in that case.

func (*Fdyn) ForceTCP

func (f *Fdyn) ForceTCP() bool

ForceTCP returns if TCP is forced to be used even when the request comes in over UDP.

func (*Fdyn) Len

func (f *Fdyn) Len() int

Len returns the number of configured proxies.

func (*Fdyn) List

func (f *Fdyn) List() []*Proxy

List returns a set of proxies to be used for this client depending on the policy in f.

func (*Fdyn) Lookup

func (f *Fdyn) Lookup(state request.Request, name string, typ uint16) (*dns.Msg, error)

Lookup will use name and type to forge a new message and will send that upstream. It will set any EDNS0 options correctly so that downstream will be able to process the reply. Lookup may be called with a nil f, an error is returned in that case.

func (*Fdyn) Name

func (f *Fdyn) Name() string

Name implements plugin.Handler.

func (*Fdyn) OnShutdown

func (f *Fdyn) OnShutdown() error

OnShutdown stops all configured proxies.

func (*Fdyn) OnStartup

func (f *Fdyn) OnStartup() (err error)

OnStartup starts a goroutines for all proxies.

func (*Fdyn) PreferUDP

func (f *Fdyn) PreferUDP() bool

PreferUDP returns if UDP is preferred to be used even when the request comes in over TCP.

func (*Fdyn) ServeDNS

func (f *Fdyn) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements plugin.Handler.

func (*Fdyn) SetProxy

func (f *Fdyn) SetProxy(p *Proxy)

SetProxy appends p to the proxy list and starts healthchecking.

type HealthChecker

type HealthChecker interface {
	Check(*Proxy) error
	SetTLSConfig(*tls.Config)
}

HealthChecker checks the upstream health.

func NewHealthChecker

func NewHealthChecker(trans string) HealthChecker

NewHealthChecker returns a new HealthChecker based on transport.

type Policy

type Policy interface {
	List([]*Proxy) []*Proxy
	String() string
}

Policy defines a policy we use for selecting upstreams.

type Proxy

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

Proxy defines an upstream host.

func NewProxy

func NewProxy(addr, trans string) *Proxy

NewProxy returns a new proxy.

func (*Proxy) Connect

func (p *Proxy) Connect(ctx context.Context, state request.Request, opts options) (*dns.Msg, error)

Connect selects an upstream, sends the request and waits for a response.

func (*Proxy) Down

func (p *Proxy) Down(maxfails uint32) bool

Down returns true if this proxy is down, i.e. has *more* fails than maxfails.

func (*Proxy) Healthcheck

func (p *Proxy) Healthcheck()

Healthcheck kicks of a round of health checks for this proxy.

func (*Proxy) SetExpire

func (p *Proxy) SetExpire(expire time.Duration)

SetExpire sets the expire duration in the lower p.transport.

func (*Proxy) SetTLSConfig

func (p *Proxy) SetTLSConfig(cfg *tls.Config)

SetTLSConfig sets the TLS config in the lower p.transport and in the healthchecking client.

type Transport

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

Transport hold the persistent cache.

func (*Transport) Dial

func (t *Transport) Dial(proto string) (*dns.Conn, bool, error)

Dial dials the address configured in transport, potentially reusing a connection or creating a new one.

func (*Transport) SetExpire

func (t *Transport) SetExpire(expire time.Duration)

SetExpire sets the connection expire time in transport.

func (*Transport) SetTLSConfig

func (t *Transport) SetTLSConfig(cfg *tls.Config)

SetTLSConfig sets the TLS config in transport.

func (*Transport) Start

func (t *Transport) Start()

Start starts the transport's connection manager.

func (*Transport) Stop

func (t *Transport) Stop()

Stop stops the transport's connection manager.

func (*Transport) Yield

func (t *Transport) Yield(c *dns.Conn)

Yield return the connection to transport for reuse.

Jump to

Keyboard shortcuts

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