SQL-IP-Pool
The sqlippool module allocates IP addresses from one or more pools
of addresses. It tracks addresses to that it does not issue the same
leased IP address to multiple devices.
Using FreeRADIUS for IP address allocation has some advantages. Centralized pool management means that the pools remains available when one or more of the NASs becomes unavailable. When pools are managed on a NAS, the pools are down when the NAS is down.
Networks may have organisation-specific policies for the way that IP addresses are assigned. These policies are difficult to implement on a NAS, but can be implemented with FreeRADIUS. For example, FreeRADIUS can assign pools of IP addresses to specific NASs or user groups. FreeRADIUS also control reallocation, in order to move users from one pool to another, without disconnecting them. This move allows address ranges to be retired or repurposed without forcibly disconnecting the users.
As with most FreeRADIUS modules, the sqlippool module ships with a
default configuration that "just works". However, the module can also
be configured to use sophisticated IP allocation policies, via custom
SQL queries.
All of the SQL queries used by the module are configurable. The module simply provides for a few "hooks", in order to allocate an IP, clear an IP, expire IPs, etc. The result is that the IP pool allocations works with all possible SQL databases, without requiring code changes. In addition, anyone familiar with SQL can customize the allocation policies. Minimal knowledge of FreeRADIUS is required.
The default schema and queries are also designed to manage both
dynamic and static IP address assignment through the use of the status
column.
Operation
The SQL IP Pools module only perform an action when FreeRADIUS
receives a packet. The entire state of the pools is held in the
fr_ippool table. The benefit of this approach is that the RADIUS
server can be restarted, replaced, or debugged without losing track of
any IP addresses.
One downside is that there is no method to perform actions at a particular time. We suggest using "cron" for periodic cleanups, analysis, etc.
Another downside is that FreeRADIUS does not "know" the state of a
particular IP address. The sqlippool module simply runs SQL
queries, which either return an IP address, or return "failed to
allocate IP". Since the entire state of the pool is in the SQL
database, we recommend using standard SQL queries to find the state of
an individual IP address, MAC address, etc.
Access-Request: A device connects to the NAS with correct credentials
-
FreeRADIUS receives an
Access-Requestfrom the NAS. After some processing (modules.unlang, etc.), theIP-Pool.Nameattribute is added to thecontrollist. This attribute indicates that the IP address should be allocated from the named pool. This attribute can be added from any module, database,unlang, etc. -
When the
sqlippoolmodule is eventually run, it looks for theIP-Pool.Nameattribute, and runs the various SQL queries in order to perform IP address allocation. If the module is configured to place address into theFramed-IP-Addressattribute (as it is by default), and that attribute already exists, the module does nothing, and returnsnoop. -
The module then runs the
alloc_existingquery, which looks for the IP address last assigned to the device from the pool indicated byIP-Pool.Name. The device is identified using theownerconfiguration item (typicallyNAS-Port) and thegatewayconfiguration item (usuallyNAS-IP-Address). -
If no address was found using
alloc_existing, and bothrequested_addressexpands to a value and thealloc_requestedquery is configured, then the module runs thealloc_requestedquery which looks to see if the address identified byrequested_addressis available. -
If no address was found using
alloc_existingoralloc_requested, the module then runs thealloc_findquery, which chooses a free IP address from the pool indicated byIP-Pool.Name. Ifalloc_finddoes not return an IP address, thepool_checkquery is run in order to determine why the allocation failed. For example, either the requested pool is empty (i.e. no free addresses), or it is non-existent. This information is returned in thesqlippoolmodule return code, asnotfound, or one of the other return codes. -
If an IP address has been found, the module runs the
alloc_updatequery. This query assigns the IP address to the device by updating thefr_ippoolrow for the IP address with information about the lease. The default information includesexpiry timebased on the configuredlease_duration, a unique identifier for the device as specified by theownerconfiguration item (typicallyNAS-Port) andgateway(theNAS-IP-Address). This information can be used to assign the same IP to the same user or device, on subsequent allocation requests. With some database backends (PostgreSQL and MS SQLServer) the update can be incorporated into thealloc_existing,alloc_requestedandalloc_findqueries, reducing round trips to the database and improving performance. -
The module returns
updatedto indicate that it was successful in allocating an IP address. -
After some additional processing (modules,
unlang, etc.), FreeRADIUS sends an Access-Accept containing aFramed-IP-Addressattribute holding the allocated IP address to the NAS.
Accounting Start: A device and a NAS successfully establish a session
-
The NAS sends an
Accounting Startrequest to FreeRADIUS. After some processing (modules.unlang, etc.), thesqlippoolmodule is run. -
The
sqlippolmodule runs theupdate_updatequery. This query uses the configuredrequested_address,ownerandpool_namein order to identify which entry in thefr_ippooltable to update. Theexpiry_timeis updated based on the configuredlease_duration. This update extends the initial lease to the configuredlease_durationin case the event that the Accounting Start request was delayed. -
The module returns
updatedto indicate that it was successful in updating the state of the IP address. -
After some additional processing (modules,
unlang, etc.), FreeRADIUS sends an Accounting-Response to the NAS.
Accounting Interim-Update: A NAS sends an Interim-Update notification for a device’s session
-
The NAS sends an
Accounting Interim-Updaterequest to FreeRADIUS. After some processing (modules.unlang, etc.), thesqlippoolmodule is run. -
The
sqlippolmodule runs theupdate_updatequery. This query uses the configuredrequested_address,ownerandpool_namein order to identify which entry in thefr_ippooltable to update. Theexpiry_timeis updated based on the configuredlease_duration. -
The module returns
updatedto indicate that it was successful in updating the state of the IP address. -
After some additional processing (modules,
unlang, etc.), FreeRADIUS sends an Accounting-Response to the NAS.
Accounting Stop: A device disconnects or its session times out
-
The NAS sends an
Accounting Stoprequest to FreeRADIUS. After some processing (modules.unlang, etc.), thesqlippoolmodule is run. -
The
sqlippolmodule runs therelease_clearquery. This query uses the configuredrequested_address,ownerandpool_namein order to identify which entry in thefr_ippooltable to update. The update "clears" the IP address, and marks it as free for later allocation. Note that by default, this "clear" does removes information about which user or device was associated with that address. The result is that on subsequent allocations, it is not possible to re-allocate the same IP address to the same user or device. If re-allocation of the previous IP address is required, then the query should be amended to not update the value of theownerfield. -
The module returns
updatedto indicate that it was successful in updating the state of the IP address. -
After some additional processing (modules,
unlang, etc.), FreeRADIUS sends an Accounting-Response to the NAS.
Accounting On/Off: A NAS indicates that all of its sessions have been cleared
-
The NAS sends an
Accounting OnorAccounting Offrequest to FreeRADIUS. After some processing (modules.unlang, etc.), thesqlippoolmodule is run. -
The
sqlippolmodule runs thebulk_release_clearquery. This query uses the configuredgatewayin order to identify all leases in thefr_ippooltable which belong to the NAS in question. The leases are cleared, and the IP addresses are immediately released for further allocation. This process effectively returns all IP address occupied by the dropped sessions back into the pool. -
The module returns
updatedto indicate that it was successful in updating the state of the IP addresses. -
After some additional processing (modules,
unlang, etc.), FreeRADIUS sends an Accounting-Response to the NAS.