diff options
author | 2022-08-14 17:26:39 +0300 | |
---|---|---|
committer | 2022-08-14 10:26:39 -0400 | |
commit | c9e9954d3306ea0f130c8db7a20e5a0c0b1bba77 (patch) | |
tree | 9e509466330ffcccceb78f3ba4456286027a18d9 | |
parent | 5c1447e0b0ef99ad6426deba7d8b1970fe19cd55 (diff) | |
download | coredns-c9e9954d3306ea0f130c8db7a20e5a0c0b1bba77.tar.gz coredns-c9e9954d3306ea0f130c8db7a20e5a0c0b1bba77.tar.zst coredns-c9e9954d3306ea0f130c8db7a20e5a0c0b1bba77.zip |
Add PTR records to supported types (#5565)
* Add PTR records to supported types
Signed-off-by: Alex Bulatov <xbulat@gmail.com>
* Add extra line
Signed-off-by: Alex Bulatov <xbulat@gmail.com>
* Fix title
Signed-off-by: Alex Bulatov <xbulat@gmail.com>
Signed-off-by: Alex Bulatov <xbulat@gmail.com>
-rw-r--r-- | plugin/rewrite/README.md | 40 | ||||
-rw-r--r-- | plugin/rewrite/reverter.go | 4 |
2 files changed, 43 insertions, 1 deletions
diff --git a/plugin/rewrite/README.md b/plugin/rewrite/README.md index b0757f68b..9de53523a 100644 --- a/plugin/rewrite/README.md +++ b/plugin/rewrite/README.md @@ -205,7 +205,7 @@ regular expression and a rewrite name as parameters and works in the same way as Note that names in the `AUTHORITY SECTION` and `ADDITIONAL SECTION` will also be rewritten following the specified rules. The names returned by the following -record types: `CNAME`, `DNAME`, `SOA`, `SRV`, `MX`, `NAPTR`, `NS` will be rewritten +record types: `CNAME`, `DNAME`, `SOA`, `SRV`, `MX`, `NAPTR`, `NS`, `PTR` will be rewritten if the `answer value` rule is specified. The syntax for the rewrite of DNS request and response is as follows: @@ -222,6 +222,44 @@ Note that the above syntax is strict. For response rewrites, only `name` rules are allowed to match the question section. The answer rewrite must be after the name, as in the syntax example. +##### Example: PTR Response Value Rewrite + +The original response contains the domain `service.consul.` in the `VALUE` part +of the `ANSWER SECTION` + +``` +$ dig @10.1.1.1 30.30.30.10.in-addr.arpa PTR + +;; QUESTION SECTION: +;30.30.30.10.in-addr.arpa. IN PTR + +;; ANSWER SECTION: +30.30.30.10.in-addr.arpa. 60 IN PTR ftp-us-west-1.service.consul. +``` + +The following configuration snippet allows for rewriting of the value +in the `ANSWER SECTION`: + +``` + rewrite stop { + name suffix .arpa .arpa + answer name auto + answer value (.*)\.service\.consul\. {1}.coredns.rocks. + } +``` + +Now, the `VALUE` in the `ANSWER SECTION` has been overwritten in the domain part: + +``` +$ dig @10.1.1.1 30.30.30.10.in-addr.arpa PTR + +;; QUESTION SECTION: +;30.30.30.10.in-addr.arpa. IN PTR + +;; ANSWER SECTION: +30.30.30.10.in-addr.arpa. 60 IN PTR ftp-us-west-1.coredns.rocks. +``` + #### Multiple Response Rewrites `name` and `value` rewrites can be chained by appending multiple answer rewrite diff --git a/plugin/rewrite/reverter.go b/plugin/rewrite/reverter.go index 7d83e557b..7abbfb89f 100644 --- a/plugin/rewrite/reverter.go +++ b/plugin/rewrite/reverter.go @@ -117,6 +117,8 @@ func getRecordValueForRewrite(rr dns.RR) (name string) { return rr.(*dns.NAPTR).Replacement case dns.TypeSOA: return rr.(*dns.SOA).Ns + case dns.TypePTR: + return rr.(*dns.PTR).Ptr default: return "" } @@ -138,5 +140,7 @@ func setRewrittenRecordValue(rr dns.RR, value string) { rr.(*dns.NAPTR).Replacement = value case dns.TypeSOA: rr.(*dns.SOA).Ns = value + case dns.TypePTR: + rr.(*dns.PTR).Ptr = value } } |