Files
elmprodvpn/selective-vpn-api/app/routes_units.go
beckline 10a10f44a8 baseline: api+gui traffic mode + candidates picker
Snapshot before app-launcher (cgroup/mark) work; ignore binaries/backups.
2026-02-14 15:52:20 +03:00

53 lines
1.5 KiB
Go

package app
import (
"fmt"
"os"
"strings"
)
// ---------------------------------------------------------------------
// routes systemd unit name resolution
// ---------------------------------------------------------------------
// EN: Resolve routes service/timer unit names from preferred/active iface.
// EN: Env overrides still have top priority for custom deployments.
// RU: Вычисление имен unit для routes service/timer по preferred/active iface.
// RU: Для кастомных окружений сохраняется приоритет переменных окружения.
func resolveRoutesUnitIface() (string, string) {
st := loadTrafficModeState()
if pref := normalizePreferredIface(st.PreferredIface); pref != "" {
return pref, "preferred"
}
if statusIface := statusIfaceFromFile(); statusIface != "" && statusIface != "-" {
return statusIface, "status"
}
if active, reason := resolveTrafficIface(""); active != "" {
return active, reason
}
return "", "iface-not-found"
}
func routesServiceUnitName() string {
if forced := strings.TrimSpace(os.Getenv(routesServiceEnv)); forced != "" {
return forced
}
iface, _ := resolveRoutesUnitIface()
if iface == "" {
return ""
}
return fmt.Sprintf(routesServiceTemplate, iface)
}
func routesTimerUnitName() string {
if forced := strings.TrimSpace(os.Getenv(routesTimerEnv)); forced != "" {
return forced
}
iface, _ := resolveRoutesUnitIface()
if iface == "" {
return ""
}
return fmt.Sprintf(routesTimerTemplate, iface)
}