Selaa lähdekoodia

libnetwork: resolver: remove setCommonFlags, use createRespMsg

This function was added in 36fd9d02be9014b8016adb5d255cdacd6dc9e64d
(libnetwork: https://github.com/moby/libnetwork/commit/ce6c6e8c350aed8e3de1910c571b93c2f4d69a8b),
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 0c22e1bd07d75f7a719fe72e466a8ff6dadfd167 (libnetwork:
https://github.com/moby/libnetwork/commit/be3531759b8025fcfeec765101c0d018a86981fc),
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>
Sebastiaan van Stijn 1 vuosi sitten
vanhempi
commit
986de11464
1 muutettua tiedostoa jossa 3 lisäystä ja 9 poistoa
  1. 3 9
      libnetwork/resolver.go

+ 3 - 9
libnetwork/resolver.go

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