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>
This commit is contained in:
Alex
2022-08-14 17:26:39 +03:00
committed by GitHub
parent 5c1447e0b0
commit c9e9954d33
2 changed files with 43 additions and 1 deletions

View File

@@ -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 Note that names in the `AUTHORITY SECTION` and `ADDITIONAL SECTION` will also be
rewritten following the specified rules. The names returned by the following 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. if the `answer value` rule is specified.
The syntax for the rewrite of DNS request and response is as follows: 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 rules are allowed to match the question section. The answer rewrite must be
after the name, as in the syntax example. 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 #### Multiple Response Rewrites
`name` and `value` rewrites can be chained by appending multiple answer rewrite `name` and `value` rewrites can be chained by appending multiple answer rewrite

View File

@@ -117,6 +117,8 @@ func getRecordValueForRewrite(rr dns.RR) (name string) {
return rr.(*dns.NAPTR).Replacement return rr.(*dns.NAPTR).Replacement
case dns.TypeSOA: case dns.TypeSOA:
return rr.(*dns.SOA).Ns return rr.(*dns.SOA).Ns
case dns.TypePTR:
return rr.(*dns.PTR).Ptr
default: default:
return "" return ""
} }
@@ -138,5 +140,7 @@ func setRewrittenRecordValue(rr dns.RR, value string) {
rr.(*dns.NAPTR).Replacement = value rr.(*dns.NAPTR).Replacement = value
case dns.TypeSOA: case dns.TypeSOA:
rr.(*dns.SOA).Ns = value rr.(*dns.SOA).Ns = value
case dns.TypePTR:
rr.(*dns.PTR).Ptr = value
} }
} }