network

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 33 Imported by: 2

Documentation

Index

Constants

View Source
const (
	VlanIDKey   = "VlanID"
	AzureCNS    = "azure-cns"
	SNATIPKey   = "NCPrimaryIPKey"
	RoutesKey   = "RoutesKey"
	IPTablesKey = "IPTablesKey"
)
View Source
const (
	CnetAddressSpace = "cnetAddressSpace"
)
View Source
const (
	// ipv6 modes
	IPV6Nat = "ipv6nat"
)
View Source
const (
	InfraVnet = 0
)

Variables

Regarding this Hnsv2 and Hnv1 variable this pattern is to avoid passing around os specific objects in platform agnostic code

View Source
var Ipv4DefaultRouteDstPrefix = net.IPNet{
	IP:   net.IPv4zero,
	Mask: net.IPv4Mask(0, 0, 0, 0),
}
View Source
var Ipv6DefaultRouteDstPrefix = net.IPNet{
	IP: net.IPv6zero,

	Mask: net.CIDRMask(0, ipv6AddressMask),
}

Functions

func ConstructEndpointID

func ConstructEndpointID(containerID string, netNsPath string, ifName string) (string, string)

ConstructEndpointID constructs endpoint name from netNsPath.

func EnableHnsV1Timeout

func EnableHnsV1Timeout(timeoutValue int)

func EnableHnsV2Timeout

func EnableHnsV2Timeout(timeoutValue int)

func GetPodNameWithoutSuffix

func GetPodNameWithoutSuffix(podName string) string

func IsNetworkNotFoundError

func IsNetworkNotFoundError(err error) bool

func NewErrorMockEndpointClient

func NewErrorMockEndpointClient(errStr string) error

func UseHnsV2

func UseHnsV2(netNs string) (bool, error)

UseHnsV2 indicates whether to use HNSv1 or HNSv2 HNSv2 should be used if the NetNs is a valid GUID and if the platform has HCN which supports HNSv2 API.

Types

type AzureHNSEndpoint

type AzureHNSEndpoint struct{}

type DNSInfo

type DNSInfo struct {
	Suffix  string
	Servers []string
	Options []string
}

DNSInfo contains DNS information for a container network or endpoint.

type EndpointClient

type EndpointClient interface {
	AddEndpoints(epInfo *EndpointInfo) error
	AddEndpointRules(epInfo *EndpointInfo) error
	DeleteEndpointRules(ep *endpoint)
	MoveEndpointsToContainerNS(epInfo *EndpointInfo, nsID uintptr) error
	SetupContainerInterfaces(epInfo *EndpointInfo) error
	ConfigureContainerInterfacesAndRoutes(epInfo *EndpointInfo) error
	DeleteEndpoints(ep *endpoint) error
}

type EndpointInfo

type EndpointInfo struct {
	Id                       string
	ContainerID              string
	NetNsPath                string
	IfName                   string
	SandboxKey               string
	IfIndex                  int
	MacAddress               net.HardwareAddr
	DNS                      DNSInfo
	IPAddresses              []net.IPNet
	IPsToRouteViaHost        []string
	InfraVnetIP              net.IPNet
	Routes                   []RouteInfo
	Policies                 []policy.Policy
	Gateways                 []net.IP
	EnableSnatOnHost         bool
	EnableInfraVnet          bool
	EnableMultiTenancy       bool
	EnableSnatForDns         bool
	AllowInboundFromHostToNC bool
	AllowInboundFromNCToHost bool
	NetworkContainerID       string
	PODName                  string
	PODNameSpace             string
	Data                     map[string]interface{}
	InfraVnetAddressSpace    string
	SkipHotAttachEp          bool
	IPV6Mode                 string
	VnetCidrs                string
	ServiceCidrs             string
	NATInfo                  []policy.NATInfo
	NICType                  cns.NICType
	SkipDefaultRoutes        bool
}

EndpointInfo contains read-only information about an endpoint.

func (*EndpointInfo) PrettyString

func (epInfo *EndpointInfo) PrettyString() string

type IPConfig

type IPConfig struct {
	Address net.IPNet
	Gateway net.IP
}

type InterfaceInfo

