sysnetdebug

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: CC0-1.0 Imports: 11 Imported by: 0

README

sysnet-debug

Debug/test implementation of gonnect sysnet abstraction.

License

Files in this repository are distributed under the CC0 license.

CC0
To the extent possible under law, ASCIIMoth has waived all copyright and related or neighboring rights to gonnect.

Documentation

Overview

Package sysnetdebug provides a channel-driven sysnet implementation for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnInfoFunc

type ConnInfoFunc func(net.Conn) *sysnet.NetInfo

ConnInfoFunc returns metadata for a tracked LocalNet connection.

type ConnRuleFunc

type ConnRuleFunc func(net.Conn, sysnet.Rule) bool

ConnRuleFunc matches a tracked LocalNet connection against a rule.

type DNSInFunc

type DNSInFunc func(dns.Interface)

DNSInFunc installs or replaces the system DNS input integration.

type DebugIPMatcher

type DebugIPMatcher struct {
	// contains filtered or unexported fields
}

DebugIPMatcher is an IP matcher backed by DebugSysBuilder callbacks.

func NewDebugIPMatcher

func NewDebugIPMatcher(builder *DebugSysBuilder) *DebugIPMatcher

NewDebugIPMatcher creates an IP matcher for a DebugSysBuilder.

func (*DebugIPMatcher) Close

func (m *DebugIPMatcher) Close() error

Close releases matcher state.

func (*DebugIPMatcher) Lock

func (m *DebugIPMatcher) Lock()

Lock is accepted for compatibility with routing code.

DebugIPMatcher synchronizes each operation internally, so this method is a no-op. This also keeps callbacks usable when callers hold the routing lock while evaluating Match.

func (*DebugIPMatcher) Map

func (m *DebugIPMatcher) Map(rule sysnet.Rule) uint64

Map records a rule and returns its matcher ID.

func (*DebugIPMatcher) Match

func (m *DebugIPMatcher) Match(pkt []byte, id uint64) bool

Match calls the configured packet matcher for packets seen on DebugTun.

func (*DebugIPMatcher) PktInfo

func (m *DebugIPMatcher) PktInfo(pkt []byte) *sysnet.NetInfo

PktInfo calls the configured packet metadata callback for packets seen on DebugTun.

func (*DebugIPMatcher) UnMap

func (m *DebugIPMatcher) UnMap(id uint64)

UnMap removes a mapped rule.

func (*DebugIPMatcher) UnMapAll

func (m *DebugIPMatcher) UnMapAll()

UnMapAll removes all mapped rules.

func (*DebugIPMatcher) Unlock

func (m *DebugIPMatcher) Unlock()

Unlock is accepted for compatibility with routing code.

type DebugSysBuilder

type DebugSysBuilder struct {
	// contains filtered or unexported fields
}

DebugSysBuilder is a channel-driven sysnet implementation for tests.

The builder owns raw loopback networks, a swappable DNS middleware, and the current DebugTun. Each Build call returns fresh detached wrappers and closes wrappers returned by the previous build.

func NewDebugSysBuilder

func NewDebugSysBuilder(rules []sysnet.RuleTypeInfo, opts ...Option) *DebugSysBuilder

NewDebugSysBuilder creates a DebugSysBuilder with the supplied rule list.

func (*DebugSysBuilder) AllocIP

func (b *DebugSysBuilder) AllocIP() subnet.IPAllocator

AllocIP returns the builder's gonnect subnet IP allocator.

func (*DebugSysBuilder) AllocSubnet

func (b *DebugSysBuilder) AllocSubnet() subnet.SubnetAllocator

AllocSubnet returns the builder's gonnect subnet allocator.

func (*DebugSysBuilder) Build

func (b *DebugSysBuilder) Build(opts sysnet.BuildOpts) (*sysnet.System, error)

Build creates a debug System with fresh detached wrappers.

func (*DebugSysBuilder) Close

func (b *DebugSysBuilder) Close() error

Close closes current detached build artifacts and raw debug resources.

func (*DebugSysBuilder) ConnInfo

func (b *DebugSysBuilder) ConnInfo(c net.Conn) *sysnet.NetInfo

ConnInfo returns callback metadata only for connections accepted by LocalNet.

func (*DebugSysBuilder) ConnRule

func (b *DebugSysBuilder) ConnRule(c net.Conn, rule sysnet.Rule) bool

ConnRule calls the configured matcher only for connections accepted by LocalNet.

func (*DebugSysBuilder) DNSMiddleware

func (b *DebugSysBuilder) DNSMiddleware() *SwapDNS

DNSMiddleware returns the builder's swappable DNS middleware.

func (*DebugSysBuilder) DebugTun

