middleware

package
v0.0.0-...-0c57748 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package middleware provides some types and functions common among middleware.

Index

Constants

View Source
const Namespace = "coredns"

Variables

This section is empty.

Functions

func Edns0Version

func Edns0Version(req *dns.Msg) (*dns.Msg, error)

Edns0Version checks the EDNS version in the request. If error is nil everything is OK and we can invoke the middleware. If non-nil, the returned Msg is valid to be returned to the client (and should). For some reason this response should not contain a question RR in the question section.

func Exchange

func Exchange(c *dns.Client, m *dns.Msg, server string) (*dns.Msg, error)

func Less

func Less(a, b string) int

Less returns <0 when a is less than b, 0 when they are equal and >0 when a is larger than b. The function orders names in DNSSEC canonical order: RFC 4034s section-6.1

See http://bert-hubert.blogspot.co.uk/2015/10/how-to-do-fast-canonical-ordering-of.html for a blog article on this implementation.

The values of a and b are *not* lowercased before the comparison!

func Proto

func Proto(w dns.ResponseWriter) string

Proto gets the protocol used as the transport. This will be udp or tcp.

func RcodeToString

func RcodeToString(rcode int) string

Types

type Addr

type Addr string

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

func (Addr) Normalize

func (a Addr) Normalize() string

Normalize will return a normalized address, if not port is specified port 53 is added, otherwise the port will be left as is.

type Handler

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

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. If the status code is not one of the following: * SERVFAIL (dns.RcodeServerFailure) * REFUSED (dns.RecodeRefused) * FORMERR (dns.RcodeFormatError) * NOTIMP (dns.RcodeNotImplemented)

CoreDNS assumes *no* reply has yet been written. 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 middleware.

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 middleware 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) 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) Normalize

func (h Host) Normalize() string

Normalize will return the host portion of host, stripping of any port. The host will also be fully qualified and lowercased.

type LogRoller

type LogRoller struct {
	Filename   string
	MaxSize    int
	MaxAge     int
	MaxBackups int
	LocalTime  bool
}

LogRoller implements a middleware that provides a rolling logger.

func ParseRoller

func ParseRoller(c *caddy.Controller) (*LogRoller, error)

func (LogRoller) GetLogWriter

func (l LogRoller) GetLogWriter() io.Writer

GetLogWriter returns an io.Writer that writes to a rolling logger.

type Middleware

type Middleware func(Handler) Handler

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

type MsgType

type MsgType int
const (
	Success    MsgType = iota
	NameError          // NXDOMAIN in header, SOA in auth.
	NoData             // NOERROR in header, SOA in auth.
	Delegation         // NOERROR in header, NS in auth, optionally fluff in additional (not checked).
	OtherError         // Don't cache these.
)

func Classify

func Classify(m *dns.Msg) (MsgType, *dns.OPT)

Classify classifies a message, it returns the MessageType.

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 Replacer

type Replacer interface {
	Replace(string) string
	Set(key, value string)
}

Replacer is a type which can replace placeholder substrings in a string with actual values from a dns.Msg and responseRecorder. Always use NewReplacer to get one of these.

func NewReplacer

func NewReplacer(r *dns.Msg, rr *ResponseRecorder, emptyValue string) Replacer

NewReplacer makes a new replacer based on r and rr. Do not create a new replacer until r and rr have all the needed values, because this function copies those values into the replacer. rr may be nil if it is not available. emptyValue should be the string that is used in place of empty string (can still be empty string).

type ResponseRecorder

type ResponseRecorder struct {
	dns.ResponseWriter
	// contains filtered or unexported fields
}

ResponseRecorder is a type of ResponseWriter that captures the rcode code written to it and also the size of the message written in the response. A rcode code does not have to be written, however, in which case 0 must be assumed. It is best to have the constructor initialize this type with that default status code.

func NewResponseRecorder

func NewResponseRecorder(w dns.ResponseWriter) *ResponseRecorder

NewResponseRecorder makes and returns a new responseRecorder, which captures the DNS rcode from the ResponseWriter and also the length of the response message written through it.

func (*ResponseRecorder) Hijack

func (r *ResponseRecorder) Hijack()

Hijack implements dns.Hijacker. It simply wraps the underlying ResponseWriter's Hijack method if there is one, or returns an error.

func (*ResponseRecorder) Msg

func (r *ResponseRecorder) Msg() *dns.Msg

Msg returns the written message from the ResponseRecorder.

func (*ResponseRecorder) Rcode

func (r *ResponseRecorder) Rcode() string

Rcode returns the rcode.

func (*ResponseRecorder) Size

func (r *ResponseRecorder) Size() int

Size returns the size.

