implemented ANY type
This commit is contained in:
		
							parent
							
								
									c283d7a108
								
							
						
					
					
						commit
						a3ab188219
					
				
							
								
								
									
										27
									
								
								coolDns.go
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								coolDns.go
									
									
									
									
									
								
							@ -43,6 +43,18 @@ type configZone struct {
 | 
			
		||||
	ACL  []string `yaml:"acl"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var anyRecordTypes = []uint16{
 | 
			
		||||
	dns.TypeSOA,
 | 
			
		||||
	dns.TypeA,
 | 
			
		||||
	dns.TypeAAAA,
 | 
			
		||||
	dns.TypeNS,
 | 
			
		||||
	dns.TypeCNAME,
 | 
			
		||||
	dns.TypeMX,
 | 
			
		||||
	dns.TypeTXT,
 | 
			
		||||
	dns.TypeSRV,
 | 
			
		||||
	dns.TypeCAA,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func loadConfig() (*config, error) {
 | 
			
		||||
	file, err := ioutil.ReadFile("config.yml")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@ -172,6 +184,13 @@ func createServer(zones []zone, config config, aclList map[string]*net.IPNet) *d
 | 
			
		||||
			for _, q := range r.Question {
 | 
			
		||||
				rrs := z.rr[q.Qtype]
 | 
			
		||||
 | 
			
		||||
				// Handle ANY
 | 
			
		||||
				if q.Qtype == dns.TypeANY {
 | 
			
		||||
					for _, rrType := range anyRecordTypes {
 | 
			
		||||
						m.Answer = append(m.Answer, z.rr[rrType][q.Name]...)
 | 
			
		||||
					}
 | 
			
		||||
				} else {
 | 
			
		||||
					// Handle any other type
 | 
			
		||||
					m.Answer = append(m.Answer, rrs[q.Name]...)
 | 
			
		||||
 | 
			
		||||
					// Check for wildcard
 | 
			
		||||
@ -185,12 +204,16 @@ func createServer(zones []zone, config config, aclList map[string]*net.IPNet) *d
 | 
			
		||||
							m.Answer = append(m.Answer, newRR)
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// Handle extras
 | 
			
		||||
				switch q.Qtype {
 | 
			
		||||
				// Dont handle extra stuff when answering ANY request
 | 
			
		||||
				// case dns.TypeANY:
 | 
			
		||||
				// 	fallthrough
 | 
			
		||||
				case dns.TypeMX:
 | 
			
		||||
					// Resolve MX domains
 | 
			
		||||
					for _, mxRR := range rrs[q.Name] {
 | 
			
		||||
					for _, mxRR := range m.Answer {
 | 
			
		||||
						if t, ok := mxRR.(*dns.MX); ok {
 | 
			
		||||
							m.Extra = append(m.Extra, z.rr[dns.TypeA][t.Mx]...)
 | 
			
		||||
							m.Extra = append(m.Extra, z.rr[dns.TypeAAAA][t.Mx]...)
 | 
			
		||||
@ -211,7 +234,7 @@ func createServer(zones []zone, config config, aclList map[string]*net.IPNet) *d
 | 
			
		||||
					}
 | 
			
		||||
				case dns.TypeNS:
 | 
			
		||||
					// Resove NS records
 | 
			
		||||
					for _, nsRR := range rrs[q.Name] {
 | 
			
		||||
					for _, nsRR := range m.Answer {
 | 
			
		||||
						if t, ok := nsRR.(*dns.NS); ok {
 | 
			
		||||
							m.Extra = append(m.Extra, z.rr[dns.TypeA][t.Ns]...)
 | 
			
		||||
							m.Extra = append(m.Extra, z.rr[dns.TypeAAAA][t.Ns]...)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user