ipvs

package
v1.0.0 Latest Latest
Warning

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

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

README

This source file was originally from: k8s.io/kubernetes@/v1.21.0

We've changed it for handle xfrm interface and route

Documentation

Index

Constants

View Source
const (
	// FlagPersistent specify IPVS service session affinity
	FlagPersistent = 0x1
	// FlagHashed specify IPVS service hash flag
	FlagHashed = 0x2
)
View Source
const (
	// KernelModuleIPVS is the kernel module "ip_vs"
	KernelModuleIPVS string = "ip_vs"
	// KernelModuleIPVSRR is the kernel module "ip_vs_rr"
	KernelModuleIPVSRR string = "ip_vs_rr"
	// KernelModuleIPVSWRR is the kernel module "ip_vs_wrr"
	KernelModuleIPVSWRR string = "ip_vs_wrr"
	// KernelModuleIPVSSH is the kernel module "ip_vs_sh"
	KernelModuleIPVSSH string = "ip_vs_sh"
	// KernelModuleNfConntrackIPV4 is the module "nf_conntrack_ipv4"
	KernelModuleNfConntrackIPV4 string = "nf_conntrack_ipv4"
	// KernelModuleNfConntrack is the kernel module "nf_conntrack"
	KernelModuleNfConntrack string = "nf_conntrack"
)

IPVS required kernel modules.

View Source
const DefaultScheduler = "rr"

DefaultScheduler is the default ipvs scheduler algorithm - round robin.

Variables

This section is empty.

Functions

func CanUseIPVSProxier

func CanUseIPVSProxier(handle KernelHandler) (bool, error)

CanUseIPVSProxier returns true if we can use the ipvs Proxier. This is determined by checking if all the required kernel modules can be loaded. It may return an error if it fails to get the kernel modules information without error, in which case it will also return false.

func GetRequiredIPVSModules

func GetRequiredIPVSModules(kernelVersion *version.Version) []string

GetRequiredIPVSModules returns the required ipvs modules for the given linux kernel version.

func IsRsGracefulTerminationNeeded

func IsRsGracefulTerminationNeeded(proto string) bool

IsRsGracefulTerminationNeeded returns true if protocol requires graceful termination for the stale connections

func SupportXfrmInterface

func SupportXfrmInterface(handle KernelHandler) (bool, error)

Types

type Interface

type Interface interface {
	// Flush clears all virtual servers in system. return occurred error immediately.
	Flush() error
	// AddVirtualServer creates the specified virtual server.
	AddVirtualServer(*VirtualServer) error
	// UpdateVirtualServer updates an already existing virtual server.  If the virtual server does not exist, return error.
	UpdateVirtualServer(*VirtualServer) error
	// DeleteVirtualServer deletes the specified virtual server.  If the virtual server does not exist, return error.
	DeleteVirtualServer(*VirtualServer) error
	// Given a partial virtual server, GetVirtualServer will return the specified virtual server information in the system.
	GetVirtualServer(*VirtualServer) (*VirtualServer, error)
	// GetVirtualServers lists all virtual servers in the system.
	GetVirtualServers() ([]*VirtualServer, error)
	// AddRealServer creates the specified real server for the specified virtual server.
	AddRealServer(*VirtualServer, *RealServer) error
	// GetRealServers returns all real servers for the specified virtual server.
	GetRealServers(*VirtualServer) ([]*RealServer, error)
	// DeleteRealServer deletes the specified real server from the specified virtual server.
	DeleteRealServer(*VirtualServer, *RealServer) error
	// UpdateRealServer updates the specified real server from the specified virtual server.
	UpdateRealServer(*VirtualServer, *RealServer) error
	// ConfigureTimeouts is the equivalent to running "ipvsadm --set" to configure tcp, tcpfin and udp timeouts
	ConfigureTimeouts(time.Duration, time.Duration, time.Duration) error
}

Interface is an injectable interface for running ipvs commands. Implementations must be goroutine-safe.

func New

func New(exec utilexec.Interface) Interface

New returns a new Interface which will call ipvs APIs.

type KernelHandler

type KernelHandler interface {
	GetModules() ([]string, error)
	GetKernelVersion() (string, error)
}

KernelHandler can handle the current installed kernel modules.

type LinuxKernelHandler

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

LinuxKernelHandler implements KernelHandler interface.

func NewLinuxKernelHandler

func NewLinuxKernelHandler() *LinuxKernelHandler

NewLinuxKernelHandler initializes LinuxKernelHandler with exec.

func (*LinuxKernelHandler) GetKernelVersion

func (handle *LinuxKernelHandler) GetKernelVersion() (string, error)

GetKernelVersion returns currently running kernel version.

func (*LinuxKernelHandler) GetModules

func (handle *LinuxKernelHandler) GetModules() ([]string, error)

GetModules returns all installed kernel modules.

type NetLinkHandle

type NetLinkHandle interface {
	// EnsureAddressBind checks if address is bound to the interface and, if not, binds it.  If the address is already bound, return true.
	EnsureAddressBind(address, devName string) (exist bool, err error)
	// UnbindAddress unbind address from the interface
	UnbindAddress(address, devName string) error
	// EnsureDummyDevice checks if dummy device is exist and, if not, create one.  If the dummy device is already exist, return true.
	EnsureDummyDevice(devName string) (exist bool, err error)
	// DeleteDummyDevice deletes the given dummy device by name.
	DeleteDummyDevice(devName string) error
	// ListBindAddress will list all IP addresses which are bound in a given interface
	ListBindAddress(devName string) ([]string, error)
	// GetLocalAddresses returns all unique local type IP addresses based on specified device and filter device
	// If device is not specified, it will list all unique local type addresses except filter device addresses
	GetLocalAddresses(dev, filterDev string) (sets.String, error)
	// EnsureXfrmInterface checks if xfrm interface is exist and, if not, create one and up one
	EnsureXfrmInterface(devName string, ifid uint32) error
	// DeleteXfrmInterface deletes the given xfrm interface by name.
	DeleteXfrmInterface(devName string) error
	// EnsureRouteAdd checks if the route is exist and, if not, adds it
	EnsureRouteAdd(subnet, devName string) error
	// DeleteRoute deletes the route
	DeleteRoute(subnet, devName string) error
	// GetRoute get route by subnet and devName
	GetRoute(subnet, devName string) (*netlink.Route, error)
}

NetLinkHandle for revoke netlink interface

func NewNetLinkHandle

func NewNetLinkHandle(isIPv6 bool) NetLinkHandle

NewNetLinkHandle will create a new NetLinkHandle

type Protocol

type Protocol uint16

Protocol is the IPVS service protocol type

type RealServer

type RealServer struct {
	Address      net.IP
	Port         uint16
	Weight       int
	ActiveConn   int
	InactiveConn int
}

RealServer is an user-oriented definition of an IPVS real server in its entirety.

func (*RealServer) Equal

func (rs *RealServer) Equal(other *RealServer) bool

Equal check the equality of real server. We don't use struct == since it doesn't work because of slice.

func (*RealServer) String

func (rs *RealServer) String() string

type ServiceFlags

type ServiceFlags uint32

ServiceFlags is used to specify session affinity, ip hash etc.

type VirtualServer

type VirtualServer struct {
	Address   net.IP
	Protocol  string
	Port      uint16
	Scheduler string
	Flags     ServiceFlags
	Timeout   uint32
}

VirtualServer is an user-oriented definition of an IPVS virtual server in its entirety.

func (*VirtualServer) Equal

func (svc *VirtualServer) Equal(other *VirtualServer) bool

Equal check the equality of virtual server. We don't use struct == since it doesn't work because of slice.

func (*VirtualServer) String

func (svc *VirtualServer) String() string

Jump to

Keyboard shortcuts

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