mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	plugin/etcd: Filter empty host field by qtype (#2499)
When a query, different from a TXT lookup is performed, all services with a missing `Host` field should be filtered out, as these otherwize cause a line in the answer section with a single dot (`.`) as the result. This behavior manifests for example when a TXT record is present on a domain, eg. an A or SRV lookup is performed on said domain. If there are no services containing a `Host` field, a `NODATA` response should be given. If there are other Services, these alone should be returned for the query. Filter any service that has an empty Host field from all lookup types other than TXT to solve this issue. At the same time the check for empty `Text` fields in TXT queries are also moved to the same check in the etcd ServiceBackend.
This commit is contained in:
		
				
					committed by
					
						 Miek Gieben
						Miek Gieben
					
				
			
			
				
	
			
			
			
						parent
						
							e343556687
						
					
				
				
					commit
					a84c26d78b
				
			| @@ -78,7 +78,7 @@ func (e *Etcd) Records(state request.Request, exact bool) ([]msg.Service, error) | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	segments := strings.Split(msg.Path(name, e.PathPrefix), "/") | ||||
| 	return e.loopNodes(r.Kvs, segments, star) | ||||
| 	return e.loopNodes(r.Kvs, segments, star, state.QType()) | ||||
| } | ||||
|  | ||||
| func (e *Etcd) get(path string, recursive bool) (*etcdcv3.GetResponse, error) { | ||||
| @@ -115,7 +115,7 @@ func (e *Etcd) get(path string, recursive bool) (*etcdcv3.GetResponse, error) { | ||||
| 	return r, nil | ||||
| } | ||||
|  | ||||
| func (e *Etcd) loopNodes(kv []*mvccpb.KeyValue, nameParts []string, star bool) (sx []msg.Service, err error) { | ||||
| func (e *Etcd) loopNodes(kv []*mvccpb.KeyValue, nameParts []string, star bool, qType uint16) (sx []msg.Service, err error) { | ||||
| 	bx := make(map[msg.Service]struct{}) | ||||
| Nodes: | ||||
| 	for _, n := range kv { | ||||
| @@ -149,7 +149,10 @@ Nodes: | ||||
| 		if serv.Priority == 0 { | ||||
| 			serv.Priority = priority | ||||
| 		} | ||||
| 		sx = append(sx, *serv) | ||||
|  | ||||
| 		if shouldInclude(serv, qType) { | ||||
| 			sx = append(sx, *serv) | ||||
| 		} | ||||
| 	} | ||||
| 	return sx, nil | ||||
| } | ||||
| @@ -173,3 +176,13 @@ func (e *Etcd) TTL(kv *mvccpb.KeyValue, serv *msg.Service) uint32 { | ||||
| 	} | ||||
| 	return serv.TTL | ||||
| } | ||||
|  | ||||
| // shouldInclude returns true if the service should be included in a list of records, given the qType. For all the | ||||
| // currently supported lookup types, the only one to allow for an empty Host field in the service are TXT records. | ||||
| // Similarly, the TXT record in turn requires the Text field to be set. | ||||
| func shouldInclude(serv *msg.Service, qType uint16) bool { | ||||
| 	if qType == dns.TypeTXT { | ||||
| 		return serv.Text != "" | ||||
| 	} | ||||
| 	return serv.Host != "" | ||||
| } | ||||
		Reference in New Issue
	
	Block a user