rewrite

package
v0.0.0-...-7f72c11 Latest Latest
Warning

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

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

README

rewrite

rewrite performs internal message rewriting. Rewrites are invisible to the client. There are simple rewrites (fast) and complex rewrites (slower), but they're powerful enough to accommodate most dynamic back-end applications.

Syntax

rewrite FIELD FROM TO
  • FIELD is (type, class, name, ...)
  • FROM is the exact name of type to match
  • TO is the destination name or type to rewrite to

When the FIELD is type and FROM is (A, MX, etc.), the type of the message will be rewritten; e.g., to rewrite ANY queries to HINFO, use rewrite type ANY HINFO.

When the FIELD is class and FROM is (IN, CH, or HS) the class of the message will be rewritten; e.g., to rewrite CH queries to IN use rewrite class CH IN.

When the FIELD is name the query name in the message is rewritten; this needs to be a full match of the name, e.g., rewrite name miek.nl example.org.

When the FIELD is edns0 an EDNS0 option can be appended to the request as described below.

If you specify multiple rules and an incoming query matches on multiple (simple) rules, only the first rewrite is applied.

EDNS0 Options

Using FIELD edns0, you can set, append, or replace specific EDNS0 options on the request.

  • replace will modify any matching (what that means may vary based on EDNS0 type) option with the specified option
  • append will add the option regardless of what options already exist
  • set will modify a matching option or add one if none is found

Currently supported are EDNS0_LOCAL and EDNS0_NSID.

EDNS0_LOCAL

This has two fields, code and data. A match is defined as having the same code. Data may be a string, or if it starts with 0x it will be treated as hex. Example:

rewrite edns0 local set 0xffee 0x61626364

rewrites the first local option with code 0xffee, setting the data to "abcd". Equivalent:

rewrite edns0 local set 0xffee abcd
EDNS0_NSID

This has no fields; it will add an NSID option with an empty string for the NSID. If the option already exists and the action is replace or set, then the NSID in the option will be set to the empty string.

Documentation

Overview

Package rewrite is middleware for rewriting requests internally to something different.

Package rewrite is middleware for rewriting requests internally to something different.

Index

Constants

View Source
const (
	Is         = "is"
	Not        = "not"
	Has        = "has"
	NotHas     = "not_has"
	StartsWith = "starts_with"
	EndsWith   = "ends_with"
	Match      = "match"
	NotMatch   = "not_match"
)

Operators

Variables

This section is empty.

Functions

This section is empty.

Types

type If

type If struct {
	A        string
	Operator string
	B        string
}

If is statement for a rewrite condition.

func NewIf

func NewIf(a, operator, b string) (If, error)

NewIf creates a new If condition.

func (If) True

func (i If) True(r *dns.Msg) bool

True returns true if the condition is true and false otherwise. If r is not nil, it replaces placeholders before comparison.

type ResponseReverter

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

ResponseReverter reverses the operations done on the question section of a packet. This is need because the client will otherwise disregards the response, i.e. dig will complain with ';; Question section mismatch: got miek.nl/HINFO/IN'

func NewResponseReverter

func NewResponseReverter(w dns.ResponseWriter, r *dns.Msg) *ResponseReverter

NewResponseReverter returns a pointer to a new ResponseReverter.

func (*ResponseReverter) Hijack

func (r *ResponseReverter) Hijack()

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

func (*ResponseReverter) Write

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

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

func (*ResponseReverter) WriteMsg

func (r *ResponseReverter) 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 a rewrite

const (
	// RewriteIgnored is returned when rewrite is not done on request.
	RewriteIgnored Result = iota
	// RewriteDone is returned when rewrite is done on request.
	RewriteDone
	// RewriteStatus is returned when rewrite is not needed and status code should be set
	// for the request.
	RewriteStatus
)

type Rewrite

type Rewrite struct {
	Next  middleware.Handler
	Rules []Rule
	// contains filtered or unexported fields
}

Rewrite is middleware to rewrite requests internally before being handled.

func (Rewrite) Name

func (rw Rewrite) Name() string

Name implements the Handler interface.

func (Rewrite) ServeDNS

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

ServeDNS implements the middleware.Handler interface.

type Rule

type Rule interface {
	// Rewrite rewrites the current request.
	Rewrite(*dns.Msg) Result
}

Rule describes a rewrite rule.

Jump to

Keyboard shortcuts

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