Skip to content

Commit

Permalink
MOD: Fixed plugins bug
Browse files Browse the repository at this point in the history
  • Loading branch information
oif committed Oct 26, 2017
1 parent 0c41af9 commit b343f3d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cmd/apexd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
inbound "github.com/oif/apex/pkg/engine/v1"
engine "github.com/oif/apex/pkg/engine/v1"
"github.com/oif/apex/plugin/cache"
"github.com/oif/apex/plugin/gdns"
"github.com/oif/apex/plugin/statistics"
Expand All @@ -11,7 +11,7 @@ import (

func main() {
log.SetLevel(log.WarnLevel)
s := new(inbound.Server)
s := new(engine.Server)
s.ListenAddress = ":53"
s.ListenProtocol = []string{"udp"}
s.RegisterPlugins(func() *statistics.Plugin {
Expand Down
39 changes: 26 additions & 13 deletions plugin/cache/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@ package cache
import "github.com/miekg/dns"

type item struct {
Rcode int
Authoritative bool
AuthenticatedData bool
RecursionDesired bool
RecursionAvailable bool
AuthenticatedData bool
CheckingDisabled bool
Rcode int
Answer []dns.RR
Ns []dns.RR
Extra []dns.RR

originTTL uint32
storedAt uint32
}

func newItem(m *dns.Msg) *item {
i := new(item)
i.Rcode = m.Rcode
i.Authoritative = m.Authoritative
i.AuthenticatedData = m.AuthenticatedData
i.RecursionDesired = m.RecursionDesired
i.RecursionAvailable = m.RecursionAvailable
i.AuthenticatedData = m.AuthenticatedData
i.CheckingDisabled = m.CheckingDisabled

// fmt.Printf("ans %v", m.Answer)

i.Answer = m.Answer
i.Ns = m.Ns
i.Extra = make([]dns.RR, len(m.Extra))
Expand All @@ -36,14 +44,19 @@ func newItem(m *dns.Msg) *item {
}

func (i *item) replyToMsg(m *dns.Msg) {
m.Authoritative = false
m.AuthenticatedData = i.AuthenticatedData
m.RecursionAvailable = i.RecursionAvailable
m.Rcode = i.Rcode
m.Compress = true
tmp := new(dns.Msg)
tmp.SetReply(m)
tmp.Compress = true
tmp.Authoritative = false
tmp.Rcode = i.Rcode
// m.RecursionDesired = i.RecursionDesired
tmp.RecursionAvailable = i.RecursionAvailable
tmp.AuthenticatedData = i.AuthenticatedData
// m.CheckingDisabled = i.CheckingDisabled

m.Answer = i.Answer
m.Ns = i.Ns
m.Extra = i.Extra
tmp.Answer = i.Answer
tmp.Ns = i.Ns
tmp.Extra = i.Extra

tmp.CopyTo(m)
}
7 changes: 7 additions & 0 deletions plugin/gdns/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func (p *Plugin) Patch(c *plugin.Context) {
c.AbortWithError(errors.New(comment))
return
}
c.Msg.Rcode = response.Status
c.Msg.Truncated = response.Truncated
c.Msg.RecursionDesired = response.RecursionDesired
c.Msg.RecursionAvailable = response.RecursionAvailable
c.Msg.AuthenticatedData = response.AuthenticatedData
c.Msg.CheckingDisabled = response.CheckingDisabled
c.Msg.Response = true

for _, ans := range response.Answer {
// construct every response for dnsPack
Expand Down
6 changes: 3 additions & 3 deletions plugin/statistics/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ func (p *Plugin) AfterResponse(c *plugin.Context, err error) {
"response_time": responseTime,
}).Info("Response time usage statistics")
// write influxdb
go func() {
go func(responseTime int64) {
err := p.pushResponsePoint(c.Msg.Question[0].Qtype, c.Msg.Question[0].Name, responseTime, !c.HasError())
if err != nil {

}
}()
}(responseTime)
}

// Patch the dns pakcage
func (p *Plugin) Patch(c *plugin.Context) {}

func makeNanoTimestamp() int64 {
return time.Now().UnixNano() / int64(time.Microsecond)
return time.Now().UnixNano() / int64(time.Millisecond)
}

func (p *Plugin) pushResponsePoint(qtype uint16, name string, responseTime int64, isSuccess bool) (err error) {
Expand Down

0 comments on commit b343f3d

Please sign in to comment.