func (b *DebugSysBuilder) DebugTun() *DebugTun

DebugTun returns the current raw DebugTun, or nil when no TUN is built.

func (*DebugSysBuilder) ListRules

func (b *DebugSysBuilder) ListRules() []sysnet.RuleTypeInfo

ListRules returns a new copy of the configured rule metadata.

func (*DebugSysBuilder) RawLocalNet

func (b *DebugSysBuilder) RawLocalNet() *gonnect.LoopbackNetwork

RawLocalNet returns the raw local loopback network.

func (*DebugSysBuilder) RawOutNet

func (b *DebugSysBuilder) RawOutNet() *gonnect.LoopbackNetwork

RawOutNet returns the raw outbound loopback network.

func (*DebugSysBuilder) RuleCompl

func (b *DebugSysBuilder) RuleCompl(rule sysnet.Rule) []string

RuleCompl calls the configured completer or returns an empty slice by default.

func (*DebugSysBuilder) RuleVerify

func (b *DebugSysBuilder) RuleVerify(rule sysnet.Rule) bool

RuleVerify calls the configured verifier or returns false by default.

func (*DebugSysBuilder) SetConnInfo

func (b *DebugSysBuilder) SetConnInfo(fn ConnInfoFunc)

SetConnInfo replaces the connection metadata callback.

func (*DebugSysBuilder) SetConnRule

func (b *DebugSysBuilder) SetConnRule(fn ConnRuleFunc)

SetConnRule replaces the connection rule callback.

func (*DebugSysBuilder) SetDNSBackend

func (b *DebugSysBuilder) SetDNSBackend(backend dns.Interface)

SetDNSBackend replaces the backend used by DNSOut wrappers.

func (*DebugSysBuilder) SetDNSIn

func (b *DebugSysBuilder) SetDNSIn(fn DNSInFunc)

SetDNSIn replaces the DNSIn callback returned by future Build calls.

func (*DebugSysBuilder) SetIPInfo

func (b *DebugSysBuilder) SetIPInfo(fn IPInfoFunc)

SetIPInfo replaces the packet metadata callback used by new and existing matchers.

func (*DebugSysBuilder) SetIPMatch

func (b *DebugSysBuilder) SetIPMatch(fn IPMatchFunc)

SetIPMatch replaces the packet rule callback used by new and existing matchers.

func (*DebugSysBuilder) SetRuleCompl

func (b *DebugSysBuilder) SetRuleCompl(fn RuleComplFunc)

SetRuleCompl replaces the rule completion callback.

func (*DebugSysBuilder) SetRuleVerify

func (b *DebugSysBuilder) SetRuleVerify(fn RuleVerifyFunc)

SetRuleVerify replaces the rule verification callback.

func (*DebugSysBuilder) SetRules

func (b *DebugSysBuilder) SetRules(rules []sysnet.RuleTypeInfo)

SetRules replaces the rule metadata returned by ListRules.

func (*DebugSysBuilder) SetTunNameFormat

func (b *DebugSysBuilder) SetTunNameFormat(format string)

SetTunNameFormat replaces the TUN name format string.

func (*DebugSysBuilder) SetTunNameVerify

func (b *DebugSysBuilder) SetTunNameVerify(fn TunNameVerifyFunc)

SetTunNameVerify replaces the TUN name verification callback.

func (*DebugSysBuilder) TunInbound

func (b *DebugSysBuilder) TunInbound() chan<- []byte

TunInbound returns the current DebugTun inbound channel.

func (*DebugSysBuilder) TunNameFormat

func (b *DebugSysBuilder) TunNameFormat() string

TunNameFormat returns the configured TUN name format.

func (*DebugSysBuilder) TunNameVerify

func (b *DebugSysBuilder) TunNameVerify(name string) bool

TunNameVerify calls the configured verifier or returns false by default.

func (*DebugSysBuilder) TunOutbound

func (b *DebugSysBuilder) TunOutbound() <-chan []byte

TunOutbound returns the current DebugTun outbound channel.

type DebugTun

type DebugTun struct {
	// contains filtered or unexported fields
}

DebugTun is a channel-backed virtual TUN used by DebugSysBuilder.

Packets sent to Inbound are read by System.Tun. Packets written to System.Tun are copied to Outbound. DebugTun copies packet data at channel boundaries so tests can safely reuse their input buffers.

func NewDebugTun

func NewDebugTun(name string, mtu int) *DebugTun

NewDebugTun creates a DebugTun with the supplied name and MTU.

func (*DebugTun) BatchSize

func (d *DebugTun) BatchSize() int

BatchSize returns one because DebugTun transports one packet per channel item.

