plugin

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 18 Imported by: 3,739

Documentation

Overview

Package plugin provides some types and functions common among plugin.

Index

Constants

View Source
const Namespace = "coredns"

Namespace is the namespace used for the metrics.

Variables

View Source
var ErrOnce = errors.New("this plugin can only be used once per Server Block")

ErrOnce is returned when a plugin doesn't support multiple setups per server.

View Source
var NativeHistogramBucketFactor = 1.05

NativeHistogramBucketFactor controls the resolution of Prometheus native histogram buckets. See: https://pkg.go.dev/github.com/prometheus/client_golang@v1.19.0/prometheus#section-readme

View Source
var SlimTimeBuckets = prometheus.ExponentialBuckets(0.00025, 10, 5) // from 0.25ms to 2.5 seconds

SlimTimeBuckets is low cardinality set of duration buckets.

View Source
var TimeBuckets = prometheus.ExponentialBuckets(0.00025, 2, 16) // from 0.25ms to 8 seconds

TimeBuckets is based on Prometheus client_golang prometheus.DefBuckets

Functions

func A

func A(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, truncated bool, err error)

A returns A records from Backend or an error.

func AAAA

func AAAA(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, truncated bool, err error)

AAAA returns AAAA records from Backend or an error.

func BackendError

func BackendError(ctx context.Context, b ServiceBackend, zone string, rcode int, state request.Request, err error, opt Options) (int, error)

BackendError writes an error response to the client.

func CNAME

func CNAME(ctx context.Context, b ServiceBackend, zone string, state request.Request, opt Options) (records []dns.RR, err error)

CNAME returns CNAME records from the backend or an error.

func ClientWrite

func ClientWrite(rcode int) bool

ClientWrite returns true if the response has been written to the client. Each plugin to adhere to this protocol.

func Done added in v1.5.0

func Done(ctx context.Context) bool

Done is a non-blocking function that returns true if the context has been canceled.

func Error

func Error(name string, err error) error

Error returns err with 'plugin/name: ' prefixed to it.

func MX

func MX(ctx context.Context, b ServiceBackend, zone string, state request.Request, opt Options) (records, extra []dns.RR, err error)

MX returns MX records from the Backend. If the Target is not a name but an IP address, a name is created on the fly.

func NS

func NS(ctx context.Context, b ServiceBackend, zone string, state request.Request, opt Options) (records, extra []dns.RR, err error)

NS returns NS records from the backend

func NextOrFailure

