Compare commits

...

7 Commits

Author SHA1 Message Date
Andrey Meshkov
b54bf94697 Merge: - client: hide dns is starting message by default
* commit '7fade498b910a2492b2e214f0b2a706b51548b34':
  - client: add setDnsRunningStatus action
  - client: save in store dnsStatus even if running false
  - client: hide dns is starting message by default
2019-12-17 22:35:34 +03:00
Artem Baskal
7fade498b9 - client: add setDnsRunningStatus action 2019-12-17 18:54:28 +03:00
Artem Baskal
39640d8190 - client: save in store dnsStatus even if running false 2019-12-17 17:46:59 +03:00
Artem Baskal
242e5e136f - client: hide dns is starting message by default 2019-12-17 16:15:44 +03:00
Simon Zolin
b105f20837 Merge: - DNS: fix slow response to /status and /access/list requests
Close #1264

* commit '8521635f63e9570a4e75033533dec8180e7f130a':
  - DNS: fix slow response to /status and /access/list requests
2019-12-17 15:11:48 +03:00
Simon Zolin
8521635f63 - DNS: fix slow response to /status and /access/list requests 2019-12-17 13:09:03 +03:00
Simon Zolin
04de9d0f7b Merge: - DNS: "custom_ip" blocking mode didn't work after app restart
Close #1262

Squashed commit of the following:

commit bacd683ef5b52e275323a3c07b370ca08702403e
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Mon Dec 16 17:00:49 2019 +0300

    fix

commit 3d4f9626460de3e13a621f2b8e535e9e0939e2bb
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Mon Dec 16 16:54:23 2019 +0300

    fix

commit bf924bf90e9b705883bec88f8d7af11c39c1f322
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Mon Dec 16 16:45:41 2019 +0300

    add test

commit 43338ea3645a025d69dd838bc732344255960bed
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Mon Dec 16 16:07:51 2019 +0300

    - DNS: "custom_ip" blocking mode didn't work after app restart

commit 220f32e713a95d2c67355c61e419dd09df9d42b2
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Mon Dec 16 15:46:01 2019 +0300

    - first run: fix panic on stop in case initialization didn't complete

    e.g. when Stats module can't be initialized because of incompatible file system
2019-12-16 17:04:30 +03:00
9 changed files with 92 additions and 14 deletions

View File