func (*DebugTun) Close

func (d *DebugTun) Close() error

Close permanently closes DebugTun.

func (*DebugTun) Events

func (d *DebugTun) Events() <-chan tun.Event

Events returns DebugTun lifecycle events.

func (*DebugTun) File

func (d *DebugTun) File() *os.File

File always returns nil because DebugTun is virtual.

func (*DebugTun) Inbound

func (d *DebugTun) Inbound() chan<- []byte

Inbound returns the channel used by tests to inject packets into System.Tun.

func (*DebugTun) IsNative

func (d *DebugTun) IsNative() bool

IsNative reports false because DebugTun is virtual.

func (*DebugTun) MRO

func (d *DebugTun) MRO() int

MRO returns zero because DebugTun does not reserve read headroom.

func (*DebugTun) MTU

func (d *DebugTun) MTU() (int, error)

MTU returns the configured DebugTun MTU.

func (*DebugTun) MWO

func (d *DebugTun) MWO() int

MWO returns zero because DebugTun does not reserve write headroom.

func (*DebugTun) Name

func (d *DebugTun) Name() (string, error)

Name returns the configured DebugTun name.

func (*DebugTun) Outbound

func (d *DebugTun) Outbound() <-chan []byte

Outbound returns the channel used by tests to observe packets written to System.Tun.

func (*DebugTun) Read

func (d *DebugTun) Read(bufs [][]byte, sizes []int, offset int) (int, error)

Read reads one packet from Inbound.

func (*DebugTun) Write

func (d *DebugTun) Write(bufs [][]byte, offset int) (int, error)

Write writes packets to Outbound.

type IPInfoFunc

type IPInfoFunc func([]byte) *sysnet.NetInfo

IPInfoFunc returns metadata for a packet read from the current DebugTun.

type IPMatchFunc

type IPMatchFunc func([]byte, sysnet.Rule) bool

IPMatchFunc matches a packet read from the current DebugTun against a rule.

type Option

type Option func(*DebugSysBuilder)

Option configures a DebugSysBuilder at construction time.

func WithConnInfo

func WithConnInfo(fn ConnInfoFunc) Option

WithConnInfo sets the connection metadata callback.

func WithConnRule

func WithConnRule(fn ConnRuleFunc) Option

WithConnRule sets the connection rule callback.

func WithDNSIn

func WithDNSIn(fn DNSInFunc) Option

WithDNSIn sets the DNSIn callback returned by Build.

func WithIPInfo

func WithIPInfo(fn IPInfoFunc) Option

WithIPInfo sets the packet metadata callback.

func WithIPMatch

func WithIPMatch(fn IPMatchFunc) Option

WithIPMatch sets the packet rule callback.

func WithRuleCompl

func WithRuleCompl(fn RuleComplFunc) Option

WithRuleCompl sets the rule completion callback.

func WithRuleVerify

func WithRuleVerify(fn RuleVerifyFunc) Option

WithRuleVerify sets the rule verification callback.

func WithTunNameFormat

func WithTunNameFormat(format string) Option

WithTunNameFormat sets the TUN name format returned by TunNameFormat.

func WithTunNameVerify

func WithTunNameVerify(fn TunNameVerifyFunc) Option

WithTunNameVerify sets the TUN name verification callback.

type RuleComplFunc

type RuleComplFunc func(sysnet.Rule) []string

RuleComplFunc returns completions for a partial sysnet rule.

type RuleVerifyFunc

type RuleVerifyFunc func(sysnet.Rule) bool

RuleVerifyFunc verifies a sysnet rule.

type SwapDNS

type SwapDNS struct {
	// contains filtered or unexported fields
}

SwapDNS is a DNS middleware with a replaceable backend.

Without a backend it consumes requests and replies with nil response and nil error, which keeps tests from hanging while still making the operation a no-op.

func NewSwapDNS

func NewSwapDNS() *SwapDNS

NewSwapDNS creates a SwapDNS without a backend.

func (*SwapDNS) Backend

func (s *SwapDNS) Backend() dns.Interface

Backend returns the currently configured DNS backend.

func (*SwapDNS) Close

func (s *SwapDNS) Close() error

Close closes the middleware provider without closing the backend.

func (*SwapDNS) Requests

func (s *SwapDNS) Requests() chan<- dns.Request

Requests returns the request channel.

func (*SwapDNS) SetBackend

func (s *SwapDNS) SetBackend(backend dns.Interface)

SetBackend replaces the DNS backend used by future requests.

type TunNameVerifyFunc

type TunNameVerifyFunc func(string) bool

TunNameVerifyFunc verifies a TUN device name.

Jump to

Keyboard shortcuts

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