summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorradhitya <alif@radhitya.org>2026-06-21 09:48:42 +0700
committerradhitya <alif@radhitya.org>2026-06-21 09:48:42 +0700
commitb7359e1d45f505171356bcae3c7d5e2341ecc859 (patch)
treef91d4a4b08ce279d488a76e9b7141e69fc844ea9 /internal/config
parent2b1f613c42de3861141eb6f93c1740b6937ee183 (diff)
forward mode, cache opt, ACL, rate limit, admin/health, systemd, fix UDP reply
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go63
1 files changed, 49 insertions, 14 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 1fa8069..b2c88ee 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -8,11 +8,13 @@ import (
)
type Config struct {
- Server ServerConfig `toml:"server"`
- Cache CacheConfig `toml:"cache"`
- Resolver ResolverConfig `toml:"resolver"`
+ Server ServerConfig `toml:"server"`
+ Cache CacheConfig `toml:"cache"`
+ Resolver ResolverConfig `toml:"resolver"`
Blocklist BlocklistConfig `toml:"blocklist"`
- Log LogConfig `toml:"log"`
+ Admin AdminConfig `toml:"admin"`
+ ACL ACLConfig `toml:"acl"`
+ Log LogConfig `toml:"log"`
}
type ServerConfig struct {
@@ -27,10 +29,10 @@ type CacheConfig struct {
}
type ResolverConfig struct {
- Mode string `toml:"mode"`
- Timeout string `toml:"timeout"`
- MaxDelegations int `toml:"max_delegations"`
- Forwarders []string `toml:"forwarders"`
+ Mode string `toml:"mode"`
+ Timeout string `toml:"timeout"`
+ MaxDelegations int `toml:"max_delegations"`
+ Forwarders []string `toml:"forwarders"`
}
type BlocklistConfig struct {
@@ -44,13 +46,23 @@ type LogConfig struct {
}
type CLIFlags struct {
- Config string
- LogLevel string
+ Config string
+ LogLevel string
ListenUDP string
ListenTCP string
ListenDOH string
}
+type ACLConfig struct {
+ Allow []string `toml:"allow"`
+ RateLimitQPS int `toml:"rate_limit_qps"`
+ RateLimitBurst int `toml:"rate_limit_burst"`
+}
+
+type AdminConfig struct {
+ Listen string `toml:"listen"`
+}
+
func ParseFlags() CLIFlags {
var f CLIFlags
flag.StringVar(&f.Config, "config", "linum.toml", "path to config file")
@@ -62,7 +74,7 @@ func ParseFlags() CLIFlags {
return f
}
-func Default() Config{
+func Default() Config {
return Config{
Server: ServerConfig{
ListenUDP: ":5353",
@@ -73,8 +85,8 @@ func Default() Config{
MaxEntries: 100000,
},
Resolver: ResolverConfig{
- Mode: "recursive",
- Timeout: "2s",
+ Mode: "recursive",
+ Timeout: "2s",
MaxDelegations: 30,
},
Blocklist: BlocklistConfig{
@@ -83,6 +95,14 @@ func Default() Config{
Log: LogConfig{
Level: "info",
},
+ Admin: AdminConfig{
+ Listen: "127.0.0.1:8080",
+ },
+ ACL: ACLConfig{
+ Allow: []string{},
+ RateLimitQPS: 50,
+ RateLimitBurst: 10,
+ },
}
}
@@ -132,6 +152,18 @@ func Merge(dst, src Config) Config {
if src.Log.Level != "" {
dst.Log.Level = src.Log.Level
}
+ if src.ACL.Allow != nil {
+ dst.ACL.Allow = src.ACL.Allow
+ }
+ if src.ACL.RateLimitQPS != 0 {
+ dst.ACL.RateLimitQPS = src.ACL.RateLimitQPS
+ }
+ if src.ACL.RateLimitBurst != 0 {
+ dst.ACL.RateLimitBurst = src.ACL.RateLimitBurst
+ }
+ if src.Admin.Listen != "" {
+ dst.Admin.Listen = src.Admin.Listen
+ }
return dst
}
@@ -157,10 +189,13 @@ func (c Config) Validate() error {
default:
return fmt.Errorf("invalid blocklist response %q (want zero_ip or nxdomain)", c.Blocklist.Response)
}
+ switch c.ACL.Allow {
+ default:
+ }
switch c.Resolver.Mode {
case "recursive", "forward", "":
- // nothing happened lol
+ // nothing happened lol
default:
return fmt.Errorf("invalid resolver mode %q (recursive or forward)", c.Resolver.Mode)
}