Skip to content

Commit 369aaf4

Browse files
committed
Allow to configure TTL
1 parent acc2cd5 commit 369aaf4

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

commands/ns.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func init() {
2727
"your zone name (e.g. 'buglloc.com')")
2828
flags.String("ipv4", "127.0.0.1",
2929
"default ipv4 address")
30+
flags.Uint32("ttl", cfg.TTL,
31+
"DNS records TTL")
3032
flags.String("ipv6", "::1",
3133
"default ipv6 address")
3234
flags.String("upstream", "77.88.8.8:53",
@@ -58,5 +60,6 @@ func parseServerConfig(cmd *cobra.Command, args []string) error {
5860
cfg.AllowProxy = !viper.GetBool("NoProxy")
5961
cfg.UseDefault = viper.GetBool("UseDefault")
6062
cfg.Upstream = viper.GetString("Upstream")
63+
cfg.TTL = uint32(viper.GetInt("Ttl"))
6164
return nil
6265
}

pkg/cfg/cfg.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ var (
2121
// Enable "strict" mode
2222
UseDefault bool
2323
AllowProxy bool
24+
TTL uint32 = 0
2425
)

pkg/handlers/cname.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package handlers
33
import (
44
"github.com/buglloc/simplelog"
55
"github.com/miekg/dns"
6+
7+
"github.com/buglloc/rip/pkg/cfg"
68
)
79

810
func CnameHandler(question dns.Question, name string, l log.Logger) (rrs []dns.RR) {
@@ -12,7 +14,7 @@ func CnameHandler(question dns.Question, name string, l log.Logger) (rrs []dns.R
1214
Name: question.Name,
1315
Rrtype: dns.TypeCNAME,
1416
Class: dns.ClassINET,
15-
Ttl: 0,
17+
Ttl: cfg.TTL,
1618
},
1719
Target: dns.Fqdn(subName),
1820
}}

pkg/handlers/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func createIpRR(question dns.Question, ip net.IP) (rr dns.RR) {
8080
Name: question.Name,
8181
Rrtype: question.Qtype,
8282
Class: dns.ClassINET,
83-
Ttl: 0,
83+
Ttl: cfg.TTL,
8484
}
8585

8686
if question.Qtype == dns.TypeA {

0 commit comments

Comments
 (0)