Documentation ¶
Overview ¶
Package addr contains types for SCION addressing.
A SCION address is composed of the following parts: ISD (ISolation Domain identifier), AS (Autonomous System idenifier), and Host (the host address).
The ISD-AS parts are often considered together. Conventionally, this is abbreviated to "IA".
The allocations and formatting of ISDs and ASes are documented here: https://github.com/scionproto/scion/wiki/ISD-and-AS-numbering. Note that the ':' separator for AS formatting is not used in paths/filenames for compatibility reasons, so '_' is used instead in those contexts.
Index ¶
- Constants
- Variables
- func FormatAS(as AS, opts ...FormatOption) string
- func FormatAddrPort(a Addr, port uint16) string
- func FormatIA(ia IA, opts ...FormatOption) string
- func FormatISD(isd ISD, opts ...FormatOption) string
- type AS
- type Addr
- type FormatOption
- type Host
- type HostAddrType
- type IA
- type ISD
- type SVC
Examples ¶
Constants ¶
Variables ¶
var ( // ErrUnsupportedSVCAddress indicates an unsupported SVC address. ErrUnsupportedSVCAddress = serrors.New("unsupported SVC address") )
Functions ¶
func FormatAddrPort ¶ added in v0.9.0
FormatAddrPort formats an Addr with a port to the format
[<ISD>-<AS>,<Host>]:<Port>.
EXPERIMENTAL: This API is experimental. It may be changed to a String() function an a combined AddrPort type instead.
func FormatISD ¶
func FormatISD(isd ISD, opts ...FormatOption) string
FormatISD formats the ISD number.
Types ¶
type AS ¶
type AS uint64
AS is the Autonomous System identifier. See formatting and allocations here: https://github.com/scionproto/scion/wiki/ISD-and-AS-numbering#as-numbers
func MustParseAS ¶ added in v0.12.0
MustParseAS parses s and returns the corresponding addr.AS object. It panics if s is not valid AS representation.
func ParseAS ¶
ParseAS parses an AS from a decimal (in the case of the 32bit BGP AS number space) or ipv6-style hex (in the case of SCION-only AS numbers) string.
func ParseFormattedAS ¶
func ParseFormattedAS(as string, opts ...FormatOption) (AS, error)
ParseFormattedAS parses an AS number that was formatted with the FormatAS function. The same options must be provided to successfully parse.
func (AS) MarshalText ¶
func (*AS) UnmarshalText ¶
type Addr ¶ added in v0.9.0
Addr is a full SCION address, composed of ISD, AS and Host part.
func MustParseAddr ¶ added in v0.9.0
MustParseAddr calls ParseAddr(s) and panics on error. It is intended for use in tests with hard-coded strings.
func ParseAddr ¶ added in v0.9.0
ParseAddr parses s as an address in the format <ISD>-<AS>,<Host>, returning the result as an Addr.
Example ¶
package main import ( "fmt" "github.com/scionproto/scion/pkg/addr" ) func main() { a, err := addr.ParseAddr("6-ffaa:0:123,198.51.100.1") fmt.Printf("ia: %v, host type: %v, host: %v, err: %v\n", a.IA, a.Host.Type(), a.Host, err) }
Output: ia: 6-ffaa:0:123, host type: IP, host: 198.51.100.1, err: <nil>
Example (Svc) ¶
package main import ( "fmt" "github.com/scionproto/scion/pkg/addr" ) func main() { a, err := addr.ParseAddr("6-ffaa:0:123,CS") fmt.Printf("ia: %v, host type: %v, host: %v, err: %v\n", a.IA, a.Host.Type(), a.Host, err) }
Output: ia: 6-ffaa:0:123, host type: SVC, host: CS, err: <nil>
func ParseAddrPort ¶ added in v0.9.0
ParseAddrPort parses s as a SCION address with a port, in the format
[<ISD>-<AS>,<Host>]:<Port>.
Examples:
- [isd-as,svc]:port (e.g., [1-ff00:0:110,CS]:80)
- [isd-as,ipv4]:port (e.g., [1-ff00:0:110,192.0.2.1]:80)
- [isd-as,ipv6%zone]:port (e.g., [1-ff00:0:110,2001:DB8::1%zone]:80)
EXPERIMENTAL: This API is experimental. It may be changed to return a combined AddrPort type instead.
func (Addr) MarshalText ¶ added in v0.9.0
func (*Addr) UnmarshalText ¶ added in v0.9.0
type FormatOption ¶
type FormatOption func(*formatOptions)
func WithDefaultPrefix ¶
func WithDefaultPrefix() FormatOption
WithDefaultPrefix enables the default prefix which depends on the type. For the AS number, the prefix is 'AS'. For the ISD number, the prefix is 'ISD'.
func WithFileSeparator ¶
func WithFileSeparator() FormatOption
WithFileSeparator returns an option that sets the separator to underscore.
func WithSeparator ¶
func WithSeparator(separator string) FormatOption
WithSeparator sets the separator to use for formatting AS numbers. In case of the empty string, the ':' is used.
type Host ¶ added in v0.9.0
type Host struct {
// contains filtered or unexported fields
}
Host represents the AS-local host identifier of a SCION address.
Different address types (IPv4, IPv6, SVC) are all represented with this Host struct, discriminated with a Type() field.
The zero value is a valid object with Host{}.Type() == HostTypeNone.
Example ¶
package main import ( "fmt" "net/netip" "github.com/scionproto/scion/pkg/addr" ) func main() { hs := []addr.Host{ {}, addr.HostIP(netip.MustParseAddr("::1")), addr.HostIP(netip.AddrFrom4([4]byte{198, 51, 100, 1})), addr.HostSVC(addr.SvcCS), } for _, h := range hs { fmt.Printf("h: %q, h.Type(): %q", h, h.Type()) switch h.Type() { case addr.HostTypeIP: fmt.Printf(", h.IP().Is4(): %v", h.IP().Is4()) case addr.HostTypeSVC: fmt.Printf(", h.SVC().IsMulticast(): %v", h.SVC().IsMulticast()) default: fmt.Printf(", h == addr.Host{}: %v", h == addr.Host{}) } fmt.Println() } // Use Host as map key: stuff := make(map[addr.Host]struct{}) for _, h := range hs { stuff[h] = struct{}{} } _, hasSvcCS := stuff[addr.HostSVC(addr.SvcCS)] _, hasSvcDS := stuff[addr.HostSVC(addr.SvcDS)] fmt.Printf("has SvcCS: %v, has SvcDS: %v", hasSvcCS, hasSvcDS) }
Output: h: "<None>", h.Type(): "None", h == addr.Host{}: true h: "::1", h.Type(): "IP", h.IP().Is4(): false h: "198.51.100.1", h.Type(): "IP", h.IP().Is4(): true h: "CS", h.Type(): "SVC", h.SVC().IsMulticast(): false has SvcCS: true, has SvcDS: false
func MustParseHost ¶ added in v0.9.0
MustParseHost calls ParseHost(s) and panics on error. It is intended for use in tests with hard-coded strings.
func ParseHost ¶ added in v0.9.0
ParseHost parses s as either a service address or an IP address, returning the result as a Host address. s can either be a SVC address, in the format supported by ParseSVC(s), or an IP address in dotted decimal or IPv6 format.
func (Host) IP ¶ added in v0.9.0
IP returns the IP address represented by h. Panics if h.Type() is not HostTypeIP.
func (Host) SVC ¶ added in v0.9.0
SVC returns the SVC address represented by h. Panics if h.Type() is not HostTypeSVC.
func (Host) Type ¶ added in v0.9.0
func (h Host) Type() HostAddrType
Type returns the type of the address represented by h.
type HostAddrType ¶
type HostAddrType uint8
HostAddrType discriminates between different types of Host addresses.
const ( HostTypeNone HostAddrType = iota HostTypeIP HostTypeSVC )
func (HostAddrType) String ¶
func (t HostAddrType) String() string
type IA ¶
type IA uint64
IA represents the ISD (ISolation Domain) and AS (Autonomous System) Id of a given SCION AS. The highest 16 bit form the ISD number and the lower 48 bits form the AS number.
func MustIAFrom ¶
MustIAFrom creates an IA from the ISD and AS number. It panics if any error is encountered. Callers must ensure that the values passed to this function are valid.
func MustParseIA ¶ added in v0.12.0
MustParseIA parses s and returns the corresponding addr.IA object. It panics if s is not a valid ISD-AS representation.
func ParseFormattedIA ¶
func ParseFormattedIA(ia string, opts ...FormatOption) (IA, error)
ParseFormattedIA parses an IA that was formatted with the FormatIA function. The same options must be provided to successfully parse.
func (IA) IsWildcard ¶
IsWildcard returns whether the ia has a wildcard part (isd or as).
func (IA) MarshalText ¶
func (*IA) UnmarshalText ¶
type ISD ¶
type ISD uint16
ISD is the ISolation Domain identifier. See formatting and allocations here: https://github.com/scionproto/scion/wiki/ISD-and-AS-numbering#isd-numbers
func MustParseISD ¶ added in v0.12.0
MustParseISD parses s and returns the corresponding addr.ISD object. It panics if s is not valid ISD representation.
func ParseFormattedISD ¶
func ParseFormattedISD(isd string, opts ...FormatOption) (ISD, error)
ParseFormattedISD parses an ISD number that was formatted with the FormatISD function. The same options must be provided to successfully parse.
type SVC ¶ added in v0.9.0
type SVC uint16
SVC is a SCION service address. A service address is a short identifier for the service type, and a flag-bit for multicast. The package's SVC constant values are defined without multicast. The Multicast and Base methods set/unset the multicast flag.
func ParseSVC ¶ added in v0.9.0
ParseSVC returns the SVC address corresponding to str. For anycast SVC addresses, use CS_A and DS_A; shorthand versions without the _A suffix (e.g., CS) also return anycast SVC addresses. For multicast, use CS_M, and DS_M.
func (SVC) BaseString ¶ added in v0.9.0
BaseString returns the upper case name of the service. For unrecognized services, it returns "<SVC:Hex-Value>".
func (SVC) IsMulticast ¶ added in v0.9.0
IsMulticast returns the value of the multicast flag.