Files
tomswall/internal/config/params.go
T
unkinben 8d9a76c751 Add comprehensive nftables compiler with shorewall feature parity
Rewrites the compiler from ~440 to ~1700 lines covering all major shorewall
firewall features: loopback, conntrack fast-path, anti-spoof, DHCP, intra-zone,
blacklist/whitelist, conntrack notrack, tunnels (13 types), rules with sections,
DNAT/redirect, SNAT/masquerade, static NAT, policies with zone exclusions,
MSS clamping, rate limiting, connection limiting, negated addresses, ICMP type
matching, TCP RST reject, user/UID matching, mark match/set, NFQUEUE, NONAT,
and policy-level rate/conn limiting.

Adds full config types for all shorewall subsystems (mangle, accounting, maclist,
netmap, providers, tunnels, conntrack, blrules, proxyarp/ndp, routes, tc, secmarks),
shorewall migration tooling, expanded CLI commands, expression-level diff engine,
and 49 unit tests.
2026-07-01 23:56:44 +10:00

33 lines
743 B
Go

package config
import (
"fmt"
"strings"
)
// SubstituteVars replaces ${var} and $var references in a string with values
// from the vars map. This is the YAML equivalent of shorewall's params file.
func SubstituteVars(s string, vars map[string]string) string {
if len(vars) == 0 || !strings.Contains(s, "$") {
return s
}
result := s
for k, v := range vars {
result = strings.ReplaceAll(result, "${"+k+"}", v)
result = strings.ReplaceAll(result, "$"+k, v)
}
return result
}
func (c *Config) validateVars() error {
for k := range c.Vars {
if k == "" {
return fmt.Errorf("vars: empty variable name")
}
if strings.ContainsAny(k, " \t${}") {
return fmt.Errorf("vars: invalid variable name %q", k)
}
}
return nil
}