libnetwork: resolver: remove setCommonFlags, use createRespMsg

This function was added in 36fd9d02be
(libnetwork: ce6c6e8c35),
because there were multiple places where a DNS response was created,
which had to use the same options. However, new "common" options were
added since, and having it in a function separate from the other (also
common) options was just hiding logic, so let's remove it.

What the above probably _should_ have done was to create a common utility
to create a DNS response (as all other options are shared as well). This
was actually done in 0c22e1bd07 (libnetwork:
be3531759b),
which added a `createRespMsg` utility, but missed that it could be used
for both cases.

This patch:

- removes the setCommonFlags function
- uses createRespMsg instead to share common options

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-17 10:15:38 +02:00
parent 01ac4892e0
commit 986de11464
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -199,10 +199,6 @@ func (r *Resolver) ResolverOptions() []string {
return []string{"ndots:0"}
}
func setCommonFlags(msg *dns.Msg) {
msg.RecursionAvailable = true
}
//nolint:gosec // The RNG is not used in a security-sensitive context.
var (
shuffleRNG = rand.New(rand.NewSource(time.Now().Unix()))
@ -220,9 +216,9 @@ func shuffleAddr(addr []net.IP) []net.IP {
}
func createRespMsg(query *dns.Msg) *dns.Msg {
resp := new(dns.Msg)
resp := &dns.Msg{}
resp.SetReply(query)
setCommonFlags(resp)
resp.RecursionAvailable = true
return resp
}
@ -306,9 +302,7 @@ func (r *Resolver) handlePTRQuery(query *dns.Msg) (*dns.Msg, error) {
r.log().Debugf("[resolver] lookup for IP %s: name %s", name, host)
fqdn := dns.Fqdn(host)
resp := new(dns.Msg)
resp.SetReply(query)
setCommonFlags(resp)
resp := createRespMsg(query)
rr := new(dns.PTR)
rr.Hdr = dns.RR_Header{Name: ptr, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: respTTL}