config

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

iprd/config (package)

config provides the configuration models, defaults, validation, TOML helpers, and command-line flag values used by the iprd package and daemon.

Configuration types

The package separates reusable listener settings from daemon-specific forwarding settings:

  • InterfaceConfig defines BPF filtering options for one network interface, selected by name or index.
  • ListenerConfig defines packet capture, filtering, report forwarding, and capture-file behavior.
  • ForwardConfig defines the TCP forwarding endpoint and optional mDNS/DNS-SD advertisement.
  • IPRDConfig embeds ListenerConfig and ForwardConfig to provide the complete daemon configuration.

Use DefaultListenerConfig(), DefaultForwardConfig(), or DefaultIPRDConfig() when constructing configuration programmatically. The corresponding ParseListenerConfig() and ParseConfig() functions apply defaults, normalize interface selectors, and validate the result.

cfg, err := iprdconfig.ParseConfig(&iprdconfig.IPRDConfig{
    ListenerConfig: iprdconfig.ListenerConfig{
        ListenInterfaces: []string{"eth0", "eth1"},
        ForwardKnown:     true,
        Interfaces: []iprdconfig.InterfaceConfig{
            {
                Selector:         "eth1",
                FilterKnownPorts: true,
            },
        },
    },
    ForwardConfig: iprdconfig.ForwardConfig{
        Bind: "0.0.0.0",
        Port: 7788,
        MDNS: true,
    },
})
if err != nil {
    return err
}

ListenInterfaces accepts interface names or numeric indexes. Comma-separated selectors are normalized into individual, unique values. The legacy ListenInterface field remains supported, but new callers should use ListenInterfaces.

An empty listener list is valid while parsing partial configuration; iprd.ListenerManager.Run() still requires at least one configured interface unless automatic interface selection is enabled with Auto.

Per-interface filtering

Global BPF settings on ListenerConfig apply to every listener. Entries in Interfaces add settings for a specific selector. Use InterfaceConfigFor() to retrieve the combined global and per-interface configuration.

filter := cfg.InterfaceConfigFor("eth1")
fmt.Println(filter.FilterKnownPorts)

When NoRootNetwork is enabled, at least one NetworkInclusions entry must be supplied so the resulting filter still includes a network. Network values use BPF IPv4 network notation, such as 192.168.1.0, 192.168.1, 172.16, or 10.

TOML configuration

NewIPRDConfigFromBytes() and NewIPRDConfigFromFile() decode, normalize, and validate TOML configuration. WriteIPRDConfigToFile() performs the same validation before writing a configuration file.

listen_interfaces = ["eth0", "eth1"]
forward_known = true
capture_file = "/var/log/iprd/capture.pcapng"

forward_bind = "0.0.0.0"
forward_port = 7788
mdns = true
mdns_interfaces = ["eth0"]

[[interfaces]]
selector = "eth1"
filter_known_ports = true
ignored_devices = ["00:11:22:33:44:55"]
network_exclusions = ["10"]
cfg, err := iprdconfig.NewIPRDConfigFromFile("iprd.toml")
if err != nil {
    return err
}

if err := iprdconfig.WriteIPRDConfigToFile(cfg, "normalized.toml"); err != nil {
    return err
}

All configuration types also provide Validate() and Merge() methods. Merge() applies non-zero values from a target configuration and returns a new value; it is best suited to additive overrides because zero values do not clear existing settings.

Command-line flag values

FlagSlice and FlagInterface implement flag.Value for applications exposing iprd configuration through Go's flag package.

  • FlagSlice accepts repeated or comma-separated values.
  • FlagInterface accepts interface names, indexes, comma-separated selectors, and numeric index ranges. Per-interface options follow the selector after :, for example eth0:known-ports,exclude=10.

Use FlagInterface.Selectors() and FlagInterface.Configs() to obtain deterministic slices after parsing flags.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteIPRDConfigToFile

func WriteIPRDConfigToFile(supplied *IPRDConfig, filePath string) error

WriteIPRDConfigToFile write TOML configuration of supplied to filePath

Types

type FlagInterface

type FlagInterface map[string]*InterfaceConfig

FlagInterface is a flag value representing a interface configuration. Each key is an interface selector (e.g. "eth0" or 1), with attached InterfaceConfig representing supplied options. Options are specified after ":" separated by commas (e.g., "eth0:no-root-network,add-network=172.16").

func (FlagInterface) Configs

func (f FlagInterface) Configs() []InterfaceConfig

Configs returns the flag values as a deterministic list of interface configurations.

func (FlagInterface) Selectors

func (f FlagInterface) Selectors() []string

Selectors returns the configured interface selectors in deterministic order.

func (*FlagInterface) Set

func (f *FlagInterface) Set(value string) error

func (*FlagInterface) String

func (f *FlagInterface) String() string

type FlagSlice

type FlagSlice []string

FlagSlice is a flag value that supports multiple comma-separated values and chaining.

func (*FlagSlice) Set

func (f *FlagSlice) Set(value string) error

func (*FlagSlice) String

func (f *FlagSlice) String() string

type ForwardConfig

type ForwardConfig struct {
	Bind           string   `toml:"forward_bind" json:"forward_bind"`
	Port           int      `toml:"forward_port" json:"forward_port"`
	MDNS           bool     `toml:"mdns" json:"mdns"`
	MDNSInterfaces []string `toml:"mdns_interfaces,omitempty" json:"mdns_interfaces,omitempty"`
}

ForwardConfig describes the daemon's TCP forwarding endpoint and service advertisement.

func DefaultForwardConfig

func DefaultForwardConfig() *ForwardConfig

DefaultForwardConfig returns the default daemon forwarding configuration.

