ip

package
v0.0.0-...-ba09d25 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ip holds IPv4/IPv6 common utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DAD

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

DAD performs duplicate address detection for addresses.

func (*DAD) CheckDuplicateAddressLocked

func (d *DAD) CheckDuplicateAddressLocked(addr tcpip.Address, h stack.DADCompletionHandler) stack.DADCheckAddressDisposition

CheckDuplicateAddressLocked performs DAD for an address, calling the completion handler once DAD resolves.

If DAD is already performing for the provided address, h will be called when the currently running process completes.

Precondition: d.protocolMU must be locked.

func (*DAD) ExtendIfNonceEqualLocked

func (d *DAD) ExtendIfNonceEqualLocked(addr tcpip.Address, nonce []byte) ExtendIfNonceEqualLockedDisposition

ExtendIfNonceEqualLocked extends the DAD process if the provided nonce is the same as the nonce sent in the last DAD message.

Precondition: d.protocolMU must be locked.

func (*DAD) Init

func (d *DAD) Init(protocolMU sync.Locker, configs stack.DADConfigurations, opts DADOptions)

Init initializes the DAD state.

Must only be called once for the lifetime of d; Init will panic if it is called twice.

The lock will only be taken when timers fire.

func (*DAD) SetConfigsLocked

func (d *DAD) SetConfigsLocked(c stack.DADConfigurations)

SetConfigsLocked sets the DAD configurations.

Precondition: d.protocolMU must be locked.

func (*DAD) StopLocked

func (d *DAD) StopLocked(addr tcpip.Address, reason stack.DADResult)

StopLocked stops a currently running DAD process.

Precondition: d.protocolMU must be locked.

type DADOptions

type DADOptions struct {
	Clock              tcpip.Clock
	SecureRNG          io.Reader
	NonceSize          uint8
	ExtendDADTransmits uint8
	Protocol           DADProtocol
	NICID              tcpip.NICID
}

DADOptions holds options for DAD.

type DADProtocol

type DADProtocol interface {
	// SendDADMessage attempts to send a DAD probe message.
	SendDADMessage(tcpip.Address, []byte) tcpip.Error
}

DADProtocol is a protocol whose core state machine can be represented by DAD.

type ErrLinkLocalDestinationAddress

type ErrLinkLocalDestinationAddress struct{}

ErrLinkLocalDestinationAddress indicates the received packet had a link-local destination address.

func (*ErrLinkLocalDestinationAddress) String

type ErrLinkLocalSourceAddress

type ErrLinkLocalSourceAddress struct{}

ErrLinkLocalSourceAddress indicates the received packet had a link-local source address.

func (*ErrLinkLocalSourceAddress) String

type ErrMessageTooLong

type ErrMessageTooLong struct{}

ErrMessageTooLong indicates the packet was too big for the outgoing MTU.

+stateify savable

func (*ErrMessageTooLong) String

func (*ErrMessageTooLong) String() string

type ErrNoRoute

type ErrNoRoute struct{}

ErrNoRoute indicates that a route for the received packet couldn't be found.

func (*ErrNoRoute) String

func (*ErrNoRoute) String() string

type ErrOther

type ErrOther struct {
	Err tcpip.Error
}

ErrOther indicates the packet coould not be forwarded for a reason captured by the contained error.

func (*ErrOther) String

func (e *ErrOther) String() string

type ErrParameterProblem

type ErrParameterProblem struct{}

ErrParameterProblem indicates the received packet had a problem with an IP parameter.

func (*ErrParameterProblem) String

func (*ErrParameterProblem) String() string

type ErrTTLExceeded

type ErrTTLExceeded struct{}

ErrTTLExceeded indicates that the received packet's TTL has been exceeded.

func (*ErrTTLExceeded) String

func (*ErrTTLExceeded) String() string

type ExtendIfNonceEqualLockedDisposition

type ExtendIfNonceEqualLockedDisposition int

ExtendIfNonceEqualLockedDisposition enumerates the possible results from ExtendIfNonceEqualLocked.

const (
	// Extended indicates that the DAD process was extended.
	Extended ExtendIfNonceEqualLockedDisposition = iota

	// AlreadyExtended indicates that the DAD process was already extended.
	AlreadyExtended

	// NoDADStateFound indicates that DAD state was not found for the address.
	NoDADStateFound

	// NonceDisabled indicates that nonce values are not sent with DAD messages.
	NonceDisabled

	// NonceNotEqual indicates that the nonce value passed and the nonce in the
	// last send DAD message are not equal.
	NonceNotEqual
)

type ForwardingError

type ForwardingError interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

ForwardingError represents an error that occured while trying to forward a packet.

type GenericMulticastProtocolOptions

type GenericMulticastProtocolOptions struct {
	// Rand is the source of random numbers.
	Rand *rand.Rand

	// Clock is the clock used to create timers.
	Clock tcpip.Clock

	// Protocol is the implementation of the variant of multicast group protocol
	// in use.
	Protocol MulticastGroupProtocol

	// MaxUnsolicitedReportDelay is the maximum amount of time to wait between
	// transmitting unsolicited reports.
	//
	// Unsolicited reports are transmitted when a group is newly joined.
	MaxUnsolicitedReportDelay time.Duration
}

