From: Alan T. DeKok Date: Wed, 10 Sep 2014 12:49:08 +0000 (-0400) Subject: Fix allocate_find query. Addresses #786 X-Git-Tag: release_3_0_5~571 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0715ec7813be2e0bfebdf896d88f765b37971dd;p=thirdparty%2Ffreeradius-server.git Fix allocate_find query. Addresses #786 --- diff --git a/raddb/mods-config/sql/ippool-dhcp/mysql/queries.conf b/raddb/mods-config/sql/ippool-dhcp/mysql/queries.conf index ada0018df52..0a5d7effe2a 100644 --- a/raddb/mods-config/sql/ippool-dhcp/mysql/queries.conf +++ b/raddb/mods-config/sql/ippool-dhcp/mysql/queries.conf @@ -35,17 +35,24 @@ allocate_clear = "\ AND nasipaddress = '%{Nas-IP-Address}'" # -# The ORDER BY clause of this query tries to allocate the same IP-address -# which user had last session... +# Search for the SAME Calling-Station-ID as last time, OR an entry +# where there is no Calling-Station-Id. +# +# If the lease was expired, the allocate_clear above will reset the +# Calling-Station-Id to ''. +# +# If the lease wasn't expired, we want to give the user the same IP +# as last time. +# +# Then, we order by expiry_time, so that when there is no existing +# entry for the Calling-Station-Id, it picks the OLDEST expired IP. # allocate_find = "\ SELECT framedipaddress \ FROM ${ippool_table} \ WHERE pool_name = '%{control:Pool-Name}' \ - AND (expiry_time < NOW() OR expiry_time IS NULL) \ + AND (callingstationid = '%{Calling-Station-Id}' or callingstationid = '') \ ORDER BY \ - (username <> '%{User-Name}'), \ - (callingstationid <> '%{Calling-Station-Id}'), \ expiry_time \ LIMIT 1 \ FOR UPDATE"