From d5d4923570fef7c78dbdc2a2b14be8ff39153911 Mon Sep 17 00:00:00 2001 From: Denis Machard <5562930+dmachard@users.noreply.github.com> Date: Fri, 29 Mar 2024 18:17:50 +0100 Subject: [PATCH] transform: normalize lowercase RR's (#665) * code cleanup * implement #525 --- README.md | 2 +- config.yml | 2 +- docs/transformers/transform_normalize.md | 18 ++-- pkgconfig/transformers.go | 2 + transformers/atags.go | 2 +- transformers/atags_test.go | 2 +- transformers/extract.go | 2 +- transformers/extract_test.go | 4 +- transformers/filtering.go | 8 +- transformers/filtering_test.go | 30 +++---- transformers/geoip.go | 2 +- transformers/geoip_test.go | 6 +- transformers/latency.go | 2 +- transformers/latency_test.go | 4 +- transformers/machinelearning.go | 2 +- transformers/machinelearning_test.go | 2 +- transformers/normalize.go | 34 ++++++-- transformers/normalize_test.go | 83 ++++++++++++++++--- transformers/reducer.go | 2 +- transformers/reducer_test.go | 6 +- transformers/relabeling.go | 2 +- transformers/relabeling_test.go | 2 +- transformers/suspicious.go | 2 +- transformers/suspicious_test.go | 18 ++-- .../{subprocessors.go => transformers.go} | 52 ++++++------ ...rocessors_test.go => transformers_test.go} | 0 transformers/userprivacy.go | 2 +- transformers/userprivacy_test.go | 22 ++--- 28 files changed, 200 insertions(+), 115 deletions(-) rename transformers/{subprocessors.go => transformers.go} (77%) rename transformers/{subprocessors_test.go => transformers_test.go} (100%) diff --git a/README.md b/README.md index eb5ca453..8e7bb56f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Go Report Go version Go tests -Go bench +Go bench Go lines

