plugin/cache: Add option to adjust SERVFAIL response cache TTL (#5320)

* add servfail cache opt

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver
2022-06-17 15:48:57 -04:00
committed by GitHub
parent d60ce0c8d4
commit dded10420b
5 changed files with 78 additions and 2 deletions

17
plugin/cache/setup.go vendored
View File

@@ -188,6 +188,23 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
}
ca.verifyStale = mode == "verify"
}
case "servfail":
args := c.RemainingArgs()
if len(args) != 1 {
return nil, c.ArgErr()
}
d, err := time.ParseDuration(args[0])
if err != nil {
return nil, err
}
if d < 0 {
return nil, errors.New("invalid negative ttl for servfail")
}
if d > 5*time.Minute {
// RFC 2308 prohibits caching SERVFAIL longer than 5 minutes
return nil, errors.New("caching SERVFAIL responses over 5 minutes is not permitted")
}
ca.failttl = d
default:
return nil, c.ArgErr()
}