aurp

package
v0.0.0-...-545087f Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package aurp implements types for encoding and decoding AppleTalk Update-Based Routing Protocol (AURP, RFC 1504) messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inc

func Inc(p *uint16)

Inc increments a uint16. It avoids 0 (65535 + 1 = 1).

func ParsePacket

func ParsePacket(p []byte) (DomainHeader, Packet, error)

ParsePacket parses the body of a UDP packet for a domain header, and then based on the packet type, an AURP-Tr header, an AURP routing header, and then a particular packet type.

(This function contains the big switch statement.)

Types

type AppleTalkPacket

type AppleTalkPacket struct {
	DomainHeader // where PacketTypeAppleTalk

	Data []byte
}

AppleTalkPacket is for encapsulated AppleTalk traffic.

func (*AppleTalkPacket) WriteTo

func (p *AppleTalkPacket) WriteTo(w io.Writer) (int64, error)

type Authority

type Authority byte

Authority represents the different possible authorities ("types") for domain identifiers.

const (
	// AuthorityNull is for null domain identifiers, suitable only when there is
	// no need to distinguish the domains connected to a tunnel.
	AuthorityNull Authority = iota

	// AuthorityIP is for
	AuthorityIP
)

Various authorities.

type CmdCode

type CmdCode uint16

CmdCode is the command code used in AURP packets.

const (
	CmdCodeRIReq     CmdCode = 0x0001
	CmdCodeRIRsp     CmdCode = 0x0002
	CmdCodeRIAck     CmdCode = 0x0003
	CmdCodeRIUpd     CmdCode = 0x0004
	CmdCodeRD        CmdCode = 0x0005
	CmdCodeZoneReq   CmdCode = 0x0006 // has subcodes
	CmdCodeZoneRsp   CmdCode = 0x0007 // has subcodes
	CmdCodeOpenReq   CmdCode = 0x0008
	CmdCodeOpenRsp   CmdCode = 0x0009
	CmdCodeTickle    CmdCode = 0x000e
	CmdCodeTickleAck CmdCode = 0x000f
)

Various command codes.

type DomainHeader

type DomainHeader struct {
	DestinationDI DomainIdentifier
	SourceDI      DomainIdentifier
	Version       uint16     // Should always be 0x0001
	Reserved      uint16     // Should always be 0x0000
	PacketType    PacketType // 2 = AppleTalk data packet, 3 = AURP packet
}

DomainHeader represents the header used to encapsulate both AppleTalk data packets and AURP packets within UDP.

func ParseDomainHeader

func ParseDomainHeader(b []byte) (DomainHeader, []byte, error)

ParseDomainHeader parses a domain header, returning the DH and the remainder of the input slice. It does not validate the version or packet type fields.

func (*DomainHeader) WriteTo

func (dh *DomainHeader) WriteTo(w io.Writer) (int64, error)

WriteTo writes the encoded form of the domain header to w.

type DomainIdentifier

type DomainIdentifier interface {
	fmt.Stringer
	io.WriterTo
}

DomainIdentifier is the byte representation of a domain identifier.

type ErrorCode

type ErrorCode int16
const (
	ErrCodeNormalClose           ErrorCode = -1
	ErrCodeRoutingLoop           ErrorCode = -2
	ErrCodeOutOfSync             ErrorCode = -3
	ErrCodeOptionNegotiation     ErrorCode = -4
	ErrCodeInvalidVersion        ErrorCode = -5
	ErrCodeInsufficientResources ErrorCode = -6
	ErrCodeAuthentication        ErrorCode = -7
)

Various error codes.

func (ErrorCode) String

func (e ErrorCode) String() string

type EventCode

type EventCode uint8
const (
	// Null event
	EventCodeNull EventCode = 0

	// Network added event
	EventCodeNA EventCode = 1

	// Network deleted event
	EventCodeND EventCode = 2

	// Network route change event
	EventCodeNRC EventCode = 3

	// Network distance change event
	EventCodeNDC EventCode = 4

	// Network zone change event
	// Note: "The ZC event tuple is not yet defined."
	EventCodeZC EventCode = 5
)

func (EventCode) String

func (ec EventCode) String() string

type EventTuple

type EventTuple struct {
	EventCode  EventCode
	Extended   bool
	RangeStart ddp.Network
	Distance   uint8
	RangeEnd   ddp.Network
}

func (*EventTuple) WriteTo

