From 8ae09c094193c9684e2b61d83713f83f8c6c7ede Mon Sep 17 00:00:00 2001 From: benvin Date: Sun, 26 Jul 2026 16:07:28 +1000 Subject: [PATCH] Agent: translate blrules/conntrack/secmarks/vars Map the rendered global-compiled tail into native config.Blrules/Conntrack/ Secmarks/Vars. --- internal/agent/rendered.go | 40 +++++++++++++++++++++++++++++++++++++ internal/agent/translate.go | 26 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/internal/agent/rendered.go b/internal/agent/rendered.go index 13fa356..7f2651a 100644 --- a/internal/agent/rendered.go +++ b/internal/agent/rendered.go @@ -38,6 +38,46 @@ type RenderedConfig struct { TCFilters []RenderedTCFilter `yaml:"tc_filters,omitempty" json:"tc_filters,omitempty"` TCInterfaces []RenderedTCInterface `yaml:"tc_interfaces,omitempty" json:"tc_interfaces,omitempty"` TCPriorities []RenderedTCPriority `yaml:"tc_priorities,omitempty" json:"tc_priorities,omitempty"` + Blrules []RenderedBlrule `yaml:"blrules,omitempty" json:"blrules,omitempty"` + Conntrack []RenderedConntrack `yaml:"conntrack,omitempty" json:"conntrack,omitempty"` + Secmarks []RenderedSecmark `yaml:"secmarks,omitempty" json:"secmarks,omitempty"` + Vars map[string]string `yaml:"vars,omitempty" json:"vars,omitempty"` +} + +type RenderedBlrule struct { + Priority int `yaml:"priority,omitempty" json:"priority,omitempty"` + 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"` + Log string `yaml:"log,omitempty" json:"log,omitempty"` + Comment string `yaml:"comment,omitempty" json:"comment,omitempty"` +} + +type RenderedConntrack 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"` + Chain string `yaml:"chain,omitempty" json:"chain,omitempty"` + Helper string `yaml:"helper,omitempty" json:"helper,omitempty"` + User string `yaml:"user,omitempty" json:"user,omitempty"` + Comment string `yaml:"comment,omitempty" json:"comment,omitempty"` +} + +type RenderedSecmark struct { + Secmark string `yaml:"secmark" json:"secmark"` + Chain string `yaml:"chain" json:"chain"` + 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 RenderedMangle struct { diff --git a/internal/agent/translate.go b/internal/agent/translate.go index 23f0736..0eb0192 100644 --- a/internal/agent/translate.go +++ b/internal/agent/translate.go @@ -190,6 +190,32 @@ func Translate(rc *RenderedConfig) (*config.Config, error) { }) } + for _, b := range rc.Blrules { + cfg.Blrules = append(cfg.Blrules, config.BlruleRule{ + Action: config.BlruleAction(b.Action), Source: b.Source, Dest: b.Dest, Proto: b.Proto, + DPort: config.PortSpec(b.DPort), SPort: config.PortSpec(b.SPort), Log: b.Log, Comment: b.Comment, + }) + } + for _, c := range rc.Conntrack { + cfg.Conntrack = append(cfg.Conntrack, config.ConntrackRule{ + Action: config.ConntrackAction(c.Action), Source: c.Source, Dest: c.Dest, Proto: c.Proto, + DPort: config.PortSpec(c.DPort), SPort: config.PortSpec(c.SPort), + Chain: config.ConntrackChain(c.Chain), Helper: c.Helper, User: c.User, Comment: c.Comment, + }) + } + for _, sm := range rc.Secmarks { + cfg.Secmarks = append(cfg.Secmarks, config.SecmarkRule{ + Secmark: sm.Secmark, Chain: sm.Chain, Source: sm.Source, Dest: sm.Dest, Proto: sm.Proto, + DPort: config.PortSpec(sm.DPort), SPort: config.PortSpec(sm.SPort), Comment: sm.Comment, + }) + } + if len(rc.Vars) > 0 { + cfg.Vars = make(map[string]string, len(rc.Vars)) + for k, v := range rc.Vars { + cfg.Vars[k] = v + } + } + return cfg, nil }