Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of DNSTap extra field on outgoing messages #547

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dnsutils/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,11 @@ func (dm *DNSMessage) ToDNSTap() ([]byte, error) {

dt.Message = msg

// add dnstap extra
if len(dm.DNSTap.Extra) > 0 {
dt.Extra = []byte(dm.DNSTap.Extra)
}

data, err := proto.Marshal(dt)
if err != nil {
return nil, err
Expand Down
28 changes: 28 additions & 0 deletions dnsutils/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,36 @@ import (
"testing"

"github.com/dmachard/go-dnscollector/pkgconfig"
"github.com/dmachard/go-dnstap-protobuf"
"google.golang.org/protobuf/proto"
)

func TestDnsMessage_Encode_ToDNSTap(t *testing.T) {
dm := GetFakeDNSMessageWithPayload()
dm.DNSTap.Extra = "extra:value"

// encode to dnstap
tapMsg, err := dm.ToDNSTap()
if err != nil {
t.Fatalf("could not encode to dnstap: %v\n", err)
}

// decode dnstap message
dt := &dnstap.Dnstap{}
err = proto.Unmarshal(tapMsg, dt)
if err != nil {
t.Fatalf("error to decode dnstap: %v", err)
}

if string(dt.GetIdentity()) != dm.DNSTap.Identity {
t.Errorf("identify field should be equal got=%s", string(dt.GetIdentity()))
}

if string(dt.GetExtra()) != dm.DNSTap.Extra {
t.Errorf("extra field should be equal got=%s", string(dt.GetExtra()))
}
}

func TestDnsMessage_Json_Reference(t *testing.T) {
dm := DNSMessage{}
dm.Init()
Expand Down
41 changes: 0 additions & 41 deletions processors/dnstap.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,46 +120,8 @@ func (d *DNSTapProcessor) Stop() {
d.LogInfo("stopping to process...")
d.stopRun <- true
<-d.doneRun

// d.LogInfo("stopping to monitor loggers...")
// d.stopMonitor <- true
// <-d.doneMonitor
}

// func (d *DNSTapProcessor) MonitorLoggers() {
// // watchInterval := 10 * time.Second
// // bufferFull := time.NewTimer(watchInterval)
// MONITOR_LOOP:
// for {
// select {
// case <-d.stopMonitor:
// // close(d.dropped)
// // bufferFull.Stop()
// d.doneMonitor <- true
// break MONITOR_LOOP

// case loggerName := <-d.dropped:
// if _, ok := d.droppedCount[loggerName]; !ok {
// d.droppedCount[loggerName] = 1
// } else {
// d.droppedCount[loggerName]++
// }

// case <-bufferFull.C:
// for v, k := range d.droppedCount {
// if k > 0 {
// d.LogError("logger[%s] buffer is full, %d packet(s) dropped", v, k)
// d.droppedCount[v] = 0
// }
// }
// bufferFull.Reset(watchInterval)

// }
// }
// d.LogInfo("monitor terminated")
// }

// func (d *DNSTapProcessor) Run(loggersChannel []chan dnsutils.DNSMessage, loggersName []string) {
func (d *DNSTapProcessor) Run(defaultWorkers []pkgutils.Worker, droppedworkers []pkgutils.Worker) {
dt := &dnstap.Dnstap{}

Expand All @@ -170,9 +132,6 @@ func (d *DNSTapProcessor) Run(defaultWorkers []pkgutils.Worker, droppedworkers [
// prepare enabled transformers
transforms := transformers.NewTransforms(&d.config.IngoingTransformers, d.logger, d.name, defaultRoutes, d.ConnID)

// start goroutine to count dropped messsages
// go d.MonitorLoggers()

// read incoming dns message
d.LogInfo("waiting dns message to process...")
RUN_LOOP:
Expand Down
Loading