Skip to content

Commit

Permalink
Add template.custom_fakeip
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 18, 2024
1 parent ea777c2 commit 774257d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/configuration/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"enable_fakeip": false,
"pre_dns_rules": [],
"custom_dns_rules": [],
"custom_fakeip": {},

// Inbound

Expand Down Expand Up @@ -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/).
Expand Down
1 change: 1 addition & 0 deletions option/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
12 changes: 8 additions & 4 deletions template/render_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 774257d

Please sign in to comment.