diameter

package module
v0.0.0-...-565f580 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 11 Imported by: 3

README

diameter

RFC6733 implementation by golang

License

MIT

Documentation

Index

Constants

View Source
const (
	MultiRoundAuth uint32 = 1001 // MultiRoundAuth is Result-Code 1001

	Success        uint32 = 2001 // Success is Result-Code 2001
	LimitedSuccess uint32 = 2002 // LimitedSuccess is Result-Code 2002

	CommandUnspported      uint32 = 3001 // CommandUnspported is Result-Code 3001
	UnableToDeliver        uint32 = 3002 // UnableToDeliver is Result-Code 3002
	RealmNotServed         uint32 = 3003 // RealmNotServed is Result-Code 3003
	TooBusy                uint32 = 3004 // TooBusy is Result-Code 3004
	LoopDetected           uint32 = 3005 // LoopDetected is Result-Code 3005
	RedirectIndication     uint32 = 3006 // RedirectIndication is Result-Code 3006
	ApplicationUnsupported uint32 = 3007 // ApplicationUnsupported is Result-Code 3007
	InvalidHdrBits         uint32 = 3008 // InvalidHdrBits is Result-Code 3008
	InvalidAvpBits         uint32 = 3009 // InvalidAvpBits is Result-Code 3009
	UnknownPeer            uint32 = 3010 // UnknownPeer is Result-Code 3010

	AuthenticationRejected uint32 = 4001 // AuthenticationRejected is Result-Code 4001
	OutOfSpace             uint32 = 4002 // OutOfSpace is Result-Code 4002
	ElectionLost           uint32 = 4003 // ElectionLost is Result-Code 4003

	AvpUnsupported        uint32 = 5001 // AvpUnsupported is Result-Code 5001
	UnknownSessionID      uint32 = 5002 // UnknownSessionID is Result-Code 5002
	AuthorizationRejected uint32 = 5003 // AuthorizationRejected is Result-Code 5003
	InvalidAvpValue       uint32 = 5004 // InvalidAvpValue is Result-Code 5004
	MissingAvp            uint32 = 5005 // MissingAvp is Result-Code 5005
	ResourcesExceeded     uint32 = 5006 // ResourcesExceeded is Result-Code 5006
	ContradictingAvps     uint32 = 5007 // ContradictingAvps is Result-Code 5007
	AvpNotAllowed         uint32 = 5008 // AvpNotAllowed is Result-Code 5008
	AvpOccursTooManyTimes uint32 = 5009 // AvpOccursTooManyTimes is Result-Code 5009
	NoCommonApplication   uint32 = 5010 // NoCommonApplication is Result-Code 5010
	UnsupportedVersion    uint32 = 5011 // UnsupportedVersion is Result-Code 5011
	UnableToComply        uint32 = 5012 // UnableToComply is Result-Code 5012
	InvalidBitInHeader    uint32 = 5013 // InvalidBitInHeader is Result-Code 5013
	InvalidAvpLength      uint32 = 5014 // InvalidAvpLength is Result-Code 5014
	InvalidMessageLength  uint32 = 5015 // InvalidMessageLength is Result-Code 5015
	InvalidAvpBitCombo    uint32 = 5016 // InvalidAvpBitCombo is Result-Code 5016
	NoCommonSecurity      uint32 = 5017 // NoCommonSecurity is Result-Code 5017
)
View Source
const (
	VendorID    uint32 = 41102         // VendorID of this code
	ProductName        = "round-robin" // ProductName of this code
	FirmwareRev uint32 = 230619001     // FirmwareRev of this code

)

Variables

View Source
var (
	WDInterval = time.Second * 30 // WDInterval is watchdog send interval time
	WDMaxSend  = 3                // WDMaxSend is watchdog expired count

	Host  Identity // Local diameter hostname
	Realm Identity // Local diameter realm

	OverwriteAddr []net.IP // Overwrite IP addresses of local host in CER

)
View Source
var (
	// TraceMessage is called when Diameter message is receved or sent.
	// Inputs are handled message, message direction and occured error while message handling.
	TraceMessage func(Message, Direction, error)

	// TraceEvent is called on event.
	// Inputs are old state, new state, event name and occured error while event handling.
	TraceEvent func(string, string, string, error)

	// ConnectionUpNotify is called when Diameter connection up.
	ConnectionUpNotify func(*Connection)

	// ConnectionDownNotify is called when Diameter connection down.
	ConnectionDownNotify func(*Connection)

	// ConnectionAbortNotify is called when Diameter connection abort.
	ConnectionAbortNotify func(*Connection)
)
View Source
var (
	// Statistics values
	RxReq     uint64
	RejectReq uint64
	TxAnsFail uint64
	Tx1xxx    uint64
	Tx2xxx    uint64
	Tx3xxx    uint64
	Tx4xxx    uint64
	Tx5xxx    uint64
	TxEtc     uint64

	TxReq      uint64
	InvalidAns uint64
	Rx1xxx     uint64
	Rx2xxx     uint64
	Rx3xxx     uint64
	Rx4xxx     uint64
	Rx5xxx     uint64
	RxEtc      uint64
)
View Source
var DefaultRxHandler func(Message) Message = func(m Message) Message {
	return m.generateAnswerBy(UnableToDeliver)
}