type InterfaceInfo struct {
	Name              string
	MacAddress        net.HardwareAddr
	IPConfigs         []*IPConfig
	Routes            []RouteInfo
	DNS               DNSInfo
	NICType           cns.NICType
	SkipDefaultRoutes bool
}

InterfaceInfo contains information for secondary interfaces

type MockEndpointClient

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

func NewMockEndpointClient

func NewMockEndpointClient(fn func(*EndpointInfo) error) *MockEndpointClient

func (*MockEndpointClient) AddEndpointRules

func (client *MockEndpointClient) AddEndpointRules(_ *EndpointInfo) error

func (*MockEndpointClient) AddEndpoints

func (client *MockEndpointClient) AddEndpoints(epInfo *EndpointInfo) error

func (*MockEndpointClient) ConfigureContainerInterfacesAndRoutes

func (client *MockEndpointClient) ConfigureContainerInterfacesAndRoutes(_ *EndpointInfo) error

func (*MockEndpointClient) DeleteEndpointRules

func (client *MockEndpointClient) DeleteEndpointRules(_ *endpoint)

func (*MockEndpointClient) DeleteEndpoints

func (client *MockEndpointClient) DeleteEndpoints(ep *endpoint) error

func (*MockEndpointClient) MoveEndpointsToContainerNS

func (client *MockEndpointClient) MoveEndpointsToContainerNS(_ *EndpointInfo, _ uintptr) error

func (*MockEndpointClient) SetupContainerInterfaces

func (client *MockEndpointClient) SetupContainerInterfaces(_ *EndpointInfo) error

type MockHNSEndpoint

type MockHNSEndpoint struct {
	HnsIDMap         map[string]*hcsshim.HNSEndpoint
	IsAttachedFlag   bool
	HotAttachFailure bool
}

func NewMockHNSEndpoint

func NewMockHNSEndpoint(isAttached bool, hotAttachFailure bool) *MockHNSEndpoint

func (*MockHNSEndpoint) GetHNSEndpointByID

func (az *MockHNSEndpoint) GetHNSEndpointByID(id string) (*hcsshim.HNSEndpoint, error)

func (*MockHNSEndpoint) GetHNSEndpointByName

func (az *MockHNSEndpoint) GetHNSEndpointByName(endpointName string) (*hcsshim.HNSEndpoint, error)

func (*MockHNSEndpoint) HotAttachEndpoint

func (az *MockHNSEndpoint) HotAttachEndpoint(containerID, endpointID string) error

func (*MockHNSEndpoint) IsAttached

func (az *MockHNSEndpoint) IsAttached(hnsep *hcsshim.HNSEndpoint, containerID string) (bool, error)

type MockNamespace

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

func (*MockNamespace) Close

func (ns *MockNamespace) Close() error

Close releases the resources associated with the namespace object.

func (*MockNamespace) Enter

func (ns *MockNamespace) Enter() error

Enter puts the caller thread inside the namespace.

func (*MockNamespace) Exit

func (ns *MockNamespace) Exit() error

Exit puts the caller thread to its previous namespace.

func (*MockNamespace) GetFd

func (ns *MockNamespace) GetFd() uintptr

GetFd returns the file descriptor of the namespace.

func (*MockNamespace) GetName

func (ns *MockNamespace) GetName() string

type MockNamespaceClient

type MockNamespaceClient struct{}

func NewMockNamespaceClient

func NewMockNamespaceClient() *MockNamespaceClient

func (*MockNamespaceClient) GetCurrentThreadNamespace

func (c *MockNamespaceClient) GetCurrentThreadNamespace() (NamespaceInterface, error)

GetCurrentThreadNamespace returns the caller thread's current namespace.

func (*MockNamespaceClient) OpenNamespace

func (c *MockNamespaceClient) OpenNamespace(ns string) (NamespaceInterface, error)

OpenNamespace creates a new namespace object for the given netns path.

type MockNetworkManager

type MockNetworkManager struct {
	TestNetworkInfoMap  map[string]*NetworkInfo
	TestEndpointInfoMap map[string]*EndpointInfo
	TestEndpointClient  *MockEndpointClient
}

MockNetworkManager is a mock structure for Network Manager

func NewMockNetworkmanager

