Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions infra/conf/v4/dns_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ import (
)

type DNSOutboundConfig struct {
Network cfgcommon.Network `json:"network"`
Address *cfgcommon.Address `json:"address"`
Port uint16 `json:"port"`
UserLevel uint32 `json:"userLevel"`
Network cfgcommon.Network `json:"network"`
Address *cfgcommon.Address `json:"address"`
Port uint16 `json:"port"`
UserLevel uint32 `json:"userLevel"`
OverrideResponseTtl bool `json:"overrideresponseTtl"`
ResponseTtl uint32 `json:"responseTtl"`
}

func (c *DNSOutboundConfig) Build() (proto.Message, error) {
config := &dns.Config{
Server: &net.Endpoint{
Network: c.Network.Build(),
Port: uint32(c.Port),
},
UserLevel: c.UserLevel,
}
if c.Address != nil {
config.Server.Address = c.Address.Build()
}
return config, nil
config := &dns.Config{
Server: &net.Endpoint{
Network: c.Network.Build(),
Port: uint32(c.Port),
},
UserLevel: c.UserLevel,
OverrideResponseTtl: c.OverrideResponseTtl,
ResponseTtl: c.ResponseTtl,
}
if c.Address != nil {
config.Server.Address = c.Address.Build()
}
return config, nil
}
11 changes: 10 additions & 1 deletion proxy/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,16 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,

var ttl uint32 = 600
if h.config.OverrideResponseTtl {
ttl = h.config.ResponseTtl
// RFC 1035: TTL 32-Bit unsigned Integer, 0 .. 4294967295
const maxTTL uint32 = 4294967295
const minTTL uint32 = 0
if h.config.ResponseTtl > maxTTL {
ttl = maxTTL
} else if h.config.ResponseTtl < minTTL {
ttl = minTTL
} else {
ttl = h.config.ResponseTtl
}
}

switch qType {
Expand Down
Loading