[RADIATOR] DB connections in hook code?

Heikki Vatiainen hvn at open.com.au
Wed Dec 21 14:30:44 CST 2011


On 12/21/2011 09:41 PM, Jared Watkins wrote:

> I'm new to Radiator and am working on my first set of hook code to
> evaluate it for a project.  I'm taking in call detail records via
> radius.. enriching them in the PostProcessingHook through a Handler
> and then storing some of them in a sql database.

Usually you have something like this:

<AuthBy SQL>
  Identifier sql-authby
  ...
</AuthBy>

The hook then starts with something like this:

sub {
    my $p = ${$_[0]};      # Request packet
    my $rp = ${$_[1]};     # Response packet

    my $authby_handle = Radius::AuthGeneric::find('sql-authby');
    # Build a $query with possibly @bind_values
    my $sth = $authby_handle->prepareAndExecute($query, @bind_values);
    ...
}

See goodies/hooks.txt for more hook examples. You could look for
PostAuthHook which runs earlier in the processing than PostProcessingHook.

> My question is about the environment the hook code runs in.  I know
> Radiator is multi-threaded... if I open a DB connection within a hook
> does that connection remain persistent between calls or is it closed
> and reopened for every packet?  Is the handle shared between threads
> etc?

Radiator is not multi-threaded. You can run multiple instances but there
are no parallel threads running within the same instance.

Also, as the example shows, it's easier to use e.g. AuthBy objects and
run queries using them. Since there are no threads, you do not have to
worry about using mutexes and such. The calls, such as
prepareAndExecute, open and reopen the DB connection when needed and do
failover according to handle objects configuration.

> I didn't see anything in the pdf doc that speaks to these sorts of
> questions.

See goodies/README and search for 'hook'. File hooks.txt has plenty of
examples but there are also other files that use hooks.

Thanks!
Heikki

-- 
Heikki Vatiainen <hvn at open.com.au>

Radiator: the most portable, flexible and configurable RADIUS server
anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald,
Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS,
TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP,
DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS,
NetWare etc.


More information about the radiator mailing list