Skip to content

Commit

Permalink
fixing readme TTL and using map for rcode
Browse files Browse the repository at this point in the history
  • Loading branch information
pschou committed Jul 20, 2023
1 parent f1fca60 commit f40f719
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 11 additions & 4 deletions plugin/rewrite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ rewrite ttl example.com. 30 # equivalent to rewrite ttl example.com. 30-30
At times, the need to rewrite a RCODE value could arise. For example, a DNS server
may respond with a SERVFAIL instead of NOERROR records when AAAA records are requested.

In the below example, the TTL in the answers for `coredns.rocks` domain are
being set to `15`:
In the below example, the rcode value the answer for `coredns.rocks` the replies with SERVFAIL
is being switched to NOERROR.

This example rewrites all the *.coredns.rocks domain SERVFAIL errors to NOERROR
```
Expand All @@ -351,15 +351,22 @@ This example rewrites all the *.coredns.rocks domain SERVFAIL errors to NOERROR
}
```

The same result numeric values:
```
rewrite continue {
rcode regex (.*)\.coredns\.rocks 2 0
}
```

The syntax for the RCODE rewrite rule is as follows. The meaning of
`exact|prefix|suffix|substring|regex` is the same as with the name rewrite rules.
An omitted type is defaulted to `exact`.

```
rewrite [continue|stop] rcode [exact|prefix|suffix|substring|regex] STRING OLD NEW
rewrite [continue|stop] rcode [exact|prefix|suffix|substring|regex] STRING FROM TO
```

The values of OLD and NEW can be any of the following:
The values of FROM and TO can be any of the following, text value or numeric:

```
0 NOERROR
Expand Down
6 changes: 2 additions & 4 deletions plugin/rewrite/rcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,8 @@ func isValidRCode(v string) (int, bool) {
return int(i), true
}

for RCodeInt, RCodeStr := range dns.RcodeToString {
if strings.EqualFold(RCodeStr, v) {
return RCodeInt, true
}
if RCodeInt, ok := dns.StringToRcode[strings.ToUpper(v)]; ok {
return RCodeInt, true
}
return 0, false
}

0 comments on commit f40f719

Please sign in to comment.