Documentation
¶
Overview ¶
Package linux implements gonnect/sysnet.System for Linux.
Index ¶
- type Callbacks
- type Config
- type ConnmarkManager
- type DNSConfig
- type DNSMode
- type FeatureConfig
- type KillswitchClient
- type PacketListenFunc
- type PmarkConfig
- type PmarkController
- type RoutingManager
- type System
- func (s *System) AddTunAddr(t gtun.Tun, addr string) error
- func (s *System) AddTunRoute(t gtun.Tun, route string) error
- func (s *System) AllocIP() subnet.IPAllocator
- func (s *System) AllocSubnet() subnet.SubnetAllocator
- func (s *System) BuildDefaultTun(opts sysnet.DefaultTunOpts) (sysnet.DefaultTun, error)
- func (s *System) BuildMatcher(rule sysnet.Rule) (sysnet.Matcher, error)
- func (s *System) BuildTun(opts sysnet.TunOpts) (gtun.Tun, error)
- func (s *System) Close() error
- func (s *System) DefaultTunWarnings(t sysnet.DefaultTun) []sysnet.Warning
- func (s *System) Features() sysnet.Features
- func (s *System) GetTunAddrs(t gtun.Tun) ([]string, error)
- func (s *System) GetTunRotue(t gtun.Tun) ([]string, error)
- func (s *System) ListRules() sysnet.RulesInfo
- func (s *System) LocalNet() gonnect.Network
- func (s *System) OutDNS() gdns.Interface
- func (s *System) OutNet() gonnect.Network
- func (s *System) RuleCompl(rule sysnet.Rule) (out []string)
- func (s *System) RuleVerify(rule sysnet.Rule) bool
- func (s *System) SetTunAddrs(t gtun.Tun, addrs []string) error
- func (s *System) SetTunMTU(t gtun.Tun, mtu int) error
- func (s *System) SetTunName(t gtun.Tun, name string) ([]string, error)
- func (s *System) SetTunRoutes(t gtun.Tun, routes []string) error
- func (s *System) TunNameVerify(name string) (bool, bool)
- func (s *System) TunWarnings(t gtun.Tun) []sysnet.Warning
- func (s *System) VerifyDefaultTunOpts(opts sysnet.DefaultTunOpts) error
- func (s *System) VerifyTunOpts(opts sysnet.TunOpts) error
- type SystemConfig
- type TUNFactory
- type TUNIndexFunc
- type TunConfigurator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callbacks ¶
type Callbacks struct {
TunCreated func(tun gtun.Tun)
TunConfigured func(tun gtun.Tun, opts sysnet.TunOpts)
DefaultTunCreated func(tun sysnet.DefaultTun)
DefaultTunConfigured func(tun sysnet.DefaultTun, opts sysnet.DefaultTunOpts)
DefaultTunClosed func()
RoutingApplied func(config routing.Config)
DNSConfigured func(server netip.Addr)
KillswitchUpdated func(rules killswitch.AllowRules)
}
Callbacks are optional hooks fired after successful lifecycle operations. Implementations must be quick; System never requires callbacks to be set.
type Config ¶
type Config struct {
Features FeatureConfig
Allocator *linuxsubnet.CombinedAllocator
DNSProvider dns.DNSProvider
RoutingManager RoutingManager
Connmark ConnmarkManager
Pmark PmarkController
Killswitch KillswitchClient
TUNFactory TUNFactory
TunConfig TunConfigurator
RuleTracker *multirule.Tracker
OwnerLookup func(sockowner.FlowTuple) (*sockowner.SocketOwner, error)
PacketListen PacketListenFunc
TUNIndex TUNIndexFunc
AppBypassMark uint32
AppBypassMask uint32
UserMark uint32
UserMarkMask uint32
PmarkPriority int
DefaultTunBaseName string
KillswitchAllowExclude bool
Logf func(format string, args ...any)
Callbacks Callbacks
// ExtraClosers are resources owned by System in addition to the standard
// injected components. They are closed by System.Close after DNS, routing,
// and killswitch state has been released.
ExtraClosers []io.Closer
}
Config supplies System dependencies. Privileged integrations are injected so tests and embedders can choose exactly which Linux components System owns.
type ConnmarkManager ¶ added in v0.2.2
type ConnmarkManager interface {
Apply(linuxconnmark.Config) error
Rollback() error
Close() error
}
ConnmarkManager is the nftables conntrack-mark surface used by System.
type DNSConfig ¶
type DNSConfig struct {
Mode DNSMode
ResolvconfInterface string
ResolvedInterfaceIndex int
FallbackServers []netip.AddrPort
}
DNSConfig configures the DNSProvider built by New.
FallbackServers are used by DNS providers only when no usable original upstream resolver is available. ResolvconfInterface is the provider-owned resolvconf record name; when empty, "sysnet-linux" is used.
type DNSMode ¶
type DNSMode string
DNSMode selects the host DNS integration used by New.
DNSModeAuto uses dns.DnsMode to detect the host DNS integration.
type FeatureConfig ¶
type FeatureConfig struct {
Tun bool
DefaultTun bool
DynTun bool
DynDefaultTun bool
TunNames bool
DefaultTunNames bool
StrictMode bool
TunRules bool
MatcherRules bool
DNSControl bool
Routing bool
Pmark bool
Killswitch bool
}
FeatureConfig describes features requested by the caller. Effective feature support is the requested value degraded by the components supplied in Config.
type KillswitchClient ¶
type KillswitchClient interface {
CreateTMPRuleset(killswitch.AllowRules) (uint64, error)
UpdateTMPRuleset(uint64, killswitch.AllowRules) error
DeleteTMPRuleset(uint64) error
Close() error
}
KillswitchClient is the killswitch temporary-ruleset surface used by System.
type PacketListenFunc ¶
PacketListenFunc opens the UDP socket backing the DefaultTun DNS server.
type PmarkConfig ¶
type PmarkConfig struct {
PinPath string
Callbacks pmark.Callbacks
TombCollectionEvents uint64
TombTTL time.Duration
Priority int
}
PmarkConfig configures the optional p-mark integration built by New.
P-mark is attempted only when PinPath is non-empty. This avoids creating a global bpffs directory implicitly. When enabled, New also starts the fwmark eBPF manager, because DefaultTun include/exclude rules need p-mark values to become socket fwmarks before routing can see them.
type PmarkController ¶
type PmarkController interface {
SetChecker(pmark.CheckFunc) (uint64, error)
ForceProcessTraversal() error
}
PmarkController is the p-mark daemon surface used by System.
type RoutingManager ¶
type RoutingManager interface {
Apply(routing.Config) error
Refresh() error
Rollback(routing.Config) error
Status() (routing.DesiredState, bool)
Close() error
}
RoutingManager is the routing.Manager surface used by System.
type System ¶
type System struct {
// contains filtered or unexported fields
}
System composes the Linux DNS, TUN, routing, p-mark, and killswitch helpers.
func New ¶
func New(config SystemConfig) (*System, error)
New creates a Linux System by constructing native components under the hood.
New probes the current process environment and enables features on a best-effort basis. In particular, TUN and routing are enabled only when CAP_NET_ADMIN is effective and a throwaway TUN can be created; DNS control is enabled only when a configured provider can be built; killswitch is enabled only when requested and a daemon path is usable; TunRules are enabled only when p-mark starts successfully. A missing optional integration is logged and degrades Features(), rather than making construction fail.
Errors are reserved for invalid static configuration or failures in the underlying System constructor after feature degradation.
func (*System) AllocIP ¶
func (s *System) AllocIP() subnet.IPAllocator
AllocIP returns the shared IP allocator.
func (*System) AllocSubnet ¶
func (s *System) AllocSubnet() subnet.SubnetAllocator
AllocSubnet returns the shared subnet allocator.
func (*System) BuildDefaultTun ¶
func (s *System) BuildDefaultTun( opts sysnet.DefaultTunOpts, ) (sysnet.DefaultTun, error)
BuildDefaultTun creates or rebuilds the single active DefaultTun.
func (*System) BuildMatcher ¶
BuildMatcher builds a socket-owner based matcher for LocalNet/TUN flows.
func (*System) DefaultTunWarnings ¶ added in v0.2.12
func (s *System) DefaultTunWarnings(t sysnet.DefaultTun) []sysnet.Warning
DefaultTunWarnings returns read-only runtime warnings for an active DefaultTun created by this System.
func (*System) Features ¶
Features returns effective support after degrading requested features by supplied component availability.
func (*System) RuleCompl ¶
RuleCompl returns quick best-effort completions for rules whose value space is enumerable without process traversal. Account completions are read from the local passwd and group databases, and executable path completion inspects only one directory with a small scan cap so large filesystems cannot make completion expensive.
func (*System) RuleVerify ¶
RuleVerify checks whether a rule value is syntactically valid.
func (*System) TunNameVerify ¶
TunNameVerify checks Linux interface name syntax and availability.
func (*System) TunWarnings ¶ added in v0.2.12
TunWarnings returns read-only runtime warnings for a regular TUN created by this System. sysnet-linux does not currently report regular TUN warnings.
func (*System) VerifyDefaultTunOpts ¶
func (s *System) VerifyDefaultTunOpts(opts sysnet.DefaultTunOpts) error
VerifyDefaultTunOpts validates DefaultTun options without mutating host state.
type SystemConfig ¶
type SystemConfig struct {
Features FeatureConfig
Allocator linuxsubnet.DefaultAllocatorConfig
DNS DNSConfig
KillswitchPath string
Pmark PmarkConfig
AppBypassMark uint32
AppBypassMask uint32
UserMark uint32
UserMarkMask uint32
DefaultTunBaseName string
KillswitchAllowExclude bool
Logf func(format string, args ...any)
Callbacks Callbacks
}
SystemConfig is the high-level, best-effort constructor configuration used by New.
The zero value requests all System-level features and lets New auto-detect which ones are actually available in the current process environment. Missing privileges, absent /dev/net/tun, unavailable routing/DNS/killswitch/p-mark integrations, and unsupported optional daemons disable the affected features while leaving allocation, OutNet, LocalNet, rule verification, and any other available features usable.
For exact dependency injection, deterministic tests, or integrations that need a DNS provider tied to a TUN created elsewhere, use NewSystem.
type TUNFactory ¶
TUNFactory creates a native TUN device.
type TUNIndexFunc ¶
TUNIndexFunc returns the kernel interface index for a TUN.
type TunConfigurator ¶
type TunConfigurator interface {
SetTunMTU(gtun.Tun, int) error
SetTunAddrs(gtun.Tun, []string) error
AddTunAddr(gtun.Tun, string) error
GetTunAddrs(gtun.Tun) ([]string, error)
SetTunRoutes(gtun.Tun, []string) error
AddTunRoute(gtun.Tun, string) error
GetTunRotue(gtun.Tun) ([]string, error)
SetTunName(gtun.Tun, string) ([]string, error)
}
TunConfigurator applies and reads mutable TUN state.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
debug
command
nolint
|
nolint |
|
Package connmark mirrors sysnet packet marks through conntrack marks so inbound replies are marked before distribution rpfilter chains run.
|
Package connmark mirrors sysnet packet marks through conntrack marks so inbound replies are marked before distribution rpfilter chains run. |
|
dnsname
Package dnsname contains string functions for working with DNS names.
|
Package dnsname contains string functions for working with DNS names. |
|
resolvconffile
Package resolvconffile parses & serializes /etc/resolv.conf-style files.
|
Package resolvconffile parses & serializes /etc/resolv.conf-style files. |
|
e2e
|
|
|
routing
command
nolint
|
nolint |
|
system
command
nolint
|
nolint |
|
Package killswitch provides a minimal client for the killswitch daemon admin API.
|
Package killswitch provides a minimal client for the killswitch daemon admin API. |
|
Package routing owns Linux policy routing for sending selected traffic through an already-created VPN TUN interface.
|
Package routing owns Linux policy routing for sending selected traffic through an already-created VPN TUN interface. |
|
Package subnet provides Linux-aware wrappers around gonnect subnet allocation.
|
Package subnet provides Linux-aware wrappers around gonnect subnet allocation. |