DefaultRxHandler for receiving Diameter request message without Handler or ralay application.

Functions

func CountRxCode

func CountRxCode(c uint32)

func CountTxCode

func CountTxCode(c uint32)

func GetAuthAppID

func GetAuthAppID(a AVP) (v uint32, e error)

GetAuthAppID read Auth-Application-Id AVP

func GetAuthSessionState

func GetAuthSessionState(a AVP) (v bool, e error)

GetAuthSessionState read Auth-Session-State AVP

func GetErrorMessage

func GetErrorMessage(a AVP) (v string, e error)

GetErrorMessage read Error-Message AVP

func GetResultCode

func GetResultCode(a AVP) (c uint32, e error)

GetResultCode read Result-Code AVP

func GetSessionID

func GetSessionID(a AVP) (v string, e error)

GetSessionID read Session-ID AVP

func GetUserName

func GetUserName(a AVP) (v string, e error)

GetUserName read User-Name AVP

func GetVendorID

func GetVendorID(a AVP) (v uint32, e error)

GetVendorID read Vendor-Id AVP

func GetVendorSpecAppID

func GetVendorSpecAppID(a AVP) (vi, ai uint32, e error)

GetVendorSpecAppID read Vendor-Specific-Application-Id AVP

func NextSession

func NextSession(h string) string

NextSession generate new session ID data

Types

type AVP

type AVP struct {
	Code      uint32 // AVP Code
	VendorID  uint32 // Vendor-ID
	Mandatory bool   // Mandatory AVP Flag
	// Protected bool // Protected AVP Flag
	Data []byte // AVP Data
}

AVP data and header

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           AVP Code                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V M P r r r r r|                  AVP Length                   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Vendor-ID (opt)                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Data ...
+-+-+-+-+-+-+-+-+

func GetFailedAVP

func GetFailedAVP(a AVP) (v []AVP, e error)

GetFailedAVP read Failed-AVP AVP

func SetAuthAppID

func SetAuthAppID(v uint32) (a AVP)

SetAuthAppID make Auth-Application-Id AVP

func SetAuthSessionState

func SetAuthSessionState(v bool) (a AVP)

SetAuthSessionState make Auth-Session-State AVP

func SetDestinationHost

func SetDestinationHost(v Identity) (a AVP)

SetDestinationHost make Destination-Host AVP

func SetDestinationRealm

func SetDestinationRealm(v Identity) (a AVP)

SetDestinationRealm make Destination-Realm AVP

func SetErrorMessage

func SetErrorMessage(v string) (a AVP)

SetErrorMessage make Error-Message AVP

func SetFailedAVP

func SetFailedAVP(v []AVP) (a AVP)

SetFailedAVP make Failed-AVP AVP

func SetGenericAVP

func SetGenericAVP(c, v uint32, m bool, b interface{}) AVP

func SetOriginHost

func SetOriginHost(v Identity) (a AVP)

SetOriginHost make Origin-Host AVP

func SetOriginRealm

func SetOriginRealm(v Identity) (a AVP)

SetOriginRealm make Origin-Realm AVP

func SetResultCode

func SetResultCode(c uint32) (a AVP)

SetResultCode make Result-Code AVP

func SetRouteRecord

func SetRouteRecord(v Identity) (a AVP)

SetRouteRecord make Route-Record AVP

func SetSessionID

func SetSessionID(v string) (a AVP)

SetSessionID make Session-ID AVP

func SetUserName

func SetUserName(v string) (a AVP)

SetUserName make User-Name AVP

func SetVendorID

func SetVendorID(v uint32) (a AVP)

SetVendorID make Vendor-Id AVP

func SetVendorSpecAppID

func SetVendorSpecAppID(vi, ai uint32) (a AVP)

SetVendorSpecAppID make Vendor-Specific-Application-Id AVP

func (AVP) Decode

func (a AVP) Decode(d interface{}) (e error)

Decode make primitive go value from AVP

func (*AVP) Encode

func (a *AVP) Encode(d interface{}) (e error)

Encode make AVP from primitive go value

func (AVP) MarshalTo

func (a AVP) MarshalTo(w io.Writer) error

MarshalTo wite binary data to io.Writer

func (AVP) String

func (a AVP) String() string

func (*AVP) UnmarshalFrom

func (a *AVP) UnmarshalFrom(r io.Reader) error

UnmarshalFrom read binary data from io.Reader

type Connection

type Connection struct {
	Host  Identity // Peer diameter hostname
	Realm Identity // Peer diameter realm
	// contains filtered or unexported fields
}

func (*Connection) Close

func (c *Connection) Close(cause Enumerated)

Close Diameter connection and stop state machine.

func (*Connection) DefaultTxHandler

func (c *Connection) DefaultTxHandler(m Message) Message

DefaultTxHandler for sending Diameter request message without Handler or relay application.

