Skip to content

Commit

Permalink
Add PowerDNS tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoiccool committed Apr 8, 2022
1 parent 45f5ad6 commit dd26921
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dnsutils/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,17 @@ type DnsTap struct {
LatencySec string `json:"latency" msgpack:"latency"`
}

type PowerDns struct {
Tags []string `json:"tags" msgpack:"tags"`
}

type DnsMessage struct {
NetworkInfo DnsNetInfo `json:"network" msgpack:"network"`
DNS Dns `json:"dns" msgpack:"dns"`
EDNS DnsExtended `json:"edns" msgpack:"edns"`
DnsTap DnsTap `json:"dnstap" msgpack:"dnstap"`
Geo DnsGeo `json:"geo" msgpack:"geo"`
PowerDns PowerDns `json:"pdns" msgpack:"pdns"`
}

func (dm *DnsMessage) Init() {
Expand Down Expand Up @@ -146,6 +151,10 @@ func (dm *DnsMessage) Init() {
City: "-",
Continent: "-",
}

dm.PowerDns = PowerDns{
Tags: []string{},
}
}

func (dm *DnsMessage) Bytes(format []string, delimiter string) []byte {
Expand Down Expand Up @@ -263,6 +272,14 @@ func (dm *DnsMessage) Bytes(format []string, delimiter string) []byte {
} else {
s.WriteString("-")
}
case "tags":
if len(dm.PowerDns.Tags) > 0 {
for _, tag := range dm.PowerDns.Tags {
s.WriteString(tag)
}
} else {
s.WriteString("-")
}
default:
log.Fatalf("unsupport directive for text format: %s", word)
}
Expand Down
6 changes: 6 additions & 0 deletions subprocessors/powerdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ func (d *PdnsProcessor) Run(sendTo []chan dnsutils.DnsMessage) {
// get query type
dm.DNS.Qtype = dnsutils.RdatatypeToString(int(pbdm.Question.GetQType()))

// get PowerDNS tags
pdns := dnsutils.PowerDns{
Tags: pbdm.Response.GetTags(),
}
dm.PowerDns = pdns

// decode answers
answers := []dnsutils.DnsAnswer{}
RRs := pbdm.GetResponse().GetRrs()
Expand Down

0 comments on commit dd26921

Please sign in to comment.