From 774257d003384bb7d0341bcae2f1342bba6c7cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 18 Nov 2024 13:28:02 +0800 Subject: [PATCH] Add `template.custom_fakeip` --- docs/configuration/template.md | 5 +++++ option/template.go | 1 + template/render_dns.go | 12 ++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/configuration/template.md b/docs/configuration/template.md index fc0ce46..d4a5e34 100644 --- a/docs/configuration/template.md +++ b/docs/configuration/template.md @@ -22,6 +22,7 @@ "enable_fakeip": false, "pre_dns_rules": [], "custom_dns_rules": [], + "custom_fakeip": {}, // Inbound @@ -158,6 +159,10 @@ List of [DNS Rule](https://sing-box.sagernet.org/configuration/dns/rule/). No default traffic bypassing DNS rules will be generated if not empty. +#### custom_fakeip + +Custom [FakeIP](https://sing-box.sagernet.org/configuration/dns/fakeip/) template. + #### inbounds List of [Inbound](https://sing-box.sagernet.org/configuration/inbound/). diff --git a/option/template.go b/option/template.go index fa34a0e..59201cc 100644 --- a/option/template.go +++ b/option/template.go @@ -35,6 +35,7 @@ type _Template struct { DisableDNSLeak bool `json:"disable_dns_leak,omitempty"` PreDNSRules []option.DNSRule `json:"pre_dns_rules,omitempty"` CustomDNSRules []option.DNSRule `json:"custom_dns_rules,omitempty"` + CustomFakeIP *option.DNSFakeIPOptions `json:"custom_fakeip,omitempty"` // Inbound Inbounds []option.Inbound `json:"inbounds,omitempty"` diff --git a/template/render_dns.go b/template/render_dns.go index 820e8b3..555c277 100644 --- a/template/render_dns.go +++ b/template/render_dns.go @@ -94,11 +94,15 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error }) } if t.EnableFakeIP { - options.DNS.FakeIP = &option.DNSFakeIPOptions{ - Enabled: true, - Inet4Range: common.Ptr(netip.MustParsePrefix("198.18.0.0/15")), + options.DNS.FakeIP = t.CustomFakeIP + if options.DNS.FakeIP == nil { + options.DNS.FakeIP = &option.DNSFakeIPOptions{} } - if !t.DisableIPv6() { + options.DNS.FakeIP.Enabled = true + if !options.DNS.FakeIP.Inet4Range.IsValid() { + options.DNS.FakeIP.Inet4Range = common.Ptr(netip.MustParsePrefix("198.18.0.0/15")) + } + if !t.DisableIPv6() && !options.DNS.FakeIP.Inet6Range.IsValid() { options.DNS.FakeIP.Inet6Range = common.Ptr(netip.MustParsePrefix("fc00::/18")) } options.DNS.Servers = append(options.DNS.Servers, option.DNSServerOptions{