radius

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2016 License: MIT Imports: 9 Imported by: 1

README

radius

Go RADIUS client library

RADIUS Accounting / RFC2866

Client usage

cl := radius.NewClient(&radius.Opts{
	Host: "",
	SharedSecret: "",
})

// send arbitrary packets
resp, err := cl.Send(...)

Session Usage

id := ...

// create a new accounting session
sess := cl.NewSession(id, radius.TextString(radius.AccessUsername, "username"))

// add some data to the session
sess.AddInputOctet(12)
sess.AddOutputOctet(33)

// close the session
sess.Stop(radius.UserRequest)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// AccountingStart represents the start of RADIUS accounting session for a specific User
	AccountingStart = Attribute{AccountingStatusType, 6, fourOctet(1)}

	// AccountingStop represents the stop of a RADIUS accounting session for a specific USer
	AccountingStop = Attribute{AccountingStatusType, 6, fourOctet(2)}

	// ?
	InterimUpdate = Attribute{AccountingStatusType, 6, fourOctet(3)}

	// ?
	AccountingOn = Attribute{AccountingStatusType, 6, fourOctet(7)}

	// ?
	AccountingOff = Attribute{AccountingStatusType, 6, fourOctet(8)}

	UserRequest        = Attribute{AccountingTerminateCause, 6, fourOctet(1)}
	LostCarrier        = Attribute{AccountingTerminateCause, 6, fourOctet(2)}
	LostService        = Attribute{AccountingTerminateCause, 6, fourOctet(3)}
	IdleTimeout        = Attribute{AccountingTerminateCause, 6, fourOctet(4)}
	SessionTimeout     = Attribute{AccountingTerminateCause, 6, fourOctet(5)}
	AdminReset         = Attribute{AccountingTerminateCause, 6, fourOctet(6)}
	AdminReboot        = Attribute{AccountingTerminateCause, 6, fourOctet(7)}
	PortError          = Attribute{AccountingTerminateCause, 6, fourOctet(8)}
	NASError           = Attribute{AccountingTerminateCause, 6, fourOctet(9)}
	NASRequest         = Attribute{AccountingTerminateCause, 6, fourOctet(10)}
	NASReboot          = Attribute{AccountingTerminateCause, 6, fourOctet(11)}
	PortUnneeded       = Attribute{AccountingTerminateCause, 6, fourOctet(12)}
	PortPreempted      = Attribute{AccountingTerminateCause, 6, fourOctet(13)}
	PortSuspended      = Attribute{AccountingTerminateCause, 6, fourOctet(14)}
	ServiceUnavailable = Attribute{AccountingTerminateCause, 6, fourOctet(15)}
	Callback           = Attribute{AccountingTerminateCause, 6, fourOctet(16)}
	UserError          = Attribute{AccountingTerminateCause, 6, fourOctet(17)}
	HostRequest        = Attribute{AccountingTerminateCause, 6, fourOctet(18)}
)

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Type   AttributeType
	Length int8
	Values []Writer
}

An Attribute is a Key-Value pair attached to a request or response

func StringAttribute

func StringAttribute(t AttributeType, str string) Attribute

StringAttribute builds an attribute of length >= 3 with the given string

func (*Attribute) Write

func (attr *Attribute) Write(w io.Writer) error

Write writes the attribute to the given writer

type AttributeType

type AttributeType int64

AttributeType defines types for an Attribute

const (

	// AccountingStatusType indicates whether the AccountingRequest is the beginning of a user service (Start) or the end of a user service (Stop)
	AccountingStatusType AttributeType = 40

	// AccountingDelayTime indicates how many seconds the client has been trying to send this record for
	AccountingDelayTime AttributeType = 41

	// AccountingInputOctets indicates how many octets have been received from this port over the course of this service being provided and is only usable when AccountingStatusType is Stop
	AccountingInputOctets AttributeType = 42

	// AccountingOutputOctets indicates how many octets have been sent from this from this port over the course of this service being provided and is only usable when AccountingStatusType is Stop
	AccountingOutputOctets AttributeType = 43

	// AccountingSessionID indicates the session ID for the accounting session, must match for the matching Start and Stop message, and must be present on all Accounting messages
	AccountingSessionID AttributeType = 44

	// AccountingAuthentic indicates how the user was authenticated and MAY be included.
	AccountingAuthentic AttributeType = 45

	// AccountingSessionTime indicates how many seconds the user has received service for and can only be included when AccountingStatusType is Stop
	AccountingSessionTime AttributeType = 46

	// AccountingInputPackets incidates how many packets have been received from the port over the course of this service being provided to a Framed (?) User and is only usable when AccountingStatusType is Stop
	AccountingInputPackets AttributeType = 47

	// AccountingOutputPackets incidates how many packets have been sent from the port over the course of this service being provided to a Framed (?) User and is only usable when AccountingStatusType is Stop
	AccountingOutputPackets AttributeType = 48

	// AccountingTerminateCause indicates how the session was terminated and is only usable when AccountingStatusType is Stop
	AccountingTerminateCause AttributeType = 49

	// AccountingMultiSessionID is used to mark multiple related sessions together
	AccountingMultiSessionID AttributeType = 50

	// AccountingMultiLinkCount is used to convey how many related sessions are linked together via the AccountingMultiSessionID
	AccountingMultiLinkCount AttributeType = 51

	// AccessUserName is used to mark the attribute as the username field
	AccessUserName AttributeType = 1
)

