rpkt

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 27 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 common.ErrMsg = "Extension header chain longer than packet"
)

Variables

View Source
var (
	// ErrUnsupportedL4 indicates an unsupported L4 header type.
	ErrUnsupportedL4 = serrors.New("unsupported L4 header type")
)

Functions

func Init

func Init(rawSRevF func(RawSRevCallbackArgs))

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 *overlay.OverlayAddr
}

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

type EgressRtrPkt

type EgressRtrPkt struct {
	Rp  *RtrPkt
	Dst *overlay.OverlayAddr
}

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 RawSRevCallbackArgs

type RawSRevCallbackArgs struct {
	SignedRevInfo *path_mgmt.SignedRevInfo
	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
	// 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 specify 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, 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) ConsDirFlag

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

ConsDirFlag retrieves the current path segment's ConsDir flag if not already known. (Consdir is defined as being the direction in which the segment was created.)

func (*RtrPkt) CreateReply

func (rp *RtrPkt) CreateReply(sp *spkt.ScnPkt) (*RtrPkt, error)

func (*RtrPkt) CreateReplyScnPkt

func (rp *RtrPkt) CreateReplyScnPkt() (*spkt.ScnPkt, error)

CreateReplyScnPkt creates a generic ScnPkt reply, by converting the RtrPkt to an ScnPkt, then reversing the ScnPkt, and setting the reply source address.

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.IA, 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 from the packet headers/extensions, 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()

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) RefInc

func (rp *RtrPkt) RefInc(val int)

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) 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.IA, 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) Validate

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

Validate performs basic validation of a packet, including calling any registered validation hooks. Returns true and no error if validation succeeded. On failure due to normal reasons (e.g., filtering), returns false and no error. If validation failed due to some exceptional event, returns an error.

Jump to

Keyboard shortcuts

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