ip4

package
v1.2.0-rc.1.0...-65ced95 Latest Latest
Warning

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

Go to latest
Published: May 20, 2019 License: GPL-2.0, GPL-2.0-or-later Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AddressBytes              = 4
	AddressBits               = 8 * AddressBytes
	SizeofHeader              = 20
	MoreFragments HeaderFlags = 1 << 13
	DontFragment  HeaderFlags = 1 << 14
	Congestion    HeaderFlags = 1 << 15
)
View Source
const DefaultTtl = 64

Variables

This section is empty.

Functions

func Init

func Init(v *vnet.Vnet) *ip.Main

func RegisterLayer

func RegisterLayer(v *vnet.Vnet, t ip.Protocol, l vnet.Layer)

func UnregisterLayer

func UnregisterLayer(v *vnet.Vnet, t ip.Protocol) (ok bool)

Types

type Address

type Address [AddressBytes]uint8

func AddressMaskForLen

func AddressMaskForLen(l uint) Address

func AddressUint32

func AddressUint32(x uint32) (a Address)

func IpAddress

func IpAddress(a *ip.Address) *Address

func NetIPToV4Address

func NetIPToV4Address(a net.IP) (a4 Address)

func (*Address) Add

func (a *Address) Add(x uint64)

func (Address) AsUint32

func (a Address) AsUint32() vnet.Uint32

func (*Address) Diff

func (a *Address) Diff(b *Address) (v int)

Compare 2 addresses for sorting.

func (*Address) FromUint32

func (a *Address) FromUint32(x vnet.Uint32)

func (*Address) HexString

func (a *Address) HexString() string

func (*Address) IsEqual

func (a *Address) IsEqual(b *Address) bool

func (*Address) IsZero

func (a *Address) IsZero() bool

func (*Address) Mask

func (a *Address) Mask(l uint) (v Address)

func (*Address) MaskLen

func (a *Address) MaskLen() (l uint, ok bool)

func (*Address) MaskedString

func (v *Address) MaskedString(r vnet.MaskedStringer) (s string)

func (*Address) MatchesPrefix

func (dst *Address) MatchesPrefix(p *Prefix) bool

True if given destination matches prefix.

func (*Address) Parse

func (a *Address) Parse(in *parse.Input)

func (*Address) String

func (a *Address) String() string

func (*Address) ToIp

func (a *Address) ToIp() (v ip.Address)

func (Address) ToNetIP

func (a Address) ToNetIP() (ip net.IP)

type Fib

type Fib struct {
	Name ip.FibName
	// contains filtered or unexported fields
}

func (*Fib) GetDrop

func (f *Fib) GetDrop(p *net.IPNet) (result *FibResult, ok bool)

func (*Fib) GetFib

func (f *Fib) GetFib(p *net.IPNet, nhs ip.NextHopVec) (a ip.Adj, result *FibResult, ok bool)

func (*Fib) GetGlean

func (f *Fib) GetGlean(p *net.IPNet, si vnet.Si) (a ip.Adj, result *FibResult, ok bool)

func (*Fib) GetInstalled

func (f *Fib) GetInstalled(p *net.IPNet) (result *FibResult, ok bool)

func (*Fib) GetLocal

func (f *Fib) GetLocal(p *net.IPNet, si vnet.Si) (a ip.Adj, result *FibResult, ok bool)

func (*Fib) GetPunt

func (f *Fib) GetPunt(p *net.IPNet) (result *FibResult, ok bool)

func (*Fib) GetReachable

func (f *Fib) GetReachable(p *net.IPNet, si vnet.Si) (a ip.Adj, result *FibResult, ok bool)

func (*Fib) GetUnreachable

func (f *Fib) GetUnreachable(p *net.IPNet, si vnet.Si) (a ip.Adj, result *FibResult, ok bool)

func (*Fib) Len

func (f *Fib) Len() (n uint)

Total number of routes in FIB.

