Skip to content

Commit

Permalink
new: add default dns with fragment in doh
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jan 30, 2024
1 parent 5e8fbcb commit 39b3309
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
67 changes: 59 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
Address: configOpt.RemoteDnsAddress,
AddressResolver: "dns-direct",
Strategy: configOpt.RemoteDnsDomainStrategy,
Detour: "select",
},
{
Tag: "dns-trick-direct",
Address: "https://sky.rethinkdns.com/",
// AddressResolver: "dns-local",
Strategy: configOpt.DirectDnsDomainStrategy,
Detour: "direct-fragment",
},
{
Tag: "dns-direct",
Expand Down Expand Up @@ -188,6 +194,7 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
parsedUrl, err := url.Parse(fmt.Sprintf("https://%s", remoteDNSAddress))
if err == nil && net.ParseIP(parsedUrl.Host) == nil {
directDNSDomains = append(directDNSDomains, fmt.Sprintf("full:%s", parsedUrl.Host))
//TODO: IS it really needed
}

routeRules := []option.Rule{
Expand Down Expand Up @@ -333,6 +340,7 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
},
},
)

options.Route = &option.RouteOptions{
Rules: routeRules,
AutoDetectInterface: true,
Expand All @@ -352,12 +360,11 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
if err != nil {
return nil, err
}
if err == nil {
if serverDomain != "" {
directDNSDomains = append(directDNSDomains, serverDomain)
}
out = *outbound

if serverDomain != "" {
directDNSDomains = append(directDNSDomains, serverDomain)
}
out = *outbound

switch out.Type {
case C.TypeDirect, C.TypeBlock, C.TypeDNS:
Expand Down Expand Up @@ -405,6 +412,19 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
Tag: "direct",
Type: C.TypeDirect,
},
{
Tag: "direct-fragment",
Type: C.TypeDirect,
DirectOptions: option.DirectOutboundOptions{
DialerOptions: option.DialerOptions{
TLSFragment: &option.TLSFragmentOptions{
Enabled: true,
Size: configOpt.TLSTricks.FragmentSize,
Sleep: configOpt.TLSTricks.FragmentSleep,
},
},
},
},
{
Tag: "bypass",
Type: C.TypeDirect,
Expand All @@ -415,9 +435,21 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
},
}...,
)

if len(directDNSDomains) > 0 {
domains := strings.Join(removeDuplicateStr(directDNSDomains), ",")
trickDnsDomains := []string{}
directDNSDomains = removeDuplicateStr(directDNSDomains)
for i, d := range directDNSDomains {

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, android)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, android)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, android)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, android)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, linux-amd64, x64)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, windows-amd64, x64)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (macos-11, macos-universal)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (macos-11, macos-universal)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (macos-11, ios)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (macos-11, ios)

i declared and not used

Check failure on line 441 in config/config.go

View workflow job for this annotation

GitHub Actions / build (macos-11, ios)

i declared and not used
if isBlockedDomain(d) {
trickDnsDomains = append(trickDnsDomains, d)
}
}
trickDomains := strings.Join(trickDnsDomains, ",")
trickRule := Rule{Domains: trickDomains, Outbound: "bypass"}
trickdnsRule := trickRule.MakeDNSRule()
trickdnsRule.Server = "dns-trick-direct"
options.DNS.Rules = append([]option.DNSRule{{Type: C.RuleTypeDefault, DefaultOptions: trickdnsRule}}, options.DNS.Rules...)

domains := strings.Join(directDNSDomains, ",")
directRule := Rule{Domains: domains, Outbound: "bypass"}
dnsRule := directRule.MakeDNSRule()
dnsRule.Server = "dns-direct"
Expand All @@ -426,6 +458,25 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options

return &options, nil
}
func isBlockedDomain(domain string) bool {
if strings.HasPrefix("full:", domain) {
return false
}
ips, err := net.LookupHost(domain)
if err != nil {
// fmt.Println(err)
return true
}

// Print the IP addresses associated with the domain
fmt.Printf("IP addresses for %s:\n", domain)
for _, ip := range ips {
if strings.HasPrefix(ip, "10.") {
return true
}
}
return false
}

func applyOverrides(overrides ConfigOptions, options option.Options) *option.Options {
if overrides.EnableClashApi {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ require (
lukechampine.com/blake3 v1.2.1 // indirect
)

replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240129222136-bef8c180eaef
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240130115748-5838de40349e

replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5X
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240129222136-bef8c180eaef h1:ligclNc3H9xwgaSwnIhxp63nEAvYJ8fNKi7+UTER31E=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240129222136-bef8c180eaef/go.mod h1:B74zKdMcH3ZEmCi2OUqJTvEXCNtNQjivUEQ20y/5XQM=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240130115748-5838de40349e h1:FhrU990kkhxRoFAMvEZwUyM05s1AWBn7lzwijl9ucq0=
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240130115748-5838de40349e/go.mod h1:B74zKdMcH3ZEmCi2OUqJTvEXCNtNQjivUEQ20y/5XQM=
github.com/hiddify/ray2sing v0.0.0-20240127015415-b0b85dcbf102 h1:4vKmPE8AyvsBYuZmjGkPnsju8ZzVxEjC9I96uqxX5+o=
github.com/hiddify/ray2sing v0.0.0-20240127015415-b0b85dcbf102/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 h1:neOb+wzHbWLNZ2sHFEV4+GTuqORO7/MndQLFW8FjUY8=
Expand Down

0 comments on commit 39b3309

Please sign in to comment.