@@ -233,6 +233,7 @@ export const getProfile = () => async (dispatch) => {
export const dnsStatusRequest = createAction('DNS_STATUS_REQUEST');
export const dnsStatusFailure = createAction('DNS_STATUS_FAILURE');
export const dnsStatusSuccess = createAction('DNS_STATUS_SUCCESS');
export const setDnsRunningStatus = createAction('SET_DNS_RUNNING_STATUS');
export const getDnsStatus = () => async (dispatch) => {
dispatch(dnsStatusRequest());
@@ -242,15 +243,17 @@ export const getDnsStatus = () => async (dispatch) => {
dispatch(dnsStatusFailure());
window.location.reload(true);
};
const handleRequestSuccess = (response) => {
const dnsStatus = response.data;
const runningStatus = dnsStatus && dnsStatus.running;
const { running } = dnsStatus;
const runningStatus = dnsStatus && running;
if (runningStatus === true) {
dispatch(dnsStatusSuccess(dnsStatus));
dispatch(getVersion());
dispatch(getTlsStatus());
dispatch(getProfile());
} else {
dispatch(setDnsRunningStatus(running));
}
};

View File

@@ -89,12 +89,13 @@ class App extends Component {
<LoadingBar className="loading-bar" updateTime={1000} />
<Route component={Header} />
<div className="container container--wrap">
{dashboard.processing && !dashboard.isCoreRunning && (
{dashboard.processing && <Loading />}
{!dashboard.isCoreRunning && (
<div className="row row-cards">
<div className="col-lg-12">
<Status reloadPage={this.reloadPage}
message="dns_start"
/>
/>
<Loading />
</div>
</div>

View File

@@ -58,12 +58,13 @@ const settings = handleActions(
const dashboard = handleActions(
{
[actions.setDnsRunningStatus]: (state, { payload }) =>
({ ...state, isCoreRunning: payload }),
[actions.dnsStatusRequest]: state => ({ ...state, processing: true }),
[actions.dnsStatusFailure]: state => ({ ...state, processing: false }),
[actions.dnsStatusSuccess]: (state, { payload }) => {
const {
version,
running,
dns_port: dnsPort,
dns_addresses: dnsAddresses,
upstream_dns: upstreamDns,
@@ -75,7 +76,7 @@ const dashboard = handleActions(
} = payload;
const newState = {
...state,
isCoreRunning: running,
isCoreRunning: true,
processing: false,
dnsVersion: version,
dnsPort,
@@ -187,7 +188,7 @@ const dashboard = handleActions(
},
{
processing: true,
isCoreRunning: false,
isCoreRunning: true,
processingVersion: true,
processingFiltering: true,
processingClients: true,

View File

@@ -119,13 +119,13 @@ type accessListJSON struct {
}
func (s *Server) handleAccessList(w http.ResponseWriter, r *http.Request) {
s.Lock()
s.RLock()
j := accessListJSON{
AllowedClients: s.conf.AllowedClients,
DisallowedClients: s.conf.DisallowedClients,
BlockedHosts: s.conf.BlockedHosts,
}
s.Unlock()
s.RUnlock()
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(j)

View File

@@ -94,7 +94,7 @@ func stringArrayDup(a []string) []string {
// WriteDiskConfig - write configuration
func (s *Server) WriteDiskConfig(c *FilteringConfig) {
s.Lock()
s.RLock()
sc := s.conf.FilteringConfig
*c = sc
c.RatelimitWhitelist = stringArrayDup(sc.RatelimitWhitelist)
@@ -103,7 +103,7 @@ func (s *Server) WriteDiskConfig(c *FilteringConfig) {
c.DisallowedClients = stringArrayDup(sc.DisallowedClients)
c.BlockedHosts = stringArrayDup(sc.BlockedHosts)
c.UpstreamDNS = stringArrayDup(sc.UpstreamDNS)
s.Unlock()
s.RUnlock()
}
// FilteringConfig represents the DNS filtering configuration of AdGuard Home
@@ -233,6 +233,13 @@ func (s *Server) startInternal() error {
func (s *Server) Prepare(config *ServerConfig) error {
if config != nil {
s.conf = *config
if s.conf.BlockingMode == "custom_ip" {
s.conf.BlockingIPAddrv4 = net.ParseIP(s.conf.BlockingIPv4)
s.conf.BlockingIPAddrv6 = net.ParseIP(s.conf.BlockingIPv6)
if s.conf.BlockingIPAddrv4 == nil || s.conf.BlockingIPAddrv6 == nil {
return fmt.Errorf("DNS: invalid custom blocking IP address specified")
}
}
}
if len(s.conf.UpstreamDNS) == 0 {

View File

@@ -424,6 +424,55 @@ func TestNullBlockedRequest(t *testing.T) {
}
}
func TestBlockedCustomIP(t *testing.T) {
rules := "||nxdomain.example.org^\n||null.example.org^\n127.0.0.1 host.example.org\n@@||whitelist.example.org^\n||127.0.0.255\n"
filters := map[int]string{}
filters[0] = rules
c := dnsfilter.Config{}
f := dnsfilter.New(&c, filters)
s := NewServer(f, nil, nil)
conf := ServerConfig{}
conf.UDPListenAddr = &net.UDPAddr{Port: 0}
conf.TCPListenAddr = &net.TCPAddr{Port: 0}
conf.ProtectionEnabled = true
conf.BlockingMode = "custom_ip"
conf.BlockingIPv4 = "bad IP"
conf.UpstreamDNS = []string{"8.8.8.8:53", "8.8.4.4:53"}
err := s.Prepare(&conf)
assert.True(t, err != nil) // invalid BlockingIPv4
conf.BlockingIPv4 = "0.0.0.1"
conf.BlockingIPv6 = "::1"
err = s.Prepare(&conf)
assert.True(t, err == nil)
err = s.Start()
assert.True(t, err == nil, "%s", err)
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
req := createTestMessageWithType("null.example.org.", dns.TypeA)
reply, err := dns.Exchange(req, addr.String())
assert.True(t, err == nil)
assert.True(t, len(reply.Answer) == 1)
a, ok := reply.Answer[0].(*dns.A)
assert.True(t, ok)
assert.True(t, a.A.String() == "0.0.0.1")
req = createTestMessageWithType("null.example.org.", dns.TypeAAAA)
reply, err = dns.Exchange(req, addr.String())
assert.True(t, err == nil)
assert.True(t, len(reply.Answer) == 1)
a6, ok := reply.Answer[0].(*dns.AAAA)
assert.True(t, ok)
assert.True(t, a6.AAAA.String() == "::1")
err = s.Stop()
if err != nil {
t.Fatalf("DNS server failed to stop: %s", err)
}
}
func TestBlockedByHosts(t *testing.T) {
s := createTestServer(t)
err := s.Start()
@@ -652,6 +701,16 @@ func createTestMessage(host string) *dns.Msg {
return &req
}
func createTestMessageWithType(host string, qtype uint16) *dns.Msg {
req := dns.Msg{}
req.Id = dns.Id()
req.RecursionDesired = true
req.Question = []dns.Question{
{Name: host, Qtype: qtype, Qclass: dns.ClassINET},
}
return &req
}
func assertGoogleAResponse(t *testing.T, reply *dns.Msg) {
assertResponse(t, reply, "8.8.8.8")
}

2
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/AdguardTeam/AdGuardHome
go 1.13
require (
github.com/AdguardTeam/dnsproxy v0.23.2
github.com/AdguardTeam/dnsproxy v0.23.3
github.com/AdguardTeam/golibs v0.3.0
github.com/AdguardTeam/urlfilter v0.7.0
github.com/NYTimes/gziphandler v1.1.1

4
go.sum
View File

@@ -1,5 +1,5 @@
github.com/AdguardTeam/dnsproxy v0.23.2 h1:HbBzoe9Pssj4UjvbeBUPHz7cpCt/7/LpVKu4olhPcKk=
github.com/AdguardTeam/dnsproxy v0.23.2/go.mod h1:2qy8rpdfBzKgMPxkHmPdaNK4XZJ322v4KtVGI8s8Bn0=
github.com/AdguardTeam/dnsproxy v0.23.3 h1:RzI9M0sX99t7qnlikvKTPW25sCFzgfBStxUJ+2z1KQI=
github.com/AdguardTeam/dnsproxy v0.23.3/go.mod h1:2qy8rpdfBzKgMPxkHmPdaNK4XZJ322v4KtVGI8s8Bn0=
github.com/AdguardTeam/golibs v0.2.4 h1:GUssokegKxKF13K67Pgl0ZGwqHjNN6X7sep5ik6ORdY=
github.com/AdguardTeam/golibs v0.2.4/go.mod h1:R3M+mAg3nWG4X4Hsag5eef/TckHFH12ZYhK7AzJc8+U=
github.com/AdguardTeam/golibs v0.3.0 h1:1zO8ulGEOdXDDM++Ap4sYfTsT/Z4tZBZtiWSA4ykcOU=

View File

@@ -70,6 +70,9 @@ func initDNSServer() error {
sessFilename := filepath.Join(baseDir, "sessions.db")
config.auth = InitAuth(sessFilename, config.Users, config.WebSessionTTLHours*60*60)
if config.auth == nil {
return fmt.Errorf("Couldn't initialize Auth module")
}
config.Users = nil
Context.rdns = InitRDNS(Context.dnsServer, &Context.clients)
@@ -254,6 +257,10 @@ func reconfigureDNSServer() error {
}
func stopDNSServer() error {
if !isRunning() {
return nil
}
err := Context.dnsServer.Stop()
if err != nil {
return errorx.Decorate(err, "Couldn't stop forwarding DNS server")