Przeglądaj źródła

Support per-zone and per-label max_hosts setting

Ask Bjørn Hansen 13 lat temu
rodzic
commit
3f66e931be
3 zmienionych plików z 12 dodań i 4 usunięć
  1. 8 1
      config.go
  2. 1 1
      serve.go
  3. 3 2
      types.go

+ 8 - 1
config.go

@@ -113,12 +113,14 @@ func readZoneFile(zoneName, fileName string) (*Zone, error) {
 			//log.Printf("k: %s v: %#v, T: %T\n", k, v, v)
 
 			switch k {
-			case "ttl", "serial":
+			case "ttl", "serial", "max_hosts":
 				switch option := k; option {
 				case "ttl":
 					Zone.Options.Ttl = int(v.(float64))
 				case "serial":
 					Zone.Options.Serial = int(v.(float64))
+				case "max_hosts":
+					Zone.Options.MaxHosts = int(v.(float64))
 				}
 				continue
 
@@ -159,11 +161,16 @@ func setupZoneData(data map[string]interface{}, Zone *Zone) {
 		label := Zone.Labels[dk]
 		label.Label = dk
 		label.Ttl = Zone.Options.Ttl
+		label.MaxHosts = Zone.Options.MaxHosts
 
 		if ttl, ok := dv["ttl"]; ok {
 			label.Ttl = int(ttl.(float64))
 		}
 
+		if maxHosts, ok := dv["max_hosts"]; ok {
+			label.MaxHosts = int(maxHosts.(float64))
+		}
+
 		for rType, dnsType := range recordTypes {
 
 			var rdata = dv[rType]

+ 1 - 1
serve.go

@@ -89,7 +89,7 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *Zone) {
 		return
 	}
 
-	if servers := labels.Picker(qtype, 4); servers != nil {
+	if servers := labels.Picker(qtype, labels.MaxHosts); servers != nil {
 		var rrs []dns.RR
 		for _, record := range servers {
 			rr := record.RR

+ 3 - 2
types.go

@@ -6,8 +6,9 @@ import (
 )
 
 type Options struct {
-	Serial int
-	Ttl    int
+	Serial   int
+	Ttl      int
+	MaxHosts int
 }
 
 type Record struct {