func (et *EventTuple) WriteTo(w io.Writer) (int64, error)

type EventTuples

type EventTuples []EventTuple

func (EventTuples) WriteTo

func (e EventTuples) WriteTo(w io.Writer) (int64, error)

type GDZLReqPacket

type GDZLReqPacket struct {
	Header
	Subcode
	StartIndex uint16
}

func (*GDZLReqPacket) WriteTo

func (p *GDZLReqPacket) WriteTo(w io.Writer) (int64, error)

type GDZLRspPacket

type GDZLRspPacket struct {
	Header
	Subcode
	StartIndex int16
	ZoneNames  []string
}

func (*GDZLRspPacket) WriteTo

func (p *GDZLRspPacket) WriteTo(w io.Writer) (int64, error)

type GZNReqPacket

type GZNReqPacket struct {
	Header
	Subcode
	ZoneName string
}

func (*GZNReqPacket) WriteTo

func (p *GZNReqPacket) WriteTo(w io.Writer) (int64, error)

type GZNRspPacket

type GZNRspPacket struct {
	Header
	Subcode
	ZoneName     string
	NotSupported bool
	Networks     NetworkTuples
}

func (*GZNRspPacket) WriteTo

func (p *GZNRspPacket) WriteTo(w io.Writer) (int64, error)
type Header struct {
	TrHeader

	CommandCode CmdCode
	Flags       RoutingFlag
}

Header represents an AURP packet header. It includes the AURP-Tr header, which includes the domain header.

func (*Header) WriteTo

func (h *Header) WriteTo(w io.Writer) (int64, error)

WriteTo writes the encoded form of the header to w.

type IPDomainIdentifier

type IPDomainIdentifier net.IP

IPDomainIdentifier represents an IP address in a domain identifier.

func (IPDomainIdentifier) String

func (i IPDomainIdentifier) String() string

func (IPDomainIdentifier) WriteTo

func (i IPDomainIdentifier) WriteTo(w io.Writer) (int64, error)

WriteTo writes the encoded form of the domain identifier to w.

type NetworkTuple

type NetworkTuple struct {
	Extended   bool
	RangeStart ddp.Network
	Distance   uint8
	RangeEnd   ddp.Network
}

func (*NetworkTuple) WriteTo

func (nt *NetworkTuple) WriteTo(w io.Writer) (int64, error)

type NetworkTuples

type NetworkTuples []NetworkTuple

func (NetworkTuples) String

func (n NetworkTuples) String() string

func (NetworkTuples) WriteTo

func (n NetworkTuples) WriteTo(w io.Writer) (int64, error)

type NullDomainIdentifier

type NullDomainIdentifier struct{}

NullDomainIdentifier represents a null domain identifier.

func (NullDomainIdentifier) String

func (NullDomainIdentifier) String() string

func (NullDomainIdentifier) WriteTo

func (NullDomainIdentifier) WriteTo(w io.Writer) (int64, error)

WriteTo writes the encoded form of the domain identifier to w.

type OpenReqPacket

type OpenReqPacket struct {
	Header

	Version uint16 // currently always 1
	Options Options
}

OpenReq is used to open a one-way connection between AIRs.

func (*OpenReqPacket) WriteTo

func (p *OpenReqPacket) WriteTo(w io.Writer) (int64, error)

type OpenRspPacket

type OpenRspPacket struct {
	Header

	RateOrErrCode int16
	Options       Options
}

OpenRsp is used to respond to Open-Req.

func (*OpenRspPacket) WriteTo

func (p *OpenRspPacket) WriteTo(w io.Writer) (int64, error)

type OptionTuple

type OptionTuple struct {
	// Length uint8 = 1(for Type) + len(Data)
	Type OptionType
	Data []byte
}

OptionTuple is used to pass option information in Open-Req and Open-Rsp packets.

func (*OptionTuple) WriteTo

func (ot *OptionTuple) WriteTo(w io.Writer) (int64, error)

type OptionType

type OptionType uint8

OptionType is used to distinguish different options.

const (
	OptionTypeAuthentication OptionType = 0x01
)

Various option types

type Options

type Options []OptionTuple

func (Options) WriteTo

func (o Options) WriteTo(w io.Writer) (int64, error)

type Packet

type Packet interface {
	io.WriterTo
}

Packet represents a full AURP packet, not including UDP or lower layers, but including the domain header and higher layers.

type PacketType

