rpkt

package
v0.0.0-...-c8fc2fc Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2018 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package rpkt contains the router representation of a SCION packet.

This differs from the higher-level github.com/scionproto/scion/go/lib/spkt package by being tied to an underlying buffer, which greatly improves processing performance at the expense of flexibility.

Index

Constants

View Source
const (
	// FIXME(kormat): remove when generic header walker is implemented.
	ErrExtChainTooLong = "Extension header chain longer than packet"
)
View Source
const (
	UnsupportedL4 = "Unsupported L4 header type"
)

Variables

This section is empty.

Functions

func Init

func Init(revTokenF func(RevTokenCallbackArgs))

Init takes callback functions provided by the router and stores them for use by the rpkt package.

Types

type EgressPair

type EgressPair struct {
	S   *rctx.Sock
	Dst *topology.AddrInfo
}

EgressPair contains the output function to send a packet with, along with an overlay destination address.

type EgressRtrPkt

type EgressRtrPkt struct {
	Rp  *RtrPkt
	Dst *topology.AddrInfo
}

type HookResult

type HookResult int
const (
	// HookError means the current hook has failed.
	HookError HookResult = iota
	// HookContinue means the caller should continue to call other hooks.
	HookContinue
	// HookFinish means the current hook has provided the definitive answer,
	// and no further hooks should be called.
	HookFinish
)

type RevTokenCallbackArgs

type RevTokenCallbackArgs struct {
	RevInfo *path_mgmt.RevInfo
	Addrs   []addr.HostSVC
}

type RtrPkt

type RtrPkt struct {
	// Id is a pseudo-random identifier for a packet, to allow correlation of logging statements.
	// (RECV)
	Id string
	// Raw is the underlying buffer that represents the raw packet bytes. (RECV)
	Raw common.RawBytes
	// TimeIn is the time the packet was received. This is used for metrics
	// calculations. (RECV)
	TimeIn time.Time
	// DirFrom is the direction from which the packet was received. (RECV)
	DirFrom rcmn.Dir
	// DirTo is the direction to which the packet is travelling. (PARSE)
	DirTo rcmn.Dir
	// Ingress contains the incoming overlay metadata the packet arrived with, and the (list of)
	// interface(s) it arrived on. (RECV)
	Ingress addrIFPair
	// Egress is a list of function & address pairs that determine how and where to the packet will
	// be sent. (PROCESS/ROUTE)
	Egress []EgressPair
	// CmnHdr is the SCION common header. Required for every packet. (PARSE)
	CmnHdr spkt.CmnHdr
	// Flag to indicate whether this router incremented the path. (ROUTE)
	IncrementedPath bool

	// HBHExt is the list of Hop-by-hop extensions, if any. (PARSE)
	HBHExt []rExtension
	// E2EExt is the list of end2end extensions, if any. (PARSE, only if needed)
	// TODO(kormat): The router currently ignores these.
	E2EExt []rExtension
	// L4Type is the type of the L4 protocol. If there isn't an L4 header, this will be L4None
	// (PROCESS, only if needed)
	L4Type common.L4ProtocolType

	// SCMPError flags if the packet is an SCMP Error packet, in which case it should never trigger
	// an error response packet. (PARSE, if SCMP extension header is present)
	SCMPError bool
	// Logger is used to log messages associated with a packet. The Id field is automatically
	// included in the output.
	log.Logger
	// The current router context to process this packet.
	Ctx *rctx.Ctx

	// Called by Release when the reference count hits 0
	Free func(*RtrPkt)
	// contains filtered or unexported fields
}

Router representation of SCION packet, including metadata. The comments for the members have tags to specifiy if the member is set during receiving (RECV), parsing (PARSE), processing (PROCESS) or routing (ROUTE). A number of the non-exported fields are pointers, as they are either optional or computed only on demand.

func NewRtrPkt

func NewRtrPkt() *RtrPkt

func RtrPktFromScnPkt

func RtrPktFromScnPkt(sp *spkt.ScnPkt, dirTo rcmn.Dir, ctx *rctx.Ctx) (*RtrPkt, error)

RtrPktFromScnPkt creates an RtrPkt from an spkt.ScnPkt.

func (*RtrPkt) Bytes

func (rp *RtrPkt) Bytes() common.RawBytes

Bytes returns the raw bytes of the RtrPkt. Needed to implement rctx.OutputObj interface.

func (*RtrPkt) DstHost

func (rp *RtrPkt) DstHost() (addr.HostAddr, error)

DstHost retrieves the destination host address if it isn't already known.

func (*RtrPkt) DstIA

func (rp *RtrPkt) DstIA() (*addr.ISD_AS, error)

DstIA retrieves the destination ISD-AS if it isn't already known.

func (*RtrPkt) ErrStr

func (rp *RtrPkt) ErrStr(desc string) string

ErrStr is a small utility method to combine an error message with a string representation of the packet, as well as a hex representation of the raw packet buffer.

func (*RtrPkt) ErrStrf

func (rp *RtrPkt) ErrStrf(desc string) func() string

ErrStrf is a wrapper for ErrStr, which returns a callback to allow lazy evaluation of ErrStr. This is used for assert.Mustf in particular, so that when the assertion passes, the expensive call to ErrStr is avoided.

func (*RtrPkt) GetRaw

func (rp *RtrPkt) GetRaw(blk scmp.RawBlock) common.RawBytes

