Documentation
¶
Overview ¶
Package diff provides configuration comparison functionality for OPNsense configurations.
Index ¶
- type Analyzer
- func (a *Analyzer) CompareAliases(oldCfg, newCfg *common.CommonDevice) []Change
- func (a *Analyzer) CompareDHCP(old, newCfg []common.DHCPScope) []Change
- func (a *Analyzer) CompareFirewallRules(old, newCfg []common.FirewallRule) []Change
- func (a *Analyzer) CompareInterfaces(old, newCfg []common.Interface) []Change
- func (a *Analyzer) CompareNAT(old, newCfg common.NATConfig) []Change
- func (a *Analyzer) CompareRoutes(old, newCfg common.Routing) []Change
- func (a *Analyzer) CompareSystem(old, newCfg *common.System) []Change
- func (a *Analyzer) CompareUsers(old, newCfg []common.User) []Change
- func (a *Analyzer) CompareVLANs(old, newCfg []common.VLAN) []Change
- type Change
- type ChangeType
- type DeviceTypeInfo
- type Engine
- type Metadata
- type Options
- type Result
- type RiskItem
- type RiskSummary
- type Section
- type SecurityImpact
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Analyzer ¶
type Analyzer struct{}
Analyzer performs structural comparison of configurations.
func (*Analyzer) CompareAliases ¶ added in v1.9.0
func (a *Analyzer) CompareAliases(oldCfg, newCfg *common.CommonDevice) []Change
CompareAliases compares the named objects (aliases) of two configs, paired by name.
A rule that names an alias holds only its name (common.ObjectRef), so the firewall and NAT comparisons see no change when the alias's members do. This comparison is what reports a pass rule whose effective source, destination or port set grew because the alias it names did (#953).
There is no section-level guard: an alias added or removed is reported on its own, as firewall rules and users are (GOTCHAS §4.1).
oldCfg and newCfg supply the rules that name each alias, for the security impact; see aliasImpact.
func (*Analyzer) CompareDHCP ¶
CompareDHCP compares DHCP configuration between two configs. Focuses on persistent configuration (static reservations) not ephemeral state (leases).
func (*Analyzer) CompareFirewallRules ¶
func (a *Analyzer) CompareFirewallRules(old, newCfg []common.FirewallRule) []Change
CompareFirewallRules compares firewall rules between two configs.
func (*Analyzer) CompareInterfaces ¶
CompareInterfaces compares interface configuration between two configs.
func (*Analyzer) CompareNAT ¶
CompareNAT compares NAT configuration between two configs.
func (*Analyzer) CompareRoutes ¶
CompareRoutes compares routing configuration between two configs.
func (*Analyzer) CompareSystem ¶
CompareSystem compares system configuration between two configs.
func (*Analyzer) CompareUsers ¶
CompareUsers compares user configuration between two configs.
type Change ¶
type Change struct {
Type ChangeType `json:"type"`
Section Section `json:"section"`
Path string `json:"path"`
Description string `json:"description"`
OldValue string `json:"old_value,omitempty"`
NewValue string `json:"new_value,omitempty"`
SecurityImpact string `json:"security_impact,omitempty"`
// contains filtered or unexported fields
}
Change represents a single configuration change.
type ChangeType ¶
type ChangeType string
ChangeType represents the type of configuration change.
const ( // ChangeAdded indicates a new element was added. ChangeAdded ChangeType = "added" // ChangeRemoved indicates an element was removed. ChangeRemoved ChangeType = "removed" // ChangeModified indicates an element was modified. ChangeModified ChangeType = "modified" // ChangeReordered indicates an element was moved but not modified. ChangeReordered ChangeType = "reordered" )
ChangeType constants enumerate the possible kinds of configuration changes.
func (ChangeType) IsValid ¶
func (c ChangeType) IsValid() bool
IsValid returns true if the change type is a valid value.
func (ChangeType) String ¶
func (c ChangeType) String() string
String returns the string representation of the change type.
func (ChangeType) Symbol ¶
func (c ChangeType) Symbol() string
Symbol returns a single-character symbol for the change type.
type DeviceTypeInfo ¶ added in v1.3.0
DeviceTypeInfo records the device types of the compared configurations.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates configuration comparison.
type Metadata ¶
type Metadata struct {
OldFile string `json:"old_file"`
NewFile string `json:"new_file"`
OldVersion string `json:"old_version,omitempty"`
NewVersion string `json:"new_version,omitempty"`
ComparedAt time.Time `json:"compared_at"`
ToolVersion string `json:"tool_version"`
}
Metadata contains comparison metadata.
type Options ¶
type Options struct {
Sections []string // Filter to specific sections (empty = all)
SecurityOnly bool // Show only security-relevant changes
Format string // Output format (terminal, markdown, json, html)
Normalize bool // Normalize displayed values to reduce noise (whitespace, IPs)
DetectOrder bool // Detect reordered rules without content changes
Mode string // Display mode (unified, side-by-side)
}
Options configures diff behavior.
func (*Options) ShouldIncludeSection ¶
ShouldIncludeSection returns true if the section should be included. Comparison is case-insensitive to handle user input normalization.
type Result ¶
type Result struct {
Summary Summary `json:"summary"`
Metadata Metadata `json:"metadata"`
DeviceType DeviceTypeInfo `json:"device_type"`
Changes []Change `json:"changes"`
RiskSummary RiskSummary `json:"risk_summary"`
}
Result contains the complete diff result.
func (*Result) ChangesBySection ¶
ChangesBySection returns changes grouped by section.
func (*Result) HasChanges ¶
HasChanges returns true if there are any changes.
type RiskItem ¶ added in v1.2.2
RiskItem is an alias for security.RiskItem to avoid type duplication.
type RiskSummary ¶ added in v1.2.2
type RiskSummary = security.RiskSummary
RiskSummary is an alias for security.RiskSummary to avoid type duplication.
type Section ¶
type Section string
Section represents a configuration section.
const ( // SectionSystem represents system configuration. SectionSystem Section = "system" // SectionFirewall represents firewall rules. SectionFirewall Section = "firewall" // SectionNAT represents NAT configuration. SectionNAT Section = "nat" // SectionInterfaces represents interface configuration. SectionInterfaces Section = "interfaces" // SectionVLANs represents VLAN configuration. SectionVLANs Section = "vlans" // SectionDHCP represents DHCP configuration. SectionDHCP Section = "dhcp" // SectionDNS represents DNS configuration. SectionDNS Section = "dns" // SectionVPN represents VPN configuration. SectionVPN Section = "vpn" // SectionUsers represents user configuration. SectionUsers Section = "users" // SectionRouting represents routing configuration. SectionRouting Section = "routing" // SectionCertificates represents certificate configuration. SectionCertificates Section = "certificates" // SectionAliases represents named objects (aliases). SectionAliases Section = "aliases" )
Section constants enumerate the configuration sections available for comparison.
func ImplementedSections ¶
func ImplementedSections() []Section
ImplementedSections returns sections that have comparison logic implemented.
func (Section) IsImplemented ¶
IsImplemented returns true if the section has comparison logic implemented.
type SecurityImpact ¶
type SecurityImpact string
SecurityImpact represents the security impact level of a change.
const ( // SecurityImpactHigh indicates a high security impact (e.g., permissive any-any rules). SecurityImpactHigh SecurityImpact = "high" // SecurityImpactMedium indicates a medium security impact (e.g., user changes, NAT modifications). SecurityImpactMedium SecurityImpact = "medium" // SecurityImpactLow indicates a low security impact (e.g., minor configuration changes). SecurityImpactLow SecurityImpact = "low" )
SecurityImpact constants define the severity tiers for security-relevant changes.
func (SecurityImpact) String ¶
func (s SecurityImpact) String() string
String returns the string representation of the security impact.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package analyzers provides semantic analysis utilities for diff comparisons.
|
Package analyzers provides semantic analysis utilities for diff comparisons. |
|
Package formatters provides output formatting for diff results.
|
Package formatters provides output formatting for diff results. |
|
Package security provides security impact scoring for configuration changes.
|
Package security provides security impact scoring for configuration changes. |