func NextOrFailure(name string, next Handler, ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

NextOrFailure calls next.ServeDNS when next is not nil, otherwise it will return, a ServerFailure and a `no next plugin found` error.

func OriginsFromArgsOrServerBlock added in v1.8.4

func OriginsFromArgsOrServerBlock(args, serverblock []string) []string

OriginsFromArgsOrServerBlock returns the normalized args if that slice is not empty, otherwise the serverblock slice is returned (in a newly copied slice).

func PTR

func PTR(ctx context.Context, b ServiceBackend, zone string, state request.Request, opt Options) (records []dns.RR, err error)

PTR returns the PTR records from the backend, only services that have a domain name as host are included.

func Register added in v1.6.4

func Register(name string, action caddy.SetupFunc)

Register registers your plugin with CoreDNS and allows it to be called when the server is running.

func SOA

func SOA(ctx context.Context, b ServiceBackend, zone string, state request.Request, opt Options) ([]dns.RR, error)

SOA returns a SOA record from the backend.

func SRV

func SRV(ctx context.Context, b ServiceBackend, zone string, state request.Request, opt Options) (records, extra []dns.RR, err error)

SRV returns SRV records from the Backend. If the Target is not a name but an IP address, a name is created on the fly.

func SplitHostPort

func SplitHostPort(s string) (hosts []string, port string, err error)

SplitHostPort splits s up in a host(s) and port portion, taking reverse address notation into account. String the string s should *not* be prefixed with any protocols, i.e. dns://. SplitHostPort can return multiple hosts when a reverse notation on a non-octet boundary is given.

func TXT

func TXT(ctx context.Context, b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, truncated bool, err error)

TXT returns TXT records from Backend or an error.

Types

type Handler

type Handler interface {
	ServeDNS(context.Context, dns.ResponseWriter, *dns.Msg) (int, error)
	Name() string
}

Handler is like dns.Handler except ServeDNS may return an rcode and/or error.

If ServeDNS writes to the response body, it should return a status code. CoreDNS assumes *no* reply has yet been written if the status code is one of the following:

* SERVFAIL (dns.RcodeServerFailure)

* REFUSED (dns.RecodeRefused)

* FORMERR (dns.RcodeFormatError)

* NOTIMP (dns.RcodeNotImplemented)

All other response codes signal other handlers above it that the response message is already written, and that they should not write to it also.

If ServeDNS encounters an error, it should return the error value so it can be logged by designated error-handling plugin.

If writing a response after calling another ServeDNS method, the returned rcode SHOULD be used when writing the response.

If handling errors after calling another ServeDNS method, the returned error value SHOULD be logged or handled accordingly.

Otherwise, return values should be propagated down the plugin chain by returning them unchanged.

type HandlerFunc

type HandlerFunc func(context.Context, dns.ResponseWriter, *dns.Msg) (int, error)

HandlerFunc is a convenience type like dns.HandlerFunc, except ServeDNS returns an rcode and an error. See Handler documentation for more information.

func (HandlerFunc) Name

func (f HandlerFunc) Name() string

Name implements the Handler interface.

func (HandlerFunc) ServeDNS

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

ServeDNS implements the Handler interface.

type Host

type Host string

Host represents a host from the Corefile, may contain port.

func (Host) MustNormalize added in v1.6.5

func (h Host) MustNormalize() (string, error)

MustNormalize will return the host portion of host, stripping of any port or transport. The host will also be fully qualified and lowercased. An error is returned on error Deprecated: use OriginsFromArgsOrServerBlock or NormalizeExact

func (Host) Normalize

func (h Host) Normalize() string

Normalize will return the host portion of host, stripping of any port or transport. The host will also be fully qualified and lowercased. An empty string is returned on failure Deprecated: use OriginsFromArgsOrServerBlock or NormalizeExact

func (Host) NormalizeExact added in v1.8.4

func (h Host) NormalizeExact() []string

NormalizeExact will return the host portion of host, stripping of any port or transport. The host will also be fully qualified and lowercased. An empty slice is returned on failure

type Name

type Name string

Name represents a domain name.

func (Name) Matches

func (n Name) Matches(child string) bool

Matches checks to see if other is a subdomain (or the same domain) of n. This method assures that names can be easily and consistently matched.

func (Name) Normalize

func (n Name) Normalize() string

Normalize lowercases and makes n fully qualified.

type Options

type Options struct{}

Options are extra options that can be specified for a lookup.

type Plugin

type Plugin func(Handler) Handler

Plugin is a middle layer which represents the traditional idea of plugin: it chains one Handler to the next by being passed the next Handler in the chain.

type ServiceBackend

type ServiceBackend interface {
	// Services communicates with the backend to retrieve the service definitions. Exact indicates
	// on exact match should be returned.
	Services(ctx context.Context, state request.Request, exact bool, opt Options) ([]msg.Service, error)

	// Reverse communicates with the backend to retrieve service definition based on a IP address
	// instead of a name. I.e. a reverse DNS lookup.
	Reverse(ctx context.Context, state request.Request, exact bool, opt Options) ([]msg.Service, error)

	// Lookup is used to find records else where.
	Lookup(ctx context.Context, state request.Request, name string, typ uint16) (*dns.Msg, error)

	// Returns _all_ services that matches a certain name.
	// Note: it does not implement a specific service.
	Records(ctx context.Context, state request.Request, exact bool) ([]msg.Service, error)

	// IsNameError returns true if err indicated a record not found condition
	IsNameError(err error) bool

	// Serial returns a SOA serial number to construct a SOA record.
	Serial(state request.Request) uint32

	// MinTTL returns the minimum TTL to be used in the SOA record.
	MinTTL(state request.Request) uint32
}

ServiceBackend defines a (dynamic) backend that returns a slice of service definitions.

type Zones

type Zones []string

Zones represents a lists of zone names.

func (Zones) Matches

func (z Zones) Matches(qname string) string

Matches checks if qname is a subdomain of any of the zones in z. The match will return the most specific zones that matches. The empty string signals a not found condition.

func (Zones) Normalize

func (z Zones) Normalize()

Normalize fully qualifies all zones in z. The zones in Z must be domain names, without a port or protocol prefix.

Directories

Path Synopsis
Package auto implements an on-the-fly loading file backend.
Package auto implements an on-the-fly loading file backend.
Package autopath implements autopathing.
Package autopath implements autopathing.
Package bind allows binding to a specific interface instead of bind to all of them.
Package bind allows binding to a specific interface instead of bind to all of them.
Package bufsize implements a plugin that clamps EDNS0 buffer size preventing packet fragmentation.
Package bufsize implements a plugin that clamps EDNS0 buffer size preventing packet fragmentation.
Package cache implements a cache.
Package cache implements a cache.
freq
Package freq keeps track of last X seen events.
Package freq keeps track of last X seen events.
Package cancel implements a plugin adds a canceling context to each request.
Package cancel implements a plugin adds a canceling context to each request.
Package chaos implements a plugin that answer to 'CH version.bind TXT' type queries.
Package chaos implements a plugin that answer to 'CH version.bind TXT' type queries.
Package clouddns implements a plugin that returns resource records from GCP Cloud DNS.
Package clouddns implements a plugin that returns resource records from GCP Cloud DNS.
Package deprecated is used when we deprecated plugin.
Package deprecated is used when we deprecated plugin.
Package dns64 implements a plugin that performs DNS64.
Package dns64 implements a plugin that performs DNS64.
Package dnssec implements a plugin that signs responses on-the-fly using NSEC black lies.
Package dnssec implements a plugin that signs responses on-the-fly using NSEC black lies.
msg
Package erratic implements a plugin that returns erratic answers (delayed, dropped).
Package erratic implements a plugin that returns erratic answers (delayed, dropped).
Package errors implements an error handling plugin.
Package errors implements an error handling plugin.
Package etcd provides the etcd version 3 backend plugin.
Package etcd provides the etcd version 3 backend plugin.
msg
Package msg defines the Service structure which is used for service discovery.
Package msg defines the Service structure which is used for service discovery.
Package file implements a file backend.
Package file implements a file backend.
rrutil
Package rrutil provides function to find certain RRs in slices.
Package rrutil provides function to find certain RRs in slices.
tree
Package tree implements Left-Leaning Red Black trees as described by Robert Sedgewick.
Package tree implements Left-Leaning Red Black trees as described by Robert Sedgewick.
Package forward implements a forwarding proxy.
Package forward implements a forwarding proxy.
Package geoip implements a max mind database plugin.
Package geoip implements a max mind database plugin.
Package health implements an HTTP handler that responds to health checks.
Package health implements an HTTP handler that responds to health checks.
Package external implements external names for kubernetes clusters.
Package external implements external names for kubernetes clusters.
Package kubernetes provides the kubernetes backend.
Package kubernetes provides the kubernetes backend.
object
Package object holds functions that convert the objects from the k8s API in to a more memory efficient structures.
Package object holds functions that convert the objects from the k8s API in to a more memory efficient structures.
Package loadbalance is a plugin for rewriting responses to do "load balancing"
Package loadbalance is a plugin for rewriting responses to do "load balancing"
Package log implements basic but useful request (access) logging plugin.
Package log implements basic but useful request (access) logging plugin.
Package metadata provides an API that allows plugins to add metadata to the context.
Package metadata provides an API that allows plugins to add metadata to the context.
Package metrics implement a handler and plugin that provides Prometheus metrics.
Package metrics implement a handler and plugin that provides Prometheus metrics.
Package nsid implements NSID protocol
Package nsid implements NSID protocol
pkg
cache
Package cache implements a cache.
Package cache implements a cache.
cidr
Package cidr contains functions that deal with classless reverse zones in the DNS.
Package cidr contains functions that deal with classless reverse zones in the DNS.
dnstest
Package dnstest allows for easy testing of DNS client against a test server.
Package dnstest allows for easy testing of DNS client against a test server.
dnsutil
Package dnsutil contains DNS related helper functions.
Package dnsutil contains DNS related helper functions.
doh
edns
Package edns provides function useful for adding/inspecting OPT records to/in messages.
Package edns provides function useful for adding/inspecting OPT records to/in messages.
fall
Package fall handles the fallthrough logic used in plugins that support it.
Package fall handles the fallthrough logic used in plugins that support it.
fuzz
Package fuzz contains functions that enable fuzzing of plugins.
Package fuzz contains functions that enable fuzzing of plugins.
log
Package log implements a small wrapper around the std lib log package.
Package log implements a small wrapper around the std lib log package.
nonwriter
Package nonwriter implements a dns.ResponseWriter that never writes, but captures the dns.Msg being written.
Package nonwriter implements a dns.ResponseWriter that never writes, but captures the dns.Msg being written.
parse
Package parse contains functions that can be used in the setup code for plugins.
Package parse contains functions that can be used in the setup code for plugins.
proxy
Package proxy implements a forwarding proxy.
Package proxy implements a forwarding proxy.
rand
Package rand is used for concurrency safe random number generator.
Package rand is used for concurrency safe random number generator.
singleflight
Package singleflight provides a duplicate function call suppression mechanism.
Package singleflight provides a duplicate function call suppression mechanism.
tls
uniq
Package uniq keeps track of "thing" that are either "todo" or "done".
Package uniq keeps track of "thing" that are either "todo" or "done".
up
Package up is used to run a function for some duration.
Package up is used to run a function for some duration.
upstream
Package upstream abstracts a upstream lookups so that plugins can handle them in an unified way.
Package upstream abstracts a upstream lookups so that plugins can handle them in an unified way.
Package pprof implements a debug endpoint for getting profiles using the go pprof tooling.
Package pprof implements a debug endpoint for getting profiles using the go pprof tooling.
Package ready is used to signal readiness of the CoreDNS process.
Package ready is used to signal readiness of the CoreDNS process.
Package reload periodically checks if the Corefile has changed, and reloads if so.
Package reload periodically checks if the Corefile has changed, and reloads if so.
Package rewrite is a plugin for rewriting requests internally to something different.
Package rewrite is a plugin for rewriting requests internally to something different.
Package route53 implements a plugin that returns resource records from AWS route53.
Package route53 implements a plugin that returns resource records from AWS route53.
Package secondary implements a secondary plugin.
Package secondary implements a secondary plugin.
Package sign implements a zone signer as a plugin.
Package sign implements a zone signer as a plugin.
Package test contains helper functions for writing plugin tests.
Package test contains helper functions for writing plugin tests.
Package trace implements OpenTracing-based tracing
Package trace implements OpenTracing-based tracing
Package whoami implements a plugin that returns details about the resolving querying it.
Package whoami implements a plugin that returns details about the resolving querying it.

Jump to

Keyboard shortcuts

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