addr

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: Apache-2.0 Imports: 8 Imported by: 19

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

View Source
const (
	HostLenNone = 0
	HostLenIPv4 = net.IPv4len
	HostLenIPv6 = net.IPv6len
	HostLenSVC  = 2
)
View Source
const (
	IABytes       = 8
	ISDBits       = 16
	ASBits        = 48
	BGPASBits     = 32
	MaxISD    ISD = (1 << ISDBits) - 1
	MaxAS     AS  = (1 << ASBits) - 1
	MaxBGPAS  AS  = (1 << BGPASBits) - 1
)

Variables

View Source
var (
	// ErrBadHostAddrType indicates an invalid host address type.
	ErrBadHostAddrType = serrors.New("unsupported host address type")
	// ErrMalformedHostAddrType indicates a malformed host address type.
	ErrMalformedHostAddrType = serrors.New("malformed host address type")
	// ErrUnsupportedSVCAddress indicates an unsupported SVC address.
	ErrUnsupportedSVCAddress = serrors.New("unsupported SVC address")
)

Functions

func FormatAS

func FormatAS(as AS, opts ...FormatOption) string

FormatAS formats the AS number.

func FormatIA

func FormatIA(ia IA, opts ...FormatOption) string

FormatIA formats the ISD-AS.

func FormatISD

func FormatISD(isd ISD, opts ...FormatOption) string

FormatISD formats the ISD number.

func HostLen

func HostLen(htype HostAddrType) (uint8, error)

func HostTypeCheck

func HostTypeCheck(t HostAddrType) bool

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 ParseAS

func ParseAS(as string) (AS, error)

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 AS) MarshalText() ([]byte, error)

func (AS) String

func (as AS) String() string

func (*AS) UnmarshalText

func (as *AS) UnmarshalText(text []byte) error

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 HostAddr

type HostAddr interface {
	Size() int
	Type() HostAddrType
	Pack() []byte
	IP() net.IP
	Copy() HostAddr
	Equal(HostAddr) bool
	fmt.Stringer
}

func HostFromIP

func HostFromIP(ip net.IP) HostAddr

func HostFromIPStr

func HostFromIPStr(s string) HostAddr

func HostFromRaw

func HostFromRaw(b []byte, htype HostAddrType) (HostAddr, error)

type HostAddrType

type HostAddrType uint8
const (
	HostTypeNone HostAddrType = iota
	HostTypeIPv4
	HostTypeIPv6
	HostTypeSVC
)

func (HostAddrType) String

func (t HostAddrType) String() string

type HostIPv4

type HostIPv4 net.IP

func (HostIPv4) Copy

func (h HostIPv4) Copy() HostAddr

func (HostIPv4) Equal

func (h HostIPv4) Equal(o HostAddr) bool

func (HostIPv4) IP

func (h HostIPv4) IP() net.IP

func (HostIPv4) Pack

func (h HostIPv4) Pack() []byte

func (HostIPv4) Size

func (h HostIPv4) Size() int

func (HostIPv4) String

func (h HostIPv4) String() string

func (HostIPv4) Type

func (h HostIPv4) Type() HostAddrType

type HostIPv6

type HostIPv6 net.IP

func (HostIPv6) Copy

func (h HostIPv6) Copy() HostAddr

func (HostIPv6) Equal

func (h HostIPv6) Equal(o HostAddr) bool

func (HostIPv6) IP

func (h HostIPv6) IP() net.IP

func (HostIPv6) Pack

func (h HostIPv6) Pack() []byte

func (HostIPv6) Size

func (h HostIPv6) Size() int

func (HostIPv6) String

func (h HostIPv6) String() string

func (HostIPv6) Type

func (h HostIPv6) Type() HostAddrType

type HostNone

type HostNone net.IP

func (HostNone) Copy

func (h HostNone) Copy() HostAddr

func (HostNone) Equal

func (h HostNone) Equal(o HostAddr) bool

func (HostNone) IP

func (h HostNone) IP() net.IP

func (HostNone) Pack

func (h HostNone) Pack() []byte

func (HostNone) Size

func (h HostNone) Size() int

func (HostNone) String

func (h HostNone) String() string

func (HostNone) Type

func (h HostNone) Type() HostAddrType

type HostSVC

type HostSVC uint16
const (
	SvcDS       HostSVC = 0x0001
	SvcCS       HostSVC = 0x0002
	SvcWildcard HostSVC = 0x0010
	SvcNone     HostSVC = 0xffff

	SVCMcast HostSVC = 0x8000
)

func HostSVCFromString

func HostSVCFromString(str string) HostSVC

HostSVCFromString returns the SVC address corresponding to str. For anycast SVC addresses, use BS_A, PS_A, CS_A, and SB_A; shorthand versions without the _A suffix (e.g., PS) also return anycast SVC addresses. For multicast, use BS_M, PS_M, CS_M, and SB_M.

func (HostSVC) Base

func (h HostSVC) Base() HostSVC

func (HostSVC) BaseString

func (h HostSVC) BaseString() string

BaseString returns the upper case name of the service. For hosts or unrecognized services, it returns UNKNOWN.

func (HostSVC) Copy

func (h HostSVC) Copy() HostAddr

func (HostSVC) Equal

func (h HostSVC) Equal(o HostAddr) bool

func (HostSVC) IP

func (h HostSVC) IP() net.IP

func (HostSVC) IsMulticast

func (h HostSVC) IsMulticast() bool

func (HostSVC) Multicast

func (h HostSVC) Multicast() HostSVC

func (HostSVC) Network

func (h HostSVC) Network() string

func (HostSVC) Pack

func (h HostSVC) Pack() []byte

func (HostSVC) PackWithPad

func (h HostSVC) PackWithPad(pad int) []byte

func (HostSVC) Size

func (h HostSVC) Size() int

func (HostSVC) String

func (h HostSVC) String() string

func (HostSVC) Type

func (h HostSVC) Type() HostAddrType

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 IAFrom

func IAFrom(isd ISD, as AS) (IA, error)

IAFrom creates an IA from the ISD and AS number.

func MustIAFrom

func MustIAFrom(isd ISD, as AS) IA

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 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 ParseIA

func ParseIA(ia string) (IA, error)

ParseIA parses an IA from a string of the format 'isd-as'.

func (IA) AS

func (ia IA) AS() AS

func (IA) Equal

func (ia IA) Equal(other IA) bool

func (IA) ISD

func (ia IA) ISD() ISD

func (IA) IsWildcard

func (ia IA) IsWildcard() bool

IsWildcard returns whether the ia has a wildcard part (isd or as).

func (IA) IsZero

func (ia IA) IsZero() bool

func (IA) MarshalText

func (ia IA) MarshalText() ([]byte, error)

func (*IA) Set

func (ia *IA) Set(s string) error

Set implements flag.Value interface

func (IA) String

func (ia IA) String() string

func (*IA) UnmarshalText

func (ia *IA) UnmarshalText(b []byte) error

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 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.

func ParseISD

func ParseISD(s string) (ISD, error)

ParseISD parses an ISD from a decimal string. Note that ISD 0 is parsed without any errors.

func (ISD) String

func (isd ISD) String() string

Jump to

Keyboard shortcuts

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