moved files
This commit is contained in:
		
							parent
							
								
									9adc685a73
								
							
						
					
					
						commit
						0336002980
					
				
							
								
								
									
										24
									
								
								cmd/cooldns.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								cmd/cooldns.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | |||||||
|  | package main | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"flag" | ||||||
|  | 	"log" | ||||||
|  | 	"os" | ||||||
|  | 	"os/signal" | ||||||
|  | 	"syscall" | ||||||
|  | 
 | ||||||
|  | 	cooldns "git.kapelle.org/niklas/cool-dns/internal" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func main() { | ||||||
|  | 	configPath := flag.String("c", "/etc/cool-dns/config.yaml", "path to the config file") | ||||||
|  | 	flag.Parse() | ||||||
|  | 
 | ||||||
|  | 	cooldns.Start(*configPath) | ||||||
|  | 
 | ||||||
|  | 	sig := make(chan os.Signal) | ||||||
|  | 	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) | ||||||
|  | 	s := <-sig | ||||||
|  | 	log.Printf("Signal (%v) received, stopping\n", s) | ||||||
|  | 	os.Exit(0) | ||||||
|  | } | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package main | package cooldns | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| @ -1,15 +1,12 @@ | |||||||
| package main | package cooldns | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"flag" |  | ||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
| 	"log" | 	"log" | ||||||
| 	"net" | 	"net" | ||||||
| 	"os" | 	"os" | ||||||
| 	"os/signal" |  | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"syscall" |  | ||||||
| 
 | 
 | ||||||