GetRaw returns slices of the underlying buffer corresponding to part of the packet identified by the blk argument. This is used, for example, by SCMP to quote parts of the packet in an error response.

func (*RtrPkt) HopF

func (rp *RtrPkt) HopF() (*spath.HopField, error)

HopF retrieves the current path Hop Field if it isn't already known.

func (*RtrPkt) IFCurr

func (rp *RtrPkt) IFCurr() (*common.IFIDType, error)

IFCurr retrieves the current interface ID if not already known.

func (*RtrPkt) IFNext

func (rp *RtrPkt) IFNext() (*common.IFIDType, error)

IFNext retrieves the next interface ID if not already known. As this may be an interface in an external ISD-AS, this is not sanity-checked.

func (*RtrPkt) IncPath

func (rp *RtrPkt) IncPath() (bool, error)

IncPath increments the packet's path, if any. The bool return value is set to true if the segment changes (specifically if the packet's metadata is updated to the new segment).

func (*RtrPkt) InfoF

func (rp *RtrPkt) InfoF() (*spath.InfoField, error)

InfoF retrieves the current path Info Field if it isn't already known.

func (*RtrPkt) L4Hdr

func (rp *RtrPkt) L4Hdr(verify bool) (l4.L4Header, error)

L4Hdr finds, parses and returns the layer 4 header, if any. The verify argument determines whether to verify the L4 header or not.

func (*RtrPkt) NeedsLocalProcessing

func (rp *RtrPkt) NeedsLocalProcessing() error

NeedsLocalProcessing determines if the router needs to do more than just forward a packet (e.g. resolve an SVC destination address).

func (*RtrPkt) Parse

func (rp *RtrPkt) Parse() error

Parse handles the basic parsing of a packet.

func (*RtrPkt) Payload

func (rp *RtrPkt) Payload(verify bool) (common.Payload, error)

Payload retrieves the packet's payload if not already known. It ensures that the layer 4 header has been parsed first, and then uses registered hooks to retrieve the payload. Note there is no generic fallback; if no hooks are registered, then no work is done.

func (*RtrPkt) Process

func (rp *RtrPkt) Process() error

Process uses any registered hooks to process the packet. Note that there is no generic fallback; if no hooks are registered, then no work is done.

func (*RtrPkt) Release

func (rp *RtrPkt) Release()

func (*RtrPkt) Reset

func (rp *RtrPkt) Reset()

Reset resets an RtrPkt to it's ~initial state, so it can be reused. Note that for performance reasons it doesn't actually clear the raw buffer, so reuse of an RtrPkt instance must ensure that the length of the buffer is set to the length of the new data, to prevent any of the old data from leaking through.

Fields that are assumed to be overwritten (and hence aren't reset): TimeIn, CmnHdr, Logger

func (*RtrPkt) Route

func (rp *RtrPkt) Route() error

Route handles routing of packets. Registered hooks are called, allowing them to add to the packet's Egress slice, and then the slice is iterated over and each entry's function is called with the entry's address as the argument. The use of a slice allows for a packet to be sent multiple times (e.g. sending IFID packets to all BS instances in the local AS).

func (*RtrPkt) RouteResolveSVC

func (rp *RtrPkt) RouteResolveSVC() (HookResult, error)

RouteResolveSVC is a hook to resolve SVC addresses for routing packets to the local ISD-AS.

func (*RtrPkt) RouteResolveSVCAny

func (rp *RtrPkt) RouteResolveSVCAny(
	svc addr.HostSVC, s *rctx.Sock) (HookResult, error)

RouteResolveSVCAny handles routing a packet to an anycast SVC address (i.e. a single instance of a local infrastructure service).

func (*RtrPkt) RouteResolveSVCMulti

func (rp *RtrPkt) RouteResolveSVCMulti(
	svc addr.HostSVC, s *rctx.Sock) (HookResult, error)

RouteResolveSVCMulti handles routing a packet to a multicast SVC address (i.e. one packet per machine hosting instances for a local infrastructure service).

func (*RtrPkt) SetPld

func (rp *RtrPkt) SetPld(pld common.Payload) error

SetPld updates/sets the payload of an RtrPkt.

func (*RtrPkt) SrcHost

func (rp *RtrPkt) SrcHost() (addr.HostAddr, error)

SrcHost retrieves the source host address if it isn't already known.

func (*RtrPkt) SrcIA

func (rp *RtrPkt) SrcIA() (*addr.ISD_AS, error)

SrcIA retrieves the source ISD-AS if it isn't already known.

func (*RtrPkt) String

func (rp *RtrPkt) String() string

func (*RtrPkt) ToScnPkt

func (rp *RtrPkt) ToScnPkt(verify bool) (*spkt.ScnPkt, error)

ToScnPkt converts this RtrPkt into an spkt.ScnPkt. The verify argument defines whether verification errors should cause this conversion to fail or not. Setting this to false is useful when trying to convert a packet that is already known to have errors, for the purpose of sending an error response.

func (*RtrPkt) UpFlag

func (rp *RtrPkt) UpFlag() (*bool, error)

UpFlag retrieves the current path segment's Up flag if not already known. (Up is defined as being the opposite to the direction in which the segment was created.)

func (*RtrPkt) Validate

func (rp *RtrPkt) Validate() error

Validate performs basic validation of a packet, including calling any registered validation hooks.

Jump to

Keyboard shortcuts

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