registration

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNoPublicAddress    common.ErrMsg = "no public address"
	ErrBindWithoutSvc     common.ErrMsg = "bind address without svc address"
	ErrOverlappingAddress common.ErrMsg = "overlapping address"
	ErrNoValue            common.ErrMsg = "nil value"
	ErrZeroIP             common.ErrMsg = "zero address"
	ErrZeroPort           common.ErrMsg = "zero port"
	ErrNilAddress         common.ErrMsg = "nil address"
	ErrSvcNone            common.ErrMsg = "svc none"
	ErrNoPorts            common.ErrMsg = "no free ports"
)
View Source
const (
	ErrBadISD common.ErrMsg = "0 is not valid ISD"
	ErrBadAS  common.ErrMsg = "0 is not valid AS"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IATable

type IATable interface {
	// Register a new entry for AS ia with the specified public, bind and
	// services addresses and associate a value with the entry. Lookup calls
	// for matching addresses will return the associated value.
	//
	// A LookupPublic call will select an entry with a matching public address.
	// For IPv4, this is either a perfect match or a 0.0.0.0 entry. For IPv6,
	// this is either a perfect match or a :: entry. If the public address to
	// register matches an existing entry, an error is returned. Using port 0
	// for the public address will allocate a valid port.
	//
	// A LookupService call will select an entry with matching bind and service
	// addresses. Binds for 0.0.0.0 or :: are not allowed. The port is
	// inherited from the public address. To not register for a service, use a
	// bind of nil and a svc of none. For more information about SVC behavior,
	// see the documentation for SVCTable.
	//
	// To unregister from the table, free the returned reference.
	Register(ia addr.IA, public *net.UDPAddr, bind net.IP, svc addr.HostSVC,
		value interface{}) (RegReference, error)
	// LookupPublic returns the value associated with the selected public
	// address. Wildcard addresses are supported. If an entry is found, the
	// returned boolean is set to true. Otherwise, it is set to false.
	LookupPublic(ia addr.IA, public *net.UDPAddr) (interface{}, bool)
	// LookupService returns the entries associated with svc and bind.
	//
	// If SVC is an anycast address, at most one entry is returned. The bind
	// address is used to narrow down the set of possible entries. If multiple
	// entries exist, one is selected arbitrarily.
	//
	// Note that nil bind addresses are supported for anycasts (the address is
	// in this case ignored), but support for this might be dropped in the
	// future.
	//
	// If SVC is a multicast address, more than one entry can be returned. The
	// bind address is ignored in this case.
	LookupService(ia addr.IA, svc addr.HostSVC, bind net.IP) []interface{}
	// LookupID returns the entry associated with the SCMP General class ID id.
	// The ID is used for SCMP Echo, TraceRoute, and RecordPath functionality.
	// If an entry is found, the returned boolean is set to true. Otherwise, it
	// is set to false.
	LookupID(ia addr.IA, id uint64) (interface{}, bool)
}

IATable manages the UDP/IP port registrations for a SCION Dispatcher.

IATable is safe for concurrent use from multiple goroutines.

func NewIATable

func NewIATable(minPort, maxPort int) IATable

NewIATable creates a new UDP/IP port registration table.

If the public address in a registration contains the port 0, a free port is allocated between minPort and maxPort.

If minPort is <= 0 or maxPort is > 65535, the function panics.

type IPTable

type IPTable map[string]interface{}

IPTable maps string representations of IP addresses to arbitrary values.

func (IPTable) OverlapsWith

func (t IPTable) OverlapsWith(ip net.IP) bool

OverlapsWith returns true if ip overlaps with any entry in t. For example, 0.0.0.0 would overlap with any other IPv4 address.

func (IPTable) Route

func (t IPTable) Route(ip net.IP) (interface{}, bool)

Route returns the object associated with destination ip.

This can either be an entry matching argument ip exactly, or a zero IP address.

type Reference

type Reference interface {
	// Free removes the object from its parent collection, cleaning up any allocations.
	Free()
}

Reference tracks an object from a collection.

type RegReference

type RegReference interface {
	Reference
	// UDPAddr returns the UDP address associated with this reference
	UDPAddr() *net.UDPAddr
	// SVCAddr returns the SVC address associated with this reference. If no
	// SVC address is associated, it returns SvcNone.
	SVCAddr() addr.HostSVC
	// RegisterID attaches an SCMP ID to this reference. The ID is released
	// when the reference is freed. Registering another ID does not overwrite
	// the previous; instead, multiple IDs get associated with the reference.
	// SCMP messages targeted at the ID will get sent to the socket associated
	// with the reference. The IA of the id is set to the IA of the reference.
	RegisterID(id uint64) error
}

type SCMPTable

type SCMPTable struct {
	// contains filtered or unexported fields
}

SCMPTable tracks SCMP General class IDs.

Attempting to register the same ID more than once will return an error.

func NewSCMPTable

func NewSCMPTable() *SCMPTable

func (*SCMPTable) Lookup

func (t *SCMPTable) Lookup(id uint64) (interface{}, bool)

func (*SCMPTable) Register

func (t *SCMPTable) Register(id uint64, value interface{}) error

func (*SCMPTable) Remove

func (t *SCMPTable) Remove(id uint64)

type SVCTable

type SVCTable interface {
	// Register adds a new entry for the select svc, IP address and port. Both
	// IPv4 and IPv6 are supported. IP addresses 0.0.0.0 and :: are not
	// supported. Port must not be 0.
	//
	// If an entry for the same svc, IP address and port exists, an error is
	// returned and the reference is nil.
	//
	// To clean up resources, call Free on the returned Reference. Calling Free
	// more than once will cause a panic.
	Register(svc addr.HostSVC, address *net.UDPAddr, value interface{}) (Reference, error)
	// Lookup returns the entries associated with svc and ip.
	//
	// If SVC is an anycast address, at most one entry is returned. The ip
	// address is used in case to narrow down the set of possible entries. If
	// multiple entries exist, one is selected arbitrarily.
	//
	// Note that nil addresses are supported for anycasts (the address is then
	// ignored), but support for this might be dropped in the future.
	//
	// If SVC is a multicast address, more than one entry can be returned. The
	// ip address is ignored in this case.
	Lookup(svc addr.HostSVC, ip net.IP) []interface{}
	String() string
}

SVCTable tracks SVC registrations.

Entries are hierarchical, and conceptually look like the following:

SVC CS:
  10.2.3.4
    :10080
    :10081
  192.0.2.1
    :20000
SVC PS:
  192.0.2.2
    :20001
  2001:db8::1
    :30001
    :30002

Call Register to add a new entry to the table. The IP and port are taken from the UDP address. IP must not be zero (so binding to multiple interfaces is not supported), and port must not be zero.

Anycasting to a local application requires the service type (e.g., CS) and the IP. This is because for SCION, the IP is selected remotely by the border router. The local dispatcher then anycasts between all local ports listening on that IP.

For example, in the table above, anycasting to CS-10.2.3.4 can either go to entry 10.2.3.4:10080 or 10.2.3.4:10081. Anycasts are chosen in round-robin fashion; the round-robin distribution is not strict, and can get skewed due to registrations and frees.

func NewSVCTable

func NewSVCTable() SVCTable

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table manages the UDP/IP port registrations for a single AS.

Table is not safe for concurrent use from multiple goroutines.

func NewTable

func NewTable(minPort, maxPort int) *Table

func (*Table) LookupID

func (t *Table) LookupID(id uint64) (interface{}, bool)

func (*Table) LookupPublic

func (t *Table) LookupPublic(address *net.UDPAddr) (interface{}, bool)

func (*Table) LookupService

func (t *Table) LookupService(svc addr.HostSVC, bind net.IP) []interface{}

func (*Table) Register

func (t *Table) Register(public *net.UDPAddr, bind net.IP, svc addr.HostSVC,
	value interface{}) (*TableReference, error)

func (*Table) Size

func (t *Table) Size() int

type TableReference

type TableReference struct {
	// contains filtered or unexported fields
}

func (*TableReference) Free

func (r *TableReference) Free()

func (*TableReference) RegisterID

func (r *TableReference) RegisterID(id uint64, value interface{}) error

func (*TableReference) UDPAddr

func (r *TableReference) UDPAddr() *net.UDPAddr

type UDPPortAllocator

type UDPPortAllocator struct {
	// contains filtered or unexported fields
}

UDPPortAllocator attempts to find a free port between a min port and a max port in an allocation table. Attempts wrap around when they reach max port.

If no port is available, the allocation function panics.

func NewUDPPortAllocator

func NewUDPPortAllocator(min, max int) *UDPPortAllocator

NewUDPPortAllocator returns an allocation. The function panics if min > max, or if min or max is not a valid port number.

func (*UDPPortAllocator) Allocate

func (a *UDPPortAllocator) Allocate(ip net.IP, t *UDPPortTable) (int, error)

Allocate returns the next available port for the IP address. It will panic if it runs out of ports.

type UDPPortTable

type UDPPortTable struct {
	// contains filtered or unexported fields
}

UDPPortTable stores port allocations for UDP/IPv4 and UDP/IPv6 sockets.

Additionally, it allocates ports dynamically if the requested port is 0.

func NewUDPPortTable

func NewUDPPortTable(minPort, maxPort int) *UDPPortTable

func NewUDPPortTableFromMap

func NewUDPPortTableFromMap(minPort, maxPort int, v4, v6 map[int]IPTable) *UDPPortTable

func (*UDPPortTable) Insert

func (t *UDPPortTable) Insert(address *net.UDPAddr, value interface{}) (*net.UDPAddr, error)

Insert adds address into the allocation table. It will return an error if an entry overlaps, or if the value is nil.

func (*UDPPortTable) Lookup

func (t *UDPPortTable) Lookup(address *net.UDPAddr) (interface{}, bool)

func (*UDPPortTable) Remove

func (t *UDPPortTable) Remove(address *net.UDPAddr)

Jump to

Keyboard shortcuts

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