plugin/rewrite: add handling of TTL field rewrites (#2048)

Resolves: #1981

Signed-off-by: Paul Greenberg <greenpau@outlook.com>
This commit is contained in:
Paul G
2018-08-29 10:41:03 -04:00
committed by GitHub
parent 52147cd657
commit 38051b9089
6 changed files with 453 additions and 25 deletions

View File

@@ -13,7 +13,7 @@ Rewrites are invisible to the client. There are simple rewrites (fast) and compl
A simplified/easy to digest syntax for *rewrite* is...
~~~
rewrite [continue|stop] FIELD FROM TO
rewrite [continue|stop] FIELD [FROM TO|FROM TTL]
~~~
* **FIELD** indicates what part of the request/response is being re-written.
@@ -25,9 +25,11 @@ e.g., to rewrite ANY queries to HINFO, use `rewrite type ANY HINFO`.
name, e.g., `rewrite name example.net example.org`. Other match types are supported, see the **Name Field Rewrites** section below.
* `answer name` - the query name in the _response_ is rewritten. This option has special restrictions and requirements, in particular it must always combined with a `name` rewrite. See below in the **Response Rewrites** section.
* `edns0` - an EDNS0 option can be appended to the request as described below in the **EDNS0 Options** section.
* `ttl` - the TTL value in the _response_ is rewritten.
* **FROM** is the name or type to match
* **FROM** is the name (exact, suffix, prefix, substring, or regex) or type to match
* **TO** is the destination name or type to rewrite to
* **TTL** is the number of seconds to set the TTL value to
If you specify multiple rules and an incoming query matches on multiple rules, the rewrite
will behave as following
@@ -177,6 +179,32 @@ follows:
rewrite [continue|stop] name regex STRING STRING answer name STRING STRING
```
### TTL Field Rewrites
At times, the need for rewriting TTL value could arise. For example, a DNS server
may prevent caching by setting TTL as low as zero (`0`). An administrator
may want to increase the TTL to prevent caching, e.g. to 15 seconds.
In the below example, the TTL in the answers for `coredns.rocks` domain are
being set to `15`:
```
rewrite continue {
ttl regex (.*)\.coredns\.rocks 15
}
```
By the same token, an administrator may use this feature to force caching by
setting TTL value really low.
The syntax for the TTL rewrite rule is as follows. The meaning of
`exact|prefix|suffix|substring|regex` is the same as with the name rewrite rules.
```
rewrite [continue|stop] ttl [exact|prefix|suffix|substring|regex] STRING SECONDS
```
## EDNS0 Options
Using FIELD edns0, you can set, append, or replace specific EDNS0 options on the request.