dns: remove network parameter from two funcs
Now that trimDNSResponse is handled by the caller we don't need to pass this value around. We can remove it from both the serviceLookup struct, and two functions.
This commit is contained in:
parent
4712e24749
commit
b4abf8b0ec
14
agent/dns.go
14
agent/dns.go
|
@ -96,7 +96,6 @@ type dnsConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type serviceLookup struct {
|
type serviceLookup struct {
|
||||||
Network string
|
|
||||||
Datacenter string
|
Datacenter string
|
||||||
Service string
|
Service string
|
||||||
Tag string
|
Tag string
|
||||||
|
@ -497,7 +496,7 @@ func (d *DNSServer) handleQuery(resp dns.ResponseWriter, req *dns.Msg) {
|
||||||
m.SetRcode(req, dns.RcodeNotImplemented)
|
m.SetRcode(req, dns.RcodeNotImplemented)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = d.dispatch(network, resp.RemoteAddr(), req, m, maxRecursionLevelDefault)
|
err = d.dispatch(resp.RemoteAddr(), req, m, maxRecursionLevelDefault)
|
||||||
rCode := rCodeFromError(err)
|
rCode := rCodeFromError(err)
|
||||||
if rCode == dns.RcodeNameError || errors.Is(err, errNoAnswer) {
|
if rCode == dns.RcodeNameError || errors.Is(err, errNoAnswer) {
|
||||||
d.addSOA(cfg, m)
|
d.addSOA(cfg, m)
|
||||||
|
@ -639,7 +638,7 @@ func (e ecsNotGlobalError) Unwrap() error {
|
||||||
|
|
||||||
// dispatch is used to parse a request and invoke the correct handler.
|
// dispatch is used to parse a request and invoke the correct handler.
|
||||||
// parameter maxRecursionLevel will handle whether recursive call can be performed
|
// parameter maxRecursionLevel will handle whether recursive call can be performed
|
||||||
func (d *DNSServer) dispatch(network string, remoteAddr net.Addr, req, resp *dns.Msg, maxRecursionLevel int) error {
|
func (d *DNSServer) dispatch(remoteAddr net.Addr, req, resp *dns.Msg, maxRecursionLevel int) error {
|
||||||
// By default the query is in the default datacenter
|
// By default the query is in the default datacenter
|
||||||
datacenter := d.agent.config.Datacenter
|
datacenter := d.agent.config.Datacenter
|
||||||
|
|
||||||
|
@ -696,7 +695,6 @@ func (d *DNSServer) dispatch(network string, remoteAddr net.Addr, req, resp *dns
|
||||||
}
|
}
|
||||||
|
|
||||||
lookup := serviceLookup{
|
lookup := serviceLookup{
|
||||||
Network: network,
|
|
||||||
Datacenter: datacenter,
|
Datacenter: datacenter,
|
||||||
Connect: false,
|
Connect: false,
|
||||||
Ingress: false,
|
Ingress: false,
|
||||||
|
@ -743,7 +741,6 @@ func (d *DNSServer) dispatch(network string, remoteAddr net.Addr, req, resp *dns
|
||||||
}
|
}
|
||||||
|
|
||||||
lookup := serviceLookup{
|
lookup := serviceLookup{
|
||||||
Network: network,
|
|
||||||
Datacenter: datacenter,
|
Datacenter: datacenter,
|
||||||
Service: queryParts[len(queryParts)-1],
|
Service: queryParts[len(queryParts)-1],
|
||||||
Connect: true,
|
Connect: true,
|
||||||
|
@ -764,7 +761,6 @@ func (d *DNSServer) dispatch(network string, remoteAddr net.Addr, req, resp *dns
|
||||||
}
|
}
|
||||||
|
|
||||||
lookup := serviceLookup{
|
lookup := serviceLookup{
|
||||||
Network: network,
|
|
||||||
Datacenter: datacenter,
|
Datacenter: datacenter,
|
||||||
Service: queryParts[len(queryParts)-1],
|
Service: queryParts[len(queryParts)-1],
|
||||||
Connect: false,
|
Connect: false,
|
||||||
|
@ -800,7 +796,7 @@ func (d *DNSServer) dispatch(network string, remoteAddr net.Addr, req, resp *dns
|
||||||
|
|
||||||
// Allow a "." in the query name, just join all the parts.
|
// Allow a "." in the query name, just join all the parts.
|
||||||
query := strings.Join(queryParts, ".")
|
query := strings.Join(queryParts, ".")
|
||||||
err := d.preparedQueryLookup(cfg, network, datacenter, query, remoteAddr, req, resp, maxRecursionLevel)
|
err := d.preparedQueryLookup(cfg, datacenter, query, remoteAddr, req, resp, maxRecursionLevel)
|
||||||
return ecsNotGlobalError{error: err}
|
return ecsNotGlobalError{error: err}
|
||||||
|
|
||||||
case "addr":
|
case "addr":
|
||||||
|
@ -1295,7 +1291,7 @@ func ednsSubnetForRequest(req *dns.Msg) *dns.EDNS0_SUBNET {
|
||||||
}
|
}
|
||||||
|
|
||||||
// preparedQueryLookup is used to handle a prepared query.
|
// preparedQueryLookup is used to handle a prepared query.
|
||||||
func (d *DNSServer) preparedQueryLookup(cfg *dnsConfig, network, datacenter, query string, remoteAddr net.Addr, req, resp *dns.Msg, maxRecursionLevel int) error {
|
func (d *DNSServer) preparedQueryLookup(cfg *dnsConfig, datacenter, query string, remoteAddr net.Addr, req, resp *dns.Msg, maxRecursionLevel int) error {
|
||||||
// Execute the prepared query.
|
// Execute the prepared query.
|
||||||
args := structs.PreparedQueryExecuteRequest{
|
args := structs.PreparedQueryExecuteRequest{
|
||||||
Datacenter: datacenter,
|
Datacenter: datacenter,
|
||||||
|
@ -1915,7 +1911,7 @@ func (d *DNSServer) resolveCNAME(cfg *dnsConfig, name string, maxRecursionLevel
|
||||||
|
|
||||||
req.SetQuestion(name, dns.TypeANY)
|
req.SetQuestion(name, dns.TypeANY)
|
||||||
// TODO: handle error response
|
// TODO: handle error response
|
||||||
d.dispatch("udp", nil, req, resp, maxRecursionLevel-1)
|
d.dispatch(nil, req, resp, maxRecursionLevel-1)
|
||||||
|
|
||||||
return resp.Answer
|
return resp.Answer
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue