Documentation ¶
Overview ¶
Package snet implements interfaces net.Conn and net.PacketConn for SCION connections.
New networking contexts can be created using NewNetwork. Calling the Dial or Listen methods on the networking context yields connections that run in that context.
A connection can be created by calling Dial or Listen; both functions register an address-port pair with the local dispatcher. For Dial, the remote address is fixed, meaning only Read and Write can be used. Attempting to ReadFrom or WriteTo a connection created by Dial is an invalid operation. For Listen, the remote address cannot be fixed. ReadFrom can be used to read from the connection and find out the sender's address; and WriteTo can be used to send a message to a chosen destination.
Multiple networking contexts can share the same SCIOND and/or dispatcher.
Write calls never return SCMP errors directly. If a write call caused an SCMP message to be received by the Conn, it can be inspected by calling Read. In this case, the error value is non-nil and can be type asserted to *OpError. Method SCMP() can be called on the error to extract the SCMP header.
Important: not draining SCMP errors via Read calls can cause the dispatcher to shutdown the socket (see https://github.com/scionproto/scion/pull/1356). To prevent this on a Conn object with only Write calls, run a separate goroutine that continuously calls Read on the Conn.
Index ¶
- Constants
- func CopyUDPAddr(a *net.UDPAddr) *net.UDPAddr
- type BaseRouter
- type Bytes
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (int, error)
- func (c *Conn) ReadFrom(b []byte) (int, net.Addr, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SVC() addr.HostSVC
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(b []byte) (int, error)
- func (c *Conn) WriteTo(b []byte, raddr net.Addr) (int, error)
- type DefaultPacketDispatcherService
- type DefaultSCMPHandler
- type GeoCoordinates
- type IntraASPathQuerier
- type L4Header
- type LinkType
- type Network
- type OpError
- type Packet
- type PacketConn
- type PacketDispatcherService
- type PacketInfo
- type Path
- type PathFingerprint
- type PathInterface
- type PathMetadata
- type PathQuerier
- type Payload
- type RevocationHandler
- type Router
- type SCIONAddress
- type SCIONNetwork
- type SCIONPacketConn
- func (c *SCIONPacketConn) Close() error
- func (c *SCIONPacketConn) ReadFrom(pkt *Packet, ov *net.UDPAddr) error
- func (c *SCIONPacketConn) SetDeadline(d time.Time) error
- func (c *SCIONPacketConn) SetReadDeadline(d time.Time) error
- func (c *SCIONPacketConn) SetWriteDeadline(d time.Time) error
- func (c *SCIONPacketConn) WriteTo(pkt *Packet, ov *net.UDPAddr) error
- type SCMPDestinationUnreachable
- type SCMPEchoReply
- type SCMPEchoRequest
- type SCMPExternalInterfaceDown
- type SCMPExternalInterfaceDownL4
- type SCMPHandler
- type SCMPInternalConnectivityDown
- type SCMPPayload
- type SCMPTracerouteReply
- type SCMPTracerouteRequest
- type SVCAddr
- type SerializationOptions
- type UDPAddr
- type UDPL4
- type UDPPayload
Constants ¶
const (
// BufSize is the receive and send buffer sizes
BufSize = 1<<16 - 1
)
const MaxSegTTL = 24 * 60 * 60
MaxSegTTL is the maximum expiry for a path segment. It's one day in seconds.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseRouter ¶ added in v0.4.0
type BaseRouter struct {
Querier PathQuerier
}
type Bytes ¶ added in v0.4.0
Bytes contains the raw slices of data related to a packet. Most callers can safely ignore it. For performance-critical applications, callers should manually allocate/recycle the Bytes.
Prior to serialization/decoding, the internal slice is reset to its full capacity, so be careful about passing in slices that have runoff data after their length.
After a packet has been serialized/decoded, the length of Contents will be equal to the size of the entire packet data. The capacity remains unchanged.
If Bytes is not initialized, space will be allocated during serialization/decoding.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func (*Conn) Read ¶
Read reads data into b from a connection with a fixed remote address. If the remote address for the connection is unknown, Read returns an error.
func (*Conn) ReadFrom ¶
ReadFrom reads data into b, returning the length of copied data and the address of the sender.
func (*Conn) RemoteAddr ¶
func (*Conn) SetReadDeadline ¶
func (*Conn) SetWriteDeadline ¶
type DefaultPacketDispatcherService ¶ added in v0.4.0
type DefaultPacketDispatcherService struct { // Dispatcher is used to get packets from the local SCION Dispatcher process. Dispatcher reliable.Dispatcher // SCMPHandler is invoked for packets that contain an SCMP L4. If the // handler is nil, errors are returned back to applications every time an // SCMP message is received. SCMPHandler SCMPHandler }
DefaultPacketDispatcherService parses/serializes packets received from / sent to the dispatcher.
type DefaultSCMPHandler ¶ added in v0.6.0
type DefaultSCMPHandler struct { // RevocationHandler manages revocations received via SCMP. If nil, the // handler is not called. RevocationHandler RevocationHandler }
DefaultSCMPHandler handles SCMP messages received from the network. If a revocation handler is configured, it is informed of any received interface down messages.
func (DefaultSCMPHandler) Handle ¶ added in v0.6.0
func (h DefaultSCMPHandler) Handle(pkt *Packet) error
type GeoCoordinates ¶ added in v0.6.0
type GeoCoordinates struct { // Latitude of the geographic coordinate, in the WGS 84 datum. Latitude float32 // Longitude of the geographic coordinate, in the WGS 84 datum. Longitude float32 // Civic address of the location. Address string }
GeoCoordinates describes a geographical position (of a border router on the path).
type IntraASPathQuerier ¶ added in v0.5.0
IntraASPathQuerier implements the PathQuerier interface. It will only provide AS internal paths, i.e., empty paths with only the IA as destination. This should only be used in places where you know that you only need to communicate inside the AS.
type L4Header ¶ added in v0.6.0
type L4Header interface {
// contains filtered or unexported methods
}
type LinkType ¶ added in v0.6.0
type LinkType uint8
LinkType describes the underlying network for inter-domain links.
const ( // LinkTypeUnset represents an unspecified link type. LinkTypeUnset LinkType = iota // LinkTypeDirect represents a direct physical connection. LinkTypeDirect // LinkTypeMultihop represents a connection with local routing/switching. LinkTypeMultihop // LinkTypeOpennet represents a connection overlayed over publicly routed Internet. LinkTypeOpennet )
LinkType values
type Packet ¶ added in v0.5.0
type Packet struct { Bytes PacketInfo }
Packet describes a SCION packet.
type PacketConn ¶ added in v0.4.0
type PacketConn interface { ReadFrom(pkt *Packet, ov *net.UDPAddr) error WriteTo(pkt *Packet, ov *net.UDPAddr) error SetReadDeadline(t time.Time) error SetWriteDeadline(t time.Time) error SetDeadline(t time.Time) error Close() error }
PacketConn gives applications easy access to writing and reading custom SCION packets.
type PacketDispatcherService ¶ added in v0.4.0
type PacketDispatcherService interface { Register(ctx context.Context, ia addr.IA, registration *net.UDPAddr, svc addr.HostSVC) (PacketConn, uint16, error) }
PacketDispatcherService constructs SCION sockets where applications have fine-grained control over header fields.
type PacketInfo ¶ added in v0.5.0
type PacketInfo struct { // Destination contains the destination address. Destination SCIONAddress // Source contains the source address. If it is an SVC address, packet // serialization will return an error. Source SCIONAddress // Path contains a SCION forwarding path. The field must be nil or an empty // path if the source and destination are inside the same AS. // // If the source and destination are in different ASes but the path is // nil or empty, an error is returned during serialization. Path spath.Path // Payload is the Payload of the message. Payload Payload }
PacketInfo contains the data needed to construct a SCION packet.
This is a high-level structure, and can only be used to create valid packets. The documentation for each field specifies cases where serialization might fail due to some violation of SCION protocol rules.
type Path ¶ added in v0.4.0
type Path interface { // UnderlayNextHop returns the address:port pair of a local-AS underlay // speaker. Usually, this is a border router that will forward the traffic. UnderlayNextHop() *net.UDPAddr // Path returns a raw (data-plane compatible) representation of the path. Path() spath.Path // Destination is the AS the path points to. Empty paths return the local // AS of the router that created them. Destination() addr.IA // Metadata returns supplementary information about this path. // Returns nil if the metadata is not available. Metadata() *PathMetadata // Copy create a copy of the path. Copy() Path }
Path is an abstract representation of a path. Most applications do not need access to the raw internals.
An empty path is a special kind of path that can be used for intra-AS traffic. Empty paths are valid return values for certain route calls (e.g., if the source and destination ASes match, or if a router was configured without a source of paths). An empty path only contains a Destination value, all other values are zero values.
type PathFingerprint ¶ added in v0.5.0
type PathFingerprint string
func Fingerprint ¶ added in v0.6.0
func Fingerprint(path Path) PathFingerprint
Fingerprint uniquely identifies the path based on the sequence of ASes and BRs, i.e. by its PathInterfaces. Other metadata, such as MTU or NextHop have no effect on the fingerprint. Returns empty string for paths where the interfaces list is not available.
func (PathFingerprint) String ¶ added in v0.5.0
func (pf PathFingerprint) String() string
type PathInterface ¶ added in v0.5.0
type PathInterface struct { // ID is the ID of the interface. ID common.IFIDType // IA is the ISD AS identifier of the interface. IA addr.IA }
PathInterface is an interface of the path.
func (PathInterface) String ¶ added in v0.6.0
func (iface PathInterface) String() string
type PathMetadata ¶ added in v0.6.0
type PathMetadata struct { // Interfaces is a list of interfaces on the path. Interfaces []PathInterface // MTU is the maximum transmission unit for the path, in bytes. MTU uint16 // Expiry is the expiration time of the path. Expiry time.Time // Latency lists the latencies between any two consecutive interfaces. // Entry i describes the latency between interface i and i+1. // Consequently, there are N-1 entries for N interfaces. // A 0-value indicates that the AS did not announce a latency for this hop. Latency []time.Duration // Bandwidth lists the bandwidth between any two consecutive interfaces, in Kbit/s. // Entry i describes the bandwidth between interfaces i and i+1. // A 0-value indicates that the AS did not announce a bandwidth for this hop. Bandwidth []uint64 // Geo lists the geographical position of the border routers along the path. // Entry i describes the position of the router for interface i. // A 0-value indicates that the AS did not announce a position for this router. Geo []GeoCoordinates // LinkType contains the announced link type of inter-domain links. // Entry i describes the link between interfaces 2*i and 2*i+1. LinkType []LinkType // InternalHops lists the number of AS internal hops for the ASes on path. // Entry i describes the hop between interfaces 2*i+1 and 2*i+2 in the same AS. // Consequently, there are no entries for the first and last ASes, as these // are not traversed completely by the path. InternalHops []uint32 // Notes contains the notes added by ASes on the path, in the order of occurrence. // Entry i is the note of AS i on the path. Notes []string }
PathMetadata contains supplementary information about a path.
The information about MTU, Latency, Bandwidth etc. are based solely on data contained in the AS entries in the path construction beacons. These entries are signed/verified based on the control plane PKI. However, the *correctness* of this meta data has *not* been checked.
func (*PathMetadata) Copy ¶ added in v0.6.0
func (pm *PathMetadata) Copy() *PathMetadata
type PathQuerier ¶ added in v0.5.0
type Payload ¶ added in v0.6.0
type Payload interface {
// contains filtered or unexported methods
}
Payload is the payload of the message, use the different payload type to instantiate it.
type RevocationHandler ¶ added in v0.4.0
type RevocationHandler interface { // RevokeRaw handles a revocation received as raw bytes. RevokeRaw(ctx context.Context, rawSRevInfo common.RawBytes) }
RevocationHandler is called by the default SCMP Handler whenever revocations are encountered.
type Router ¶ added in v0.4.0
type Router interface { // Route returns a path from the local AS to dst. If dst matches the local // AS, an empty path is returned. Route(ctx context.Context, dst addr.IA) (Path, error) // AllRoutes is similar to Route except that it returns multiple paths. AllRoutes(ctx context.Context, dst addr.IA) ([]Path, error) }
Router performs path resolution for SCION-speaking applications.
Most applications backed by SCIOND can use the default router implementation in this package. Applications that run SCIOND-less (PS, SD, BS) might be interested in spinning their own implementations.
type SCIONAddress ¶ added in v0.4.0
SCIONAddress is the fully-specified address of a host.
func (SCIONAddress) String ¶ added in v0.6.0
func (a SCIONAddress) String() string
type SCIONNetwork ¶ added in v0.3.0
type SCIONNetwork struct { LocalIA addr.IA Dispatcher PacketDispatcherService }
SCIONNetwork is the SCION networking context.
func NewNetwork ¶
func NewNetwork(ia addr.IA, dispatcher reliable.Dispatcher, revHandler RevocationHandler) *SCIONNetwork
NewNetwork creates a new networking context.
func (*SCIONNetwork) Dial ¶ added in v0.5.0
func (n *SCIONNetwork) Dial(ctx context.Context, network string, listen *net.UDPAddr, remote *UDPAddr, svc addr.HostSVC) (*Conn, error)
Dial returns a SCION connection to remote. Nil values for listen are not supported yet. Parameter network must be "udp". The returned connection's Read and Write methods can be used to receive and send SCION packets. Remote address requires a path and the underlay net hop to be set if the destination is in a remote AS.
The context is used for connection setup, it doesn't affect the returned connection.
func (*SCIONNetwork) Listen ¶ added in v0.5.0
func (n *SCIONNetwork) Listen(ctx context.Context, network string, listen *net.UDPAddr, svc addr.HostSVC) (*Conn, error)
Listen registers listen with the dispatcher. Nil values for listen are not supported yet. The returned connection's ReadFrom and WriteTo methods can be used to receive and send SCION packets with per-packet addressing. Parameter network must be "udp".
The context is used for connection setup, it doesn't affect the returned connection.
type SCIONPacketConn ¶ added in v0.4.0
type SCIONPacketConn struct {
// contains filtered or unexported fields
}
SCIONPacketConn gives applications full control over the content of valid SCION packets.
func NewSCIONPacketConn ¶ added in v0.4.0
func NewSCIONPacketConn(conn net.PacketConn, scmpHandler SCMPHandler, headerV2 bool) *SCIONPacketConn
NewSCIONPacketConn creates a new conn with packet serialization/decoding support that transfers data over conn.
func (*SCIONPacketConn) Close ¶ added in v0.4.0
func (c *SCIONPacketConn) Close() error
func (*SCIONPacketConn) ReadFrom ¶ added in v0.4.0
func (c *SCIONPacketConn) ReadFrom(pkt *Packet, ov *net.UDPAddr) error
func (*SCIONPacketConn) SetDeadline ¶ added in v0.4.0
func (c *SCIONPacketConn) SetDeadline(d time.Time) error
func (*SCIONPacketConn) SetReadDeadline ¶ added in v0.4.0
func (c *SCIONPacketConn) SetReadDeadline(d time.Time) error
func (*SCIONPacketConn) SetWriteDeadline ¶ added in v0.4.0
func (c *SCIONPacketConn) SetWriteDeadline(d time.Time) error
type SCMPDestinationUnreachable ¶ added in v0.6.0
type SCMPDestinationUnreachable struct { Payload []byte // contains filtered or unexported fields }
SCMPDestinationUnreachable is the message that a destination is not reachable.
func (SCMPDestinationUnreachable) Code ¶ added in v0.6.0
func (m SCMPDestinationUnreachable) Code() slayers.SCMPCode
Code returns the SCMP code.
func (SCMPDestinationUnreachable) Type ¶ added in v0.6.0
func (SCMPDestinationUnreachable) Type() slayers.SCMPType
Type returns the SCMP type.
type SCMPEchoReply ¶ added in v0.6.0
SCMPEchoReply is the SCMP echo reply payload.
func (SCMPEchoReply) Code ¶ added in v0.6.0
func (SCMPEchoReply) Code() slayers.SCMPCode
Code returns the SCMP code.
func (SCMPEchoReply) Type ¶ added in v0.6.0
func (SCMPEchoReply) Type() slayers.SCMPType
Type returns the SCMP type.
type SCMPEchoRequest ¶ added in v0.6.0
SCMPEchoRequest is the SCMP echo request payload.
func (SCMPEchoRequest) Code ¶ added in v0.6.0
func (SCMPEchoRequest) Code() slayers.SCMPCode
Code returns the SCMP code.
func (SCMPEchoRequest) Type ¶ added in v0.6.0
func (SCMPEchoRequest) Type() slayers.SCMPType
Type returns the SCMP type.
type SCMPExternalInterfaceDown ¶ added in v0.6.0
SCMPExternalInterfaceDown is the message that indicates that an interface is down.
func (SCMPExternalInterfaceDown) Code ¶ added in v0.6.0
func (SCMPExternalInterfaceDown) Code() slayers.SCMPCode
Code returns the SCMP code.
func (SCMPExternalInterfaceDown) Type ¶ added in v0.6.0
func (SCMPExternalInterfaceDown) Type() slayers.SCMPType
Type returns the SCMP type.
type SCMPExternalInterfaceDownL4 ¶ added in v0.6.0
type SCMPExternalInterfaceDownL4 struct {
slayers.SCMPExternalInterfaceDown
}
type SCMPHandler ¶ added in v0.4.0
type SCMPHandler interface { // Handle processes the packet as an SCMP packet. If packet is not SCMP, it // returns an error. // // If the handler returns an error value, snet will propagate the error // back to the caller. If the return value is nil, snet will reattempt to // read a data packet from the underlying dispatcher connection. // // Handlers that wish to ignore SCMP can just return nil. // // If the handler mutates the packet, the changes are seen by snet // connection method callers. Handle(pkt *Packet) error }
SCMPHandler customizes the way snet connections deal with SCMP.
type SCMPInternalConnectivityDown ¶ added in v0.6.0
SCMPInternalConnectivityDown is the message that an internal interface is down.
func (SCMPInternalConnectivityDown) Code ¶ added in v0.6.0
func (SCMPInternalConnectivityDown) Code() slayers.SCMPCode
Code returns the SCMP code.
func (SCMPInternalConnectivityDown) Type ¶ added in v0.6.0
func (SCMPInternalConnectivityDown) Type() slayers.SCMPType
Type returns the SCMP type.
type SCMPPayload ¶ added in v0.6.0
type SCMPPayload interface { Payload // Type returns the type of the SCMP message as defined in slayers. Type() slayers.SCMPType // Code returns the code of the SCMP message as defined in slayers. Code() slayers.SCMPCode }
SCMPPayload is the interface that all SCMP payloads must implement. It can be used to quickly check facts about an SCMP message.
type SCMPTracerouteReply ¶ added in v0.6.0
SCMPTracerouteReply is the SCMP traceroute reply payload.
func (SCMPTracerouteReply) Code ¶ added in v0.6.0
func (SCMPTracerouteReply) Code() slayers.SCMPCode
Code returns the SCMP code.
func (SCMPTracerouteReply) Type ¶ added in v0.6.0
func (SCMPTracerouteReply) Type() slayers.SCMPType
Type returns the SCMP type.
type SCMPTracerouteRequest ¶ added in v0.6.0
SCMPTracerouteRequest is the SCMP traceroute request payload.
func (SCMPTracerouteRequest) Code ¶ added in v0.6.0
func (SCMPTracerouteRequest) Code() slayers.SCMPCode
Code returns the SCMP code.
func (SCMPTracerouteRequest) Type ¶ added in v0.6.0
func (SCMPTracerouteRequest) Type() slayers.SCMPType
Type returns the SCMP type.
type SVCAddr ¶ added in v0.5.0
SVCAddr is the address type for SVC destinations.
type SerializationOptions ¶ added in v0.4.0
type SerializationOptions struct { // If ComputeChecksums is true, the checksums in sent Packets are // recomputed. Otherwise, the checksum value is left intact. ComputeChecksums bool // If FixLengths is true, any lengths in sent Packets are recomputed // to match the data contained in payloads/inner layers. This currently // concerns extension headers and the L4 header. FixLengths bool // If InitializePaths is set to true, then forwarding paths are reset to // their starting InfoField/HopField during serialization, irrespective of // previous offsets. If it is set to false, then the fields are left // unchanged. InitializePaths bool }
type UDPAddr ¶ added in v0.5.0
UDPAddr to be used when UDP host.
func ParseUDPAddr ¶ added in v0.5.0
ParseUDPAddr converts an address string to a SCION address. The supported formats are:
Recommended:
- isd-as,ipv4:port (e.g., 1-ff00:0:300,192.168.1.1:8080)
- isd-as,[ipv6]:port (e.g., 1-ff00:0:300,[f00d::1337]:8080)
- isd-as,[ipv6%zone]:port (e.g., 1-ff00:0:300,[f00d::1337%zone]:8080)
Others:
- isd-as,[ipv4]:port (e.g., 1-ff00:0:300,[192.168.1.1]:8080)
- isd-as,[ipv4] (e.g., 1-ff00:0:300,[192.168.1.1])
- isd-as,[ipv6] (e.g., 1-ff00:0:300,[f00d::1337])
- isd-as,[ipv6%zone] (e.g., 1-ff00:0:300,[f00d::1337%zone])
- isd-as,ipv4 (e.g., 1-ff00:0:300,192.168.1.1)
- isd-as,ipv6 (e.g., 1-ff00:0:300,f00d::1337)
- isd-as,ipv6%zone (e.g., 1-ff00:0:300,f00d::1337%zone)
Not supported:
- isd-as,ipv6:port (caveat if ipv6:port builds a valid ipv6 address, it will successfully parse as ipv6 without error)
func (*UDPAddr) Set ¶ added in v0.5.0
Set is used to satisfy the flag.Value and pflag.Value interface.
type UDPPayload ¶ added in v0.6.0
UDPPayload is a simple UDP payload.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
Package mock_snet is a generated GoMock package.
|
Package mock_snet is a generated GoMock package. |
Package path implements snet.Path with full metadata This is used by libraries that provide paths for applications to use, such as the path combinator and the sciond API.
|
Package path implements snet.Path with full metadata This is used by libraries that provide paths for applications to use, such as the path combinator and the sciond API. |
QUIC/SCION implementation.
|
QUIC/SCION implementation. |