func (*Fib) Reset

func (f *Fib) Reset()

type FibAddDelHook

type FibAddDelHook func(i ip.FibIndex, p *Prefix, r ip.Adj, isDel bool)

type FibAddDelHookVec

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

func (*FibAddDelHookVec) Add

func (t *FibAddDelHookVec) Add(x FibAddDelHook, ds ...*dep.Dep)

func (*FibAddDelHookVec) Get

func (*FibAddDelHookVec) Len

func (t *FibAddDelHookVec) Len() int

type FibResult

type FibResult struct {
	Adj       ip.Adj
	Installed bool
	Prefix    net.IPNet
	Type      RouteType
	Nhs       ip.NextHopVec // nexthops for Address
	// contains filtered or unexported fields
}

func (*FibResult) String

func (r *FibResult) String() (s string)

type FibResultVec

type FibResultVec []FibResult

func (*FibResultVec) ForeachMatchingNhAddress

func (rs *FibResultVec) ForeachMatchingNhAddress(nha net.IP, fn func(r *FibResult, nh *ip.NextHop))

func (FibResultVec) GetByNhs

func (rs FibResultVec) GetByNhs(nhs ip.NextHopVec) (r FibResult, ri int, ok bool)

returns first match

func (FibResultVec) GetBySi

func (rs FibResultVec) GetBySi(si vnet.Si) (r FibResult, ri int, ok bool)

This returns 1st FibResult with a nh si that match; used to look up local and glean

type FibVec

type FibVec []*Fib

func (FibVec) Len

func (p FibVec) Len() uint

func (*FibVec) ResetLen

func (p *FibVec) ResetLen()

func (*FibVec) Resize

func (p *FibVec) Resize(n uint)

func (*FibVec) Validate

func (p *FibVec) Validate(i uint) **Fib

func (*FibVec) ValidateInit

func (p *FibVec) ValidateInit(i uint, zero *Fib) **Fib

func (*FibVec) ValidateLen

func (p *FibVec) ValidateLen(l uint) (v **Fib)

func (*FibVec) ValidateLenInit

func (p *FibVec) ValidateLenInit(l uint, zero *Fib) (v **Fib)
type Header struct {
	// 4 bit header length (in 32bit units) and version VVVVLLLL.
	// e.g. for packets w/ no options ip_version_and_header_length == 0x45.
	Ip_version_and_header_length uint8

	// Type of service.
	Tos uint8

	// Total layer 3 packet length including this header.
	Length vnet.Uint16

	// 16-bit number such that Src, Dst, Protocol and Fragment ID together uniquely
	// identify packet for fragment re-assembly.
	Fragment_id vnet.Uint16

	// 3 bits of flags and 13 bits of fragment offset (in units of 8 bytes).
	Flags_and_fragment_offset vnet.Uint16

	// Time to live decremented by router at each hop.
	Ttl uint8

	// Next layer protocol.
	Protocol ip.Protocol

	Checksum vnet.Uint16

	// Source and destination address.
	Src, Dst net.IP
}

func GetHeader

func GetHeader(r *vnet.Ref) *Header

func ParseHeader

func ParseHeader(b []byte) (h *Header, payload []byte)

func (*Header) ComputeChecksum

func (h *Header) ComputeChecksum() vnet.Uint16

func (*Header) GetHeaderFlags

func (h *Header) GetHeaderFlags() HeaderFlags

func (*Header) Len

func (h *Header) Len() uint

func (*Header) Parse

func (h *Header) Parse(in *parse.Input)

func (*Header) Read

func (h *Header) Read(b []byte) vnet.PacketHeader

func (*Header) String

func (h *Header) String() (s string)

func (*Header) Write

func (h *Header) Write(b []byte)

type HeaderFlags

type HeaderFlags vnet.Uint16

func (HeaderFlags) FromHost

func (t HeaderFlags) FromHost() vnet.Uint16

