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
- func Init(rawSRevF func(RawSRevCallbackArgs))
- type EgressPair
- type EgressRtrPkt
- type HookResult
- type RawSRevCallbackArgs
- type RtrPkt
- func (rp *RtrPkt) Bytes() common.RawBytes
- func (rp *RtrPkt) ConsDirFlag() (*bool, error)
- func (rp *RtrPkt) CreateReply(sp *spkt.ScnPkt) (*RtrPkt, error)
- func (rp *RtrPkt) CreateReplyScnPkt() (*spkt.ScnPkt, error)
- func (rp *RtrPkt) DstHost() (addr.HostAddr, error)
- func (rp *RtrPkt) DstIA() (addr.IA, error)
- func (rp *RtrPkt) ErrStr(desc string) string
- func (rp *RtrPkt) ErrStrf(desc string) func() string
- func (rp *RtrPkt) GetRaw(blk scmp.RawBlock) common.RawBytes
- func (rp *RtrPkt) HopF() (*spath.HopField, error)
- func (rp *RtrPkt) IFCurr() (*common.IFIDType, error)
- func (rp *RtrPkt) IFNext() (*common.IFIDType, error)
- func (rp *RtrPkt) IncPath() (bool, error)
- func (rp *RtrPkt) InfoF() (*spath.InfoField, error)
- func (rp *RtrPkt) L4Hdr(verify bool) (l4.L4Header, error)
- func (rp *RtrPkt) NeedsLocalProcessing() error
- func (rp *RtrPkt) Parse() error
- func (rp *RtrPkt) Payload(verify bool) (common.Payload, error)
- func (rp *RtrPkt) Process() error
- func (rp *RtrPkt) RefInc(val int)
- func (rp *RtrPkt) Release()
- func (rp *RtrPkt) Reset()
- func (rp *RtrPkt) Route() error
- func (rp *RtrPkt) RouteResolveSVC() (HookResult, error)
- func (rp *RtrPkt) SetPld(pld common.Payload) error
- func (rp *RtrPkt) SrcHost() (addr.HostAddr, error)
- func (rp *RtrPkt) SrcIA() (addr.IA, error)
- func (rp *RtrPkt) String() string
- func (rp *RtrPkt) ToScnPkt(verify bool) (*spkt.ScnPkt, error)
- func (rp *RtrPkt) Validate() (bool, error)
Constants ¶
const (
// FIXME(kormat): remove when generic header walker is implemented.
ErrExtChainTooLong = "Extension header chain longer than packet"
)
const (
UnsupportedL4 = "Unsupported L4 header type"
)
Variables ¶
This section is empty.
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 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 RtrPktFromScnPkt ¶
RtrPktFromScnPkt creates an RtrPkt from an spkt.ScnPkt.
func (*RtrPkt) Bytes ¶
Bytes returns the raw bytes of the RtrPkt. Needed to implement rctx.OutputObj interface.
func (*RtrPkt) ConsDirFlag ¶
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) CreateReplyScnPkt ¶
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) ErrStr ¶
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 ¶
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 ¶
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) IFCurr ¶
IFCurr retrieves the current interface ID from the packet headers/extensions, if not already known.
func (*RtrPkt) IFNext ¶
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 ¶
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) L4Hdr ¶
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 ¶
NeedsLocalProcessing determines if the router needs to do more than just forward a packet (e.g. resolve an SVC destination address).
func (*RtrPkt) Payload ¶
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 ¶
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) 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 ¶
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) ToScnPkt ¶
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 ¶
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.