diff --git a/bird/bird.go b/bird/bird.go index 3feeeb3..399146c 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -9,9 +9,7 @@ import ( var ClientConf BirdConfig var StatusConf StatusConfig - -var rateLimit = 0 -var MAX_RATE = 5 +var rateLimitConf RateLimitConfig var Cache = struct { sync.RWMutex @@ -43,17 +41,21 @@ func InstallRateLimitReset() { c := time.Tick(time.Second) for _ = range c { - rateLimit = 0 + rateLimitConf.Reqs = 0 } }() } func checkRateLimit() bool { - if rateLimit > MAX_RATE { + if !rateLimitConf.Enabled { + return true + } + + if rateLimitConf.Reqs > rateLimitConf.Max { return false } - rateLimit += 1 + rateLimitConf.Reqs += 1 return true } diff --git a/bird/config.go b/bird/config.go index b5c6788..89bf0d8 100644 --- a/bird/config.go +++ b/bird/config.go @@ -14,3 +14,9 @@ type BirdConfig struct { ConfigFilename string `toml:"config"` BirdCmd string `toml:"birdc"` } + +type RateLimitConfig struct { + Reqs int `toml:"requests_per_minute"` + Max int `toml:"requests_per_minute"` + Enabled bool +} diff --git a/config.go b/config.go index 6127f0f..82660a9 100644 --- a/config.go +++ b/config.go @@ -15,9 +15,10 @@ import ( type Config struct { Server endpoints.ServerConfig - Status bird.StatusConfig - Bird bird.BirdConfig - Bird6 bird.BirdConfig + Ratelimit bird.RateLimitConfig + Status bird.StatusConfig + Bird bird.BirdConfig + Bird6 bird.BirdConfig } // Try to load configfiles as specified in the files diff --git a/etc/ecix/birdwatcher.conf b/etc/ecix/birdwatcher.conf index 93cc840..5a5e20c 100644 --- a/etc/ecix/birdwatcher.conf +++ b/etc/ecix/birdwatcher.conf @@ -1,5 +1,3 @@ - - # # Birdwatcher Configuration # @@ -36,6 +34,10 @@ reconfig_timestamp_match = "# Created: (.*)" # Remove fields e.g. last_reboot filter_fields = [] +[ratelimit] +enabled = true +requests_per_minute = 10 + [bird] listen = "0.0.0.0:29188"