Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mosajjal/sniproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mosajjal committed May 18, 2023
2 parents f179907 + f2a7afe commit e7b7e62
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 2 additions & 0 deletions config.defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
general:
# Upsteam DNS URI. examples: Upstream DNS URI. examples: udp://1.1.1.1:53, tcp://1.1.1.1:53, tcp-tls://1.1.1.1:853, https://dns.google/dns-query
upstream_dns: udp://8.8.8.8:53
# enable send DNS through socks5
upstream_dns_over_socks5: false
# Use a SOCKS proxy for upstream HTTP/HTTPS traffic. Example: socks5://admin:
upstream_socks5:
# DNS Port to listen on. Should remain 53 in most cases. MUST NOT be empty
Expand Down
1 change: 1 addition & 0 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func processQuestion(q dns.Question, decision acl.Decision) ([]dns.RR, error) {

// Otherwise do an upstream query and use that answer.
default:
dnslog.Debug().Msgf("perform external query for domain %s", q.Name)
resp, rtt, err := c.dnsClient.performExternalAQuery(q.Name, q.Qtype)
if err != nil {
return nil, err
Expand Down
37 changes: 22 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ import (
)

type runConfig struct {
PublicIPv4 string `yaml:"public_ipv4"`
PublicIPv6 string `yaml:"public_ipv6"`
UpstreamDNS string `yaml:"upstream_dns"`
UpstreamSOCKS5 string `yaml:"upstream_socks5"`
BindDNSOverUDP string `yaml:"bind_dns_over_udp"`
BindDNSOverTCP string `yaml:"bind_dns_over_tcp"`
BindDNSOverTLS string `yaml:"bind_dns_over_tls"`
BindDNSOverQuic string `yaml:"bind_dns_over_quic"`
TLSCert string `yaml:"tls_cert"`
TLSKey string `yaml:"tls_key"`
BindHTTP string `yaml:"bind_http"`
BindHTTPS string `yaml:"bind_https"`
Interface string `yaml:"interface"`
BindPrometheus string `yaml:"bind_prometheus"`
PublicIPv4 string `yaml:"public_ipv4"`
PublicIPv6 string `yaml:"public_ipv6"`
UpstreamDNS string `yaml:"upstream_dns"`
UpstreamDNSOverSocks5 bool `yaml:"upstream_dns_over_socks5"`
UpstreamSOCKS5 string `yaml:"upstream_socks5"`
BindDNSOverUDP string `yaml:"bind_dns_over_udp"`
BindDNSOverTCP string `yaml:"bind_dns_over_tcp"`
BindDNSOverTLS string `yaml:"bind_dns_over_tls"`
BindDNSOverQuic string `yaml:"bind_dns_over_quic"`
TLSCert string `yaml:"tls_cert"`
TLSKey string `yaml:"tls_key"`
BindHTTP string `yaml:"bind_http"`
BindHTTPS string `yaml:"bind_https"`
Interface string `yaml:"interface"`
BindPrometheus string `yaml:"bind_prometheus"`

acl []acl.ACL

Expand Down Expand Up @@ -273,6 +274,7 @@ func main() {
}

c.UpstreamDNS = generalConfig.String("upstream_dns")
c.UpstreamDNSOverSocks5 = generalConfig.Bool("upstream_dns_over_socks5")
c.UpstreamSOCKS5 = generalConfig.String("upstream_socks5")
c.BindDNSOverUDP = generalConfig.String("bind_dns_over_udp")
c.BindDNSOverTCP = generalConfig.String("bind_dns_over_tcp")
Expand Down Expand Up @@ -382,7 +384,12 @@ func main() {
c.dialer = proxy.Direct
}

tmp, err := dnsclient.New(c.UpstreamDNS, true, c.UpstreamSOCKS5)
dnsProxy := c.UpstreamSOCKS5
if c.UpstreamSOCKS5 != "" && !c.UpstreamDNSOverSocks5 {
logger.Debug().Msg("disabling socks5 for dns")
dnsProxy = ""
}
tmp, err := dnsclient.New(c.UpstreamDNS, true, dnsProxy)
if err != nil {
logger.Error().Msgf("error setting up dns client, removing proxy if provided: %v", err)
tmp, err = dnsclient.New(c.UpstreamDNS, false, "")
Expand Down

0 comments on commit e7b7e62

Please sign in to comment.