GenericMulticastProtocolOptions holds options for the generic multicast protocol.

type GenericMulticastProtocolState

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

GenericMulticastProtocolState is the per interface generic multicast protocol state.

There is actually no protocol named "Generic Multicast Protocol". Instead, the term used to refer to a generic multicast protocol that applies to both IPv4 and IPv6. Specifically, Generic Multicast Protocol is the core state machine of IGMPv2 as defined by RFC 2236 and MLDv1 as defined by RFC 2710.

Callers must synchronize accesses to the generic multicast protocol state; GenericMulticastProtocolState obtains no locks in any of its methods. The only exception to this is GenericMulticastProtocolState's timer/job callbacks which will obtain the lock provided to the GenericMulticastProtocolState when it is initialized.

GenericMulticastProtocolState.Init MUST be called before calling any of the methods on GenericMulticastProtocolState.

GenericMulticastProtocolState.MakeAllNonMemberLocked MUST be called when the multicast group protocol is disabled so that leave messages may be sent.

func (*GenericMulticastProtocolState) HandleQueryLocked

func (g *GenericMulticastProtocolState) HandleQueryLocked(groupAddress tcpip.Address, maxResponseTime time.Duration)

HandleQueryLocked handles a query message with the specified maximum response time.

If the group address is unspecified, then reports will be scheduled for all joined groups.

Report(s) will be scheduled to be sent after a random duration between 0 and the maximum response time.

Precondition: g.protocolMU must be locked.

func (*GenericMulticastProtocolState) HandleReportLocked

func (g *GenericMulticastProtocolState) HandleReportLocked(groupAddress tcpip.Address)

HandleReportLocked handles a report message.

If the report is for a joined group, any active delayed report will be cancelled and the host state for the group transitions to idle.

Precondition: g.protocolMU must be locked.

func (*GenericMulticastProtocolState) Init

Init initializes the Generic Multicast Protocol state.

Must only be called once for the lifetime of g; Init will panic if it is called twice.

The GenericMulticastProtocolState will only grab the lock when timers/jobs fire.

Note: the methods on opts.Protocol will always be called while protocolMU is held.

func (*GenericMulticastProtocolState) InitializeGroupsLocked

func (g *GenericMulticastProtocolState) InitializeGroupsLocked()

InitializeGroupsLocked initializes each group, as if they were newly joined but without affecting the groups' join count.

Must only be called after calling MakeAllNonMember as a group should not be initialized while it is not in the non-member state.

Precondition: g.protocolMU must be locked.

func (*GenericMulticastProtocolState) IsLocallyJoinedRLocked

func (g *GenericMulticastProtocolState) IsLocallyJoinedRLocked(groupAddress tcpip.Address) bool

IsLocallyJoinedRLocked returns true if the group is locally joined.

Precondition: g.protocolMU must be read locked.

func (*GenericMulticastProtocolState) JoinGroupLocked

func (g *GenericMulticastProtocolState) JoinGroupLocked(groupAddress tcpip.Address)

JoinGroupLocked handles joining a new group.

Precondition: g.protocolMU must be locked.

func (*GenericMulticastProtocolState) LeaveGroupLocked

func (g *GenericMulticastProtocolState) LeaveGroupLocked(groupAddress tcpip.Address) bool

LeaveGroupLocked handles leaving the group.

Returns false if the group is not currently joined.

Precondition: g.protocolMU must be locked.

func (*GenericMulticastProtocolState) MakeAllNonMemberLocked

func (g *GenericMulticastProtocolState) MakeAllNonMemberLocked()

MakeAllNonMemberLocked transitions all groups to the non-member state.

The groups will still be considered joined locally.

MUST be called when the multicast group protocol is disabled.

Precondition: g.protocolMU must be locked.

func (*GenericMulticastProtocolState) SendQueuedReportsLocked

func (g *GenericMulticastProtocolState) SendQueuedReportsLocked()

SendQueuedReportsLocked attempts to send reports for groups that failed to send reports during their last attempt.

Precondition: g.protocolMU must be locked.

type MultiCounterIPForwardingStats

type MultiCounterIPForwardingStats struct {
	// Unrouteable is the number of IP packets received which were dropped
	// because the netstack could not construct a route to their
	// destination.
	Unrouteable tcpip.MultiCounterStat

	// ExhaustedTTL is the number of IP packets received which were dropped
	// because their TTL was exhausted.
	ExhaustedTTL tcpip.MultiCounterStat

	// LinkLocalSource is the number of IP packets which were dropped
	// because they contained a link-local source address.
	LinkLocalSource tcpip.MultiCounterStat

	// LinkLocalDestination is the number of IP packets which were dropped
	// because they contained a link-local destination address.
	LinkLocalDestination tcpip.MultiCounterStat

	// PacketTooBig is the number of IP packets which were dropped because they
	// were too big for the outgoing MTU.
	PacketTooBig tcpip.MultiCounterStat

	// HostUnreachable is the number of IP packets received which could not be
	// successfully forwarded due to an unresolvable next hop.
	HostUnreachable tcpip.MultiCounterStat

	// ExtensionHeaderProblem is the number of IP packets which were dropped
	// because of a problem encountered when processing an IPv6 extension
	// header.
	ExtensionHeaderProblem tcpip.MultiCounterStat

	// Errors is the number of IP packets received which could not be
	// successfully forwarded.
	Errors tcpip.MultiCounterStat
}