func NewMockNetworkmanager(mockEndpointclient *MockEndpointClient) *MockNetworkManager

NewMockNetworkmanager returns a new mock

func (*MockNetworkManager) AddExternalInterface

func (nm *MockNetworkManager) AddExternalInterface(ifName string, subnet string) error

AddExternalInterface mock

func (*MockNetworkManager) AttachEndpoint

func (nm *MockNetworkManager) AttachEndpoint(networkID string, endpointID string, sandboxKey string) (*endpoint, error)

AttachEndpoint mock

func (*MockNetworkManager) CreateEndpoint

func (nm *MockNetworkManager) CreateEndpoint(_ apipaClient, _ string, epInfos []*EndpointInfo) error

CreateEndpoint mock

func (*MockNetworkManager) CreateNetwork

func (nm *MockNetworkManager) CreateNetwork(nwInfo *NetworkInfo) error

CreateNetwork mock

func (*MockNetworkManager) DeleteEndpoint

func (nm *MockNetworkManager) DeleteEndpoint(networkID, endpointID string) error

DeleteEndpoint mock

func (*MockNetworkManager) DeleteNetwork

func (nm *MockNetworkManager) DeleteNetwork(networkID string) error

DeleteNetwork mock

func (*MockNetworkManager) DetachEndpoint

func (nm *MockNetworkManager) DetachEndpoint(networkID string, endpointID string) error

DetachEndpoint mock

func (*MockNetworkManager) FindNetworkIDFromNetNs

func (nm *MockNetworkManager) FindNetworkIDFromNetNs(netNs string) (string, error)

func (*MockNetworkManager) GetAllEndpoints

func (nm *MockNetworkManager) GetAllEndpoints(networkID string) (map[string]*EndpointInfo, error)

func (*MockNetworkManager) GetEndpointInfo

func (nm *MockNetworkManager) GetEndpointInfo(networkID string, endpointID string) (*EndpointInfo, error)

GetEndpointInfo mock

func (*MockNetworkManager) GetEndpointInfoBasedOnPODDetails

func (nm *MockNetworkManager) GetEndpointInfoBasedOnPODDetails(networkID string, podName string, podNameSpace string, doExactMatchForPodName bool) (*EndpointInfo, error)

GetEndpointInfoBasedOnPODDetails mock

func (*MockNetworkManager) GetNetworkInfo

func (nm *MockNetworkManager) GetNetworkInfo(networkID string) (NetworkInfo, error)

GetNetworkInfo mock

func (*MockNetworkManager) GetNumEndpointsByContainerID

func (nm *MockNetworkManager) GetNumEndpointsByContainerID(_ string) int

GetNumEndpointsByContainerID mock

func (*MockNetworkManager) GetNumberOfEndpoints

func (nm *MockNetworkManager) GetNumberOfEndpoints(ifName string, networkID string) int

GetNumberOfEndpoints mock

func (*MockNetworkManager) Initialize

func (nm *MockNetworkManager) Initialize(config *common.PluginConfig, isRehydrationRequired bool) error

Initialize mock

func (*MockNetworkManager) SetupNetworkUsingState

func (nm *MockNetworkManager) SetupNetworkUsingState(networkMonitor *cnms.NetworkMonitor) error

SetupNetworkUsingState mock

func (*MockNetworkManager) Uninitialize

func (nm *MockNetworkManager) Uninitialize()

Uninitialize mock

func (*MockNetworkManager) UpdateEndpoint

func (nm *MockNetworkManager) UpdateEndpoint(networkID string, existingEpInfo *EndpointInfo, targetEpInfo *EndpointInfo) error

UpdateEndpoint mock

type Namespace

type Namespace struct{}

Namespace represents a network namespace.

func (*Namespace) Close

func (ns *Namespace) Close() error

Close releases the resources associated with the namespace object.

func (*Namespace) Enter

func (ns *Namespace) Enter() error

Enter puts the caller thread inside the namespace.

func (*Namespace) Exit

func (ns *Namespace) Exit() error

Exit puts the caller thread to its previous namespace.

func (*Namespace) GetFd

func (ns *Namespace) GetFd() uintptr

GetFd returns the file descriptor of the namespace.

