From b94cb9651078523aa1b11ac0734ac7537c469ed7 Mon Sep 17 00:00:00 2001 From: benvin Date: Sun, 26 Jul 2026 15:19:09 +1000 Subject: [PATCH] Agent: translate per-device L2/misc long-tail Map the rendered tunnels/stopped_rules/proxy_arp/proxy_ndp/arp_rules/maclist sections into native tomswall config. --- internal/agent/rendered.go | 53 +++++++++++++++++++++++++++++++++++++ internal/agent/translate.go | 37 ++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/internal/agent/rendered.go b/internal/agent/rendered.go index 63e71fd..1a8eb9f 100644 --- a/internal/agent/rendered.go +++ b/internal/agent/rendered.go @@ -25,6 +25,59 @@ type RenderedConfig struct { Providers []RenderedProvider `yaml:"providers,omitempty" json:"providers,omitempty"` Routes []RenderedRoute `yaml:"routes,omitempty" json:"routes,omitempty"` RoutingRules []RenderedRoutingRule `yaml:"routing_rules,omitempty" json:"routing_rules,omitempty"` + Tunnels []RenderedTunnel `yaml:"tunnels,omitempty" json:"tunnels,omitempty"` + StoppedRules []RenderedStoppedRule `yaml:"stopped_rules,omitempty" json:"stopped_rules,omitempty"` + ProxyARP []RenderedProxy `yaml:"proxy_arp,omitempty" json:"proxy_arp,omitempty"` + ProxyNDP []RenderedProxy `yaml:"proxy_ndp,omitempty" json:"proxy_ndp,omitempty"` + ArpRules []RenderedArpRule `yaml:"arp_rules,omitempty" json:"arp_rules,omitempty"` + Maclist []RenderedMaclist `yaml:"maclist,omitempty" json:"maclist,omitempty"` +} + +type RenderedTunnel struct { + Type string `yaml:"type" json:"type"` + Zone string `yaml:"zone" json:"zone"` + Gateways []string `yaml:"gateways,omitempty" json:"gateways,omitempty"` + GatewayZones []string `yaml:"gateway_zones,omitempty" json:"gateway_zones,omitempty"` + Port int `yaml:"port,omitempty" json:"port,omitempty"` + Comment string `yaml:"comment,omitempty" json:"comment,omitempty"` +} + +type RenderedStoppedRule struct { + Action string `yaml:"action" json:"action"` + Source string `yaml:"source,omitempty" json:"source,omitempty"` + Dest string `yaml:"dest,omitempty" json:"dest,omitempty"` + Proto string `yaml:"proto,omitempty" json:"proto,omitempty"` + DPort []string `yaml:"dport,omitempty" json:"dport,omitempty"` + SPort []string `yaml:"sport,omitempty" json:"sport,omitempty"` + Comment string `yaml:"comment,omitempty" json:"comment,omitempty"` +} + +type RenderedProxy struct { + Address string `yaml:"address" json:"address"` + Interface string `yaml:"interface,omitempty" json:"interface,omitempty"` + External string `yaml:"external" json:"external"` + HaveRoute bool `yaml:"haveroute,omitempty" json:"haveroute,omitempty"` + Persistent bool `yaml:"persistent,omitempty" json:"persistent,omitempty"` + Comment string `yaml:"comment,omitempty" json:"comment,omitempty"` +} + +type RenderedArpRule struct { + Action string `yaml:"action" json:"action"` + ActionAddress string `yaml:"action_address,omitempty" json:"action_address,omitempty"` + ActionMAC string `yaml:"action_mac,omitempty" json:"action_mac,omitempty"` + Source string `yaml:"source,omitempty" json:"source,omitempty"` + Dest string `yaml:"dest,omitempty" json:"dest,omitempty"` + Opcode int `yaml:"opcode,omitempty" json:"opcode,omitempty"` + Comment string `yaml:"comment,omitempty" json:"comment,omitempty"` +} + +type RenderedMaclist struct { + Action string `yaml:"action" json:"action"` + Interface string `yaml:"interface" json:"interface"` + MAC string `yaml:"mac,omitempty" json:"mac,omitempty"` + Addresses []string `yaml:"addresses,omitempty" json:"addresses,omitempty"` + Log string `yaml:"log,omitempty" json:"log,omitempty"` + Comment string `yaml:"comment,omitempty" json:"comment,omitempty"` } type RenderedHost struct { diff --git a/internal/agent/translate.go b/internal/agent/translate.go index 5a64a24..e186067 100644 --- a/internal/agent/translate.go +++ b/internal/agent/translate.go @@ -106,6 +106,43 @@ func Translate(rc *RenderedConfig) (*config.Config, error) { }) } + for _, t := range rc.Tunnels { + cfg.Tunnels = append(cfg.Tunnels, config.Tunnel{ + Type: t.Type, Zone: t.Zone, Gateways: t.Gateways, + GatewayZones: t.GatewayZones, Port: t.Port, Comment: t.Comment, + }) + } + for _, r := range rc.StoppedRules { + cfg.StoppedRules = append(cfg.StoppedRules, config.StoppedRule{ + Action: config.StoppedAction(r.Action), Source: r.Source, Dest: r.Dest, + Proto: r.Proto, DPort: config.PortSpec(r.DPort), SPort: config.PortSpec(r.SPort), Comment: r.Comment, + }) + } + for _, p := range rc.ProxyARP { + cfg.ProxyARP = append(cfg.ProxyARP, config.ProxyARP{ + Address: p.Address, Interface: p.Interface, External: p.External, + HaveRoute: p.HaveRoute, Persistent: p.Persistent, Comment: p.Comment, + }) + } + for _, p := range rc.ProxyNDP { + cfg.ProxyNDP = append(cfg.ProxyNDP, config.ProxyNDP{ + Address: p.Address, Interface: p.Interface, External: p.External, + HaveRoute: p.HaveRoute, Persistent: p.Persistent, Comment: p.Comment, + }) + } + for _, a := range rc.ArpRules { + cfg.ArpRules = append(cfg.ArpRules, config.ArpRule{ + Action: config.ArpAction(a.Action), ActionAddress: a.ActionAddress, ActionMAC: a.ActionMAC, + Source: a.Source, Dest: a.Dest, Opcode: a.Opcode, Comment: a.Comment, + }) + } + for _, m := range rc.Maclist { + cfg.Maclist = append(cfg.Maclist, config.MaclistEntry{ + Action: config.MaclistAction(m.Action), Interface: m.Interface, MAC: m.MAC, + Addresses: m.Addresses, Log: m.Log, Comment: m.Comment, + }) + } + return cfg, nil }