type PacketType uint16

PacketType is used to distinguish domain-header encapsulated packets.

const (
	PacketTypeAppleTalk PacketType = 0x0002
	PacketTypeRouting   PacketType = 0x0003
)

Various packet types.

type RDPacket

type RDPacket struct {
	Header

	ErrorCode ErrorCode
}

func (*RDPacket) WriteTo

func (p *RDPacket) WriteTo(w io.Writer) (int64, error)

type RIAckPacket

type RIAckPacket struct {
	Header
}

type RIReqPacket

type RIReqPacket struct {
	Header
}

type RIRspPacket

type RIRspPacket struct {
	Header

	Networks NetworkTuples
}

func (*RIRspPacket) WriteTo

func (p *RIRspPacket) WriteTo(w io.Writer) (int64, error)

type RIUpdPacket

type RIUpdPacket struct {
	Header

	Events EventTuples
}

func (*RIUpdPacket) WriteTo

func (p *RIUpdPacket) WriteTo(w io.Writer) (int64, error)

type RoutingFlag

type RoutingFlag uint16

RoutingFlag is used in the flags field

const (
	// Open-Req and RI-Req (SUI flags)
	RoutingFlagSUINA      RoutingFlag = 0x4000
	RoutingFlagSUINDOrNRC RoutingFlag = 0x2000
	RoutingFlagSUINDC     RoutingFlag = 0x1000
	RoutingFlagSUIZC      RoutingFlag = 0x0800

	// The combination of the above four flags (the SUI flags).
	RoutingFlagAllSUI RoutingFlag = 0x7800

	// RI-Rsp and GDZL-Rsp
	RoutingFlagLast RoutingFlag = 0x8000

	// Open-Rsp (environment flags)
	RoutingFlagRemappingActive   RoutingFlag = 0x4000
	RoutingFlagHopCountReduction RoutingFlag = 0x2000
	RoutingFlagReservedEnv       RoutingFlag = 0x1800

	// RI-Ack
	RoutingFlagSendZoneInfo RoutingFlag = 0x4000
)

type Subcode

type Subcode uint16

Subcode is used to distinguish types of zone request/response.

const (
	SubcodeZoneInfoReq       Subcode = 0x0001
	SubcodeZoneInfoNonExt    Subcode = 0x0001
	SubcodeZoneInfoExt       Subcode = 0x0002
	SubcodeGetZonesNet       Subcode = 0x0003
	SubcodeGetDomainZoneList Subcode = 0x0004
)

Various subcodes.

type TickleAckPacket

type TickleAckPacket struct {
	Header
}

type TicklePacket

type TicklePacket struct {
	Header
}

type TrHeader

type TrHeader struct {
	DomainHeader

	ConnectionID uint16
	Sequence     uint16
}

TrHeader represent an AURP-Tr packet header. It includes the domain header.

func (*TrHeader) WriteTo

func (h *TrHeader) WriteTo(w io.Writer) (int64, error)

WriteTo writes the encoded form of the header to w, including the domain header.

type Transport

type Transport struct {
	// LocalDI and RemoteDI are used for producing packets.
	// When sending a packet, we use LocalDI as SourceDI and RemoteDI as
	// DestinationDI.
	// (When receiving a packet, we expect to see LocalDI as DestinationDI
	// - but it might not be - and we expect to see RemoteDI as SourceDI.)
	LocalDI, RemoteDI DomainIdentifier

	// LocalConnID is used for packets sent in the role of data receiver.
	// RemoteConnID is used for packets sent in the role of data sender.
	LocalConnID, RemoteConnID uint16

	// LocalSeq is used for packets sent (as data sender)
	// RemoteSeq is used to check packets received (remote is the data sender).
	LocalSeq, RemoteSeq uint16
}

Transport tracks local and remote domain identifiers, connection IDs, and sequence numbers for use in a pair of one-way connections.

func (*Transport) NewAppleTalkPacket

func (tr *Transport) NewAppleTalkPacket(data []byte) *AppleTalkPacket

NewAppleTalkPacket returns a new AppleTalkPacket.

func (*Transport) NewGDZLReqPacket

func (tr *Transport) NewGDZLReqPacket(startIdx uint16) *GDZLReqPacket

NewGDZLReqPacket returns a new GDZL-Req packet structure.

func (*Transport) NewGDZLRspPacket