| 	"github.com/miekg/dns" | 	"github.com/miekg/dns" | ||||||
| 	"gopkg.in/yaml.v3" | 	"gopkg.in/yaml.v3" | ||||||
| @ -76,7 +73,8 @@ var anyRecordTypes = []uint16{ | |||||||
| 	dns.TypeCAA, | 	dns.TypeCAA, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func start(configPath string) { | // Start starts cooldns | ||||||
|  | func Start(configPath string) { | ||||||
| 	config, err := loadConfig(configPath) | 	config, err := loadConfig(configPath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatalf("Failed to load config: %s\n", err.Error()) | 		log.Fatalf("Failed to load config: %s\n", err.Error()) | ||||||
| @ -419,17 +417,3 @@ func handleRequest(w dns.ResponseWriter, r *dns.Msg, zone zoneView) { | |||||||
| 
 | 
 | ||||||
| 	w.WriteMsg(m) | 	w.WriteMsg(m) | ||||||
| } | } | ||||||
| 
 |  | ||||||
| func main() { |  | ||||||
| 
 |  | ||||||
| 	configPath := flag.String("c", "/etc/cool-dns/config.yaml", "path to the config file") |  | ||||||
| 	flag.Parse() |  | ||||||
| 
 |  | ||||||
| 	start(*configPath) |  | ||||||
| 
 |  | ||||||
| 	sig := make(chan os.Signal) |  | ||||||
| 	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) |  | ||||||
| 	s := <-sig |  | ||||||
| 	log.Printf("Signal (%v) received, stopping\n", s) |  | ||||||
| 	os.Exit(0) |  | ||||||
| } |  | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package main | package cooldns | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
							
								
								
									
										91
									
								
								rr_test.go
									
									
									
									
									
								
							
							
						
						
									
										91
									
								
								rr_test.go
									
									
									
									
									
								
							| @ -1,91 +0,0 @@ | |||||||
| package main |  | ||||||
| 
 |  | ||||||
| import ( |  | ||||||
| 	"net" |  | ||||||
| 	"testing" |  | ||||||
| 
 |  | ||||||
| 	"github.com/miekg/dns" |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| func init() { |  | ||||||
| 	start("test/rrConfig.yaml") |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Helper |  | ||||||
| 
 |  | ||||||
| func request(name string, rrType uint16) (*dns.Msg, error) { |  | ||||||
| 	m := new(dns.Msg) |  | ||||||
| 	m.SetQuestion(dns.Fqdn(name), rrType) |  | ||||||
| 	return dns.Exchange(m, "127.0.0.1:8053") |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func containsA(haystack []dns.RR, name, ip string) bool { |  | ||||||
| 	searchIP := net.ParseIP(ip) |  | ||||||
| 	for _, v := range haystack { |  | ||||||
| 		if v.Header().Name == dns.Fqdn(name) && v.Header().Rrtype == dns.TypeA { |  | ||||||
| 			if t, ok := v.(*dns.A); ok { |  | ||||||
| 				if t.A.Equal(searchIP) { |  | ||||||
| 					return true |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return false |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func containsAAAA(haystack []dns.RR, name, ip string) bool { |  | ||||||
| 	searchIP := net.ParseIP(ip) |  | ||||||
| 	for _, v := range haystack { |  | ||||||
| 		if v.Header().Name == dns.Fqdn(name) && v.Header().Rrtype == dns.TypeAAAA { |  | ||||||
| 			if t, ok := v.(*dns.AAAA); ok { |  | ||||||
| 				if t.AAAA.Equal(searchIP) { |  | ||||||
| 					return true |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return false |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestNormalA(t *testing.T) { |  | ||||||
| 	res, err := request("example.com", dns.TypeA) |  | ||||||
| 	if err != nil { |  | ||||||
| 		t.Error(err) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if !containsA(res.Answer, "example.com", "1.2.3.1") || !containsA(res.Answer, "example.com", "1.2.3.2") { |  | ||||||
| 		t.FailNow() |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestNormalAAAA(t *testing.T) { |  | ||||||
| 	res, err := request("example.com", dns.TypeAAAA) |  | ||||||
| 	if err != nil { |  | ||||||
| 		t.Error(err) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if !containsAAAA(res.Answer, "example.com", "2001:db8:10::1") { |  | ||||||
| 		t.FailNow() |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestNormalSOA(t *testing.T) { |  | ||||||
| 	res, err := request("example.com", dns.TypeSOA) |  | ||||||
| 	if err != nil { |  | ||||||
| 		t.Error(err) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if len(res.Answer) != 1 { |  | ||||||
| 		t.Fatalf("Should only be 1 SOA got %d", len(res.Answer)) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if soa, ok := res.Answer[0].(*dns.SOA); ok { |  | ||||||
| 		if soa.Ns != "ns.example.com." { |  | ||||||
| 			t.Fatal("Wrong SOA rr") |  | ||||||
| 		} |  | ||||||
| 	} else { |  | ||||||
| 		t.Fatal("Answer is not a SOA rr") |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,5 +0,0 @@ | |||||||
| zones: |  | ||||||
| - zone: example.com. |  | ||||||
|   file: zonefile.txt |  | ||||||
| 
 |  | ||||||
| address: 0.0.0.0:8053 |  | ||||||
| @ -1,20 +0,0 @@ | |||||||
| $ORIGIN example.com.      |  | ||||||
| $TTL 3600                |  | ||||||
| example.com.  IN  SOA   ns.example.com. username.example.com. ( 2020091025 7200 3600 1209600 3600 ) |  | ||||||
| example.com.  IN  NS    ns                     |  | ||||||
| example.com.  IN  NS    ns.somewhere.example.  |  | ||||||
| example.com.  IN  MX    10 mail.example.com.   |  | ||||||
| @             IN  MX    20 mail2.example.com.  |  | ||||||
| @             IN  MX    50 mail3               |  | ||||||
| example.com.  IN  A     1.2.3.1              |  | ||||||
| example.com.  IN  A     1.2.3.2 |  | ||||||
|               IN  AAAA  2001:db8:10::1         |  | ||||||
| ns            IN  A     1.2.3.3 |  | ||||||
|               IN  AAAA  2001:db8:10::2         |  | ||||||
| www           IN  CNAME example.com.           |  | ||||||
| wwwtest       IN  CNAME www                    |  | ||||||
| mail          IN  A     1.2.3.4 |  | ||||||
| mail2         IN  A     1.2.3.5 |  | ||||||
| mail3         IN  A     1.2.3.6 |  | ||||||
| *.www         IN  A     1.2.3.7 |  | ||||||
| a.www         IN  A     1.2.3.8 |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user