Author image PortaOne, Inc.
and 2 contributors

NAME

AnyEvent::Radius::Client - module to implement AnyEvent based RADIUS client

SYNOPSYS

    use AnyEvent;
    use AnyEvent::Radius::Client;

    my $dict = AnyEvent::Radius::Client->load_dictionary('path-to-radius-dictionary');

    sub read_reply_callback {
        # $h is HASH-REF {type, request_id, av_list, from, authenticator}
        my ($self, $h) = @_;
        ...
    }

    my $client = AnyEvent::Radius::Client->new(
                        ip => $ip,
                        port => $port,
                        on_read => \&read_reply_callback,
                        dictionary => $dict,
                        secret => $secret,
                    );
    $client->send_auth(AV_LIST1);
    $client->send_auth(AV_LIST2);
    ...
    $client->wait;
    ...
    $client->destroy;

DESCRIPTION

The AnyEvent::Radius::Client module allows to send multiple RADIUS requests in non-blocking way, and then wait for responses.

CONSTRUCTOR

new ( ..options hash )
ip
port - where to connect
secret - RADIUS secret string for remote server
dictionary - optional, dictionary loaded by load_dictionary() method
read_timeout
write_timeout - network I/O timeouts (default is 5 second)
Callbacks:
on_read - called when reply received, arguments is hash-ref with {request_id, type, av_list, authenticator} keys
on_read_raw - called when reply received, raw data packet is provided as argument
on_read_timeout - timeout waiting for reply from server. Aborts the waiting state
on_write_timeout - timeout sending request
on_error - invalid packet received, or low-level socket error

METHODS

load_dictionary ($dictionary-file)

Class method to load dictionary - returns the object to be passed to constructor

send_packet ( $type, $av_list, $cb )

Builds RADIUS packet using Data::Radius::Packet and store it to outgoing queue.

The type can be either the direct RFC packet type id, or one of its aliases, like COA, DM, POD, ACCT, AUTH ... see Data::Radius::Constants

Passing the optional callback $cb to be called upon receiving response to this request in form

  $cb->($resp_type, $resp_av_list)

or with empty parameters in case of missing response - eg. being timed out or unmatched authenticator

  $cb->()

Returns request id. Note that it's not possible to schedule more than 255 requests - trying to add more will return undef

send_auth ($av_list, $cb)
send_acct ($av_list, $cb)
send_pod ($av_list, $cb)
send_coa ($av_list, $cb)

Alias methods to send RADIUS request of required type by send_packet()

wait()

Blocks until all requests are received or read timeout reached

on_ready ( $cond_var )

Used to coordinate multiple clients instead of wait()

Example:

    my $cv = AnyEvent->condvar;
    $client1->on_ready($cv);
    $client2->on_ready($cv);
    $client3->on_ready($cv);
    $cv->recv;

Will be blocked until all clients finish their queue.

destroy()

Destroy the internal socket handle. Must be called when object is no longer required. When called from callback, it is recommended to wrap this call into AnyEvent::postpone { ... } block.

SEE ALSO

Authen::Radius, AnyEvent::Radius::Server, Data::Radius

AUTHOR

Sergey Leschenko <sergle.ua at gmail.com>

PortaOne Development Team <perl-radius at portaone.com> is the current module's maintainer at CPAN.