func (*ForwardConfig) Merge

func (cfg *ForwardConfig) Merge(target *ForwardConfig) *ForwardConfig

Merge returns a new ForwardConfig with non-zero values from target applied.

func (*ForwardConfig) Validate

func (cfg *ForwardConfig) Validate() error

Validate returns an error if ForwardConfig contains invalid endpoint values.

type IPRDConfig

type IPRDConfig struct {
	ListenerConfig
	ForwardConfig
}

IPRDConfig combines reusable listener settings with daemon forwarding settings. ListenerConfig is embedded so existing flat TOML and JSON formats are preserved.

func DefaultIPRDConfig

func DefaultIPRDConfig() *IPRDConfig

DefaultIPRDConfig returns the default daemon configuration.

func NewIPRDConfigFromBytes

func NewIPRDConfigFromBytes(data []byte) (*IPRDConfig, error)

NewIPRDConfigFromBytes unmarshals TOML data into IPRDConfig

func NewIPRDConfigFromFile

func NewIPRDConfigFromFile(filePath string) (*IPRDConfig, error)

NewIPRDConfigFromFile reads a TOML configuration file at filePath into IPRDConfig

func NormalizeConfig added in v0.6.0

func NormalizeConfig(supplied *IPRDConfig) (*IPRDConfig, error)

NormalizeConfig normalizes and validates a complete daemon configuration without reapplying defaults. This preserves valid zero values.

func ParseConfig

func ParseConfig(supplied *IPRDConfig) (*IPRDConfig, error)

ParseConfig applies daemon defaults, normalizes interface selectors, and validates the result.

func (*IPRDConfig) Merge

func (cfg *IPRDConfig) Merge(target *IPRDConfig) *IPRDConfig

Merge returns a new IPRDConfig with non-zero values from target applied.

func (*IPRDConfig) Validate

func (cfg *IPRDConfig) Validate() error

Validate returns an error if IPRDConfig contains invalid listener or forwarding values.

type InterfaceConfig

type InterfaceConfig struct {
	Selector          string   `toml:"selector" json:"selector"`
	NoRootNetwork     bool     `toml:"no_root_network" json:"no_root_network"`
	FilterKnownPorts  bool     `toml:"filter_known_ports" json:"filter_known_ports"`
	IgnoredDevices    []string `toml:"ignored_devices" json:"ignored_devices"`
	NetworkInclusions []string `toml:"network_inclusions" json:"network_inclusions"`
	NetworkExclusions []string `toml:"network_exclusions" json:"network_exclusions"`
}

InterfaceConfig describes BPF configuration for a specific interface.

func DefaultInterfaceConfig

func DefaultInterfaceConfig() *InterfaceConfig

DefaultInterfaceConfig returns a default InterfaceConfig

type ListenerConfig

type ListenerConfig struct {
	Debug              bool              `toml:"debug" json:"debug"`
	Auto               bool              `toml:"auto" json:"auto"`
	ListenInterfaces   []string          `toml:"listen_interfaces,omitempty" json:"listen_interfaces,omitempty"`
	ListenInterface    string            `toml:"listen_interface,omitempty" json:"listen_interface,omitempty"` // Deprecated: use ListenInterfaces.
	Interfaces         []InterfaceConfig `toml:"interfaces,omitempty" json:"interfaces,omitempty"`
	ForwardKnown       bool              `toml:"forward_known" json:"forward_known"`
	NoRootNetwork      bool              `toml:"no_root_network" json:"no_root_network"`
	FilterKnownPorts   bool              `toml:"filter_known_ports" json:"filter_known_ports"`
	IgnoredDevices     []string          `toml:"ignored_devices" json:"ignored_devices"`
	NetworkInclusions  []string          `toml:"network_inclusions" json:"network_inclusions"`
	NetworkExclusions  []string          `toml:"network_exclusions" json:"network_exclusions"`
	CaptureFile        string            `toml:"capture_file" json:"capture_file"`
	RotateCaptureFiles bool              `toml:"rotate_capture_files" json:"rotate_capture_files"`
	DisableSuppression bool              `toml:"disable_suppression" json:"disable_suppression"`
	PersistSuppressed  bool              `toml:"persist_suppressed" json:"persist_suppressed"`
}

ListenerConfig describes packet capture and IP report processing behavior.

func DefaultListenerConfig

func DefaultListenerConfig() *ListenerConfig

DefaultListenerConfig returns the default packet listener configuration.

func NormalizeListenerConfig added in v0.6.0

func NormalizeListenerConfig(supplied *ListenerConfig) (*ListenerConfig, error)

NormalizeListenerConfig normalizes and validates a complete listener configuration without reapplying defaults. This preserves valid zero values.

func ParseListenerConfig

func ParseListenerConfig(supplied *ListenerConfig) (*ListenerConfig, error)

ParseListenerConfig applies listener defaults, normalizes interface selectors, and validates the resulting configuration.

func (*ListenerConfig) InterfaceConfigFor

func (cfg *ListenerConfig) InterfaceConfigFor(selector string) InterfaceConfig

InterfaceConfigFor combines the global BPF configuration with overrides for a selector. The returned configuration owns its slice fields and may be modified by the caller.

func (*ListenerConfig) Merge

func (cfg *ListenerConfig) Merge(target *ListenerConfig) *ListenerConfig

Merge returns a new ListenerConfig with non-zero values from target applied.

func (*ListenerConfig) Validate

func (cfg *ListenerConfig) Validate() error

Validate returns an error if ListenerConfig contains invalid values. An empty interface list is valid for partial configuration and config-file updates; ListenerManager.Run requires at least one interface at runtime.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL