ipvs

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

README

ipvs - networking for containers

Test GoDoc Go Report Card

ipvs provides a native Go implementation for communicating with IPVS kernel module using a netlink socket.

Using ipvs
import (
	"log"

	"github.com/moby/ipvs"
)

func main() {
	handle, err := ipvs.New("")
	if err != nil {
		log.Fatalf("ipvs.New: %s", err)
	}
	svcs, err := handle.GetServices()
	if err != nil {
		log.Fatalf("handle.GetServices: %s", err)
	}
}

Contributing

Want to hack on ipvs? Docker's contributions guidelines apply.

Copyright 2015 Docker, inc. Code released under the Apache 2.0 license.

Documentation

Index

Constants

View Source
const (
	// ConnectionFlagFwdmask indicates the mask in the connection
	// flags which is used by forwarding method bits.
	ConnectionFlagFwdMask = 0x0007

	// ConnectionFlagMasq is used for masquerade forwarding method.
	ConnectionFlagMasq = 0x0000

	// ConnectionFlagLocalNode is used for local node forwarding
	// method.
	ConnectionFlagLocalNode = 0x0001

	// ConnectionFlagTunnel is used for tunnel mode forwarding
	// method.
	ConnectionFlagTunnel = 0x0002

	// ConnectionFlagDirectRoute is used for direct routing
	// forwarding method.
	ConnectionFlagDirectRoute = 0x0003

	// ConnectionFlagFullNat is used for fullnat(snat+dnat) forwarding method.
	ConnectionFlagFullNat = 0x0005
)

Destination forwarding methods

View Source
const (
	// RoundRobin distributes jobs equally amongst the available
	// real servers.
	RoundRobin = "rr"

	// LeastConnection assigns more jobs to real servers with
	// fewer active jobs.
	LeastConnection = "lc"

	// DestinationHashing assigns jobs to servers through looking
	// up a statically assigned hash table by their destination IP
	// addresses.
	DestinationHashing = "dh"

	// SourceHashing assigns jobs to servers through looking up
	// a statically assigned hash table by their source IP
	// addresses.
	SourceHashing = "sh"

	// WeightedRoundRobin assigns jobs to real servers proportionally
	// to there real servers' weight. Servers with higher weights
	// receive new jobs first and get more jobs than servers
	// with lower weights. Servers with equal weights get
	// an equal distribution of new jobs
	WeightedRoundRobin = "wrr"

	// WeightedLeastConnection assigns more jobs to servers
	// with fewer jobs and relative to the real servers' weight
	WeightedLeastConnection = "wlc"
)
View Source
const (
	// ConnFwdMask is a mask for the fwd methods
	ConnFwdMask = 0x0007

	// ConnFwdMasq denotes forwarding via masquerading/NAT
	ConnFwdMasq = 0x0000

	// ConnFwdLocalNode denotes forwarding to a local node
	ConnFwdLocalNode = 0x0001

	// ConnFwdTunnel denotes forwarding via a tunnel
	ConnFwdTunnel = 0x0002

	// ConnFwdDirectRoute denotes forwarding via direct routing
	ConnFwdDirectRoute = 0x0003

	// ConnFwdBypass denotes forwarding while bypassing the cache
	ConnFwdBypass = 0x0004

	// ConnFwdFullNat denotes forwarding via snat+dnat
	ConnFwdFullNat = 0x0005
)
View Source
const (
	// daemon in stop state
	DaemonStateNone = 0x0000

	// daemon in master state
	DaemonStateMaster = 0x0001

	// daemon in backup state
	DaemonStateBackup = 0x0002
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	TimeoutTCP    time.Duration
	TimeoutTCPFin time.Duration
	TimeoutUDP    time.Duration
}

Config defines IPVS timeout configuration

type Daemon added in v1.4.0

type Daemon struct {
	State    uint32
	SyncId   uint32
	McastIfn string
}

type Destination

type Destination struct {
	Address               net.IP
	Port                  uint16
	Weight                int
	ConnectionFlags       uint32
	AddressFamily         uint16
	UpperThreshold        uint32
	LowerThreshold        uint32
	ActiveConnections     int
	InactiveConnections   int
	PersistentConnections int
	Stats                 DstStats
}

Destination defines an IPVS destination (real server) in its entirety.

type DstStats

type DstStats SvcStats

DstStats defines IPVS destination (real server) statistics

type Handle

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

Handle provides a namespace specific ipvs handle to program ipvs rules.

func New

func New(path string) (*Handle, error)

New provides a new ipvs handle in the namespace pointed to by the passed path. It will return a valid handle or an error in case an error occurred while creating the handle.

func (*Handle) Close

func (i *Handle) Close()

Close closes the ipvs handle. The handle is invalid after Close returns.

func (*Handle) DelDaemon added in v1.4.0

func (i *Handle) DelDaemon(d *Daemon) error

DelDaemon delete a already existing daemon in the passed handle

func (*Handle) DelDestination

func (i *Handle) DelDestination(s *Service, d *Destination) error

