Documentation ¶
Overview ¶
Package ip holds IPv4/IPv6 common utilities.
Index ¶
- Constants
- type DAD
- func (d *DAD) CheckDuplicateAddressLocked(addr tcpip.Address, h stack.DADCompletionHandler) stack.DADCheckAddressDisposition
- func (d *DAD) ExtendIfNonceEqualLocked(addr tcpip.Address, nonce []byte) ExtendIfNonceEqualLockedDisposition
- func (d *DAD) Init(protocolMU sync.Locker, configs stack.DADConfigurations, opts DADOptions)
- func (d *DAD) SetConfigsLocked(c stack.DADConfigurations)
- func (d *DAD) StopLocked(addr tcpip.Address, reason stack.DADResult)
- type DADOptions
- type DADProtocol
- type ErrHostUnreachable
- type ErrInitializingSourceAddress
- type ErrLinkLocalDestinationAddress
- type ErrLinkLocalSourceAddress
- type ErrMessageTooLong
- type ErrNoMulticastPendingQueueBufferSpace
- type ErrOther
- type ErrOutgoingDeviceNoBufferSpace
- type ErrParameterProblem
- type ErrTTLExceeded
- type ErrUnexpectedMulticastInputInterface
- type ErrUnknownOutputEndpoint
- type ExtendIfNonceEqualLockedDisposition
- type ForwardingError
- type GenericMulticastProtocolOptions
- type GenericMulticastProtocolState
- func (g *GenericMulticastProtocolState) GetV1ModeLocked() bool
- func (g *GenericMulticastProtocolState) HandleQueryLocked(groupAddress tcpip.Address, maxResponseTime time.Duration)
- func (g *GenericMulticastProtocolState) HandleQueryV2Locked(groupAddress tcpip.Address, maxResponseCode uint16, ...)
- func (g *GenericMulticastProtocolState) HandleReportLocked(groupAddress tcpip.Address)
- func (g *GenericMulticastProtocolState) Init(protocolMU *sync.RWMutex, opts GenericMulticastProtocolOptions)
- func (g *GenericMulticastProtocolState) InitializeGroupsLocked()
- func (g *GenericMulticastProtocolState) IsLocallyJoinedRLocked(groupAddress tcpip.Address) bool
- func (g *GenericMulticastProtocolState) JoinGroupLocked(groupAddress tcpip.Address)
- func (g *GenericMulticastProtocolState) LeaveGroupLocked(groupAddress tcpip.Address) bool
- func (g *GenericMulticastProtocolState) MakeAllNonMemberLocked()
- func (g *GenericMulticastProtocolState) SendQueuedReportsLocked()
- func (g *GenericMulticastProtocolState) SetV1ModeLocked(v bool) bool
- type MultiCounterIPForwardingStats
- type MultiCounterIPStats
- type MulticastGroupProtocol
- type MulticastGroupProtocolV2ReportBuilder
- type MulticastGroupProtocolV2ReportRecordType
Constants ¶
const ( // DefaultRobustnessVariable is the default robustness variable // // As per RFC 3810 section 9.1 (for MLDv2), // // The Robustness Variable allows tuning for the expected packet loss on // a link. If a link is expected to be lossy, the value of the // Robustness Variable may be increased. MLD is robust to [Robustness // Variable] - 1 packet losses. The value of the Robustness Variable // MUST NOT be zero, and SHOULD NOT be one. Default value: 2. // // As per RFC 3376 section 8.1 (for IGMPv3), // // The Robustness Variable allows tuning for the expected packet loss on // a network. If a network is expected to be lossy, the Robustness // Variable may be increased. IGMP is robust to (Robustness Variable - // 1) packet losses. The Robustness Variable MUST NOT be zero, and // SHOULD NOT be one. Default: 2 DefaultRobustnessVariable = 2 // DefaultQueryInterval is the default query interval. // // As per RFC 3810 section 9.2 (for MLDv2), // // The Query Interval variable denotes the interval between General // Queries sent by the Querier. Default value: 125 seconds. // // As per RFC 3376 section 8.2 (for IGMPv3), // // The Query Interval is the interval between General Queries sent by // the Querier. Default: 125 seconds. DefaultQueryInterval = 125 * time.Second )
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.
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 ErrHostUnreachable ¶
type ErrHostUnreachable struct{}
ErrHostUnreachable indicates that the destination host could not be reached.
func (*ErrHostUnreachable) String ¶
func (*ErrHostUnreachable) String() string
type ErrInitializingSourceAddress ¶
type ErrInitializingSourceAddress struct{}
ErrInitializingSourceAddress indicates the received packet had a source address that may only be used on the local network as part of initialization work.
func (*ErrInitializingSourceAddress) String ¶
func (*ErrInitializingSourceAddress) String() string
type ErrLinkLocalDestinationAddress ¶
type ErrLinkLocalDestinationAddress struct{}
ErrLinkLocalDestinationAddress indicates the received packet had a link-local destination address.
func (*ErrLinkLocalDestinationAddress) String ¶
func (*ErrLinkLocalDestinationAddress) String() string
type ErrLinkLocalSourceAddress ¶
type ErrLinkLocalSourceAddress struct{}
ErrLinkLocalSourceAddress indicates the received packet had a link-local source address.
func (*ErrLinkLocalSourceAddress) String ¶
func (*ErrLinkLocalSourceAddress) String() 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 ErrNoMulticastPendingQueueBufferSpace ¶
type ErrNoMulticastPendingQueueBufferSpace struct{}
ErrNoMulticastPendingQueueBufferSpace indicates that a multicast packet could not be added to the pending packet queue due to insufficient buffer space.
+stateify savable
func (*ErrNoMulticastPendingQueueBufferSpace) String ¶
func (*ErrNoMulticastPendingQueueBufferSpace) String() string
type ErrOther ¶
ErrOther indicates the packet coould not be forwarded for a reason captured by the contained error.
type ErrOutgoingDeviceNoBufferSpace ¶
type ErrOutgoingDeviceNoBufferSpace struct{}
ErrOutgoingDeviceNoBufferSpace indicates that the outgoing device does not have enough space to hold a buffer.
func (*ErrOutgoingDeviceNoBufferSpace) String ¶
func (*ErrOutgoingDeviceNoBufferSpace) 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 ErrUnexpectedMulticastInputInterface ¶
type ErrUnexpectedMulticastInputInterface struct{}
ErrUnexpectedMulticastInputInterface indicates that the interface that the packet arrived on did not match the routes expected input interface.
func (*ErrUnexpectedMulticastInputInterface) String ¶
func (*ErrUnexpectedMulticastInputInterface) String() string
type ErrUnknownOutputEndpoint ¶
type ErrUnknownOutputEndpoint struct{}
ErrUnknownOutputEndpoint indicates that the output endpoint associated with a route could not be found.
func (*ErrUnknownOutputEndpoint) String ¶
func (*ErrUnknownOutputEndpoint) 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 ¶
ForwardingError represents an error that occurred 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) GetV1ModeLocked ¶
func (g *GenericMulticastProtocolState) GetV1ModeLocked() bool
GetV1ModeLocked returns the V1 configuration.
Precondition: g.protocolMU must be read locked.
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) HandleQueryV2Locked ¶
func (g *GenericMulticastProtocolState) HandleQueryV2Locked(groupAddress tcpip.Address, maxResponseCode uint16, sources header.AddressIterator, robustnessVariable uint8, queryInterval time.Duration)
HandleQueryV2Locked handles a V2 query.
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 ¶
func (g *GenericMulticastProtocolState) Init(protocolMU *sync.RWMutex, opts GenericMulticastProtocolOptions)
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.
func (*GenericMulticastProtocolState) SetV1ModeLocked ¶
func (g *GenericMulticastProtocolState) SetV1ModeLocked(v bool) bool
SetV1ModeLocked sets the V1 configuration.
Returns the previous configuration.
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 // InitializingSource is the number of IP packets which were dropped // because they contained a source address that may only be used on the local // network as part of initialization work. InitializingSource 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 // UnexpectedMulticastInputInterface is the number of multicast packets that // were received on an interface that did not match the corresponding route's // expected input interface. UnexpectedMulticastInputInterface tcpip.MultiCounterStat // UnknownOutputEndpoint is the number of packets that could not be forwarded // because the output endpoint could not be found. UnknownOutputEndpoint tcpip.MultiCounterStat // NoMulticastPendingQueueBufferSpace is the number of multicast packets that // were dropped due to insufficient buffer space in the pending packet queue. NoMulticastPendingQueueBufferSpace tcpip.MultiCounterStat // OutgoingDeviceNoBufferSpace is the number of packets that were dropped due // to insufficient space in the outgoing device. OutgoingDeviceNoBufferSpace 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 ¶
func (m *MultiCounterIPForwardingStats) Init(a, b *tcpip.IPForwardingStats)
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 // NewReportV2Builder creates a new V2 builder. NewReportV2Builder() MulticastGroupProtocolV2ReportBuilder // V2QueryMaxRespCodeToV2Delay takes a V2 query's maximum response code and // returns the V2 delay. V2QueryMaxRespCodeToV2Delay(code uint16) time.Duration // V2QueryMaxRespCodeToV1Delay takes a V2 query's maximum response code and // returns the V1 delay. V2QueryMaxRespCodeToV1Delay(code uint16) time.Duration }
MulticastGroupProtocol is a multicast group protocol whose core state machine can be represented by GenericMulticastProtocolState.
type MulticastGroupProtocolV2ReportBuilder ¶
type MulticastGroupProtocolV2ReportBuilder interface { // AddRecord adds a record to the report. AddRecord(recordType MulticastGroupProtocolV2ReportRecordType, groupAddress tcpip.Address) // Send sends the report. // // Does nothing if no records were added. // // It is invalid to use this builder after this method is called. Send() (sent bool, err tcpip.Error) }
MulticastGroupProtocolV2ReportBuilder is a builder for a V2 report.
type MulticastGroupProtocolV2ReportRecordType ¶
type MulticastGroupProtocolV2ReportRecordType int
MulticastGroupProtocolV2ReportRecordType is the type of a MulticastGroupProtocolv2 multicast address record.
const ( MulticastGroupProtocolV2ReportRecordModeIsInclude MulticastGroupProtocolV2ReportRecordType MulticastGroupProtocolV2ReportRecordModeIsExclude MulticastGroupProtocolV2ReportRecordChangeToIncludeMode MulticastGroupProtocolV2ReportRecordChangeToExcludeMode MulticastGroupProtocolV2ReportRecordAllowNewSources MulticastGroupProtocolV2ReportRecordBlockOldSources )
MulticastGroupProtocolv2 multicast address record types.