Skip to content

Commit

Permalink
geoip reload support
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Oct 25, 2023
1 parent 199cd0e commit 3bddb4c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
10 changes: 10 additions & 0 deletions transformers/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func NewDnsGeoIpProcessor(config *dnsutils.ConfigTransformers, logger *logger.Lo
return d
}

func (p *GeoIpProcessor) ReloadConfig(config *dnsutils.ConfigTransformers) {
p.config = config
}

func (p *GeoIpProcessor) LogInfo(msg string, v ...interface{}) {
log := fmt.Sprintf("transformer=geoip#%d - ", p.instance)
p.logInfo(log+msg, v...)
Expand All @@ -86,6 +90,12 @@ func (p *GeoIpProcessor) InitDnsMessage(dm *dnsutils.DnsMessage) {
}

func (p *GeoIpProcessor) Open() (err error) {
// before to open close all files
// because open can be called also on reload
p.enabled = false
p.Close()

// open files ?
if len(p.config.GeoIP.DbCountryFile) > 0 {
p.dbCountry, err = maxminddb.Open(p.config.GeoIP.DbCountryFile)
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions transformers/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,11 @@ func NewNormalizeSubprocessor(
logError: logError,
}

s.LoadActiveProcessors()
return s
}

func (p *NormalizeProcessor) ReloadConfig(config *dnsutils.ConfigTransformers) {
// save the new config
p.config = config
p.LoadActiveProcessors()
}

func (p *NormalizeProcessor) LogInfo(msg string, v ...interface{}) {
Expand Down
15 changes: 8 additions & 7 deletions transformers/subprocessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,27 @@ func NewTransforms(config *dnsutils.ConfigTransformers, logger *logger.Logger, n

func (p *Transforms) ReloadConfig(config *dnsutils.ConfigTransformers) {
p.config = config
p.Prepare()

// refresh config
p.NormalizeTransform.ReloadConfig(config)
p.GeoipTransform.ReloadConfig(config)

p.Prepare()
}

func (p *Transforms) Prepare() error {
// clean the slice
p.activeTransforms = p.activeTransforms[:0]

if p.config.Normalize.Enable {
prefixlog := fmt.Sprintf("transformer=normalize#%d - ", p.instance)
p.LogInfo(prefixlog + "subprocessor normalize is loaded")
prefixlog := fmt.Sprintf("transformer=normalize#%d ", p.instance)
p.LogInfo(prefixlog + "loaded")

p.NormalizeTransform.LoadActiveProcessors()
}

if p.config.GeoIP.Enable {
p.activeTransforms = append(p.activeTransforms, p.geoipTransform)
prefixlog := fmt.Sprintf("transformer=geoip#%d - ", p.instance)
p.LogInfo(prefixlog + "is enabled")
prefixlog := fmt.Sprintf("transformer=geoip#%d ", p.instance)
p.LogInfo(prefixlog + "loaded")

if err := p.GeoipTransform.Open(); err != nil {
p.LogError(prefixlog+"open error %v", err)
Expand Down

0 comments on commit 3bddb4c

Please sign in to comment.