type IfAddrAddDelHook

type IfAddrAddDelHook func(ia ip.IfAddr, isDel bool)

type IfAddrAddDelHookVec

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

func (*IfAddrAddDelHookVec) Add

func (t *IfAddrAddDelHookVec) Add(x IfAddrAddDelHook, ds ...*dep.Dep)

func (*IfAddrAddDelHookVec) Get

func (*IfAddrAddDelHookVec) Len

func (t *IfAddrAddDelHookVec) Len() int

type Main

type Main struct {
	vnet.Package
	ip.Main

	FibShowUsageHooks fibShowUsageHookVec
	// contains filtered or unexported fields
}

func GetMain

func GetMain(v *vnet.Vnet) *Main

func (*Main) AddDelInterfaceAddress

func (m *Main) AddDelInterfaceAddress(si vnet.Si, addr *net.IPNet, isDel bool) (err error)

func (*Main) AddDelInterfaceAddressRoute

func (m *Main) AddDelInterfaceAddressRoute(p *net.IPNet, si vnet.Si, rt RouteType, isDel bool)

In Linux, local route is added to table local when an address is assigned to interface. It stays there regardless of whether interface is admin up or down Glean route, on the other hand, is added to table main when an interface is admin up, and removed when admin down There will be explicit fdb messages to add or delete these routes, so no need to maintain state in vnet You can also have multiple local and glean per interface

func (*Main) AddDelRouteNeighbor

func (m *Main) AddDelRouteNeighbor(p *net.IPNet, n *Neighbor, fi ip.FibIndex, isDel bool) (err error)

func (*Main) AddDelRouteNextHop

func (m *Main) AddDelRouteNextHop(p *net.IPNet, nh *NextHop, isDel bool, isReplace bool) (err error)

modified for legacy netlink and ip/cli use, where nexthop were added 1 at a time instead of a vector at at time

func (*Main) AddDelRouteNextHops

func (m *Main) AddDelRouteNextHops(fibIndex ip.FibIndex, p *net.IPNet, nhs ip.NextHopVec, isDel bool, isReplace bool) (err error)

NextHops comes as a vector

func (*Main) FibReset

func (m *Main) FibReset(fi ip.FibIndex)

func (*Main) ForeachUnresolved

func (m *Main) ForeachUnresolved(fn func(fi ip.FibIndex, p net.IPNet))

func (*Main) FormatLayer

func (m *Main) FormatLayer(b []byte) (lines []string)

func (*Main) Init

func (m *Main) Init() (err error)

func (*Main) Name

func (m *Main) Name() string

func (*Main) ParseLayer

func (m *Main) ParseLayer(b []byte, in *parse.Input) (n uint)

func (*Main) ParseStream

func (m *Main) ParseStream(in *parse.Input) (r pg.Streamer, err error)

func (*Main) RegisterFibAddDelHook

func (m *Main) RegisterFibAddDelHook(f FibAddDelHook, dep ...*dep.Dep)

type MapFib

type MapFib [1 + 32]map[string]FibResultVec

string key is the string output of the net.IPNet stringer

func (*MapFib) GetByNhs

func (x *MapFib) GetByNhs(p *net.IPNet, nhs ip.NextHopVec) (a ip.Adj, result *FibResult, ok bool)

func (*MapFib) GetBySi

func (x *MapFib) GetBySi(p *net.IPNet, si vnet.Si) (a ip.Adj, result *FibResult, ok bool)

func (*MapFib) Set

func (m *MapFib) Set(ma *Main, p *net.IPNet, newAdj ip.Adj, nhs ip.NextHopVec, rt RouteType) (oldAdj ip.Adj, result *FibResult, ok bool)

func (*MapFib) SetConn

func (m *MapFib) SetConn(ma *Main, p *net.IPNet, adj ip.Adj, si vnet.Si) (oldAdj ip.Adj, result *FibResult, ok bool)

func (*MapFib) Unset

