FW: (RADIATOR) NumHosts in SQLRadius

Martin Edge martinedge at kbs.net.au
Wed Aug 28 18:40:00 CDT 2002


Information on extending the functionality of SQLRADIUS

You may remember in a previous email I was asking about how to get NumHosts
to not be a fixed value.  NumHosts defines the amount of hosts avaliable for
the downstream configuration we are currently proxy RADIUS'ing to.

Reason being, that the amount of avaliable hosts is completely different for
each proxy-radius downstream.

I have modified my version of SQLRADIUS to fix this problem, and here's what
to do if anyone else is interested:

First part is the modification of the configuration keywords in the
AuthSQLRADIUS.pm module. I added NumHostQuery, as a string.

	%Radius::AuthSQLRADIUS::ConfigKeywords =
 	   (
	   'HostSelect'    => 'string',
 	   'NumHosts'      => 'integer',
  	   'NumHostQuery'  => 'string', # Define NumHostQuery for the Config
  	   'HostColumnDef' => 'stringhash',
	);

The NumHostQuery I use:

	NumHostQuery select count(*) from downstream_host downh, downstream_dnis
ddnis \
		       where ddnis.target_id = downh.target_id and ddnis.dnis =
'%{Called-Station-Id}'

Below, is the changes I made to the chooseHost method. Denoted by the
meriads of -------'s.

Thanks,
Martin

sub chooseHost
     {
     my ($self, $fp, $p) = @_;

     # If they have already tried to send this too many times, and there
     # are no more hosts to send to take the policy from the database
     # This standard table has space for 2 hosts. Adjust this if necessary
     return if ($fp->{hostCounter} >= $self->{NumHosts});
----------------------------------------- <my
bit> ------------------------------------------------
     # However, the first time we try to find a host for this
     # instance, we should check whether there is a NumHostQuery (to
     # confirm the amount of hosts)
     # Added by Martin Edge <medge at asmorphic.net.au>
     if (defined $self->{NumHostQuery}) # If there is a NumHostQuery defined


       if (!defined $self->{NumHostQueryRan}) { # If we haven't checked
NumHostQuery result
	    # Format the Query with special character results
          my $sth = $self->prepareAndExecute(
             &Radius::Util::format_special ($self->{NumHostQuery}, $p,
undef, undef, undef)
          );

	    # fetch results
          my @results = $sth->fetchrow();

	    # If there is results, update NumHosts, and set a flag in the object so
we know
	    # we have run a check
          if (@results) {
             $self->log($main::LOG_DEBUG, "ADJUSTING NUMHOSTS TO
".$results[0]);
             $self->{NumHosts} = $results[0];
          }

          $self->{NumHostQueryRan} = 1; # Mark the Object with a 'we have
checked it'
       }
     }
----------------------------------------- </my
bit> ------------------------------------------------

     $fp->{hostCounter}++;
     my $q = &Radius::Util::format_special
     ($self->{HostSelect}, $p, undef, $fp->{hostCounter});

     my $sth = $self->prepareAndExecute($q);
     return unless $sth;

     my (@row, $host);
     if (@row = $self->getOneRow($sth))
     {
        # If there is no host (maybe no secondary?) return
        return if $row[0] eq '';

        if (defined $self->{HostColumnDef})
        {
            $host = $self->getHostColumns($fp, @row);
        }
        else
        {
            # If certain columns are present, use them to
            # initialise the Radius::Host object that tells
            # AuthRADIUS where to proxy to.
            $fp->{failurePolicy} = $row[10] if defined $row[10];

            $host = Radius::Host->new
             (undef,  $row[0],
              defined $row[1] ? (Secret                     => $row[1]) :
(),
              defined $row[2] ? (AuthPort                   => $row[2]) :
(),
              defined $row[3] ? (AcctPort                   => $row[3]) :
(),
              defined $row[4] ? (Retries                    => $row[4]) :
(),
              defined $row[5] ? (RetryTimeout               => $row[5]) :
(),
              defined $row[6] ? (UseOldAscendPasswords      => $row[6]) :
(),
              defined $row[7] ? (ServerHasBrokenPortNumbers => $row[7]) :
(),
              defined $row[8] ? (ServerHasBrokenAddresses   => $row[8]) :
(),
              defined $row[9] ? (IgnoreReplySignature       => $row[9]) :
(),
              );
        }
    }
    else
    {
        # Call the superclass to fall back to any hardwired
        # hosts.
        return $self->SUPER::chooseHost($fp, $p, $p->{rp});
    }
    return $host;
}

===
Archive at http://www.open.com.au/archives/radiator/
Announcements on radiator-announce at open.com.au
To unsubscribe, email 'majordomo at open.com.au' with
'unsubscribe radiator' in the body of the message.


More information about the radiator mailing list