SQLIPPOOL/IPPOOL prefix/range format

Phil Mayers p.mayers at imperial.ac.uk
Tue Apr 1 11:42:05 CEST 2008


rsg wrote:
> Hi,
> 
> Can you provide me with some more info to proceed with this?

There's no need to email me directly; I read the list.

> 
> I'm not quite sure of how to do it with "allocate-find".

Neither am I. It was a general suggestion.

Personally I wouldn't do it that way; I'd just insert the IPs into the 
table and let the module do it's work (unless you're leasing tens of 
millions of ips).

I guess if you want the radippool to only contain "active" ips it would 
be something like the following:

allocate-find = "select freeip('%P')"

allocate-update = "insert into radippool ..."

allocate-clear = "delete from radippool ..."

"freeip" would need to be a database stored procedure that did something 
like:

create function freeip(text) as $$$
  # mypools contains a mapping of pool name to netblock
  for netblock in select net from mypools where pool_name=$1
    # for each block in the pool, try to find a free IP
    ips = select ip from radippool where ip<<netblock and pool_name=$1
    free_ips = netblock - ips
    if free_ips:
        return free_ips[0]
$$$ language pseudo-python

...however, the stored procedure language would need IP address 
awareness and the ability to intersect/subtract CIDR blocks and IP 
lists. I'm not aware of any such capability in e.g. postgres plpgsql, so 
you'd need python or perl.

Basically, you'll have to write this yourself.

> 
> How could I define IP Prefixes and have my DB tables filled only with
> network prefixes?

That's not possible. You will have to retain state per-IP in order to 
map the nas+port (or whatever key you choose) to the IP leased and 
expiry time.

 From your email you sound like you're familiar with perl - you may wish 
to use rlm_perl instead of rlm_sqlippool; however you'll basically have 
to re-implement rlm_sqlippool.




More information about the Freeradius-Users mailing list