mocknetlink

package
v0.0.0-...-271081e Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: Apache-2.0, Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SimulatedError        = errors.New("dummy error")
	NotFoundError         = errors.New("not found")
	LinkNotFoundError     = netlink.LinkNotFoundError{}
	FileDoesNotExistError = errors.New("file does not exist")
	AlreadyExistsError    = errors.New("already exists")
	NotSupportedError     = errors.New("operation not supported")
)

Functions

func KeyForRoute

func KeyForRoute(route *netlink.Route) string

Types

type FailFlags

type FailFlags uint64
const (
	FailNextLinkList FailFlags = 1 << iota
	FailNextLinkByName
	FailNextLinkByNameNotFound
	FailNextRouteList
	FailNextRouteListEINTR
	FailNextRouteAddOrReplace
	FailNextRouteAdd
	FailNextRouteReplace
	FailNextRouteDel
	FailNextNeighSet
	FailNextNeighDel
	FailNextNeighList
	FailNextNewNetlink
	FailNextSetSocketTimeout
	FailNextLinkAdd
	FailNextLinkAddNotSupported
	FailNextLinkDel
	FailNextLinkSetMTU
	FailNextLinkSetUp
	FailNextAddrList
	FailNextAddrAdd
	FailNextAddrDel
	FailNextRuleList
	FailNextRuleAdd
	FailNextRuleDel
	FailNextNewWireguard
	FailNextNewWireguardNotSupported
	FailNextWireguardClose
	FailNextWireguardDeviceByName
	FailNextWireguardConfigureDevice
	FailNextSetStrict
	FailNone FailFlags = 0
)

func (FailFlags) String

func (f FailFlags) String() string
type MockLink struct {
	LinkAttrs netlink.LinkAttrs
	Addrs     []netlink.Addr
	LinkType  string

	WireguardPrivateKey   wgtypes.Key
	WireguardPublicKey    wgtypes.Key
	WireguardListenPort   int
	WireguardFirewallMark int
	WireguardPeers        map[wgtypes.Key]wgtypes.Peer
}

func (*MockLink) Attrs

func (l *MockLink) Attrs() *netlink.LinkAttrs

func (*MockLink) Type

func (l *MockLink) Type() string

type MockNetlinkDataplane

type MockNetlinkDataplane struct {
	NameToLink   map[string]*MockLink
	AddedLinks   set.Set[string]
	DeletedLinks set.Set[string]
	AddedAddrs   set.Set[string]
	DeletedAddrs set.Set[string]

	Rules        []netlink.Rule
	AddedRules   []netlink.Rule
	DeletedRules []netlink.Rule

	ExistingTables   set.Set[int]
	RouteKeyToRoute  map[string]netlink.Route
	AddedRouteKeys   set.Set[string]
	DeletedRouteKeys set.Set[string]
	UpdatedRouteKeys set.Set[string]

	NeighsByFamily map[int]map[NeighKey]*netlink.Neigh

	StrictEnabled               bool
	NumNewNetlinkCalls          int
	NetlinkOpen                 bool
	NumNewWireguardCalls        int
	WireguardOpen               bool
	NumLinkAddCalls             int
	NumLinkDeleteCalls          int
	ImmediateLinkUp             bool
	NumRuleListCalls            int
	NumRuleAddCalls             int
	NumRuleDelCalls             int
	WireguardConfigUpdated      bool
	HitRouteListFilteredNoDev   bool
	HitRouteListFilteredNoTable bool
	LastWireguardUpdates        map[wgtypes.Key]wgtypes.PeerConfig

	PersistentlyFailToConnect bool

	PersistFailures                bool
	FailuresToSimulate             FailFlags
	SetStrictCheckErr              error
	DeleteInterfaceAfterLinkByName bool

	ConntrackSleep time.Duration
	// contains filtered or unexported fields
}

func New

func New() *MockNetlinkDataplane

func (*MockNetlinkDataplane) AddIface

func (d *MockNetlinkDataplane) AddIface(idx int, name string, up bool, running bool) *MockLink

func (*MockNetlinkDataplane) AddMockRoute

func (d *MockNetlinkDataplane) AddMockRoute(route *netlink.Route)

func (*MockNetlinkDataplane) AddNeighs

func (d *MockNetlinkDataplane) AddNeighs(family int, neighs ...netlink.Neigh)

AddNeighs allows test code to add neighbours to the mock dataplane without going through the netlink API.

func (*MockNetlinkDataplane) AddrAdd

func (d *MockNetlinkDataplane) AddrAdd(link netlink.Link, addr *netlink.Addr) error

func (*MockNetlinkDataplane) AddrDel

func (d *MockNetlinkDataplane) AddrDel(link netlink.Link, addr *netlink.Addr) error

func (*MockNetlinkDataplane) AddrList

func (d *MockNetlinkDataplane) AddrList(link netlink.Link, family int) ([]netlink.Addr, error)

func (*MockNetlinkDataplane) DelIface

func (d *MockNetlinkDataplane) DelIface(name string)

func (*MockNetlinkDataplane) Delete

func (d *MockNetlinkDataplane) Delete()

func (*MockNetlinkDataplane) ExpectNeighs

func (d *MockNetlinkDataplane) ExpectNeighs(family int, neighs ...netlink.Neigh)