func (*Namespace) GetName

func (ns *Namespace) GetName() string

type NamespaceClient

type NamespaceClient struct{}

func NewNamespaceClient

func NewNamespaceClient() *NamespaceClient

func (*NamespaceClient) GetCurrentThreadNamespace

func (c *NamespaceClient) GetCurrentThreadNamespace() (NamespaceInterface, error)

GetCurrentThreadNamespace returns the caller thread's current namespace.

func (*NamespaceClient) OpenNamespace

func (c *NamespaceClient) OpenNamespace(_ string) (NamespaceInterface, error)

OpenNamespace creates a new namespace object for the given netns path.

type NamespaceClientInterface

type NamespaceClientInterface interface {
	OpenNamespace(nsPath string) (NamespaceInterface, error)
	GetCurrentThreadNamespace() (NamespaceInterface, error)
}

type NamespaceInterface

type NamespaceInterface interface {
	GetFd() uintptr
	GetName() string
	Enter() error
	Exit() error
	Close() error
}

type NetworkClient

type NetworkClient interface {
	CreateBridge() error
	DeleteBridge() error
	AddL2Rules(extIf *externalInterface) error
	DeleteL2Rules(extIf *externalInterface)
	SetBridgeMasterToHostInterface() error
	SetHairpinOnHostInterface(bool) error
}

type NetworkInfo

type NetworkInfo struct {
	MasterIfName                  string
	AdapterName                   string
	Id                            string
	Mode                          string
	Subnets                       []SubnetInfo
	PodSubnet                     SubnetInfo
	DNS                           DNSInfo
	Policies                      []policy.Policy
	BridgeName                    string
	EnableSnatOnHost              bool
	NetNs                         string
	Options                       map[string]interface{}
	DisableHairpinOnHostInterface bool
	IPV6Mode                      string
	IPAMType                      string
	ServiceCidrs                  string
	IsIPv6Enabled                 bool
}

NetworkInfo contains read-only information about a container network.

func (*NetworkInfo) PrettyString

func (nwInfo *NetworkInfo) PrettyString() string

type NetworkManager

type NetworkManager interface {
	Initialize(config *common.PluginConfig, isRehydrationRequired bool) error
	Uninitialize()

	AddExternalInterface(ifName string, subnet string) error

	CreateNetwork(nwInfo *NetworkInfo) error
	DeleteNetwork(networkID string) error
	GetNetworkInfo(networkID string) (NetworkInfo, error)
	// FindNetworkIDFromNetNs returns the network name that contains an endpoint created for this netNS, errNetworkNotFound if no network is found
	FindNetworkIDFromNetNs(netNs string) (string, error)
	GetNumEndpointsByContainerID(containerID string) int

	CreateEndpoint(client apipaClient, networkID string, epInfo []*EndpointInfo) error
	DeleteEndpoint(networkID string, endpointID string) error
	GetEndpointInfo(networkID string, endpointID string) (*EndpointInfo, error)
	GetAllEndpoints(networkID string) (map[string]*EndpointInfo, error)
	GetEndpointInfoBasedOnPODDetails(networkID string, podName string, podNameSpace string, doExactMatchForPodName bool) (*EndpointInfo, error)
	AttachEndpoint(networkID string, endpointID string, sandboxKey string) (*endpoint, error)
	DetachEndpoint(networkID string, endpointID string) error
	UpdateEndpoint(networkID string, existingEpInfo *EndpointInfo, targetEpInfo *EndpointInfo) error
	GetNumberOfEndpoints(ifName string, networkID string) int
	SetupNetworkUsingState(networkMonitor *cnms.NetworkMonitor) error
}

NetworkManager API.

func NewNetworkManager

Creates a new network manager.

type RouteInfo

type RouteInfo struct {
	Dst      net.IPNet
	Src      net.IP
	Gw       net.IP
	Protocol int
	DevName  string
	Scope    int
	Priority int
	Table    int
}

RouteInfo contains information about an IP route.

type SubnetInfo

type SubnetInfo struct {
	Family    platform.AddressFamily
	Prefix    net.IPNet
	Gateway   net.IP
	PrimaryIP net.IP
}

SubnetInfo contains subnet information for a container network.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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