func (*Connection) DialAndServe

func (c *Connection) DialAndServe(con net.Conn) (e error)

func (*Connection) ListenAndServe

func (c *Connection) ListenAndServe(con net.Conn) (e error)

func (*Connection) LocalAddr

func (c *Connection) LocalAddr() net.Addr

LocalAddr returns transport connection of state machine

func (*Connection) PeerAddr

func (c *Connection) PeerAddr() net.Addr

PeerAddr returns transport connection of state machine

func (*Connection) RxQueue

func (c *Connection) RxQueue() int

RxQueue returns length of Rx queue

func (*Connection) State

func (c *Connection) State() string

State returns state machine state

func (*Connection) TxQueue

func (c *Connection) TxQueue() int

TxQueue returns length of Tx queue

type Direction

type Direction bool

Direction of Diameter message. Tx or Rx.

const (
	Tx Direction = true
	Rx Direction = false
)

func (Direction) String

func (v Direction) String() string

type Enumerated

type Enumerated int32

Enumerated is Enumerated format AVP value.

const (
	// Rebooting is Enumerated value 0
	Rebooting Enumerated = 0
	// Busy is Enumerated value 1
	Busy Enumerated = 1
	// DoNotWantToTalkToYou is Enumerated value 2
	DoNotWantToTalkToYou Enumerated = 2
)

type FailureAnswer

type FailureAnswer struct {
	Code   uint32
	VenID  uint32
	ErrMsg string
	Avps   []AVP
}

FailureAnswer is error response from peer.

func (FailureAnswer) Error

func (e FailureAnswer) Error() string

type Handler

type Handler func(bool, []AVP) (bool, []AVP)

Handler handles Diameter message. Inputs are Retry flag and AVPs of Request. Outputs are Error flag and AVPs of Answer.

func Handle

func Handle(code, appID, venID uint32, h Handler, rt Router) Handler

Handle registers Diameter request handler for specified command. Input Handler is called when when request is from peer. Output Handler is used when send request to peer.

type IPFilterRule

type IPFilterRule string

IPFilterRule is IP Filter Rule format AVP value.

type Identity

type Identity string

Identity is identity of Diameter protocol

func GetDestinationHost

func GetDestinationHost(a AVP) (v Identity, e error)

GetDestinationHost read Destination-Host AVP

func GetDestinationRealm

func GetDestinationRealm(a AVP) (v Identity, e error)

GetDestinationRealm read Destination-Realm AVP

func GetOriginHost

func GetOriginHost(a AVP) (v Identity, e error)

GetOriginHost read Origin-Host AVP

func GetOriginRealm

func GetOriginRealm(a AVP) (v Identity, e error)

GetOriginRealm read Origin-Realm AVP

func GetRouteRecord

func GetRouteRecord(a AVP) (v Identity, e error)

GetRouteRecord read Route-Record AVP

func ParseIdentity

func ParseIdentity(str string) (id Identity, err error)

ParseIdentity parse Diamter identity form string

func (Identity) String

func (i Identity) String() string

type InvalidAVP

type InvalidAVP struct {
	Code uint32
	AVP
	E error
}

InvalidAVP is error of invalid AVP value

func (InvalidAVP) Error

func (e InvalidAVP) Error() string

type InvalidMessage

type InvalidMessage struct {
	Code   uint32
	ErrMsg string
}

InvalidMessage is error of invalid message

func (InvalidMessage) Error

func (e InvalidMessage) Error() string

type Message

type Message struct {
	FlgR  bool   // Request
	FlgP  bool   // Proxiable
	FlgE  bool   // Error
	FlgT  bool   // Potentially re-transmitted message
	Code  uint32 // Command-Code (24bit)
	AppID uint32 // Application-ID
	HbHID uint32 // Hop-by-Hop ID
	EtEID uint32 // End-to-End ID
	AVPs  []byte // Message body AVP binary data
}

Message is Diameter message.

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Version    |                 Message Length                |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Command Flags |                  Command Code                 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Application-ID                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                      Hop-by-Hop Identifier                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                      End-to-End Identifier                    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  AVPs ...
+-+-+-+-+-+-+-+-+-+-+-+-+-

func (*Message) GetAVP

func (m *Message) GetAVP() ([]AVP, error)

func (Message) MarshalTo

func (m Message) MarshalTo(w io.Writer) error

MarshalTo write binary data to io.Writer

func (*Message) SetAVP

func (m *Message) SetAVP(avp []AVP)

func (Message) String

func (m Message) String() string

func (*Message) UnmarshalFrom

func (m *Message) UnmarshalFrom(r io.Reader) error

UnmarshalFrom read binary data from io.Reader

type Router

type Router func(Message) *Connection

Router select destination peer for specific message.

type URI

type URI struct {
	Scheme    string
	Fqdn      Identity
	Port      int
	Transport string
	Protocol  string
}

URI is URI of Diameter protocol

func ParseURI

func ParseURI(str string) (uri URI, err error)

ParseURI parse Diamter URI form string

func (URI) String

func (d URI) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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