Skip to content

Commit

Permalink
add qname+one criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Jul 26, 2023
1 parent 2cb0ba5 commit 04e9de5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
7 changes: 3 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ multiplexer:
transforms:
normalize:
qname-lowercase: true
reducer:
repetitive-traffic-detector: true
watch-interval: 5

loggers:
- name: console
stdout:
mode: text
text-format: "timestamp-rfc3339ns identity operation rcode queryip qname qtype reducer-occurences reducer-cumulative-length"

routes:
- from: [ tap ]
Expand Down Expand Up @@ -605,9 +601,12 @@ multiplexer:
# # Use this transformer to detect trafic duplication
# # additionnals directive for text format
# # - reducer-occurences: number of occurences detected
# # - cumulative-length: sum of the length of each occurences
# reducer:
# # enable detector
# repetitive-traffic-detector: true
# # limit to qname+1 instead of the complete qname to detect repetition
# qname-plus-one: false
# # watch interval in seconds
# watch-interval: 5

Expand Down
2 changes: 2 additions & 0 deletions dnsutils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type ConfigTransformers struct {
Reducer struct {
Enable bool `yaml:"enable"`
RepetitiveTrafficDetector bool `yaml:"repetitive-traffic-detector"`
QnamePlusOne bool `yaml:"qname-plus-one"`
WatchInterval int `yaml:"watch-interval"`
}
Filtering struct {
Expand Down Expand Up @@ -130,6 +131,7 @@ func (c *ConfigTransformers) SetDefault() {

c.Reducer.Enable = false
c.Reducer.RepetitiveTrafficDetector = false
c.Reducer.QnamePlusOne = false
c.Reducer.WatchInterval = 5

c.Filtering.Enable = false
Expand Down
16 changes: 14 additions & 2 deletions doc/transformers.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,19 @@ Example of DNS messages in text format
### Traffic Reducer
Use this transformer to detect repetitive traffic
Use this transformer to detect repetitive traffic.
A query or reply is repeated when the following criterias are the same.
The following criterias are used:
- server identity
- operation
- qname or qname+1
- query ip
- qtype
Options:
- `repetitive-traffic-detector`: (boolean) detect repetitive traffic
- `qname-plus-one`: (boolean) use qname+1 instead of the complete one
- `watch-interval`: (integer) watch interval in seconds
Default values:
Expand All @@ -289,11 +298,13 @@ Default values:
transforms:
reducer:
repetitive-traffic-detector: true
qname-plus-one: false
watch-interval: 5
```

Specific directive(s) available for the text format:
Specific text directive(s) available for the text format:
- `reducer-occurences`: display the number of detected duplication
- `cumulative-length`: sum of the length of each occurences

When the feature is enabled, the following json field are populated in your DNS message:

Expand All @@ -303,6 +314,7 @@ Example:
{
"reducer": {
"occurences": 1,
"cumulative-length": 47
}
}
```
Expand Down
10 changes: 6 additions & 4 deletions example-config/use-case-20.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ multiplexer:
dnstap:
listen-ip: 0.0.0.0
listen-port: 6000
transforms:
reducer:
repetitive-traffic-detector: true
qname-plus-one: false
watch-interval: 5

loggers:
- name: console
stdout:
mode: text
transforms:
reducer:
repetitive-traffic-detector: true
watch-interval: 5
text-format: "timestamp-rfc3339ns identity operation rcode queryip qname qtype reducer-occurences reducer-cumulative-length"

routes:
- from: [ tap ]
Expand Down
8 changes: 8 additions & 0 deletions transformers/reducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/dmachard/go-dnscollector/dnsutils"
"github.com/dmachard/go-logger"
publicsuffixlist "golang.org/x/net/publicsuffix"
)

type expiredKey struct {
Expand Down Expand Up @@ -149,6 +150,13 @@ func (p *ReducerProcessor) RepetitiveTrafficDetector(dm *dnsutils.DnsMessage) in
p.strBuilder.WriteString(dm.DnsTap.Identity)
p.strBuilder.WriteString(dm.DnsTap.Operation)
p.strBuilder.WriteString(dm.NetworkInfo.QueryIp)
if p.config.Reducer.QnamePlusOne {
qname := strings.ToLower(dm.DNS.Qname)
qname = strings.TrimSuffix(qname, ".")
if etld, err := publicsuffixlist.EffectiveTLDPlusOne(qname); err == nil {
dm.DNS.Qname = etld
}
}
p.strBuilder.WriteString(dm.DNS.Qname)
p.strBuilder.WriteString(dm.DNS.Qtype)
dmTag := p.strBuilder.String()
Expand Down
3 changes: 2 additions & 1 deletion transformers/reducer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func TestReducer_Json(t *testing.T) {
refJson := `
{
"reducer": {
"occurences": 0
"occurences": 0,
"cumulative-length": 0
}
}
`
Expand Down

0 comments on commit 04e9de5

Please sign in to comment.