diff --git a/dnscrypt-proxy/coldstart.go b/dnscrypt-proxy/coldstart.go index 7f9d06ef..1c519f1c 100644 --- a/dnscrypt-proxy/coldstart.go +++ b/dnscrypt-proxy/coldstart.go @@ -59,11 +59,13 @@ func HandleCaptivePortalQuery(msg *dns.Msg, question *dns.Question, ips *Captive } } else if question.Qtype == dns.TypeAAAA { for _, xip := range *ips { - if ip := xip.To16(); ip != nil { - rr := new(dns.AAAA) - rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: ttl} - rr.AAAA = ip - respMsg.Answer = append(respMsg.Answer, rr) + if xip.To4() == nil { + if ip := xip.To16(); ip != nil { + rr := new(dns.AAAA) + rr.Hdr = dns.RR_Header{Name: question.Name, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: ttl} + rr.AAAA = ip + respMsg.Answer = append(respMsg.Answer, rr) + } } } } else if question.Qtype == dns.TypeHTTPS { @@ -154,10 +156,10 @@ func addColdStartListener(proxy *Proxy, ipsMap *CaptivePortalMap, listenAddrStr } func ColdStart(proxy *Proxy) (*CaptivePortalHandler, error) { - if len(proxy.captivePortalFile) == 0 { + if len(proxy.captivePortalMapFile) == 0 { return nil, nil } - bin, err := ReadTextFile(proxy.captivePortalFile) + bin, err := ReadTextFile(proxy.captivePortalMapFile) if err != nil { dlog.Warn(err) return nil, err diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index fbbb2aa3..5fd05ea4 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -70,7 +70,7 @@ type Config struct { AllowIP AllowIPConfig `toml:"allowed_ips"` ForwardFile string `toml:"forwarding_rules"` CloakFile string `toml:"cloaking_rules"` - CaptivePortalFile string `toml:"captive_portal_handler"` + CaptivePortals CaptivePortalsConfig `toml:"captive_portals"` StaticsConfig map[string]StaticConfig `toml:"static"` SourcesConfig map[string]SourceConfig `toml:"sources"` BrokenImplementations BrokenImplementationsConfig `toml:"broken_implementations"` @@ -272,6 +272,10 @@ type DNS64Config struct { Resolvers []string `toml:"resolver"` } +type CaptivePortalsConfig struct { + MapFile string `toml:"map_file"` +} + type ConfigFlags struct { List *bool ListAll *bool @@ -579,7 +583,7 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error { proxy.forwardFile = config.ForwardFile proxy.cloakFile = config.CloakFile - proxy.captivePortalFile = config.CaptivePortalFile + proxy.captivePortalMapFile = config.CaptivePortals.MapFile allWeeklyRanges, err := ParseAllWeeklyRanges(config.AllWeeklyRanges) if err != nil { diff --git a/dnscrypt-proxy/example-captive-portal-handler.txt b/dnscrypt-proxy/example-captive-portal-handler.txt deleted file mode 100644 index 61655719..00000000 --- a/dnscrypt-proxy/example-captive-portal-handler.txt +++ /dev/null @@ -1,7 +0,0 @@ -captive.apple.com 17.253.109.201,17.253.113.202 -connectivitycheck.gstatic.com 64.233.165.94 -connectivitycheck.android.com 172.217.20.110 -www.msftncsi.com 2.19.98.8,2.19.98.59 -dns.msftncsi.com 131.107.255.255 -www.msftconnecttest.com 13.107.4.52 -ipv4only.arpa 192.0.0.170,192.0.0.171 diff --git a/dnscrypt-proxy/example-dnscrypt-proxy.toml b/dnscrypt-proxy/example-dnscrypt-proxy.toml index 87a37004..a88320d0 100644 --- a/dnscrypt-proxy/example-dnscrypt-proxy.toml +++ b/dnscrypt-proxy/example-dnscrypt-proxy.toml @@ -346,6 +346,7 @@ reject_ttl = 600 # cloak_ttl = 600 + ########################### # DNS cache # ########################### @@ -381,6 +382,20 @@ cache_neg_max_ttl = 600 +######################################## +# Captive portal handling # +######################################## + +[captive_portals] + +## A file that contains a set of names used by operating systems to +## check for connectivity and captive portals, along with hard-coded +## IP addresses to return. + +map_file = "example-captive-portals.txt" + + + ################################## # Local DoH server # ################################## diff --git a/dnscrypt-proxy/main.go b/dnscrypt-proxy/main.go index 6cf53137..8d1e2b5a 100644 --- a/dnscrypt-proxy/main.go +++ b/dnscrypt-proxy/main.go @@ -15,7 +15,7 @@ import ( ) const ( - AppVersion = "2.0.44" + AppVersion = "2.0.45" DefaultConfigFileName = "dnscrypt-proxy.toml" ) diff --git a/dnscrypt-proxy/plugin_captive_portal.go b/dnscrypt-proxy/plugin_captive_portal.go index 4cefdc59..93df3076 100644 --- a/dnscrypt-proxy/plugin_captive_portal.go +++ b/dnscrypt-proxy/plugin_captive_portal.go @@ -19,6 +19,7 @@ func (plugin *PluginCaptivePortal) Description() string { func (plugin *PluginCaptivePortal) Init(proxy *Proxy) error { plugin.captivePortalMap = proxy.captivePortalMap + dlog.Notice("Captive portals handler enabled") return nil } diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index aa3ee905..85a09a8c 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -44,7 +44,7 @@ type Proxy struct { nxLogFormat string localDoHCertFile string localDoHCertKeyFile string - captivePortalFile string + captivePortalMapFile string localDoHPath string mainProto string cloakFile string