ip

package
v0.0.0-...-4bf4b70 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: Apache-2.0, MIT Imports: 5 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 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

	// AllNodesAddress is a multicast address that all nodes on a network should
	// be a member of.
	//
	// This address will not have the generic multicast protocol performed on it;
	// it will be left in the non member/listener state, and packets will never
	// be sent for it.
	AllNodesAddress tcpip.Address
}

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 MultiCounterIPStats

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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
}

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