diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index af54317dd..e17bc8a8e 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,3 +1,7 @@ +### 2.13.2 +* Fixing broken answer when hostname is not found +* Fixing ping slowness + ### 2.13.1 * Make sure value column will not break the table (#116) diff --git a/VERSION b/VERSION index 94f15e9cc..0e83a9a9c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.13.1 +2.13.2 diff --git a/dns.go b/dns.go index ec9245a5a..025a478f4 100644 --- a/dns.go +++ b/dns.go @@ -29,7 +29,7 @@ func handleQuestion(respWriter dns.ResponseWriter, reqMsg *dns.Msg) { defer func() { err := recover() if err != nil { - logging.Errorf("status=error, error=%v, stack=%s", ctx, err, string(debug.Stack())) + logging.Errorf("status=fatal-error-handling-question, req=%+v, err=%s, stack=%+v", ctx, reqMsg.Question, err, string(debug.Stack())) } }() @@ -38,7 +38,7 @@ func handleQuestion(respWriter dns.ResponseWriter, reqMsg *dns.Msg) { if questionsQtd != 0 { firstQuestion = reqMsg.Question[0] } else { - logging.Error(ctx, "status=question-is-nil") + logging.Error(ctx, "status=no-questions-to-answer, reqId=%d", reqMsg.Id) return } @@ -49,16 +49,10 @@ func handleQuestion(respWriter dns.ResponseWriter, reqMsg *dns.Msg) { solverFactory := proxy.NewCnameDnsSolverFactory(&proxy.DefaultDnsSolverFactory{}) msg, err := solverFactory.Solve(ctx, firstQuestion, getSolvers()) - if err != nil { - logging.Errorf("status=not-resolved, question=%+v", ctx, firstQuestion, err) - respWriter.WriteMsg(msg) - } else { - logging.Debugf("status=resolved, question=%+v, answers=%+v", ctx, firstQuestion, msg.Answer) - msg.SetReply(reqMsg) - msg.Compress = conf.Compress() - respWriter.WriteMsg(msg) - } - + msg.SetReply(reqMsg) + msg.Compress = conf.Compress() + respWriter.WriteMsg(msg) + logging.Debugf("status=complete, question=%+v, answers=%+v, err=%+v", ctx, firstQuestion, msg.Answer, err) } var solversCreated int32 = 0 diff --git a/docker-compose.yml b/docker-compose.yml index 136703a9f..965d54db2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,7 @@ services: - TERM=xterm - GOPATH=/app - MG_WORK_DIR=/app/src/github.com/mageddo/dns-proxy-server + network_mode: bridge command: tail -f /dev/null app-dps: @@ -22,7 +23,7 @@ services: - ./app:/app working_dir: /app ports: - - 5380:3000 + - 5381:3000 command: tail -f /dev/null # Run from docker image diff --git a/events/local/local.go b/events/local/local.go index e9f32d853..a867e5564 100644 --- a/events/local/local.go +++ b/events/local/local.go @@ -16,7 +16,7 @@ import ( "time" ) -var confPath string = GetConfPath() +var confPath = GetConfPath() func GetConfPath() string { return utils.GetPath(*flags.ConfPath) @@ -29,11 +29,8 @@ func LoadConfiguration() (*LocalConfiguration, error){ RemoteDnsServers: make([][4]byte, 0), } - logging.Infof("status=begin, confPath=%s", confPath) - if _, err := os.Stat(confPath); err == nil { - logging.Info("status=openingFile") f, _ := os.Open(confPath) defer f.Close() @@ -51,16 +48,15 @@ func LoadConfiguration() (*LocalConfiguration, error){ } } } - logging.Info("status=success") + logging.Debugf("status=success-loaded-file, path=%s", confPath) } else { - logging.Info("status=create-new-conf") err := os.MkdirAll(confPath[:strings.LastIndex(confPath, "/")], 0755) if err != nil { - logging.Errorf("status=error-to-create-conf-folder, err=%v", err) + logging.Errorf("status=error-to-create-conf-path, path=%s", confPath) return nil, err } SaveConfiguration(&configuration) - logging.Info("status=success") + logging.Info("status=success-creating-conf-file, path=%s", confPath) } return &configuration, nil } diff --git a/proxy/factory.go b/proxy/factory.go index abf3e316b..607f34631 100644 --- a/proxy/factory.go +++ b/proxy/factory.go @@ -5,6 +5,7 @@ import ( "errors" "github.com/mageddo/go-logging" "github.com/miekg/dns" + "reflect" ) type DnsSolverFactory interface { @@ -14,14 +15,18 @@ type DnsSolverFactory interface { type DefaultDnsSolverFactory struct {} func (*DefaultDnsSolverFactory) Solve(ctx context.Context, question dns.Question, solvers []DnsSolver) (*dns.Msg, error) { - for _, solver := range solvers { + var solver DnsSolver + for _, solver = range solvers { msg, err := solver.Solve(ctx, question) if msg != nil { - logging.Debugf("solver-factory=default, status=found, question=%+v, answers=%d", question, len(msg.Answer)) + logging.Debugf( + "solver=%s, status=found, question=%+v, answers=%d", + ctx, reflect.TypeOf(solver).String(), question, len(msg.Answer), + ) return msg, err } } - logging.Debugf("solver-factory=default, status=not-found, question=%+v", question) + logging.Debugf("status=not-found, lastSolver=%s, question=%+v", ctx, reflect.TypeOf(solver).String(), question) return nil, errors.New("Not solver for the question " + question.Name) } @@ -43,6 +48,7 @@ func (s *CnameDnsSolverFactory) Solve(ctx context.Context, question dns.Question firstAnswer := firstMsg.Answer[0] if firstAnswer.Header().Rrtype == dns.TypeCNAME && firstAnswer.Header().Class == 256 { question.Name = firstAnswer.(*dns.CNAME).Target + logging.Debugf("status=solving-cname, questionName=%s", ctx, question.Name) if secondMsg, err := s.proxy.Solve(ctx, question, solvers); secondMsg != nil { if err != nil { return nil, err diff --git a/proxy/local.go b/proxy/local.go index 284fd3c69..c2701c90e 100644 --- a/proxy/local.go +++ b/proxy/local.go @@ -7,6 +7,7 @@ import ( "github.com/miekg/dns" "golang.org/x/net/context" "net" + "reflect" ) type localDnsSolver struct { @@ -16,9 +17,11 @@ func (s localDnsSolver) Solve(ctx context.Context, question dns.Question) (*dns. questionName := question.Name[:len(question.Name)-1] for _, host := range getAllHosts("." + questionName) { if msg, err := s.solveHostname(ctx, question, host); err == nil { + logging.Debugf("status=found, solver=%s, question=%+v", ctx, reflect.TypeOf(s).String(), question) return msg, nil } } + logging.Debugf("status=not-found, solver=%s, hostname=%+v", ctx, reflect.TypeOf(s).String(), question) return nil, errors.New("hostname not found " + questionName) } @@ -55,7 +58,7 @@ func (s localDnsSolver) solveHostname(ctx context.Context, question dns.Question } activeEnv, _ := conf.GetActiveEnv() if activeEnv == nil { - return nil, errors.New("Not active env found") + return nil, errors.New("Not active env found.") } if hostname, _ := activeEnv.GetHostname(key); hostname != nil {