driver

package
v1.2.0-rc.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LinkIP   = net.IPv4(169, 254, 1, 1)
	LinkIPv6 = net.ParseIP("fe80::1")
)

default addrs

View Source
var DefaultLogger = NewDefaultLogger()

DefaultLogger default log

View Source
var Hook = &PodInfoHook{ExtraInfo: make(map[string]string)}

Hook for log

View Source
var Log = DefaultLogger.WithField("subSys", "terway-cni")

Log for default log

Functions

func AddNeigh added in v1.1.0

func AddNeigh(link netlink.Link, mac net.HardwareAddr, ip *terwayTypes.IPSet) error

AddNeigh add arp for link

func AddrDel added in v1.1.0

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

func AddrReplace added in v1.1.0

func AddrReplace(link netlink.Link, addr *netlink.Addr) error

func CheckIPVLanAvailable added in v1.1.0

func CheckIPVLanAvailable() (bool, error)

CheckIPVLanAvailable checks if current kernel version meet the requirement (>= 4.19)

func DelIPRulesByIP added in v1.1.0

func DelIPRulesByIP(ipNet *net.IPNet) error

func EnableIPv6 added in v1.1.0

func EnableIPv6() error

func EnsureAddr added in v1.1.0

func EnsureAddr(link netlink.Link, expect *netlink.Addr) (bool, error)

EnsureAddr ensure only one IP for each family is present on link

func EnsureAddrWithPrefix added in v1.1.0

func EnsureAddrWithPrefix(link netlink.Link, ipNetSet *terwayTypes.IPNetSet, prefixRoute bool) (bool, error)

EnsureAddrWithPrefix take the ipNet set and ensure only one IP for each family is present on link it will remove other unmatched IPs

func EnsureClsActQdsic added in v1.1.0

func EnsureClsActQdsic(link netlink.Link) error

func EnsureDefaultRoute added in v1.1.0

func EnsureDefaultRoute(link netlink.Link, gw *terwayTypes.IPSet, table int) (bool, error)

func EnsureHostNsConfig added in v1.1.0

func EnsureHostNsConfig(ipv4, ipv6 bool) error

EnsureHostNsConfig setup host namespace configs

func EnsureHostToContainerRoute added in v1.1.0

func EnsureHostToContainerRoute(link netlink.Link, ipNetSet *terwayTypes.IPNetSet) (bool, error)

EnsureHostToContainerRoute create host to container route

func EnsureIPRule added in v1.1.0

func EnsureIPRule(link netlink.Link, ipNetSet *terwayTypes.IPNetSet, tableID int) (bool, error)

func EnsureLinkMTU added in v1.1.0

func EnsureLinkMTU(link netlink.Link, mtu int) (bool, error)

EnsureLinkMTU set link mtu,return changed and err

func EnsureLinkName added in v1.1.0

func EnsureLinkName(link netlink.Link, name string) (bool, error)

func EnsureLinkUp added in v1.1.0

func EnsureLinkUp(link netlink.Link) (bool, error)

EnsureLinkUp set link up,return changed and err

func EnsureNeighbor added in v1.1.0

func EnsureNeighbor(link netlink.Link, hostIPSet *terwayTypes.IPNetSet) (bool, error)

func EnsureNetConfSet added in v1.1.0

func EnsureNetConfSet(ipv4, ipv6 bool) error

EnsureNetConfSet will set net config to all link

func EnsureRoute added in v1.1.0

func EnsureRoute(expected *netlink.Route) (bool, error)

EnsureRoute will call ip route replace if route is not found

func EnsureVlanUntagger added in v1.1.0

func EnsureVlanUntagger(link netlink.Link) error

func FindIPRule added in v1.1.0

func FindIPRule(rule *netlink.Rule) ([]netlink.Rule, error)

FindIPRule look up ip rules in config

func FoundRoutes added in v1.1.0

func FoundRoutes(expected *netlink.Route) ([]netlink.Route, error)

FoundRoutes look up routes

func GetHostIP added in v1.1.0

func GetHostIP(ipv4, ipv6 bool) (*terwayTypes.IPNetSet, error)

func IPNetToMaxMask added in v1.1.0

func IPNetToMaxMask(ipNet *terwayTypes.IPNetSet)

func JSONStr added in v1.1.0

func JSONStr(v interface{}) string

JSONStr json to str

func LinkAdd added in v1.1.0

func LinkAdd(link netlink.Link) error

func LinkDel added in v1.1.0

func LinkDel(link netlink.Link) error

func LinkSetDown added in v1.1.0

func LinkSetDown(link netlink.Link) error

func LinkSetMTU added in v1.1.0

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

func LinkSetName added in v1.1.0

func LinkSetName(link netlink.Link, name string) error

func LinkSetNsFd added in v1.1.0

func LinkSetNsFd(link netlink.Link, netNS ns.NetNS) error

func LinkSetUp added in v1.1.0

func LinkSetUp(link netlink.Link) error

func NeighAdd added in v1.1.0

func NeighAdd(neigh *netlink.Neigh) error

func NeighSet added in v1.1.0

func NeighSet(neigh *netlink.Neigh) error

func NetlinkFamily added in v1.1.0

func NetlinkFamily(ip net.IP) int

func NewDefaultLogger added in v1.1.0

func NewDefaultLogger() *logrus.Logger

func NewIPNetWithMaxMask added in v1.1.0