func (m *MapFib) Unset(p *net.IPNet, nhs ip.NextHopVec) (oldAdj ip.Adj, ok bool)

func (*MapFib) UnsetConn

func (m *MapFib) UnsetConn(p *net.IPNet, si vnet.Si) (oldAdj ip.Adj, ok bool)

func (*MapFib) UnsetFirst

func (m *MapFib) UnsetFirst(p *net.IPNet) (oldAdj ip.Adj, ok bool)

type Neighbor

type Neighbor struct {
	Header Header

	LocalSi  vnet.Si
	FibIndex ip.FibIndex
	Weight   ip.NextHopWeight

	// Header payload (for example, GRE header).
	Payload []byte
	// contains filtered or unexported fields
}

func (*Neighbor) FinalizeAdjacency

func (n *Neighbor) FinalizeAdjacency(a *ip.Adjacency)

func (*Neighbor) NextHopFibIndex

func (n *Neighbor) NextHopFibIndex(m *Main) ip.FibIndex

func (*Neighbor) NextHopWeight

func (n *Neighbor) NextHopWeight() ip.NextHopWeight

type NextHop

type NextHop struct {
	Address net.IP
	Si      vnet.Si
	Weight  ip.NextHopWeight
}

func (*NextHop) FinalizeAdjacency

func (n *NextHop) FinalizeAdjacency(a *ip.Adjacency)

func (*NextHop) NextHopFibIndex

func (n *NextHop) NextHopFibIndex(m *Main) ip.FibIndex

func (*NextHop) NextHopWeight

func (n *NextHop) NextHopWeight() ip.NextHopWeight

func (*NextHop) ParseWithArgs

func (x *NextHop) ParseWithArgs(in *parse.Input, args *parse.Args)

type NextHopper

type NextHopper interface {
	ip.AdjacencyFinalizer
	NextHopFibIndex(m *Main) ip.FibIndex
	NextHopWeight() ip.NextHopWeight
}

type Prefix

type Prefix struct {
	Address
	Len uint32
}

func FromIp4Prefix

func FromIp4Prefix(i *ip.Prefix) (p Prefix)

func IPNetToV4Prefix

func IPNetToV4Prefix(ipn net.IPNet) (p Prefix)

func (*Prefix) Add

func (p *Prefix) Add(offset uint) (q Prefix)

Add adds offset to prefix. For example, 1.2.3.0/24 + 1 = 1.2.4.0/24.

func (*Prefix) ApplyMask

func (p *Prefix) ApplyMask() (q *Prefix)

func (*Prefix) IsEqual

func (p *Prefix) IsEqual(q *Prefix) bool

func (*Prefix) LessThan

func (p *Prefix) LessThan(q *Prefix) bool

func (*Prefix) Mask

func (p *Prefix) Mask() vnet.Uint32

func (*Prefix) MaskAsAddress

func (p *Prefix) MaskAsAddress() (a Address)

func (*Prefix) Matches

func (p *Prefix) Matches(q *Prefix) bool

func (*Prefix) Parse

func (p *Prefix) Parse(in *parse.Input)

func (*Prefix) SetLen

func (p *Prefix) SetLen(l uint)

func (*Prefix) String

func (p *Prefix) String() string

func (Prefix) ToIPNet

func (p Prefix) ToIPNet() (ipn net.IPNet)

func (*Prefix) ToIpPrefix

func (p *Prefix) ToIpPrefix() (i ip.Prefix)

type RouteType

type RouteType uint8
const (
	// drops at hardware (blackhole)
	DROP RouteType = iota
	// punts to Linux
	PUNT
	// neighbor
	CONN
	// has via next hop(s)
	VIA
	// glean
	GLEAN
	// interface addr of vnet recognized interface
	LOCAL
)

this list of const is in order of perference for installing route

func (RouteType) String

func (t RouteType) String() string

Jump to

Keyboard shortcuts

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