mocknetlink

package
v0.0.0-...-21cfbab Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SimulatedError        = errors.New("dummy error")
	NotFoundError         = errors.New("not found")
	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 uint32
const (
	FailNextLinkList FailFlags = 1 << iota
	FailNextLinkByName
	FailNextLinkByNameNotFound
	FailNextRouteList
	FailNextRouteAdd
	FailNextRouteDel
	FailNextAddARP
	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]

	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) AddStaticArpEntry

func (d *MockNetlinkDataplane) AddStaticArpEntry(cidr ip.CIDR, destMAC net.HardwareAddr, ifaceName string) error

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) Delete

func (d *MockNetlinkDataplane) Delete()

func (*MockNetlinkDataplane) GetDeletedConntrackEntries

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

func (*MockNetlinkDataplane) GetFeatures

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

func (*MockNetlinkDataplane) HasStaticArpEntry

func (d *MockNetlinkDataplane) HasStaticArpEntry(cidr ip.CIDR, destMAC net.HardwareAddr, ifaceName string) bool

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 (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) 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)

Jump to

Keyboard shortcuts

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