func NewIPNetWithMaxMask(ipNet *net.IPNet) *net.IPNet

func PodInfoKey added in v1.1.0

func PodInfoKey(namespace, name string) string

func RouteAdd added in v1.1.0

func RouteAdd(route *netlink.Route) error

func RouteDel added in v1.1.0

func RouteDel(route *netlink.Route) error

func RouteReplace added in v1.1.0

func RouteReplace(route *netlink.Route) error

func RuleAdd added in v1.1.0

func RuleAdd(rule *netlink.Rule) error

func RuleDel added in v1.1.0

func RuleDel(rule *netlink.Rule) error

func SetLogDebug added in v1.1.0

func SetLogDebug()
func SetupLink(link netlink.Link, cfg *SetupConfig) error

SetupLink is a common setup for all links 1. set link name 2. set link up 3. set link ip address

Types

type CheckConfig added in v1.1.0

type CheckConfig struct {
	RecordPodEvent

	NetNS ns.NetNS

	HostVETHName    string
	ContainerIFName string

	ContainerIPNet *terwayTypes.IPNetSet
	HostIPSet      *terwayTypes.IPNetSet
	GatewayIP      *terwayTypes.IPSet

	ENIIndex int32 // phy device
	TrunkENI bool
	MTU      int
}

type IPvlanDriver added in v1.1.0

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

func NewIPVlanDriver added in v1.1.0

func NewIPVlanDriver(ipv4, ipv6 bool) *IPvlanDriver

func (*IPvlanDriver) Check added in v1.1.0

func (d *IPvlanDriver) Check(cfg *CheckConfig) error

func (*IPvlanDriver) Setup added in v1.1.0

func (d *IPvlanDriver) Setup(cfg *SetupConfig, netNS ns.NetNS) error

func (*IPvlanDriver) Teardown added in v1.1.0

func (d *IPvlanDriver) Teardown(cfg *TeardownCfg, netNS ns.NetNS) error

type Locker added in v1.1.0

type Locker struct {
	FD *os.File
}

func GrabFileLock added in v1.1.0

func GrabFileLock(lockfilePath string) (*Locker, error)

GrabFileLock get file lock with timeout 11seconds

func (*Locker) Close added in v1.1.0

func (l *Locker) Close() error

Close close

type NetnsDriver

type NetnsDriver interface {
	Setup(cfg *SetupConfig, netNS ns.NetNS) error

	Teardown(cfg *TeardownCfg, netNS ns.NetNS) error

	Check(cfg *CheckConfig) error
}

NetnsDriver to config container netns interface and routes

type PodInfoHook added in v1.1.0

type PodInfoHook struct {
	ExtraInfo map[string]string
}

func (*PodInfoHook) AddExtraInfo added in v1.1.0

func (p *PodInfoHook) AddExtraInfo(k, v string)

func (*PodInfoHook) AddExtraInfos added in v1.1.0

func (p *PodInfoHook) AddExtraInfos(e map[string]string)

func (*PodInfoHook) Fire added in v1.1.0

func (p *PodInfoHook) Fire(e *logrus.Entry) error

func (*PodInfoHook) Levels added in v1.1.0

func (p *PodInfoHook) Levels() []logrus.Level

type RawNicDriver added in v1.1.0

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

RawNicDriver put nic in net ns

func NewRawNICDriver added in v1.1.0

func NewRawNICDriver(ipv4, ipv6 bool) *RawNicDriver

func (*RawNicDriver) Check added in v1.1.0

func (r *RawNicDriver) Check(cfg *CheckConfig) error

func (*RawNicDriver) Setup added in v1.1.0

func (r *RawNicDriver) Setup(cfg *SetupConfig, netNS ns.NetNS) error

func (*RawNicDriver) Teardown added in v1.1.0

func (r *RawNicDriver) Teardown(cfg *TeardownCfg, netNS ns.NetNS) error

type RecordPodEvent added in v1.1.0

type RecordPodEvent func(msg string)

type SetupConfig added in v1.1.0

type SetupConfig struct {
	HostVETHName string

	ContainerIfName string
	ContainerIPNet  *terwayTypes.IPNetSet
	GatewayIP       *terwayTypes.IPSet
	MTU             int
	ENIIndex        int
	TrunkENI        bool

	// add extra route in container
	ExtraRoutes []types.Route

	ServiceCIDR *terwayTypes.IPNetSet
	HostIPSet   *terwayTypes.IPNetSet
	// ipvlan
	HostStackCIDRs []*net.IPNet

	Ingress uint64
	Egress  uint64
}

type TeardownCfg added in v1.1.0

type TeardownCfg struct {
	HostVETHName string

	ContainerIfName string
	ContainerIPNet  *terwayTypes.IPNetSet
}

type VETHDriver added in v1.1.0

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

func NewVETHDriver added in v1.1.0

func NewVETHDriver(ipv4, ipv6 bool) *VETHDriver

func (*VETHDriver) Check added in v1.1.0

func (d *VETHDriver) Check(cfg *CheckConfig) error

func (*VETHDriver) Setup added in v1.1.0

func (d *VETHDriver) Setup(cfg *SetupConfig, netNS ns.NetNS) error

func (*VETHDriver) Teardown added in v1.1.0

func (d *VETHDriver) Teardown(cfg *TeardownCfg, netNS ns.NetNS) error

Jump to

Keyboard shortcuts

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