Skip to content

Commit

Permalink
suspicious and userprivacy reload
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Oct 26, 2023
1 parent 1ee05ed commit 151fc49
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions transformers/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func NewMapQueries(ttl time.Duration, channels []chan dnsutils.DnsMessage) MapQu
}
}

func (mp *MapQueries) SetTtl(ttl time.Duration) {
mp.ttl = ttl
}

func (mp *MapQueries) Exists(key uint64) (ok bool) {
mp.RLock()
defer mp.RUnlock()
Expand Down Expand Up @@ -69,6 +73,10 @@ func NewHashQueries(ttl time.Duration) HashQueries {
}
}

func (mp *HashQueries) SetTtl(ttl time.Duration) {
mp.ttl = ttl
}

func (mp *HashQueries) Get(key uint64) (value int64, ok bool) {
mp.RLock()
defer mp.RUnlock()
Expand Down Expand Up @@ -124,6 +132,13 @@ func NewLatencySubprocessor(config *dnsutils.ConfigTransformers, logger *logger.
return &s
}

func (s *LatencyProcessor) ReloadConfig(config *dnsutils.ConfigTransformers) {
s.config = config

s.hashQueries.SetTtl(time.Duration(config.Latency.QueriesTimeout) * time.Second)
s.mapQueries.SetTtl(time.Duration(config.Latency.QueriesTimeout) * time.Second)
}

func (s *LatencyProcessor) MeasureLatency(dm *dnsutils.DnsMessage) {
queryport, _ := strconv.Atoi(dm.NetworkInfo.QueryPort)
if len(dm.NetworkInfo.QueryIp) > 0 && queryport > 0 && !dm.DNS.MalformedPacket {
Expand Down
3 changes: 3 additions & 0 deletions transformers/subprocessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func (p *Transforms) ReloadConfig(config *dnsutils.ConfigTransformers) {
p.NormalizeTransform.ReloadConfig(config)
p.GeoipTransform.ReloadConfig(config)
p.FilteringTransform.ReloadConfig(config)
p.UserPrivacyTransform.ReloadConfig(config)
p.LatencyTransform.ReloadConfig(config)
p.SuspiciousTransform.ReloadConfig(config)

p.Prepare()
}
Expand Down
1 change: 1 addition & 0 deletions transformers/subprocessors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func TestTransformAndFilter(t *testing.T) {
config.UserPrivacy.AnonymizeIP = true

// file contains google.fr, test.github.com
config.Filtering.Enable = true
config.Filtering.KeepDomainFile = "../testsdata/filtering_keep_domains.txt"

TEST_URL1 := "mail.google.com"
Expand Down
15 changes: 15 additions & 0 deletions transformers/suspicious.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ func NewSuspiciousSubprocessor(config *dnsutils.ConfigTransformers, logger *logg
}

func (p *SuspiciousTransform) ReadConfig() {
// cleanup maps
for key := range p.CommonQtypes {
delete(p.CommonQtypes, key)
}
for key := range p.whitelistDomainsRegex {
delete(p.whitelistDomainsRegex, key)
}

// load maps
for _, v := range p.config.Suspicious.CommonQtypes {
p.CommonQtypes[v] = true
}
Expand All @@ -51,6 +60,12 @@ func (p *SuspiciousTransform) ReadConfig() {
}
}

func (s *SuspiciousTransform) ReloadConfig(config *dnsutils.ConfigTransformers) {
s.config = config

s.ReadConfig()
}

func (p *SuspiciousTransform) IsEnabled() bool {
return p.config.Suspicious.Enable
}
Expand Down
4 changes: 4 additions & 0 deletions transformers/userprivacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func NewUserPrivacySubprocessor(config *dnsutils.ConfigTransformers, logger *log
return s
}

func (s *UserPrivacyProcessor) ReloadConfig(config *dnsutils.ConfigTransformers) {
s.config = config
}

func (s *UserPrivacyProcessor) MinimazeQname(qname string) string {
if etpo, err := publicsuffix.EffectiveTLDPlusOne(qname); err == nil {
return etpo
Expand Down

0 comments on commit 151fc49

Please sign in to comment.