dae icon indicating copy to clipboard operation
dae copied to clipboard

[Bug Report] DNS: Preserve upstream TTL when dial_mode == ip

Open tomaegg opened this issue 5 months ago • 2 comments

Checks

  • [x] I have searched the existing issues
  • [x] I have read the documentation
  • [x] Is it your first time sumbitting an issue

Current Behavior

Problem: ttl of dns response is zero when dial mode is "ip", which should be kept with its original ttl

According to the code of dae in master branch, dae set ttl of upstream dns response zero, which is designed to make all dns request go through dae with dial mode == domain*.

// Set ttl.
for i := range msg.Answer {
	// Set TTL = zero. This requests applications must resend every request.
	// However, it may be not defined in the standard.
	msg.Answer[i].Header().Ttl = 0
}

However, when dial mode == ip, there is no need to set zero ttl, and keeping its original ttl is acceptable.

I prepare to make a PR to solve this problem. My solution:

  1. add dial_mode field to dns controller to judge dial mode
  2. when dial_mode is ip, keep dns cache; set ttl with the minimal ttl of msg.Answer. In current master branch, dns controller fetches the ttl of first answer as follows.
	// Get TTL.
	var ttl uint32
	for i := range msg.Answer {
		if ttl == 0 {
			ttl = msg.Answer[i].Header().Ttl
			break
		}
	}
	if ttl == 0 {
		// It seems no answers (NXDomain).
		ttl = minFirefoxCacheTtl
	}

Knowing that the developer @LostAttractor is refactoring the dns module of dae. So I wonder whether the solution above is acceptable? Or Maybe as a temporary solution. Or should I wait for the dns module to be refactored completely?

Expected Behavior

Upstream TTL of DNS query is preserved

Steps to Reproduce

set dial mode ip and check the answer of nslookup or something else, we could find the ttl of upstream is zero

  • Dae: version v1.0.0, go runtime go1.23.9 linux/arm64
  • OS: immortalwrt, archlinux could also reproduce
  • Kernel: Linux ImmortalWrt 6.6.86 #0 SMP Tue Apr 15 11:38:42 2025 aarch64 GNU/Linux

Environment

  • Dae version (use dae --version):
  • OS (e.g cat /etc/os-release):
  • Kernel (e.g. uname -a):
  • Others:

Anything else?

No response

tomaegg avatar Aug 08 '25 09:08 tomaegg

Thanks for opening this issue!

dae-prow[bot] avatar Aug 08 '25 09:08 dae-prow[bot]

https://github.com/LostAttractor/dae/tree/feat https://github.com/LostAttractor/dae/tree/next (breaking changes很多) 此问题在我的开发分支中已经完全解决,但向上游合并可能还需要一些时间

LostAttractor avatar Aug 09 '25 18:08 LostAttractor