Add traffic-control long-tail: mangle/accounting/tc_*
Storage + CRUD (migration 0008, model, id-keyed store, REST handlers) + compiler rendering for mangle, accounting, and tc_devices/tc_classes/tc_filters/ tc_interfaces/tc_priorities, each owned by a device. (Nested tc option structs deferred.)
This commit is contained in:
@@ -45,6 +45,13 @@ type Input struct {
|
||||
ProxyNDP []model.ProxyEntry
|
||||
ArpRules []model.ArpRule
|
||||
Maclist []model.MaclistEntry
|
||||
Mangle []model.MangleRule
|
||||
Accounting []model.AccountingRule
|
||||
TCDevices []model.TCDevice
|
||||
TCClasses []model.TCClass
|
||||
TCFilters []model.TCFilter
|
||||
TCInterfaces []model.TCInterface
|
||||
TCPriorities []model.TCPriority
|
||||
}
|
||||
|
||||
// RenderedConfig is the per-device output served to the agent.
|
||||
@@ -72,6 +79,13 @@ type RenderedConfig struct {
|
||||
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"`
|
||||
Mangle []RenderedMangle `yaml:"mangle,omitempty" json:"mangle,omitempty"`
|
||||
Accounting []RenderedAccounting `yaml:"accounting,omitempty" json:"accounting,omitempty"`
|
||||
TCDevices []RenderedTCDevice `yaml:"tc_devices,omitempty" json:"tc_devices,omitempty"`
|
||||
TCClasses []RenderedTCClass `yaml:"tc_classes,omitempty" json:"tc_classes,omitempty"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// RenderedSNAT is a resolved SNAT/masquerade rule: source addresses masqueraded
|
||||
@@ -220,6 +234,7 @@ func Render(in Input) (*RenderedConfig, error) {
|
||||
// Per-device long-tail sections owned by this device.
|
||||
renderPerDevice(in, out)
|
||||
renderPerDeviceL2(in, out)
|
||||
renderTraffic(in, out)
|
||||
|
||||
return out, nil
|
||||
}
|
||||
@@ -480,5 +495,26 @@ func Compile(ctx context.Context, s *store.Store, device string) (*RenderedConfi
|
||||
if in.Maclist, err = s.ListMaclist(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Mangle, err = s.ListMangle(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Accounting, err = s.ListAccounting(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.TCDevices, err = s.ListTCDevices(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.TCClasses, err = s.ListTCClasses(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.TCFilters, err = s.ListTCFilters(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.TCInterfaces, err = s.ListTCInterfaces(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.TCPriorities, err = s.ListTCPriorities(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return Render(in)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package compiler
|
||||
|
||||
// Traffic-control tier rendered into a device's config.
|
||||
|
||||
type RenderedMangle struct {
|
||||
Action string `yaml:"action" json:"action"`
|
||||
Chain string `yaml:"chain,omitempty" json:"chain,omitempty"`
|
||||
MarkValue string `yaml:"mark_value,omitempty" json:"mark_value,omitempty"`
|
||||
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"`
|
||||
User string `yaml:"user,omitempty" json:"user,omitempty"`
|
||||
Mark string `yaml:"mark,omitempty" json:"mark,omitempty"`
|
||||
Length string `yaml:"length,omitempty" json:"length,omitempty"`
|
||||
TOS string `yaml:"tos,omitempty" json:"tos,omitempty"`
|
||||
Helper string `yaml:"helper,omitempty" json:"helper,omitempty"`
|
||||
Probability *float64 `yaml:"probability,omitempty" json:"probability,omitempty"`
|
||||
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
type RenderedAccounting struct {
|
||||
Action string `yaml:"action" json:"action"`
|
||||
Section string `yaml:"section,omitempty" json:"section,omitempty"`
|
||||
Chain string `yaml:"chain,omitempty" json:"chain,omitempty"`
|
||||
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"`
|
||||
Mark string `yaml:"mark,omitempty" json:"mark,omitempty"`
|
||||
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
type RenderedTCDevice struct {
|
||||
Interface string `yaml:"interface" json:"interface"`
|
||||
InBandwidth string `yaml:"in_bandwidth,omitempty" json:"in_bandwidth,omitempty"`
|
||||
OutBandwidth string `yaml:"out_bandwidth,omitempty" json:"out_bandwidth,omitempty"`
|
||||
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
type RenderedTCClass struct {
|
||||
Interface string `yaml:"interface" json:"interface"`
|
||||
Mark int `yaml:"mark,omitempty" json:"mark,omitempty"`
|
||||
Rate string `yaml:"rate,omitempty" json:"rate,omitempty"`
|
||||
Ceil string `yaml:"ceil,omitempty" json:"ceil,omitempty"`
|
||||
Priority int `yaml:"priority,omitempty" json:"priority,omitempty"`
|
||||
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
type RenderedTCFilter struct {
|
||||
Class string `yaml:"class" json:"class"`
|
||||
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"`
|
||||
TOS string `yaml:"tos,omitempty" json:"tos,omitempty"`
|
||||
Length int `yaml:"length,omitempty" json:"length,omitempty"`
|
||||
Priority int `yaml:"priority,omitempty" json:"priority,omitempty"`
|
||||
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
type RenderedTCInterface struct {
|
||||
Interface string `yaml:"interface" json:"interface"`
|
||||
Type string `yaml:"type,omitempty" json:"type,omitempty"`
|
||||
InBandwidth string `yaml:"in_bandwidth,omitempty" json:"in_bandwidth,omitempty"`
|
||||
OutBandwidth string `yaml:"out_bandwidth,omitempty" json:"out_bandwidth,omitempty"`
|
||||
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
type RenderedTCPriority struct {
|
||||
Band int `yaml:"band" json:"band"`
|
||||
Proto string `yaml:"proto,omitempty" json:"proto,omitempty"`
|
||||
DPort []string `yaml:"dport,omitempty" json:"dport,omitempty"`
|
||||
SPort []string `yaml:"sport,omitempty" json:"sport,omitempty"`
|
||||
Address string `yaml:"address,omitempty" json:"address,omitempty"`
|
||||
Interface string `yaml:"interface,omitempty" json:"interface,omitempty"`
|
||||
Helper string `yaml:"helper,omitempty" json:"helper,omitempty"`
|
||||
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
func renderTraffic(in Input, out *RenderedConfig) {
|
||||
dev := in.Device.Name
|
||||
for _, m := range in.Mangle {
|
||||
if m.Device != dev {
|
||||
continue
|
||||
}
|
||||
out.Mangle = append(out.Mangle, RenderedMangle{
|
||||
Action: m.Action, Chain: m.Chain, MarkValue: m.MarkValue, Source: m.Source, Dest: m.Dest,
|
||||
Proto: m.Proto, DPort: m.DPort, SPort: m.SPort, User: m.User, Mark: m.Mark,
|
||||
Length: m.Length, TOS: m.TOS, Helper: m.Helper, Probability: m.Probability, Comment: m.Comment,
|
||||
})
|
||||
}
|
||||
for _, a := range in.Accounting {
|
||||
if a.Device != dev {
|
||||
continue
|
||||
}
|
||||
out.Accounting = append(out.Accounting, RenderedAccounting{
|
||||
Action: a.Action, Section: a.Section, Chain: a.Chain, Source: a.Source, Dest: a.Dest,
|
||||
Proto: a.Proto, DPort: a.DPort, SPort: a.SPort, Mark: a.Mark, Comment: a.Comment,
|
||||
})
|
||||
}
|
||||
for _, t := range in.TCDevices {
|
||||
if t.Device != dev {
|
||||
continue
|
||||
}
|
||||
out.TCDevices = append(out.TCDevices, RenderedTCDevice{
|
||||
Interface: t.Interface, InBandwidth: t.InBandwidth, OutBandwidth: t.OutBandwidth, Comment: t.Comment,
|
||||
})
|
||||
}
|
||||
for _, t := range in.TCClasses {
|
||||
if t.Device != dev {
|
||||
continue
|
||||
}
|
||||
out.TCClasses = append(out.TCClasses, RenderedTCClass{
|
||||
Interface: t.Interface, Mark: t.Mark, Rate: t.Rate, Ceil: t.Ceil, Priority: t.Priority, Comment: t.Comment,
|
||||
})
|
||||
}
|
||||
for _, t := range in.TCFilters {
|
||||
if t.Device != dev {
|
||||
continue
|
||||
}
|
||||
out.TCFilters = append(out.TCFilters, RenderedTCFilter{
|
||||
Class: t.Class, Source: t.Source, Dest: t.Dest, Proto: t.Proto, DPort: t.DPort, SPort: t.SPort,
|
||||
TOS: t.TOS, Length: t.Length, Priority: t.Priority, Comment: t.Comment,
|
||||
})
|
||||
}
|
||||
for _, t := range in.TCInterfaces {
|
||||
if t.Device != dev {
|
||||
continue
|
||||
}
|
||||
out.TCInterfaces = append(out.TCInterfaces, RenderedTCInterface{
|
||||
Interface: t.Interface, Type: t.Type, InBandwidth: t.InBandwidth, OutBandwidth: t.OutBandwidth, Comment: t.Comment,
|
||||
})
|
||||
}
|
||||
for _, t := range in.TCPriorities {
|
||||
if t.Device != dev {
|
||||
continue
|
||||
}
|
||||
out.TCPriorities = append(out.TCPriorities, RenderedTCPriority{
|
||||
Band: t.Band, Proto: t.Proto, DPort: t.DPort, SPort: t.SPort,
|
||||
Address: t.Address, Interface: t.Interface, Helper: t.Helper, Comment: t.Comment,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user