addr

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

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 added in v0.7.0

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

FormatAS formats the AS number.

func FormatIA added in v0.7.0

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

FormatIA formats the ISD-AS.

func FormatISD added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.4.0

func (as AS) MarshalText() ([]byte, error)

func (AS) String

func (as AS) String() string

func (*AS) UnmarshalText added in v0.4.0

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

type FormatOption added in v0.7.0

type FormatOption func(*formatOptions)

func WithDefaultPrefix added in v0.7.0

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 added in v0.7.0

func WithFileSeparator() FormatOption

WithFileSeparator returns an option that sets the separator to underscore.

func WithSeparator added in v0.7.0

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 added in v0.3.1

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.6.0

func (h HostSVC) Network() string

func (HostSVC) Pack

func (h HostSVC) Pack() []byte

func (HostSVC) PackWithPad added in v0.6.0

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 added in v0.7.0

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

IAFrom creates an IA from the ISD and AS number.

func MustIAFrom added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

func ParseIA(ia string) (IA, error)

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

func (IA) AS added in v0.7.0

func (ia IA) AS() AS

func (IA) Equal added in v0.4.0

func (ia IA) Equal(other IA) bool

func (IA) ISD added in v0.7.0

func (ia IA) ISD() ISD

func (IA) IsWildcard added in v0.4.0

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 added in v0.4.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.4.0

func (isd ISD) String() string

Jump to

Keyboard shortcuts

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