func (*ResponseRecorder) Start

func (r *ResponseRecorder) Start() time.Time

Start returns the start time of the ResponseRecorder.

func (*ResponseRecorder) Write

func (r *ResponseRecorder) Write(buf []byte) (int, error)

Write is a wrapper that records the size of the message that gets written.

func (*ResponseRecorder) WriteMsg

func (r *ResponseRecorder) WriteMsg(res *dns.Msg) error

WriteMsg records the status code and calls the underlying ResponseWriter's WriteMsg method.

type Result

type Result int

Result is the result of Scrub.

const (
	// ScrubIgnored is returned when Scrub did nothing to the message.
	ScrubIgnored Result = iota
	// ScrubDone is returned when the reply has been scrubbed.
	ScrubDone
)

type State

type State struct {
	Req *dns.Msg
	W   dns.ResponseWriter
	// contains filtered or unexported fields
}

State contains some connection state and is useful in middleware.

func (*State) Class

func (s *State) Class() string

Class returns the class of the question in the request.

func (*State) Clear

func (s *State) Clear()

Clear clears all caching from State s.

func (*State) Do

func (s *State) Do() bool

Do returns if the request has the DO (DNSSEC OK) bit set.

func (*State) ErrorMessage

func (s *State) ErrorMessage(rcode int) *dns.Msg

ErrorMessage returns an error message suitable for sending back to the client.

func (*State) Family

func (s *State) Family() int

Family returns the family of the transport. 1 for IPv4 and 2 for IPv6.

func (*State) IP

func (s *State) IP() string

IP gets the (remote) IP address of the client making the request.

func (*State) Name

func (s *State) Name() string

Name returns the name of the question in the request. Note this name will always have a closing dot and will be lower cased. After a call Name the value will be cached. To clear this caching call Clear.

func (*State) Now

func (s *State) Now(format string) string

Now returns the current timestamp in the specified format.

func (*State) NowDate

func (s *State) NowDate() time.Time

NowDate returns the current date/time that can be used in other time functions.

func (*State) Port

func (s *State) Port() (string, error)

Post gets the (remote) Port of the client making the request.

func (*State) Proto

func (s *State) Proto() string

Proto gets the protocol used as the transport. This will be udp or tcp.

func (*State) QClass

func (s *State) QClass() uint16

QClass returns the class of the question in the request.

func (*State) QName

func (s *State) QName() string

QName returns the name of the question in the request.

func (*State) QType

func (s *State) QType() uint16

QType returns the type of the question as an uint16.

func (*State) RemoteAddr

func (s *State) RemoteAddr() string

RemoteAddr returns the net.Addr of the client that sent the current request.

func (*State) Scrub

func (s *State) Scrub(reply *dns.Msg) (*dns.Msg, Result)

Scrub scrubs the reply message so that it will fit the client's buffer. If even after dropping the additional section, it still does not fit the TC bit will be set on the message. Note, the TC bit will be set regardless of protocol, even TCP message will get the bit, the client should then retry with pigeons. TODO(referral).

func (*State) Size

func (s *State) Size() int

UDPSize returns if UDP buffer size advertised in the requests OPT record. Or when the request was over TCP, we return the maximum allowed size of 64K.

func (*State) SizeAndDo

func (s *State) SizeAndDo(m *dns.Msg) bool

SizeAndDo adds an OPT record that the reflects the intent from state. The returned bool indicated if an record was found and normalised.

func (*State) Type

func (s *State) Type() string

Type returns the type of the question as a string.

type Zones

type Zones []string

func (Zones) FullyQualify

func (z Zones) FullyQualify()

FullyQualify fully qualifies all zones in z.

func (Zones) Matches

func (z Zones) Matches(qname string) string

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

Directories

Path Synopsis
Package errors implements an HTTP error handling middleware.
Package errors implements an HTTP error handling middleware.
Package etcd provides the etcd backend.
Package etcd provides the etcd backend.
msg
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 kubernetes provides the kubernetes backend.
Package kubernetes provides the kubernetes backend.
msg
util
Package kubernetes/util provides helper functions for the kubernetes middleware
Package kubernetes/util provides helper functions for the kubernetes middleware
Package loadbalance is middleware for rewriting responses to do "load balancing"
Package loadbalance is middleware for rewriting responses to do "load balancing"
Package log implements basic but useful request (access) logging middleware.
Package log implements basic but useful request (access) logging middleware.
Package proxy is middleware that proxies requests.
Package proxy is middleware that proxies requests.
Package rewrite is middleware for rewriting requests internally to something different.
Package rewrite is middleware for rewriting requests internally to something different.

Jump to

Keyboard shortcuts

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