mirror of
				https://github.com/miekg/dns.git
				synced 2025-11-03 20:21:24 +01:00 
			
		
		
		
	WIP kill otherdata for cname and dname
This commit is contained in:
		
							parent
							
								
									4bca364480
								
							
						
					
					
						commit
						a2fc07f45a
					
				
							
								
								
									
										26
									
								
								sanitize.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								sanitize.go
									
									
									
									
									
								
							@ -6,12 +6,30 @@ package dns
 | 
				
			|||||||
// TODO(miek): This function will be extended to also look for CNAMEs and DNAMEs.
 | 
					// TODO(miek): This function will be extended to also look for CNAMEs and DNAMEs.
 | 
				
			||||||
// if found, it will prune rrs from the "other data" that can exist. Example:
 | 
					// if found, it will prune rrs from the "other data" that can exist. Example:
 | 
				
			||||||
// if it finds a: a.miek.nl. CNAME foo, all other RRs with the ownername a.miek.nl.
 | 
					// if it finds a: a.miek.nl. CNAME foo, all other RRs with the ownername a.miek.nl.
 | 
				
			||||||
// will be removed.
 | 
					// will be removed. When a DNAME is found all RRs with an ownername below that of
 | 
				
			||||||
 | 
					// the DNAME will be removed.
 | 
				
			||||||
func Dedup(rrs []RR) []RR {
 | 
					func Dedup(rrs []RR) []RR {
 | 
				
			||||||
	m := make(map[string]RR)
 | 
						m := make(map[string]RR)
 | 
				
			||||||
	keys := make([]string, 0, len(rrs))
 | 
						keys := make([]string, 0, len(rrs))
 | 
				
			||||||
 | 
						var cname map[nameClass]bool
 | 
				
			||||||
 | 
						var dname map[nameClass]bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, r := range rrs {
 | 
						for _, r := range rrs {
 | 
				
			||||||
 | 
							switch r.Header().Rrtype {
 | 
				
			||||||
 | 
							case TypeCNAME:
 | 
				
			||||||
 | 
								if cname == nil {
 | 
				
			||||||
 | 
									cname = make(map[nameClass]bool)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								cname[nameClass{r.Header().Name, r.Header().Class}] = true
 | 
				
			||||||
 | 
							case TypeDNAME:
 | 
				
			||||||
 | 
								if dname == nil {
 | 
				
			||||||
 | 
									dname = make(map[nameClass]bool)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								dname[nameClass{r.Header().Name, r.Header().Class}] = true
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								if
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		key := normalizedString(r)
 | 
							key := normalizedString(r)
 | 
				
			||||||
		keys = append(keys, key)
 | 
							keys = append(keys, key)
 | 
				
			||||||
		if _, ok := m[key]; ok {
 | 
							if _, ok := m[key]; ok {
 | 
				
			||||||
@ -39,6 +57,12 @@ func Dedup(rrs []RR) []RR {
 | 
				
			|||||||
	return rrs[:i]
 | 
						return rrs[:i]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// nameClass is used to index the CNAME and DNAME maps.
 | 
				
			||||||
 | 
					type nameClass struct {
 | 
				
			||||||
 | 
						name string
 | 
				
			||||||
 | 
						class uint16
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// normalizedString returns a normalized string from r. The TTL
 | 
					// normalizedString returns a normalized string from r. The TTL
 | 
				
			||||||
// is removed and the domain name is lowercased.
 | 
					// is removed and the domain name is lowercased.
 | 
				
			||||||
func normalizedString(r RR) string {
 | 
					func normalizedString(r RR) string {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user