DelDestination deletes an already existing real server in the passed ipvs service in the passed handle.

func (*Handle) DelLocalAddress added in v1.3.0

func (i *Handle) DelLocalAddress(s *Service, d *LocalAddress) error

DelLocalAddress deletes an already existing local address in the passed ipvs service in the passed handle.

func (*Handle) DelService

func (i *Handle) DelService(s *Service) error

DelService deletes an already existing service in the passed handle.

func (*Handle) Flush

func (i *Handle) Flush() error

Flush deletes all existing services in the passed handle.

func (*Handle) GetConfig

func (i *Handle) GetConfig() (*Config, error)

GetConfig returns the current timeout configuration

func (*Handle) GetDaemons added in v1.4.0

func (i *Handle) GetDaemons() ([]*Daemon, error)

GetDaemons return the current daemon information

func (*Handle) GetDestinations

func (i *Handle) GetDestinations(s *Service) ([]*Destination, error)

GetDestinations returns an array of Destinations configured for this Service

func (*Handle) GetInfo

func (i *Handle) GetInfo() (*Info, error)

GetInfo returns info details from IPVS

func (*Handle) GetLocalAddresses added in v1.3.0

func (i *Handle) GetLocalAddresses(s *Service) ([]*LocalAddress, error)

GetLocalAddresses returns an array of LocalAddress configured for this Service

func (*Handle) GetService

func (i *Handle) GetService(s *Service) (*Service, error)

GetService gets details of a specific IPVS services, useful in updating statisics etc.,

func (*Handle) GetServices

func (i *Handle) GetServices() ([]*Service, error)

GetServices returns an array of services configured on the Node

func (*Handle) IsServicePresent

func (i *Handle) IsServicePresent(s *Service) bool

IsServicePresent queries for the ipvs service in the passed handle.

func (*Handle) NewDaemon added in v1.4.0

func (i *Handle) NewDaemon(d *Daemon) error

NewDaemon create a new daemon in the passed handle

func (*Handle) NewDestination

func (i *Handle) NewDestination(s *Service, d *Destination) error

NewDestination creates a new real server in the passed ipvs service which should already be existing in the passed handle.

func (*Handle) NewLocalAddress added in v1.3.0

func (i *Handle) NewLocalAddress(s *Service, d *LocalAddress) error

NewLocalAddress creates a new local address in the passed ipvs service which should already be existing in the passed handle.

func (*Handle) NewService

func (i *Handle) NewService(s *Service) error

NewService creates a new ipvs service in the passed handle.

func (*Handle) SetConfig

func (i *Handle) SetConfig(c *Config) error

SetConfig set the current timeout configuration. 0: no change

func (*Handle) UpdateDestination

func (i *Handle) UpdateDestination(s *Service, d *Destination) error

UpdateDestination updates an already existing real server in the passed ipvs service in the passed handle.

func (*Handle) UpdateService

func (i *Handle) UpdateService(s *Service) error

UpdateService updates an already existing service in the passed handle.

func (*Handle) Zero added in v1.4.0

func (i *Handle) Zero() error

Zero zero the packet, byte and rate counters of services in the passed handle.

func (*Handle) ZeroService added in v1.4.0

func (i *Handle) ZeroService(s *Service) error

ZeroService zero the packet, byte and rate counters of a service in the passed handle.

type IPProto added in v1.2.1

type IPProto uint16

IPProto specifies the protocol encapsulated within an IP datagram

func (IPProto) String added in v1.2.1

func (p IPProto) String() string

String return name of the protocol

func (IPProto) Value added in v1.2.1

func (p IPProto) Value() uint16

Value return number of the protocol

type Info

type Info struct {
	Version       *Version
	ConnTableSize uint32
}

Info defines IPVS info

type LocalAddress added in v1.3.0

type LocalAddress struct {
	Address     net.IP
	Conflicts   uint64
	Connections uint32
}

LocalAddress defines in IPVS laddr in its entirety

type Service

type Service struct {
	// Virtual service address.
	Address  net.IP
	Protocol IPProto
	Port     uint16
	FWMark   uint32 // Firewall mark of the service.

	// Virtual service options.
	SchedName     string
	Flags         uint32
	Timeout       uint32
	Netmask       uint32
	AddressFamily uint16
	PEName        string
	Stats         SvcStats
}

Service defines an IPVS service in its entirety.

func (Service) String added in v1.4.0

func (svc Service) String() string

String returns a string representation of a service

type SvcStats

type SvcStats struct {
	Connections uint32
	PacketsIn   uint32
	PacketsOut  uint32
	BytesIn     uint64
	BytesOut    uint64
	CPS         uint32
	BPSOut      uint32
	PPSIn       uint32
	PPSOut      uint32
	BPSIn       uint32
}

SvcStats defines an IPVS service statistics

type Version

type Version struct {
	Major uint
	Minor uint
	Patch uint
}

Version defines IPVS version

func (*Version) String

func (v *Version) String() string

String returns a string of IPVS version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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