func (*MockNetlinkDataplane) FeatureGate

func (d *MockNetlinkDataplane) FeatureGate(name string) string

func (*MockNetlinkDataplane) GetDeletedConntrackEntries

func (d *MockNetlinkDataplane) GetDeletedConntrackEntries() []net.IP

func (*MockNetlinkDataplane) GetFeatures

func (d *MockNetlinkDataplane) GetFeatures() *environment.Features

func (*MockNetlinkDataplane) IfIndex

func (d *MockNetlinkDataplane) IfIndex(name string) int

func (*MockNetlinkDataplane) LinkAdd

func (d *MockNetlinkDataplane) LinkAdd(link netlink.Link) error

func (*MockNetlinkDataplane) LinkByName

func (d *MockNetlinkDataplane) LinkByName(name string) (netlink.Link, error)

func (*MockNetlinkDataplane) LinkDel

func (d *MockNetlinkDataplane) LinkDel(link netlink.Link) error
func (d *MockNetlinkDataplane) LinkList() ([]netlink.Link, error)

func (*MockNetlinkDataplane) LinkSetMTU

func (d *MockNetlinkDataplane) LinkSetMTU(link netlink.Link, mtu int) error

func (*MockNetlinkDataplane) LinkSetUp

func (d *MockNetlinkDataplane) LinkSetUp(link netlink.Link) error

func (*MockNetlinkDataplane) NeighAdd

func (d *MockNetlinkDataplane) NeighAdd(neigh *netlink.Neigh) error

func (*MockNetlinkDataplane) NeighDel

func (d *MockNetlinkDataplane) NeighDel(neigh *netlink.Neigh) error

func (*MockNetlinkDataplane) NeighList

func (d *MockNetlinkDataplane) NeighList(linkIndex, family int) ([]netlink.Neigh, error)

func (*MockNetlinkDataplane) NeighSet

func (d *MockNetlinkDataplane) NeighSet(neigh *netlink.Neigh) error
func (d *MockNetlinkDataplane) NewMockNetlink() (netlinkshim.Interface, error)

func (*MockNetlinkDataplane) NewMockWireguard

func (d *MockNetlinkDataplane) NewMockWireguard() (netlinkshim.Wireguard, error)

func (*MockNetlinkDataplane) RefreshFeatures

func (d *MockNetlinkDataplane) RefreshFeatures()

func (*MockNetlinkDataplane) RemoveConntrackFlows

func (d *MockNetlinkDataplane) RemoveConntrackFlows(ipVersion uint8, ipAddr net.IP)

func (*MockNetlinkDataplane) RemoveMockRoute

func (d *MockNetlinkDataplane) RemoveMockRoute(route *netlink.Route)

func (*MockNetlinkDataplane) ResetDeltas

func (d *MockNetlinkDataplane) ResetDeltas()

func (*MockNetlinkDataplane) RouteAdd

func (d *MockNetlinkDataplane) RouteAdd(route *netlink.Route) error

func (*MockNetlinkDataplane) RouteDel

func (d *MockNetlinkDataplane) RouteDel(route *netlink.Route) error

func (*MockNetlinkDataplane) RouteListFiltered

func (d *MockNetlinkDataplane) RouteListFiltered(family int, filter *netlink.Route, filterMask uint64) ([]netlink.Route, error)

func (*MockNetlinkDataplane) RouteListFilteredIter

func (d *MockNetlinkDataplane) RouteListFilteredIter(
	family int,
	filter *netlink.Route,
	filterMask uint64,
	f func(netlink.Route) (cont bool),
) error

func (*MockNetlinkDataplane) RouteReplace

func (d *MockNetlinkDataplane) RouteReplace(route *netlink.Route) error

func (*MockNetlinkDataplane) RuleAdd

func (d *MockNetlinkDataplane) RuleAdd(rule *netlink.Rule) error

func (*MockNetlinkDataplane) RuleDel

func (d *MockNetlinkDataplane) RuleDel(rule *netlink.Rule) error

func (*MockNetlinkDataplane) RuleList

func (d *MockNetlinkDataplane) RuleList(family int) ([]netlink.Rule, error)

func (*MockNetlinkDataplane) SetIface

func (d *MockNetlinkDataplane) SetIface(name string, up bool, running bool)

func (*MockNetlinkDataplane) SetSocketTimeout

func (d *MockNetlinkDataplane) SetSocketTimeout(to time.Duration) error

func (*MockNetlinkDataplane) SetStrictCheck

func (d *MockNetlinkDataplane) SetStrictCheck(b bool) error

type MockWireguard

type MockWireguard struct {
	*MockNetlinkDataplane
}

func (*MockWireguard) Close

func (d *MockWireguard) Close() error

func (*MockWireguard) ConfigureDevice

func (d *MockWireguard) ConfigureDevice(name string, cfg wgtypes.Config) error

func (*MockWireguard) DeviceByName

func (d *MockWireguard) DeviceByName(name string) (*wgtypes.Device, error)

func (*MockWireguard) Devices

func (d *MockWireguard) Devices() ([]*wgtypes.Device, error)

type NeighKey

type NeighKey struct {
	LinkIndex int
	MAC       string
	IP        ip.Addr
}

Jump to

Keyboard shortcuts

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