From eabac20beb02bb9029787414b57ccbdea43db6cf Mon Sep 17 00:00:00 2001 From: Donavan Fritz Date: Wed, 21 Feb 2024 15:47:00 -0800 Subject: [PATCH] updates --- .gitea/workflows/main.yaml | 14 ++++++++++++++ Dockerfile | 8 ++++++++ synthetic.go | 28 ++++++++++++++-------------- 3 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 .gitea/workflows/main.yaml create mode 100644 Dockerfile diff --git a/.gitea/workflows/main.yaml b/.gitea/workflows/main.yaml new file mode 100644 index 0000000..fbf2771 --- /dev/null +++ b/.gitea/workflows/main.yaml @@ -0,0 +1,14 @@ +name: Synthetic CoreDNS Plugin CI/CD Build +on: + push: + branches: + - main +jobs: + test: + runs-on: main + steps: + - name: run tests + run: | + set -x + docker build \ + --progress plain . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4d66aff --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# run go test inside a docker container for consistency as acceptance testing +FROM golang:1.21 + +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN go test -v diff --git a/synthetic.go b/synthetic.go index 5e919b8..3430d98 100644 --- a/synthetic.go +++ b/synthetic.go @@ -26,7 +26,7 @@ func (s synthetic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms // Create a new state for this request. This is used to store state and allows us to pass this state := request.Request{W: w, Req: r} - log.Info("Received request for ", state.QName(), " of type ", state.QType()) + log.Debug("Received request for ", state.QName(), " of type ", state.QType()) // // FOR FORWARD LOOKUPS @@ -35,7 +35,7 @@ func (s synthetic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms // if state.QType() == dns.TypeA || state.QType() == dns.TypeAAAA { if strings.HasPrefix(state.Name(), s.Config.prefix) { - log.Info("Possible synthetic response for:", state.QName()) + log.Debug("Possible synthetic response for:", state.QName()) // pull out the ip address ipStr := strings.TrimPrefix(strings.Split(state.Name(), ".")[0], s.Config.prefix) @@ -46,7 +46,7 @@ func (s synthetic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms // respond according to the IP type and the request type if ip != nil { - log.Info("Valid IP from hostname:", ip) + log.Debug("Valid IP from hostname:", ip) // check if ip is within the synthetic network var found bool @@ -58,10 +58,10 @@ func (s synthetic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms } // don't continue if the IP is not in the synthetic network (fall back to recorded response) if found { - log.Info("IP ", ip, " is in synthetic network") + log.Debug("IP ", ip, " is in synthetic network") if ip.To4() == nil && state.QType() == dns.TypeAAAA { - log.Info("Responding to AAAA request for ", state.QName()) + log.Debug("Responding to AAAA request for ", state.QName()) m := new(dns.Msg) m.SetReply(r) hdr := dns.RR_Header{Name: state.QName(), Rrtype: state.QType(), Class: state.QClass(), Ttl: s.Config.ttl} @@ -70,7 +70,7 @@ func (s synthetic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms return dns.RcodeSuccess, nil } if ip.To4() != nil && state.QType() == dns.TypeA { - log.Info("Responding to A request for ", state.QName()) + log.Debug("Responding to A request for ", state.QName()) m := new(dns.Msg) m.SetReply(r) hdr := dns.RR_Header{Name: state.QName(), Rrtype: state.QType(), Class: state.QClass(), Ttl: s.Config.ttl} @@ -79,24 +79,24 @@ func (s synthetic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms return dns.RcodeSuccess, nil } if ip.To4() == nil && state.QType() == dns.TypeA { - log.Info("Responding to A request for ", state.QName(), " with empty answer") + log.Debug("Responding to A request for ", state.QName(), " with empty answer") m := new(dns.Msg) m.SetReply(r) w.WriteMsg(m) return dns.RcodeSuccess, nil } if ip.To4() != nil && state.QType() == dns.TypeAAAA { - log.Info("Responding to AAAA request for ", state.QName(), " with empty answer") + log.Debug("Responding to AAAA request for ", state.QName(), " with empty answer") m := new(dns.Msg) m.SetReply(r) w.WriteMsg(m) return dns.RcodeSuccess, nil } - log.Info("Unexpected code path for: ", state.QName()) + log.Debug("Unexpected code path for: ", state.QName()) } - log.Info("IP not in a valid network: ", ip) + log.Debug("IP not in a valid network: ", ip) } - log.Info("Invalid IP from hostname: ", state.QName()) + log.Debug("Invalid IP from hostname: ", state.QName()) } } @@ -112,16 +112,16 @@ func (s synthetic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms // If the next plugin in the chain's recorded response is success, we go with that. if rc == dns.RcodeSuccess && len(rec.Msg.Answer) > 0 { - log.Info("Next Plugin's answers are acceptable. no synthetic response") + log.Debug("Next Plugin's answers are acceptable. no synthetic response") w.WriteMsg(rec.Msg) return rc, err } if state.QType() == dns.TypePTR { - log.Info("Attempting to inject synthetic response for reverse lookup: ", state.QName()) + log.Debug("Attempting to inject synthetic response for reverse lookup: ", state.QName()) ip := inArpaToIp(state.QName()) - log.Info("Parsed IP: ", ip) + log.Debug("Parsed IP: ", ip) if ip != nil { forward := ipToDomainName(s.Config.prefix, ip, s.Config.forward)