MultiCounterIPForwardingStats holds IP forwarding statistics. Each counter may have several versions.

func (*MultiCounterIPForwardingStats) Init

Init sets internal counters to track a and b counters.

type MultiCounterIPStats

type MultiCounterIPStats struct {
	// PacketsReceived is the number of IP packets received from the link
	// layer.
	PacketsReceived tcpip.MultiCounterStat

	// ValidPacketsReceived is the number of valid IP packets that reached the IP
	// layer.
	ValidPacketsReceived tcpip.MultiCounterStat

	// DisabledPacketsReceived is the number of IP packets received from
	// the link layer when the IP layer is disabled.
	DisabledPacketsReceived tcpip.MultiCounterStat

	// InvalidDestinationAddressesReceived is the number of IP packets
	// received with an unknown or invalid destination address.
	InvalidDestinationAddressesReceived tcpip.MultiCounterStat

	// InvalidSourceAddressesReceived is the number of IP packets received
	// with a source address that should never have been received on the
	// wire.
	InvalidSourceAddressesReceived tcpip.MultiCounterStat

	// PacketsDelivered is the number of incoming IP packets successfully
	// delivered to the transport layer.
	PacketsDelivered tcpip.MultiCounterStat

	// PacketsSent is the number of IP packets sent via WritePacket.
	PacketsSent tcpip.MultiCounterStat

	// OutgoingPacketErrors is the number of IP packets which failed to
	// write to a link-layer endpoint.
	OutgoingPacketErrors tcpip.MultiCounterStat

	// MalformedPacketsReceived is the number of IP Packets that were
	// dropped due to the IP packet header failing validation checks.
	MalformedPacketsReceived tcpip.MultiCounterStat

	// MalformedFragmentsReceived is the number of IP Fragments that were
	// dropped due to the fragment failing validation checks.
	MalformedFragmentsReceived tcpip.MultiCounterStat

	// IPTablesPreroutingDropped is the number of IP packets dropped in the
	// Prerouting chain.
	IPTablesPreroutingDropped tcpip.MultiCounterStat

	// IPTablesInputDropped is the number of IP packets dropped in the
	// Input chain.
	IPTablesInputDropped tcpip.MultiCounterStat

	// IPTablesForwardDropped is the number of IP packets dropped in the
	// Forward chain.
	IPTablesForwardDropped tcpip.MultiCounterStat

	// IPTablesOutputDropped is the number of IP packets dropped in the
	// Output chain.
	IPTablesOutputDropped tcpip.MultiCounterStat

	// IPTablesPostroutingDropped is the number of IP packets dropped in
	// the Postrouting chain.
	IPTablesPostroutingDropped tcpip.MultiCounterStat

	// OptionTimestampReceived is the number of Timestamp options seen.
	OptionTimestampReceived tcpip.MultiCounterStat

	// OptionRecordRouteReceived is the number of Record Route options
	// seen.
	OptionRecordRouteReceived tcpip.MultiCounterStat

	// OptionRouterAlertReceived is the number of Router Alert options
	// seen.
	OptionRouterAlertReceived tcpip.MultiCounterStat

	// OptionUnknownReceived is the number of unknown IP options seen.
	OptionUnknownReceived tcpip.MultiCounterStat

	// Forwarding collects stats related to IP forwarding.
	Forwarding MultiCounterIPForwardingStats
}

MultiCounterIPStats holds IP statistics, each counter may have several versions.

func (*MultiCounterIPStats) Init

func (m *MultiCounterIPStats) Init(a, b *tcpip.IPStats)

Init sets internal counters to track a and b counters.

type MulticastGroupProtocol

type MulticastGroupProtocol interface {
	// Enabled indicates whether the generic multicast protocol will be
	// performed.
	//
	// When enabled, the protocol may transmit report and leave messages when
	// joining and leaving multicast groups respectively, and handle incoming
	// packets.
	//
	// When disabled, the protocol will still keep track of locally joined groups,
	// it just won't transmit and handle packets, or update groups' state.
	Enabled() bool

	// SendReport sends a multicast report for the specified group address.
	//
	// Returns false if the caller should queue the report to be sent later. Note,
	// returning false does not mean that the receiver hit an error.
	SendReport(groupAddress tcpip.Address) (sent bool, err tcpip.Error)

	// SendLeave sends a multicast leave for the specified group address.
	SendLeave(groupAddress tcpip.Address) tcpip.Error

	// ShouldPerformProtocol returns true iff the protocol should be performed for
	// the specified group.
	ShouldPerformProtocol(tcpip.Address) bool
}

MulticastGroupProtocol is a multicast group protocol whose core state machine can be represented by GenericMulticastProtocolState.

Jump to

Keyboard shortcuts

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