Documentation
¶
Overview ¶
Package policycompiler computes effector operations from a desired target→policy map and the daemon's current state. Order of operations is rigid (see spec §7.4) and reverse-order rollback runs on any failure.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ARP ¶
type ARP interface {
Start(t arpengine.Target) error
Stop(t arpengine.Target) error
StopAll() error
}
ARP uses arpengine.Target so the implementation (arpengine.Engine) satisfies this interface by structural typing without an adapter.
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler orchestrates the four effectors.
func New ¶
func New(nft NFT, tc TC, pcap Pcap, arp ARP, realIface string, operatorMAC net.HardwareAddr) *Compiler
New constructs a compiler bound to the operator's real iface (used by nft and tc when installing per-target rules and filters).
operatorMAC is the hardware address of the operator's interface. Policies targeting this MAC are rejected to prevent self-DoS.
func (*Compiler) Apply ¶
Apply moves the system to desired.
Phase 1 (teardown) is best-effort across all targets: a failing teardown for target A does NOT stop teardown of B/C/D. This matters at daemon shutdown where comp.Apply(empty) is called — one bad cleanup mustn't abandon every other target's kernel state. The c.current entry for a target is removed only on successful teardown so retrying Apply will retry the cleanup. Errors are aggregated and returned at the end.
Phase 2 (bringup) is strict: a failing bringup short-circuits, with the partial step list reverted in reverse order. The caller can retry by resending the same desired-state map.
c.current is kept in sync with reality: an entry is only present when its kernel-side state has been successfully built up.
type NFT ¶
type NFT interface {
AddTargetDrop(ctx context.Context, mac net.HardwareAddr) error
AddTargetMark(ctx context.Context, mac net.HardwareAddr, mark uint32) error
AddReturnMark(ctx context.Context, mac, gwMAC net.HardwareAddr, targetIP net.IP, mark uint32) error
RemoveTarget(ctx context.Context, mac net.HardwareAddr) error
}
NFT and TC interfaces are deliberately scoped to what the compiler actually calls: per-target rule add/clear. Daemon-lifecycle methods (EnsureTables, EnsureIFB, EnsureRedirect, Teardown) are concrete methods on the *Manager structs in nftmgr/tcmgr and called directly from the daemon main, not via these interfaces. Keeping the interface thin makes the compiler trivially mockable and prevents the test stubs from drifting when daemon-lifecycle methods evolve.
type Spec ¶
type Spec struct {
Target arpengine.Target
Kind Kind
// Throttle:
RateKbit int
// Pcap:
PcapDir string
MaxBytes int64
MaxAge time.Duration
}
Spec is the desired policy for a target. Target is an arpengine.Target so the same value flows directly into ARP.Start without a conversion.
type TC ¶
type TC interface {
SetThrottle(ctx context.Context, realIface, mac, rate string, mark uint32) error
ClearThrottle(ctx context.Context, realIface, mac string, mark uint32) error
SetCapture(ctx context.Context, realIface, mac string, mark uint32) error
ClearCapture(ctx context.Context, realIface string, mark uint32) error
}