Skip to content

Commit

Permalink
add peer directives
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Feb 13, 2024
1 parent b14bdb4 commit 3ded512
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ global:
# - timestamp-unixns: unix timestamp with nano support
# - localtime: local time
# - identity: dnstap identity
# - peer-name: hostname or ip address of the dnstap sender
# - version: dnstap version
# - extra: dnstap extra as string
# - operation: dnstap operation
Expand Down
4 changes: 4 additions & 0 deletions dnsutils/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type DNSTap struct {
PolicyMatch string `json:"policy-match" msgpack:"policy-match"`
PolicyAction string `json:"policy-action" msgpack:"policy-action"`
PolicyValue string `json:"policy-value" msgpack:"policy-value"`
PeerName string `json:"peer-name" msgpack:"peer-name"`
}

type PowerDNS struct {
Expand Down Expand Up @@ -264,6 +265,7 @@ func (dm *DNSMessage) Init() {
PolicyMatch: "-",
PolicyAction: "-",
PolicyValue: "-",
PeerName: "-",
}

dm.DNS = DNS{
Expand Down Expand Up @@ -603,6 +605,8 @@ func (dm *DNSMessage) ToTextLine(format []string, fieldDelimiter string, fieldBo
s.WriteString(ts.Format("2006-01-02 15:04:05.999999999"))
case directive == "identity":
s.WriteString(dm.DNSTap.Identity)
case directive == "peer-name":
s.WriteString(dm.DNSTap.PeerName)
case directive == "version":
s.WriteString(dm.DNSTap.Version)
case directive == "extra":
Expand Down
9 changes: 8 additions & 1 deletion dnsutils/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ func TestDnsMessage_Json_Reference(t *testing.T) {
"policy-action": "-",
"policy-match": "-",
"policy-value": "-",
"policy-rule": "-"
"policy-rule": "-",
"peer-name": "-"
}
}
`
Expand Down Expand Up @@ -260,6 +261,7 @@ func TestDnsMessage_JsonFlatten_Reference(t *testing.T) {
"dnstap.policy-action": "-",
"dnstap.policy-match": "-",
"dnstap.policy-value": "-",
"dnstap.peer-name": "-",
"edns.dnssec-ok": 0,
"edns.options": [],
"edns.rcode": 0,
Expand Down Expand Up @@ -590,6 +592,11 @@ func TestDnsMessage_TextFormat_DefaultDirectives(t *testing.T) {
PolicyValue: "value"}},
expected: "rule type action match value",
},
{
format: "peer-name",
dm: DNSMessage{DNSTap: DNSTap{PeerName: "testpeer"}},
expected: "testpeer",
},
}

for _, tc := range testcases {
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Default directives:
- `timestamp-unixns`: unix timestamp with nano support
- `localtime`: local time
- `identity`: dnstap identity
- `peer-name`: hostname or ip address of the dnstap sender
- `version`: dnstap version
- `extra`: dnstap extra as string
- `operation`: dnstap operation
Expand Down
2 changes: 2 additions & 0 deletions docs/dnsjson.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Example:
"dnstap": {
"operation": "CLIENT_RESPONSE",
"identity": "dnsdist1",
"peer-name": "172.16.0.2",
"version": "-",
"extra": "-",
"timestamp-rfc3339ns": "2021-12-27T14:33:44.559002118Z",
Expand Down Expand Up @@ -113,6 +114,7 @@ Using flat-json requires more processing on the host running go-dnscollector but
"dns.resource-records.ar": [],
"dns.resource-records.ns": [],
"dnstap.identity": "foo",
"dnstap.peer-name": "172.16.0.2",
"dnstap.latency": "0.000000",
"dnstap.operation": "CLIENT_RESPONSE",
"dnstap.timestamp-rfc3339ns": "2023-03-31T10:14:46.664534902Z",
Expand Down
2 changes: 2 additions & 0 deletions processors/dnstap.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ RUN_LOOP:
dm := dnsutils.DNSMessage{}
dm.Init()

dm.DNSTap.PeerName = d.PeerName

// init dns message with additionnals parts
transforms.InitDNSMessageFormat(&dm)

Expand Down

0 comments on commit 3ded512

Please sign in to comment.