diff --git a/config.yml b/config.yml index f0b7e304..992ad7eb 100644 --- a/config.yml +++ b/config.yml @@ -25,7 +25,7 @@ multiplexer: listen-port: 6000 transforms: normalize: - qname-lowercase: false + qname-lowercase: true loggers: - name: console diff --git a/docs/transformers/transform_normalize.md b/docs/transformers/transform_normalize.md index 586da2cc..f83c82a0 100644 --- a/docs/transformers/transform_normalize.md +++ b/docs/transformers/transform_normalize.md @@ -9,22 +9,26 @@ is `co.uk` and the `TLD+1` is `amazon.co.uk`. Options: -* `qname-lowercase` (boolean) +*`qname-lowercase` (boolean) > enable or disable lowercase -* `add-tld` (boolean) +*`rr-lowercase` (boolean) + > enable or disable lowercase for all resources records + +*`add-tld` (boolean) > add top level domain -* `add-tld-plus-one` (boolean) +*`add-tld-plus-one` (boolean) > add top level domain plus one label -* `quiet-text` (boolean) +*`quiet-text` (boolean) > Quiet text mode to reduce the size of the logs ```yaml transforms: normalize: qname-lowercase: true + rr-lowercase: false add-tld: false add-tld-plus-one: false quiet-text: false @@ -64,6 +68,6 @@ Example: Specific directives added for text format: -* `publicsuffix-tld`: [Public Suffix](https://publicsuffix.org/) of the DNS QNAME -* `publicsuffix-etld+1`: [Public Suffix](https://publicsuffix.org/) plus one label of the DNS QNAME -* `publicsuffix-managed-icann`: [Public Suffix](https://publicsuffix.org/) flag for managed icann domains +*`publicsuffix-tld`: [Public Suffix](https://publicsuffix.org/) of the DNS QNAME +*`publicsuffix-etld+1`: [Public Suffix](https://publicsuffix.org/) plus one label of the DNS QNAME +*`publicsuffix-managed-icann`: [Public Suffix](https://publicsuffix.org/) flag for managed icann domains diff --git a/pkgconfig/transformers.go b/pkgconfig/transformers.go index e7af80ab..201d7c19 100644 --- a/pkgconfig/transformers.go +++ b/pkgconfig/transformers.go @@ -18,6 +18,7 @@ type ConfigTransformers struct { Normalize struct { Enable bool `yaml:"enable"` QnameLowerCase bool `yaml:"qname-lowercase"` + RRLowerCase bool `yaml:"rr-lowercase"` QuietText bool `yaml:"quiet-text"` AddTld bool `yaml:"add-tld"` AddTldPlusOne bool `yaml:"add-tld-plus-one"` @@ -104,6 +105,7 @@ func (c *ConfigTransformers) SetDefault() { c.Normalize.Enable = false c.Normalize.QnameLowerCase = false + c.Normalize.RRLowerCase = false c.Normalize.QuietText = false c.Normalize.AddTld = false c.Normalize.AddTldPlusOne = false diff --git a/transformers/atags.go b/transformers/atags.go index aff6e0b2..9f4a80f6 100644 --- a/transformers/atags.go +++ b/transformers/atags.go @@ -16,7 +16,7 @@ type ATagsProcessor struct { logError func(msg string, v ...interface{}) } -func NewATagsSubprocessor(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, +func NewATagsTransform(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{})) ATagsProcessor { s := ATagsProcessor{ diff --git a/transformers/atags_test.go b/transformers/atags_test.go index 6c49bd7d..cf07064b 100644 --- a/transformers/atags_test.go +++ b/transformers/atags_test.go @@ -18,7 +18,7 @@ func TestATags_AddTag(t *testing.T) { // init the processor log := logger.New(false) outChans := []chan dnsutils.DNSMessage{} - transform := NewATagsSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + transform := NewATagsTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) if !transform.IsEnabled() { t.Errorf("subprocessor should be enabled") diff --git a/transformers/extract.go b/transformers/extract.go index 1f7afb90..0989b5c0 100644 --- a/transformers/extract.go +++ b/transformers/extract.go @@ -16,7 +16,7 @@ type ExtractProcessor struct { logError func(msg string, v ...interface{}) } -func NewExtractSubprocessor(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, +func NewExtractTransform(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{})) ExtractProcessor { s := ExtractProcessor{ diff --git a/transformers/extract_test.go b/transformers/extract_test.go index a476c201..e8aebe19 100644 --- a/transformers/extract_test.go +++ b/transformers/extract_test.go @@ -23,7 +23,7 @@ func TestExtract_Json(t *testing.T) { dm.Init() // init subproccesor - extract := NewExtractSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + extract := NewExtractTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) extract.InitDNSMessage(&dm) // expected json @@ -66,7 +66,7 @@ func TestExtract_AddPayload(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - extract := NewExtractSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + extract := NewExtractTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) // feature is enabled ? if !extract.IsEnabled() { diff --git a/transformers/filtering.go b/transformers/filtering.go index ae6970e0..82156b6b 100644 --- a/transformers/filtering.go +++ b/transformers/filtering.go @@ -38,7 +38,7 @@ type FilteringProcessor struct { logError func(msg string, v ...interface{}) } -func NewFilteringProcessor(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, +func NewFilteringTransform(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{}), ) FilteringProcessor { @@ -92,12 +92,12 @@ func (p *FilteringProcessor) LoadActiveFilters() { if !p.config.Filtering.LogQueries { p.activeFilters = append(p.activeFilters, p.ignoreQueryFilter) - p.LogInfo("drop queries subprocessor is enabled") + p.LogInfo("drop queries transformer is enabled") } if !p.config.Filtering.LogReplies { p.activeFilters = append(p.activeFilters, p.ignoreReplyFilter) - p.LogInfo("drop replies subprocessor is enabled") + p.LogInfo("drop replies transformer is enabled") } if len(p.mapRcodes) > 0 { @@ -137,7 +137,7 @@ func (p *FilteringProcessor) LoadActiveFilters() { p.downsample = p.config.Filtering.Downsample p.downsampleCount = 0 p.activeFilters = append(p.activeFilters, p.downsampleFilter) - p.LogInfo("down sampling subprocessor is enabled") + p.LogInfo("transformer=downsampling is enabled") } } diff --git a/transformers/filtering_test.go b/transformers/filtering_test.go index e256c0a4..72e1a957 100644 --- a/transformers/filtering_test.go +++ b/transformers/filtering_test.go @@ -24,7 +24,7 @@ func TestFilteringQR(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadActiveFilters() dm := dnsutils.GetFakeDNSMessage() @@ -49,7 +49,7 @@ func TestFilteringByRcodeNOERROR(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadRcodes() filtering.LoadActiveFilters() @@ -70,7 +70,7 @@ func TestFilteringByRcodeEmpty(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadRcodes() filtering.LoadActiveFilters() @@ -90,7 +90,7 @@ func TestFilteringByKeepQueryIp(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadQueryIPList() filtering.LoadActiveFilters() @@ -122,7 +122,7 @@ func TestFilteringByDropQueryIp(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadQueryIPList() filtering.LoadActiveFilters() @@ -154,7 +154,7 @@ func TestFilteringByKeepRdataIp(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadrDataIPList() filtering.LoadActiveFilters() @@ -250,7 +250,7 @@ func TestFilteringByFqdn(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadDomainsList() filtering.LoadActiveFilters() @@ -276,7 +276,7 @@ func TestFilteringByDomainRegex(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadDomainsList() filtering.LoadActiveFilters() @@ -309,7 +309,7 @@ func TestFilteringByKeepDomain(t *testing.T) { config.Filtering.KeepDomainFile = "../testsdata/filtering_keep_domains.txt" // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadDomainsList() filtering.LoadActiveFilters() @@ -351,7 +351,7 @@ func TestFilteringByKeepDomainRegex(t *testing.T) { config.Filtering.KeepDomainFile = "../testsdata/filtering_keep_domains_regex.txt" // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadDomainsList() filtering.LoadActiveFilters() @@ -388,14 +388,14 @@ func TestFilteringByDownsampleDisabled(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadActiveFilters() // init DNS Message dm := dnsutils.GetFakeDNSMessage() // test for default behavior when downsample is set to 0 - filtering = NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering = NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) if filtering.CheckIfDrop(&dm) == true { t.Errorf("dns query should not be dropped! downsampling rate is set to 0 and should not downsample.") @@ -415,7 +415,7 @@ func TestFilteringByDownsample(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadActiveFilters() // init DNS Message @@ -449,7 +449,7 @@ func TestFilteringByDownsampleUpdateJSONModel(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadActiveFilters() // init DNS Message @@ -482,7 +482,7 @@ func TestFilteringMultipleFilters(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - filtering := NewFilteringProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + filtering := NewFilteringTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) filtering.LoadQueryIPList() filtering.LoadDomainsList() filtering.LoadActiveFilters() diff --git a/transformers/geoip.go b/transformers/geoip.go index 773f0523..9af9b2b4 100644 --- a/transformers/geoip.go +++ b/transformers/geoip.go @@ -47,7 +47,7 @@ type GeoIPProcessor struct { logError func(msg string, v ...interface{}) } -func NewDNSGeoIPProcessor(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, +func NewDNSGeoIPTransform(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{}), ) GeoIPProcessor { diff --git a/transformers/geoip_test.go b/transformers/geoip_test.go index 532efa5b..4bd393dc 100644 --- a/transformers/geoip_test.go +++ b/transformers/geoip_test.go @@ -22,7 +22,7 @@ func TestGeoIP_Json(t *testing.T) { dm.Init() // init subproccesor - geoip := NewDNSGeoIPProcessor(config, logger.New(true), "test", 0, outChans, log.Info, log.Error) + geoip := NewDNSGeoIPTransform(config, logger.New(true), "test", 0, outChans, log.Info, log.Error) if err := geoip.Open(); err != nil { t.Fatalf("geoip init failed: %v+", err) } @@ -72,7 +72,7 @@ func TestGeoIP_LookupCountry(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - geoip := NewDNSGeoIPProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + geoip := NewDNSGeoIPTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) if err := geoip.Open(); err != nil { t.Fatalf("geoip init failed: %v+", err) } @@ -103,7 +103,7 @@ func TestGeoIP_LookupAsn(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - geoip := NewDNSGeoIPProcessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + geoip := NewDNSGeoIPTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) if err := geoip.Open(); err != nil { t.Fatalf("geoip init failed: %v", err) } diff --git a/transformers/latency.go b/transformers/latency.go index 4ff05266..e45ea5b8 100644 --- a/transformers/latency.go +++ b/transformers/latency.go @@ -113,7 +113,7 @@ type LatencyProcessor struct { logError func(msg string, v ...interface{}) } -func NewLatencySubprocessor(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, +func NewLatencyTransform(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{}), ) *LatencyProcessor { diff --git a/transformers/latency_test.go b/transformers/latency_test.go index 4213d532..9e92edf7 100644 --- a/transformers/latency_test.go +++ b/transformers/latency_test.go @@ -18,7 +18,7 @@ func TestLatency_MeasureLatency(t *testing.T) { outChannels := []chan dnsutils.DNSMessage{} // init transformer - latencyProcessor := NewLatencySubprocessor(config, logger.New(true), "test", 0, outChannels, log.Info, log.Error) + latencyProcessor := NewLatencyTransform(config, logger.New(true), "test", 0, outChannels, log.Info, log.Error) testcases := []struct { name string @@ -73,7 +73,7 @@ func TestLatency_DetectEvictedTimeout(t *testing.T) { outChannels = append(outChannels, make(chan dnsutils.DNSMessage, 1)) // init transformer - latencyProcessor := NewLatencySubprocessor(config, logger.New(true), "test", 0, outChannels, log.Info, log.Error) + latencyProcessor := NewLatencyTransform(config, logger.New(true), "test", 0, outChannels, log.Info, log.Error) testcases := []struct { name string diff --git a/transformers/machinelearning.go b/transformers/machinelearning.go index 1edfad5b..0a0b2c3d 100644 --- a/transformers/machinelearning.go +++ b/transformers/machinelearning.go @@ -30,7 +30,7 @@ type MlProcessor struct { logError func(msg string, v ...interface{}) } -func NewMachineLearningSubprocessor(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, +func NewMachineLearningTransform(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{}), ) MlProcessor { diff --git a/transformers/machinelearning_test.go b/transformers/machinelearning_test.go index 2248e9e5..2741ef47 100644 --- a/transformers/machinelearning_test.go +++ b/transformers/machinelearning_test.go @@ -16,7 +16,7 @@ func TestML_AddFeatures(t *testing.T) { // init the processor log := logger.New(false) outChans := []chan dnsutils.DNSMessage{} - transform := NewMachineLearningSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + transform := NewMachineLearningTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) dm := dnsutils.GetFakeDNSMessage() diff --git a/transformers/normalize.go b/transformers/normalize.go index dee77562..1c4d9b22 100644 --- a/transformers/normalize.go +++ b/transformers/normalize.go @@ -74,7 +74,7 @@ type NormalizeProcessor struct { logError func(msg string, v ...interface{}) } -func NewNormalizeSubprocessor( +func NewNormalizeTransform( config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{}), @@ -109,19 +109,24 @@ func (p *NormalizeProcessor) LoadActiveProcessors() { // clean the slice p.activeProcessors = p.activeProcessors[:0] + if p.config.Normalize.RRLowerCase { + p.activeProcessors = append(p.activeProcessors, p.RRLowercase) + p.LogInfo("transformer=lowercase is enabled") + } + if p.config.Normalize.QnameLowerCase { - p.activeProcessors = append(p.activeProcessors, p.LowercaseQname) - p.LogInfo("lowercase subprocessor is enabled") + p.activeProcessors = append(p.activeProcessors, p.QnameLowercase) + p.LogInfo("transformer=lowercase is enabled") } if p.config.Normalize.QuietText { p.activeProcessors = append(p.activeProcessors, p.QuietText) - p.LogInfo("quiet text subprocessor is enabled") + p.LogInfo("transformer=quiet_text is enabled") } if p.config.Normalize.AddTld { p.activeProcessors = append(p.activeProcessors, p.GetEffectiveTld) - p.LogInfo("add tld subprocessor is enabled") + p.LogInfo("transformer=add_tld is enabled") } if p.config.Normalize.AddTldPlusOne { p.activeProcessors = append(p.activeProcessors, p.GetEffectiveTldPlusOne) @@ -143,12 +148,29 @@ func (p *NormalizeProcessor) InitDNSMessage(dm *dnsutils.DNSMessage) { } } -func (p *NormalizeProcessor) LowercaseQname(dm *dnsutils.DNSMessage) int { +func (p *NormalizeProcessor) QnameLowercase(dm *dnsutils.DNSMessage) int { dm.DNS.Qname = strings.ToLower(dm.DNS.Qname) return ReturnSuccess } +func processRecords(records []dnsutils.DNSAnswer) { + for i := range records { + records[i].Name = strings.ToLower(records[i].Name) + switch records[i].Rdatatype { + case "CNAME", "SOA", "NS", "MX", "PTR", "SRV": + records[i].Rdata = strings.ToLower(records[i].Rdata) + } + } +} + +func (p *NormalizeProcessor) RRLowercase(dm *dnsutils.DNSMessage) int { + processRecords(dm.DNS.DNSRRs.Answers) + processRecords(dm.DNS.DNSRRs.Nameservers) + processRecords(dm.DNS.DNSRRs.Records) + return ReturnSuccess +} + func (p *NormalizeProcessor) QuietText(dm *dnsutils.DNSMessage) int { if v, found := DnstapMessage[dm.DNSTap.Operation]; found { dm.DNSTap.Operation = v diff --git a/transformers/normalize_test.go b/transformers/normalize_test.go index 6026f1a6..60f4ffab 100644 --- a/transformers/normalize_test.go +++ b/transformers/normalize_test.go @@ -19,15 +19,51 @@ func TestNormalize_LowercaseQname(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - qnameNorm := NewNormalizeSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + normTransformer := NewNormalizeTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) qname := "www.Google.Com" dm := dnsutils.GetFakeDNSMessage() dm.DNS.Qname = qname - ret := qnameNorm.LowercaseQname(&dm) + normTransformer.QnameLowercase(&dm) if dm.DNS.Qname != strings.ToLower(qname) { - t.Errorf("Qname to lowercase failed, got %d", ret) + t.Errorf("Qname to lowercase failed, got %s", dm.DNS.Qname) + } +} + +func TestNormalize_RRLowercaseQname(t *testing.T) { + // enable feature + config := pkgconfig.GetFakeConfigTransformers() + config.Normalize.Enable = true + + log := logger.New(false) + outChans := []chan dnsutils.DNSMessage{} + + // init the processor + normTransformer := NewNormalizeTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + + // create DNSMessage with answers + rrqname := "www.RRGoogle.Com" + dm := dnsutils.GetFakeDNSMessage() + dm.DNS.Qname = "www.test.com" + dm.DNS.DNSRRs.Answers = append(dm.DNS.DNSRRs.Answers, dnsutils.DNSAnswer{Name: rrqname}) + dm.DNS.DNSRRs.Nameservers = append(dm.DNS.DNSRRs.Nameservers, dnsutils.DNSAnswer{Name: rrqname}) + dm.DNS.DNSRRs.Records = append(dm.DNS.DNSRRs.Records, dnsutils.DNSAnswer{Name: rrqname}) + + // process DNSMessage + normTransformer.RRLowercase(&dm) + + // checks + if dm.DNS.DNSRRs.Answers[0].Name != strings.ToLower(rrqname) { + t.Errorf("RR Answers to lowercase failed, got %s", dm.DNS.DNSRRs.Answers[0].Name) + } + + if dm.DNS.DNSRRs.Nameservers[0].Name != strings.ToLower(rrqname) { + t.Errorf("RR Nameservers to lowercase failed, got %s", dm.DNS.DNSRRs.Nameservers[0].Name) + } + + if dm.DNS.DNSRRs.Records[0].Name != strings.ToLower(rrqname) { + t.Errorf("RR Records to lowercase failed, got %s", dm.DNS.DNSRRs.Records[0].Name) } } @@ -41,7 +77,7 @@ func TestNormalize_QuietText(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - norm := NewNormalizeSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + norm := NewNormalizeTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) dm := dnsutils.GetFakeDNSMessage() norm.QuietText(&dm) @@ -65,7 +101,7 @@ func TestNormalize_AddTLD(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - psl := NewNormalizeSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + psl := NewNormalizeTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) tt := []struct { name string @@ -116,7 +152,7 @@ func TestNormalize_AddTldPlusOne(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - psl := NewNormalizeSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + psl := NewNormalizeTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) tt := []struct { name string @@ -159,7 +195,7 @@ func TestNormalize_SuffixUnmanaged(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - psl := NewNormalizeSubprocessor(config, logger.New(true), "test", 0, outChans, log.Info, log.Error) + psl := NewNormalizeTransform(config, logger.New(true), "test", 0, outChans, log.Info, log.Error) dm := dnsutils.GetFakeDNSMessage() // https://publicsuffix.org/list/effective_tld_names.dat @@ -185,7 +221,7 @@ func TestNormalize_SuffixICANNManaged(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - psl := NewNormalizeSubprocessor(config, logger.New(true), "test", 0, outChans, log.Info, log.Error) + psl := NewNormalizeTransform(config, logger.New(true), "test", 0, outChans, log.Info, log.Error) dm := dnsutils.GetFakeDNSMessage() // https://publicsuffix.org/list/effective_tld_names.dat @@ -211,7 +247,7 @@ func BenchmarkNormalize_GetEffectiveTld(b *testing.B) { log := logger.New(false) channels := []chan dnsutils.DNSMessage{} - subprocessor := NewNormalizeSubprocessor(config, logger.New(false), "test", 0, channels, log.Info, log.Error) + subprocessor := NewNormalizeTransform(config, logger.New(false), "test", 0, channels, log.Info, log.Error) dm := dnsutils.GetFakeDNSMessage() dm.DNS.Qname = "en.wikipedia.org" @@ -228,7 +264,7 @@ func BenchmarkNormalize_GetEffectiveTldPlusOne(b *testing.B) { log := logger.New(false) channels := []chan dnsutils.DNSMessage{} - subprocessor := NewNormalizeSubprocessor(config, logger.New(false), "test", 0, channels, log.Info, log.Error) + subprocessor := NewNormalizeTransform(config, logger.New(false), "test", 0, channels, log.Info, log.Error) dm := dnsutils.GetFakeDNSMessage() dm.DNS.Qname = "en.wikipedia.org" @@ -245,13 +281,34 @@ func BenchmarkNormalize_QnameLowercase(b *testing.B) { log := logger.New(false) channels := []chan dnsutils.DNSMessage{} - subprocessor := NewNormalizeSubprocessor(config, logger.New(false), "test", 0, channels, log.Info, log.Error) + subprocessor := NewNormalizeTransform(config, logger.New(false), "test", 0, channels, log.Info, log.Error) dm := dnsutils.GetFakeDNSMessage() dm.DNS.Qname = "EN.Wikipedia.Org" b.ResetTimer() for i := 0; i < b.N; i++ { - subprocessor.LowercaseQname(&dm) + subprocessor.QnameLowercase(&dm) + } +} + +func BenchmarkNormalize_RRLowercase(b *testing.B) { + config := pkgconfig.GetFakeConfigTransformers() + + log := logger.New(false) + channels := []chan dnsutils.DNSMessage{} + + tranform := NewNormalizeTransform(config, logger.New(false), "test", 0, channels, log.Info, log.Error) + + name := "En.Tikipedia.Org" + dm := dnsutils.GetFakeDNSMessage() + dm.DNS.Qname = name + dm.DNS.DNSRRs.Answers = append(dm.DNS.DNSRRs.Answers, dnsutils.DNSAnswer{Name: name}) + dm.DNS.DNSRRs.Nameservers = append(dm.DNS.DNSRRs.Nameservers, dnsutils.DNSAnswer{Name: name}) + dm.DNS.DNSRRs.Records = append(dm.DNS.DNSRRs.Records, dnsutils.DNSAnswer{Name: name}) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + tranform.RRLowercase(&dm) } } @@ -261,7 +318,7 @@ func BenchmarkNormalize_QuietText(b *testing.B) { log := logger.New(false) channels := []chan dnsutils.DNSMessage{} - subprocessor := NewNormalizeSubprocessor(config, logger.New(false), "test", 0, channels, log.Info, log.Error) + subprocessor := NewNormalizeTransform(config, logger.New(false), "test", 0, channels, log.Info, log.Error) dm := dnsutils.GetFakeDNSMessage() dm.DNS.Qname = "EN.Wikipedia.Org" diff --git a/transformers/reducer.go b/transformers/reducer.go index 801b6f46..c8121076 100644 --- a/transformers/reducer.go +++ b/transformers/reducer.go @@ -113,7 +113,7 @@ type ReducerProcessor struct { strBuilder strings.Builder } -func NewReducerSubprocessor( +func NewReducerTransform( config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{}), diff --git a/transformers/reducer_test.go b/transformers/reducer_test.go index 4d2c9376..ba7713fe 100644 --- a/transformers/reducer_test.go +++ b/transformers/reducer_test.go @@ -24,7 +24,7 @@ func TestReducer_Json(t *testing.T) { // init subproccesor - reducer := NewReducerSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + reducer := NewReducerTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) reducer.InitDNSMessage(&dm) // expected json @@ -70,7 +70,7 @@ func TestReducer_RepetitiveTrafficDetector(t *testing.T) { outChans = append(outChans, outChan) // init subproccesor - reducer := NewReducerSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + reducer := NewReducerTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) reducer.LoadActiveReducers() // malformed DNS message @@ -184,7 +184,7 @@ func TestReducer_QnamePlusOne(t *testing.T) { outChans = append(outChans, outChan) // init subproccesor - reducer := NewReducerSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + reducer := NewReducerTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) reducer.LoadActiveReducers() testcases := []struct { diff --git a/transformers/relabeling.go b/transformers/relabeling.go index b1cef587..c3d17377 100644 --- a/transformers/relabeling.go +++ b/transformers/relabeling.go @@ -19,7 +19,7 @@ type RelabelProcessor struct { RelabelingRules []dnsutils.RelabelingRule } -func NewRelabelSubprocessor(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, +func NewRelabelTransform(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{})) RelabelProcessor { s := RelabelProcessor{ diff --git a/transformers/relabeling_test.go b/transformers/relabeling_test.go index c11a3d94..d27c9908 100644 --- a/transformers/relabeling_test.go +++ b/transformers/relabeling_test.go @@ -23,7 +23,7 @@ func TestRelabeling_CompileRegex(t *testing.T) { // init the processor log := logger.New(false) outChans := []chan dnsutils.DNSMessage{} - relabelingProc := NewRelabelSubprocessor( + relabelingProc := NewRelabelTransform( config, logger.New(false), "test", diff --git a/transformers/suspicious.go b/transformers/suspicious.go index 07e02547..976ee217 100644 --- a/transformers/suspicious.go +++ b/transformers/suspicious.go @@ -22,7 +22,7 @@ type SuspiciousTransform struct { logError func(msg string, v ...interface{}) } -func NewSuspiciousSubprocessor(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, +func NewSuspiciousTransform(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{}), ) SuspiciousTransform { diff --git a/transformers/suspicious_test.go b/transformers/suspicious_test.go index 2614d0c4..0cb603fc 100644 --- a/transformers/suspicious_test.go +++ b/transformers/suspicious_test.go @@ -22,7 +22,7 @@ func TestSuspicious_Json(t *testing.T) { dm.Init() // init subproccesor - suspicious := NewSuspiciousSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + suspicious := NewSuspiciousTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) suspicious.InitDNSMessage(&dm) // expected json @@ -71,7 +71,7 @@ func TestSuspicious_MalformedPacket(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - suspicious := NewSuspiciousSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + suspicious := NewSuspiciousTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) // malformed DNS message dm := dnsutils.GetFakeDNSMessage() @@ -101,7 +101,7 @@ func TestSuspicious_LongDomain(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - suspicious := NewSuspiciousSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + suspicious := NewSuspiciousTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) // malformed DNS message dm := dnsutils.GetFakeDNSMessage() @@ -131,7 +131,7 @@ func TestSuspicious_SlowDomain(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - suspicious := NewSuspiciousSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + suspicious := NewSuspiciousTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) // malformed DNS message dm := dnsutils.GetFakeDNSMessage() @@ -161,7 +161,7 @@ func TestSuspicious_LargePacket(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - suspicious := NewSuspiciousSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + suspicious := NewSuspiciousTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) // malformed DNS message dm := dnsutils.GetFakeDNSMessage() @@ -190,7 +190,7 @@ func TestSuspicious_UncommonQtype(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - suspicious := NewSuspiciousSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + suspicious := NewSuspiciousTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) // malformed DNS message dm := dnsutils.GetFakeDNSMessage() @@ -220,7 +220,7 @@ func TestSuspicious_ExceedMaxLabels(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - suspicious := NewSuspiciousSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + suspicious := NewSuspiciousTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) // malformed DNS message dm := dnsutils.GetFakeDNSMessage() @@ -249,7 +249,7 @@ func TestSuspicious_UnallowedChars(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - suspicious := NewSuspiciousSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + suspicious := NewSuspiciousTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) // malformed DNS message dm := dnsutils.GetFakeDNSMessage() @@ -278,7 +278,7 @@ func TestSuspicious_WhitelistDomains(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init subproccesor - suspicious := NewSuspiciousSubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + suspicious := NewSuspiciousTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) // IPv6 DNS message PTR dm := dnsutils.GetFakeDNSMessage() diff --git a/transformers/subprocessors.go b/transformers/transformers.go similarity index 77% rename from transformers/subprocessors.go rename to transformers/transformers.go index f77f2f81..24955b3a 100644 --- a/transformers/subprocessors.go +++ b/transformers/transformers.go @@ -49,17 +49,17 @@ func NewTransforms(config *pkgconfig.ConfigTransformers, logger *logger.Logger, instance: instance, } - d.SuspiciousTransform = NewSuspiciousSubprocessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.NormalizeTransform = NewNormalizeSubprocessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.ExtractProcessor = NewExtractSubprocessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.LatencyTransform = NewLatencySubprocessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.ReducerTransform = NewReducerSubprocessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.UserPrivacyTransform = NewUserPrivacySubprocessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.FilteringTransform = NewFilteringProcessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.GeoipTransform = NewDNSGeoIPProcessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.MachineLearningTransform = NewMachineLearningSubprocessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.ATagsTransform = NewATagsSubprocessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) - d.RelabelTransform = NewRelabelSubprocessor(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.SuspiciousTransform = NewSuspiciousTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.NormalizeTransform = NewNormalizeTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.ExtractProcessor = NewExtractTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.LatencyTransform = NewLatencyTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.ReducerTransform = NewReducerTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.UserPrivacyTransform = NewUserPrivacyTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.FilteringTransform = NewFilteringTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.GeoipTransform = NewDNSGeoIPTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.MachineLearningTransform = NewMachineLearningTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.ATagsTransform = NewATagsTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) + d.RelabelTransform = NewRelabelTransform(config, logger, name, instance, outChannels, d.LogInfo, d.LogError) d.Prepare() return d @@ -94,17 +94,17 @@ func (p *Transforms) Prepare() error { } if p.config.Normalize.Enable { - p.LogInfo(prefixlog + "qname lowercase subprocessor is " + enabled) + p.LogInfo(prefixlog + "transformer=qname_lowercase is " + enabled) p.NormalizeTransform.LoadActiveProcessors() } if p.config.GeoIP.Enable { p.activeTransforms = append(p.activeTransforms, p.geoipTransform) - p.LogInfo(prefixlog + "geoip subprocessor is " + enabled) + p.LogInfo(prefixlog + "transformer=geoip is " + enabled) if err := p.GeoipTransform.Open(); err != nil { - p.LogError(prefixlog+"geoip subprocessor open error %v", err) + p.LogError(prefixlog+"transformer=geoip - open error %v", err) } } @@ -112,22 +112,22 @@ func (p *Transforms) Prepare() error { // Apply user privacy on qname and query ip if p.config.UserPrivacy.AnonymizeIP { p.activeTransforms = append(p.activeTransforms, p.anonymizeIP) - p.LogInfo(prefixlog + "ip anonymization subprocessor is enabled") + p.LogInfo(prefixlog + "transformer=ip_anonymization is enabled") } if p.config.UserPrivacy.MinimazeQname { p.activeTransforms = append(p.activeTransforms, p.minimazeQname) - p.LogInfo(prefixlog + "minimaze qname subprocessor is enabled") + p.LogInfo(prefixlog + "transformer=minimaze_qname is enabled") } if p.config.UserPrivacy.HashIP { p.activeTransforms = append(p.activeTransforms, p.hashIP) - p.LogInfo(prefixlog + "hash ip subprocessor is enabled") + p.LogInfo(prefixlog + "transformer=hash_ip is enabled") } } if p.config.Filtering.Enable { - p.LogInfo(prefixlog + "filtering subprocessor is " + enabled) + p.LogInfo(prefixlog + "transformer=filtering is " + enabled) p.FilteringTransform.LoadRcodes() p.FilteringTransform.LoadDomainsList() @@ -140,21 +140,21 @@ func (p *Transforms) Prepare() error { if p.config.Latency.Enable { if p.config.Latency.MeasureLatency { p.activeTransforms = append(p.activeTransforms, p.measureLatency) - p.LogInfo(prefixlog + "measure latency subprocessor is enabled") + p.LogInfo(prefixlog + "transformer=measure_latency is enabled") } if p.config.Latency.UnansweredQueries { p.activeTransforms = append(p.activeTransforms, p.detectEvictedTimeout) - p.LogInfo(prefixlog + "unanswered queries subprocessor is enabled") + p.LogInfo(prefixlog + "transformer=unanswered_queries is enabled") } } if p.config.Suspicious.Enable { p.activeTransforms = append(p.activeTransforms, p.suspiciousTransform) - p.LogInfo(prefixlog + "suspicious subprocessor is " + enabled) + p.LogInfo(prefixlog + "transformer=suspicious is " + enabled) } if p.config.Reducer.Enable { - p.LogInfo(prefixlog + "reducer subprocessor is " + enabled) + p.LogInfo(prefixlog + "transformer=reducer is " + enabled) p.ReducerTransform.LoadActiveReducers() } @@ -162,22 +162,22 @@ func (p *Transforms) Prepare() error { if p.config.Extract.Enable { if p.config.Extract.AddPayload { p.activeTransforms = append(p.activeTransforms, p.addBase64Payload) - p.LogInfo(prefixlog + "extract subprocessor is enabled") + p.LogInfo(prefixlog + "transformer=extract is enabled") } } if p.config.MachineLearning.Enable { p.activeTransforms = append(p.activeTransforms, p.machineLearningTransform) - p.LogInfo(prefixlog + "machinelearning subprocessor is" + enabled) + p.LogInfo(prefixlog + "transformer=machinelearning is" + enabled) } if p.config.ATags.Enable { p.activeTransforms = append(p.activeTransforms, p.ATagsTransform.AddTags) - p.LogInfo(prefixlog + "atags subprocessor is enabled") + p.LogInfo(prefixlog + "transformer=atags is enabled") } if p.config.Relabeling.Enable { - p.LogInfo(prefixlog + "relabeling subprocessor is enabled") + p.LogInfo(prefixlog + "transformer=relabeling is enabled") } return nil diff --git a/transformers/subprocessors_test.go b/transformers/transformers_test.go similarity index 100% rename from transformers/subprocessors_test.go rename to transformers/transformers_test.go diff --git a/transformers/userprivacy.go b/transformers/userprivacy.go index 568eef21..29d2d58d 100644 --- a/transformers/userprivacy.go +++ b/transformers/userprivacy.go @@ -45,7 +45,7 @@ type UserPrivacyProcessor struct { logError func(msg string, v ...interface{}) } -func NewUserPrivacySubprocessor(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, +func NewUserPrivacyTransform(config *pkgconfig.ConfigTransformers, logger *logger.Logger, name string, instance int, outChannels []chan dnsutils.DNSMessage, logInfo func(msg string, v ...interface{}), logError func(msg string, v ...interface{}), ) UserPrivacyProcessor { diff --git a/transformers/userprivacy_test.go b/transformers/userprivacy_test.go index b2572b2d..2989e848 100644 --- a/transformers/userprivacy_test.go +++ b/transformers/userprivacy_test.go @@ -22,7 +22,7 @@ func BenchmarkUserPrivacy_ReduceQname(b *testing.B) { log := logger.New(false) channels := []chan dnsutils.DNSMessage{} - subprocessor := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, channels, log.Info, log.Error) + subprocessor := NewUserPrivacyTransform(config, logger.New(false), "test", 0, channels, log.Info, log.Error) qname := "localhost.domain.local.home" b.ResetTimer() @@ -39,7 +39,7 @@ func BenchmarkUserPrivacy_HashIP(b *testing.B) { log := logger.New(false) channels := []chan dnsutils.DNSMessage{} - subprocessor := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, channels, log.Info, log.Error) + subprocessor := NewUserPrivacyTransform(config, logger.New(false), "test", 0, channels, log.Info, log.Error) b.ResetTimer() for i := 0; i < b.N; i++ { @@ -56,7 +56,7 @@ func BenchmarkUserPrivacy_HashIPSha512(b *testing.B) { log := logger.New(false) channels := []chan dnsutils.DNSMessage{} - subprocessor := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, channels, log.Info, log.Error) + subprocessor := NewUserPrivacyTransform(config, logger.New(false), "test", 0, channels, log.Info, log.Error) b.ResetTimer() for i := 0; i < b.N; i++ { @@ -72,7 +72,7 @@ func BenchmarkUserPrivacy_AnonymizeIP(b *testing.B) { log := logger.New(false) channels := []chan dnsutils.DNSMessage{} - subprocessor := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, channels, log.Info, log.Error) + subprocessor := NewUserPrivacyTransform(config, logger.New(false), "test", 0, channels, log.Info, log.Error) b.ResetTimer() for i := 0; i < b.N; i++ { @@ -91,7 +91,7 @@ func TestUserPrivacy_ReduceQname(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - userPrivacy := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + userPrivacy := NewUserPrivacyTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) qname := "www.google.com" ret := userPrivacy.MinimazeQname(qname) @@ -122,7 +122,7 @@ func TestUserPrivacy_HashIPDefault(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - userPrivacy := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + userPrivacy := NewUserPrivacyTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) ret := userPrivacy.HashIP(TestIP4) if ret != "c0ca1efec6aaf505e943397662c28f89ac8f3bc2" { @@ -141,7 +141,7 @@ func TestUserPrivacy_HashIPSha512(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - userPrivacy := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + userPrivacy := NewUserPrivacyTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) ret := userPrivacy.HashIP(TestIP4) if ret != "800e8f97a29404b7031dfb8d7185b2d30a3cd326b535cda3dcec20a0f4749b1099f98e49245d67eb188091adfba9a45dc0c15e612b554ae7181d8f8a479b67a0" { @@ -159,7 +159,7 @@ func TestUserPrivacy_AnonymizeIPv4DefaultMask(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - userPrivacy := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + userPrivacy := NewUserPrivacyTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) ret := userPrivacy.AnonymizeIP(TestIP4) if ret != "192.168.0.0" { @@ -177,7 +177,7 @@ func TestUserPrivacy_AnonymizeIPv6DefaultMask(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - userPrivacy := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + userPrivacy := NewUserPrivacyTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) ret := userPrivacy.AnonymizeIP(TestIP6) if ret != "fe80::" { @@ -196,7 +196,7 @@ func TestUserPrivacy_AnonymizeIPv4RemoveIP(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - userPrivacy := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + userPrivacy := NewUserPrivacyTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) ret := userPrivacy.AnonymizeIP(TestIP4) if ret != "0.0.0.0" { @@ -215,7 +215,7 @@ func TestUserPrivacy_AnonymizeIPv6RemoveIP(t *testing.T) { outChans := []chan dnsutils.DNSMessage{} // init the processor - userPrivacy := NewUserPrivacySubprocessor(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) + userPrivacy := NewUserPrivacyTransform(config, logger.New(false), "test", 0, outChans, log.Info, log.Error) ret := userPrivacy.AnonymizeIP(TestIP6) if ret != "::" {