dns: small refactor to setEDNS to return early

Using a guard clause instead of a long nested if.

The diff is best viewed with whitespace turned off.
This commit is contained in:
Daniel Nephin 2021-04-13 14:46:59 -04:00
parent f1bc7bd49a
commit b09aa1e3c6
1 changed files with 29 additions and 27 deletions

View File

@ -273,8 +273,11 @@ func (d *DNSServer) ReloadConfig(newCfg *config.RuntimeConfig) error {
// possibly the ECS headers as well if they were present in the
// original request
func setEDNS(request *dns.Msg, response *dns.Msg, ecsGlobal bool) {
// Enable EDNS if enabled
if edns := request.IsEdns0(); edns != nil {
edns := request.IsEdns0()
if edns == nil {
return
}
// cannot just use the SetEdns0 function as we need to embed
// the ECS option as well
ednsResp := new(dns.OPT)
@ -301,7 +304,6 @@ func setEDNS(request *dns.Msg, response *dns.Msg, ecsGlobal bool) {
response.Extra = append(response.Extra, ednsResp)
}
}
// recursorAddr is used to add a port to the recursor if omitted.
func recursorAddr(recursor string) (string, error) {