Documentation
¶
Overview ¶
Package sysnetdebug provides a channel-driven sysnet implementation for tests.
Index ¶
- type ConnInfoFunc
- type ConnRuleFunc
- type DNSInFunc
- type DebugIPMatcher
- func (m *DebugIPMatcher) Close() error
- func (m *DebugIPMatcher) Lock()
- func (m *DebugIPMatcher) Map(rule sysnet.Rule) uint64
- func (m *DebugIPMatcher) Match(pkt []byte, id uint64) bool
- func (m *DebugIPMatcher) PktInfo(pkt []byte) *sysnet.NetInfo
- func (m *DebugIPMatcher) UnMap(id uint64)
- func (m *DebugIPMatcher) UnMapAll()
- func (m *DebugIPMatcher) Unlock()
- type DebugSysBuilder
- func (b *DebugSysBuilder) AllocIP() subnet.IPAllocator
- func (b *DebugSysBuilder) AllocSubnet() subnet.SubnetAllocator
- func (b *DebugSysBuilder) Build(opts sysnet.BuildOpts) (*sysnet.System, error)
- func (b *DebugSysBuilder) Close() error
- func (b *DebugSysBuilder) ConnInfo(c net.Conn) *sysnet.NetInfo
- func (b *DebugSysBuilder) ConnRule(c net.Conn, rule sysnet.Rule) bool
- func (b *DebugSysBuilder) DNSMiddleware() *SwapDNS
- func (b *DebugSysBuilder) DebugTun() *DebugTun
- func (b *DebugSysBuilder) ListRules() []sysnet.RuleTypeInfo
- func (b *DebugSysBuilder) RawLocalNet() *gonnect.LoopbackNetwork
- func (b *DebugSysBuilder) RawOutNet() *gonnect.LoopbackNetwork
- func (b *DebugSysBuilder) RuleCompl(rule sysnet.Rule) []string
- func (b *DebugSysBuilder) RuleVerify(rule sysnet.Rule) bool
- func (b *DebugSysBuilder) SetConnInfo(fn ConnInfoFunc)
- func (b *DebugSysBuilder) SetConnRule(fn ConnRuleFunc)
- func (b *DebugSysBuilder) SetDNSBackend(backend dns.Interface)
- func (b *DebugSysBuilder) SetDNSIn(fn DNSInFunc)
- func (b *DebugSysBuilder) SetIPInfo(fn IPInfoFunc)
- func (b *DebugSysBuilder) SetIPMatch(fn IPMatchFunc)
- func (b *DebugSysBuilder) SetRuleCompl(fn RuleComplFunc)
- func (b *DebugSysBuilder) SetRuleVerify(fn RuleVerifyFunc)
- func (b *DebugSysBuilder) SetRules(rules []sysnet.RuleTypeInfo)
- func (b *DebugSysBuilder) SetTunNameFormat(format string)
- func (b *DebugSysBuilder) SetTunNameVerify(fn TunNameVerifyFunc)
- func (b *DebugSysBuilder) TunInbound() chan<- []byte
- func (b *DebugSysBuilder) TunNameFormat() string
- func (b *DebugSysBuilder) TunNameVerify(name string) bool
- func (b *DebugSysBuilder) TunOutbound() <-chan []byte
- type DebugTun
- func (d *DebugTun) BatchSize() int
- func (d *DebugTun) Close() error
- func (d *DebugTun) Events() <-chan tun.Event
- func (d *DebugTun) File() *os.File
- func (d *DebugTun) Inbound() chan<- []byte
- func (d *DebugTun) IsNative() bool
- func (d *DebugTun) MRO() int
- func (d *DebugTun) MTU() (int, error)
- func (d *DebugTun) MWO() int
- func (d *DebugTun) Name() (string, error)
- func (d *DebugTun) Outbound() <-chan []byte
- func (d *DebugTun) Read(bufs [][]byte, sizes []int, offset int) (int, error)
- func (d *DebugTun) Write(bufs [][]byte, offset int) (int, error)
- type IPInfoFunc
- type IPMatchFunc
- type Option
- func WithConnInfo(fn ConnInfoFunc) Option
- func WithConnRule(fn ConnRuleFunc) Option
- func WithDNSIn(fn DNSInFunc) Option
- func WithIPInfo(fn IPInfoFunc) Option
- func WithIPMatch(fn IPMatchFunc) Option
- func WithRuleCompl(fn RuleComplFunc) Option
- func WithRuleVerify(fn RuleVerifyFunc) Option
- func WithTunNameFormat(format string) Option
- func WithTunNameVerify(fn TunNameVerifyFunc) Option
- type RuleComplFunc
- type RuleVerifyFunc
- type SwapDNS
- type TunNameVerifyFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnInfoFunc ¶
ConnInfoFunc returns metadata for a tracked LocalNet connection.
type ConnRuleFunc ¶
ConnRuleFunc matches a tracked LocalNet connection against a rule.
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) 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) 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 ¶
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 ¶
NewDebugTun creates a DebugTun with the supplied name and MTU.
func (*DebugTun) BatchSize ¶
BatchSize returns one because DebugTun transports one packet per channel item.
func (*DebugTun) Inbound ¶
Inbound returns the channel used by tests to inject packets into System.Tun.
func (*DebugTun) Outbound ¶
Outbound returns the channel used by tests to observe packets written to System.Tun.
type IPInfoFunc ¶
IPInfoFunc returns metadata for a packet read from the current DebugTun.
type IPMatchFunc ¶
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 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 ¶
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 ¶
RuleComplFunc returns completions for a partial sysnet rule.
type RuleVerifyFunc ¶
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 (*SwapDNS) SetBackend ¶
SetBackend replaces the DNS backend used by future requests.
type TunNameVerifyFunc ¶
TunNameVerifyFunc verifies a TUN device name.