func (tr *Transport) NewGDZLRspPacket(startIdx int16, zoneNames []string) *GDZLRspPacket

NewGZNRspPacket returns a new GDZL-Rsp packet structure. If GDZL function is not supported, startIdx should be set to -1.

func (*Transport) NewGZNReqPacket

func (tr *Transport) NewGZNReqPacket(zoneName string) *GZNReqPacket

NewGZNReqPacket returns a new GZN-Req packet structure requesting nets for a given zone name.

func (*Transport) NewGZNRspPacket

func (tr *Transport) NewGZNRspPacket(zoneName string, notSupported bool, nets NetworkTuples) *GZNRspPacket

NewGZNRspPacket returns a new GZN-Rsp packet structure.

func (*Transport) NewOpenReqPacket

func (tr *Transport) NewOpenReqPacket(opts Options) *OpenReqPacket

NewOpenReqPacket returns a new Open-Req packet structure. By default it sets all SUI flags and uses version 1.

func (*Transport) NewOpenRspPacket

func (tr *Transport) NewOpenRspPacket(envFlags RoutingFlag, rateOrErr int16, opts Options) *OpenRspPacket

NewOpenRspPacket returns a new Open-Rsp packet structure.

func (*Transport) NewRDPacket

func (tr *Transport) NewRDPacket(errCode ErrorCode) *RDPacket

NewRDPacket returns a new RD packet structure.

func (*Transport) NewRIAckPacket

func (tr *Transport) NewRIAckPacket(connID, seq uint16, szi RoutingFlag) *RIAckPacket

NewRIAckPacket returns a new RI-Ack packet structure.

func (*Transport) NewRIReqPacket

func (tr *Transport) NewRIReqPacket() *RIReqPacket

NewRIReqPacket returns a new RI-Req packet structure. By default it sets all SUI flags.

func (*Transport) NewRIRspPacket

func (tr *Transport) NewRIRspPacket(last RoutingFlag, nets NetworkTuples) *RIRspPacket

NewRIRspPacket returs a new RI-Rsp packet structure.

func (*Transport) NewRIUpdPacket

func (tr *Transport) NewRIUpdPacket(events EventTuples) *RIUpdPacket

NewRIUpdPacket returns a new RI-Upd packet structure.

func (*Transport) NewTickleAckPacket

func (tr *Transport) NewTickleAckPacket() *TickleAckPacket

NewTickleAckPacket returns a new Tickle-Ack packet.

func (*Transport) NewTicklePacket

func (tr *Transport) NewTicklePacket() *TicklePacket

NewTicklePacket returns a new Tickle packet structure.

func (*Transport) NewZIRspPacket

func (tr *Transport) NewZIRspPacket(zoneLists map[ddp.Network][]string) *ZIRspPacket

NewZIRspPacket returns a new ZI-Rsp packet structure containing the given zone information. It automatically chooses between subcodes 1 or 2 depending on whether there is one network ID or more than one network ID.

type ZIReqPacket

type ZIReqPacket struct {
	Header
	Subcode
	Networks []ddp.Network
}

func (*ZIReqPacket) WriteTo

func (p *ZIReqPacket) WriteTo(w io.Writer) (int64, error)

type ZIRspPacket

type ZIRspPacket struct {
	Header
	Subcode
	Zones ZoneTuples
}

ZIRspPacket represents a ZI-Rsp: a response packet to a ZI-Req.

"When the data sender receives a ZI-Req and the zone list for the network or networks for which that ZI-Req requested zone information fits in one ZI-Rsp packet, it sends a nonextended ZI-Rsp." "When the data sender receives a ZI-Req and the zone list for a network about which that ZI-Req requested zone information does not fit in a single ZI-Rsp packet, it sends a sequence of extended ZI-Rsp packets." "All tuples in a single extended ZI-Rsp packet must contain the same network number" "Duplicate zone names never exist in extended ZI-Rsp packets"

func (*ZIRspPacket) WriteTo

func (p *ZIRspPacket) WriteTo(w io.Writer) (int64, error)

type ZoneTuple

type ZoneTuple struct {
	Network ddp.Network
	Name    string
}

type ZoneTuples

type ZoneTuples []ZoneTuple

func (ZoneTuples) String

func (zs ZoneTuples) String() string

func (ZoneTuples) WriteTo

func (zs ZoneTuples) WriteTo(w io.Writer) (int64, error)

Jump to

Keyboard shortcuts

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