feat: add support for AmneziaWG (#649)

This commit is contained in:
Christoph
2026-11-10 23:20:12 +01:00
parent 61c8ceaab8
commit e314fd5e80
38 changed files with 2136 additions and 22 deletions
+15 -5
View File
@@ -6,6 +6,7 @@ import (
)
const LocalBackendName = "local"
const AmneziaWGBackendName = "amneziawg"
type Backend struct {
Default string `yaml:"default"` // The default backend to use (defaults to the internal backend)
@@ -19,9 +20,10 @@ type Backend struct {
// External Backend-specific configuration
Mikrotik []BackendMikrotik `yaml:"mikrotik"`
Pfsense []BackendPfsense `yaml:"pfsense"`
Opnsense []BackendOpnsense `yaml:"opnsense"`
Mikrotik []BackendMikrotik `yaml:"mikrotik"`
Pfsense []BackendPfsense `yaml:"pfsense"`
Opnsense []BackendOpnsense `yaml:"opnsense"`
AmneziaWG BackendAmneziaWG `yaml:"amneziawg"`
}
// Validate checks the backend configuration for errors.
@@ -31,9 +33,12 @@ func (b *Backend) Validate() error {
}
uniqueMap := make(map[string]struct{})
if b.AmneziaWG.Enabled {
uniqueMap[AmneziaWGBackendName] = struct{}{}
}
checkBackendId := func(id string) error {
if id == LocalBackendName {
return fmt.Errorf("backend ID %q is a reserved keyword", LocalBackendName)
if id == LocalBackendName || id == AmneziaWGBackendName {
return fmt.Errorf("backend ID %q is a reserved keyword", id)
}
if _, exists := uniqueMap[id]; exists {
return fmt.Errorf("backend ID %q is not unique", id)
@@ -197,3 +202,8 @@ func (b *BackendOpnsense) GetApiTimeout() time.Duration {
}
return b.ApiTimeout
}
type BackendAmneziaWG struct {
Enabled bool `yaml:"enabled"` // Requires a loaded AmneziaWG host kernel module.
IgnoredInterfaces []string `yaml:"ignored_interfaces"`
}
+4
View File
@@ -165,6 +165,10 @@ func defaultConfig() *Config {
// Most resolconf implementations use "tun." as a prefix for interface names.
// But systemd's implementation uses no prefix, for example.
LocalResolvconfPrefix: getEnvStr("WG_PORTAL_BACKEND_LOCAL_RESOLVCONF_PREFIX", "tun."),
AmneziaWG: BackendAmneziaWG{
Enabled: getEnvBool("WG_PORTAL_BACKEND_AMNEZIAWG_ENABLED", false),
IgnoredInterfaces: getEnvStrSlice("WG_PORTAL_BACKEND_IGNORED_AMNEZIAWG_INTERFACES", nil),
},
}
cfg.Web = WebConfig{