func (AttributeType) Write

func (a AttributeType) Write(w io.Writer) error

Write writes the attribute type to the given writer

type AttributeValue

type AttributeValue Writer

An AttributeValue is a value attached to an attribute

type Authenticator

type Authenticator interface {
	Calculate(p *Packet) ([]byte, error)
}

An Authenticator is responsible for calculating the Authenticator field of the packet

func AccountingRequestAuthenticator

func AccountingRequestAuthenticator(sharedSecret string) Authenticator

AccountingRequestAuthenticator returns an implementation of Authenticator used for sending RADIUS accounting requests

type Client

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

A Client is the representation of a connection to a RADIUS server

func NewClient

func NewClient(o *Options) *Client

NewClient creates a new client from the given options

func (*Client) Close

func (cl *Client) Close()

Close closes the client and any related sessions

func (*Client) NewSession

func (cl *Client) NewSession(ID string, attrs ...Attribute) *Session

func (*Client) Send

func (cl *Client) Send(p *Packet) (*Packet, error)

Send sends a request packet to the RADIUS server

type Identifier

type Identifier uint8

Identifier is the unique ID of a Packet

func (*Identifier) Read

func (id *Identifier) Read(r io.Reader) error

Read reads the identifier from the given reader

func (Identifier) Write

func (id Identifier) Write(w io.Writer) error

Write writes the identifier to the given writer

type Options

type Options struct {
	Host         string
	SharedSecret string
}

Options defines the options used to connect to a RADIUS server (currently only supporting accounting)

type Packet

type Packet struct {
	Code       PacketCode
	ID         Identifier
	Attributes []Attribute
	// contains filtered or unexported fields
}

A Packet is a RADIUS message

func (*Packet) Length

func (p *Packet) Length() int16

Length returns the length of the packet

func (*Packet) Read

func (p *Packet) Read(rx io.Reader) error

func (*Packet) Write

func (p *Packet) Write(wx io.Writer) error

type PacketCode

type PacketCode int64

A PacketCode is a code that defines the type of the packet

const (

	// AccountingRequest represents a RADIUS accounting request packet
	AccountingRequest PacketCode = 4

	// AccountingResponse respresents a RADIUS accounting response packet
	AccountingResponse PacketCode = 5
)

func (*PacketCode) Read

func (code *PacketCode) Read(r io.Reader) error

Read reads the packet code from the reader

func (PacketCode) Write

func (code PacketCode) Write(w io.Writer) error

Write writes the packet code to the writer

type Reader

type Reader interface {
	Read(r io.Reader) error
}

Reader defines an object that can be read from the given io.Reader

type Session

type Session struct {
	ID string
	// contains filtered or unexported fields
}

A Session represents an Accounting session

func (*Session) AddInputOctets

func (s *Session) AddInputOctets(i int32)

func (*Session) AddOutputOctets

func (s *Session) AddOutputOctets(i int32)

func (*Session) InterimUpdate

func (s *Session) InterimUpdate(attrs ...Attribute) error

InterimUpdate sends an update

func (*Session) Start

func (s *Session) Start(attrs ...Attribute) error

Start starts the session

func (*Session) Stop

func (s *Session) Stop(attrs ...Attribute) (err error)

Stop stops the session

type Writer

type Writer interface {
	Write(w io.Writer) error
}

Writer defines an object that can be written to the given io.Writer

type WriterFunc

type WriterFunc func(w io.Writer) error

WriterFunc defines a function conversion for the radius.Writer interface

func (WriterFunc) Write

func (f WriterFunc) Write(w io.Writer) error

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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